Skip to contentSkip to conversation

vhost: fix deadlock with no multiqueue

PATCH In review David Marchand 2 participants 3 messages Mar 23, 2023 – Mar 26, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost: fix deadlock with no multiqueue

This deadlock happens when a guest, that had virtio ports with multi queues configured, does not announce the multi q feature in SET_FEATURES.
In such a situation, all vq locks are already taken before calling free_vq(), which itself takes the lock.

As mentioned in the code, in this situation, the virtio device is not running yet and no datapath thread is using the vq. So we can release the lock before calling free_vq().

Bugzilla ID: 1196

Fixes 4b02c2673757 ("vhost: annotate async accesses")
---
 lib/vhost/vhost_user.c | 3 +++
 1 file changed, 3 insertions(+)
lib/vhost/vhost_user.c +3 -0
index f5edba8548..d60e39b6bc 100644
@@ -397,6 +397,9 @@ vhost_user_set_features(struct virtio_net **pdev,
 			dev->virtqueue[dev->nr_vring] = NULL;
 			cleanup_vq(vq, 1);
 			cleanup_vq_inflight(dev, vq);
+			/* vhost_user_lock_all_queue_pairs locked all qps */
+			vq_assert_lock(dev, vq);
+			rte_spinlock_unlock(&vq->access_lock);
 			free_vq(dev, vq);
 		}
 	}
Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · David Marchand

This deadlock happens when a guest, that had virtio ports with multi queues configured, does not announce the multi q feature in SET_FEATURES.
In such a situation, all vq locks are already taken before calling free_vq(), which itself takes the lock.

As mentioned in the code, in this situation, the virtio device is not running yet and no datapath thread is using the vq. So we can release the lock before calling free_vq().

Bugzilla ID: 1196

Fixes 4b02c2673757 ("vhost: annotate async accesses")
---
  lib/vhost/vhost_user.c | 3 +++
  1 file changed, 3 insertions(+)
lib/vhost/vhost_user.c +0 -0
index f5edba8548..d60e39b6bc 100644

lib/vhost/vhost_user.c vhost_user_set_features(struct virtio_net **pdev, · line 405

Quoted 9 lines
lib/vhost/vhost_user.c +3 -0
@@ -397,6 +397,9 @@ vhost_user_set_features(struct virtio_net **pdev,
  			dev->virtqueue[dev->nr_vring] = NULL;
  			cleanup_vq(vq, 1);
  			cleanup_vq_inflight(dev, vq);
+			/* vhost_user_lock_all_queue_pairs locked all qps */
+			vq_assert_lock(dev, vq);
+			rte_spinlock_unlock(&vq->access_lock);
  			free_vq(dev, vq);
  		}
  	}

Thanks,
Maxime

author Applied
#2 lore raw
Quoted 11 lines · Maxime Coquelin
Quoted 10 lines · David Marchand

This deadlock happens when a guest, that had virtio ports with multi queues configured, does not announce the multi q feature in SET_FEATURES.
In such a situation, all vq locks are already taken before calling free_vq(), which itself takes the lock.

As mentioned in the code, in this situation, the virtio device is not running yet and no datapath thread is using the vq. So we can release the lock before calling free_vq().

Quoted 5 lines
Quoted 4 lines

Bugzilla ID: 1196

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

Applied, thanks.

Signature · 1 line
David Marchand