qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [RFC PATCH v3 0/4] AMBA platform device passthrough
@ 2014-06-23 14:54 Alvise Rigo
  2014-06-23 14:54 ` [Qemu-devel] [RFC PATCH v3 1/4] Add AMBA devices support to VFIO Alvise Rigo
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Alvise Rigo @ 2014-06-23 14:54 UTC (permalink / raw)
  To: qemu-devel, a.motakis, eric.auger; +Cc: tech, Alvise Rigo

These patches are the next iteration of "[Qemu-devel] [RFC v2 0/4] AMBA
platform device passthrough" and are based on the latest version of VFIO
for platform devices "[RFC PATCH v6 00/20] VFIO support for platform
devices on ARM" and the initial patch series "[Qemu-devel] [RFC v3 0/10] KVM
platform device passthrough".

- [PATCH 1/4] Possibility to bind a wider class of devices. In
  particular the patch proposes a solution to enhance a bit the device
  tree nodes generation, allowing to specify more than one compatibility
  property (handy for AMBA devices). This was required by the DMA330
  that needs "arm,pl330","arm,primecell" as compatibility string,
  together with a clock source defined in the device tree. In the future
  VFIO will be able to tell if we are dealing with an AMBA device;
  before that, we have to rely on the compatibility string to state
  that.

- [PATCH 3/4] The last version of VFIO allows to pass an eventfd file descriptor
  to unmask a host interrupt. This can be used in conjunction with IRQFD to
  benefit of the resampler feature; in this way QEMU no longer has to unmask
  the interrupt because the kernel will take care of it.

- [PATCH 4/4] If event_notifier_init fails to create a new eventfd, it
  will fallback using pipe/pipe2 and we end up passing to the kernel a
  wrong file descriptor. This patch force to use eventfd.

  Changes since v2:

- The EXEC_FLAG now is always used by VFIO if it is supported. QEMU does not
  need to query the kernel any more to know whether using this flag or not.
  For this reason, the patch [1/4] of the previous version has been removed.

- Included patch [2/4] from Eric Auger, required by patch [3/4] and [4/4].

- The patch [3/4] of the previous version has been also removed since the
  introduction of the new mechanism of handling IRQs and EOIs through IRQFD.
  The patch can nevertheless be used to improve the standard, timer based,
  mechanism.

- [PATCH 4/4] Instead of checking whether eventfd has been used by
  event_notifier_init, a new method (eventfd_notifier_init) is added to fulfill
  this purpose.

Alvise Rigo (3):
  Add AMBA devices support to VFIO
  Force eventfd as notifying mechanism for VFIO
  Let VFIO handle the unmasking of interrupts at EOI

Eric Auger (1):
  vfio: Add irqfd support in platform device

 hw/arm/virt.c                 |  59 +++++++++++---
 hw/intc/arm_gic_kvm.c         |   1 +
 hw/vfio/pci.c                 |  18 ++---
 hw/vfio/platform.c            | 179 ++++++++++++++++++++++++++++++++++++++----
 include/qemu/event_notifier.h |   1 +
 util/event_notifier-posix.c   |  24 +++++-
 6 files changed, 244 insertions(+), 38 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] [RFC PATCH v3 1/4] Add AMBA devices support to VFIO
  2014-06-23 14:54 [Qemu-devel] [RFC PATCH v3 0/4] AMBA platform device passthrough Alvise Rigo
@ 2014-06-23 14:54 ` Alvise Rigo
  2014-06-23 14:54 ` [Qemu-devel] [RFC PATCH v3 2/4] vfio: Add irqfd support in platform device Alvise Rigo
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Alvise Rigo @ 2014-06-23 14:54 UTC (permalink / raw)
  To: qemu-devel, a.motakis, eric.auger
  Cc: Peter Maydell, tech, Alvise Rigo, Eric Auger

The impossibility to add more then one compatibility property to the
device tree node was not permitting to bind AMBA devices.
Now we can add an arbitrary number of compatibility property values divided by
the character ";".

If the compatibility string contains the substring "arm,primecell", a
clock property will be added to the device tree node in order to allow the AMBA
bus code to probe the device.

[Eric Auger]
put str_ptr in the declaration part and rename pcompat into compat

Signed-off-by: Alvise Rigo <a.rigo@virtualopensystems.com>
Signed-off-by: Eric Auger <eric.auger@linaro.org>
---
 hw/arm/virt.c | 45 +++++++++++++++++++++++++++++++++++----------
 1 file changed, 35 insertions(+), 10 deletions(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 8de6d1a..bc561b5 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -369,6 +369,7 @@ static int vfio_init_func(QemuOpts *opts, void *opaque)
     int irq_start = vbi->avail_vfio_irq;
     hwaddr vfio_base = vbi->avail_vfio_base;
     char *nodename;
+    char *str_ptr;
     char *corrected_compat, *compat, *name;
     int num_irqs, num_regions;
     MemoryRegion *mr;
@@ -377,6 +378,8 @@ static int vfio_init_func(QemuOpts *opts, void *opaque)
     uint64_t *reg_attr;
     uint64_t size;
     Error *errp = NULL;
+    bool is_amba = false;
+    int compat_str_len;
 
     if (!driver) {
         qerror_report(QERR_MISSING_PARAMETER, "driver");
@@ -442,17 +445,30 @@ static int vfio_init_func(QemuOpts *opts, void *opaque)
 
         /*
          * process compatibility property string passed by end-user
-         * replaces / by ,
-         * currently a single property compatibility value is supported!
+         * replaces / by , and ; by NUL character
          */
         corrected_compat = g_strdup(compat);
-        char *slash = strchr(corrected_compat, '/');
-        if (slash != NULL) {
-            *slash = ',';
-        } else {
-            error_report("Wrong compat string %s, should contain a /\n",
-                         compat);
-            exit(1);
+        /*
+         * the total length of the string has to include also the last
+         * NUL char.
+         */
+        compat_str_len = strlen(corrected_compat) + 1;
+
+        str_ptr = corrected_compat;
+        while ((str_ptr = strchr(str_ptr, '/')) != NULL) {
+            *str_ptr = ',';
+        }
+
+        /* check if is an AMBA device */
+        str_ptr = corrected_compat;
+        if (strstr(str_ptr, "arm,primecell") != NULL) {
+            is_amba = true;
+        }
+
+        /* substitute ";" with the NUL char */
+        str_ptr = corrected_compat;
+        while ((str_ptr = strchr(str_ptr, ';')) != NULL) {
+            *str_ptr = '\0';
         }
 
         sysbus_mmio_map(s, 0, vfio_base);
@@ -462,7 +478,7 @@ static int vfio_init_func(QemuOpts *opts, void *opaque)
         qemu_fdt_add_subnode(vbi->fdt, nodename);
 
         qemu_fdt_setprop(vbi->fdt, nodename, "compatible",
-                             corrected_compat, strlen(corrected_compat));
+                             corrected_compat, compat_str_len);
 
         ret = qemu_fdt_setprop_sized_cells_from_array(vbi->fdt, nodename, "reg",
                          num_regions*2, reg_attr);
@@ -471,6 +487,15 @@ static int vfio_init_func(QemuOpts *opts, void *opaque)
         }
 
         irq_attr = g_new(uint32_t, num_irqs*3);
+
+        if (is_amba) {
+            qemu_fdt_setprop_cells(vbi->fdt, nodename, "clocks",
+                                   vbi->clock_phandle);
+            char clock_names[] = "apb_pclk";
+            qemu_fdt_setprop(vbi->fdt, nodename, "clock-names", clock_names,
+                                                       sizeof(clock_names));
+        }
+
         for (i = 0; i < num_irqs; i++) {
             sysbus_connect_irq(s, i, vbi->pic[irq_start+i]);
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [RFC PATCH v3 2/4] vfio: Add irqfd support in platform device
  2014-06-23 14:54 [Qemu-devel] [RFC PATCH v3 0/4] AMBA platform device passthrough Alvise Rigo
  2014-06-23 14:54 ` [Qemu-devel] [RFC PATCH v3 1/4] Add AMBA devices support to VFIO Alvise Rigo
@ 2014-06-23 14:54 ` Alvise Rigo
  2014-06-23 14:54 ` [Qemu-devel] [RFC PATCH v3 3/4] Force eventfd as notifying mechanism for VFIO Alvise Rigo
  2014-06-23 14:54 ` [Qemu-devel] [RFC PATCH v3 4/4] Let VFIO handle the unmasking of interrupts at EOI Alvise Rigo
  3 siblings, 0 replies; 5+ messages in thread
From: Alvise Rigo @ 2014-06-23 14:54 UTC (permalink / raw)
  To: qemu-devel, a.motakis, eric.auger
  Cc: Peter Maydell, Eric Auger, Alvise Rigo, Markus Armbruster,
	Alex Williamson, Paolo Bonzini, tech, Andreas Färber,
	Christoffer Dall

From: Eric Auger <eric.auger@linaro.org>

This patch aims at optimizing IRQ handling using irqfd framework.
It brings significant performance improvement over "traditional" IRQ
handling introduced in :
"vfio: Add initial IRQ support in platform device".

This new IRQ handling method depends on kernel KVM irqfd/GSI routing
capability.

The IRQ handling method can be dynamically chosen (default is irqfd,
if kernel supports it obviously).  For example to disable irqfd
handling, use:

-device vfio-platform,vfio_device="fff51000.ethernet",\
compat="calxeda/hb-xgmac",mmap-timeout-ms=110,irqfd=false\

Performances are improved for the following reasons:
- eventfds signalled by the VFIO platform driver are handled on
  kernel side by the KVM irqfd framework.
- the end of interrupt(EOI) is trapped at GIC level and not at MMIO
  region level. As a reminder, in traditional IRQ handling QEMU
  assumed the first guest access to a device MMIO region after IRQ
  hit was the IRQ status register reset. This trap was approximate
  and obliged to swap to slow path after IRQ hit. A mmap timer
  mechanism enabled to swap back to fast path after the mmap period
  introducing extra complexity. Now GIC detects the completion of
  the virtual IRQ and signals a resampler eventfd on maintenance
  IRQ. The corresponding handler re-enables the physical IRQ.

Next optimization step consists in attempting to remove EOI trap
(ie.  maintenance IRQ). This should be covered by another patch in
near future.

This work was tested with Calxeda Midway xgmac.

Signed-off-by: Eric Auger <eric.auger@linaro.org>
Signed-off-by: Alvise Rigo <a.rigo@virtualopensystems.com>
---
 hw/arm/virt.c         |  14 +++++
 hw/intc/arm_gic_kvm.c |   1 +
 hw/vfio/platform.c    | 165 +++++++++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 166 insertions(+), 14 deletions(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index bc561b5..de1b885 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -43,6 +43,9 @@
 #include "monitor/qdev.h"
 #include "qemu/config-file.h"
 
+#define ENABLE_IRQFD 1
+void vfio_setup_irqfd(SysBusDevice *s, int index, int virq);
+
 #define NUM_VIRTIO_TRANSPORTS 32
 
 /* Number of external interrupt lines to configure the GIC with */
@@ -380,6 +383,7 @@ static int vfio_init_func(QemuOpts *opts, void *opaque)
     Error *errp = NULL;
     bool is_amba = false;
     int compat_str_len;
+    bool irqfd_allowed;
 
     if (!driver) {
         qerror_report(QERR_MISSING_PARAMETER, "driver");
@@ -417,6 +421,13 @@ static int vfio_init_func(QemuOpts *opts, void *opaque)
                          error_get_pretty(errp));
             exit(1);
            }
+        irqfd_allowed = object_property_get_bool(OBJECT(s), "irqfd", &errp);
+        if (errp != NULL) {
+            error_report("Couldn't retrieve irqfd flag: %s\n",
+                         error_get_pretty(errp));
+            exit(1);
+           }
+
 
         /*
          * collect region info and build reg property as tuplets
@@ -502,6 +513,9 @@ static int vfio_init_func(QemuOpts *opts, void *opaque)
             irq_attr[3*i] = cpu_to_be32(0);
             irq_attr[3*i+1] = cpu_to_be32(irq_start+i);
             irq_attr[3*i+2] = cpu_to_be32(0x4);
+            if (irqfd_allowed) {
+                vfio_setup_irqfd(s, i, irq_start+i);
+            }
         }
 
         ret = qemu_fdt_setprop(vbi->fdt, nodename, "interrupts",
diff --git a/hw/intc/arm_gic_kvm.c b/hw/intc/arm_gic_kvm.c
index 5038885..18a6204 100644
--- a/hw/intc/arm_gic_kvm.c
+++ b/hw/intc/arm_gic_kvm.c
@@ -576,6 +576,7 @@ static void kvm_arm_gic_realize(DeviceState *dev, Error **errp)
                             KVM_DEV_ARM_VGIC_GRP_ADDR,
                             KVM_VGIC_V2_ADDR_TYPE_CPU,
                             s->dev_fd);
+    kvm_irqfds_allowed = true;
 }
 
 static void kvm_arm_gic_class_init(ObjectClass *klass, void *data)
diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
index 377783b..d87fcc3 100644
--- a/hw/vfio/platform.c
+++ b/hw/vfio/platform.c
@@ -23,6 +23,7 @@
 #include "hw/sysbus.h"
 
 #include "vfio-common.h"
+#include "sysemu/kvm.h"
 
 typedef struct VFIOINTp {
     QLIST_ENTRY(VFIOINTp) next; /* entry for IRQ list */
@@ -34,6 +35,7 @@ typedef struct VFIOINTp {
     int state; /* inactive, pending, active */
     bool kvm_accel; /* set when QEMU bypass through KVM enabled */
     uint8_t pin; /* index */
+    uint8_t virtualID; /* virtual IRQ */
 } VFIOINTp;
 
 
@@ -44,6 +46,7 @@ typedef struct VFIOPlatformDevice {
     /* queue of pending IRQ */
     QSIMPLEQ_HEAD(pending_intp_queue, VFIOINTp) pending_intp_queue;
     char *compat; /* compatibility string */
+    bool irqfd_allowed;
 } VFIOPlatformDevice;
 
 
@@ -54,6 +57,7 @@ static const MemoryRegionOps vfio_region_ops = {
 };
 
 static void vfio_intp_interrupt(void *opaque);
+void vfio_setup_irqfd(SysBusDevice *s, int index, int virq);
 
 /*
  * It is mandatory to pass a VFIOPlatformDevice since VFIODevice
@@ -419,29 +423,138 @@ static int vfio_platform_get_device_interrupts(VFIODevice *vdev)
 }
 
 
-static void vfio_disable_intp(VFIODevice *vdev)
+static void vfio_disable_intp(VFIOINTp *intp)
 {
+    int fd = event_notifier_get_fd(&intp->interrupt);
+    DPRINTF("close IRQ pin=%d fd=%d\n", intp->pin, fd);
+
+    /* remove the IRQ handler */
+    vfio_disable_irqindex(&intp->vdev->vdev, intp->pin);
+    intp->state = VFIO_IRQ_INACTIVE;
+    qemu_set_irq(intp->qemuirq, 0);
+    qemu_set_fd_handler(fd, NULL, NULL, NULL);
+    event_notifier_cleanup(&intp->interrupt);
+
+}
+
+
+/* IRQFD */
+
+static void resampler_handler(void *opaque)
+{
+    VFIOINTp *intp = (VFIOINTp *)opaque;
+    DPRINTF("%s index %d virtual ID = %d fd = %d\n",
+            __func__,
+            intp->pin, intp->virtualID,
+            event_notifier_get_fd(&intp->unmask));
+    vfio_unmask_irqindex(&intp->vdev->vdev, intp->pin);
+}
+
+
+static void vfio_enable_intp_kvm(VFIOINTp *intp)
+{
+#ifdef CONFIG_KVM
+    struct kvm_irqfd irqfd = {
+        .fd = event_notifier_get_fd(&intp->interrupt),
+        .gsi = intp->virtualID,
+        .flags = KVM_IRQFD_FLAG_RESAMPLE,
+    };
+
+    if (!kvm_irqfds_enabled() ||
+        !kvm_check_extension(kvm_state, KVM_CAP_IRQFD_RESAMPLE)) {
+        return;
+    }
+
+    /* Get to a known interrupt state */
+    qemu_set_fd_handler(irqfd.fd, NULL, NULL, NULL);
+    intp->state = VFIO_IRQ_INACTIVE;
+    qemu_set_irq(intp->qemuirq, 0);
+
+    /* Get an eventfd for resample/unmask */
+    if (event_notifier_init(&intp->unmask, 0)) {
+        error_report("vfio: Error: event_notifier_init failed eoi");
+        goto fail;
+    }
+
+    /* KVM triggers it, VFIO listens for it */
+    irqfd.resamplefd = event_notifier_get_fd(&intp->unmask);
+    qemu_set_fd_handler(irqfd.resamplefd, resampler_handler, NULL, intp);
+
+
+    if (kvm_vm_ioctl(kvm_state, KVM_IRQFD, &irqfd)) {
+        error_report("vfio: Error: Failed to setup resample irqfd: %m");
+        goto fail_irqfd;
+    }
+    intp->kvm_accel = true;
+
+    DPRINTF("%s irqfd pin=%d to virtID = %d fd=%d, resamplefd=%d)\n",
+            __func__, intp->pin, intp->virtualID,
+            irqfd.fd, irqfd.resamplefd);
+
+    return;
+
+fail_irqfd:
+    event_notifier_cleanup(&intp->unmask);
+fail:
+    qemu_set_fd_handler(irqfd.fd, vfio_intp_interrupt, NULL, intp);
+    vfio_unmask_irqindex(&intp->vdev->vdev, intp->pin);
+#endif
+}
+
+void vfio_setup_irqfd(SysBusDevice *s, int index, int virq)
+{
+    VFIOPlatformDevice *vdev = container_of(s, VFIOPlatformDevice, sbdev);
     VFIOINTp *intp;
-    VFIOPlatformDevice *vplatdev = container_of(vdev, VFIOPlatformDevice, vdev);
-    int fd;
+    QLIST_FOREACH(intp, &vdev->intp_list, next) {
+        if (intp->pin == index) {
+            intp->virtualID = virq;
+            vfio_enable_intp_kvm(intp);
+        }
+    }
+}
 
-    QLIST_FOREACH(intp, &vplatdev->intp_list, next) {
-        fd = event_notifier_get_fd(&intp->interrupt);
-        DPRINTF("close IRQ pin=%d fd=%d\n", intp->pin, fd);
+static void vfio_disable_intp_kvm(VFIOINTp *intp)
+{
+#ifdef CONFIG_KVM
 
-        vfio_disable_irqindex(vdev, intp->pin);
-        intp->state = VFIO_IRQ_INACTIVE;
-        qemu_set_irq(intp->qemuirq, 0);
+    struct kvm_irqfd irqfd = {
+        .fd = event_notifier_get_fd(&intp->interrupt),
+        .gsi = intp->virtualID,
+        .flags = KVM_IRQFD_FLAG_DEASSIGN,
+        };
 
-        qemu_set_fd_handler(fd, NULL, NULL, NULL);
-        event_notifier_cleanup(&intp->interrupt);
+    if (!intp->kvm_accel) {
+        return;
     }
 
-    /* restore fast path */
-    vfio_mmap_set_enabled(vdev, true);
+    /*
+     * Get to a known state, hardware masked, QEMU ready to accept new
+     * interrupts, QEMU IRQ de-asserted.
+     */
+    intp->state = VFIO_IRQ_INACTIVE;
+    /* Tell KVM to stop listening for an INTp irqfd */
+    if (kvm_vm_ioctl(kvm_state, KVM_IRQFD, &irqfd)) {
+        error_report("vfio: Error: Failed to disable INTx irqfd: %m");
+    }
+
+    /* We only need to close the eventfd for VFIO to cleanup the kernel side */
+    event_notifier_cleanup(&intp->unmask);
+
+    /* QEMU starts listening for interrupt events. */
+    qemu_set_fd_handler(irqfd.fd, vfio_intp_interrupt, NULL, intp->vdev);
+
+    intp->kvm_accel = false;
 
+    /* If we've missed an event, let it re-fire through QEMU */
+    vfio_unmask_irqindex(&intp->vdev->vdev, intp->pin);
+
+    DPRINTF("%s: KVM INTx accel disabled\n", __func__);
+#endif
 }
 
+
+
+
 static bool vfio_platform_is_device_already_attached(VFIODevice *vdev,
                                                      VFIOGroup *group)
 {
@@ -489,6 +602,25 @@ static void vfio_platform_realize(DeviceState *dev, Error **errp)
     }
 }
 
+
+static void vfio_disable_all_intp(VFIODevice *vdev)
+{
+    VFIOINTp *intp;
+    VFIOPlatformDevice *vplatdev =
+        container_of(vdev, VFIOPlatformDevice, vdev);
+
+    QLIST_FOREACH(intp, &vplatdev->intp_list, next) {
+        /* first disable IRQFD handled IRQ and turn them in QEMU handled ones */
+        vfio_disable_intp_kvm(intp);
+        /* actually disable IRQ */
+        vfio_disable_intp(intp);
+    }
+
+    /* restore fast path */
+    vfio_mmap_set_enabled(vdev, true);
+
+}
+
 static void vfio_platform_unrealize(DeviceState *dev, Error **errp)
 {
     int i;
@@ -505,7 +637,7 @@ static void vfio_platform_unrealize(DeviceState *dev, Error **errp)
      * timer free
      * g_free vdev dynamic fields
     */
-    vfio_disable_intp(vbasedev);
+    vfio_disable_all_intp(vbasedev);
 
     while (!QSIMPLEQ_EMPTY(&vplatdev->pending_intp_queue)) {
             QSIMPLEQ_REMOVE_HEAD(&vplatdev->pending_intp_queue, pqnext);
@@ -532,6 +664,10 @@ static void vfio_platform_unrealize(DeviceState *dev, Error **errp)
 
 }
 
+
+
+
+
 static const VMStateDescription vfio_platform_vmstate = {
     .name = TYPE_VFIO_PLATFORM,
     .unmigratable = 1,
@@ -557,6 +693,7 @@ DEFINE_PROP_UINT32("mmap-timeout-ms", VFIOPlatformDevice,
                    vdev.mmap_timeout, 1100),
 DEFINE_PROP_UINT32("num_irqs", VFIOPlatformDevice, vdev.num_irqs, 0),
 DEFINE_PROP_UINT32("num_regions", VFIOPlatformDevice, vdev.num_regions, 0),
+DEFINE_PROP_BOOL("irqfd", VFIOPlatformDevice, irqfd_allowed, true),
 DEFINE_PROP_END_OF_LIST(),
 };
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [RFC PATCH v3 3/4] Force eventfd as notifying mechanism for VFIO
  2014-06-23 14:54 [Qemu-devel] [RFC PATCH v3 0/4] AMBA platform device passthrough Alvise Rigo
  2014-06-23 14:54 ` [Qemu-devel] [RFC PATCH v3 1/4] Add AMBA devices support to VFIO Alvise Rigo
  2014-06-23 14:54 ` [Qemu-devel] [RFC PATCH v3 2/4] vfio: Add irqfd support in platform device Alvise Rigo
@ 2014-06-23 14:54 ` Alvise Rigo
  2014-06-23 14:54 ` [Qemu-devel] [RFC PATCH v3 4/4] Let VFIO handle the unmasking of interrupts at EOI Alvise Rigo
  3 siblings, 0 replies; 5+ messages in thread
From: Alvise Rigo @ 2014-06-23 14:54 UTC (permalink / raw)
  To: qemu-devel, a.motakis, eric.auger; +Cc: Alex Williamson, tech, Alvise Rigo

The method event_notifier_init doesn't assure that eventfd is used.
Create a new method (eventfd_notifier_init) to initialize only eventfd
file descriptors. This method is also used by event_notifier_init which
has not been modified to keep compatibility with util/event_notifier-win32.c.

Signed-off-by: Alvise Rigo <a.rigo@virtualopensystems.com>
---
 hw/vfio/pci.c                 | 18 +++++++++---------
 hw/vfio/platform.c            |  8 ++++----
 include/qemu/event_notifier.h |  1 +
 util/event_notifier-posix.c   | 24 +++++++++++++++++++++---
 4 files changed, 35 insertions(+), 16 deletions(-)

diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index c86bef9..eae7dce 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -261,8 +261,8 @@ static void vfio_enable_intx_kvm(VFIOPCIDevice *vdev)
     pci_irq_deassert(&vdev->pdev);
 
     /* Get an eventfd for resample/unmask */
-    if (event_notifier_init(&vdev->intx.unmask, 0)) {
-        error_report("vfio: Error: event_notifier_init failed eoi");
+    if (eventfd_notifier_init(&vdev->intx.unmask, 0)) {
+        error_report("vfio: Error: eventfd_notifier_init failed eoi");
         goto fail;
     }
 
@@ -414,9 +414,9 @@ static int vfio_enable_intx(VFIOPCIDevice *vdev)
     }
 #endif
 
-    ret = event_notifier_init(&vdev->intx.interrupt, 0);
+    ret = eventfd_notifier_init(&vdev->intx.interrupt, 0);
     if (ret) {
-        error_report("vfio: Error: event_notifier_init failed");
+        error_report("vfio: Error: eventfd_notifier_init failed");
         return ret;
     }
 
@@ -555,8 +555,8 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,
 
     msix_vector_use(pdev, nr);
 
-    if (event_notifier_init(&vector->interrupt, 0)) {
-        error_report("vfio: Error: event_notifier_init failed");
+    if (eventfd_notifier_init(&vector->interrupt, 0)) {
+        error_report("vfio: Error: eventfd_notifier_init failed");
     }
 
     /*
@@ -718,8 +718,8 @@ retry:
         vector->vdev = vdev;
         vector->use = true;
 
-        if (event_notifier_init(&vector->interrupt, 0)) {
-            error_report("vfio: Error: event_notifier_init failed");
+        if (eventfd_notifier_init(&vector->interrupt, 0)) {
+            error_report("vfio: Error: eventfd_notifier_init failed");
         }
 
         vector->msg = msi_get_message(&vdev->pdev, i);
@@ -2925,7 +2925,7 @@ static void vfio_register_err_notifier(VFIOPCIDevice *vdev)
         return;
     }
 
-    if (event_notifier_init(&vdev->err_notifier, 0)) {
+    if (eventfd_notifier_init(&vdev->err_notifier, 0)) {
         error_report("vfio: Unable to init event notifier for error detection");
         vdev->pci_aer = false;
         return;
diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
index d87fcc3..65dcf0e 100644
--- a/hw/vfio/platform.c
+++ b/hw/vfio/platform.c
@@ -349,9 +349,9 @@ static int vfio_enable_intp(VFIODevice *vdev, unsigned int index)
 
     sysbus_init_irq(sbdev, &intp->qemuirq);
 
-    ret = event_notifier_init(&intp->interrupt, 0);
+    ret = eventfd_notifier_init(&intp->interrupt, 0);
     if (ret) {
-        error_report("vfio: Error: event_notifier_init failed ");
+        error_report("vfio: Error: eventfd_notifier_init failed ");
         return ret;
     }
     /* build the irq_set to be passed to the vfio kernel driver */
@@ -471,8 +471,8 @@ static void vfio_enable_intp_kvm(VFIOINTp *intp)
     qemu_set_irq(intp->qemuirq, 0);
 
     /* Get an eventfd for resample/unmask */
-    if (event_notifier_init(&intp->unmask, 0)) {
-        error_report("vfio: Error: event_notifier_init failed eoi");
+    if (eventfd_notifier_init(&intp->unmask, 0)) {
+        error_report("vfio: Error: eventfd_notifier_init failed eoi");
         goto fail;
     }
 
diff --git a/include/qemu/event_notifier.h b/include/qemu/event_notifier.h
index 88b57af..9220069 100644
--- a/include/qemu/event_notifier.h
+++ b/include/qemu/event_notifier.h
@@ -30,6 +30,7 @@ struct EventNotifier {
 
 typedef void EventNotifierHandler(EventNotifier *);
 
+int eventfd_notifier_init(EventNotifier *, int active);
 int event_notifier_init(EventNotifier *, int active);
 void event_notifier_cleanup(EventNotifier *);
 int event_notifier_set(EventNotifier *);
diff --git a/util/event_notifier-posix.c b/util/event_notifier-posix.c
index 8442c6e..bb29760 100644
--- a/util/event_notifier-posix.c
+++ b/util/event_notifier-posix.c
@@ -25,19 +25,37 @@ void event_notifier_init_fd(EventNotifier *e, int fd)
     e->wfd = fd;
 }
 
-int event_notifier_init(EventNotifier *e, int active)
+int eventfd_notifier_init(EventNotifier *e, int active)
 {
-    int fds[2];
     int ret;
 
 #ifdef CONFIG_EVENTFD
     ret = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
+    if (ret >= 0) {
+        e->rfd = e->wfd = ret;
+        ret = 0;
+
+        if (active) {
+            event_notifier_set(e);
+        }
+    }
 #else
     ret = -1;
     errno = ENOSYS;
 #endif
+
+    return ret;
+}
+
+int event_notifier_init(EventNotifier *e, int active)
+{
+    int fds[2];
+    int ret;
+
+    ret = eventfd_notifier_init(e, active);
+
     if (ret >= 0) {
-        e->rfd = e->wfd = ret;
+        return 0;
     } else {
         if (errno != ENOSYS) {
             return -errno;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [RFC PATCH v3 4/4] Let VFIO handle the unmasking of interrupts at EOI
  2014-06-23 14:54 [Qemu-devel] [RFC PATCH v3 0/4] AMBA platform device passthrough Alvise Rigo
                   ` (2 preceding siblings ...)
  2014-06-23 14:54 ` [Qemu-devel] [RFC PATCH v3 3/4] Force eventfd as notifying mechanism for VFIO Alvise Rigo
@ 2014-06-23 14:54 ` Alvise Rigo
  3 siblings, 0 replies; 5+ messages in thread
