From: netdev-bot+sashiko@kernel.org
To: vikas.gupta@broadcom.com
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, andrew+netdev@lunn.ch, horms@kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
bhargava.marreddy@broadcom.com, rahul-rg.gupta@broadcom.com,
vsrama-krishna.nemani@broadcom.com,
rajashekar.hudumula@broadcom.com, dharmender.garg@broadcom.com,
ajit.khaparde@broadcom.com
Subject: Re: [PATCH net-next v8 09/10] bnge: add aRFS flow steering ndo support
Date: Thu, 19 Nov 2026 17:09:11 +0000 [thread overview]
Message-ID: <179510815141.3136.11040952527486167006@kernel.org> (raw)
In-Reply-To: <20261116140653.1685797-10-vikas.gupta@broadcom.com>
Thank you for your contribution! Sashiko AI review found 6 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · 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).
- [Medium] bnge_rx_flow_steer() lets network traffic create dynamic aRFS
NTUPLE filters.
- [Low] The commit message's closing note does not match the code.
- [Low] In the expire loop of bnge_cfg_ntp_filters()
(bnge_filter.c:834-835), the return value of…
- [Low] The locked expire re-check in bnge_cfg_ntp_filters() does not
cover a bnge_rx_flow_steer() hit on an existing filter for the same…
- [Low] bnge_cfg_one_usr_fltr() (bnge_filter.c:660-664) now writes
ntp_fltr->l2_key and l2_filter_id under…
- [Low] On a queue change, bnge_ntp_fltr_retarget() (bnge_netdev.c:3248)
commits the new queue with WRITE_ONCE(fltr->base.rxq, rxq_index) and…
--
bnge: add aRFS flow steering ndo support
This adds an ndo_rx_flow_steer implementation for bnge. It creates aRFS
NTUPLE filters from incoming flows and inserts them into the shared NTUPLE
hash table. Firmware programming and aging through rps_may_expire_flow()
are deferred to sp_task, which the periodic timer queues with the new
BNGE_RX_NTP_FLTR_SP_EVENT.
> Note that, if the L2 filter is freed before sp_task programs the rule,
> the captured firmware id is stale. The NTUPLE alloc either fails (id
> gone) or binds to a recycled id for a different filter. The rule is
> then dropped, or it stays until it ages out.
[Severity: Low]
Is this note still accurate? bnge_cfg_ntp_filters() never programs the id
captured in bnge_rx_flow_steer(). Before every install it looks the id up
again from the stored key:
l2_id = bnge_lookup_l2_filter_from_key(bn, &fltr->l2_key);
if (l2_id == BNGE_FLTR_ID_INVALID) {
bnge_del_ntp_filter_rcu(bn, fltr);
continue;
}
fltr->l2_filter_id = l2_id;
L2 filters are only freed under netdev_lock. That covers bnge_set_rx_mode()
through ndo_set_rx_mode_async, close/teardown, and the ethtool delete path.
sp_task also holds netdev_lock, so the "binds to a recycled id for a
different filter" case doesn't look reachable. The note seems to describe
an earlier version of the patch.
The message also leaves out several behaviour changes to the existing
ethtool n-tuple path:
- bnge_fltr_match() now compares l2_key instead of l2_filter_id
- bnge_cfg_one_usr_fltr() now refreshes l2_key under ntp_fltr_lock
- bnge_get_all_fltr_ids_rcu() and bnge_get_one_fltr_rcu() now filter on
bnge_is_usr_fltr() instead of fltr->flags
- bnge_del_ntp_filter_rcu() now uses hlist_del_init_rcu()
Could the commit message be updated to match the code and mention these
changes?
> diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_filter.c b/drivers/net/ethernet/broadcom/bnge/bnge_filter.c
> index e2dc3a34cad33..a0a8aebad20b6 100644
> --- a/drivers/net/ethernet/broadcom/bnge/bnge_filter.c
> +++ b/drivers/net/ethernet/broadcom/bnge/bnge_filter.c
[ ... ]
> @@ -642,7 +657,11 @@ static void bnge_cfg_one_usr_fltr(struct bnge_net *bn,
> if (fltr->type == BNGE_FLTR_TYPE_NTUPLE) {
> ntp_fltr = container_of(fltr, struct bnge_ntuple_filter, base);
> l2_fltr = bn->vnic_info[BNGE_VNIC_DEFAULT].l2_filters[0];
> + /* bnge_rx_flow_steer() can already run and match this rule */
> + spin_lock_bh(&bn->ntp_fltr_lock);
> ntp_fltr->l2_filter_id = l2_fltr->base.filter_id;
> + ntp_fltr->l2_key = l2_fltr->l2_key;
> + spin_unlock_bh(&bn->ntp_fltr_lock);
[Severity: Low]
Does ntp_fltr_lock actually serialize this write against
bnge_rx_flow_steer()?
The first match in bnge_rx_flow_steer() goes through
bnge_lookup_ntp_filter_from_idx(). That function walks the bucket under
rcu_read_lock() only:
hlist_for_each_entry_rcu(f, head, base.hlist) {
if (bnge_fltr_match(f, fltr))
return f;
}
With this patch, bnge_fltr_match() reads l2_key.dst_mac_addr and
l2_key.vlan with plain loads.
bnge_open_core() sets BNGE_STATE_OPEN and enables interrupts before it
calls bnge_cfg_usr_fltrs(). An RX softirq on another CPU can therefore run
set_rps_cpu()->bnge_rx_flow_steer()->bnge_fltr_match() while this code
writes l2_key, and the two paths share no lock.
The lock here only orders the write against the match loop in
bnge_insert_ntp_filter(). Would KCSAN flag this as a data race? On a MAC
change across close/open, can the reader see a torn key and return a user
filter's sw_id to the RPS core? If the lock is only meant to cover
bnge_insert_ntp_filter(), could the comment say so?
[ ... ]
> @@ -715,3 +734,105 @@ void bnge_clear_usr_fltrs(struct bnge_net *bn)
> }
> }
> }
> +
> +void bnge_cfg_ntp_filters(struct bnge_net *bn)
> +{
[ ... ]
> + /* Free the old HW rule; reinstall it below on the new queue. */
> + list_for_each_entry_safe(fltr, tmp, &update_list, base.list_node) {
> + list_del_init(&fltr->base.list_node);
> + /* If the free fails the rule stays on the old queue. It is not
> + * retried, so a firmware that keeps failing is not hit on every
> + * tick.
> + */
> + if (bnge_hwrm_cfa_ntuple_filter_free(bn->bd, fltr))
> + continue;
[Severity: Low]
What happens to the software state when this free fails?
bnge_ntp_fltr_retarget() has already committed the new queue before
firmware is touched:
WRITE_ONCE(fltr->base.rxq, rxq_index);
WRITE_ONCE(fltr->flow_id, flow_id);
smp_mb__before_atomic();
set_bit(BNGE_FLTR_RXQ_UPDATE, &fltr->base.state);
bnge_hwrm_cfa_ntuple_filter_free() also sets BNGE_FLTR_FW_DELETED before it
sends the HWRM request.
If HWRM_CFA_NTUPLE_FILTER_FREE fails, the firmware rule still steers to the
old rfs_ring_tbl_idx. But fltr->base.rxq now holds the new queue, and
FW_DELETED is set even though the rule is still live.
>From then on, bnge_rx_flow_steer() calls for this flow and target hit the
READ_ONCE(fltr->base.rxq) == rxq_index check in bnge_ntp_fltr_retarget()
and never queue a reprogram. rps_may_expire_flow() is also evaluated
against the new queue's flow table, not the ring the hardware is using.
The comment accepts that the rule stays on the old queue. Should the old
rxq be restored and FW_DELETED cleared on failure, so that software still
matches what firmware has programmed?
> + clear_bit(BNGE_FLTR_FW_DELETED, &fltr->base.state);
> + list_add(&fltr->base.list_node, &install_list);
> + }
[ ... ]
> + list_for_each_entry_safe(fltr, tmp, &expire_list, base.list_node) {
> + list_del_init(&fltr->base.list_node);
> + /* Decide again under ntp_fltr_lock: the scan ran without it and
> + * the firmware calls above can take long. Use the rxq and
> + * flow_id that bnge_rx_flow_steer() writes under it. Unlink
> + * here too, so a flow cannot be retargeted onto a filter that
> + * is about to be freed. The firmware free comes after the
> + * unlock.
> + */
> + spin_lock_bh(&bn->ntp_fltr_lock);
> + if (test_bit(BNGE_FLTR_RXQ_UPDATE, &fltr->base.state) ||
> + !rps_may_expire_flow(bn->netdev, fltr->base.rxq,
> + fltr->flow_id, fltr->base.sw_id)) {
> + spin_unlock_bh(&bn->ntp_fltr_lock);
> + continue;
> + }
[Severity: Low]
Does this re-check cover a bnge_rx_flow_steer() hit on this filter for the
same rxq?
In that case bnge_ntp_fltr_retarget() returns early and writes no state:
if ((fltr->base.flags & BNGE_ACT_NO_AGING) ||
READ_ONCE(fltr->base.rxq) == rxq_index)
return false;
bnge_rx_flow_steer() then drops ntp_fltr_lock and returns
fltr->base.sw_id. set_rps_cpu() in net/core/dev.c records that id only
after the ndo returns, outside ntp_fltr_lock:
rc = dev->netdev_ops->ndo_rx_flow_steer(dev, skb, rxq_index, flow_id);
...
WRITE_ONCE(rflow->filter, rc);
Suppose this re-check runs inside that window. RXQ_UPDATE is clear and
rps_may_expire_flow() still sees the old rflow state. The filter is
unlinked and freed in firmware, and its sw_id bit is released. The core
then stores a dead sw_id in rflow->filter.
The rflow then looks active, so set_rps_cpu() skips the ndo. The flow runs
without a hardware rule until the slot goes stale, and the dead sw_id can
alias a reused id.
Hitting this needs a packet of the flow to arrive on a queue other than
the one the rule targets. One example is after the failed retarget free
described above.
The comment above says the locked re-check keeps a flow from being
retargeted onto a filter that is about to be freed. Doesn't that only
hold when the rxq changes and RXQ_UPDATE is set?
> + hlist_del_init_rcu(&fltr->base.hlist);
> + spin_unlock_bh(&bn->ntp_fltr_lock);
> +
> + bnge_hwrm_cfa_ntuple_filter_free(bn->bd, fltr);
> + bnge_del_ntp_filter_rcu(bn, fltr);
[Severity: Low]
Can this leak the firmware ntuple filter? The return value of
bnge_hwrm_cfa_ntuple_filter_free() is ignored. bnge_del_ntp_filter_rcu()
then clears the sw_id bit, decrements ntp_fltr_count and kfree_rcu()s the
object anyway.
bnge_hwrm_cfa_ntuple_filter_free() resets base.filter_id only when the
send succeeds:
rc = bnge_hwrm_req_send(bd, req);
if (!rc)
fltr->base.filter_id = BNGE_FLTR_ID_INVALID;
return rc;
If HWRM_CFA_NTUPLE_FILTER_FREE fails, the rule stays programmed in
firmware, but the only copy of its handle is freed. Nothing can free the
rule until the VNIC/L2 contexts are torn down. Meanwhile the orphaned rule
keeps steering the old flow, and the released sw_id can be handed to a new
filter.
The update loop above checks the same call and keeps the rule on failure.
Should the expire path handle failure the same way? bnxt_en has the same
pattern.
> + }
> +#endif
> +}
[ ... ]
> diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
> index b71e427d3ba10..0e7c506af402c 100644
> --- a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
> +++ b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
[ ... ]
> @@ -3226,6 +3235,146 @@ static int bnge_set_features(struct net_device *dev, netdev_features_t features)
[ ... ]
> +static int bnge_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
> + u16 rxq_index, u32 flow_id)
> +{
[ ... ]
> + new_fltr->flow_id = flow_id;
> + new_fltr->base.rxq = rxq_index;
> + rc = bnge_insert_ntp_filter(bn, new_fltr, idx);
> + if (!rc) {
> + bnge_queue_sp_work(bn, BNGE_RX_NTP_FLTR_SP_EVENT);
> + return new_fltr->base.sw_id;
> + }
[Severity: Medium]
Can remote traffic fill the ntuple table that ethtool rules rely on?
The aRFS filters created here share bn->ntp_fltr_bmap and the hash table
with administrator ethtool rules. The bitmap is sized bd->max_fltr
(BNGE_MAX_NTUPLE_FLTRS), and no slots are reserved for BNGE_ACT_NO_AGING
rules.
A remote peer can open many TCP connections to a local listener that reads
from them. With RFS enabled, each socket's flow reaches this function
through set_rps_cpu(). Unconnected UDP does not record rxhash, so this
needs TCP or connected sockets.
Once the bitmap is full, bnge_add_ntuple_cls_rule()->
bnge_insert_ntp_filter() fails:
bit_id = bitmap_find_free_region(bn->ntp_fltr_bmap,
bn->bd->max_fltr, 0);
if (bit_id < 0) {
spin_unlock_bh(&bn->ntp_fltr_lock);
return -ENOMEM;
}
There is a second failure mode. bnge_fltr_match() ignores the filter type,
and the bnge_toeplitz() index matches the hardware RSS hash. A live aRFS
entry for a full-mask 5-tuple therefore makes bnge_add_ntuple_cls_rule()
fail with -EEXIST for that exact flow, including a drop rule meant to stop
it:
fltr = bnge_lookup_ntp_filter_from_idx(bn, new_fltr, idx);
if (fltr) {
rcu_read_unlock();
rc = -EEXIST;
goto err_free_fltr;
}
Each new flow also costs a GFP_ATOMIC allocation in softirq and an HWRM
call in sp_task under netdev_lock.
bnxt_en uses the same shared bitmap design, but this patch is the first to
let traffic insert into the bnge table. Should the number of aRFS filters
be capped below max_fltr, or part of the table be reserved for user rules?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116140653.1685797-1-vikas.gupta%40broadcom.com
next prev parent reply other threads:[~2026-11-19 17:09 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 14:06 [PATCH net-next v8 00/10] add features to bnge Vikas Gupta
2026-11-16 14:06 ` [PATCH net-next v8 01/10] bnge: restructure VNIC and filter code Vikas Gupta
2026-11-16 14:06 ` [PATCH net-next v8 02/10] bnge: add NTUPLE/ARFS VNIC Vikas Gupta
2026-11-19 17:09 ` netdev-bot+sashiko
2026-11-16 14:06 ` [PATCH net-next v8 03/10] bnge: add helper functions for multi RSS contexts Vikas Gupta
2026-11-16 14:06 ` [PATCH net-next v8 04/10] bnge: add RXFH ethtool support Vikas Gupta
2026-11-19 17:09 ` netdev-bot+sashiko
2026-11-16 14:06 ` [PATCH net-next v8 05/10] bnge: add ethtool support to manage RSS contexts Vikas Gupta
2026-11-19 17:09 ` netdev-bot+sashiko
2026-11-16 14:06 ` [PATCH net-next v8 06/10] bnge: remove refcount from L2 filter Vikas Gupta
2026-11-16 14:06 ` [PATCH net-next v8 07/10] bnge: add NTUPLE filter infrastructure Vikas Gupta
2026-11-19 17:09 ` netdev-bot+sashiko
2026-11-16 14:06 ` [PATCH net-next v8 08/10] bnge: add NTUPLE filter support in ethtool Vikas Gupta
2026-11-19 17:09 ` netdev-bot+sashiko
2026-11-16 14:06 ` [PATCH net-next v8 09/10] bnge: add aRFS flow steering ndo support Vikas Gupta
2026-11-19 17:09 ` netdev-bot+sashiko [this message]
2026-11-16 14:06 ` [PATCH net-next v8 10/10] bnge: add cpu_rmap support for IRQ affinity Vikas Gupta
2026-11-19 17:09 ` netdev-bot+sashiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179510815141.3136.11040952527486167006@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=ajit.khaparde@broadcom.com \
--cc=andrew+netdev@lunn.ch \
--cc=bhargava.marreddy@broadcom.com \
--cc=davem@davemloft.net \
--cc=dharmender.garg@broadcom.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rahul-rg.gupta@broadcom.com \
--cc=rajashekar.hudumula@broadcom.com \
--cc=vikas.gupta@broadcom.com \
--cc=vsrama-krishna.nemani@broadcom.com \
/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
all inboxes | Powered by JetHome®