net: bgmac: add Northstar IPv4 TCP/UDP NAT flowtable offload
Subsystems (9)
Florian Fainelli
maintainercover net: bgmac: add Northstar IPv4 TCP/UDP NAT flowtable offload
This patch series adds support for the Broadcom Northstar IPv4 TCP/UDP NAT flowtable hardware called Flow Accelerator (FA). There is a second generation called FA+/FA2 which will be added on top later on since it builds upon the custom Broadcom tag.
Florian Fainelli (9):
net: ethernet: bgmac: validate RX length against the DMA packet
capacity
netfilter: flowtable: reject non-host IPv4 packets before lookup
netfilter: flowtable: retain offload ownership until deletion
completes
dt-bindings: net: describe the Northstar flow accelerator
net: dsa: add Broadcom FA metadata and IPv4 exception paths
net: flow_offload: allow drivers to validate and invalidate cached
paths
net: bgmac: add Northstar IPv4 TCP/UDP NAT flowtable offload
net: add KUnit coverage for FA and flowtable path validation
docs: net: document Northstar FA setup and NAT qualification
.../bindings/net/brcm,bcm4708-fa.yaml | 45 + .../bindings/net/brcm,bcm5301x-gmac.yaml | 27 + .../ethernet/broadcom/bcm-ns-fa.rst | 507 +++++ .../device_drivers/ethernet/index.rst | 1 + Documentation/networking/nf_flowtable.rst | 13 + MAINTAINERS | 8 + drivers/net/dsa/b53/Kconfig | 12 + drivers/net/dsa/b53/b53_common.c | 427 +++- drivers/net/dsa/b53/b53_fa_test.c | 102 + drivers/net/dsa/b53/b53_priv.h | 6 + drivers/net/dsa/b53/b53_regs.h | 39 + drivers/net/ethernet/broadcom/.kunitconfig | 21 + drivers/net/ethernet/broadcom/Kconfig | 35 + drivers/net/ethernet/broadcom/Makefile | 1 + .../net/ethernet/broadcom/bcm-ns-fa-test.c | 661 ++++++ drivers/net/ethernet/broadcom/bcm-ns-fa.c | 1901 +++++++++++++++++ drivers/net/ethernet/broadcom/bcm-ns-fa.h | 30 + drivers/net/ethernet/broadcom/bgmac-bcma.c | 5 + drivers/net/ethernet/broadcom/bgmac.c | 41 +- drivers/net/ethernet/broadcom/bgmac.h | 2 + include/linux/dsa/brcm.h | 19 + include/net/dsa.h | 2 + include/net/flow_offload.h | 12 + include/net/netfilter/nf_flow_table.h | 8 +- net/dsa/Kconfig | 20 + net/dsa/tag_brcm.c | 120 +- net/dsa/tag_brcm_test.c | 199 ++ net/netfilter/Kconfig | 10 + net/netfilter/nf_flow_table_core.c | 21 +- net/netfilter/nf_flow_table_core_test.c | 171 ++ net/netfilter/nf_flow_table_ip.c | 4 + net/netfilter/nf_flow_table_offload.c | 62 + net/netfilter/nf_flow_table_offload_test.c | 129 ++ net/netfilter/nft_flow_offload.c | 6 +- .../kunit/configs/nf_flow_table.config | 9 + 35 files changed, 4651 insertions(+), 25 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml create mode 100644 Documentation/devicetree/bindings/net/brcm,bcm5301x-gmac.yaml create mode 100644 Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst create mode 100644 drivers/net/dsa/b53/b53_fa_test.c create mode 100644 drivers/net/ethernet/broadcom/.kunitconfig create mode 100644 drivers/net/ethernet/broadcom/bcm-ns-fa-test.c create mode 100644 drivers/net/ethernet/broadcom/bcm-ns-fa.c create mode 100644 drivers/net/ethernet/broadcom/bcm-ns-fa.h create mode 100644 net/dsa/tag_brcm_test.c create mode 100644 net/netfilter/nf_flow_table_core_test.c create mode 100644 net/netfilter/nf_flow_table_offload_test.c create mode 100644 tools/testing/kunit/configs/nf_flow_table.config
Signature · 1 line
2.53.0
Florian Fainelli
maintainerPATCH 1/9 net: ethernet: bgmac: validate RX length against the DMA packet capacity
BGMAC_RX_ALLOC_SIZE includes skb_shared_info and alignment space beyond the DMA receive buffer. An invalid completion length can pass that check and reach skb_put() with more data than the skb tailroom permits.
Limit received frames to BGMAC_RX_MAX_FRAME_SIZE and reject lengths too short for the FCS subtraction. Keep invalid DMA completions visible through rate-limited diagnostics and RX error counters.
--- drivers/net/ethernet/broadcom/bgmac.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/ethernet/broadcom/bgmac.c +7 -3
@@ -457,10 +457,14 @@ static int bgmac_dma_rx_read(struct bgmac *bgmac, struct bgmac_dma_ring *ring,break ; } -if (len >BGMAC_RX_ALLOC_SIZE ) { +/* The allocation also contains headroom and skb_shared_info; +* only the mapped packet area may be supplied by the DMA. +*/ +if (unlikely (len >BGMAC_RX_MAX_FRAME_SIZE || len <ETH_FCS_LEN )) {if (net_ratelimit ()) -netdev_err (bgmac->net_dev,"Found oversized packet at slot %d, DMA issue!\n" , - ring->start); +netdev_err (bgmac->net_dev, +"Invalid RX length %u at slot %d (flags %#x)\n" , + len, ring->start, flags);put_page (virt_to_head_page (buf)); bgmac->net_dev->stats.rx_length_errors++; bgmac->net_dev->stats.rx_errors++;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net-next 1/9] net: ethernet: bgmac: validate RX length against the DMA packet capacity
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 (1) · 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] In bgmac_dma_rx_read() (drivers/net/ethernet/broadcom/bgmac.c:463), the patch now treats…
- [Low] The commit message is accurate but leaves out the user-visible impact of the bugs this patch fixes in bgmac_dma_rx_read().
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is High severity, and the new check does not close it.
--
net: ethernet: bgmac: validate RX length against the DMA packet capacity
This patch changes the upper bound of the RX length check in bgmac_dma_rx_read() from BGMAC_RX_ALLOC_SIZE to BGMAC_RX_MAX_FRAME_SIZE. It also rejects lengths shorter than ETH_FCS_LEN. Invalid lengths are reported through a rate-limited netdev_err() and counted in rx_length_errors and rx_errors.
Quoted 6 lines
BGMAC_RX_ALLOC_SIZEincludesskb_shared_infoand alignment space beyond the DMA receive buffer. An invalid completion length can pass that check and reachskb_put()with more data than the skb tailroom permits.Limit received frames to
BGMAC_RX_MAX_FRAME_SIZEand reject lengths too short for the FCS subtraction.
[Severity: Low]
This isn't a bug, but could the commit message state the user-visible impact of what is being fixed?
For len < ETH_FCS_LEN, the u16 subtraction "len -= ETH_FCS_LEN" wraps to 65532..65535. The skb_put() that follows then ends in skb_over_panic() and BUG().
Lengths between the skb tailroom limit (about 1602 bytes with NET_SKB_PAD=64) and BGMAC_RX_ALLOC_SIZE also reach skb_over_panic().
Lengths from 1537 up to that tailroom limit got through skb_put(). They delivered bytes past the 1536-byte DMA-mapped frame area. Those bytes come from the non-zeroed netdev_alloc_frag() buffer, and the device never wrote them.
The message names the tailroom and FCS cases. It does not say that they end in a kernel BUG(), and it does not mention the stale data delivery.
Quoted 9 lines
drivers/net/ethernet/broadcom/bgmac.c +0
-1@@ -457,10 +457,14 @@ static int bgmac_dma_rx_read(struct bgmac *bgmac, struct bgmac_dma_ring *ring,break ; } -if (len >BGMAC_RX_ALLOC_SIZE ) {
drivers/net/ethernet/broadcom/bgmac.c static int bgmac_dma_rx_read(struct bgmac *bgmac, struct bgmac_dma_ring *ring, · line 467
Quoted 10 lines
drivers/net/ethernet/broadcom/bgmac.c +7
-2+/* The allocation also contains headroom and skb_shared_info; +* only the mapped packet area may be supplied by the DMA. +*/ +if (unlikely (len >BGMAC_RX_MAX_FRAME_SIZE || len <ETH_FCS_LEN )) {if (net_ratelimit ()) -netdev_err (bgmac->net_dev,"Found oversized packet at slot %d, DMA issue!\n" , - ring->start); +netdev_err (bgmac->net_dev, +"Invalid RX length %u at slot %d (flags %#x)\n" , + len, ring->start, flags);
[Severity: Medium]
Does this new bound drop frames that the driver itself tells the MAC to accept, and whose MTU it advertises?
bgmac_chip_init() sets the MAC max frame length to 1550:
bgmac_umac_write(bgmac, UMAC_MAX_FRAME_LEN, 32 + ETHER_MAX_LEN);
bgmac_change_mtu() sets it to 32 + mtu, which can be as large as 1564:
bgmac_umac_write(bgmac, UMAC_MAX_FRAME_LEN, 32 + mtu);
bgmac_enet_probe() sets max_mtu without subtracting ETH_HLEN or VLAN_HLEN:
net_dev->max_mtu = BGMAC_RX_MAX_FRAME_SIZE - ETH_FCS_LEN;
The driver accepts any MTU from 1519 to 1532. At those MTUs a full-sized frame can be up to 14 + 1532 + 4 = 1550 bytes. Such a frame is now always dropped, logged as an invalid RX length, and counted in rx_length_errors.
Before this patch these frames were delivered with stale tail bytes, so dropping them is safer. However, the new comment and the commit message assume that len > BGMAC_RX_MAX_FRAME_SIZE can only come from a DMA error.
Should max_mtu and/or UMAC_MAX_FRAME_LEN also be clamped to the per-descriptor capacity? One option for max_mtu is BGMAC_RX_MAX_FRAME_SIZE - ETH_HLEN - ETH_FCS_LEN, possibly minus VLAN_HLEN. Could the commit message also mention that these frames are now dropped?
[Severity: High]
This is a pre-existing issue, and the new check does not appear to close it. Can a remote sender get stale buffer contents delivered as a received frame through an overflow-continue slot?
bgmac_dma_rx_ring_enable() turns on overflow-continue:
ctl |= BGMAC_DMA_RX_OVERFLOW_CONT;
Each descriptor holds only BGMAC_RX_BUF_SIZE, which is 30 + 1536 bytes. The MAC accepts frames up to 1550 bytes by default, and up to 1564 bytes after an MTU change.
With overflow-continue, the DMA64 engine writes the rest of an oversized frame as raw data at offset 0 of the next descriptor's buffer. That buffer has no RX status header. brcmsmac's dma_rx() drives the same engine with the same 0x400 bit, and it handles these continuation buffers explicitly:
resid = len - (di->rxbufsize - di->rxoffset);
...
while ((resid > 0) && (p = _dma_getnextrxp(di, false))) {
pkt_len = min_t(uint, resid, di->rxbufsize);bgmac_dma_rx_read() treats every slot as an independent frame. The new check drops the first slot when len > 1536. The next slot is then parsed as a fresh frame:
len = le16_to_cpu(rx->len); flags = le16_to_cpu(rx->flags);
In that slot, rx->len and rx->flags are frame bytes 1536..1539, which the sender controls. A value in [4, 1536] passes both the poison check and the new bound. build_skb() and skb_put() then deliver up to about 1532 bytes starting at buffer offset 30.
DMA wrote only the first (frame_len - 1536) bytes of that buffer in this round, which is at most 28 bytes. The rest is stale netdev_alloc_frag() memory, because bgmac_dma_rx_skb_for_slot() only writes the poison header. The resulting skb goes to eth_type_trans() and napi_gro_receive(). From there it can be processed locally, bridged, or forwarded.
The old BGMAC_RX_ALLOC_SIZE check let through an even wider range of lengths. This patch narrows that range but does not remove it.
Could multi-descriptor frames be tracked so the continuation slots are dropped too? Alternatively, could UMAC_MAX_FRAME_LEN and max_mtu be capped at the single-buffer capacity?
Quoted 3 lines
drivers/net/ethernet/broadcom/bgmac.c +0
-0put_page (virt_to_head_page (buf)); bgmac->net_dev->stats.rx_length_errors++; bgmac->net_dev->stats.rx_errors++;
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116222519.1416501-1-florian.fainelli%40broadcom.com
Florian Fainelli
maintainerRe: [PATCH net-next 1/9] net: ethernet: bgmac: validate RX length against the DMA packet capacity
Quoted 146 lines · On 11/17/26 15:29, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 (1) · 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] In
bgmac_dma_rx_read()(drivers/net/ethernet/broadcom/bgmac.c:463), the patch now treats…
- [Low] The commit message is accurate but leaves out the user-visible impact of the bugs this patch fixes inbgmac_dma_rx_read().Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is High severity, and the new check does not close it.--
net: ethernet: bgmac: validate RX length against the DMA packet capacity
This patch changes the upper bound of the RX length check in
bgmac_dma_rx_read()fromBGMAC_RX_ALLOC_SIZEtoBGMAC_RX_MAX_FRAME_SIZE. It also rejects lengths shorter thanETH_FCS_LEN. Invalid lengths are reported through a rate-limitednetdev_err()and counted inrx_length_errorsandrx_errors.Quoted 6 lines
BGMAC_RX_ALLOC_SIZEincludesskb_shared_infoand alignment space beyond the DMA receive buffer. An invalid completion length can pass that check and reachskb_put()with more data than the skb tailroom permits.Limit received frames to
BGMAC_RX_MAX_FRAME_SIZEand reject lengths too short for the FCS subtraction.[Severity: Low]
This isn't a bug, but could the commit message state the user-visible impact of what is being fixed?For len <
ETH_FCS_LEN, the u16 subtraction "len -=ETH_FCS_LEN" wraps to 65532..65535. Theskb_put()that follows then ends inskb_over_panic()andBUG().Lengths between the skb tailroom limit (about 1602 bytes with NET_SKB_PAD=64) and
BGMAC_RX_ALLOC_SIZEalso reachskb_over_panic().Lengths from 1537 up to that tailroom limit got through
skb_put(). They delivered bytes past the 1536-byte DMA-mapped frame area. Those bytes come from the non-zeroednetdev_alloc_frag()buffer, and the device never wrote them.The message names the tailroom and FCS cases. It does not say that they end in a kernel
BUG(), and it does not mention the stale data delivery.Quoted 9 lines
drivers/net/ethernet/broadcom/bgmac.c +0
-1@@ -457,10 +457,14 @@ static int bgmac_dma_rx_read(struct bgmac *bgmac, struct bgmac_dma_ring *ring,break ; } -if (len >BGMAC_RX_ALLOC_SIZE ) {drivers/net/ethernet/broadcom/bgmac.c static int bgmac_dma_rx_read(struct bgmac *bgmac, struct bgmac_dma_ring *ring, · line 467
Quoted 10 lines
drivers/net/ethernet/broadcom/bgmac.c +7
-2+/* The allocation also contains headroom and skb_shared_info; +* only the mapped packet area may be supplied by the DMA. +*/ +if (unlikely (len >BGMAC_RX_MAX_FRAME_SIZE || len <ETH_FCS_LEN )) {if (net_ratelimit ()) -netdev_err (bgmac->net_dev,"Found oversized packet at slot %d, DMA issue!\n" , - ring->start); +netdev_err (bgmac->net_dev, +"Invalid RX length %u at slot %d (flags %#x)\n" , + len, ring->start, flags);[Severity: Medium]
Does this new bound drop frames that the driver itself tells the MAC to accept, and whose MTU it advertises?
bgmac_chip_init()sets the MAC max frame length to 1550:bgmac_umac_write(bgmac, UMAC_MAX_FRAME_LEN, 32 + ETHER_MAX_LEN);
bgmac_change_mtu()sets it to 32 + mtu, which can be as large as 1564:bgmac_umac_write(bgmac, UMAC_MAX_FRAME_LEN, 32 + mtu);
bgmac_enet_probe()setsmax_mtuwithout subtractingETH_HLENorVLAN_HLEN:net_dev->max_mtu = BGMAC_RX_MAX_FRAME_SIZE - ETH_FCS_LEN;The driver accepts any MTU from 1519 to 1532. At those MTUs a full-sized frame can be up to 14 + 1532 + 4 = 1550 bytes. Such a frame is now always dropped, logged as an invalid RX length, and counted in
rx_length_errors.Before this patch these frames were delivered with stale tail bytes, so dropping them is safer. However, the new comment and the commit message assume that len >
BGMAC_RX_MAX_FRAME_SIZEcan only come from a DMA error.Should
max_mtuand/orUMAC_MAX_FRAME_LENalso be clamped to the per-descriptor capacity? One option formax_mtuisBGMAC_RX_MAX_FRAME_SIZE-ETH_HLEN-ETH_FCS_LEN, possibly minusVLAN_HLEN. Could the commit message also mention that these frames are now dropped?[Severity: High]
This is a pre-existing issue, and the new check does not appear to close it. Can a remote sender get stale buffer contents delivered as a received frame through an overflow-continue slot?
bgmac_dma_rx_ring_enable()turns on overflow-continue:ctl |= BGMAC_DMA_RX_OVERFLOW_CONT;Each descriptor holds only
BGMAC_RX_BUF_SIZE, which is 30 + 1536 bytes. The MAC accepts frames up to 1550 bytes by default, and up to 1564 bytes after an MTU change.With overflow-continue, the DMA64 engine writes the rest of an oversized frame as raw data at offset 0 of the next descriptor's buffer. That buffer has no RX status header. brcmsmac's
dma_rx()drives the same engine with the same0x400bit, and it handles these continuation buffers explicitly:resid = len - (di->rxbufsize - di->rxoffset); ... while ((resid > 0) && (p = _dma_getnextrxp(di, false))) { pkt_len = min_t(uint, resid, di->rxbufsize);
bgmac_dma_rx_read()treats every slot as an independent frame. The new check drops the first slot when len > 1536. The next slot is then parsed as a fresh frame:len = le16_to_cpu(rx->len); flags = le16_to_cpu(rx->flags);In that slot,
rx->lenandrx->flagsare frame bytes 1536..1539, which the sender controls. A value in [4, 1536] passes both the poison check and the new bound.build_skb()andskb_put()then deliver up to about 1532 bytes starting at buffer offset 30.DMA wrote only the first (
frame_len- 1536) bytes of that buffer in this round, which is at most 28 bytes. The rest is stalenetdev_alloc_frag()memory, becausebgmac_dma_rx_skb_for_slot()only writes the poison header. The resulting skb goes toeth_type_trans()andnapi_gro_receive(). From there it can be processed locally, bridged, or forwarded.
Quoted 11 lines
The old
BGMAC_RX_ALLOC_SIZEcheck let through an even wider range of lengths. This patch narrows that range but does not remove it.Could multi-descriptor frames be tracked so the continuation slots are dropped too? Alternatively, could
UMAC_MAX_FRAME_LENandmax_mtube capped at the single-buffer capacity?Quoted 3 lines
drivers/net/ethernet/broadcom/bgmac.c +0
-0put_page (virt_to_head_page (buf)); bgmac->net_dev->stats.rx_length_errors++; bgmac->net_dev->stats.rx_errors++;
[Medium] RX bound vs. MAC max frame length / max_mtu
Valid. The driver programmed UMAC_MAX_FRAME_LEN to 32 + ETHER_MAX_LEN (or 32 + mtu), and max_mtu ignored ETH_HLEN, so the MAC could accept frames larger than one RX descriptor can hold, which the new check then drops. In v2, UMAC_MAX_FRAME_LEN is clamped to BGMAC_RX_MAX_FRAME_SIZE and max_mtu becomes BGMAC_RX_MAX_FRAME_SIZE - ETH_HLEN - VLAN_HLEN -ETH_FCS_LEN (1514). MTUs 1515..1532 are no longer accepted; frames of
that size were already delivered with stale tail bytes. The commit
message now says so.
[High, pre-existing] overflow-continue continuation slots
The analysis is right: with BGMAC_DMA_RX_OVERFLOW_CONT, the tail of an
oversized frame lands at offset 0 of the next descriptor, which has no RX header, and was previously parsed as a new frame. Rather than tracking multi-descriptor frames, v2 caps the MAC maximum frame length at the single-buffer capacity (the clamp above), so oversized frames are dropped by the MAC and never spill into a following descriptor.
[Low] commit message
Fixed in v2: it now describes the skb_over_panic()/BUG() cases (len < ETH_FCS_LEN and len above the tailroom) and the delivery of uninitialized netdev_alloc_frag() bytes.
pw-bot: cr
Signature · 1 line
Florian
Florian Fainelli
maintainerPATCH 2/9 netfilter: flowtable: reject non-host IPv4 packets before lookup
In reply to Florian FainelliThe IPv4 forwarding path rejects frames whose packet type is not PACKET_HOST, but an installed flowtable tuple bypasses that check. A packet addressed to an unrelated, broadcast or multicast destination MAC can therefore be forwarded if its IPv4 transport tuple matches a flow.
Return to the normal stack before the flow lookup for non-host packets. This preserves the IPv4 input path's forwarding decision.
Reproduced on BCM53012 using an active UDP NAT tuple: classic forwarding dropped the unrelated unicast destination MAC while software flowtable forwarding transmitted it. Boundary tests cover TCP/UDP, both NAT initiators and unicast, broadcast and multicast MACs.
Implementation, tests and changelog prepared with OpenAI Codex assistance.
--- net/netfilter/nf_flow_table_ip.c | 4 ++++ 1 file changed, 4 insertions(+)
net/netfilter/nf_flow_table_ip.c +4 -0
@@ -911,6 +911,10 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, };int ret; +/* The ingress hook runs before IPv4 rejects non-host Ethernet frames. */ +if (unlikely (skb->pkt_type !=PACKET_HOST )) +return NF_ACCEPT ; +if (!nf_flow_skb_encap_protocol (&ctx, skb))return NF_ACCEPT ;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net-next 2/9] netfilter: flowtable: reject non-host IPv4 packets before lookup
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] netfilter: flowtable: pkt_type check in nf_flow_offload_ip_hook() breaks bridge and VLAN offload --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] netfilter: flowtable: pkt_type check in nf_flow_offload_ip_hook() breaks bridge and VLAN offload
--
commit 2c508624181706744cfb38cdb730adaefd3aea13
Author: Florian Fainelli <[email protected]>
netfilter: flowtable: reject non-host IPv4 packets before lookup
This commit returns NF_ACCEPT before the flowtable lookup in nf_flow_offload_ip_hook() when skb->pkt_type is not PACKET_HOST.
net/netfilter/nf_flow_table_ip.c nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, · line 916
Quoted 11 lines
net/netfilter/nf_flow_table_ip.c +3
-0@@ -911,6 +911,10 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, };int ret; +/* The ingress hook runs before IPv4 rejects non-host Ethernet frames. */ +if (unlikely (skb->pkt_type !=PACKET_HOST )) +return NF_ACCEPT ;
[Severity: High]
Does this break software flowtable offload for bridged and VLAN interfaces whose MAC address differs from the underlying physical port's MAC?
When a flow is routed over a bridge or VLAN, nft_dev_path_info() binds the flowtable ingress hook to the underlying physical port. Frames addressed to the bridge or VLAN MAC arrive on that port with skb->pkt_type set to PACKET_OTHERHOST by eth_skb_pkt_type().
In __netif_receive_skb_core(), nf_ingress() runs before vlan_do_receive() and br_handle_frame() promote skb->pkt_type from PACKET_OTHERHOST to PACKET_HOST:
net/core/dev.c:__netif_receive_skb_core() {
...
if (nf_ingress(skb, &pt_prev, &ret, orig_dev) < 0)
goto out;
...
if (skb_vlan_tag_present(skb)) {
...
if (vlan_do_receive(&skb))
goto another_round;
...
}
rx_handler = rcu_dereference(skb->dev->rx_handler);
}Because skb->pkt_type is still PACKET_OTHERHOST when nf_flow_offload_ip_hook() runs, every packet on these flows bypasses the flowtable and falls back to the slow path.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH net-next 2/9] netfilter: flowtable: reject non-host IPv4 packets before lookup
In reply to Florian FainelliThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 2 · Medium: 0 · 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).
- [High] The new early return in nf_flow_offload_ip_hook() (net/netfilter/nf_flow_table_ip.c:915) checks skb->pkt_type at netdev…
- [High] The fix only covers IPv4.
- [Low] The commit trailer reads 'Signed-off-by: FLorian Fainelli <[email protected]>', but the author is 'Florian Fainelli'…
--
netfilter: flowtable: reject non-host IPv4 packets before lookup
This commit makes nf_flow_offload_ip_hook() return early when pkt_type is not PACKET_HOST. Those packets then go to the normal IPv4 stack before the flowtable lookup. The goal is to apply the same PACKET_HOST check that the classic IPv4 forwarding path uses.
Quoted 3 lines
Fixes 97add9f0d66d ("netfilter: flow table support for IPv4")Signed-off-by FLorian Fainelli <[email protected]>
[Severity: Low]
This isn't a bug, but the Signed-off-by name has a typo ("FLorian") and does not match the author name ("Florian Fainelli"). There is also an extra blank line between the Fixes: tag and the Signed-off-by: tag.
net/netfilter/nf_flow_table_ip.c nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, · line 916
Quoted 11 lines
net/netfilter/nf_flow_table_ip.c +3
-0@@ -911,6 +911,10 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, };int ret; +/* The ingress hook runs before IPv4 rejects non-host Ethernet frames. */ +if (unlikely (skb->pkt_type !=PACKET_HOST )) +return NF_ACCEPT ;
[Severity: High]
Could this turn off the software fast path for flows that pass through a bridge or VLAN upper device?
This hook runs at netdev ingress on the lower device. At that point pkt_type still holds what eth_type_trans() set by comparing h_dest with the lower device's own MAC. In __netif_receive_skb_core(), nf_ingress() runs before both places that reclassify the frame:
__netif_receive_skb_core()
nf_ingress() <- nf_flow_offload_ip_hook() runs here
vlan_do_receive()
rx_handler() <- br_handle_frame()
net/8021q/vlan_core.c:vlan_do_receive() {
...
if (unlikely(skb->pkt_type == PACKET_OTHERHOST)) {
/* ... */
if (ether_addr_equal_64bits(eth_hdr(skb)->h_dest, vlan_dev->dev_addr))
skb->pkt_type = PACKET_HOST;
}
...
}net/bridge/br_input.c:br_handle_frame() {
...
if (ether_addr_equal(p->br->dev->dev_addr, dest))
skb->pkt_type = PACKET_HOST;
...
}The flowtable supports DEV_PATH_BRIDGE and DEV_PATH_VLAN paths. nft_dev_path_info() puts the upper device's dev_addr in h_source, but the ingress ifindex is the lower port. Hosts therefore send routed traffic to the bridge or VLAN MAC.
Two setups hit this:
- A bridge port whose MAC differs from the bridge MAC. This is common in a multi-port bridge, because the bridge takes one port's MAC.
- A VLAN device with its own MAC.
In both cases, every packet of an offloaded flow would be PACKET_OTHERHOST at this hook. It would return NF_ACCEPT before nf_flow_offload_lookup(). The IPv4 stack later sees PACKET_HOST and forwards these packets.
Given that, does the patch keep "the IPv4 input path's forwarding decision", as the commit message says? Would it work better to compare h_dest with the address the flow expects (for example after the tuple lookup) rather than test the lower device's raw pkt_type?
net/netfilter/nf_flow_table_ip.c nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, · line 920
Quoted 4 lines
net/netfilter/nf_flow_table_ip.c +1
-0+if (!nf_flow_skb_encap_protocol (&ctx, skb))return NF_ACCEPT ;
[Severity: High]
Is the same bypass still open for IPv6? In the same file, nf_flow_offload_ipv6_hook() has no pkt_type check. It goes straight to the lookup, forward and nf_flow_queue_xmit6() steps:
net/netfilter/nf_flow_table_ip.c:nf_flow_offload_ipv6_hook() {
...
if (!nf_flow_skb_encap_protocol(&ctx, skb))
return NF_ACCEPT;
if (unlikely(ctx.ether_type != htons(ETH_P_IPV6)))
return NF_ACCEPT;
tuplehash = nf_flow_offload_ipv6_lookup(&ctx, flow_table, skb);
...
}Classic IPv6 forwarding drops these frames:
net/ipv6/ip6_output.c:ip6_forward() {
...
if (skb->pkt_type != PACKET_HOST)
goto drop;
...
}nf_flow_offload_inet_hook() sends ETH_P_IPV6 to the unpatched hook. With this patch, an inet flowtable would reject non-host frames for IPv4. For IPv6 it would still forward frames sent to an unrelated unicast, broadcast or multicast MAC, as long as the 5-tuple matches an installed flow.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116222519.1416501-1-florian.fainelli%40broadcom.com
Florian Fainelli
maintainerRe: [PATCH net-next 2/9] netfilter: flowtable: reject non-host IPv4 packets before lookup
Quoted 129 lines · On 11/17/26 15:29, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 2 · Medium: 0 · 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).
- [High] The new early return in
nf_flow_offload_ip_hook()(net/netfilter/nf_flow_table_ip.c:915) checksskb->pkt_typeat netdev…
- [High] The fix only covers IPv4.
- [Low] The commit trailer reads 'Signed-off-by: FLorian Fainelli <[email protected]>', but the author is 'Florian Fainelli'…--
netfilter: flowtable: reject non-host IPv4 packets before lookup
This commit makes
nf_flow_offload_ip_hook()return early whenpkt_typeis notPACKET_HOST. Those packets then go to the normal IPv4 stack before the flowtable lookup. The goal is to apply the samePACKET_HOSTcheck that the classic IPv4 forwarding path uses.Quoted 3 lines
Fixes 97add9f0d66d ("netfilter: flow table support for IPv4")Signed-off-by FLorian Fainelli <[email protected]>[Severity: Low]
This isn't a bug, but the Signed-off-by name has a typo ("FLorian") and does not match the author name ("Florian Fainelli"). There is also an extra blank line between the Fixes: tag and the Signed-off-by: tag.net/netfilter/nf_flow_table_ip.c nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, · line 916
Quoted 11 lines
net/netfilter/nf_flow_table_ip.c +3
-0@@ -911,6 +911,10 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, };int ret; +/* The ingress hook runs before IPv4 rejects non-host Ethernet frames. */ +if (unlikely (skb->pkt_type !=PACKET_HOST )) +return NF_ACCEPT ;[Severity: High]
Could this turn off the software fast path for flows that pass through a bridge or VLAN upper device?This hook runs at netdev ingress on the lower device. At that point
pkt_typestill holds whateth_type_trans()set by comparingh_destwith the lower device's own MAC. In__netif_receive_skb_core(),nf_ingress()runs before both places that reclassify the frame:
__netif_receive_skb_core()
nf_ingress()<-nf_flow_offload_ip_hook()runs here
vlan_do_receive()
rx_handler()<-br_handle_frame()net/8021q/vlan_core.c:vlan_do_receive() { ... if (unlikely(skb->pkt_type == PACKET_OTHERHOST)) { /* ... */ if (ether_addr_equal_64bits(eth_hdr(skb)->h_dest, vlan_dev->dev_addr)) skb->pkt_type = PACKET_HOST; } ... }net/bridge/br_input.c:br_handle_frame() { ... if (ether_addr_equal(p->br->dev->dev_addr, dest)) skb->pkt_type = PACKET_HOST; ... }The flowtable supports
DEV_PATH_BRIDGEandDEV_PATH_VLANpaths.nft_dev_path_info()puts the upper device'sdev_addrinh_source, but the ingress ifindex is the lower port. Hosts therefore send routed traffic to the bridge or VLAN MAC.Two setups hit this:
- A bridge port whose MAC differs from the bridge MAC. This is common in a multi-port bridge, because the bridge takes one port's MAC.
- A VLAN device with its own MAC.In both cases, every packet of an offloaded flow would be
PACKET_OTHERHOSTat this hook. It would returnNF_ACCEPTbeforenf_flow_offload_lookup(). The IPv4 stack later seesPACKET_HOSTand forwards these packets.Given that, does the patch keep "the IPv4 input path's forwarding decision", as the commit message says? Would it work better to compare
h_destwith the address the flow expects (for example after the tuple lookup) rather than test the lower device's rawpkt_type?net/netfilter/nf_flow_table_ip.c nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, · line 920
Quoted 4 lines
net/netfilter/nf_flow_table_ip.c +1
-0+if (!nf_flow_skb_encap_protocol (&ctx, skb))return NF_ACCEPT ;[Severity: High]
Is the same bypass still open for IPv6? In the same file,nf_flow_offload_ipv6_hook()has nopkt_typecheck. It goes straight to the lookup, forward andnf_flow_queue_xmit6()steps:net/netfilter/nf_flow_table_ip.c:nf_flow_offload_ipv6_hook() { ... if (!nf_flow_skb_encap_protocol(&ctx, skb)) return NF_ACCEPT; if (unlikely(ctx.ether_type != htons(ETH_P_IPV6))) return NF_ACCEPT; tuplehash = nf_flow_offload_ipv6_lookup(&ctx, flow_table, skb); ... }Classic IPv6 forwarding drops these frames:
net/ipv6/ip6_output.c:ip6_forward() { ... if (skb->pkt_type != PACKET_HOST) goto drop; ... }
Quoted 6 lines
nf_flow_offload_inet_hook()sendsETH_P_IPV6to the unpatched hook. With this patch, an inet flowtable would reject non-host frames for IPv4. For IPv6 it would still forward frames sent to an unrelated unicast, broadcast or multicast MAC, as long as the 5-tuple matches an installed flow.
[High] pkt_type breaks bridge/VLAN offload
Agreed. The hook runs on the lower device before vlan_do_receive() and br_handle_frame() reclassify skb->pkt_type, so frames sent to a bridge or VLAN MAC are PACKET_OTHERHOST at this point and every such flow would fall back to the slow path.
v2 drops the early pkt_type test. After the flow lookup it compares the Ethernet destination with the address the peers of the flow send to, i.e. the source MAC recorded for the reverse direction, which is the MAC of the upper device for bridge and VLAN paths. If the reverse direction carries no MAC, or the device is not Ethernet, it falls back to skb->pkt_type, since the hook then runs on the routing device itself.
[High] IPv6 not covered
Agreed. v2 applies the same check in nf_flow_offload_ipv6_hook() and adds a Fixes: tag for the IPv6 flowtable support.
[Low] Signed-off-by typo
Will be fixed in v2.
pw-bot: cr
Signature · 1 line
Florian
Florian Fainelli
maintainerPATCH 3/9 netfilter: flowtable: retain offload ownership until deletion completes
In reply to Florian FainelliTeardown clears IPS_OFFLOAD before asynchronous hardware deletion and hash removal. A new packet can therefore create a replacement flow on the same conntrack while the old owner still exists. Repeated teardown can clear the replacement's IPS_OFFLOAD, and the old hardware delete worker can clear its IPS_HW_OFFLOAD after a new hardware rule was installed.
The FA route-change reproducer observed four fresh hardware rows but only one of two connections still carrying HW_OFFLOAD. Two deterministic KUnit cases also fail before this change: repeated notification releases a new claim, and hardware retirement admits a new claim before deletion finishes.
Release IPS_OFFLOAD after both hash entries have been removed. For hardware flows, GC reaches this point only after hardware deletion is complete. NF_FLOW_TEARDOWN immediately excludes the old software fast path. Packets reaching software still use normal conntrack and forwarding; TCP state and timeout repair run at first teardown. Hardware deletion may remain pending. Holding the admission bit prevents overlapping owners.
The delayed release is observable: conntrack dumps may temporarily report OFFLOAD or HW_OFFLOAD and omit TCP state after a FIN or RST has returned to the slow path. The status covers ownership pending cleanup during the GC and asynchronous delete interval, rather than guaranteeing acceleration. This trades transient reporting for correct ownership serialization and prevents an old cleanup from clearing its replacement's status. Document the interval and use packet captures/counters to identify the packet path.
Include the private lifetime tests and their KUnit configuration here, independently of the FA series. They cover real hash removal, deferred hardware retirement, late RCU notification and balanced conntrack references. The nf_flow_table.config configuration runs these two cases on its own.
--- Documentation/networking/nf_flowtable.rst | 13 +++ MAINTAINERS | 1 + net/netfilter/Kconfig | 10 +++ net/netfilter/nf_flow_table_core.c | 9 +- net/netfilter/nf_flow_table_core_test.c | 86 +++++++++++++++++++ .../kunit/configs/nf_flow_table.config | 9 ++ 6 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 net/netfilter/nf_flow_table_core_test.c create mode 100644 tools/testing/kunit/configs/nf_flow_table.config
Documentation/networking/nf_flowtable.rst +13 -0
@@ -205,6 +205,19 @@ refers to the software offload mode, so there is a distinction between [OFFLOAD] which refers to the software flowtable fastpath and [HW_OFFLOAD] which refers to the hardware offload datapath being used by the flow. +During teardown, software fastpath lookups immediately stop matching the +flow. Packets reaching software follow the classic forwarding path, while +hardware deletion may still be pending. The OFFLOAD status +bit remains set until hash removal and asynchronous hardware deletion are +complete, preventing a new owner from racing the old owner's cleanup. As a +result, conntrack dumps can temporarily retain [OFFLOAD] or [HW_OFFLOAD] +and omit the TCP state after a FIN or RST has returned to the slow path. +TCP state and timeout repair still run at first teardown. The transient +status describes ownership pending cleanup, rather than guaranteeing that +packets are still accelerated. It clears when garbage collection finishes +the deletion; packet captures and forwarding counters identify the actual +forwarding path during that interval. + The flowtable hardware offload infrastructure also supports for the DSA (Distributed Switch Architecture).
MAINTAINERS +1 -0
@@ -19396,6 +19396,7 @@ F: net/*/netfilter.c F: net/*/netfilter/ F: net/bridge/br_netfilter*.c F: net/netfilter/ +F: tools/testing/kunit/configs/nf_flow_table.config F: tools/testing/selftests/net/netfilter/ NETRONIX EMBEDDED CONTROLLER
net/netfilter/Kconfig +10 -0
@@ -718,6 +718,16 @@ config NF_FLOW_TABLE To compile it as a module, choose M here. +config NF_FLOW_TABLE_KUNIT_TEST + bool "KUnit tests for flowtable ownership" if !KUNIT_ALL_TESTS + depends on KUNIT=y && NF_FLOW_TABLE + default KUNIT_ALL_TESTS + help + Test conntrack offload ownership during flowtable teardown. + Require hash and asynchronous hardware deletion before re-enrolment. + Verify that late notifications cannot release a replacement owner. + These private tests are embedded in the flowtable core. + config NF_FLOW_TABLE_PROCFS bool "Supply flow table statistics in procfs" depends on NF_FLOW_TABLE
net/netfilter/nf_flow_table_core.c +8 -1
@@ -393,12 +393,15 @@ static void flow_offload_del(struct nf_flowtable *flow_table,rhashtable_remove_fast (&flow_table->rhashtable, &flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY ].node, nf_flow_offload_rhash_params); +/* Release admission only after both hashes and async hardware state +* have gone. An older owner must not clear its replacement's status. +*/ +clear_bit_unlock (IPS_OFFLOAD_BIT , &flow->ct->status);flow_offload_free (flow); }void flow_offload_teardown (struct flow_offload *flow) { -clear_bit (IPS_OFFLOAD_BIT , &flow->ct->status);if (!test_and_set_bit (NF_FLOW_TEARDOWN , &flow->flags))flow_offload_fixup_ct (flow); }
@@ -876,3 +879,7 @@ module_exit(nf_flow_table_module_exit);MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Pablo Neira Ayuso <[email protected]>" );MODULE_DESCRIPTION ("Netfilter flow table module" ); + +#if IS_ENABLED (CONFIG_NF_FLOW_TABLE_KUNIT_TEST ) +#include "nf_flow_table_core_test.c" +#endif
net/netfilter/nf_flow_table_core_test.c new file +86 -0
86 lines not on this page · raw message
tools/testing/kunit/configs/nf_flow_table.config new file +9 -0
@@ -0,0 +1,9 @@ +CONFIG_KUNIT=y +CONFIG_NET=y +CONFIG_INET=y +CONFIG_NETFILTER=y +CONFIG_NETFILTER_INGRESS=y +CONFIG_NF_CONNTRACK=y +CONFIG_NF_TABLES=y +CONFIG_NF_FLOW_TABLE=y +CONFIG_NF_FLOW_TABLE_KUNIT_TEST=y
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net-next 3/9] netfilter: flowtable: retain offload ownership until deletion completes
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] netfilter: flowtable: race in nf_flow_table_extend_ct_timeout() on teardown It also noticed 2…
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] netfilter: flowtable: race in nf_flow_table_extend_ct_timeout() on teardown
It also noticed 2 related pre-existing issues this patch does not introduce:
- [Critical] netfilter: flowtable: use-after-free in flow_offload_work_handler() [1]
- [Medium] netfilter: flowtable: missing GRE timeout fixup in flow_offload_fixup_ct() [2]
--
commit b8d898f427299669723392171cb227b67d8f7493
Author: Florian Fainelli <[email protected]>
netfilter: flowtable: retain offload ownership until deletion completes
This commit delays clearing IPS_OFFLOAD_BIT from flow_offload_teardown() to flow_offload_del() so a replacement flow cannot claim the conntrack entry before hash removal and asynchronous hardware deletion finish, and adds KUnit tests covering flow teardown ownership.
Quoted 8 lines
net/netfilter/nf_flow_table_core.c +0
-0@@ -393,12 +393,15 @@ static void flow_offload_del(struct nf_flowtable *flow_table,rhashtable_remove_fast (&flow_table->rhashtable, &flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY ].node, nf_flow_offload_rhash_params);
net/netfilter/nf_flow_table_core.c static void flow_offload_del(struct nf_flowtable *flow_table, · line 401
Quoted 10 lines
net/netfilter/nf_flow_table_core.c +4
-1+/* Release admission only after both hashes and async hardware state +* have gone. An older owner must not clear its replacement's status. +*/ +clear_bit_unlock (IPS_OFFLOAD_BIT , &flow->ct->status);flow_offload_free (flow); }void flow_offload_teardown (struct flow_offload *flow) { -clear_bit (IPS_OFFLOAD_BIT , &flow->ct->status);
[Severity: Medium]
Can nf_flow_table_extend_ct_timeout() now race with flow_offload_teardown() and overwrite the repaired ct->timeout back to NF_CT_DAY?
Previously, flow_offload_teardown() cleared IPS_OFFLOAD_BIT before calling flow_offload_fixup_ct(), and nf_flow_table_extend_ct_timeout() relied on testing IPS_OFFLOAD_BIT after sampling ct->timeout to abort if teardown had already lowered the timeout. With IPS_OFFLOAD_BIT kept set until flow_offload_del(), a teardown that runs after nf_flow_offload_gc_step() samples NF_FLOW_TEARDOWN as false is no longer detected:
CPU0 (datapath) CPU1 (GC workqueue)
nf_flow_offload_gc_step()
teardown = test_bit(NF_FLOW_TEARDOWN, ...) // falseflow_offload_teardown(flow)
test_and_set_bit(NF_FLOW_TEARDOWN, ...) flow_offload_fixup_ct(flow)
nf_ct_refresh(ct, timeout)
nf_flow_table_extend_ct_timeout(flow->ct)
ct_timeout = READ_ONCE(ct->timeout)
test_bit(IPS_OFFLOAD_BIT, &ct->status)
// still true
cmpxchg(&ct->timeout, ct_timeout,
new_timeout) <-- sets NF_CT_DAYBecause NF_FLOW_TEARDOWN is already set, flow_offload_fixup_ct() will not run again when the flow is deleted, leaving the torn-down conntrack entry with a 24-hour timeout if no further slow-path packets arrive. Checking NF_FLOW_TEARDOWN on flow->flags inside nf_flow_table_extend_ct_timeout() after reading ct->timeout would close this window.
net/netfilter/nf_flow_table_core.c static void flow_offload_del(struct nf_flowtable *flow_table, · line 405
Quoted 1 line
net/netfilter/nf_flow_table_core.c +0
-0if (!test_and_set_bit (NF_FLOW_TEARDOWN , &flow->flags))
[Severity: Critical]
This problem wasn't introduced by this patch, but can flow_offload_refresh() queue hardware offload work after teardown has started [1], causing a use-after-free in flow_offload_work_handler()?
flow_offload_refresh() checks NF_FLOW_CLOSING before calling nf_flow_offload_refresh(), but does not check NF_FLOW_TEARDOWN or NF_FLOW_HW_DYING:
net/netfilter/nf_flow_table_core.c:flow_offload_refresh() {
...
if (likely(!nf_flowtable_hw_offload(flow_table)) ||
test_bit(NF_FLOW_CLOSING, &flow->flags))
return;
if (test_bit(NF_FLOW_HW, &flow->flags))
nf_flow_offload_refresh(flow_table, flow);
}If the datapath refreshes a flow while the garbage collector tears it down and deletes it, the queued FLOW_CLS_REPLACE work item can outlive the flow:
CPU0 (datapath) CPU1 (GC & workqueue)flow_offload_refresh()
nf_flow_offload_work_alloc()
test_and_set_bit(NF_FLOW_HW_PENDING,
&flow->flags)
nf_flow_offload_gc_step()
nf_flow_offload_del(flow_table, flow)
...
flow_offload_del(flow_table, flow)
flow_offload_free(flow)
flow_offload_work_handler()
clear_bit(..., &offload->flow->flags)
<-- use-after-freenet/netfilter/nf_flow_table_core.c static void flow_offload_del(struct nf_flowtable *flow_table, · line 407
Quoted 2 lines
net/netfilter/nf_flow_table_core.c +0
-0flow_offload_fixup_ct (flow); }
[Severity: Medium]
This problem wasn't introduced by this patch, but does flow_offload_fixup_ct() leave offloaded IPPROTO_GRE connections with an NF_CT_DAY timeout on teardown [2]?
flow_offload_add() sets ct->timeout to NF_CT_DAY for all offloaded flows, including GRE v0 flows admitted by nft_flow_offload_eval(), but flow_offload_fixup_ct() only restores timeouts for IPPROTO_TCP and IPPROTO_UDP and returns early for other protocols. If no further packets go through the slow path, a torn-down GRE conntrack entry stays in the table for up to 24 hours instead of expiring after the GRE conntrack timeout.
[1] https://sashiko.dev/#/bug/linux-f53f0af6-15c0-4a1b-b9e3-375ce214f143
[2] https://sashiko.dev/#/bug/linux-e64b7493-5a95-4afe-8a7a-6a28c113967a
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [PATCH net-next 3/9] netfilter: flowtable: retain offload ownership until deletion completes
In reply to Florian FainelliThank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 4 · Low: 2
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] Moving IPS_OFFLOAD_BIT out of flow_offload_teardown() means the lockless check in nf_flow_table_extend_ct_timeout() can no longer…
- [Medium] This patch reverses the central change of the commit in its
Fixes: tag but does not say so, and it does not mention the later…
- [Medium] The patch's ownership argument ('For hardware flows, GC reaches this point only after hardware deletion is complete ...…
- [Medium] The patch now releases IPS_OFFLOAD (re-admission) in flow_offload_del() once NF_FLOW_HW_DEAD is set, and the commit…
- [Low] The new KUnit test nf_flow_test_hardware_retirement() and the NF_FLOW_TABLE_KUNIT_TEST help text say they check that hash removal…
- [Low] The new Documentation/networking/nf_flowtable.rst text (and the commit message) list the visible side effects of keeping IPS_OFFLOAD…
--
netfilter: flowtable: retain offload ownership until deletion completes
This patch moves the clearing of IPS_OFFLOAD_BIT from flow_offload_teardown() to flow_offload_del(), after both hash entries have been removed. The goal is that a replacement flow can't be admitted on the same conntrack while the old owner's cleanup is still pending. It also documents the transient status and adds KUnit tests for the ownership lifetime.
Quoted 5 lines
Documentation/networking/nf_flowtable.rst +0
-0
Documentation/networking/nf_flowtable.rst refers to the software offload mode, so there is a distinction between [OFFLOAD] · line 214
Quoted 10 lines
Documentation/networking/nf_flowtable.rst +7
-0@@ -205,6 +205,19 @@ refers to the software offload mode, so there is a distinction between [OFFLOAD] which refers to the software flowtable fastpath and [HW_OFFLOAD] which refers to the hardware offload datapath being used by the flow. +During teardown, software fastpath lookups immediately stop matching the +flow. Packets reaching software follow the classic forwarding path, while +hardware deletion may still be pending. The OFFLOAD status +bit remains set until hash removal and asynchronous hardware deletion are +complete, preventing a new owner from racing the old owner's cleanup. As a +result, conntrack dumps can temporarily retain [OFFLOAD] or [HW_OFFLOAD] +and omit the TCP state after a FIN or RST has returned to the slow path.
[Severity: Low]
Is this list of side effects complete? Several in-tree users of IPS_OFFLOAD_BIT now see the bit set for the whole GC and async DESTROY window.
ctnetlink_dump_info() skips the timeout as well as the protoinfo:
net/netfilter/nf_conntrack_netlink.c:ctnetlink_dump_info() {
...
if (!test_bit(IPS_OFFLOAD_BIT, &ct->status) &&
(ctnetlink_dump_timeout(skb, ct, false) < 0 ||
ctnetlink_dump_protoinfo(skb, ct, false) < 0))
...
}ct_seq_show() hides the expires field in the same way. As a result, the repaired timeout mentioned in the next paragraph can't be seen during this interval.
nf_nat_used_tuple_harder() also reads the bit as "entry is offloaded":
net/netfilter/nf_nat_core.c:nf_nat_used_tuple_harder() {
...
static const unsigned long flags_offload = IPS_OFFLOAD | IPS_HW_OFFLOAD;
...
if (nf_ct_kill(ct))
taken = flags & flags_offload;
...
}A torn-down TCP entry in CLOSE or TIME_WAIT that has gone back to the slow path would now be evicted but still reported as taken.
The UAPI comment for IPS_OFFLOAD_BIT in nf_conntrack_common.h still says "Conntrack has been offloaded to flow table", but this text redefines the bit as ownership pending cleanup.
Should these effects be documented here too?
[ ... ]
net/netfilter/nf_flow_table_core.c static void flow_offload_del(struct nf_flowtable *flow_table, · line 399
Quoted 12 lines
net/netfilter/nf_flow_table_core.c +4
-0@@ -393,12 +393,15 @@ static void flow_offload_del(struct nf_flowtable *flow_table,rhashtable_remove_fast (&flow_table->rhashtable, &flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY ].node, nf_flow_offload_rhash_params); +/* Release admission only after both hashes and async hardware state +* have gone. An older owner must not clear its replacement's status. +*/ +clear_bit_unlock (IPS_OFFLOAD_BIT , &flow->ct->status);
[Severity: Medium]
The commit message says "For hardware flows, GC reaches this point only after hardware deletion is complete" and "Holding the admission bit prevents overlapping owners".
Can a datapath reader still queue a FLOW_CLS_REPLACE for this flow after its DESTROY has completed?
flow_offload_lookup() checks NF_FLOW_TEARDOWN once. The later flow_offload_refresh() only looks at NF_FLOW_CLOSING and NF_FLOW_HW:
net/netfilter/nf_flow_table_core.c:flow_offload_refresh() {
...
if (likely(!nf_flowtable_hw_offload(flow_table)) ||
test_bit(NF_FLOW_CLOSING, &flow->flags))
return;
if (test_bit(NF_FLOW_HW, &flow->flags))
nf_flow_offload_refresh(flow_table, flow);
}nf_flow_offload_work_alloc() is gated only by NF_FLOW_PENDING. flow_offload_work_handler() clears that bit after flow_offload_work_del() has set NF_FLOW_HW_DEAD. One possible sequence:
reader gc / offload workflow_offload_lookup()
TEARDOWN not set
flow_offload_teardown() nf_flow_offload_del() flow_offload_work_del()
set_bit(NF_FLOW_HW_DEAD)
NF_FLOW_PENDING clearedflow_offload_refresh()
nf_flow_offload_refresh()
REPLACE queued
flow_offload_work_add()
set_bit(IPS_HW_OFFLOAD_BIT)
flow_offload_del()
clear_bit_unlock(IPS_OFFLOAD_BIT) flow_offload_free()
After this, the re-installed hardware rule is keyed by a freed cookie, and IPS_HW_OFFLOAD stays set on the ct. nft_flow_offload_eval() or act_ct can then admit a replacement owner through test_and_set_bit(IPS_OFFLOAD_BIT).
With PREEMPT_RCU or PREEMPT_RT, the reader's RCU section could span flow_offload_del(). Could the queued REPLACE work then use the flow after flow_offload_free_rcu() has freed it?
The lookup/refresh window existed before this patch, but the new ownership argument depends on it being closed. Later patches in the series don't touch flow_offload_refresh() or nf_flow_offload_refresh().
[Severity: Medium]
Does NF_FLOW_HW_DEAD really mean the device removed the rule? flow_offload_work_del() sets it unconditionally:
net/netfilter/nf_flow_table_offload.c:flow_offload_work_del() {
clear_bit(IPS_HW_OFFLOAD_BIT, &offload->flow->ct->status);
flow_offload_tuple_del(offload, FLOW_OFFLOAD_DIR_ORIGINAL);
if (test_bit(NF_FLOW_HW_BIDIRECTIONAL, &offload->flow->flags))
flow_offload_tuple_del(offload, FLOW_OFFLOAD_DIR_REPLY);
set_bit(NF_FLOW_HW_DEAD, &offload->flow->flags);
}flow_offload_tuple_del() throws away the return value of nf_flow_offload_tuple(..., FLOW_CLS_DESTROY, ...), and nf_flow_offload_tuple() skips callbacks that return errors.
A driver's DESTROY can fail and leave the rule programmed, for example bnxt_tc_del_flow() after a firmware HWRM failure. In that case flow_offload_del() still releases IPS_OFFLOAD and frees the flow, and the flow's tuplehash[dir].tuple is the driver cookie.
Could a replacement owner then program a second rule for the same tuple while the stale rule, with the old route or NAT, stays in hardware with no way to delete it?
The ignored DESTROY result predates this patch. However, the ownership serialization described in the commit message depends on deletion having completed.
net/netfilter/nf_flow_table_core.c static void flow_offload_del(struct nf_flowtable *flow_table, · line 407
Quoted 9 lines
net/netfilter/nf_flow_table_core.c +0
-1flow_offload_free (flow); }void flow_offload_teardown (struct flow_offload *flow) { -clear_bit (IPS_OFFLOAD_BIT , &flow->ct->status);if (!test_and_set_bit (NF_FLOW_TEARDOWN , &flow->flags))flow_offload_fixup_ct (flow); }
[Severity: Medium]
Without this clear_bit(), can the flowtable GC overwrite the timeout that flow_offload_fixup_ct() just repaired?
nf_flow_offload_gc_step() samples NF_FLOW_TEARDOWN once and doesn't check it again before calling nf_flow_table_extend_ct_timeout(). The only guard left in the extend helper is the IPS_OFFLOAD_BIT re-test:
net/netfilter/nf_flow_table_core.c:nf_flow_table_extend_ct_timeout() {
u32 ct_timeout = READ_ONCE(ct->timeout);
...
if (!refcount_inc_not_zero(&ct->ct_general.use))
return;
/* load ct->status after refcount increase */
smp_acquire__after_ctrl_dep();
if (nf_ct_is_confirmed(ct) &&
test_bit(IPS_OFFLOAD_BIT, &ct->status)) {
...
cmpxchg(&ct->timeout, ct_timeout, new_timeout);
...
}That re-test now always passes until flow_offload_del() runs. Consider:
CPU0 CPU1nf_flow_offload_gc_step()
teardown = false
flow_offload_teardown()
set NF_FLOW_TEARDOWN
flow_offload_fixup_ct()
nf_ct_refresh()
nf_flow_table_extend_ct_timeout()
READ_ONCE(ct->timeout)
/* repaired, below 5 min */
test_bit(IPS_OFFLOAD_BIT)
/* still set */ cmpxchg(&ct->timeout, ct_timeout,
now + NF_CT_DAY)
CPU1 can be the datapath after a failed dst check or a missing outdev, act_ct on FIN/RST, or nf_flow_table_cleanup() on netdev events.
The refcount, smp_acquire__after_ctrl_dep() and re-test sequence from commit 03428ca5cee9 depends on teardown clearing the bit before flow_offload_fixup_ct() repairs ct->timeout.
flow_offload_del() doesn't repair the timeout again. A UDP flow with no further packets would therefore keep its conntrack entry for NF_CT_DAY instead of seconds or minutes.
Doesn't this contradict "TCP state and timeout repair run at first teardown" in the commit message? Later patches in the series leave flow_offload_teardown(), nf_flow_offload_gc_step() and nf_flow_table_extend_ct_timeout() unchanged.
[Severity: Medium]
This undoes the main change of the commit named in the Fixes: tag:
e5eaac2beb54 moved this clear_bit() from flow_offload_del() into flow_offload_teardown(). The reason was that conntrack gc could race to undo the packet path's timeout adjustment, leaving the entry with the one-day offload timeout.
Moving it back looks safe on mainline only because commit 03428ca5cee9 ("netfilter: conntrack: rework offload nf_conn timeout extension logic") removed this block from gc_worker():
if (test_bit(IPS_OFFLOAD_BIT, &tmp->status)) {
nf_ct_offload_timeout(tmp);
...
continue;
}03428ca5cee9 has no Fixes: or stable tag. Suppose this patch is backported to a stable tree that has e5eaac2beb54 but not 03428ca5cee9.
Wouldn't gc_worker() then reset ct->timeout to now + NF_CT_DAY during the whole window from teardown to flow_offload_del()? flow_offload_del() would then clear the bit without another repair. For closed TCP and expired UDP entries, that brings back the bug e5eaac2beb54 fixed.
Could the commit message say that it reverts part of e5eaac2beb54 and depends on 03428ca5cee9?
[ ... ]
Quoted 6 lines
net/netfilter/nf_flow_table_core_test.c new file +0
-0@@ -0,0 +1,86 @@
[ ... ]
net/netfilter/nf_flow_table_core_test.c line 63
Quoted 10 lines
net/netfilter/nf_flow_table_core_test.c new file +10
-0+flow_offload_teardown (flow); +/* nft_flow_offload must not admit another owner during async DESTROY. */ +KUNIT_EXPECT_TRUE (test,test_and_set_bit (IPS_OFFLOAD_BIT , &ct->status)); +flow_offload_teardown (flow); +KUNIT_EXPECT_TRUE (test,test_bit (IPS_OFFLOAD_BIT , &ct->status)); +/* Model completed hardware deletion before the GC removes the hashes. */ +clear_bit (IPS_HW_OFFLOAD_BIT , &ct->status); +set_bit (NF_FLOW_HW_DEAD , &flow->flags); +rcu_read_lock (); +flow_offload_del (&table, flow);
[Severity: Low]
Does this test cover the ordering it describes? The Kconfig help says "Require hash and asynchronous hardware deletion before re-enrolment". However, the only code that makes deletion wait for hardware removal is in nf_flow_offload_gc_step():
if (test_bit(NF_FLOW_HW, &flow->flags)) {
if (!test_bit(NF_FLOW_HW_DYING, &flow->flags))
nf_flow_offload_del(flow_table, flow);
else if (test_bit(NF_FLOW_HW_DEAD, &flow->flags))
flow_offload_del(flow_table, flow);This test sets NF_FLOW_HW_DEAD by hand and calls flow_offload_del() directly, and flow_offload_del() reads neither flag. If the HW_DYING/HW_DEAD gating were removed or broken, neither case would fail.
Both cases also use IPPROTO_ICMP, so flow_offload_fixup_ct() returns immediately. The TCP state and timeout repair at first teardown is never exercised. nf_flow_test_teardown_repeat() only checks that flow_offload_teardown() no longer touches IPS_OFFLOAD_BIT.
Later in the series the Kconfig help is reworded to "Test flowtable ownership during asynchronous hardware deletion", so the gap seems to remain in the final state.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116222519.1416501-1-florian.fainelli%40broadcom.com
Florian Fainelli
maintainerRe: [PATCH net-next 3/9] netfilter: flowtable: retain offload ownership until deletion completes
Quoted 324 lines · On 11/17/26 15:29, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 4 · Low: 2
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] Moving
IPS_OFFLOAD_BITout offlow_offload_teardown()means the lockless check innf_flow_table_extend_ct_timeout()can no longer…
- [Medium] This patch reverses the central change of the commit in its
Fixes: tag but does not say so, and it does not mention the later…
- [Medium] The patch's ownership argument ('For hardware flows, GC reaches this point only after hardware deletion is complete ...…
- [Medium] The patch now releasesIPS_OFFLOAD(re-admission) inflow_offload_del()onceNF_FLOW_HW_DEADis set, and the commit…
- [Low] The new KUnit testnf_flow_test_hardware_retirement()and theNF_FLOW_TABLE_KUNIT_TESThelp text say they check that hash removal…
- [Low] The newDocumentation/networking/nf_flowtable.rsttext (and the commit message) list the visible side effects of keeping IPS_OFFLOAD…--
netfilter: flowtable: retain offload ownership until deletion completes
This patch moves the clearing of
IPS_OFFLOAD_BITfromflow_offload_teardown()toflow_offload_del(), after both hash entries have been removed. The goal is that a replacement flow can't be admitted on the same conntrack while the old owner's cleanup is still pending. It also documents the transient status and adds KUnit tests for the ownership lifetime.Quoted 5 lines
Documentation/networking/nf_flowtable.rst +0
-0Documentation/networking/nf_flowtable.rst refers to the software offload mode, so there is a distinction between [OFFLOAD] · line 214
Quoted 10 lines
Documentation/networking/nf_flowtable.rst +7
-0@@ -205,6 +205,19 @@ refers to the software offload mode, so there is a distinction between [OFFLOAD] which refers to the software flowtable fastpath and [HW_OFFLOAD] which refers to the hardware offload datapath being used by the flow. +During teardown, software fastpath lookups immediately stop matching the +flow. Packets reaching software follow the classic forwarding path, while +hardware deletion may still be pending. The OFFLOAD status +bit remains set until hash removal and asynchronous hardware deletion are +complete, preventing a new owner from racing the old owner's cleanup. As a +result, conntrack dumps can temporarily retain [OFFLOAD] or [HW_OFFLOAD] +and omit the TCP state after a FIN or RST has returned to the slow path.[Severity: Low]
Is this list of side effects complete? Several in-tree users ofIPS_OFFLOAD_BITnow see the bit set for the whole GC and async DESTROY window.
ctnetlink_dump_info()skips the timeout as well as the protoinfo:net/netfilter/nf_conntrack_netlink.c:ctnetlink_dump_info() { ... if (!test_bit(IPS_OFFLOAD_BIT, &ct->status) && (ctnetlink_dump_timeout(skb, ct, false) < 0 || ctnetlink_dump_protoinfo(skb, ct, false) < 0)) ... }
ct_seq_show()hides the expires field in the same way. As a result, the repaired timeout mentioned in the next paragraph can't be seen during this interval.
nf_nat_used_tuple_harder()also reads the bit as "entry is offloaded":net/netfilter/nf_nat_core.c:nf_nat_used_tuple_harder() { ... static const unsigned long flags_offload = IPS_OFFLOAD | IPS_HW_OFFLOAD; ... if (nf_ct_kill(ct)) taken = flags & flags_offload; ... }A torn-down TCP entry in CLOSE or
TIME_WAITthat has gone back to the slow path would now be evicted but still reported as taken.The UAPI comment for
IPS_OFFLOAD_BITinnf_conntrack_common.hstill says "Conntrack has been offloaded to flow table", but this text redefines the bit as ownership pending cleanup.Should these effects be documented here too?
[ ... ]
net/netfilter/nf_flow_table_core.c static void flow_offload_del(struct nf_flowtable *flow_table, · line 399
Quoted 12 lines
net/netfilter/nf_flow_table_core.c +4
-0@@ -393,12 +393,15 @@ static void flow_offload_del(struct nf_flowtable *flow_table,rhashtable_remove_fast (&flow_table->rhashtable, &flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY ].node, nf_flow_offload_rhash_params); +/* Release admission only after both hashes and async hardware state +* have gone. An older owner must not clear its replacement's status. +*/ +clear_bit_unlock (IPS_OFFLOAD_BIT , &flow->ct->status);[Severity: Medium]
The commit message says "For hardware flows, GC reaches this point only after hardware deletion is complete" and "Holding the admission bit prevents overlapping owners".Can a datapath reader still queue a
FLOW_CLS_REPLACEfor this flow after its DESTROY has completed?
flow_offload_lookup()checksNF_FLOW_TEARDOWNonce. The laterflow_offload_refresh()only looks atNF_FLOW_CLOSINGandNF_FLOW_HW:net/netfilter/nf_flow_table_core.c:flow_offload_refresh() { ... if (likely(!nf_flowtable_hw_offload(flow_table)) || test_bit(NF_FLOW_CLOSING, &flow->flags)) return; if (test_bit(NF_FLOW_HW, &flow->flags)) nf_flow_offload_refresh(flow_table, flow); }
nf_flow_offload_work_alloc()is gated only byNF_FLOW_PENDING.flow_offload_work_handler()clears that bit afterflow_offload_work_del()has setNF_FLOW_HW_DEAD. One possible sequence:reader gc / offload work
flow_offload_lookup()
TEARDOWN not set
flow_offload_teardown()nf_flow_offload_del()flow_offload_work_del()
set_bit(NF_FLOW_HW_DEAD)
NF_FLOW_PENDINGclearedflow_offload_refresh()
nf_flow_offload_refresh()
REPLACE queued
flow_offload_work_add()
set_bit(IPS_HW_OFFLOAD_BIT)
flow_offload_del()
clear_bit_unlock(IPS_OFFLOAD_BIT)flow_offload_free()After this, the re-installed hardware rule is keyed by a freed cookie, and
IPS_HW_OFFLOADstays set on the ct.nft_flow_offload_eval()oract_ctcan then admit a replacement owner throughtest_and_set_bit(IPS_OFFLOAD_BIT).With
PREEMPT_RCUorPREEMPT_RT, the reader's RCU section could spanflow_offload_del(). Could the queued REPLACE work then use the flow afterflow_offload_free_rcu()has freed it?The lookup/refresh window existed before this patch, but the new ownership argument depends on it being closed. Later patches in the series don't touch
flow_offload_refresh()ornf_flow_offload_refresh().[Severity: Medium]
DoesNF_FLOW_HW_DEADreally mean the device removed the rule?flow_offload_work_del()sets it unconditionally:net/netfilter/nf_flow_table_offload.c:flow_offload_work_del() { clear_bit(IPS_HW_OFFLOAD_BIT, &offload->flow->ct->status); flow_offload_tuple_del(offload, FLOW_OFFLOAD_DIR_ORIGINAL); if (test_bit(NF_FLOW_HW_BIDIRECTIONAL, &offload->flow->flags)) flow_offload_tuple_del(offload, FLOW_OFFLOAD_DIR_REPLY); set_bit(NF_FLOW_HW_DEAD, &offload->flow->flags); }
flow_offload_tuple_del()throws away the return value ofnf_flow_offload_tuple(..., FLOW_CLS_DESTROY, ...), andnf_flow_offload_tuple()skips callbacks that return errors.A driver's DESTROY can fail and leave the rule programmed, for example
bnxt_tc_del_flow()after a firmware HWRM failure. In that caseflow_offload_del()still releasesIPS_OFFLOADand frees the flow, and the flow's tuplehash[dir].tuple is the driver cookie.Could a replacement owner then program a second rule for the same tuple while the stale rule, with the old route or NAT, stays in hardware with no way to delete it?
The ignored DESTROY result predates this patch. However, the ownership serialization described in the commit message depends on deletion having completed.
net/netfilter/nf_flow_table_core.c static void flow_offload_del(struct nf_flowtable *flow_table, · line 407
Quoted 9 lines
net/netfilter/nf_flow_table_core.c +0
-1flow_offload_free (flow); }void flow_offload_teardown (struct flow_offload *flow) { -clear_bit (IPS_OFFLOAD_BIT , &flow->ct->status);if (!test_and_set_bit (NF_FLOW_TEARDOWN , &flow->flags))flow_offload_fixup_ct (flow); }[Severity: Medium]
Without thisclear_bit(), can the flowtable GC overwrite the timeout thatflow_offload_fixup_ct()just repaired?
nf_flow_offload_gc_step()samplesNF_FLOW_TEARDOWNonce and doesn't check it again before callingnf_flow_table_extend_ct_timeout(). The only guard left in the extend helper is theIPS_OFFLOAD_BITre-test:net/netfilter/nf_flow_table_core.c:nf_flow_table_extend_ct_timeout() { u32 ct_timeout = READ_ONCE(ct->timeout); ... if (!refcount_inc_not_zero(&ct->ct_general.use)) return; /* load ct->status after refcount increase */ smp_acquire__after_ctrl_dep(); if (nf_ct_is_confirmed(ct) && test_bit(IPS_OFFLOAD_BIT, &ct->status)) { ... cmpxchg(&ct->timeout, ct_timeout, new_timeout); ... }That re-test now always passes until
flow_offload_del()runs. Consider:CPU0 CPU1
nf_flow_offload_gc_step()
teardown = falseflow_offload_teardown() set NF_FLOW_TEARDOWN flow_offload_fixup_ct() nf_ct_refresh() nf_flow_table_extend_ct_timeout() READ_ONCE(ct->timeout) /* repaired, below 5 min */ test_bit(IPS_OFFLOAD_BIT) /* still set */cmpxchg(&ct->timeout,
ct_timeout,
now +NF_CT_DAY)CPU1 can be the datapath after a failed dst check or a missing outdev,
act_cton FIN/RST, ornf_flow_table_cleanup()on netdev events.The refcount,
smp_acquire__after_ctrl_dep()and re-test sequence from commit03428ca5cee9depends on teardown clearing the bit beforeflow_offload_fixup_ct()repairsct->timeout.
flow_offload_del()doesn't repair the timeout again. A UDP flow with no further packets would therefore keep its conntrack entry forNF_CT_DAYinstead of seconds or minutes.Doesn't this contradict "TCP state and timeout repair run at first teardown" in the commit message? Later patches in the series leave
flow_offload_teardown(),nf_flow_offload_gc_step()andnf_flow_table_extend_ct_timeout()unchanged.[Severity: Medium]
This undoes the main change of the commit named in the Fixes: tag:Fixes e5eaac2beb54 ("netfilter: flowtable: fix TCP flow teardown")
e5eaac2beb54moved thisclear_bit()fromflow_offload_del()intoflow_offload_teardown(). The reason was that conntrack gc could race to undo the packet path's timeout adjustment, leaving the entry with the one-day offload timeout.Moving it back looks safe on mainline only because commit
03428ca5cee9("netfilter: conntrack: rework offloadnf_conntimeout extension logic") removed this block fromgc_worker():if (test_bit(IPS_OFFLOAD_BIT, &tmp->status)) { nf_ct_offload_timeout(tmp); ... continue; }
03428ca5cee9has no Fixes: or stable tag. Suppose this patch is backported to a stable tree that hase5eaac2beb54but not03428ca5cee9.Wouldn't
gc_worker()then resetct->timeoutto now +NF_CT_DAYduring the whole window from teardown toflow_offload_del()?flow_offload_del()would then clear the bit without another repair. For closed TCP and expired UDP entries, that brings back the buge5eaac2beb54fixed.Could the commit message say that it reverts part of
e5eaac2beb54and depends on03428ca5cee9?[ ... ]
Quoted 6 lines
net/netfilter/nf_flow_table_core_test.c new file +0
-0@@ -0,0 +1,86 @@[ ... ]
net/netfilter/nf_flow_table_core_test.c line 63
Quoted 10 lines
net/netfilter/nf_flow_table_core_test.c new file +10
-0+flow_offload_teardown (flow); +/* nft_flow_offload must not admit another owner during async DESTROY. */ +KUNIT_EXPECT_TRUE (test,test_and_set_bit (IPS_OFFLOAD_BIT , &ct->status)); +flow_offload_teardown (flow); +KUNIT_EXPECT_TRUE (test,test_bit (IPS_OFFLOAD_BIT , &ct->status)); +/* Model completed hardware deletion before the GC removes the hashes. */ +clear_bit (IPS_HW_OFFLOAD_BIT , &ct->status); +set_bit (NF_FLOW_HW_DEAD , &flow->flags); +rcu_read_lock (); +flow_offload_del (&table, flow);[Severity: Low]
Does this test cover the ordering it describes? TheKconfighelp says "Require hash and asynchronous hardware deletion before re-enrolment". However, the only code that makes deletion wait for hardware removal is innf_flow_offload_gc_step():if (test_bit(NF_FLOW_HW, &flow->flags)) { if (!test_bit(NF_FLOW_HW_DYING, &flow->flags)) nf_flow_offload_del(flow_table, flow); else if (test_bit(NF_FLOW_HW_DEAD, &flow->flags)) flow_offload_del(flow_table, flow);This test sets
NF_FLOW_HW_DEADby hand and callsflow_offload_del()directly, andflow_offload_del()reads neither flag. If the HW_DYING/HW_DEAD gating were removed or broken, neither case would fail.
Quoted 9 lines
Both cases also use
IPPROTO_ICMP, soflow_offload_fixup_ct()returns immediately. The TCP state and timeout repair at first teardown is never exercised.nf_flow_test_teardown_repeat()only checks thatflow_offload_teardown()no longer touchesIPS_OFFLOAD_BIT.Later in the series the
Kconfighelp is reworded to "Test flowtable ownership during asynchronous hardware deletion", so the gap seems to remain in the final state.
[Medium] extend_ct_timeout() racing with teardown
Agreed. With IPS_OFFLOAD kept until flow_offload_del(), the re-test of
the bit in nf_flow_table_extend_ct_timeout() no longer detects a teardown that already repaired ct->timeout. v2 passes the flow to the helper and checks NF_FLOW_TEARDOWN after sampling ct->timeout (teardown sets the flag before repairing the timeout), before the cmpxchg. A KUnit case covers it.
[Medium] Reverts part of e5eaac2beb54, depends on 03428ca5cee9
Agreed. The commit message now says this moves the clear_bit() back to flow_offload_del(), that this is only safe since 03428ca5cee9 removed the IPS_OFFLOAD handling from gc_worker(), and that the patch must not be backported to trees without it.
[Medium] "Hardware deletion is complete"
Agreed on the wording. GC reaches flow_offload_del() once the DESTROY
work has run (NF_FLOW_HW_DEAD), not once the device is known to have removed the rule, since the DESTROY result is not propagated. v2 words it that way. Making DESTROY failures visible is a separate, pre-existing limitation of the hardware offload code and not addressed here.
[Medium] Refresh queued after DESTROY
The lookup/refresh window in flow_offload_refresh() predates this patch and is independent of when IPS_OFFLOAD is released, so I'd rather not change it here. I will look at it separately.
[Low] Documentation and KUnit
v2 documents the other effects of the bit remaining set (ctnetlink and
/proc omit the timeout as well as the TCP state, NAT does not reuse the tuple), makes the retirement test go through nf_flow_offload_gc_step() so the HW_DYING/HW_DEAD gating is covered, and describes in Kconfig only what the tests check. The TCP/UDP timeout repair itself is still not covered by them.
Pre-existing issues from the first review
The use-after-free in flow_offload_work_handler() and the missing GRE timeout fixup in flow_offload_fixup_ct() are not introduced by this patch. I will follow up on them separately.
pw-bot: cr
Signature · 1 line
Florian
Florian Fainelli
maintainerPATCH 4/9 dt-bindings: net: describe the Northstar flow accelerator
In reply to Florian FainelliDescribe the BCM4708/BCM53011/BCM53012 accelerator register resource and the GMAC2 consumer phandle. The accelerator is inline on switch CPU port 8; GMAC0 and GMAC1 bypass it. Document the additional port-5/GMAC0 CPU connection for exceptions that cannot safely traverse the inline lookup. Keep existing boards unchanged unless their topology explicitly opts in.
--- .../bindings/net/brcm,bcm4708-fa.yaml | 45 +++++++++++++++++++ .../bindings/net/brcm,bcm5301x-gmac.yaml | 27 +++++++++++ MAINTAINERS | 2 + 3 files changed, 74 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml create mode 100644 Documentation/devicetree/bindings/net/brcm,bcm5301x-gmac.yaml
Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml new file +45 -0
@@ -0,0 +1,45 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/brcm,bcm4708-fa.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Broadcom Northstar BCM4708 and BCM5301X flow accelerator + +maintainers: + - Florian Fainelli <[email protected]> + +description: | + The flow accelerator is inline between GMAC2 and switch port 8 (IMP0). + GMAC0 and GMAC1 bypass it. The GMAC2 BCMA Ethernet node references this + register block through a brcm,flow-accelerator phandle. Miss packets carry + a prepended accelerator descriptor in place of the embedded switch tag. + + Switch port 5 (IMP5), connected to GMAC0, provides a second CPU path for + exceptions that must bypass the accelerator, including TCP control, + low-TTL and oversized packets. Describe that CPU port with an ethernet + phandle to GMAC0 and an internal, 1 Gbps full-duplex fixed link in the + switch's ports node. Port 8 remains the data connection to GMAC2. + +properties: + compatible: + enum: + - brcm,bcm4708-fa + - brcm,bcm53011-fa + - brcm,bcm53012-fa + + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + flow-accelerator@18027c00 { + compatible = "brcm,bcm53011-fa"; + reg = <0x18027c00 0xc0>; + };
Documentation/devicetree/bindings/net/brcm,bcm5301x-gmac.yaml new file +27 -0
@@ -0,0 +1,27 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/brcm,bcm5301x-gmac.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Broadcom Northstar BCMA GMAC flow accelerator connection + +maintainers: + - Florian Fainelli <[email protected]> + +description: | + BCMA enumerates the Northstar GMACs. This binding describes the optional + inline flow accelerator connection on GMAC2, connected to switch IMP0. + +select: + required: + - brcm,flow-accelerator + +properties: + brcm,flow-accelerator: + $ref: /schemas/types.yaml#/definitions/phandle + description: | + Phandle to the BCM4708, BCM53011 or BCM53012 inline flow accelerator. + Only GMAC2 (BCMA Ethernet core unit 2) has this connection. + +additionalProperties: true
MAINTAINERS +2 -0
@@ -5669,6 +5669,8 @@ R: Broadcom internal kernel review list <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/net/brcm,amac.yaml +F: Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml +F: Documentation/devicetree/bindings/net/brcm,bcm5301x-gmac.yaml F: drivers/net/ethernet/broadcom/bgmac* F: drivers/net/ethernet/broadcom/unimac.h
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net-next 4/9] dt-bindings: net: describe the Northstar flow accelerator
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
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] The flow-accelerator register resource in brcm,bcm4708-fa.yaml is modelled as a standalone MMIO block with only compatible and…
- [Low] The new brcm,bcm5301x-gmac.yaml schema is selected only when the brcm,flow-accelerator property is present (`select: required:…
- [Low] The FA binding description calls switch port 5 'IMP5' ('Switch port 5 (IMP5), connected to GMAC0, ...').
--
dt-bindings: net: describe the Northstar flow accelerator
This commit adds a binding for the register block of the BCM4708/BCM53011/BCM53012 flow accelerator. It also adds a schema for the brcm,flow-accelerator phandle on the GMAC2 BCMA Ethernet node. The description covers the second CPU path, port 5 to GMAC0, for exceptions that bypass the accelerator.
Quoted 6 lines
Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml new file +0
-0@@ -0,0 +1,45 @@
[ ... ]
Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml line 18
Quoted 7 lines
Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml new file +7
-0+description: | + The flow accelerator is inline between GMAC2 and switch port 8 (IMP0). + GMAC0 and GMAC1 bypass it. The GMAC2 BCMA Ethernet node references this + register block through a brcm,flow-accelerator phandle. Miss packets carry + a prepended accelerator descriptor in place of the embedded switch tag. + + Switch port 5 (IMP5), connected to GMAC0, provides a second CPU path for
[Severity: Low]
Should this say IMP1 instead of IMP5? The b53 SRAB code calls the two IMP ports IMP0 (port 8) and IMP1 (port 5):
drivers/net/dsa/b53/b53_srab.c:
#define B53_SRAB_IMP1_SLEEP_TIMER BIT(10) #define B53_SRAB_P7_SLEEP_TIMER BIT(11) #define B53_SRAB_IMP0_SLEEP_TIMER BIT(12)
This description already uses IMP0 for port 8.
Quoted 4 lines
Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml new file +4
-0+ exceptions that must bypass the accelerator, including TCP control, + low-TTL and oversized packets. Describe that CPU port with an ethernet + phandle to GMAC0 and an internal, 1 Gbps full-duplex fixed link in the + switch's ports node. Port 8 remains the data connection to GMAC2.
[ ... ]
Quoted 5 lines
Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml new file +5
-0+ reg: + maxItems: 1 + +required: + - compatible
Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml line 45
Quoted 10 lines
Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml new file +10
-0+ - reg + +additionalProperties: false + +examples: + - | + flow-accelerator@18027c00 { + compatible = "brcm,bcm53011-fa"; + reg = <0x18027c00 0xc0>; + };
[Severity: Medium]
Can the flow accelerator be treated as a standalone MMIO block? The example address 0x18027c00 falls inside the 4 KiB BCMA window of GMAC core unit 3. bcm-ns.dtsi already describes that core under the 0x18000000 axi bus:
arch/arm/boot/dts/broadcom/bcm-ns.dtsi:
gmac3: ethernet@27000 {
reg = <0x27000 0x800>;
};The binding allows only compatible and reg. It has no clocks or resets and no link to the GMAC3 core. It also does not say that the hosting core must be out of reset and clocked.
Later in the series, bcm_ns_fa_init() in drivers/net/ethernet/broadcom/bcm-ns-fa.c maps this node and writes to it straight away:
np = of_parse_phandle(parent->of_node, "brcm,flow-accelerator", 0); ... fa->regs = devm_ioremap_resource(parent, &res); ... writel(0, fa->regs + FA_STATUS_MASK);
Nothing in bgmac or bcm-ns-fa calls bcma_core_enable() on core unit 3. bgmac_probe() also rejects core_unit 3 when that core has no MAC address, so it never gets enabled there.
Suppose the bootloader leaves the GMAC3 wrapper in reset or clock-gated. Could bgmac_probe() for GMAC2 -> bcm_ns_fa_init() -> writel() then take an imprecise external abort or hang the bus? And if something later resets the GMAC3 wrapper, would that wipe the programmed FA state?
This is inferred from how AI wrappers usually behave. I have not checked it against the Northstar register map, so I can't confirm that GMAC3 hosts the FA. On BCM53012 boards where CFE leaves core 3 enabled, it may work as is.
Should the binding describe how the FA relates to its hosting core, or the clocks and resets it depends on?
Quoted 10 lines
Documentation/devicetree/bindings/net/brcm,bcm5301x-gmac.yaml new file +4
-0@@ -0,0 +1,27 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/brcm,bcm5301x-gmac.yaml#
[ ... ]
Documentation/devicetree/bindings/net/brcm,bcm5301x-gmac.yaml line 27
Quoted 12 lines
Documentation/devicetree/bindings/net/brcm,bcm5301x-gmac.yaml new file +12
-0+select: + required: + - brcm,flow-accelerator + +properties: + brcm,flow-accelerator: + $ref: /schemas/types.yaml#/definitions/phandle + description: | + Phandle to the BCM4708, BCM53011 or BCM53012 inline flow accelerator. + Only GMAC2 (BCMA Ethernet core unit 2) has this connection. + +additionalProperties: true
[Severity: Low]
The "Only GMAC2" restriction exists only in the description text. The schema is selected purely by the presence of the property, and it sets
additionalProperties: true. Wouldn't a DT that puts brcm,flow-accelerator on gmac0 (ethernet@24000), gmac1 or gmac3 still pass dt_binding_check and dtbs_check?
Nothing checks that the phandle points to a brcm,*-fa node either.
Later in the series, bgmac_probe() in bgmac-bcma.c enforces the rule at runtime:
if (of_property_present(core->dev.of_node, "brcm,flow-accelerator") && core->core_unit != 2) return -EINVAL;
So a misplaced phandle makes that GMAC fail to probe, and dtbs_check gives no warning beforehand.
Separately, the file name and $id suggest a brcm,bcm5301x-gmac compatible, but the BCMA GMAC nodes have no compatible. Is that naming intended?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116222519.1416501-1-florian.fainelli%40broadcom.com
Florian Fainelli
maintainerRe: [PATCH net-next 4/9] dt-bindings: net: describe the Northstar flow accelerator
Quoted 162 lines · On 11/17/26 15:29, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
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] The flow-accelerator register resource in brcm,bcm4708-fa.yaml is modelled as a standalone MMIO block with only
compatibleand…
- [Low] The new brcm,bcm5301x-gmac.yaml schema is selected only when thebrcm,flow-acceleratorproperty is present (`select: required:…
- [Low] The FA binding description calls switch port 5 'IMP5' ('Switch port 5 (IMP5), connected to GMAC0, ...').--
dt-bindings: net: describe the Northstar flow accelerator
This commit adds a binding for the register block of the BCM4708/BCM53011/BCM53012 flow accelerator. It also adds a schema for the brcm,flow-accelerator phandle on the GMAC2 BCMA Ethernet node. The description covers the second CPU path, port 5 to GMAC0, for exceptions that bypass the accelerator.
Quoted 6 lines
Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml new file +0
-0@@ -0,0 +1,45 @@[ ... ]
Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml line 18
Quoted 7 lines
Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml new file +7
-0+description: | + The flow accelerator is inline between GMAC2 and switch port 8 (IMP0). + GMAC0 and GMAC1 bypass it. The GMAC2 BCMA Ethernet node references this + register block through a brcm,flow-accelerator phandle. Miss packets carry + a prepended accelerator descriptor in place of the embedded switch tag. + + Switch port 5 (IMP5), connected to GMAC0, provides a second CPU path for[Severity: Low]
Should this say IMP1 instead of IMP5? The b53 SRAB code calls the two IMP ports IMP0 (port 8) and IMP1 (port 5):
drivers/net/dsa/b53/b53_srab.c:#define B53_SRAB_IMP1_SLEEP_TIMER BIT(10) #define B53_SRAB_P7_SLEEP_TIMER BIT(11) #define B53_SRAB_IMP0_SLEEP_TIMER BIT(12)This description already uses IMP0 for port 8.
Quoted 4 lines
Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml new file +4
-0+ exceptions that must bypass the accelerator, including TCP control, + low-TTL and oversized packets. Describe that CPU port with an ethernet + phandle to GMAC0 and an internal, 1 Gbps full-duplex fixed link in the + switch's ports node. Port 8 remains the data connection to GMAC2.[ ... ]
Quoted 5 lines
Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml new file +5
-0+ reg: + maxItems: 1 + +required: + - compatibleDocumentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml line 45
Quoted 10 lines
Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml new file +10
-0+ - reg + +additionalProperties: false + +examples: + - | + flow-accelerator@18027c00 { + compatible = "brcm,bcm53011-fa"; + reg = <0x18027c00 0xc0>; + };[Severity: Medium]
Can the flow accelerator be treated as a standalone MMIO block? The example address0x18027c00falls inside the 4 KiB BCMA window of GMAC core unit 3.bcm-ns.dtsialready describes that core under the0x18000000axi bus:
arch/arm/boot/dts/broadcom/bcm-ns.dtsi:gmac3: ethernet@27000 { reg = <0x27000 0x800>; };The binding allows only compatible and reg. It has no clocks or resets and no link to the GMAC3 core. It also does not say that the hosting core must be out of reset and clocked.
Later in the series,
bcm_ns_fa_init()indrivers/net/ethernet/broadcom/bcm-ns-fa.cmaps this node and writes to it straight away:np = of_parse_phandle(parent->of_node, "brcm,flow-accelerator", 0); ... fa->regs = devm_ioremap_resource(parent, &res); ... writel(0, fa->regs + FA_STATUS_MASK);Nothing in bgmac or bcm-ns-fa calls
bcma_core_enable()on core unit 3.bgmac_probe()also rejectscore_unit3 when that core has no MAC address, so it never gets enabled there.Suppose the bootloader leaves the GMAC3 wrapper in reset or clock-gated. Could
bgmac_probe()for GMAC2 ->bcm_ns_fa_init()->writel()then take an imprecise external abort or hang the bus? And if something later resets the GMAC3 wrapper, would that wipe the programmed FA state?This is inferred from how AI wrappers usually behave. I have not checked it against the Northstar register map, so I can't confirm that GMAC3 hosts the FA. On BCM53012 boards where CFE leaves core 3 enabled, it may work as is.
Should the binding describe how the FA relates to its hosting core, or the clocks and resets it depends on?
Quoted 10 lines
Documentation/devicetree/bindings/net/brcm,bcm5301x-gmac.yaml new file +4
-0@@ -0,0 +1,27 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/brcm,bcm5301x-gmac.yaml#[ ... ]
Documentation/devicetree/bindings/net/brcm,bcm5301x-gmac.yaml line 27
Quoted 12 lines
Documentation/devicetree/bindings/net/brcm,bcm5301x-gmac.yaml new file +12
-0+select: + required: + - brcm,flow-accelerator + +properties: + brcm,flow-accelerator: + $ref: /schemas/types.yaml#/definitions/phandle + description: | + Phandle to the BCM4708, BCM53011 or BCM53012 inline flow accelerator. + Only GMAC2 (BCMA Ethernet core unit 2) has this connection. + +additionalProperties: true[Severity: Low]
The "Only GMAC2" restriction exists only in the description text. The schema is selected purely by the presence of the property, and it sets
additionalProperties: true. Wouldn't a DT that puts brcm,flow-accelerator on gmac0 (ethernet@24000), gmac1 or gmac3 still passdt_binding_checkanddtbs_check?Nothing checks that the phandle points to a brcm,*-fa node either.
Later in the series,
bgmac_probe()inbgmac-bcma.cenforces the rule at runtime:if (of_property_present(core->dev.of_node, "brcm,flow-accelerator") && core->core_unit != 2) return -EINVAL;
Quoted 6 lines
So a misplaced phandle makes that GMAC fail to probe, and
dtbs_checkgives no warning beforehand.Separately, the file name and $id suggest a brcm,bcm5301x-gmac compatible, but the BCMA GMAC nodes have no compatible. Is that naming intended?
[Medium] FA modeled as a standalone MMIO block
The register block does not overlap the GMAC3 node: 0x18027c00 is in the
GMAC3 BCMA window but outside the 0x800 bytes described by ethernet@27000. Per the data sheets, the FA is part of the AXI MAC + FA block together with the four GMAC cores (GMAC3 being the block's loopback port), not a separate peripheral. It has no clock or reset input of its own in the DT, and BCMA wrappers are not modeled as DT clocks/resets.
I cannot tell from the documentation how the GMAC3 BCMA wrapper state
affects access to these registers, so I am checking this on hardware and will add the core enable to bcm_ns_fa_init() if it turns out to be needed. v2 documents where the registers live in the binding description.
[Low] IMP5 vs IMP1
Agreed, port 5 is IMP1. Fixed in v2.
[Low] GMAC2-only restriction / naming
v2 restricts the consumer schema to ethernet@26000 with a $nodename pattern. BCMA GMAC nodes have no compatible, which is why the schema is selected by the property; the description now says so. dt-schema cannot check what the phandle points to, the driver validates the compatible.
pw-bot: cr
Signature · 1 line
Florian
Florian Fainelli
maintainerPATCH 5/9 net: dsa: add Broadcom FA metadata and IPv4 exception paths
In reply to Florian FainelliAdd a brcm-fa tagger for the prepended Northstar miss descriptor, with hash, bucket and parser status fields distinct from ordinary switch tags. Select it only for an explicitly connected accelerator on GMAC2/port 8.
Original FA ignores standalone switch exceptions and its key lacks input port, TTL, packet length and TCP flags. Reserve B53 CFP rules to redirect SYN/FIN/RST, TTL 0/1 and lengths above 1500 through port 5/GMAC0, outside FA. Per-port router-MAC allow rules and a default IPv4 trap prevent a live tuple from bypassing Linux ingress policy on another switch port. Nine masked length prefixes cover 1501 through 65535. Preserve VLAN, EAP and STP filtering, and keep ordinary data flooding off the auxiliary CPU.
Update MAC guards through a netdevice notifier after DSA registration. Coordinate guard and conduit readiness with an RCU-protected backend registry. Disable admission and retire entries before removing any exception path. Keep incomplete or failed guards disabled across bridge join and leave, using the same readiness checks as conduit changes. Decode embedded auxiliary tags before delivering those packets to Linux; retain strict validation of ordinary Broadcom tags.
--- drivers/net/dsa/b53/Kconfig | 1 + drivers/net/dsa/b53/b53_common.c | 423 ++++++++++++++++++++++++++++++- drivers/net/dsa/b53/b53_priv.h | 6 + drivers/net/dsa/b53/b53_regs.h | 39 +++ include/linux/dsa/brcm.h | 19 ++ include/net/dsa.h | 2 + net/dsa/Kconfig | 9 + net/dsa/tag_brcm.c | 116 ++++++++- 8 files changed, 603 insertions(+), 12 deletions(-)
drivers/net/dsa/b53/Kconfig +1 -0
@@ -7,6 +7,7 @@ menuconfig B53 select NET_DSA_TAG_BRCM_LEGACY select NET_DSA_TAG_BRCM_LEGACY_FCS select NET_DSA_TAG_BRCM_PREPEND + select NET_DSA_TAG_BRCM_FA help This driver adds support for Broadcom managed switch chips. It supports BCM5325E, BCM5365, BCM539x, BCM53115 and BCM53125 as well as BCM63XX
drivers/net/dsa/b53/b53_common.c +418 -5
533 lines not on this page · raw message
drivers/net/dsa/b53/b53_priv.h +6 -0
@@ -153,6 +153,12 @@ struct b53_device {u8 num_arl_bins;u16 num_arl_buckets;enum dsa_tag_protocol tag_protocol; +u16 fa_cfp_ports; +bool fa_cfp_enabled; +bool fa_guards_ready; +bool fa_guards_failed; +bool fa_stopping; +struct notifier_block fa_netdev_nb;/* used ports mask */ u16 enabled_ports;
drivers/net/dsa/b53/b53_regs.h +39 -0
@@ -614,4 +614,43 @@/* CFP Control Register with ports map (8 bit) */ #define B53_CFP_CTRL 0x00 +/* Northstar CFP indirect table port. */ +#define B53_CFP_TCAM_PAGE 0xa0 +#define B53_CFP_ACC 0x00 +#define CFP_ACC_START BIT(0) +#define CFP_ACC_WRITE (2 << 1) +#define CFP_ACC_TCAM BIT(10) +#define CFP_ACC_ACTION (2 << 10) +#define CFP_ACC_METER (4 << 10) +#define CFP_ACC_RESET BIT(15) +#define CFP_ACC_INDEX (n) ((n) << 16) +#define B53_CFP_DATA (n) (0x10 + (n) * 4) +#define B53_CFP_MASK (n) (0x30 + (n) * 4) +#define B53_CFP_ACTION (n) (0x50 + (n) * 4) +#define B53_CFP_METER 0x60 +#define B53_CFP_UDF1_A0 0x20 +#define CFP_UDF_BASE_END_L2 (2 << 5) +#define CFP_UDF_BASE_END_L3 (3 << 5) +#define CFP_UDF_OFFSET (n) (n) + +/* Slice 1 IPv4 key fields, indexed by DATA/MASK word. */ +#define CFP_TCAM0_VALID GENMASK(1, 0) +#define CFP_TCAM0_SLICE1 BIT(2) +#define CFP_TCAM0_SLICE_MASK GENMASK(3, 2) +#define CFP_TCAM0_UDF0_FLAG (n) BIT(8 + (n)) +#define CFP_TCAM_UDF_OFFSET 8 +#define CFP_TCAM5_UDF_VALID (n) BIT(24 + (n)) +#define CFP_TCAM6_L3_FRAMING GENMASK(25, 24) +#define CFP_TCAM6_IP_PROTOCOL GENMASK(15, 8) +#define CFP_TCAM6_IP_FRAGMENT BIT(7) +#define CFP_TCAM7_SOURCE_PORTS GENMASK(7, 0) + +/* Both meter outcomes replace the destination map with CPU port 5. */ +#define CFP_ACT0_FWD_MAP_REPLACE (2 << 24) +#define CFP_ACT0_DST_PORT5 BIT(19) +#define CFP_ACT0_REASON_TERMINATION BIT(6) +#define CFP_ACT1_CLASS_ID (n) ((n) << 20) +#define CFP_ACT1_FWD_MAP_REPLACE (2 << 11) +#define CFP_ACT1_DST_PORT5 BIT(6) +#endif /* !__B53_REGS_H */
include/linux/dsa/brcm.h +19 -0
@@ -8,6 +8,25 @@#ifndef _NET_DSA_BRCM_H#define _NET_DSA_BRCM_H +#include <linux/list.h> +#include <linux/types.h> + +struct net_device ; +struct sk_buff ; + +/* Original FA control packets arrive through the auxiliary CPU port. */ +struct brcm_fa_control { +struct list_head list; +struct net_device *conduit; +void (*receive)(void *priv,struct sk_buff *skb,unsigned int port); +void (*state_change)(void *priv,bool ready); +void *priv; +}; + +void brcm_fa_control_register (struct brcm_fa_control *control); +void brcm_fa_control_unregister (struct brcm_fa_control *control); +void brcm_fa_control_set_ready (struct net_device *conduit,bool ready); +/* Broadcom tag specific helpers to insert and extract queue/port number */ #define BRCM_TAG_SET_PORT_QUEUE (p, q) ((p) << 8 | q)#define BRCM_TAG_GET_PORT (v) ((v) >> 8)
include/net/dsa.h +2 -0
@@ -62,6 +62,7 @@ struct tc_action;#define DSA_TAG_PROTO_KSZ8463_VALUE 34#define DSA_TAG_PROTO_MT7628_VALUE 35#define DSA_TAG_PROTO_KS8995_VALUE 36 +#define DSA_TAG_PROTO_BRCM_FA_VALUE 37enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -69,6 +70,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_BRCM_LEGACY =DSA_TAG_PROTO_BRCM_LEGACY_VALUE ,DSA_TAG_PROTO_BRCM_LEGACY_FCS =DSA_TAG_PROTO_BRCM_LEGACY_FCS_VALUE ,DSA_TAG_PROTO_BRCM_PREPEND =DSA_TAG_PROTO_BRCM_PREPEND_VALUE , +DSA_TAG_PROTO_BRCM_FA =DSA_TAG_PROTO_BRCM_FA_VALUE ,DSA_TAG_PROTO_DSA =DSA_TAG_PROTO_DSA_VALUE ,DSA_TAG_PROTO_EDSA =DSA_TAG_PROTO_EDSA_VALUE , DSA_TAG_PROTO_GSWIP = DSA_TAG_PROTO_GSWIP_VALUE,
net/dsa/Kconfig +9 -0
@@ -69,6 +69,15 @@ config NET_DSA_TAG_BRCM_PREPEND Broadcom switches which places the tag before the Ethernet header (prepended). +config NET_DSA_TAG_BRCM_FA + tristate "Tag driver for the Broadcom Northstar flow accelerator" + select NET_DSA_TAG_BRCM_COMMON + help + Support the prepended four-byte FA metadata tag on Northstar GMAC2. + The receive format includes a hash, bucket, parser status, and input + switch port. Transmit uses the ordinary prepended Broadcom tag. + Enable this for a B53 switch explicitly connected to an accelerator. + config NET_DSA_TAG_HELLCREEK tristate "Tag driver for Hirschmann Hellcreek TSN switches" help
net/dsa/tag_brcm.c +109 -7
173 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net-next 5/9] net: dsa: add Broadcom FA metadata and IPv4 exception paths
Thank you for your contribution! Sashiko AI review found 7 potential issues to consider: - [Medium] net: dsa: b53: broken guard error handling in b53_fa_netdev_event() - [Medium] net: dsa: b53…
Thank you for your contribution! Sashiko AI review found 7 potential issues to consider:
- [Medium] net: dsa: b53: broken guard error handling in b53_fa_netdev_event()
- [Medium] net: dsa: b53: unrecorded standalone port on b53_fa_port() failure
- [Medium] net: dsa: b53: missing CPU port 5 in non-default VLANs in b53_vlan_add()
- [Medium] net: dsa: b53: active fa_netdev_nb during teardown and b53_switch_shutdown()
- [Medium] net: dsa: tag_brcm: brcm_tag_rcv_ll() reads prepended tag as MAC DA
- [Low] net: dsa: b53: duplicate CFP rule programming in b53_fa_setup()
- [Low] net: dsa: b53: unlocked fa_guards_ready access in b53_switch_register()
--
commit 5efa0c79a851eb8221145c59826df5a46728bb31
Author: Florian Fainelli <[email protected]>
net: dsa: add Broadcom FA metadata and IPv4 exception paths
This commit adds a brcm-fa DSA tag driver for the Broadcom Northstar flow accelerator on port 8 and configures B53 CFP rules to redirect IPv4 exception traffic and router-MAC guard misses to auxiliary CPU port 5.
Quoted 4 lines
drivers/net/dsa/b53/b53_common.c +0
-0
[ ... ]
Quoted 30 lines
drivers/net/dsa/b53/b53_common.c +30
-0+static int b53_fa_rule (struct b53_device *dev,unsigned int index, +const u32 data[8 ],const u32 mask[8 ],bool trap) +{ +unsigned int i; +int err; + +for (i =0 ; i <8 ; i++) { + err =b53_write32 (dev,B53_CFP_TCAM_PAGE ,B53_CFP_DATA (i), data[i]); +if (!err) + err =b53_write32 (dev,B53_CFP_TCAM_PAGE ,B53_CFP_MASK (i), mask[i]); +if (err) +return err; + } + err =b53_write32 (dev,B53_CFP_TCAM_PAGE ,B53_CFP_ACTION (0 ), + trap ?CFP_ACT0_FWD_MAP_REPLACE |CFP_ACT0_DST_PORT5 | +CFP_ACT0_REASON_TERMINATION :0 ); +if (!err) + err =b53_write32 (dev,B53_CFP_TCAM_PAGE ,B53_CFP_ACTION (1 ), + trap ?CFP_ACT1_CLASS_ID (1 ) |CFP_ACT1_FWD_MAP_REPLACE | +CFP_ACT1_DST_PORT5 :0 ); +if (!err) + err =b53_fa_cfp_write (dev, index,CFP_ACC_ACTION ); +if (!err) + err =b53_write32 (dev,B53_CFP_TCAM_PAGE ,B53_CFP_METER ,0 ); +if (!err) + err =b53_write32 (dev,B53_CFP_TCAM_PAGE ,B53_CFP_METER +4 ,0 ); +if (!err) + err =b53_fa_cfp_write (dev, index,CFP_ACC_METER ); +return err ?:b53_fa_cfp_write (dev, index,CFP_ACC_TCAM ); +}
[ ... ]
Quoted 2 lines
drivers/net/dsa/b53/b53_common.c +2
-0+static int b53_fa_setup (struct b53_device *dev) +{
[ ... ]
Quoted 30 lines
drivers/net/dsa/b53/b53_common.c +30
-0+for (rule =0 ; rule <3 ; rule++) { +memset (data,0 ,sizeof (data)); +memset (mask,0 ,sizeof (mask)); + data[0 ] =CFP_TCAM0_VALID |CFP_TCAM0_SLICE1 |CFP_TCAM0_UDF0_FLAG (rule); +/* Slice 1; FIN, SYN or RST. */ + mask[0 ] =CFP_TCAM0_VALID |CFP_TCAM0_SLICE_MASK |CFP_TCAM0_UDF0_FLAG (rule); + data[5 ] =CFP_TCAM5_UDF_VALID (0 );/* UDF A0 valid. */ + mask[5 ] =CFP_TCAM5_UDF_VALID (0 ); + data[6 ] =FIELD_PREP (CFP_TCAM6_IP_PROTOCOL ,IPPROTO_TCP ); + mask[6 ] =CFP_TCAM6_L3_FRAMING |CFP_TCAM6_IP_PROTOCOL |CFP_TCAM6_IP_FRAGMENT ; +for (i =0 ; i <ARRAY_SIZE (data); i++) { + err =b53_write32 (dev,B53_CFP_TCAM_PAGE ,B53_CFP_DATA (i), data[i]); +if (!err) + err =b53_write32 (dev,B53_CFP_TCAM_PAGE ,B53_CFP_MASK (i), mask[i]); +if (err) +return err; + } +/* Both meter outcomes redirect to IMP5, with class 1 and a +* termination reason. Preserve VLAN, EAP and STP filtering. +*/ + err =b53_write32 (dev,B53_CFP_TCAM_PAGE ,B53_CFP_ACTION (0 ), +CFP_ACT0_FWD_MAP_REPLACE |CFP_ACT0_DST_PORT5 | +CFP_ACT0_REASON_TERMINATION ); +if (!err) + err =b53_write32 (dev,B53_CFP_TCAM_PAGE ,B53_CFP_ACTION (1 ), +CFP_ACT1_CLASS_ID (1 ) |CFP_ACT1_FWD_MAP_REPLACE | +CFP_ACT1_DST_PORT5 ); +if (!err) + err =b53_fa_cfp_write (dev, rule,CFP_ACC_ACTION ); +if (!err)
drivers/net/dsa/b53/b53_common.c int b53_setup_devlink_resources(struct dsa_switch *ds) · line 1530
Quoted 10 lines
drivers/net/dsa/b53/b53_common.c +10
-0+ err =b53_write32 (dev,B53_CFP_TCAM_PAGE ,B53_CFP_METER ,0 ); +if (!err) + err =b53_write32 (dev,B53_CFP_TCAM_PAGE ,B53_CFP_METER +4 ,0 ); +if (!err) + err =b53_fa_cfp_write (dev, rule,CFP_ACC_METER ); +if (!err) + err =b53_fa_cfp_write (dev, rule,CFP_ACC_TCAM ); +if (err) +return err; + }
[Severity: Low]
This isn't a bug, but this loop open-codes b53_fa_rule(dev, rule, data, mask, true).
[ ... ]
Quoted 19 lines
drivers/net/dsa/b53/b53_common.c +19
-0+static int b53_fa_port (struct b53_device *dev,int port,bool standalone) +{ +struct dsa_port *control =dsa_to_port (dev->ds,5 ); +bool ready; +u16 ports; +int err; + +if (!dev->fa_cfp_enabled) +return 0 ; + ports = dev->fa_cfp_ports & ~BIT (port); +if (standalone) + ports |=BIT (port); + ready =b53_fa_ready (dev,dsa_port_conduit_is_operational (control)); + err =b53_write16 (dev,B53_CFP_PAGE ,B53_CFP_CTRL , + ready ? ports :0 ); +if (!err) + dev->fa_cfp_ports = ports; +return err; +}
[ ... ]
Quoted 29 lines
drivers/net/dsa/b53/b53_common.c +29
-0+static int b53_fa_netdev_event (struct notifier_block *nb,unsigned long event,void *ptr) +{ + struct b53_device *dev = container_of(nb, struct b53_device, fa_netdev_nb); +struct net_device *netdev =netdev_notifier_info_to_dev (ptr); +struct dsa_port *dp, *control, *data_cpu; +u32 data[8 ] = {}, mask[8 ] = {}; +unsigned int i; +int err; + +if (dev->fa_stopping || !dsa_user_dev_check (netdev) || + (event !=NETDEV_REGISTER && event !=NETDEV_UP && + event !=NETDEV_PRE_CHANGEADDR && event !=NETDEV_CHANGEADDR )) +return NOTIFY_DONE ; + dp =dsa_port_from_netdev (netdev); +if (dp->ds != dev->ds || dp->index >=8 ) +return NOTIFY_DONE ; + control =dsa_to_port (dev->ds,5 ); + data_cpu =dsa_to_port (dev->ds,8 ); +brcm_fa_control_set_ready (data_cpu->conduit, false); +if (event !=NETDEV_PRE_CHANGEADDR ) { + data[0 ] =CFP_TCAM0_VALID |CFP_TCAM0_SLICE1 ; + mask[0 ] =CFP_TCAM0_VALID |CFP_TCAM0_SLICE_MASK ; + mask[6 ] =CFP_TCAM6_L3_FRAMING ; + data[7 ] =BIT (dp->index); + mask[7 ] =CFP_TCAM7_SOURCE_PORTS ; +for (i =0 ; i <3 ; i++) +b53_fa_udf (data, mask,3 + i,get_unaligned_be16 (netdev->dev_addr +2 * i), +0xffff ); + }
drivers/net/dsa/b53/b53_common.c int b53_setup_devlink_resources(struct dsa_switch *ds) · line 1639
Quoted 10 lines
drivers/net/dsa/b53/b53_common.c +10
-0+ err =b53_fa_rule (dev,B53_FA_ALLOW_BASE + dp->index, data, mask, false); +if (err) { + dev->fa_guards_failed = true; +dev_err (dev->dev,"failed to update FA ingress guard: %d\n" , err); + }else if (event !=NETDEV_PRE_CHANGEADDR ) { +b53_fa_conduit_state_change (dev->ds, control->conduit, +dsa_port_conduit_is_operational (control)); + } +return NOTIFY_DONE ; +}
[Severity: Medium]
What restores the port's allow rule at B53_FA_ALLOW_BASE + dp->index if netif_set_mac_address() fails after NETDEV_PRE_CHANGEADDR?
netif_set_mac_address() emits NETDEV_PRE_CHANGEADDR before calling ops->ndo_set_mac_address(). If a subsequent notifier or dsa_user_set_mac_address() rejects the address (for example when !is_valid_ether_addr()), NETDEV_CHANGEADDR is never sent. The port's hardware allow rule remains zeroed out and all IPv4 traffic on that port hits B53_FA_DEFAULT_RULE and traps to CPU port 5, even after another port event re-enables FA via b53_fa_conduit_state_change().
Also, when b53_fa_rule() fails here, dev->fa_guards_failed is set to true, but skipping b53_fa_conduit_state_change() leaves B53_CFP_CTRL enabled in hardware.
[ ... ]
drivers/net/dsa/b53/b53_common.c void b53_br_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge) · line 2782
Quoted 9 lines
drivers/net/dsa/b53/b53_common.c +4
-0@@ -2439,6 +2775,10 @@ void b53_br_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge) vl->members |=BIT (port);b53_set_vlan_entry (dev, pvid, vl); } +if (b53_fa_port (dev, port, true)) { +dev_err (ds->dev,"failed to restore FA classification on port %d\n" , port); +b53_disable_port (ds, port); + } }
[Severity: Medium]
If b53_fa_port(dev, port, true) fails in b53_br_leave(), can a subsequent ndo_open re-enable the standalone port without CFP classification?
When b53_write16() fails in b53_fa_port(), BIT(port) is not recorded in dev->fa_cfp_ports and dev->fa_guards_failed is not set. Bringing the port up later via dsa_user_open() -> b53_enable_port() re-enables Rx/Tx without setting BIT(5) in B53_PVLAN_PORT_MASK(port), and the following NETDEV_UP event in b53_fa_netdev_event() writes dev->fa_cfp_ports (still missing BIT(port)) to B53_CFP_CTRL and re-enables FA admission.
[ ... ]
drivers/net/dsa/b53/b53_common.c static bool b53_can_enable_brcm_tags(struct dsa_switch *ds, int port, · line 2946
Quoted 8 lines
drivers/net/dsa/b53/b53_common.c +8
-0+static struct dsa_port *b53_preferred_cpu_port (struct dsa_switch *ds) +{ +struct b53_device *dev = ds->priv; + +if (is5301x (dev) &&dsa_is_cpu_port (ds,B53_CPU_PORT ) &&b53_uses_fa_tag (ds,B53_CPU_PORT )) +return dsa_to_port (ds,B53_CPU_PORT ); +return NULL ; +}
[Severity: Medium]
When dev->vlan_filtering is enabled, will hardware VLAN filtering drop VLAN-tagged IPv4 frames that CFP redirects to CPU port 5?
CFP trap rules redirect frames to port 5 without bypassing VLAN filtering, and on B53 ds->vlan_filtering_is_global is true, so enabling VLAN filtering on any bridge enforces VLAN table membership across all ports. Because b53_preferred_cpu_port() assigns port 8 as dp->cpu_dp for all user ports, DSA host VLAN programming only calls b53_vlan_add() for the user port and port 8, leaving BIT(5) unset in dev->vlans[vid].members for any non-default VID.
[ ... ]
Quoted 8 lines
drivers/net/dsa/b53/b53_common.c +3
-1@@ -3385,7 +3773,32 @@ int b53_switch_register(struct b53_device *dev)dev_info (dev->dev,"found switch: %s, rev %i\n" , dev->name, dev->core_rev); -return dsa_register_switch (dev->ds); + ret =dsa_register_switch (dev->ds); +if (ret || !dev->fa_cfp_enabled) +return ret;
drivers/net/dsa/b53/b53_common.c int b53_switch_register(struct b53_device *dev) · line 3788
Quoted 10 lines
drivers/net/dsa/b53/b53_common.c +10
-0+/* Registration replays existing user devices, after their MACs and +* DSA private data are initialized. Keep lookup gated until it finishes. +*/ + dev->fa_netdev_nb.notifier_call = b53_fa_netdev_event; + ret =register_netdevice_notifier (&dev->fa_netdev_nb); +if (ret) + goto unregister_switch; + ret =devm_add_action_or_reset (dev->dev, b53_fa_unregister_notifier, dev); +if (ret) + goto unregister_switch;
[Severity: Medium]
Can b53_fa_netdev_event() run while the switch is being torn down or after b53_switch_shutdown()?
Deferring b53_fa_unregister_notifier() to devres keeps dev->fa_netdev_nb registered with dev->fa_stopping == false throughout dsa_tree_teardown_conduit() and dsa_tree_teardown_ports(), because b53_teardown() only runs later in dsa_tree_teardown_switches(). During system shutdown, b53_switch_shutdown() -> dsa_switch_shutdown() drops the netdev_put() references on each CPU port's conduit without calling b53_teardown() or running devres actions, so any later user port netdevice event will dereference the unreferenced control->conduit and data_cpu->conduit pointers.
drivers/net/dsa/b53/b53_common.c int b53_switch_register(struct b53_device *dev) · line 3797
Quoted 9 lines
drivers/net/dsa/b53/b53_common.c +9
-0+ dev->fa_guards_ready = true; +if (!dev->fa_guards_failed) { +struct dsa_port *control =dsa_to_port (dev->ds,5 ); + +rtnl_lock (); +b53_fa_conduit_state_change (dev->ds, control->conduit, +dsa_port_conduit_is_operational (control)); +rtnl_unlock (); + }
[Severity: Low]
Should dev->fa_guards_ready and dev->fa_guards_failed be accessed under rtnl_lock() here? register_netdevice_notifier() has already dropped rtnl_lock(), so a concurrent netdevice event can run b53_fa_netdev_event() or b53_fa_port() on another CPU while these booleans are updated and read.
Quoted 4 lines
net/dsa/tag_brcm.c +0
-0
[ ... ]
Quoted 7 lines
net/dsa/tag_brcm.c +1
-1@@ -146,9 +150,10 @@ static struct sk_buff *brcm_tag_xmit_ll(struct sk_buff *skb,*/ static struct sk_buff *brcm_tag_rcv_ll (struct sk_buff *skb,struct net_device *dev, -unsigned int offset) +unsigned int offset,bool fa) {
[ ... ]
Quoted 1 line
net/dsa/tag_brcm.c +0
-0@@ -407,7 +416,100 @@ DSA_TAG_DRIVER(brcm_prepend_netdev_ops);
[ ... ]
net/dsa/tag_brcm.c DSA_TAG_DRIVER(brcm_prepend_netdev_ops); · line 470
Quoted 10 lines
net/dsa/tag_brcm.c +10
-0+static struct sk_buff *brcm_fa_tag_rcv (struct sk_buff *skb,struct net_device *dev) +{ +struct dsa_port *cpu = dev->dsa_ptr; +struct brcm_fa_control *control; +struct dsa_port *data_cpu; +unsigned int port; +u8 reason; + +if (cpu->index !=5 ) +return brcm_tag_rcv_ll (skb, dev,ETH_HLEN , true);
[Severity: Medium]
On the cpu->index != 5 path, does brcm_tag_rcv_ll() inspect the 4-byte prepended FA tag instead of the destination MAC when checking is_link_local_ether_addr(eth_hdr(skb)->h_dest)?
net/dsa/tag_brcm.c:brcm_tag_rcv_ll() {
...
/* Remove Broadcom tag and update checksum */
skb_pull_rcsum(skb, BRCM_TAG_LEN);
if (likely(!is_link_local_ether_addr(eth_hdr(skb)->h_dest)))
dsa_default_offload_fwd_mark(skb);
...
}eth_type_trans() on the conduit sets skb->mac_header to the start of the prepended tag, and skb_pull_rcsum(skb, BRCM_TAG_LEN) only advances skb->data; skb->mac_header is not updated until dsa_switch_rcv() runs after cpu_dp->rcv() returns. Because byte 0 of the prepended tag does not have bit 0 set, is_link_local_ether_addr() returns false and link-local control frames (01:80:c2:00:00:xx) on bridged ports get skb->offload_fwd_mark set, preventing the software bridge from forwarding them when STP is disabled or group_fwd_mask is configured.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
[email protected]
AI reviewRe: [PATCH net-next 5/9] net: dsa: add Broadcom FA metadata and IPv4 exception paths
In reply to Florian FainelliThank you for your contribution! Sashiko AI review found 13 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 13 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 7 · Low: 5
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).
- [High] Bridged ports lose every FA exception guard while their CPU- bound traffic still passes through the inline FA.
- [Medium] When FA is enabled, b53_setup_port() and b53_br_leave() put standalone user ports in EAP_MODE_BASIC instead of EAP_MODE_SIMPLIFIED.
- [Medium] On NETDEV_PRE_CHANGEADDR, b53_fa_netdev_event() writes an all- zero TCAM entry over the port's router-MAC allow rule…
- [Medium] If b53_fa_port(dev, port, true) fails in b53_br_leave(), the code logs an error and calls b53_disable_port(), which only sets the…
- [Medium] The TCP SYN/FIN/RST trap rules 0-2 in b53_fa_setup() include CFP_TCAM6_IP_FRAGMENT in the mask with data 0, so they match only…
- [Medium] The commit says it 'keep[s] ordinary data flooding off the auxiliary CPU'.
- [Medium] net: dsa: b53: missing CPU port 5 in non-default VLANs in b53_vlan_add()
- [Medium] net: dsa: tag_brcm: brcm_tag_rcv_ll() reads prepended tag as MAC DA
- [Low] The B53 CFP action and meter RAM programming differs from the reference programming of the same register block.
- [Low] b53_uses_fa_tag() does not follow the DT binding's compatible list.
- [Low] The NET_DSA_TAG_BRCM_FA help text says 'Transmit uses the ordinary prepended Broadcom tag' and 'Enable this for a B53 switch…
- [Low] Plain bool FA state flags are read and written concurrently without a common lock or READ_ONCE/WRITE_ONCE.
- [Low] net: dsa: b53: duplicate CFP rule programming in b53_fa_setup()
--
net: dsa: add Broadcom FA metadata and IPv4 exception paths
This patch adds a brcm-fa DSA tagger for the Northstar flow accelerator miss descriptor. It also adds B53 CFP rules that send TCP SYN/FIN/RST, TTL 0/1, packets longer than 1500 bytes and non-router-MAC IPv4 traffic to port 5/GMAC0, outside the FA. A netdevice notifier and an RCU-protected backend registry in tag_brcm.c coordinate guard and conduit readiness.
Quoted 4 lines
drivers/net/dsa/b53/b53_common.c +0
-0
[ ... ]
drivers/net/dsa/b53/b53_common.c int b53_setup_port(struct dsa_switch *ds, int port) · line 689
Quoted 7 lines
drivers/net/dsa/b53/b53_common.c +2
-1@@ -678,7 +685,8 @@ int b53_setup_port(struct dsa_switch *ds, int port)* dropping frames because it isn't allowed to forward there. */ if (dsa_is_user_port (ds, port)) -b53_set_eap_mode (dev, port,EAP_MODE_SIMPLIFIED ); +b53_set_eap_mode (dev, port, dev->fa_cfp_enabled ?EAP_MODE_BASIC : +EAP_MODE_SIMPLIFIED );
[Severity: Medium]
On FA boards, standalone user ports now get EAP_MODE_BASIC. Does that bring back the problem fixed by commit 4227ea91e2657f ("net: dsa: b53:
prevent standalone from trying to forward to other ports")?
That commit uses EAP_MODE_SIMPLIFIED to send all standalone-port traffic to the CPU. In BASIC mode, a frame that no CFP trap redirects goes through normal ARL forwarding. That covers non-IPv4 traffic such as ARP and IPv6. It also covers IPv4 frames that hit the allow rules, which have no action.
Suppose the DA was learned on a VLAN-unaware bridged port with learning on (shared PVID 0). The ARL forwards the frame to that port, the PVLAN mask blocks it, and the frame is dropped instead of reaching Linux.
b53_br_leave() makes the same change, so ports leaving a bridge are hit too. Two comments no longer match the code: "Force all traffic to go to the CPU port" above this call, and "Enable redirection of unknown SA to the CPU port" in b53_br_leave(). The commit message does not mention this change either.
[ ... ]
Quoted 1 line
drivers/net/dsa/b53/b53_common.c +0
-0@@ -1326,6 +1336,315 @@ int b53_setup_devlink_resources(struct dsa_switch *ds)
[ ... ]
drivers/net/dsa/b53/b53_common.c int b53_setup_devlink_resources(struct dsa_switch *ds) · line 1381
Quoted 3 lines
drivers/net/dsa/b53/b53_common.c +3
-0+static int b53_fa_rule (struct b53_device *dev,unsigned int index, +const u32 data[8 ],const u32 mask[8 ],bool trap) +{
[Severity: Low]
This isn't a bug, but the TCP flag loop open-codes what b53_fa_rule() does with trap set:
- the eight DATA/MASK writes
- both action words and the action commit
- the meter writes and the meter commit
- the TCAM commit
Could this loop just build data and mask and then call b53_fa_rule(dev, rule, data, mask, true)? With two copies, any change to the action or meter programming has to be made twice, and one copy is easy to miss.
[ ... ]
Quoted 7 lines
drivers/net/dsa/b53/b53_common.c +7
-0+ err =b53_write32 (dev,B53_CFP_TCAM_PAGE ,B53_CFP_ACTION (0 ), + trap ?CFP_ACT0_FWD_MAP_REPLACE |CFP_ACT0_DST_PORT5 | +CFP_ACT0_REASON_TERMINATION :0 ); +if (!err) + err =b53_write32 (dev,B53_CFP_TCAM_PAGE ,B53_CFP_ACTION (1 ), + trap ?CFP_ACT1_CLASS_ID (1 ) |CFP_ACT1_FWD_MAP_REPLACE | +CFP_ACT1_DST_PORT5 :0 );
drivers/net/dsa/b53/b53_common.c int b53_setup_devlink_resources(struct dsa_switch *ds) · line 1408
Quoted 10 lines
drivers/net/dsa/b53/b53_common.c +10
-0+if (!err) + err =b53_fa_cfp_write (dev, index,CFP_ACC_ACTION ); +if (!err) + err =b53_write32 (dev,B53_CFP_TCAM_PAGE ,B53_CFP_METER ,0 ); +if (!err) + err =b53_write32 (dev,B53_CFP_TCAM_PAGE ,B53_CFP_METER +4 ,0 ); +if (!err) + err =b53_fa_cfp_write (dev, index,CFP_ACC_METER ); +return err ?:b53_fa_cfp_write (dev, index,CFP_ACC_TCAM ); +}
[Severity: Medium]
With vlan_filtering enabled, can these redirects to port 5 still reach GMAC0 for VLAN-tagged traffic?
The trap actions do not set VLAN bypass. The comment in b53_fa_setup() says VLAN filtering is preserved on purpose.
Port 5 is only a member of VID 0, which it gets from the b53_for_each_port() loop in b53_setup(). For any other VID, b53_vlan_add() is called for the user port and for its cpu_dp. b53_preferred_cpu_port() makes cpu_dp port 8 for every user port, so BIT(5) never ends up in dev->vlans[vid].members.
b53 sets ds->vlan_filtering_is_global. Enabling vlan_filtering on any bridge on the switch therefore also turns on VLAN table enforcement for the standalone ports, and those are the only ports with CFP classification enabled.
Take a standalone port with an 802.1Q upper. Its tagged SYN/FIN/RST, TTL 0/1 and oversized IPv4 frames are redirected to a port that is not a member of their VLAN. So is everything caught by B53_FA_DEFAULT_RULE. Wouldn't the switch drop these frames instead of delivering them to Linux?
Should port 5 be kept in step with port 8 in b53_vlan_add() and b53_vlan_del() when fa_cfp_enabled is set? Or should the trap action bypass the VLAN check for port 5 after all?
[Severity: Low]
Is the policer meant to stay enabled here? The register layout matchesbcm_sf2: ACT_POL_DATA0/1/2 sit at 0x50/0x54/0x58 and RATE_METER0/1 at 0x60/0x64. In that layout, writing 0 to RATE_METER0 selects POLICER_MODE_RFC2698. bcm_sf2 does this instead:
drivers/net/dsa/bcm_sf2_cfp.c:bcm_sf2_cfp_act_pol_set() {
...
core_writel(priv, 0, CORE_ACT_POL_DATA2);
...
/* Disable the policer */
core_writel(priv, POLICER_MODE_DISABLE, CORE_RATE_METER0);
...
}Here B53_CFP_ACTION(2) is never written before the action RAM commit, and RATE_METER2..6 are never written at all.
Would every rule, including the allow rules, then get a zero-rate trTCM? Would the third action word (MAC limit bypass, TC change, PCP/DEI remark) come from whatever the staging register happens to hold? The TCP flag loop in b53_fa_setup() open-codes the same sequence.
[ ... ]
Quoted 2 lines
drivers/net/dsa/b53/b53_common.c +2
-0+static int b53_fa_setup (struct b53_device *dev) +{
[ ... ]
drivers/net/dsa/b53/b53_common.c int b53_setup_devlink_resources(struct dsa_switch *ds) · line 1500
Quoted 10 lines
drivers/net/dsa/b53/b53_common.c +10
-0+for (rule =0 ; rule <3 ; rule++) { +memset (data,0 ,sizeof (data)); +memset (mask,0 ,sizeof (mask)); + data[0 ] =CFP_TCAM0_VALID |CFP_TCAM0_SLICE1 |CFP_TCAM0_UDF0_FLAG (rule); +/* Slice 1; FIN, SYN or RST. */ + mask[0 ] =CFP_TCAM0_VALID |CFP_TCAM0_SLICE_MASK |CFP_TCAM0_UDF0_FLAG (rule); + data[5 ] =CFP_TCAM5_UDF_VALID (0 );/* UDF A0 valid. */ + mask[5 ] =CFP_TCAM5_UDF_VALID (0 ); + data[6 ] =FIELD_PREP (CFP_TCAM6_IP_PROTOCOL ,IPPROTO_TCP ); + mask[6 ] =CFP_TCAM6_L3_FRAMING |CFP_TCAM6_IP_PROTOCOL |CFP_TCAM6_IP_FRAGMENT ;
[Severity: Medium]CFP_TCAM6_IP_FRAGMENT is in the mask with data 0, so these SYN/FIN/RST traps match only unfragmented packets. b53_fa_guards() has no rule that sends IPv4 fragments to port 5 either.
Take a first fragment (MF set, offset 0) with SYN, FIN or RST, TTL above 1, at most 1500 bytes, addressed to the port's router MAC. It would match the allow rule and take the FA inline path instead of GMAC0.
If the original FA looks up first fragments, can TCP control segments for a live tuple skip the exception path and Linux conntrack?
Two later pieces of the series seem to assume fragments are trapped:
- The documentation says "IP options and fragments retire pairs by their L3 identity before Linux can process a reused tuple".
- fa_control_receive() in the backend handles fragments.
[ ... ]
drivers/net/dsa/b53/b53_common.c int b53_setup_devlink_resources(struct dsa_switch *ds) · line 1537
Quoted 4 lines
drivers/net/dsa/b53/b53_common.c +4
-0+/* Ordinary flooding must reach only the data CPU, not both MACs. */ +b53_port_set_ucast_flood (dev,5 , false); +b53_port_set_mcast_flood (dev,5 , false); + err =b53_write8 (dev,B53_CTRL_PAGE ,B53_PORT_CTRL (5 ),PORT_CTRL_RX_UCST_EN );
[Severity: Medium]
Do the RX_*CST_EN bits do anything on port 5? b53_regs.h documents them as port 8 only:
#define PORT_CTRL_RX_BCST_EN BIT(2) /* Broadcast RX (P8 only) */
At the same time, b53_enable_port() and b53_br_leave() add BIT(5) to the PVLAN egress mask of every user port:
if (dev->fa_cfp_enabled && (dev->fa_cfp_ports & BIT(port))) pvlan |= BIT(5);
b53_br_join() keeps that bit through its read-modify-write. b53 has no broadcast flood mask, so broadcast frames would seem to egress both port 5 and port 8.
brcm_fa_tag_rcv() passes port 5 frames without BRCM_EG_RC_PROT_TERM up the stack. Would Linux then receive ARP, DHCP and other broadcasts twice on the user netdev, and forward them twice when the port is bridged? That would not match "keep ordinary data flooding off the auxiliary CPU" in the commit message.
[ ... ]
Quoted 9 lines
drivers/net/dsa/b53/b53_common.c +9
-0+static int b53_fa_port (struct b53_device *dev,int port,bool standalone) +{ +struct dsa_port *control =dsa_to_port (dev->ds,5 ); +bool ready; +u16 ports; +int err; + +if (!dev->fa_cfp_enabled) +return 0 ;
drivers/net/dsa/b53/b53_common.c int b53_setup_devlink_resources(struct dsa_switch *ds) · line 1573
Quoted 10 lines
drivers/net/dsa/b53/b53_common.c +10
-0+ ports = dev->fa_cfp_ports & ~BIT (port); +if (standalone) + ports |=BIT (port); + ready =b53_fa_ready (dev,dsa_port_conduit_is_operational (control)); + err =b53_write16 (dev,B53_CFP_PAGE ,B53_CFP_CTRL , + ready ? ports :0 ); +if (!err) + dev->fa_cfp_ports = ports; +return err; +}
[Severity: High]
What protects a bridged port after b53_br_join() calls b53_fa_port(dev, port, false)?
Clearing the port's bit in B53_CFP_CTRL turns off all of its guard rules for as long as it stays bridged: SYN/FIN/RST, TTL 0/1, length, the router-MAC allow rule and the default IPv4 trap.
b53_fa_conduit_state_change() and b53_fa_netdev_event() both call brcm_fa_control_set_ready(data->conduit, false) before writing CFP_CTRL. This function does not. FA readiness therefore stays true, and live entries are not retired before this port's exception path goes away.
Port 8 is still the preferred CPU port. It still has unicast and multicast flooding on from b53_setup_port(), and it is still in every PVLAN mask.
A host on the bridged port could send a frame to a standalone port's router MAC, carrying the tuple of a flow offloaded for that port. The FA key has no input port, so would the frame be forwarded and NATed in hardware without Linux seeing it? TTL 0/1, FIN/RST and oversized packets on that tuple would get through the same way.
This looks like the "live tuple from bypassing Linux ingress policy on another switch port" case that the commit message says is prevented. It also breaks "Disable admission and retire entries before removing any exception path". The later patches in the series leave this code as is, and the documentation patch only says that CFP classification is disabled on bridge members.
[ ... ]
Quoted 2 lines
drivers/net/dsa/b53/b53_common.c +2
-0+static int b53_fa_netdev_event (struct notifier_block *nb,unsigned long event,void *ptr) +{
[ ... ]
Quoted 4 lines
drivers/net/dsa/b53/b53_common.c +4
-0+ control =dsa_to_port (dev->ds,5 ); + data_cpu =dsa_to_port (dev->ds,8 ); +brcm_fa_control_set_ready (data_cpu->conduit, false); +if (event !=NETDEV_PRE_CHANGEADDR ) {
[ ... ]
drivers/net/dsa/b53/b53_common.c
Quoted 2 lines
drivers/net/dsa/b53/b53_common.c +2
-0+ } + err =b53_fa_rule (dev,B53_FA_ALLOW_BASE + dp->index, data, mask, false);
[Severity: Medium]
What brings back the allow rule and FA readiness if the address change fails after NETDEV_PRE_CHANGEADDR?
On that event, this code writes an all-zero entry over the port's allow rule and drops readiness for the whole data conduit. Only a later NETDEV_CHANGEADDR undoes this.
netif_set_mac_address() can return early without sending NETDEV_CHANGEADDR:
net/core/dev.c:netif_set_mac_address() {
...
err = netif_pre_changeaddr_notify(dev, ss->__data, extack);
if (err)
return err;
if (memcmp(dev->dev_addr, ss->__data, dev->addr_len)) {
err = ops->ndo_set_mac_address(dev, ss);
if (err)
return err;
...
}dsa_user_set_mac_address() returns -EADDRNOTAVAIL for an invalid address, so "ip link set lanX address 01:00:00:00:00:00" is enough to trigger this. A later notifier vetoing PRE_CHANGEADDR has the same effect.
Would all hardware flows then stay retired until an unrelated NETDEV_UP or NETDEV_CHANGEADDR event, or a control conduit state change?
[ ... ]
drivers/net/dsa/b53/b53_common.c void b53_br_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge) · line 2783
Quoted 10 lines
drivers/net/dsa/b53/b53_common.c +4
-0@@ -2439,6 +2775,10 @@ void b53_br_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge) vl->members |=BIT (port);b53_set_vlan_entry (dev, pvid, vl); } +if (b53_fa_port (dev, port, true)) { +dev_err (ds->dev,"failed to restore FA classification on port %d\n" , port); +b53_disable_port (ds, port); + } }EXPORT_SYMBOL (b53_br_leave);
[Severity: Medium]
Is b53_disable_port() enough on this failure path? It only sets the RX/TX disable bits in PORT_CTRL. It does not set fa_guards_failed or drop FA readiness, and fa_cfp_ports still lacks this port's bit.
The next ndo_open runs b53_enable_port(), which clears those bits:
b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), 0);
The port is then standalone with no CFP classification. Its traffic goes through port 8 and the FA while readiness is still true.
The notifier failure path sets fa_guards_failed for this kind of case. Should this path set it too?
[ ... ]
Quoted 1 line
drivers/net/dsa/b53/b53_common.c +0
-0@@ -2564,6 +2905,46 @@ static bool b53_can_enable_brcm_tags(struct dsa_switch *ds, int port,
[ ... ]
Quoted 2 lines
drivers/net/dsa/b53/b53_common.c +2
-0+static bool b53_uses_fa_tag (struct dsa_switch *ds,int port) +{
[ ... ]
drivers/net/dsa/b53/b53_common.c static bool b53_can_enable_brcm_tags(struct dsa_switch *ds, int port, · line 2929
Quoted 6 lines
drivers/net/dsa/b53/b53_common.c +6
-0+ ethernet =of_parse_phandle (node,"ethernet" ,0 ); + fa =of_parse_phandle (ethernet,"brcm,flow-accelerator" ,0 ); + enabled =IS_ENABLED (CONFIG_BCM_NS_FA ) &&of_device_is_available (fa) && + (dev->chip_id ==BCM53011_DEVICE_ID || + dev->chip_id ==BCM53012_DEVICE_ID || + (is5301x (dev) &&of_device_is_compatible (fa,"brcm,bcm4708-fa" )));
[Severity: Low]
Should this check use the compatibles listed in the binding? brcm,bcm4708-fa.yaml allows brcm,bcm4708-fa, brcm,bcm53011-fa and brcm,bcm53012-fa, and its example uses brcm,bcm53011-fa. bcm_ns_fa_init() later in the series accepts all three.
As written, BCM53011/BCM53012 accept any available node without looking at its compatible. BCM53010/53018/53019 accept only brcm,bcm4708-fa.
That leads to two mismatched setups:
- A 5301x board whose DT uses brcm,bcm53011-fa or brcm,bcm53012-fa gets the FA backend set up on GMAC2, while b53 uses the ordinary brcm tag and installs no CFP guards.
- A 53011/53012 board with an unrelated compatible gets FA tagging, and then bgmac probe fails.
[ ... ]
Quoted 8 lines
drivers/net/dsa/b53/b53_common.c +3
-1@@ -3385,7 +3773,32 @@ int b53_switch_register(struct b53_device *dev)dev_info (dev->dev,"found switch: %s, rev %i\n" , dev->name, dev->core_rev); -return dsa_register_switch (dev->ds); + ret =dsa_register_switch (dev->ds); +if (ret || !dev->fa_cfp_enabled) +return ret;
[ ... ]
drivers/net/dsa/b53/b53_common.c int b53_switch_register(struct b53_device *dev) · line 3790
Quoted 8 lines
drivers/net/dsa/b53/b53_common.c +8
-0+ ret =register_netdevice_notifier (&dev->fa_netdev_nb); +if (ret) + goto unregister_switch; + ret =devm_add_action_or_reset (dev->dev, b53_fa_unregister_notifier, dev); +if (ret) + goto unregister_switch; + dev->fa_guards_ready = true; +if (!dev->fa_guards_failed) {
[Severity: Low]
These plain bool flags are accessed concurrently with no common lock and no READ_ONCE()/WRITE_ONCE():
- Here, fa_guards_ready is written and fa_guards_failed is read outside rtnl, after b53_fa_netdev_event() is already live.
- The notifier reads both flags under rtnl and may write fa_guards_failed.
- b53_teardown() writes dev->fa_stopping without rtnl, while b53_fa_netdev_event() reads it for every netdevice event in the system.
The final readiness looks correct, because b53_fa_ready() is evaluated again under rtnl_lock() below. Won't KCSAN still report these accesses as data races?
[ ... ]
Quoted 6 lines
net/dsa/Kconfig +0
-0@@ -69,6 +69,15 @@ config NET_DSA_TAG_BRCM_PREPEND Broadcom switches which places the tag before the Ethernet header
net/dsa/Kconfig config NET_DSA_TAG_BRCM_PREPEND · line 79
Quoted 10 lines
net/dsa/Kconfig +8
-0(prepended). +config NET_DSA_TAG_BRCM_FA + tristate "Tag driver for the Broadcom Northstar flow accelerator" + select NET_DSA_TAG_BRCM_COMMON + help + Support the prepended four-byte FA metadata tag on Northstar GMAC2. + The receive format includes a hash, bucket, parser status, and input + switch port. Transmit uses the ordinary prepended Broadcom tag. + Enable this for a B53 switch explicitly connected to an accelerator.
[Severity: Low]
This isn't a bug, but the help text does not match the code. brcm_fa_tag_xmit() puts the tag inside the frame for user ports behind CPU port 5:
return brcm_tag_xmit_ll(skb, dev, dp->cpu_dp->index == 5 ? 2 * ETH_ALEN : 0);
drivers/net/dsa/b53/Kconfig also selects NET_DSA_TAG_BRCM_FA unconditionally, so the user has nothing to enable. Could the help text be updated to match?
[ ... ]
Quoted 94 lines
net/dsa/tag_brcm.c +87
-0@@ -407,7 +416,100 @@ DSA_TAG_DRIVER(brcm_prepend_netdev_ops);MODULE_ALIAS_DSA_TAG_DRIVER (DSA_TAG_PROTO_BRCM_PREPEND ,BRCM_PREPEND_NAME );#endif +#if IS_ENABLED (CONFIG_NET_DSA_TAG_BRCM_FA ) +static LIST_HEAD (brcm_fa_controls); +static DEFINE_MUTEX (brcm_fa_control_lock); + +void brcm_fa_control_register (struct brcm_fa_control *control) +{ +mutex_lock (&brcm_fa_control_lock); +list_add_rcu (&control->list, &brcm_fa_controls); +mutex_unlock (&brcm_fa_control_lock); +} +EXPORT_SYMBOL_GPL (brcm_fa_control_register); + +void brcm_fa_control_unregister (struct brcm_fa_control *control) +{ +mutex_lock (&brcm_fa_control_lock); +list_del_rcu (&control->list); +mutex_unlock (&brcm_fa_control_lock); +synchronize_net (); +} +EXPORT_SYMBOL_GPL (brcm_fa_control_unregister); + +void brcm_fa_control_set_ready (struct net_device *conduit,bool ready) +{ +struct brcm_fa_control *control; + +/* State callbacks can sleep while retiring hardware entries. */ +mutex_lock (&brcm_fa_control_lock); +list_for_each_entry (control, &brcm_fa_controls, list) +if (control->conduit == conduit && control->state_change) + control->state_change (control->priv, ready); +mutex_unlock (&brcm_fa_control_lock); +} +EXPORT_SYMBOL_GPL (brcm_fa_control_set_ready); + +static struct sk_buff *brcm_fa_tag_xmit (struct sk_buff *skb, +struct net_device *dev) +{ +struct dsa_port *dp =dsa_user_to_port (dev); + +return brcm_tag_xmit_ll (skb, dev, dp->cpu_dp->index ==5 ?2 *ETH_ALEN :0 ); +} + +static struct sk_buff *brcm_fa_tag_rcv (struct sk_buff *skb,struct net_device *dev) +{ +struct dsa_port *cpu = dev->dsa_ptr; +struct brcm_fa_control *control; +struct dsa_port *data_cpu; +unsigned int port; +u8 reason; + +if (cpu->index !=5 ) +return brcm_tag_rcv_ll (skb, dev,ETH_HLEN , true); +if (!pskb_may_pull (skb,BRCM_TAG_LEN )) + goto drop; + reason = skb->data[0 ];/* Embedded tag byte 2 after eth_type_trans(). */ + port = skb->data[1 ] &BRCM_EG_PID_MASK ; + skb =brcm_tag_rcv_ll (skb, dev,2 , false); +if (!skb) +return NULL ; +dsa_strip_etype_header (skb,BRCM_TAG_LEN ); +skb_set_mac_header (skb, -ETH_HLEN ); +if (!(reason &BRCM_EG_RC_PROT_TERM )) +return skb; + data_cpu =dsa_to_port (cpu->ds,8 ); +if (!data_cpu || !dsa_port_is_cpu (data_cpu)) +return skb; +rcu_read_lock (); +list_for_each_entry_rcu (control, &brcm_fa_controls, list) +if (control->conduit == data_cpu->conduit) + control->receive (control->priv, skb, port); +rcu_read_unlock (); +return skb; +drop: +kfree_skb (skb); +return NULL ; +} + +static const struct dsa_device_ops brcm_fa_netdev_ops = { + .name =BRCM_FA_NAME , + .proto =DSA_TAG_PROTO_BRCM_FA , + .xmit = brcm_fa_tag_xmit, + .rcv = brcm_fa_tag_rcv, + .needed_headroom =BRCM_TAG_LEN , + .promisc_on_conduit = true, +}; + +DSA_TAG_DRIVER (brcm_fa_netdev_ops);
net/dsa/tag_brcm.c DSA_TAG_DRIVER(brcm_prepend_netdev_ops); · line 515
Quoted 10 lines
net/dsa/tag_brcm.c +6
-0+MODULE_ALIAS_DSA_TAG_DRIVER (DSA_TAG_PROTO_BRCM_FA ,BRCM_FA_NAME ); +#endif +static struct dsa_tag_driver *dsa_tag_driver_array[] = { +#if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_FA) + &DSA_TAG_DRIVER_NAME (brcm_fa_netdev_ops), +#endif #if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM) &DSA_TAG_DRIVER_NAME (brcm_netdev_ops), #endif
[Severity: Medium]
Does the link-local check at the end of brcm_tag_rcv_ll() look at the right bytes for this call?
With offset == ETH_HLEN the tag is prepended. eth_type_trans() on the conduit therefore left skb->mac_header pointing at the four-byte tag, not at the destination MAC. skb_pull_rcsum() only moves skb->data. After the pull, eth_hdr(skb)->h_dest covers the tag plus the first two bytes of the real DA. is_link_local_ether_addr() then does not recognise 01:80:c2:00:00:xx frames.
Port 8 is the CPU port for all user ports on these boards. STP BPDUs, LLDP, LACP and EAPOL received on bridged ports would all get offload_fwd_mark set.
The switch only trapped these frames and did not forward them. With the mark set, the bridge also won't forward them in software to other ports on the same switch. That matters with STP disabled or with a group_fwd_mask configured.
The port 5 branch in brcm_fa_tag_rcv() fixes up the MAC header with skb_set_mac_header(), but this branch does not.
brcm_tag_rcv_prepend() seems to have the same problem already, so this may need its own fix in brcm_tag_rcv_ll(). After the pull, it could read the DA from skb->data - ETH_HLEN, or reset the MAC header first. Which would you prefer?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116222519.1416501-1-florian.fainelli%40broadcom.com
Florian Fainelli
maintainerRe: [PATCH net-next 5/9] net: dsa: add Broadcom FA metadata and IPv4 exception paths
Quoted 599 lines · On 11/17/26 15:29, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 13 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 7 · Low: 5
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).
- [High] Bridged ports lose every FA exception guard while their CPU- bound traffic still passes through the inline FA.
- [Medium] When FA is enabled,b53_setup_port()andb53_br_leave()put standalone user ports inEAP_MODE_BASICinstead ofEAP_MODE_SIMPLIFIED.
- [Medium] OnNETDEV_PRE_CHANGEADDR,b53_fa_netdev_event()writes an all- zero TCAM entry over the port's router-MAC allow rule…
- [Medium] Ifb53_fa_port(dev, port, true)fails inb53_br_leave(), the code logs an error and callsb53_disable_port(), which only sets the…
- [Medium] The TCP SYN/FIN/RST trap rules 0-2 inb53_fa_setup()includeCFP_TCAM6_IP_FRAGMENTin the mask with data 0, so they match only…
- [Medium] The commit says it 'keep[s] ordinary data flooding off the auxiliary CPU'.
- [Medium] net: dsa: b53: missing CPU port 5 in non-default VLANs inb53_vlan_add()
- [Medium] net: dsa:tag_brcm:brcm_tag_rcv_ll()reads prepended tag as MAC DA
- [Low] The B53 CFP action and meter RAM programming differs from the reference programming of the same register block.
- [Low]b53_uses_fa_tag()does not follow the DT binding's compatible list.
- [Low] TheNET_DSA_TAG_BRCM_FAhelp text says 'Transmit uses the ordinary prepended Broadcom tag' and 'Enable this for a B53 switch…
- [Low] Plain bool FA state flags are read and written concurrently without a common lock or READ_ONCE/WRITE_ONCE.
- [Low] net: dsa: b53: duplicate CFP rule programming inb53_fa_setup()--
net: dsa: add Broadcom FA metadata and IPv4 exception paths
This patch adds a brcm-fa DSA tagger for the Northstar flow accelerator miss descriptor. It also adds B53 CFP rules that send TCP SYN/FIN/RST, TTL 0/1, packets longer than 1500 bytes and non-router-MAC IPv4 traffic to port 5/GMAC0, outside the FA. A netdevice notifier and an RCU-protected backend registry in
tag_brcm.ccoordinate guard and conduit readiness.Quoted 4 lines
drivers/net/dsa/b53/b53_common.c +0
-0[ ... ]
drivers/net/dsa/b53/b53_common.c int b53_setup_port(struct dsa_switch *ds, int port) · line 689
Quoted 7 lines
drivers/net/dsa/b53/b53_common.c +2
-1@@ -678,7 +685,8 @@ int b53_setup_port(struct dsa_switch *ds, int port)* dropping frames because it isn't allowed to forward there. */ if (dsa_is_user_port (ds, port)) -b53_set_eap_mode (dev, port,EAP_MODE_SIMPLIFIED ); +b53_set_eap_mode (dev, port, dev->fa_cfp_enabled ?EAP_MODE_BASIC : +EAP_MODE_SIMPLIFIED );[Severity: Medium]
On FA boards, standalone user ports now getEAP_MODE_BASIC. Does that bring back the problem fixed by commit4227ea91e2657f("net: dsa: b53:
prevent standalone from trying to forward to other ports")?That commit uses
EAP_MODE_SIMPLIFIEDto send all standalone-port traffic to the CPU. In BASIC mode, a frame that no CFP trap redirects goes through normal ARL forwarding. That covers non-IPv4 traffic such as ARP and IPv6. It also covers IPv4 frames that hit the allow rules, which have no action.Suppose the DA was learned on a VLAN-unaware bridged port with learning on (shared PVID 0). The ARL forwards the frame to that port, the PVLAN mask blocks it, and the frame is dropped instead of reaching Linux.
b53_br_leave()makes the same change, so ports leaving a bridge are hit too. Two comments no longer match the code: "Force all traffic to go to the CPU port" above this call, and "Enable redirection of unknown SA to the CPU port" inb53_br_leave(). The commit message does not mention this change either.[ ... ]
Quoted 1 line
drivers/net/dsa/b53/b53_common.c +0
-0@@ -1326,6 +1336,315 @@ int b53_setup_devlink_resources(struct dsa_switch *ds)[ ... ]
drivers/net/dsa/b53/b53_common.c int b53_setup_devlink_resources(struct dsa_switch *ds) · line 1381
Quoted 3 lines
drivers/net/dsa/b53/b53_common.c +3
-0+static int b53_fa_rule (struct b53_device *dev,unsigned int index, +const u32 data[8 ],const u32 mask[8 ],bool trap) +{[Severity: Low]
This isn't a bug, but the TCP flag loop open-codes whatb53_fa_rule()does with trap set:- the eight DATA/MASK writes
- both action words and the action commit
- the meter writes and the meter commit
- the TCAM commitCould this loop just build data and mask and then call
b53_fa_rule(dev, rule, data, mask, true)? With two copies, any change to the action or meter programming has to be made twice, and one copy is easy to miss.[ ... ]
Quoted 7 lines
drivers/net/dsa/b53/b53_common.c +7
-0+ err =b53_write32 (dev,B53_CFP_TCAM_PAGE ,B53_CFP_ACTION (0 ), + trap ?CFP_ACT0_FWD_MAP_REPLACE |CFP_ACT0_DST_PORT5 | +CFP_ACT0_REASON_TERMINATION :0 ); +if (!err) + err =b53_write32 (dev,B53_CFP_TCAM_PAGE ,B53_CFP_ACTION (1 ), + trap ?CFP_ACT1_CLASS_ID (1 ) |CFP_ACT1_FWD_MAP_REPLACE | +CFP_ACT1_DST_PORT5 :0 );drivers/net/dsa/b53/b53_common.c int b53_setup_devlink_resources(struct dsa_switch *ds) · line 1408
Quoted 10 lines
drivers/net/dsa/b53/b53_common.c +10
-0+if (!err) + err =b53_fa_cfp_write (dev, index,CFP_ACC_ACTION ); +if (!err) + err =b53_write32 (dev,B53_CFP_TCAM_PAGE ,B53_CFP_METER ,0 ); +if (!err) + err =b53_write32 (dev,B53_CFP_TCAM_PAGE ,B53_CFP_METER +4 ,0 ); +if (!err) + err =b53_fa_cfp_write (dev, index,CFP_ACC_METER ); +return err ?:b53_fa_cfp_write (dev, index,CFP_ACC_TCAM ); +}[Severity: Medium]
Withvlan_filteringenabled, can these redirects to port 5 still reach GMAC0 for VLAN-tagged traffic?The trap actions do not set VLAN bypass. The comment in
b53_fa_setup()says VLAN filtering is preserved on purpose.Port 5 is only a member of VID 0, which it gets from the
b53_for_each_port()loop inb53_setup(). For any other VID,b53_vlan_add()is called for the user port and for itscpu_dp.b53_preferred_cpu_port()makescpu_dpport 8 for every user port, so BIT(5) never ends up in dev->vlans[vid].members.b53 sets
ds->vlan_filtering_is_global. Enablingvlan_filteringon any bridge on the switch therefore also turns on VLAN table enforcement for the standalone ports, and those are the only ports with CFP classification enabled.Take a standalone port with an 802.1Q upper. Its tagged SYN/FIN/RST, TTL 0/1 and oversized IPv4 frames are redirected to a port that is not a member of their VLAN. So is everything caught by
B53_FA_DEFAULT_RULE. Wouldn't the switch drop these frames instead of delivering them to Linux?Should port 5 be kept in step with port 8 in
b53_vlan_add()andb53_vlan_del()whenfa_cfp_enabledis set? Or should the trap action bypass the VLAN check for port 5 after all?[Severity: Low]
Is the policer meant to stay enabled here? The register layout matchesbcm_sf2: ACT_POL_DATA0/1/2 sit at 0x50/0x54/0x58 and RATE_METER0/1 at 0x60/0x64. In that layout, writing 0 toRATE_METER0selectsPOLICER_MODE_RFC2698.bcm_sf2does this instead:drivers/net/dsa/bcm_sf2_cfp.c:bcm_sf2_cfp_act_pol_set() { ... core_writel(priv, 0, CORE_ACT_POL_DATA2); ... /* Disable the policer */ core_writel(priv, POLICER_MODE_DISABLE, CORE_RATE_METER0); ... }Here
B53_CFP_ACTION(2)is never written before the action RAM commit, and RATE_METER2..6 are never written at all.Would every rule, including the allow rules, then get a zero-rate trTCM? Would the third action word (MAC limit bypass, TC change, PCP/DEI remark) come from whatever the staging register happens to hold? The TCP flag loop in
b53_fa_setup()open-codes the same sequence.[ ... ]
Quoted 2 lines
drivers/net/dsa/b53/b53_common.c +2
-0+static int b53_fa_setup (struct b53_device *dev) +{[ ... ]
drivers/net/dsa/b53/b53_common.c int b53_setup_devlink_resources(struct dsa_switch *ds) · line 1500
Quoted 10 lines
drivers/net/dsa/b53/b53_common.c +10
-0+for (rule =0 ; rule <3 ; rule++) { +memset (data,0 ,sizeof (data)); +memset (mask,0 ,sizeof (mask)); + data[0 ] =CFP_TCAM0_VALID |CFP_TCAM0_SLICE1 |CFP_TCAM0_UDF0_FLAG (rule); +/* Slice 1; FIN, SYN or RST. */ + mask[0 ] =CFP_TCAM0_VALID |CFP_TCAM0_SLICE_MASK |CFP_TCAM0_UDF0_FLAG (rule); + data[5 ] =CFP_TCAM5_UDF_VALID (0 );/* UDF A0 valid. */ + mask[5 ] =CFP_TCAM5_UDF_VALID (0 ); + data[6 ] =FIELD_PREP (CFP_TCAM6_IP_PROTOCOL ,IPPROTO_TCP ); + mask[6 ] =CFP_TCAM6_L3_FRAMING |CFP_TCAM6_IP_PROTOCOL |CFP_TCAM6_IP_FRAGMENT ;[Severity: Medium]
CFP_TCAM6_IP_FRAGMENTis in the mask with data 0, so these SYN/FIN/RST traps match only unfragmented packets.b53_fa_guards()has no rule that sends IPv4 fragments to port 5 either.Take a first fragment (MF set, offset 0) with SYN, FIN or RST, TTL above 1, at most 1500 bytes, addressed to the port's router MAC. It would match the allow rule and take the FA inline path instead of GMAC0.
If the original FA looks up first fragments, can TCP control segments for a live tuple skip the exception path and Linux conntrack?
Two later pieces of the series seem to assume fragments are trapped:
- The documentation says "IP options and fragments retire pairs by their L3 identity before Linux can process a reused tuple".
-fa_control_receive()in the backend handles fragments.[ ... ]
drivers/net/dsa/b53/b53_common.c int b53_setup_devlink_resources(struct dsa_switch *ds) · line 1537
Quoted 4 lines
drivers/net/dsa/b53/b53_common.c +4
-0+/* Ordinary flooding must reach only the data CPU, not both MACs. */ +b53_port_set_ucast_flood (dev,5 , false); +b53_port_set_mcast_flood (dev,5 , false); + err =b53_write8 (dev,B53_CTRL_PAGE ,B53_PORT_CTRL (5 ),PORT_CTRL_RX_UCST_EN );[Severity: Medium]
Do the RX_*CST_EN bits do anything on port 5?b53_regs.hdocuments them as port 8 only:#define
PORT_CTRL_RX_BCST_ENBIT(2) /* Broadcast RX (P8 only) */At the same time,
b53_enable_port()andb53_br_leave()add BIT(5) to the PVLAN egress mask of every user port:if (dev->fa_cfp_enabled && (dev->fa_cfp_ports & BIT(port))) pvlan |= BIT(5);
b53_br_join()keeps that bit through its read-modify-write. b53 has no broadcast flood mask, so broadcast frames would seem to egress both port 5 and port 8.
brcm_fa_tag_rcv()passes port 5 frames withoutBRCM_EG_RC_PROT_TERMup the stack. Would Linux then receive ARP, DHCP and other broadcasts twice on the user netdev, and forward them twice when the port is bridged? That would not match "keep ordinary data flooding off the auxiliary CPU" in the commit message.[ ... ]
Quoted 9 lines
drivers/net/dsa/b53/b53_common.c +9
-0+static int b53_fa_port (struct b53_device *dev,int port,bool standalone) +{ +struct dsa_port *control =dsa_to_port (dev->ds,5 ); +bool ready; +u16 ports; +int err; + +if (!dev->fa_cfp_enabled) +return 0 ;drivers/net/dsa/b53/b53_common.c int b53_setup_devlink_resources(struct dsa_switch *ds) · line 1573
Quoted 10 lines
drivers/net/dsa/b53/b53_common.c +10
-0+ ports = dev->fa_cfp_ports & ~BIT (port); +if (standalone) + ports |=BIT (port); + ready =b53_fa_ready (dev,dsa_port_conduit_is_operational (control)); + err =b53_write16 (dev,B53_CFP_PAGE ,B53_CFP_CTRL , + ready ? ports :0 ); +if (!err) + dev->fa_cfp_ports = ports; +return err; +}[Severity: High]
What protects a bridged port afterb53_br_join()callsb53_fa_port(dev, port, false)?Clearing the port's bit in
B53_CFP_CTRLturns off all of its guard rules for as long as it stays bridged: SYN/FIN/RST, TTL 0/1, length, the router-MAC allow rule and the default IPv4 trap.
b53_fa_conduit_state_change()andb53_fa_netdev_event()both callbrcm_fa_control_set_ready(data->conduit, false)before writingCFP_CTRL. This function does not. FA readiness therefore stays true, and live entries are not retired before this port's exception path goes away.Port 8 is still the preferred CPU port. It still has unicast and multicast flooding on from
b53_setup_port(), and it is still in every PVLAN mask.A host on the bridged port could send a frame to a standalone port's router MAC, carrying the tuple of a flow offloaded for that port. The FA key has no input port, so would the frame be forwarded and NATed in hardware without Linux seeing it? TTL 0/1, FIN/RST and oversized packets on that tuple would get through the same way.
This looks like the "live tuple from bypassing Linux ingress policy on another switch port" case that the commit message says is prevented. It also breaks "Disable admission and retire entries before removing any exception path". The later patches in the series leave this code as is, and the documentation patch only says that CFP classification is disabled on bridge members.
[ ... ]
Quoted 2 lines
drivers/net/dsa/b53/b53_common.c +2
-0+static int b53_fa_netdev_event (struct notifier_block *nb,unsigned long event,void *ptr) +{[ ... ]
Quoted 4 lines
drivers/net/dsa/b53/b53_common.c +4
-0+ control =dsa_to_port (dev->ds,5 ); + data_cpu =dsa_to_port (dev->ds,8 ); +brcm_fa_control_set_ready (data_cpu->conduit, false); +if (event !=NETDEV_PRE_CHANGEADDR ) {[ ... ]
drivers/net/dsa/b53/b53_common.c
Quoted 2 lines
drivers/net/dsa/b53/b53_common.c +2
-0+ } + err =b53_fa_rule (dev,B53_FA_ALLOW_BASE + dp->index, data, mask, false);[Severity: Medium]
What brings back the allow rule and FA readiness if the address change fails afterNETDEV_PRE_CHANGEADDR?On that event, this code writes an all-zero entry over the port's allow rule and drops readiness for the whole data conduit. Only a later
NETDEV_CHANGEADDRundoes this.
netif_set_mac_address()can return early without sendingNETDEV_CHANGEADDR:net/core/dev.c:netif_set_mac_address() { ... err = netif_pre_changeaddr_notify(dev, ss->__data, extack); if (err) return err; if (memcmp(dev->dev_addr, ss->__data, dev->addr_len)) { err = ops->ndo_set_mac_address(dev, ss); if (err) return err; ... }
dsa_user_set_mac_address()returns-EADDRNOTAVAILfor an invalid address, so "ip link set lanX address 01:00:00:00:00:00" is enough to trigger this. A later notifier vetoingPRE_CHANGEADDRhas the same effect.Would all hardware flows then stay retired until an unrelated
NETDEV_UPorNETDEV_CHANGEADDRevent, or a control conduit state change?[ ... ]
drivers/net/dsa/b53/b53_common.c void b53_br_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge) · line 2783
Quoted 10 lines
drivers/net/dsa/b53/b53_common.c +4
-0@@ -2439,6 +2775,10 @@ void b53_br_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge) vl->members |=BIT (port);b53_set_vlan_entry (dev, pvid, vl); } +if (b53_fa_port (dev, port, true)) { +dev_err (ds->dev,"failed to restore FA classification on port %d\n" , port); +b53_disable_port (ds, port); + } }EXPORT_SYMBOL (b53_br_leave);[Severity: Medium]
Isb53_disable_port()enough on this failure path? It only sets the RX/TX disable bits inPORT_CTRL. It does not setfa_guards_failedor drop FA readiness, andfa_cfp_portsstill lacks this port's bit.The next
ndo_openrunsb53_enable_port(), which clears those bits:b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), 0);The port is then standalone with no CFP classification. Its traffic goes through port 8 and the FA while readiness is still true.
The notifier failure path sets
fa_guards_failedfor this kind of case. Should this path set it too?[ ... ]
Quoted 1 line
drivers/net/dsa/b53/b53_common.c +0
-0@@ -2564,6 +2905,46 @@ static bool b53_can_enable_brcm_tags(struct dsa_switch *ds, int port,[ ... ]
Quoted 2 lines
drivers/net/dsa/b53/b53_common.c +2
-0+static bool b53_uses_fa_tag (struct dsa_switch *ds,int port) +{[ ... ]
drivers/net/dsa/b53/b53_common.c static bool b53_can_enable_brcm_tags(struct dsa_switch *ds, int port, · line 2929
Quoted 6 lines
drivers/net/dsa/b53/b53_common.c +6
-0+ ethernet =of_parse_phandle (node,"ethernet" ,0 ); + fa =of_parse_phandle (ethernet,"brcm,flow-accelerator" ,0 ); + enabled =IS_ENABLED (CONFIG_BCM_NS_FA ) &&of_device_is_available (fa) && + (dev->chip_id ==BCM53011_DEVICE_ID || + dev->chip_id ==BCM53012_DEVICE_ID || + (is5301x (dev) &&of_device_is_compatible (fa,"brcm,bcm4708-fa" )));[Severity: Low]
Should this check use the compatibles listed in the binding? brcm,bcm4708-fa.yaml allows brcm,bcm4708-fa, brcm,bcm53011-fa and brcm,bcm53012-fa, and its example uses brcm,bcm53011-fa.bcm_ns_fa_init()later in the series accepts all three.As written, BCM53011/BCM53012 accept any available node without looking at its compatible. BCM53010/53018/53019 accept only brcm,bcm4708-fa.
That leads to two mismatched setups:
- A 5301x board whose DT uses brcm,bcm53011-fa or brcm,bcm53012-fa gets the FA backend set up on GMAC2, while b53 uses the ordinary brcm tag and installs no CFP guards.
- A 53011/53012 board with an unrelated compatible gets FA tagging, and then bgmac probe fails.[ ... ]
Quoted 8 lines
drivers/net/dsa/b53/b53_common.c +3
-1@@ -3385,7 +3773,32 @@ int b53_switch_register(struct b53_device *dev)dev_info (dev->dev,"found switch: %s, rev %i\n" , dev->name, dev->core_rev); -return dsa_register_switch (dev->ds); + ret =dsa_register_switch (dev->ds); +if (ret || !dev->fa_cfp_enabled) +return ret;[ ... ]
drivers/net/dsa/b53/b53_common.c int b53_switch_register(struct b53_device *dev) · line 3790
Quoted 8 lines
drivers/net/dsa/b53/b53_common.c +8
-0+ ret =register_netdevice_notifier (&dev->fa_netdev_nb); +if (ret) + goto unregister_switch; + ret =devm_add_action_or_reset (dev->dev, b53_fa_unregister_notifier, dev); +if (ret) + goto unregister_switch; + dev->fa_guards_ready = true; +if (!dev->fa_guards_failed) {[Severity: Low]
These plain bool flags are accessed concurrently with no common lock and no READ_ONCE()/WRITE_ONCE():- Here,
fa_guards_readyis written andfa_guards_failedis read outside rtnl, afterb53_fa_netdev_event()is already live.
- The notifier reads both flags under rtnl and may writefa_guards_failed.
-b53_teardown()writesdev->fa_stoppingwithout rtnl, whileb53_fa_netdev_event()reads it for every netdevice event in the system.The final readiness looks correct, because
b53_fa_ready()is evaluated again underrtnl_lock()below. Won't KCSAN still report these accesses as data races?[ ... ]
Quoted 6 lines
net/dsa/Kconfig +0
-0@@ -69,6 +69,15 @@ config NET_DSA_TAG_BRCM_PREPEND Broadcom switches which places the tag before the Ethernet headernet/dsa/Kconfig config NET_DSA_TAG_BRCM_PREPEND · line 79
Quoted 10 lines
net/dsa/Kconfig +8
-0(prepended). +config NET_DSA_TAG_BRCM_FA + tristate "Tag driver for the Broadcom Northstar flow accelerator" + select NET_DSA_TAG_BRCM_COMMON + help + Support the prepended four-byte FA metadata tag on Northstar GMAC2. + The receive format includes a hash, bucket, parser status, and input + switch port. Transmit uses the ordinary prepended Broadcom tag. + Enable this for a B53 switch explicitly connected to an accelerator.[Severity: Low]
This isn't a bug, but the help text does not match the code.brcm_fa_tag_xmit()puts the tag inside the frame for user ports behind CPU port 5:return brcm_tag_xmit_ll(skb, dev, dp->cpu_dp->index == 5 ? 2 * ETH_ALEN : 0);
drivers/net/dsa/b53/Kconfigalso selectsNET_DSA_TAG_BRCM_FAunconditionally, so the user has nothing to enable. Could the help text be updated to match?[ ... ]
Quoted 94 lines
net/dsa/tag_brcm.c +87
-0@@ -407,7 +416,100 @@ DSA_TAG_DRIVER(brcm_prepend_netdev_ops);MODULE_ALIAS_DSA_TAG_DRIVER (DSA_TAG_PROTO_BRCM_PREPEND ,BRCM_PREPEND_NAME );#endif +#if IS_ENABLED (CONFIG_NET_DSA_TAG_BRCM_FA ) +static LIST_HEAD (brcm_fa_controls); +static DEFINE_MUTEX (brcm_fa_control_lock); + +void brcm_fa_control_register (struct brcm_fa_control *control) +{ +mutex_lock (&brcm_fa_control_lock); +list_add_rcu (&control->list, &brcm_fa_controls); +mutex_unlock (&brcm_fa_control_lock); +} +EXPORT_SYMBOL_GPL (brcm_fa_control_register); + +void brcm_fa_control_unregister (struct brcm_fa_control *control) +{ +mutex_lock (&brcm_fa_control_lock); +list_del_rcu (&control->list); +mutex_unlock (&brcm_fa_control_lock); +synchronize_net (); +} +EXPORT_SYMBOL_GPL (brcm_fa_control_unregister); + +void brcm_fa_control_set_ready (struct net_device *conduit,bool ready) +{ +struct brcm_fa_control *control; + +/* State callbacks can sleep while retiring hardware entries. */ +mutex_lock (&brcm_fa_control_lock); +list_for_each_entry (control, &brcm_fa_controls, list) +if (control->conduit == conduit && control->state_change) + control->state_change (control->priv, ready); +mutex_unlock (&brcm_fa_control_lock); +} +EXPORT_SYMBOL_GPL (brcm_fa_control_set_ready); + +static struct sk_buff *brcm_fa_tag_xmit (struct sk_buff *skb, +struct net_device *dev) +{ +struct dsa_port *dp =dsa_user_to_port (dev); + +return brcm_tag_xmit_ll (skb, dev, dp->cpu_dp->index ==5 ?2 *ETH_ALEN :0 ); +} + +static struct sk_buff *brcm_fa_tag_rcv (struct sk_buff *skb,struct net_device *dev) +{ +struct dsa_port *cpu = dev->dsa_ptr; +struct brcm_fa_control *control; +struct dsa_port *data_cpu; +unsigned int port; +u8 reason; + +if (cpu->index !=5 ) +return brcm_tag_rcv_ll (skb, dev,ETH_HLEN , true); +if (!pskb_may_pull (skb,BRCM_TAG_LEN )) + goto drop; + reason = skb->data[0 ];/* Embedded tag byte 2 after eth_type_trans(). */ + port = skb->data[1 ] &BRCM_EG_PID_MASK ; + skb =brcm_tag_rcv_ll (skb, dev,2 , false); +if (!skb) +return NULL ; +dsa_strip_etype_header (skb,BRCM_TAG_LEN ); +skb_set_mac_header (skb, -ETH_HLEN ); +if (!(reason &BRCM_EG_RC_PROT_TERM )) +return skb; + data_cpu =dsa_to_port (cpu->ds,8 ); +if (!data_cpu || !dsa_port_is_cpu (data_cpu)) +return skb; +rcu_read_lock (); +list_for_each_entry_rcu (control, &brcm_fa_controls, list) +if (control->conduit == data_cpu->conduit) + control->receive (control->priv, skb, port); +rcu_read_unlock (); +return skb; +drop: +kfree_skb (skb); +return NULL ; +} + +static const struct dsa_device_ops brcm_fa_netdev_ops = { + .name =BRCM_FA_NAME , + .proto =DSA_TAG_PROTO_BRCM_FA , + .xmit = brcm_fa_tag_xmit, + .rcv = brcm_fa_tag_rcv, + .needed_headroom =BRCM_TAG_LEN , + .promisc_on_conduit = true, +}; + +DSA_TAG_DRIVER (brcm_fa_netdev_ops);net/dsa/tag_brcm.c DSA_TAG_DRIVER(brcm_prepend_netdev_ops); · line 515
Quoted 10 lines
net/dsa/tag_brcm.c +6
-0+MODULE_ALIAS_DSA_TAG_DRIVER (DSA_TAG_PROTO_BRCM_FA ,BRCM_FA_NAME ); +#endif +static struct dsa_tag_driver *dsa_tag_driver_array[] = { +#if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_FA) + &DSA_TAG_DRIVER_NAME (brcm_fa_netdev_ops), +#endif #if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM) &DSA_TAG_DRIVER_NAME (brcm_netdev_ops), #endif[Severity: Medium]
Does the link-local check at the end ofbrcm_tag_rcv_ll()look at the right bytes for this call?With offset ==
ETH_HLENthe tag is prepended.eth_type_trans()on the conduit therefore leftskb->mac_headerpointing at the four-byte tag, not at the destination MAC.skb_pull_rcsum()only movesskb->data. After the pull, eth_hdr(skb)->h_dest covers the tag plus the first two bytes of the real DA.is_link_local_ether_addr()then does not recognise 01:80:c2:00:00:xx frames.Port 8 is the CPU port for all user ports on these boards. STP BPDUs, LLDP, LACP and EAPOL received on bridged ports would all get
offload_fwd_markset.The switch only trapped these frames and did not forward them. With the mark set, the bridge also won't forward them in software to other ports on the same switch. That matters with STP disabled or with a
group_fwd_maskconfigured.
Quoted 8 lines
The port 5 branch in
brcm_fa_tag_rcv()fixes up the MAC header withskb_set_mac_header(), but this branch does not.
brcm_tag_rcv_prepend()seems to have the same problem already, so this may need its own fix inbrcm_tag_rcv_ll(). After the pull, it could read the DA fromskb->data-ETH_HLEN, or reset the MAC header first. Which would you prefer?
[High] bridged ports lose their guards
Agreed: the FA key has no input port, so a bridged port without guards could hit a live tuple. v2 requires every user port to have its
exception rules for FA to be ready: while any port is a bridge member, entries are retired and new ones are not admitted. b53_fa_port() also retires entries before touching CFP_CTRL.
[Medium] PRE_CHANGEADDR / failed MAC change; guard write failure
Agreed. PRE_CHANGEADDR now only retires the entries and schedules a resynchronization of the allow rules and readiness once RTNL is released, which also covers a MAC change that fails. A failure to write a guard now disables the CFP and FA instead of leaving CFP_CTRL enabled.
[Medium] b53_br_leave() failure
Agreed: the port is now recorded before the CFP_CTRL write and a write failure marks the guards failed, so FA stays off.
[Medium] CPU port 5 in non-default VLANs
Agreed: b53_vlan_add()/del() keep port 5 a tagged member of the VLANs of port 8.
[Medium] notifier active during teardown/shutdown
Agreed: the notifier is now unregistered and its work cancelled in b53_switch_remove()/b53_switch_shutdown(), before the DSA teardown, and the CFP is disabled there. The flags use READ_ONCE/WRITE_ONCE and the final readiness update is done under RTNL.
[Medium] brcm_tag_rcv_ll() link-local check
Agreed, this is an existing problem with the prepended tag. v2 fixes it in a separate patch before this one.
[Medium] TCP flag rules and fragments
The FA parser does not support fragments (data sheet: "The parser does not support options and fragmentation"), so fragments are never accelerated and take the software path. No change.
[Medium] EAP basic mode on standalone ports
The CFP rules have to classify standalone traffic, which the simplified mode would redirect to the CPU first. I will clarify the comments and the commit message; the mode is unchanged.
[Medium] data flooding
The RX_xCST_EN bits are only valid for port 8, so that write was a no-op and is removed. Unicast and multicast flooding to port 5 stays disabled. I am checking broadcast on hardware; the commit message no longer claims that all flooding is off.
[Low] policer/meter, duplicated rule programming, compatibles, Kconfig help
The BCM5301x CFP has no ACT_POL_DATA2 or policer mode field, unlike bcm_sf2: RATE_METER0 is only the current quota, so no change. The other three are fixed in v2.
pw-bot: cr
Signature · 1 line
Florian
Florian Fainelli
maintainerPATCH 6/9 net: flow_offload: allow drivers to validate and invalidate cached paths
In reply to Florian FainelliA classifier does not necessarily contain the mark, DSCP and output- interface inputs used to select its forwarding path. A partial driver FIB lookup cannot establish that a cached software route is stale.
Provide optional owner validation and invalidation callbacks. Validation runs under RCU without sleeping and distinguishes a proven stale path from unavailable context. Retain direct-path dst references for hardware flowtables and validate the actual cached routes, cookies and direct Ethernet neighbours in both directions on demand.
Mark references retained only for driver validation. They must not opt plain direct flows into packet-path or GC route checks after unrelated IPv4 generation changes. Keep the existing checks for direct tunnel, neighbour and XFRM routes. The explicit owner callback bypasses that policy and validates the retained dst itself. Other hardware users and tables without a validating driver keep their existing automatic-check behaviour. Software-only direct flows retain their previous reference policy. Release retained references with the flow.
Netfilter implements invalidation by marking the owning connection for teardown. Owners keep cookies valid through an RCU grace period after DESTROY; drivers stop issuing notifications when their rules are destroyed.
--- include/net/flow_offload.h | 12 ++++++ include/net/netfilter/nf_flow_table.h | 8 ++-- net/netfilter/nf_flow_table_core.c | 12 +++--- net/netfilter/nf_flow_table_offload.c | 58 +++++++++++++++++++++++++++ net/netfilter/nft_flow_offload.c | 6 ++- 5 files changed, 87 insertions(+), 9 deletions(-)
include/net/flow_offload.h +12 -0
@@ -697,6 +697,18 @@ struct flow_cls_offload {bool use_act_stats;unsigned long cookie;struct flow_rule *rule; +/* Optional owner notification when a rule no longer represents the path. +* Call under RCU; the owner retains the cookie and callback until a +* grace period after DESTROY. Drivers must stop new calls at DESTROY. +* The callback must not sleep or call back into the offload driver. +*/ +void (*invalidate)(unsigned long cookie); +/* Optional cached-path validation, called under RCU during REPLACE. +* Return 0 for a valid path, -ESTALE for a demonstrably stale path, +* or -EOPNOTSUPP when validation is unavailable. Do not sleep or +* call back into the driver. The callback does not invalidate its owner. +*/ +int (*validate)(unsigned long cookie);struct flow_stats stats;u32 classid; };
include/net/netfilter/nf_flow_table.h +5 -3
@@ -154,7 +154,8 @@ struct flow_offload_tuple { encap_num:2, needs_gso_segment:1, tun_num:2, - in_vlan_ingress:2; + in_vlan_ingress:2, + dst_validation_only:1;u16 mtu;u32 dst_cookie;struct dst_entry *dst_cache;
@@ -305,7 +306,7 @@ nf_flow_table_offload_del_cb(struct nf_flowtable *flow_table, }void flow_offload_route_init (struct flow_offload *flow, -struct nf_flow_route *route); +struct nf_flow_route *route,bool keep_dst);int flow_offload_add (struct nf_flowtable *flow_table,struct flow_offload *flow); void flow_offload_refresh(struct nf_flowtable *flow_table,
@@ -313,7 +314,8 @@ void flow_offload_refresh(struct nf_flowtable *flow_table,static inline bool nf_flow_dst_check (struct flow_offload_tuple *tuple) { -if (!tuple->dst_cache) +/* A driver-only reference must not change direct-path/GC semantics. */ +if (!tuple->dst_cache || tuple->dst_validation_only)return true;return dst_check (tuple->dst_cache, tuple->dst_cookie);
net/netfilter/nf_flow_table_core.c +7 -5
@@ -96,7 +96,7 @@ static struct dst_entry *nft_route_dst_fetch(struct nf_flow_route *route,static int flow_offload_fill_route (struct flow_offload *flow,struct nf_flow_route *route, -enum flow_offload_tuple_dir dir) +enum flow_offload_tuple_dir dir,bool keep_dst) {struct flow_offload_tuple *flow_tuple = &flow->tuplehash[dir].tuple;struct dst_entry *dst =nft_route_dst_fetch (route, dir);
@@ -127,7 +127,9 @@ static int flow_offload_fill_route(struct flow_offload *flow,switch (route->tuple[dir].xmit_type) {case FLOW_OFFLOAD_XMIT_DIRECT : -if (route->tuple[!dir].in.num_tuns) { + flow_tuple->dst_validation_only = keep_dst && + !route->tuple[!dir].in.num_tuns; +if (keep_dst || route->tuple[!dir].in.num_tuns) { flow_tuple->dst_cache = dst; flow_tuple->dst_cookie =flow_offload_dst_cookie (flow_tuple);
@@ -162,10 +164,10 @@ static void nft_flow_dst_release(struct flow_offload *flow, }void flow_offload_route_init (struct flow_offload *flow, -struct nf_flow_route *route) +struct nf_flow_route *route,bool keep_dst) { -flow_offload_fill_route (flow, route,FLOW_OFFLOAD_DIR_ORIGINAL ); -flow_offload_fill_route (flow, route,FLOW_OFFLOAD_DIR_REPLY ); +flow_offload_fill_route (flow, route,FLOW_OFFLOAD_DIR_ORIGINAL , keep_dst); +flow_offload_fill_route (flow, route,FLOW_OFFLOAD_DIR_REPLY , keep_dst); flow->type =NF_FLOW_OFFLOAD_ROUTE ; }EXPORT_SYMBOL_GPL (flow_offload_route_init);
net/netfilter/nf_flow_table_offload.c +58 -0
70 lines not on this page · raw message
net/netfilter/nft_flow_offload.c +5 -1
@@ -113,7 +113,11 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,if (!flow) goto err_flow_alloc; -flow_offload_route_init (flow, &route); +/* Hardware admission may validate the route used to build a direct path. +* Keep its reference and cookie instead of reconstructing a lookup with +* incomplete policy-routing inputs in the driver. +*/ +flow_offload_route_init (flow, &route,nf_flowtable_hw_offload (flowtable));if (tcph)flow_offload_ct_tcp (ct);
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net-next 6/9] net: flow_offload: allow drivers to validate and invalidate cached paths
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
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.
Quoted 5 lines
net/netfilter/nf_flow_table_offload.c +0
-0@@ -885,6 +885,62 @@ static int nf_flow_offload_alloc(const struct flow_offload_work *offload,
[ ... ]
Quoted 15 lines
net/netfilter/nf_flow_table_offload.c +15
-0+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 ;
[ ... ]
net/netfilter/nf_flow_table_offload.c static int nf_flow_offload_alloc(const struct flow_offload_work *offload, · line 933
Quoted 5 lines
net/netfilter/nf_flow_table_offload.c +5
-0+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?
net/netfilter/nf_flow_table_offload.c static int nf_flow_offload_alloc(const struct flow_offload_work *offload, · line 934
Quoted 1 line
net/netfilter/nf_flow_table_offload.c +1
-0+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?
Quoted 8 lines
net/netfilter/nf_flow_table_offload.c +8
-0+ 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 ; +}
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116222519.1416501-1-florian.fainelli%40broadcom.com
Florian Fainelli
maintainerRe: [PATCH net-next 6/9] net: flow_offload: allow drivers to validate and invalidate cached paths
Quoted 133 lines · On 11/17/26 15:29, [email protected] wrote:
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:929and 934) is documented as…--
net:
flow_offload: allow drivers to validate and invalidate cached pathsThis 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.Quoted 5 lines
net/netfilter/nf_flow_table_offload.c +0
-0@@ -885,6 +885,62 @@ static int nf_flow_offload_alloc(const struct flow_offload_work *offload,[ ... ]
Quoted 15 lines
net/netfilter/nf_flow_table_offload.c +15
-0+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 ;[ ... ]
net/netfilter/nf_flow_table_offload.c static int nf_flow_offload_alloc(const struct flow_offload_work *offload, · line 933
Quoted 5 lines
net/netfilter/nf_flow_table_offload.c +5
-0+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 undertbl->lock, and insert a newNUD_NONEentry 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,
-ESTALEfor a demonstrably stale path, or-EOPNOTSUPPwhen validation is unavailable.The first case is neighbour creation failing (
-ENOBUFSatgc_thresh3, or-ENOMEM).dst_neigh_lookup()turns theERR_PTRinto 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 abovegc_thresh2. The next validate then creates aNUD_NONEentry, fails theNUD_VALIDtest below, and returns-ESTALE, even though the next hop and MAC have not changed.The consumer,
fa_replace()indrivers/net/ethernet/broadcom/bcm-ns-fa.c(added later in this series by "net: bgmac: add Northstar IPv4 TCP/UDP NAT flowtable offload"), callscls->invalidate()on-ESTALE. That runsflow_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-onlyipv4_neigh_lookup()and returns-EOPNOTSUPPon a miss. Would a noref lookup under RCU, such as__ipv4_neigh_lookup_noref()or__ipv6_neigh_lookup_noref(), returning-EOPNOTSUPPon a miss, fit the documented contract better?net/netfilter/nf_flow_table_offload.c static int nf_flow_offload_alloc(const struct flow_offload_work *offload, · line 934
Quoted 1 line
net/netfilter/nf_flow_table_offload.c +1
-0+neigh_ha_snapshot (mac, neigh, dst->dev);[Severity: Low]
Should thesedst->devaccesses usedst_dev_rcu()? This callback runs under RCU whiledst_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 ofdst->dev, andipv4_dst_neigh_lookup()does a third load throughdst_dev_rcu(). KCSAN will report the plain loads, and the three loads can see differentnet_deviceswithin one validation pass.There's no memory safety problem here.
blackhole_netdevhasaddr_lenset toETH_ALEN, so mac[] is fully written, and-ESTALEis the right answer for a route that has moved to blackhole.Would taking a single dev =
dst_dev_rcu(dst)snapshot, or passingneigh->devtoneigh_ha_snapshot(), avoid the race?
Quoted 11 lines
Quoted 8 lines
net/netfilter/nf_flow_table_offload.c +8
-0+ 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 ; +}[ ... ]
[Medium] validation creating neighbours / reporting -ESTALE
Agreed. dst_neigh_lookup() can create an entry (and run forced GC), and turns a creation failure or a garbage collected entry into -ESTALE, which makes the owner tear down a healthy flow. v2 looks up the next hop with __ipv4_neigh_lookup_noref() under RCU, never creating an entry, and returns -EOPNOTSUPP when there is none, since the path is then not proven stale.
It also returns -EOPNOTSUPP for non-IPv4 tuples, as the next hop address used is an IPv4 one.
[Low] dst->dev accesses
Agreed. v2 takes a single dst_dev_rcu() snapshot under rcu_read_lock() and uses it for the ifindex check, the neighbour lookup and neigh_ha_snapshot().
pw-bot: cr
Signature · 1 line
Florian
Pablo Neira Ayuso
maintainerRe: [PATCH net-next 6/9] net: flow_offload: allow drivers to validate and invalidate cached paths
In reply to Florian FainelliOn Mon, Nov 16, 2026 at 02:25:16PM -0800, Florian Fainelli wrote:
[...]
Quoted 28 lines
net/netfilter/nf_flow_table_offload.c +28
-0+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 ; +/* This is the actual route selected with the packet's policy +* context, including mark, DSCP and the reverse lookup's oif. +*/ +if (!dst_check (dst, tuple->dst_cookie)) +return -ESTALE ; +if (tuple->xmit_type !=FLOW_OFFLOAD_XMIT_DIRECT ) +continue ; +/* A stacked path may have a different final Ethernet neighbour. +* Do not mistake that unsupported context for a stale owner. +*/ +if (dst->dev->ifindex != tuple->out.ifidx) +return -EOPNOTSUPP ; + neigh =dst_neigh_lookup (dst, &other->src_v4);
net/netfilter/nf_flow_table_offload.c static int nf_flow_offload_alloc(const struct flow_offload_work *offload, · line 941
Quoted 10 lines
net/netfilter/nf_flow_table_offload.c +10
-0+if (!neigh) +return -ESTALE ; +neigh_ha_snapshot (mac, neigh, dst->dev); + 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 ;
This validation to catch for stale entries looks very similar to what I'm working on. I guess there is a chance to consolidate all this in common infrastructure for both software and hardware modes.
Florian Fainelli
maintainerRe: [PATCH net-next 6/9] net: flow_offload: allow drivers to validate and invalidate cached paths
Quoted 36 lines · Pablo Neira Ayuso
On Mon, Nov 16, 2026 at 02:25:16PM -0800, Florian Fainelli wrote:
[...]Quoted 34 lines
net/netfilter/nf_flow_table_offload.c +34
-0+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 ; +/* This is the actual route selected with the packet's policy +* context, including mark, DSCP and the reverse lookup's oif. +*/ +if (!dst_check (dst, tuple->dst_cookie)) +return -ESTALE ; +if (tuple->xmit_type !=FLOW_OFFLOAD_XMIT_DIRECT ) +continue ; +/* A stacked path may have a different final Ethernet neighbour. +* Do not mistake that unsupported context for a stale owner. +*/ +if (dst->dev->ifindex != tuple->out.ifidx) +return -EOPNOTSUPP ; + neigh =dst_neigh_lookup (dst, &other->src_v4); +if (!neigh) +return -ESTALE ; +neigh_ha_snapshot (mac, neigh, dst->dev); + valid = (READ_ONCE (neigh->nud_state) &NUD_VALID ) && +ether_addr_equal (mac, tuple->out.h_dest); +neigh_release (neigh);
Quoted 8 lines
net/netfilter/nf_flow_table_offload.c static int nf_flow_offload_alloc(const struct flow_offload_work *offload, · line 941
Quoted 4 lines
net/netfilter/nf_flow_table_offload.c +4
-0+if (!valid) +return -ESTALE ; + } +return 0 ;This validation to catch for stale entries looks very similar to what I'm working on. I guess there is a chance to consolidate all this in common infrastructure for both software and hardware modes.
Excellent, happy to point you to an off the shelf device where you could be testing this on, if you would like to?
Signature · 1 line
Florian
Pablo Neira Ayuso
maintainerRe: [PATCH net-next 6/9] net: flow_offload: allow drivers to validate and invalidate cached paths
Hi Florian,
Quoted 48 lines · Florian Fainelli
Quoted 36 lines · Pablo Neira Ayuso
On Mon, Nov 16, 2026 at 02:25:16PM -0800, Florian Fainelli wrote:
[...]Quoted 34 lines
net/netfilter/nf_flow_table_offload.c +34
-0+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 ; +/* This is the actual route selected with the packet's policy +* context, including mark, DSCP and the reverse lookup's oif. +*/ +if (!dst_check (dst, tuple->dst_cookie)) +return -ESTALE ; +if (tuple->xmit_type !=FLOW_OFFLOAD_XMIT_DIRECT ) +continue ; +/* A stacked path may have a different final Ethernet neighbour. +* Do not mistake that unsupported context for a stale owner. +*/ +if (dst->dev->ifindex != tuple->out.ifidx) +return -EOPNOTSUPP ; + neigh =dst_neigh_lookup (dst, &other->src_v4); +if (!neigh) +return -ESTALE ; +neigh_ha_snapshot (mac, neigh, dst->dev); + valid = (READ_ONCE (neigh->nud_state) &NUD_VALID ) && +ether_addr_equal (mac, tuple->out.h_dest); +neigh_release (neigh);Quoted 8 lines
net/netfilter/nf_flow_table_offload.c static int nf_flow_offload_alloc(const struct flow_offload_work *offload, · line 941
Quoted 4 lines
net/netfilter/nf_flow_table_offload.c +4
-0+if (!valid) +return -ESTALE ; + } +return 0 ;This validation to catch for stale entries looks very similar to what I'm working on. I guess there is a chance to consolidate all this in common infrastructure for both software and hardware modes.
Quoted 2 lines
Excellent, happy to point you to an off the shelf device where you could be testing this on, if you would like to?
I have a setup with Banana pi r64 and openwrt, I have this large series of backports to synchronize with with current upstream trees:
patches/generic-backport/951-netfilter-flowtable-inline-vlan-encapsulation-in-xmi.patch patches/generic-backport/952-netfilter-flowtable-inline-pppoe-encapsulation-in-xm.patch patches/generic-backport/953-netfilter-flowtable-remove-hw_ifidx.patch patches/generic-backport/953-netfilter-flowtable-use-tuple-address-to-calculate-n.patch patches/generic-backport/954-netfilter-flowtable-Add-IPIP-rx-sw-acceleration.patch patches/generic-backport/955-netfilter-flowtable-Add-IPIP-tx-sw-acceleration.patch patches/generic-backport/956-netfilter-always-set-route-tuple-out-ifindex.patch patches/generic-backport/957-netfilter-Add-ctx-pointer-in-nf_flow_skb_encap_proto.patch patches/generic-backport/958-netfilter-Introduce-tunnel-metadata-info-in-nf_flowt.patch patches/generic-backport/959-netfilter-flowtable-Add-IP6IP6-rx-sw-acceleration.patch patches/generic-backport/960-netfilter-flowtable-Add-IP6IP6-tx-sw-acceleration.patch patches/generic-backport/961-netfilter-flowtable-dedicated-slab-for-flow-entry.patch patches/generic-backport/962-netfilter-nf_flow_table_ip-reset-mac-header-before-v.patch patches/generic-backport/963-netfilter-replace-skb_try_make_writable-by-skb_ensur.patch patches/generic-backport/964-netfilter-flowtable-fix-inline-vlan-encapsulation-in.patch patches/generic-backport/965-netfilter-fix-inline-pppoe-encapsulation-i.patch patches/generic-backport/966-flowtable-use-skb_pull_rcsum-to-pop-vlan-p.patch patches/generic-backport/967-netfilter-flowtable-avoid-num_encaps-underflow-on-br.patch patches/generic-backport/967-netfilter-flowtable-bail-out-if-forward-path-cannot-.patch patches/generic-backport/968-netfilter-flowtable-fix-and-simplify-IP6IP6-tunnel-h.patch patches/generic-backport/969-netfilter-flowtable-use-dst-in-this-direction-when-p.patch patches/generic-backport/970-netfilter-flowtable-Validate-iph-ihl-in-nf_flow_ip4_.patch patches/generic-backport/971-netfilter-flowtable-IPIP-tunnel-hardware-offload-is-.patch patches/generic-backport/972-netfilter-flowtable-support-IPIP-tunnel-with-direct-.patch patches/generic-backport/973-netfilter-flowtable-use-correct-direction-to-set-up-.patch patches/generic-backport/974-netfilter-flowtable-tear-down-flow-entries-with-stal.patch patches/generic-backport/975-netfilter-flowtable-consolidate-net_device-field-in-.patch patches/generic-backport/976-netfilter-flowtable-consolidate-flowtable-device-che.patch patches/generic-backport/977-net-dsa-stop-at-the-user-device-in-.fill_forward_pat.patch patches/generic-backport/978-net-do-not-advance-stack-index-from-dev_fwd_path.patch patches/generic-backport/979-net-pass-dst-via-net_device_path-in-dev_fill_forward.patch patches/generic-backport/980-netfilter-flowtable-release-tunnel-route-on-error-wh.patch patches/generic-backport/981-net-pass-net_device_path_ctx-to-dev_fill_forward_pat.patch patches/generic-backport/982-net-remove-WARN_ON_ONCE-from-the-dev_fill_forward_pa.patch patches/generic-backport/982-0001-netfilter-flowtable-generalize-pending-status-bit.patch patches/generic-backport/983-netfilter-nft_meta-add-double-tagged-vlan-and-pppoe-.patch patches/generic-backport/984-net-netfilter-add-ether_type-to-net_device_path_ctx-.patch patches/generic-backport/985-netfilter-flowtable-rename-tun.l3_proto-to-tun.inner.patch patches/generic-backport/986-netfilter-flowtable-rename-ctx.tun.proto-to-ctx.tun..patch patches/generic-backport/987--netfilter-flowtable-store-ethertype-in-flowtable-con.patch patches/generic-backport/987-netfilter-flowtable-move-ipv4-and-ipv6-xmit-path-to-.patch patches/generic-backport/988-netfilter-flowtable-detach-layer-2-encapsulation-par.patch
I guess this should be fine for testing this patch, maybe there is a better way.
I still have to automate testing more classic scenarios in the real hardware, such as PPPoE (I have configuration to make this local), vlan, ipip tunnels, wireguard, etc.
If there's anything else I'm missing, please, let me know.
Thanks.
Florian Fainelli
maintainerPATCH 7/9 net: bgmac: add Northstar IPv4 TCP/UDP NAT flowtable offload
In reply to Florian FainelliExpose the inline BCM4708/BCM5301X accelerator through TC_SETUP_FT on GMAC2. Learn placement hashes from miss metadata and install exact IPv4 TCP/UDP SNAT or DNAT rules with shared router-MAC and next-hop resources. Restrict admission to two standalone untagged DSA ports, distinct router MACs, MTU 1500 and one flowtable in the initial namespace. Require an operational GMAC0 exception path for both protocols and the flowtable FIN/RST exclusion mask for TCP. Reject unsupported or exhausted rules.
Gate lookup synchronously and retire all hardware owners on every IPv4 route, rule or nexthop notification, including unrelated prefixes and local-table changes. This is deliberately conservative: the driver lacks enough policy-routing context to prove an event irrelevant. Coalesce control work, accepting reduced offload residency during unrelated churn. Track explicit low-MTU prefixes incrementally from notifier replay and updates; avoid repeated FIB dumps. Bound tracking memory and latch software fallback if tracking is exhausted.
Use the owner's actual cached-route and neighbour validation as the only authority for stale-owner teardown. The driver's partial FIB lookup is an eligibility probe; it lacks mark, DSCP and output-interface context. A mismatch or unsupported shape declines hardware offload without tearing down a valid policy-routed software flow. Reject publication across invalidation generations. Use RCU lookups and tracked netdevice references. Drive neighbour probes from hardware counter activity, including the initial pre-wrap jiffies epoch. Retire owners on neighbour, topology or exception-path changes that withdraw their hardware paths.
Quiesce lookups using GMAC2 CPU flow control around indirect table accesses, drain an in-flight frame, check busy and address completion, and release read mode before resuming traffic. Preserve Broadcom-tag relocation when disabling lookup. On an uncertain transaction, gate the parser before releasing pause, retain uncertain resources and reject new entries until reprobe. Add optional per-device completion fault injection.
TCP control packets retire both NAT directions before tuple reuse. Accumulate packet deltas and preserve the final delta for retired owners; do not fabricate hardware byte counters. Provide debugfs status and raw table readback. FA2/FA+, PPPoE and board enablement remain separate work.
--- MAINTAINERS | 1 + drivers/net/ethernet/broadcom/Kconfig | 24 + drivers/net/ethernet/broadcom/Makefile | 1 + drivers/net/ethernet/broadcom/bcm-ns-fa.c | 1897 ++++++++++++++++++++ drivers/net/ethernet/broadcom/bcm-ns-fa.h | 30 + drivers/net/ethernet/broadcom/bgmac-bcma.c | 5 + drivers/net/ethernet/broadcom/bgmac.c | 31 + drivers/net/ethernet/broadcom/bgmac.h | 2 + 8 files changed, 1991 insertions(+) create mode 100644 drivers/net/ethernet/broadcom/bcm-ns-fa.c create mode 100644 drivers/net/ethernet/broadcom/bcm-ns-fa.h
MAINTAINERS +1 -0
@@ -5671,6 +5671,7 @@ S: Maintained F: Documentation/devicetree/bindings/net/brcm,amac.yaml F: Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml F: Documentation/devicetree/bindings/net/brcm,bcm5301x-gmac.yaml +F: drivers/net/ethernet/broadcom/bcm-ns-fa* F: drivers/net/ethernet/broadcom/bgmac* F: drivers/net/ethernet/broadcom/unimac.h
drivers/net/ethernet/broadcom/Kconfig +24 -0
@@ -163,13 +163,36 @@ config BNX2X_SRIOV config BGMAC tristate + depends on BCM_NS_FA || !BCM_NS_FA help This enables the integrated ethernet controller support for many Broadcom (mostly iProc) SoCs. An appropriate bus interface driver needs to be enabled to select this. +config BCM_NS_FA + tristate "Broadcom Northstar IPv4 TCP/UDP NAT flow accelerator" + depends on ARCH_BCM_5301X || COMPILE_TEST + depends on OF && NET_DSA && NF_FLOW_TABLE + select NET_DSA_TAG_BRCM_FA + help + Offload IPv4 TCP/UDP NAT flows from nftables flowtables to the inline + accelerator on BCM4708, BCM53011 and BCM53012. Requires GMAC2, a B53 switch + using brcm-fa tags, a second CPU link through GMAC0 for IPv4 exceptions, + and explicit device tree configuration. + VLANs, bridges, and double NAT use the software path. + +config BCM_NS_FA_FAULT_INJECTION + bool "Fault injection for Northstar FA table transactions" + depends on BCM_NS_FA && FAULT_INJECTION_DEBUG_FS + help + Add per-device fail_table controls in debugfs to simulate an uncertain + indirect table completion. The failure disables hardware lookup until + reprobe and leaves forwarding to software. Intended for driver testing. + Injection is disabled by default and can be armed through debugfs. + config BGMAC_BCMA tristate "Broadcom iProc GBit BCMA support" + depends on BCM_NS_FA || !BCM_NS_FA depends on BCMA && BCMA_HOST_SOC depends on BCM47XX || ARCH_BCM_5301X || COMPILE_TEST select BGMAC
@@ -183,6 +206,7 @@ config BGMAC_BCMA config BGMAC_PLATFORM tristate "Broadcom iProc GBit platform support" + depends on BCM_NS_FA || !BCM_NS_FA depends on ARCH_BCM_IPROC || COMPILE_TEST select BGMAC select PHYLIB
drivers/net/ethernet/broadcom/Makefile +1 -0
@@ -19,3 +19,4 @@ obj-$(CONFIG_SYSTEMPORT) += bcmsysport.o obj-$(CONFIG_BNXT) += bnxt/ obj-$(CONFIG_BCMASP) += asp2/ obj-$(CONFIG_BNGE) += bnge/ +obj-$(CONFIG_BCM_NS_FA) += bcm-ns-fa.o
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +1897 -0
1,897 lines not on this page · raw message
drivers/net/ethernet/broadcom/bcm-ns-fa.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _BCM_NS_FA_H +#define _BCM_NS_FA_H + +#include <linux/netdevice.h> + +struct bcm_ns_fa ; + +#if IS_REACHABLE (CONFIG_BCM_NS_FA ) +struct bcm_ns_fa *bcm_ns_fa_init (struct net_device *dev); +void bcm_ns_fa_rx (struct bcm_ns_fa *fa,struct sk_buff *skb); +int bcm_ns_fa_setup_tc (struct bcm_ns_fa *fa,enum tc_setup_type type,void *data); +void bcm_ns_fa_flush (struct bcm_ns_fa *fa); +void bcm_ns_fa_set_offload (struct bcm_ns_fa *fa,bool enable); +#else +static inline struct bcm_ns_fa *bcm_ns_fa_init (struct net_device *dev) +{ +return NULL ; +} + +static inline void bcm_ns_fa_rx (struct bcm_ns_fa *fa,struct sk_buff *skb) {} +static inline void bcm_ns_fa_flush (struct bcm_ns_fa *fa) {} +static inline void bcm_ns_fa_set_offload (struct bcm_ns_fa *fa,bool enable) {} +static inline int bcm_ns_fa_setup_tc (struct bcm_ns_fa *fa, +enum tc_setup_type type,void *data) +{ +return -EOPNOTSUPP ; +} +#endif +#endif
drivers/net/ethernet/broadcom/bgmac-bcma.c +5 -0
@@ -11,6 +11,7 @@#include <linux/bcma/bcma.h> #include <linux/brcmphy.h> #include <linux/etherdevice.h> +#include <linux/of.h> #include <linux/of_mdio.h> #include <linux/of_net.h> #include "bgmac.h"
@@ -130,6 +131,10 @@ static int bgmac_probe(struct bcma_device *core)const u8 *mac;int err; +if (of_property_present (core->dev.of_node,"brcm,flow-accelerator" ) && + core->core_unit !=2 ) +return -EINVAL ; + bgmac =bgmac_alloc (&core->dev);if (!bgmac)return -ENOMEM ;
drivers/net/ethernet/broadcom/bgmac.c +31 -0
@@ -486,6 +486,7 @@ static int bgmac_dma_rx_read(struct bgmac *bgmac, struct bgmac_dma_ring *ring,skb_pull (skb,BGMAC_RX_FRAME_OFFSET +BGMAC_RX_BUF_OFFSET ); +bcm_ns_fa_rx (bgmac->fa, skb);skb_checksum_none_assert (skb); skb->protocol =eth_type_trans (skb, bgmac->net_dev); bgmac->net_dev->stats.rx_bytes += len;
@@ -1272,7 +1273,25 @@ static int bgmac_change_mtu(struct net_device *net_dev, int mtu)return 0 ; } +static int bgmac_set_features (struct net_device *dev,netdev_features_t features) +{ +struct bgmac *bgmac =netdev_priv (dev); + +bcm_ns_fa_set_offload (bgmac->fa, features &NETIF_F_HW_TC ); +return 0 ; +} + +static int bgmac_setup_tc (struct net_device *dev,enum tc_setup_type type, +void *data) +{ +struct bgmac *bgmac =netdev_priv (dev); + +return bcm_ns_fa_setup_tc (bgmac->fa, type, data); +} +static const struct net_device_ops bgmac_netdev_ops = { + .ndo_set_features = bgmac_set_features, + .ndo_setup_tc = bgmac_setup_tc, .ndo_open = bgmac_open, .ndo_stop = bgmac_stop, .ndo_start_xmit = bgmac_start_xmit,
@@ -1560,6 +1579,17 @@ int bgmac_enet_probe(struct bgmac *bgmac) net_dev->hw_features = net_dev->features; net_dev->vlan_features = net_dev->features; + bgmac->fa =bcm_ns_fa_init (net_dev); +if (IS_ERR (bgmac->fa)) { + err =PTR_ERR (bgmac->fa); + bgmac->fa =NULL ; + goto err_phy_disconnect; + } +if (bgmac->fa) { + net_dev->features |=NETIF_F_HW_TC ; + net_dev->hw_features |=NETIF_F_HW_TC ; + } +/* Omit FCS from max MTU size */ net_dev->max_mtu =BGMAC_RX_MAX_FRAME_SIZE -ETH_FCS_LEN ;
@@ -1610,6 +1640,7 @@ int bgmac_enet_suspend(struct bgmac *bgmac)netif_tx_unlock (bgmac->net_dev);bgmac_chip_intrs_off (bgmac); +bcm_ns_fa_flush (bgmac->fa);bgmac_chip_reset (bgmac);bgmac_dma_cleanup (bgmac);
drivers/net/ethernet/broadcom/bgmac.h +2 -0
@@ -5,6 +5,7 @@#include <linux/netdevice.h> #include "unimac.h" +#include "bcm-ns-fa.h" #define BGMAC_DEV_CTL 0x000#define BGMAC_DC_TSM 0x00000002
@@ -437,6 +438,7 @@ struct bgmac_rx_header { }; struct bgmac { + struct bcm_ns_fa *fa; union { struct { void __iomem *base;
Signature · 1 line
2.53.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] net: bgmac: incomplete TCP flow retirement in fa_insert() and fa_control_match() - [Medium] net…
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [High] net: bgmac: incomplete TCP flow retirement in fa_insert() and fa_control_match()
- [Medium] net: bgmac: unlocked block_list access and missing netns check in bcm_ns_fa_setup_tc()
- [Medium] net: bgmac: untracked neighbours in fa_route_check() and eviction in fa_netevent()
- [Low] net: bgmac: unlocked list_del_rcu() on fa_write() error path in fa_insert()
It also noticed 1 related pre-existing issue this patch does not introduce:
- [Medium] net: bgmac: fixed PHY resource leak on probe error and remove paths [1]
--
commit 90c733393e363fb5e285d7f2e6d82b71424dc058
Author: Florian Fainelli <[email protected]>
net: bgmac: add Northstar IPv4 TCP/UDP NAT flowtable offload
This commit adds IPv4 TCP/UDP NAT flowtable hardware offload support for the Broadcom Northstar BCM4708/BCM5301X inline flow accelerator on GMAC2.
Quoted 5 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +0
-0
[ ... ]
Quoted 9 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +9
-0+static bool fa_control_match (const struct fa_flow *entry, +const struct fa_tuple *tuple,unsigned int port, +bool ports_valid) +{ +size_t len = ports_valid ?sizeof (*tuple) : offsetof(struct fa_tuple , sport); + +return entry->l4proto ==IPPROTO_TCP && entry->in_port == port && + !memcmp (&entry->tuple, tuple, len); +}
[ ... ]
Quoted 45 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +45
-0+static int fa_netevent (struct notifier_block *nb,unsigned long event,void *ptr) +{ + struct bcm_ns_fa *fa = container_of(nb, struct bcm_ns_fa, netevent_nb); +struct fa_neighbour *cached =NULL ; +struct neighbour *neighbour = ptr; +bool invalidate = false; +unsigned int i; +char mac[ETH_ALEN ]; +__be32 address; +u8 state; + +if (event ==NETEVENT_IPV4_MPATH_HASH_UPDATE || + event ==NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE ) { +if (ptr == &init_net) +fa_invalidate (fa); +return NOTIFY_DONE ; + } +if (event ==NETEVENT_REDIRECT ) { +struct netevent_redirect *redirect = ptr; + +if (net_eq (dev_net (redirect->new->dev), &init_net)) +fa_invalidate (fa); +return NOTIFY_DONE ; + } +if (event !=NETEVENT_NEIGH_UPDATE || neighbour->tbl->family !=AF_INET || + !fa_port (fa, neighbour->dev)) +return NOTIFY_DONE ; + state =READ_ONCE (neighbour->nud_state); + address =get_unaligned ((__be32 *)neighbour->primary_key); +neigh_ha_snapshot (mac, neighbour, neighbour->dev); +spin_lock_bh (&fa->learn_lock); +for (i =0 ; i <ARRAY_SIZE (fa->neighbours); i++) { +struct fa_neighbour *candidate = &fa->neighbours[i]; + +if (candidate->valid && candidate->ifindex == neighbour->dev->ifindex && + candidate->address == address) { + cached = candidate; + invalidate = !(state &NUD_VALID ) ||memcmp (candidate->mac, mac,ETH_ALEN ); +break ; + } + } +if (!cached) { + cached = &fa->neighbours[fa->neighbour_next++ %FA_NEXTHOPS ]; + invalidate = cached->valid || !(state &NUD_VALID ) || !list_empty (&fa->entries); + }
drivers/net/ethernet/broadcom/bcm-ns-fa.c line 1235
Quoted 10 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +10
-0+ *cached = (struct fa_neighbour ) { + .address = address, .ifindex = neighbour->dev->ifindex, + .state = state, .valid = true, + }; +memcpy (cached->mac, mac,ETH_ALEN ); +spin_unlock_bh (&fa->learn_lock); +if (invalidate) +fa_invalidate (fa); +return NOTIFY_DONE ; +}
[Severity: Medium]
Can an admitted flow's next-hop neighbour be missing from fa->neighbours[], preventing fa_neighbour_activity() from sending reachability probes?
fa->neighbours[] is only populated on NETEVENT_NEIGH_UPDATE while fa_port(fa, neighbour->dev) is true; neither fa_route_check() nor fa_insert() records the neighbour of an admitted flow. A neighbour resolved before fa_port() became true (such as before carrier-up or via a static entry) is never added, and an existing entry can also be evicted by 128 failed ARP updates because fa_netevent() unconditionally writes non-NUD_VALID updates into the ring with valid = true.
In addition, when !cached is true, invalidate is false if cached->valid is false, state is NUD_VALID, and list_empty(&fa->entries) is true. If the first flow has already passed fa_route_check() and fa_learn_lookup() and is sleeping in fa_mac_get() before being added to fa->entries, a NETEVENT_NEIGH_UPDATE changing that uncached neighbour to a new NUD_VALID MAC skips fa_invalidate() and lets fa_insert() commit the stale MAC to hardware.
Quoted 21 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +21
-0+ +static void fa_control_work (struct work_struct *work) +{ + struct bcm_ns_fa *fa = container_of(work, struct bcm_ns_fa, control_work); +unsigned long generation; +unsigned int i; + +mutex_lock (&fa->lock); +for (;;) { +spin_lock_bh (&fa->learn_lock); + generation = fa->pending_generation; +spin_unlock_bh (&fa->learn_lock); +for (i =0 ; i <FA_SLOTS ; i++) { +struct fa_flow *entry = fa->flows[i]; + +if (entry &&test_bit (FA_FLOW_CLOSING , &entry->flags) && entry->reverse) +set_bit (FA_FLOW_CLOSING , &entry->reverse->flags); + } +for (i =0 ; i <FA_SLOTS ; i++) +if (fa->flows[i] &&test_bit (FA_FLOW_CLOSING , &fa->flows[i]->flags)) +fa_uninstall (fa, i);
[ ... ]
Quoted 6 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +6
-0+list_add_rcu (&entry->list, &fa->entries); +spin_unlock_bh (&fa->learn_lock); +fa_encode (&rule, po, nh, entry->out_port, data); +/* Publish to NAPI before committing: a concurrent control trap must +* stop lookups even if it arrives while this entry is being written. +*/
drivers/net/ethernet/broadcom/bcm-ns-fa.c line 1380
Quoted 10 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +10
-0+fa_control_update (fa,0 ,FA_CTL_NO_DA_CHECK ); + err =fa_write (fa,FA_FLOW_TABLE , slot, data); +if (err) { +fa_fail (fa); +list_del_rcu (&entry->list); +netdev_put (entry->in, &entry->in_tracker); +netdev_put (entry->out, &entry->out_tracker); +kfree_rcu (entry, rcu); +return err; + }
[Severity: Low]
Should list_del_rcu(&entry->list) on the fa_write() error path hold spin_lock_bh(&fa->learn_lock)?
fa_insert() adds entry to fa->entries under fa->learn_lock and fa_destroy() holds fa->learn_lock around list_del_rcu(), whereas fa_fail() releases fa->learn_lock before list_del_rcu() runs here, racing with readers under fa->learn_lock such as list_empty(&fa->entries) in fa_netevent().
Quoted 11 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +11
-0+ entry->installed = true; +if (rule.l4proto ==IPPROTO_TCP ) { +struct fa_flow *other; + +list_for_each_entry (other, &fa->entries, list) { +if (other == entry || other->l4proto !=IPPROTO_TCP || other->reverse || +test_bit (FA_FLOW_CLOSING , &other->flags) || + other->in_port != entry->out_port || + other->out_port != entry->in_port || +memcmp (&other->tuple, &entry->reply,sizeof (other->tuple)) || +memcmp (&other->reply, &entry->tuple,sizeof (other->reply)))
drivers/net/ethernet/broadcom/bcm-ns-fa.c line 1401
Quoted 10 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +10
-0+continue ; + entry->reverse = other; + other->reverse = entry; +break ; + } + } + entry->lastused = jiffies; + fa->flows[slot] = entry; + fa->nr_flows++; +return 0 ;
[Severity: High]
Can a TCP direction remain active in the hardware flow table after a TCP FIN, RST, or SYN control packet arrives in the opposite direction?
When flow_offload_rule_add() installs a bidirectional TCP flow, it calls FLOW_CLS_REPLACE for the original direction (other) and then the reply direction (entry). In fa_insert(), entry is added to fa->entries before fa_write() sleeps in fa_table_begin(), while entry->reverse and other->reverse are only linked after fa_write() returns:
CPU0 (workqueue) CPU1 (GMAC0 NAPI)fa_insert() [reply: entry]
spin_lock_bh(&fa->learn_lock)
list_add_rcu(&entry->list, ...)
spin_unlock_bh(&fa->learn_lock)
fa_write()
fa_table_begin()
fsleep(20)
fa_control_receive()
fa_tcp_control() [original tuple]
/* matches other, not entry */
set_bit(FA_FLOW_CLOSING,
&other->flags)
queue_work(..., &fa->control_work) list_for_each_entry(other, ...)
if (... || test_bit(FA_FLOW_CLOSING, &other->flags))
continue; <-- skips other, reverse not linked
fa->flows[slot] = entry;mutex_unlock(&fa->lock)
fa_control_work()
/* other->reverse is NULL */
fa_uninstall(other)
fa->control_pending = false
fa_lookup_update(fa) <-- re-enables lookup with entry still installed
The same happens if other was already retired by fa_control_work() (while still in fa->entries with FA_FLOW_CLOSING set awaiting FLOW_CLS_DESTROY) before fa_insert() runs for entry.
Also, if only one direction of a TCP flow was offloaded (for example, when only one direction's miss hash was learned on GMAC2 or the reply bucket was full), entry->reverse is NULL and fa_control_match() only checks entry->in_port and entry->tuple, ignoring entry->out_port and entry->reply. Any FIN, RST, or SYN arriving in the reply direction will not match in fa_tcp_control() and will leave the offloaded direction in hardware.
[ ... ]
Quoted 35 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +35
-0+int bcm_ns_fa_setup_tc (struct bcm_ns_fa *fa,enum tc_setup_type type,void *data) +{ +struct flow_block_offload *block = data; +struct flow_block_cb *cb; + +if (!fa || type !=TC_SETUP_FT || + block->binder_type !=FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS ) +return -EOPNOTSUPP ; + block->driver_block_list = &fa->block_list; +/* DSA forwards each user-port bind to the same conduit. Keep one +* callback per flowtable, with a reference for each bound user port. +*/ +switch (block->command) { +case FLOW_BLOCK_BIND : + cb =flow_block_cb_lookup (block->block, fa_block_cb, fa); +if (cb) { +flow_block_cb_incref (cb); +return 0 ; + } +/* Different flowtables have independent cookies and policy. The +* hardware cannot partition tables by ingress port or netns. +*/ +if (!list_empty (&fa->block_list)) +return -EBUSY ; + cb =flow_block_cb_alloc (fa_block_cb, fa, fa,NULL ); +if (IS_ERR (cb)) +return PTR_ERR (cb); +flow_block_cb_incref (cb); +flow_block_cb_add (cb, block); +list_add_tail (&cb->driver_list, &fa->block_list); +return 0 ; +case FLOW_BLOCK_UNBIND : + cb =flow_block_cb_lookup (block->block, fa_block_cb, fa); +if (!cb) +return -ENOENT ;
drivers/net/ethernet/broadcom/bcm-ns-fa.c line 1608
Quoted 10 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +10
-0+bcm_ns_fa_flush (fa); +if (!flow_block_cb_decref (cb)) { +flow_block_cb_remove (cb, block); +list_del (&cb->driver_list); + } +return 0 ; +default : +return -EOPNOTSUPP ; + } +}
[Severity: Medium]
Does bcm_ns_fa_setup_tc() need to hold fa->lock and reject binds outside init_net?
nf_tables calls ndo_setup_tc(TC_SETUP_FT) under the per-netns commit_mutex and per-flowtable flow_block_lock without holding rtnl_lock() or fa->lock. If a DSA user port is moved to another network namespace, flowtable bind and unbind operations in that namespace can race with init_net on fa->block_list without synchronization, and binding a flowtable in a non-initial namespace occupies fa->block_list (even though fa_port() rejects rules outside init_net), blocking init_net with -EBUSY and flushing hardware flows on unbind.
Quoted 4 lines
drivers/net/ethernet/broadcom/bgmac.c +0
-0
[ ... ]
drivers/net/ethernet/broadcom/bgmac.c int bgmac_enet_probe(struct bgmac *bgmac) · line 1587
Quoted 10 lines
drivers/net/ethernet/broadcom/bgmac.c +6
-0@@ -1560,6 +1579,17 @@ int bgmac_enet_probe(struct bgmac *bgmac) net_dev->hw_features = net_dev->features; net_dev->vlan_features = net_dev->features; + bgmac->fa =bcm_ns_fa_init (net_dev); +if (IS_ERR (bgmac->fa)) { + err =PTR_ERR (bgmac->fa); + bgmac->fa =NULL ; + goto err_phy_disconnect; + }
[Severity: Medium]
This problem wasn't introduced by this patch, but jumping to err_phy_disconnect (as well as the existing register_netdev() error path and bgmac_enet_remove()) only calls phy_disconnect() without unregistering the fixed PHY [1]:
drivers/net/ethernet/broadcom/bgmac.c:bgmac_phy_connect_direct() {
...
phy_dev = fixed_phy_register(&fphy_status, NULL);
if (IS_ERR(phy_dev)) {
dev_err(bgmac->dev, "Failed to register fixed PHY device\n");
return PTR_ERR(phy_dev);
}
err = phy_connect_direct(bgmac->net_dev, phy_dev, bgmac_adjust_link,
PHY_INTERFACE_MODE_MII);
if (err) {
dev_err(bgmac->dev, "Connecting PHY failed\n");
return err;
}
...
}When a fixed PHY was registered via bgmac_phy_connect_direct() or of_phy_get_and_connect() with a fixed-link DT node, failing to call fixed_phy_unregister() (or of_phy_deregister_fixed_link()) leaks the phy_device and one of the 8 global fixed_phy_ids slots.
[1] https://sashiko.dev/#/bug/linux-e2734269-f662-4a85-ac81-0eead2b697c2
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 7 · 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).
- [High] net: bgmac: incomplete TCP flow retirement in fa_insert() and fa_control_match()
- [Medium] If the optional flow accelerator fails to initialise, the GMAC2 Ethernet probe fails with it.
- [Medium] Neighbour handling and MTU tracking disable or flush all hardware offload on much broader triggers than the commit message…
- [Medium] Admission in fa_parse() is limited to exactly two running standalone user ports, because the FA lookup key built by fa_encode()…
- [Medium] bcm_ns_fa_setup_tc() reads and modifies fa->block_list without any driver-wide lock: the list_empty() single-flowtable -EBUSY check,…
- [Medium] Both the GMAC2 miss path (bcm_ns_fa_rx) and the GMAC0 exception path (fa_control_receive) call fa_receive_tcp_control().
- [Medium] Suspend does not take the FA out of service, and resume does not restore it.
- [Medium] net: bgmac: untracked neighbours in fa_route_check() and eviction in fa_netevent()
- [Low] The rule that only GMAC2 carries the accelerator is enforced only in bgmac-bcma.c (bgmac_probe rejects brcm,flow-accelerator when…
- [Low] The comment above fa_mtu_route_update() in bcm-ns-fa.c says 'All accesses, including the registration retry reset, hold learn_lock.'…
- [Low] The debugfs files 'fa' (fa_debug_show) and 'fa_table' (fa_table_show) print entry->cookie with %#lx.
--
net: bgmac: add Northstar IPv4 TCP/UDP NAT flowtable offload
This adds a driver for the BCM4708/BCM5301X inline flow accelerator. It exposes the accelerator through TC_SETUP_FT on GMAC2 and installs exact IPv4 TCP/UDP SNAT/DNAT rules using hashes learned from miss metadata. Hardware owners are retired on FIB, neighbour and topology changes, GMAC2 is quiesced around indirect table accesses, and debugfs status and fault injection are provided.
Quoted 6 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +0
-0@@ -0,0 +1,1897 @@
[ ... ]
drivers/net/ethernet/broadcom/bcm-ns-fa.c line 639
Quoted 13 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +13
-0+static bool fa_receive_tcp_control (struct bcm_ns_fa *fa,const struct iphdr *ip, +unsigned int total,unsigned int linear, +unsigned int port) +{ +struct fa_tuple tuple; +const struct tcphdr *tcp; + + tuple.src =get_unaligned (&ip->saddr); + tuple.dst =get_unaligned (&ip->daddr); +if (ip->ihl !=5 || (ip->frag_off &htons (IP_MF |IP_OFFSET ))) { +fa_tcp_control (fa, &tuple, port, false); +return true; + }
[Severity: Medium]
Can one spoofed packet tear down every offloaded TCP flow to a peer here?
Both bcm_ns_fa_rx() and fa_control_receive() pass IPv4 TCP packets to this function. Any such packet with IP options or fragmentation bits set reaches fa_tcp_control() with ports_valid == false. In that case fa_control_match() compares only the addresses:
size_t len = ports_valid ? sizeof(*tuple) : offsetof(struct fa_tuple, sport);
As a result, every TCP entry between that address pair on that ingress port gets FA_FLOW_CLOSING. fa_tcp_control() also sets control_pending, gates lookups globally through fa_lookup_update(), and queues control_work. That work uninstalls the matched entries and their reverse entries, and pauses GMAC2 for each table access.
The sender needs only the IP pair and a valid IP header checksum, not the ports. The B53 CFP trap rules exclude fragments, but the default IPv4 rule passes router-MAC traffic inline, so a WAN sender can reach this path.
The software flowtable sends fragments to the slow path and does not tear the flow down. Is this port-wildcard teardown intended? The commit message only says "TCP control packets retire both NAT directions".
[ ... ]
drivers/net/ethernet/broadcom/bcm-ns-fa.c line 1057
Quoted 7 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +7
-0+/* FIB notifications identify the preferred alias for each table/prefix. +* Retain only low-MTU prefixes, rather than dumping the FIB after changes. +* All accesses, including the registration retry reset, hold learn_lock. +*/ +static void fa_mtu_route_update (struct bcm_ns_fa *fa,unsigned long event, +const struct fib_entry_notifier_info *info) +{
[Severity: Low]
Is this comment accurate? fa_replace() reads route_mtu_ok while holding only fa->lock:
if (!cls->invalidate || !cls->validate || !fa->enabled ||
!READ_ONCE(fa->route_mtu_ok) ||fa_debug_show() also reads route_mtu_ok, nr_mtu_routes and mtu_tracking_failed without learn_lock. The writers use plain stores under learn_lock rather than WRITE_ONCE(), so KCSAN will report these as data races.
Admission still looks correct, because fa_insert() rechecks the generation and control_pending under learn_lock. Could the comment be updated to describe the lockless reads, and the writers be annotated to match?
[ ... ]
Quoted 2 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +2
-0+static int fa_netevent (struct notifier_block *nb,unsigned long event,void *ptr) +{
[ ... ]
Quoted 5 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +5
-0+spin_lock_bh (&fa->learn_lock); +for (i =0 ; i <ARRAY_SIZE (fa->neighbours); i++) { +struct fa_neighbour *candidate = &fa->neighbours[i]; + + if (candidate->valid && candidate->ifindex == neighbour->dev->ifindex &&
drivers/net/ethernet/broadcom/bcm-ns-fa.c line 1225
Quoted 10 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +10
-0+ candidate->address == address) { + cached = candidate; + invalidate = !(state &NUD_VALID ) ||memcmp (candidate->mac, mac,ETH_ALEN ); +break ; + } + } +if (!cached) { + cached = &fa->neighbours[fa->neighbour_next++ %FA_NEXTHOPS ]; + invalidate = cached->valid || !(state &NUD_VALID ) || !list_empty (&fa->entries); + }
[Severity: High]
Can the reply direction of a TCP flow stay installed in hardware after the connection has been closed?
fa_insert() publishes the new entry on fa->entries before it calls fa_write(). entry->reverse and other->reverse are linked only after fa_write() returns. fa_write() goes through fa_table_begin(), which pauses GMAC2 and sleeps in fsleep(). Meanwhile GMAC0 keeps delivering trapped TCP control packets to fa_control_receive().
flow_offload_rule_add() installs the original direction first and the reply direction second. Suppose a FIN or RST for the original direction arrives on GMAC0 while the reply entry is still inside fa_write(). fa_tcp_control() matches only the original entry, because fa_control_match() compares entry->in_port and entry->tuple. It sets FA_FLOW_CLOSING on that entry and queues control_work, which then blocks on fa->lock.
When fa_write() returns, the reverse-linking loop skips the peer because FA_FLOW_CLOSING is already set. Neither side gets a reverse pointer. fa_control_work() then uninstalls only the original entry, clears control_pending and re-enables lookup in fa_lookup_update(). The reply entry stays valid in the hardware table until the flowtable sends FLOW_CLS_DESTROY.
The same skip also lets a reply entry be installed when its peer has already been retired and is only waiting for FLOW_CLS_DESTROY.
A third case needs no race. flow_offload_rule_add() treats one successful direction as success. A TCP flow can therefore be installed with entry->reverse == NULL, for example when the reply hash was never learned or its bucket is full. A FIN or RST in the reply direction arrives on entry->out_port and carries entry->reply. fa_control_match() never compares either field, so nothing retires the installed direction.
This contradicts the commit message, which says "TCP control packets retire both NAT directions before tuple reuse". Until the entry is destroyed, later packets on a reused tuple could be translated and forwarded by stale hardware state without passing through conntrack.
Should fa_control_match() also match entry->reply on entry->out_port? And when fa_insert() finds its peer with FA_FLOW_CLOSING set, should it retire or abort the new entry instead of skipping the peer?
[Severity: Medium]
Does this flush all hardware flows even for neighbours that are not the next hop of any installed flow?
For an IPv4 NETEVENT_NEIGH_UPDATE on an FA port, fa_invalidate() runs in three cases:
- the neighbour is not cached and any entry exists
- a cached neighbour leaves NUD_VALID
- the ring wraps over a valid slot
None of these checks whether the neighbour is the next hop of an installed flow. So the first ARP resolution of a new LAN host, or ARP failing for a non-existent LAN address, retires every entry. It also sets control_pending until control_work runs.
fa_mtu_route_update() has a similar global effect:
fa->route_mtu_ok = !fa->nr_mtu_routes && !fa->mtu_tracking_failed;
A single low-MTU prefix in any table, for any destination, gates lookup in fa_lookup_update() and makes fa_replace() reject every rule.
mtu_tracking_failed is also cleared only in fa_fib_reset(). One GFP_ATOMIC failure, or more than FA_MTU_ROUTES_MAX prefixes, disables offload until reprobe, even after those routes are deleted.
The commit message describes retiring owners on changes "that withdraw their hardware paths" and tracking low-MTU prefixes. Are these wider triggers intended? If so, could they be narrowed or documented?
[ ... ]
Quoted 19 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +19
-0+switch (block->command) { +case FLOW_BLOCK_BIND : + cb =flow_block_cb_lookup (block->block, fa_block_cb, fa); +if (cb) { +flow_block_cb_incref (cb); +return 0 ; + } +/* Different flowtables have independent cookies and policy. The +* hardware cannot partition tables by ingress port or netns. +*/ +if (!list_empty (&fa->block_list)) +return -EBUSY ; + cb =flow_block_cb_alloc (fa_block_cb, fa, fa,NULL ); +if (IS_ERR (cb)) +return PTR_ERR (cb); +flow_block_cb_incref (cb); +flow_block_cb_add (cb, block); +list_add_tail (&cb->driver_list, &fa->block_list); +return 0 ;
drivers/net/ethernet/broadcom/bcm-ns-fa.c line 1604
Quoted 10 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +10
-0+case FLOW_BLOCK_UNBIND : + cb =flow_block_cb_lookup (block->block, fa_block_cb, fa); +if (!cb) +return -ENOENT ; +bcm_ns_fa_flush (fa); +if (!flow_block_cb_decref (cb)) { +flow_block_cb_remove (cb, block); +list_del (&cb->driver_list); + } +return 0 ;
[Severity: Medium]
What serializes fa->block_list across different flowtables?
The struct comment says fa->lock protects flow blocks, but this path does not take it. Around ndo_setup_tc, nf_flow_table_offload_cmd() holds only that flowtable's own flow_block_lock:
down_write(&flowtable->flow_block_lock);
err = dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_FT, bo);
up_write(&flowtable->flow_block_lock);DSA user ports can be moved to another netns. dsa_user_setup_ft_block() sends every user port's bind to the same conduit, and so to the same struct bcm_ns_fa. Two flowtables in different namespaces could both see list_empty() as true and both call list_add_tail() on fa->block_list. A bind could also race with list_del() from an unbind in the other namespace.
Can this corrupt fa->block_list and bind two flowtables to one hardware table?
[ ... ]
Quoted 6 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +6
-0+static int fa_netdev_event (struct notifier_block *nb,unsigned long event,void *ptr) +{ + struct bcm_ns_fa *fa = container_of(nb, struct bcm_ns_fa, netdev_nb); +struct net_device *dev =netdev_notifier_info_to_dev (ptr); + +/* New active ports or upper devices change the lookup domain. Flush
drivers/net/ethernet/broadcom/bcm-ns-fa.c line 1663
Quoted 10 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +10
-0+* synchronously before the new topology becomes usable. +*/ +if (event !=NETDEV_GOING_DOWN && event !=NETDEV_DOWN && + event !=NETDEV_PRE_CHANGEADDR && + event !=NETDEV_CHANGEADDR && + event !=NETDEV_CHANGE && + event !=NETDEV_CHANGEMTU && + event !=NETDEV_PRECHANGEUPPER && event !=NETDEV_CHANGEUPPER && + event !=NETDEV_UP && event !=NETDEV_UNREGISTER ) +return NOTIFY_DONE ;
[Severity: Medium]
Is the next-hop neighbour of an admitted flow guaranteed to be in fa->neighbours[]?
fa_route_check() looks up and validates the next-hop neighbour, but neither it nor fa_insert() records it. fa->neighbours[] is filled only by fa_netevent(), and only for NETEVENT_NEIGH_UPDATE events that arrive while fa_port() is true for the device. fa_neighbour_activity() probes only neighbours that are in this cache and whose MAC matches a referenced fa->nh[] entry.
The cache is a 128-slot ring. Every update for an address that is not already cached takes the next slot. That includes NUD_INCOMPLETE and NUD_FAILED transitions, which are stored with valid set. An ARP scan of the LAN, or more than 128 active hosts, can therefore evict the next hop of an installed flow.
After that, the neighbour is never passed to neigh_event_send(). It stays NUD_STALE while all its traffic is forwarded in hardware. If the peer's MAC changes without a gratuitous ARP, the hardware keeps sending to the old address. This defeats the commit message's "Drive neighbour probes from hardware counter activity".
There is also a race on the first flow. For an uncached neighbour, fa_netevent() invalidates only in three cases:
- the reused slot had valid set
- the new state is not NUD_VALID
- fa->entries is not empty
Suppose the first flow has passed fa_route_check() and fa_learn_lookup(), but fa_insert() is still sleeping in fa_mac_get() before list_add_rcu(). fa->entries is still empty at that point. A NUD_VALID update that changes the MAC then does not invalidate. It also leaves control_generation and invalidate_generation unchanged, so the generation check in fa_insert() passes. The old MAC from rule->eth is written to the next-hop table.
Could fa_insert() record the admitted neighbour in fa->neighbours[]? Alternatively, could fa_neighbour_activity() look up neighbours from the installed entries rather than the ring? Separately, should the uncached case in fa_netevent() invalidate whenever an insertion may be in flight?
[Severity: Medium]
Is NETDEV_UP early enough to flush before a third port becomes usable?
fa_parse() admits rules only while exactly two user ports are running, because the lookup key built by fa_encode() has no ingress port or VLAN. When a third port is opened, __dev_open() calls ndo_open first:
dsa_user_open()
dsa_port_enable_rt()
ds->ops->port_enable()
phylink_start()NETDEV_UP is sent only after that. The B53 notifier installs the per-port router-MAC allow rule at NETDEV_REGISTER, so IPv4 frames from the new port can already reach the inline FA.
In that window, a frame could arrive on the new port with a pool router MAC as DA and a tuple matching an installed entry. Could it be NATed and forwarded in hardware, bypassing that port's ingress policy? Would handling NETDEV_PRE_UP here close the window?
[ ... ]
drivers/net/ethernet/broadcom/bcm-ns-fa.c line 1702
Quoted 2 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +2
-0+seq_printf (s,"%u %#lx %s %s %u\n" , i, entry->cookie, + entry->in->name, entry->out->name, hits);
[Severity: Low]
Does this print a raw kernel heap address? The cookie comes from nf_flow_offload_init():
cls_flow->cookie = (unsigned long)tuple;
Printing it with %#lx bypasses %p hashing and kptr_restrict. fa_table_show() prints the cookie the same way. Could both use %p or drop the cookie?
[ ... ]
Quoted 4 lines
drivers/net/ethernet/broadcom/bgmac-bcma.c +0
-0
[ ... ]
drivers/net/ethernet/broadcom/bgmac-bcma.c static int bgmac_probe(struct bcma_device *core) · line 140
Quoted 11 lines
drivers/net/ethernet/broadcom/bgmac-bcma.c +4
-0@@ -130,6 +131,10 @@ static int bgmac_probe(struct bcma_device *core)const u8 *mac;int err; +if (of_property_present (core->dev.of_node,"brcm,flow-accelerator" ) && + core->core_unit !=2 ) +return -EINVAL ; + bgmac =bgmac_alloc (&core->dev);if (!bgmac)return -ENOMEM ;
[Severity: Low]
The GMAC2-only rule is enforced only here. bcm_ns_fa_init() is called from the shared bgmac_enet_probe(), which bgmac-platform.c also uses, and bgmac-platform has no equivalent check. Is platform support intended?
The new bcm_ns_fa_flush() call in bgmac_enet_suspend() can only be reached through bgmac-platform's dev_pm_ops, because bgmac_bcma_driver has no PM callbacks. On the BCMA configurations the binding allows, that hook is dead code. bgmac_enet_resume() also never redoes the FA setup from bcm_ns_fa_init().
The Kconfig change also adds this to BGMAC_PLATFORM:
depends on BCM_NS_FA || !BCM_NS_FA
If platform support is intended, should it get the GMAC2 check and a resume reinit? If not, should the suspend hook and the Kconfig coupling be dropped?
Quoted 4 lines
drivers/net/ethernet/broadcom/bgmac.c +0
-0
[ ... ]
Quoted 5 lines
drivers/net/ethernet/broadcom/bgmac.c +1
-0@@ -1560,6 +1579,17 @@ int bgmac_enet_probe(struct bgmac *bgmac) net_dev->hw_features = net_dev->features; net_dev->vlan_features = net_dev->features; + bgmac->fa =bcm_ns_fa_init (net_dev);
drivers/net/ethernet/broadcom/bgmac.c int bgmac_enet_probe(struct bgmac *bgmac) · line 1592
Quoted 10 lines
drivers/net/ethernet/broadcom/bgmac.c +10
-0+if (IS_ERR (bgmac->fa)) { + err =PTR_ERR (bgmac->fa); + bgmac->fa =NULL ; + goto err_phy_disconnect; + } +if (bgmac->fa) { + net_dev->features |=NETIF_F_HW_TC ; + net_dev->hw_features |=NETIF_F_HW_TC ; + } +
[Severity: Medium]
Should a failure in the optional accelerator take down the whole GMAC2 interface?
bcm_ns_fa_init() returns ERR_PTR in many cases:
- the compatible does not match
- resource or ioremap errors
- the FA_STATUS init-done poll times out
- a pool-table fa_write() fails
- a notifier fails to register (register_fib_notifier() can return -EBUSY)
- devm_add_action_or_reset() fails
Each of these skips register_netdev() here. With CONFIG_BCM_NS_FA=n the same DT probes fine, and runtime table failures fall back to software.
Could this warn and continue with bgmac->fa = NULL, at least for the hardware and transient errors? The commit message does not mention this new probe dependency.
[ ... ]
drivers/net/ethernet/broadcom/bgmac.c int bgmac_enet_suspend(struct bgmac *bgmac) · line 1646
Quoted 8 lines
drivers/net/ethernet/broadcom/bgmac.c +1
-0@@ -1610,6 +1640,7 @@ int bgmac_enet_suspend(struct bgmac *bgmac)netif_tx_unlock (bgmac->net_dev);bgmac_chip_intrs_off (bgmac); +bcm_ns_fa_flush (bgmac->fa);bgmac_chip_reset (bgmac);bgmac_dma_cleanup (bgmac);
[Severity: Medium]
This flushes the entries, but fa->enabled stays set, lookups are not gated, and netif_running() is still true. What happens when the table is accessed after bgmac_chip_reset()?
A later FLOW_CLS_REPLACE, or a read of the fa or fa_table debugfs files, goes through fa_table_begin(). That rewrites BGMAC_DEV_CTL and polls the MAC that has just been reset:
err = read_poll_timeout(bgmac_read, val, val & BGMAC_DS_PO, 1, 1000,
false, bgmac, BGMAC_DEV_STATUS);If that poll times out, fa_fail() latches fa->failed until reprobe.
bgmac_enet_resume() also does not reprogram the setup done in bcm_ns_fa_init(): FA_CTL, FA_BRCM_HDR, FA_L2_SKIP, FA_L2_TAG, FA_IPV4, FA_NAPT and the pool clear. If those registers are lost across suspend, would the driver keep publishing entries to an FA whose configuration no longer matches its state? This path can only be reached through bgmac-platform's PM ops.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116222519.1416501-1-florian.fainelli%40broadcom.com
Florian Fainelli
maintainerQuoted 477 lines · On 11/17/26 15:29, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 7 · 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).
- [High] net: bgmac: incomplete TCP flow retirement in
fa_insert()andfa_control_match()
- [Medium] If the optional flow accelerator fails to initialise, the GMAC2 Ethernet probe fails with it.
- [Medium] Neighbour handling and MTU tracking disable or flush all hardware offload on much broader triggers than the commit message…
- [Medium] Admission infa_parse()is limited to exactly two running standalone user ports, because the FA lookup key built by fa_encode()…
- [Medium]bcm_ns_fa_setup_tc()reads and modifiesfa->block_listwithout any driver-wide lock: thelist_empty()single-flowtable-EBUSYcheck,…
- [Medium] Both the GMAC2 miss path (bcm_ns_fa_rx) and the GMAC0 exception path (fa_control_receive) callfa_receive_tcp_control().
- [Medium] Suspend does not take the FA out of service, and resume does not restore it.
- [Medium] net: bgmac: untracked neighbours infa_route_check()and eviction infa_netevent()
- [Low] The rule that only GMAC2 carries the accelerator is enforced only inbgmac-bcma.c(bgmac_proberejects brcm,flow-accelerator when…
- [Low] The comment abovefa_mtu_route_update()inbcm-ns-fa.csays 'All accesses, including the registration retry reset, hold learn_lock.'…
- [Low] The debugfs files 'fa' (fa_debug_show) and 'fa_table' (fa_table_show) printentry->cookiewith %#lx.--
net: bgmac: add Northstar IPv4 TCP/UDP NAT flowtable offload
This adds a driver for the BCM4708/BCM5301X inline flow accelerator. It exposes the accelerator through
TC_SETUP_FTon GMAC2 and installs exact IPv4 TCP/UDP SNAT/DNAT rules using hashes learned from miss metadata. Hardware owners are retired on FIB, neighbour and topology changes, GMAC2 is quiesced around indirect table accesses, and debugfs status and fault injection are provided.Quoted 6 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +0
-0@@ -0,0 +1,1897 @@[ ... ]
drivers/net/ethernet/broadcom/bcm-ns-fa.c line 639
Quoted 13 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +13
-0+static bool fa_receive_tcp_control (struct bcm_ns_fa *fa,const struct iphdr *ip, +unsigned int total,unsigned int linear, +unsigned int port) +{ +struct fa_tuple tuple; +const struct tcphdr *tcp; + + tuple.src =get_unaligned (&ip->saddr); + tuple.dst =get_unaligned (&ip->daddr); +if (ip->ihl !=5 || (ip->frag_off &htons (IP_MF |IP_OFFSET ))) { +fa_tcp_control (fa, &tuple, port, false); +return true; + }[Severity: Medium]
Can one spoofed packet tear down every offloaded TCP flow to a peer here?Both
bcm_ns_fa_rx()andfa_control_receive()pass IPv4 TCP packets to this function. Any such packet with IP options or fragmentation bits set reachesfa_tcp_control()withports_valid== false. In that casefa_control_match()compares only the addresses:size_t len = ports_valid ? sizeof(*tuple) : offsetof(struct fa_tuple, sport);As a result, every TCP entry between that address pair on that ingress port gets
FA_FLOW_CLOSING.fa_tcp_control()also setscontrol_pending, gates lookups globally throughfa_lookup_update(), and queuescontrol_work. That work uninstalls the matched entries and their reverse entries, and pauses GMAC2 for each table access.The sender needs only the IP pair and a valid IP header checksum, not the ports. The B53 CFP trap rules exclude fragments, but the default IPv4 rule passes router-MAC traffic inline, so a WAN sender can reach this path.
The software flowtable sends fragments to the slow path and does not tear the flow down. Is this port-wildcard teardown intended? The commit message only says "TCP control packets retire both NAT directions".
[ ... ]
drivers/net/ethernet/broadcom/bcm-ns-fa.c line 1057
Quoted 7 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +7
-0+/* FIB notifications identify the preferred alias for each table/prefix. +* Retain only low-MTU prefixes, rather than dumping the FIB after changes. +* All accesses, including the registration retry reset, hold learn_lock. +*/ +static void fa_mtu_route_update (struct bcm_ns_fa *fa,unsigned long event, +const struct fib_entry_notifier_info *info) +{[Severity: Low]
Is this comment accurate?fa_replace()readsroute_mtu_okwhile holding onlyfa->lock:if (!cls->invalidate || !cls->validate || !fa->enabled || !READ_ONCE(fa->route_mtu_ok) ||
fa_debug_show()also readsroute_mtu_ok,nr_mtu_routesandmtu_tracking_failedwithoutlearn_lock. The writers use plain stores underlearn_lockrather thanWRITE_ONCE(), so KCSAN will report these as data races.Admission still looks correct, because
fa_insert()rechecks the generation andcontrol_pendingunderlearn_lock. Could the comment be updated to describe the lockless reads, and the writers be annotated to match?[ ... ]
Quoted 2 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +2
-0+static int fa_netevent (struct notifier_block *nb,unsigned long event,void *ptr) +{[ ... ]
Quoted 5 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +5
-0+spin_lock_bh (&fa->learn_lock); +for (i =0 ; i <ARRAY_SIZE (fa->neighbours); i++) { +struct fa_neighbour *candidate = &fa->neighbours[i]; + + if (candidate->valid && candidate->ifindex == neighbour->dev->ifindex &&drivers/net/ethernet/broadcom/bcm-ns-fa.c line 1225
Quoted 10 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +10
-0+ candidate->address == address) { + cached = candidate; + invalidate = !(state &NUD_VALID ) ||memcmp (candidate->mac, mac,ETH_ALEN ); +break ; + } + } +if (!cached) { + cached = &fa->neighbours[fa->neighbour_next++ %FA_NEXTHOPS ]; + invalidate = cached->valid || !(state &NUD_VALID ) || !list_empty (&fa->entries); + }[Severity: High]
Can the reply direction of a TCP flow stay installed in hardware after the connection has been closed?
fa_insert()publishes the new entry onfa->entriesbefore it callsfa_write().entry->reverseandother->reverseare linked only afterfa_write()returns.fa_write()goes throughfa_table_begin(), which pauses GMAC2 and sleeps infsleep(). Meanwhile GMAC0 keeps delivering trapped TCP control packets tofa_control_receive().
flow_offload_rule_add()installs the original direction first and the reply direction second. Suppose a FIN or RST for the original direction arrives on GMAC0 while the reply entry is still insidefa_write().fa_tcp_control()matches only the original entry, becausefa_control_match()comparesentry->in_portandentry->tuple. It setsFA_FLOW_CLOSINGon that entry and queuescontrol_work, which then blocks onfa->lock.When
fa_write()returns, the reverse-linking loop skips the peer becauseFA_FLOW_CLOSINGis already set. Neither side gets a reverse pointer.fa_control_work()then uninstalls only the original entry, clearscontrol_pendingand re-enables lookup infa_lookup_update(). The reply entry stays valid in the hardware table until the flowtable sendsFLOW_CLS_DESTROY.The same skip also lets a reply entry be installed when its peer has already been retired and is only waiting for
FLOW_CLS_DESTROY.A third case needs no race.
flow_offload_rule_add()treats one successful direction as success. A TCP flow can therefore be installed withentry->reverse== NULL, for example when the reply hash was never learned or its bucket is full. A FIN or RST in the reply direction arrives onentry->out_portand carriesentry->reply.fa_control_match()never compares either field, so nothing retires the installed direction.This contradicts the commit message, which says "TCP control packets retire both NAT directions before tuple reuse". Until the entry is destroyed, later packets on a reused tuple could be translated and forwarded by stale hardware state without passing through conntrack.
Should
fa_control_match()also matchentry->replyonentry->out_port? And whenfa_insert()finds its peer withFA_FLOW_CLOSINGset, should it retire or abort the new entry instead of skipping the peer?[Severity: Medium]
Does this flush all hardware flows even for neighbours that are not the next hop of any installed flow?For an IPv4
NETEVENT_NEIGH_UPDATEon an FA port,fa_invalidate()runs in three cases:- the neighbour is not cached and any entry exists
- a cached neighbour leavesNUD_VALID
- the ring wraps over a valid slotNone of these checks whether the neighbour is the next hop of an installed flow. So the first ARP resolution of a new LAN host, or ARP failing for a non-existent LAN address, retires every entry. It also sets
control_pendinguntilcontrol_workruns.
fa_mtu_route_update()has a similar global effect:fa->route_mtu_ok = !fa->nr_mtu_routes && !fa->mtu_tracking_failed;A single low-MTU prefix in any table, for any destination, gates lookup in
fa_lookup_update()and makesfa_replace()reject every rule.
mtu_tracking_failedis also cleared only infa_fib_reset(). OneGFP_ATOMICfailure, or more thanFA_MTU_ROUTES_MAXprefixes, disables offload until reprobe, even after those routes are deleted.The commit message describes retiring owners on changes "that withdraw their hardware paths" and tracking low-MTU prefixes. Are these wider triggers intended? If so, could they be narrowed or documented?
[ ... ]
Quoted 19 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +19
-0+switch (block->command) { +case FLOW_BLOCK_BIND : + cb =flow_block_cb_lookup (block->block, fa_block_cb, fa); +if (cb) { +flow_block_cb_incref (cb); +return 0 ; + } +/* Different flowtables have independent cookies and policy. The +* hardware cannot partition tables by ingress port or netns. +*/ +if (!list_empty (&fa->block_list)) +return -EBUSY ; + cb =flow_block_cb_alloc (fa_block_cb, fa, fa,NULL ); +if (IS_ERR (cb)) +return PTR_ERR (cb); +flow_block_cb_incref (cb); +flow_block_cb_add (cb, block); +list_add_tail (&cb->driver_list, &fa->block_list); +return 0 ;drivers/net/ethernet/broadcom/bcm-ns-fa.c line 1604
Quoted 10 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +10
-0+case FLOW_BLOCK_UNBIND : + cb =flow_block_cb_lookup (block->block, fa_block_cb, fa); +if (!cb) +return -ENOENT ; +bcm_ns_fa_flush (fa); +if (!flow_block_cb_decref (cb)) { +flow_block_cb_remove (cb, block); +list_del (&cb->driver_list); + } +return 0 ;[Severity: Medium]
What serializesfa->block_listacross different flowtables?The struct comment says
fa->lockprotects flow blocks, but this path does not take it. Aroundndo_setup_tc,nf_flow_table_offload_cmd()holds only that flowtable's ownflow_block_lock:down_write(&flowtable->flow_block_lock); err = dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_FT, bo); up_write(&flowtable->flow_block_lock);DSA user ports can be moved to another netns.
dsa_user_setup_ft_block()sends every user port's bind to the same conduit, and so to the same structbcm_ns_fa. Two flowtables in different namespaces could both seelist_empty()as true and both calllist_add_tail()onfa->block_list. A bind could also race withlist_del()from an unbind in the other namespace.Can this corrupt
fa->block_listand bind two flowtables to one hardware table?[ ... ]
Quoted 6 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +6
-0+static int fa_netdev_event (struct notifier_block *nb,unsigned long event,void *ptr) +{ + struct bcm_ns_fa *fa = container_of(nb, struct bcm_ns_fa, netdev_nb); +struct net_device *dev =netdev_notifier_info_to_dev (ptr); + +/* New active ports or upper devices change the lookup domain. Flush drivers/net/ethernet/broadcom/bcm-ns-fa.c line 1663
Quoted 10 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +10
-0+* synchronously before the new topology becomes usable. +*/ +if (event !=NETDEV_GOING_DOWN && event !=NETDEV_DOWN && + event !=NETDEV_PRE_CHANGEADDR && + event !=NETDEV_CHANGEADDR && + event !=NETDEV_CHANGE && + event !=NETDEV_CHANGEMTU && + event !=NETDEV_PRECHANGEUPPER && event !=NETDEV_CHANGEUPPER && + event !=NETDEV_UP && event !=NETDEV_UNREGISTER ) +return NOTIFY_DONE ;[Severity: Medium]
Is the next-hop neighbour of an admitted flow guaranteed to be in fa->neighbours[]?
fa_route_check()looks up and validates the next-hop neighbour, but neither it norfa_insert()records it. fa->neighbours[] is filled only byfa_netevent(), and only forNETEVENT_NEIGH_UPDATEevents that arrive whilefa_port()is true for the device.fa_neighbour_activity()probes only neighbours that are in this cache and whose MAC matches a referenced fa->nh[] entry.The cache is a 128-slot ring. Every update for an address that is not already cached takes the next slot. That includes
NUD_INCOMPLETEandNUD_FAILEDtransitions, which are stored with valid set. An ARP scan of the LAN, or more than 128 active hosts, can therefore evict the next hop of an installed flow.After that, the neighbour is never passed to
neigh_event_send(). It staysNUD_STALEwhile all its traffic is forwarded in hardware. If the peer's MAC changes without a gratuitous ARP, the hardware keeps sending to the old address. This defeats the commit message's "Drive neighbour probes from hardware counter activity".There is also a race on the first flow. For an uncached neighbour,
fa_netevent()invalidates only in three cases:- the reused slot had valid set
- the new state is notNUD_VALID
-fa->entriesis not emptySuppose the first flow has passed
fa_route_check()andfa_learn_lookup(), butfa_insert()is still sleeping infa_mac_get()beforelist_add_rcu().fa->entriesis still empty at that point. ANUD_VALIDupdate that changes the MAC then does not invalidate. It also leavescontrol_generationandinvalidate_generationunchanged, so the generation check infa_insert()passes. The old MAC fromrule->ethis written to the next-hop table.Could
fa_insert()record the admitted neighbour in fa->neighbours[]? Alternatively, couldfa_neighbour_activity()look up neighbours from the installed entries rather than the ring? Separately, should the uncached case infa_netevent()invalidate whenever an insertion may be in flight?[Severity: Medium]
IsNETDEV_UPearly enough to flush before a third port becomes usable?
fa_parse()admits rules only while exactly two user ports are running, because the lookup key built byfa_encode()has no ingress port or VLAN. When a third port is opened,__dev_open()callsndo_openfirst:dsa_user_open() dsa_port_enable_rt() ds->ops->port_enable() phylink_start()
NETDEV_UPis sent only after that. The B53 notifier installs the per-port router-MAC allow rule atNETDEV_REGISTER, so IPv4 frames from the new port can already reach the inline FA.In that window, a frame could arrive on the new port with a pool router MAC as DA and a tuple matching an installed entry. Could it be NATed and forwarded in hardware, bypassing that port's ingress policy? Would handling
NETDEV_PRE_UPhere close the window?[ ... ]
drivers/net/ethernet/broadcom/bcm-ns-fa.c line 1702
Quoted 2 lines
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +2
-0+seq_printf (s,"%u %#lx %s %s %u\n" , i, entry->cookie, + entry->in->name, entry->out->name, hits);[Severity: Low]
Does this print a raw kernel heap address? The cookie comes fromnf_flow_offload_init():cls_flow->cookie = (unsigned long)tuple;Printing it with %#lx bypasses %p hashing and
kptr_restrict.fa_table_show()prints the cookie the same way. Could both use %p or drop the cookie?[ ... ]
Quoted 4 lines
drivers/net/ethernet/broadcom/bgmac-bcma.c +0
-0[ ... ]
drivers/net/ethernet/broadcom/bgmac-bcma.c static int bgmac_probe(struct bcma_device *core) · line 140
Quoted 11 lines
drivers/net/ethernet/broadcom/bgmac-bcma.c +4
-0@@ -130,6 +131,10 @@ static int bgmac_probe(struct bcma_device *core)const u8 *mac;int err; +if (of_property_present (core->dev.of_node,"brcm,flow-accelerator" ) && + core->core_unit !=2 ) +return -EINVAL ; + bgmac =bgmac_alloc (&core->dev);if (!bgmac)return -ENOMEM ;[Severity: Low]
The GMAC2-only rule is enforced only here.bcm_ns_fa_init()is called from the sharedbgmac_enet_probe(), whichbgmac-platform.calso uses, and bgmac-platform has no equivalent check. Is platform support intended?The new
bcm_ns_fa_flush()call inbgmac_enet_suspend()can only be reached through bgmac-platform'sdev_pm_ops, becausebgmac_bcma_driverhas no PM callbacks. On the BCMA configurations the binding allows, that hook is dead code.bgmac_enet_resume()also never redoes the FA setup frombcm_ns_fa_init().The
Kconfigchange also adds this toBGMAC_PLATFORM:depends on BCM_NS_FA || !BCM_NS_FAIf platform support is intended, should it get the GMAC2 check and a resume reinit? If not, should the suspend hook and the
Kconfigcoupling be dropped?Quoted 4 lines
drivers/net/ethernet/broadcom/bgmac.c +0
-0[ ... ]
Quoted 5 lines
drivers/net/ethernet/broadcom/bgmac.c +1
-0@@ -1560,6 +1579,17 @@ int bgmac_enet_probe(struct bgmac *bgmac) net_dev->hw_features = net_dev->features; net_dev->vlan_features = net_dev->features; + bgmac->fa =bcm_ns_fa_init (net_dev);drivers/net/ethernet/broadcom/bgmac.c int bgmac_enet_probe(struct bgmac *bgmac) · line 1592
Quoted 10 lines
drivers/net/ethernet/broadcom/bgmac.c +10
-0+if (IS_ERR (bgmac->fa)) { + err =PTR_ERR (bgmac->fa); + bgmac->fa =NULL ; + goto err_phy_disconnect; + } +if (bgmac->fa) { + net_dev->features |=NETIF_F_HW_TC ; + net_dev->hw_features |=NETIF_F_HW_TC ; + } +[Severity: Medium]
Should a failure in the optional accelerator take down the whole GMAC2 interface?
bcm_ns_fa_init()returnsERR_PTRin many cases:- the compatible does not match
- resource or ioremap errors
- theFA_STATUSinit-done poll times out
- a pool-tablefa_write()fails
- a notifier fails to register (register_fib_notifier()can return-EBUSY)
-devm_add_action_or_reset()failsEach of these skips
register_netdev()here. WithCONFIG_BCM_NS_FA=nthe same DT probes fine, and runtime table failures fall back to software.Could this warn and continue with
bgmac->fa= NULL, at least for the hardware and transient errors? The commit message does not mention this new probe dependency.[ ... ]
drivers/net/ethernet/broadcom/bgmac.c int bgmac_enet_suspend(struct bgmac *bgmac) · line 1646
Quoted 8 lines
drivers/net/ethernet/broadcom/bgmac.c +1
-0@@ -1610,6 +1640,7 @@ int bgmac_enet_suspend(struct bgmac *bgmac)netif_tx_unlock (bgmac->net_dev);bgmac_chip_intrs_off (bgmac); +bcm_ns_fa_flush (bgmac->fa);bgmac_chip_reset (bgmac);bgmac_dma_cleanup (bgmac);[Severity: Medium]
This flushes the entries, butfa->enabledstays set, lookups are not gated, andnetif_running()is still true. What happens when the table is accessed afterbgmac_chip_reset()?A later
FLOW_CLS_REPLACE, or a read of the fa orfa_tabledebugfs files, goes throughfa_table_begin(). That rewritesBGMAC_DEV_CTLand polls the MAC that has just been reset:err = read_poll_timeout(bgmac_read, val, val & BGMAC_DS_PO, 1, 1000, false, bgmac, BGMAC_DEV_STATUS);
Quoted 9 lines
If that poll times out,
fa_fail()latchesfa->faileduntil reprobe.
bgmac_enet_resume()also does not reprogram the setup done inbcm_ns_fa_init():FA_CTL,FA_BRCM_HDR,FA_L2_SKIP,FA_L2_TAG,FA_IPV4,FA_NAPTand the pool clear. If those registers are lost across suspend, would the driver keep publishing entries to an FA whose configuration no longer matches its state? This path can only be reached through bgmac-platform's PM ops.
[High] incomplete TCP flow retirement
Agreed. v2 matches control packets against both directions of an entry (each on its own ingress port), and when a direction is inserted while its peer is already being retired the new entry is retired too.
[Medium] wildcard teardown for IP options/fragments
Not intended. v2 uses the exact ports, found with ihl, and leaves
non-first fragments and unparseable headers to the slow path, as the software flowtable does.
[Medium] setup_tc locking, other netns
Agreed: block_list is now protected by fa->lock and only the initial namespace can bind.
[Medium] neighbours / first-flow race / NETDEV_UP
v2 probes the next hop of every installed entry instead of the cache of updates, checks the neighbour again once an entry is published, and flushes on NETDEV_PRE_UP.
[Medium] probe failure, broad invalidations, suspend
The accelerator is inline in the data path and the tag format depends on its configuration, hence the probe failure; this is now in the commit message together with the broad invalidation triggers. Suspend/resume is not supported (BCMA has no PM callbacks) and the unreachable flush is removed.
[Low] list_del_rcu locking, comments, debugfs cookie, GMAC2 check
Fixed in v2, except for the check in the platform driver: bgmac-platform has no brcm,flow-accelerator property, so FA does not initialize there.
The fixed PHY leak is pre-existing and unrelated, I will send a separate patch.
pw-bot: cr
Signature · 1 line
Florian
Florian Fainelli
maintainerPATCH 8/9 net: add KUnit coverage for FA and flowtable path validation
In reply to Florian FainelliExercise Northstar NAT fields, byte order, protocol-aware hash learning, TCP control identity, lookup gating, MTU tracking and owner invalidation. Check B53 UDF layout and every IPv4 packet length, failed- guard readiness, and FA/ordinary switch tags.
Test cached-route owner validation with route-cookie expiry, changed or invalid neighbours, absent route context and unsupported stacked paths. Require explicit owner validation to detect an expired validation-only dst even though the generic packet/GC helper ignores that reference.
Add seven scenarios using real route initialization and the private GC
step: ordinary direct software forwarding, validation-only references, direct tunnels with and without hardware requested, neighbour routes with and without hardware requested, and XFRM. Check legacy validation policy, GC teardown and balanced dst references. The validation-only scenario fails both packet and GC expectations before the policy fix.
The independent netfilter prerequisite already carries its two lifetime tests and standalone configuration. Extend that test configuration's help for these path cases, embed private tests in their parent units, and keep the combined FA configuration beside the backend.
--- MAINTAINERS | 3 + drivers/net/dsa/b53/Kconfig | 11 + drivers/net/dsa/b53/b53_common.c | 4 + drivers/net/dsa/b53/b53_fa_test.c | 102 +++ drivers/net/ethernet/broadcom/.kunitconfig | 21 + drivers/net/ethernet/broadcom/Kconfig | 11 + .../net/ethernet/broadcom/bcm-ns-fa-test.c | 661 ++++++++++++++++++ drivers/net/ethernet/broadcom/bcm-ns-fa.c | 4 + net/dsa/Kconfig | 11 + net/dsa/tag_brcm.c | 4 + net/dsa/tag_brcm_test.c | 199 ++++++ net/netfilter/Kconfig | 10 +- net/netfilter/nf_flow_table_core_test.c | 85 +++ net/netfilter/nf_flow_table_offload.c | 4 + net/netfilter/nf_flow_table_offload_test.c | 129 ++++ 15 files changed, 1254 insertions(+), 5 deletions(-) create mode 100644 drivers/net/dsa/b53/b53_fa_test.c create mode 100644 drivers/net/ethernet/broadcom/.kunitconfig create mode 100644 drivers/net/ethernet/broadcom/bcm-ns-fa-test.c create mode 100644 net/dsa/tag_brcm_test.c create mode 100644 net/netfilter/nf_flow_table_offload_test.c
MAINTAINERS +3 -0
@@ -5305,6 +5305,7 @@ F: drivers/net/dsa/bcm_sf2* F: include/linux/dsa/brcm.h F: include/linux/platform_data/b53.h F: net/dsa/tag_brcm.c +F: net/dsa/tag_brcm_test.c BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE M: Florian Fainelli <[email protected]>
@@ -5671,6 +5672,8 @@ S: Maintained F: Documentation/devicetree/bindings/net/brcm,amac.yaml F: Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml F: Documentation/devicetree/bindings/net/brcm,bcm5301x-gmac.yaml +F: drivers/net/dsa/b53/b53_fa_test.c +F: drivers/net/ethernet/broadcom/.kunitconfig F: drivers/net/ethernet/broadcom/bcm-ns-fa* F: drivers/net/ethernet/broadcom/bgmac* F: drivers/net/ethernet/broadcom/unimac.h
drivers/net/dsa/b53/Kconfig +11 -0
@@ -13,6 +13,17 @@ menuconfig B53 BCM5325E, BCM5365, BCM539x, BCM53115 and BCM53125 as well as BCM63XX integrated switches. +config B53_FA_KUNIT_TEST + bool "KUnit tests for B53 FA exception guards" if !KUNIT_ALL_TESTS + depends on KUNIT=y && B53 + default KUNIT_ALL_TESTS + help + Tests are compiled into the parent driver and require built-in KUnit. + Verify the original FA classifier field layout and complete packet + length range used to divert unsafe packets around the accelerator. + Check cross-word destination MAC encoding and every 16-bit IPv4 + packet length against the standard MTU without accessing hardware. + config B53_SPI_DRIVER tristate "B53 SPI connected switch driver" depends on B53 && SPI
drivers/net/dsa/b53/b53_common.c +4 -0
@@ -3802,6 +3802,10 @@ int b53_switch_register(struct b53_device *dev) }EXPORT_SYMBOL (b53_switch_register); +#if IS_ENABLED (CONFIG_B53_FA_KUNIT_TEST ) +#include "b53_fa_test.c" +#endif +MODULE_AUTHOR ("Jonas Gorski <[email protected]>" );MODULE_DESCRIPTION ("B53 switch library" );MODULE_LICENSE ("Dual BSD/GPL" );
drivers/net/dsa/b53/b53_fa_test.c new file +102 -0
102 lines not on this page · raw message
drivers/net/ethernet/broadcom/.kunitconfig new file +21 -0
@@ -0,0 +1,21 @@ +CONFIG_KUNIT=y +CONFIG_DEBUG_KERNEL=y +CONFIG_NET_DEV_REFCNT_TRACKER=y +CONFIG_COMPILE_TEST=y +CONFIG_NET=y +CONFIG_INET=y +CONFIG_NETDEVICES=y +CONFIG_NET_VENDOR_BROADCOM=y +CONFIG_NETFILTER=y +CONFIG_NF_CONNTRACK=y +CONFIG_NF_TABLES=y +CONFIG_NF_FLOW_TABLE=y +CONFIG_NF_FLOW_TABLE_KUNIT_TEST=y +CONFIG_NET_DSA=y +CONFIG_OF=y +CONFIG_BCM_NS_FA=y +CONFIG_BCM_NS_FA_KUNIT_TEST=y +CONFIG_NET_DSA_TAG_BRCM_FA=y +CONFIG_NET_DSA_TAG_BRCM_FA_KUNIT_TEST=y +CONFIG_B53=y +CONFIG_B53_FA_KUNIT_TEST=y
drivers/net/ethernet/broadcom/Kconfig +11 -0
@@ -190,6 +190,17 @@ config BCM_NS_FA_FAULT_INJECTION reprobe and leaves forwarding to software. Intended for driver testing. Injection is disabled by default and can be armed through debugfs. +config BCM_NS_FA_KUNIT_TEST + bool "KUnit tests for the Northstar flow accelerator" if !KUNIT_ALL_TESTS + depends on KUNIT=y && BCM_NS_FA + default KUNIT_ALL_TESTS + help + Test NAT action validation, table field encoding, and RX hash learning. + Exercise upper-device inspection under RCU with real netdevices. + Tests are compiled into the parent driver and require built-in KUnit. + These tests run without an accelerator and do not simulate table I/O. + Use the hardware validation plan to check actual forwarding. + config BGMAC_BCMA tristate "Broadcom iProc GBit BCMA support" depends on BCM_NS_FA || !BCM_NS_FA
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c new file +661 -0
661 lines not on this page · raw message
drivers/net/ethernet/broadcom/bcm-ns-fa.c +4 -0
@@ -1893,5 +1893,9 @@ struct bcm_ns_fa *bcm_ns_fa_init(struct net_device *dev) }EXPORT_SYMBOL_GPL (bcm_ns_fa_init); +#if IS_ENABLED (CONFIG_BCM_NS_FA_KUNIT_TEST ) +#include "bcm-ns-fa-test.c" +#endif +MODULE_DESCRIPTION ("Broadcom Northstar IPv4 TCP/UDP NAT flow accelerator" );MODULE_LICENSE ("GPL" );
net/dsa/Kconfig +11 -0
@@ -78,6 +78,17 @@ config NET_DSA_TAG_BRCM_FA switch port. Transmit uses the ordinary prepended Broadcom tag. Enable this for a B53 switch explicitly connected to an accelerator. +config NET_DSA_TAG_BRCM_FA_KUNIT_TEST + bool "KUnit tests for Broadcom FA tags" if !KUNIT_ALL_TESTS + depends on KUNIT=y && NET_DSA_TAG_BRCM_FA + default KUNIT_ALL_TESTS + help + Tests are compiled into the parent driver and require built-in KUnit. + Verify FA miss demultiplexing, parser-status handling, and rejection + of unsupported opcodes without changing ordinary Broadcom tagging. + Exercise source-port demultiplexing and consumption of the metadata + tag through the receive path, without requiring a physical switch. + config NET_DSA_TAG_HELLCREEK tristate "Tag driver for Hirschmann Hellcreek TSN switches" help
net/dsa/tag_brcm.c +4 -0
@@ -526,5 +526,9 @@ static struct dsa_tag_driver *dsa_tag_driver_array[] = {module_dsa_tag_drivers (dsa_tag_driver_array); +#if IS_ENABLED (CONFIG_NET_DSA_TAG_BRCM_FA_KUNIT_TEST ) +#include "tag_brcm_test.c" +#endif +MODULE_DESCRIPTION ("DSA tag driver for Broadcom switches using in-frame headers" );MODULE_LICENSE ("GPL" );
net/dsa/tag_brcm_test.c new file +199 -0
199 lines not on this page · raw message
net/netfilter/Kconfig +5 -5
@@ -719,14 +719,14 @@ config NF_FLOW_TABLE To compile it as a module, choose M here. config NF_FLOW_TABLE_KUNIT_TEST - bool "KUnit tests for flowtable ownership" if !KUNIT_ALL_TESTS + bool "KUnit tests for flowtable ownership and cached paths" if !KUNIT_ALL_TESTS depends on KUNIT=y && NF_FLOW_TABLE default KUNIT_ALL_TESTS help - Test conntrack offload ownership during flowtable teardown. - Require hash and asynchronous hardware deletion before re-enrolment. - Verify that late notifications cannot release a replacement owner. - These private tests are embedded in the flowtable core. + Test flowtable ownership during asynchronous hardware deletion and + repeated teardown notifications, and validate cached forwarding paths. + Tests cover route expiry, neighbour changes and unsupported contexts. + The tests are embedded in their parent translation units. config NF_FLOW_TABLE_PROCFS bool "Supply flow table statistics in procfs"
net/netfilter/nf_flow_table_core_test.c +85 -0
94 lines not on this page · raw message
net/netfilter/nf_flow_table_offload.c +4 -0
@@ -1382,3 +1382,7 @@ void nf_flow_table_offload_exit(void)destroy_workqueue (nf_flow_offload_del_wq);destroy_workqueue (nf_flow_offload_stats_wq); } + +#if IS_ENABLED (CONFIG_NF_FLOW_TABLE_KUNIT_TEST ) +#include "nf_flow_table_offload_test.c" +#endif
net/netfilter/nf_flow_table_offload_test.c new file +129 -0
129 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net-next 8/9] net: add KUnit coverage for FA and flowtable path validation
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] net: broadcom: fa: invalid MMIO heap pointer in bcm-ns-fa KUnit tests --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] net: broadcom: fa: invalid MMIO heap pointer in bcm-ns-fa KUnit tests
--
commit ba8a6de53c2a0a0ed0378db8bfcb3ef2f7005c51
Author: Florian Fainelli <[email protected]>
net: add KUnit coverage for FA and flowtable path validation
This commit adds KUnit test suites for Broadcom B53 FA exception guards, Northstar flow accelerator rule encoding and invalidation, Broadcom FA DSA tags, and Netfilter flowtable cached path validation.
Quoted 5 lines
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c new file +0
-0
[ ... ]
Quoted 28 lines
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c new file +28
-0+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 ); + fa->learned =kunit_kcalloc (test,FA_SLOTS ,sizeof (*fa->learned),GFP_KERNEL ); +KUNIT_ASSERT_NOT_NULL (test, fa->regs); +KUNIT_ASSERT_NOT_NULL (test, fa->learned); +mutex_init (&fa->lock); +spin_lock_init (&fa->learn_lock); +fa_control_state_change (fa, true); +KUNIT_EXPECT_TRUE (test, fa->tcp_ready); +fa_control_state_change (fa, false); +KUNIT_EXPECT_FALSE (test, fa->tcp_ready); + fa->stopping = true; +fa_control_state_change (fa, true); +KUNIT_EXPECT_FALSE (test, fa->tcp_ready); +} + +static void fa_test_lookup_gate_preserves_tags (struct kunit *test) +{ +struct bcm_ns_fa *fa =kunit_kzalloc (test,sizeof (*fa),GFP_KERNEL ); +u32 *regs =kunit_kzalloc (test,0xc0 ,GFP_KERNEL ); +u32 control =FA_CTL_CRC_OVERWRITE |FA_CTL_NO_DA_CHECK ; +u32 header =FA_BRCM_HW |FA_BRCM_RX |FA_BRCM_TX |FA_BRCM_PARSE_EXCEPTIONS ; + +KUNIT_ASSERT_NOT_NULL (test, fa);
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c line 436
Quoted 10 lines
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c new file +10
-0+KUNIT_ASSERT_NOT_NULL (test, regs); + fa->regs = (void __iomem *)regs; +writel (control, fa->regs +FA_CTL ); +writel (header, fa->regs +FA_BRCM_HDR ); + fa->enabled = true; + fa->tcp_ready = true; + fa->route_mtu_ok = true; +fa_lookup_update (fa); +KUNIT_EXPECT_EQ (test,readl (fa->regs +FA_L2_ETHERTYPE ), + (u32)(ETH_P_IP |ETH_P_IPV6 <<16 ));
[Severity: Medium]
Can fa->regs be backed by a raw kunit_kzalloc() buffer when writel() and readl() are called on it here and in fa_test_invalidation()?
Running this suite under the default User Mode Linux KUnit runner (with drivers/net/ethernet/broadcom/.kunitconfig) enables indirect iomem emulation in lib/logic_iomem.c, where get_area() rejects plain heap addresses that lack the ioremap bias. Every readl() and writel() on fa->regs triggers a warning splat, drops the write, and returns 0xffffffffU from readl(), causing the register expectations in fa_test_lookup_gate_preserves_tags() and owner.lookup_stopped in fa_test_invalidation() to fail.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
[email protected]
AI reviewRe: [PATCH net-next 8/9] net: add KUnit coverage for FA and flowtable path validation
In reply to Florian FainelliThank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
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.
Quoted 14 lines
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c new file +8
-0@@ -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;
[ ... ]
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c line 38
Quoted 6 lines
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c new file +6
-0+ 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.
[ ... ]
Quoted 3 lines
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c new file +3
-0+static void fa_test_nat_actions (struct kunit *test) +{ +struct fa_rule rule = { .direction =FA_DIR_UNSET , .l4proto =IPPROTO_UDP };
[ ... ]
Quoted 5 lines
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c new file +5
-0+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 );
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c line 171
Quoted 10 lines
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c new file +10
-0+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?
[ ... ]
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c line 250
Quoted 7 lines
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c new file +7
-0+ 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.
[ ... ]
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c line 404
Quoted 6 lines
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c new file +6
-0+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.
[ ... ]
Quoted 5 lines
net/netfilter/nf_flow_table_core_test.c +0
-0@@ -72,9 +72,94 @@ static void nf_flow_test_hardware_retirement(struct kunit *test)
[ ... ]
Quoted 2 lines
net/netfilter/nf_flow_table_core_test.c +2
-0+for (i =0 ; i <ARRAY_SIZE (cases); i++) { +struct nf_flowtable table = { .type = &type };
[ ... ]
Quoted 6 lines
net/netfilter/nf_flow_table_core_test.c +6
-0+ 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);
[ ... ]
net/netfilter/nf_flow_table_core_test.c static void nf_flow_test_hardware_retirement(struct kunit *test) · line 153
Quoted 4 lines
net/netfilter/nf_flow_table_core_test.c +4
-0+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?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116222519.1416501-1-florian.fainelli%40broadcom.com
Florian Fainelli
maintainerRe: [PATCH net-next 8/9] net: add KUnit coverage for FA and flowtable path validation
Quoted 258 lines · On 11/17/26 15:29, [email protected] wrote:
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()setsNF_FLOW_HWandNF_FLOW_HW_DYINGon every flow, under the comment "Avoid queuing real DELETE/STATS work…
- [Low] Infa_test_rx_learning()(drivers/net/ethernet/broadcom/bcm-ns-fa-test.c), the TCP sub-case setsip->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 ininit_netwithalloc_etherdev()andregister_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.
Quoted 14 lines
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c new file +8
-0@@ -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;[ ... ]
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c line 38
Quoted 6 lines
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c new file +6
-0+ 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 minimalndo_start_xmitthat just drops the skb?
fa_test_netdev_opsis an empty static struct, so itsndo_start_xmitis NULL. Infa_test_upper_device_rcu(), both devices are registered ininit_netand 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 NULLndo_start_xmit. That could be a network manager reacting toRTM_NEWLINK, or anAF_PACKETsender.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.calready uses the same pattern, so this is only a hardening suggestion.[ ... ]
Quoted 3 lines
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c new file +3
-0+static void fa_test_nat_actions (struct kunit *test) +{ +struct fa_rule rule = { .direction =FA_DIR_UNSET , .l4proto =IPPROTO_UDP };[ ... ]
Quoted 5 lines
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c new file +5
-0+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 );drivers/net/ethernet/broadcom/bcm-ns-fa-test.c line 171
Quoted 10 lines
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c new file +10
-0+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_PORTset 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_PORTbit alone rejects the opposite-side UDP rewrite, so thefa_direction()conflict check is never exercised. If the mask and offset checks were removed fromfa_mangle(), theREMAP_IPbit 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?[ ... ]
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c line 250
Quoted 7 lines
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c new file +7
-0+ 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]
Shouldip->checkbe recomputed here?The other sub-cases in
fa_test_rx_learning()refresh the checksum withip_fast_csum()after editing the header. The IPv4 header checksum covers the protocol byte, sobcm_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.[ ... ]
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c line 404
Quoted 6 lines
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c new file +6
-0+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()andfa_test_invalidation()all pointfa->regsatkunit_kzalloc()memory. They then call writel()/readl() on it, either directly or throughfa_lookup_update():writel(enabled ? ETH_P_IP | ETH_P_IPV6 << 16 : 0, fa->regs + FA_L2_ETHERTYPE); readl(fa->regs + FA_L2_ETHERTYPE);
kunit.pydefaults to ARCH=um and merges arch_uml.config, which setsCONFIG_KUNIT_UML_PCI=y. That selectsUML_PCI, thenUML_IOMEM_EMULATION, thenINDIRECT_IOMEM, andINDIRECT_IOMEM_FALLBACKstays off. The raw accessors then go throughlib/logic_iomem.c, whereget_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()reads0xffffffffforFA_L2_ETHERTYPE,FA_CTLandFA_BRCM_HDR, so its expectations fail.
- Infa_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/.kunitconfigenablesCOMPILE_TESTand does not restrict the architecture. So runningkunit.pywith --kunitconfigdrivers/net/ethernet/broadcomseems 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_TESThelp text says the tests "do not simulate table I/O", which doesn't quite match these cases.[ ... ]
Quoted 5 lines
net/netfilter/nf_flow_table_core_test.c +0
-0@@ -72,9 +72,94 @@ static void nf_flow_test_hardware_retirement(struct kunit *test)[ ... ]
Quoted 2 lines
net/netfilter/nf_flow_table_core_test.c +2
-0+for (i =0 ; i <ARRAY_SIZE (cases); i++) { +struct nf_flowtable table = { .type = &type };[ ... ]
Quoted 6 lines
net/netfilter/nf_flow_table_core_test.c +6
-0+ 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);[ ... ]
net/netfilter/nf_flow_table_core_test.c static void nf_flow_test_hardware_retirement(struct kunit *test) · line 153
Quoted 4 lines
net/netfilter/nf_flow_table_core_test.c +4
-0+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. Insidenf_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 settingflow->timeoutand 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 memoryThis 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 onnf_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:
Quoted 9 lines
- pre-set
NF_FLOW_PENDINGsonf_flow_offload_work_alloc()bails out
- leaveNF_FLOW_HWclear for the non-hardware cases
- flushnf_flow_offload_stats_wqbefore the objects go out of scopeSeparately,
NF_FLOW_HWis 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?
[Medium] fake register windows
Agreed: UML rejects plain memory for readl()/writel(). v2 skips those three cases where MMIO is emulated (CONFIG_INDIRECT_IOMEM); they still run elsewhere, and the Kconfig help is corrected.
[Medium] GC test queueing STATS work
Agreed. v2 only marks the flows that GC tears down as hardware flows with their DESTROY queued, and leaves the others as software flows, for which GC does nothing.
[Low] NAT negatives, TCP learning sub-case, test netdevs
Fixed in v2: negative cases use fresh rules, the checksum is recomputed for the TCP case, and the test netdevs have an ndo_start_xmit.
pw-bot: cr
Signature · 1 line
Florian
Florian Fainelli
maintainerPATCH 9/9 docs: net: document Northstar FA setup and NAT qualification
In reply to Florian FainelliDescribe the supported topology, GMAC2 data and GMAC0 exception wiring, configuration, counters and software fallback. Provide classic/software/ hardware NAT controls and same-live-tuple TTL, MTU and ingress-policy checks. Cover live route/neighbour changes, reachability probes and read/insertion/deletion completion injection with reprobe recovery.
Explain that every IPv4 route, rule or nexthop event retires all hardware owners, including unrelated and local-table updates. Document the resulting offload-residency cost and distinguish actual cached-path validation from the driver's incomplete FIB eligibility probe. Keep campaign history and review status in the accompanying package.
--- .../ethernet/broadcom/bcm-ns-fa.rst | 507 ++++++++++++++++++ .../device_drivers/ethernet/index.rst | 1 + MAINTAINERS | 1 + 3 files changed, 509 insertions(+) create mode 100644 Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst new file +507 -0
@@ -0,0 +1,507 @@ +.. SPDX-License-Identifier: GPL-2.0-only + +Broadcom Northstar flow accelerator +=================================== + +Status and scope +---------------- + +The driver supports BCM4708, BCM53011 and BCM53012. IPv4 TCP and UDP +SNAT/DNAT have been validated on BCM953012ER (BCM53012), including normal +and software-flowtable controls, external wire checks, hardware table +pressure, software fallback, natural aging, teardown and recovery. + +BCM4708 and BCM53011 remain unvalidated. BCM53012 validation covers the +limited topology below; maximum throughput has not been established. + +The driver accepts nftables flowtable offload through ``TC_SETUP_FT`` on +bgmac. DSA forwards flowtable binds from its user ports to the GMAC2 conduit. +The FA is inline on the UniMAC2 / switch IMP0 (port 8) path. GMAC0 and GMAC1 +are pass-through paths and cannot accelerate these flows. + +The initial supported configuration is deliberately limited: + +* IPv4 TCP/UDP with source NAT or destination NAT, including port translation. +* Two standalone, untagged DSA router ports on the same switch, both using + GMAC2 as their conduit, in the initial network namespace. +* Distinct unicast MAC addresses on the LAN and WAN router interfaces. +* MTU 1500 on both router interfaces, one hardware flowtable, no upper devices. + +IPv6, VLAN devices, PPPoE, tunnels, bridges, bonds, hairpin forwarding, +plain routing, multipath/nexthop-object routes, and simultaneous source and +destination NAT in one direction +are rejected for hardware offload. They can still use software forwarding. +Hardware admission requires a second, operational CPU connection from switch +port 5 to GMAC0. B53 CFP redirects IPv4 exceptions through this connection, +physically bypassing FA. This includes TCP SYN/FIN/RST, TTL 0/1, IP lengths +above 1500, and packets that do not match the input port's router MAC. TCP +also requires the flowtable FIN/RST exclusion mask. Boards without the +auxiliary connection retain software forwarding for both protocols. + +The hardware has 1024 directional IPv4 entries, arranged in 256 four-way +buckets, four router MAC entries, and 128 next-hop entries. Capacity exhaustion +returns an error to the flowtable infrastructure, leaving traffic in software. +One connection normally needs two directional entries. Next-hop entries are +shared by destination MAC; router MACs are shared with an internal/external +side attribute. The driver learns the tuple hash from opcode-2 miss tags, +so it does not implement an assumed software equivalent of the hardware CRC. +A finite RX hash cache can also cause an offload attempt to fall back to +software under miss floods. + +The new ``brcm-fa`` DSA tag protocol carries the prepended FA miss descriptor. +Its hash, bucket, and parser status fields differ from the ordinary switch +tag. The bgmac receive hook observes the metadata for hash learning; the DSA +tagger consumes it and selects the input port. Timestamp descriptors are not +supported. The ordinary ``brcm`` and ``brcm-prepend`` taggers retain their +opcode validation. + +Implementation notes +-------------------- + +Table operations use the documented indirect access sequence. DATA0 triggers +the transfer; reads discard the initial DATA0 value and wait for the fetch +before consuming DATA7 through DATA0. Every wait is bounded. The driver keeps +clear-on-read disabled because clearing on a read gives unreliable hit counts. +Instead it reads cumulative packet counts and computes wrapping deltas in +software. + +The indirect read port is released after each access, including an access +that times out. Leaving read mode armed prevents per-entry hit counters from +updating and breaks the flowtable's activity accounting. + +Live packet lookups must not overlap software table transactions. On the +tested BCM53012, that overlap can advance the indirect address more than +once and persistently copy one flow's key into another slot. Before each +transaction, the driver requests GMAC2 CPU flow control, waits for pause to +assert and allows an in-flight frame to drain. It preserves automatic flow +control and restores the previous MAC control on every exit path. The switch +CPU port must honor pause, with matching internal link speeds at both ends. +The FA stays in normal mode so packet and Broadcom-header processing retain +their usual paths. Completion checks cover both the busy bit and the +auto-incremented table address. Frequent statistics and debugfs reads also +consume time on the internal link; include that work in performance tests. + +Router destination MAC validation is enabled before publishing a forwarding +entry. With no installed entries, it is disabled to obtain hashes for the +first unknown tuples. VLAN TPIDs are disabled in the FA parser so tagged +packets cannot match an installed untagged tuple merely by sharing its inner +five-tuple, including the TCP/UDP protocol bit. When both CPU connections +are explicitly described, B53 CFP reserves rules for TCP SYN/FIN/RST, TTL +0/1 and IPv4 total lengths above 1500. These redirect to port 5 with a +classification and termination reason. Nine masked prefixes cover every +length from 1501 through 65535. Per-port allow rules require the router's +destination MAC on that physical input port; a final IPv4 rule redirects +everything else to port 5. MAC changes disable admission while updating +these rules. Both +meter outcomes use the same action. Ordinary data uses port 8 only; flooding +to the auxiliary CPU is disabled. Standalone ports use basic EAP mode, with +private VLAN membership restricting forwarding to the CPU connections. +VLAN, EAP and STP filtering remain enabled. CFP classification is disabled +on bridge members and CPU ports. + +FA must ignore switch exception metadata to accelerate standalone data, +which normally carries the switch flooding reason. Consequently, an inline +SYN/FIN/RST trap through port 8 is insufficient: FA would accelerate those +packets as well. The auxiliary GMAC0 path avoids that lookup entirely. It +uses embedded Broadcom tags; the port 8 data path uses prepended FA metadata. +The tagger dispatches control packets to FA before delivering them to Linux. +The auxiliary conduit uses promiscuous mode to receive the router port MACs. +Before disabling its CFP redirects, B53 disables hardware lookup, retires +all entries and blocks admission. Re-enabling the path permits fresh +connections to offload. + +On a valid TCP control packet, NAPI marks the matching direction as closing +and immediately disables IPv4 lookup in the parser. Broadcom-tag relocation +remains active so the control packet can traverse the software forwarding +path. A worker removes both NAT directions before resuming lookups. Global +bypass is unsuitable here because it also disables tag relocation. IP options +and fragments retire pairs by their L3 identity before Linux can process a +reused tuple. RCU protects entry +identity, and a generation check prevents an insertion learned before the +control packet from racing past it. Closing rows retain their final packet +delta for software accounting until the flowtable deletes their ownership. + +Hardware packet counters refresh flowtable last-used time and packet +accounting. The hardware has no per-entry byte counter; reported byte totals +therefore do not include accelerated traffic. Three-bit timestamps are not +used for aging. Debugfs reads do not consume the driver's accounting deltas. + +Netdevice shutdown, address/MTU changes, new active switch ports, and upper +interface changes flush entries. Every IPv4 FIB route, rule and nexthop change +flushes all FA-owned flows, including unrelated prefixes and local-table +entries. This is intentional: the rule does not carry enough routing-policy +context to prove that an event cannot affect an installed path. Work is +coalesced, but even unrelated routing churn can reduce offload residency. +Redirects and next-hop MAC or validity changes also disable lookup and schedule +entry retirement. The driver also notifies the flowtable owner to retire +its cached software path; merely removing hardware rows would leave stale +direct-transmit routes and destination MACs in use. Generation checks reject observations and publications +that raced with invalidation. Before admitting a rule, the flowtable owner +validates its actual cached routes and direct-path neighbours. Hardware +flowtables retain validation-only route references, so this check preserves the mark, +DSCP and output-interface context used when those paths were selected. +These references do not enable automatic route checks for plain direct +flows in other drivers or hardware-enabled flowtables. Existing direct +tunnel, neighbour and XFRM route checks keep their previous behaviour. +A proven stale cached route or neighbour retires the software owner too. +The driver's separate FIB lookup is only a hardware eligibility probe: +it lacks the complete policy context, so any mismatch declines hardware +offload without tearing down a valid software owner. Unsupported route types, +such as multipath, nexthop objects and lightweight tunnels, decline hardware +admission without tearing down valid software flowtable forwarding. +Valid neighbour aging transitions do not unnecessarily flush entries. +Hardware counter activity drives Linux +neighbour reachability probes, so an accelerated connection cannot leave a +stale neighbour untested indefinitely. + +The flowtable classifier provides no per-route MTU. The driver therefore +keeps all flows in software while any IPv4 route in the initial network +namespace has an explicit MTU below 1500. The initial FIB notifier replay +seeds a hash of low-MTU table/prefix pairs; route replacements and deletions +update it incrementally without further FIB dumps. Ordinary routes use no +tracking memory. If allocation fails or more than 1024 low-MTU prefixes +need tracking, hardware admission remains disabled until reprobe; route +updates and software forwarding continue. This conservative restriction also +applies to unrelated routes. The CFP length trap handles packets exceeding +the admitted interface MTU, including packets of an already installed tuple. + +A table timeout disables parser lookup +and prevents further hardware insertion until reprobe. Tag relocation remains +active for software fallback. Reconfiguration can +leave an existing conntrack entry temporarily labelled HW_OFFLOAD after its +hardware entries have been flushed. Use fresh connections after topology or +ruleset changes; the label alone is never proof of forwarding by hardware. + +Device tree and kernel configuration +------------------------------------ + +Enable at least:: + + CONFIG_BGMAC_BCMA=y + CONFIG_BCM_NS_FA=y + CONFIG_NET_DSA=y + CONFIG_B53=y + CONFIG_B53_SRAB_DRIVER=y + CONFIG_NET_DSA_TAG_BRCM_FA=y + CONFIG_NF_CONNTRACK=y + CONFIG_NF_TABLES=y + CONFIG_NF_FLOW_TABLE=y + CONFIG_NF_FLOW_TABLE_INET=y + CONFIG_NFT_FLOW_OFFLOAD=y + CONFIG_NFT_NAT=y + CONFIG_NF_NAT=y + CONFIG_DEBUG_FS=y + +Modules are supported too. Use the board's existing ARM configuration and +retain its PHY, switch, filesystem, and boot-device options. + +For a BCM53012 board, add the following node under the root address space +(adjust the compatible to ``brcm,bcm53011-fa`` for BCM53011):: + + / { + fa: flow-accelerator@18027c00 { + compatible = "brcm,bcm53012-fa"; + reg = <0x18027c00 0xc0>; + }; + }; + + &gmac2 { + brcm,flow-accelerator = <&fa>; + status = "okay"; + }; + +Both tested user ports must use switch port 8 and GMAC2. In the existing B53 +switch node, port 8 must have ``ethernet = <&gmac2>``. Also enable +switch port 5 with ``ethernet = <&gmac0>``, ``phy-mode = "internal"`` and a +1 Gbps full-duplex fixed link. Enable GMAC0 and bring its network interface +up before testing either protocol; retain port 8 as the preferred conduit for +user ports. +Remove any other conflicting CPU assignments for this test. B53 selects ``brcm-fa`` +when it finds the enabled accelerator through this phandle. Do not set +``dsa-tag-protocol``: B53 does not implement the runtime protocol-change +operation. No existing board is enabled automatically by this series. + +The FA resource is outside the GMAC3 DMA register window. It is managed by +the GMAC2 consumer; it does not need a separate platform driver or character +device. Leave the accelerator disabled or omit the GMAC2 phandle to retain +the existing board configuration. + +Three-host hardware test +------------------------ + +Use a dedicated test router with serial access and two external Linux hosts. +Traffic generated on the router itself does not exercise the inline receive +path. Keep all other switch user ports administratively down. Replace the +interface names below with those on the board:: + + LAN host BCM5301X router WAN host + 192.0.2.2/24 -- lan1 192.0.2.1 198.51.100.1 wan -- 198.51.100.2/24 + \ / + GMAC2 / FA + +Assign distinct router MACs before bringing up the interfaces:: + + ip link set lan1 down + ip link set wan down + ip link set lan1 address 02:00:00:00:01:01 + ip link set wan address 02:00:00:00:02:01 + ip addr add 192.0.2.1/24 dev lan1 + ip addr add 198.51.100.1/24 dev wan + ip link set lan1 up + ip link set wan up + sysctl -w net.ipv4.ip_forward=1 + +On the LAN host, assign 192.0.2.2/24 and a default route via 192.0.2.1. +On the WAN host, assign 198.51.100.2/24 and a default route via 198.51.100.1. +Do not put the router ports in a bridge or create VLAN uppers. Ensure that +other firewall rules on this lab router permit the test packets. + +Mount debugfs if necessary and locate the FA status file:: + + mount -t debugfs none /sys/kernel/debug + find /sys/kernel/debug -name fa -type f + cat /sys/kernel/debug/<GMAC2-device-name>/fa + +The file contains ``failed``, global ``hits`` and ``misses``, error bits, +and a row for every programmed directional entry. Each row identifies its +slot, cookie, input/output interfaces, and raw hardware packet count. Save +snapshots with timestamps before, during, and after every test. + +The adjacent ``fa_table`` file shows each software-owned tuple and the eight +hardware words in DATA7 through DATA0 order. It uses the same lock and +bounded indirect accesses as statistics collection. Save it when an entry +stops counting to compare the hardware key against software ownership. + +Install a uniquely named test table; do not flush unrelated tables:: + + table inet fa_test { + flowtable ft { + hook ingress priority 0; + devices = { lan1, wan }; + flags offload; + counter; + } + chain forward { + type filter hook forward priority 0; policy drop; + meta l4proto udp ct state established flow add @ft + ct state established,related counter accept + iifname "lan1" oifname "wan" udp dport 5001 counter accept + iifname "wan" oifname "lan1" udp dport 5001 ct status dnat counter accept + } + chain prerouting { + type nat hook prerouting priority dstnat; policy accept; + iifname "wan" udp dport 15001 dnat ip to 192.0.2.2:5001 + } + chain postrouting { + type nat hook postrouting priority srcnat; policy accept; + iifname "lan1" oifname "wan" ip saddr 192.0.2.2 snat ip to 198.51.100.1:45000 + } + } + +Save this as a ruleset and load it with ``nft -f <file>``. For the two control +runs described below, edit only this test table. Delete it between phases +with ``nft delete table inet fa_test``. Delete matching conntrack entries +between phases, for example:: + + conntrack -D -p udp --orig-src 192.0.2.2 --orig-dst 198.51.100.2 --dport 5001 + +For SNAT, run a UDP or TCP echo server on the WAN host at +198.51.100.2:5001. Run a client on the LAN host, bind its source to +192.0.2.2:40000, and connect to that server. Verify the server observes +the translated peer 198.51.100.1:45000. Include a sequence number in each +payload and check every returned payload for loss or corruption. + +Run three phases with a fresh connection each time: + +1. **Normal forwarding:** omit the ``flow add @ft`` rule. Forward-chain + counters should grow throughout the test. FA entry counts and hit counts + should not grow for this traffic. +2. **Software flowtable:** restore ``flow add @ft`` and omit ``flags offload``. + Expect OFFLOAD and no hardware entries/hit growth for this flow. Reduced + forward-chain counters in this phase demonstrate why those counters alone + cannot prove hardware offload. +3. **Hardware flowtable:** restore ``flags offload``. Wait a few seconds for + asynchronous rule installation, then compare multiple debugfs snapshots. + +The hardware phase passes only when all of the following hold: + +* The WAN server sees the peer as 198.51.100.1:45000, proving address and + source-port translation. The client receives the original payloads. +* ``conntrack -L -p udp -o extended`` identifies the expected original and + reply tuples and reports HW_OFFLOAD. OFFLOAD alone is insufficient. +* There are two hardware entry rows for the connection and **both** packet + counters advance while the echo stream runs. The netfilter core can mark + HW_OFFLOAD when only one direction is accepted, so check each direction. +* The global FA hit count advances with the transfer, ``failed`` remains 0, + and hardware error bits do not increase. +* Captures on the external hosts show the expected rewritten IPv4/TCP or + IPv4/UDP tuples, valid checksums, unchanged payloads, and exactly one TTL + decrement. +* Router CPU load and GMAC DMA packet growth are substantially below the + software phase at the same offered packet rate. A router-side capture + should see initial misses but few steady-state packets from this stream. + Compare external captures; packet-capture placement and GRO can affect + counts on the router. + +Use ``tcpdump -ni <host-interface> -vv -w <capture.pcap> udp`` on both external +hosts. If host checksum offload obscures validation, temporarily disable the +relevant offloads on the test hosts and restore them afterward. Capture from +the receiving host or a wire tap when checking checksums. + +For DNAT, stop the WAN server and run the echo server on the LAN host at +192.0.2.2:5001. Run the client on the WAN host, bind it to 198.51.100.2:40001, +and connect it to 198.51.100.1:15001. Verify destination IP/port translation +on the LAN capture and the source IP/port restoration on the WAN reply. +Repeat all three phases and require hit growth in both directions. + +Stress, teardown, and negative tests +------------------------------------ + +* Change SNAT to a port range for parallel sessions. Exercise multiple + clients and next hops, hot buckets, more than 128 next-hop MACs, and over + 512 bidirectional sessions. Failures to allocate must fall back to software + without modifying a different connection's entry. Four-way collisions can + exhaust a bucket before the whole table is full. +* Keep a densely occupied table active while repeatedly reading statistics. + Compare the software tuples with the raw entries in ``fa_table`` before + and after the test. Every valid hardware key must match its owning slot, + cookies must stay stable and every active direction's counter must grow. + Intact echoes and HW_OFFLOAD labels alone can conceal damaged entries + whose traffic has fallen back to software. +* Stop the generator and wait longer than the configured UDP conntrack + timeout. Hardware rows must disappear. Run sustained traffic longer than + that timeout and verify that counter-based last-used refresh keeps the + connection alive. Check packet counter wrap handling during a long soak. +* Delete the test flowtable during traffic. Entries must disappear and + forwarding must continue through the remaining firewall/NAT path. Delete + only the flow-add rule first if retaining the table is useful for this test. +* Disable ``hw-tc-offload`` on the conduit with ethtool. Entries must be + flushed and new hardware insertions rejected. Re-enable it and use fresh + connections. +* Test port down/up, a third port up, router MAC changes, MTU changes, a bridge + or VLAN upper being added, conduit down/up, module unload/reload, and + suspend/resume if supported. Require removal of stale entries and clean + resource reuse. Start fresh connections after each topology change. +* Try IPv6, ICMP, GRE, PPPoE, VLAN and QinQ devices, double NAT, and + hairpin NAT. They must not create FA entries. Exercise tagged packets whose + inner tuple equals a live untagged offload; they must not hit that entry. +* Send IPv4 fragments, IP options, bad IP checksums, runt/truncated headers, + and switch exception traffic. Require software handling or the normal + stack/switch drop behavior, never a stale or unrelated hardware hit. +* Verify UDP zero-checksum packets, nonzero checksums, packets whose updated + checksum folds to zero, minimum-size frames, and maximum MTU packets. +* Repeat SNAT, DNAT, table pressure, software fallback, aging and recovery + with TCP. Require the TCP bit in every owned raw table key and advancing + counters in both directions. Compare classic, software and hardware modes. +* While hardware data counters advance, capture SYN/FIN/RST on the GMAC0 + auxiliary conduit. Require embedded Broadcom tags and delivery to Linux. + Close with FIN and RST, reuse the same tuple, and change its NAT + mapping; require immediate removal of the old hardware directions, correct + new peers and intact framed payloads. Repeat with options and fragmented + control packets. An HW_OFFLOAD label alone does not qualify this test. + Bring GMAC0 down while TCP data flows. Require removal of its hardware + rows, intact software forwarding, and rejection of new TCP hardware + entries. Bring GMAC0 up and require fresh connections to offload again. +* Run TCP and UDP with identical IP addresses and transport ports. Require + independent hashes, hardware protocol bits and correct payload delivery; + closing TCP must leave the UDP directions installed and advancing. +* With a development fault-injection mechanism, force an indirect-port busy + timeout. Require bounded completion, ``failed 1``, no further insertions, + no reuse of uncertain table resources, and working software forwarding. + Reprobe before repeating. The driver provides no writable debugfs register + interface; do not poke live registers from userspace. + +Boundary and invalidation qualification +--------------------------------------- + +Run these tests with UDP and TCP, SNAT and DNAT, and classic, software +flowtable and hardware forwarding. Install both hardware directions and +verify their raw keys before injecting packets of that same live tuple: + +* TTL 0 and 1 must produce the software baseline's ICMP time-exceeded + response without forwarding a wrapped TTL. Ordinary traffic must decrement + TTL exactly once. +* An IP length of 1500 must pass. At 1501, DF must produce ICMP fragmentation + needed with MTU 1500; without DF, Linux must fragment into packets no + larger than 1500. Check transport checksums after reassembly. +* Inject the tuple on the opposite physical port, addressed both to the + original input MAC and the receiving port's MAC. Require the same ingress + firewall policy as the software baseline. Also test unrelated unicast, + broadcast and multicast destination MACs. These must not enter IPv4 + forwarding merely because a five-tuple matches. + +While a hardware connection is live, replace its neighbour MAC and require +all subsequently forwarded frames to use the new MAC. Set the neighbour to +``NUD_FAILED`` while preventing ARP replies and require forwarding to stop. +Restore reachability and require recovery. Force a valid neighbour to STALE +while hardware counters advance and require a Linux ARP reachability probe. + +Install a blackhole host route and then a source-policy blackhole rule; +require forwarding to stop after each netlink acknowledgment. Remove each +change and check payload delivery and fresh hardware admission. Add an MTU +1200 host route both during an existing connection and before a fresh one. +Require zero hardware entries, intact small software-forwarded packets and +ICMP fragmentation-needed with MTU 1200 for a 1280-byte DF probe. Remove +that route and verify recovery. Keep the flowtable installed throughout; +recreating it would conceal missing invalidation. + +Fault injection qualification +----------------------------- + +A development kernel can enable ``CONFIG_FAULT_INJECTION``, +``CONFIG_FAULT_INJECTION_DEBUG_FS`` and +``CONFIG_BCM_NS_FA_FAULT_INJECTION``. The per-device ``fail_table`` directory +uses the standard fault-injection attributes. The default probability is +zero. Injection returns a timeout after an indirect transfer has completed, +which deliberately makes completion uncertain to its caller. This tests +software handling of uncertain reads and writes, including a write that may +already have published an entry; it does not emulate a physical bus hang. +The ordinary hardware busy/address waits remain bounded independently. + +For one injected failure, with the device name adjusted as needed:: + + D=/sys/kernel/debug/bcma0:5 + echo 1 > $D/fail_table/times + echo 1 > $D/fail_table/interval + echo 0 > $D/fail_table/space + echo 100 > $D/fail_table/probability + +The next table access fails. To restrict injection to a table write, set +``fail_table_write_only`` to ``Y`` before arming it, then insert a fresh +connection or delete an installed one. Run read, insertion and deletion +cases on separate clean probes. Verify ``failed 1`` and exactly one +``fault_injections`` increment. Lookup must be disabled before the paused +switch traffic resumes. Broadcom-tag relocation must remain active, and +uncertain entries and MAC resources must not be reused until reprobe. + +Keep UDP and TCP SNAT/DNAT traffic active across each failure. Validate all +eight wire directions for correct tuples, payloads, checksums and exactly +one TTL decrement. Require a fresh connection to work in software and an +ethtool feature toggle to leave the failed state latched. Stop the test, +reprobe and require clean hardware admission again. Do not poke live +registers from userspace; no writable register interface is provided. + +Automated validation +-------------------- + +Run the supplied KUnit configuration from a clean source tree:: + + ./tools/testing/kunit/kunit.py run --arch=x86_64 \ + --kunitconfig=drivers/net/ethernet/broadcom/.kunitconfig \ + --build_dir=/tmp/bcm-ns-fa-kunit '*fa*' + +The backend, switch and tagger provide KUnit suites named ``bcm-ns-fa``, +``b53-fa-guards`` and ``brcm-fa-tag``. Enable ``CONFIG_BCM_NS_FA_KUNIT_TEST`` and +``CONFIG_NET_DSA_TAG_BRCM_FA_KUNIT_TEST`` and ``CONFIG_B53_FA_KUNIT_TEST`` +with KUnit and their parent drivers. +They cover cross-word field layout and endianness, NAT action rejection, +miss-hash learning exclusions, opcode validation, source-port demultiplexing, +consumption of the four-byte metadata tag, route-MTU admission and CFP UDF +layout. The length-prefix test checks all 65536 possible IPv4 lengths. +These tests do not simulate the FA. + +Build the bgmac, B53, and DSA objects with ``W=1`` for ARM, plus an x86 +COMPILE_TEST configuration; also check the FA-disabled configuration and +built-in/module combinations. Run ``dt_binding_check`` for both new schemas, +``checkpatch.pl``, and ``git diff --check``. The hardware matrix above remains +mandatory even when all automated checks pass.
Documentation/networking/device_drivers/ethernet/index.rst +1 -0
@@ -18,6 +18,7 @@ Contents: amd/pds_vdpa amd/pds_vfio_pci aquantia/atlantic + broadcom/bcm-ns-fa chelsio/cxgb dlink/dl2k davicom/dm9000
MAINTAINERS +1 -0
@@ -5672,6 +5672,7 @@ S: Maintained F: Documentation/devicetree/bindings/net/brcm,amac.yaml F: Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml F: Documentation/devicetree/bindings/net/brcm,bcm5301x-gmac.yaml +F: Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst F: drivers/net/dsa/b53/b53_fa_test.c F: drivers/net/ethernet/broadcom/.kunitconfig F: drivers/net/ethernet/broadcom/bcm-ns-fa*
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net-next 9/9] docs: net: document Northstar FA setup and NAT qualification
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 4 · Low: 2
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] The reference nftables ruleset in Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-…
- [Medium] bcm-ns-fa.rst (lines 130-131) says "Every IPv4 FIB route, rule and nexthop change flushes all FA-owned flows".
- [Medium] B53 and the FA backend decide independently whether FA metadata mode is active, and they use different tests.
- [Medium] The FA block is at 0x18027c00 (reg <0x18027c00 0xc0>), which is offset 0xc00 inside the GMAC3 BCMA core aperture (gmac3:…
- [Low] The 'Automated validation' section runs kunit.py with the suite filter '*fa*' against drivers/net/ethernet/broadcom/.kunitconfig.
- [Low] The commit message for "docs: net: document Northstar FA setup and NAT qualification" ends with "Keep campaign history and review…
--
docs: net: document Northstar FA setup and NAT qualification
This adds documentation for the Broadcom Northstar flow accelerator. It covers the supported GMAC2/GMAC0 topology, the device tree and kernel configuration, and how route and neighbour invalidation works. It also describes a three-host NAT qualification procedure, fault injection tests and KUnit validation, and adds the new file to the index and MAINTAINERS.
Quoted 2 lines
validation from the driver's incomplete FIB eligibility probe. Keep campaign history and review status in the accompanying package.
[Severity: Low]
This isn't a bug, but what does "the accompanying package" refer to? The patch only adds bcm-ns-fa.rst, an index entry and a MAINTAINERS line. Nothing in the tree matches that description.
Could this sentence go in the cover letter or below the --- line instead of the permanent changelog?
Quoted 6 lines
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst new file +0
-0@@ -0,0 +1,507 @@
[ ... ]
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst line 134
Quoted 6 lines
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst new file +6
-0+Netdevice shutdown, address/MTU changes, new active switch ports, and upper +interface changes flush entries. Every IPv4 FIB route, rule and nexthop change +flushes all FA-owned flows, including unrelated prefixes and local-table +entries. This is intentional: the rule does not carry enough routing-policy +context to prove that an event cannot affect an installed path. Work is +coalesced, but even unrelated routing churn can reduce offload residency.
[Severity: Medium]
Can the IPv4 FIB notifier actually provide this guarantee? fa_fib_event() in drivers/net/ethernet/broadcom/bcm-ns-fa.c is the only route invalidation path. The same promise appears in its comment. However, fib_table_insert() only notifies when the new alias is the first one for that prefix and table:
net/ipv4/fib_trie.c:fib_table_insert() {
...
if (fib_find_alias(&l->leaf, new_fa->fa_slen, 0, 0, tb->tb_id, true) ==
new_fa) {
enum fib_event_type fib_event;
...
}The NLM_F_REPLACE branch and the delete path work the same way:
net/ipv4/fib_trie.c:fib_notify_alias_delete() {
...
/* Do not notify if we do not care about the route. */
if (fib_find_alias(fah, slen, 0, 0, tb_id, true) != fa_to_delete)
return;
...
}Aliases are sorted by descending DSCP. If a prefix also has a DSCP-specific alias (ip route ... tos X), the DSCP-0 alias that ordinary traffic uses is not first. Adding, replacing or deleting that alias raises no notifier event. As a result, neither fa_invalidate_locked() nor fa_mtu_route_update() runs.
Flowtable GC doesn't catch this for hardware flows either, because validation-only references are skipped:
include/net/netfilter/nf_flow_table.h:nf_flow_dst_check() {
/* A driver-only reference must not change direct-path/GC semantics. */
if (!tuple->dst_cache || tuple->dst_validation_only)
return true;
...
}nf_flow_offload_validate() only runs at admission.
Suppose the DSCP-0 route is replaced with a blackhole, moved to another next hop, or given an MTU below 1500 as a non-first alias. Would the hardware rows keep forwarding on the old path while counter activity keeps refreshing them? The same gap applies to the later claim that flows stay in software while any route has an MTU below 1500. The blackhole and MTU 1200 qualification steps only use first-alias routes, so they would pass anyway.
A minor point: fa_fib_event() also handles FIB_EVENT_ENTRY_ADD and FIB_EVENT_ENTRY_APPEND, which IPv4 never emits.
[ ... ]
Quoted 9 lines
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst new file +9
-0+For a BCM53012 board, add the following node under the root address space +(adjust the compatible to ``brcm,bcm53011-fa`` for BCM53011):: + + / { + fa: flow-accelerator@18027c00 { + compatible = "brcm,bcm53012-fa"; + reg = <0x18027c00 0xc0>; + }; + };
[ ... ]
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst line 222
Quoted 4 lines
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst new file +4
-0+Remove any other conflicting CPU assignments for this test. B53 selects ``brcm-fa`` +when it finds the enabled accelerator through this phandle. Do not set +``dsa-tag-protocol``: B53 does not implement the runtime protocol-change +operation. No existing board is enabled automatically by this series.
[Severity: Medium]
Is this the whole condition? B53 and the FA backend each decide on their own whether FA metadata mode is active, and they use different tests:
drivers/net/dsa/b53/b53_common.c:b53_uses_fa_tag() {
...
enabled = IS_ENABLED(CONFIG_BCM_NS_FA) && of_device_is_available(fa) &&
(dev->chip_id == BCM53011_DEVICE_ID ||
dev->chip_id == BCM53012_DEVICE_ID ||
(is5301x(dev) && of_device_is_compatible(fa, "brcm,bcm4708-fa")));
...
}drivers/net/ethernet/broadcom/bcm-ns-fa.c:bcm_ns_fa_init() {
...
if (!of_device_is_compatible(np, "brcm,bcm4708-fa") &&
!of_device_is_compatible(np, "brcm,bcm53011-fa") &&
!of_device_is_compatible(np, "brcm,bcm53012-fa")) {
of_node_put(np);
return ERR_PTR(-ENODEV);
}
...
}bcm_ns_fa_init() ignores the chip. It then always enables FA_BRCM_HDR processing and clears FA_CTL_BYPASS.
Take the brcm,bcm53012-fa node from the example above on a 5301x switch whose runtime chip_id is BCM53010, BCM53018 or BCM53019. The backend would switch GMAC2 RX to the FA descriptor format. B53 would keep the ordinary brcm tagger on port 8 and skip the CFP exception guards. Would conduit RX on port 8 then be misparsed or dropped?
An available FA node with any other compatible makes bcm_ns_fa_init() return -ENODEV. That fails the whole GMAC2 probe:
drivers/net/ethernet/broadcom/bgmac.c:bgmac_enet_probe() {
...
bgmac->fa = bcm_ns_fa_init(net_dev);
if (IS_ERR(bgmac->fa)) {
err = PTR_ERR(bgmac->fa);
bgmac->fa = NULL;
...
}Also, "brcm,bcm4708-fa" turns on FA mode for any 5301x chip. That includes parts the binding, the Kconfig help and this document do not list as supported.
Could B53 and the backend share one predicate, and could the document state the actual conditions?
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst line 227
Quoted 5 lines
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst new file +5
-0+ +The FA resource is outside the GMAC3 DMA register window. It is managed by +the GMAC2 consumer; it does not need a separate platform driver or character +device. Leave the accelerator disabled or omit the GMAC2 phandle to retain +the existing board configuration.
[Severity: Medium]
What state does the GMAC3 core need to be in? The FA block at 0x18027c00 is at offset 0xc00 inside the GMAC3 BCMA core aperture (gmac3:
ethernet@27000 in bcm-ns.dtsi). bcm_ns_fa_init() maps and programs it from GMAC2 without checking or enabling the core that hosts it.
If the FA shares GMAC3's reset or clock domain, two cases look like problems.
First, when GMAC3 is disabled in DT, nothing releases the core's reset:
drivers/bcma/main.c:bcma_register_devices() {
...
np = core->dev.of_node;
if (np && !of_device_is_available(np))
continue;
...
}Could FA register accesses then abort, or hit the FA_INIT_DONE poll timeout, depending on what the bootloader left behind?
Second, when GMAC3 is enabled, bgmac_probe() in bgmac-bcma.c only rejects the phandle on a core other than unit 2. GMAC3 therefore still probes, and bgmac_enet_probe() unconditionally calls:
bgmac_clk_enable(bgmac, 0);
This reaches bcma_core_enable(), which pulses the GMAC3 core reset. If that happens after GMAC2 has initialized the FA, does it wipe FA_CTL and the table state? The GMAC2 side would still believe its flows[] and next-hop bookkeeping match the hardware. BGMAC_FEAT_NO_RESET suppresses the reset in open/close, but not this probe-time enable.
The setup steps only cover GMAC0 and GMAC2. Should they say whether GMAC3 must be enabled, disabled or left alone?
[ ... ]
Quoted 13 lines
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst new file +13
-0+ table inet fa_test { + flowtable ft { + hook ingress priority 0; + devices = { lan1, wan }; + flags offload; + counter; + } + chain forward { + type filter hook forward priority 0; policy drop; + meta l4proto udp ct state established flow add @ft + ct state established,related counter accept + iifname "lan1" oifname "wan" udp dport 5001 counter accept + iifname "wan" oifname "lan1" udp dport 5001 ct status dnat counter accept
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst line 299
Quoted 10 lines
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst new file +10
-0+ } + chain prerouting { + type nat hook prerouting priority dstnat; policy accept; + iifname "wan" udp dport 15001 dnat ip to 192.0.2.2:5001 + } + chain postrouting { + type nat hook postrouting priority srcnat; policy accept; + iifname "lan1" oifname "wan" ip saddr 192.0.2.2 snat ip to 198.51.100.1:45000 + } + }
[Severity: Medium]
Will this table load with nft -f? The snat rule in the postrouting chain asks for a port mapping. However, iifname, oifname and ip saddr don't set a transport protocol. nft rejects such a rule with "transport protocol mapping is only valid after transport protocol match". nft -f loads the file as one transaction, so the whole fa_test table would be rejected.
The dnat rule is fine because udp dport 15001 comes first. Would a meta l4proto (or tcp/udp) match before the snat statement fix this? The in-tree nft_flowtable.sh and nft_nat.sh selftests do that.
Separately, the forward chain only handles UDP:
meta l4proto udp ct state established flow add @ft iifname "lan1" oifname "wan" udp dport 5001 counter accept
With policy drop, wouldn't a new TCP SYN match no accept rule and be dropped? The text below says "run a UDP or TCP echo server". Later sections ask for the SNAT, DNAT, pressure, fallback and aging tests to be repeated with TCP, but no TCP ruleset is given.
[ ... ]
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst line 491
Quoted 3 lines
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst new file +3
-0+ ./tools/testing/kunit/kunit.py run --arch=x86_64 \ + --kunitconfig=drivers/net/ethernet/broadcom/.kunitconfig \ + --build_dir=/tmp/bcm-ns-fa-kunit '*fa*'
[Severity: Low]
Does the '*fa*' filter skip suites that this kunitconfig builds? drivers/net/ethernet/broadcom/.kunitconfig also sets CONFIG_NF_FLOW_TABLE_KUNIT_TEST=y. That builds the nf-flow-lifetime suite (net/netfilter/nf_flow_table_core_test.c) and the nf-flow-path suite (net/netfilter/nf_flow_table_offload_test.c). Neither name contains "fa", so the documented command builds them but never runs them.
nf-flow-path covers the cached route and neighbour validation in nf_flow_offload_validate() that the commit message relies on.
Should the filter include these suites? Should the text below also mention CONFIG_NF_FLOW_TABLE_KUNIT_TEST next to the three suites it lists?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116222519.1416501-1-florian.fainelli%40broadcom.com
Florian Fainelli
maintainerRe: [PATCH net-next 9/9] docs: net: document Northstar FA setup and NAT qualification
Quoted 290 lines · On 11/17/26 15:29, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 4 · Low: 2
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] The reference nftables ruleset in Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-…
- [Medium]bcm-ns-fa.rst(lines 130-131) says "Every IPv4 FIB route, rule and nexthop change flushes all FA-owned flows".
- [Medium] B53 and the FA backend decide independently whether FA metadata mode is active, and they use different tests.
- [Medium] The FA block is at0x18027c00(reg <0x18027c000xc0>), which is offset0xc00inside the GMAC3 BCMA core aperture (gmac3:…
- [Low] The 'Automated validation' section runskunit.pywith the suite filter'*fa*'againstdrivers/net/ethernet/broadcom/.kunitconfig.
- [Low] The commit message for "docs: net: document Northstar FA setup and NAT qualification" ends with "Keep campaign history and review…--
docs: net: document Northstar FA setup and NAT qualification
This adds documentation for the Broadcom Northstar flow accelerator. It covers the supported GMAC2/GMAC0 topology, the device tree and kernel configuration, and how route and neighbour invalidation works. It also describes a three-host NAT qualification procedure, fault injection tests and KUnit validation, and adds the new file to the index and
MAINTAINERS.Quoted 2 lines
validation from the driver's incomplete FIB eligibility probe. Keep campaign history and review status in the accompanying package.
[Severity: Low]
This isn't a bug, but what does "the accompanying package" refer to? The patch only addsbcm-ns-fa.rst, an index entry and aMAINTAINERSline. Nothing in the tree matches that description.Could this sentence go in the cover letter or below the --- line instead of the permanent changelog?
Quoted 6 lines
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst new file +0
-0@@ -0,0 +1,507 @@[ ... ]
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst line 134
Quoted 6 lines
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst new file +6
-0+Netdevice shutdown, address/MTU changes, new active switch ports, and upper +interface changes flush entries. Every IPv4 FIB route, rule and nexthop change +flushes all FA-owned flows, including unrelated prefixes and local-table +entries. This is intentional: the rule does not carry enough routing-policy +context to prove that an event cannot affect an installed path. Work is +coalesced, but even unrelated routing churn can reduce offload residency.[Severity: Medium]
Can the IPv4 FIB notifier actually provide this guarantee?fa_fib_event()indrivers/net/ethernet/broadcom/bcm-ns-fa.cis the only route invalidation path. The same promise appears in its comment. However,fib_table_insert()only notifies when the new alias is the first one for that prefix and table:net/ipv4/fib_trie.c:fib_table_insert() { ... if (fib_find_alias(&l->leaf, new_fa->fa_slen, 0, 0, tb->tb_id, true) == new_fa) { enum fib_event_type fib_event; ... }The
NLM_F_REPLACEbranch and the delete path work the same way:net/ipv4/fib_trie.c:fib_notify_alias_delete() { ... /* Do not notify if we do not care about the route. */ if (fib_find_alias(fah, slen, 0, 0, tb_id, true) != fa_to_delete) return; ... }Aliases are sorted by descending DSCP. If a prefix also has a DSCP-specific alias (ip route ... tos X), the DSCP-0 alias that ordinary traffic uses is not first. Adding, replacing or deleting that alias raises no notifier event. As a result, neither
fa_invalidate_locked()norfa_mtu_route_update()runs.Flowtable GC doesn't catch this for hardware flows either, because validation-only references are skipped:
include/net/netfilter/nf_flow_table.h:nf_flow_dst_check() { /* A driver-only reference must not change direct-path/GC semantics. */ if (!tuple->dst_cache || tuple->dst_validation_only) return true; ... }
nf_flow_offload_validate()only runs at admission.Suppose the DSCP-0 route is replaced with a blackhole, moved to another next hop, or given an MTU below 1500 as a non-first alias. Would the hardware rows keep forwarding on the old path while counter activity keeps refreshing them? The same gap applies to the later claim that flows stay in software while any route has an MTU below 1500. The blackhole and MTU 1200 qualification steps only use first-alias routes, so they would pass anyway.
A minor point:
fa_fib_event()also handlesFIB_EVENT_ENTRY_ADDandFIB_EVENT_ENTRY_APPEND, which IPv4 never emits.[ ... ]
Quoted 9 lines
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst new file +9
-0+For a BCM53012 board, add the following node under the root address space +(adjust the compatible to ``brcm,bcm53011-fa`` for BCM53011):: + + / { + fa: flow-accelerator@18027c00 { + compatible = "brcm,bcm53012-fa"; + reg = <0x18027c00 0xc0>; + }; + };[ ... ]
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst line 222
Quoted 4 lines
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst new file +4
-0+Remove any other conflicting CPU assignments for this test. B53 selects ``brcm-fa`` +when it finds the enabled accelerator through this phandle. Do not set +``dsa-tag-protocol``: B53 does not implement the runtime protocol-change +operation. No existing board is enabled automatically by this series.[Severity: Medium]
Is this the whole condition? B53 and the FA backend each decide on their own whether FA metadata mode is active, and they use different tests:drivers/net/dsa/b53/b53_common.c:b53_uses_fa_tag() { ... enabled = IS_ENABLED(CONFIG_BCM_NS_FA) && of_device_is_available(fa) && (dev->chip_id == BCM53011_DEVICE_ID || dev->chip_id == BCM53012_DEVICE_ID || (is5301x(dev) && of_device_is_compatible(fa, "brcm,bcm4708-fa"))); ... }drivers/net/ethernet/broadcom/bcm-ns-fa.c:bcm_ns_fa_init() { ... if (!of_device_is_compatible(np, "brcm,bcm4708-fa") && !of_device_is_compatible(np, "brcm,bcm53011-fa") && !of_device_is_compatible(np, "brcm,bcm53012-fa")) { of_node_put(np); return ERR_PTR(-ENODEV); } ... }
bcm_ns_fa_init()ignores the chip. It then always enablesFA_BRCM_HDRprocessing and clearsFA_CTL_BYPASS.Take the brcm,bcm53012-fa node from the example above on a 5301x switch whose runtime
chip_idis BCM53010, BCM53018 or BCM53019. The backend would switch GMAC2 RX to the FA descriptor format. B53 would keep the ordinary brcm tagger on port 8 and skip the CFP exception guards. Would conduit RX on port 8 then be misparsed or dropped?An available FA node with any other compatible makes
bcm_ns_fa_init()return-ENODEV. That fails the whole GMAC2 probe:drivers/net/ethernet/broadcom/bgmac.c:bgmac_enet_probe() { ... bgmac->fa = bcm_ns_fa_init(net_dev); if (IS_ERR(bgmac->fa)) { err = PTR_ERR(bgmac->fa); bgmac->fa = NULL; ... }Also, "brcm,bcm4708-fa" turns on FA mode for any 5301x chip. That includes parts the binding, the
Kconfighelp and this document do not list as supported.Could B53 and the backend share one predicate, and could the document state the actual conditions?
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst line 227
Quoted 5 lines
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst new file +5
-0+ +The FA resource is outside the GMAC3 DMA register window. It is managed by +the GMAC2 consumer; it does not need a separate platform driver or character +device. Leave the accelerator disabled or omit the GMAC2 phandle to retain +the existing board configuration.[Severity: Medium]
What state does the GMAC3 core need to be in? The FA block at0x18027c00is at offset0xc00inside the GMAC3 BCMA core aperture (gmac3:
ethernet@27000 inbcm-ns.dtsi).bcm_ns_fa_init()maps and programs it from GMAC2 without checking or enabling the core that hosts it.If the FA shares GMAC3's reset or clock domain, two cases look like problems.
First, when GMAC3 is disabled in DT, nothing releases the core's reset:
drivers/bcma/main.c:bcma_register_devices() { ... np = core->dev.of_node; if (np && !of_device_is_available(np)) continue; ... }Could FA register accesses then abort, or hit the
FA_INIT_DONEpoll timeout, depending on what the bootloader left behind?Second, when GMAC3 is enabled,
bgmac_probe()inbgmac-bcma.conly rejects the phandle on a core other than unit 2. GMAC3 therefore still probes, andbgmac_enet_probe()unconditionally calls:bgmac_clk_enable(bgmac, 0);This reaches
bcma_core_enable(), which pulses the GMAC3 core reset. If that happens after GMAC2 has initialized the FA, does it wipeFA_CTLand the table state? The GMAC2 side would still believe its flows[] and next-hop bookkeeping match the hardware.BGMAC_FEAT_NO_RESETsuppresses the reset in open/close, but not this probe-time enable.The setup steps only cover GMAC0 and GMAC2. Should they say whether GMAC3 must be enabled, disabled or left alone?
[ ... ]
Quoted 13 lines
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst new file +13
-0+ table inet fa_test { + flowtable ft { + hook ingress priority 0; + devices = { lan1, wan }; + flags offload; + counter; + } + chain forward { + type filter hook forward priority 0; policy drop; + meta l4proto udp ct state established flow add @ft + ct state established,related counter accept + iifname "lan1" oifname "wan" udp dport 5001 counter accept + iifname "wan" oifname "lan1" udp dport 5001 ct status dnat counter acceptDocumentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst line 299
Quoted 10 lines
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst new file +10
-0+ } + chain prerouting { + type nat hook prerouting priority dstnat; policy accept; + iifname "wan" udp dport 15001 dnat ip to 192.0.2.2:5001 + } + chain postrouting { + type nat hook postrouting priority srcnat; policy accept; + iifname "lan1" oifname "wan" ip saddr 192.0.2.2 snat ip to 198.51.100.1:45000 + } + }[Severity: Medium]
Will this table load with nft -f? The snat rule in the postrouting chain asks for a port mapping. However, iifname, oifname and ip saddr don't set a transport protocol. nft rejects such a rule with "transport protocol mapping is only valid after transport protocol match". nft -f loads the file as one transaction, so the wholefa_testtable would be rejected.The dnat rule is fine because udp dport 15001 comes first. Would a meta l4proto (or tcp/udp) match before the snat statement fix this? The in-tree
nft_flowtable.shandnft_nat.shselftests do that.Separately, the forward chain only handles UDP:
meta l4proto udp ct state established flow add @ft iifname "lan1" oifname "wan" udp dport 5001 counter accept
With policy drop, wouldn't a new TCP SYN match no accept rule and be dropped? The text below says "run a UDP or TCP echo server". Later sections ask for the SNAT, DNAT, pressure, fallback and aging tests to be repeated with TCP, but no TCP ruleset is given.
[ ... ]
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst line 491
Quoted 3 lines
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst new file +3
-0+ ./tools/testing/kunit/kunit.py run --arch=x86_64 \ + --kunitconfig=drivers/net/ethernet/broadcom/.kunitconfig \ + --build_dir=/tmp/bcm-ns-fa-kunit '*fa*'[Severity: Low]
Does the '*fa*' filter skip suites that this kunitconfig builds?drivers/net/ethernet/broadcom/.kunitconfigalso setsCONFIG_NF_FLOW_TABLE_KUNIT_TEST=y. That builds the nf-flow-lifetime suite (net/netfilter/nf_flow_table_core_test.c) and the nf-flow-path suite (net/netfilter/nf_flow_table_offload_test.c). Neither name contains "fa", so the documented command builds them but never runs them.
Quoted 8 lines
nf-flow-path covers the cached route and neighbour validation in
nf_flow_offload_validate()that the commit message relies on.Should the filter include these suites? Should the text below also mention
CONFIG_NF_FLOW_TABLE_KUNIT_TESTnext to the three suites it lists?[ ... ]
[Medium] FIB notifications
Agreed: only the first alias of a prefix is notified, so changes to non-first aliases (DSCP routes) are not seen. v2 documents the limit and that DSCP-specific routes must not be used with FA.
[Medium] B53 and the backend deciding differently
Both now accept the same compatibles (patch 6), on a BCM5301x switch. v2 documents the actual conditions and what happens for an enabled node with another compatible.
[Medium] GMAC3
GMAC3 is not probed by bgmac without a MAC address, so its core is not reset by the driver. Whether the accelerator registers are accessible depends on the bootloader state; v2 documents it, and makes reading them
the first step of the hardware validation.
[Medium] nftables ruleset
Agreed, v2 matches the protocol before the NAT statements and covers TCP as well as UDP.
[Low] kunit filter, commit message
Fixed in v2.
pw-bot: cr
Signature · 1 line
Florian
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.
Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Florian Fainelli
maintainerQuoted 8 lines · On 11/16/26 14:38, [email protected] wrote:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
The commits with a Fixes: tag were developed in response to a test failure developing the flow accelerator hardware on BCM5301X SoCs.
Signature · 1 line
Florian