nestedsvm: Don't set CR2 while injecting VMEXIT_EXCEPTION_PF
PATCH 1/1 nestedsvm: Don't set CR2 while injecting VMEXIT_EXCEPTION_PF
According to the APM, the #PF intercept is tested before CR2 is written so don't write CR2 while injecting VMEXIT_EXCEPTION_PF into L1. The faulting address is available to L1 in EXITINFO2.
--- xen/arch/x86/hvm/svm/nestedsvm.c | 2 -- 1 file changed, 2 deletions(-)
xen/arch/x86/hvm/svm/nestedsvm.c +0 -2
@@ -741,8 +741,6 @@ nsvm_vcpu_vmexit_inject(struct vcpu *v, struct cpu_user_regs *regs, ns_vmcb->exit_int_info = ns_vmcb->event_inj;break ;case VMEXIT_EXCEPTION_PF : - ns_vmcb->_cr2 = ns_vmcb->ei.exc.cr2; - fallthrough;case VMEXIT_NPF : ns_vmcb->exitinfo2 = svm->ns_vmexit.exitinfo2; fallthrough;
Signature · 1 line
2.56.0
Quoted 6 lines · Ross Lagerwall
According to the APM, the #PF intercept is tested before CR2 is written so don't write CR2 while injecting
VMEXIT_EXCEPTION_PFinto L1. The faulting address is available to L1 in EXITINFO2.Fixes 9a779e4fc161 ("Implement SVM specific part for Nested Virtualization")Signed-off-by Ross Lagerwall <[email protected]>
xen/arch/x86/hvm/svm/nestedsvm.c nsvm_vcpu_vmexit_inject(struct vcpu *v, struct cpu_user_regs *regs, · line 744
Quoted 7 lines
xen/arch/x86/hvm/svm/nestedsvm.c +0
-1@@ -741,8 +741,6 @@ nsvm_vcpu_vmexit_inject(struct vcpu *v, struct cpu_user_regs *regs, ns_vmcb->exit_int_info = ns_vmcb->event_inj;break ;case VMEXIT_EXCEPTION_PF : - ns_vmcb->_cr2 = ns_vmcb->ei.exc.cr2;
Further to what you say in the description, isn't this also a stale value, as ...
xen/arch/x86/hvm/svm/nestedsvm.c nsvm_vcpu_vmexit_inject(struct vcpu *v, struct cpu_user_regs *regs, · line 745
Quoted 3 lines
xen/arch/x86/hvm/svm/nestedsvm.c +0
-1- fallthrough;case VMEXIT_NPF : ns_vmcb->exitinfo2 = svm->ns_vmexit.exitinfo2;
... the correct one is written only here? If you agree, I'd be inclined to have the description say "... so don't write CR2 (with a stale value) while ..." (happy to adjust while committing).
Jan
Quoted 9 lines · Jan Beulich
Quoted 6 lines · Ross Lagerwall
According to the APM, the #PF intercept is tested before CR2 is written so don't write CR2 while injecting
VMEXIT_EXCEPTION_PFinto L1. The faulting address is available to L1 in EXITINFO2.Fixes 9a779e4fc161 ("Implement SVM specific part for Nested Virtualization")Signed-off-by Ross Lagerwall <[email protected]>Acked-by Jan Beulich <[email protected]>
Thanks
Quoted 12 lines
xen/arch/x86/hvm/svm/nestedsvm.c nsvm_vcpu_vmexit_inject(struct vcpu *v, struct cpu_user_regs *regs, · line 744
Quoted 8 lines
xen/arch/x86/hvm/svm/nestedsvm.c +0
-1@@ -741,8 +741,6 @@ nsvm_vcpu_vmexit_inject(struct vcpu *v, struct cpu_user_regs *regs, ns_vmcb->exit_int_info = ns_vmcb->event_inj;break ;case VMEXIT_EXCEPTION_PF : - ns_vmcb->_cr2 = ns_vmcb->ei.exc.cr2;Further to what you say in the description, isn't this also a stale value, as ...
Quoted 7 lines
xen/arch/x86/hvm/svm/nestedsvm.c nsvm_vcpu_vmexit_inject(struct vcpu *v, struct cpu_user_regs *regs, · line 745
Quoted 3 lines
xen/arch/x86/hvm/svm/nestedsvm.c +0
-1- fallthrough;case VMEXIT_NPF : ns_vmcb->exitinfo2 = svm->ns_vmexit.exitinfo2;... the correct one is written only here? If you agree, I'd be inclined to have the description say "... so don't write CR2 (with a stale value) while ..." (happy to adjust while committing).
In most cases it wouldn't be stale because ei.exc.cr2 is the same as exitinfo2 and ns_vmcb->exitinfo2 is updated before this in prepare4vmexit(). However, I think it may be stale in some cases, e.g. if the #PF was raised by the L0 emulator.
Ross
Quoted 29 lines · Ross Lagerwall
Quoted 9 lines · Jan Beulich
Quoted 6 lines · Ross Lagerwall
According to the APM, the #PF intercept is tested before CR2 is written so don't write CR2 while injecting
VMEXIT_EXCEPTION_PFinto L1. The faulting address is available to L1 in EXITINFO2.Fixes 9a779e4fc161 ("Implement SVM specific part for Nested Virtualization")Signed-off-by Ross Lagerwall <[email protected]>Acked-by Jan Beulich <[email protected]>Thanks
Quoted 16 lines
xen/arch/x86/hvm/svm/nestedsvm.c nsvm_vcpu_vmexit_inject(struct vcpu *v, struct cpu_user_regs *regs, · line 744
Quoted 8 lines
xen/arch/x86/hvm/svm/nestedsvm.c +0
-1@@ -741,8 +741,6 @@ nsvm_vcpu_vmexit_inject(struct vcpu *v, struct cpu_user_regs *regs, ns_vmcb->exit_int_info = ns_vmcb->event_inj;break ;case VMEXIT_EXCEPTION_PF : - ns_vmcb->_cr2 = ns_vmcb->ei.exc.cr2;Further to what you say in the description, isn't this also a stale value, as ...
Quoted 3 lines
xen/arch/x86/hvm/svm/nestedsvm.c +0
-1- fallthrough;case VMEXIT_NPF : ns_vmcb->exitinfo2 = svm->ns_vmexit.exitinfo2;
Quoted 8 lines
Quoted 3 lines
... the correct one is written only here? If you agree, I'd be inclined to have the description say "... so don't write CR2 (with a stale value) while ..." (happy to adjust while committing).
In most cases it wouldn't be stale because ei.exc.cr2 is the same as exitinfo2 and
ns_vmcb->exitinfo2is updated before this inprepare4vmexit(). However, I think it may be stale in some cases, e.g. if the #PF was raised by the L0 emulator.
So further add "possibly" to what I suggested? (If ns_vmcb->exitinfo2 was always updated earlier on, the updating here could be avoided.)
Jan
Quoted 34 lines · Jan Beulich
Quoted 33 lines · Ross Lagerwall
Quoted 9 lines · Jan Beulich
Quoted 6 lines · Ross Lagerwall
According to the APM, the #PF intercept is tested before CR2 is written so don't write CR2 while injecting
VMEXIT_EXCEPTION_PFinto L1. The faulting address is available to L1 in EXITINFO2.Fixes 9a779e4fc161 ("Implement SVM specific part for Nested Virtualization")Signed-off-by Ross Lagerwall <[email protected]>Acked-by Jan Beulich <[email protected]>Thanks
Quoted 19 lines
xen/arch/x86/hvm/svm/nestedsvm.c nsvm_vcpu_vmexit_inject(struct vcpu *v, struct cpu_user_regs *regs, · line 744
Quoted 8 lines
xen/arch/x86/hvm/svm/nestedsvm.c +0
-1@@ -741,8 +741,6 @@ nsvm_vcpu_vmexit_inject(struct vcpu *v, struct cpu_user_regs *regs, ns_vmcb->exit_int_info = ns_vmcb->event_inj;break ;case VMEXIT_EXCEPTION_PF : - ns_vmcb->_cr2 = ns_vmcb->ei.exc.cr2;Further to what you say in the description, isn't this also a stale value, as ...
xen/arch/x86/hvm/svm/nestedsvm.c nsvm_vcpu_vmexit_inject(struct vcpu *v, struct cpu_user_regs *regs, · line 745
Quoted 3 lines
xen/arch/x86/hvm/svm/nestedsvm.c +0
-1- fallthrough;case VMEXIT_NPF : ns_vmcb->exitinfo2 = svm->ns_vmexit.exitinfo2;... the correct one is written only here? If you agree, I'd be inclined to have the description say "... so don't write CR2 (with a stale value) while ..." (happy to adjust while committing).
Quoted 7 lines
Quoted 4 lines
In most cases it wouldn't be stale because ei.exc.cr2 is the same as exitinfo2 and
ns_vmcb->exitinfo2is updated before this inprepare4vmexit(). However, I think it may be stale in some cases, e.g. if the #PF was raised by the L0 emulator.So further add "possibly" to what I suggested? (If
ns_vmcb->exitinfo2was always updated earlier on, the updating here could be avoided.)
Yes, I agree with that adjustment.
Ross
Quoted 15 lines · Ross Lagerwall
According to the APM, the #PF intercept is tested before CR2 is written so don't write CR2 while injecting
VMEXIT_EXCEPTION_PFinto L1. The faulting address is available to L1 in EXITINFO2.Fixes 9a779e4fc161 ("Implement SVM specific part for Nested Virtualization")Signed-off-by Ross Lagerwall <[email protected]>--- xen/arch/x86/hvm/svm/nestedsvm.c | 2 -- 1 file changed, 2 deletions(-)xen/arch/x86/hvm/svm/nestedsvm.c +0
-0
xen/arch/x86/hvm/svm/nestedsvm.c nsvm_vcpu_vmexit_inject(struct vcpu *v, struct cpu_user_regs *regs, · line 746
Quoted 8 lines
xen/arch/x86/hvm/svm/nestedsvm.c +0
-2@@ -741,8 +741,6 @@ nsvm_vcpu_vmexit_inject(struct vcpu *v, struct cpu_user_regs *regs, ns_vmcb->exit_int_info = ns_vmcb->event_inj;break ;case VMEXIT_EXCEPTION_PF : - ns_vmcb->_cr2 = ns_vmcb->ei.exc.cr2; - fallthrough;case VMEXIT_NPF : ns_vmcb->exitinfo2 = svm->ns_vmexit.exitinfo2; fallthrough;