Re: [RFC PATCH v2 08/23] KVM: x86/tdp_mmu: Alloc external_spt page for mirror page table splitting
From: Huang, Kai
Date: Tue Nov 11 2025 - 04:59:32 EST
On Thu, 2025-08-07 at 17:43 +0800, Yan Zhao wrote:
> From: Isaku Yamahata <isaku.yamahata@xxxxxxxxx>
>
> Enhance tdp_mmu_alloc_sp_split() to allocate a page for sp->external_spt,
^
tdp_mmu_alloc_sp_for_split()
[...]
> +static struct kvm_mmu_page *tdp_mmu_alloc_sp_for_split(bool mirror);
> +
It doesn't seem you need such declaration in _this_ patch. If any later
patch needs it, then perhaps it's better to do in that patch.
> static void tdp_account_mmu_page(struct kvm *kvm, struct kvm_mmu_page *sp)
> {
> kvm_account_pgtable_pages((void *)sp->spt, +1);
> @@ -1475,7 +1477,7 @@ bool kvm_tdp_mmu_wrprot_slot(struct kvm *kvm,
> return spte_set;
> }
>
> -static struct kvm_mmu_page *tdp_mmu_alloc_sp_for_split(void)
> +static struct kvm_mmu_page *tdp_mmu_alloc_sp_for_split(bool mirror)
> {
> struct kvm_mmu_page *sp;
>
> @@ -1489,6 +1491,15 @@ static struct kvm_mmu_page *tdp_mmu_alloc_sp_for_split(void)
> return NULL;
> }
>
> + if (mirror) {
> + sp->external_spt = (void *)get_zeroed_page(GFP_KERNEL_ACCOUNT);
> + if (!sp->external_spt) {
> + free_page((unsigned long)sp->spt);
> + kmem_cache_free(mmu_page_header_cache, sp);
> + return NULL;
> + }
> + }
> +
> return sp;
> }
>
> @@ -1568,7 +1579,7 @@ static int tdp_mmu_split_huge_pages_root(struct kvm *kvm,
> else
> write_unlock(&kvm->mmu_lock);
>
> - sp = tdp_mmu_alloc_sp_for_split();
> + sp = tdp_mmu_alloc_sp_for_split(is_mirror_sp(root));
>
> if (shared)
> read_lock(&kvm->mmu_lock);