Re: [PATCH v10 13/28] KVM: VMX: Virtualize FRED nested exception tracking

From: Binbin Wu

Date: Thu Oct 29 2026 - 04:45:45 EST


On 9/12/2026 5:36 AM, Sohil Mehta wrote:
> From: "Xin Li (Intel)" <xin@xxxxxxxxx>
>
> Set the VMX nested exception bit in VM-entry interruption information
> field when injecting a nested exception using FRED event delivery to
> ensure:
> 1) A nested exception is injected on a correct stack level.
> 2) The nested bit defined in FRED stack frame is set.
>
> The event stack level used by FRED event delivery depends on whether
> the event was a nested exception encountered during delivery of an
> earlier event, because a nested exception is "regarded" as happening
> on ring 0. E.g., when #PF is configured to use stack level 1 in
> IA32_FRED_STKLVLS MSR:
> - nested #PF will be delivered on the stack pointed by IA32_FRED_RSP1
> MSR when encountered in ring 3 and ring 0.
> - normal #PF will be delivered on the stack pointed by IA32_FRED_RSP0
> MSR when encountered in ring 3.
>
> The VMX nested-exception support ensures a correct event stack level is
> chosen when a VM entry injects a nested exception.
>
> In addition, save/restore the nested flag of an exception during VM
> save/restore and live migration to ensure a correct event stack level
> is chosen when a nested exception is injected through FRED event
> delivery across VM save/restore and live migration.
>
> Note, like the other fields of struct kvm_queued_exception, the nested
> flag is meaningful only while the exception is pending or injected. It
> is not consulted otherwise, and so doesn't need to be cleared when an
> exception is dropped.

Just try to understand the sentence.
The patch clears is_nested alongside pending/injected in two places:
1. kvm_clear_exception_queue()
2. When the exception from userspace is converted to a nested vm exit.

So are they needed?

>
> Signed-off-by: Xin Li (Intel) <xin@xxxxxxxxx>
> [ Sean: reworked kvm_requeue_exception() to simply the code changes ]
^
simplify

> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> Signed-off-by: Sohil Mehta <sohil.mehta@xxxxxxxxx>
> Reviewed-by: Chao Gao <chao.gao@xxxxxxxxx>

[...]

> @@ -8978,6 +8993,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
> ex->has_payload, ex->payload);
> ex->injected = false;
> ex->pending = false;
> + ex->is_nested = false;
> }
> vcpu->arch.exception_from_userspace = false;
>
> diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
> index 0f5919b092e4..2d6bae66cfae 100644
> --- a/arch/x86/kvm/x86.h
> +++ b/arch/x86/kvm/x86.h
> @@ -158,6 +158,7 @@ static inline void kvm_clear_exception_queue(struct kvm_vcpu *vcpu)
> {
> vcpu->arch.exception.pending = false;
> vcpu->arch.exception.injected = false;
> + vcpu->arch.exception.is_nested = false;
> vcpu->arch.exception_vmexit.pending = false;
> }