Skip to contentSkip to conversation

net/iavf: remove global adminq response buffer

PATCH Superseded Anatoly Burakov 2 participants 23 messages Feb 25 – Apr 3 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/iavf: remove global adminq response buffer

In many places where we are calling down into virtchnl, we are using a globally allocated adminq response buffer. This is unnecessary, so replace with adminq buffers allocated on stack.

---
 drivers/net/intel/iavf/iavf.h        |   1 -
 drivers/net/intel/iavf/iavf_ethdev.c |  13 --
 drivers/net/intel/iavf/iavf_vchnl.c  | 240 +++++++++++++++------------
 3 files changed, 136 insertions(+), 118 deletions(-)
drivers/net/intel/iavf/iavf.h +0 -1
index f9bb398a77..c44ef54766 100644
@@ -242,7 +242,6 @@ struct iavf_info {
 	volatile RTE_ATOMIC(enum virtchnl_ops) pend_cmd; /* pending command not finished */
 	RTE_ATOMIC(uint32_t) pend_cmd_count;
 	int cmd_retval; /* return value of the cmd response from PF */
-	uint8_t *aq_resp; /* buffer to store the adminq response from PF */
 
 	/** iAVF watchdog enable */
 	bool watchdog_enabled;
drivers/net/intel/iavf/iavf_ethdev.c +0 -13
index 26e7febecf..d32a3c56a1 100644
@@ -2545,11 +2545,6 @@ iavf_init_vf(struct rte_eth_dev *dev)
 		goto err;
 	}
 
-	vf->aq_resp = rte_zmalloc("vf_aq_resp", IAVF_AQ_BUF_SZ, 0);
-	if (!vf->aq_resp) {
-		PMD_INIT_LOG(ERR, "unable to allocate vf_aq_resp memory");
-		goto err_aq;
-	}
 	if (iavf_check_api_version(adapter) != 0) {
 		PMD_INIT_LOG(ERR, "check_api version failed");
 		goto err_api;
@@ -2623,8 +2618,6 @@ iavf_init_vf(struct rte_eth_dev *dev)
 	rte_free(vf->vf_res);
 	vf->vsi_res = NULL;
 err_api:
-	rte_free(vf->aq_resp);
-err_aq:
 	iavf_shutdown_adminq(hw);
 err:
 	return -1;
@@ -2642,9 +2635,6 @@ iavf_uninit_vf(struct rte_eth_dev *dev)
 	vf->vsi_res = NULL;
 	vf->vf_res = NULL;
 
-	rte_free(vf->aq_resp);
-	vf->aq_resp = NULL;
-
 	rte_free(vf->qos_cap);
 	vf->qos_cap = NULL;
 
@@ -2997,9 +2987,6 @@ iavf_dev_close(struct rte_eth_dev *dev)
 	vf->vsi_res = NULL;
 	vf->vf_res = NULL;
 
-	rte_free(vf->aq_resp);
-	vf->aq_resp = NULL;
-
 	/*
 	 * If the VF is reset via VFLR, the device will be knocked out of bus
 	 * master mode, and the driver will fail to recover from the reset. Fix
drivers/net/intel/iavf/iavf_vchnl.c +136 -104

786 lines not on this page · raw message

Signature · 1 line
2.47.3
#1 lore raw

PATCH v2 1/1 net/iavf: remove global adminq response buffer

In many places where we are calling down into virtchnl, we are using a globally allocated adminq response buffer. This is unnecessary, so replace with adminq buffers allocated on stack.

---
 drivers/net/intel/iavf/iavf.h        |   3 +-
 drivers/net/intel/iavf/iavf_ethdev.c |  43 ++---
 drivers/net/intel/iavf/iavf_vchnl.c  | 250 +++++++++++++++------------
 3 files changed, 156 insertions(+), 140 deletions(-)
drivers/net/intel/iavf/iavf.h +1 -2
index f9bb398a77..33ba3115d0 100644
@@ -242,7 +242,6 @@ struct iavf_info {
 	volatile RTE_ATOMIC(enum virtchnl_ops) pend_cmd; /* pending command not finished */
 	RTE_ATOMIC(uint32_t) pend_cmd_count;
 	int cmd_retval; /* return value of the cmd response from PF */
-	uint8_t *aq_resp; /* buffer to store the adminq response from PF */
 
 	/** iAVF watchdog enable */
 	bool watchdog_enabled;
@@ -517,7 +516,7 @@ int iavf_dev_link_update(struct rte_eth_dev *dev,
 			__rte_unused int wait_to_complete);
 void iavf_dev_alarm_handler(void *param);
 int iavf_query_stats(struct iavf_adapter *adapter,
-		    struct virtchnl_eth_stats **pstats);
+		    struct virtchnl_eth_stats *pstats);
 int iavf_config_promisc(struct iavf_adapter *adapter, bool enable_unicast,
 		       bool enable_multicast);
 int iavf_add_del_eth_addr(struct iavf_adapter *adapter,
drivers/net/intel/iavf/iavf_ethdev.c +15 -28

104 lines not on this page · raw message

drivers/net/intel/iavf/iavf_vchnl.c +140 -110

807 lines not on this page · raw message

Signature · 1 line
2.47.3
#2 lore raw
Quoted 6 lines · Anatoly Burakov

In many places where we are calling down into virtchnl, we are using a globally allocated adminq response buffer. This is unnecessary, so replace with adminq buffers allocated on stack.

---

Changes from v1:

Stats query was passing in a pointer-to-pointer and storing pointer to global adminq response buffer as output parameter, so changing that to a local buffer resulted in storing a pointer to a buffer that was stack allocated (i.e. introduced a use-after-free).

I've changed that to allocate the stats structure on the stack and write into that, instead of returning a pointer to output buffer and reading from it.

Signature · 2 lines
Thanks,
Anatoly
#4 lore raw
Quoted 10 lines · Bruce Richardson
Quoted 6 lines · Anatoly Burakov

In many places where we are calling down into virtchnl, we are using a globally allocated adminq response buffer. This is unnecessary, so replace with adminq buffers allocated on stack.

---

Applied to dpdk-next-net-intel.

I've actually removed this patch from next-net-intel as we are seeing failures in Intel CI on next-net-intel branch and this patch has been identified as the culprit. Please investigate and resubmit a new patch for 26.07.

Thanks,
/Bruce

#5 lore raw

v3 cover Reduce reliance on global response buffer in IAVF

In reply to Anatoly Burakov

In many places where we are calling down into virtchnl, we are using a globally allocated adminq response buffer. This is unnecessary, so replace with adminq buffers allocated on stack. However, because IAVF virtchnl message queue works asynchronously in most cases, we can't remove the global buffer entirely, and we need to do some cleanup and refactoring to be able to reduce our usage of these buffers. This patchset does that.

v1 -> v2:
- Stats query was passing in a pointer-to-pointer and storing pointer to global adminq response buffer as output parameter, so changing that to a local buffer resulted in storing a pointer to a buffer that was stack allocated (i.e. introduced a use-after-free).

v2 -> v3:
- Reworked the virtchnl message handling to not rely on implicit behavior
- Split up into 8 patches for easy review

Anatoly Burakov (8):
net/iavf: avoid passing around pointers
net/iavf: add a variable for hena
net/iavf: add virtchnl interrupt enable flag
net/iavf: rework "async" virtchnl requests
net/iavf: refactor sending virtchnl messages
net/iavf: respect output buffer in virtchnl
net/iavf: do not use global virtchnl buffer
net/iavf: embed virtchnl response buffer

 drivers/net/intel/iavf/iavf.h        |  58 +---
 drivers/net/intel/iavf/iavf_ethdev.c |  50 ++-
 drivers/net/intel/iavf/iavf_vchnl.c  | 483 ++++++++++++++++-----------
 3 files changed, 304 insertions(+), 287 deletions(-)
Signature · 1 line
2.47.3
#6 lore raw

PATCH v3 1/8 net/iavf: avoid passing around pointers

Currently, when querying the stats for IAVF, we pass a pointer-to-pointer and then use it as an input for another function. It does not really need to be a pointer because it is populated from virtchnl command response anyway. Replace it with passing in a stack-allocated struct, and pass it into the stats query function.

---
 drivers/net/intel/iavf/iavf.h        |  2 +-
 drivers/net/intel/iavf/iavf_ethdev.c | 34 ++++++++++++++--------------
 drivers/net/intel/iavf/iavf_vchnl.c  |  5 ++--
 3 files changed, 20 insertions(+), 21 deletions(-)
drivers/net/intel/iavf/iavf.h +1 -1
index 403c61e2e8..b2389e0bbd 100644
@@ -518,7 +518,7 @@ int iavf_dev_link_update(struct rte_eth_dev *dev,
 			__rte_unused int wait_to_complete);
 void iavf_dev_alarm_handler(void *param);
 int iavf_query_stats(struct iavf_adapter *adapter,
-		    struct virtchnl_eth_stats **pstats);
+		    struct virtchnl_eth_stats *pstats);
 int iavf_config_promisc(struct iavf_adapter *adapter, bool enable_unicast,
 		       bool enable_multicast);
 int iavf_add_del_eth_addr(struct iavf_adapter *adapter,
drivers/net/intel/iavf/iavf_ethdev.c +17 -17
index 1eca20bc9a..e3690cce11 100644
@@ -1793,7 +1793,7 @@ iavf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
 	struct iavf_vsi *vsi = &vf->vsi;
-	struct virtchnl_eth_stats *pstats = NULL;
+	struct virtchnl_eth_stats pstats;
 	int ret;
 
 	ret = iavf_query_stats(adapter, &pstats);
@@ -1801,16 +1801,16 @@ iavf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
 		uint8_t crc_stats_len = (dev->data->dev_conf.rxmode.offloads &
 					 RTE_ETH_RX_OFFLOAD_KEEP_CRC) ? 0 :
 					 RTE_ETHER_CRC_LEN;
-		iavf_update_stats(vsi, pstats);
-		stats->ipackets = pstats->rx_unicast + pstats->rx_multicast +
-				pstats->rx_broadcast - pstats->rx_discards;
-		stats->opackets = pstats->tx_broadcast + pstats->tx_multicast +
-						pstats->tx_unicast;
-		stats->imissed = pstats->rx_discards;
-		stats->oerrors = pstats->tx_errors + pstats->tx_discards;
-		stats->ibytes = pstats->rx_bytes;
+		iavf_update_stats(vsi, &pstats);
+		stats->ipackets = pstats.rx_unicast + pstats.rx_multicast +
+				pstats.rx_broadcast - pstats.rx_discards;
+		stats->opackets = pstats.tx_broadcast + pstats.tx_multicast +
+						pstats.tx_unicast;
+		stats->imissed = pstats.rx_discards;
+		stats->oerrors = pstats.tx_errors + pstats.tx_discards;
+		stats->ibytes = pstats.rx_bytes;
 		stats->ibytes -= stats->ipackets * crc_stats_len;
-		stats->obytes = pstats->tx_bytes;
+		stats->obytes = pstats.tx_bytes;
 	} else {
 		PMD_DRV_LOG(ERR, "Get statistics failed");
 	}
@@ -1825,15 +1825,15 @@ iavf_dev_stats_reset(struct rte_eth_dev *dev)
 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
 	struct iavf_vsi *vsi = &vf->vsi;
-	struct virtchnl_eth_stats *pstats = NULL;
+	struct virtchnl_eth_stats stats;
 
 	/* read stat values to clear hardware registers */
-	ret = iavf_query_stats(adapter, &pstats);
+	ret = iavf_query_stats(adapter, &stats);
 	if (ret != 0)
 		return ret;
 
 	/* set stats offset base on current values */
-	vsi->eth_stats_offset.eth_stats = *pstats;
+	vsi->eth_stats_offset.eth_stats = stats;
 
 	return 0;
 }
@@ -1909,21 +1909,21 @@ static int iavf_dev_xstats_get(struct rte_eth_dev *dev,
 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
 	struct iavf_vsi *vsi = &vf->vsi;
-	struct virtchnl_eth_stats *pstats = NULL;
+	struct virtchnl_eth_stats stats;
 	struct iavf_eth_xstats iavf_xtats = {{0}};
 
 	if (n < IAVF_NB_XSTATS)
 		return IAVF_NB_XSTATS;
 
-	ret = iavf_query_stats(adapter, &pstats);
+	ret = iavf_query_stats(adapter, &stats);
 	if (ret != 0)
 		return 0;
 
 	if (!xstats)
 		return 0;
 
-	iavf_update_stats(vsi, pstats);
-	iavf_xtats.eth_stats = *pstats;
+	iavf_update_stats(vsi, &stats);
+	iavf_xtats.eth_stats = stats;
 
 	if (iavf_ipsec_crypto_supported(adapter))
 		iavf_dev_update_ipsec_xstats(dev, &iavf_xtats.ips_stats);
drivers/net/intel/iavf/iavf_vchnl.c +2 -3
index 08dd6f2d7f..a1dc573841 100644
@@ -1483,7 +1483,7 @@ iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
 
 int
 iavf_query_stats(struct iavf_adapter *adapter,
-		struct virtchnl_eth_stats **pstats)
+		struct virtchnl_eth_stats *pstats)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
 	struct virtchnl_queue_select q_stats;
@@ -1504,10 +1504,9 @@ iavf_query_stats(struct iavf_adapter *adapter,
 	err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
 	if (err) {
 		PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
-		*pstats = NULL;
 		return err;
 	}
-	*pstats = (struct virtchnl_eth_stats *)args.out_buffer;
+	*pstats = *(struct virtchnl_eth_stats *)args.out_buffer;
 	return 0;
 }
 
Signature · 1 line
2.47.3
Acked-by on v3 1/8
#7 lore raw

Re: [PATCH v3 1/8] net/iavf: avoid passing around pointers

Quoted 7 lines · Anatoly Burakov

Currently, when querying the stats for IAVF, we pass a pointer-to-pointer and then use it as an input for another function. It does not really need to be a pointer because it is populated from virtchnl command response anyway. Replace it with passing in a stack-allocated struct, and pass it into the stats query function.

#8 lore raw

PATCH v3 2/8 net/iavf: add a variable for hena

In reply to Anatoly Burakov

Currently, we read RSS hena value directly from output buffer using an in place pointer cast. Use a variable instead.

---
 drivers/net/intel/iavf/iavf_vchnl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/intel/iavf/iavf_vchnl.c +3 -1
index a1dc573841..d97bdf0dc1 100644
@@ -1933,6 +1933,7 @@ int
 iavf_get_hena_caps(struct iavf_adapter *adapter, uint64_t *caps)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	struct virtchnl_rss_hena *hena;
 	struct iavf_cmd_info args;
 	int err;
 
@@ -1949,7 +1950,8 @@ iavf_get_hena_caps(struct iavf_adapter *adapter, uint64_t *caps)
 		return err;
 	}
 
-	*caps = ((struct virtchnl_rss_hena *)args.out_buffer)->hena;
+	hena = (struct virtchnl_rss_hena *)args.out_buffer;
+	*caps = hena->hena;
 	return 0;
 }
 
Signature · 1 line
2.47.3
Acked-by on v3 2/8
#9 lore raw

Re: [PATCH v3 2/8] net/iavf: add a variable for hena

Quoted 5 lines · Anatoly Burakov

Currently, we read RSS hena value directly from output buffer using an in place pointer cast. Use a variable instead.

---

Not sure I see that much point in this patch alone, but it's harmless.

Quoted 28 lines
 drivers/net/intel/iavf/iavf_vchnl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/intel/iavf/iavf_vchnl.c +3 -1
index a1dc573841..d97bdf0dc1 100644
@@ -1933,6 +1933,7 @@ int
 iavf_get_hena_caps(struct iavf_adapter *adapter, uint64_t *caps)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	struct virtchnl_rss_hena *hena;
 	struct iavf_cmd_info args;
 	int err;
 
@@ -1949,7 +1950,8 @@ iavf_get_hena_caps(struct iavf_adapter *adapter, uint64_t *caps)
 		return err;
 	}
 
-	*caps = ((struct virtchnl_rss_hena *)args.out_buffer)->hena;
+	hena = (struct virtchnl_rss_hena *)args.out_buffer;
+	*caps = hena->hena;
 	return 0;
 }
 
Signature · 1 line
2.47.3
#10 lore raw

PATCH v3 3/8 net/iavf: add virtchnl interrupt enable flag

In reply to Anatoly Burakov

For some functionality, we will need to know if the virtchnl message queue interrupts are enabled (i.e. if the new virtchnl messages will be delivered into an interrupt thread as opposed to having to directly poll the queue). Add such flag and track its status during init/close.

---
 drivers/net/intel/iavf/iavf.h        | 1 +
 drivers/net/intel/iavf/iavf_ethdev.c | 3 +++
 2 files changed, 4 insertions(+)
