kvm: x86: Introduce APICv x86 ops for checking APIC inhibit reasons
authorSuravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Thu, 14 Nov 2019 20:15:10 +0000 (14:15 -0600)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 5 Feb 2020 14:17:42 +0000 (15:17 +0100)
Inibit reason bits are used to determine if APICv deactivation is
applicable for a particular hardware virtualization architecture.

Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/svm.c
arch/x86/kvm/vmx/vmx.c
arch/x86/kvm/x86.c

index 0189687877a7a34f751c58cf9f945602d960a5e4..81c41bfb0a5f17381fb01a0cab5613ebb03bca01 100644 (file)
@@ -1123,6 +1123,7 @@ struct kvm_x86_ops {
        void (*enable_nmi_window)(struct kvm_vcpu *vcpu);
        void (*enable_irq_window)(struct kvm_vcpu *vcpu);
        void (*update_cr8_intercept)(struct kvm_vcpu *vcpu, int tpr, int irr);
+       bool (*check_apicv_inhibit_reasons)(ulong bit);
        void (*refresh_apicv_exec_ctrl)(struct kvm_vcpu *vcpu);
        void (*hwapic_irr_update)(struct kvm_vcpu *vcpu, int max_irr);
        void (*hwapic_isr_update)(struct kvm_vcpu *vcpu, int isr);
index dcea6b663d5c812760df7d477bfbdc6b48761445..842c0630af35c635b1925e562cb02fd7634229ed 100644 (file)
@@ -7298,6 +7298,13 @@ static bool svm_apic_init_signal_blocked(struct kvm_vcpu *vcpu)
                   (svm->vmcb->control.intercept & (1ULL << INTERCEPT_INIT));
 }
 
+static bool svm_check_apicv_inhibit_reasons(ulong bit)
+{
+       ulong supported = BIT(APICV_INHIBIT_REASON_DISABLE);
+
+       return supported & BIT(bit);
+}
+
 static struct kvm_x86_ops svm_x86_ops __ro_after_init = {
        .cpu_has_kvm_support = has_svm,
        .disabled_by_bios = is_disabled,
@@ -7373,6 +7380,7 @@ static struct kvm_x86_ops svm_x86_ops __ro_after_init = {
        .update_cr8_intercept = update_cr8_intercept,
        .set_virtual_apic_mode = svm_set_virtual_apic_mode,
        .refresh_apicv_exec_ctrl = svm_refresh_apicv_exec_ctrl,
+       .check_apicv_inhibit_reasons = svm_check_apicv_inhibit_reasons,
        .load_eoi_exitmap = svm_load_eoi_exitmap,
        .hwapic_irr_update = svm_hwapic_irr_update,
        .hwapic_isr_update = svm_hwapic_isr_update,
index 3e18df4cfb345436c69c70a1930b117520b85bc8..7ba8de3325be772c9a5cb6e6d23487a19707f0af 100644 (file)
@@ -7710,6 +7710,13 @@ static __exit void hardware_unsetup(void)
        free_kvm_area();
 }
 
+static bool vmx_check_apicv_inhibit_reasons(ulong bit)
+{
+       ulong supported = BIT(APICV_INHIBIT_REASON_DISABLE);
+
+       return supported & BIT(bit);
+}
+
 static struct kvm_x86_ops vmx_x86_ops __ro_after_init = {
        .cpu_has_kvm_support = cpu_has_kvm_support,
        .disabled_by_bios = vmx_disabled_by_bios,
@@ -7785,6 +7792,7 @@ static struct kvm_x86_ops vmx_x86_ops __ro_after_init = {
        .refresh_apicv_exec_ctrl = vmx_refresh_apicv_exec_ctrl,
        .load_eoi_exitmap = vmx_load_eoi_exitmap,
        .apicv_post_state_restore = vmx_apicv_post_state_restore,
+       .check_apicv_inhibit_reasons = vmx_check_apicv_inhibit_reasons,
        .hwapic_irr_update = vmx_hwapic_irr_update,
        .hwapic_isr_update = vmx_hwapic_isr_update,
        .guest_apic_has_interrupt = vmx_guest_apic_has_interrupt,
index 3ceb0bc7d3f2f2a6b9c5f688b7e28a4167ccbeb1..dbff8011f0f24c3308934c53ff06df2db58ea169 100644 (file)
@@ -8034,6 +8034,10 @@ EXPORT_SYMBOL_GPL(kvm_vcpu_update_apicv);
  */
 void kvm_request_apicv_update(struct kvm *kvm, bool activate, ulong bit)
 {
+       if (!kvm_x86_ops->check_apicv_inhibit_reasons ||
+           !kvm_x86_ops->check_apicv_inhibit_reasons(bit))
+               return;
+
        if (activate) {
                if (!test_and_clear_bit(bit, &kvm->arch.apicv_inhibit_reasons) ||
                    !kvm_apicv_activated(kvm))