Skip to content

Commit 3ab52af

Browse files
Björn TöpelJeff Kirsher
authored andcommitted
i40e: disallow changing the number of descriptors when AF_XDP is on
When an AF_XDP UMEM is attached to any of the Rx rings, we disallow a user to change the number of descriptors via e.g. "ethtool -G IFNAME". Otherwise, the size of the stash/reuse queue can grow unbounded, which would result in OOM or leaking userspace buffers. Signed-off-by: Björn Töpel <bjorn.topel@intel.com> Tested-by: Andrew Bowers <andrewx.bowers@intel.com> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
1 parent 411dc16 commit 3ab52af

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

drivers/net/ethernet/intel/i40e/i40e_ethtool.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "i40e.h"
77
#include "i40e_diag.h"
8+
#include "i40e_txrx_common.h"
89

910
/* ethtool statistics helpers */
1011

@@ -1710,6 +1711,13 @@ static int i40e_set_ringparam(struct net_device *netdev,
17101711
(new_rx_count == vsi->rx_rings[0]->count))
17111712
return 0;
17121713

1714+
/* If there is a AF_XDP UMEM attached to any of Rx rings,
1715+
* disallow changing the number of descriptors -- regardless
1716+
* if the netdev is running or not.
1717+
*/
1718+
if (i40e_xsk_any_rx_ring_enabled(vsi))
1719+
return -EBUSY;
1720+
17131721
while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
17141722
timeout--;
17151723
if (!timeout)

drivers/net/ethernet/intel/i40e/i40e_txrx_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,6 @@ static inline void i40e_arm_wb(struct i40e_ring *tx_ring,
8989

9090
void i40e_xsk_clean_rx_ring(struct i40e_ring *rx_ring);
9191
void i40e_xsk_clean_tx_ring(struct i40e_ring *tx_ring);
92+
bool i40e_xsk_any_rx_ring_enabled(struct i40e_vsi *vsi);
9293

9394
#endif /* I40E_TXRX_COMMON_ */

drivers/net/ethernet/intel/i40e/i40e_xsk.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,3 +944,24 @@ void i40e_xsk_clean_tx_ring(struct i40e_ring *tx_ring)
944944
if (xsk_frames)
945945
xsk_umem_complete_tx(umem, xsk_frames);
946946
}
947+
948+
/**
949+
* i40e_xsk_any_rx_ring_enabled - Checks if Rx rings have AF_XDP UMEM attached
950+
* @vsi: vsi
951+
*
952+
* Returns true if any of the Rx rings has an AF_XDP UMEM attached
953+
**/
954+
bool i40e_xsk_any_rx_ring_enabled(struct i40e_vsi *vsi)
955+
{
956+
int i;
957+
958+
if (!vsi->xsk_umems)
959+
return false;
960+
961+
for (i = 0; i < vsi->num_queue_pairs; i++) {
962+
if (vsi->xsk_umems[i])
963+
return true;
964+
}
965+
966+
return false;
967+
}

0 commit comments

Comments
 (0)