[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aXt9pfN8uGLX2c-o@google.com>
Date: Thu, 29 Jan 2026 07:32:53 -0800
From: Sean Christopherson <seanjc@...gle.com>
To: Thomas Gleixner <tglx@...nel.org>, Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
Kiryl Shutsemau <kas@...nel.org>, Paolo Bonzini <pbonzini@...hat.com>, linux-kernel@...r.kernel.org,
linux-coco@...ts.linux.dev, kvm@...r.kernel.org,
Kai Huang <kai.huang@...el.com>, Rick Edgecombe <rick.p.edgecombe@...el.com>,
Yan Zhao <yan.y.zhao@...el.com>, Vishal Annapurve <vannapurve@...gle.com>,
Ackerley Tng <ackerleytng@...gle.com>, Sagi Shahar <sagis@...gle.com>,
Binbin Wu <binbin.wu@...ux.intel.com>, Xiaoyao Li <xiaoyao.li@...el.com>,
Isaku Yamahata <isaku.yamahata@...el.com>
Subject: Re: [RFC PATCH v5 41/45] KVM: TDX: Honor the guest's accept level
contained in an EPT violation
On Wed, Jan 28, 2026, Sean Christopherson wrote:
> +int kvm_tdp_mmu_split_huge_pages(struct kvm_vcpu *vcpu, gfn_t start, gfn_t end,
> + int target_level)
> +{
> + struct kvm_mmu_page *root = root_to_sp(vcpu->arch.mmu->root.hpa);
This is wrong, mmu->root.hpa is the shared root, not the mirror root. Dittof for
the sanity check in tdx_handle_mismatched_accept().
Rather than operate on the vCPU's root, I think it makes sense to add an API to
operate on all mirror roots. In practice, there can only be one valid mirror
root, so KVM isn't actually doing more work. Then TDX can reuse that API for
splitting the head+tail pages when preparing for a partial shared=>private
conversion.
Slotted in before this patch:
---
From: Sean Christopherson <seanjc@...gle.com>
Date: Thu, 29 Jan 2026 15:21:30 +0000
Subject: [PATCH] KVM: x86/mmu: Add a TDP MMU API to split hugepages for mirror
roots
Add an exported API to split hugepages in mirror roots for a given gfn
range. TDX will use the API to split hugepages in preparation for
partially converting a hugepage from private to shared, and for splitting
a hugepage to match the guest's ACCEPT level.
For all intents and purposes, no functional change intended.
Signed-off-by: Sean Christopherson <seanjc@...gle.com>
---
arch/x86/kvm/mmu/tdp_mmu.c | 39 ++++++++++++++++++++++++++++----------
arch/x86/kvm/mmu/tdp_mmu.h | 2 ++
2 files changed, 31 insertions(+), 10 deletions(-)
diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
index e32034bfca5a..a45d8ee91481 100644
--- a/arch/x86/kvm/mmu/tdp_mmu.c
+++ b/arch/x86/kvm/mmu/tdp_mmu.c
@@ -1597,6 +1597,26 @@ static int tdp_mmu_split_huge_pages_root(struct kvm *kvm,
return 0;
}
+static int tdp_mmu_split_huge_pages(struct kvm *kvm, int as_id,
+ enum kvm_tdp_mmu_root_types type,
+ gfn_t start, gfn_t end,
+ int target_level, bool shared)
+{
+ struct kvm_mmu_page *root;
+ int r;
+
+ kvm_lockdep_assert_mmu_lock_held(kvm, shared);
+
+ __for_each_tdp_mmu_root_yield_safe(kvm, root, as_id, type) {
+ r = tdp_mmu_split_huge_pages_root(kvm, root, start, end,
+ target_level, shared);
+ if (r) {
+ kvm_tdp_mmu_put_root(kvm, root);
+ return r;
+ }
+ }
+ return 0;
+}
/*
* Try to split all huge pages mapped by the TDP MMU down to the target level.
@@ -1606,18 +1626,17 @@ void kvm_tdp_mmu_try_split_huge_pages(struct kvm *kvm,
gfn_t start, gfn_t end,
int target_level, bool shared)
{
- struct kvm_mmu_page *root;
- int r = 0;
+ tdp_mmu_split_huge_pages(kvm, slot->as_id, KVM_VALID_ROOTS, start, end,
+ target_level, shared);
+}
- kvm_lockdep_assert_mmu_lock_held(kvm, shared);
- for_each_valid_tdp_mmu_root_yield_safe(kvm, root, slot->as_id) {
- r = tdp_mmu_split_huge_pages_root(kvm, root, start, end, target_level, shared);
- if (r) {
- kvm_tdp_mmu_put_root(kvm, root);
- break;
- }
- }
+int kvm_tdp_mmu_mirrors_split_huge_pages(struct kvm *kvm, gfn_t start,
+ gfn_t end, int target_level)
+{
+ return tdp_mmu_split_huge_pages(kvm, 0, KVM_MIRROR_ROOTS, start, end,
+ target_level, false);
}
+EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_tdp_mmu_mirrors_split_huge_pages);
static bool tdp_mmu_need_write_protect(struct kvm *kvm, struct kvm_mmu_page *sp)
{
diff --git a/arch/x86/kvm/mmu/tdp_mmu.h b/arch/x86/kvm/mmu/tdp_mmu.h
index bd62977c9199..a6919de10ca2 100644
--- a/arch/x86/kvm/mmu/tdp_mmu.h
+++ b/arch/x86/kvm/mmu/tdp_mmu.h
@@ -97,6 +97,8 @@ void kvm_tdp_mmu_try_split_huge_pages(struct kvm *kvm,
const struct kvm_memory_slot *slot,
gfn_t start, gfn_t end,
int target_level, bool shared);
+int kvm_tdp_mmu_mirrors_split_huge_pages(struct kvm *kvm, gfn_t start,
+ gfn_t end, int target_level);
static inline void kvm_tdp_mmu_walk_lockless_begin(void)
{
base-commit: 86c3bb72bf5c6201636529ee4609334b0887c6e3
--
Powered by blists - more mailing lists