From: Paolo Bonzini <pbonzini@redhat.com>
To: Sean Christopherson <seanjc@google.com>
Cc: linux-kernel@vger.kernel.org, kvm <kvm@vger.kernel.org>
Subject: Re: [PATCH 1/2] KVM: x86: fix usage of kvm_lock in set_nx_huge_pages()
Date: Sat, 25 Jan 2025 01:08:28 +0100 [thread overview]
Message-ID: <0188baf2-0bff-4b08-af1d-21815d4e3b42@redhat.com> (raw)
In-Reply-To: <Z5QhGndjNwYdnIZF@google.com>
On 1/25/25 00:44, Sean Christopherson wrote:
>> I did try a long SRCU critical section and it was unreviewable. It
>> ends up a lot less manageable than just making the lock a leaf,
>> especially as the lock hierarchy spans multiple subsystems (static
>> key, KVM, cpufreq---thanks CPU hotplug lock...).
>
> I'm not following. If __kvmclock_cpufreq_notifier() and set_nx_huge_pages()
> switch to SRCU, then the deadlock goes away (it might even go away if just one
> of those two switches). [...] It would be single use in the it only
> protects pure reader of vm_list, but there are plenty of those users.
Yes, single use in the sense that only set_nx_huge_pages() really needs
it. kvm_lock doesn't produce any noticeable contention and as you noted
sometimes you really need it even in pure readers.
> SRCU readers would only interact with kvm_destroy_vm() from a locking perspective,
> and if that's problematic then we would already have a plethora of issues.
Ah yeah, I missed that you cannot hold any lock when calling
kvm_put_kvm(). So the waiting side is indeed a leaf and cannot block
someone else.
Still from your patch (thanks!) I don't really like the special cases on
taking SRCU vs. kvm_lock... It really seems like a job for a mutex or
rwsem. It keeps the complexity in the one place that is different (i.e.
where a lock is taken inside the iteration) and everything else can just
iterate normally.
Paolo
next prev parent reply other threads:[~2025-01-25 0:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-24 19:11 [RFC PATCH 0/2] KVM: x86: Strengthen locking rules for kvm_lock Paolo Bonzini
2025-01-24 19:11 ` [PATCH 1/2] KVM: x86: fix usage of kvm_lock in set_nx_huge_pages() Paolo Bonzini
2025-01-24 20:11 ` Sean Christopherson
2025-01-24 22:19 ` Paolo Bonzini
2025-01-24 23:44 ` Sean Christopherson
2025-01-25 0:08 ` Paolo Bonzini [this message]
2025-01-25 0:44 ` Sean Christopherson
2025-01-27 17:27 ` Paolo Bonzini
2025-01-27 17:56 ` Paolo Bonzini
2025-01-27 18:01 ` Sean Christopherson
2025-01-27 18:17 ` Paolo Bonzini
2025-01-24 19:11 ` [PATCH 2/2] Documentation: explain issues with taking locks inside kvm_lock Paolo Bonzini
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=0188baf2-0bff-4b08-af1d-21815d4e3b42@redhat.com \
--to=pbonzini@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=seanjc@google.com \
/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
all inboxes | Powered by JetHome®