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

From: Yishai Hadas

Date: Wed Apr 15 2026 - 11:13:37 EST


On 14/04/2026 23:06, Alex Williamson wrote:
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.

Alex,
How about staying with spin_lock but without the 'irq' variant, instead of replacing to mutex ?

The scope of the lock is very small which can fit spin.
We may potentially get a performance degradation compared to mutex as part of the hot path of STOP_COPY where this lock is used.

Note:
I don't see that other peer vfio-pci variant drivers maintain a list of buffers as of this driver, unless I missed that.

Patch 2 converts the list_lock acquisitions to guard()/scoped_guard()
where the lock scope aligns naturally with function or block scope.


This patch might not be applicable if we'll stay with spin_lock.

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,


Those 2 patches seem fine to me.
Reviewed-by: Yishai Hadas <yishaih@xxxxxxxxxx>

Yishai

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(-)