[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <SA1PR11MB673412E7813B659F16284B74A8C12@SA1PR11MB6734.namprd11.prod.outlook.com>
Date: Thu, 13 Jun 2024 18:02:56 +0000
From: "Li, Xin3" <xin3.li@...el.com>
To: Sean Christopherson <seanjc@...gle.com>
CC: "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"kvm@...r.kernel.org" <kvm@...r.kernel.org>, "linux-doc@...r.kernel.org"
<linux-doc@...r.kernel.org>, "linux-kselftest@...r.kernel.org"
<linux-kselftest@...r.kernel.org>, "pbonzini@...hat.com"
<pbonzini@...hat.com>, "corbet@....net" <corbet@....net>,
"tglx@...utronix.de" <tglx@...utronix.de>, "mingo@...hat.com"
<mingo@...hat.com>, "bp@...en8.de" <bp@...en8.de>,
"dave.hansen@...ux.intel.com" <dave.hansen@...ux.intel.com>, "x86@...nel.org"
<x86@...nel.org>, "hpa@...or.com" <hpa@...or.com>, "shuah@...nel.org"
<shuah@...nel.org>, "vkuznets@...hat.com" <vkuznets@...hat.com>,
"peterz@...radead.org" <peterz@...radead.org>, "Shankar, Ravi V"
<ravi.v.shankar@...el.com>, "xin@...or.com" <xin@...or.com>
Subject: RE: [PATCH v2 12/25] KVM: VMX: Handle FRED event data
> On Wed, Feb 07, 2024, Xin Li wrote:
> > @@ -7382,6 +7419,24 @@ static noinstr void vmx_vcpu_enter_exit(struct
> kvm_vcpu *vcpu,
> >
> > vmx_disable_fb_clear(vmx);
> >
> > + /*
> > + * %cr2 needs to be saved after a VM exit and restored before a VM
> > + * entry in case a VM exit happens immediately after delivery of a
> > + * guest #PF but before guest reads %cr2.
> > + *
> > + * A FRED guest should read its #PF faulting linear address from
> > + * the event data field in its FRED stack frame instead of %cr2.
> > + * But the FRED 5.0 spec still requires a FRED CPU to update %cr2
> > + * in the normal way, thus %cr2 is still updated even for a FRED
> > + * guest.
> > + *
> > + * Note, an NMI could interrupt KVM:
> > + * 1) after VM exit but before CR2 is saved.
> > + * 2) after CR2 is restored but before VM entry.
> > + * And a #PF could happen durng NMI handlng, which overwrites %cr2.
> > + * Thus exc_nmi() should save and restore %cr2 upon entering and
> > + * before leaving to make sure %cr2 not corrupted.
> > + */
>
> This is 99.9% noise. What software does or does not do with respect to CR2 is
> completely irrelevant. The *only* thing that matters is the architectural
> behavior, and architecturally guest CR2 _must_ be up-to-date at all times because
> CR2 accesses cannot be intercepted. So, just say:
>
> /*
> * Note, even though FRED delivers the faulting linear address via the
> * event data field on the stack, CR2 is still updated.
> */
Will do!
There is a reason for this comment because it won't be architectural:
https://lore.kernel.org/lkml/c0c7c605-d487-483e-a034-983b76ee1dfa@zytor.com/
FRED is designed to atomically save and restore _full_ supervisor/user
context upon event delivery and return. But unfortunately, KVM still has
to save/restore guest CR2 explicitly due to the issue mentioned above.
Thanks!
Xin
Powered by blists - more mailing lists