qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Auger <eric.auger@linaro.org>
To: eric.auger@st.com, christoffer.dall@linaro.org,
	qemu-devel@nongnu.org, a.rigo@virtualopensystems.com,
	kim.phillips@freescale.com, marc.zyngier@arm.com,
	manish.jaggi@caviumnetworks.com, joel.schopp@amd.com,
	agraf@suse.de, peter.maydell@linaro.org, pbonzini@redhat.com,
	afaerber@suse.de
Cc: patches@linaro.org, eric.auger@linaro.org, will.deacon@arm.com,
	stuart.yoder@freescale.com, Bharat.Bhushan@freescale.com,
	alex.williamson@redhat.com, a.motakis@virtualopensystems.com,
	kvmarm@lists.cs.columbia.edu
Subject: [Qemu-devel] [PATCH v6 12/16] vfio/platform: add fake injection modality
Date: Tue,  9 Sep 2014 08:31:12 +0100	[thread overview]
Message-ID: <1410247876-4967-13-git-send-email-eric.auger@linaro.org> (raw)
In-Reply-To: <1410247876-4967-1-git-send-email-eric.auger@linaro.org>

This code is aimed at testing multiple IRQ injection with
user-side handled eventfds. Principle is a timer periodically
triggers an IRQ at VFIO driver level. Then this IRQ follows
regular VFIO driver -> eventfd trigger -> user-side eventfd handler.
The IRQ is not injected into the guest. the IRQ is completed
on another timer timeout to emulate eoi on write/read access.

for instance, following options
 x-fake-irq[0]=1,x-fake-period[0]=10,x-fake-duration[0]=50,
x-fake-irq[1]=2,x-fake-period[i]=20,x-fake-duration[1]=100
set vfio platform IRQ indexed #1 and #2 as fake IRQ

Signed-off-by: Eric Auger <eric.auger@linaro.org>

---

this modality was used to test calxeda xgmac assignment with
main IRQ generated by the HW and IRQ #1 and #2 as fake IRQs
---
 hw/vfio/platform.c              | 131 +++++++++++++++++++++++++++++++++++++++-
 include/hw/vfio/vfio-platform.h |  13 ++++
 trace-events                    |   3 +
 3 files changed, 145 insertions(+), 2 deletions(-)

diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
index 9987b25..93aa94a 100644
--- a/hw/vfio/platform.c
+++ b/hw/vfio/platform.c
@@ -25,6 +25,8 @@
 #include "hw/sysbus.h"
 #include "trace.h"
 
+#define MAX_FAKE_INTP 5
+
 static void vfio_intp_interrupt(VFIOINTp *intp);
 typedef void (*eventfd_user_side_handler_t)(VFIOINTp *intp);
 static int vfio_set_trigger_eventfd(VFIOINTp *intp,
@@ -141,6 +143,27 @@ static void vfio_intp_mmap_enable(void *opaque)
 }
 
 /**
+ * vfio_fake_intp_index - returns the fake IRQ index
+ *
+ * @intp the interrupt struct pointer
+ * if the IRQ is not fake, returns < 0
+ * if it is fake returns the index of the fake IRQ
+ * ie the index i for which x-fake-irq[i]=intp->pin
+ */
+static int vfio_fake_intp_index(VFIOINTp *intp)
+{
+    VFIOPlatformDevice *vdev = intp->vdev;
+    int i;
+
+    for (i = 0; i < MAX_FAKE_INTP; i++) {
+        if (intp->pin == vdev->fake_intp_index[i]) {
+            return i;
+        }
+    }
+    return -1;
+}
+
+/**
  * vfio_intp_interrupt - The user-side eventfd handler
  * @opaque: opaque pointer which in practice is the VFIOINTp*
  *
@@ -199,8 +222,18 @@ static void vfio_intp_interrupt(VFIOINTp *intp)
     /* sets slow path */
     vfio_mmap_set_enabled(vdev, false);
 
-    /* trigger the virtual IRQ */
-    qemu_set_irq(intp->qemuirq, 1);
+    if (intp->fake_intp_index < 0) {
+        /* trigger the virtual IRQ */
+        qemu_set_irq(intp->qemuirq, 1);
+    } else {
+        /*
+         * the vIRQ is not triggered but we emulate a handling
+         * duration
+         */
+        timer_mod(intp->fake_eoi_timer,
+                  qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +
+                      intp->fake_intp_duration);
+    }
 
     /* schedule the mmap timer which will restore mmap path after EOI*/
     if (vdev->mmap_timeout) {
@@ -231,9 +264,64 @@ static int vfio_start_eventfd_injection(VFIOINTp *intp)
         return ret;
     }
     vfio_unmask_irqindex(vbasedev, intp->pin);
