Skip to content

vfio/virtio: Fix list_lock type and modernize locking

Alex Williamson kvm lkml stable virtualization 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 3 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4vfio/virtio: Convert list_lock from spinlock to mutexdrivers/vfio/pci/virtio/common.h drivers/vfio/pci/virtio/migrate.c+18 -170 replies
2/4vfio/virtio: Use guard() for list_lock where applicabledrivers/vfio/pci/virtio/migrate.c+16 -210 replies
3/4vfio/virtio: Use guard() for migf->lock where applicabledrivers/vfio/pci/virtio/migrate.c+14 -260 replies
4/4vfio/virtio: Use guard() for bar_mutex in legacy I/Odrivers/vfio/pci/virtio/legacy_io.c+8 -90 replies

Reviews trailers per patch

None of the 4 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchYishai Hadas
SeriesR-b R-b
1/4
2/4
3/4
4/4

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/4] vfio/virtio: Fix list_lock type and modernize locking

Jinhui Guo reported a mismatched spin_lock()/spin_unlock_irq() pair in virtiovf_read_device_context_chunk() where spin_unlock_irq() would unconditionally enable interrupts despite spin_lock() never having disabled them. On closer inspection, the list_lock spinlock with IRQ disabling was copied from the mlx5 variant driver where a hardirq completion callback justifies it, but the virtio driver has no interrupt context usage of list_lock. Patch 1 converts list_lock to a mutex, fixing the mismatch and aligning with peer vfio-pci variant drivers.
Patch 2 converts the list_lock acquisitions to guard()/scoped_guard() where the lock scope aligns naturally with function or block scope.

Patches 3 and 4 extend the same guard() conversion to the remaining two mutexes in the driver (migf->lock and bar_mutex). These are relatively independent of the list_lock fix but complete the conversion across the driver. Thanks,

Alex

Alex Williamson (4):
vfio/virtio: Convert list_lock from spinlock to mutex vfio/virtio: Use guard() for list_lock where applicable vfio/virtio: Use guard() for migf->lock where applicable vfio/virtio: Use guard() for bar_mutex in legacy I/O

 drivers/vfio/pci/virtio/common.h    |  2 +-
 drivers/vfio/pci/virtio/legacy_io.c | 17 +++---
 drivers/vfio/pci/virtio/migrate.c   | 90 ++++++++++++-----------------
 3 files changed, 46 insertions(+), 63 deletions(-)
Signature · 1 line
2.51.0