Skip to content

Commit 52911bb

Browse files
committed
Merge branch '100GbE' of git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/net-queue
Tony Nguyen says: ==================== Intel Wired LAN Driver Updates 2021-11-22 Maciej Fijalkowski says: Here are the two fixes for issues around ethtool's set_channels() callback for ice driver. Both are related to XDP resources. First one corrects the size of vsi->txq_map that is used to track the usage of Tx resources and the second one prevents the wrong refcounting of bpf_prog. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 60ebd67 + f65ee53 commit 52911bb

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

drivers/net/ethernet/intel/ice/ice_lib.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,13 @@ static int ice_vsi_alloc_arrays(struct ice_vsi *vsi)
8989
if (!vsi->rx_rings)
9090
goto err_rings;
9191

92-
/* XDP will have vsi->alloc_txq Tx queues as well, so double the size */
93-
vsi->txq_map = devm_kcalloc(dev, (2 * vsi->alloc_txq),
92+
/* txq_map needs to have enough space to track both Tx (stack) rings
93+
* and XDP rings; at this point vsi->num_xdp_txq might not be set,
94+
* so use num_possible_cpus() as we want to always provide XDP ring
95+
* per CPU, regardless of queue count settings from user that might
96+
* have come from ethtool's set_channels() callback;
97+
*/
98+
vsi->txq_map = devm_kcalloc(dev, (vsi->alloc_txq + num_possible_cpus()),
9499
sizeof(*vsi->txq_map), GFP_KERNEL);
95100

96101
if (!vsi->txq_map)

drivers/net/ethernet/intel/ice/ice_main.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2609,7 +2609,18 @@ int ice_prepare_xdp_rings(struct ice_vsi *vsi, struct bpf_prog *prog)
26092609
ice_stat_str(status));
26102610
goto clear_xdp_rings;
26112611
}
2612-
ice_vsi_assign_bpf_prog(vsi, prog);
2612+
2613+
/* assign the prog only when it's not already present on VSI;
2614+
* this flow is a subject of both ethtool -L and ndo_bpf flows;
2615+
* VSI rebuild that happens under ethtool -L can expose us to
2616+
* the bpf_prog refcount issues as we would be swapping same
2617+
* bpf_prog pointers from vsi->xdp_prog and calling bpf_prog_put
2618+
* on it as it would be treated as an 'old_prog'; for ndo_bpf
2619+
* this is not harmful as dev_xdp_install bumps the refcount
2620+
* before calling the op exposed by the driver;
2621+
*/
2622+
if (!ice_is_xdp_ena_vsi(vsi))
2623+
ice_vsi_assign_bpf_prog(vsi, prog);
26132624

26142625
return 0;
26152626
clear_xdp_rings:
@@ -2785,6 +2796,11 @@ ice_xdp_setup_prog(struct ice_vsi *vsi, struct bpf_prog *prog,
27852796
if (xdp_ring_err)
27862797
NL_SET_ERR_MSG_MOD(extack, "Freeing XDP Tx resources failed");
27872798
} else {
2799+
/* safe to call even when prog == vsi->xdp_prog as
2800+
* dev_xdp_install in net/core/dev.c incremented prog's
2801+
* refcount so corresponding bpf_prog_put won't cause
2802+
* underflow
2803+
*/
27882804
ice_vsi_assign_bpf_prog(vsi, prog);
27892805
}
27902806

0 commit comments

Comments
 (0)