[PATCH v7 12/27] net/i40e: avoid rte malloc in VF resource queries
Anatoly Burakov
anatoly.burakov at intel.com
Fri Feb 20 11:14:19 CET 2026
Currently, when responding to VF resource queries, we are dynamically
allocating a temporary buffer with rte_zmalloc followed by an immediate
rte_free. This memory does not need to be stored in hugepage memory and
the allocation size is pretty small, so replace it with stack allocation.
Signed-off-by: Anatoly Burakov <anatoly.burakov at intel.com>
Acked-by: Bruce Richardson <bruce.richardson at intel.com>
---
drivers/net/intel/i40e/i40e_pf.c | 26 +++++++-------------------
1 file changed, 7 insertions(+), 19 deletions(-)
diff --git a/drivers/net/intel/i40e/i40e_pf.c b/drivers/net/intel/i40e/i40e_pf.c
index ebe1deeade..08cdd6bc4d 100644
--- a/drivers/net/intel/i40e/i40e_pf.c
+++ b/drivers/net/intel/i40e/i40e_pf.c
@@ -309,9 +309,14 @@ static int
i40e_pf_host_process_cmd_get_vf_resource(struct i40e_pf_vf *vf, uint8_t *msg,
bool b_op)
{
- struct virtchnl_vf_resource *vf_res = NULL;
+ /* only have 1 VSI by default */
+ struct {
+ struct virtchnl_vf_resource vf_res;
+ struct virtchnl_vsi_resource vsi_res;
+ } res = {0};
+ struct virtchnl_vf_resource *vf_res = &res.vf_res;
struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
- uint32_t len = 0;
+ uint32_t len = sizeof(res);
uint64_t default_hena = I40E_RSS_HENA_ALL;
int ret = I40E_SUCCESS;
@@ -322,20 +327,6 @@ i40e_pf_host_process_cmd_get_vf_resource(struct i40e_pf_vf *vf, uint8_t *msg,
return ret;
}
- /* only have 1 VSI by default */
- len = sizeof(struct virtchnl_vf_resource) +
- I40E_DEFAULT_VF_VSI_NUM *
- sizeof(struct virtchnl_vsi_resource);
-
- vf_res = rte_zmalloc("i40e_vf_res", len, 0);
- if (vf_res == NULL) {
- PMD_DRV_LOG(ERR, "failed to allocate mem");
- ret = I40E_ERR_NO_MEMORY;
- vf_res = NULL;
- len = 0;
- goto send_msg;
- }
-
if (VF_IS_V10(&vf->version)) /* doesn't support offload negotiate */
vf->request_caps = VIRTCHNL_VF_OFFLOAD_L2 |
VIRTCHNL_VF_OFFLOAD_VLAN;
@@ -377,11 +368,8 @@ i40e_pf_host_process_cmd_get_vf_resource(struct i40e_pf_vf *vf, uint8_t *msg,
rte_ether_addr_copy(&vf->mac_addr,
(struct rte_ether_addr *)vf_res->vsi_res[0].default_mac_addr);
-send_msg:
i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_GET_VF_RESOURCES,
ret, (uint8_t *)vf_res, len);
- rte_free(vf_res);
-
return ret;
}
--
2.47.3
More information about the dev
mailing list