On Tue, Jul 04, 2023 at 09:50:22PM +0000, Huang, Kai wrote: > On Tue, 2023-07-04 at 18:58 +0200, Peter Zijlstra wrote: > > On Fri, Jun 30, 2023 at 02:24:56PM -0700, Sean Christopherson wrote: > > > > > Waiting until userspace attempts to create the first TDX guest adds complexity > > > and limits what KVM can do to harden itself. Currently, all feature support in > > > KVM is effectively frozen at module load. E.g. most of the setup code is > > > contained in __init functions, many module-scoped variables are effectively > > > RO after init (though they can't be marked as such until we smush kvm-intel.ko > > > and kvm-amd.ko into kvm.ko, which is tentatively the long-term plan). All of > > > those patterns would get tossed aside if KVM waits until userspace attempts to > > > create the first guest. > > > > .... > > > > People got poked and the following was suggested: > > > > On boot do: > > > > TDH.SYS.INIT > > TDH.SYS.LP.INIT > > TDH.SYS.CONFIG > > TDH.SYS.KEY.CONFIG > > > > This should get TDX mostly sorted, but doesn't consume much resources. > > Then later, when starting the first TDX guest, do the whole > > > > TDH.TDMR.INIT > > > > dance to set up the PAMT array -- which is what gobbles up memory. From > > what I understand the TDH.TDMR.INIT thing is not one of those > > excessively long calls. > > The TDH.TDMR.INIT itself has it's own latency requirement implemented in the TDX > module, thus it only initializes a small chunk (1M I guess) in each call. > Therefore we need a loop to do bunch of TDH.TDMR.INIT in order to initialize all > PAMT entries for all TDX-usable memory, which can be time-consuming. Yeah, so you can put a cond_resched() in that loop and all is well, you do not negatively affect other tasks. Because *that* was the concern raised.