DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>
Subject: [PATCH 27.03 4/6] net/idpf: use stack storage for virtchnl messages
Date: Mon, 16 Nov 2026 16:09:30 +0000	[thread overview]
Message-ID: <20261116160932.1006354-5-bruce.richardson@intel.com> (raw)
In-Reply-To: <20261116160932.1006354-1-bruce.richardson@intel.com>

Rather than using malloc and free for virtchnl message buffers whose
maximum size is known at compile time, define them on the stack using
RTE_DEFINE_FLEX. This removes the allocation failure and cleanup paths.

As part of this, the queue chunks in idpf_vc_queues_ena_dis() are now
filled sequentially rather than indexed by queue type.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 drivers/net/intel/idpf/idpf_common_device.c   | 27 ++-----
 drivers/net/intel/idpf/idpf_common_virtchnl.c | 77 +++++++------------
 2 files changed, 36 insertions(+), 68 deletions(-)

diff --git a/drivers/net/intel/idpf/idpf_common_device.c b/drivers/net/intel/idpf/idpf_common_device.c
index 1586dae96c..d3cb74f4a8 100644
--- a/drivers/net/intel/idpf/idpf_common_device.c
+++ b/drivers/net/intel/idpf/idpf_common_device.c
@@ -157,23 +157,15 @@ idpf_init_mbx(struct idpf_hw *hw)
 static int
 idpf_get_pkt_type(struct idpf_adapter *adapter)
 {
-	struct virtchnl2_get_ptype_info *req_ptype_info;
-	struct virtchnl2_get_ptype_info *recv_ptype_info;
+	struct virtchnl2_get_ptype_info req_ptype_msg = {0};
+	struct virtchnl2_get_ptype_info *req_ptype_info = &req_ptype_msg;
+	RTE_DEFINE_FLEX_BYTES(struct virtchnl2_get_ptype_info, recv_ptype_info,
+			IDPF_DFLT_MBX_BUF_SIZE);
 	uint16_t recv_num_ptypes = 0;
 	uint16_t ptype_offset, i, j;
 	uint16_t start_ptype_id = 0;
 	int ret;
 
-	req_ptype_info = rte_zmalloc("req_ptype_info", IDPF_DFLT_MBX_BUF_SIZE, 0);
-	if (req_ptype_info == NULL)
-		return -ENOMEM;
-
-	recv_ptype_info = rte_zmalloc("recv_ptype_info", IDPF_DFLT_MBX_BUF_SIZE, 0);
-	if (recv_ptype_info == NULL) {
-		ret = -ENOMEM;
-		goto free_req_ptype_info;
-	}
-
 	while (start_ptype_id < IDPF_MAX_PKT_TYPE) {
 		memset(req_ptype_info, 0, sizeof(*req_ptype_info));
 		memset(recv_ptype_info, 0, sizeof(*recv_ptype_info));
@@ -188,13 +180,13 @@ idpf_get_pkt_type(struct idpf_adapter *adapter)
 		ret = idpf_vc_ptype_info_query(adapter, req_ptype_info, recv_ptype_info);
 		if (ret != 0) {
 			DRV_LOG(ERR, "Fail to query packet type information");
-			goto free_recv_ptype_info;
+			goto out;
 		}
 
 		recv_num_ptypes += rte_le_to_cpu_16(recv_ptype_info->num_ptypes);
 		if (recv_num_ptypes > IDPF_MAX_PKT_TYPE) {
 			ret = -EINVAL;
-			goto free_recv_ptype_info;
+			goto out;
 		}
 
 		start_ptype_id = rte_le_to_cpu_16(req_ptype_info->start_ptype_id) +
@@ -213,7 +205,7 @@ idpf_get_pkt_type(struct idpf_adapter *adapter)
 			ptype_offset += IDPF_GET_PTYPE_SIZE(ptype);
 			if (ptype_offset > IDPF_DFLT_MBX_BUF_SIZE) {
 				ret = -EINVAL;
-				goto free_recv_ptype_info;
+				goto out;
 			}
 
 			for (j = 0; j < ptype->proto_id_count; j++) {
@@ -374,10 +366,7 @@ idpf_get_pkt_type(struct idpf_adapter *adapter)
 		}
 	}
 
-free_recv_ptype_info:
-	rte_free(recv_ptype_info);
-free_req_ptype_info:
-	rte_free(req_ptype_info);
+out:
 	clear_cmd(adapter);
 	return ret;
 }
diff --git a/drivers/net/intel/idpf/idpf_common_virtchnl.c b/drivers/net/intel/idpf/idpf_common_virtchnl.c
index 4befd5fc83..2159dd9ad1 100644
--- a/drivers/net/intel/idpf/idpf_common_virtchnl.c
+++ b/drivers/net/intel/idpf/idpf_common_virtchnl.c
@@ -463,15 +463,15 @@ int
 idpf_vc_rss_key_set(struct idpf_vport *vport)
 {
 	struct idpf_adapter *adapter = vport->adapter;
-	struct virtchnl2_rss_key *rss_key;
+	RTE_DEFINE_FLEX(struct virtchnl2_rss_key, rss_key, key, IDPF_RSS_KEY_LEN - 1);
 	struct idpf_cmd_info args;
 	int len, err;
 
+	if (vport->rss_key_size > IDPF_RSS_KEY_LEN)
+		return -EINVAL;
+
 	len = sizeof(*rss_key) + sizeof(rss_key->key[0]) *
 		(vport->rss_key_size - 1);
-	rss_key = rte_zmalloc("rss_key", len, 0);
-	if (rss_key == NULL)
-		return -ENOMEM;
 
 	rss_key->vport_id = vport->vport_id;
 	rss_key->key_len = vport->rss_key_size;
@@ -489,7 +489,6 @@ idpf_vc_rss_key_set(struct idpf_vport *vport)
 	if (err != 0)
 		DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_SET_RSS_KEY");
 
-	rte_free(rss_key);
 	return err;
 }
 
@@ -781,15 +780,13 @@ idpf_vc_ena_dis_one_queue(struct idpf_vport *vport, uint16_t qid,
 			  uint32_t type, bool on)
 {
 	struct idpf_adapter *adapter = vport->adapter;
-	struct virtchnl2_del_ena_dis_queues *queue_select;
+	struct virtchnl2_del_ena_dis_queues queue_select_msg = {0};
+	struct virtchnl2_del_ena_dis_queues *queue_select = &queue_select_msg;
 	struct virtchnl2_queue_chunk *queue_chunk;
 	struct idpf_cmd_info args;
 	int err, len;
 
 	len = sizeof(struct virtchnl2_del_ena_dis_queues);
-	queue_select = rte_zmalloc("queue_select", len, 0);
-	if (queue_select == NULL)
-		return -ENOMEM;
 
 	queue_chunk = queue_select->chunks.chunks;
 	queue_select->chunks.num_chunks = 1;
@@ -810,7 +807,6 @@ idpf_vc_ena_dis_one_queue(struct idpf_vport *vport, uint16_t qid,
 		DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_%s_QUEUES",
 			on ? "ENABLE" : "DISABLE");
 
-	rte_free(queue_select);
 	return err;
 }
 
@@ -819,15 +815,13 @@ int
 idpf_vc_ena_dis_one_queue_vcpf(struct idpf_adapter *adapter, uint16_t qid,
 			  uint32_t type, bool on)
 {
-	struct virtchnl2_del_ena_dis_queues *queue_select;
+	struct virtchnl2_del_ena_dis_queues queue_select_msg = {0};
+	struct virtchnl2_del_ena_dis_queues *queue_select = &queue_select_msg;
 	struct virtchnl2_queue_chunk *queue_chunk;
 	struct idpf_cmd_info args;
 	int err, len;
 
 	len = sizeof(struct virtchnl2_del_ena_dis_queues);
-	queue_select = rte_zmalloc("queue_select", len, 0);
-	if (queue_select == NULL)
-		return -ENOMEM;
 
 	queue_chunk = queue_select->chunks.chunks;
 	queue_select->chunks.num_chunks = 1;
@@ -848,7 +842,6 @@ idpf_vc_ena_dis_one_queue_vcpf(struct idpf_adapter *adapter, uint16_t qid,
 		DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_%s_QUEUES",
 			on ? "ENABLE" : "DISABLE");
 
-	rte_free(queue_select);
 	return err;
 }
 
