Fix lock errors in VDUSE suspend feature
Eugenio Pérez
maintainercover Fix lock errors in VDUSE suspend feature
Fix wrong ordering at taking semaphore after spinlock and convert the spinlock take and release into guards, so they are not lost after a return.
This series goes on top of https://lore.kernel.org/lkml/[email protected]/
---
It would be great if these can be squashed.
Eugenio Pérez (2):
vduse: fix not releasing taken semaphore in vduse_dev_queue_irq_work
vduse: not take the device semaphore while holding vq spinlock
drivers/vdpa/vdpa_user/vduse_dev.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
--
2.54.0
Eugenio Pérez
maintainerPATCH 1/2 vduse: fix not releasing taken semaphore in vduse_dev_queue_irq_work
If dev->suspended the function returns not relasing the semaphore, so the only solution to be able to use the device is to reset again from userspace. Convert the semaphore functions to the equivalent guard() to avoid it.
--- drivers/vdpa/vdpa_user/vduse_dev.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/vdpa/vdpa_user/vduse_dev.c +2 -7
@@ -1281,21 +1281,16 @@ static int vduse_dev_queue_irq_work(struct vduse_dev *dev, {int ret = -EINVAL ; -down_read (&dev->rwsem); -if (dev->suspended) +guard (rwsem_read)(&dev->rwsem); +if (dev->suspended || !(dev->status &VIRTIO_CONFIG_S_DRIVER_OK ))return ret; -if (!(dev->status &VIRTIO_CONFIG_S_DRIVER_OK )) - goto unlock; - ret =0 ;if (irq_effective_cpu ==IRQ_UNBOUND )queue_work (vduse_irq_wq, irq_work);else queue_work_on (irq_effective_cpu, vduse_irq_bound_wq, irq_work); -unlock: -up_read (&dev->rwsem);return ret; }
Signature · 1 line
2.54.0
Eugenio Pérez
maintainerPATCH 2/2 vduse: not take the device semaphore while holding vq spinlock
In reply to Eugenio PérezIt's an invalid lock pattern, so take them reversely.
This also makes the lock ordering coherent with vduse_dev_reset.
--- drivers/vdpa/vdpa_user/vduse_dev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/vdpa/vdpa_user/vduse_dev.c +4 -4
@@ -561,14 +561,14 @@ static int vduse_vdpa_set_vq_address(struct vdpa_device *vdpa, u16 idx,static void vduse_vq_kick (struct vduse_virtqueue *vq) { -guard (spinlock)(&vq->kick_lock); -if (!vq->ready) -return ; -guard (rwsem_read)(&vq->dev->rwsem);if (vq->dev->suspended)return ; +guard (spinlock)(&vq->kick_lock); +if (!vq->ready) +return ; +if (vq->kickfd)eventfd_signal (vq->kickfd);else
--
2.54.0
Michael S. Tsirkin
maintainerQuoted 4 lines · Eugenio Pérez
Fix wrong ordering at taking semaphore after spinlock and convert the spinlock take and release into guards, so they are not lost after a return.
This series goes on top of https://lore.kernel.org/lkml/[email protected]/
And vduse: Fix error around jumping over a __cleanup() variable
does it obliviate that?
Quoted 12 lines
---
It would be great if these can be squashed.Eugenio Pérez (2):
vduse: fix not releasing taken semaphore invduse_dev_queue_irq_work
vduse: not take the device semaphore while holding vq spinlockdrivers/vdpa/vdpa_user/vduse_dev.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)--
2.54.0
Michael S. Tsirkin
maintainerQuoted 6 lines · Eugenio Pérez
Fix wrong ordering at taking semaphore after spinlock and convert the spinlock take and release into guards, so they are not lost after a return.
This series goes on top of https://lore.kernel.org/lkml/[email protected]/
---
It would be great if these can be squashed.
if you want that then just send v4.
Quoted 10 lines
Eugenio Pérez (2):
vduse: fix not releasing taken semaphore invduse_dev_queue_irq_work
vduse: not take the device semaphore while holding vq spinlockdrivers/vdpa/vdpa_user/vduse_dev.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)--
2.54.0
Michael S. Tsirkin
maintainerQuoted 4 lines · Eugenio Pérez
Fix wrong ordering at taking semaphore after spinlock and convert the spinlock take and release into guards, so they are not lost after a return.
This series goes on top of https://lore.kernel.org/lkml/[email protected]/
does not apply there.
Quoted 12 lines
---
It would be great if these can be squashed.Eugenio Pérez (2):
vduse: fix not releasing taken semaphore invduse_dev_queue_irq_work
vduse: not take the device semaphore while holding vq spinlockdrivers/vdpa/vdpa_user/vduse_dev.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)--
2.54.0
Michael S. Tsirkin
maintainerQuoted 4 lines · Eugenio Pérez
Fix wrong ordering at taking semaphore after spinlock and convert the spinlock take and release into guards, so they are not lost after a return.
This series goes on top of https://lore.kernel.org/lkml/[email protected]/
You mean 20260610-vduse_vq_kick-fix-guard-usage-v1-1-0ce02c08006e@kernel.org actually
Quoted 12 lines
---
It would be great if these can be squashed.Eugenio Pérez (2):
vduse: fix not releasing taken semaphore invduse_dev_queue_irq_work
vduse: not take the device semaphore while holding vq spinlockdrivers/vdpa/vdpa_user/vduse_dev.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)--
2.54.0
Michael S. Tsirkin
maintainerQuoted 6 lines · Eugenio Pérez
Fix wrong ordering at taking semaphore after spinlock and convert the spinlock take and release into guards, so they are not lost after a return.
This series goes on top of https://lore.kernel.org/lkml/[email protected]/
---
It would be great if these can be squashed.
ok i figured out the confusion. squashed
Quoted 10 lines
Eugenio Pérez (2):
vduse: fix not releasing taken semaphore invduse_dev_queue_irq_work
vduse: not take the device semaphore while holding vq spinlockdrivers/vdpa/vdpa_user/vduse_dev.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)--
2.54.0
Eugenio Perez Martin
maintainerQuoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · Eugenio Pérez
Fix wrong ordering at taking semaphore after spinlock and convert the spinlock take and release into guards, so they are not lost after a return.
This series goes on top of https://lore.kernel.org/lkml/[email protected]/
---
It would be great if these can be squashed.ok i figured out the confusion. squashed
Yes, you're right; this is on top of Nathan's. Thanks for both merging and figuring it out!