Re: [PATCH 5/7] KVM: SVM: Support FRED nested exception injection
From: Sean Christopherson
Date: Fri Mar 06 2026 - 21:08:01 EST
On Thu, Jan 29, 2026, Shivansh Dhiman wrote:
> From: Neeraj Upadhyay <Neeraj.Upadhyay@xxxxxxx>
>
> Set the SVM nested exception bit in EVENT_INJECTION_CTL 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 FRED_RSP1
> MSR when encountered in ring 3 and ring 0.
> - normal #PF will be delivered on the stack pointed by FRED_RSP0
> MSR when encountered in ring 3.
>
> The SVM nested-exception support ensures a correct event stack level is
> chosen when a VM entry injects a nested exception.
>
> Signed-off-by: Neeraj Upadhyay <Neeraj.Upadhyay@xxxxxxx>
> Co-developed-by: Shivansh Dhiman <shivansh.dhiman@xxxxxxx>
> Signed-off-by: Shivansh Dhiman <shivansh.dhiman@xxxxxxx>
> Reviewed-by: Nikunj A Dadhania <nikunj@xxxxxxx>
> ---
> arch/x86/include/asm/svm.h | 1 +
> arch/x86/kvm/svm/svm.c | 5 ++++-
> 2 files changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h
> index c2f3e03e1f4b..f4a9781c1d6c 100644
> --- a/arch/x86/include/asm/svm.h
> +++ b/arch/x86/include/asm/svm.h
> @@ -657,6 +657,7 @@ static inline void __unused_size_checks(void)
>
> #define SVM_EVTINJ_VALID (1 << 31)
> #define SVM_EVTINJ_VALID_ERR (1 << 11)
> +#define SVM_EVTINJ_NESTED_EXCEPTION (1 << 13)
>
> #define SVM_EXITINTINFO_VEC_MASK SVM_EVTINJ_VEC_MASK
> #define SVM_EXITINTINFO_TYPE_MASK SVM_EVTINJ_TYPE_MASK
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index 693b46d715b4..374589784206 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -363,6 +363,7 @@ static void svm_inject_exception(struct kvm_vcpu *vcpu)
> {
> struct kvm_queued_exception *ex = &vcpu->arch.exception;
> struct vcpu_svm *svm = to_svm(vcpu);
> + bool nested = is_fred_enabled(vcpu) && ex->nested;
Reverse fir-tree please (swap this with the line above it). Similar to my comment
on the VMX series, us is_nested to avoid shadowing the global nested.