From: sashiko-bot@kernel.org
To: "Florian Fainelli" <florian.fainelli@broadcom.com>
Cc: "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS"
<devicetree@vger.kernel.org>,
robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next 7/9] net: bgmac: add Northstar IPv4 TCP/UDP NAT flowtable offload
Date: Tue, 17 Nov 2026 22:33:59 +0000 [thread overview]
Message-ID: <sashiko-outbox-219755@kernel.org> (raw)
In-Reply-To: <20261116222519.1416501-8-florian.fainelli@broadcom.com>
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 <florian.fainelli@broadcom.com>
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.
> diff --git a/drivers/net/ethernet/broadcom/bcm-ns-fa.c b/drivers/net/ethernet/broadcom/bcm-ns-fa.c
> new file mode 100644
> index 0000000000000..8665ba94cbab6
> --- /dev/null
> +++ b/drivers/net/ethernet/broadcom/bcm-ns-fa.c
[ ... ]
> +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);
> +}
[ ... ]
> +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);
> + }
> + *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.
> +
> +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);
[ ... ]
> + 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.
> + */
> + 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().
> + 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)))
> + 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.
[ ... ]
> +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;
> + 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.
> diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c
> index 1c502bd64d7df..527f9842eb833 100644
> --- a/drivers/net/ethernet/broadcom/bgmac.c
> +++ b/drivers/net/ethernet/broadcom/bgmac.c
[ ... ]
> @@ -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
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116222519.1416501-1-florian.fainelli@broadcom.com?part=7
next prev parent reply other threads:[~2026-11-17 22:34 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 22:25 [PATCH net-next 0/9] net: bgmac: add Northstar IPv4 TCP/UDP NAT flowtable offload Florian Fainelli
2026-11-16 22:25 ` [PATCH net-next 1/9] net: ethernet: bgmac: validate RX length against the DMA packet capacity Florian Fainelli
2026-11-16 22:25 ` [PATCH net-next 2/9] netfilter: flowtable: reject non-host IPv4 packets before lookup Florian Fainelli
2026-11-17 22:33 ` sashiko-bot
2026-11-16 22:25 ` [PATCH net-next 3/9] netfilter: flowtable: retain offload ownership until deletion completes Florian Fainelli
2026-11-17 22:33 ` sashiko-bot
2026-11-16 22:25 ` [PATCH net-next 4/9] dt-bindings: net: describe the Northstar flow accelerator Florian Fainelli
2026-11-16 22:25 ` [PATCH net-next 5/9] net: dsa: add Broadcom FA metadata and IPv4 exception paths Florian Fainelli
2026-11-17 22:33 ` sashiko-bot
2026-11-16 22:25 ` [PATCH net-next 6/9] net: flow_offload: allow drivers to validate and invalidate cached paths Florian Fainelli
2026-11-16 22:25 ` [PATCH net-next 7/9] net: bgmac: add Northstar IPv4 TCP/UDP NAT flowtable offload Florian Fainelli
2026-11-17 22:33 ` sashiko-bot [this message]
2026-11-16 22:25 ` [PATCH net-next 8/9] net: add KUnit coverage for FA and flowtable path validation Florian Fainelli
2026-11-17 22:34 ` sashiko-bot
2026-11-16 22:25 ` [PATCH net-next 9/9] docs: net: document Northstar FA setup and NAT qualification Florian Fainelli
2026-11-16 22:38 ` [PATCH net-next 0/9] net: bgmac: add Northstar IPv4 TCP/UDP NAT flowtable offload netdev-bot+sinfo
2026-11-16 22:45 ` Florian Fainelli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-219755@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=florian.fainelli@broadcom.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox