From patchwork Tue Sep 9 07:31:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 37037 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f200.google.com (mail-ig0-f200.google.com [209.85.213.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 725BD20C93 for ; Tue, 9 Sep 2014 07:32:02 +0000 (UTC) Received: by mail-ig0-f200.google.com with SMTP id uq10sf75943379igb.7 for ; Tue, 09 Sep 2014 00:32:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=4mBYpq+kxqVlbqr9hCoL79ge/Or5kurRukXC8JnmiZE=; b=AvSOTnzj9zx1yjHrznA5vfpVYZ0LmSoBJAPkKHcP2wq/s2x7n8H63k1Cmh4hqt/hZH aFvzx/OZsto0GRnef5Zg5MSqGB1deS4N9Iw9rSvBlUy2rrN+aLQDBQJl0emMt719l2HZ VH4nKWhboek7fN+Y/FRN7E4z86YZxBNt3vBpH23gg11bZdoDxI/Ns1aH9GMuVZRdvu8t +hEnvjNM9jhlg4t9sW/g7KNKJGBtGyu7FRPHsuBpd0Jp1AIB8DWNPbmsB6uvnMIBLbyJ daf8VbeAIOXn7E7jmQSqAPPt6Y3lt6mXIpYkNr+1QuXaMVq6Dlo/vU69ntk5UodcoG3m JFxg== X-Gm-Message-State: ALoCoQmvKFIPu15qrjveDnr2SwiwW2znMEbn9r5fOxGqgSbh0toE/ZPNNPxWXnAReAw1N5Cy7Zop X-Received: by 10.42.188.210 with SMTP id db18mr18218991icb.9.1410247922077; Tue, 09 Sep 2014 00:32:02 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.95.50 with SMTP id h47ls2017491qge.43.gmail; Tue, 09 Sep 2014 00:32:02 -0700 (PDT) X-Received: by 10.220.88.76 with SMTP id z12mr2620848vcl.14.1410247921987; Tue, 09 Sep 2014 00:32:01 -0700 (PDT) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id xe15si5485996vdc.85.2014.09.09.00.32.01 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Sep 2014 00:32:01 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id la4so523601vcb.21 for ; Tue, 09 Sep 2014 00:32:01 -0700 (PDT) X-Received: by 10.52.149.209 with SMTP id uc17mr567921vdb.65.1410247921910; Tue, 09 Sep 2014 00:32:01 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp244059vcb; Tue, 9 Sep 2014 00:32:01 -0700 (PDT) X-Received: by 10.194.95.234 with SMTP id dn10mr41142612wjb.73.1410247920897; Tue, 09 Sep 2014 00:32:00 -0700 (PDT) Received: from mail-wg0-f42.google.com (mail-wg0-f42.google.com [74.125.82.42]) by mx.google.com with ESMTPS id k1si16104386wja.119.2014.09.09.00.32.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Sep 2014 00:32:00 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 74.125.82.42 as permitted sender) client-ip=74.125.82.42; Received: by mail-wg0-f42.google.com with SMTP id x12so4229088wgg.25 for ; Tue, 09 Sep 2014 00:32:00 -0700 (PDT) X-Received: by 10.180.87.231 with SMTP id bb7mr28841406wib.63.1410247920498; Tue, 09 Sep 2014 00:32:00 -0700 (PDT) Received: from midway01-04-00.lavalab ([88.98.47.97]) by mx.google.com with ESMTPSA id s1sm14513743wiw.6.2014.09.09.00.31.59 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Sep 2014 00:31:59 -0700 (PDT) From: Eric Auger 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: eric.auger@linaro.org, kvmarm@lists.cs.columbia.edu, patches@linaro.org, will.deacon@arm.com, Bharat.Bhushan@freescale.com, stuart.yoder@freescale.com, a.motakis@virtualopensystems.com, alex.williamson@redhat.com Subject: [PATCH v6 12/16] vfio/platform: add fake injection modality Date: Tue, 9 Sep 2014 08:31:12 +0100 Message-Id: <1410247876-4967-13-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1410247876-4967-1-git-send-email-eric.auger@linaro.org> References: <1410247876-4967-1-git-send-email-eric.auger@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 --- 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