mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yan Zhao <yan.y.zhao@intel.com>
To: "Edgecombe, Rick P" <rick.p.edgecombe@intel.com>
Cc: "Du, Fan" <fan.du@intel.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"Huang, Kai" <kai.huang@intel.com>,
	"Li, Xiaoyao" <xiaoyao.li@intel.com>,
	"Hansen, Dave" <dave.hansen@intel.com>,
	"thomas.lendacky@amd.com" <thomas.lendacky@amd.com>,
	"tabba@google.com" <tabba@google.com>,
	"vbabka@suse.cz" <vbabka@suse.cz>,
	"david@kernel.org" <david@kernel.org>,
	"kas@kernel.org" <kas@kernel.org>,
	"binbin.wu@linux.intel.com" <binbin.wu@linux.intel.com>,
	"seanjc@google.com" <seanjc@google.com>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"Peng, Chao P" <chao.p.peng@intel.com>,
	"ackerleytng@google.com" <ackerleytng@google.com>,
	"michael.roth@amd.com" <michael.roth@amd.com>,
	"nik.borisov@suse.com" <nik.borisov@suse.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"sagis@google.com" <sagis@google.com>,
	"Annapurve, Vishal" <vannapurve@google.com>,
	"Chen, Farrah" <farrah.chen@intel.com>,
	"Gao, Chao" <chao.gao@intel.com>,
	"francescolavra.fl@gmail.com" <francescolavra.fl@gmail.com>,
	"Miao, Jun" <jun.miao@intel.com>,
	"jgross@suse.com" <jgross@suse.com>,
	"pgonda@google.com" <pgonda@google.com>,
	"x86@kernel.org" <x86@kernel.org>
Subject: Re: [PATCH v4 08/17] KVM: TDX: Adjust the topup count of DPAMT page pairs for splitting S-EPT
Date: Wed, 14 Oct 2026 13:36:00 +0800	[thread overview]
Message-ID: <as8UwKoAaT/1HgNr@yzhao56-desk.sh.intel.com> (raw)
In-Reply-To: <ae995b5ec798491c3a5511fc44b6308e9664a53b.camel@intel.com>

On Tue, Oct 13, 2026 at 12:36:13AM +0800, Edgecombe, Rick P wrote:
> On Sat, 2026-10-10 at 13:13 +0800, Yan Zhao wrote:
> > > For fault:
> > > topup(true, true, PT64_ROOT_MAX_LEVEL - 1)
> > > 
> > > For split:
> > > topup(false, false, 1)
> > Hmm, having the caller perform the -1 calculation gives me some hesitation.
> > The meaning of nr_extra_spts is not straightforward, though it seems to mean
> > the number of spts excluding the root.
> 
> It means "extra" beyond the root. How about:
> 
> int topup(bool root_spt, int nr_extra_spts, bool private_page)
> 
> The idea is to tell external infra what the fault handler might do. It might add
> a root, it might add a private leaf and it may need extra spts beyond the root.
> These are all concepts known to mirror EPT and also has all the info needed for
> the calculation on the TDX side, and also doesn't assume anything about TDX
> implementation from the mirror side. There is extra info passed, that is not
> needed. But the gain is that the code on both sides and calculation are self
> documenting.
It seems strange to me to have nr_extra_spts if root_spt is false, in which case
nr_extra_spts are all the spts the caller wants to topup for, so why call them
extra?

