add features to bnge
Vikas Gupta
maintainerv6 cover add features to bnge
Hi,
This series adds ntuple filter, RSS context, and flow steering support to bnge driver.
Patch 1 is a pure refactor (no functional change) that relocates the filter and VNIC related code into the appropriate files. Patch 7 drops the refcount usage from L2 filters, also with no functional change. The subsequent patches then add the ethtool commands for configuring ntuple flows and RSS contexts.
Thanks,
Vikas
v5->v6:
- Addressed comments from Sashiko
https://sashiko.dev/#/patchset/20261103123651.442893-1-vikas.gupta%40broadcom.com
- Fix inline keyword use in C file.
v4->v5:
- Addressed comments from Sashiko
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928061307.1172344-1-vikas.gupta%40broadcom.com
v3->v4:
- Addressed comments from Sashiko
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260917064548.773334-1-vikas.gupta%40broadcom.com
https://sashiko.dev/#/patchset/20260917064548.773334-1-vikas.gupta%40broadcom.com
- The patch count drops to 10 now that the HSI patches have been merged.
v2->v3:
- Build fix.
- Addressed comments from Sashiko
https://sashiko.dev/#/patchset/20260908093053.2596020-1-vikas.gupta%40broadcom.com
Below Sashiko comments are not valid:
Patch-8:
Comment under bnge_toeplitz().
Explanation: bnge_toeplitz() is not used for aRFS.
Patch-9:
Comment regarding bnge_clear_usr_fltrs().
Explanation:
Both bnge_clear_usr_fltrs() (only invoked while the interface is down) and bnge_grxclsrule() execute under the netdev instance lock, so they are serialized and never touch the filter list at the same time.
Patch-10:
Comment "Does this direct dereference of the MAC header need a linearization ...".
Explanation: ndo_rx_flow_steer runs on the RX path
after eth_type_trans(), which already accesses and pulls the Ethernet header.
Comment Related to bnge_cfg_ntp_filters().
Explanation:
bnge_cfg_ntp_filters() runs from bnge_sp_task(), which holds the netdev instance lock while executing.v1->v2:
- Build fixes.
- Addressed comments from Sashiko
https://sashiko.dev/#/patchset/20260814011435.194631-1-vikas.gupta%40broadcom.com
Vikas Gupta (10):
bnge: restructure VNIC and filter code
bnge: add NTUPLE/ARFS VNIC
bnge: add helper functions for multi RSS contexts
bnge: add RXFH ethtool support
bnge: add ethtool support to manage RSS contexts
bnge: remove refcount from L2 filter
bnge: add NTUPLE filter infrastructure
bnge: add NTUPLE filter support in ethtool
bnge: add aRFS flow steering ndo support
bnge: add cpu_rmap support for IRQ affinity
drivers/net/ethernet/broadcom/bnge/Makefile | 4 +- drivers/net/ethernet/broadcom/bnge/bnge.h | 13 +- .../net/ethernet/broadcom/bnge/bnge_ethtool.c | 1140 +++++++++++++++++ .../net/ethernet/broadcom/bnge/bnge_filter.c | 790 ++++++++++++ .../net/ethernet/broadcom/bnge/bnge_filter.h | 130 ++ .../ethernet/broadcom/bnge/bnge_hwrm_lib.c | 170 ++- .../ethernet/broadcom/bnge/bnge_hwrm_lib.h | 8 + .../net/ethernet/broadcom/bnge/bnge_netdev.c | 534 +++++--- .../net/ethernet/broadcom/bnge/bnge_netdev.h | 94 +- .../net/ethernet/broadcom/bnge/bnge_resc.c | 151 ++- .../net/ethernet/broadcom/bnge/bnge_resc.h | 1 + .../net/ethernet/broadcom/bnge/bnge_vnic.c | 378 ++++++ .../net/ethernet/broadcom/bnge/bnge_vnic.h | 96 ++ 13 files changed, 3188 insertions(+), 321 deletions(-) create mode 100644 drivers/net/ethernet/broadcom/bnge/bnge_filter.c create mode 100644 drivers/net/ethernet/broadcom/bnge/bnge_filter.h create mode 100644 drivers/net/ethernet/broadcom/bnge/bnge_vnic.c create mode 100644 drivers/net/ethernet/broadcom/bnge/bnge_vnic.h
Signature · 1 line
2.52.0
Vikas Gupta
maintainerPATCH v6 1/10 bnge: restructure VNIC and filter code
Move VNIC and L2 filter code out of bnge_netdev.c into dedicated bnge_vnic.c/h and bnge_filter.c/h files in preparation for multi-VNIC, RSS context, and NTUPLE filter support.
This is a code reorganization with no functional change, which helps centralize the functions into their respective modules.
The move comes with a few small cleanups:
- The BNGE_FLTR_TYPE_*, BNGE_FLTR_* state and BNGE_VNIC_*_FLAG macros become enums with new values. None of them reaches firmware, and all users are inside the driver.
- struct bnge_filter_base members hash and list are renamed to hlist and list_node.
- bnge_rss_ctxs_in_use() is renamed to bnge_get_total_rss_ctxs(), and bnge_get_total_vnics() no longer takes the rx_rings argument.
- bnge_fill_hw_rss_tbl() and bnge_set_dflt_rss_indir_tbl() use u16 indexes and temporaries; the values fit.
--- drivers/net/ethernet/broadcom/bnge/Makefile | 4 +- drivers/net/ethernet/broadcom/bnge/bnge.h | 7 - .../net/ethernet/broadcom/bnge/bnge_filter.c | 113 ++++++++++++ .../net/ethernet/broadcom/bnge/bnge_filter.h | 58 ++++++ .../ethernet/broadcom/bnge/bnge_hwrm_lib.c | 2 + .../ethernet/broadcom/bnge/bnge_hwrm_lib.h | 2 + .../net/ethernet/broadcom/bnge/bnge_netdev.c | 170 +----------------- .../net/ethernet/broadcom/bnge/bnge_netdev.h | 72 -------- .../net/ethernet/broadcom/bnge/bnge_resc.c | 31 +--- .../net/ethernet/broadcom/bnge/bnge_vnic.c | 100 +++++++++++ .../net/ethernet/broadcom/bnge/bnge_vnic.h | 63 +++++++ 11 files changed, 350 insertions(+), 272 deletions(-) create mode 100644 drivers/net/ethernet/broadcom/bnge/bnge_filter.c create mode 100644 drivers/net/ethernet/broadcom/bnge/bnge_filter.h create mode 100644 drivers/net/ethernet/broadcom/bnge/bnge_vnic.c create mode 100644 drivers/net/ethernet/broadcom/bnge/bnge_vnic.h
drivers/net/ethernet/broadcom/bnge/Makefile +3 -1
@@ -12,4 +12,6 @@ bng_en-y := bnge_core.o \ bnge_ethtool.o \ bnge_auxr.o \ bnge_txrx.o \ - bnge_link.o + bnge_link.o \ + bnge_vnic.o \ + bnge_filter.o
drivers/net/ethernet/broadcom/bnge/bnge.h +0 -7
@@ -163,13 +163,6 @@ struct bnge_dev {#define BNGE_L2_FLTR_MAX_FLTR 1024u32 *rss_indir_tbl; -#define BNGE_RSS_TABLE_ENTRIES 64 -#define BNGE_RSS_TABLE_SIZE (BNGE_RSS_TABLE_ENTRIES * 4) -#define BNGE_RSS_TABLE_MAX_TBL 8 -#define BNGE_MAX_RSS_TABLE_SIZE \ - (BNGE_RSS_TABLE_SIZE * BNGE_RSS_TABLE_MAX_TBL) -#define BNGE_MAX_RSS_TABLE_ENTRIES \ - (BNGE_RSS_TABLE_ENTRIES * BNGE_RSS_TABLE_MAX_TBL)u16 rss_indir_tbl_entries;u32 rss_cap;
drivers/net/ethernet/broadcom/bnge/bnge_filter.c new file +113 -0
113 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_filter.h new file +58 -0
58 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c +2 -0
@@ -15,6 +15,8 @@#include "bnge_rmem.h" #include "bnge_resc.h" #include "bnge_netdev.h" +#include "bnge_vnic.h" +#include "bnge_filter.h" static const u16 bnge_async_events_arr[] = {ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE ,
drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.h +2 -0
@@ -4,6 +4,8 @@#ifndef _BNGE_HWRM_LIB_H_#define _BNGE_HWRM_LIB_H_ +struct bnge_l2_filter ; +#define BNGE_PLC_EN_JUMBO_THRES_VALID \ VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID#define BNGE_PLC_EN_HDS_THRES_VALID \
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +2 -168
182 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_netdev.h +0 -72
86 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +7 -24
@@ -11,6 +11,7 @@#include "bnge_hwrm.h" #include "bnge_hwrm_lib.h" #include "bnge_resc.h" +#include "bnge_vnic.h" static u16 bnge_num_tx_to_cp (struct bnge_dev *bd,u16 tx) {
@@ -187,13 +188,13 @@ int bnge_cal_nr_rss_ctxs(u16 rx_rings) BNGE_RSS_TABLE_MAX_TBL); } -static u16 bnge_rss_ctxs_in_use (struct bnge_dev *bd, -struct bnge_hw_rings *hwr) +static u16 bnge_get_total_rss_ctxs (struct bnge_dev *bd, +struct bnge_hw_rings *hwr) {return bnge_cal_nr_rss_ctxs (hwr->grp); } -static u16 bnge_get_total_vnics (struct bnge_dev *bd,u16 rx_rings) +static u16 bnge_get_total_vnics (struct bnge_dev *bd) {return 1 ; }
@@ -204,24 +205,6 @@ u32 bnge_get_rxfh_indir_size(struct bnge_dev *bd)BNGE_RSS_TABLE_ENTRIES ; } -static void bnge_set_dflt_rss_indir_tbl (struct bnge_dev *bd) -{ -u16 max_entries, pad; -u32 *rss_indir_tbl; -int i; - - max_entries =bnge_get_rxfh_indir_size (bd); - rss_indir_tbl = &bd->rss_indir_tbl[0 ]; - -for (i =0 ; i < max_entries; i++) - rss_indir_tbl[i] =ethtool_rxfh_indir_default (i, - bd->rx_nr_rings); - - pad = bd->rss_indir_tbl_entries - max_entries; -if (pad) -memset (&rss_indir_tbl[i],0 , pad *sizeof (*rss_indir_tbl)); -} -static void bnge_copy_reserved_rings (struct bnge_dev *bd,struct bnge_hw_rings *hwr) {
@@ -254,7 +237,7 @@ static bool bnge_need_reserve_rings(struct bnge_dev *bd)if (hw_resc->resv_tx_rings != bd->tx_nr_rings)return true; - vnic =bnge_get_total_vnics (bd, rx); + vnic =bnge_get_total_vnics (bd);if (bnge_is_agg_reqd (bd)) rx <<=1 ;
@@ -300,12 +283,12 @@ int bnge_reserve_rings(struct bnge_dev *bd) sh = true; hwr.cmpl = hwr.rx + hwr.tx; - hwr.vnic =bnge_get_total_vnics (bd, hwr.rx); + hwr.vnic =bnge_get_total_vnics (bd);if (bnge_is_agg_reqd (bd)) hwr.rx <<=1 ; hwr.grp = bd->rx_nr_rings; - hwr.rss_ctx =bnge_rss_ctxs_in_use (bd, &hwr); + hwr.rss_ctx =bnge_get_total_rss_ctxs (bd, &hwr); hwr.stat =bnge_func_stat_ctxs_demand (bd); old_rx_rings = bd->hw_resc.resv_rx_rings;
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c new file +100 -0
100 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_vnic.h new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.52.0
Vikas Gupta
maintainerPATCH v6 2/10 bnge: add NTUPLE/ARFS VNIC
In reply to Vikas GuptaInitialize the second VNIC, which is specifically used for the NTUPLE/ARFS feature. This VNIC helps support the aRFS/NTUPLE functionality. With this change, the total number of VNICs becomes 2. Add bnge_set_dflt_rfs() to configure the default NTUPLE feature state at netdev allocation time.
The NTUPLE/aRFS VNIC is always allocated, so the function needs at least BNGE_BASE_VNICS (2) VNICs and the matching RSS contexts. Firmware grants these to every supported function. If it grants fewer, bnge_reserve_rings() fails with -ENOMEM and the device does not probe, as it would for any other missing ring resource.
The patch also removes BNGE_FW_CAP_CFA_NTUPLE_RX_EXT_IP_PROTO and BNGE_FW_CAP_CFA_RFS_RING_TBL_IDX_V3, which nothing uses, and renumbers BNGE_FW_CAP_VNIC_RE_FLUSH from BIT_ULL(26) to BIT_ULL(24).
--- drivers/net/ethernet/broadcom/bnge/bnge.h | 4 +- .../net/ethernet/broadcom/bnge/bnge_netdev.c | 58 +++++++++++++++++-- .../net/ethernet/broadcom/bnge/bnge_netdev.h | 1 + .../net/ethernet/broadcom/bnge/bnge_resc.c | 29 +++++++--- .../net/ethernet/broadcom/bnge/bnge_resc.h | 1 + .../net/ethernet/broadcom/bnge/bnge_vnic.c | 33 ++++++++++- .../net/ethernet/broadcom/bnge/bnge_vnic.h | 8 ++- 7 files changed, 115 insertions(+), 19 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge.h +1 -3
@@ -63,9 +63,7 @@ enum {BNGE_FW_CAP_THRESHOLD_TEMP_SUPPORTED =BIT_ULL (21 ),BNGE_FW_CAP_DFLT_VLAN_TPID_PCP =BIT_ULL (22 ),BNGE_FW_CAP_VNIC_TUNNEL_TPA =BIT_ULL (23 ), -BNGE_FW_CAP_CFA_NTUPLE_RX_EXT_IP_PROTO =BIT_ULL (24 ), -BNGE_FW_CAP_CFA_RFS_RING_TBL_IDX_V3 =BIT_ULL (25 ), - BNGE_FW_CAP_VNIC_RE_FLUSH = BIT_ULL(26), + BNGE_FW_CAP_VNIC_RE_FLUSH = BIT_ULL(24), }; enum {
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +52 -6
100 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_netdev.h +1 -0
@@ -152,6 +152,7 @@ enum {BNGE_NET_EN_GRO =BIT (0 ),BNGE_NET_EN_LRO =BIT (1 ),BNGE_NET_EN_JUMBO =BIT (2 ), + BNGE_NET_EN_NTUPLE = BIT(3), };#define BNGE_NET_EN_TPA (BNGE_NET_EN_GRO | BNGE_NET_EN_LRO)
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +22 -7
@@ -191,12 +191,16 @@ int bnge_cal_nr_rss_ctxs(u16 rx_rings)static u16 bnge_get_total_rss_ctxs (struct bnge_dev *bd,struct bnge_hw_rings *hwr) { -return bnge_cal_nr_rss_ctxs (hwr->grp); +u16 rss_ctx =bnge_cal_nr_rss_ctxs (hwr->grp); + + rss_ctx *= hwr->vnic; + +return rss_ctx; }static u16 bnge_get_total_vnics (struct bnge_dev *bd) { -return 1 ; +return BNGE_BASE_VNICS ; }u32 bnge_get_rxfh_indir_size (struct bnge_dev *bd)
@@ -222,8 +226,12 @@ static void bnge_copy_reserved_rings(struct bnge_dev *bd,static bool bnge_rings_ok (struct bnge_hw_rings *hwr) { -return hwr->tx && hwr->rx && hwr->nq && hwr->grp && hwr->vnic && - hwr->stat && hwr->cmpl; +/* The default and the NTUPLE VNICs each need a full set of RSS +* contexts for the final number of ring groups. +*/ +return hwr->tx && hwr->rx && hwr->nq && hwr->grp && + hwr->vnic >=BNGE_BASE_VNICS && hwr->stat && hwr->cmpl && + hwr->rss_ctx >=bnge_cal_nr_rss_ctxs (hwr->grp) *BNGE_BASE_VNICS ; }static bool bnge_need_reserve_rings (struct bnge_dev *bd)
@@ -232,18 +240,21 @@ static bool bnge_need_reserve_rings(struct bnge_dev *bd)u16 cprs =bnge_cprs_demand (bd);u16 rx = bd->rx_nr_rings, stat;u16 nqs =bnge_nqs_demand (bd); -u16 vnic; +struct bnge_hw_rings hwr = {};if (hw_resc->resv_tx_rings != bd->tx_nr_rings)return true; - vnic =bnge_get_total_vnics (bd); + hwr.grp = bd->rx_nr_rings; + hwr.vnic =bnge_get_total_vnics (bd);if (bnge_is_agg_reqd (bd)) rx <<=1 ; stat =bnge_func_stat_ctxs_demand (bd);if (hw_resc->resv_rx_rings != rx || hw_resc->resv_cp_rings != cprs || - hw_resc->resv_vnics != vnic || hw_resc->resv_stat_ctxs != stat) + hw_resc->resv_vnics != hwr.vnic || + hw_resc->resv_rsscos_ctxs !=bnge_get_total_rss_ctxs (bd, &hwr) || + hw_resc->resv_stat_ctxs != stat)return true;if (hw_resc->resv_irqs != nqs)return true;
@@ -327,6 +338,10 @@ int bnge_reserve_rings(struct bnge_dev *bd) bd->rx_nr_rings = rx_rings; bd->nq_nr_rings = hwr.nq; +/* One ring group per rx ring, so rss_ctx is checked against the final +* rx ring count. +*/ + hwr.grp = rx_rings;if (!bnge_rings_ok (&hwr))return -ENOMEM ;
drivers/net/ethernet/broadcom/bnge/bnge_resc.h +1 -0
@@ -75,6 +75,7 @@ void bnge_aux_init_dflt_config(struct bnge_dev *bd);u32 bnge_get_rxfh_indir_size (struct bnge_dev *bd);int bnge_cal_nr_rss_ctxs (u16 rx_rings);bool bnge_aux_has_enough_resources (struct bnge_dev *bd); +bool bnge_arfs_capable (struct bnge_dev *bd,bool new_rss_ctx);static inline u32 bnge_adjust_pow_two (u32 total_ent,u16 ent_per_blk)
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +32 -1
@@ -42,7 +42,11 @@ void bnge_fill_hw_rss_tbl(struct bnge_net *bn, struct bnge_vnic_info *vnic)for (i =0 ; i < tbl_size; i++) {u16 ring_id, j; - j = bd->rss_indir_tbl[i]; +if (vnic->flags &BNGE_VNIC_NTUPLE_FLAG ) + j =ethtool_rxfh_indir_default (i, bd->rx_nr_rings); +else + j = bd->rss_indir_tbl[i]; + rxr = &bn->rx_ring[j]; ring_id = rxr->rx_ring_struct.fw_ring_id;
@@ -98,3 +102,30 @@ int bnge_setup_vnic(struct bnge_net *bn, struct bnge_vnic_info *vnic) }return rc; } + +static int bnge_alloc_and_setup_vnic (struct bnge_net *bn, +struct bnge_vnic_info *vnic, +u16 rx_rings) +{ +int rc; + + rc =bnge_hwrm_vnic_alloc (bn->bd, vnic, rx_rings); +if (rc) { +netdev_err (bn->netdev,"hwrm vnic %u alloc failure rc: %d\n" , + vnic->vnic_id, rc); +return rc; + } + +/* If bnge_setup_vnic() fails, the VNIC allocated above is not freed +* here; the caller (bnge_init_chip) unwinds via its err_out path. +*/ +return bnge_setup_vnic (bn, vnic); +} + +int bnge_alloc_rfs_vnic (struct bnge_net *bn) +{ +struct bnge_vnic_info *vnic; + + vnic = &bn->vnic_info[BNGE_VNIC_NTUPLE ]; +return bnge_alloc_and_setup_vnic (bn, vnic, bn->bd->rx_nr_rings); +}
drivers/net/ethernet/broadcom/bnge/bnge_vnic.h +6 -2
@@ -22,13 +22,16 @@ struct bnge_l2_filter;#define BNGE_MAX_UC_ADDRS 4enum { -BNGE_VNIC_DEFAULT =0 +BNGE_VNIC_DEFAULT =0 , +BNGE_VNIC_NTUPLE =1 , +BNGE_BASE_VNICS =2 };enum {BNGE_VNIC_RSS_FLAG =BIT (0 ),BNGE_VNIC_MCAST_FLAG =BIT (1 ), -BNGE_VNIC_UCAST_FLAG =BIT (2 ) +BNGE_VNIC_UCAST_FLAG =BIT (2 ), +BNGE_VNIC_NTUPLE_FLAG =BIT (3 ) };struct bnge_vnic_info {
@@ -60,4 +63,5 @@ int bnge_hwrm_vnic_rss_cfg(struct bnge_net *bn, struct bnge_vnic_info *vnic);int bnge_setup_vnic (struct bnge_net *bn,struct bnge_vnic_info *vnic);void bnge_set_dflt_rss_indir_tbl (struct bnge_dev *bd); +int bnge_alloc_rfs_vnic (struct bnge_net *bn);#endif /* _BNGE_VNIC_H_ */
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v6 02/10] bnge: add NTUPLE/ARFS VNIC
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
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] This patch makes the optional NTUPLE/aRFS VNIC a hard probe requirement, and nothing degrades gracefully when firmware grants too…
--
bnge: add NTUPLE/ARFS VNIC
This patch adds a second VNIC for NTUPLE/aRFS. The VNIC is always allocated, so the function now needs two VNICs and twice the RSS contexts. NTUPLE is turned on by default at netdev allocation time, and bnge_rings_ok() now fails the reservation when fewer than two VNICs, or too few RSS contexts for both, are granted.
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +0
-0
[ ... ]
Quoted 5 lines
static u16
bnge_get_total_vnics(struct bnge_dev *bd){drivers/net/ethernet/broadcom/bnge/bnge_resc.c +1
-1-return 1 ; +return BNGE_BASE_VNICS ; }
[ ... ]
Quoted 13 lines
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +6
-2@@ -222,8 +226,12 @@ static void bnge_copy_reserved_rings(struct bnge_dev *bd,static bool bnge_rings_ok (struct bnge_hw_rings *hwr) { -return hwr->tx && hwr->rx && hwr->nq && hwr->grp && hwr->vnic && - hwr->stat && hwr->cmpl; +/* The default and the NTUPLE VNICs each need a full set of RSS +* contexts for the final number of ring groups. +*/ +return hwr->tx && hwr->rx && hwr->nq && hwr->grp && + hwr->vnic >=BNGE_BASE_VNICS && hwr->stat && hwr->cmpl && + hwr->rss_ctx >=bnge_cal_nr_rss_ctxs (hwr->grp) *BNGE_BASE_VNICS ; }
[ ... ]
drivers/net/ethernet/broadcom/bnge/bnge_resc.c int bnge_reserve_rings(struct bnge_dev *bd) · line 346
Quoted 10 lines
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +4
-0@@ -327,6 +338,10 @@ int bnge_reserve_rings(struct bnge_dev *bd) bd->rx_nr_rings = rx_rings; bd->nq_nr_rings = hwr.nq; +/* One ring group per rx ring, so rss_ctx is checked against the final +* rx ring count. +*/ + hwr.grp = rx_rings;if (!bnge_rings_ok (&hwr))return -ENOMEM ;
[Severity: Medium]
Can a partial grant of RSS contexts or VNICs now stop the device from probing?
bnge_get_total_vnics() always returns BNGE_BASE_VNICS, whatever the NETIF_F_NTUPLE / BNGE_NET_EN_NTUPLE state. bnge_rings_ok() now requires vnic >= 2 and rss_ctx >= 2 * bnge_cal_nr_rss_ctxs(grp). Before this patch it only needed a non-zero vnic and did not check rss_ctx.
Earlier in bnge_reserve_rings(), rx_rings is trimmed by hwr.grp, by the stat/nq limits and by bnge_adjust_rings():
rx_rings = min_t(u16, rx_rings, hwr.grp);
However, rx_rings is never trimmed to what the granted resv_rsscos_ctxs can cover. There is also no fallback that drops the NTUPLE VNIC.
The default ring count from _bnge_get_max_rings() also ignores max_rsscos_ctxs and max_vnics:
*max_rx = min_t(int, *max_rx, BNGE_MAX_RSS_TABLE_ENTRIES);
For example, with 100 default rx rings, bnge_cal_nr_rss_ctxs(100) is 2, so 4 contexts are needed. If firmware grants 2 or 3, this worked before the patch (one VNIC, rss_ctx not checked). Now the path is:
bnge_net_init_dflt_rings()
bnge_reserve_rings()
bnge_rings_ok() returns false
return -ENOMEM
bnge_net_init_dflt_rings() then sets the tx/rx ring counts to 0 and returns the error, so probe fails. With rx_rings trimmed to 64, only 2 contexts would have been needed.
A function that gets only one VNIC would also stop probing, even though NTUPLE is optional and can be turned off.
The commit message says:
If it grants fewer, bnge_reserve_rings() fails with -ENOMEM and the device does not probe, as it would for any other missing ring resource.
Is this accurate? The other resources are trimmed to a partial grant and only fail when the grant is zero. A partial RSS context shortfall fails outright.
For comparison, bnxt requests the NTUPLE VNIC only when RFS is enabled. It also clears NTUPLE through bnxt_rfs_capable() when resources are short. Would something similar work here? Another option would be to trim rx_rings to what the granted RSS contexts can cover.
This also looks unchanged at the end of the series. The later bnge_rss_ctx_capable() only covers additional user RSS contexts, and bnge_rings_ok() and _bnge_get_max_rings() are not changed.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261106093524.838341-1-vikas.gupta%40broadcom.com
Vikas Gupta
maintainerPATCH v6 3/10 bnge: add helper functions for multi RSS contexts
In reply to Vikas GuptaAdd infrastructure for creating, modifying, and deleting user-defined RSS contexts. This helps the next patch implement commands for ethtool. For each user RSS context, a VNIC is allocated.
--- .../net/ethernet/broadcom/bnge/bnge_netdev.c | 14 +-- .../net/ethernet/broadcom/bnge/bnge_netdev.h | 2 + .../net/ethernet/broadcom/bnge/bnge_vnic.c | 113 ++++++++++++++++++ .../net/ethernet/broadcom/bnge/bnge_vnic.h | 15 +++ 4 files changed, 132 insertions(+), 12 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +2 -12
@@ -1102,7 +1102,7 @@ static int bnge_alloc_vnic_attributes(struct bnge_net *bn) {struct bnge_dev *bd = bn->bd;struct bnge_vnic_info *vnic; -int i, size; +int i;for (i =0 ; i < bn->nr_vnics; i++) { vnic = &bn->vnic_info[i];
@@ -1127,18 +1127,8 @@ static int bnge_alloc_vnic_attributes(struct bnge_net *bn) }/* Allocate rss table and hash key */ - size =L1_CACHE_ALIGN (BNGE_MAX_RSS_TABLE_SIZE ); - - vnic->rss_table_size = size +HW_HASH_KEY_SIZE ; - vnic->rss_table =dma_alloc_coherent (bd->dev, - vnic->rss_table_size, - &vnic->rss_table_dma_addr, -GFP_KERNEL ); -if (!vnic->rss_table) +if (bnge_alloc_vnic_rss_table (bn, vnic)) goto err_free_vnic_attributes; - - vnic->rss_hash_key = ((void *)vnic->rss_table) + size; - vnic->rss_hash_key_dma_addr = vnic->rss_table_dma_addr + size; }return 0 ;
drivers/net/ethernet/broadcom/bnge/bnge_netdev.h +2 -0
@@ -371,6 +371,8 @@ struct bnge_net {u8 pri2cos_idx[8 ];bool pri2cos_valid; + +u16 num_rss_ctx; };#define BNGE_DEFAULT_RX_RING_SIZE 511
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +113 -0
116 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_vnic.h +15 -0
@@ -58,10 +58,25 @@ struct bnge_vnic_info {u32 vnic_id; }; +struct bnge_rss_ctx { +struct bnge_vnic_info vnic; +u32 index; +}; +void bnge_fill_hw_rss_tbl (struct bnge_net *bn,struct bnge_vnic_info *vnic);int bnge_hwrm_vnic_rss_cfg (struct bnge_net *bn,struct bnge_vnic_info *vnic);int bnge_setup_vnic (struct bnge_net *bn,struct bnge_vnic_info *vnic);void bnge_set_dflt_rss_indir_tbl (struct bnge_dev *bd);int bnge_alloc_rfs_vnic (struct bnge_net *bn); +int bnge_alloc_vnic_rss_table (struct bnge_net *bn, +struct bnge_vnic_info *vnic); +struct bnge_rss_ctx *bnge_get_rss_ctx_from_index (struct bnge_net *bn,u32 idx); +void bnge_modify_rss (struct bnge_net *bn,struct ethtool_rxfh_context *ctx, +struct bnge_rss_ctx *rss_ctx, +const struct ethtool_rxfh_param *rxfh); +void bnge_del_one_rss_ctx (struct bnge_net *bn,struct bnge_rss_ctx *rss_ctx, +bool all); +void bnge_hwrm_realloc_rss_ctx_vnic (struct bnge_net *bn); +void bnge_clear_rss_ctxs (struct bnge_net *bn);#endif /* _BNGE_VNIC_H_ */
Signature · 1 line
2.52.0
Vikas Gupta
maintainerPATCH v6 4/10 bnge: add RXFH ethtool support
In reply to Vikas GuptaIntroduce ethtool RXFH operations including get/set_rxfh for reading and programming the RSS hash key and indirection table.
Currently set_rxfh and set_rxfh_fields are supported only while the device is down. A future patch series will rework bnge_close_core()/bnge_open_core() so they can be driven safely from the ethtool path, adding full functionality by applying the configuration on a live device.
The default RSS key changes. It used to be a per-device get_random_bytes() key created on first open in bnge_init_vnics(). It is now the system-wide netdev_rss_key_fill() key set in bnge_netdev_alloc(), and rss_hash_key_valid is removed.
--- drivers/net/ethernet/broadcom/bnge/bnge.h | 1 + .../net/ethernet/broadcom/bnge/bnge_ethtool.c | 345 ++++++++++++++++++ .../ethernet/broadcom/bnge/bnge_hwrm_lib.c | 2 + .../net/ethernet/broadcom/bnge/bnge_netdev.c | 11 +- .../net/ethernet/broadcom/bnge/bnge_netdev.h | 1 - .../net/ethernet/broadcom/bnge/bnge_resc.c | 7 +- .../net/ethernet/broadcom/bnge/bnge_vnic.h | 1 + 7 files changed, 358 insertions(+), 10 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge.h +1 -0
@@ -85,6 +85,7 @@ enum {BNGE_RSS_CAP_AH_V6_RSS_CAP =BIT (5 ),BNGE_RSS_CAP_ESP_V4_RSS_CAP =BIT (6 ),BNGE_RSS_CAP_ESP_V6_RSS_CAP =BIT (7 ), + BNGE_RSS_CAP_IPV6_FLOW_LABEL_RSS_CAP = BIT(8), };#define BNGE_MAX_QUEUE 8
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +345 -0
363 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c +2 -0
@@ -676,6 +676,8 @@ int bnge_hwrm_vnic_qcaps(struct bnge_dev *bd) bd->rss_cap |=BNGE_RSS_CAP_ESP_V4_RSS_CAP ;if (flags &VNIC_QCAPS_RESP_FLAGS_RSS_IPSEC_ESP_SPI_IPV6_CAP ) bd->rss_cap |=BNGE_RSS_CAP_ESP_V6_RSS_CAP ; +if (flags &VNIC_QCAPS_RESP_FLAGS_RSS_IPV6_FLOW_LABEL_CAP ) + bd->rss_cap |=BNGE_RSS_CAP_IPV6_FLOW_LABEL_RSS_CAP ; }bnge_hwrm_req_drop (bd, req);
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +3 -8
@@ -1747,13 +1747,6 @@ static void bnge_init_vnics(struct bnge_net *bn)u8 *key = (void *)vnic->rss_hash_key;int k; -if (!bn->rss_hash_key_valid && - !bn->rss_hash_key_updated) { -get_random_bytes (bn->rss_hash_key, -HW_HASH_KEY_SIZE ); - bn->rss_hash_key_updated = true; - } -memcpy (vnic->rss_hash_key, bn->rss_hash_key,HW_HASH_KEY_SIZE );
@@ -1761,7 +1754,6 @@ static void bnge_init_vnics(struct bnge_net *bn)continue ; bn->rss_hash_key_updated = false; - bn->rss_hash_key_valid = true; bn->toeplitz_prefix =0 ;for (k =0 ; k <8 ; k++) {
@@ -3400,6 +3392,9 @@ int bnge_netdev_alloc(struct bnge_dev *bd, int max_irqs) bn->tx_ring_size =BNGE_DEFAULT_TX_RING_SIZE ; bn->rx_dir =DMA_FROM_DEVICE ; +netdev_rss_key_fill (bn->rss_hash_key,sizeof (bn->rss_hash_key)); + bn->rss_hash_key_updated = true; +bnge_set_tpa_flags (bd);bnge_init_ring_params (bn);bnge_set_ring_params (bd);
drivers/net/ethernet/broadcom/bnge/bnge_netdev.h +0 -1
@@ -335,7 +335,6 @@ struct bnge_net {u16 rx_dma_offset;u8 rss_hash_key[HW_HASH_KEY_SIZE ]; - u8 rss_hash_key_valid:1; u8 rss_hash_key_updated:1;int rsscos_nr_ctxs;u32 stats_coal_ticks;
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +6 -1
@@ -366,7 +366,7 @@ int bnge_reserve_rings(struct bnge_dev *bd)int bnge_alloc_irqs (struct bnge_dev *bd) { -u16 aux_msix, tx_cp, num_entries; +u16 aux_msix, tx_cp, num_entries, old_rx;int i, irqs_demand, rc;u16 max, min =1 ;
@@ -403,12 +403,17 @@ int bnge_alloc_irqs(struct bnge_dev *bd)* We dont need to consider NQs as they have been calculated * and must be more than irqs_demand. */ + old_rx = bd->rx_nr_rings; rc =bnge_adjust_rings (bd, &bd->rx_nr_rings, &bd->tx_nr_rings, irqs_demand - aux_msix, min ==1 );if (rc) goto err_free_irqs; +/* The indirection table may point at rings that were just removed */ +if (bd->rx_nr_rings != old_rx) +bnge_set_dflt_rss_indir_tbl (bd); + tx_cp =bnge_num_tx_to_cp (bd, bd->tx_nr_rings); bd->nq_nr_rings = (min ==1 ) ? max_t(u16, tx_cp, bd->rx_nr_rings) :
drivers/net/ethernet/broadcom/bnge/bnge_vnic.h +1 -0
@@ -16,6 +16,7 @@ struct bnge_l2_filter;#define BNGE_MAX_RSS_TABLE_ENTRIES \ (BNGE_RSS_TABLE_ENTRIES * BNGE_RSS_TABLE_MAX_TBL) +#define BNGE_MAX_ETH_RSS_CTX 32#define BNGE_MAX_CTX_PER_VNIC 8#define BNGE_MAX_MC_ADDRS 16
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v6 04/10] bnge: add RXFH ethtool support
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
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] This patch adds bnge_set_rxfh_fields() (bnge_ethtool.c:856), which lets userspace change bd->rss_hash_cfg while the interface is…
--
bnge: add RXFH ethtool support
This commit adds ethtool RXFH operations to bnge for reading and programming the RSS hash key, indirection table and hash fields. The set operations are only allowed while the device is down. It also changes the default RSS key to the system-wide netdev_rss_key_fill() key.
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +0
-0
[ ... ]
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +4
-0+static int bnge_set_rxfh_fields (struct net_device *dev, +const struct ethtool_rxfh_fields *cmd, +struct netlink_ext_ack *extack) +{
[ ... ]
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c static int bnge_set_pauseparam(struct net_device *dev, · line 1004
Quoted 12 lines
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +12
-0+if (bd->rss_hash_cfg == rss_hash_cfg) +return 0 ; + +if (netif_running (dev)) { +NL_SET_ERR_MSG_MOD (extack, +"RSS configuration can only be changed while the interface is down" ); +return -EBUSY ; + } + + bd->rss_hash_cfg = rss_hash_cfg; + +return 0 ;
[Severity: Medium]
Could the hash fields set here be silently replaced at the next open on firmware that advertises BNGE_RSS_CAP_RSS_HASH_TYPE_DELTA?
The new value is only stored in bd->rss_hash_cfg and 0 is returned at once. Firmware first sees it on open, via bnge_open_core()->bnge_init_chip()->bnge_setup_vnic()-> bnge_hwrm_vnic_set_rss(). That path always sends the full state, with no INCLUDE/EXCLUDE flag:
drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c:__bnge_hwrm_vnic_set_rss() {
...
req->hash_type = cpu_to_le32(bd->rss_hash_cfg);
...
}Right after that, bnge_init_chip() reads the value back from firmware and writes it over the stored one:
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c:bnge_init_chip() {
...
if (bd->rss_cap & BNGE_RSS_CAP_RSS_HASH_TYPE_DELTA)
bnge_hwrm_update_rss_hash_cfg(bn);
...
}drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c:bnge_hwrm_update_rss_hash_cfg() {
...
if (!bnge_hwrm_req_send(bd, req))
bd->rss_hash_cfg =
le32_to_cpu(resp->hash_type) ?: bd->rss_hash_cfg;
...
}bnxt uses the same HWRM interface, and it switches to delta semantics whenever this capability is set:
bnxt_set_dflt_rss_hash_type() sets rss_hash_delta = rss_hash_cfg bnxt_set_rxfh_fields() sets rss_hash_delta = old ^ new __bnxt_hwrm_vnic_set_rss() sends HASH_TYPE_INCLUDE/EXCLUDE
If DELTA-mode firmware does not apply a plain full-state hash_type as requested, would the user's "ethtool -N <dev> rx-flow-hash ..." setting be dropped at the next "ip link set up"? In that case there is no error or extack warning, and bd->rss_hash_cfg quietly takes on firmware's value.
Before this patch the full-state send and the readback already existed, but nothing user-driven changed rss_hash_cfg. Later patches in the series don't seem to add INCLUDE/EXCLUDE handling or a check of the readback against the requested value.
Should __bnge_hwrm_vnic_set_rss() use INCLUDE/EXCLUDE when BNGE_RSS_CAP_RSS_HASH_TYPE_DELTA is set? Alternatively, should the readback be checked against the requested configuration?
Quoted 6 lines
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +6
-0+ +err_l3_shared: +NL_SET_ERR_MSG_MOD (extack, +"2-tuple hashing is shared by all flows of an IP version, use ip4/ip6 to disable it" ); +return -EINVAL ; +}
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261106093524.838341-1-vikas.gupta%40broadcom.com
Vikas Gupta
maintainerPATCH v6 5/10 bnge: add ethtool support to manage RSS contexts
In reply to Vikas GuptaIntroduce ethtool callbacks to manage RSS contexts.
Each context allocates a dedicated VNIC with its own RSS indirection table and hash key, configured with TPA settings matching those of the default VNIC.
The patch also changes existing behaviour:
- bnge_reserve_rings() no longer always resets bd->rss_indir_tbl when the RX ring count drops. A user-configured default table is kept, and ethtool_rxfh_indir_lost() is called when it no longer fits.
- bnge_fill_hw_rss_tbl() remaps out-of-range entries for every VNIC, including the default one.
- bnge_del_one_rss_ctx() resets fw_rss_cos_lb_ctx[] and decrements rsscos_nr_ctxs, and bnge_hwrm_realloc_rss_ctx_vnic() takes rss_lock.
- bnge_set_features() fails with -EBUSY when NTUPLE is cleared while RSS contexts exist.
--- .../net/ethernet/broadcom/bnge/bnge_ethtool.c | 173 ++++++++++++++++++ .../net/ethernet/broadcom/bnge/bnge_netdev.c | 9 + .../net/ethernet/broadcom/bnge/bnge_resc.c | 94 +++++++++- .../net/ethernet/broadcom/bnge/bnge_resc.h | 2 +- .../net/ethernet/broadcom/bnge/bnge_vnic.c | 124 ++++++++++++- .../net/ethernet/broadcom/bnge/bnge_vnic.h | 16 +- 6 files changed, 405 insertions(+), 13 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +173 -0
@@ -1073,6 +1073,176 @@ static u32 bnge_get_rx_ring_count(struct net_device *dev)return bd->rx_nr_rings; } +static int bnge_rxfh_context_check (struct bnge_net *bn, +const struct ethtool_rxfh_param *rxfh, +struct netlink_ext_ack *extack) +{ +if (rxfh->hfunc && rxfh->hfunc !=ETH_RSS_HASH_TOP ) { +NL_SET_ERR_MSG_MOD (extack,"RSS hash function not supported" ); +return -EOPNOTSUPP ; + } + +if (!(bn->priv_flags &BNGE_NET_EN_NTUPLE )) { +NL_SET_ERR_MSG_MOD (extack, +"Enable ntuple filtering before adding RSS contexts" ); +return -EOPNOTSUPP ; + } + +if (!netif_running (bn->netdev)) { +NL_SET_ERR_MSG_MOD (extack,"Unable to set RSS contexts when interface is down" ); +return -EAGAIN ; + } + +return 0 ; +} + +static int bnge_create_rxfh_context (struct net_device *dev, +struct ethtool_rxfh_context *ctx, +const struct ethtool_rxfh_param *rxfh, +struct netlink_ext_ack *extack) +{ +struct bnge_net *bn =netdev_priv (dev); +struct bnge_rss_ctx *rss_ctx; +struct bnge_vnic_info *vnic; +int rc; + + rc =bnge_rxfh_context_check (bn, rxfh, extack); +if (rc) +return rc; + +if (bn->num_rss_ctx >=BNGE_MAX_ETH_RSS_CTX ) { +NL_SET_ERR_MSG_FMT_MOD (extack,"Out of RSS contexts, maximum %u" , +BNGE_MAX_ETH_RSS_CTX ); +return -EINVAL ; + } + +if (!bnge_rss_ctx_capable (bn->bd)) { +NL_SET_ERR_MSG_MOD (extack,"Out of hardware resources" ); +return -ENOMEM ; + } + + rss_ctx =ethtool_rxfh_context_priv (ctx); + + bn->num_rss_ctx++; + + vnic = &rss_ctx->vnic; + +bnge_init_vnic_mem (vnic); + + vnic->rss_ctx = ctx; + vnic->flags |=BNGE_VNIC_RSSCTX_FLAG ; + rc =bnge_alloc_vnic_rss_table (bn, vnic); +if (rc) + goto err_del_rss_ctx; + +/* Populate defaults in the context */ +bnge_set_dflt_rss_indir_tbl (bn->bd, ctx); + ctx->hfunc =ETH_RSS_HASH_TOP ; +memcpy (vnic->rss_hash_key, bn->rss_hash_key,HW_HASH_KEY_SIZE ); +memcpy (ethtool_rxfh_context_key (ctx), + bn->rss_hash_key,HW_HASH_KEY_SIZE ); + + rc =bnge_hwrm_vnic_alloc (bn->bd, vnic, bn->bd->rx_nr_rings); +if (rc) { +NL_SET_ERR_MSG_MOD (extack,"Unable to allocate VNIC" ); + goto err_del_rss_ctx; + } + + rc =bnge_hwrm_vnic_set_tpa (bn->bd, vnic, + bn->priv_flags &BNGE_NET_EN_TPA ); +if (rc) { +NL_SET_ERR_MSG_MOD (extack, +"Unable to set TPA settings to vnic" ); + goto err_del_rss_ctx; + } +bnge_modify_rss (bn, ctx, rss_ctx, rxfh); + + rc =bnge_setup_vnic (bn, vnic); +if (rc) { +NL_SET_ERR_MSG_MOD (extack,"Unable to setup vnic" ); + goto err_del_rss_ctx; + } + + rss_ctx->index = rxfh->rss_context; +return 0 ; + +err_del_rss_ctx: +bnge_del_one_rss_ctx (bn, rss_ctx, true); +return rc; +} + +static int bnge_modify_rxfh_context (struct net_device *dev, +struct ethtool_rxfh_context *ctx, +const struct ethtool_rxfh_param *rxfh, +struct netlink_ext_ack *extack) +{ +struct bnge_net *bn =netdev_priv (dev); +u8 old_key[HW_HASH_KEY_SIZE ]; +struct bnge_rss_ctx *rss_ctx; +u32 *old_indir =NULL ; +u32 tbl_size; +int rc; + + rc =bnge_rxfh_context_check (bn, rxfh, extack); +if (rc) +return rc; + + rss_ctx =ethtool_rxfh_context_priv (ctx); + tbl_size =bnge_get_rxfh_indir_size (bn->bd); + +if (ctx->indir_size != tbl_size) { +NL_SET_ERR_MSG_MOD (extack, +"RSS context indirection table size mismatch" ); +return -EINVAL ; + } + +/* Snapshot the software state so it can be restored if the hardware +* update fails, keeping the reported config consistent with the +* hardware. +*/ +if (rxfh->key) +memcpy (old_key, rss_ctx->vnic.rss_hash_key,HW_HASH_KEY_SIZE ); +if (rxfh->indir) { + old_indir =kmemdup (ethtool_rxfh_context_indir (ctx), + tbl_size *sizeof (*old_indir),GFP_KERNEL ); +if (!old_indir) +return -ENOMEM ; + } + +bnge_modify_rss (bn, ctx, rss_ctx, rxfh); + + rc =bnge_hwrm_vnic_rss_cfg (bn, &rss_ctx->vnic); +if (rc) { +if (rxfh->key) +memcpy (rss_ctx->vnic.rss_hash_key, old_key, +HW_HASH_KEY_SIZE ); +if (rxfh->indir) +memcpy (ethtool_rxfh_context_indir (ctx), old_indir, + tbl_size *sizeof (*old_indir)); +/* Part of the update may have reached the device */ +if (bnge_hwrm_vnic_rss_cfg (bn, &rss_ctx->vnic)) +netdev_warn (dev,"Failed to restore RSS context %u\n" , + rss_ctx->index); + } + +kfree (old_indir); +return rc; +} + +static int bnge_remove_rxfh_context (struct net_device *dev, +struct ethtool_rxfh_context *ctx, +u32 rss_context, +struct netlink_ext_ack *extack) +{ +struct bnge_net *bn =netdev_priv (dev); +struct bnge_rss_ctx *rss_ctx; + + rss_ctx =ethtool_rxfh_context_priv (ctx); + +bnge_del_one_rss_ctx (bn, rss_ctx, true); +return 0 ; +} +static const struct ethtool_ops bnge_ethtool_ops = { .cap_link_lanes_supported =1 , .get_link_ksettings = bnge_get_link_ksettings,
@@ -1102,6 +1272,9 @@ static const struct ethtool_ops bnge_ethtool_ops = { .set_rxfh = bnge_set_rxfh, .get_rxfh_fields = bnge_get_rxfh_fields, .set_rxfh_fields = bnge_set_rxfh_fields, + .create_rxfh_context = bnge_create_rxfh_context, + .modify_rxfh_context = bnge_modify_rxfh_context, + .remove_rxfh_context = bnge_remove_rxfh_context, };void bnge_set_ethtool_ops (struct net_device *dev)
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +9 -0
@@ -2796,6 +2796,8 @@ static int bnge_open_core(struct bnge_net *bn)/* Poll link status and check for SFP+ module status */ bnge_get_port_module_status (bn); +bnge_hwrm_realloc_rss_ctx_vnic (bn); +return 0 ; err_free_irq:
@@ -3013,7 +3015,10 @@ static void bnge_close_core(struct bnge_net *bn)clear_bit (BNGE_STATE_OPEN , &bd->state);timer_delete_sync (&bn->timer); + +bnge_clear_rss_ctxs (bn);bnge_shutdown_nic (bn); +bnge_disable_napi (bn);/* Save ring stats before shutdown */
@@ -3145,6 +3150,10 @@ static int bnge_set_features(struct net_device *dev, netdev_features_t features)if (flags == bn->priv_flags)return 0 ; +if ((bn->priv_flags &BNGE_NET_EN_NTUPLE ) && + !(flags &BNGE_NET_EN_NTUPLE ) && bn->num_rss_ctx) +return -EBUSY ; + bn->priv_flags = flags;return 0 ;
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +89 -5
144 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_resc.h +1 -1
@@ -75,7 +75,7 @@ void bnge_aux_init_dflt_config(struct bnge_dev *bd);u32 bnge_get_rxfh_indir_size (struct bnge_dev *bd);int bnge_cal_nr_rss_ctxs (u16 rx_rings);bool bnge_aux_has_enough_resources (struct bnge_dev *bd); -bool bnge_arfs_capable (struct bnge_dev *bd,bool new_rss_ctx); +bool bnge_rss_ctx_capable (struct bnge_dev *bd);static inline u32 bnge_adjust_pow_two (u32 total_ent,u16 ent_per_blk)
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +119 -5
179 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_vnic.h +14 -2
@@ -22,6 +22,11 @@ struct bnge_l2_filter;#define BNGE_MAX_MC_ADDRS 16#define BNGE_MAX_UC_ADDRS 4 +#define BNGE_VNIC_ID_INVALID 0xffffffff + +struct ethtool_rxfh_context ; +struct ethtool_rxfh_param ; +enum {BNGE_VNIC_DEFAULT =0 ,BNGE_VNIC_NTUPLE =1 ,
@@ -32,7 +37,8 @@ enum {BNGE_VNIC_RSS_FLAG =BIT (0 ),BNGE_VNIC_MCAST_FLAG =BIT (1 ),BNGE_VNIC_UCAST_FLAG =BIT (2 ), -BNGE_VNIC_NTUPLE_FLAG =BIT (3 ) +BNGE_VNIC_NTUPLE_FLAG =BIT (3 ), +BNGE_VNIC_RSSCTX_FLAG =BIT (4 ) }; struct bnge_vnic_info {
@@ -57,6 +63,8 @@ struct bnge_vnic_info {u32 flags;u32 vnic_id; + +struct ethtool_rxfh_context *rss_ctx; };struct bnge_rss_ctx {
@@ -68,7 +76,8 @@ void bnge_fill_hw_rss_tbl(struct bnge_net *bn, struct bnge_vnic_info *vnic);int bnge_hwrm_vnic_rss_cfg (struct bnge_net *bn,struct bnge_vnic_info *vnic);int bnge_setup_vnic (struct bnge_net *bn,struct bnge_vnic_info *vnic); -void bnge_set_dflt_rss_indir_tbl (struct bnge_dev *bd); +void bnge_set_dflt_rss_indir_tbl (struct bnge_dev *bd, +struct ethtool_rxfh_context *ctx);int bnge_alloc_rfs_vnic (struct bnge_net *bn);int bnge_alloc_vnic_rss_table (struct bnge_net *bn,struct bnge_vnic_info *vnic);
@@ -78,6 +87,9 @@ void bnge_modify_rss(struct bnge_net *bn, struct ethtool_rxfh_context *ctx, const struct ethtool_rxfh_param *rxfh);void bnge_del_one_rss_ctx (struct bnge_net *bn,struct bnge_rss_ctx *rss_ctx,bool all); +void bnge_check_rss_ctxs_lost (struct bnge_dev *bd,u16 new_rx_rings); +void bnge_refill_dflt_rss_ctxs (struct bnge_dev *bd);void bnge_hwrm_realloc_rss_ctx_vnic (struct bnge_net *bn);void bnge_clear_rss_ctxs (struct bnge_net *bn); +void bnge_init_vnic_mem (struct bnge_vnic_info *vnic);#endif /* _BNGE_VNIC_H_ */
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v6 05/10] bnge: add ethtool support to manage RSS contexts
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · 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] When the RX ring count shrinks so that bnge_cal_nr_rss_ctxs() changes, bnge_check_rss_ctxs_lost()…
- [Medium] bnge_refill_dflt_rss_ctxs() calls ethtool_rxfh_ctxs_resize() when any context's indir_size differs from the new table size.
- [Medium] In bnge_reserve_rings() (drivers/net/ethernet/broadcom/bnge/bnge_resc.c) the work is split by…
- [Low] bnge_init_vnic_mem() sets vnic->vnic_id = BNGE_VNIC_ID_INVALID (0xffffffff, a u32) for every RSS-context VNIC.
--
bnge: add ethtool support to manage RSS contexts
This adds ethtool create/modify/remove callbacks for RSS contexts. Each context gets a dedicated VNIC with its own indirection table and hash key. It also changes how bnge_reserve_rings() handles the default and per-context indirection tables when the RX ring count changes.
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +0
-0
[ ... ]
Quoted 19 lines
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +9
-1@@ -331,9 +364,17 @@ int bnge_reserve_rings(struct bnge_dev *bd) hwr.nq = sh ?max_t (u16, tx_cp, rx_rings) : tx_cp + rx_rings; bd->tx_nr_rings = hwr.tx; -if (rx_rings != bd->rx_nr_rings) + rx_changed = rx_rings != bd->rx_nr_rings; +if (rx_changed) {dev_warn (bd->dev,"RX rings resv reduced to %d than earlier %d requested\n" , rx_rings, bd->rx_nr_rings); + indir_lost = bd->netdev && +netif_is_rxfh_configured (bd->netdev) && + (bnge_cal_nr_rss_ctxs (bd->rx_nr_rings) != +bnge_cal_nr_rss_ctxs (rx_rings) || +bnge_get_max_rss_ring (bd) >= rx_rings); +bnge_check_rss_ctxs_lost (bd, rx_rings); + } bd->rx_nr_rings = rx_rings; bd->nq_nr_rings = hwr.nq;
[ ... ]
Quoted 8 lines
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +2
-2@@ -345,8 +386,18 @@ int bnge_reserve_rings(struct bnge_dev *bd)if (!bnge_rings_ok (&hwr))return -ENOMEM ; -if (old_rx_rings != bd->hw_resc.resv_rx_rings) -bnge_set_dflt_rss_indir_tbl (bd); +if (old_rx_rings != bd->hw_resc.resv_rx_rings || rx_changed) { + if (!bd->netdev || indir_lost ||
drivers/net/ethernet/broadcom/bnge/bnge_resc.c int bnge_reserve_rings(struct bnge_dev *bd) · line 400
Quoted 10 lines
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +10
-0+ !netif_is_rxfh_configured(bd->netdev)) +bnge_set_dflt_rss_indir_tbl (bd,NULL ); +bnge_refill_dflt_rss_ctxs (bd); + } + +/* Notify only now, so the notification reports the new ring count +* and the reset indirection table. +*/ +if (indir_lost) +ethtool_rxfh_indir_lost (bd->netdev);
[Severity: Medium]
What happens when bnge_rings_ok() fails after rx_changed was true?
By that point bnge_check_rss_ctxs_lost() has already deleted user contexts and bd->rx_nr_rings has been lowered. The -ENOMEM return then skips the default table reset, bnge_refill_dflt_rss_ctxs() and ethtool_rxfh_indir_lost().
On a later open, the request uses the reduced bd->rx_nr_rings. If firmware grants that same count, old_rx_rings == resv_rx_rings and rx_changed is false, so this block never runs again.
Default contexts would keep their old ctx->indir_size and old entries. bnge_modify_rxfh_context() would then reject every change:
if (ctx->indir_size != tbl_size) {
NL_SET_ERR_MSG_MOD(extack,
"RSS context indirection table size mismatch");
return -EINVAL;
}ethtool would also report tables that don't match what bnge_fill_hw_rss_tbl() programs after clamping. For context 0, rss_indir_user_size stays set and the lost notification is never sent, even if the user table points at rings that no longer exist.
Skipping the reset of the main default table on this path predates this patch. What's new is that the context handling and the indir_lost notification now rely on the same ordering.
Could the repair steps run before the bnge_rings_ok() check, or could the state changes wait until after it?
[ ... ]
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +0
-0
[ ... ]
Quoted 1 line
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +0
-0@@ -201,6 +222,88 @@ void bnge_hwrm_realloc_rss_ctx_vnic(struct bnge_net *bn)
[ ... ]
Quoted 2 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +2
-0+void bnge_check_rss_ctxs_lost (struct bnge_dev *bd,u16 new_rx_rings) +{
[ ... ]
Quoted 15 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +15
-0+xa_for_each (&bd->netdev->ethtool->rss_ctx, context, ctx) { +struct bnge_rss_ctx *rss_ctx =ethtool_rxfh_context_priv (ctx); +u32 *indir =ethtool_rxfh_context_indir (ctx); +bool lost = false; +u32 i; + +if (!ctx->indir_user_size) +continue ; + +if (bnge_cal_nr_rss_ctxs (bd->rx_nr_rings) != +bnge_cal_nr_rss_ctxs (new_rx_rings)) { + lost = true; + }else { +for (i =0 ; i < ctx->indir_size; i++) { +if (indir[i] >= new_rx_rings) {
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c void bnge_hwrm_realloc_rss_ctx_vnic(struct bnge_net *bn) · line 263
Quoted 10 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +10
-0+ lost = true; +break ; + } + } + } + +if (lost) { +bnge_del_one_rss_ctx (bn, rss_ctx, true); +ethtool_rxfh_context_lost (bd->netdev, rss_ctx->index); + }
[Severity: Medium]
If the ring change moves bnge_cal_nr_rss_ctxs() (for example 100 -> 60 rings, so the table drops from 128 to 64 entries), does this delete every context that has a user-configured table, whatever the table contains?
The core can already fold such tables. From ethtool_rxfh_can_resize():
if (new_size < old_size) {
if (new_size < user_size)
return false;
if (old_size % new_size)
return false;
if (!ethtool_rxfh_is_periodic(tbl, old_size, new_size))
return false;
return true;
}The netlink path can also store an indir_user_size smaller than indir_size when a short table is replicated.
bnge_refill_dflt_rss_ctxs() does call ethtool_rxfh_ctxs_can_resize() and ethtool_rxfh_ctxs_resize(). It only does so after this loop has removed every user context, so user tables never get the chance to fold.
Could ethtool_rxfh_ctxs_can_resize() be tried before contexts are declared lost?
Context 0 is handled the same way in bnge_reserve_rings():
indir_lost = bd->netdev && netif_is_rxfh_configured(bd->netdev) && (bnge_cal_nr_rss_ctxs(bd->rx_nr_rings) != bnge_cal_nr_rss_ctxs(rx_rings) || bnge_get_max_rss_ring(bd) >= rx_rings);
Should ethtool_rxfh_indir_can_resize() and ethtool_rxfh_indir_resize() be tried there too, instead of treating any size change as lost?
In the final state of the series (after "bnge: add NTUPLE filter support in ethtool"), bnge_del_one_rss_ctx(..., true) also frees every BNGE_ACT_RSS_CTX ntuple rule that targets the context. Userspace only gets RSS_DELETE_NTF for the context and a "device error, RSS context %d lost" message. Nothing reports the removed rules, and the commit message doesn't mention this for non-default contexts.
The comment in bnge_refill_dflt_rss_ctxs() also seems inaccurate:
/* Contexts with a user table that no longer fits were already * dropped by bnge_check_rss_ctxs_lost(); only default ones resize. */
Tables that would fit after folding are dropped as well.
Quoted 6 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +6
-0+ } +mutex_unlock (&bd->netdev->ethtool->rss_lock); +} + +void bnge_refill_dflt_rss_ctxs (struct bnge_dev *bd) +{
[ ... ]
Quoted 7 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +7
-0+if (resize) { +if (ethtool_rxfh_ctxs_can_resize (bd->netdev, tbl_size)) { +dev_warn (bd->dev, +"RSS contexts cannot be resized to %u entries\n" , + tbl_size); +return ; + }
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c void bnge_hwrm_realloc_rss_ctx_vnic(struct bnge_net *bn) · line 307
Quoted 10 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +9
-0+ethtool_rxfh_ctxs_resize (bd->netdev, tbl_size); + } + +mutex_lock (&bd->netdev->ethtool->rss_lock); +xa_for_each (&bd->netdev->ethtool->rss_ctx, context, ctx) { +if (!ctx->indir_user_size) +bnge_set_dflt_rss_indir_tbl (bd, ctx); + } +mutex_unlock (&bd->netdev->ethtool->rss_lock); }
[Severity: Medium]
Can this send RSS_NTF for tables that are never programmed into hardware?
ethtool_rxfh_ctxs_resize() updates ctx->indir_size, leaves the data alone when shrinking, and then notifies right away:
xa_for_each(&dev->ethtool->rss_ctx, context, ctx) ethtool_rss_notify(dev, ETHTOOL_MSG_RSS_NTF, context);
The default contexts are rewritten by bnge_set_dflt_rss_indir_tbl(bd, ctx) only afterwards, and no further notification is sent.
For example, going from 128 to 60 RX rings, the notified 64-entry table is i % 128, i.e. 0..63. That includes rings 60..63, which don't exist. The table that bnge_hwrm_realloc_rss_ctx_vnic() later programs is i % 60.
bnge_reserve_rings() deliberately delays the context 0 notification until the final table is in place. Could the non-default contexts be notified after the refill in the same way?
[ ... ]
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c int bnge_alloc_vnic_rss_table(struct bnge_net *bn, · line 354
Quoted 11 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +7
-0@@ -242,3 +345,14 @@ int bnge_alloc_vnic_rss_table(struct bnge_net *bn, vnic->rss_hash_key_dma_addr = vnic->rss_table_dma_addr + size;return 0 ; } + +void bnge_init_vnic_mem (struct bnge_vnic_info *vnic) +{ +int i; + + vnic->fw_vnic_id =INVALID_HW_RING_ID ; + vnic->vnic_id =BNGE_VNIC_ID_INVALID ;
[Severity: Low]vnic_id is a u32, and this sets it to 0xffffffff for every RSS context VNIC. The error messages in bnge_hwrm_vnic_rss_cfg() and bnge_setup_vnic() print it with %d:
netdev_err(bn->netdev, "hwrm vnic %d set rss failure rc: %d\n", vnic->vnic_id, rc);
So any firmware failure on a context VNIC logs "vnic -1", which doesn't say which RSS context failed. Would it be better to print the RSS context index (or fw_vnic_id) for these VNICs?
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +4
-0+ +for (i =0 ; i <BNGE_MAX_CTX_PER_VNIC ; i++) + vnic->fw_rss_cos_lb_ctx[i] =INVALID_HW_RING_ID ; +}
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261106093524.838341-1-vikas.gupta%40broadcom.com
Vikas Gupta
maintainerPATCH v6 6/10 bnge: remove refcount from L2 filter
In reply to Vikas GuptaA reference count was previously used under the assumption that any context holding the last reference could delete the L2 filter.
However, going forward, the filter will only be removed by the same context that created it, making refcount unnecessary.
--- .../net/ethernet/broadcom/bnge/bnge_filter.c | 33 +++++++------------ .../net/ethernet/broadcom/bnge/bnge_filter.h | 2 -- 2 files changed, 11 insertions(+), 24 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +11 -22
@@ -4,6 +4,7 @@#include <linux/kernel.h> #include <linux/dma-mapping.h> #include <linux/jhash.h> +#include <net/netdev_lock.h> #include "bnge.h" #include "bnge_netdev.h"
@@ -13,8 +14,8 @@void bnge_del_l2_filter (struct bnge_net *bn,struct bnge_l2_filter *fltr) { -if (!refcount_dec_and_test (&fltr->refcnt)) -return ; +netdev_assert_locked_or_invisible (bn->netdev); +hlist_del_rcu (&fltr->base.hlist);kfree_rcu (fltr, base.rcu); }
@@ -31,18 +32,19 @@ static void bnge_init_l2_filter(struct bnge_net *bn, head = &bn->l2_fltr_hash_tbl[idx];hlist_add_head_rcu (&fltr->base.hlist, head); -refcount_set (&fltr->refcnt,1 ); } -static struct bnge_l2_filter *__bnge_lookup_l2_filter (struct bnge_net *bn, -struct bnge_l2_key *key, -u32 idx) +static struct bnge_l2_filter *bnge_lookup_l2_filter (struct bnge_net *bn, +struct bnge_l2_key *key, +u32 idx) {struct bnge_l2_filter *fltr;struct hlist_head *head; +netdev_assert_locked_or_invisible (bn->netdev); + head = &bn->l2_fltr_hash_tbl[idx]; -hlist_for_each_entry_rcu (fltr, head, base.hlist) { +hlist_for_each_entry (fltr, head, base.hlist) {struct bnge_l2_key *l2_key = &fltr->l2_key; if (ether_addr_equal(l2_key->dst_mac_addr, key->dst_mac_addr) &&
@@ -52,20 +54,6 @@ static struct bnge_l2_filter *__bnge_lookup_l2_filter(struct bnge_net *bn,return NULL ; } -static struct bnge_l2_filter *bnge_lookup_l2_filter (struct bnge_net *bn, -struct bnge_l2_key *key, -u32 idx) -{ -struct bnge_l2_filter *fltr; - -rcu_read_lock (); - fltr =__bnge_lookup_l2_filter (bn, key, idx); -if (fltr) -refcount_inc (&fltr->refcnt); -rcu_read_unlock (); -return fltr; -} -static struct bnge_l2_filter *bnge_alloc_l2_filter (struct bnge_net *bn,struct bnge_l2_key *key,gfp_t gfp)
@@ -75,9 +63,10 @@ static struct bnge_l2_filter *bnge_alloc_l2_filter(struct bnge_net *bn, idx =jhash2 (&key->filter_key,BNGE_L2_KEY_SIZE , bn->hash_seed) &BNGE_L2_FLTR_HASH_MASK ; + fltr =bnge_lookup_l2_filter (bn, key, idx);if (fltr) -return fltr; +return ERR_PTR (-EEXIST ); fltr =kzalloc_obj (*fltr, gfp);if (!fltr)
drivers/net/ethernet/broadcom/bnge/bnge_filter.h +0 -2
@@ -6,7 +6,6 @@#include <linux/types.h> #include <linux/if_ether.h> -#include <linux/refcount.h> #include <linux/jhash.h> struct bnge_net ;
@@ -49,7 +48,6 @@ struct bnge_l2_filter {/* base filter must be the first member */ struct bnge_filter_base base;struct bnge_l2_key l2_key; -refcount_t refcnt; };void bnge_del_l2_filter (struct bnge_net *bn,struct bnge_l2_filter *fltr);
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v6 06/10] bnge: remove refcount from L2 filter
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message says the patch only removes the L2 filter refcount, but the patch also changes what bnge_alloc_l2_filter()…
--
bnge: remove refcount from L2 filter
This patch removes the refcount from struct bnge_l2_filter. From now on, only the context that created a filter will delete it. The lookup helper is folded into one function that asserts the netdev instance lock is held, and bnge_alloc_l2_filter() now returns -EEXIST for a duplicate key.
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +0
-0
[ ... ]
drivers/net/ethernet/broadcom/bnge/bnge_filter.c static struct bnge_l2_filter *bnge_alloc_l2_filter(struct bnge_net *bn, · line 69
Quoted 9 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +2
-1@@ -75,9 +63,10 @@ static struct bnge_l2_filter *bnge_alloc_l2_filter(struct bnge_net *bn, idx =jhash2 (&key->filter_key,BNGE_L2_KEY_SIZE , bn->hash_seed) &BNGE_L2_FLTR_HASH_MASK ; + fltr =bnge_lookup_l2_filter (bn, key, idx);if (fltr) -return fltr; +return ERR_PTR (-EEXIST );
[Severity: Low]
This changes what bnge_alloc_l2_filter() does, and the commit message doesn't mention it. Could the changelog describe this?
Before this patch, a duplicate dst MAC/VLAN key returned the existing filter with an extra reference, so the caller shared it. Now a duplicate key is a hard error.
bnge_hwrm_set_vnic_filter() passes the error up to both of its callers. In bnge_cfg_rx_mode() it gets treated like any other HWRM failure:
rc = bnge_hwrm_set_vnic_filter(bn, 0, i, vnic->uc_list + off);
if (rc) {
...
netdev_err(dev, "HWRM vnic filter failure rc: %d\n",
rc);
vnic->uc_filter_count = i;
return rc;
}In bnge_init_chip() it would make open fail on the dev_addr filter.
As far as I can tell, nothing can request a duplicate key at this commit:
- the unicast address list is already de-duplicated
- dev_addr is skipped when uc_list is filled
- there is no ndo_set_mac_address
- bnge_hwrm_clear_vnic_filter() removes every tracked filter on close
So this shouldn't change behaviour yet. A later patch in the series also seems to depend on it on purpose, since it adds explicit -EEXIST handling in bnge_cfg_rx_mode() for addresses "Already delivered by a user L2 rule".
The commit message only describes removing the refcount, though, so could it also mention that duplicate keys now return -EEXIST instead of being shared?
Quoted 3 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +0
-0fltr =kzalloc_obj (*fltr, gfp);if (!fltr)
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261106093524.838341-1-vikas.gupta%40broadcom.com
Vikas Gupta
maintainerPATCH v6 7/10 bnge: add NTUPLE filter infrastructure
In reply to Vikas GuptaAdd the core NTUPLE filter data structures and firmware command wrappers needed for flow rule management.
This helps further patches implement user-created NTUPLE rules as well as rules via kernel flow steering.
bd->max_fltr is the fixed BNGE_MAX_NTUPLE_FLTRS (8192). It is no longer the sum of the firmware EM and WM flow counts and the L2 filter count. It sizes ntp_fltr_bmap, limits bnge_insert_ntp_filter() and, with the 128 L2 rules, is the rule count that ethtool reports.
--- drivers/net/ethernet/broadcom/bnge/bnge.h | 1 - .../net/ethernet/broadcom/bnge/bnge_filter.c | 498 +++++++++++++++++- .../net/ethernet/broadcom/bnge/bnge_filter.h | 69 ++- .../ethernet/broadcom/bnge/bnge_hwrm_lib.c | 157 +++++- .../ethernet/broadcom/bnge/bnge_hwrm_lib.h | 6 + .../net/ethernet/broadcom/bnge/bnge_netdev.c | 33 +- .../net/ethernet/broadcom/bnge/bnge_netdev.h | 17 + .../net/ethernet/broadcom/bnge/bnge_resc.c | 6 +- .../net/ethernet/broadcom/bnge/bnge_vnic.c | 20 + 9 files changed, 791 insertions(+), 16 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge.h +0 -1
@@ -159,7 +159,6 @@ struct bnge_dev {u16 tso_max_segs;int max_fltr; -#define BNGE_L2_FLTR_MAX_FLTR 1024u32 *rss_indir_tbl;u16 rss_indir_tbl_entries;
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +491 -7
551 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_filter.h +68 -1
98 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c +156 -1
173 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.h +6 -0
@@ -13,6 +13,8 @@ struct bnge_l2_filter;#define BNGE_VNIC_CFG_ROCE_DUAL_MODE \ VNIC_CFG_REQ_FLAGS_ROCE_DUAL_VNIC_MODE +struct bnge_ntuple_filter ; +int bnge_hwrm_ver_get (struct bnge_dev *bd);int bnge_hwrm_func_reset (struct bnge_dev *bd);int bnge_hwrm_fw_set_time (struct bnge_dev *bd);
@@ -67,4 +69,8 @@ int bnge_hwrm_shutdown_link(struct bnge_dev *bd);int bnge_hwrm_port_qstats (struct bnge_dev *bd,u8 flags);int bnge_hwrm_port_qstats_ext (struct bnge_dev *bd,u8 flags);int bnge_hwrm_func_qstat_ext (struct bnge_dev *bd,struct bnge_stats_mem *stats); +int bnge_hwrm_cfa_ntuple_filter_alloc (struct bnge_dev *bd, +struct bnge_ntuple_filter *fltr); +int bnge_hwrm_cfa_ntuple_filter_free (struct bnge_dev *bd, +struct bnge_ntuple_filter *fltr);#endif /* _BNGE_HWRM_LIB_H_ */
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +31 -2
@@ -1192,6 +1192,10 @@ static void bnge_free_core(struct bnge_net *bn)bnge_free_ring_stats (bn);bnge_free_ring_grps (bn);bnge_free_vnics (bn); + +/* Free non-user filters only */ +bnge_free_ntp_fltrs (bn, true); +kfree (bn->tx_ring_map); bn->tx_ring_map =NULL ;kfree (bn->tx_ring);
@@ -1280,6 +1284,10 @@ static int bnge_alloc_core(struct bnge_net *bn)bnge_init_stats (bn); + rc =bnge_fltrs_mem (bn); +if (rc) + goto err_free_ring_stats; + rc =bnge_alloc_vnics (bn);if (rc) goto err_free_ring_stats;
@@ -2056,7 +2064,7 @@ static int bnge_cfg_rx_mode(struct bnge_net *bn, struct netdev_hw_addr_list *uc,struct bnge_l2_filter *fltr = vnic->l2_filters[i];bnge_hwrm_l2_filter_free (bd, fltr); -bnge_del_l2_filter (bn, fltr); +bnge_del_l2_filter_rcu (bn, fltr); } vnic->uc_filter_count =1 ;
@@ -2274,7 +2282,7 @@ static void bnge_hwrm_clear_vnic_filter(struct bnge_net *bn)struct bnge_l2_filter *fltr = vnic->l2_filters[i];bnge_hwrm_l2_filter_free (bn->bd, fltr); -bnge_del_l2_filter (bn, fltr); +bnge_del_l2_filter_rcu (bn, fltr); } vnic->uc_filter_count =0 ;
@@ -3008,6 +3016,7 @@ static void bnge_save_ring_stats(struct bnge_net *bn)static void bnge_close_core (struct bnge_net *bn) { +struct bnge_filter_base *fltr;struct bnge_dev *bd = bn->bd;bnge_tx_disable (bn);
@@ -3021,6 +3030,20 @@ static void bnge_close_core(struct bnge_net *bn)bnge_disable_napi (bn); +/* Invalidate user L2 filters now that NAPI is disabled so that +* subsequent re-enabling during open cannot read a stale or torn +* filter_id before bnge_cfg_usr_fltrs() completes reallocation. +*/ +/* Only the driver's tracking is reset here. The user filters are +* programmed again by bnge_cfg_usr_fltrs() on the next open. +*/ +list_for_each_entry (fltr, &bn->usr_fltr_list, list_node) { +if (fltr->type ==BNGE_FLTR_TYPE_L2 ) +clear_bit (BNGE_FLTR_VALID , &fltr->state); +else + fltr->filter_id =BNGE_FLTR_ID_INVALID ; + } +/* Save ring stats before shutdown */ spin_lock_bh (&bn->stats_lock);bnge_save_ring_stats (bn);
@@ -3422,6 +3445,9 @@ int bnge_netdev_alloc(struct bnge_dev *bd, int max_irqs) goto err_free_workq;spin_lock_init (&bn->stats_lock); +spin_lock_init (&bn->ntp_fltr_lock); +INIT_LIST_HEAD (&bn->usr_fltr_list); + netdev->request_ops_lock = true; rc =register_netdev (netdev);if (rc) {
@@ -3450,6 +3476,9 @@ void bnge_netdev_free(struct bnge_dev *bd)unregister_netdev (netdev); +bnge_free_ntp_fltrs (bn, false); +bnge_free_l2_filters (bn); +timer_shutdown_sync (&bn->timer);cancel_work_sync (&bn->sp_task); bn->sp_event =0 ;
drivers/net/ethernet/broadcom/bnge/bnge_netdev.h +17 -0
@@ -284,6 +284,9 @@ enum bnge_sp_event { BNGE_PERIODIC_STATS_SP_EVENT, }; +#define BNGE_NTP_FLTR_HASH_SIZE 512 +#define BNGE_NTP_FLTR_HASH_MASK (BNGE_NTP_FLTR_HASH_SIZE - 1) +struct bnge_net {struct bnge_dev *bd;struct net_device *netdev;
@@ -372,6 +375,20 @@ struct bnge_net {bool pri2cos_valid;u16 num_rss_ctx; + +struct list_head usr_fltr_list; +unsigned long *ntp_fltr_bmap; +unsigned long *l2_fltr_bmap; +int ntp_fltr_count; +int l2_fltr_count; +int user_fltr_count; + +struct hlist_head ntp_fltr_hash_tbl[BNGE_NTP_FLTR_HASH_SIZE ]; +/* Protects the aRFS/ntuple hash table add and delete. usr_fltr_list, +* l2_fltr_hash_tbl and l2_fltr_bmap are covered by the netdev instance +* lock instead. +*/ +spinlock_t ntp_fltr_lock; };#define BNGE_DEFAULT_RX_RING_SIZE 511
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +2 -4
@@ -12,6 +12,7 @@#include "bnge_hwrm_lib.h" #include "bnge_resc.h" #include "bnge_vnic.h" +#include "bnge_filter.h" static u16 bnge_num_tx_to_cp (struct bnge_dev *bd,u16 tx) {
@@ -671,7 +672,6 @@ bool bnge_rss_ctx_capable(struct bnge_dev *bd)int bnge_net_init_dflt_config (struct bnge_dev *bd) { -struct bnge_hw_resc *hw_resc;int rc; rc =bnge_alloc_rss_indir_tbl (bd);
@@ -682,9 +682,7 @@ int bnge_net_init_dflt_config(struct bnge_dev *bd)if (rc) goto err_free_tbl; - hw_resc = &bd->hw_resc; - bd->max_fltr = hw_resc->max_rx_em_flows + hw_resc->max_rx_wm_flows + -BNGE_L2_FLTR_MAX_FLTR ; + bd->max_fltr =BNGE_MAX_NTUPLE_FLTRS ;return 0 ;
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +20 -0
@@ -178,8 +178,15 @@ void bnge_del_one_rss_ctx(struct bnge_net *bn, struct bnge_rss_ctx *rss_ctx, bool all) {struct bnge_vnic_info *vnic = &rss_ctx->vnic; +struct bnge_filter_base *usr_fltr, *tmp; +struct bnge_ntuple_filter *ntp_fltr;int i; +/* The kernel ethtool core prevents deleting a busy RSS context via +* ethtool_check_rss_ctx_busy(). +* When all == false (interface down), software filters are deliberately +* preserved so they can be restored when the interface is brought up. +*/ bnge_hwrm_vnic_free_one (bn->bd, &rss_ctx->vnic);for (i =0 ; i <BNGE_MAX_CTX_PER_VNIC ; i++) {if (vnic->fw_rss_cos_lb_ctx[i] !=INVALID_HW_RING_ID ) {
@@ -192,6 +199,19 @@ void bnge_del_one_rss_ctx(struct bnge_net *bn, struct bnge_rss_ctx *rss_ctx,if (!all)return ; +/* Delete all filters associated with this user RSS context */ +list_for_each_entry_safe (usr_fltr, tmp, &bn->usr_fltr_list, list_node) { +if (usr_fltr->type ==BNGE_FLTR_TYPE_NTUPLE && + (usr_fltr->flags &BNGE_ACT_RSS_CTX ) && + usr_fltr->fw_vnic_id == rss_ctx->index) { + ntp_fltr =container_of (usr_fltr, + struct bnge_ntuple_filter, + base); +bnge_hwrm_cfa_ntuple_filter_free (bn->bd, ntp_fltr); +bnge_del_ntp_filter_rcu (bn, ntp_fltr); + } + } +if (vnic->rss_table) dma_free_coherent(bn->bd->dev, vnic->rss_table_size, vnic->rss_table,
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v6 07/10] bnge: add NTUPLE filter infrastructure
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] bnge: code duplication between bnge_alloc_user_l2_filter() and bnge_alloc_l2_filter()
--
Quoted 334 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +323
-1@@ -72,10 +227,339 @@ static struct bnge_l2_filter *bnge_alloc_l2_filter(struct bnge_net *bn,if (!fltr)return ERR_PTR (-ENOMEM ); -bnge_init_l2_filter (bn, fltr, key, idx); + rc =bnge_init_l2_filter (bn, fltr, key, idx); +if (rc) { +kfree (fltr); + fltr =ERR_PTR (rc); + } +return fltr; } +struct bnge_l2_filter *bnge_alloc_user_l2_filter (struct bnge_net *bn, +struct bnge_l2_key *key, +u8 flags) +{ +struct bnge_l2_filter *fltr; +u32 idx; +int rc; + + idx =jhash2 (&key->filter_key,BNGE_L2_KEY_SIZE , bn->hash_seed) & +BNGE_L2_FLTR_HASH_MASK ; + fltr =bnge_lookup_l2_filter (bn, key, idx); +if (fltr) { + fltr =ERR_PTR (-EEXIST ); + goto l2_filter_exit; + } + fltr =kzalloc_obj (*fltr,GFP_KERNEL ); +if (!fltr) { + fltr =ERR_PTR (-ENOMEM ); + goto l2_filter_exit; + } + fltr->base.flags = flags; + rc =bnge_init_l2_filter (bn, fltr, key, idx); +if (rc) { +kfree (fltr); +return ERR_PTR (rc); + } + +l2_filter_exit: +return fltr; +} + +void bnge_free_l2_filters (struct bnge_net *bn) +{ +int i; + +netdev_assert_locked_or_invisible (bn->netdev); + +for (i =0 ; i <BNGE_L2_FLTR_HASH_SIZE ; i++) { +struct bnge_l2_filter *fltr; +struct hlist_head *head; +struct hlist_node *tmp; + + head = &bn->l2_fltr_hash_tbl[i]; +hlist_for_each_entry_safe (fltr, tmp, head, base.hlist) +bnge_del_l2_filter (bn, fltr); + } + +bitmap_free (bn->l2_fltr_bmap); + bn->l2_fltr_bmap =NULL ; + bn->l2_fltr_count =0 ; +} + +void bnge_free_ntp_fltrs (struct bnge_net *bn,bool skip_user) +{ +int i; + +netdev_assert_locked_or_invisible (bn->netdev); + +/* Under netdev instance lock and all our NAPIs have been disabled. +* It's safe to delete the hash table. +*/ +for (i =0 ; i <BNGE_NTP_FLTR_HASH_SIZE ; i++) { +struct bnge_ntuple_filter *fltr; +struct hlist_head *head; +struct hlist_node *tmp; + + head = &bn->ntp_fltr_hash_tbl[i]; +hlist_for_each_entry_safe (fltr, tmp, head, base.hlist) { +if (skip_user &&bnge_is_usr_fltr (&fltr->base)) +continue ; +bnge_del_ntp_filter (bn, fltr); + } + } + +if (skip_user) +return ; + +bitmap_free (bn->ntp_fltr_bmap); + bn->ntp_fltr_bmap =NULL ; + bn->ntp_fltr_count =0 ; +} + +static int bnge_alloc_l2_fltrs_mem (struct bnge_net *bn) +{ +int i, rc =0 ; + +if (bn->l2_fltr_bmap) +return 0 ; + +for (i =0 ; i <BNGE_L2_FLTR_HASH_SIZE ; i++) +INIT_HLIST_HEAD (&bn->l2_fltr_hash_tbl[i]); + + bn->l2_fltr_count =0 ; + bn->l2_fltr_bmap =bitmap_zalloc (BNGE_MAX_L2_FLTRS ,GFP_KERNEL ); + +if (!bn->l2_fltr_bmap) + rc = -ENOMEM ; + +return rc; +} + +static int bnge_alloc_ntp_fltrs_mem (struct bnge_net *bn) +{ +struct bnge_dev *bd = bn->bd; +int i, rc =0 ; + +if (!(bn->priv_flags &BNGE_NET_EN_NTUPLE ) || bn->ntp_fltr_bmap) +return 0 ; + +for (i =0 ; i <BNGE_NTP_FLTR_HASH_SIZE ; i++) +INIT_HLIST_HEAD (&bn->ntp_fltr_hash_tbl[i]); + + bn->ntp_fltr_count =0 ; + bn->ntp_fltr_bmap =bitmap_zalloc (bd->max_fltr,GFP_KERNEL ); + +if (!bn->ntp_fltr_bmap) + rc = -ENOMEM ; + +return rc; +} + +int bnge_fltrs_mem (struct bnge_net *bn) +{ +bool ntp_alloced = !bn->ntp_fltr_bmap; +int rc; + + rc =bnge_alloc_ntp_fltrs_mem (bn); +if (rc) +return rc; + + rc =bnge_alloc_l2_fltrs_mem (bn); +if (rc) + goto err_free_ntp_mem; + +return 0 ; + +err_free_ntp_mem: +if (ntp_alloced) { +bitmap_free (bn->ntp_fltr_bmap); + bn->ntp_fltr_bmap =NULL ; + } +return rc; +} + +#define BNGE_IPV4_4TUPLE (bd, fkeys) \ + (((fkeys)->basic.ip_proto == IPPROTO_TCP && \ + (bd)->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4) || \ + ((fkeys)->basic.ip_proto == IPPROTO_UDP && \ + (bd)->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4)) + +#define BNGE_IPV6_4TUPLE (bd, fkeys) \ + (((fkeys)->basic.ip_proto == IPPROTO_TCP && \ + (bd)->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6) || \ + ((fkeys)->basic.ip_proto == IPPROTO_UDP && \ + (bd)->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6)) + +static u32 bnge_get_rss_flow_tuple_len (struct bnge_dev *bd, +struct flow_keys *fkeys) +{ +if (fkeys->basic.n_proto ==htons (ETH_P_IP )) { +if (BNGE_IPV4_4TUPLE (bd, fkeys)) +return sizeof (fkeys->addrs.v4addrs) + +sizeof (fkeys->ports); + +if (bd->rss_hash_cfg &VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4 ) +return sizeof (fkeys->addrs.v4addrs); + } + +if (fkeys->basic.n_proto ==htons (ETH_P_IPV6 )) { +if (BNGE_IPV6_4TUPLE (bd, fkeys)) +return sizeof (fkeys->addrs.v6addrs) + +sizeof (fkeys->ports); + +if (bd->rss_hash_cfg &VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6 ) +return sizeof (fkeys->addrs.v6addrs); + } + +return 0 ; +} + +static u32 bnge_toeplitz (struct bnge_net *bn,struct flow_keys *fkeys, +const unsigned char *key) +{ +u64 prefix = bn->toeplitz_prefix, hash =0 ; +struct bnge_ipv4_tuple tuple4; +struct bnge_ipv6_tuple tuple6; +struct bnge_dev *bd = bn->bd; +u8 *four_tuple; +int i, j, len; + + len =bnge_get_rss_flow_tuple_len (bd, fkeys); +if (!len) +return 0 ; + +if (fkeys->basic.n_proto ==htons (ETH_P_IP )) { + tuple4.v4addrs = fkeys->addrs.v4addrs; + tuple4.ports = fkeys->ports; + four_tuple = (u8 *)&tuple4; + }else { + tuple6.v6addrs = fkeys->addrs.v6addrs; + tuple6.ports = fkeys->ports; + four_tuple = (u8 *)&tuple6; + } + +for (i =0 , j =8 ; i < len; i++, j++) { +u8 byte = four_tuple[i]; +int bit; + +for (bit =0 ; bit <8 ; bit++, prefix <<=1 , byte <<=1 ) { +if (byte &0x80 ) + hash ^= prefix; + } + prefix |= (j <HW_HASH_KEY_SIZE ) ? key[j] :0 ; + } + +/* The valid part of the hash is in the upper 32 bits. */ +return (hash >>32 ) &BNGE_NTP_FLTR_HASH_MASK ; +} + +u32 bnge_get_ntp_filter_idx (struct bnge_net *bn,struct flow_keys *fkeys, +const struct sk_buff *skb) +{ +struct bnge_vnic_info *vnic; + +if (skb) +return skb_get_hash_raw (skb) &BNGE_NTP_FLTR_HASH_MASK ; + + vnic = &bn->vnic_info[BNGE_VNIC_DEFAULT ]; +return bnge_toeplitz (bn, fkeys, (void *)vnic->rss_hash_key); +} + +static bool bnge_fltr_match (struct bnge_ntuple_filter *f1, +struct bnge_ntuple_filter *f2) +{ +struct bnge_flow_masks *masks1 = &f1->fmasks; +struct bnge_flow_masks *masks2 = &f2->fmasks; +struct flow_keys *keys1 = &f1->fkeys; +struct flow_keys *keys2 = &f2->fkeys; + +if (keys1->basic.n_proto != keys2->basic.n_proto || + keys1->basic.ip_proto != keys2->basic.ip_proto) +return false; + +if (keys1->basic.n_proto ==htons (ETH_P_IP )) { +if (keys1->addrs.v4addrs.src != keys2->addrs.v4addrs.src || + masks1->addrs.v4addrs.src != masks2->addrs.v4addrs.src || + keys1->addrs.v4addrs.dst != keys2->addrs.v4addrs.dst || + masks1->addrs.v4addrs.dst != masks2->addrs.v4addrs.dst) +return false; + }else { +if (!ipv6_addr_equal (&keys1->addrs.v6addrs.src, + &keys2->addrs.v6addrs.src) || + !ipv6_addr_equal (&masks1->addrs.v6addrs.src, + &masks2->addrs.v6addrs.src) || + !ipv6_addr_equal (&keys1->addrs.v6addrs.dst, + &keys2->addrs.v6addrs.dst) || + !ipv6_addr_equal (&masks1->addrs.v6addrs.dst, + &masks2->addrs.v6addrs.dst)) +return false; + } + +return keys1->ports.src == keys2->ports.src && + masks1->ports.src == masks2->ports.src && + keys1->ports.dst == keys2->ports.dst && + masks1->ports.dst == masks2->ports.dst && + keys1->control.flags == keys2->control.flags && + f1->l2_filter_id == f2->l2_filter_id; +} + +int bnge_insert_ntp_filter (struct bnge_net *bn,struct bnge_ntuple_filter *fltr, +u32 idx) +{ +struct bnge_ntuple_filter *f; +struct hlist_head *head; +int bit_id; + +spin_lock_bh (&bn->ntp_fltr_lock); + + head = &bn->ntp_fltr_hash_tbl[idx]; +hlist_for_each_entry (f, head, base.hlist) { +if (bnge_fltr_match (f, fltr)) { +spin_unlock_bh (&bn->ntp_fltr_lock); +return -EEXIST ; + } + } + + 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 ; + } + + fltr->base.sw_id = (u16 )bit_id; + fltr->base.filter_id =BNGE_FLTR_ID_INVALID ; + fltr->base.type =BNGE_FLTR_TYPE_NTUPLE ; + fltr->base.flags |=BNGE_ACT_RING_DST ; + + head = &bn->ntp_fltr_hash_tbl[idx]; +hlist_add_head_rcu (&fltr->base.hlist, head); + +bnge_insert_usr_fltr (bn, &fltr->base); + bn->ntp_fltr_count++; + +spin_unlock_bh (&bn->ntp_fltr_lock); + +return 0 ; +} + +struct bnge_ntuple_filter * +bnge_lookup_ntp_filter_from_idx (struct bnge_net *bn, +struct bnge_ntuple_filter *fltr,u32 idx) +{ +struct bnge_ntuple_filter *f; +struct hlist_head *head; + + head = &bn->ntp_fltr_hash_tbl[idx];
drivers/net/ethernet/broadcom/bnge/bnge_filter.c static struct bnge_l2_filter *bnge_alloc_l2_filter(struct bnge_net *bn, · line 565
Quoted 10 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +7
-0+hlist_for_each_entry_rcu (f, head, base.hlist) { +if (bnge_fltr_match (f, fltr)) +return f; + } +return NULL ; +} +int bnge_hwrm_set_vnic_filter (struct bnge_net *bn,u16 vnic_id,u16 idx,const u8 *mac_addr) {
[Severity: Low]bnge_alloc_user_l2_filter() is almost a copy of bnge_alloc_l2_filter() just above it. Both do the jhash2() bucket computation, the bnge_lookup_l2_filter() -EEXIST check, kzalloc_obj(), the bnge_init_l2_filter() call and kfree() on failure.
There are only two differences. The user variant sets fltr->base.flags before calling bnge_init_l2_filter(), and it hardcodes GFP_KERNEL. GFP_KERNEL is also what the only caller of bnge_alloc_l2_filter(), bnge_hwrm_set_vnic_filter(), passes, so the gfp argument buys nothing today.
bnge_init_l2_filter() already decides from base.flags, via bnge_insert_usr_fltr(), whether the filter goes on usr_fltr_list. Could bnge_alloc_l2_filter() take a u8 flags argument instead, so both paths share one helper? The gfp argument could be dropped unless you expect a non-GFP_KERNEL caller later.
With two copies, one is likely to be fixed or extended without the other, for example in the l2_fltr_bmap and sw_id handling that this patch just added to both.
There is no functional problem here; this is a maintainability nit.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261106093524.838341-1-vikas.gupta%40broadcom.com
Vikas Gupta
maintainerPATCH v6 8/10 bnge: add NTUPLE filter support in ethtool
In reply to Vikas GuptaIntroduce ethtool rx flow classification (rxnfc) operations for NTUPLE filter management.
User filters stay in software while the interface is down. bnge_cfg_usr_fltrs() programs them in firmware again on open, and bnge_clear_usr_fltrs() deletes them when NTUPLE is turned off.
bnge_hwrm_l2_filter_alloc() sets CFA_L2_FILTER_ALLOC_REQ_FLAGS_TRAFFIC_L2 only for user ETHER_FLOW ring rules. The default and unicast MAC filters keep the traffic type they had before this patch.
User ETHER_FLOW rules and the unicast address filters share the L2 filter table, so the result depends on the order in which a MAC is added. If the rule is added first, a later unicast address for the same MAC (a macvlan, for example) is left to the rule and is delivered only to the rule's ring, not through the default VNIC. If the unicast address is added first, adding a rule for the same MAC fails with -EEXIST.
When such a rule is deleted, bnge_del_usr_l2_filter() programs the unicast filter of the MAC that the rule had been serving. If the firmware refuses it, a warning is logged and the address is left without a filter until its address list changes.
The unicast address filters and the user ETHER_FLOW rules share the same L2 filters. After the old unicast filters are freed, bnge_cfg_rx_mode() counts the free L2 filters, and when the addresses do not fit it receives them in promiscuous mode, as it already does for more than BNGE_MAX_L2_FLTRS - 1 addresses.
BNGE_MAX_UC_ADDRS (4) is removed. The per-VNIC l2_filters[] array and the uc_list buffer are sized by BNGE_MAX_L2_FLTRS, the number of L2 filters of a function, because the unicast address filters and the user rules share that pool and the free-L2-filter check above is what limits them.
--- .../net/ethernet/broadcom/bnge/bnge_ethtool.c | 621 ++++++++++++++++++ .../net/ethernet/broadcom/bnge/bnge_filter.c | 127 ++++ .../net/ethernet/broadcom/bnge/bnge_filter.h | 4 + .../ethernet/broadcom/bnge/bnge_hwrm_lib.c | 9 +- .../net/ethernet/broadcom/bnge/bnge_netdev.c | 44 +- .../net/ethernet/broadcom/bnge/bnge_vnic.h | 5 +- 6 files changed, 803 insertions(+), 7 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +621 -0
@@ -7,6 +7,7 @@#include <net/devlink.h> #include <linux/ethtool.h> #include <linux/etherdevice.h> +#include <linux/if_vlan.h> #include <linux/ethtool_netlink.h> #include "bnge.h"
@@ -15,6 +16,7 @@#include "bnge_resc.h" #include "bnge_ethtool.h" #include "bnge_hwrm_lib.h" +#include "bnge_filter.h" static int bnge_nway_reset (struct net_device *dev) {
@@ -999,6 +1001,12 @@ static int bnge_set_rxfh_fields(struct net_device *dev,return -EBUSY ; } +if (bnge_has_usr_ntp_fltr (bn)) { +NL_SET_ERR_MSG_MOD (extack, +"Delete user ntuple rules before changing the RSS hash fields" ); +return -EBUSY ; + } + bd->rss_hash_cfg = rss_hash_cfg;return 0 ;
@@ -1060,6 +1068,12 @@ static int bnge_set_rxfh(struct net_device *dev,return -EBUSY ; } +if (rxfh->key &&bnge_has_usr_ntp_fltr (bn)) { +NL_SET_ERR_MSG_MOD (extack, +"Delete user ntuple rules before changing the RSS hash key" ); +return -EBUSY ; + } +bnge_modify_rss (bn,NULL ,NULL , rxfh);return 0 ;
@@ -1243,6 +1257,611 @@ static int bnge_remove_rxfh_context(struct net_device *dev,return 0 ; } +#define BNGE_IP_PROTO_FULL_MASK 0xFF +#define BNGE_IP_PROTO_WILDCARD 0x0 + +static int bnge_get_all_fltr_ids_rcu (struct bnge_net *bn, +struct hlist_head tbl[], +u32 tbl_size,u32 *ids,u32 start, +u32 id_cnt,u32 offset) +{ +u32 i, j = start; + +for (i =0 ; i < tbl_size; i++) { +struct bnge_filter_base *fltr; +struct hlist_head *head; + + head = &tbl[i]; +hlist_for_each_entry_rcu (fltr, head, hlist) { +if (!fltr->flags || +test_bit (BNGE_FLTR_FW_DELETED , &fltr->state)) +continue ; +if (j == id_cnt) +return -EMSGSIZE ; + ids[j++] = fltr->sw_id + offset; + } + } +return j; +} + +static struct bnge_filter_base *bnge_get_one_fltr_rcu (struct bnge_net *bn, +struct hlist_head tbl[], +u32 tbl_size,u32 id, +u32 offset) +{ +u32 i; + +for (i =0 ; i < tbl_size; i++) { +struct bnge_filter_base *fltr; +struct hlist_head *head; + + head = &tbl[i]; +hlist_for_each_entry_rcu (fltr, head, hlist) { +if (fltr->flags && fltr->sw_id + offset == id) +return fltr; + } + } +return NULL ; +} + +static int bnge_grxclsrlall (struct bnge_net *bn,struct ethtool_rxnfc *cmd, +u32 *rule_locs) +{ +int count; + + cmd->data =BNGE_MAX_L2_FLTRS + bn->bd->max_fltr; +rcu_read_lock (); + count =bnge_get_all_fltr_ids_rcu (bn, bn->l2_fltr_hash_tbl, +BNGE_L2_FLTR_HASH_SIZE , rule_locs,0 , + cmd->rule_cnt,0 ); +if (count >=0 ) + count =bnge_get_all_fltr_ids_rcu (bn, bn->ntp_fltr_hash_tbl, +BNGE_NTP_FLTR_HASH_SIZE , + rule_locs, count, + cmd->rule_cnt, +BNGE_MAX_L2_FLTRS ); +rcu_read_unlock (); +if (count <0 ) +return count; + + cmd->rule_cnt = count; +return 0 ; +} + +static int bnge_grxclsrule (struct bnge_net *bn,struct ethtool_rxnfc *cmd) +{ +struct ethtool_rx_flow_spec *fs = + (struct ethtool_rx_flow_spec *)&cmd->fs; +struct bnge_filter_base *fltr_base; +struct bnge_ntuple_filter *fltr; +struct bnge_flow_masks *fmasks; +struct bnge_dev *bd = bn->bd; +struct flow_keys *fkeys; +int rc = -EINVAL ; + +if (fs->location >=BNGE_MAX_L2_FLTRS + bd->max_fltr) +return rc; + +rcu_read_lock (); + fltr_base =bnge_get_one_fltr_rcu (bn, bn->l2_fltr_hash_tbl, +BNGE_L2_FLTR_HASH_SIZE , + fs->location,0 ); +if (fltr_base) { +struct ethhdr *h_ether = &fs->h_u.ether_spec; +struct ethhdr *m_ether = &fs->m_u.ether_spec; +struct bnge_l2_filter *l2_fltr; +struct bnge_l2_key *l2_key; + + l2_fltr = container_of(fltr_base, struct bnge_l2_filter, base); + l2_key = &l2_fltr->l2_key; + fs->flow_type =ETHER_FLOW ; +ether_addr_copy (h_ether->h_dest, l2_key->dst_mac_addr); +eth_broadcast_addr (m_ether->h_dest); +if (l2_key->vlan) { +struct ethtool_flow_ext *m_ext = &fs->m_ext; +struct ethtool_flow_ext *h_ext = &fs->h_ext; + + fs->flow_type |=FLOW_EXT ; + m_ext->vlan_tci =htons (0xfff ); + h_ext->vlan_tci =htons (l2_key->vlan); + } +if (fltr_base->flags &BNGE_ACT_RING_DST ) + fs->ring_cookie = fltr_base->rxq; +rcu_read_unlock (); +return 0 ; + } + fltr_base =bnge_get_one_fltr_rcu (bn, bn->ntp_fltr_hash_tbl, +BNGE_NTP_FLTR_HASH_SIZE , + fs->location,BNGE_MAX_L2_FLTRS ); +if (!fltr_base) { +rcu_read_unlock (); +return rc; + } + fltr = container_of(fltr_base, struct bnge_ntuple_filter, base); + + fkeys = &fltr->fkeys; + fmasks = &fltr->fmasks; +if (fkeys->basic.n_proto ==htons (ETH_P_IP )) { +if (fkeys->basic.ip_proto ==BNGE_IP_PROTO_WILDCARD ) { + fs->flow_type =IP_USER_FLOW ; + fs->h_u.usr_ip4_spec.ip_ver =ETH_RX_NFC_IP4 ; + fs->h_u.usr_ip4_spec.proto =BNGE_IP_PROTO_WILDCARD ; + fs->m_u.usr_ip4_spec.proto =0 ; + }else if (fkeys->basic.ip_proto ==IPPROTO_ICMP ) { + fs->flow_type =IP_USER_FLOW ; + fs->h_u.usr_ip4_spec.ip_ver =ETH_RX_NFC_IP4 ; + fs->h_u.usr_ip4_spec.proto =IPPROTO_ICMP ; + fs->m_u.usr_ip4_spec.proto =BNGE_IP_PROTO_FULL_MASK ; + }else if (fkeys->basic.ip_proto ==IPPROTO_TCP ) { + fs->flow_type =TCP_V4_FLOW ; + }else if (fkeys->basic.ip_proto ==IPPROTO_UDP ) { + fs->flow_type =UDP_V4_FLOW ; + }else { + goto fltr_err; + } + + fs->h_u.tcp_ip4_spec.ip4src = fkeys->addrs.v4addrs.src; + fs->m_u.tcp_ip4_spec.ip4src = fmasks->addrs.v4addrs.src; + fs->h_u.tcp_ip4_spec.ip4dst = fkeys->addrs.v4addrs.dst; + fs->m_u.tcp_ip4_spec.ip4dst = fmasks->addrs.v4addrs.dst; +if (fs->flow_type ==TCP_V4_FLOW || + fs->flow_type ==UDP_V4_FLOW ) { + fs->h_u.tcp_ip4_spec.psrc = fkeys->ports.src; + fs->m_u.tcp_ip4_spec.psrc = fmasks->ports.src; + fs->h_u.tcp_ip4_spec.pdst = fkeys->ports.dst; + fs->m_u.tcp_ip4_spec.pdst = fmasks->ports.dst; + } + }else { +if (fkeys->basic.ip_proto ==BNGE_IP_PROTO_WILDCARD ) { + fs->flow_type =IPV6_USER_FLOW ; + fs->h_u.usr_ip6_spec.l4_proto = +BNGE_IP_PROTO_WILDCARD ; + fs->m_u.usr_ip6_spec.l4_proto =0 ; + }else if (fkeys->basic.ip_proto ==IPPROTO_ICMPV6 ) { + fs->flow_type =IPV6_USER_FLOW ; + fs->h_u.usr_ip6_spec.l4_proto =IPPROTO_ICMPV6 ; + fs->m_u.usr_ip6_spec.l4_proto = +BNGE_IP_PROTO_FULL_MASK ; + }else if (fkeys->basic.ip_proto ==IPPROTO_TCP ) { + fs->flow_type =TCP_V6_FLOW ; + }else if (fkeys->basic.ip_proto ==IPPROTO_UDP ) { + fs->flow_type =UDP_V6_FLOW ; + }else { + goto fltr_err; + } + +memcpy (fs->h_u.tcp_ip6_spec.ip6src, + &fkeys->addrs.v6addrs.src, +sizeof (struct in6_addr )); +memcpy (fs->m_u.tcp_ip6_spec.ip6src, + &fmasks->addrs.v6addrs.src, +sizeof (struct in6_addr )); +memcpy (fs->h_u.tcp_ip6_spec.ip6dst, + &fkeys->addrs.v6addrs.dst, +sizeof (struct in6_addr )); +memcpy (fs->m_u.tcp_ip6_spec.ip6dst, + &fmasks->addrs.v6addrs.dst, +sizeof (struct in6_addr )); + +if (fs->flow_type ==TCP_V6_FLOW || + fs->flow_type ==UDP_V6_FLOW ) { + fs->h_u.tcp_ip6_spec.psrc = fkeys->ports.src; + fs->m_u.tcp_ip6_spec.psrc = fmasks->ports.src; + fs->h_u.tcp_ip6_spec.pdst = fkeys->ports.dst; + fs->m_u.tcp_ip6_spec.pdst = fmasks->ports.dst; + } + } + +if (fltr->base.flags &BNGE_ACT_DROP ) { + fs->ring_cookie =RX_CLS_FLOW_DISC ; + }else if (fltr->base.flags &BNGE_ACT_RSS_CTX ) { + fs->flow_type |=FLOW_RSS ; + fs->ring_cookie = fltr->base.rxq; + cmd->rss_context = fltr->base.fw_vnic_id; + }else { + fs->ring_cookie = fltr->base.rxq; + } + rc =0 ; + +fltr_err: +rcu_read_unlock (); + +return rc; +} + +static bool bnge_verify_ntuple_ip4_flow (struct ethtool_usrip4_spec *ip_spec, +struct ethtool_usrip4_spec *ip_mask) +{ +u8 mproto = ip_mask->proto; +u8 sproto = ip_spec->proto; + +if (ip_mask->l4_4_bytes || ip_mask->tos || + ip_spec->ip_ver !=ETH_RX_NFC_IP4 || + (mproto && (mproto !=BNGE_IP_PROTO_FULL_MASK || + sproto !=IPPROTO_ICMP ))) +return false; +return true; +} + +static bool bnge_verify_ntuple_ip6_flow (struct ethtool_usrip6_spec *ip_spec, +struct ethtool_usrip6_spec *ip_mask) +{ +u8 mproto = ip_mask->l4_proto; +u8 sproto = ip_spec->l4_proto; + +if (ip_mask->l4_4_bytes || ip_mask->tclass || + (mproto && (mproto !=BNGE_IP_PROTO_FULL_MASK || + sproto !=IPPROTO_ICMPV6 ))) +return false; +return true; +} + +static int bnge_add_ntuple_cls_rule (struct bnge_net *bn, +struct ethtool_rxnfc *cmd) +{ +struct ethtool_rx_flow_spec *fs = &cmd->fs; +struct bnge_ntuple_filter *new_fltr, *fltr; +u32 flow_type = fs->flow_type &0xff ; +struct bnge_l2_filter *l2_fltr; +struct bnge_flow_masks *fmasks; +struct flow_keys *fkeys; +u32 idx; +int rc; + +if (!bn->vnic_info) +return -EAGAIN ; + +if (fs->flow_type & (FLOW_MAC_EXT |FLOW_EXT )) +return -EOPNOTSUPP ; + +if (fs->ring_cookie !=RX_CLS_FLOW_DISC && +ethtool_get_flow_spec_ring_vf (fs->ring_cookie)) +return -EOPNOTSUPP ; + +if (flow_type ==IP_USER_FLOW ) { +if (!bnge_verify_ntuple_ip4_flow (&fs->h_u.usr_ip4_spec, + &fs->m_u.usr_ip4_spec)) +return -EOPNOTSUPP ; + } + +if (flow_type ==IPV6_USER_FLOW ) { +if (!bnge_verify_ntuple_ip6_flow (&fs->h_u.usr_ip6_spec, + &fs->m_u.usr_ip6_spec)) +return -EOPNOTSUPP ; + } + + new_fltr =kzalloc_obj (*new_fltr,GFP_KERNEL ); +if (!new_fltr) +return -ENOMEM ; + + l2_fltr = bn->vnic_info[BNGE_VNIC_DEFAULT ].l2_filters[0 ]; + new_fltr->l2_filter_id = l2_fltr->base.filter_id; + fmasks = &new_fltr->fmasks; + fkeys = &new_fltr->fkeys; + + rc = -EOPNOTSUPP ; +switch (flow_type) { +case IP_USER_FLOW : { +struct ethtool_usrip4_spec *ip_spec = &fs->h_u.usr_ip4_spec; +struct ethtool_usrip4_spec *ip_mask = &fs->m_u.usr_ip4_spec; + + fkeys->basic.ip_proto = ip_mask->proto ? ip_spec->proto + :BNGE_IP_PROTO_WILDCARD ; + fkeys->basic.n_proto =htons (ETH_P_IP ); + fkeys->addrs.v4addrs.src = ip_spec->ip4src; + fmasks->addrs.v4addrs.src = ip_mask->ip4src; + fkeys->addrs.v4addrs.dst = ip_spec->ip4dst; + fmasks->addrs.v4addrs.dst = ip_mask->ip4dst; +break ; + } +case TCP_V4_FLOW : +case UDP_V4_FLOW : { +struct ethtool_tcpip4_spec *ip_spec = &fs->h_u.tcp_ip4_spec; +struct ethtool_tcpip4_spec *ip_mask = &fs->m_u.tcp_ip4_spec; + +if (ip_mask->tos) + goto err_free_fltr; + + fkeys->basic.ip_proto =IPPROTO_TCP ; +if (flow_type ==UDP_V4_FLOW ) + fkeys->basic.ip_proto =IPPROTO_UDP ; + fkeys->basic.n_proto =htons (ETH_P_IP ); + fkeys->addrs.v4addrs.src = ip_spec->ip4src; + fmasks->addrs.v4addrs.src = ip_mask->ip4src; + fkeys->addrs.v4addrs.dst = ip_spec->ip4dst; + fmasks->addrs.v4addrs.dst = ip_mask->ip4dst; + fkeys->ports.src = ip_spec->psrc; + fmasks->ports.src = ip_mask->psrc; + fkeys->ports.dst = ip_spec->pdst; + fmasks->ports.dst = ip_mask->pdst; +break ; + } +case IPV6_USER_FLOW : { +struct ethtool_usrip6_spec *ip_spec = &fs->h_u.usr_ip6_spec; +struct ethtool_usrip6_spec *ip_mask = &fs->m_u.usr_ip6_spec; + + fkeys->basic.ip_proto = ip_mask->l4_proto ? ip_spec->l4_proto + :BNGE_IP_PROTO_WILDCARD ; + fkeys->basic.n_proto =htons (ETH_P_IPV6 ); + +memcpy (&fkeys->addrs.v6addrs.src, ip_spec->ip6src, +sizeof (struct in6_addr )); +memcpy (&fmasks->addrs.v6addrs.src, ip_mask->ip6src, +sizeof (struct in6_addr )); +memcpy (&fkeys->addrs.v6addrs.dst, ip_spec->ip6dst, +sizeof (struct in6_addr )); +memcpy (&fmasks->addrs.v6addrs.dst, ip_mask->ip6dst, +sizeof (struct in6_addr )); +break ; + } +case TCP_V6_FLOW : +case UDP_V6_FLOW : { +struct ethtool_tcpip6_spec *ip_spec = &fs->h_u.tcp_ip6_spec; +struct ethtool_tcpip6_spec *ip_mask = &fs->m_u.tcp_ip6_spec; + +if (ip_mask->tclass) + goto err_free_fltr; + + fkeys->basic.ip_proto =IPPROTO_TCP ; +if (flow_type ==UDP_V6_FLOW ) + fkeys->basic.ip_proto =IPPROTO_UDP ; + fkeys->basic.n_proto =htons (ETH_P_IPV6 ); + +memcpy (&fkeys->addrs.v6addrs.src, ip_spec->ip6src, +sizeof (struct in6_addr )); +memcpy (&fmasks->addrs.v6addrs.src, ip_mask->ip6src, +sizeof (struct in6_addr )); +memcpy (&fkeys->addrs.v6addrs.dst, ip_spec->ip6dst, +sizeof (struct in6_addr )); +memcpy (&fmasks->addrs.v6addrs.dst, ip_mask->ip6dst, +sizeof (struct in6_addr )); + + fkeys->ports.src = ip_spec->psrc; + fmasks->ports.src = ip_mask->psrc; + fkeys->ports.dst = ip_spec->pdst; + fmasks->ports.dst = ip_mask->pdst; +break ; + } +default : + rc = -EOPNOTSUPP ; + goto err_free_fltr; + } +/* A rule with no address or port mask is accepted only as an ICMP or +* ICMPv6 protocol match; the verify helpers above admit no other +* protocol-only rule. +*/ +if (!memcmp (&BNGE_FLOW_MASK_NONE , fmasks,sizeof (*fmasks)) && + !((flow_type ==IP_USER_FLOW || flow_type ==IPV6_USER_FLOW ) && + fkeys->basic.ip_proto)) + goto err_free_fltr; + + idx =bnge_get_ntp_filter_idx (bn, fkeys,NULL ); +rcu_read_lock (); + fltr =bnge_lookup_ntp_filter_from_idx (bn, new_fltr, idx); +if (fltr) { +rcu_read_unlock (); + rc = -EEXIST ; + goto err_free_fltr; + } +rcu_read_unlock (); + + new_fltr->base.flags =BNGE_ACT_NO_AGING ; +if (fs->flow_type &FLOW_RSS ) { +struct bnge_rss_ctx *rss_ctx; + + new_fltr->base.fw_vnic_id =0 ; + new_fltr->base.flags |=BNGE_ACT_RSS_CTX ; + rss_ctx =bnge_get_rss_ctx_from_index (bn, cmd->rss_context); +if (rss_ctx) { + new_fltr->base.fw_vnic_id = rss_ctx->index; + }else { + rc = -EINVAL ; + goto err_free_fltr; + } + } +if (fs->ring_cookie ==RX_CLS_FLOW_DISC ) + new_fltr->base.flags |=BNGE_ACT_DROP ; +else + new_fltr->base.rxq =ethtool_get_flow_spec_ring (fs->ring_cookie); +__set_bit (BNGE_FLTR_VALID , &new_fltr->base.state); + rc =bnge_insert_ntp_filter (bn, new_fltr, idx); +if (!rc) { + rc =bnge_hwrm_cfa_ntuple_filter_alloc (bn->bd, new_fltr); +if (rc) { +bnge_del_ntp_filter_rcu (bn, new_fltr); +return rc; + } + fs->location =BNGE_MAX_L2_FLTRS + new_fltr->base.sw_id; +return 0 ; + } + +err_free_fltr: +kfree (new_fltr); +return rc; +} + +static int bnge_add_l2_cls_rule (struct bnge_net *bn, +struct ethtool_rx_flow_spec *fs) +{ +u32 ring =ethtool_get_flow_spec_ring (fs->ring_cookie); +struct ethhdr *h_ether = &fs->h_u.ether_spec; +struct ethhdr *m_ether = &fs->m_u.ether_spec; +struct bnge_l2_filter *fltr; +struct bnge_l2_key key; +u16 vnic_id; +u8 flags; +int rc; + +if (ethtool_get_flow_spec_ring_vf (fs->ring_cookie)) +return -EOPNOTSUPP ; + +if (!is_broadcast_ether_addr (m_ether->h_dest)) +return -EINVAL ; + +if (!is_zero_ether_addr (m_ether->h_source) || m_ether->h_proto) +return -EOPNOTSUPP ; + +if (is_broadcast_ether_addr (h_ether->h_dest) || +is_multicast_ether_addr (h_ether->h_dest)) +return -EINVAL ; + +ether_addr_copy (key.dst_mac_addr, h_ether->h_dest); + key.vlan =0 ; +if (fs->flow_type &FLOW_EXT ) { +struct ethtool_flow_ext *m_ext = &fs->m_ext; +struct ethtool_flow_ext *h_ext = &fs->h_ext; + +if (m_ext->vlan_etype || m_ext->data[0 ] || m_ext->data[1 ]) +return -EOPNOTSUPP ; + + key.vlan =ntohs (h_ext->vlan_tci) &VLAN_VID_MASK ; +if (m_ext->vlan_tci !=htons (VLAN_VID_MASK ) || !key.vlan) +return -EINVAL ; + } + + flags =BNGE_ACT_RING_DST ; + vnic_id = bn->vnic_info[BNGE_VNIC_NTUPLE ].fw_vnic_id; + + fltr =bnge_alloc_user_l2_filter (bn, &key, flags); +if (IS_ERR (fltr)) +return PTR_ERR (fltr); + + fltr->base.fw_vnic_id = vnic_id; + fltr->base.rxq = ring; + rc =bnge_hwrm_l2_filter_alloc (bn->bd, fltr); +if (rc) +bnge_del_l2_filter_rcu (bn, fltr); +else + fs->location = fltr->base.sw_id; +return rc; +} + +static int bnge_srxclsrlins (struct bnge_net *bn,struct ethtool_rxnfc *cmd) +{ +struct ethtool_rx_flow_spec *fs = &cmd->fs; +struct bnge_dev *bd = bn->bd; +u32 ring, flow_type; +int rc; + +if (!netif_running (bn->netdev)) +return -EAGAIN ; +if (!(bn->priv_flags &BNGE_NET_EN_NTUPLE )) +return -EPERM ; +if (fs->location !=RX_CLS_LOC_ANY ) +return -EINVAL ; + + flow_type = fs->flow_type; + +if (flow_type &FLOW_MAC_EXT ) +return -EINVAL ; + + flow_type &= ~FLOW_EXT ; + +if (fs->ring_cookie ==RX_CLS_FLOW_DISC && flow_type !=ETHER_FLOW ) +return bnge_add_ntuple_cls_rule (bn, cmd); + + ring =ethtool_get_flow_spec_ring (fs->ring_cookie); +if (ring >= bd->rx_nr_rings) +return -EINVAL ; + +if (flow_type ==ETHER_FLOW ) + rc =bnge_add_l2_cls_rule (bn, fs); +else + rc =bnge_add_ntuple_cls_rule (bn, cmd); +return rc; +} + +static int bnge_srxclsrldel (struct bnge_net *bn,struct ethtool_rxnfc *cmd) +{ +struct ethtool_rx_flow_spec *fs = &cmd->fs; +struct bnge_filter_base *fltr_base; +struct bnge_ntuple_filter *fltr; +u32 id = fs->location; + +rcu_read_lock (); + fltr_base =bnge_get_one_fltr_rcu (bn, bn->l2_fltr_hash_tbl, +BNGE_L2_FLTR_HASH_SIZE , id,0 ); +if (fltr_base) { +struct bnge_l2_filter *l2_fltr; + + l2_fltr = container_of(fltr_base, struct bnge_l2_filter, base); +rcu_read_unlock (); +/* The firmware filter is gone once the interface is closed. */ +if (test_bit (BNGE_FLTR_VALID , &l2_fltr->base.state)) +bnge_hwrm_l2_filter_free (bn->bd, l2_fltr); +bnge_del_usr_l2_filter (bn, l2_fltr); +return 0 ; + } + fltr_base =bnge_get_one_fltr_rcu (bn, bn->ntp_fltr_hash_tbl, +BNGE_NTP_FLTR_HASH_SIZE , id, +BNGE_MAX_L2_FLTRS ); +if (!fltr_base) { +rcu_read_unlock (); +return -ENOENT ; + } + + fltr = container_of(fltr_base, struct bnge_ntuple_filter, base); +if (!(fltr->base.flags &BNGE_ACT_NO_AGING )) { +rcu_read_unlock (); +return -EINVAL ; + } +rcu_read_unlock (); +bnge_hwrm_cfa_ntuple_filter_free (bn->bd, fltr); +bnge_del_ntp_filter_rcu (bn, fltr); +return 0 ; +} + +static int bnge_get_rxnfc (struct net_device *dev,struct ethtool_rxnfc *cmd, +u32 *rule_locs) +{ +struct bnge_net *bn =netdev_priv (dev); +struct bnge_dev *bd = bn->bd; +int rc =0 ; + +switch (cmd->cmd) { +case ETHTOOL_GRXCLSRLCNT : + cmd->rule_cnt = bn->user_fltr_count; + cmd->data = (BNGE_MAX_L2_FLTRS + bd->max_fltr) | +RX_CLS_LOC_SPECIAL ; +break ; + +case ETHTOOL_GRXCLSRLALL : + rc =bnge_grxclsrlall (bn, cmd, (u32 *)rule_locs); +break ; + +case ETHTOOL_GRXCLSRULE : + rc =bnge_grxclsrule (bn, cmd); +break ; + +default : + rc = -EOPNOTSUPP ; +break ; + } + +return rc; +} + +static int bnge_set_rxnfc (struct net_device *dev,struct ethtool_rxnfc *cmd) +{ +struct bnge_net *bn =netdev_priv (dev); +int rc; + +switch (cmd->cmd) { +case ETHTOOL_SRXCLSRLINS : + rc =bnge_srxclsrlins (bn, cmd); +break ; + +case ETHTOOL_SRXCLSRLDEL : + rc =bnge_srxclsrldel (bn, cmd); +break ; + +default : + rc = -EOPNOTSUPP ; +break ; + } +return rc; +} +static const struct ethtool_ops bnge_ethtool_ops = { .cap_link_lanes_supported =1 , .get_link_ksettings = bnge_get_link_ksettings,
@@ -1275,6 +1894,8 @@ static const struct ethtool_ops bnge_ethtool_ops = { .create_rxfh_context = bnge_create_rxfh_context, .modify_rxfh_context = bnge_modify_rxfh_context, .remove_rxfh_context = bnge_remove_rxfh_context, + .get_rxnfc = bnge_get_rxnfc, + .set_rxnfc = bnge_set_rxnfc, };void bnge_set_ethtool_ops (struct net_device *dev)
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +127 -0
130 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_filter.h +4 -0
@@ -106,6 +106,7 @@ bnge_lookup_ntp_filter_from_idx(struct bnge_net *bn, struct bnge_ntuple_filter *fltr, u32 idx);void bnge_del_l2_filter (struct bnge_net *bn,struct bnge_l2_filter *fltr);void bnge_del_l2_filter_rcu (struct bnge_net *bn,struct bnge_l2_filter *fltr); +void bnge_del_usr_l2_filter (struct bnge_net *bn,struct bnge_l2_filter *fltr);__le64 bnge_lookup_l2_filter_rcu (struct bnge_net *bn,struct bnge_l2_key *key,u32 idx);
@@ -120,4 +121,7 @@ void bnge_del_ntp_filter(struct bnge_net *bn, struct bnge_ntuple_filter *nfltr);void bnge_del_ntp_filter_rcu (struct bnge_net *bn,struct bnge_ntuple_filter *fltr); +void bnge_cfg_usr_fltrs (struct bnge_net *bn); +void bnge_clear_usr_fltrs (struct bnge_net *bn); +bool bnge_has_usr_ntp_fltr (struct bnge_net *bn);#endif /* _BNGE_FILTER_H_ */
drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c +6 -3
@@ -906,15 +906,18 @@ int bnge_hwrm_l2_filter_alloc(struct bnge_dev *bd, struct bnge_l2_filter *fltr) {struct hwrm_cfa_l2_filter_alloc_output *resp;struct hwrm_cfa_l2_filter_alloc_input *req; +u32 flags;int rc; rc =bnge_hwrm_req_init (bd, req,HWRM_CFA_L2_FILTER_ALLOC );if (rc)return rc; - req->flags =cpu_to_le32 (CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX ); - - req->flags |=cpu_to_le32 (CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST ); + flags =CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX | +CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST ; +if (BNGE_L2_FLTR_IS_NTP_MAC (fltr)) + flags |=CFA_L2_FILTER_ALLOC_REQ_FLAGS_TRAFFIC_L2 ; + req->flags =cpu_to_le32 (flags); req->dst_id =cpu_to_le16 (fltr->base.fw_vnic_id); req->enables = cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR |
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +42 -2
100 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_vnic.h +3 -2
@@ -4,6 +4,8 @@#ifndef _BNGE_VNIC_H_#define _BNGE_VNIC_H_ +#include "bnge_filter.h" +struct bnge_net ;struct bnge_dev ;struct bnge_l2_filter ;
@@ -20,7 +22,6 @@ struct bnge_l2_filter;#define BNGE_MAX_CTX_PER_VNIC 8#define BNGE_MAX_MC_ADDRS 16 -#define BNGE_MAX_UC_ADDRS 4#define BNGE_VNIC_ID_INVALID 0xffffffff
@@ -46,7 +47,7 @@ struct bnge_vnic_info {u16 fw_rss_cos_lb_ctx[BNGE_MAX_CTX_PER_VNIC ];u16 mru;/* index 0 always dev_addr */ -struct bnge_l2_filter *l2_filters[BNGE_MAX_UC_ADDRS ]; +struct bnge_l2_filter *l2_filters[BNGE_MAX_L2_FLTRS ];u16 uc_filter_count;u8 *uc_list;dma_addr_t rss_table_dma_addr;
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v6 08/10] bnge: add NTUPLE filter support in ethtool
Thank 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: 4 · 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] bnge_cfg_rx_mode() (drivers/net/ethernet/broadcom/bnge/bnge_netdev.c) used to program at…
- [Medium] bnge_cfg_rx_mode() decides from the shared L2 pool whether to program unicast filters or fall back to promiscuous mode.
- [Medium] bnge_srxclsrldel() (drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c) ignores the return…
- [Medium] bnge_hwrm_l2_filter_alloc() now sets CFA_L2_FILTER_ALLOC_REQ_FLAGS_TRAFFIC_L2 for user ETHER_FLOW ring…
- [Low] Two existing ethtool operations gain new -EBUSY failures, and the commit message mentions neither.
--
bnge: add NTUPLE filter support in ethtool
This adds ethtool rxnfc operations to manage NTUPLE and ETHER_FLOW filters in bnge. User filters stay in software across down/up and are programmed again on open. The unicast address filters and the user ETHER_FLOW rules now share the L2 filter pool. BNGE_MAX_UC_ADDRS is removed, and l2_filters[] and uc_list are sized by BNGE_MAX_L2_FLTRS.
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +0
-0
[ ... ]
Quoted 14 lines
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +6
-0@@ -999,6 +1001,12 @@ static int bnge_set_rxfh_fields(struct net_device *dev,return -EBUSY ; } +if (bnge_has_usr_ntp_fltr (bn)) { +NL_SET_ERR_MSG_MOD (extack, +"Delete user ntuple rules before changing the RSS hash fields" ); +return -EBUSY ; + } + bd->rss_hash_cfg = rss_hash_cfg;return 0 ;
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c static int bnge_set_rxfh(struct net_device *dev, · line 1076
Quoted 9 lines
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +6
-0@@ -1060,6 +1068,12 @@ static int bnge_set_rxfh(struct net_device *dev,return -EBUSY ; } +if (rxfh->key &&bnge_has_usr_ntp_fltr (bn)) { +NL_SET_ERR_MSG_MOD (extack, +"Delete user ntuple rules before changing the RSS hash key" ); +return -EBUSY ; + } +
[Severity: Low]
This isn't a bug, but the commit message doesn't mention that two existing ethtool operations can now fail with -EBUSY.
While a user ntuple rule exists, bnge_set_rxfh_fields() rejects any hash field change and bnge_set_rxfh() rejects any RSS hash key change. The only explanation is the comment above bnge_has_usr_ntp_fltr(). It says rules are indexed by a hash of the RSS key and hash fields and are never rehashed.
So a user who adds rules with ethtool -N and later runs ethtool -X ... hkey or changes rx-flow-hash will now get EBUSY. Could the commit log mention this restriction?
[ ... ]
Quoted 1 line
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +0
-0@@ -1243,6 +1257,611 @@ static int bnge_remove_rxfh_context(struct net_device *dev,
[ ... ]
Quoted 21 lines
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +21
-0+static int bnge_srxclsrldel (struct bnge_net *bn,struct ethtool_rxnfc *cmd) +{ +struct ethtool_rx_flow_spec *fs = &cmd->fs; +struct bnge_filter_base *fltr_base; +struct bnge_ntuple_filter *fltr; +u32 id = fs->location; + +rcu_read_lock (); + fltr_base =bnge_get_one_fltr_rcu (bn, bn->l2_fltr_hash_tbl, +BNGE_L2_FLTR_HASH_SIZE , id,0 ); +if (fltr_base) { +struct bnge_l2_filter *l2_fltr; + + l2_fltr = container_of(fltr_base, struct bnge_l2_filter, base); +rcu_read_unlock (); +/* The firmware filter is gone once the interface is closed. */ +if (test_bit (BNGE_FLTR_VALID , &l2_fltr->base.state)) +bnge_hwrm_l2_filter_free (bn->bd, l2_fltr); +bnge_del_usr_l2_filter (bn, l2_fltr); +return 0 ; + }
[ ... ]
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c static int bnge_remove_rxfh_context(struct net_device *dev, · line 1812
Quoted 5 lines
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +5
-0+rcu_read_unlock (); +bnge_hwrm_cfa_ntuple_filter_free (bn->bd, fltr); +bnge_del_ntp_filter_rcu (bn, fltr); +return 0 ; +}
[Severity: Medium]
What happens in bnge_srxclsrldel() if bnge_hwrm_l2_filter_free() or bnge_hwrm_cfa_ntuple_filter_free() fails?
Both can fail through bnge_hwrm_req_send(). Examples are -EAGAIN for HWRM_ERR_CODE_BUSY or HOT_RESET_PROGRESS, -EIO for unknown errors, and timeouts. bnge_hwrm_cfa_ntuple_filter_free() resets filter_id only on success.
In both branches the return value is ignored. The software entry is freed by bnge_del_l2_filter_rcu() or bnge_del_ntp_filter_rcu(), and userspace gets 0. The rule disappears from ETHTOOL_GRXCLSRLALL, but the firmware filter would still be installed and still steering or dropping traffic.
The only record of that filter_id is gone, so nothing later can free it. bnge_hwrm_clear_usr_l2_fltrs() walks only usr_fltr_list, and bnge_hwrm_clear_vnic_filter() walks only vnic->l2_filters[].
For an ETHER_FLOW rule, bnge_del_usr_l2_filter() then programs a new unicast filter for the same MAC on the default VNIC right away. The orphaned RING_DST filter may still be in firmware at that point.
Should the error be returned and the software entry kept? bnxt_srxclsrldel() in bnxt_en has the same pattern.
Quoted 5 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +0
-0@@ -584,3 +584,130 @@ int bnge_hwrm_set_vnic_filter(struct bnge_net *bn, u16 vnic_id, u16 idx,
[ ... ]
Quoted 2 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +2
-0+void bnge_del_usr_l2_filter (struct bnge_net *bn,struct bnge_l2_filter *fltr) +{
[ ... ]
drivers/net/ethernet/broadcom/bnge/bnge_filter.c int bnge_hwrm_set_vnic_filter(struct bnge_net *bn, u16 vnic_id, u16 idx, · line 615
Quoted 11 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +11
-0+ vnic = &bn->vnic_info[BNGE_VNIC_DEFAULT ]; +for (i =1 , off =0 ; i < vnic->uc_filter_count; i++, off +=ETH_ALEN ) { +if (vnic->l2_filters[i] || + !ether_addr_equal (vnic->uc_list + off, mac)) +continue ; +if (bnge_hwrm_set_vnic_filter (bn,0 , i, vnic->uc_list + off)) +netdev_warn (bn->netdev, +"failed to restore uc filter %pM\n" , mac); +break ; + } +}
[Severity: Medium]
Is a failed restore in bnge_del_usr_l2_filter() ever retried?
If bnge_hwrm_set_vnic_filter() fails here, even with a transient -EAGAIN from HWRM_ERR_CODE_BUSY, the driver only prints a warning. vnic->l2_filters[i] stays NULL. bnge_uc_list_updated() compares only the address lists against vnic->uc_list:
if (!ether_addr_equal(ha->addr, vnic->uc_list + off))
return true;Later rx_mode events and the core retry timer therefore see uc_update == false and never reprogram that slot. Unicast traffic to the MAC (a macvlan, for example) would be dropped until the address list changes, unless the device is promiscuous for some other reason.
The commit message does say "the address is left without a filter until its address list changes". Elsewhere the driver retries on -EAGAIN, but a firmware-busy error here is never retried. The open path also reaches this
code: bnge_cfg_one_usr_fltr() calls it when a user L2 rule cannot be restored.
A second stale state is not mentioned. Suppose bnge_cfg_rx_mode() chose promiscuous mode earlier because uc_count > l2_free. Then uc_filter_count is 1 and this loop does nothing. Deleting user rules frees L2 slots, but nothing runs the promiscuous decision again. The VNIC stays promiscuous until some unrelated rx_mode event.
Would it make sense to schedule an rx_mode update after a user L2 rule is deleted?
[ ... ]
Quoted 5 lines
drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c +0
-0@@ -906,15 +906,18 @@ int bnge_hwrm_l2_filter_alloc(struct bnge_dev *bd, struct bnge_l2_filter *fltr)
[ ... ]
drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c int bnge_hwrm_l2_filter_alloc(struct bnge_dev *bd, struct bnge_l2_filter *fltr) · line 920
Quoted 8 lines
drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c +5
-3- req->flags =cpu_to_le32 (CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX ); - - req->flags |=cpu_to_le32 (CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST ); + flags =CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX | +CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST ; +if (BNGE_L2_FLTR_IS_NTP_MAC (fltr)) + flags |=CFA_L2_FILTER_ALLOC_REQ_FLAGS_TRAFFIC_L2 ; + req->flags =cpu_to_le32 (flags);
[Severity: Medium]
Can RoCE traffic for a MAC end up with no L2 filter at all?
User ETHER_FLOW ring rules now get TRAFFIC_L2. The unicast and default filters from bnge_hwrm_set_vnic_filter() keep traffic type 0 (CFA_L2_FILTER_ALLOC_REQ_FLAGS_TRAFFIC_NO_ROCE_L2).
When a user rule for MAC X already exists, bnge_alloc_l2_filter() returns -EEXIST from the software hash lookup. bnge_cfg_rx_mode() then installs no firmware filter for that address:
if (rc == -EEXIST) {
/* Already delivered by a user L2 rule */
vnic->l2_filters[i] = NULL;
continue;
}In the HWRM spec, type 0 exists for old drivers and covers both RoCE and L2 traffic, while TRAFFIC_L2 matches L2 traffic only. If that reading is right, no firmware L2 filter covers RoCE frames to MAC X while the rule exists. One example is a RoCE GID on a macvlan with the rule's MAC, with the bnge RoCE auxiliary device present.
The commit message only talks about L2 delivery to the rule's ring. bnxt_en uses the same HWRM interface and never sets TRAFFIC_L2 on its L2 filters, so this split looks new to bnge.
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +0
-0
[ ... ]
Quoted 16 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +6
-1@@ -2079,7 +2082,12 @@ static int bnge_cfg_rx_mode(struct bnge_net *bn, struct netdev_hw_addr_list *uc,netdev_hw_addr_list_for_each (ha, uc)if (!ether_addr_equal (ha->addr, dev->dev_addr)) uc_count++; -if (uc_count >BNGE_MAX_UC_ADDRS -1 ) { +/* The unicast addresses and the user ETHER_FLOW rules share the L2 +* filters. Receive the addresses that do not fit in promiscuous mode. +*/ + l2_free =BNGE_MAX_L2_FLTRS - +bitmap_weight (bn->l2_fltr_bmap,BNGE_MAX_L2_FLTRS ); +if (uc_count >BNGE_MAX_L2_FLTRS -1 || uc_count > l2_free) { vnic->rx_mask |=CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS ; }else {netdev_hw_addr_list_for_each (ha, uc) {@@ -2095,6 +2103,11 @@ static int bnge_cfg_rx_mode(struct bnge_net *bn, struct netdev_hw_addr_list *uc,
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c static int bnge_cfg_rx_mode(struct bnge_net *bn, struct netdev_hw_addr_list *uc, · line 2113
Quoted 10 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +5
-0for (i =1 , off =0 ; i < vnic->uc_filter_count; i++, off +=ETH_ALEN ) { rc =bnge_hwrm_set_vnic_filter (bn,0 , i, vnic->uc_list + off); +if (rc == -EEXIST ) { +/* Already delivered by a user L2 rule */ + vnic->l2_filters[i] =NULL ; +continue ; + }if (rc) {if (rc == -EAGAIN )netdev_warn (dev,"FW busy while setting vnic filter, will retry\n" );
[Severity: Medium]
What happens in bnge_cfg_rx_mode() when firmware runs out of L2 filters?
Before this patch, at most 3 secondary unicast addresses were programmed (BNGE_MAX_UC_ADDRS - 1). Anything beyond that fell back to promiscuous mode. Now up to 127 can be programmed, but both bounds come only from the software l2_fltr_bmap. bnge_hwrm_func_resc_qcaps() reads hw_resc->max_l2_ctxs, but nothing uses it, and the CFA L2 table is shared across functions.
Suppose firmware rejects a filter partway through this loop with an error other than -EEXIST, for example HWRM_ERR_CODE_RESOURCE_ALLOC_ERROR, which maps to -ENOSPC. The function then returns before skip_uc:
vnic->uc_filter_count = i;
return rc;PROMISCUOUS is never set and the rx mask is not reprogrammed. The core netif_rx_mode retry gives up after 4 attempts. After that, the remaining addresses have neither a filter nor promiscuous mode, so their traffic would be dropped silently. With the old 3-address cap this path was practically unreachable.
Should a failure here fall back to promiscuous mode, or should the limit take firmware capacity into account?
The commit message also says the driver uses promiscuous mode "as it already does for more than BNGE_MAX_L2_FLTRS - 1 addresses". The old threshold was actually BNGE_MAX_UC_ADDRS - 1, which is 3.
This change has two side effects. Every unicast list change now frees and re-allocates up to 127 firmware filters through HWRM instead of 3. Also, every struct bnge_vnic_info grows from 4 to 128 l2_filters[] pointers, including the copy embedded in each struct bnge_rss_ctx, even though only the default VNIC uses the array.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261106093524.838341-1-vikas.gupta%40broadcom.com
Vikas Gupta
maintainerPATCH v6 9/10 bnge: add aRFS flow steering ndo support
In reply to Vikas GuptaIntroduce the ndo_rx_flow_steer callback (bnge_rx_flow_steer) to support aRFS.
This callback creates an NTUPLE filter that steers matching packets to the appropriate RX queue. The implementation dissects flow keys from the SKB, creates an NTUPLE filter with the associated L2 filter, inserts it into the NTUPLE hash table, and schedules the sp_task workqueue via BNGE_RX_NTP_FLTR_SP_EVENT to program the filter in the firmware.
Add bnge_cfg_ntp_filters() called from the periodic timer via sp_task to handle deferred filter programming and expiration via rps_may_expire_flow().
bnge_timer() queues aRFS aging only while NTUPLE is enabled. NTUPLE can only be turned off with the interface closed, and bnge_close_core() then deletes the timer and purges dynamic aRFS filters.
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.
--- .../net/ethernet/broadcom/bnge/bnge_ethtool.c | 5 +- .../net/ethernet/broadcom/bnge/bnge_filter.c | 85 ++++++++++- .../net/ethernet/broadcom/bnge/bnge_filter.h | 5 +- .../ethernet/broadcom/bnge/bnge_hwrm_lib.c | 2 +- .../net/ethernet/broadcom/bnge/bnge_netdev.c | 138 ++++++++++++++++++ .../net/ethernet/broadcom/bnge/bnge_netdev.h | 1 + 6 files changed, 228 insertions(+), 8 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +3 -2
@@ -1273,7 +1273,7 @@ static int bnge_get_all_fltr_ids_rcu(struct bnge_net *bn, head = &tbl[i];hlist_for_each_entry_rcu (fltr, head, hlist) { -if (!fltr->flags || +if (!bnge_is_usr_fltr (fltr) ||test_bit (BNGE_FLTR_FW_DELETED , &fltr->state))continue ;if (j == id_cnt)
@@ -1297,7 +1297,8 @@ static struct bnge_filter_base *bnge_get_one_fltr_rcu(struct bnge_net *bn, head = &tbl[i];hlist_for_each_entry_rcu (fltr, head, hlist) { -if (fltr->flags && fltr->sw_id + offset == id) +if (bnge_is_usr_fltr (fltr) && + fltr->sw_id + offset == id)return fltr; } }
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +81 -4
112 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_filter.h +4 -1
@@ -19,7 +19,8 @@ enum {enum {BNGE_FLTR_VALID , -BNGE_FLTR_FW_DELETED +BNGE_FLTR_FW_DELETED , +BNGE_FLTR_RXQ_UPDATE };enum {
@@ -97,6 +98,7 @@ struct bnge_ntuple_filter {#define BNGE_FLTR_ID_INVALID cpu_to_le64(0xffffffffffffffffULL)void bnge_free_ntp_fltrs (struct bnge_net *bn,bool skip_user_filters); +bool bnge_is_usr_fltr (struct bnge_filter_base *fltr);u32 bnge_get_ntp_filter_idx (struct bnge_net *bn,struct flow_keys *fkeys,const struct sk_buff *skb); int bnge_insert_ntp_filter(struct bnge_net *bn, struct bnge_ntuple_filter *fltr,
@@ -124,4 +126,5 @@ void bnge_del_ntp_filter_rcu(struct bnge_net *bn,void bnge_cfg_usr_fltrs (struct bnge_net *bn);void bnge_clear_usr_fltrs (struct bnge_net *bn);bool bnge_has_usr_ntp_fltr (struct bnge_net *bn); +void bnge_cfg_ntp_filters (struct bnge_net *bn);#endif /* _BNGE_FILTER_H_ */
drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c +1 -1
@@ -1007,8 +1007,8 @@ bnge_cfg_rfs_ring_tbl_idx(struct bnge_dev *bd, struct bnge_ntuple_filter *fltr) {struct bnge_net *bn =netdev_priv (bd->netdev); +u32 rxq =READ_ONCE (fltr->base.rxq);struct bnge_vnic_info *def_vnic; -u32 rxq = fltr->base.rxq;u32 enables;if (fltr->base.flags &BNGE_ACT_RSS_CTX ) {
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +138 -0
162 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_netdev.h +1 -0
@@ -282,6 +282,7 @@ enum bnge_sp_event {BNGE_LINK_CFG_CHANGE_SP_EVENT ,BNGE_UPDATE_PHY_SP_EVENT ,BNGE_PERIODIC_STATS_SP_EVENT , + BNGE_RX_NTP_FLTR_SP_EVENT, };#define BNGE_NTP_FLTR_HASH_SIZE 512
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v6 09/10] bnge: add aRFS flow steering ndo support
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: 3 · Low: 0
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 aRFS expiry loop in bnge_cfg_ntp_filters() (drivers/net/ethernet/broadcom/bnge/bnge_filter.c) ignores the return…
- [Medium] Check-then-act race between the aRFS expiry loop in bnge_cfg_ntp_filters() and the retarget path in bnge_rx_flow_steer().
- [Medium] bnge: race on ntp_fltr->l2_filter_id in bnge_open_core() inserts duplicate filter
--
bnge: add aRFS flow steering ndo support
This commit adds an ndo_rx_flow_steer callback to the bnge driver. The callback creates NTUPLE filters for aRFS and inserts them into the NTUPLE hash table. A new function, bnge_cfg_ntp_filters(), runs from sp_task to program pending filters in firmware, reprogram retargeted filters and expire idle filters via rps_may_expire_flow().
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +0
-0
[ ... ]
Quoted 1 line
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +0
-0@@ -711,3 +711,80 @@ void bnge_clear_usr_fltrs(struct bnge_net *bn)
[ ... ]
drivers/net/ethernet/broadcom/bnge/bnge_filter.c void bnge_clear_usr_fltrs(struct bnge_net *bn) · line 787
Quoted 7 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +7
-0+list_for_each_entry_safe (fltr, tmp, &expire_list, base.list_node) { +list_del_init (&fltr->base.list_node); +/* Retargeted by bnge_rx_flow_steer() after the scan */ +if (test_bit (BNGE_FLTR_RXQ_UPDATE , &fltr->base.state)) +continue ; +bnge_hwrm_cfa_ntuple_filter_free (bn->bd, fltr); +bnge_del_ntp_filter_rcu (bn, fltr);
[Severity: Medium]
Should the return value of bnge_hwrm_cfa_ntuple_filter_free() be ignored here?
The free can fail in two ways. bnge_hwrm_req_init() can fail to allocate the request, or bnge_hwrm_req_send() can hit a firmware error or timeout. In both cases filter_id stays valid:
bnge_hwrm_cfa_ntuple_filter_free() {
...
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 unlinks and frees the software filter, which is the only object holding that firmware id. It also clears the filter's sw_id bit in ntp_fltr_bmap.
Does this leak the firmware n-tuple rule? It would keep steering the flow to the old RX queue, and the driver could not free it until the interface is closed.
The update_list loop earlier in bnge_cfg_ntp_filters() handles the same failure by keeping the software filter:
if (bnge_hwrm_cfa_ntuple_filter_free(bn->bd, fltr)) continue;
Should the expire loop do the same?
This path becomes reachable once the follow-up patch "bnge: add cpu_rmap support for IRQ affinity" sets dev->rx_cpu_rmap.
[Severity: Medium]
Can a concurrent retarget from bnge_rx_flow_steer() still get lost here?
The test_bit() check runs without ntp_fltr_lock. The filter also stays linked in ntp_fltr_hash_tbl until bnge_del_ntp_filter_rcu() runs, which happens after the sleeping HWRM free. One possible sequence:
sp_task, in bnge_cfg_ntp_filters():
rps_may_expire_flow() returns true, so the filter goes on expire_list test_bit(BNGE_FLTR_RXQ_UPDATE) returns false bnge_hwrm_cfa_ntuple_filter_free() sleeps
softirq on another CPU, in set_rps_cpu()->bnge_rx_flow_steer():
bnge_lookup_ntp_filter_from_idx() finds the still-linked filter WRITE_ONCE(fltr->base.rxq, rxq_index); set_bit(BNGE_FLTR_RXQ_UPDATE, &fltr->base.state);
rc = fltr->base.sw_id is returned to set_rps_cpu()
sp_task:
bnge_del_ntp_filter_rcu() unlinks the filter and clears its sw_id in ntp_fltr_bmap
set_rps_cpu() then stores the returned sw_id in rflow->filter. While the flow stays active on the same CPU, set_rps_cpu() then takes this path:
if (READ_ONCE(tmp_rflow->filter) != RPS_NO_FILTER) {
if (rps_flow_is_active(tmp_rflow, ...)) {
if (hash != READ_ONCE(tmp_rflow->hash) ||
next_cpu == tmp_cpu)
goto out;So ndo_rx_flow_steer() is not called again.
Doesn't that leave the flow without hardware steering until it goes idle or moves to another CPU? The RPS flow table would also hold a sw_id that has been released and can be reused.
The comment "Retargeted by bnge_rx_flow_steer() after the scan" suggests this check is meant to cover that case.
The scan loop also reads rxq and flow_id as two separate lockless loads:
rxq = READ_ONCE(fltr->base.rxq); flow_id = READ_ONCE(fltr->flow_id);
Could these see a torn pair while a retarget is in progress, and put a filter that was just retargeted on expire_list?
[ ... ]
Quoted 126 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +119
-0@@ -3222,6 +3231,132 @@ static int bnge_set_features(struct net_device *dev, netdev_features_t features)return 0 ; } +#ifdef CONFIG_RFS_ACCEL +static __le64 bnge_lookup_l2_filter_from_key (struct bnge_net *bn, +struct bnge_l2_key *key) +{ +u32 idx; + + idx =jhash2 (&key->filter_key,BNGE_L2_KEY_SIZE , bn->hash_seed) & +BNGE_L2_FLTR_HASH_MASK ; +return bnge_lookup_l2_filter_rcu (bn, key, idx); +} + +static int bnge_rx_flow_steer (struct net_device *dev,const struct sk_buff *skb, +u16 rxq_index,u32 flow_id) +{ +struct ethhdr *eth = (struct ethhdr *)skb_mac_header (skb); +struct bnge_ntuple_filter *fltr, *new_fltr; +struct bnge_net *bn =netdev_priv (dev); +struct flow_keys *fkeys; +__le64 filter_id; +u32 flags, idx; +int rc =0 ; + +/* Hold rcu_read_lock() across the L2 filter lookup and check +* BNGE_STATE_OPEN inside it. bnge_close_core() clears the +* flag before bnge_shutdown_nic() frees the L2 filters via +* kfree_rcu(), so if we observe the device open here the +* filter cannot be freed under us for the duration of +* this critical section. +*/ +rcu_read_lock (); +if (!test_bit (BNGE_STATE_OPEN , &bn->bd->state)) { +rcu_read_unlock (); +return -EINVAL ; + } + +if (ether_addr_equal (dev->dev_addr, eth->h_dest)) { +struct bnge_vnic_info *vnic = &bn->vnic_info[BNGE_VNIC_DEFAULT ]; +struct bnge_l2_filter *l2_filter; + +if (!vnic->uc_filter_count) { +rcu_read_unlock (); +return -EINVAL ; + } + l2_filter = vnic->l2_filters[0 ]; + filter_id = l2_filter->base.filter_id; + }else { +struct bnge_l2_key key; + +ether_addr_copy (key.dst_mac_addr, eth->h_dest); + key.vlan =0 ; + + filter_id =bnge_lookup_l2_filter_from_key (bn, &key); +if (filter_id ==BNGE_FLTR_ID_INVALID ) { +rcu_read_unlock (); +return -EINVAL ; + } + } +rcu_read_unlock (); + + new_fltr =kzalloc_obj (*new_fltr,GFP_ATOMIC ); +if (!new_fltr) +return -ENOMEM ; + + fkeys = &new_fltr->fkeys; +if (!skb_flow_dissect_flow_keys (skb, fkeys,0 )) { + rc = -EPROTONOSUPPORT ; + goto err_free; + } + +if ((fkeys->basic.n_proto !=htons (ETH_P_IP ) && + fkeys->basic.n_proto !=htons (ETH_P_IPV6 )) || + (fkeys->basic.ip_proto !=IPPROTO_TCP && + fkeys->basic.ip_proto !=IPPROTO_UDP )) { + rc = -EPROTONOSUPPORT ; + goto err_free; + } + new_fltr->fmasks =BNGE_FLOW_IPV4_MASK_ALL ; +if (fkeys->basic.n_proto ==htons (ETH_P_IPV6 )) + new_fltr->fmasks =BNGE_FLOW_IPV6_MASK_ALL ; + + flags = fkeys->control.flags; +if (flags &FLOW_DIS_IS_FRAGMENT ) { + rc = -EPROTONOSUPPORT ; + goto err_free; + } + + new_fltr->l2_filter_id = filter_id; + + idx =bnge_get_ntp_filter_idx (bn, fkeys, skb); +rcu_read_lock (); + fltr =bnge_lookup_ntp_filter_from_idx (bn, new_fltr, idx); +/* Filter already exists. If the flow moved to another queue, +* retarget it, sp_task reprograms it in hardware. +*/ +if (fltr) { +if (!(fltr->base.flags &BNGE_ACT_NO_AGING ) && +READ_ONCE (fltr->base.rxq) != rxq_index) { +spin_lock_bh (&bn->ntp_fltr_lock); +WRITE_ONCE (fltr->base.rxq, rxq_index); +WRITE_ONCE (fltr->flow_id, flow_id); +/* Pairs with test_and_clear_bit() in sp_task */ +smp_mb__before_atomic (); +set_bit (BNGE_FLTR_RXQ_UPDATE , &fltr->base.state); +spin_unlock_bh (&bn->ntp_fltr_lock); +bnge_queue_sp_work (bn,BNGE_RX_NTP_FLTR_SP_EVENT ); + } + rc = fltr->base.sw_id; +rcu_read_unlock (); + goto err_free; + } +rcu_read_unlock (); + + 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; + }
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c static int bnge_set_features(struct net_device *dev, netdev_features_t features) · line 3362
Quoted 10 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +7
-0+ +err_free: +kfree (new_fltr); +return rc; +} +#endif +static const struct net_device_ops bnge_netdev_ops = { .ndo_open = bnge_open, .ndo_stop = bnge_close,
[Severity: Medium]
Can bnge_rx_flow_steer() run here before the retained user n-tuple filters have been rebound to the new L2 filter?
bnge_close_core() keeps the ethtool n-tuple rules in ntp_fltr_hash_tbl and usr_fltr_list. They keep the l2_filter_id they had before the close. On the next open, bnge_init_chip() allocates a fresh default L2 filter in vnic->l2_filters[0]. bnge_open_core() then enables NAPI, sets BNGE_STATE_OPEN and enables interrupts. It calls bnge_cfg_usr_fltrs() only after the sleeping HWRM calls in bnge_get_port_module_status() and bnge_hwrm_realloc_rss_ctx_vnic().
In that window a packet for dev->dev_addr can reach bnge_rx_flow_steer(). It passes the BNGE_STATE_OPEN check and picks up the new vnic->l2_filters[0]->base.filter_id. It then looks the flow up with bnge_lookup_ntp_filter_from_idx(). bnge_fltr_match() compares l2_filter_id, so a retained user rule for the same tuple does not match while it still carries the old id. The NO_AGING branch, which is meant to let the user rule win, is skipped. bnge_insert_ntp_filter() then adds a second, dynamic filter for that flow to the bucket.
There is also a plain data race on the field itself. bnge_cfg_one_usr_fltr() rewrites ntp_fltr->l2_filter_id without ntp_fltr_lock:
ntp_fltr->l2_filter_id = l2_fltr->base.filter_id;
At the same time, bnge_rx_flow_steer() and bnge_insert_ntp_filter() can read that 64-bit value from softirq. On 32-bit the read can tear.
Doesn't this leave two hash table entries for the same flow? Once sp_task programs the dynamic one, it could also leave two firmware rules, one steering to the aRFS queue instead of the queue or action the user configured with ethtool.
Would it make sense to restore the user filters before BNGE_STATE_OPEN is set? Alternatively, bnge_rx_flow_steer() could back off until bnge_cfg_usr_fltrs() has run. If the l2_filter_id update has to stay where it is, should it at least be done under ntp_fltr_lock?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261106093524.838341-1-vikas.gupta%40broadcom.com
Vikas Gupta
maintainerRe: [PATCH net-next v6 09/10] bnge: add aRFS flow steering ndo support
I see a few of Sashiko's comments are valid and will address them in v7.
Quoted 306 lines · On Tue, Nov 10, 2026 at 9:49 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · Low: 0
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 aRFS expiry loop in
bnge_cfg_ntp_filters()(drivers/net/ethernet/broadcom/bnge/bnge_filter.c) ignores the return…
- [Medium] Check-then-act race between the aRFS expiry loop inbnge_cfg_ntp_filters()and the retarget path inbnge_rx_flow_steer().
- [Medium] bnge: race onntp_fltr->l2_filter_idinbnge_open_core()inserts duplicate filter--
bnge: add aRFS flow steering ndo support
This commit adds an
ndo_rx_flow_steercallback to the bnge driver. The callback creates NTUPLE filters for aRFS and inserts them into the NTUPLE hash table. A new function,bnge_cfg_ntp_filters(), runs fromsp_taskto program pending filters in firmware, reprogram retargeted filters and expire idle filters viarps_may_expire_flow().Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +0
-0[ ... ]
Quoted 1 line
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +0
-0@@ -711,3 +711,80 @@ void bnge_clear_usr_fltrs(struct bnge_net *bn)[ ... ]
drivers/net/ethernet/broadcom/bnge/bnge_filter.c void bnge_clear_usr_fltrs(struct bnge_net *bn) · line 787
Quoted 7 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +7
-0+list_for_each_entry_safe (fltr, tmp, &expire_list, base.list_node) { +list_del_init (&fltr->base.list_node); +/* Retargeted by bnge_rx_flow_steer() after the scan */ +if (test_bit (BNGE_FLTR_RXQ_UPDATE , &fltr->base.state)) +continue ; +bnge_hwrm_cfa_ntuple_filter_free (bn->bd, fltr); +bnge_del_ntp_filter_rcu (bn, fltr);[Severity: Medium]
Should the return value ofbnge_hwrm_cfa_ntuple_filter_free()be ignored here?The free can fail in two ways.
bnge_hwrm_req_init()can fail to allocate the request, orbnge_hwrm_req_send()can hit a firmware error or timeout. In both casesfilter_idstays valid:bnge_hwrm_cfa_ntuple_filter_free() { ... 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 unlinks and frees the software filter, which is the only object holding that firmware id. It also clears the filter'ssw_idbit inntp_fltr_bmap.Does this leak the firmware n-tuple rule? It would keep steering the flow to the old RX queue, and the driver could not free it until the interface is closed.
The
update_listloop earlier inbnge_cfg_ntp_filters()handles the same failure by keeping the software filter:if (bnge_hwrm_cfa_ntuple_filter_free(bn->bd, fltr)) continue;Should the expire loop do the same?
This path becomes reachable once the follow-up patch "bnge: add
cpu_rmapsupport for IRQ affinity" setsdev->rx_cpu_rmap.[Severity: Medium]
Can a concurrent retarget frombnge_rx_flow_steer()still get lost here?The
test_bit()check runs withoutntp_fltr_lock. The filter also stays linked inntp_fltr_hash_tbluntilbnge_del_ntp_filter_rcu()runs, which happens after the sleeping HWRM free. One possible sequence:
sp_task, inbnge_cfg_ntp_filters():
rps_may_expire_flow()returns true, so the filter goes onexpire_listtest_bit(BNGE_FLTR_RXQ_UPDATE)returns falsebnge_hwrm_cfa_ntuple_filter_free()sleepssoftirq on another CPU, in set_rps_cpu()->bnge_rx_flow_steer():
bnge_lookup_ntp_filter_from_idx()finds the still-linked filterWRITE_ONCE(fltr->base.rxq, rxq_index);set_bit(BNGE_FLTR_RXQ_UPDATE, &fltr->base.state);
rc =fltr->base.sw_idis returned toset_rps_cpu()
sp_task:
bnge_del_ntp_filter_rcu()unlinks the filter and clears itssw_idinntp_fltr_bmap
set_rps_cpu()then stores the returnedsw_idinrflow->filter. While the flow stays active on the same CPU,set_rps_cpu()then takes this path:if (READ_ONCE(tmp_rflow->filter) != RPS_NO_FILTER) { if (rps_flow_is_active(tmp_rflow, ...)) { if (hash != READ_ONCE(tmp_rflow->hash) || next_cpu == tmp_cpu) goto out;So
ndo_rx_flow_steer()is not called again.Doesn't that leave the flow without hardware steering until it goes idle or moves to another CPU? The RPS flow table would also hold a
sw_idthat has been released and can be reused.The comment "Retargeted by
bnge_rx_flow_steer()after the scan" suggests this check is meant to cover that case.The scan loop also reads rxq and
flow_idas two separate lockless loads:rxq = READ_ONCE(fltr->base.rxq); flow_id = READ_ONCE(fltr->flow_id);Could these see a torn pair while a retarget is in progress, and put a filter that was just retargeted on
expire_list?[ ... ]
Quoted 126 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +119
-0@@ -3222,6 +3231,132 @@ static int bnge_set_features(struct net_device *dev, netdev_features_t features)return 0 ; } +#ifdef CONFIG_RFS_ACCEL +static __le64 bnge_lookup_l2_filter_from_key (struct bnge_net *bn, +struct bnge_l2_key *key) +{ +u32 idx; + + idx =jhash2 (&key->filter_key,BNGE_L2_KEY_SIZE , bn->hash_seed) & +BNGE_L2_FLTR_HASH_MASK ; +return bnge_lookup_l2_filter_rcu (bn, key, idx); +} + +static int bnge_rx_flow_steer (struct net_device *dev,const struct sk_buff *skb, +u16 rxq_index,u32 flow_id) +{ +struct ethhdr *eth = (struct ethhdr *)skb_mac_header (skb); +struct bnge_ntuple_filter *fltr, *new_fltr; +struct bnge_net *bn =netdev_priv (dev); +struct flow_keys *fkeys; +__le64 filter_id; +u32 flags, idx; +int rc =0 ; + +/* Hold rcu_read_lock() across the L2 filter lookup and check +* BNGE_STATE_OPEN inside it. bnge_close_core() clears the +* flag before bnge_shutdown_nic() frees the L2 filters via +* kfree_rcu(), so if we observe the device open here the +* filter cannot be freed under us for the duration of +* this critical section. +*/ +rcu_read_lock (); +if (!test_bit (BNGE_STATE_OPEN , &bn->bd->state)) { +rcu_read_unlock (); +return -EINVAL ; + } + +if (ether_addr_equal (dev->dev_addr, eth->h_dest)) { +struct bnge_vnic_info *vnic = &bn->vnic_info[BNGE_VNIC_DEFAULT ]; +struct bnge_l2_filter *l2_filter; + +if (!vnic->uc_filter_count) { +rcu_read_unlock (); +return -EINVAL ; + } + l2_filter = vnic->l2_filters[0 ]; + filter_id = l2_filter->base.filter_id; + }else { +struct bnge_l2_key key; + +ether_addr_copy (key.dst_mac_addr, eth->h_dest); + key.vlan =0 ; + + filter_id =bnge_lookup_l2_filter_from_key (bn, &key); +if (filter_id ==BNGE_FLTR_ID_INVALID ) { +rcu_read_unlock (); +return -EINVAL ; + } + } +rcu_read_unlock (); + + new_fltr =kzalloc_obj (*new_fltr,GFP_ATOMIC ); +if (!new_fltr) +return -ENOMEM ; + + fkeys = &new_fltr->fkeys; +if (!skb_flow_dissect_flow_keys (skb, fkeys,0 )) { + rc = -EPROTONOSUPPORT ; + goto err_free; + } + +if ((fkeys->basic.n_proto !=htons (ETH_P_IP ) && + fkeys->basic.n_proto !=htons (ETH_P_IPV6 )) || + (fkeys->basic.ip_proto !=IPPROTO_TCP && + fkeys->basic.ip_proto !=IPPROTO_UDP )) { + rc = -EPROTONOSUPPORT ; + goto err_free; + } + new_fltr->fmasks =BNGE_FLOW_IPV4_MASK_ALL ; +if (fkeys->basic.n_proto ==htons (ETH_P_IPV6 )) + new_fltr->fmasks =BNGE_FLOW_IPV6_MASK_ALL ; + + flags = fkeys->control.flags; +if (flags &FLOW_DIS_IS_FRAGMENT ) { + rc = -EPROTONOSUPPORT ; + goto err_free; + } + + new_fltr->l2_filter_id = filter_id; + + idx =bnge_get_ntp_filter_idx (bn, fkeys, skb); +rcu_read_lock (); + fltr =bnge_lookup_ntp_filter_from_idx (bn, new_fltr, idx); +/* Filter already exists. If the flow moved to another queue, +* retarget it, sp_task reprograms it in hardware. +*/ +if (fltr) { +if (!(fltr->base.flags &BNGE_ACT_NO_AGING ) && +READ_ONCE (fltr->base.rxq) != rxq_index) { +spin_lock_bh (&bn->ntp_fltr_lock); +WRITE_ONCE (fltr->base.rxq, rxq_index); +WRITE_ONCE (fltr->flow_id, flow_id); +/* Pairs with test_and_clear_bit() in sp_task */ +smp_mb__before_atomic (); +set_bit (BNGE_FLTR_RXQ_UPDATE , &fltr->base.state); +spin_unlock_bh (&bn->ntp_fltr_lock); +bnge_queue_sp_work (bn,BNGE_RX_NTP_FLTR_SP_EVENT ); + } + rc = fltr->base.sw_id; +rcu_read_unlock (); + goto err_free; + } +rcu_read_unlock (); + + 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; + }drivers/net/ethernet/broadcom/bnge/bnge_netdev.c static int bnge_set_features(struct net_device *dev, netdev_features_t features) · line 3362
Quoted 10 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +7
-0+ +err_free: +kfree (new_fltr); +return rc; +} +#endif +static const struct net_device_ops bnge_netdev_ops = { .ndo_open = bnge_open, .ndo_stop = bnge_close,[Severity: Medium]
Canbnge_rx_flow_steer()run here before the retained user n-tuple filters have been rebound to the new L2 filter?
bnge_close_core()keeps the ethtool n-tuple rules inntp_fltr_hash_tblandusr_fltr_list. They keep thel2_filter_idthey had before the close. On the next open,bnge_init_chip()allocates a fresh default L2 filter in vnic->l2_filters[0].bnge_open_core()then enables NAPI, setsBNGE_STATE_OPENand enables interrupts. It callsbnge_cfg_usr_fltrs()only after the sleeping HWRM calls inbnge_get_port_module_status()andbnge_hwrm_realloc_rss_ctx_vnic().In that window a packet for
dev->dev_addrcan reachbnge_rx_flow_steer(). It passes theBNGE_STATE_OPENcheck and picks up the new vnic->l2_filters[0]->base.filter_id. It then looks the flow up withbnge_lookup_ntp_filter_from_idx().bnge_fltr_match()comparesl2_filter_id, so a retained user rule for the same tuple does not match while it still carries the old id. TheNO_AGINGbranch, which is meant to let the user rule win, is skipped.bnge_insert_ntp_filter()then adds a second, dynamic filter for that flow to the bucket.There is also a plain data race on the field itself.
bnge_cfg_one_usr_fltr()rewritesntp_fltr->l2_filter_idwithoutntp_fltr_lock:ntp_fltr->l2_filter_id = l2_fltr->base.filter_id;At the same time,
bnge_rx_flow_steer()andbnge_insert_ntp_filter()can read that 64-bit value from softirq. On 32-bit the read can tear.Doesn't this leave two hash table entries for the same flow? Once
sp_taskprograms the dynamic one, it could also leave two firmware rules, one steering to the aRFS queue instead of the queue or action the user configured with ethtool.
Quoted 8 lines
Would it make sense to restore the user filters before
BNGE_STATE_OPENis set? Alternatively,bnge_rx_flow_steer()could back off untilbnge_cfg_usr_fltrs()has run. If thel2_filter_idupdate has to stay where it is, should it at least be done underntp_fltr_lock?--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261106093524.838341-1-vikas.gupta%40broadcom.com
pw-bot: cr
Vikas Gupta
maintainerPATCH v6 10/10 bnge: add cpu_rmap support for IRQ affinity
In reply to Vikas GuptaWhen CONFIG_RFS_ACCEL is enabled, allocate and populate a cpu_rmap for the RX IRQ vectors so that the kernel's aRFS infrastructure can correctly map flows to the RX queues serviced by the nearest CPU.
This ensures that NTUPLE rules created by the kernel steer packets to the optimal queue based on CPU/IRQ affinity.
Also, This is the patch that turns aRFS on. Before it dev->rx_cpu_rmap was never set, so set_rps_cpu() took its early exit and bnge_rx_flow_steer() from the previous patch was never called. A failed rmap allocation does not fail the open; aRFS stays off. If adding an IRQ to the rmap fails for one ring, aRFS is turned off for all rings, because a later ring would otherwise take the free slot and map to the wrong RX queue.
--- .../net/ethernet/broadcom/bnge/bnge_netdev.c | 57 ++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +56 -1
@@ -18,6 +18,7 @@#include <net/ip.h> #include <linux/skbuff.h> #include <net/page_pool/helpers.h> +#include <linux/cpu_rmap.h> #include "bnge.h" #include "bnge_hwrm.h"
@@ -2481,10 +2482,23 @@ static int bnge_setup_interrupts(struct bnge_net *bn) {struct net_device *dev = bn->netdev;struct bnge_dev *bd = bn->bd; +int rc;bnge_setup_msix (bn); -return netif_set_real_num_queues (dev, bd->tx_nr_rings, bd->rx_nr_rings); + rc =netif_set_real_num_queues (dev, bd->tx_nr_rings, bd->rx_nr_rings); +if (rc) +return rc; + +#ifdef CONFIG_RFS_ACCEL +if (bn->priv_flags &BNGE_NET_EN_NTUPLE ) { + dev->rx_cpu_rmap =alloc_irq_cpu_rmap (bd->rx_nr_rings); +if (!dev->rx_cpu_rmap) +netdev_warn (dev,"Unable to allocate the CPU rmap, aRFS disabled\n" ); + } +#endif + +return rc; }static void bnge_hwrm_resource_free (struct bnge_net *bn,bool close_path)
@@ -2494,12 +2508,35 @@ static void bnge_hwrm_resource_free(struct bnge_net *bn, bool close_path)bnge_hwrm_stat_ctx_free (bn); } +#ifdef CONFIG_RFS_ACCEL +/* set_rps_cpu() reads rx_cpu_rmap under rcu_read_lock(). Hide the pointer and +* wait for readers that already loaded it before the rmap is freed. +*/ +static void bnge_free_cpu_rmap (struct bnge_net *bn) +{ +struct cpu_rmap *rmap = bn->netdev->rx_cpu_rmap; + +if (!rmap) +return ; + +WRITE_ONCE (bn->netdev->rx_cpu_rmap,NULL ); +synchronize_net (); +free_irq_cpu_rmap (rmap); +} +#else +static void bnge_free_cpu_rmap (struct bnge_net *bn) +{ +} +#endif +static void bnge_free_irq (struct bnge_net *bn) {struct bnge_dev *bd = bn->bd;struct bnge_irq *irq;int i; +bnge_free_cpu_rmap (bn); +for (i =0 ; i < bd->nq_nr_rings; i++) {int map_idx =bnge_cp_num_to_irq_num (bn, i);
@@ -2519,6 +2556,7 @@ static void bnge_free_irq(struct bnge_net *bn)static int bnge_request_irq (struct bnge_net *bn) { +struct cpu_rmap *rmap =NULL ;struct bnge_dev *bd = bn->bd;int i, rc;
@@ -2527,10 +2565,27 @@ static int bnge_request_irq(struct bnge_net *bn)netdev_err (bn->netdev,"bnge_setup_interrupts err: %d\n" , rc);return rc; } + +#ifdef CONFIG_RFS_ACCEL + rmap = bn->netdev->rx_cpu_rmap; +#endif +for (i =0 ; i < bd->nq_nr_rings; i++) {int map_idx =bnge_cp_num_to_irq_num (bn, i);struct bnge_irq *irq = &bd->irq_tbl[map_idx]; +if (IS_ENABLED (CONFIG_RFS_ACCEL ) && + rmap && bn->bnapi[i]->rx_ring) { + rc =irq_cpu_rmap_add (rmap, irq->vector); +if (rc) { +netdev_warn (bn->netdev, +"failed adding irq rmap for ring %d, disabling aRFS\n" , + i); +bnge_free_cpu_rmap (bn); + rmap =NULL ; + } + } + rc =request_irq (irq->vector, irq->handler,0 , irq->name, bn->bnapi[i]);if (rc)
Signature · 1 line
2.52.0