xen/arch/x86/hvm/hvm.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
The APM leaves it undefined what happens when the VMM doesn't intercept
writes to EFER and EFER.SVME is cleared. The current implementation in
Xen resets the nested state without doing a VMEXIT which is unexpected
and may potentially hit a BUG or assertion failure.
Therefore, implement the same behaviour as the APM documents for SEV-ES
guests; ignore the attempt to clear it.
Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
---
Another option here could be to fail VMRUN if L1 does not intercept
writes to EFER. However, this wouldn't match the behaviour of real
processors and may cause incomplete toy hypervisors to unexpectedly
fail.
xen/arch/x86/hvm/hvm.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 71da15c0a4ed..f4155f523598 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -2156,9 +2156,15 @@ int hvm_set_efer(uint64_t value)
((value & EFER_SVME) == 0 ) &&
((value ^ v->arch.hvm.guest_efer) & EFER_SVME) )
{
- /* Cleared EFER.SVME: Flush all nestedp2m tables */
- p2m_flush_nestedp2m(v->domain);
- nestedhvm_vcpu_reset(v);
+ if ( nestedhvm_vcpu_in_guestmode(v) )
+ /* Ignore attempts to clear EFER.SVME from L2 */
+ value |= EFER_SVME;
+ else
+ {
+ /* Cleared EFER.SVME: Flush all nestedp2m tables */
+ p2m_flush_nestedp2m(v->domain);
+ nestedhvm_vcpu_reset(v);
+ }
}
value |= v->arch.hvm.guest_efer & EFER_LMA;
--
2.56.0
On 13/11/2026 4:02 pm, Ross Lagerwall wrote:
> The APM leaves it undefined what happens when the VMM doesn't intercept
> writes to EFER and EFER.SVME is cleared. The current implementation in
> Xen resets the nested state without doing a VMEXIT which is unexpected
> and may potentially hit a BUG or assertion failure.
>
> Therefore, implement the same behaviour as the APM documents for SEV-ES
> guests; ignore the attempt to clear it.
I agree this is the right course of action. It's also what KVM does as
well IIRC.
>
> Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
> ---
>
> Another option here could be to fail VMRUN if L1 does not intercept
> writes to EFER. However, this wouldn't match the behaviour of real
> processors and may cause incomplete toy hypervisors to unexpectedly
> fail.
>
> xen/arch/x86/hvm/hvm.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
> index 71da15c0a4ed..f4155f523598 100644
> --- a/xen/arch/x86/hvm/hvm.c
> +++ b/xen/arch/x86/hvm/hvm.c
> @@ -2156,9 +2156,15 @@ int hvm_set_efer(uint64_t value)
> ((value & EFER_SVME) == 0 ) &&
> ((value ^ v->arch.hvm.guest_efer) & EFER_SVME) )
> {
> - /* Cleared EFER.SVME: Flush all nestedp2m tables */
> - p2m_flush_nestedp2m(v->domain);
> - nestedhvm_vcpu_reset(v);
> + if ( nestedhvm_vcpu_in_guestmode(v) )
> + /* Ignore attempts to clear EFER.SVME from L2 */
> + value |= EFER_SVME;
> + else
> + {
> + /* Cleared EFER.SVME: Flush all nestedp2m tables */
> + p2m_flush_nestedp2m(v->domain);
> + nestedhvm_vcpu_reset(v);
> + }
> }
>
> value |= v->arch.hvm.guest_efer & EFER_LMA;
I think this is ok, given the state of the codebase, so Reviewed-by:
Andrew Cooper <andrew.cooper3@citrix.com>
However, this is bad logic. nestedhvm_vcpu_reset() ultimately sets
GIF=1 and this is almost certainly not what happens in real hardware.
It also zeroes a lot of state which are by definition 0 in root mode.
It's also nasty having SVM specifics escape into common code, but it's
necessary as we're choosing to ignore in a guest-visible way. We don't
want to have two areas of code trying to decide what the eventual EFER
should be.
We'll need to fix all of this due course.
~Andrew
On 13.11.2026 17:02, Ross Lagerwall wrote:
> The APM leaves it undefined what happens when the VMM doesn't intercept
> writes to EFER and EFER.SVME is cleared. The current implementation in
> Xen resets the nested state without doing a VMEXIT which is unexpected
> and may potentially hit a BUG or assertion failure.
>
> Therefore, implement the same behaviour as the APM documents for SEV-ES
> guests; ignore the attempt to clear it.
>
> Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
> ---
>
> Another option here could be to fail VMRUN if L1 does not intercept
> writes to EFER. However, this wouldn't match the behaviour of real
> processors and may cause incomplete toy hypervisors to unexpectedly
> fail.
+1
> --- a/xen/arch/x86/hvm/hvm.c
> +++ b/xen/arch/x86/hvm/hvm.c
> @@ -2156,9 +2156,15 @@ int hvm_set_efer(uint64_t value)
> ((value & EFER_SVME) == 0 ) &&
> ((value ^ v->arch.hvm.guest_efer) & EFER_SVME) )
Unrelated to your change, but: What is this? When we have checked that
SVME is clear in value, why would value need XORing with what's currently
in effect to figure whether a 1->0 transition is occurring?
Jan
> {
> - /* Cleared EFER.SVME: Flush all nestedp2m tables */
> - p2m_flush_nestedp2m(v->domain);
> - nestedhvm_vcpu_reset(v);
> + if ( nestedhvm_vcpu_in_guestmode(v) )
> + /* Ignore attempts to clear EFER.SVME from L2 */
> + value |= EFER_SVME;
> + else
> + {
> + /* Cleared EFER.SVME: Flush all nestedp2m tables */
> + p2m_flush_nestedp2m(v->domain);
> + nestedhvm_vcpu_reset(v);
> + }
> }
>
> value |= v->arch.hvm.guest_efer & EFER_LMA;
On 11/16/26 11:34 AM, Jan Beulich wrote: > On 13.11.2026 17:02, Ross Lagerwall wrote: >> The APM leaves it undefined what happens when the VMM doesn't intercept >> writes to EFER and EFER.SVME is cleared. The current implementation in >> Xen resets the nested state without doing a VMEXIT which is unexpected >> and may potentially hit a BUG or assertion failure. >> >> Therefore, implement the same behaviour as the APM documents for SEV-ES >> guests; ignore the attempt to clear it. >> >> Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com> > > Acked-by: Jan Beulich <jbeulich@suse.com> > Thanks >> --- >> >> Another option here could be to fail VMRUN if L1 does not intercept >> writes to EFER. However, this wouldn't match the behaviour of real >> processors and may cause incomplete toy hypervisors to unexpectedly >> fail. > > +1 > >> --- a/xen/arch/x86/hvm/hvm.c >> +++ b/xen/arch/x86/hvm/hvm.c >> @@ -2156,9 +2156,15 @@ int hvm_set_efer(uint64_t value) >> ((value & EFER_SVME) == 0 ) && >> ((value ^ v->arch.hvm.guest_efer) & EFER_SVME) ) > > Unrelated to your change, but: What is this? When we have checked that > SVME is clear in value, why would value need XORing with what's currently > in effect to figure whether a 1->0 transition is occurring? > I agree that it is unnecessary. Looks like it has been that way since the code was added. Ross
© 2016 - 2026 Red Hat, Inc.