ice: Fix DMA mappings leak
Subsystems (2)
PATCH 1/1 ice: Fix DMA mappings leak
From: Przemyslaw Patynowski <[email protected]>
Fix leak, when user changes ring parameters.
During reallocation of RX buffers, new DMA mappings are created for those buffers. New buffers with different RX ring count should substitute older ones, but those buffers were freed in ice_vsi_cfg_rxq and reallocated again with ice_alloc_rx_buf. kfree on rx_buf caused leak of already mapped DMA.
Reallocate ZC with xdp_buf struct, when BPF program loads. Reallocate back to rx_buf, when BPF program unloads.
If BPF program is loaded/unloaded and XSK pools are created, reallocate RX queues accordingly in XDP_SETUP_XSK_POOL handler.
Steps for reproduction:
while :
do
for ((i=0; i<=8160; i=i+32)) do ethtool -G enp130s0f0 rx $i tx $i sleep 0.5 ethtool -g enp130s0f0 done
done
--- drivers/net/ethernet/intel/ice/ice_base.c | 17 ------ drivers/net/ethernet/intel/ice/ice_main.c | 8 +++ drivers/net/ethernet/intel/ice/ice_xsk.c | 63 +++++++++++++++++++++++ drivers/net/ethernet/intel/ice/ice_xsk.h | 7 +++ 4 files changed, 78 insertions(+), 17 deletions(-)
drivers/net/ethernet/intel/ice/ice_base.c +0 -17
@@ -7,18 +7,6 @@#include "ice_dcb_lib.h" #include "ice_sriov.h" -static bool ice_alloc_rx_buf_zc (struct ice_rx_ring *rx_ring) -{ - rx_ring->xdp_buf =kcalloc (rx_ring->count,sizeof (*rx_ring->xdp_buf),GFP_KERNEL ); -return !!rx_ring->xdp_buf; -} - -static bool ice_alloc_rx_buf (struct ice_rx_ring *rx_ring) -{ - rx_ring->rx_buf =kcalloc (rx_ring->count,sizeof (*rx_ring->rx_buf),GFP_KERNEL ); -return !!rx_ring->rx_buf; -} -/** * __ice_vsi_get_qs_contig - Assign a contiguous chunk of queues to VSI * @qs_cfg: gathered variables needed for PF->VSI queues assignment
@@ -519,11 +507,8 @@ int ice_vsi_cfg_rxq(struct ice_rx_ring *ring)xdp_rxq_info_reg (&ring->xdp_rxq, ring->netdev, ring->q_index, ring->q_vector->napi.napi_id); -kfree (ring->rx_buf); ring->xsk_pool =ice_xsk_pool (ring);if (ring->xsk_pool) { -if (!ice_alloc_rx_buf_zc (ring)) -return -ENOMEM ;xdp_rxq_info_unreg_mem_model (&ring->xdp_rxq); ring->rx_buf_len =
@@ -538,8 +523,6 @@ int ice_vsi_cfg_rxq(struct ice_rx_ring *ring)dev_info (dev,"Registered XDP mem model MEM_TYPE_XSK_BUFF_POOL on Rx ring %d\n" , ring->q_index); }else { -if (!ice_alloc_rx_buf (ring)) -return -ENOMEM ;if (!xdp_rxq_info_is_reg (&ring->xdp_rxq))/* coverity[check_return] */ xdp_rxq_info_reg(&ring->xdp_rxq,
drivers/net/ethernet/intel/ice/ice_main.c +8 -0
@@ -2885,10 +2885,18 @@ ice_xdp_setup_prog(struct ice_vsi *vsi, struct bpf_prog *prog,if (xdp_ring_err)NL_SET_ERR_MSG_MOD (extack,"Setting up XDP Tx resources failed" ); } +/* reallocate RX queues that are used for zero-copy */ + xdp_ring_err =ice_realloc_zc_buf (vsi, true); +if (xdp_ring_err) +NL_SET_ERR_MSG_MOD (extack,"Setting up XDP Rx resources failed" ); }else if (ice_is_xdp_ena_vsi (vsi) && !prog) { xdp_ring_err =ice_destroy_xdp_rings (vsi);if (xdp_ring_err)NL_SET_ERR_MSG_MOD (extack,"Freeing XDP Tx resources failed" ); +/* reallocate RX queues that were used for zero-copy */ + xdp_ring_err =ice_realloc_zc_buf (vsi, false); +if (xdp_ring_err) +NL_SET_ERR_MSG_MOD (extack,"Freeing XDP Rx resources failed" ); }else {/* safe to call even when prog == vsi->xdp_prog as * dev_xdp_install in net/core/dev.c incremented prog's
drivers/net/ethernet/intel/ice/ice_xsk.c +63 -0
86 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_xsk.h +7 -0
@@ -27,6 +27,7 @@ bool ice_xsk_any_rx_ring_ena(struct ice_vsi *vsi);void ice_xsk_clean_rx_ring (struct ice_rx_ring *rx_ring);void ice_xsk_clean_xdp_ring (struct ice_tx_ring *xdp_ring);bool ice_xmit_zc (struct ice_tx_ring *xdp_ring,u32 budget,int napi_budget); +int ice_realloc_zc_buf (struct ice_vsi *vsi,bool zc);#else static inline bool ice_xmit_zc(struct ice_tx_ring __always_unused *xdp_ring,
@@ -72,5 +73,11 @@ ice_xsk_wakeup(struct net_device __always_unused *netdev,static inline void ice_xsk_clean_rx_ring (struct ice_rx_ring *rx_ring) { }static inline void ice_xsk_clean_xdp_ring (struct ice_tx_ring *xdp_ring) { } + +static inline int ice_realloc_zc_buf (struct ice_vsi __always_unused *vsi, +bool __always_unused zc) +{ +return 0 ; +}#endif /* CONFIG_XDP_SOCKETS */ #endif /* !_ICE_XSK_H_ */
Signature · 6 lines
2.27.0 _______________________________________________ Intel-wired-lan mailing list [email protected] https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
A message that is not in the archive (sent off-list or not yet received): PH0PR11MB51448E6BF36E8FE9611634A3E2709@PH0PR11MB5144.namprd11.prod.outlook.com
Rout, ChandanX
Tested-byQuoted 35 lines
-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Mateusz Palczewski
Sent: Thursday, August 11, 2022 3:39 PM
To: [email protected]
Cc: Patynowski, PrzemyslawX <[email protected]>
Subject: [Intel-wired-lan] [PATCH net v1] ice: Fix DMA mappings leakFrom: Przemyslaw Patynowski <[email protected]>
Fix leak, when user changes ring parameters.
During reallocation of RX buffers, new DMA mappings are created for those buffers. New buffers with different RX ring count should substitute older ones, but those buffers were freed inice_vsi_cfg_rxqand reallocated again withice_alloc_rx_buf. kfree onrx_bufcaused leak of already mapped DMA. Reallocate ZC withxdp_bufstruct, when BPF program loads. Reallocate back torx_buf, when BPF program unloads.
If BPF program is loaded/unloaded and XSK pools are created, reallocate RX queues accordingly inXDP_SETUP_XSK_POOLhandler.Steps for reproduction:
while :
dofor ((i=0; i<=8160; i=i+32)) do ethtool -G enp130s0f0 rx $i tx $i sleep 0.5 ethtool -g enp130s0f0 donedone
Fixes 617f3e1b588c ("ice: xsk: allocate separate memory for XDP SW ring")Signed-off-by Przemyslaw Patynowski
Quoted 8 lines
Signed-off-by Mateusz Palczewski <[email protected]>---
drivers/net/ethernet/intel/ice/ice_base.c | 17 ------ drivers/net/ethernet/intel/ice/ice_main.c | 8 +++ drivers/net/ethernet/intel/ice/ice_xsk.c | 63 +++++++++++++++++++++++ drivers/net/ethernet/intel/ice/ice_xsk.h | 7 +++ 4 files changed, 78 insertions(+), 17 deletions(-)
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan