From: "Huang, Kai" <kai.huang@intel.com>
To: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"pbonzini@redhat.com" <pbonzini@redhat.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: "seanjc@google.com" <seanjc@google.com>,
"Zhao, Yan Y" <yan.y.zhao@intel.com>,
"Edgecombe, Rick P" <rick.p.edgecombe@intel.com>
Subject: Re: [PATCH 12/30] KVM: VMX: Initialize TDX during KVM module load
Date: Thu, 20 Feb 2025 23:27:48 +0000 [thread overview]
Message-ID: <64168d1d11afb399685067c6f8d57a738bb97eb6.camel@intel.com> (raw)
In-Reply-To: <20250220170604.2279312-13-pbonzini@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 3235 bytes --]
> +
> +static void __do_tdx_cleanup(void)
> +{
> + /*
> + * Once TDX module is initialized, it cannot be disabled and
> + * re-initialized again w/o runtime update (which isn't
> + * supported by kernel). Only need to remove the cpuhp here.
> + * The TDX host core code tracks TDX status and can handle
> + * 'multiple enabling' scenario.
> + */
> + WARN_ON_ONCE(!tdx_cpuhp_state);
> + cpuhp_remove_state_nocalls(tdx_cpuhp_state);
> + tdx_cpuhp_state = 0;
> +}
> +
> +static int __init __do_tdx_bringup(void)
> +{
> + int r;
> +
> + /*
> + * TDX-specific cpuhp callback to call tdx_cpu_enable() on all
> + * online CPUs before calling tdx_enable(), and on any new
> + * going-online CPU to make sure it is ready for TDX guest.
> + */
> + r = cpuhp_setup_state_cpuslocked(CPUHP_AP_ONLINE_DYN,
> + "kvm/cpu/tdx:online",
> + tdx_online_cpu, NULL);
> + if (r < 0)
> + return r;
> +
> + tdx_cpuhp_state = r;
> +
> + r = tdx_enable();
> + if (r)
> + __do_tdx_cleanup();
> +
> + return r;
> +}
>
[...]
> +static int __init __tdx_bringup(void)
> +{
> + int r;
> +
> + /*
> + * Enabling TDX requires enabling hardware virtualization first,
> + * as making SEAMCALLs requires CPU being in post-VMXON state.
> + */
> + r = kvm_enable_virtualization();
> + if (r)
> + return r;
> +
> + cpus_read_lock();
> + r = __do_tdx_bringup();
> + cpus_read_unlock();
> +
Hi Paolo,
This patch still doesn't address a bug Chao pointed out, that the
__do_tdx_cleanup() can be called from __do_tdx_bringup() with cpus_read_lock()
being hold, so we need to use cpuhp_remove_state_nocalls_cpuslocked() in
__do_tdx_cleanup().
I posted a diff to address here:
https://lore.kernel.org/lkml/46ea74bcd8eebe241a143e9280c65ca33cb8dcce.camel@intel.com/T/#m1e86328e69b27e6cc9978f90df923144d699c350
It would be great if you could squash to the kvm-coco-queue. There will be some
minor rebase conflict to the rest patches, though, so if you want me to send out
fixup patch(es) for you to squash please do let me know.
Btw, the diff also moves the 'enable_virt_at_load' check to
kvm_can_support_tdx(), which isn't related to this issue. Below is the diff
(also attached) w/o this code change but only to address the above bug if you
prefer.
diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
index 0666dfbe0bc0..9115467f208d 100644
--- a/arch/x86/kvm/vmx/tdx.c
+++ b/arch/x86/kvm/vmx/tdx.c
@@ -38,10 +38,17 @@ static void __do_tdx_cleanup(void)
* 'multiple enabling' scenario.
*/
WARN_ON_ONCE(!tdx_cpuhp_state);
- cpuhp_remove_state_nocalls(tdx_cpuhp_state);
+ cpuhp_remove_state_nocalls_cpuslocked(tdx_cpuhp_state);
tdx_cpuhp_state = 0;
}
+static void __tdx_cleanup(void)
+{
+ cpus_read_lock();
+ __do_tdx_cleanup();
+ cpus_read_unlock();
+}
+
static int __init __do_tdx_bringup(void)
{
int r;
@@ -103,7 +110,7 @@ static int __init __tdx_bringup(void)
void tdx_cleanup(void)
{
if (enable_tdx) {
- __do_tdx_cleanup();
+ __tdx_cleanup();
kvm_disable_virtualization();
}
}
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: tdx-init-2.diff --]
[-- Type: text/x-patch; name="tdx-init-2.diff", Size: 769 bytes --]
diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
index 0666dfbe0bc0..9115467f208d 100644
--- a/arch/x86/kvm/vmx/tdx.c
+++ b/arch/x86/kvm/vmx/tdx.c
@@ -38,10 +38,17 @@ static void __do_tdx_cleanup(void)
* 'multiple enabling' scenario.
*/
WARN_ON_ONCE(!tdx_cpuhp_state);
- cpuhp_remove_state_nocalls(tdx_cpuhp_state);
+ cpuhp_remove_state_nocalls_cpuslocked(tdx_cpuhp_state);
tdx_cpuhp_state = 0;
}
+static void __tdx_cleanup(void)
+{
+ cpus_read_lock();
+ __do_tdx_cleanup();
+ cpus_read_unlock();
+}
+
static int __init __do_tdx_bringup(void)
{
int r;
@@ -103,7 +110,7 @@ static int __init __tdx_bringup(void)
void tdx_cleanup(void)
{
if (enable_tdx) {
- __do_tdx_cleanup();
+ __tdx_cleanup();
kvm_disable_virtualization();
}
}
next prev parent reply other threads:[~2025-02-20 23:28 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-20 17:05 [PATCH v3 00/30] TDX initialization + vCPU/VM creation Paolo Bonzini
2025-02-20 17:05 ` [PATCH 01/30] x86/virt/tdx: Add SEAMCALL wrappers for TDX KeyID management Paolo Bonzini
2025-02-20 17:05 ` [PATCH 02/30] x86/virt/tdx: Add SEAMCALL wrappers for TDX TD creation Paolo Bonzini
2025-02-20 17:05 ` [PATCH 03/30] x86/virt/tdx: Add SEAMCALL wrappers for TDX vCPU creation Paolo Bonzini
2025-02-20 17:05 ` [PATCH 04/30] x86/virt/tdx: Add SEAMCALL wrappers for TDX page cache management Paolo Bonzini
2025-02-20 17:05 ` [PATCH 05/30] x86/virt/tdx: Add SEAMCALL wrappers for TDX VM/vCPU field access Paolo Bonzini
2025-02-20 17:05 ` [PATCH 06/30] x86/virt/tdx: Add SEAMCALL wrappers for TDX flush operations Paolo Bonzini
2025-02-20 17:05 ` [PATCH 07/30] x86/virt/tdx: allocate tdx_sys_info in static memory Paolo Bonzini
2025-02-20 21:59 ` Huang, Kai
2025-02-20 23:37 ` Edgecombe, Rick P
2025-02-20 17:05 ` [PATCH 08/30] x86/virt/tdx: Read essential global metadata for KVM Paolo Bonzini
2025-02-20 17:05 ` [PATCH 09/30] x86/virt/tdx: Add tdx_guest_keyid_alloc/free() to alloc and free TDX guest KeyID Paolo Bonzini
2025-02-20 17:05 ` [PATCH 10/30] KVM: Export hardware virtualization enabling/disabling functions Paolo Bonzini
2025-02-20 17:05 ` [PATCH 11/30] KVM: VMX: Refactor VMX module init/exit functions Paolo Bonzini
2025-02-20 21:55 ` Huang, Kai
2025-02-20 17:05 ` [PATCH 12/30] KVM: VMX: Initialize TDX during KVM module load Paolo Bonzini
2025-02-20 23:27 ` Huang, Kai [this message]
2025-02-24 18:57 ` Paolo Bonzini
2025-02-24 21:31 ` Huang, Kai
2025-02-20 17:05 ` [PATCH 13/30] KVM: TDX: Get TDX global information Paolo Bonzini
2025-02-21 0:12 ` Huang, Kai
2025-02-20 17:05 ` [PATCH 14/30] KVM: TDX: Add placeholders for TDX VM/vCPU structures Paolo Bonzini
2025-02-20 17:05 ` [PATCH 15/30] KVM: TDX: Define TDX architectural definitions Paolo Bonzini
2025-02-20 17:05 ` [PATCH 16/30] KVM: TDX: Add TDX "architectural" error codes Paolo Bonzini
2025-02-20 17:05 ` [PATCH 17/30] KVM: TDX: Add helper functions to print TDX SEAMCALL error Paolo Bonzini
2025-02-20 17:05 ` [PATCH 18/30] KVM: TDX: Add place holder for TDX VM specific mem_enc_op ioctl Paolo Bonzini
2025-02-25 10:50 ` Huang, Kai
2025-02-20 17:05 ` [PATCH 19/30] KVM: TDX: Get system-wide info about TDX module on initialization Paolo Bonzini
2025-02-20 17:05 ` [PATCH 20/30] KVM: TDX: create/destroy VM structure Paolo Bonzini
2025-02-21 0:55 ` Sean Christopherson
2025-02-21 1:08 ` Sean Christopherson
2025-02-22 0:30 ` Edgecombe, Rick P
2025-02-22 1:38 ` Sean Christopherson
2025-02-24 8:32 ` Yan Zhao
2025-02-21 11:04 ` Yan Zhao
2025-02-21 19:43 ` Sean Christopherson
2025-02-21 12:25 ` Yan Zhao
2025-02-25 16:24 ` Xiaoyao Li
2025-02-20 17:05 ` [PATCH 21/30] KVM: TDX: Support per-VM KVM_CAP_MAX_VCPUS extension check Paolo Bonzini
2025-02-20 17:05 ` [PATCH 22/30] KVM: x86: expose cpuid_entry2_find for TDX Paolo Bonzini
2025-02-20 17:05 ` [PATCH 23/30] KVM: TDX: initialize VM with TDX specific parameters Paolo Bonzini
2025-02-21 2:31 ` Xiaoyao Li
2025-02-25 17:28 ` Paolo Bonzini
2025-02-20 17:05 ` [PATCH 24/30] KVM: TDX: Make pmu_intel.c ignore guest TD case Paolo Bonzini
2025-02-20 17:05 ` [PATCH 25/30] KVM: TDX: Don't offline the last cpu of one package when there's TDX guest Paolo Bonzini
2025-02-20 17:06 ` [PATCH 26/30] KVM: TDX: create/free TDX vcpu structure Paolo Bonzini
2025-02-20 17:06 ` [PATCH 27/30] KVM: TDX: Do TDX specific vcpu initialization Paolo Bonzini
2025-02-20 17:06 ` [PATCH 28/30] KVM: x86: Introduce KVM_TDX_GET_CPUID Paolo Bonzini
2025-02-20 17:06 ` [PATCH 29/30] KVM: x86/mmu: Taking guest pa into consideration when calculate tdp level Paolo Bonzini
2025-02-20 17:06 ` [PATCH 30/30] KVM: TDX: Register TDX host key IDs to cgroup misc controller 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=64168d1d11afb399685067c6f8d57a738bb97eb6.camel@intel.com \
--to=kai.huang@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=rick.p.edgecombe@intel.com \
--cc=seanjc@google.com \
--cc=yan.y.zhao@intel.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®