mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Huang, Kai" <kai.huang@intel.com>
To: "Hansen, Dave" <dave.hansen@intel.com>,
	"seanjc@google.com" <seanjc@google.com>,
	"bp@alien8.de" <bp@alien8.de>,
	"peterz@infradead.org" <peterz@infradead.org>,
	"hpa@zytor.com" <hpa@zytor.com>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"kirill.shutemov@linux.intel.com"
	<kirill.shutemov@linux.intel.com>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"Williams, Dan J" <dan.j.williams@intel.com>
Cc: "nik.borisov@suse.com" <nik.borisov@suse.com>,
	"Hunter, Adrian" <adrian.hunter@intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Edgecombe, Rick P" <rick.p.edgecombe@intel.com>,
	"x86@kernel.org" <x86@kernel.org>,
	"Yamahata, Isaku" <isaku.yamahata@intel.com>
Subject: Re: [PATCH v8 8.2/9] x86/virt/tdx: Reduce TDMR's reserved areas by using CMRs to find memory holes
Date: Tue, 10 Dec 2024 02:26:44 +0000	[thread overview]
Message-ID: <83df85a3b318e6578628692ce0d28b9cf736061e.camel@intel.com> (raw)
In-Reply-To: <78a359f8-5a0c-463c-b886-ff4165b395d2@intel.com>

On Mon, 2024-12-09 at 14:54 -0800, Dave Hansen wrote:
> On 12/8/24 22:50, Kai Huang wrote:
> > A TDX module initialization failure was reported on an Emerald Rapids
> > platform [*]:
> > 
> >   virt/tdx: initialization failed: TDMR [0x0, 0x80000000): reserved areas exhausted.
> >   virt/tdx: module initialization failed (-28)
> > 
> > The kernel informs the TDX module of "TDX-usable memory regions" via the
> > structure "TD Memory Region" (TDMR).  Each TDMR contains a limited
> > number of "reserved areas" to inform the TDX module of the regions that
> > cannot be used by TDX.
> > 
> > The kernel builds the list of "TDX-usable memory regions" from memblock
> > (which reflects e820) and marks all memory holes as "reserved areas" in
> > TDMRs.  It turns out on some large systems the holes in memblock can be
> > too fine-grained [1] and exceed the number of reserved areas that the
> > module can track per TDMR, resulting in the failure mentioned above.
> > 
> > The TDX module also reports TDX-capable memory as "Convertible Memory
> > Regions" (CMRs).  CMRs tend to be coarser-grained [2] than the e820.
> > Use CMRs to find memory holes when populating reserved areas to reduce
> > their consumption.
> > 
> > Note the kernel does not prevent non-CMR memory from being added to
> > "TDX-usable memory regions" but depends on the TDX module to catch in
> > the TDH.SYS.CONFIG.  After switching to using CMRs to populate reserved
> > areas this will no longer work.  To ensure no non-CMR memory is included
> > in the TDMRs, verify that the memory region is truly TDX convertible
> > before adding it as a TDX-usable memory region at early stage.
> 
> Thanks for trimming the changelog down.  But this changelog never
> actually says what the fix is. It's also quite heavy on the "what" and
> very light on the "why".
> 
> I think the "why" boils down to the fact that the kernel is treating RAM
> -- as defined by the platform and TDX module -- as non-RAM.

Yes.

