From: "Huang, Kai" <kai.huang@intel.com>
To: "seanjc@google.com" <seanjc@google.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"pbonzini@redhat.com" <pbonzini@redhat.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Gao, Chao" <chao.gao@intel.com>
Subject: Re: [PATCH v3 4/8] KVM: Add a module param to allow enabling virtualization when KVM is loaded
Date: Wed, 14 Aug 2024 11:47:58 +1200 [thread overview]
Message-ID: <4273c812-9ca4-4cf8-a3cc-921db5f3828e@intel.com> (raw)
In-Reply-To: <c3205ac001776585d2a1fd14ebfec631d8ff7d3a.camel@intel.com>
On 13/08/2024 5:22 pm, Huang, Kai wrote:
> On Mon, 2024-08-12 at 19:31 -0700, Sean Christopherson wrote:
>> On Fri, Aug 02, 2024, Kai Huang wrote:
>>>
>>>> +static void kvm_uninit_virtualization(void)
>>>> +{
>>>> + if (enable_virt_at_load)
>>>> + kvm_disable_virtualization();
>>>> +
>>>> + WARN_ON(kvm_usage_count);
>>>> +}
>>>>
>>>
>>> Hi Sean,
>>>
>>> The above "WARN_ON(kvm_usage_count);" assumes the
>>> kvm_uninit_virtualization() is the last call of
>>> kvm_disable_virtualization(), and it is called ...
>>>
>>>> @@ -6433,6 +6468,8 @@ void kvm_exit(void)
>>>> */
>>>> misc_deregister(&kvm_dev);
>>>>
>>>> + kvm_uninit_virtualization();
>>>> +
>>>>
>>>
>>> ... from kvm_exit().
>>>
>>> Accordingly, kvm_init_virtualization() is called in kvm_init().
>>>
>>> For TDX, we want to "explicitly call kvm_enable_virtualization() +
>>> initializing TDX module" before kvm_init() in vt_init(), since kvm_init()
>>> is supposed to be the last step after initializing TDX.
>>>
>>> In the exit path, accordingly, for TDX we want to call kvm_exit() first,
>>> and then "do TDX cleanup staff + explicitly call
>>> kvm_disable_virtualizaation()".
>>>
>>> This will trigger the above "WARN_ON(kvm_usage_count);" when
>>> enable_virt_at_load is true, because kvm_uninit_virtualization() isn't
>>> the last call of kvm_disable_virtualization().
>>>
>>> To resolve, I think one way is we can move kvm_init_virtualization() out
>>> of kvm_init(), but I am not sure whether there's another common place
>>> that kvm_init_virtualization() can be called for all ARCHs.
>>>
>>> Do you have any comments?
>>
>> Drat. That's my main coment, though not the exact word I used :-)
>>
>> I managed to completely forget about TDX needing to enable virtualization to do
>> its setup before creating /dev/kvm. A few options jump to mind:
>>
>> 1. Expose kvm_enable_virtualization() to arch code and delete the WARN_ON().
>>
>> 2. Move kvm_init_virtualization() as you suggested.
>>
>> 3. Move the call to misc_register() out of kvm_init(), so that arch code can
>> do additional setup between kvm_init() and kvm_register_dev_kvm() or whatever.
>>
>> I'm leaning towards #1. IIRC, that was my original intent before going down the
>> "enable virtualization at module load" path. And it's not mutually exclusive
>> with allowing virtualization to be forced on at module load.
>>
>> If #1 isn't a good option for whatever reason, I'd lean slightly for #3 over #2,
>> purely because it's less arbitrary (registering /dev/kvm is the only thing that
>> has strict ordering requirements). But I don't know that having a separate
>> registration API would be a net positive, e.g. it's kinda nice that kvm_init()
>> needs to be last, because it helps ensure some amount of guaranteed ordering
>> between common KVM and arch code.
>
> I agree with option 1). We just allow arch code to do additional
> kvm_enable_virtualization() before kvm_init() and kvm_disable_virtualization()
> after kvm_exit(). I think it's kinda normal behaviour anyway.
>
> And this is exactly what I am doing :-)
>
> https://github.com/intel/tdx/commit/2f7cef685527a5ef952346ff5ab9adbb8bb6f371
> https://github.com/intel/tdx/commit/6c76ffa47a98ca370fad389271dc3cedf304df2d
>
Hi Sean,
Forgot to ask: I assume you will post v4 with that WARN_ON() in
kvm_uninit_virtualizaiton() removed, correct?
I am not sure whether you will include the patch to export
kvm_enable_virtualization() and kvm_disable_virtualization() but either
way is fine to me.
I am thinking if we can get this patchset merged to kvm-coco-queue then
we can actually start to review (and try to integrate) the "init TDX
during KVM loading" patches.
I appreciate if you and Paolo could share some plan on this. Thanks!
next prev parent reply other threads:[~2024-08-13 23:48 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-08 0:06 [PATCH v3 0/8] KVM: Register cpuhp/syscore callbacks when enabling virt Sean Christopherson
2024-06-08 0:06 ` [PATCH v3 1/8] KVM: Use dedicated mutex to protect kvm_usage_count to avoid deadlock Sean Christopherson
2024-06-10 0:26 ` Huang, Kai
2024-08-14 18:06 ` Paolo Bonzini
2024-08-15 14:39 ` Sean Christopherson
2024-08-15 16:10 ` Paolo Bonzini
2024-08-30 23:45 ` Sean Christopherson
2024-09-02 13:03 ` Paolo Bonzini
2024-06-08 0:06 ` [PATCH v3 2/8] KVM: Register cpuhp and syscore callbacks when enabling hardware Sean Christopherson
2024-06-10 0:55 ` Huang, Kai
2024-08-14 18:12 ` Paolo Bonzini
2024-08-14 20:55 ` Sean Christopherson
2024-06-08 0:06 ` [PATCH v3 3/8] KVM: Rename functions related to enabling virtualization hardware Sean Christopherson
2024-06-08 0:06 ` [PATCH v3 4/8] KVM: Add a module param to allow enabling virtualization when KVM is loaded Sean Christopherson
2024-08-02 12:02 ` Huang, Kai
2024-08-02 12:06 ` Huang, Kai
2024-08-13 2:31 ` Sean Christopherson
2024-08-13 5:22 ` Huang, Kai
2024-08-13 23:47 ` Huang, Kai [this message]
2024-08-14 18:14 ` Paolo Bonzini
2024-06-08 0:06 ` [PATCH v3 5/8] KVM: Add arch hooks for enabling/disabling virtualization Sean Christopherson
2024-08-14 18:15 ` Paolo Bonzini
2024-06-08 0:06 ` [PATCH v3 6/8] x86/reboot: Unconditionally define cpu_emergency_virt_cb typedef Sean Christopherson
2024-06-08 0:06 ` [PATCH v3 7/8] KVM: x86: Register "emergency disable" callbacks when virt is enabled Sean Christopherson
2024-06-08 0:06 ` [PATCH v3 8/8] KVM: Enable virtualization at load/initialization by default Sean Christopherson
2024-08-14 18:20 ` Paolo Bonzini
2024-06-10 0:59 ` [PATCH v3 0/8] KVM: Register cpuhp/syscore callbacks when enabling virt Huang, Kai
2024-08-14 18:23 ` Paolo Bonzini
2024-08-14 22:17 ` Huang, Kai
2024-08-15 14:41 ` Sean Christopherson
2024-08-20 8:57 ` 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=4273c812-9ca4-4cf8-a3cc-921db5f3828e@intel.com \
--to=kai.huang@intel.com \
--cc=chao.gao@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--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®