xen/x86/hvm: Propagate emulated CR2 writes to the VMCB
PATCH 1/1 xen/x86/hvm: Propagate emulated CR2 writes to the VMCB
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.
--- xen/arch/x86/hvm/emulate.c | 1 + 1 file changed, 1 insertion(+)
xen/arch/x86/hvm/emulate.c +1 -0
@@ -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 ;
Signature · 1 line
2.43.0
Quoted 6 lines · Stefano Stabellini
hvmemul_write_cr()updates guest_cr[2] but, unlike every other writer of it, doesn't callhvm_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 <[email protected]>
I wonder whether there's more missing here, see below.
xen/arch/x86/hvm/emulate.c static int cf_check hvmemul_write_cr( · line 2353
Quoted 13 lines
--- xen/arch/x86/hvm/emulate.c | 1 + 1 file changed, 1 insertion(+)xen/arch/x86/hvm/emulate.c +1
-0@@ -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.
Quoted 22 lines · Roger Pau Monné
Quoted 6 lines · Stefano Stabellini
hvmemul_write_cr()updates guest_cr[2] but, unlike every other writer of it, doesn't callhvm_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 <[email protected]>Acked-by Roger Pau Monné <[email protected]>I wonder whether there's more missing here, see below.
Quoted 10 lines
--- xen/arch/x86/hvm/emulate.c | 1 + 1 file changed, 1 insertion(+)xen/arch/x86/hvm/emulate.c +0
-0@@ -2350,6 +2350,7 @@ static int cf_check hvmemul_write_cr(
Quoted 6 lines
xen/arch/x86/hvm/emulate.c static int cf_check hvmemul_write_cr( · line 2353
Quoted 3 lines
xen/arch/x86/hvm/emulate.c +1
-0case 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 tonestedhvm_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
Quoted 29 lines · Ross Lagerwall
Quoted 16 lines · Roger Pau Monné
Quoted 6 lines · Stefano Stabellini
hvmemul_write_cr()updates guest_cr[2] but, unlike every other writer of it, doesn't callhvm_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 <[email protected]>Acked-by Roger Pau Monné <[email protected]>I wonder whether there's more missing here, see below.
Quoted 4 lines
--- xen/arch/x86/hvm/emulate.c | 1 + 1 file changed, 1 insertion(+)Quoted 11 lines
xen/arch/x86/hvm/emulate.c static int cf_check hvmemul_write_cr( · line 2352
Quoted 8 lines
xen/arch/x86/hvm/emulate.c +1
-0@@ -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 tonestedhvm_set_cr()?
Quoted 4 lines
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 tohvm_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.
Quoted 6 lines · Stefano Stabellini
hvmemul_write_cr()updates guest_cr[2] but, unlike every other writer of it, doesn't callhvm_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 <[email protected]>
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