1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00

net: ipv6: rpl_iptunnel: mitigate 2-realloc issue

This patch mitigates the two-reallocations issue with rpl_iptunnel by
providing the dst_entry (in the cache) to the first call to
skb_cow_head(). As a result, the very first iteration would still
trigger two reallocations (i.e., empty cache), while next iterations
would only trigger a single reallocation.

Performance tests before/after applying this patch, which clearly shows
there is no impact (it even shows improvement):
- before: https://ibb.co/nQJhqwc
- after: https://ibb.co/4ZvW6wV

Signed-off-by: Justin Iurman <justin.iurman@uliege.be>
Cc: Alexander Aring <aahringo@redhat.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
Justin Iurman 2024-12-03 13:49:45 +01:00 committed by Paolo Abeni
parent 40475b6376
commit 985ec6f5e6

View file

@ -125,7 +125,8 @@ static void rpl_destroy_state(struct lwtunnel_state *lwt)
} }
static int rpl_do_srh_inline(struct sk_buff *skb, const struct rpl_lwt *rlwt, static int rpl_do_srh_inline(struct sk_buff *skb, const struct rpl_lwt *rlwt,
const struct ipv6_rpl_sr_hdr *srh) const struct ipv6_rpl_sr_hdr *srh,
struct dst_entry *cache_dst)
{ {
struct ipv6_rpl_sr_hdr *isrh, *csrh; struct ipv6_rpl_sr_hdr *isrh, *csrh;
const struct ipv6hdr *oldhdr; const struct ipv6hdr *oldhdr;
@ -153,7 +154,7 @@ static int rpl_do_srh_inline(struct sk_buff *skb, const struct rpl_lwt *rlwt,
hdrlen = ((csrh->hdrlen + 1) << 3); hdrlen = ((csrh->hdrlen + 1) << 3);
err = skb_cow_head(skb, hdrlen + skb->mac_len); err = skb_cow_head(skb, hdrlen + dst_dev_overhead(cache_dst, skb));
if (unlikely(err)) { if (unlikely(err)) {
kfree(buf); kfree(buf);
return err; return err;
@ -186,7 +187,8 @@ static int rpl_do_srh_inline(struct sk_buff *skb, const struct rpl_lwt *rlwt,
return 0; return 0;
} }
static int rpl_do_srh(struct sk_buff *skb, const struct rpl_lwt *rlwt) static int rpl_do_srh(struct sk_buff *skb, const struct rpl_lwt *rlwt,
struct dst_entry *cache_dst)
{ {
struct dst_entry *dst = skb_dst(skb); struct dst_entry *dst = skb_dst(skb);
struct rpl_iptunnel_encap *tinfo; struct rpl_iptunnel_encap *tinfo;
@ -196,7 +198,7 @@ static int rpl_do_srh(struct sk_buff *skb, const struct rpl_lwt *rlwt)
tinfo = rpl_encap_lwtunnel(dst->lwtstate); tinfo = rpl_encap_lwtunnel(dst->lwtstate);
return rpl_do_srh_inline(skb, rlwt, tinfo->srh); return rpl_do_srh_inline(skb, rlwt, tinfo->srh, cache_dst);
} }
static int rpl_output(struct net *net, struct sock *sk, struct sk_buff *skb) static int rpl_output(struct net *net, struct sock *sk, struct sk_buff *skb)
@ -208,14 +210,14 @@ static int rpl_output(struct net *net, struct sock *sk, struct sk_buff *skb)
rlwt = rpl_lwt_lwtunnel(orig_dst->lwtstate); rlwt = rpl_lwt_lwtunnel(orig_dst->lwtstate);
err = rpl_do_srh(skb, rlwt);
if (unlikely(err))
goto drop;
local_bh_disable(); local_bh_disable();
dst = dst_cache_get(&rlwt->cache); dst = dst_cache_get(&rlwt->cache);
local_bh_enable(); local_bh_enable();
err = rpl_do_srh(skb, rlwt, dst);
if (unlikely(err))
goto drop;
if (unlikely(!dst)) { if (unlikely(!dst)) {
struct ipv6hdr *hdr = ipv6_hdr(skb); struct ipv6hdr *hdr = ipv6_hdr(skb);
struct flowi6 fl6; struct flowi6 fl6;
@ -237,15 +239,15 @@ static int rpl_output(struct net *net, struct sock *sk, struct sk_buff *skb)
local_bh_disable(); local_bh_disable();
dst_cache_set_ip6(&rlwt->cache, dst, &fl6.saddr); dst_cache_set_ip6(&rlwt->cache, dst, &fl6.saddr);
local_bh_enable(); local_bh_enable();
err = skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev));
if (unlikely(err))
goto drop;
} }
skb_dst_drop(skb); skb_dst_drop(skb);
skb_dst_set(skb, dst); skb_dst_set(skb, dst);
err = skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev));
if (unlikely(err))
goto drop;
return dst_output(net, sk, skb); return dst_output(net, sk, skb);
drop: drop:
@ -262,29 +264,31 @@ static int rpl_input(struct sk_buff *skb)
rlwt = rpl_lwt_lwtunnel(orig_dst->lwtstate); rlwt = rpl_lwt_lwtunnel(orig_dst->lwtstate);
err = rpl_do_srh(skb, rlwt);
if (unlikely(err))
goto drop;
local_bh_disable(); local_bh_disable();
dst = dst_cache_get(&rlwt->cache); dst = dst_cache_get(&rlwt->cache);
local_bh_enable();
err = rpl_do_srh(skb, rlwt, dst);
if (unlikely(err))
goto drop;
if (!dst) { if (!dst) {
ip6_route_input(skb); ip6_route_input(skb);
dst = skb_dst(skb); dst = skb_dst(skb);
if (!dst->error) { if (!dst->error) {
local_bh_disable();
dst_cache_set_ip6(&rlwt->cache, dst, dst_cache_set_ip6(&rlwt->cache, dst,
&ipv6_hdr(skb)->saddr); &ipv6_hdr(skb)->saddr);
local_bh_enable();
} }
err = skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev));
if (unlikely(err))
goto drop;
} else { } else {
skb_dst_drop(skb); skb_dst_drop(skb);
skb_dst_set(skb, dst); skb_dst_set(skb, dst);
} }
local_bh_enable();
err = skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev));
if (unlikely(err))
goto drop;
return dst_input(skb); return dst_input(skb);