Also, is there a case where "private_page" is false? I can't find one...
Specifically for the "split" case (patch 6,
https://lore.kernel.org/all/20260928091005.15567-1-yan.y.zhao@intel.com/) where
.topup_external_cache() is invoked in tdp_mmu_alloc_sp_for_split(), how does the
caller (tdp_mmu_alloc_sp_for_split()) know whether private_page should be true
or false without TDX's specific knowledge?

So, I propose dropping the private_page argument and renaming root_spt to
has_root_spt. i.e., either:

(1) int topup(bool has_root_spt, int nr_spts);

or

(2) int topup(bool has_root_spt, int nonroot_spts);

I prefer (1), as it gives the caller the freedom to always pass
PT64_ROOT_MAX_LEVEL even for 4-level VMs. Additionally, has_root_spt in topup()
in (2) would be useless.

int topup(bool has_root_spt, int nonroot_spts)
{
 	add_to_cache(nonroot_spts + 1);
}

> > private_page arg should be unnecessary, since the split path also needs to
> > allocate DPAMT pages for the guest private page.
> > 
> > > Why have root as a separate arg even though it is never used? Because it
> > > makes
> > > the logic make sense from code KVM.
> > What about:
> > 
> > int topup(bool has_root, int nr_spts)
> > {
> >  	add_to_cache(nr_spts + (has_root ? -1 : 0) + 1);
> > }
> 
> "(has_root ? -1 : 0) + 1)" is going to need a comment. So I was suggesting just
> to make it obvious in the code.
like this?

int topup(bool has_root, int nr_spts)
{
	int pairs = nr_spts;

	/* the one for root has been allocated */
	if (has_root)
		pairs -= 1;

	/* for guest private page */
	pairs += 1;

 	add_to_cache(pairs);
}

> > For fault:
> > topup(true, PT64_ROOT_MAX_LEVEL)
> > 
> > For split:
> > topup(false, 1)
> > 
> > > > Besides, I actually introduced a separate cache and op for split in v3,
> > > > https://lore.kernel.org/all/20260106102345.25261-1-yan.y.zhao@intel.com.
> > > > Sean merged the cache/op for split with the cache/op for fault in
> > > > DPAMT+Hugepage v5.
> > > 
> > > Yea, but he didn't have any big assumptions in it like this. It was way
> > > simpler.
> > Since the re-insertion solution looks good to you, it should be not be too
> > complex now :)
> > 
> > Given that the fault path theoretically also needs to address the root-only -1
> > calculation issue, having split and fault share the same op seems reasonable?
> 

  reply	other threads:[~2026-10-14  5:37 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28  9:07 [PATCH v4 00/17] KVM: TDX huge page support for private memory Yan Zhao
2026-09-28  9:08 ` [PATCH v4 01/17] x86/virt/tdx: Enhance tdx_pamt_get/put() to support huge pages Yan Zhao
2026-10-01 23:02   ` Edgecombe, Rick P
2026-10-10 10:18     ` Yan Zhao
2026-10-12 23:18       ` Edgecombe, Rick P
2026-10-15  3:41         ` Yan Zhao
2026-10-15 18:11           ` Edgecombe, Rick P
2026-10-19  6:35             ` Yan Zhao
2026-10-21 21:28               ` Edgecombe, Rick P
2026-10-22  9:21                 ` Yan Zhao
2026-09-28  9:08 ` [PATCH v4 02/17] x86/virt/tdx: Add a SEAMCALL wrapper to demote a 2MB huge page Yan Zhao
2026-10-02  0:54   ` Edgecombe, Rick P
2026-10-12  9:31     ` Yan Zhao
2026-10-12 22:16       ` Edgecombe, Rick P
2026-10-14  9:40         ` Yan Zhao
2026-10-14 18:32           ` Edgecombe, Rick P
2026-10-15  6:11             ` Yan Zhao
2026-10-15  9:28               ` Yan Zhao
2026-10-15  9:49                 ` Yan Zhao
2026-10-15 18:30                   ` Edgecombe, Rick P
2026-10-19 11:04                     ` Yan Zhao
2026-10-21 22:02                       ` Edgecombe, Rick P
2026-10-22  8:46                         ` Yan Zhao
2026-10-22 15:51                           ` Edgecombe, Rick P
2026-10-23  8:12                             ` Yan Zhao
2026-09-28  9:08 ` [PATCH v4 03/17] KVM: TDX: Reset private huge pages after S-EPT page removal Yan Zhao
2026-10-07  0:06   ` Edgecombe, Rick P
2026-10-10  9:22     ` Yan Zhao
2026-09-28  9:09 ` [PATCH v4 04/17] KVM: x86/mmu: Prevent huge page promotion for mirror roots in fault path Yan Zhao
2026-10-07  0:32   ` Edgecombe, Rick P
2026-09-28  9:09 ` [PATCH v4 05/17] KVM: x86/tdp_mmu: Alloc external_spt page for mirror page table splitting Yan Zhao
2026-10-07  0:33   ` Edgecombe, Rick P
2026-10-10  7:41     ` Yan Zhao
2026-09-28  9:10 ` [PATCH v4 06/17] KVM: x86/mmu: Allocate DPAMT pages for vCPU-induced page split Yan Zhao
2026-10-07 15:45   ` Edgecombe, Rick P
2026-10-10  6:37     ` Yan Zhao
2026-10-10  6:40       ` Yan Zhao
2026-10-12 16:41       ` Edgecombe, Rick P
2026-09-28  9:10 ` [PATCH v4 07/17] KVM: TDX: Add core support for splitting/demoting 2MB S-EPT mappings to 4KB Yan Zhao
2026-10-07 21:52   ` Edgecombe, Rick P
2026-10-10  6:34     ` Yan Zhao
2026-10-12 16:40       ` Edgecombe, Rick P
2026-10-14  5:39         ` Yan Zhao
2026-09-28  9:10 ` [PATCH v4 08/17] KVM: TDX: Adjust the topup count of DPAMT page pairs for splitting S-EPT Yan Zhao
2026-10-07 22:48   ` Edgecombe, Rick P
2026-10-08  1:16     ` Edgecombe, Rick P
2026-10-09  9:08       ` Yan Zhao
2026-10-09 22:12         ` Edgecombe, Rick P
2026-10-10  5:13           ` Yan Zhao
2026-10-12 16:36             ` Edgecombe, Rick P
2026-10-14  5:36               ` Yan Zhao [this message]
2026-10-14 18:34                 ` Edgecombe, Rick P
2026-10-15  4:47                   ` Yan Zhao
2026-10-15 17:21                     ` Edgecombe, Rick P
2026-10-19  1:59                       ` Yan Zhao
2026-10-21 22:28                         ` Edgecombe, Rick P
2026-10-22  7:24                           ` Yan Zhao
2026-10-22 15:56                             ` Edgecombe, Rick P
2026-10-22 23:59                               ` Yan Zhao
2026-10-23  1:20                                 ` Yan Zhao
2026-10-23  1:56                                 ` Edgecombe, Rick P
2026-10-23  2:03                                   ` Yan Zhao
2026-10-23  2:06                                     ` Edgecombe, Rick P
2026-10-23  2:12                                       ` Yan Zhao
2026-10-23  2:15                                         ` Edgecombe, Rick P
2026-10-09  8:39     ` Yan Zhao
2026-10-09 22:11       ` Edgecombe, Rick P
2026-10-10  5:18         ` Yan Zhao
2026-09-28  9:10 ` [PATCH v4 09/17] KVM: x86/mmu: Introduce hugepage_set_guest_inhibit() Yan Zhao
2026-10-07 23:57   ` Edgecombe, Rick P
2026-10-10  6:00     ` Yan Zhao
2026-09-28  9:11 ` [PATCH v4 10/17] KVM: x86/mmu: Add a TDP MMU API to split huge pages for mirror roots Yan Zhao
2026-10-08  0:25   ` Edgecombe, Rick P
2026-09-28  9:11 ` [PATCH v4 11/17] KVM: TDX: Honor the guest's accept level contained in an EPT violation Yan Zhao
2026-10-08  1:05   ` Edgecombe, Rick P
2026-10-09  9:33     ` Yan Zhao
2026-10-09 22:00       ` Edgecombe, Rick P
2026-10-10  5:42         ` Yan Zhao
2026-10-12 16:14           ` Edgecombe, Rick P
2026-09-28  9:11 ` [PATCH v4 12/17] KVM: x86/mmu: Add support for splitting S-EPT entry under non-vCPU context Yan Zhao
2026-09-28  9:11 ` [PATCH v4 13/17] [GMEM-DEPENDENT] KVM: guest_memfd: Add helpers to get start/end gfns give gmem+slot+pgoff Yan Zhao
2026-10-08 23:16   ` Edgecombe, Rick P
2026-09-28  9:11 ` [PATCH v4 14/17] [GMEM-DEPENDENT] KVM: guest_memfd: Split kvm_gmem_invalidate_start() to start() and zap() Yan Zhao
2026-09-28  9:12 ` [PATCH v4 15/17] [GMEM-DEPENDENT] KVM: guest_memfd: Add a pre-zap hook .gmem_prezap() Yan Zhao
2026-10-14  7:01   ` Yan Zhao
2026-09-28  9:12 ` [PATCH v4 16/17] [GMEM-DEPENDENT] KVM: TDX: Implement .gmem_prezap() hook to split S-EPT Yan Zhao
2026-09-28  9:12 ` [PATCH v4 17/17] KVM: TDX: Turn on PG_LEVEL_2M Yan Zhao

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=as8UwKoAaT/1HgNr@yzhao56-desk.sh.intel.com \
    --to=yan.y.zhao@intel.com \
    --cc=ackerleytng@google.com \
    --cc=binbin.wu@linux.intel.com \
    --cc=chao.gao@intel.com \
    --cc=chao.p.peng@intel.com \
    --cc=dave.hansen@intel.com \
    --cc=david@kernel.org \
    --cc=fan.du@intel.com \
    --cc=farrah.chen@intel.com \
    --cc=francescolavra.fl@gmail.com \
    --cc=jgross@suse.com \
    --cc=jun.miao@intel.com \
    --cc=kai.huang@intel.com \
    --cc=kas@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.roth@amd.com \
    --cc=nik.borisov@suse.com \
    --cc=pbonzini@redhat.com \
    --cc=pgonda@google.com \
    --cc=rick.p.edgecombe@intel.com \
    --cc=sagis@google.com \
    --cc=seanjc@google.com \
    --cc=tabba@google.com \
    --cc=thomas.lendacky@amd.com \
    --cc=vannapurve@google.com \
    --cc=vbabka@suse.cz \
    --cc=x86@kernel.org \
    --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®