[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aK7OOiZ8er7QpXJ5@yzhao56-desk.sh.intel.com>
Date: Wed, 27 Aug 2025 17:22:02 +0800
From: Yan Zhao <yan.y.zhao@...el.com>
To: Sean Christopherson <seanjc@...gle.com>
CC: Paolo Bonzini <pbonzini@...hat.com>, <kvm@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, Michael Roth <michael.roth@....com>, "Ira
Weiny" <ira.weiny@...el.com>, Vishal Annapurve <vannapurve@...gle.com>, "Rick
Edgecombe" <rick.p.edgecombe@...el.com>
Subject: Re: [RFC PATCH 12/12] KVM: TDX: Rename nr_premapped to
nr_pending_tdh_mem_page_adds
On Tue, Aug 26, 2025 at 05:05:22PM -0700, Sean Christopherson wrote:
> Rename "nr_premapped" to an asurdly verbose "nr_pending_tdh_mem_page_adds"
> to make it explicitly clear what the counter tracks. "pre-map" is far
> too similar to "pre-fault", especially since tdx_sept_set_private_spte()
> deals with both "pre_fault_allowed" and the counter.
>
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@...gle.com>
> ---
> arch/x86/kvm/vmx/tdx.c | 8 ++++----
> arch/x86/kvm/vmx/tdx.h | 9 +++++++--
> 2 files changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
> index 5d2bb27f22da..f9ac590e8ff0 100644
> --- a/arch/x86/kvm/vmx/tdx.c
> +++ b/arch/x86/kvm/vmx/tdx.c
> @@ -1639,7 +1639,7 @@ static int tdx_sept_set_private_spte(struct kvm *kvm, gfn_t gfn,
> if (KVM_BUG_ON(kvm->arch.pre_fault_allowed, kvm))
> return -EIO;
>
> - kvm_tdx->nr_premapped++;
> + kvm_tdx->nr_pending_tdh_mem_page_adds++;
> return 0;
> }
>
> @@ -1771,7 +1771,7 @@ static int tdx_sept_zap_private_spte(struct kvm *kvm, gfn_t gfn,
> if (tdx_is_sept_zap_err_due_to_premap(kvm_tdx, err, entry, level)) {
> lockdep_assert_held(&kvm->slots_lock);
>
> - if (KVM_BUG_ON(--kvm_tdx->nr_premapped < 0, kvm))
> + if (KVM_BUG_ON(--kvm_tdx->nr_pending_tdh_mem_page_adds < 0, kvm))
> return -EIO;
>
> return 0;
> @@ -2846,7 +2846,7 @@ static int tdx_td_finalize(struct kvm *kvm, struct kvm_tdx_cmd *cmd)
> * Pages are pending for KVM_TDX_INIT_MEM_REGION to issue
> * TDH.MEM.PAGE.ADD().
> */
> - if (kvm_tdx->nr_premapped)
> + if (kvm_tdx->nr_pending_tdh_mem_page_adds)
> return -EINVAL;
>
> cmd->hw_error = tdh_mr_finalize(&kvm_tdx->td);
> @@ -3160,7 +3160,7 @@ static int tdx_gmem_post_populate(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn,
> goto out;
> }
>
> - KVM_BUG_ON(--kvm_tdx->nr_premapped < 0, kvm);
> + KVM_BUG_ON(--kvm_tdx->nr_pending_tdh_mem_page_adds < 0, kvm);
>
> if (arg->flags & KVM_TDX_MEASURE_MEMORY_REGION) {
> for (i = 0; i < PAGE_SIZE; i += TDX_EXTENDMR_CHUNKSIZE) {
> diff --git a/arch/x86/kvm/vmx/tdx.h b/arch/x86/kvm/vmx/tdx.h
> index 04ba9ea3e0ba..45d86f9fa41c 100644
> --- a/arch/x86/kvm/vmx/tdx.h
> +++ b/arch/x86/kvm/vmx/tdx.h
> @@ -36,8 +36,13 @@ struct kvm_tdx {
>
> struct tdx_td td;
>
> - /* For KVM_TDX_INIT_MEM_REGION. */
> - unsigned long nr_premapped;
> + /*
> + * The number of pages that KVM_TDX_INIT_MEM_REGION has mapped into the
> + * S-EPT, but not yet initialized via TDH.MEM.PAGE_ADD. Used to sanity
> + * check adding pages to the image, and to ensure that all pages have
> + * been initialized before finalizing the TD.
> + */
To ensure the consistency between mirror EPT and S-EPT? (as in
https://lore.kernel.org/all/aK7Ji3kAoDaEYn3h@yzhao56-desk.sh.intel.com).
tdx_td_finalize() holds slots_lock, so it can't run in-between a
KVM_TDX_INIT_MEM_REGION.
> + unsigned long nr_pending_tdh_mem_page_adds;
>
> /*
> * Prevent vCPUs from TD entry to ensure SEPT zap related SEAMCALLs do
> --
> 2.51.0.268.g9569e192d0-goog
>
Powered by blists - more mailing lists