xen/arch/x86/hvm/svm/nestedsvm.c | 2 -- 1 file changed, 2 deletions(-)
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.
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 | 2 --
1 file changed, 2 deletions(-)
diff --git a/xen/arch/x86/hvm/svm/nestedsvm.c b/xen/arch/x86/hvm/svm/nestedsvm.c
index 81cae929dd05..366178ff54a7 100644
--- a/xen/arch/x86/hvm/svm/nestedsvm.c
+++ b/xen/arch/x86/hvm/svm/nestedsvm.c
@@ -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;
--
2.56.0
On 13/11/2026 5:24 pm, Ross Lagerwall wrote:
> 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.
>
> 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 | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/xen/arch/x86/hvm/svm/nestedsvm.c b/xen/arch/x86/hvm/svm/nestedsvm.c
> index 81cae929dd05..366178ff54a7 100644
> --- a/xen/arch/x86/hvm/svm/nestedsvm.c
> +++ b/xen/arch/x86/hvm/svm/nestedsvm.c
> @@ -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;
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
On 13.11.2026 18:24, Ross Lagerwall wrote:
> 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.
>
> Fixes: 9a779e4fc161 ("Implement SVM specific part for Nested Virtualization")
> Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
> --- a/xen/arch/x86/hvm/svm/nestedsvm.c
> +++ b/xen/arch/x86/hvm/svm/nestedsvm.c
> @@ -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 ...
> - 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
On 11/16/26 11:42 AM, Jan Beulich wrote:
> On 13.11.2026 18:24, Ross Lagerwall wrote:
>> 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.
>>
>> Fixes: 9a779e4fc161 ("Implement SVM specific part for Nested Virtualization")
>> Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
>
> Acked-by: Jan Beulich <jbeulich@suse.com>
Thanks
>
>> --- a/xen/arch/x86/hvm/svm/nestedsvm.c
>> +++ b/xen/arch/x86/hvm/svm/nestedsvm.c
>> @@ -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 ...
>
>> - 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
On 16.11.2026 13:05, Ross Lagerwall wrote:
> On 11/16/26 11:42 AM, Jan Beulich wrote:
>> On 13.11.2026 18:24, Ross Lagerwall wrote:
>>> 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.
>>>
>>> Fixes: 9a779e4fc161 ("Implement SVM specific part for Nested Virtualization")
>>> Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
>>
>> Acked-by: Jan Beulich <jbeulich@suse.com>
>
> Thanks
>
>>
>>> --- a/xen/arch/x86/hvm/svm/nestedsvm.c
>>> +++ b/xen/arch/x86/hvm/svm/nestedsvm.c
>>> @@ -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 ...
>>
>>> - 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.
So further add "possibly" to what I suggested? (If ns_vmcb->exitinfo2 was always
updated earlier on, the updating here could be avoided.)
Jan
On 11/16/26 12:23 PM, Jan Beulich wrote:
> On 16.11.2026 13:05, Ross Lagerwall wrote:
>> On 11/16/26 11:42 AM, Jan Beulich wrote:
>>> On 13.11.2026 18:24, Ross Lagerwall wrote:
>>>> 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.
>>>>
>>>> Fixes: 9a779e4fc161 ("Implement SVM specific part for Nested Virtualization")
>>>> Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
>>>
>>> Acked-by: Jan Beulich <jbeulich@suse.com>
>>
>> Thanks
>>
>>>
>>>> --- a/xen/arch/x86/hvm/svm/nestedsvm.c
>>>> +++ b/xen/arch/x86/hvm/svm/nestedsvm.c
>>>> @@ -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 ...
>>>
>>>> - 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.
>
> So further add "possibly" to what I suggested? (If ns_vmcb->exitinfo2 was always
> updated earlier on, the updating here could be avoided.)
Yes, I agree with that adjustment.
Ross
© 2016 - 2026 Red Hat, Inc.