patch 'vhost/crypto: skip fetch before vring init' has been queued to stable release 23.11.4

Xueming Li xuemingl at nvidia.com
Tue Apr 8 09:44:36 CEST 2025


Hi,

FYI, your patch has been queued to stable release 23.11.4

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 04/10/25. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.

Queued patches are on a temporary branch at:
https://git.dpdk.org/dpdk-stable/log/?h=23.11-staging

This queued commit can be viewed at:
https://git.dpdk.org/dpdk-stable/commit/?h=23.11-staging&id=2d91d69fb5e5fae47919afa5390231121f5e629f

Thanks.

Xueming Li <xuemingl at nvidia.com>

---
>From 2d91d69fb5e5fae47919afa5390231121f5e629f Mon Sep 17 00:00:00 2001
From: Gowrishankar Muthukrishnan <gmuthukrishn at marvell.com>
Date: Fri, 28 Feb 2025 19:17:09 +0530
Subject: [PATCH] vhost/crypto: skip fetch before vring init
Cc: Xueming Li <xuemingl at nvidia.com>

[ upstream commit b03cb9c87a61054ce34b1c19c89170c80d75d27d ]

Until virtio avail ring is initialized (by VHOST_USER_SET_VRING_ADDR),
worker thread should not try to fetch crypto op, which would lead to
memory fault.

Fixes: 939066d96563 ("vhost/crypto: add public function implementation")

Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn at marvell.com>
Acked-by: Akhil Goyal <gakhil at marvell.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin at redhat.com>
---
 lib/vhost/vhost_crypto.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/lib/vhost/vhost_crypto.c b/lib/vhost/vhost_crypto.c
index 7b22281815..23eb59459e 100644
--- a/lib/vhost/vhost_crypto.c
+++ b/lib/vhost/vhost_crypto.c
@@ -7,6 +7,7 @@
 #include <rte_mbuf.h>
 #include <rte_cryptodev.h>
 
+#include "iotlb.h"
 #include "rte_vhost_crypto.h"
 #include "vhost.h"
 #include "vhost_user.h"
@@ -1579,6 +1580,20 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,
 
 	vq = dev->virtqueue[qid];
 
+	if (unlikely(vq == NULL)) {
+		VC_LOG_ERR("Invalid virtqueue %u", qid);
+		return 0;
+	}
+
+	if (unlikely(rte_rwlock_read_trylock(&vq->access_lock) != 0))
+		return 0;
+
+	vhost_user_iotlb_rd_lock(vq);
+	if (unlikely(!vq->access_ok)) {
+		VC_LOG_DBG("Virtqueue %u vrings not yet initialized", qid);
+		goto out_unlock;
+	}
+
 	avail_idx = *((volatile uint16_t *)&vq->avail->idx);
 	start_idx = vq->last_used_idx;
 	count = avail_idx - start_idx;
@@ -1586,7 +1601,7 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,
 	count = RTE_MIN(count, nb_ops);
 
 	if (unlikely(count == 0))
-		return 0;
+		goto out_unlock;
 
 	/* for zero copy, we need 2 empty mbufs for src and dst, otherwise
 	 * we need only 1 mbuf as src and dst
@@ -1596,7 +1611,7 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,
 		if (unlikely(rte_mempool_get_bulk(vcrypto->mbuf_pool,
 				(void **)mbufs, count * 2) < 0)) {
 			VC_LOG_ERR("Insufficient memory");
-			return 0;
+			goto out_unlock;
 		}
 
 		for (i = 0; i < count; i++) {
@@ -1626,7 +1641,7 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,
 		if (unlikely(rte_mempool_get_bulk(vcrypto->mbuf_pool,
 				(void **)mbufs, count) < 0)) {
 			VC_LOG_ERR("Insufficient memory");
-			return 0;
+			goto out_unlock;
 		}
 
 		for (i = 0; i < count; i++) {
@@ -1655,6 +1670,10 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,
 
 	vq->last_used_idx += i;
 
+out_unlock:
+	vhost_user_iotlb_rd_unlock(vq);
+	rte_rwlock_read_unlock(&vq->access_lock);
+
 	return i;
 }
 
-- 
2.34.1

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2025-04-08 15:39:06.361153041 +0800
+++ 0011-vhost-crypto-skip-fetch-before-vring-init.patch	2025-04-08 15:39:05.886436594 +0800
@@ -1 +1 @@
-From b03cb9c87a61054ce34b1c19c89170c80d75d27d Mon Sep 17 00:00:00 2001
+From 2d91d69fb5e5fae47919afa5390231121f5e629f Mon Sep 17 00:00:00 2001
@@ -4,0 +5,3 @@
+Cc: Xueming Li <xuemingl at nvidia.com>
+
+[ upstream commit b03cb9c87a61054ce34b1c19c89170c80d75d27d ]
@@ -11 +13,0 @@
-Cc: stable at dpdk.org
@@ -21 +23 @@
-index 4c36df9cb2..38c5a7f06f 100644
+index 7b22281815..23eb59459e 100644
@@ -24 +26 @@
-@@ -8,6 +8,7 @@
+@@ -7,6 +7,7 @@
@@ -32 +34 @@
-@@ -1586,6 +1587,20 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,
+@@ -1579,6 +1580,20 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,
@@ -53 +55 @@
-@@ -1593,7 +1608,7 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,
+@@ -1586,7 +1601,7 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,
@@ -62 +64 @@
-@@ -1603,7 +1618,7 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,
+@@ -1596,7 +1611,7 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,
@@ -71 +73 @@
-@@ -1633,7 +1648,7 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,
+@@ -1626,7 +1641,7 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,
@@ -80 +82 @@
-@@ -1662,6 +1677,10 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,
+@@ -1655,6 +1670,10 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,


More information about the stable mailing list