@@ -893,16 +886,18 @@ idpf_vc_queue_switch(struct idpf_vport *vport, uint16_t qid,
 }
 
 #define IDPF_RXTX_QUEUE_CHUNKS_NUM	2
+#define IDPF_RXTX_QUEUE_CHUNKS_MAX	(IDPF_RXTX_QUEUE_CHUNKS_NUM + 2)
 RTE_EXPORT_INTERNAL_SYMBOL(idpf_vc_queues_ena_dis)
 int
 idpf_vc_queues_ena_dis(struct idpf_vport *vport, bool enable)
 {
 	struct idpf_adapter *adapter = vport->adapter;
-	struct virtchnl2_del_ena_dis_queues *queue_select;
+	RTE_DEFINE_FLEX(struct virtchnl2_del_ena_dis_queues, queue_select, chunks.chunks,
+			IDPF_RXTX_QUEUE_CHUNKS_MAX - 1);
 	struct virtchnl2_queue_chunk *queue_chunk;
 	uint32_t type;
 	struct idpf_cmd_info args;
-	uint16_t num_chunks;
+	uint16_t num_chunks, idx = 0;
 	int err, len;
 
 	num_chunks = IDPF_RXTX_QUEUE_CHUNKS_NUM;
@@ -913,38 +908,35 @@ idpf_vc_queues_ena_dis(struct idpf_vport *vport, bool enable)
 
 	len = sizeof(struct virtchnl2_del_ena_dis_queues) +
 		sizeof(struct virtchnl2_queue_chunk) * (num_chunks - 1);
-	queue_select = rte_zmalloc("queue_select", len, 0);
-	if (queue_select == NULL)
-		return -ENOMEM;
 
 	queue_chunk = queue_select->chunks.chunks;
 	queue_select->chunks.num_chunks = num_chunks;
 	queue_select->vport_id = vport->vport_id;
 
 	type = VIRTCHNL_QUEUE_TYPE_RX;
-	queue_chunk[type].type = type;
-	queue_chunk[type].start_queue_id = vport->chunks_info.rx_start_qid;
-	queue_chunk[type].num_queues = vport->num_rx_q;
+	queue_chunk[idx].type = type;
+	queue_chunk[idx].start_queue_id = vport->chunks_info.rx_start_qid;
+	queue_chunk[idx++].num_queues = vport->num_rx_q;
 
 	type = VIRTCHNL2_QUEUE_TYPE_TX;
-	queue_chunk[type].type = type;
-	queue_chunk[type].start_queue_id = vport->chunks_info.tx_start_qid;
-	queue_chunk[type].num_queues = vport->num_tx_q;
+	queue_chunk[idx].type = type;
+	queue_chunk[idx].start_queue_id = vport->chunks_info.tx_start_qid;
+	queue_chunk[idx++].num_queues = vport->num_tx_q;
 
 	if (vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) {
 		type = VIRTCHNL2_QUEUE_TYPE_RX_BUFFER;
-		queue_chunk[type].type = type;
-		queue_chunk[type].start_queue_id =
+		queue_chunk[idx].type = type;
+		queue_chunk[idx].start_queue_id =
 			vport->chunks_info.rx_buf_start_qid;
-		queue_chunk[type].num_queues = vport->num_rx_bufq;
+		queue_chunk[idx++].num_queues = vport->num_rx_bufq;
 	}
 
 	if (vport->txq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) {
 		type = VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION;
-		queue_chunk[type].type = type;
-		queue_chunk[type].start_queue_id =
+		queue_chunk[idx].type = type;
+		queue_chunk[idx].start_queue_id =
 			vport->chunks_info.tx_compl_start_qid;
-		queue_chunk[type].num_queues = vport->num_tx_complq;
+		queue_chunk[idx++].num_queues = vport->num_tx_complq;
 	}
 
 	args.ops = enable ? VIRTCHNL2_OP_ENABLE_QUEUES :
@@ -958,7 +950,6 @@ idpf_vc_queues_ena_dis(struct idpf_vport *vport, bool enable)
 		DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_%s_QUEUES",
 			enable ? "ENABLE" : "DISABLE");
 
-	rte_free(queue_select);
 	return err;
 }
 
