From: Sean Christopherson <seanjc@google.com>
To: Chao Gao <chao.gao@intel.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Kai Huang <kai.huang@intel.com>
Subject: Re: [PATCH v2 1/6] KVM: Register cpuhp and syscore callbacks when enabling hardware
Date: Wed, 29 May 2024 07:29:18 -0700 [thread overview]
Message-ID: <Zlc7vtp4HaPHqZ2K@google.com> (raw)
In-Reply-To: <Zk2MRRkS6c5cGYSV@chao-email>
On Wed, May 22, 2024, Chao Gao wrote:
> On Tue, May 21, 2024 at 07:28:22PM -0700, Sean Christopherson wrote:
> >Register KVM's cpuhp and syscore callback when enabling virtualization
> >in hardware instead of registering the callbacks during initialization,
> >and let the CPU up/down framework invoke the inner enable/disable
> >functions. Registering the callbacks during initialization makes things
> >more complex than they need to be, as KVM needs to be very careful about
> >handling races between enabling CPUs being onlined/offlined and hardware
> >being enabled/disabled.
> >
> >Intel TDX support will require KVM to enable virtualization during KVM
> >initialization, i.e. will add another wrinkle to things, at which point
> >sorting out the potential races with kvm_usage_count would become even
> >more complex.
> >
>
> >Use a dedicated mutex to guard kvm_usage_count, as taking kvm_lock outside
> >cpu_hotplug_lock is disallowed. Ideally, KVM would *always* take kvm_lock
> >outside cpu_hotplug_lock, but KVM x86 takes kvm_lock in several notifiers
> >that may be called under cpus_read_lock(). kvmclock_cpufreq_notifier() in
> >particular has callchains that are infeasible to guarantee will never be
> >called with cpu_hotplug_lock held. And practically speaking, using a
> >dedicated mutex is a non-issue as the cost is a few bytes for all of KVM.
>
> Shouldn't this part go to a separate patch?
>
> I think so because you post a lockdep splat which indicates the existing
> locking order is problematic. So, using a dedicated mutex actually fixes
> some bug and needs a "Fixes:" tag, so that it can be backported separately.
Oooh, good point. I'll try to re-decipher the lockdep splat, and go this route
if using a dedicated lock does is indeed fix a real issue.
> And Documentation/virt/kvm/locking.rst needs to be updated accordingly.
>
> Actually, you are doing a partial revert to the commit:
>
> 0bf50497f03b ("KVM: Drop kvm_count_lock and instead protect kvm_usage_count with kvm_lock")
>
> Perhaps you can handle this as a revert. After that, change the lock from
> a raw_spinlock_t to a mutex.
Hmm, I'd prefer to not revert to a spinlock, even temporarily.
next prev parent reply other threads:[~2024-05-29 14:29 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-22 2:28 [PATCH v2 0/6] KVM: Register cpuhp/syscore callbacks when enabling virt Sean Christopherson
2024-05-22 2:28 ` [PATCH v2 1/6] KVM: Register cpuhp and syscore callbacks when enabling hardware Sean Christopherson
2024-05-22 6:10 ` Chao Gao
2024-05-29 14:29 ` Sean Christopherson [this message]
2024-05-22 2:28 ` [PATCH v2 2/6] KVM: Rename functions related to enabling virtualization hardware Sean Christopherson
2024-05-22 7:10 ` Chao Gao
2024-05-22 22:34 ` Huang, Kai
2024-05-22 2:28 ` [PATCH v2 3/6] KVM: Add a module param to allow enabling virtualization when KVM is loaded Sean Christopherson
2024-05-22 22:27 ` Huang, Kai
2024-05-23 4:23 ` Chao Gao
2024-05-23 23:11 ` Huang, Kai
2024-05-24 2:39 ` Chao Gao
2024-05-27 22:36 ` Huang, Kai
2024-05-29 15:01 ` Sean Christopherson
2024-05-29 22:45 ` Huang, Kai
2024-05-29 23:07 ` Sean Christopherson
2024-05-30 0:06 ` Huang, Kai
2024-05-22 2:28 ` [PATCH v2 4/6] KVM: Add arch hooks for enabling/disabling virtualization Sean Christopherson
2024-05-22 22:33 ` Huang, Kai
2024-05-28 22:50 ` Sean Christopherson
2024-05-23 5:31 ` Chao Gao
2024-05-22 2:28 ` [PATCH v2 5/6] x86/reboot: Unconditionally define cpu_emergency_virt_cb typedef Sean Christopherson
2024-05-22 22:35 ` Huang, Kai
2024-05-23 5:41 ` Chao Gao
2024-05-22 2:28 ` [PATCH v2 6/6] KVM: x86: Register "emergency disable" callbacks when virt is enabled Sean Christopherson
2024-05-22 22:37 ` Huang, Kai
2024-05-23 5:59 ` Chao Gao
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=Zlc7vtp4HaPHqZ2K@google.com \
--to=seanjc@google.com \
--cc=chao.gao@intel.com \
--cc=kai.huang@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.