+
+    /* in case of fake irq, starts its injection */
+    if (intp->fake_intp_index >= 0) {
+        timer_mod(intp->fake_intp_timer,
+                  qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +
+                  intp->fake_intp_period);
+    }
     return 0;
 }
 
+/**
+ * vfio_fake_intp_eoi - fake interrupt completion routine
+ * @opaque: actually is an IRQ struct pointer
+ *
+ * called on timer handler context
+ */
+static void vfio_fake_intp_eoi(void *opaque)
+{
+    VFIOINTp *intp = (VFIOINTp *)opaque;
+    trace_vfio_fake_intp_eoi(intp->pin);
+    vfio_platform_eoi(&intp->vdev->vbasedev);
+}
+
+/**
+ * vfio_fake_intp_eoi - fake interrupt injection routine
+ * @opaque: actually is an IRQ struct pointer
+ *
+ * called on timer context
+ * use the VFIO loopback mode, ie. triggers the eventfd
+ * associated to the intp->pin although no physical IRQ hit.
+ */
+static void vfio_fake_intp_injection(void *opaque)
+{
+    VFIOINTp *intp = (VFIOINTp *)opaque;
+    VFIODevice *vbasedev = &intp->vdev->vbasedev;
+    struct vfio_irq_set *irq_set;
+    int argsz, ret;
+    int32_t *pfd;
+
+    argsz = sizeof(*irq_set) + sizeof(*pfd);
+    irq_set = g_malloc0(argsz);
+    irq_set->argsz = argsz;
+    irq_set->flags = VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_TRIGGER;
+    irq_set->index = intp->pin;
+    irq_set->start = 0;
+    irq_set->count = 1;
+    ret = ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, irq_set);
+    g_free(irq_set);
+    if (ret < 0) {
+        error_report("vfio: Failed to trigger fake IRQ: %m");
+    } else {
+        trace_vfio_fake_intp_injection(intp->pin);
+        timer_mod(intp->fake_intp_timer,
+                  qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +
+                      intp->fake_intp_period);
+    }
+}
+
 /*
  * Functions used whatever the injection method
  */
@@ -304,6 +392,23 @@ static VFIOINTp *vfio_init_intp(VFIODevice *vbasedev, unsigned int index)
     intp->vdev = vdev;
     intp->pin = index;
     intp->state = VFIO_IRQ_INACTIVE;
+    intp->fake_intp_index = vfio_fake_intp_index(intp);
+
+    if (intp->fake_intp_index >= 0) {
+        intp->fake_intp_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL,
+                                         vfio_fake_intp_injection,
+                                         intp);
+        intp->fake_eoi_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL,
+                                         vfio_fake_intp_eoi,
+                                         intp);
+        intp->fake_intp_period  =
+            vdev->fake_intp_period[intp->fake_intp_index];
+        intp->fake_intp_duration  =
+            vdev->fake_intp_duration[intp->fake_intp_index];
+        trace_vfio_init_intp_fake(intp->fake_intp_index,
+                                  intp->fake_intp_period,
+                                  intp->fake_intp_duration);
+    }
     sysbus_init_irq(sbdev, &intp->qemuirq);
 
     /* Get an eventfd for trigger */
@@ -524,6 +629,20 @@ static void vfio_map_region(VFIOPlatformDevice *vdev, int nr)
     }
 }
 
