Skip to content

Commit 3bbf356

Browse files
ssuthiku-amdbonzini
authored andcommitted
svm: Do not intercept CR8 when enable AVIC
When enable AVIC: * Do not intercept CR8 since this should be handled by AVIC HW. * Also, we don't need to sync cr8/V_TPR and APIC backing page. Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> [Rename svm_in_nested_interrupt_shadow to svm_nested_virtualize_tpr. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 46781ea commit 3bbf356

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

arch/x86/kvm/svm.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,8 @@ static void init_vmcb(struct vcpu_svm *svm)
10921092
set_cr_intercept(svm, INTERCEPT_CR0_WRITE);
10931093
set_cr_intercept(svm, INTERCEPT_CR3_WRITE);
10941094
set_cr_intercept(svm, INTERCEPT_CR4_WRITE);
1095-
set_cr_intercept(svm, INTERCEPT_CR8_WRITE);
1095+
if (!kvm_vcpu_apicv_active(&svm->vcpu))
1096+
set_cr_intercept(svm, INTERCEPT_CR8_WRITE);
10961097

10971098
set_dr_intercepts(svm);
10981099

@@ -4078,11 +4079,17 @@ static void svm_set_irq(struct kvm_vcpu *vcpu)
40784079
SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_INTR;
40794080
}
40804081

4082+
static inline bool svm_nested_virtualize_tpr(struct kvm_vcpu *vcpu)
4083+
{
4084+
return is_guest_mode(vcpu) && (vcpu->arch.hflags & HF_VINTR_MASK);
4085+
}
4086+
40814087
static void update_cr8_intercept(struct kvm_vcpu *vcpu, int tpr, int irr)
40824088
{
40834089
struct vcpu_svm *svm = to_svm(vcpu);
40844090

4085-
if (is_guest_mode(vcpu) && (vcpu->arch.hflags & HF_VINTR_MASK))
4091+
if (svm_nested_virtualize_tpr(vcpu) ||
4092+
kvm_vcpu_apicv_active(vcpu))
40864093
return;
40874094

40884095
clr_cr_intercept(svm, INTERCEPT_CR8_WRITE);
@@ -4255,7 +4262,7 @@ static inline void sync_cr8_to_lapic(struct kvm_vcpu *vcpu)
42554262
{
42564263
struct vcpu_svm *svm = to_svm(vcpu);
42574264

4258-
if (is_guest_mode(vcpu) && (vcpu->arch.hflags & HF_VINTR_MASK))
4265+
if (svm_nested_virtualize_tpr(vcpu))
42594266
return;
42604267

42614268
if (!is_cr_intercept(svm, INTERCEPT_CR8_WRITE)) {
@@ -4269,7 +4276,8 @@ static inline void sync_lapic_to_cr8(struct kvm_vcpu *vcpu)
42694276
struct vcpu_svm *svm = to_svm(vcpu);
42704277
u64 cr8;
42714278

4272-
if (is_guest_mode(vcpu) && (vcpu->arch.hflags & HF_VINTR_MASK))
4279+
if (svm_nested_virtualize_tpr(vcpu) ||
4280+
kvm_vcpu_apicv_active(vcpu))
42734281
return;
42744282

42754283
cr8 = kvm_get_cr8(vcpu);

0 commit comments

Comments
 (0)