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 8/9] net: add KUnit coverage for FA and flowtable path validation
Date: Tue, 17 Nov 2026 23:29:29 +0000 [thread overview]
Message-ID: <179495816919.3136.9689954625386670626@kernel.org> (raw)
In-Reply-To: <20261116222519.1416501-9-florian.fainelli@broadcom.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 3
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] Three bcm-ns-fa KUnit cases use plain slab memory as if it
were an MMIO register window: fa_test_tcp_control_readiness,…
- [Medium] nf_flow_test_gc_routes() sets NF_FLOW_HW and NF_FLOW_HW_DYING
on every flow, under the comment "Avoid queuing real DELETE/STATS work…
- [Low] In fa_test_rx_learning() (drivers/net/ethernet/broadcom/bcm-ns-
fa-test.c), the TCP sub-case sets `ip->protocol = IPPROTO_TCP;` (line…
- [Low] fa_test_nat_actions() has three negative assertions that do not
test what their comments say.
- [Low] fa_test_upper_device_rcu() registers two real Ethernet devices in
init_net with alloc_etherdev() and register_netdev().
--
net: add KUnit coverage for FA and flowtable path validation
This commit adds KUnit suites for the Northstar flow accelerator, the B53
FA exception guards and the Broadcom FA tagger. It also adds flowtable
tests for cached-route owner validation, plus a GC test that covers seven
route and xmit scenarios. The tests are compiled into their parent
translation units, and a combined .kunitconfig sits beside the FA backend.
> diff --git a/drivers/net/ethernet/broadcom/bcm-ns-fa-test.c b/drivers/net/ethernet/broadcom/bcm-ns-fa-test.c
> new file mode 100644
> index 0000000000000..59406f84809e7
> --- /dev/null
> +++ b/drivers/net/ethernet/broadcom/bcm-ns-fa-test.c
> @@ -0,0 +1,661 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/* Included in bcm-ns-fa.c to exercise private table formats and validation. */
> +#include <kunit/test.h>
> +#include <net/lwtunnel.h>
> +#include <net/nexthop.h>
> +#include <linux/rtnetlink.h>
> +
> +static const struct net_device_ops fa_test_netdev_ops;
[ ... ]
> + lower->netdev_ops = &fa_test_netdev_ops;
> + upper->netdev_ops = &fa_test_netdev_ops;
> + eth_hw_addr_random(lower);
> + eth_hw_addr_random(upper);
> + KUNIT_ASSERT_EQ(test, register_netdev(lower), 0);
> + KUNIT_ASSERT_EQ(test, register_netdev(upper), 0);
[Severity: Low]
This isn't a bug, but could these test devices get a minimal
ndo_start_xmit that just drops the skb?
fa_test_netdev_ops is an empty static struct, so its ndo_start_xmit is
NULL. In fa_test_upper_device_rcu(), both devices are registered in
init_net and show up as eth%d with carrier on while the test runs.
If something outside the test brings one of them up and transmits on it,
dev_hard_start_xmit() would call the NULL ndo_start_xmit. That could be a
network manager reacting to RTM_NEWLINK, or an AF_PACKET sender.
The window is short, and re-running the suite after boot needs root
through the KUnit debugfs run file. net/core/dev_addr_lists_test.c
already uses the same pattern, so this is only a hardening suggestion.
[ ... ]
> +static void fa_test_nat_actions(struct kunit *test)
> +{
> + struct fa_rule rule = { .direction = FA_DIR_UNSET, .l4proto = IPPROTO_UDP };
[ ... ]
> + KUNIT_ASSERT_EQ(test, fa_mangle(&rule, &act), 0);
> + KUNIT_EXPECT_EQ(test, rule.remap_port, (u16)0xabcd);
> + KUNIT_EXPECT_EQ(test, rule.action, (u8)3);
> + /* Opposite-side rewrites cannot share a hardware entry. */
> + act.mangle.mask = (__force u32)cpu_to_be32(0xffff0000);
> + KUNIT_EXPECT_EQ(test, fa_mangle(&rule, &act), -EOPNOTSUPP);
> + /* Partial IPv4 masks and arbitrary offsets must not be accepted. */
> + act.mangle.htype = FLOW_ACT_MANGLE_HDR_TYPE_IP4;
> + act.mangle.offset = offsetof(struct iphdr, daddr);
> + act.mangle.mask = 1;
> + KUNIT_EXPECT_EQ(test, fa_mangle(&rule, &act), -EOPNOTSUPP);
> + act.mangle.mask = 0;
> + act.mangle.offset = offsetof(struct iphdr, ttl);
> + KUNIT_EXPECT_EQ(test, fa_mangle(&rule, &act), -EOPNOTSUPP);
> +}
[Severity: Low]
Do these three negative checks test what their comments describe?
By this point rule.action already has FA_ACT_REMAP_IP | FA_ACT_REMAP_PORT
set and the direction is SNAT. fa_mangle() rejects with:
if (fa_direction(rule, dir) || (rule->action & FA_ACT_REMAP_IP))
return -EOPNOTSUPP;
...
if (fa_direction(rule, dir) || (rule->action & FA_ACT_REMAP_PORT))
return -EOPNOTSUPP;
The REMAP_PORT bit alone rejects the opposite-side UDP rewrite, so the
fa_direction() conflict check is never exercised. If the mask and offset
checks were removed from fa_mangle(), the REMAP_IP bit would still reject
both the partial-mask daddr case and the ttl offset case, and this test
would still pass.
Would running each negative case against a fresh rule exercise each of
those checks in fa_mangle() on its own?
[ ... ]
> + tag[2] = 1;
> + bcm_ns_fa_rx(fa, skb);
> + KUNIT_EXPECT_EQ(test, fa->learn_next, 1U);
> + tag[2] = 0;
> + ip->protocol = IPPROTO_TCP;
> + bcm_ns_fa_rx(fa, skb);
> + KUNIT_EXPECT_EQ(test, fa->learn_next, 1U);
[Severity: Low]
Should ip->check be recomputed here?
The other sub-cases in fa_test_rx_learning() refresh the checksum with
ip_fast_csum() after editing the header. The IPv4 header checksum covers
the protocol byte, so bcm_ns_fa_rx() drops this frame on the checksum
before it reaches the TCP branch:
total < ihl || total > skb->len - offset || skb_headlen(skb) < offset + ihl ||
ip_compute_csum(ip, ihl))
return;
if (ip->protocol == IPPROTO_TCP &&
fa_receive_tcp_control(fa, ip, total, skb_headlen(skb) - offset, tag[3] & 0x1f))
The learn_next == 1 expectation therefore passes because of the checksum
guard. fa_receive_tcp_control() and the TCP learning path never run in
this sub-case.
[ ... ]
> +static void fa_test_tcp_control_readiness(struct kunit *test)
> +{
> + struct bcm_ns_fa *fa = kunit_kzalloc(test, sizeof(*fa), GFP_KERNEL);
> +
> + KUNIT_ASSERT_NOT_NULL(test, fa);
> + fa->regs = (void __iomem *)kunit_kzalloc(test, 0xc0, GFP_KERNEL);
[Severity: Medium]
Can these fake register windows work on the default KUnit architecture?
fa_test_tcp_control_readiness(), fa_test_lookup_gate_preserves_tags() and
fa_test_invalidation() all point fa->regs at kunit_kzalloc() memory. They
then call writel()/readl() on it, either directly or through
fa_lookup_update():
writel(enabled ? ETH_P_IP | ETH_P_IPV6 << 16 : 0, fa->regs + FA_L2_ETHERTYPE);
readl(fa->regs + FA_L2_ETHERTYPE);
kunit.py defaults to ARCH=um and merges arch_uml.config, which sets
CONFIG_KUNIT_UML_PCI=y. That selects UML_PCI, then UML_IOMEM_EMULATION,
then INDIRECT_IOMEM, and INDIRECT_IOMEM_FALLBACK stays off. The raw
accessors then go through lib/logic_iomem.c, where get_area() does:
if (WARN_ON((a & IOREMAP_MASK) != IOREMAP_BIAS))
return NULL;
The fallback read then WARNs again and returns ~0. Writes WARN and are
dropped.
On UML, this would have these effects:
- fa_test_lookup_gate_preserves_tags() reads 0xffffffff for
FA_L2_ETHERTYPE, FA_CTL and FA_BRCM_HDR, so its expectations fail.
- In fa_test_invalidation(), lookup_stopped = !readl(...) evaluates to
false, so that check fails.
- fa_test_tcp_control_readiness() emits WARN splats that taint the
kernel.
The new drivers/net/ethernet/broadcom/.kunitconfig enables COMPILE_TEST
and does not restrict the architecture. So running kunit.py with
--kunitconfig drivers/net/ethernet/broadcom seems to build exactly this
configuration.
Should the MMIO-dependent cases be limited to architectures with direct
MMIO, or should the lookup gate be observed some other way? Also, the
BCM_NS_FA_KUNIT_TEST help text says the tests "do not simulate table
I/O", which doesn't quite match these cases.
[ ... ]
> diff --git a/net/netfilter/nf_flow_table_core_test.c b/net/netfilter/nf_flow_table_core_test.c
> index 378a1c60b50b9..5c7645239d2e4 100644
> --- a/net/netfilter/nf_flow_table_core_test.c
> +++ b/net/netfilter/nf_flow_table_core_test.c
> @@ -72,9 +72,94 @@ static void nf_flow_test_hardware_retirement(struct kunit *test)
[ ... ]
> + for (i = 0; i < ARRAY_SIZE(cases); i++) {
> + struct nf_flowtable table = { .type = &type };
[ ... ]
> + flow->ct = ct;
> + flow->timeout = nf_flowtable_time_stamp + NF_FLOW_TIMEOUT;
> + /* Avoid queuing real DELETE/STATS work from this private GC test. */
> + set_bit(NF_FLOW_HW, &flow->flags);
> + set_bit(NF_FLOW_HW_DYING, &flow->flags);
> + set_bit(IPS_OFFLOAD_BIT, &ct->status);
[ ... ]
> + nf_flow_offload_gc_step(&table, flow, NULL);
> + KUNIT_EXPECT_EQ_MSG(test, test_bit(NF_FLOW_TEARDOWN, &flow->flags),
> + cases[i].check, "GC path: %s", cases[i].name);
> + flow_offload_route_release(flow);
[Severity: Medium]
Do these flags actually prevent STATS work from being queued?
In the "software direct" and "validation only" cases (check == false),
nf_flow_offload_gc_step() skips the teardown block and reaches:
} else if (test_bit(NF_FLOW_HW, &flow->flags)) {
nf_flow_offload_stats(flow_table, flow);
}
That branch does not look at NF_FLOW_HW_DYING. Inside
nf_flow_offload_stats(), only this timing check stops a work item from
being queued:
delta = nf_flow_timeout_delta(flow->timeout);
if ((delta >= (9 * flow_offload_get_timeout(flow)) / 10))
return;
For this ICMP ct the timeout is NF_FLOW_TIMEOUT (30 * HZ). If the test
thread stalls for more than about 3 seconds between setting flow->timeout
and the GC call, nf_flow_offload_work_alloc() will record:
- offload->flowtable = &table, which is the stack variable above
- offload->flow = flow, which is kunit-managed memory
This could happen on a loaded QEMU or UML host, or with KASAN enabled.
flow_offload_queue_work() then reads table.net, which is NULL here, and
queues the work on nf_flow_offload_stats_wq.
Nothing flushes or cancels that work. Could flow_offload_work_handler()
later run against a dead stack frame and freed kunit memory?
Any of these would avoid it:
- pre-set NF_FLOW_PENDING so nf_flow_offload_work_alloc() bails out
- leave NF_FLOW_HW clear for the non-hardware cases
- flush nf_flow_offload_stats_wq before the objects go out of scope
Separately, NF_FLOW_HW is set for every scenario, so the GC step handles
the "software direct" case as a hardware flow. Does this still cover the
"ordinary direct software forwarding" scenario that the commit message
describes?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116222519.1416501-1-florian.fainelli%40broadcom.com
next prev parent 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
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 [this message]
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=179495816919.3136.9689954625386670626@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