Re: [PATCH net-next v12 09/10] bnge: add aRFS flow steering ndo support

From: Vikas Gupta

Date: Sun Dec 06 2026 - 03:50:06 EST


On Sat, Dec 5, 2026 at 8:16 PM <netdev-bot+sashiko@xxxxxxxxxx> wrote:
>
> Thank you for your contribution! Sashiko AI review found 4 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 · Medium: 2 · 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] Installed aRFS rules are not revalidated when the L2 filter
> they were programmed against is recreated or deleted while the…
> - [Medium] In the expire loop of bnge_cfg_ntp_filters(), the return value
> of bnge_hwrm_cfa_ntuple_filter_free() is ignored and…
> - [Low] bnge_cfg_one_usr_fltr() now writes ntp_fltr->l2_key and
> l2_filter_id under ntp_fltr_lock.
> - [Low] The comment on bnge_net::ntp_fltr_lock still says it "Protects
> the aRFS/ntuple hash table add and delete".
>
> --
>
> bnge: add aRFS flow steering ndo support
>
> This adds bnge_rx_flow_steer() as the ndo_rx_flow_steer callback. It
> creates aRFS ntuple filters, and bnge_cfg_ntp_filters(), run from sp_task,
> programs, retargets and expires them. The ntuple rule matching now
> compares the L2 filter key instead of the firmware L2 filter id.
>
> > diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_filter.c b/drivers/net/ethernet/broadcom/bnge/bnge_filter.c
> > index 639c36d571f24..b7261018216bc 100644
> > --- a/drivers/net/ethernet/broadcom/bnge/bnge_filter.c
> > +++ b/drivers/net/ethernet/broadcom/bnge/bnge_filter.c
>
> [ ... ]
>
> > @@ -643,7 +658,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 order this write against bnge_rx_flow_steer()?
>
> The first match in bnge_rx_flow_steer() runs under rcu_read_lock() only:
>
> bnge_rx_flow_steer()
> rcu_read_lock()
> bnge_lookup_ntp_filter_from_idx()
> bnge_fltr_match()
> ether_addr_equal(f1->l2_key.dst_mac_addr,
> f2->l2_key.dst_mac_addr) &&
> f1->l2_key.vlan == f2->l2_key.vlan;
>
> Those are plain loads done without ntp_fltr_lock. The lock therefore only
> orders this write against the second match in bnge_insert_ntp_filter().
>
> bnge_open_core() sets BNGE_STATE_OPEN and enables NAPI and interrupts
> before it calls bnge_cfg_usr_fltrs(). RX and aRFS can run while this
> struct copy updates a rule that is already in ntp_fltr_hash_tbl.
>
> If a torn read causes a false miss, bnge_insert_ntp_filter() catches it
> with -EEXIST. A false match returns the user rule's sw_id, and no aRFS
> rule gets installed for that flow.
>
> The impact looks small. Should the comment be corrected and the lockless
> accesses annotated?
>
> [ ... ]
>
> > @@ -716,3 +735,105 @@ void bnge_clear_usr_fltrs(struct bnge_net *bn)
> > }
> > }
> > }
> > +
> > +void bnge_cfg_ntp_filters(struct bnge_net *bn)
> > +{
>
> [ ... ]
>
> > + list_for_each_entry_safe(fltr, tmp, &install_list, base.list_node) {
> > + list_del_init(&fltr->base.list_node);
> > + /* The firmware id of the L2 filter changes whenever the filter
> > + * is recreated, so look it up again from the key before
> > + * programming the rule.
> > + */
> > + l2_id = bnge_lookup_l2_filter_from_key(bn, &fltr->l2_key);
>
> [Severity: Medium]
> The L2 id is looked up again only here, for rules on install_list. What
> happens to rules that are already BNGE_FLTR_VALID when their L2 filter is
> recreated or deleted while the interface is up?
>
> In the non-dev_addr branch of bnge_rx_flow_steer(),
> bnge_lookup_l2_filter_from_key() can return a secondary unicast filter
> (vnic->l2_filters[1..]) or a vlan 0 user ETHER_FLOW L2 filter.
>
> On a unicast list change, bnge_set_rx_mode()->bnge_cfg_rx_mode() frees
> all of them in firmware and recreates them with new ids:
>
> bnge_cfg_rx_mode() {
> ...
> for (i = 1; i < vnic->uc_filter_count; i++) {
> struct bnge_l2_filter *fltr = vnic->l2_filters[i];
>
> if (!fltr)
> continue;
> bnge_hwrm_l2_filter_free(bd, fltr);
> bnge_del_l2_filter_rcu(bn, fltr);
> }
> ...
> }
>
> bnge_srxclsrldel() does the same to a user L2 filter, through
> bnge_hwrm_l2_filter_free() and bnge_del_usr_l2_filter().
>
> Neither path touches the ntuple rules that depend on those filters. A
> BNGE_FLTR_VALID aRFS rule keeps a firmware entry built on the freed L2
> context until the flow expires or moves to another queue.
>
> Depending on the firmware, that entry either keeps steering with a stale
> context, or it is removed silently. In the second case, later
> bnge_hwrm_cfa_ntuple_filter_free() calls fail, and the driver state no
> longer matches the hardware.
>
> The new comment on struct bnge_ntuple_filter also says l2_filter_id "is
> reassigned by firmware on every open". The commit message says the id also
> changes "after a unicast address list change".
>
> Should installed rules be revalidated when this happens, or should the
> comment at least describe the limitation?
>
> For reference, bnxt_cfg_rx_mode() also frees the firmware L2 filter while
> ntuple rules hold a refcount on it. That refcount only keeps the software
> struct alive, so the real effect depends on how the firmware treats ntuple
> entries whose L2 context is freed.

Those rules have no NO_AGING and are aged out by rps_may_expire_flow(),
after which aRFS reinstalls them with a fresh id. The teardown uses the rule's
own ntuple_filter_id, not l2_filter_id, so state converges regardless of whether
firmware keeps or drops the entry when its L2 context is freed (no
leak in either case).
Persistent user ntuple rules always bind to l2_filters[0] (dev_addr),
which is never
freed mid-up, so they're unaffected.


>
> [ ... ]
>
> > + 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: Medium]
> Can this leak the firmware ntuple entry?
>
> bnge_hwrm_cfa_ntuple_filter_free() can fail in bnge_hwrm_req_init() or
> bnge_hwrm_req_send(). On failure it leaves filter_id valid:
>
> rc = bnge_hwrm_req_send(bd, req);
> if (!rc)
> fltr->base.filter_id = BNGE_FLTR_ID_INVALID;
> return rc;
>
> bnge_del_ntp_filter_rcu() then frees the only copy of base.filter_id and
> releases the sw_id. Nothing retries the free.
>
> The firmware entry keeps steering that 5-tuple to the old ring until the
> VNIC is torn down at close. A later aRFS rule for the same flow is either
> programmed next to it or refused as a duplicate. If it is refused, every
> later attempt repeats alloc -> sp_task -> firmware alloc failure ->
> delete.
>
> The update loop above checks the return value of the same call. Should
> the expire path handle a failed free as well?

Yes, on a failed free the firmware entry can be orphaned, but it's bounded
and there's no host-side inconsistency or corruption, so we treat the firmware
free as authoritative and accept the leak on the rare failure.
We will revisit this when we plan to enhance free HWRM return values.

Sashiko's comments were all Medium or Low severity, and after reviewing them,
we don't plan to respin this series. All Medium comments have been answered.

Thanks,
Vikas

>
> > + }
> > +#endif
> > +}
>
> [ ... ]
>
> > diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
> > index 44637152b075c..de7320521a3e0 100644
> > --- a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
> > +++ b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
>
> [ ... ]
>
> > @@ -3433,6 +3442,146 @@ static int bnge_set_features(struct net_device *dev, netdev_features_t features)
> > return 0;
> > }
> >
> > +#ifdef CONFIG_RFS_ACCEL
> > +/* Called with ntp_fltr_lock held. Returns true if sp_task must be queued. */
> > +static bool bnge_ntp_fltr_retarget(struct bnge_net *bn,
> > + struct bnge_ntuple_filter *fltr,
> > + u16 rxq_index, u32 flow_id)
> > +{
> > + if ((fltr->base.flags & BNGE_ACT_NO_AGING) ||
> > + READ_ONCE(fltr->base.rxq) == rxq_index)
> > + return false;
> > +
> > + WRITE_ONCE(fltr->base.rxq, rxq_index);
> > + WRITE_ONCE(fltr->flow_id, flow_id);
>
> [Severity: Low]
> This isn't a bug, but the comment on bnge_net::ntp_fltr_lock in
> bnge_netdev.h still says:
>
> /* Protects the aRFS/ntuple hash table add and delete. ...
>
> This patch also uses the lock for per-filter state:
>
> - rxq and flow_id here
> - the expire re-check and unlink in bnge_cfg_ntp_filters()
> - the hlist_unhashed() check in bnge_rx_flow_steer()
> - the l2_key and l2_filter_id writes in bnge_cfg_one_usr_fltr()
>
> Could the struct comment be updated, so a later change does not write rxq
> or flow_id without holding the lock?
>
> [ ... ]
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201132011.2705569-1-vikas.gupta%40broadcom.com

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature