[PATCH 20.11] vhost: fix async access
David Marchand
david.marchand at redhat.com
Fri Jun 17 07:52:27 CEST 2022
[ upstream commit 2d47fd3dfb596d266b89d82c2c4b2351c3d6fe20 ]
vq->async accesses must be protected with vq->access_lock.
Fixes: eb666d24085f ("vhost: fix async unregister deadlock")
Fixes: 0c0935c5f794 ("vhost: allow to check in-flight packets for async vhost")
Signed-off-by: David Marchand <david.marchand at redhat.com>
Acked-by: Sunil Pai G <sunil.pai.g at intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin at redhat.com>
---
lib/librte_vhost/vhost.c | 27 +++++++++++----------------
1 file changed, 11 insertions(+), 16 deletions(-)
diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index 1a7c240492..40a2554417 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -1693,31 +1693,26 @@ int rte_vhost_async_channel_unregister(int vid, uint16_t queue_id)
if (vq == NULL)
return ret;
- ret = 0;
-
- if (!vq->async_registered)
- return ret;
-
if (!rte_spinlock_trylock(&vq->access_lock)) {
VHOST_LOG_CONFIG(ERR, "Failed to unregister async channel. "
"virt queue busy.\n");
- return -1;
+ return ret;
}
- if (vq->async_pkts_inflight_n) {
+ if (!vq->async_registered) {
+ ret = 0;
+ } else if (vq->async_pkts_inflight_n) {
VHOST_LOG_CONFIG(ERR, "Failed to unregister async channel. "
"async inflight packets must be completed before unregistration.\n");
- ret = -1;
- goto out;
- }
-
- vhost_free_async_mem(vq);
+ } else {
+ ret = 0;
+ vhost_free_async_mem(vq);
- vq->async_ops.transfer_data = NULL;
- vq->async_ops.check_completed_copies = NULL;
- vq->async_registered = false;
+ vq->async_ops.transfer_data = NULL;
+ vq->async_ops.check_completed_copies = NULL;
+ vq->async_registered = false;
+ }
-out:
rte_spinlock_unlock(&vq->access_lock);
return ret;
--
2.36.1
More information about the stable
mailing list