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>
 
 #include "i40e.h"
 #include "i40e_diag.h"
+#include "i40e_txrx_common.h"
 
 /* ethtool statistics helpers */
 
            (new_rx_count == vsi->rx_rings[0]->count))
                return 0;
 
+       /* If there is a AF_XDP UMEM attached to any of Rx rings,
+        * disallow changing the number of descriptors -- regardless
+        * if the netdev is running or not.
+        */
+       if (i40e_xsk_any_rx_ring_enabled(vsi))
+               return -EBUSY;
+
        while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
                timeout--;
                if (!timeout)
 
 
 void i40e_xsk_clean_rx_ring(struct i40e_ring *rx_ring);
 void i40e_xsk_clean_tx_ring(struct i40e_ring *tx_ring);
+bool i40e_xsk_any_rx_ring_enabled(struct i40e_vsi *vsi);
 
 #endif /* I40E_TXRX_COMMON_ */
 
        if (xsk_frames)
                xsk_umem_complete_tx(umem, xsk_frames);
 }
+
+/**
+ * i40e_xsk_any_rx_ring_enabled - Checks if Rx rings have AF_XDP UMEM attached
+ * @vsi: vsi
+ *
+ * Returns true if any of the Rx rings has an AF_XDP UMEM attached
+ **/
+bool i40e_xsk_any_rx_ring_enabled(struct i40e_vsi *vsi)
+{
+       int i;
+
+       if (!vsi->xsk_umems)
+               return false;
+
+       for (i = 0; i < vsi->num_queue_pairs; i++) {
+               if (vsi->xsk_umems[i])
+                       return true;
+       }
+
+       return false;
+}