[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8bf596b45f68363134f431bcc550e16a9a231b80.camel@intel.com>
Date: Wed, 04 May 2022 13:15:45 +1200
From: Kai Huang <kai.huang@...el.com>
To: Dave Hansen <dave.hansen@...el.com>, linux-kernel@...r.kernel.org,
kvm@...r.kernel.org
Cc: seanjc@...gle.com, pbonzini@...hat.com, len.brown@...el.com,
tony.luck@...el.com, rafael.j.wysocki@...el.com,
reinette.chatre@...el.com, dan.j.williams@...el.com,
peterz@...radead.org, ak@...ux.intel.com,
kirill.shutemov@...ux.intel.com,
sathyanarayanan.kuppuswamy@...ux.intel.com,
isaku.yamahata@...el.com
Subject: Re: [PATCH v3 00/21] TDX host kernel support
On Tue, 2022-05-03 at 17:25 -0700, Dave Hansen wrote:
> On 5/3/22 16:59, Kai Huang wrote:
> > Should be:
> >
> > // prevent racing with TDX module initialization */
> > tdx_init_disable();
> >
> > if (tdx_module_initialized()) {
> > if (new_memory_resource in TDMRs)
> > // allow memory hot-add
> > else
> > // reject memory hot-add
> > } else if (new_memory_resource in CMR) {
> > // add new memory to TDX memory so it can be
> > // included into TDMRs
> >
> > // allow memory hot-add
> > }
> > else
> > // reject memory hot-add
> >
> > tdx_module_enable();
> >
> > And when platform doesn't TDX, always allow memory hot-add.
>
> I don't think it even needs to be *that* complicated.
>
> It could just be winner take all: if TDX is initialized first, don't
> allow memory hotplug. If memory hotplug happens first, don't allow TDX
> to be initialized.
>
> That's fine at least for a minimal patch set.
OK. This should also work.
We will need tdx_init_disable() which grabs the mutex to prevent TDX module
initialization from running concurrently, and to disable TDX module
initialization once for all.
>
> What you have up above is probably where you want to go eventually, but
> it means doing things like augmenting the e820 since it's the single
> source of truth for creating the TMDRs right now.
>
Yes. But in this case, I am thinking about probably we should switch from
consulting e820 to consulting memblock. The advantage of using e820 is it's
easy to include legacy PMEM as TDX memory, but the disadvantage is (as you can
see in e820_for_each_mem() loop) I am actually merging contiguous different
types of RAM entries in order to be consistent with the behavior of
e820_memblock_setup(). This is not nice.
If memory hot-add and TDX can only be one winner, legacy PMEM actually won't be
used as TDX memory anyway now. The reason is TDX guest will very likely needing
to use the new fd-based backend (see my reply in other emails), but not just
some random backend. To me it's totally fine to not support using legacy PMEM
directly as TD guest backend (and if we create a TD with real NVDIMM as backend
using dax, the TD cannot be created anyway). Given we cannot kmem-hot-add
legacy PMEM back as system RAM, to me it's pointless to include legacy PMEM into
TDMRs.
In this case, we can just create TDMRs based on memblock directly. One problem
is memblock will be gone after kernel boots, but this can be solved either by
keeping the memblock, or build the TDX memory early when memblock is still
alive.
Btw, eventually, as it's likely we need to support different source of TDX
memory (CLX memory, etc), I think eventually we will need some data structures
to represent TDX memory block and APIs to add those blocks to the whole TDX
memory so those TDX memory ranges from different source can be added before
initializing the TDX module.
struct tdx_memblock {
struct list_head list;
phys_addr_t start;
phys_addr_t end;
int nid;
...
};
struct tdx_memory {
struct list_head tmb_list;
...
};
int tdx_memory_add_memblock(start, end, nid, ...);
And the TDMRs can be created based on 'struct tdx_memory'.
For now, we only need to add memblock to TDX memory.
Any comments?
--
Thanks,
-Kai
Powered by blists - more mailing lists