Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: jhs@mojatatu.com
Cc: netdev@vger.kernel.org, daniel@iogearbox.net,
	john.fastabend@gmail.com, sdf@fomichev.me, martin.lau@linux.dev,
	ast@kernel.org, andrii@kernel.org, eddyz87@gmail.com,
	memxor@gmail.com, song@kernel.org, yonghong.song@linux.dev,
	jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, bpf@vger.kernel.org,
	jiri@resnulli.us, victor@mojatatu.com, sashiko-bot@kernel.org
Subject: Re: [PATCH net-next v4 2/4] net: dst: keep the LWT metadata of a dropped route
Date: Thu, 19 Nov 2026 20:02:42 +0000	[thread overview]
Message-ID: <179511856244.3136.14894552339395914339@kernel.org> (raw)
In-Reply-To: <CORE-9NOG.v4.r0.20261116135311-2@mojatatu.com>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message says the ip/ip6 copy "starts with an empty
  cache, which costs the tunnel one route lookup".
- [Low] The kernel-doc of skb_dst_drop_keep_metadata() (net/core/dst.c)
  does not match the implementation in two places.

--

net: dst: keep the LWT metadata of a dropped route

This commit adds skb_dst_drop_keep_metadata(). The helper releases an
skb's route dst, but first moves the ip/ip6 tunnel info or the xfrm md
info held in the route's lwtstate onto a newly allocated metadata dst.
Nothing calls it yet; the nft fwd and bpf redirect patches later in the
series will use it.

> diff --git a/net/core/dst.c b/net/core/dst.c
> index 092861133023c..fd63580e6529d 100644
> --- a/net/core/dst.c
> +++ b/net/core/dst.c
> @@ -353,3 +353,82 @@ void metadata_dst_free_percpu(struct metadata_dst __percpu *md_dst)

[ ... ]

> + * A dst that is metadata, or absent, is left in place. Any other dst is
> + * released, and a route with no encapsulation parameters leaves the skb
> + * with no dst at all.
> + *
> + * Return: true when the skb is left free to be sent: its dst was already
> + * metadata or absent, the encapsulation parameters were moved onto a new
> + * dst, or there were none and the route was simply released. False when
> + * the copy could not be allocated or a reference on the route could not
> + * be taken; the caller must drop the skb.
> + */

[Severity: Low]

Does this kernel-doc match what skb_dst_drop_keep_metadata() actually does?

The Return: section says true means the parameters were moved, or "there
were none and the route was simply released". The code only keeps
LWTUNNEL_ENCAP_XFRM, LWTUNNEL_ENCAP_IP and LWTUNNEL_ENCAP_IP6.

Take a route whose lwtstate is MPLS, ILA, SEG6, SEG6_LOCAL, BPF, RPL or
IOAM6. It falls through to skb_dst_drop() with md_dst == NULL, its
encapsulation is thrown away, and the function still returns true, the
same value documented for "there were none".

The code is consistent with the two readers the doc names,
skb_tunnel_info() and skb_xfrm_md_info(). The general wording of the
contract, though, does not say it is limited to those types.

Also, "Any other dst is released" does not hold for the xfrm branch:

    md_dst->u.xfrm_info.dst_orig = old;
    skb_dstref_steal(skb);
    skb_dst_set(skb, &md_dst->dst);

In that branch the route is not released. It keeps a counted reference
inside the metadata dst, which is what the earlier sentence "for xfrm the
route is kept" describes.

The v4 changelog says this Return: section was meant to be corrected.
Could these two points be covered as well?

> +bool skb_dst_drop_keep_metadata(struct sk_buff *skb)
> +{

[ ... ]

> +	if (old->lwtstate &&
> +	    (old->lwtstate->type == LWTUNNEL_ENCAP_IP ||
> +	     old->lwtstate->type == LWTUNNEL_ENCAP_IP6)) {
> +		struct ip_tunnel_info *src = lwt_tun_info(old->lwtstate);
> +		struct ip_tunnel_info *dst;
> +
> +		md_dst = metadata_dst_alloc(src->options_len,
> +					    METADATA_IP_TUNNEL, GFP_ATOMIC);

[Severity: Low]

The commit message says:

    the copy starts with an empty cache, which costs the tunnel one
    route lookup.

Is that accurate? This metadata_dst_alloc() runs with GFP_ATOMIC once per
skb, and dst_cache_init() is never called on md_dst->u.tun_info.dst_cache.
__metadata_dst_init() memsets the payload, so dst_cache.cache stays NULL:

net/core/dst.c:__metadata_dst_init() {
    ...
	memset(dst + 1, 0, sizeof(*md_dst) + optslen - sizeof(*dst));
    ...
}

With a NULL cache, dst_cache_get_ip4() and dst_cache_get_ip6() return NULL,
and dst_cache_set_ip4() and dst_cache_set_ip6() store nothing. So the copy
has no cache at all, not an empty one.

The route's own lwtstate has a shared, persistent cache, set up by
dst_cache_init() in ip_tun_build_state(). Before this series the tunnel
used that cache through skb_tunnel_info().

Later in the series, nft_fwd_neigh_eval() and __bpf_redirect_neigh_v4/v6()
call this helper. At that point, wouldn't every steered packet over an
ip/ip6 encap route cost a GFP_ATOMIC metadata_dst allocation, an
RCU-deferred free, and a full route lookup in the collect_md tunnel?

Could the commit message say that the cost is per packet and that it adds
an allocation?

> +		if (!md_dst)
> +			return false;

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/CORE-9NOG.v4.r0.20261116135311%40mojatatu.com

  reply	other threads:[~2026-11-19 20:02 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 19:01 [PATCH net-next v4 0/4] net: drop the stale dst when steering to another device Jamal Hadi Salim
2026-11-16 19:01 ` [PATCH net-next v4 1/4] net: xfrm: interface: restore dst_orig on every xfrm interface Jamal Hadi Salim
2026-11-19 20:02   ` netdev-bot+sashiko
2026-11-16 19:01 ` [PATCH net-next v4 2/4] net: dst: keep the LWT metadata of a dropped route Jamal Hadi Salim
2026-11-19 20:02   ` netdev-bot+sashiko [this message]
2026-11-16 19:01 ` [PATCH net-next v4 3/4] netfilter: nft_fwd_netdev: drop the stale dst when steering to a device Jamal Hadi Salim
2026-11-19 20:02   ` netdev-bot+sashiko
2026-11-16 19:01 ` [PATCH net-next v4 4/4] bpf: drop the stale dst when redirecting to an explicit nexthop Jamal Hadi Salim
2026-11-16 20:46   ` Alexei Starovoitov
2026-11-16 22:06     ` Jamal Hadi Salim
2026-11-17  4:50       ` Alexei Starovoitov
2026-11-17 13:15         ` Jamal Hadi Salim
2026-11-17 14:00           ` Jamal Hadi Salim
2026-11-19 20:02   ` netdev-bot+sashiko

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=179511856244.3136.14894552339395914339@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=eddyz87@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=emil@etsalapatis.com \
    --cc=horms@kernel.org \
    --cc=ihor.solodrai@linux.dev \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kuba@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sashiko-bot@kernel.org \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=victor@mojatatu.com \
    --cc=yonghong.song@linux.dev \
    /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