From: David Hildenbrand <david@redhat.com>
To: kvm@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
rkrcmar@redhat.com, david@redhat.com
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 [thread overview]
Message-ID: <20170306131815.12033-3-david@redhat.com> (raw)
In-Reply-To: <20170306131815.12033-1-david@redhat.com>
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 <david@redhat.com>
---
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
next prev parent reply other threads:[~2017-03-06 13:44 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-06 13:17 [PATCH RFC 00/21] pic/ioapic/irqchip cleanups + minor fixes David Hildenbrand
2017-03-06 13:17 ` [PATCH RFC 01/21] KVM: x86: race between KVM_SET_GSI_ROUTING and KVM_CREATE_IRQCHIP David Hildenbrand
2017-03-06 13:17 ` David Hildenbrand [this message]
2017-03-06 18:08 ` [PATCH RFC 02/21] KVM: x86: check against irqchip_mode in kvm_set_routing_entry() Paolo Bonzini
2017-03-07 9:55 ` David Hildenbrand
2017-03-07 10:53 ` Paolo Bonzini
2017-03-07 14:40 ` Radim Krčmář
2017-03-07 15:32 ` David Hildenbrand
2017-03-06 13:17 ` [PATCH RFC 03/21] KVM: x86: check against irqchip_mode in pic_in_kernel() David Hildenbrand
2017-03-06 13:17 ` [PATCH RFC 04/21] KVM: x86: check against irqchip_mode in ioapic_in_kernel() David Hildenbrand
2017-03-06 13:17 ` [PATCH RFC 05/21] KVM: x86: get rid of pic_irqchip() David Hildenbrand
2017-03-06 13:18 ` [PATCH RFC 06/21] KVM: x86: get rid of ioapic_irqchip() David Hildenbrand
2017-03-06 13:18 ` [PATCH RFC 07/21] KVM: x86: use ioapic_in_kernel() to check for ioapic existence David Hildenbrand
2017-03-06 13:18 ` [PATCH RFC 08/21] KVM: x86: remove duplicate checks for ioapic David Hildenbrand
2017-03-06 13:18 ` [PATCH RFC 09/21] KVM: x86: convert kvm_(set|get)_ioapic() into void David Hildenbrand
2017-03-06 13:18 ` [PATCH RFC 10/21] KVM: x86: don't take kvm->irq_lock when creating IRQCHIP David Hildenbrand
2017-03-06 13:18 ` [PATCH RFC 11/21] KVM: x86: push usage of slots_lock down David Hildenbrand
2017-03-06 13:18 ` [PATCH RFC 12/21] KVM: x86: KVM_IRQCHIP_PIC_MASTER only has 8 pins David Hildenbrand
2017-03-06 13:18 ` [PATCH RFC 13/21] KVM: x86: remove all-vcpu request from kvm_ioapic_init() David Hildenbrand
2017-03-06 13:18 ` [PATCH RFC 14/21] KVM: x86: directly call kvm_make_scan_ioapic_request() in ioapic.c David Hildenbrand
2017-03-06 13:18 ` [PATCH RFC 15/21] KVM: x86: rename kvm_vcpu_request_scan_ioapic() David Hildenbrand
2017-03-06 13:18 ` [PATCH RFC 16/21] KVM: x86: drop goto label in kvm_set_routing_entry() David Hildenbrand
2017-03-06 13:18 ` [PATCH RFC 17/21] KVM: x86: simplify pic_unlock() David Hildenbrand
2017-03-06 13:18 ` [PATCH RFC 18/21] KVM: x86: make kvm_pic_reset() static David Hildenbrand
2017-03-06 13:18 ` [PATCH RFC 19/21] KVM: x86: drop picdev_in_range() David Hildenbrand
2017-03-06 13:18 ` [PATCH RFC 20/21] KVM: x86: set data directly in picdev_read() David Hildenbrand
2017-03-06 13:18 ` [PATCH RFC 21/21] KVM: x86: simplify pic_ioport_read() David Hildenbrand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170306131815.12033-3-david@redhat.com \
--to=david@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.