drivers/net/intel/iavf/iavf.h +1 -0
index b2389e0bbd..cf98d12247 100644
@@ -243,6 +243,7 @@ struct iavf_info {
 	RTE_ATOMIC(uint32_t) pend_cmd_count;
 	int cmd_retval; /* return value of the cmd response from PF */
 	uint8_t *aq_resp; /* buffer to store the adminq response from PF */
+	bool aq_intr_enabled;
 
 	/** iAVF watchdog enable */
 	bool watchdog_enabled;
drivers/net/intel/iavf/iavf_ethdev.c +3 -0
index e3690cce11..9fdebec0f4 100644
@@ -2853,6 +2853,7 @@ iavf_dev_init(struct rte_eth_dev *eth_dev)
 
 	/* configure and enable device interrupt */
 	iavf_enable_irq0(hw);
+	vf->aq_intr_enabled = true;
 
 	ret = iavf_flow_init(adapter);
 	if (ret) {
@@ -2900,6 +2901,7 @@ iavf_dev_init(struct rte_eth_dev *eth_dev)
 	iavf_security_ctx_destroy(adapter);
 
 flow_init_err:
+	vf->aq_intr_enabled = false;
 	iavf_disable_irq0(hw);
 
 	if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
@@ -2975,6 +2977,7 @@ iavf_dev_close(struct rte_eth_dev *dev)
 		iavf_config_promisc(adapter, false, false);
 
 	iavf_vf_reset(hw);
+	vf->aq_intr_enabled = false;
 	iavf_shutdown_adminq(hw);
 	if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
 		/* disable uio intr before callback unregister */
Signature · 1 line
2.47.3
Acked-by on v3 3/8
#11 lore raw

Re: [PATCH v3 3/8] net/iavf: add virtchnl interrupt enable flag

Quoted 7 lines · Anatoly Burakov

For some functionality, we will need to know if the virtchnl message queue interrupts are enabled (i.e. if the new virtchnl messages will be delivered into an interrupt thread as opposed to having to directly poll the queue). Add such flag and track its status during init/close.

---

#12 lore raw

PATCH v3 4/8 net/iavf: rework "async" virtchnl requests

In reply to Anatoly Burakov

Currently, IPsec crypto requests are called with async parameter set to 1 on account of these requests generating two virtchnl responses instead of having just one, like all other requests.

However, this terminology is misleading, because in actuality *almost all* virtchnl requests are asynchronously implemented; that is, almost all of them will send a request into virtchnl command queue, and then expect to receive a virtchnl response in an interrupt thread, which will update the global "pending command" status and write into the global response buffer, while the pending request will simply check pending command status on a timer. So, for almost all requests, the command status is updated asynchronously. The only times this *doesn't* happen is 1) when the request is sent from an interrupt thread context, or 2) when the requests are sent at init time and the interrupt thread isn't active yet. In both of those cases we directly poll the virtchnl queue for responses.

To make things a little less confusing, remove the usage of "asynchronous" terminology across all callsites, and instead make it explicit that what we're actually interested in is the number of responses we are waiting for, and whether the thread is meant to directly poll the message queue or wait for interrupt thread to update command status, not whether the requests are "asynchronous". We also make it an implementation detail, not part of the API for executing VF commands.

---
 drivers/net/intel/iavf/iavf.h       |  53 --------
 drivers/net/intel/iavf/iavf_vchnl.c | 187 ++++++++++++++++++----------
 2 files changed, 121 insertions(+), 119 deletions(-)
drivers/net/intel/iavf/iavf.h +0 -53
index cf98d12247..440376c4ca 100644
@@ -432,59 +432,6 @@ struct iavf_cmd_info {
 	uint32_t out_size;      /* buffer size for response */
 };
 
-/* notify current command done. Only call in case execute
- * _atomic_set_cmd successfully.
- */
-static inline void
-_notify_cmd(struct iavf_info *vf, int msg_ret)
-{
-	vf->cmd_retval = msg_ret;
-	rte_wmb();
-	vf->pend_cmd = VIRTCHNL_OP_UNKNOWN;
-}
-
-/* clear current command. Only call in case execute
- * _atomic_set_cmd successfully.
- */
-static inline void
-_clear_cmd(struct iavf_info *vf)
-{
-	rte_wmb();
-	vf->pend_cmd = VIRTCHNL_OP_UNKNOWN;
-	vf->cmd_retval = VIRTCHNL_STATUS_SUCCESS;
-}
-
-/* Check there is pending cmd in execution. If none, set new command. */
-static inline int
-_atomic_set_cmd(struct iavf_info *vf, enum virtchnl_ops ops)
-{
-	enum virtchnl_ops op_unk = VIRTCHNL_OP_UNKNOWN;
-	int ret = rte_atomic_compare_exchange_strong_explicit(&vf->pend_cmd, &op_unk, ops,
-			rte_memory_order_acquire, rte_memory_order_acquire);
-
-	if (!ret)
-		PMD_DRV_LOG(ERR, "There is incomplete cmd %d", vf->pend_cmd);
-
-	rte_atomic_store_explicit(&vf->pend_cmd_count, 1, rte_memory_order_relaxed);
-
-	return !ret;
-}
-
-/* Check there is pending cmd in execution. If none, set new command. */
-static inline int
-_atomic_set_async_response_cmd(struct iavf_info *vf, enum virtchnl_ops ops)
-{
-	enum virtchnl_ops op_unk = VIRTCHNL_OP_UNKNOWN;
-	int ret = rte_atomic_compare_exchange_strong_explicit(&vf->pend_cmd, &op_unk, ops,
-			rte_memory_order_acquire, rte_memory_order_acquire);
-
-	if (!ret)
-		PMD_DRV_LOG(ERR, "There is incomplete cmd %d", vf->pend_cmd);
-
-	rte_atomic_store_explicit(&vf->pend_cmd_count, 2, rte_memory_order_relaxed);
-
-	return !ret;
-}
 int iavf_check_api_version(struct iavf_adapter *adapter);
 int iavf_get_vf_resource(struct iavf_adapter *adapter);
 void iavf_dev_event_post(struct rte_eth_dev *dev,
drivers/net/intel/iavf/iavf_vchnl.c +121 -66

516 lines not on this page · raw message

Signature · 1 line
2.47.3
Acked-by on v3 4/8
#13 lore raw

Re: [PATCH v3 4/8] net/iavf: rework "async" virtchnl requests

Quoted 24 lines · Anatoly Burakov

Currently, IPsec crypto requests are called with async parameter set to 1 on account of these requests generating two virtchnl responses instead of having just one, like all other requests.

However, this terminology is misleading, because in actuality *almost all* virtchnl requests are asynchronously implemented; that is, almost all of them will send a request into virtchnl command queue, and then expect to receive a virtchnl response in an interrupt thread, which will update the global "pending command" status and write into the global response buffer, while the pending request will simply check pending command status on a timer. So, for almost all requests, the command status is updated asynchronously. The only times this *doesn't* happen is 1) when the request is sent from an interrupt thread context, or 2) when the requests are sent at init time and the interrupt thread isn't active yet. In both of those cases we directly poll the virtchnl queue for responses.

To make things a little less confusing, remove the usage of "asynchronous" terminology across all callsites, and instead make it explicit that what we're actually interested in is the number of responses we are waiting for, and whether the thread is meant to directly poll the message queue or wait for interrupt thread to update command status, not whether the requests are "asynchronous". We also make it an implementation detail, not part of the API for executing VF commands.

Quoted 1 line

One minor nit inline below.

Quoted 150 lines
---
 drivers/net/intel/iavf/iavf.h       |  53 --------
 drivers/net/intel/iavf/iavf_vchnl.c | 187 ++++++++++++++++++----------
 2 files changed, 121 insertions(+), 119 deletions(-)
drivers/net/intel/iavf/iavf.h +0 -53
index cf98d12247..440376c4ca 100644
@@ -432,59 +432,6 @@ struct iavf_cmd_info {
 	uint32_t out_size;      /* buffer size for response */
 };
 
-/* notify current command done. Only call in case execute
- * _atomic_set_cmd successfully.
- */
-static inline void
-_notify_cmd(struct iavf_info *vf, int msg_ret)
-{
-	vf->cmd_retval = msg_ret;
-	rte_wmb();
-	vf->pend_cmd = VIRTCHNL_OP_UNKNOWN;
-}
-
-/* clear current command. Only call in case execute
- * _atomic_set_cmd successfully.
- */
-static inline void
-_clear_cmd(struct iavf_info *vf)
-{
-	rte_wmb();
-	vf->pend_cmd = VIRTCHNL_OP_UNKNOWN;
-	vf->cmd_retval = VIRTCHNL_STATUS_SUCCESS;
-}
-
-/* Check there is pending cmd in execution. If none, set new command. */
-static inline int
-_atomic_set_cmd(struct iavf_info *vf, enum virtchnl_ops ops)
-{
-	enum virtchnl_ops op_unk = VIRTCHNL_OP_UNKNOWN;
-	int ret = rte_atomic_compare_exchange_strong_explicit(&vf->pend_cmd, &op_unk, ops,
-			rte_memory_order_acquire, rte_memory_order_acquire);
-
-	if (!ret)
-		PMD_DRV_LOG(ERR, "There is incomplete cmd %d", vf->pend_cmd);
-
-	rte_atomic_store_explicit(&vf->pend_cmd_count, 1, rte_memory_order_relaxed);
-
-	return !ret;
-}
-
-/* Check there is pending cmd in execution. If none, set new command. */
-static inline int
-_atomic_set_async_response_cmd(struct iavf_info *vf, enum virtchnl_ops ops)
-{
-	enum virtchnl_ops op_unk = VIRTCHNL_OP_UNKNOWN;
-	int ret = rte_atomic_compare_exchange_strong_explicit(&vf->pend_cmd, &op_unk, ops,
-			rte_memory_order_acquire, rte_memory_order_acquire);
-
-	if (!ret)
-		PMD_DRV_LOG(ERR, "There is incomplete cmd %d", vf->pend_cmd);
-
-	rte_atomic_store_explicit(&vf->pend_cmd_count, 2, rte_memory_order_relaxed);
-
-	return !ret;
-}
 int iavf_check_api_version(struct iavf_adapter *adapter);
 int iavf_get_vf_resource(struct iavf_adapter *adapter);
 void iavf_dev_event_post(struct rte_eth_dev *dev,
drivers/net/intel/iavf/iavf_vchnl.c +56 -5
index d97bdf0dc1..d240745f5c 100644
@@ -309,42 +309,97 @@ iavf_read_msg_from_pf(struct iavf_adapter *adapter, uint16_t buf_len,
 }
 
 static int
-iavf_execute_vf_cmd(struct iavf_adapter *adapter, struct iavf_cmd_info *args,
-	int async)
+iavf_set_pending_cmd(struct iavf_info *vf, enum virtchnl_ops ops,
+		    uint32_t resp_count)
+{
+	enum virtchnl_ops op_unk = VIRTCHNL_OP_UNKNOWN;
+	int ret = rte_atomic_compare_exchange_strong_explicit(&vf->pend_cmd,
+			&op_unk, ops, rte_memory_order_acquire,
+			rte_memory_order_acquire);
+
+	if (ret == 0) {
+		PMD_DRV_LOG(ERR, "There is incomplete cmd %d", vf->pend_cmd);
+		return -1;
+	}
+
+	rte_atomic_store_explicit(&vf->pend_cmd_count, resp_count,
+			rte_memory_order_relaxed);
+
+	return 0;
+}
+
+static inline void
+iavf_clear_pending_cmd(struct iavf_info *vf)
+{
+	rte_wmb();
+	vf->pend_cmd = VIRTCHNL_OP_UNKNOWN;
+	vf->cmd_retval = VIRTCHNL_STATUS_SUCCESS;
+}
+
+static inline void
+iavf_notify_pending_cmd(struct iavf_info *vf, int msg_ret)
+{
+	vf->cmd_retval = msg_ret;
+	rte_wmb();
+	vf->pend_cmd = VIRTCHNL_OP_UNKNOWN;
+}
+
+static int
+iavf_get_cmd_resp_count(enum virtchnl_ops op)
+{
+	switch (op) {
+	case VIRTCHNL_OP_RESET_VF:
+	case VIRTCHNL_OP_REQUEST_QUEUES:
+		/* These commands trigger reset and are not waited for */
+		return 0;
+	case VIRTCHNL_OP_INLINE_IPSEC_CRYPTO:
+		/* IPsec crypto commands generate two responses */
+		return 2;
+	default:
+		/* All other commands generate one response */
+		return 1;
+	}
+}
+
+static int
+iavf_execute_vf_cmd(struct iavf_adapter *adapter, struct iavf_cmd_info *args)
 {
 	struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
 	enum iavf_aq_result result;
 	enum iavf_status ret;
+	uint32_t resp_count;
 	int err = 0;
 	int i = 0;
 
 	if (vf->vf_reset)
 		return -EIO;
 
+	resp_count = iavf_get_cmd_resp_count(args->ops);
 
-	if (async) {
-		if (_atomic_set_async_response_cmd(vf, args->ops))
-			return -1;

drivers/net/intel/iavf/iavf_vchnl.c iavf_read_msg_from_pf(struct iavf_adapter *adapter, uint16_t buf_len, · line 385

Quoted 10 lines
drivers/net/intel/iavf/iavf_vchnl.c +6 -4
-	} else {
-		if (_atomic_set_cmd(vf, args->ops))
-			return -1;
-	}
+	/*
+	 * For some commands, we are not waiting for responses because they
+	 * produce a reset event. However, we still need to set pending command
+	 * to avoid sending commands while another one is already in progress.
+	 */
+	if (iavf_set_pending_cmd(vf, args->ops, RTE_MAX(1U, resp_count)))

Nit: according to coding style this should be explicitly "!= 0"

Quoted 2 lines
drivers/net/intel/iavf/iavf_vchnl.c +1 -0
+		return -1;
 

<snip>

#14 lore raw

PATCH v3 5/8 net/iavf: refactor sending virtchnl messages

In reply to Anatoly Burakov

Currently, there is a certain amount of duplication and unnecessary branching in the virtchnl message handling function which makes it difficult to read and reason about.

Refactor the function to achieve the following:

- clean and explicit distinction between synchronous and asynchronous ops
- common looping and error handling logic
- fewer and clearer special cases

---
 drivers/net/intel/iavf/iavf_vchnl.c | 151 +++++++++++++---------------
 1 file changed, 70 insertions(+), 81 deletions(-)
drivers/net/intel/iavf/iavf_vchnl.c +70 -81
index d240745f5c..3f6ce0dd89 100644
@@ -361,16 +361,66 @@ iavf_get_cmd_resp_count(enum virtchnl_ops op)
 	}
 }
 
+static int
+iavf_op_needs_poll(struct iavf_info *vf)
+{
+	/* Poll if interrupts disabled or we are in interrupt thread */
+	return !vf->aq_intr_enabled || rte_thread_is_intr();
+}
+
+static int
+iavf_wait_for_msg(struct iavf_adapter *adapter, struct iavf_cmd_info *args,
+		bool poll)
+{
+	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	int err = 0;
+	int i = 0;
+
+	if (args->out_buffer == NULL) {
+		PMD_DRV_LOG(ERR, "Invalid buffer for cmd %d response", args->ops);
+		return -EINVAL;
+	}
+
+	/* Wait for command completion */
+	do {
+		if (poll) {
+			enum iavf_aq_result result;
+			result = iavf_read_msg_from_pf(adapter, args->out_size,
+					args->out_buffer);
+			if (result == IAVF_MSG_CMD)
+				break;
+		} else {
+			/* check if interrupt thread has erased pending cmd */
+			if (vf->pend_cmd == VIRTCHNL_OP_UNKNOWN)
+				break;
+		}
+		iavf_msec_delay(ASQ_DELAY_MS);
+	} while (i++ < MAX_TRY_TIMES);
+
+	if (i >= MAX_TRY_TIMES) {
+		PMD_DRV_LOG(ERR, "No response for cmd %d", args->ops);
+		err = -EIO;
+	} else if (vf->cmd_retval == VIRTCHNL_STATUS_ERR_NOT_SUPPORTED) {
+		PMD_DRV_LOG(ERR, "Cmd %d not supported", args->ops);
+		err = -ENOTSUP;
+	} else if (vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
+		PMD_DRV_LOG(ERR, "Return failure %d for cmd %d",
+				vf->cmd_retval, args->ops);
+		err = -EINVAL;
+	}
+
+	return err;
+}
+
 static int
 iavf_execute_vf_cmd(struct iavf_adapter *adapter, struct iavf_cmd_info *args)
 {
 	struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
-	enum iavf_aq_result result;
-	enum iavf_status ret;
+	enum iavf_status status;
 	uint32_t resp_count;
-	int err = 0;
-	int i = 0;
+	bool poll = iavf_op_needs_poll(vf);
+	int err;
 
 	if (vf->vf_reset)
 		return -EIO;
@@ -385,89 +435,28 @@ iavf_execute_vf_cmd(struct iavf_adapter *adapter, struct iavf_cmd_info *args)
 	if (iavf_set_pending_cmd(vf, args->ops, RTE_MAX(1U, resp_count)))
 		return -1;
 
-	ret = iavf_aq_send_msg_to_pf(hw, args->ops, IAVF_SUCCESS,
-				    args->in_args, args->in_args_size, NULL);
-	if (ret) {
+	status = iavf_aq_send_msg_to_pf(hw, args->ops, IAVF_SUCCESS,
+			args->in_args, args->in_args_size, NULL);
+	if (status != IAVF_SUCCESS) {
 		PMD_DRV_LOG(ERR, "fail to send cmd %d", args->ops);
-		iavf_clear_pending_cmd(vf);
-		return err;
+		err = (int)status;
+		goto clear_cmd;
+	} else if (resp_count == 0) {
+		/* we're not waiting on responses */
+		err = 0;
+		goto clear_cmd;
 	}
 
-	if (resp_count == 0) {
-		/* reset pending commands, counter will be overwritten on reset */
-		iavf_clear_pending_cmd(vf);
-		return 0;
-	}
-
-	switch (args->ops) {
-	case VIRTCHNL_OP_VERSION:
-	case VIRTCHNL_OP_GET_VF_RESOURCES:
-	case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS:
-	case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
-		/* for init virtchnl ops, need to poll the response */
-		do {
-			result = iavf_read_msg_from_pf(adapter, args->out_size,
-						   args->out_buffer);
-			if (result == IAVF_MSG_CMD)
-				break;
-			iavf_msec_delay(ASQ_DELAY_MS);
-		} while (i++ < MAX_TRY_TIMES);
-		if (i >= MAX_TRY_TIMES ||
-		    vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
-			err = -1;
-			PMD_DRV_LOG(ERR, "No response or return failure (%d)"
-				    " for cmd %d", vf->cmd_retval, args->ops);
-		}
-		iavf_clear_pending_cmd(vf);
-		break;
-	default:
-		if (rte_thread_is_intr()) {
-			/* For virtchnl ops were executed in eal_intr_thread,
-			 * need to poll the response.
-			 */
-			do {
-				result = iavf_read_msg_from_pf(adapter, args->out_size,
-							args->out_buffer);
-				if (result == IAVF_MSG_CMD)
-					break;
-				iavf_msec_delay(ASQ_DELAY_MS);
-			} while (i++ < MAX_TRY_TIMES);
-			if (i >= MAX_TRY_TIMES ||
-				vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
-				err = -1;
-				PMD_DRV_LOG(ERR, "No response or return failure (%d)"
-						" for cmd %d", vf->cmd_retval, args->ops);
-			}
-			iavf_clear_pending_cmd(vf);
-		} else {
-			/* For other virtchnl ops in running time,
-			 * wait for the cmd done flag.
-			 */
-			do {
-				if (vf->pend_cmd == VIRTCHNL_OP_UNKNOWN)
-					break;
-				iavf_msec_delay(ASQ_DELAY_MS);
-				/* If don't read msg or read sys event, continue */
-			} while (i++ < MAX_TRY_TIMES);
+	err = iavf_wait_for_msg(adapter, args, poll);
 
-			if (i >= MAX_TRY_TIMES) {
-				PMD_DRV_LOG(ERR, "No response for cmd %d", args->ops);
-				iavf_clear_pending_cmd(vf);
-				err = -EIO;
-			} else if (vf->cmd_retval ==
-				VIRTCHNL_STATUS_ERR_NOT_SUPPORTED) {
-				PMD_DRV_LOG(ERR, "Cmd %d not supported", args->ops);
-				err = -ENOTSUP;
-			} else if (vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
-				PMD_DRV_LOG(ERR, "Return failure %d for cmd %d",
-						vf->cmd_retval, args->ops);
-				err = -EINVAL;
-			}
-		}
-		break;
-	}
+	/* in interrupt success case, pending cmd is cleared by intr thread */
+	if (err != 0 || poll)
+		goto clear_cmd;
 
 	return err;
+clear_cmd:
+	iavf_clear_pending_cmd(vf);
+	return err;
 }
 
 static int
Signature · 1 line
2.47.3
Acked-by on v3 5/8
#15 lore raw

Re: [PATCH v3 5/8] net/iavf: refactor sending virtchnl messages

Quoted 6 lines · Anatoly Burakov

Currently, there is a certain amount of duplication and unnecessary branching in the virtchnl message handling function which makes it difficult to read and reason about.

Refactor the function to achieve the following:

Quoted 9 lines

- clean and explicit distinction between synchronous and asynchronous ops
- common looping and error handling logic
- fewer and clearer special cases

---
 drivers/net/intel/iavf/iavf_vchnl.c | 151 +++++++++++++---------------
 1 file changed, 70 insertions(+), 81 deletions(-)
#16 lore raw

PATCH v3 6/8 net/iavf: respect output buffer in virtchnl

In reply to Anatoly Burakov

Currently, in asynchronous case for virtchnl messages, we only store the command response data inside the global buffer. This is correct, because we populate the response in a different thread from the caller context, but this results in caller's out_buffer value being ignored. Correct it by populating caller's response buffer with data from response even in cases where the messages arrive asynchronously.

---
 drivers/net/intel/iavf/iavf_vchnl.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/net/intel/iavf/iavf_vchnl.c +7 -0
index 3f6ce0dd89..250816c24a 100644
@@ -449,6 +449,13 @@ iavf_execute_vf_cmd(struct iavf_adapter *adapter, struct iavf_cmd_info *args)
 
 	err = iavf_wait_for_msg(adapter, args, poll);
 
+	/*
+	 * messages received through interrupts store their response in global
+	 * buffer, so we need to copy it if we received the message.
+	 */
+	if (!poll && err == 0)
+		memcpy(args->out_buffer, vf->aq_resp, args->out_size);
+
 	/* in interrupt success case, pending cmd is cleared by intr thread */
 	if (err != 0 || poll)
 		goto clear_cmd;
Signature · 1 line
2.47.3
Acked-by on v3 6/8
#17 lore raw

Re: [PATCH v3 6/8] net/iavf: respect output buffer in virtchnl

Quoted 11 lines · Anatoly Burakov

Currently, in asynchronous case for virtchnl messages, we only store the command response data inside the global buffer. This is correct, because we populate the response in a different thread from the caller context, but this results in caller's out_buffer value being ignored. Correct it by populating caller's response buffer with data from response even in cases where the messages arrive asynchronously.

---
 drivers/net/intel/iavf/iavf_vchnl.c | 7 +++++++
 1 file changed, 7 insertions(+)
#18 lore raw

PATCH v3 7/8 net/iavf: do not use global virtchnl buffer

In reply to Anatoly Burakov

Currently, a lot of virtchnl requests will use global virtchnl output buffer as their out_buffer for VF requests. This was originally done this way because most requests were done asynchronously and the response was not written directly into the out_buffer. This is no longer the case, so the per-command buffers can be safely replaced with stack allocated buffers.

---
 drivers/net/intel/iavf/iavf_vchnl.c | 147 +++++++++++++++++-----------
 1 file changed, 89 insertions(+), 58 deletions(-)
drivers/net/intel/iavf/iavf_vchnl.c +89 -58
index 250816c24a..1e98503b31 100644
@@ -650,7 +650,7 @@ iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
 int
 iavf_enable_vlan_strip(struct iavf_adapter *adapter)
 {
-	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	int ret;
 
@@ -658,7 +658,7 @@ iavf_enable_vlan_strip(struct iavf_adapter *adapter)
 	args.ops = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
 	args.in_args = NULL;
 	args.in_args_size = 0;
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 	ret = iavf_execute_vf_cmd_safe(adapter, &args);
 	if (ret)
@@ -671,7 +671,7 @@ iavf_enable_vlan_strip(struct iavf_adapter *adapter)
 int
 iavf_disable_vlan_strip(struct iavf_adapter *adapter)
 {
-	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	int ret;
 
@@ -679,7 +679,7 @@ iavf_disable_vlan_strip(struct iavf_adapter *adapter)
 	args.ops = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
 	args.in_args = NULL;
 	args.in_args_size = 0;
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 	ret = iavf_execute_vf_cmd_safe(adapter, &args);
 	if (ret)
@@ -698,6 +698,7 @@ iavf_check_api_version(struct iavf_adapter *adapter)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
 	struct virtchnl_version_info version, *pver;
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	int err;
 
@@ -707,7 +708,7 @@ iavf_check_api_version(struct iavf_adapter *adapter)
 	args.ops = VIRTCHNL_OP_VERSION;
 	args.in_args = (uint8_t *)&version;
 	args.in_args_size = sizeof(version);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -747,12 +748,13 @@ iavf_get_vf_resource(struct iavf_adapter *adapter)
 {
 	struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	uint32_t caps, len;
 	int err, i;
 
 	args.ops = VIRTCHNL_OP_GET_VF_RESOURCES;
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	caps = IAVF_BASIC_OFFLOAD_CAPS | VIRTCHNL_VF_CAP_ADV_LINK_SPEED |
@@ -808,13 +810,14 @@ int
 iavf_get_supported_rxdid(struct iavf_adapter *adapter)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	int ret;
 
 	args.ops = VIRTCHNL_OP_GET_SUPPORTED_RXDIDS;
 	args.in_args = NULL;
 	args.in_args_size = 0;
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	ret = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -836,6 +839,7 @@ iavf_config_vlan_strip_v2(struct iavf_adapter *adapter, bool enable)
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
 	struct virtchnl_vlan_supported_caps *stripping_caps;
 	struct virtchnl_vlan_setting vlan_strip;
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	uint32_t *ethertype;
 	int ret;
@@ -859,7 +863,7 @@ iavf_config_vlan_strip_v2(struct iavf_adapter *adapter, bool enable)
 			    VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2;
 	args.in_args = (uint8_t *)&vlan_strip;
 	args.in_args_size = sizeof(vlan_strip);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 	ret = iavf_execute_vf_cmd_safe(adapter, &args);
 	if (ret)
@@ -876,6 +880,7 @@ iavf_config_vlan_insert_v2(struct iavf_adapter *adapter, bool enable)
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
 	struct virtchnl_vlan_supported_caps *insertion_caps;
 	struct virtchnl_vlan_setting vlan_insert;
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	uint32_t *ethertype;
 	int ret;
@@ -899,7 +904,7 @@ iavf_config_vlan_insert_v2(struct iavf_adapter *adapter, bool enable)
 			    VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2;
 	args.in_args = (uint8_t *)&vlan_insert;
 	args.in_args_size = sizeof(vlan_insert);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 	ret = iavf_execute_vf_cmd_safe(adapter, &args);
 	if (ret)
@@ -916,6 +921,7 @@ iavf_add_del_vlan_v2(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
 	struct virtchnl_vlan_supported_caps *supported_caps;
 	struct virtchnl_vlan_filter_list_v2 vlan_filter;
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct virtchnl_vlan *vlan_setting;
 	struct iavf_cmd_info args;
 	uint32_t filtering_caps;
@@ -942,7 +948,7 @@ iavf_add_del_vlan_v2(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
 	args.ops = add ? VIRTCHNL_OP_ADD_VLAN_V2 : VIRTCHNL_OP_DEL_VLAN_V2;
 	args.in_args = (uint8_t *)&vlan_filter;
 	args.in_args_size = sizeof(vlan_filter);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
 	if (err)
@@ -956,13 +962,14 @@ int
 iavf_get_vlan_offload_caps_v2(struct iavf_adapter *adapter)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	int ret;
 
 	args.ops = VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS;
 	args.in_args = NULL;
 	args.in_args_size = 0;
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	ret = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -972,7 +979,7 @@ iavf_get_vlan_offload_caps_v2(struct iavf_adapter *adapter)
 		return ret;
 	}
 
-	rte_memcpy(&vf->vlan_v2_caps, vf->aq_resp, sizeof(vf->vlan_v2_caps));
+	rte_memcpy(&vf->vlan_v2_caps, args.out_buffer, sizeof(vf->vlan_v2_caps));
 
 	return 0;
 }
@@ -982,6 +989,7 @@ iavf_enable_queues(struct iavf_adapter *adapter)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
 	struct virtchnl_queue_select queue_select;
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	int err;
 
@@ -994,7 +1002,7 @@ iavf_enable_queues(struct iavf_adapter *adapter)
 	args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
 	args.in_args = (u8 *)&queue_select;
 	args.in_args_size = sizeof(queue_select);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
 	if (err) {
@@ -1010,6 +1018,7 @@ iavf_disable_queues(struct iavf_adapter *adapter)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
 	struct virtchnl_queue_select queue_select;
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	int err;
 
@@ -1022,7 +1031,7 @@ iavf_disable_queues(struct iavf_adapter *adapter)
 	args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
 	args.in_args = (u8 *)&queue_select;
 	args.in_args_size = sizeof(queue_select);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
 	if (err) {
@@ -1039,6 +1048,7 @@ iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
 	struct virtchnl_queue_select queue_select;
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	int err;
 
@@ -1058,7 +1068,7 @@ iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
 		args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
 	args.in_args = (u8 *)&queue_select;
 	args.in_args_size = sizeof(queue_select);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
 	if (err)
@@ -1071,6 +1081,7 @@ int
 iavf_enable_queues_lv(struct iavf_adapter *adapter)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct {
 		struct virtchnl_del_ena_dis_queues msg;
 		struct virtchnl_queue_chunk chunks[IAVF_RXTX_QUEUE_CHUNKS_NUM - 1];
@@ -1096,7 +1107,7 @@ iavf_enable_queues_lv(struct iavf_adapter *adapter)
 	args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2;
 	args.in_args = (u8 *)queue_select;
 	args.in_args_size = sizeof(queue_req);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
 	if (err)
@@ -1110,6 +1121,7 @@ int
 iavf_disable_queues_lv(struct iavf_adapter *adapter)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct {
 		struct virtchnl_del_ena_dis_queues msg;
 		struct virtchnl_queue_chunk chunks[IAVF_RXTX_QUEUE_CHUNKS_NUM - 1];
@@ -1135,7 +1147,7 @@ iavf_disable_queues_lv(struct iavf_adapter *adapter)
 	args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
 	args.in_args = (u8 *)queue_select;
 	args.in_args_size = sizeof(queue_req);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
 	if (err)
@@ -1150,6 +1162,7 @@ iavf_switch_queue_lv(struct iavf_adapter *adapter, uint16_t qid,
 		 bool rx, bool on)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct {
 		struct virtchnl_del_ena_dis_queues msg;
 	} queue_req = {0};
@@ -1177,7 +1190,7 @@ iavf_switch_queue_lv(struct iavf_adapter *adapter, uint16_t qid,
 		args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
 	args.in_args = (u8 *)queue_select;
 	args.in_args_size = sizeof(queue_req);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
 	if (err)
@@ -1191,6 +1204,7 @@ int
 iavf_configure_rss_lut(struct iavf_adapter *adapter)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct virtchnl_rss_lut *rss_lut;
 	struct iavf_cmd_info args;
 	int len, err = 0;
@@ -1207,7 +1221,7 @@ iavf_configure_rss_lut(struct iavf_adapter *adapter)
 	args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
 	args.in_args = (u8 *)rss_lut;
 	args.in_args_size = len;
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -1223,6 +1237,7 @@ int
 iavf_configure_rss_key(struct iavf_adapter *adapter)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct virtchnl_rss_key *rss_key;
 	struct iavf_cmd_info args;
 	int len, err = 0;
@@ -1239,7 +1254,7 @@ iavf_configure_rss_key(struct iavf_adapter *adapter)
 	args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
 	args.in_args = (u8 *)rss_key;
 	args.in_args_size = len;
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -1307,6 +1322,7 @@ iavf_configure_queue_chunk(struct iavf_adapter *adapter,
 		uint16_t chunk_start)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct {
 		struct virtchnl_vsi_queue_config_info config;
 		struct virtchnl_queue_pair_info qp[IAVF_CFG_Q_NUM_PER_BUF];
@@ -1335,7 +1351,7 @@ iavf_configure_queue_chunk(struct iavf_adapter *adapter,
 	args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
 	args.in_args = (uint8_t *)vc_config;
 	args.in_args_size = buf_len;
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -1370,6 +1386,7 @@ int
 iavf_config_irq_map(struct iavf_adapter *adapter)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct {
 		struct virtchnl_irq_map_info map_info;
 		struct virtchnl_vector_map vecmap[IAVF_MAX_NUM_QUEUES_DFLT];
@@ -1419,7 +1436,7 @@ iavf_config_irq_map(struct iavf_adapter *adapter)
 	args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
 	args.in_args = (u8 *)map_info;
 	args.in_args_size = buf_len;
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
 	if (err)
@@ -1438,6 +1455,7 @@ iavf_config_irq_map_lv_chunk(struct iavf_adapter *adapter,
 		struct virtchnl_queue_vector qv_maps[IAVF_CFG_Q_NUM_PER_BUF];
 	} chunk_req = {0};
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args = {0};
 	struct virtchnl_queue_vector_maps *map_info = &chunk_req.map_info;
 	struct virtchnl_queue_vector *qv_maps = chunk_req.qv_maps;
@@ -1464,7 +1482,7 @@ iavf_config_irq_map_lv_chunk(struct iavf_adapter *adapter,
 	args.ops = VIRTCHNL_OP_MAP_QUEUE_VECTOR;
 	args.in_args = (u8 *)map_info;
 	args.in_args_size = buf_len;
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	return iavf_execute_vf_cmd_safe(adapter, &args);
@@ -1497,6 +1515,7 @@ iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
 	} list_req = {0};
 	struct virtchnl_ether_addr_list *list = &list_req.list;
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args = {0};
 	int err, i;
 	size_t buf_len;
@@ -1524,7 +1543,7 @@ iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
 	args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
 	args.in_args = (uint8_t *)list;
 	args.in_args_size = buf_len;
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
 	if (err)
@@ -1537,6 +1556,7 @@ iavf_query_stats(struct iavf_adapter *adapter,
 		struct virtchnl_eth_stats *pstats)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct virtchnl_queue_select q_stats;
 	struct iavf_cmd_info args;
 	int err;
@@ -1549,7 +1569,7 @@ iavf_query_stats(struct iavf_adapter *adapter,
 	args.ops = VIRTCHNL_OP_GET_STATS;
 	args.in_args = (uint8_t *)&q_stats;
 	args.in_args_size = sizeof(q_stats);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -1567,6 +1587,7 @@ iavf_config_promisc(struct iavf_adapter *adapter,
 		   bool enable_multicast)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct virtchnl_promisc_info promisc;
 	struct iavf_cmd_info args;
 	int err;
@@ -1586,7 +1607,7 @@ iavf_config_promisc(struct iavf_adapter *adapter,
 	args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
 	args.in_args = (uint8_t *)&promisc;
 	args.in_args_size = sizeof(promisc);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -1612,6 +1633,7 @@ iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
 {
 	struct virtchnl_ether_addr_list *list;
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
 			   sizeof(struct virtchnl_ether_addr)];
 	struct iavf_cmd_info args;
@@ -1630,7 +1652,7 @@ iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
 	args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
 	args.in_args = cmd_buffer;
 	args.in_args_size = sizeof(cmd_buffer);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
 	if (err)
@@ -1644,6 +1666,7 @@ iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
 {
 	struct virtchnl_vlan_filter_list *vlan_list;
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
 							sizeof(uint16_t)];
 	struct iavf_cmd_info args;
@@ -1657,7 +1680,7 @@ iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
 	args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
 	args.in_args = cmd_buffer;
 	args.in_args_size = sizeof(cmd_buffer);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
 	if (err)
@@ -1673,7 +1696,7 @@ iavf_fdir_add(struct iavf_adapter *adapter,
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
 	struct virtchnl_fdir_add *fdir_ret;
-
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	int err;
 
@@ -1683,7 +1706,7 @@ iavf_fdir_add(struct iavf_adapter *adapter,
 	args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
 	args.in_args = (uint8_t *)(&filter->add_fltr);
 	args.in_args_size = sizeof(*(&filter->add_fltr));
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -1733,7 +1756,7 @@ iavf_fdir_del(struct iavf_adapter *adapter,
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
 	struct virtchnl_fdir_del *fdir_ret;
-
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	int err;
 
@@ -1743,7 +1766,7 @@ iavf_fdir_del(struct iavf_adapter *adapter,
 	args.ops = VIRTCHNL_OP_DEL_FDIR_FILTER;
 	args.in_args = (uint8_t *)(&filter->del_fltr);
 	args.in_args_size = sizeof(filter->del_fltr);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -1780,7 +1803,7 @@ iavf_fdir_check(struct iavf_adapter *adapter,
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
 	struct virtchnl_fdir_add *fdir_ret;
-
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	int err;
 
@@ -1790,7 +1813,7 @@ iavf_fdir_check(struct iavf_adapter *adapter,
 	args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
 	args.in_args = (uint8_t *)(&filter->add_fltr);
 	args.in_args_size = sizeof(*(&filter->add_fltr));
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -1822,6 +1845,7 @@ int
 iavf_flow_sub(struct iavf_adapter *adapter, struct iavf_fsub_conf *filter)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct virtchnl_flow_sub *fsub_cfg;
 	struct iavf_cmd_info args;
 	int err;
@@ -1833,7 +1857,7 @@ iavf_flow_sub(struct iavf_adapter *adapter, struct iavf_fsub_conf *filter)
 	args.ops = VIRTCHNL_OP_FLOW_SUBSCRIBE;
 	args.in_args = (uint8_t *)(&filter->sub_fltr);
 	args.in_args_size = sizeof(*(&filter->sub_fltr));
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -1874,6 +1898,7 @@ iavf_flow_unsub(struct iavf_adapter *adapter, struct iavf_fsub_conf *filter)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
 	struct virtchnl_flow_unsub *unsub_cfg;
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	int err;
 
@@ -1884,7 +1909,7 @@ iavf_flow_unsub(struct iavf_adapter *adapter, struct iavf_fsub_conf *filter)
 	args.ops = VIRTCHNL_OP_FLOW_UNSUBSCRIBE;
 	args.in_args = (uint8_t *)(&filter->unsub_fltr);
 	args.in_args_size = sizeof(filter->unsub_fltr);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -1917,7 +1942,7 @@ iavf_flow_sub_check(struct iavf_adapter *adapter,
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
 	struct virtchnl_flow_sub *fsub_cfg;
-
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	int err;
 
@@ -1927,7 +1952,7 @@ iavf_flow_sub_check(struct iavf_adapter *adapter,
 	args.ops = VIRTCHNL_OP_FLOW_SUBSCRIBE;
 	args.in_args = (uint8_t *)(&filter->sub_fltr);
 	args.in_args_size = sizeof(*(&filter->sub_fltr));
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -1958,7 +1983,7 @@ int
 iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
 		     struct virtchnl_rss_cfg *rss_cfg, bool add)
 {
-	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	int err;
 
@@ -1967,7 +1992,7 @@ iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
 		VIRTCHNL_OP_DEL_RSS_CFG;
 	args.in_args = (u8 *)rss_cfg;
 	args.in_args_size = sizeof(*rss_cfg);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -1983,7 +2008,7 @@ iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
 int
 iavf_get_hena_caps(struct iavf_adapter *adapter, uint64_t *caps)
 {
-	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct virtchnl_rss_hena *hena;
 	struct iavf_cmd_info args;
 	int err;
@@ -1991,7 +2016,7 @@ iavf_get_hena_caps(struct iavf_adapter *adapter, uint64_t *caps)
 	args.ops = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
 	args.in_args = NULL;
 	args.in_args_size = 0;
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -2009,7 +2034,7 @@ iavf_get_hena_caps(struct iavf_adapter *adapter, uint64_t *caps)
 int
 iavf_set_hena(struct iavf_adapter *adapter, uint64_t hena)
 {
-	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct virtchnl_rss_hena vrh;
 	struct iavf_cmd_info args;
 	int err;
@@ -2018,7 +2043,7 @@ iavf_set_hena(struct iavf_adapter *adapter, uint64_t hena)
 	args.ops = VIRTCHNL_OP_SET_RSS_HENA;
 	args.in_args = (u8 *)&vrh;
 	args.in_args_size = sizeof(vrh);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -2033,6 +2058,7 @@ int
 iavf_get_qos_cap(struct iavf_adapter *adapter)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	uint32_t len;
 	int err;
@@ -2040,7 +2066,7 @@ iavf_get_qos_cap(struct iavf_adapter *adapter)
 	args.ops = VIRTCHNL_OP_GET_QOS_CAPS;
 	args.in_args = NULL;
 	args.in_args_size = 0;
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
 
@@ -2064,7 +2090,7 @@ int iavf_set_q_tc_map(struct rte_eth_dev *dev,
 {
 	struct iavf_adapter *adapter =
 			IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
-	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	int err;
 
@@ -2072,7 +2098,7 @@ int iavf_set_q_tc_map(struct rte_eth_dev *dev,
 	args.ops = VIRTCHNL_OP_CONFIG_QUEUE_TC_MAP;
 	args.in_args = (uint8_t *)q_tc_mapping;
 	args.in_args_size = size;
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -2087,7 +2113,7 @@ int iavf_set_q_bw(struct rte_eth_dev *dev,
 {
 	struct iavf_adapter *adapter =
 			IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
-	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	int err;
 
@@ -2095,7 +2121,7 @@ int iavf_set_q_bw(struct rte_eth_dev *dev,
 	args.ops = VIRTCHNL_OP_CONFIG_QUEUE_BW;
 	args.in_args = (uint8_t *)q_bw;
 	args.in_args_size = size;
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -2111,6 +2137,7 @@ iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
 			uint32_t mc_addrs_num, bool add)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
 		(IAVF_NUM_MACADDR_MAX * sizeof(struct virtchnl_ether_addr))];
 	struct virtchnl_ether_addr_list *list;
@@ -2141,7 +2168,7 @@ iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
 	args.in_args = cmd_buffer;
 	args.in_args_size = sizeof(struct virtchnl_ether_addr_list) +
 		i * sizeof(struct virtchnl_ether_addr);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
 
@@ -2160,6 +2187,7 @@ iavf_request_queues(struct rte_eth_dev *dev, uint16_t num)
 	struct iavf_adapter *adapter =
 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
 	struct iavf_info *vf =  IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct virtchnl_vf_res_request vfres;
 	struct iavf_cmd_info args;
 	uint16_t num_queue_pairs;
@@ -2181,7 +2209,7 @@ iavf_request_queues(struct rte_eth_dev *dev, uint16_t num)
 	args.ops = VIRTCHNL_OP_REQUEST_QUEUES;
 	args.in_args = (u8 *)&vfres;
 	args.in_args_size = sizeof(vfres);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
@@ -2224,6 +2252,7 @@ int
 iavf_get_max_rss_queue_region(struct iavf_adapter *adapter)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	uint16_t qregion_width;
 	int err;
@@ -2231,7 +2260,7 @@ iavf_get_max_rss_queue_region(struct iavf_adapter *adapter)
 	args.ops = VIRTCHNL_OP_GET_MAX_RSS_QREGION;
 	args.in_args = NULL;
 	args.in_args_size = 0;
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -2255,14 +2284,14 @@ iavf_ipsec_crypto_request(struct iavf_adapter *adapter,
 		uint8_t *msg, size_t msg_len,
 		uint8_t *resp_msg, size_t resp_msg_len)
 {
-	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	int err;
 
 	args.ops = VIRTCHNL_OP_INLINE_IPSEC_CRYPTO;
 	args.in_args = msg;
 	args.in_args_size = msg_len;
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -2280,7 +2309,7 @@ iavf_ipsec_crypto_request(struct iavf_adapter *adapter,
 int
 iavf_set_vf_quanta_size(struct iavf_adapter *adapter, u16 start_queue_id, u16 num_queues)
 {
-	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct iavf_cmd_info args;
 	struct virtchnl_quanta_cfg q_quanta;
 	int err;
@@ -2296,7 +2325,7 @@ iavf_set_vf_quanta_size(struct iavf_adapter *adapter, u16 start_queue_id, u16 nu
 	args.ops = VIRTCHNL_OP_CONFIG_QUANTA;
 	args.in_args = (uint8_t *)&q_quanta;
 	args.in_args_size = sizeof(q_quanta);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -2312,6 +2341,7 @@ int
 iavf_get_ptp_cap(struct iavf_adapter *adapter)
 {
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct virtchnl_ptp_caps ptp_caps;
 	struct iavf_cmd_info args;
 	int err;
@@ -2322,7 +2352,7 @@ iavf_get_ptp_cap(struct iavf_adapter *adapter)
 	args.ops = VIRTCHNL_OP_1588_PTP_GET_CAPS;
 	args.in_args = (uint8_t *)&ptp_caps;
 	args.in_args_size = sizeof(ptp_caps);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd_safe(adapter, &args);
@@ -2342,6 +2372,7 @@ iavf_get_phc_time(struct ci_rx_queue *rxq)
 {
 	struct iavf_adapter *adapter = rxq->iavf_vsi->adapter;
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct virtchnl_phc_time phc_time;
 	struct iavf_cmd_info args;
 	int err = 0;
@@ -2349,7 +2380,7 @@ iavf_get_phc_time(struct ci_rx_queue *rxq)
 	args.ops = VIRTCHNL_OP_1588_PTP_GET_TIME;
 	args.in_args = (uint8_t *)&phc_time;
 	args.in_args_size = sizeof(phc_time);
-	args.out_buffer = vf->aq_resp;
+	args.out_buffer = msg_buf;
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	rte_spinlock_lock(&vf->phc_time_aq_lock);
Signature · 1 line
2.47.3
Acked-by on v3 7/8
#19 lore raw

Re: [PATCH v3 7/8] net/iavf: do not use global virtchnl buffer

Quoted 11 lines · Anatoly Burakov

Currently, a lot of virtchnl requests will use global virtchnl output buffer as their out_buffer for VF requests. This was originally done this way because most requests were done asynchronously and the response was not written directly into the out_buffer. This is no longer the case, so the per-command buffers can be safely replaced with stack allocated buffers.

---
 drivers/net/intel/iavf/iavf_vchnl.c | 147 +++++++++++++++++-----------
 1 file changed, 89 insertions(+), 58 deletions(-)
#20 lore raw

PATCH v3 8/8 net/iavf: embed virtchnl response buffer

In reply to Anatoly Burakov

There is no need to dynamically allocate this buffer separately as it is fixed in size and is always allocated for all driver instances no matter the configuration. Embed it in iavf_info struct.

---
 drivers/net/intel/iavf/iavf.h        |  2 +-
 drivers/net/intel/iavf/iavf_ethdev.c | 13 -------------
 drivers/net/intel/iavf/iavf_vchnl.c  |  4 ----
 3 files changed, 1 insertion(+), 18 deletions(-)
drivers/net/intel/iavf/iavf.h +1 -1
index 440376c4ca..067ebc29d0 100644
@@ -242,7 +242,7 @@ struct iavf_info {
 	volatile RTE_ATOMIC(enum virtchnl_ops) pend_cmd; /* pending command not finished */
 	RTE_ATOMIC(uint32_t) pend_cmd_count;
 	int cmd_retval; /* return value of the cmd response from PF */
-	uint8_t *aq_resp; /* buffer to store the adminq response from PF */
+	uint8_t aq_resp[IAVF_AQ_BUF_SZ]; /* buffer to store the adminq response from PF */
 	bool aq_intr_enabled;
 
 	/** iAVF watchdog enable */
drivers/net/intel/iavf/iavf_ethdev.c +0 -13
index 9fdebec0f4..6d0306b3ac 100644
@@ -2553,11 +2553,6 @@ iavf_init_vf(struct rte_eth_dev *dev)
 		goto err;
 	}
 
-	vf->aq_resp = rte_zmalloc("vf_aq_resp", IAVF_AQ_BUF_SZ, 0);
-	if (!vf->aq_resp) {
-		PMD_INIT_LOG(ERR, "unable to allocate vf_aq_resp memory");
-		goto err_aq;
-	}
 	if (iavf_check_api_version(adapter) != 0) {
 		PMD_INIT_LOG(ERR, "check_api version failed");
 		goto err_api;
@@ -2631,8 +2626,6 @@ iavf_init_vf(struct rte_eth_dev *dev)
 	rte_free(vf->vf_res);
 	vf->vsi_res = NULL;
 err_api:
-	rte_free(vf->aq_resp);
-err_aq:
 	iavf_shutdown_adminq(hw);
 err:
 	return -1;
@@ -2650,9 +2643,6 @@ iavf_uninit_vf(struct rte_eth_dev *dev)
 	vf->vsi_res = NULL;
 	vf->vf_res = NULL;
 
-	rte_free(vf->aq_resp);
-	vf->aq_resp = NULL;
-
 	rte_free(vf->qos_cap);
 	vf->qos_cap = NULL;
 
@@ -3009,9 +2999,6 @@ iavf_dev_close(struct rte_eth_dev *dev)
 	vf->vsi_res = NULL;
 	vf->vf_res = NULL;
 
-	rte_free(vf->aq_resp);
-	vf->aq_resp = NULL;
-
 	/*
 	 * If the VF is reset via VFLR, the device will be knocked out of bus
 	 * master mode, and the driver will fail to recover from the reset. Fix
drivers/net/intel/iavf/iavf_vchnl.c +0 -4
index 1e98503b31..03cb2a55d8 100644
@@ -564,10 +564,6 @@ iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
 	int ret;
 
 	info.buf_len = IAVF_AQ_BUF_SZ;
-	if (!vf->aq_resp) {
-		PMD_DRV_LOG(ERR, "Buffer for adminq resp should not be NULL");
-		return;
-	}
 	info.msg_buf = vf->aq_resp;
 
 	pending = 1;
Signature · 1 line
2.47.3
Acked-by on v3 8/8
#21 lore raw

Re: [PATCH v3 8/8] net/iavf: embed virtchnl response buffer

Quoted 11 lines · Anatoly Burakov

There is no need to dynamically allocate this buffer separately as it is fixed in size and is always allocated for all driver instances no matter the configuration. Embed it in iavf_info struct.

---
 drivers/net/intel/iavf/iavf.h        |  2 +-
 drivers/net/intel/iavf/iavf_ethdev.c | 13 -------------
 drivers/net/intel/iavf/iavf_vchnl.c  |  4 ----
 3 files changed, 1 insertion(+), 18 deletions(-)
#22 lore raw

Re: [PATCH v3 0/8] Reduce reliance on global response buffer in IAVF

In reply to Anatoly Burakov
Quoted 17 lines · Anatoly Burakov

In many places where we are calling down into virtchnl, we are using a globally allocated adminq response buffer. This is unnecessary, so replace with adminq buffers allocated on stack. However, because IAVF virtchnl message queue works asynchronously in most cases, we can't remove the global buffer entirely, and we need to do some cleanup and refactoring to be able to reduce our usage of these buffers. This patchset does that.

v1 -> v2:
- Stats query was passing in a pointer-to-pointer and storing pointer to global adminq response buffer as output parameter, so changing that to a local buffer resulted in storing a pointer to a buffer that was stack allocated (i.e. introduced a use-after-free).

v2 -> v3:
- Reworked the virtchnl message handling to not rely on implicit behavior
- Split up into 8 patches for easy review

Quoted 10 lines

Anatoly Burakov (8):
net/iavf: avoid passing around pointers
net/iavf: add a variable for hena
net/iavf: add virtchnl interrupt enable flag
net/iavf: rework "async" virtchnl requests
net/iavf: refactor sending virtchnl messages
net/iavf: respect output buffer in virtchnl
net/iavf: do not use global virtchnl buffer
net/iavf: embed virtchnl response buffer

Series applied to dpdk-next-net-intel.

Thanks,
/Bruce