From: Neeraj Upadhyay <Neeraj.Upadhyay@amd.com>
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@amd.com>
Co-developed-by: Shivansh Dhiman <shivansh.dhiman@amd.com>
Signed-off-by: Shivansh Dhiman <shivansh.dhiman@amd.com>
Reviewed-by: Nikunj A Dadhania <nikunj@amd.com>
---
Changes in v2:
- Replace variable 'nested' with 'is_nested' (Sean Christopherson).
- Formatted variables in reverse fir-tree order (Sean Christopherson).
---
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 a42ed39aa8fb..c0f6523e2b2d 100644
--- a/arch/x86/include/asm/svm.h
+++ b/arch/x86/include/asm/svm.h
@@ -656,6 +656,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 2da493f9dd8b..39d1177a24f0 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -362,6 +362,7 @@ static int svm_update_soft_interrupt_rip(struct kvm_vcpu *vcpu)
static void svm_inject_exception(struct kvm_vcpu *vcpu)
{
struct kvm_queued_exception *ex = &vcpu->arch.exception;
+ bool is_nested = is_fred_enabled(vcpu) && ex->nested;
struct vcpu_svm *svm = to_svm(vcpu);
kvm_deliver_exception_payload(vcpu, ex);
@@ -373,6 +374,7 @@ static void svm_inject_exception(struct kvm_vcpu *vcpu)
svm->vmcb->control.event_inj = ex->vector
| SVM_EVTINJ_VALID
| (ex->has_error_code ? SVM_EVTINJ_VALID_ERR : 0)
+ | (is_nested ? SVM_EVTINJ_NESTED_EXCEPTION : 0)
| SVM_EVTINJ_TYPE_EXEPT;
if (is_fred_enabled(vcpu))
@@ -4158,7 +4160,8 @@ static void svm_complete_interrupts(struct kvm_vcpu *vcpu)
kvm_requeue_exception(vcpu, vector,
exitintinfo & SVM_EXITINTINFO_VALID_ERR,
- error_code, false, event_data);
+ error_code, exitintinfo & SVM_EVTINJ_NESTED_EXCEPTION,
+ event_data);
break;
}
case SVM_EXITINTINFO_TYPE_INTR:
--
2.43.0