Re: [PATCH v3 04/21] x86/virt/tdx: Add skeleton for detecting and initializing TDX on demand

From: Kai Huang
Date: Thu Apr 28 2022 - 20:11:26 EST


On Thu, 2022-04-28 at 16:53 -0700, Dave Hansen wrote:
> On 4/28/22 16:44, Kai Huang wrote:
> > > Just like the SME test, it doesn't even need to be precise. It just
> > > needs to be 100% accurate in that it is *ALWAYS* set for any system that
> > > might have dirtied cache aliases.
> > >
> > > I'm not sure why you are so fixated on SEAMRR specifically for this.
> > I see. I think I can simply use MTRR.SEAMRR bit check. If CPU supports SEAMRR,
> > then basically it supports MKTME.
> >
> > Is this look good for you?
>
> Sure, fine, as long as it comes with a coherent description that
> explains why the check is good enough.
>
> > > > "During initializing the TDX module, one step requires some SEAMCALL must be
> > > > done on all logical cpus enabled by BIOS, otherwise a later step will fail.
> > > > Disable CPU hotplug during the initialization process to prevent any CPU going
> > > > offline during initializing the TDX module. Note it is caller's responsibility
> > > > to guarantee all BIOS-enabled CPUs are in cpu_present_mask and all present CPUs
> > > > are online."
> > > But, what if a CPU went offline just before this lock was taken? What
> > > if the caller make sure all present CPUs are online, makes the call,
> > > then a CPU is taken offline. The lock wouldn't do any good.
> > >
> > > What purpose does the lock serve?
> > I thought cpus_read_lock() can prevent any CPU from going offline, no?
>
> It doesn't prevent squat before the lock is taken, though.

This is true. So I think w/o taking the lock is also fine, as the TDX module
initialization is a state machine. If any cpu goes offline during logical-cpu
level initialization and TDH.SYS.LP.INIT isn't done on that cpu, then later the
TDH.SYS.CONFIG will fail. Similarly, if any cpu going offline causes
TDH.SYS.KEY.CONFIG is not done for any package, then TDH.SYS.TDMR.INIT will
fail.

A problem (I realized it exists in current implementation too) is shutting down
the TDX module, which requires calling TDH.SYS.LP.SHUTDOWN on all BIOS-enabled
cpus. Kernel can do this SEAMCALL at most for all present cpus. However when
any cpu is offline, this SEAMCALL won't be called on it, and it seems we need to
add new CPU hotplug callback to call this SEAMCALL when the cpu is online again.

Any suggestion? Thanks!


--
Thanks,
-Kai