> From: Thomas Gleixner <tglx@xxxxxxxxxxxxx> > Sent: Thursday, December 16, 2021 5:35 PM > > On Thu, Dec 16 2021 at 01:04, Kevin Tian wrote: > >> From: Paolo Bonzini <paolo.bonzini@xxxxxxxxx> On Behalf Of Paolo > Bonzini > >> Considering that in practice all Linux guests with AMX would have XFD > >> passthrough (because if there's no prctl, Linux keeps AMX disabled in > >> XFD), this removes the need to do all the #NM handling too. Just make > > > > #NM trap is for XFD_ERR thus still required. > > > >> XFD passthrough if it can ever be set to a nonzero value. This costs an > >> RDMSR per vmexit even if neither the host nor the guest ever use AMX. > > > > Well, we can still trap WRMSR(XFD) in the start and then disable > interception > > after the 1st trap. > > If we go for buffer expansion at vcpu_create() or CPUID2 then I think > you don't need a trap at all. > > XFD_ERR: Always 0 on the host. Guest state needs to be preserved on > VMEXIT and restored on VMENTER > > This can be done simply with the MSR entry/exit controls. No trap > required neither for #NM for for XFD_ERR. > > VMENTER loads guest state. VMEXIT saves guest state and loads host state > (0) This implies three MSR operations for every vm-exit. With trap we only need one RDMSR in host #NM handler, one RDMSR/one WRMSR exit in guest #NM handler, which are both rare. plus one RDMSR/one WRMSR per vm-exit only if saved xfd_err is non-zero which is again rare. > > XFD: Always guest state > > So VMENTER does nothing and VMEXIT either saves guest state and the sync > function uses the automatically saved value or you keep the sync > function which does the rdmsrl() as is. > Yes, this is the 3rd open that I asked in another reply. The only restriction with this approach is that the sync cost is added also for legacy OS which doesn't touch xfd at all. Thanks Kevin