From: Paolo Abeni <pabeni@redhat.com>
To: Justin Iurman <justin.iurman@uliege.be>, netdev@vger.kernel.org
Cc: davem@davemloft.net, dsahern@kernel.org, edumazet@google.com,
kuba@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net 1/2] net: ioam6: use "new" dst entry with skb_cow_head
Date: Thu, 04 Jul 2024 11:08:15 +0200 [thread overview]
Message-ID: <c026a24950813970edab1917c4f85b70db4900b2.camel@redhat.com> (raw)
In-Reply-To: <20240702174451.22735-2-justin.iurman@uliege.be>
On Tue, 2024-07-02 at 19:44 +0200, Justin Iurman wrote:
> In ioam6_output(), we call skb_cow_head() with LL_RESERVED_SPACE(). The
> latter uses "dst", which is potentially not the good one anymore. As a
> consequence, there might not be enough headroom, depending on the "new"
> dev (e.g., needed_headroom > 0). Therefore, we first need to get the
> "new" dst entry (from the cache or by calling ip6_route_output()), just
> like seg6 and rpl both do, and only then call skb_cow_head() with
> LL_RESERVED_SPACE() on the "new" dst entry.
>
> Fixes: 8cb3bf8bff3c ("ipv6: ioam: Add support for the ip6ip6 encapsulation")
> Signed-off-by: Justin Iurman <justin.iurman@uliege.be>
> ---
> net/ipv6/ioam6_iptunnel.c | 65 +++++++++++++++++++--------------------
> 1 file changed, 32 insertions(+), 33 deletions(-)
>
> diff --git a/net/ipv6/ioam6_iptunnel.c b/net/ipv6/ioam6_iptunnel.c
> index bf7120ecea1e..b08c13550144 100644
> --- a/net/ipv6/ioam6_iptunnel.c
> +++ b/net/ipv6/ioam6_iptunnel.c
> @@ -295,7 +295,7 @@ static int ioam6_do_encap(struct net *net, struct sk_buff *skb,
>
> static int ioam6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
> {
> - struct dst_entry *dst = skb_dst(skb);
> + struct dst_entry *dst, *orig_dst = skb_dst(skb);
> struct in6_addr orig_daddr;
> struct ioam6_lwt *ilwt;
> int err = -EINVAL;
> @@ -304,7 +304,7 @@ static int ioam6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
> if (skb->protocol != htons(ETH_P_IPV6))
> goto drop;
>
> - ilwt = ioam6_lwt_state(dst->lwtstate);
> + ilwt = ioam6_lwt_state(orig_dst->lwtstate);
>
> /* Check for insertion frequency (i.e., "k over n" insertions) */
> pkt_cnt = atomic_fetch_inc(&ilwt->pkt_cnt);
> @@ -346,45 +346,44 @@ static int ioam6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
> goto drop;
> }
>
> - err = skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev));
> - if (unlikely(err))
> - goto drop;
> + local_bh_disable();
> + dst = dst_cache_get(&ilwt->cache);
> + local_bh_enable();
This makes the dst lookup and cache update unconditional, at best
slowing down ioam6_output(), possibly introducing unintended side
effects.
> +
> + if (unlikely(!dst)) {
> + struct ipv6hdr *hdr = ipv6_hdr(skb);
> + struct flowi6 fl6;
> +
> + memset(&fl6, 0, sizeof(fl6));
> + fl6.daddr = hdr->daddr;
> + fl6.saddr = hdr->saddr;
> + fl6.flowlabel = ip6_flowinfo(hdr);
> + fl6.flowi6_mark = skb->mark;
> + fl6.flowi6_proto = hdr->nexthdr;
> +
> + dst = ip6_route_output(net, NULL, &fl6);
> + if (dst->error) {
> + err = dst->error;
> + dst_release(dst);
> + goto drop;
> + }
>
> - if (!ipv6_addr_equal(&orig_daddr, &ipv6_hdr(skb)->daddr)) {
> local_bh_disable();
> - dst = dst_cache_get(&ilwt->cache);
> + dst_cache_set_ip6(&ilwt->cache, dst, &fl6.saddr);
> local_bh_enable();
> + }
>
> - if (unlikely(!dst)) {
> - struct ipv6hdr *hdr = ipv6_hdr(skb);
> - struct flowi6 fl6;
> -
> - memset(&fl6, 0, sizeof(fl6));
> - fl6.daddr = hdr->daddr;
> - fl6.saddr = hdr->saddr;
> - fl6.flowlabel = ip6_flowinfo(hdr);
> - fl6.flowi6_mark = skb->mark;
> - fl6.flowi6_proto = hdr->nexthdr;
> -
> - dst = ip6_route_output(net, NULL, &fl6);
> - if (dst->error) {
> - err = dst->error;
> - dst_release(dst);
> - goto drop;
> - }
> -
> - local_bh_disable();
> - dst_cache_set_ip6(&ilwt->cache, dst, &fl6.saddr);
> - local_bh_enable();
> - }
> + skb_dst_drop(skb);
> + skb_dst_set(skb, dst);
>
> - skb_dst_drop(skb);
> - skb_dst_set(skb, dst);
> + err = skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev));
> + if (unlikely(err))
> + goto drop;
This is quite a bit of code churn, but you just need to postpone the
cow operation after the dst lookup right?
I suggest to simply move the cow there, something alike (completely
untested):
---
diff --git a/net/ipv6/ioam6_iptunnel.c b/net/ipv6/ioam6_iptunnel.c
index bf7120ecea1e..636480bded0e 100644
--- a/net/ipv6/ioam6_iptunnel.c
+++ b/net/ipv6/ioam6_iptunnel.c
@@ -346,10 +346,6 @@ static int ioam6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
goto drop;
}
- err = skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev));
- if (unlikely(err))
- goto drop;
-
if (!ipv6_addr_equal(&orig_daddr, &ipv6_hdr(skb)->daddr)) {
local_bh_disable();
dst = dst_cache_get(&ilwt->cache);
@@ -381,9 +377,17 @@ static int ioam6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
skb_dst_drop(skb);
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);
}
out:
+ err = skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev));
+ if (unlikely(err))
+ goto drop;
+
return dst->lwtstate->orig_output(net, sk, skb);
drop:
kfree_skb(skb);
---
Thanks,
Paolo
next prev parent reply other threads:[~2024-07-04 9:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-02 17:44 [PATCH net 0/2] net: ioam6: fix bugs in ioam6_iptunnel Justin Iurman
2024-07-02 17:44 ` [PATCH net 1/2] net: ioam6: use "new" dst entry with skb_cow_head Justin Iurman
2024-07-04 9:08 ` Paolo Abeni [this message]
2024-07-02 17:44 ` [PATCH net 2/2] net: ioam6: mitigate the two reallocations problem Justin Iurman
2024-07-02 18:30 ` Justin Iurman
2024-07-04 9:23 ` Paolo Abeni
2024-07-04 11:58 ` Justin Iurman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c026a24950813970edab1917c4f85b70db4900b2.camel@redhat.com \
--to=pabeni@redhat.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=justin.iurman@uliege.be \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®