Skip to contentSkip to conversation

split out uses of kvm_irqchip_in_kernel()

PATCH In review Peter Maydell 3 participants 13 messages Jul 26, 2012 – Aug 9, 2012 KVM

lore
Share & tools
lore
#0 lore raw

v2 cover split out uses of kvm_irqchip_in_kernel()

This patch series removes all uses of kvm_irqchip_in_kernel() from architecture-independent code, by creating a set of more specific functions instead to test for the particular aspects of behaviour that the calling code is actually interested in.

The uses in x86-specific code could in theory be further broken down into kvm_ioapic(), kvm_pit(), etc, but I leave that for one of the x86 maintainers if they think it's worthwhile.

Changes v1->v2:
* more blank lines round kvm.h doc comments / macros
* 1: fn name changed to: kvm_async_interrupts_enabled() (and corresponding bool is now kvm_async_interrupts_allowed, so we are consistent about the enabled/allowed convention)
* 2: fn name changed to: kvm_set_irq()
* 3: fix return type of kvm_allows_irq0_override() to bool
* 5 (and new patch 6): split out separate kvm_gsi_routing_enabled() check for use in kvm_irqchip_add_msi_route()

Peter Maydell (7):
kvm: Decouple 'async interrupt delivery' from 'kernel irqchip'
kvm: Rename kvm_irqchip_set_irq() to kvm_set_irq()
kvm: Move kvm_allows_irq0_override() to target-i386, fix return type
kvm: Decouple 'irqfds usable' from 'kernel irqchip'
kvm: Decouple 'MSI routing via irqfds' from 'kernel irqchip'
kvm: Decouple 'GSI routing' from 'kernel irqchip'
kvm: Add documentation comment for kvm_irqchip_in_kernel()

 cpus.c                    |    3 +-
 hw/kvm/i8259.c            |    2 +-
 hw/kvm/ioapic.c           |    2 +-
 hw/pc.c                   |    1 +
 hw/virtio-pci.c           |    4 +-
 kvm-all.c                 |   25 ++++++++++--------
 kvm-stub.c                |    9 +++---
 kvm.h                     |   60 ++++++++++++++++++++++++++++++++++++++++++--
 target-i386/Makefile.objs |    1 +
 target-i386/kvm-stub.c    |   18 +++++++++++++
 target-i386/kvm.c         |   13 +++++++++
 target-i386/kvm_i386.h    |   16 ++++++++++++
 12 files changed, 130 insertions(+), 24 deletions(-)
 create mode 100644 target-i386/kvm-stub.c
 create mode 100644 target-i386/kvm_i386.h
Signature · 1 line
1.7.5.4
#1 lore raw

PATCH v2 1/7 kvm: Decouple 'async interrupt delivery' from 'kernel irqchip'

On x86 userspace delivers interrupts to the kernel asynchronously (and therefore VCPU idle management is done in the kernel) if and only if there is an in-kernel irqchip. On other architectures this isn't necessarily true (they may always send interrupts asynchronously), so define a new kvm_async_interrupts_enabled() function instead of misusing kvm_irqchip_in_kernel().

---
 cpus.c     |    3 ++-
 kvm-all.c  |    7 ++++++-
 kvm-stub.c |    1 +
 kvm.h      |   13 +++++++++++++
 4 files changed, 22 insertions(+), 2 deletions(-)
cpus.c +2 -1
index 756e624..8c54dd0 100644
@@ -69,7 +69,8 @@ static bool cpu_thread_is_idle(CPUArchState *env)
     if (env->stopped || !runstate_is_running()) {
         return true;
     }
