Skip to contentSkip to conversation

vhost: fix vring enable with VDPA

PATCH Applied David Marchand 4 participants 5 messages Mar 2, 2023 – Mar 6, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost: fix vring enable with VDPA

For VDPA devices, vq are not locked once the device has been configured. But we need to hold the vq lock to check if vhost async is enabled.

Combining VDPA and vhost async does not seem to make much sense, so prevent this combination, and only assert the lock is taken when VDPA is not configured on this vq.

Bugzilla ID: 1169

Fixes 4b02c2673757 ("vhost: annotate async accesses")
---
 lib/vhost/vhost.c      | 4 ++--
 lib/vhost/vhost_user.c | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)
lib/vhost/vhost.c +2 -2
index c36dc06a0a..6b73c03224 100644
@@ -1754,7 +1754,7 @@ rte_vhost_async_channel_register(int vid, uint16_t queue_id)
 
 	vq = dev->virtqueue[queue_id];
 
-	if (unlikely(vq == NULL || !dev->async_copy))
+	if (unlikely(vq == NULL || !dev->async_copy || dev->vdpa_dev))
 		return -1;
 
 	rte_spinlock_lock(&vq->access_lock);
@@ -1778,7 +1778,7 @@ rte_vhost_async_channel_register_thread_unsafe(int vid, uint16_t queue_id)
 
 	vq = dev->virtqueue[queue_id];
 
-	if (unlikely(vq == NULL || !dev->async_copy))
+	if (unlikely(vq == NULL || !dev->async_copy || dev->vdpa_dev))
 		return -1;
 
 	vq_assert_lock(dev, vq);
lib/vhost/vhost_user.c +4 -4
index d702d082dd..daf3458985 100644
@@ -2177,10 +2177,10 @@ vhost_user_set_vring_enable(struct virtio_net **pdev,
 		enable, index);
 
 	vq = dev->virtqueue[index];