@@ -1044,7 +1035,8 @@ int
 idpf_vc_rxq_config(struct idpf_vport *vport, struct idpf_rx_queue *rxq)
 {
 	struct idpf_adapter *adapter = vport->adapter;
-	struct virtchnl2_config_rx_queues *vc_rxqs = NULL;
+	RTE_DEFINE_FLEX(struct virtchnl2_config_rx_queues, vc_rxqs, qinfo,
+			IDPF_RXQ_PER_GRP + IDPF_RX_BUFQ_PER_GRP - 1);
 	struct virtchnl2_rxq_info *rxq_info;
 	struct idpf_cmd_info args;
 	uint16_t num_qs;
@@ -1057,12 +1049,6 @@ idpf_vc_rxq_config(struct idpf_vport *vport, struct idpf_rx_queue *rxq)
 
 	size = sizeof(*vc_rxqs) + (num_qs - 1) *
 		sizeof(struct virtchnl2_rxq_info);
-	vc_rxqs = rte_zmalloc("cfg_rxqs", size, 0);
-	if (vc_rxqs == NULL) {
-		DRV_LOG(ERR, "Failed to allocate virtchnl2_config_rx_queues");
-		err = -ENOMEM;
-		return err;
-	}
 	vc_rxqs->vport_id = vport->vport_id;
 	vc_rxqs->num_qinfo = num_qs;
 	if (vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SINGLE) {
@@ -1122,7 +1108,6 @@ idpf_vc_rxq_config(struct idpf_vport *vport, struct idpf_rx_queue *rxq)
 	args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
 
 	err = idpf_vc_cmd_execute(adapter, &args);
-	rte_free(vc_rxqs);
 	if (err != 0)
 		DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_CONFIG_RX_QUEUES");
 
@@ -1170,7 +1155,8 @@ int
 idpf_vc_txq_config(struct idpf_vport *vport, struct ci_tx_queue *txq)
 {
 	struct idpf_adapter *adapter = vport->adapter;
-	struct virtchnl2_config_tx_queues *vc_txqs = NULL;
+	RTE_DEFINE_FLEX(struct virtchnl2_config_tx_queues, vc_txqs, qinfo,
+			IDPF_TXQ_PER_GRP + IDPF_TX_COMPLQ_PER_GRP - 1);
 	struct virtchnl2_txq_info *txq_info;
 	struct idpf_cmd_info args;
 	uint16_t num_qs;
@@ -1183,12 +1169,6 @@ idpf_vc_txq_config(struct idpf_vport *vport, struct ci_tx_queue *txq)
 
 	size = sizeof(*vc_txqs) + (num_qs - 1) *
 		sizeof(struct virtchnl2_txq_info);
-	vc_txqs = rte_zmalloc("cfg_txqs", size, 0);
-	if (vc_txqs == NULL) {
-		DRV_LOG(ERR, "Failed to allocate virtchnl2_config_tx_queues");
-		err = -ENOMEM;
-		return err;
-	}
 	vc_txqs->vport_id = vport->vport_id;
 	vc_txqs->num_qinfo = num_qs;
 
@@ -1230,7 +1210,6 @@ idpf_vc_txq_config(struct idpf_vport *vport, struct ci_tx_queue *txq)
 	args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
 
 	err = idpf_vc_cmd_execute(adapter, &args);
-	rte_free(vc_txqs);
 	if (err != 0)
 		DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_CONFIG_TX_QUEUES");
 
-- 
2.55.0


  parent reply	other threads:[~2026-11-16 16:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 16:09 [PATCH 27.03 0/6] eliminate unnecessary dynamic allocation Bruce Richardson
2026-11-16 16:09 ` [PATCH 27.03 1/6] eal: add macros for local variable-length structure buffers Bruce Richardson
2026-11-16 16:09 ` [PATCH 27.03 2/6] net/iavf: use stack storage for virtchnl messages Bruce Richardson
2026-11-16 16:09 ` [PATCH 27.03 3/6] net/ice: use stack storage for function-local buffers Bruce Richardson
2026-11-16 16:09 ` Bruce Richardson [this message]
2026-11-16 16:09 ` [PATCH 27.03 5/6] net/cpfl: " Bruce Richardson
2026-11-16 16:09 ` [PATCH 27.03 6/6] net/i40e: " Bruce Richardson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261116160932.1006354-5-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox