From: Yan Zhao <yan.y.zhao@intel.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>, <kvm@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
Rick Edgecombe <rick.p.edgecombe@intel.com>,
Xiaoyao Li <xiaoyao.li@intel.com>,
Kai Huang <kai.huang@intel.com>,
Binbin Wu <binbin.wu@linux.intel.com>
Subject: Re: [PATCH v3 1/3] KVM: x86/mmu: Use KVM's max TDP level to determine need for 32-bit TDP root
Date: Mon, 14 Sep 2026 17:02:56 +0800 [thread overview]
Message-ID: <aqe4QCxIhcoBL+po@yzhao56-desk.sh.intel.com> (raw)
In-Reply-To: <20260902230932.2760127-2-seanjc@google.com>
On Wed, Sep 02, 2026 at 04:09:30PM -0700, Sean Christopherson wrote:
> When checking to see if KVM needs to allocate a TDP PAE root that's 32-bit
> addressable, query KVM's overall max TDP level, not the vCPU-specific TDP
> level, as the logic is specific to using NPT on 32-bit hosts. Querying the
> vCPU's alleged TDP level is flawed and confusing, as KVM selects between
> 4-level vs. 5-level based on the guest's MAXPHYADDR, and MAXPHYADDR isn't
> yet configured (via CPUID) when the vCPU is being created.
>
> I.e. as is, it would *appear* that KVM is violating its own rules with
> respect to changing guest CPUID (see kvm_mmu_after_set_cpuid()). In
> practice, the flaw is benign as the goal is purely to see if KVM needs to
> use PAE-paging; whether KVM will use 4-level vs. 5-level is irrelevant.
>
> More importantly, avoiding kvm_mmu_get_tdp_level() during vCPU creation
> will allow hardening KVM's handling of S-EPT mirror root level.
>
> For all intents and purposes, no functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
> arch/x86/kvm/mmu/mmu.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index 064ecc33b926..c9a684151420 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c
> @@ -6834,7 +6834,7 @@ static int __kvm_mmu_create(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, struct k
> * other exception is for shadowing L1's 32-bit or PAE NPT on 64-bit
> * KVM; that horror is handled on-demand by mmu_alloc_special_roots().
> */
> - if (tdp_enabled && kvm_mmu_get_tdp_level(vcpu) > PT32E_ROOT_LEVEL)
> + if (tdp_enabled && kvm_mmu_get_max_tdp_level() > PT32E_ROOT_LEVEL)
> return 0;
Reviewed-by: Yan Zhao <yan.y.zhao@intel.com>
On a separate note, though it shouldn't be a real issue, is the below change
necessary?
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index bb68a021cfaf..abbba26dbdc6 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -1810,7 +1810,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
phys_as = entry->eax & 0xff;
g_phys_as = phys_as;
if (kvm_mmu_get_max_tdp_level() < 5)
- g_phys_as = min(g_phys_as, 48U);
+ g_phys_as = min(g_phys_as, kvm_mmu_get_max_tdp_level() == 3 ? 32U : 48U);
}
entry->eax = phys_as | (virt_as << 8) | (g_phys_as << 16);
> page = alloc_page(GFP_KERNEL_ACCOUNT | __GFP_DMA32);
> --
> 2.55.0.970.g62bdec98f9-goog
>
next prev parent reply other threads:[~2026-09-14 9:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 23:09 [PATCH v3 0/3] KVM: VMX: Explicitly track TDX VMs' root level Sean Christopherson
2026-09-02 23:09 ` [PATCH v3 1/3] KVM: x86/mmu: Use KVM's max TDP level to determine need for 32-bit TDP root Sean Christopherson
2026-09-09 14:08 ` Xiaoyao Li
2026-09-14 9:02 ` Yan Zhao [this message]
2026-09-17 0:12 ` Sean Christopherson
2026-09-02 23:09 ` [PATCH v3 2/3] KVM: VMX: Explicitly track TDX VMs' root level instead of guessing it from CPUID Sean Christopherson
2026-09-09 14:16 ` Xiaoyao Li
2026-09-02 23:09 ` [PATCH v3 3/3] KVM: VMX: Drop TDX_SHARED_BIT_PWL_{4,5} and dedup related code Sean Christopherson
2026-09-09 14:18 ` Xiaoyao Li
2026-09-14 9:05 ` Yan Zhao
2026-09-21 14:05 ` [PATCH v3 0/3] KVM: VMX: Explicitly track TDX VMs' root level Sean Christopherson
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=aqe4QCxIhcoBL+po@yzhao56-desk.sh.intel.com \
--to=yan.y.zhao@intel.com \
--cc=binbin.wu@linux.intel.com \
--cc=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=xiaoyao.li@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®