Skip to content

Commit f0aa6a3

Browse files
committed
eth: bnxt: always recalculate features after XDP clearing, fix null-deref
Recalculate features when XDP is detached. Before: # ip li set dev eth0 xdp obj xdp_dummy.bpf.o sec xdp # ip li set dev eth0 xdp off # ethtool -k eth0 | grep gro rx-gro-hw: off [requested on] After: # ip li set dev eth0 xdp obj xdp_dummy.bpf.o sec xdp # ip li set dev eth0 xdp off # ethtool -k eth0 | grep gro rx-gro-hw: on The fact that HW-GRO doesn't get re-enabled automatically is just a minor annoyance. The real issue is that the features will randomly come back during another reconfiguration which just happens to invoke netdev_update_features(). The driver doesn't handle reconfiguring two things at a time very robustly. Starting with commit 98ba1d9 ("bnxt_en: Fix RSS logic in __bnxt_reserve_rings()") we only reconfigure the RSS hash table if the "effective" number of Rx rings has changed. If HW-GRO is enabled "effective" number of rings is 2x what user sees. So if we are in the bad state, with HW-GRO re-enablement "pending" after XDP off, and we lower the rings by / 2 - the HW-GRO rings doing 2x and the ethtool -L doing / 2 may cancel each other out, and the: if (old_rx_rings != bp->hw_resc.resv_rx_rings && condition in __bnxt_reserve_rings() will be false. The RSS map won't get updated, and we'll crash with: BUG: kernel NULL pointer dereference, address: 0000000000000168 RIP: 0010:__bnxt_hwrm_vnic_set_rss+0x13a/0x1a0 bnxt_hwrm_vnic_rss_cfg_p5+0x47/0x180 __bnxt_setup_vnic_p5+0x58/0x110 bnxt_init_nic+0xb72/0xf50 __bnxt_open_nic+0x40d/0xab0 bnxt_open_nic+0x2b/0x60 ethtool_set_channels+0x18c/0x1d0 As we try to access a freed ring. The issue is present since XDP support was added, really, but prior to commit 98ba1d9 ("bnxt_en: Fix RSS logic in __bnxt_reserve_rings()") it wasn't causing major issues. Fixes: 1054aee ("bnxt_en: Use NETIF_F_GRO_HW.") Fixes: 98ba1d9 ("bnxt_en: Fix RSS logic in __bnxt_reserve_rings()") Reviewed-by: Michael Chan <[email protected]> Reviewed-by: Somnath Kotur <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent b3af609 commit f0aa6a3

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4708,7 +4708,7 @@ void bnxt_set_ring_params(struct bnxt *bp)
47084708
/* Changing allocation mode of RX rings.
47094709
* TODO: Update when extending xdp_rxq_info to support allocation modes.
47104710
*/
4711-
int bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode)
4711+
static void __bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode)
47124712
{
47134713
struct net_device *dev = bp->dev;
47144714

@@ -4729,15 +4729,30 @@ int bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode)
47294729
bp->rx_skb_func = bnxt_rx_page_skb;
47304730
}
47314731
bp->rx_dir = DMA_BIDIRECTIONAL;
4732-
/* Disable LRO or GRO_HW */
4733-
netdev_update_features(dev);
47344732
} else {
47354733
dev->max_mtu = bp->max_mtu;
47364734
bp->flags &= ~BNXT_FLAG_RX_PAGE_MODE;
47374735
bp->rx_dir = DMA_FROM_DEVICE;
47384736
bp->rx_skb_func = bnxt_rx_skb;
47394737
}
4740-
return 0;
4738+
}
4739+
4740+
void bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode)
4741+
{
4742+
__bnxt_set_rx_skb_mode(bp, page_mode);
4743+
4744+
if (!page_mode) {
4745+
int rx, tx;
4746+
4747+
bnxt_get_max_rings(bp, &rx, &tx, true);
4748+
if (rx > 1) {
4749+
bp->flags &= ~BNXT_FLAG_NO_AGG_RINGS;
4750+
bp->dev->hw_features |= NETIF_F_LRO;
4751+
}
4752+
}
4753+
4754+
/* Update LRO and GRO_HW availability */
4755+
netdev_update_features(bp->dev);
47414756
}
47424757

47434758
static void bnxt_free_vnic_attributes(struct bnxt *bp)
@@ -16214,7 +16229,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1621416229
if (bp->max_fltr < BNXT_MAX_FLTR)
1621516230
bp->max_fltr = BNXT_MAX_FLTR;
1621616231
bnxt_init_l2_fltr_tbl(bp);
16217-
bnxt_set_rx_skb_mode(bp, false);
16232+
__bnxt_set_rx_skb_mode(bp, false);
1621816233
bnxt_set_tpa_flags(bp);
1621916234
bnxt_set_ring_params(bp);
1622016235
bnxt_rdma_aux_device_init(bp);

drivers/net/ethernet/broadcom/bnxt/bnxt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2846,7 +2846,7 @@ u32 bnxt_fw_health_readl(struct bnxt *bp, int reg_idx);
28462846
bool bnxt_bs_trace_avail(struct bnxt *bp, u16 type);
28472847
void bnxt_set_tpa_flags(struct bnxt *bp);
28482848
void bnxt_set_ring_params(struct bnxt *);
2849-
int bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode);
2849+
void bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode);
28502850
void bnxt_insert_usr_fltr(struct bnxt *bp, struct bnxt_filter_base *fltr);
28512851
void bnxt_del_one_usr_fltr(struct bnxt *bp, struct bnxt_filter_base *fltr);
28522852
int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp, unsigned long *bmap,

drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -422,15 +422,8 @@ static int bnxt_xdp_set(struct bnxt *bp, struct bpf_prog *prog)
422422
bnxt_set_rx_skb_mode(bp, true);
423423
xdp_features_set_redirect_target(dev, true);
424424
} else {
425-
int rx, tx;
426-
427425
xdp_features_clear_redirect_target(dev);
428426
bnxt_set_rx_skb_mode(bp, false);
429-
bnxt_get_max_rings(bp, &rx, &tx, true);
430-
if (rx > 1) {
431-
bp->flags &= ~BNXT_FLAG_NO_AGG_RINGS;
432-
bp->dev->hw_features |= NETIF_F_LRO;
433-
}
434427
}
435428
bp->tx_nr_rings_xdp = tx_xdp;
436429
bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc + tx_xdp;

0 commit comments

Comments
 (0)