Skip to content

Commit cae72dc

Browse files
Maxim Levitskybonzini
authored andcommitted
KVM: x86: inhibit APICv when KVM_GUESTDBG_BLOCKIRQ active
KVM_GUESTDBG_BLOCKIRQ relies on interrupts being injected using standard kvm's inject_pending_event, and not via APICv/AVIC. Since this is a debug feature, just inhibit APICv/AVIC while KVM_GUESTDBG_BLOCKIRQ is in use on at least one vCPU. Fixes: 61e5f69 ("KVM: x86: implement KVM_GUESTDBG_BLOCKIRQ") Reported-by: Vitaly Kuznetsov <[email protected]> Signed-off-by: Maxim Levitsky <[email protected]> Reviewed-by: Sean Christopherson <[email protected]> Tested-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent e6cd31f commit cae72dc

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,7 @@ struct kvm_x86_msr_filter {
10341034
#define APICV_INHIBIT_REASON_IRQWIN 3
10351035
#define APICV_INHIBIT_REASON_PIT_REINJ 4
10361036
#define APICV_INHIBIT_REASON_X2APIC 5
1037+
#define APICV_INHIBIT_REASON_BLOCKIRQ 6
10371038

10381039
struct kvm_arch {
10391040
unsigned long n_used_mmu_pages;

arch/x86/kvm/svm/avic.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,8 @@ bool svm_check_apicv_inhibit_reasons(ulong bit)
904904
BIT(APICV_INHIBIT_REASON_NESTED) |
905905
BIT(APICV_INHIBIT_REASON_IRQWIN) |
906906
BIT(APICV_INHIBIT_REASON_PIT_REINJ) |
907-
BIT(APICV_INHIBIT_REASON_X2APIC);
907+
BIT(APICV_INHIBIT_REASON_X2APIC) |
908+
BIT(APICV_INHIBIT_REASON_BLOCKIRQ);
908909

909910
return supported & BIT(bit);
910911
}

arch/x86/kvm/vmx/vmx.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7565,7 +7565,8 @@ static void hardware_unsetup(void)
75657565
static bool vmx_check_apicv_inhibit_reasons(ulong bit)
75667566
{
75677567
ulong supported = BIT(APICV_INHIBIT_REASON_DISABLE) |
7568-
BIT(APICV_INHIBIT_REASON_HYPERV);
7568+
BIT(APICV_INHIBIT_REASON_HYPERV) |
7569+
BIT(APICV_INHIBIT_REASON_BLOCKIRQ);
75697570

75707571
return supported & BIT(bit);
75717572
}

arch/x86/kvm/x86.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10753,6 +10753,24 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
1075310753
return ret;
1075410754
}
1075510755

10756+
static void kvm_arch_vcpu_guestdbg_update_apicv_inhibit(struct kvm *kvm)
10757+
{
10758+
bool inhibit = false;
10759+
struct kvm_vcpu *vcpu;
10760+
int i;
10761+
10762+
down_write(&kvm->arch.apicv_update_lock);
10763+
10764+
kvm_for_each_vcpu(i, vcpu, kvm) {
10765+
if (vcpu->guest_debug & KVM_GUESTDBG_BLOCKIRQ) {
10766+
inhibit = true;
10767+
break;
10768+
}
10769+
}
10770+
__kvm_request_apicv_update(kvm, !inhibit, APICV_INHIBIT_REASON_BLOCKIRQ);
10771+
up_write(&kvm->arch.apicv_update_lock);
10772+
}
10773+
1075610774
int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
1075710775
struct kvm_guest_debug *dbg)
1075810776
{
@@ -10805,6 +10823,8 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
1080510823

1080610824
static_call(kvm_x86_update_exception_bitmap)(vcpu);
1080710825

10826+
kvm_arch_vcpu_guestdbg_update_apicv_inhibit(vcpu->kvm);
10827+
1080810828
r = 0;
1080910829

1081010830
out:

0 commit comments

Comments
 (0)