patches for DPDK stable branches
 help / color / mirror / Atom feed
* [v9 2/6] vhost: skip crypto op fetch before vring init
       [not found] <cover.1740749809.git.gmuthukrishn@marvell.com>
@ 2025-02-28 13:47 ` Gowrishankar Muthukrishnan
  2025-03-03  9:08   ` Maxime Coquelin
  2025-02-28 13:47 ` [v9 4/6] examples/vhost_crypto: fix user callbacks Gowrishankar Muthukrishnan
  1 sibling, 1 reply; 4+ messages in thread
From: Gowrishankar Muthukrishnan @ 2025-02-28 13:47 UTC (permalink / raw)
  To: dev, maxime.coquelin, Chenbo Xia, Fan Zhang, Jay Zhou
  Cc: anoobj, Akhil Goyal, David Marchand, Gowrishankar Muthukrishnan, stable

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")
Cc: stable@dpdk.org

Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
Acked-by: Akhil Goyal <gakhil@marvell.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 4c36df9cb2..38c5a7f06f 100644
--- a/lib/vhost/vhost_crypto.c
+++ b/lib/vhost/vhost_crypto.c
@@ -8,6 +8,7 @@
 #include <rte_mbuf.h>
 #include <rte_cryptodev.h>
 
+#include "iotlb.h"
 #include "rte_vhost_crypto.h"
 #include "vhost.h"
 #include "vhost_user.h"
@@ -1586,6 +1587,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;
@@ -1593,7 +1608,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
@@ -1603,7 +1618,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++) {
@@ -1633,7 +1648,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++) {
@@ -1662,6 +1677,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.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [v9 4/6] examples/vhost_crypto: fix user callbacks
       [not found] <cover.1740749809.git.gmuthukrishn@marvell.com>
  2025-02-28 13:47 ` [v9 2/6] vhost: skip crypto op fetch before vring init Gowrishankar Muthukrishnan
@ 2025-02-28 13:47 ` Gowrishankar Muthukrishnan
  2025-03-03  9:46   ` Maxime Coquelin
  1 sibling, 1 reply; 4+ messages in thread
From: Gowrishankar Muthukrishnan @ 2025-02-28 13:47 UTC (permalink / raw)
  To: dev, maxime.coquelin, Chenbo Xia, Jay Zhou, Fan Zhang
  Cc: anoobj, Akhil Goyal, David Marchand, Gowrishankar Muthukrishnan, stable

In order to handle new vhost user connection, use new_connection
and destroy_connection callbacks.

Fixes: f5188211c721 ("examples/vhost_crypto: add sample application")
Cc: stable@dpdk.org

Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
Acked-by: Akhil Goyal <gakhil@marvell.com>
---
 examples/vhost_crypto/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/examples/vhost_crypto/main.c b/examples/vhost_crypto/main.c
index 558c09a60f..b1fe4120b9 100644
--- a/examples/vhost_crypto/main.c
+++ b/examples/vhost_crypto/main.c
@@ -362,8 +362,8 @@ destroy_device(int vid)
 }
 
 static const struct rte_vhost_device_ops virtio_crypto_device_ops = {
-	.new_device =  new_device,
-	.destroy_device = destroy_device,
+	.new_connection =  new_device,
+	.destroy_connection = destroy_device,
 };
 
 static int
-- 
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [v9 2/6] vhost: skip crypto op fetch before vring init
  2025-02-28 13:47 ` [v9 2/6] vhost: skip crypto op fetch before vring init Gowrishankar Muthukrishnan
@ 2025-03-03  9:08   ` Maxime Coquelin
  0 siblings, 0 replies; 4+ messages in thread
From: Maxime Coquelin @ 2025-03-03  9:08 UTC (permalink / raw)
  To: Gowrishankar Muthukrishnan, dev, Chenbo Xia, Fan Zhang, Jay Zhou
  Cc: anoobj, Akhil Goyal, David Marchand, stable



On 2/28/25 2:47 PM, Gowrishankar Muthukrishnan wrote:
> 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")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
> Acked-by: Akhil Goyal <gakhil@marvell.com>
> ---
>   lib/vhost/vhost_crypto.c | 25 ++++++++++++++++++++++---
>   1 file changed, 22 insertions(+), 3 deletions(-)
> 

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [v9 4/6] examples/vhost_crypto: fix user callbacks
  2025-02-28 13:47 ` [v9 4/6] examples/vhost_crypto: fix user callbacks Gowrishankar Muthukrishnan
@ 2025-03-03  9:46   ` Maxime Coquelin
  0 siblings, 0 replies; 4+ messages in thread
From: Maxime Coquelin @ 2025-03-03  9:46 UTC (permalink / raw)
  To: Gowrishankar Muthukrishnan, dev, Chenbo Xia, Jay Zhou, Fan Zhang
  Cc: anoobj, Akhil Goyal, David Marchand, stable



On 2/28/25 2:47 PM, Gowrishankar Muthukrishnan wrote:
> In order to handle new vhost user connection, use new_connection
> and destroy_connection callbacks.
> 
> Fixes: f5188211c721 ("examples/vhost_crypto: add sample application")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
> Acked-by: Akhil Goyal <gakhil@marvell.com>
> ---
>   examples/vhost_crypto/main.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-03-03  9:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <cover.1740749809.git.gmuthukrishn@marvell.com>
2025-02-28 13:47 ` [v9 2/6] vhost: skip crypto op fetch before vring init Gowrishankar Muthukrishnan
2025-03-03  9:08   ` Maxime Coquelin
2025-02-28 13:47 ` [v9 4/6] examples/vhost_crypto: fix user callbacks Gowrishankar Muthukrishnan
2025-03-03  9:46   ` Maxime Coquelin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).