Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: florian.fainelli@broadcom.com
Cc: netdev@vger.kernel.org, rafal@milecki.pl,
	bcm-kernel-feedback-list@broadcom.com, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, robh@kernel.org, krzk+dt@kernel.org,
	conor+dt@kernel.org, horms@kernel.org, corbet@lwn.net,
	jonas.gorski@gmail.com, olteanv@gmail.com, pablo@netfilter.org,
	fw@strlen.de, phil@nwl.cc, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
	netfilter-devel@vger.kernel.org, coreteam@netfilter.org
Subject: Re: [PATCH net-next 6/9] net: flow_offload: allow drivers to validate and invalidate cached paths
Date: Tue, 17 Nov 2026 23:29:25 +0000	[thread overview]
Message-ID: <179495816543.3136.12103952304400202953@kernel.org> (raw)
In-Reply-To: <20261116222519.1416501-7-florian.fainelli@broadcom.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] nf_flow_offload_validate()
  (net/netfilter/nf_flow_table_offload.c:931-939) checks the neighbour…
- [Low] nf_flow_offload_validate()
  (net/netfilter/nf_flow_table_offload.c:929 and 934) is documented as…

--

net: flow_offload: allow drivers to validate and invalidate cached paths

This adds optional invalidate and validate callbacks to struct
flow_cls_offload. Offload drivers can use them to ask the flowtable owner
whether a cached path is still valid, and to tear the owning flow down.
Netfilter now keeps direct-path dst references for hardware flowtables and
implements both callbacks, checking dst cookies and direct Ethernet
neighbours in each direction.

> diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
> index 4365859220e6a..1f3adf70f5987 100644
> --- a/net/netfilter/nf_flow_table_offload.c
> +++ b/net/netfilter/nf_flow_table_offload.c
> @@ -885,6 +885,62 @@ static int nf_flow_offload_alloc(const struct flow_offload_work *offload,

[ ... ]

> +static int nf_flow_offload_validate(unsigned long cookie)
> +{
> +	struct flow_offload *flow = nf_flow_offload_cookie_flow(cookie);
> +	unsigned int dir;
> +
> +	for (dir = 0; dir < FLOW_OFFLOAD_DIR_MAX; dir++) {
> +		struct flow_offload_tuple *tuple = &flow->tuplehash[dir].tuple;
> +		struct flow_offload_tuple *other = &flow->tuplehash[!dir].tuple;
> +		struct dst_entry *dst = tuple->dst_cache;
> +		struct neighbour *neigh;
> +		u8 mac[ETH_ALEN];
> +		bool valid;
> +
> +		if (!dst)
> +			return -EOPNOTSUPP;

[ ... ]

> +		if (dst->dev->ifindex != tuple->out.ifidx)
> +			return -EOPNOTSUPP;
> +		neigh = dst_neigh_lookup(dst, &other->src_v4);
> +		if (!neigh)
> +			return -ESTALE;

[Severity: Medium]
Can this lookup change the neighbour table? For IPv4, dst_neigh_lookup()
goes through ipv4_dst_neigh_lookup()->ip_neigh_gw4(), which creates an
entry when the noref lookup misses:

include/net/route.h:ip_neigh_gw4() {
    ...
	neigh = __ipv4_neigh_lookup_noref(dev, (__force u32)daddr);
	if (unlikely(!neigh)) {
		struct neigh_table *tbl = arp_table(dev_net(dev));

		neigh = __neigh_create(tbl, &daddr, dev, false);
	}
    ...
}

So validation can allocate a neighbour with GFP_ATOMIC, run forced GC
under tbl->lock, and insert a new NUD_NONE entry into the ARP table.

It also looks like two cases that are not provably stale end up returning
-ESTALE. The header documents the contract as:

    Return 0 for a valid path, -ESTALE for a demonstrably stale path,
    or -EOPNOTSUPP when validation is unavailable.

The first case is neighbour creation failing (-ENOBUFS at gc_thresh3, or
-ENOMEM). dst_neigh_lookup() turns the ERR_PTR into NULL, and the
!neigh branch above returns -ESTALE.

The second case is an entry that was garbage collected while the flow kept
forwarding. The software DIRECT path uses the cached out.h_dest and never
confirms the neighbour, so the entry can age out. Periodic GC can remove it
above gc_thresh1, and forced GC can remove it above gc_thresh2. The next
validate then creates a NUD_NONE entry, fails the NUD_VALID test below, and
returns -ESTALE, even though the next hop and MAC have not changed.

The consumer, fa_replace() in drivers/net/ethernet/broadcom/bcm-ns-fa.c
(added later in this series by "net: bgmac: add Northstar IPv4 TCP/UDP NAT
flowtable offload"), calls cls->invalidate() on -ESTALE. That runs
flow_offload_teardown() on a healthy flow.

A flow that the driver declined keeps being offered through
flow_offload_refresh(), roughly once per HZ. Under neighbour table pressure
this could keep tearing such flows down.

That driver's own fa_route_check() uses the lookup-only ipv4_neigh_lookup()
and returns -EOPNOTSUPP on a miss. Would a noref lookup under RCU, such as
__ipv4_neigh_lookup_noref() or __ipv6_neigh_lookup_noref(), returning
-EOPNOTSUPP on a miss, fit the documented contract better?

> +		neigh_ha_snapshot(mac, neigh, dst->dev);

[Severity: Low]
Should these dst->dev accesses use dst_dev_rcu()? This callback runs under
RCU while dst_dev_put() can concurrently republish the device:

net/core/dst.c:dst_dev_put() {
    ...
	rcu_assign_pointer(dst->dev_rcu, blackhole_netdev);
    ...
}

The ifindex check and neigh_ha_snapshot() each do a plain load of
dst->dev, and ipv4_dst_neigh_lookup() does a third load through
dst_dev_rcu(). KCSAN will report the plain loads, and the three loads can
see different net_devices within one validation pass.

There's no memory safety problem here. blackhole_netdev has addr_len set
to ETH_ALEN, so mac[] is fully written, and -ESTALE is the right answer for
a route that has moved to blackhole.

Would taking a single dev = dst_dev_rcu(dst) snapshot, or passing
neigh->dev to neigh_ha_snapshot(), avoid the race?

> +		valid = (READ_ONCE(neigh->nud_state) & NUD_VALID) &&
> +			ether_addr_equal(mac, tuple->out.h_dest);
> +		neigh_release(neigh);
> +		if (!valid)
> +			return -ESTALE;
> +	}
> +	return 0;
> +}

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116222519.1416501-1-florian.fainelli%40broadcom.com

  reply	other threads:[~2026-11-17 23:29 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 22:25 [PATCH net-next 0/9] net: bgmac: add Northstar IPv4 TCP/UDP NAT flowtable offload Florian Fainelli
2026-11-16 22:25 ` [PATCH net-next 1/9] net: ethernet: bgmac: validate RX length against the DMA packet capacity Florian Fainelli
2026-11-17 23:29   ` netdev-bot+sashiko
2026-11-17 23:43     ` Florian Fainelli
2026-11-16 22:25 ` [PATCH net-next 2/9] netfilter: flowtable: reject non-host IPv4 packets before lookup Florian Fainelli
2026-11-17 23:29   ` netdev-bot+sashiko
2026-11-16 22:25 ` [PATCH net-next 3/9] netfilter: flowtable: retain offload ownership until deletion completes Florian Fainelli
2026-11-17 23:29   ` netdev-bot+sashiko
2026-11-16 22:25 ` [PATCH net-next 4/9] dt-bindings: net: describe the Northstar flow accelerator Florian Fainelli
2026-11-17 23:29   ` netdev-bot+sashiko
2026-11-16 22:25 ` [PATCH net-next 5/9] net: dsa: add Broadcom FA metadata and IPv4 exception paths Florian Fainelli
2026-11-17 23:29   ` netdev-bot+sashiko
2026-11-16 22:25 ` [PATCH net-next 6/9] net: flow_offload: allow drivers to validate and invalidate cached paths Florian Fainelli
2026-11-17 23:29   ` netdev-bot+sashiko [this message]
2026-11-16 22:25 ` [PATCH net-next 7/9] net: bgmac: add Northstar IPv4 TCP/UDP NAT flowtable offload Florian Fainelli
2026-11-17 23:29   ` netdev-bot+sashiko
2026-11-16 22:25 ` [PATCH net-next 8/9] net: add KUnit coverage for FA and flowtable path validation Florian Fainelli
2026-11-17 23:29   ` netdev-bot+sashiko
2026-11-16 22:25 ` [PATCH net-next 9/9] docs: net: document Northstar FA setup and NAT qualification Florian Fainelli
2026-11-17 23:29   ` netdev-bot+sashiko
2026-11-16 22:38 ` [PATCH net-next 0/9] net: bgmac: add Northstar IPv4 TCP/UDP NAT flowtable offload netdev-bot+sinfo
2026-11-16 22:45   ` Florian Fainelli

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=179495816543.3136.12103952304400202953@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=coreteam@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@kernel.org \
    --cc=florian.fainelli@broadcom.com \
    --cc=fw@strlen.de \
    --cc=horms@kernel.org \
    --cc=jonas.gorski@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.org \
    --cc=phil@nwl.cc \
    --cc=rafal@milecki.pl \
    --cc=robh@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