[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZmslBVWkRHAjIXrE@google.com>
Date: Thu, 13 Jun 2024 09:57:41 -0700
From: Sean Christopherson <seanjc@...gle.com>
To: Xin Li <xin3.li@...el.com>
Cc: linux-kernel@...r.kernel.org, kvm@...r.kernel.org,
linux-doc@...r.kernel.org, linux-kselftest@...r.kernel.org,
pbonzini@...hat.com, corbet@....net, tglx@...utronix.de, mingo@...hat.com,
bp@...en8.de, dave.hansen@...ux.intel.com, x86@...nel.org, hpa@...or.com,
shuah@...nel.org, vkuznets@...hat.com, peterz@...radead.org,
ravi.v.shankar@...el.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.
*/
> if (vcpu->arch.cr2 != native_read_cr2())
> native_write_cr2(vcpu->arch.cr2);
>
Powered by blists - more mailing lists