All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xen/x86/hvm: Propagate emulated CR2 writes to the VMCB
@ 2026-10-20 21:33 Stefano Stabellini
  2026-10-21  8:19 ` Roger Pau Monné
  2026-10-26  9:59 ` Jan Beulich
  0 siblings, 2 replies; 5+ messages in thread
From: Stefano Stabellini @ 2026-10-20 21:33 UTC (permalink / raw)
  To: xen-devel
  Cc: jbeulich, andrew.cooper3, roger, jason.andryuk, teddy.astie,
	stefano.stabellini

hvmemul_write_cr() updates guest_cr[2] but, unlike every other writer of
it, doesn't call hvm_update_guest_cr(). On SVM, CR2 is loaded from
the VMCB, so the emulated write never reaches the guest, and the next
VMExit overwrites guest_cr[2] with the stale VMCB value.

Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
---
 xen/arch/x86/hvm/emulate.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c
index c09ea002ec..cd2831d34b 100644
--- a/xen/arch/x86/hvm/emulate.c
+++ b/xen/arch/x86/hvm/emulate.c
@@ -2350,6 +2350,7 @@ static int cf_check hvmemul_write_cr(
 
     case 2:
         curr->arch.hvm.guest_cr[2] = val;
+        hvm_update_guest_cr(curr, 2);
         rc = X86EMUL_OKAY;
         break;
 
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] xen/x86/hvm: Propagate emulated CR2 writes to the VMCB
  2026-10-20 21:33 [PATCH] xen/x86/hvm: Propagate emulated CR2 writes to the VMCB Stefano Stabellini
@ 2026-10-21  8:19 ` Roger Pau Monné
  2026-10-21 13:11   ` Ross Lagerwall
  2026-10-26  9:59 ` Jan Beulich
  1 sibling, 1 reply; 5+ messages in thread
From: Roger Pau Monné @ 2026-10-21  8:19 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: xen-devel, jbeulich, andrew.cooper3, jason.andryuk, teddy.astie

On Tue, Oct 20, 2026 at 02:33:15PM -0700, Stefano Stabellini wrote:
> hvmemul_write_cr() updates guest_cr[2] but, unlike every other writer of
> it, doesn't call hvm_update_guest_cr(). On SVM, CR2 is loaded from
> the VMCB, so the emulated write never reaches the guest, and the next
> VMExit overwrites guest_cr[2] with the stale VMCB value.
> 
> Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>

Acked-by: Roger Pau Monné <roger@xenproject.org>

I wonder whether there's more missing here, see below.

> ---
>  xen/arch/x86/hvm/emulate.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c
> index c09ea002ec..cd2831d34b 100644
> --- a/xen/arch/x86/hvm/emulate.c
> +++ b/xen/arch/x86/hvm/emulate.c
> @@ -2350,6 +2350,7 @@ static int cf_check hvmemul_write_cr(
>  
>      case 2:
>          curr->arch.hvm.guest_cr[2] = val;
> +        hvm_update_guest_cr(curr, 2);

Looking at hvm_update_cr(), is this possibly also missing a call to
nestedhvm_set_cr()?

Thanks, Roger.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] xen/x86/hvm: Propagate emulated CR2 writes to the VMCB
  2026-10-21  8:19 ` Roger Pau Monné
@ 2026-10-21 13:11   ` Ross Lagerwall
  2026-10-21 14:02     ` Roger Pau Monné
  0 siblings, 1 reply; 5+ messages in thread
From: Ross Lagerwall @ 2026-10-21 13:11 UTC (permalink / raw)
  To: Roger Pau Monné, Stefano Stabellini
  Cc: xen-devel, jbeulich, andrew.cooper3, jason.andryuk, teddy.astie

On 10/21/26 9:19 AM, Roger Pau Monné wrote:
> On Tue, Oct 20, 2026 at 02:33:15PM -0700, Stefano Stabellini wrote:
>> hvmemul_write_cr() updates guest_cr[2] but, unlike every other writer of
>> it, doesn't call hvm_update_guest_cr(). On SVM, CR2 is loaded from
>> the VMCB, so the emulated write never reaches the guest, and the next
>> VMExit overwrites guest_cr[2] with the stale VMCB value.
>>
>> Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
> 
> Acked-by: Roger Pau Monné <roger@xenproject.org>
> 
> I wonder whether there's more missing here, see below.
> 
>> ---
>>   xen/arch/x86/hvm/emulate.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c
>> index c09ea002ec..cd2831d34b 100644
>> --- a/xen/arch/x86/hvm/emulate.c
>> +++ b/xen/arch/x86/hvm/emulate.c
>> @@ -2350,6 +2350,7 @@ static int cf_check hvmemul_write_cr(
>>   
>>       case 2:
>>           curr->arch.hvm.guest_cr[2] = val;
>> +        hvm_update_guest_cr(curr, 2);
> 
> Looking at hvm_update_cr(), is this possibly also missing a call to
> nestedhvm_set_cr()?

AFAIK the values set by nestedhvm_set_cr() are not used at all with nested SVM
and from a brief look may only be used for CR0 and CR4 for VVMX. So maybe it is
not needed, though for consistency I think it would make sense to replace both
lines with a single call to hvm_update_cr().

Ross


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] xen/x86/hvm: Propagate emulated CR2 writes to the VMCB
  2026-10-21 13:11   ` Ross Lagerwall
@ 2026-10-21 14:02     ` Roger Pau Monné
  0 siblings, 0 replies; 5+ messages in thread