-    if (!env->halted || qemu_cpu_has_work(env) || kvm_irqchip_in_kernel()) {
+    if (!env->halted || qemu_cpu_has_work(env) ||
+        kvm_async_interrupts_enabled()) {
         return false;
     }
     return true;
kvm-all.c +6 -1
index 2148b20..0a38ba1 100644
@@ -100,6 +100,7 @@ struct KVMState
 
 KVMState *kvm_state;
 bool kvm_kernel_irqchip;
+bool kvm_async_interrupts_allowed;
 
 static const KVMCapabilityInfo kvm_required_capabilites[] = {
     KVM_CAP_INFO(USER_MEMORY),
@@ -857,7 +858,7 @@ int kvm_irqchip_set_irq(KVMState *s, int irq, int level)
     struct kvm_irq_level event;
     int ret;
 
-    assert(kvm_irqchip_in_kernel());
+    assert(kvm_async_interrupts_enabled());
 
     event.level = level;
     event.irq = irq;
@@ -1201,6 +1202,10 @@ static int kvm_irqchip_create(KVMState *s)
         s->irqchip_inject_ioctl = KVM_IRQ_LINE_STATUS;
     }
     kvm_kernel_irqchip = true;
+    /* If we have an in-kernel IRQ chip then we must have asynchronous
+     * interrupt delivery (though the reverse is not necessarily true)
+     */
+    kvm_async_interrupts_allowed = true;
 
     kvm_init_irq_routing(s);
 
kvm-stub.c +1 -0
index d23b11c..a7a03e1 100644
@@ -19,6 +19,7 @@
 
 KVMState *kvm_state;
 bool kvm_kernel_irqchip;
+bool kvm_async_interrupts_allowed;
 
 int kvm_init_vcpu(CPUArchState *env)
 {
kvm.h +13 -0
index 2617dd5..09818f3 100644
@@ -24,13 +24,26 @@
 
 extern int kvm_allowed;
 extern bool kvm_kernel_irqchip;
+extern bool kvm_async_interrupts_allowed;
 
 #if defined CONFIG_KVM || !defined NEED_CPU_H
 #define kvm_enabled()           (kvm_allowed)
 #define kvm_irqchip_in_kernel() (kvm_kernel_irqchip)
+
+/**
+ * kvm_async_interrupts_enabled:
+ *
+ * Returns: true if we can deliver interrupts to KVM
+ * asynchronously (ie by ioctl from any thread at any time)
+ * rather than having to do interrupt delivery synchronously
+ * (where the vcpu must be stopped at a suitable point first).
+ */
+#define kvm_async_interrupts_enabled() (kvm_async_interrupts_allowed)
+
 #else
 #define kvm_enabled()           (0)
 #define kvm_irqchip_in_kernel() (false)
+#define kvm_async_interrupts_enabled() (false)
 #endif
 
 struct kvm_run;
Signature · 1 line
1.7.5.4
#2 lore raw

PATCH v2 2/7 kvm: Rename kvm_irqchip_set_irq() to kvm_set_irq()

In reply to Peter Maydell

Rename the function kvm_irqchip_set_irq() to kvm_set_irq(), since it can be used for sending (asynchronous) interrupts whether there is a full irqchip model in the kernel or not. (We don't include 'async' in the function name since asynchronous is the normal case.)

---
 hw/kvm/i8259.c  |    2 +-
 hw/kvm/ioapic.c |    2 +-
 kvm-all.c       |    6 +++---
 kvm.h           |    2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)
hw/kvm/i8259.c +1 -1
index 94d1b9a..1e24cd4 100644
@@ -94,7 +94,7 @@ static void kvm_pic_set_irq(void *opaque, int irq, int level)
 {
     int delivered;
 
-    delivered = kvm_irqchip_set_irq(kvm_state, irq, level);
+    delivered = kvm_set_irq(kvm_state, irq, level);
     apic_report_irq_delivered(delivered);
 }
 
hw/kvm/ioapic.c +1 -1
index 3ae3175..6c3b8fe 100644
@@ -82,7 +82,7 @@ static void kvm_ioapic_set_irq(void *opaque, int irq, int level)
     KVMIOAPICState *s = opaque;
     int delivered;
 
-    delivered = kvm_irqchip_set_irq(kvm_state, s->kvm_gsi_base + irq, level);
+    delivered = kvm_set_irq(kvm_state, s->kvm_gsi_base + irq, level);
     apic_report_irq_delivered(delivered);
 }
 
kvm-all.c +3 -3
index 0a38ba1..7c635be 100644
@@ -853,7 +853,7 @@ static void kvm_handle_interrupt(CPUArchState *env, int mask)
     }
 }
 
-int kvm_irqchip_set_irq(KVMState *s, int irq, int level)
+int kvm_set_irq(KVMState *s, int irq, int level)
 {
     struct kvm_irq_level event;
     int ret;
@@ -864,7 +864,7 @@ int kvm_irqchip_set_irq(KVMState *s, int irq, int level)
     event.irq = irq;
     ret = kvm_vm_ioctl(s, s->irqchip_inject_ioctl, &event);
     if (ret < 0) {
-        perror("kvm_set_irqchip_line");
+        perror("kvm_set_irq");
         abort();
     }
 
@@ -1089,7 +1089,7 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg)
 
     assert(route->kroute.type == KVM_IRQ_ROUTING_MSI);
 
-    return kvm_irqchip_set_irq(s, route->kroute.gsi, 1);
+    return kvm_set_irq(s, route->kroute.gsi, 1);
 }
 
 int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg)
kvm.h +1 -1
index 09818f3..744209d 100644
@@ -146,7 +146,7 @@ int kvm_arch_on_sigbus(int code, void *addr);
 
 void kvm_arch_init_irq_routing(KVMState *s);
 
-int kvm_irqchip_set_irq(KVMState *s, int irq, int level);
+int kvm_set_irq(KVMState *s, int irq, int level);
 int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg);
 
 void kvm_irqchip_add_irq_route(KVMState *s, int gsi, int irqchip, int pin);
Signature · 1 line
1.7.5.4
#3 lore raw

PATCH v2 3/7 kvm: Move kvm_allows_irq0_override() to target-i386, fix return type

In reply to Peter Maydell

kvm_allows_irq0_override() is a totally x86 specific concept:
move it to the target-specific source file where it belongs. This means we need a new header file for the prototype:
kvm_i386.h, in line with the existing kvm_ppc.h.

While we are moving it, fix the return type to be 'bool' rather than 'int'.

---
 hw/pc.c                   |    1 +
 kvm-all.c                 |    5 -----
 kvm-stub.c                |    5 -----
 kvm.h                     |    2 --
 target-i386/Makefile.objs |    1 +
 target-i386/kvm-stub.c    |   18 ++++++++++++++++++
 target-i386/kvm.c         |    6 ++++++
 target-i386/kvm_i386.h    |   16 ++++++++++++++++
 8 files changed, 42 insertions(+), 12 deletions(-)
 create mode 100644 target-i386/kvm-stub.c
 create mode 100644 target-i386/kvm_i386.h
hw/pc.c +1 -0
index 598267a..4953376 100644
@@ -42,6 +42,7 @@
 #include "sysbus.h"
 #include "sysemu.h"
 #include "kvm.h"
+#include "kvm_i386.h"
 #include "xen.h"
 #include "blockdev.h"
 #include "hw/block-common.h"
kvm-all.c +0 -5
index 7c635be..9a34090 100644
@@ -1672,11 +1672,6 @@ int kvm_has_gsi_routing(void)
 #endif
 }
 
-int kvm_allows_irq0_override(void)
-{
-    return !kvm_irqchip_in_kernel() || kvm_has_gsi_routing();
-}
-
 void *kvm_vmalloc(ram_addr_t size)
 {
 #ifdef TARGET_S390X
kvm-stub.c +0 -5
index a7a03e1..f2b0c61 100644
@@ -72,11 +72,6 @@ int kvm_has_many_ioeventfds(void)
     return 0;
 }
 
-int kvm_allows_irq0_override(void)
-{
-    return 1;
-}
-
 int kvm_has_pit_state2(void)
 {
     return 0;
kvm.h +0 -2
index 744209d..47bf5ba 100644
@@ -75,8 +75,6 @@ int kvm_has_pit_state2(void);
 int kvm_has_many_ioeventfds(void);
 int kvm_has_gsi_routing(void);
 
-int kvm_allows_irq0_override(void);
-
 #ifdef NEED_CPU_H
 int kvm_init_vcpu(CPUArchState *env);
 
target-i386/Makefile.objs +1 -0
index 683fd59..0715f58 100644
@@ -3,6 +3,7 @@ obj-y += excp_helper.o fpu_helper.o cc_helper.o int_helper.o svm_helper.o
 obj-y += smm_helper.o misc_helper.o mem_helper.o seg_helper.o
 obj-$(CONFIG_SOFTMMU) += machine.o arch_memory_mapping.o arch_dump.o
 obj-$(CONFIG_KVM) += kvm.o hyperv.o
+obj-$(CONFIG_NO_KVM) += kvm-stub.o
 obj-$(CONFIG_LINUX_USER) += ioport-user.o
 obj-$(CONFIG_BSD_USER) += ioport-user.o
 
target-i386/kvm-stub.c new file +18 -0
new file mode 100644
index 0000000..11429c4
@@ -0,0 +1,18 @@
+/*
+ * QEMU KVM x86 specific function stubs
+ *
+ * Copyright Linaro Limited 2012
+ *
+ * Author: Peter Maydell <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+#include "qemu-common.h"
+#include "kvm_i386.h"
+
+bool kvm_allows_irq0_override(void)
+{
+    return 1;
+}
target-i386/kvm.c +6 -0
index e53c2f6..7e5f51e 100644
@@ -23,6 +23,7 @@
 #include "qemu-common.h"
 #include "sysemu.h"
 #include "kvm.h"
+#include "kvm_i386.h"
 #include "cpu.h"
 #include "gdbstub.h"
 #include "host-utils.h"
@@ -65,6 +66,11 @@ static bool has_msr_async_pf_en;
 static bool has_msr_misc_enable;
 static int lm_capable_kernel;
 
+bool kvm_allows_irq0_override(void)
+{
+    return !kvm_irqchip_in_kernel() || kvm_has_gsi_routing();
+}
+
 static struct kvm_cpuid2 *try_get_cpuid(KVMState *s, int max)
 {
     struct kvm_cpuid2 *cpuid;
target-i386/kvm_i386.h new file +16 -0
new file mode 100644
index 0000000..b82bbf4
@@ -0,0 +1,16 @@
+/*
+ * QEMU KVM support -- x86 specific functions.
+ *
+ * Copyright (c) 2012 Linaro Limited
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef QEMU_KVM_I386_H
+#define QEMU_KVM_I386_H
+
+bool kvm_allows_irq0_override(void);
+
+#endif
Signature · 1 line
1.7.5.4
#4 lore raw

PATCH v2 4/7 kvm: Decouple 'irqfds usable' from 'kernel irqchip'

In reply to Peter Maydell

Instead of assuming that we can use irqfds if and only if kvm_irqchip_in_kernel(), add a bool to the KVMState which indicates this, and is set only on x86 and only if the irqchip is in the kernel.

The kernel documentation implies that the only thing you need to use KVM_IRQFD is that KVM_CAP_IRQFD is advertised, but this seems to be untrue. In particular the kernel does not (alas) return a sensible error if you try to set up an irqfd when you haven't created an irqchip. If it did we could remove all this nonsense and let the kernel return the error code.

---
 kvm-all.c         |    3 ++-
 kvm-stub.c        |    1 +
 kvm.h             |   11 +++++++++++
 target-i386/kvm.c |    4 ++++
 4 files changed, 18 insertions(+), 1 deletions(-)
kvm-all.c +2 -1
index 9a34090..3a69e53 100644
@@ -101,6 +101,7 @@ struct KVMState
 KVMState *kvm_state;
 bool kvm_kernel_irqchip;
 bool kvm_async_interrupts_allowed;
+bool kvm_irqfds_allowed;
 
 static const KVMCapabilityInfo kvm_required_capabilites[] = {
     KVM_CAP_INFO(USER_MEMORY),
@@ -1126,7 +1127,7 @@ static int kvm_irqchip_assign_irqfd(KVMState *s, int fd, int virq, bool assign)
         .flags = assign ? 0 : KVM_IRQFD_FLAG_DEASSIGN,
     };
 
-    if (!kvm_irqchip_in_kernel()) {
+    if (!kvm_irqfds_enabled()) {
         return -ENOSYS;
     }
 
kvm-stub.c +1 -0
index f2b0c61..02e7fe0 100644
@@ -20,6 +20,7 @@
 KVMState *kvm_state;
 bool kvm_kernel_irqchip;
 bool kvm_async_interrupts_allowed;
+bool kvm_irqfds_allowed;
 
 int kvm_init_vcpu(CPUArchState *env)
 {
kvm.h +11 -0
index 47bf5ba..21436ef 100644
@@ -25,6 +25,7 @@
 extern int kvm_allowed;
 extern bool kvm_kernel_irqchip;
 extern bool kvm_async_interrupts_allowed;
+extern bool kvm_irqfds_allowed;
 
 #if defined CONFIG_KVM || !defined NEED_CPU_H
 #define kvm_enabled()           (kvm_allowed)
@@ -40,10 +41,20 @@ extern bool kvm_async_interrupts_allowed;
  */
 #define kvm_async_interrupts_enabled() (kvm_async_interrupts_allowed)
 
+/**
+ * kvm_irqfds_enabled:
+ *
+ * Returns: true if we can use irqfds to inject interrupts into
+ * a KVM CPU (ie the kernel supports irqfds and we are running
+ * with a configuration where it is meaningful to use them).
+ */
+#define kvm_irqfds_enabled() (kvm_irqfds_allowed)
+
 #else
 #define kvm_enabled()           (0)
 #define kvm_irqchip_in_kernel() (false)
 #define kvm_async_interrupts_enabled() (false)
+#define kvm_irqfds_enabled() (false)
 #endif
 
 struct kvm_run;
target-i386/kvm.c +4 -0
index 7e5f51e..5cb33a2 100644
@@ -2045,4 +2045,8 @@ void kvm_arch_init_irq_routing(KVMState *s)
          */
         no_hpet = 1;
     }
