vhost: fix vring enable with VDPA
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
--- lib/vhost/vhost.c | 4 ++-- lib/vhost/vhost_user.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-)
lib/vhost/vhost.c +2 -2
@@ -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
@@ -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
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")Signed-off-by David Marchand <[email protected]>--- lib/vhost/vhost.c | 4 ++-- lib/vhost/vhost_user.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-)lib/vhost/vhost.c +2
-2@@ -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@@ -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
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 VDPAFor 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")Signed-off-by David Marchand <[email protected]>--- lib/vhost/vhost.c | 4 ++-- lib/vhost/vhost_user.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-)lib/vhost/vhost.c +1
-1@@ -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
-1rte_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
-0vq_assert_lock (dev, vq);lib/vhost/vhost_user.c +4
-4@@ -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");
returnRTE_VHOST_MSG_RESULT_ERR;
--
2.39.2
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 VDPAFor 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")Signed-off-by David Marchand <[email protected]>---
Verified it resolves the issue, thanks David.
Maxime Coquelin
AppliedQuoted 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")Signed-off-by David Marchand <[email protected]>--- 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