+static void vfio_platform_initfn(Object *obj)
+{
+    int i;
+
+    qdev_prop_set_uint32(DEVICE(obj), "len-x-fake-irq", MAX_FAKE_INTP);
+    qdev_prop_set_uint32(DEVICE(obj), "len-x-fake-period", MAX_FAKE_INTP);
+    qdev_prop_set_uint32(DEVICE(obj), "len-x-fake-duration", MAX_FAKE_INTP);
+
+    for (i = 0; i < MAX_FAKE_INTP; i++) {
+        char *propname = g_strdup_printf("x-fake-irq[%d]", i);
+        qdev_prop_set_uint32(DEVICE(obj), propname, -1);
+    }
+}
+
 /**
  * vfio_platform_realize  - the device realize function
  * @dev: device state pointer
@@ -566,6 +685,13 @@ static const VMStateDescription vfio_platform_vmstate = {
 static Property vfio_platform_dev_properties[] = {
     DEFINE_PROP_STRING("host", VFIOPlatformDevice, vbasedev.name),
     DEFINE_PROP_STRING("compat", VFIOPlatformDevice, compat),
+    DEFINE_PROP_ARRAY("x-fake-irq", VFIOPlatformDevice, len_x_fake_irq,
+                      fake_intp_index, qdev_prop_uint32, uint32_t),
+    DEFINE_PROP_ARRAY("x-fake-period", VFIOPlatformDevice, len_x_fake_period,
+                      fake_intp_period, qdev_prop_uint32, uint32_t),
+    DEFINE_PROP_ARRAY("x-fake-duration", VFIOPlatformDevice,
+                      len_x_fake_duration, fake_intp_duration,
+                      qdev_prop_uint32, uint32_t),
     DEFINE_PROP_UINT32("mmap-timeout-ms", VFIOPlatformDevice,
                        mmap_timeout, 1100),
     DEFINE_PROP_END_OF_LIST(),
@@ -587,6 +713,7 @@ static const TypeInfo vfio_platform_dev_info = {
     .parent = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(VFIOPlatformDevice),
     .class_init = vfio_platform_class_init,
+    .instance_init = vfio_platform_initfn,
     .class_size = sizeof(VFIOPlatformDeviceClass),
     .abstract   = true,
 };
diff --git a/include/hw/vfio/vfio-platform.h b/include/hw/vfio/vfio-platform.h
index c7e10cc..95ece9d 100644
--- a/include/hw/vfio/vfio-platform.h
+++ b/include/hw/vfio/vfio-platform.h
@@ -42,6 +42,12 @@ typedef struct VFIOINTp {
     bool kvm_accel; /* set when QEMU bypass through KVM enabled */
     uint8_t pin; /* index */
     uint8_t virtualID; /* virtual IRQ */
+    /* fake irq injection test modality */
+    int fake_intp_index;
+    QEMUTimer *fake_intp_timer; /* fake IRQ injection timer */
+    QEMUTimer *fake_eoi_timer; /* timer to handle fake IRQ completion */
+    uint32_t fake_intp_period; /* delay between fake IRQ injections */
+    uint32_t fake_intp_duration; /* duration of the IRQ */
 } VFIOINTp;
 
 typedef int (*start_irq_fn_t)(VFIOINTp *intp);
@@ -58,6 +64,13 @@ typedef struct VFIOPlatformDevice {
     QEMUTimer *mmap_timer; /* enable mmaps after periods w/o interrupts */
     start_irq_fn_t start_irq_fn;
     QemuMutex  intp_mutex;
+    /* fake irq injection test modality */
+    int32_t *fake_intp_index; /* array of fake IRQ indexes */
+    uint32_t *fake_intp_period; /* delay between fake IRQ injections */
+    uint32_t *fake_intp_duration; /* duration of the vIRQ handling*/
+    uint32_t len_x_fake_irq;
+    uint32_t len_x_fake_period;
+    uint32_t len_x_fake_duration;
 } VFIOPlatformDevice;
 
 