From: Roger Pau Monné @ 2026-10-21 14:02 UTC (permalink / raw)
  To: Ross Lagerwall
  Cc: Stefano Stabellini, xen-devel, jbeulich, andrew.cooper3,
	jason.andryuk, teddy.astie

On Wed, Oct 21, 2026 at 02:11:30PM +0100, Ross Lagerwall wrote:
> On 10/21/26 9:19 AM, Roger Pau Monné wrote:
> > On Tue, Oct 20, 2026 at 02:33:15PM -0700, Stefano Stabellini wrote:
> > > hvmemul_write_cr() updates guest_cr[2] but, unlike every other writer of
> > > it, doesn't call hvm_update_guest_cr(). On SVM, CR2 is loaded from
> > > the VMCB, so the emulated write never reaches the guest, and the next
> > > VMExit overwrites guest_cr[2] with the stale VMCB value.
> > > 
> > > Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
> > 
> > Acked-by: Roger Pau Monné <roger@xenproject.org>
> > 
> > I wonder whether there's more missing here, see below.
> > 
> > > ---
> > >   xen/arch/x86/hvm/emulate.c | 1 +
> > >   1 file changed, 1 insertion(+)
> > > 
> > > diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c
> > > index c09ea002ec..cd2831d34b 100644
> > > --- a/xen/arch/x86/hvm/emulate.c
> > > +++ b/xen/arch/x86/hvm/emulate.c
> > > @@ -2350,6 +2350,7 @@ static int cf_check hvmemul_write_cr(
> > >       case 2:
> > >           curr->arch.hvm.guest_cr[2] = val;
> > > +        hvm_update_guest_cr(curr, 2);
> > 
> > Looking at hvm_update_cr(), is this possibly also missing a call to
> > nestedhvm_set_cr()?
> 
> AFAIK the values set by nestedhvm_set_cr() are not used at all with nested SVM
> and from a brief look may only be used for CR0 and CR4 for VVMX. So maybe it is
> not needed, though for consistency I think it would make sense to replace both
> lines with a single call to hvm_update_cr().

Yes, however at the time being hvm_update_cr() is static to hvm.c.
It would mean exporting the function, which maybe we should have done
in the first place instead of exporting hvm_update_guest_cr()?

Thanks, Roger.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] xen/x86/hvm: Propagate emulated CR2 writes to the VMCB
  2026-10-20 21:33 [PATCH] xen/x86/hvm: Propagate emulated CR2 writes to the VMCB Stefano Stabellini
  2026-10-21  8:19 ` Roger Pau Monné
@ 2026-10-26  9:59 ` Jan Beulich
  1 sibling, 0 replies; 5+ messages in thread
From: Jan Beulich @ 2026-10-26  9:59 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: andrew.cooper3, roger, jason.andryuk, teddy.astie, xen-devel

On 20.10.2026 23:33, Stefano Stabellini wrote:
> hvmemul_write_cr() updates guest_cr[2] but, unlike every other writer of
> it, doesn't call hvm_update_guest_cr(). On SVM, CR2 is loaded from
> the VMCB, so the emulated write never reaches the guest, and the next
> VMExit overwrites guest_cr[2] with the stale VMCB value.
> 
> Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>

Especially as this looks to affect not just (or even not at all) nested,
I think there should have been a Fixes: tag here. I see the change was
already committed without, but I think this wants backporting nevertheless.

Jan


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-10-26  9:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-20 21:33 [PATCH] xen/x86/hvm: Propagate emulated CR2 writes to the VMCB Stefano Stabellini
2026-10-21  8:19 ` Roger Pau Monné
2026-10-21 13:11   ` Ross Lagerwall
2026-10-21 14:02     ` Roger Pau Monné
2026-10-26  9:59 ` Jan Beulich

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.