+    /* We know at this point that we're using the in-kernel
+     * irqchip, so we can use irqfds.
+     */
+    kvm_irqfds_allowed = true;
 }
Signature · 1 line
1.7.5.4
#5 lore raw

PATCH v2 5/7 kvm: Decouple 'MSI routing via irqfds' from 'kernel irqchip'

In reply to Peter Maydell

Decouple another x86-specific assumption about what irqchips imply.

---
 hw/virtio-pci.c   |    4 ++--
 kvm-all.c         |    1 +
 kvm-stub.c        |    1 +
 kvm.h             |   11 +++++++++++
 target-i386/kvm.c |    4 +++-
 5 files changed, 18 insertions(+), 3 deletions(-)
hw/virtio-pci.c +2 -2
index 4e03f0b..98e02ef 100644
@@ -627,7 +627,7 @@ static int virtio_pci_set_guest_notifiers(void *opaque, bool assign)
     int r, n;
 
     /* Must unset vector notifier while guest notifier is still assigned */
-    if (kvm_irqchip_in_kernel() && !assign) {
+    if (kvm_msi_via_irqfd_enabled() && !assign) {
         msix_unset_vector_notifiers(&proxy->pci_dev);
         g_free(proxy->vector_irqfd);
         proxy->vector_irqfd = NULL;
@@ -645,7 +645,7 @@ static int virtio_pci_set_guest_notifiers(void *opaque, bool assign)
     }
 
     /* Must set vector notifier after guest notifier has been assigned */
-    if (kvm_irqchip_in_kernel() && assign) {
+    if (kvm_msi_via_irqfd_enabled() && assign) {
         proxy->vector_irqfd =
             g_malloc0(sizeof(*proxy->vector_irqfd) *
                       msix_nr_vectors_allocated(&proxy->pci_dev));
kvm-all.c +1 -0
index 3a69e53..cdacd74 100644
@@ -102,6 +102,7 @@ KVMState *kvm_state;
 bool kvm_kernel_irqchip;
 bool kvm_async_interrupts_allowed;
 bool kvm_irqfds_allowed;
+bool kvm_msi_via_irqfd_allowed;
 
 static const KVMCapabilityInfo kvm_required_capabilites[] = {
     KVM_CAP_INFO(USER_MEMORY),
kvm-stub.c +1 -0
index 02e7fe0..158bb7b 100644
@@ -21,6 +21,7 @@ KVMState *kvm_state;
 bool kvm_kernel_irqchip;
 bool kvm_async_interrupts_allowed;
 bool kvm_irqfds_allowed;
+bool kvm_msi_via_irqfd_allowed;
 
 int kvm_init_vcpu(CPUArchState *env)
 {
kvm.h +11 -0
index 21436ef..34d32c7 100644
@@ -26,6 +26,7 @@ extern int kvm_allowed;
 extern bool kvm_kernel_irqchip;
 extern bool kvm_async_interrupts_allowed;
 extern bool kvm_irqfds_allowed;
+extern bool kvm_msi_via_irqfd_allowed;
 
 #if defined CONFIG_KVM || !defined NEED_CPU_H
 #define kvm_enabled()           (kvm_allowed)
@@ -50,11 +51,21 @@ extern bool kvm_irqfds_allowed;
  */
 #define kvm_irqfds_enabled() (kvm_irqfds_allowed)
 
+/**
+ * kvm_msi_via_irqfd_enabled:
+ *
+ * Returns: true if we can route a PCI MSI (Message Signaled Interrupt)
+ * to a KVM CPU via an irqfd. This requires that the kernel supports
+ * this and that we're running in a configuration that permits it.
+ */
+#define kvm_msi_via_irqfd_enabled() (kvm_msi_via_irqfd_allowed)
+
 #else
 #define kvm_enabled()           (0)
 #define kvm_irqchip_in_kernel() (false)
 #define kvm_async_interrupts_enabled() (false)
 #define kvm_irqfds_enabled() (false)
+#define kvm_msi_via_irqfd_enabled() (false)
 #endif
 
 struct kvm_run;
target-i386/kvm.c +3 -1
index 5cb33a2..46ee906 100644
@@ -2046,7 +2046,9 @@ void kvm_arch_init_irq_routing(KVMState *s)
         no_hpet = 1;
     }
     /* We know at this point that we're using the in-kernel
-     * irqchip, so we can use irqfds.
+     * irqchip, so we can use irqfds, and on x86 we know
+     * we can use msi via irqfd.
      */
     kvm_irqfds_allowed = true;
+    kvm_msi_via_irqfd_allowed = true;
 }
Signature · 1 line
1.7.5.4
#6 lore raw

PATCH v2 6/7 kvm: Decouple 'GSI routing' from 'kernel irqchip'

In reply to Peter Maydell

Don't assume having an in-kernel irqchip means that GSI routing is enabled.

---
 kvm-all.c         |    3 ++-
 kvm-stub.c        |    1 +
 kvm.h             |   10 ++++++++++
 target-i386/kvm.c |    3 ++-
 4 files changed, 15 insertions(+), 2 deletions(-)
kvm-all.c +2 -1
index cdacd74..6def6c9 100644
@@ -103,6 +103,7 @@ bool kvm_kernel_irqchip;
 bool kvm_async_interrupts_allowed;
 bool kvm_irqfds_allowed;
 bool kvm_msi_via_irqfd_allowed;
+bool kvm_gsi_routing_allowed;
 
 static const KVMCapabilityInfo kvm_required_capabilites[] = {
     KVM_CAP_INFO(USER_MEMORY),
@@ -1099,7 +1100,7 @@ int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg)
     struct kvm_irq_routing_entry kroute;
     int virq;
 
-    if (!kvm_irqchip_in_kernel()) {
+    if (!kvm_gsi_routing_enabled()) {
         return -ENOSYS;
     }
 
kvm-stub.c +1 -0
index 158bb7b..94c9ea1 100644
@@ -22,6 +22,7 @@ bool kvm_kernel_irqchip;
 bool kvm_async_interrupts_allowed;
 bool kvm_irqfds_allowed;
 bool kvm_msi_via_irqfd_allowed;
+bool kvm_gsi_routing_allowed;
 
 int kvm_init_vcpu(CPUArchState *env)
 {
kvm.h +10 -0
index 34d32c7..444ed2e 100644
@@ -27,6 +27,7 @@ extern bool kvm_kernel_irqchip;
 extern bool kvm_async_interrupts_allowed;
 extern bool kvm_irqfds_allowed;
 extern bool kvm_msi_via_irqfd_allowed;
+extern bool kvm_gsi_routing_allowed;
 
 #if defined CONFIG_KVM || !defined NEED_CPU_H
 #define kvm_enabled()           (kvm_allowed)
@@ -60,12 +61,21 @@ extern bool kvm_msi_via_irqfd_allowed;
  */
 #define kvm_msi_via_irqfd_enabled() (kvm_msi_via_irqfd_allowed)
 
+/**
+ * kvm_gsi_routing_enabled:
+ *
+ * Returns: true if GSI routing is enabled (ie the kernel supports
+ * it and we're running in a configuration that permits it).
+ */
+#define kvm_gsi_routing_enabled() (kvm_gsi_routing_allowed)
+
 #else
 #define kvm_enabled()           (0)
 #define kvm_irqchip_in_kernel() (false)
 #define kvm_async_interrupts_enabled() (false)
 #define kvm_irqfds_enabled() (false)
 #define kvm_msi_via_irqfd_enabled() (false)
+#define kvm_gsi_routing_allowed() (false)
 #endif
 
 struct kvm_run;
target-i386/kvm.c +2 -1
index 46ee906..e58460f 100644
@@ -2047,8 +2047,9 @@ void kvm_arch_init_irq_routing(KVMState *s)
     }
     /* We know at this point that we're using the in-kernel
      * irqchip, so we can use irqfds, and on x86 we know
-     * we can use msi via irqfd.
+     * we can use msi via irqfd and GSI routing.
      */
     kvm_irqfds_allowed = true;
     kvm_msi_via_irqfd_allowed = true;
+    kvm_gsi_routing_allowed = true;
 }
Signature · 1 line
1.7.5.4
#7 lore raw

PATCH v2 7/7 kvm: Add documentation comment for kvm_irqchip_in_kernel()

In reply to Peter Maydell

Now we've cleared out the architecture-independent uses of kvm_irqchip_in_kernel(), we can add a doc comment describing what it means.

---
 kvm.h |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
kvm.h +11 -0
index 444ed2e..5b8f588 100644
@@ -31,6 +31,17 @@ extern bool kvm_gsi_routing_allowed;
 
 #if defined CONFIG_KVM || !defined NEED_CPU_H
 #define kvm_enabled()           (kvm_allowed)
+/**
+ * kvm_irqchip_in_kernel:
+ *
+ * Returns: true if the user asked us to create an in-kernel
+ * irqchip via the "kernel_irqchip=on" machine option.
+ * What this actually means is architecture and machine model
+ * specific: on PC, for instance, it means that the LAPIC,
+ * IOAPIC and PIT are all in kernel. This function should never
+ * be used from generic target-independent code: use one of the
+ * following functions or some other specific check instead.
+ */
 #define kvm_irqchip_in_kernel() (kvm_kernel_irqchip)
 
 /**
Signature · 1 line
1.7.5.4
#8 lore raw
In reply to Peter Maydell

ping?

thanks
-- PMM

Quoted 48 lines · Peter Maydell

This patch series removes all uses of kvm_irqchip_in_kernel() from architecture-independent code, by creating a set of more specific functions instead to test for the particular aspects of behaviour that the calling code is actually interested in.

The uses in x86-specific code could in theory be further broken down into kvm_ioapic(), kvm_pit(), etc, but I leave that for one of the x86 maintainers if they think it's worthwhile.

Changes v1->v2:
* more blank lines round kvm.h doc comments / macros
* 1: fn name changed to: kvm_async_interrupts_enabled() (and corresponding bool is now kvm_async_interrupts_allowed, so we are consistent about the enabled/allowed convention)
* 2: fn name changed to: kvm_set_irq()
* 3: fix return type of kvm_allows_irq0_override() to bool
* 5 (and new patch 6): split out separate kvm_gsi_routing_enabled() check for use in kvm_irqchip_add_msi_route()

Peter Maydell (7):
kvm: Decouple 'async interrupt delivery' from 'kernel irqchip'
kvm: Rename kvm_irqchip_set_irq() to kvm_set_irq()
kvm: Move kvm_allows_irq0_override() to target-i386, fix return type
kvm: Decouple 'irqfds usable' from 'kernel irqchip'
kvm: Decouple 'MSI routing via irqfds' from 'kernel irqchip'
kvm: Decouple 'GSI routing' from 'kernel irqchip'
kvm: Add documentation comment for kvm_irqchip_in_kernel()

 cpus.c                    |    3 +-
 hw/kvm/i8259.c            |    2 +-
 hw/kvm/ioapic.c           |    2 +-
 hw/pc.c                   |    1 +
 hw/virtio-pci.c           |    4 +-
 kvm-all.c                 |   25 ++++++++++--------
 kvm-stub.c                |    9 +++---
 kvm.h                     |   60 ++++++++++++++++++++++++++++++++++++++++++--
 target-i386/Makefile.objs |    1 +
 target-i386/kvm-stub.c    |   18 +++++++++++++
 target-i386/kvm.c         |   13 +++++++++
 target-i386/kvm_i386.h    |   16 ++++++++++++
 12 files changed, 130 insertions(+), 24 deletions(-)
 create mode 100644 target-i386/kvm-stub.c
 create mode 100644 target-i386/kvm_i386.h

--
1.7.5.4

#9 lore raw
Quoted 1 line · Peter Maydell

ping?

Sorry, head is full with other stuff. Will try to have a final look today.

Jan

Quoted 53 lines

thanks
-- PMM

Quoted 48 lines · Peter Maydell

This patch series removes all uses of kvm_irqchip_in_kernel() from architecture-independent code, by creating a set of more specific functions instead to test for the particular aspects of behaviour that the calling code is actually interested in.

The uses in x86-specific code could in theory be further broken down into kvm_ioapic(), kvm_pit(), etc, but I leave that for one of the x86 maintainers if they think it's worthwhile.

Changes v1->v2:
* more blank lines round kvm.h doc comments / macros
* 1: fn name changed to: kvm_async_interrupts_enabled() (and corresponding bool is now kvm_async_interrupts_allowed, so we are consistent about the enabled/allowed convention)
* 2: fn name changed to: kvm_set_irq()
* 3: fix return type of kvm_allows_irq0_override() to bool
* 5 (and new patch 6): split out separate kvm_gsi_routing_enabled() check for use in kvm_irqchip_add_msi_route()

Peter Maydell (7):
kvm: Decouple 'async interrupt delivery' from 'kernel irqchip'
kvm: Rename kvm_irqchip_set_irq() to kvm_set_irq()
kvm: Move kvm_allows_irq0_override() to target-i386, fix return type
kvm: Decouple 'irqfds usable' from 'kernel irqchip'
kvm: Decouple 'MSI routing via irqfds' from 'kernel irqchip'
kvm: Decouple 'GSI routing' from 'kernel irqchip'
kvm: Add documentation comment for kvm_irqchip_in_kernel()

 cpus.c                    |    3 +-
 hw/kvm/i8259.c            |    2 +-
 hw/kvm/ioapic.c           |    2 +-
 hw/pc.c                   |    1 +
 hw/virtio-pci.c           |    4 +-
 kvm-all.c                 |   25 ++++++++++--------
 kvm-stub.c                |    9 +++---
 kvm.h                     |   60 ++++++++++++++++++++++++++++++++++++++++++--
 target-i386/Makefile.objs |    1 +
 target-i386/kvm-stub.c    |   18 +++++++++++++
 target-i386/kvm.c         |   13 +++++++++
 target-i386/kvm_i386.h    |   16 ++++++++++++
 12 files changed, 130 insertions(+), 24 deletions(-)
 create mode 100644 target-i386/kvm-stub.c
 create mode 100644 target-i386/kvm_i386.h

--
1.7.5.4

Acked-by on the v2 series
#10 lore raw
In reply to Peter Maydell
Quoted 8 lines · Peter Maydell

This patch series removes all uses of kvm_irqchip_in_kernel() from architecture-independent code, by creating a set of more specific functions instead to test for the particular aspects of behaviour that the calling code is actually interested in.

The uses in x86-specific code could in theory be further broken down into kvm_ioapic(), kvm_pit(), etc, but I leave that for one of the x86 maintainers if they think it's worthwhile.

With the existing KVM irqchip support for x86, you can't break things down like this.

Quoted 20 lines

Changes v1->v2:
* more blank lines round kvm.h doc comments / macros
* 1: fn name changed to: kvm_async_interrupts_enabled() (and corresponding bool is now kvm_async_interrupts_allowed, so we are consistent about the enabled/allowed convention)
* 2: fn name changed to: kvm_set_irq()
* 3: fix return type of kvm_allows_irq0_override() to bool
* 5 (and new patch 6): split out separate kvm_gsi_routing_enabled() check for use in kvm_irqchip_add_msi_route()

Peter Maydell (7):
kvm: Decouple 'async interrupt delivery' from 'kernel irqchip'
kvm: Rename kvm_irqchip_set_irq() to kvm_set_irq()
kvm: Move kvm_allows_irq0_override() to target-i386, fix return type
kvm: Decouple 'irqfds usable' from 'kernel irqchip'
kvm: Decouple 'MSI routing via irqfds' from 'kernel irqchip'
kvm: Decouple 'GSI routing' from 'kernel irqchip'
kvm: Add documentation comment for kvm_irqchip_in_kernel()

Quoted 16 lines
 cpus.c                    |    3 +-
 hw/kvm/i8259.c            |    2 +-
 hw/kvm/ioapic.c           |    2 +-
 hw/pc.c                   |    1 +
 hw/virtio-pci.c           |    4 +-
 kvm-all.c                 |   25 ++++++++++--------
 kvm-stub.c                |    9 +++---
 kvm.h                     |   60 ++++++++++++++++++++++++++++++++++++++++++--
 target-i386/Makefile.objs |    1 +
 target-i386/kvm-stub.c    |   18 +++++++++++++
 target-i386/kvm.c         |   13 +++++++++
 target-i386/kvm_i386.h    |   16 ++++++++++++
 12 files changed, 130 insertions(+), 24 deletions(-)
 create mode 100644 target-i386/kvm-stub.c
 create mode 100644 target-i386/kvm_i386.h

For the whole series:

#11 lore raw
Quoted 6 lines · Jan Kiszka
Quoted 5 lines · Peter Maydell

This patch series removes all uses of kvm_irqchip_in_kernel() from architecture-independent code, by creating a set of more specific functions instead to test for the particular aspects of behaviour that the calling code is actually interested in.

Quoted 7 lines
Quoted 3 lines

The uses in x86-specific code could in theory be further broken down into kvm_ioapic(), kvm_pit(), etc, but I leave that for one of the x86 maintainers if they think it's worthwhile.

For the whole series:

Just a ping to check this will get into qemu before the hardfreeze next week...

-- PMM

#12 lore raw
Quoted 11 lines · Peter Maydell
Quoted 10 lines · Jan Kiszka
Quoted 8 lines · Peter Maydell

This patch series removes all uses of kvm_irqchip_in_kernel() from architecture-independent code, by creating a set of more specific functions instead to test for the particular aspects of behaviour that the calling code is actually interested in.

The uses in x86-specific code could in theory be further broken down into kvm_ioapic(), kvm_pit(), etc, but I leave that for one of the x86 maintainers if they think it's worthwhile.

Quoted 6 lines
Quoted 3 lines

For the whole series:

Just a ping to check this will get into qemu before the hardfreeze next week...

Thanks for the ping; all applied. Will push after autotesting.

Signature · 1 line
error compiling committee.c: too many arguments to function