From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Hildenbrand Subject: [PATCH RFC 02/21] KVM: x86: check against irqchip_mode in kvm_set_routing_entry() Date: Mon, 6 Mar 2017 14:17:56 +0100 Message-ID: <20170306131815.12033-3-david@redhat.com> References: <20170306131815.12033-1-david@redhat.com> Cc: Paolo Bonzini , rkrcmar@redhat.com, david@redhat.com To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:44462 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753603AbdCFNon (ORCPT ); Mon, 6 Mar 2017 08:44:43 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F37EDC05683F for ; Mon, 6 Mar 2017 13:18:21 +0000 (UTC) In-Reply-To: <20170306131815.12033-1-david@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Let's replace the checks for pic_in_kernel() and ioapic_in_kernel() by checks against irqchip_mode. Add another state, indicating that the caller is currently initializing the irqchip. This is necessary to switch pic_in_kernel() and ioapic_in_kernel() to irqchip_mode, too. Signed-off-by: David Hildenbrand --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/irq.h | 8 +++++++- arch/x86/kvm/irq_comm.c | 8 ++------ arch/x86/kvm/x86.c | 2 ++ 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 74ef58c..c8cdcc3 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -727,6 +727,7 @@ struct kvm_hv { enum kvm_irqchip_mode { KVM_IRQCHIP_NONE, + KVM_IRQCHIP_KERNEL_INIT, /* KVM_CREATE_IRQCHIP in progress */ KVM_IRQCHIP_KERNEL, /* created with KVM_CREATE_IRQCHIP */ KVM_IRQCHIP_SPLIT, /* created with KVM_CAP_SPLIT_IRQCHIP */ }; diff --git a/arch/x86/kvm/irq.h b/arch/x86/kvm/irq.h index 40d5b2c..9ebb6f5 100644 --- a/arch/x86/kvm/irq.h +++ b/arch/x86/kvm/irq.h @@ -96,6 +96,11 @@ static inline int irqchip_split(struct kvm *kvm) return kvm->arch.irqchip_mode == KVM_IRQCHIP_SPLIT; } +static inline int irqchip_kernel_init(struct kvm *kvm) +{ + return kvm->arch.irqchip_mode == KVM_IRQCHIP_KERNEL_INIT; +} + static inline int irqchip_kernel(struct kvm *kvm) { return kvm->arch.irqchip_mode == KVM_IRQCHIP_KERNEL; @@ -103,7 +108,8 @@ static inline int irqchip_kernel(struct kvm *kvm) static inline int irqchip_in_kernel(struct kvm *kvm) { - bool ret = kvm->arch.irqchip_mode != KVM_IRQCHIP_NONE; + bool ret = kvm->arch.irqchip_mode == KVM_IRQCHIP_KERNEL || + kvm->arch.irqchip_mode == KVM_IRQCHIP_SPLIT; /* Matches with wmb after initializing kvm->irq_routing. */ smp_rmb(); diff --git a/arch/x86/kvm/irq_comm.c b/arch/x86/kvm/irq_comm.c index b96d389..4e4a67a 100644 --- a/arch/x86/kvm/irq_comm.c +++ b/arch/x86/kvm/irq_comm.c @@ -282,22 +282,18 @@ int kvm_set_routing_entry(struct kvm *kvm, switch (ue->type) { case KVM_IRQ_ROUTING_IRQCHIP: + if (!irqchip_kernel(kvm) && !irqchip_kernel_init(kvm)) + goto out; delta = 0; switch (ue->u.irqchip.irqchip) { case KVM_IRQCHIP_PIC_SLAVE: delta = 8; /* fall through */ case KVM_IRQCHIP_PIC_MASTER: - if (!pic_in_kernel(kvm)) - goto out; - e->set = kvm_set_pic_irq; max_pin = PIC_NUM_PINS; break; case KVM_IRQCHIP_IOAPIC: - if (!ioapic_in_kernel(kvm)) - goto out; - max_pin = KVM_IOAPIC_NUM_PINS; e->set = kvm_set_ioapic_irq; break; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index b2a4b11..c69940c 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4022,8 +4022,10 @@ long kvm_arch_vm_ioctl(struct file *filp, goto create_irqchip_unlock; } + kvm->arch.irqchip_mode = KVM_IRQCHIP_KERNEL_INIT; r = kvm_setup_default_irq_routing(kvm); if (r) { + kvm->arch.irqchip_mode = KVM_IRQCHIP_NONE; mutex_lock(&kvm->slots_lock); mutex_lock(&kvm->irq_lock); kvm_ioapic_destroy(kvm); -- 2.9.3