-	/* vhost_user_lock_all_queue_pairs locked all qps */
-	vq_assert_lock(dev, vq);
-	if (enable && vq->async) {
-		if (vq->async->pkts_inflight_n) {
+	if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
+		/* vhost_user_lock_all_queue_pairs locked all qps */
+		vq_assert_lock(dev, vq);
+		if (enable && vq->async && vq->async->pkts_inflight_n) {
 			VHOST_LOG_CONFIG(dev->ifname, ERR,
 				"failed to enable vring. Inflight packets must be completed first\n");
 			return RTE_VHOST_MSG_RESULT_ERR;
Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 47 lines · David Marchand

For VDPA devices, vq are not locked once the device has been configured. But we need to hold the vq lock to check if vhost async is enabled.

Combining VDPA and vhost async does not seem to make much sense, so prevent this combination, and only assert the lock is taken when VDPA is not configured on this vq.

Bugzilla ID: 1169

Fixes 4b02c2673757 ("vhost: annotate async accesses")
---
  lib/vhost/vhost.c      | 4 ++--
  lib/vhost/vhost_user.c | 8 ++++----
  2 files changed, 6 insertions(+), 6 deletions(-)
lib/vhost/vhost.c +2 -2
index c36dc06a0a..6b73c03224 100644
@@ -1754,7 +1754,7 @@ rte_vhost_async_channel_register(int vid, uint16_t queue_id)
 
  	vq = dev->virtqueue[queue_id];
 
-	if (unlikely(vq == NULL || !dev->async_copy))
+	if (unlikely(vq == NULL || !dev->async_copy || dev->vdpa_dev))
  		return -1;
 
  	rte_spinlock_lock(&vq->access_lock);
@@ -1778,7 +1778,7 @@ rte_vhost_async_channel_register_thread_unsafe(int vid, uint16_t queue_id)
 
  	vq = dev->virtqueue[queue_id];
 
-	if (unlikely(vq == NULL || !dev->async_copy))
+	if (unlikely(vq == NULL || !dev->async_copy || dev->vdpa_dev))
  		return -1;
 
  	vq_assert_lock(dev, vq);
lib/vhost/vhost_user.c +0 -1
index d702d082dd..daf3458985 100644
@@ -2177,10 +2177,10 @@ vhost_user_set_vring_enable(struct virtio_net **pdev,
  		enable, index);
 
  	vq = dev->virtqueue[index];
-	/* vhost_user_lock_all_queue_pairs locked all qps */

lib/vhost/vhost_user.c vhost_user_set_vring_enable(struct virtio_net **pdev, · line 2186

Quoted 10 lines
lib/vhost/vhost_user.c +4 -3
-	vq_assert_lock(dev, vq);
-	if (enable && vq->async) {
-		if (vq->async->pkts_inflight_n) {
+	if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
+		/* vhost_user_lock_all_queue_pairs locked all qps */
+		vq_assert_lock(dev, vq);
+		if (enable && vq->async && vq->async->pkts_inflight_n) {
  			VHOST_LOG_CONFIG(dev->ifname, ERR,
  				"failed to enable vring. Inflight packets must be completed first\n");
  			return RTE_VHOST_MSG_RESULT_ERR;

Thanks,
Maxime

Reviewed-by on v1 1/1
#2 lore raw
In reply to David Marchand
Quoted 68 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Thursday, March 2, 2023 5:48 PM
To: [email protected]
Cc: [email protected]; [email protected]; Maxime Coquelin <[email protected]>; Xia, Chenbo <[email protected]>; Morten Brørup <[email protected]>
Subject: [PATCH] vhost: fix vring enable with VDPA

For VDPA devices, vq are not locked once the device has been configured. But we need to hold the vq lock to check if vhost async is enabled.

Combining VDPA and vhost async does not seem to make much sense, so prevent this combination, and only assert the lock is taken when VDPA is not configured on this vq.

Bugzilla ID: 1169

Fixes 4b02c2673757 ("vhost: annotate async accesses")
---
 lib/vhost/vhost.c      | 4 ++--
 lib/vhost/vhost_user.c | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)
lib/vhost/vhost.c +1 -1
index c36dc06a0a..6b73c03224 100644
@@ -1754,7 +1754,7 @@ rte_vhost_async_channel_register(int vid, uint16_t
 queue_id)
 
 	vq = dev->virtqueue[queue_id];
 
-	if (unlikely(vq == NULL || !dev->async_copy))
+	if (unlikely(vq == NULL || !dev->async_copy || dev->vdpa_dev))
 		return -1;
 
lib/vhost/vhost.c +1 -1
 	rte_spinlock_lock(&vq->access_lock);
@@ -1778,7 +1778,7 @@ rte_vhost_async_channel_register_thread_unsafe(int
 vid, uint16_t queue_id)
 
 	vq = dev->virtqueue[queue_id];
 
-	if (unlikely(vq == NULL || !dev->async_copy))
+	if (unlikely(vq == NULL || !dev->async_copy || dev->vdpa_dev))
 		return -1;
 
lib/vhost/vhost.c +0 -0
 	vq_assert_lock(dev, vq);
lib/vhost/vhost_user.c +4 -4
index d702d082dd..daf3458985 100644
@@ -2177,10 +2177,10 @@ vhost_user_set_vring_enable(struct virtio_net
 **pdev,
 		enable, index);
 
 	vq = dev->virtqueue[index];
-	/* vhost_user_lock_all_queue_pairs locked all qps */
-	vq_assert_lock(dev, vq);
-	if (enable && vq->async) {
-		if (vq->async->pkts_inflight_n) {
+	if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
+		/* vhost_user_lock_all_queue_pairs locked all qps */
+		vq_assert_lock(dev, vq);
+		if (enable && vq->async && vq->async->pkts_inflight_n) {
 			VHOST_LOG_CONFIG(dev->ifname, ERR,
 				"failed to enable vring. Inflight packets must be
Quoted 4 lines

completed first\n");
return RTE_VHOST_MSG_RESULT_ERR;
--
2.39.2

Tested-by on v1 1/1
#3 lore raw
In reply to David Marchand
Quoted 16 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Thursday, March 2, 2023 11:48 AM
To: [email protected]
Cc: Semion Simma <[email protected]>; Yajun Wu <[email protected]>; Maxime Coquelin <[email protected]>; Chenbo Xia <[email protected]>; Morten Brørup <[email protected]>
Subject: [PATCH] vhost: fix vring enable with VDPA

For VDPA devices, vq are not locked once the device has been configured. But we need to hold the vq lock to check if vhost async is enabled.

Combining VDPA and vhost async does not seem to make much sense, so prevent this combination, and only assert the lock is taken when VDPA is not configured on this vq.

Quoted 5 lines

Bugzilla ID: 1169

Fixes 4b02c2673757 ("vhost: annotate async accesses")

---

Verified it resolves the issue, thanks David.

#4 lore raw
In reply to David Marchand
Quoted 7 lines · David Marchand

For VDPA devices, vq are not locked once the device has been configured. But we need to hold the vq lock to check if vhost async is enabled.

Combining VDPA and vhost async does not seem to make much sense, so prevent this combination, and only assert the lock is taken when VDPA is not configured on this vq.

Quoted 9 lines

Bugzilla ID: 1169

Fixes 4b02c2673757 ("vhost: annotate async accesses")
---
  lib/vhost/vhost.c      | 4 ++--
  lib/vhost/vhost_user.c | 8 ++++----
  2 files changed, 6 insertions(+), 6 deletions(-)

Applied to dpdk-next-virtio/main.

Thanks,
Maxime