From: Alvise Rigo @ 2014-06-23 14:54 UTC (permalink / raw)
  To: qemu-devel, a.motakis, eric.auger; +Cc: Alex Williamson, tech, Alvise Rigo

Now that VFIO can unmask the interrupt autonomously through an eventfd
file descriptor, get rid of the resampler_handler.

TODO: move this code and PCI one to common.c
Signed-off-by: Alvise Rigo <a.rigo@virtualopensystems.com>
---
 hw/vfio/platform.c | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
index 65dcf0e..4fbdcdf 100644
--- a/hw/vfio/platform.c
+++ b/hw/vfio/platform.c
@@ -440,20 +440,13 @@ static void vfio_disable_intp(VFIOINTp *intp)
 
 /* IRQFD */
 
-static void resampler_handler(void *opaque)
-{
-    VFIOINTp *intp = (VFIOINTp *)opaque;
-    DPRINTF("%s index %d virtual ID = %d fd = %d\n",
-            __func__,
-            intp->pin, intp->virtualID,
-            event_notifier_get_fd(&intp->unmask));
-    vfio_unmask_irqindex(&intp->vdev->vdev, intp->pin);
-}
-
-
-static void vfio_enable_intp_kvm(VFIOINTp *intp)
+static void vfio_enable_intp_kvm(VFIOPlatformDevice *vdev, VFIOINTp *intp)
 {
 #ifdef CONFIG_KVM
+    int argsz, ret;
+    struct vfio_irq_set *irq_set;
+    uint32_t *efd;
+
     struct kvm_irqfd irqfd = {
         .fd = event_notifier_get_fd(&intp->interrupt),
         .gsi = intp->virtualID,
@@ -476,10 +469,27 @@ static void vfio_enable_intp_kvm(VFIOINTp *intp)
         goto fail;
     }
 
+    argsz = sizeof(*irq_set) + sizeof(*efd);
+
+    irq_set = g_malloc0(argsz);
+    irq_set->argsz = argsz;
+    irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_UNMASK;
+    irq_set->index = intp->pin;
+    irq_set->start = 0;
+    irq_set->count = 1;
+
     /* KVM triggers it, VFIO listens for it */
     irqfd.resamplefd = event_notifier_get_fd(&intp->unmask);
-    qemu_set_fd_handler(irqfd.resamplefd, resampler_handler, NULL, intp);
+    efd = (uint32_t *)&irq_set->data;
+
+    *efd = irqfd.resamplefd;
 
+    ret = ioctl(vdev->vdev.fd, VFIO_DEVICE_SET_IRQS, irq_set);
+    g_free(irq_set);
+    if (ret) {
+        error_report("vfio: Error: Failed to setup interrupt unmask fd: %m");
+        goto fail_irqfd;
+    }
 
     if (kvm_vm_ioctl(kvm_state, KVM_IRQFD, &irqfd)) {
         error_report("vfio: Error: Failed to setup resample irqfd: %m");
@@ -508,7 +518,7 @@ void vfio_setup_irqfd(SysBusDevice *s, int index, int virq)
     QLIST_FOREACH(intp, &vdev->intp_list, next) {
         if (intp->pin == index) {
             intp->virtualID = virq;
-            vfio_enable_intp_kvm(intp);
+            vfio_enable_intp_kvm(vdev, intp);
         }
     }
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-06-23 14:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-23 14:54 [Qemu-devel] [RFC PATCH v3 0/4] AMBA platform device passthrough Alvise Rigo
2014-06-23 14:54 ` [Qemu-devel] [RFC PATCH v3 1/4] Add AMBA devices support to VFIO Alvise Rigo
2014-06-23 14:54 ` [Qemu-devel] [RFC PATCH v3 2/4] vfio: Add irqfd support in platform device Alvise Rigo
2014-06-23 14:54 ` [Qemu-devel] [RFC PATCH v3 3/4] Force eventfd as notifying mechanism for VFIO Alvise Rigo
2014-06-23 14:54 ` [Qemu-devel] [RFC PATCH v3 4/4] Let VFIO handle the unmasking of interrupts at EOI Alvise Rigo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).