From: Yishai Hadas <yishaih@nvidia.com>
To: Alex Williamson <alex.williamson@nvidia.com>
Cc: <alex@shazbot.org>, <kvm@vger.kernel.org>,
<guojinhui.liam@bytedance.com>, <linux-kernel@vger.kernel.org>,
<virtualization@lists.linux.dev>
Subject: Re: [PATCH 0/4] vfio/virtio: Fix list_lock type and modernize locking
Date: Wed, 15 Apr 2026 20:23:14 +0300 [thread overview]
Message-ID: <e202ba24-b93c-48d3-bfbe-4fb1e538f4b7@nvidia.com> (raw)
In-Reply-To: <20260415093945.36d01312@nvidia.com>
On 15/04/2026 18:39, Alex Williamson wrote:
> On Wed, 15 Apr 2026 18:12:50 +0300
> Yishai Hadas <yishaih@nvidia.com> wrote:
>
>> 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.
>
> The argument doesn't make sense to me, we use a spinlock if we have an
> operation that cannot be preempted and a spinlock-irq if we need to
> manage that from a hardirq context. I think we just need mutual
> exclusion here. Stealing the CPU because you want the absolute best
> performance for a little bit of list manipulation is not valid
> justification.
>
> Documentation/locking/mutex-design.rst:
>
> When to use mutexes
> -------------------
>
> Unless the strict semantics of mutexes are unsuitable and/or the critical
> region prevents the lock from being shared, always prefer them to any other
> locking primitive.
>
> Can you cite specific requirements for a spinlock in the critical
> section here? Thanks,
>
I see
In our use case, we mostly expect a single task handling the migration,
so real contention is unlikely and we don’t anticipate the overhead of
sleeping and waking to be triggered.
That said, I’m fine with using a mutex here as of your patch.
So,
Reviewed-by: Yishai Hadas <yishaih@nvidia.com>
For the full series.
Yishai
>
>>> 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@nvidia.com>
>>
>> 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(-)
>>>
>>
>
prev parent reply other threads:[~2026-04-15 17:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-14 20:06 [PATCH 0/4] vfio/virtio: Fix list_lock type and modernize locking Alex Williamson
2026-04-14 20:06 ` [PATCH 1/4] vfio/virtio: Convert list_lock from spinlock to mutex Alex Williamson
2026-04-14 20:06 ` [PATCH 2/4] vfio/virtio: Use guard() for list_lock where applicable Alex Williamson
2026-04-14 20:06 ` [PATCH 3/4] vfio/virtio: Use guard() for migf->lock " Alex Williamson
2026-04-14 20:06 ` [PATCH 4/4] vfio/virtio: Use guard() for bar_mutex in legacy I/O Alex Williamson
2026-04-15 15:12 ` [PATCH 0/4] vfio/virtio: Fix list_lock type and modernize locking Yishai Hadas
2026-04-15 15:39 ` Alex Williamson
2026-04-15 17:23 ` Yishai Hadas [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e202ba24-b93c-48d3-bfbe-4fb1e538f4b7@nvidia.com \
--to=yishaih@nvidia.com \
--cc=alex.williamson@nvidia.com \
--cc=alex@shazbot.org \
--cc=guojinhui.liam@bytedance.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=virtualization@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox