Skip to content

Commit 772f254

Browse files
Maxim Levitskysean-jc
authored andcommitted
KVM: SVM: add wrappers to enable/disable IRET interception
SEV-ES guests don't use IRET interception for the detection of an end of a NMI. Therefore it makes sense to create a wrapper to avoid repeating the check for the SEV-ES. No functional change is intended. Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com> [Renamed iret intercept API of style svm_{clr,set}_iret_intercept()] Signed-off-by: Santosh Shukla <Santosh.Shukla@amd.com> Link: https://lore.kernel.org/r/20230227084016.3368-5-santosh.shukla@amd.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 5d1ec45 commit 772f254

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

arch/x86/kvm/svm/svm.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,16 +2490,29 @@ static int task_switch_interception(struct kvm_vcpu *vcpu)
24902490
has_error_code, error_code);
24912491
}
24922492

2493+
static void svm_clr_iret_intercept(struct vcpu_svm *svm)
2494+
{
2495+
if (!sev_es_guest(svm->vcpu.kvm))
2496+
svm_clr_intercept(svm, INTERCEPT_IRET);
2497+
}
2498+
2499+
static void svm_set_iret_intercept(struct vcpu_svm *svm)
2500+
{
2501+
if (!sev_es_guest(svm->vcpu.kvm))
2502+
svm_set_intercept(svm, INTERCEPT_IRET);
2503+
}
2504+
24932505
static int iret_interception(struct kvm_vcpu *vcpu)
24942506
{
24952507
struct vcpu_svm *svm = to_svm(vcpu);
24962508

24972509
++vcpu->stat.nmi_window_exits;
24982510
svm->awaiting_iret_completion = true;
2499-
if (!sev_es_guest(vcpu->kvm)) {
2500-
svm_clr_intercept(svm, INTERCEPT_IRET);
2511+
2512+
svm_clr_iret_intercept(svm);
2513+
if (!sev_es_guest(vcpu->kvm))
25012514
svm->nmi_iret_rip = kvm_rip_read(vcpu);
2502-
}
2515+
25032516
kvm_make_request(KVM_REQ_EVENT, vcpu);
25042517
return 1;
25052518
}
@@ -3508,8 +3521,7 @@ static void svm_inject_nmi(struct kvm_vcpu *vcpu)
35083521
return;
35093522

35103523
svm->nmi_masked = true;
3511-
if (!sev_es_guest(vcpu->kvm))
3512-
svm_set_intercept(svm, INTERCEPT_IRET);
3524+
svm_set_iret_intercept(svm);
35133525
++vcpu->stat.nmi_injections;
35143526
}
35153527

@@ -3649,12 +3661,10 @@ static void svm_set_nmi_mask(struct kvm_vcpu *vcpu, bool masked)
36493661

36503662
if (masked) {
36513663
svm->nmi_masked = true;
3652-
if (!sev_es_guest(vcpu->kvm))
3653-
svm_set_intercept(svm, INTERCEPT_IRET);
3664+
svm_set_iret_intercept(svm);
36543665
} else {
36553666
svm->nmi_masked = false;
3656-
if (!sev_es_guest(vcpu->kvm))
3657-
svm_clr_intercept(svm, INTERCEPT_IRET);
3667+
svm_clr_iret_intercept(svm);
36583668
}
36593669
}
36603670

0 commit comments

Comments
 (0)