diff --git a/trace-events b/trace-events
index b0411e9..61f3cba 100644
--- a/trace-events
+++ b/trace-events
@@ -1387,7 +1387,10 @@ vfio_platform_populate_regions(int region_index, unsigned long flag, unsigned lo
 vfio_platform_base_device_init(char *name, int groupid) "%s belongs to group #%d"
 vfio_platform_realize(char *name, char *compat) "vfio device %s, compat = %s"
 vfio_intp_interrupt_set_pending(int index) "irq %d is set PENDING"
+vfio_fake_intp_injection(int index) "fake irq %d injected"
 vfio_platform_eoi_handle_pending(int index) "handle PENDING IRQ %d"
+vfio_fake_intp_eoi(int index) "eoi fake IRQ %d"
+vfio_init_intp_fake(int index, int period, int duration) "fake irq index = %d, duration = %d, period=%d"
 
 #hw/acpi/memory_hotplug.c
 mhp_acpi_invalid_slot_selected(uint32_t slot) "0x%"PRIx32
-- 
1.8.3.2

  parent reply	other threads:[~2014-09-09  7:32 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-09  7:31 [Qemu-devel] [PATCH v6 00/16] KVM platform device passthrough Eric Auger
2014-09-09  7:31 ` [Qemu-devel] [PATCH v6 01/16] vfio: move hw/misc/vfio.c to hw/vfio/pci.c Move vfio.h into include/hw/vfio Eric Auger
2014-09-09  7:31 ` [Qemu-devel] [PATCH v6 02/16] hw/vfio/pci: Rename VFIODevice into VFIOPCIDevice Eric Auger
2014-09-09  7:31 ` [Qemu-devel] [PATCH v6 03/16] hw/vfio/pci: introduce VFIODevice Eric Auger
2014-09-09  7:31 ` [Qemu-devel] [PATCH v6 04/16] hw/vfio/pci: Introduce VFIORegion Eric Auger
2014-09-09  7:31 ` [Qemu-devel] [PATCH v6 05/16] hw/vfio/pci: split vfio_get_device Eric Auger
2014-09-09  7:31 ` [Qemu-devel] [PATCH v6 06/16] hw/vfio/pci: rename group_list into vfio_group_list Eric Auger
2014-09-09  7:31 ` [Qemu-devel] [PATCH v6 07/16] hw/vfio/pci: use name field in format strings Eric Auger
2014-09-09  7:31 ` [Qemu-devel] [PATCH v6 08/16] hw/vfio: create common module Eric Auger
2014-09-10 13:09   ` Alexander Graf
2014-09-11 12:11     ` Eric Auger
2014-09-11 12:13       ` Alexander Graf
2014-09-11 14:21         ` Eric Auger
2014-09-09  7:31 ` [Qemu-devel] [PATCH v6 09/16] hw/vfio/platform: add vfio-platform support Eric Auger
2014-09-09  7:31 ` [Qemu-devel] [PATCH v6 10/16] hw/vfio: calxeda xgmac device Eric Auger
2014-09-09  7:31 ` [Qemu-devel] [PATCH v6 11/16] hw/arm/dyn_sysbus_devtree: enable vfio-calxeda-xgmac dynamic instantiation Eric Auger
2014-09-10 13:12   ` Alexander Graf
2014-09-11 14:20     ` Eric Auger
2014-09-09  7:31 ` Eric Auger [this message]
2014-09-09  7:31 ` [Qemu-devel] [PATCH v6 13/16] hw/vfio/platform: Add irqfd support Eric Auger
2014-09-09  7:31 ` [Qemu-devel] [PATCH v6 14/16] linux-headers: Update KVM headers from linux-next tag ToBeFilled Eric Auger
2014-09-09  7:31 ` [Qemu-devel] [PATCH v6 15/16] VFIO: COMMON: vfio_kvm_device_fd moved in the common header Eric Auger
2014-09-09  7:31 ` [Qemu-devel] [PATCH v6 16/16] VFIO: PLATFORM: add forwarded irq support Eric Auger
2014-09-11 22:14 ` [Qemu-devel] [PATCH v6 00/16] KVM platform device passthrough Alex Williamson
2014-09-11 22:23   ` Christoffer Dall
2014-09-11 22:51     ` Alex Williamson
2014-09-11 23:05       ` Christoffer Dall
2014-09-15 22:01         ` Eric Auger
2014-09-16 20:51           ` Alex Williamson
2014-09-16 21:19             ` Eric Auger
2014-09-16 21:23             ` Alex Williamson
2014-09-19  0:29               ` Eric Auger

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=1410247876-4967-13-git-send-email-eric.auger@linaro.org \
    --to=eric.auger@linaro.org \
    --cc=Bharat.Bhushan@freescale.com \
    --cc=a.motakis@virtualopensystems.com \
    --cc=a.rigo@virtualopensystems.com \
    --cc=afaerber@suse.de \
    --cc=agraf@suse.de \
    --cc=alex.williamson@redhat.com \
    --cc=christoffer.dall@linaro.org \
    --cc=eric.auger@st.com \
    --cc=joel.schopp@amd.com \
    --cc=kim.phillips@freescale.com \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=manish.jaggi@caviumnetworks.com \
    --cc=marc.zyngier@arm.com \
    --cc=patches@linaro.org \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stuart.yoder@freescale.com \
    --cc=will.deacon@arm.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 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).