[PATCH] x86/nestedsvm: Don't restore L1's CR2 during VMEXIT

Ross Lagerwall posted 1 patch 5 days, 4 hours ago
xen/arch/x86/hvm/svm/nestedsvm.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
[PATCH] x86/nestedsvm: Don't restore L1's CR2 during VMEXIT
Posted by Ross Lagerwall 5 days, 4 hours ago
According to the APM, the host CR2 is not restored during a VMEXIT.

The state of CR2 after a VMRUN that exits with VMEXIT_INVALID is not
explicitly defined by the APM. After this change, CR2 in L1 after a
failed VMRUN may contain either the original L1 CR2 or the L2 CR2. This
is in line with the observed behaviour of real hardware.

Fixes: 9a779e4fc161 ("Implement SVM specific part for Nested Virtualization")
Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
---
 xen/arch/x86/hvm/svm/nestedsvm.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/xen/arch/x86/hvm/svm/nestedsvm.c b/xen/arch/x86/hvm/svm/nestedsvm.c
index 81cae929dd05..5ddb0cda55bb 100644
--- a/xen/arch/x86/hvm/svm/nestedsvm.c
+++ b/xen/arch/x86/hvm/svm/nestedsvm.c
@@ -178,7 +178,6 @@ static int nsvm_vcpu_hostsave(struct vcpu *v, unsigned int inst_len)
      */
     n1vmcb->_efer = v->arch.hvm.guest_efer;
     n1vmcb->_cr0 = v->arch.hvm.guest_cr[0];
-    n1vmcb->_cr2 = v->arch.hvm.guest_cr[2];
     n1vmcb->_cr4 = v->arch.hvm.guest_cr[4];
 
     /* Remember the host interrupt flag */
@@ -232,8 +231,7 @@ static int nsvm_vcpu_hostrestore(struct vcpu *v, struct cpu_user_regs *regs)
     if ( rc != X86EMUL_OKAY )
         gdprintk(XENLOG_ERR, "hvm_set_cr0 failed, rc: %u\n", rc);
 
-    /* CR2 */
-    v->arch.hvm.guest_cr[2] = n1vmcb->_cr2;
+    /* Sync the current CR2 to L1's VMCB */
     hvm_update_guest_cr(v, 2);
 
     /* CR3 */
-- 
2.56.0