> 
> > -	ret = tdmrs_populate_rsvd_areas_all(tdmr_list, tmb_list,
> > +	/*
> > +	 * On some large systems, the TDX memory blocks (which reflects
> > +	 * e820) in the first 1GB can be too fine-grained.  Using them
> > +	 * to populate reserved areas may result in reserved areas being
> > +	 * exhausted.  CMRs are coarser-grained than e820.  Use CMRs to
> > +	 * populate reserved areas to reduce their consumption.
> > +	 */
> 
> I think there are still too many details here for a comment. This
> comment is describing *highly* implementation and platform-specific
> details particular to this bug you are fixing today. They will be
> irrelevant to anyone reading this code tomorrow.
> 
> So in the end, I buy that the CMR's have something to offer here. But I
> think that "why" I mentioned above casts doubt on whether
> for_each_mem_pfn_range() is the right primitive on which to build the
> TDX memblocks in the first place.

We can change to just use CMRs as TDX memory blocks, i.e., always cover all CMRs
in TDMRs, but this will have much wider impact.

The main concern is the PAMT allocation: PAMT is allocated from page allocator,
but the CMRs -- the RAM as defined by the platform and the TDX module - - can
cover more, and sometimes much more, regions than the regions end up to the page
allocator.

E.g., today we can use 'memmap=' to reserve part of memory for other purpose. 
And in the future CMRs may cover CXL memory regions which could be much larger
IIUC.

If we change to cover CMRs in TDMRs, we could end up with a much larger TDMR
ranges.  In this case we may end up with wasting PAMTs (e.g., if the admin wants
to use CXL for other non-TDX purpose), increasing the failure rate, or a
complete failure of PAMT allocation.

> I suspect there's a much simpler solution that will emerge when
> considering a deeper fix as opposed to adding CMRs as a band-aid.

I don't have an immediate solution other than using CMRs to fill up reserved
areas.  I will think more.

Perhaps we can try to split the TDMR to make it cover less reserved areas.  But
this won't work when the TDMR is already 1GB.  And this will result in new cases
where "one TDX memory block can end up to multiple TDMRs" etc.  To me it's over-
complicated and is not as good as using the CMR.  (This is listed as an
alternative in the initial changelog but was removed to trim down the log).

Btw, Rick is concerning with the overall KVM TDX upstream because this series is
a dependency to the rest KVM TDX patches.  Technically this bugfix is not
related to the KVM TDX support.  We are going to look at dropping the CMR staff
for now (the code which reads CMRs in patch 3, and patch 7-8), as the TDX KVM
patches can live without it for initial support.



  reply	other threads:[~2024-12-10  2:26 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-13 11:57 [PATCH v8 0/9] TDX host: metadata reading tweaks and bug fixes Kai Huang
2024-11-13 11:57 ` [PATCH v8 1/9] x86/virt/tdx: Rename 'struct tdx_tdmr_sysinfo' to reflect the spec better Kai Huang
2024-11-13 11:57 ` [PATCH v8 2/9] x86/virt/tdx: Start to track all global metadata in one structure Kai Huang
2024-11-13 11:57 ` [PATCH v8 3/9] x86/virt/tdx: Use auto-generated code to read global metadata Kai Huang
2024-12-13 11:17   ` Huang, Kai
2024-11-13 11:57 ` [PATCH v8 4/9] x86/virt/tdx: Use dedicated struct members for PAMT entry sizes Kai Huang
2024-11-13 11:57 ` [PATCH v8 5/9] x86/virt/tdx: Add missing header file inclusion to local tdx.h Kai Huang
2024-11-13 11:57 ` [PATCH v8 6/9] x86/virt/tdx: Switch to use auto-generated global metadata reading code Kai Huang
2024-11-13 11:57 ` [PATCH v8 7/9] x86/virt/tdx: Trim away tail null CMRs Kai Huang
2024-11-13 11:57 ` [PATCH v8 8/9] x86/virt/tdx: Reduce TDMR's reserved areas by using CMRs to find memory holes Kai Huang
2024-12-04 14:22   ` Huang, Kai
2024-12-05 12:45     ` Huang, Kai
2024-12-05 12:40   ` [PATCH v8 8.1/9] " Kai Huang
2024-12-05 18:10     ` Dave Hansen
2024-12-06  2:45       ` Huang, Kai
2024-12-09  6:57       ` Huang, Kai
2024-12-09  6:50   ` [PATCH v8 8.2/9] " Kai Huang
2024-12-09 22:54     ` Dave Hansen
2024-12-10  2:26       ` Huang, Kai [this message]
2024-12-10  2:46         ` Dan Williams
2024-12-10  4:24           ` Huang, Kai
2024-12-10 16:58             ` Dave Hansen
2024-12-11  4:34               ` Huang, Kai
2024-11-13 11:57 ` [PATCH v8 9/9] x86/virt/tdx: Require the module to assert it has the NO_RBP_MOD mitigation Kai Huang
2024-11-13 22:25 ` [PATCH v8 0/9] TDX host: metadata reading tweaks and bug fixes Edgecombe, Rick P
2024-11-13 22:40   ` Huang, Kai
2024-11-13 22:53     ` Edgecombe, Rick P
2024-11-13 23:35       ` Huang, Kai

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=83df85a3b318e6578628692ce0d28b9cf736061e.camel@intel.com \
    --to=kai.huang@intel.com \
    --cc=adrian.hunter@intel.com \
    --cc=bp@alien8.de \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@intel.com \
    --cc=hpa@zytor.com \
    --cc=isaku.yamahata@intel.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nik.borisov@suse.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rick.p.edgecombe@intel.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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®