From patchwork Fri Oct 31 14:05:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 39911 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 98545202FE for ; Fri, 31 Oct 2014 14:06:32 +0000 (UTC) Received: by mail-wg0-f69.google.com with SMTP id l18sf659904wgh.8 for ; Fri, 31 Oct 2014 07:06:31 -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=Ufuivm5Zstw/Zz+jOTsa9SKfkGqwIDXm2ACxmhsBu7o=; b=gm1DpwAfaa6sdvV7z/v14OSEKhemS/Hm7lYLvu1vIOfKBAi8+s5QSgV/jfMDgCxCOX y5OxUdbmmA8e1H5WP5z+VPl0c4frbbpBOuVLhJRsH5hbe5JMLXTV3v6uZJ3GH7bEuZiD gWWOpsAK9Ed+bK9OnlbhQZQtkCDXH4Hk+bYWobMgG9Fu8RUQgKU4fbid3i3cnqGprgE/ +2IP4jHIRD777LPKuehvD8UStBRXVGgVXa/gymxWE+YVBD2TF13PiRqmb/9vhkolUUZX f+GX++mKS3L7HM2zPYzSqCrPJOzBoFDi5bGv/kxFVOC1/oENWUl+oKo7qlMy9r46OcRW mtsw== X-Gm-Message-State: ALoCoQlHfFPQQKLBtY3zHGUUe5JLAPOIVpVjZw5hod4NZpBW+6sYcWDKAgU2s4z/absZznnZiZX0 X-Received: by 10.180.19.226 with SMTP id i2mr676561wie.5.1414764391706; Fri, 31 Oct 2014 07:06:31 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.199.38 with SMTP id jh6ls473872lac.9.gmail; Fri, 31 Oct 2014 07:06:31 -0700 (PDT) X-Received: by 10.152.203.139 with SMTP id kq11mr26785234lac.63.1414764391514; Fri, 31 Oct 2014 07:06:31 -0700 (PDT) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com. [209.85.215.41]) by mx.google.com with ESMTPS id du3si16894207lbc.32.2014.10.31.07.06.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Oct 2014 07:06:31 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by mail-la0-f41.google.com with SMTP id s18so1685324lam.14 for ; Fri, 31 Oct 2014 07:06:31 -0700 (PDT) X-Received: by 10.112.77.74 with SMTP id q10mr26280622lbw.66.1414764391398; Fri, 31 Oct 2014 07:06:31 -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.112.84.229 with SMTP id c5csp207553lbz; Fri, 31 Oct 2014 07:06:30 -0700 (PDT) X-Received: by 10.181.8.72 with SMTP id di8mr4336310wid.1.1414764389897; Fri, 31 Oct 2014 07:06:29 -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 b10si26659363wiy.74.2014.10.31.07.06.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Oct 2014 07:06:29 -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 k14so6647677wgh.15 for ; Fri, 31 Oct 2014 07:06:29 -0700 (PDT) X-Received: by 10.194.239.196 with SMTP id vu4mr2386675wjc.4.1414764389637; Fri, 31 Oct 2014 07:06:29 -0700 (PDT) Received: from midway01-04-00.lavalab ([88.98.47.97]) by mx.google.com with ESMTPSA id v10sm12504563wiy.23.2014.10.31.07.06.28 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Oct 2014 07:06:28 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, christoffer.dall@linaro.org, qemu-devel@nongnu.org, agraf@suse.de, pbonzini@redhat.com, kim.phillips@freescale.com, a.rigo@virtualopensystems.com, manish.jaggi@caviumnetworks.com, joel.schopp@amd.com Cc: eric.auger@linaro.org, kvmarm@lists.cs.columbia.edu, patches@linaro.org, alex.williamson@redhat.com, peter.maydell@linaro.org, will.deacon@arm.com, Bharat.Bhushan@freescale.com, stuart.yoder@freescale.com, a.motakis@virtualopensystems.com Subject: [PATCH v7 13/16] hw/vfio/platform: Add irqfd support Date: Fri, 31 Oct 2014 14:05:47 +0000 Message-Id: <1414764350-5140-14-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1414764350-5140-1-git-send-email-eric.auger@linaro.org> References: <1414764350-5140-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.215.41 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 patch aims at optimizing IRQ handling using irqfd framework. Instead of handling the eventfds on user-side they are handled on kernel side using - the KVM irqfd framework, - the VFIO driver virqfd framework. the virtual IRQ completion is trapped at interrupt controller This removes the need for fast/slow path swap. Overall this brings significant performance improvements. it depends on host kernel KVM irqfd. Signed-off-by: Alvise Rigo Signed-off-by: Eric Auger --- v5 -> v6 - rely on kvm_irqfds_enabled() and kvm_resamplefds_enabled() - guard KVM code with #ifdef CONFIG_KVM v3 -> v4: [Alvise Rigo] Use of VFIO Platform driver v6 unmask/virqfd feature and removal of resamplefd handler. Physical IRQ unmasking is now done in VFIO driver. v3: [Eric Auger] initial support with resamplefd handled on QEMU side since the unmask was not supported on VFIO platform driver v5. Conflicts: hw/vfio/platform.c --- hw/vfio/platform.c | 96 +++++++++++++++++++++++++++++++++++++++++ include/hw/vfio/vfio-platform.h | 1 + trace-events | 2 + 3 files changed, 99 insertions(+) diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index 9f66610..bdd5c93 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -25,6 +25,7 @@ #include "hw/sysbus.h" #include "trace.h" #include "hw/platform-bus.h" +#include "sysemu/kvm.h" static void vfio_intp_interrupt(VFIOINTp *intp); typedef void (*eventfd_user_side_handler_t)(VFIOINTp *intp); @@ -236,6 +237,83 @@ static int vfio_start_eventfd_injection(VFIOINTp *intp) } /* + * Functions used for irqfd + */ + +#ifdef CONFIG_KVM + +/** + * vfio_set_resample_eventfd - sets the resamplefd for an IRQ + * @intp: the IRQ struct pointer + * programs the VFIO driver to unmask this IRQ when the + * intp->unmask eventfd is triggered + */ +static int vfio_set_resample_eventfd(VFIOINTp *intp) +{ + 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_EVENTFD | VFIO_IRQ_SET_ACTION_UNMASK; + irq_set->index = intp->pin; + irq_set->start = 0; + irq_set->count = 1; + pfd = (int32_t *)&irq_set->data; + *pfd = event_notifier_get_fd(&intp->unmask); + qemu_set_fd_handler(*pfd, NULL, NULL, intp); + ret = ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, irq_set); + g_free(irq_set); + if (ret < 0) { + error_report("vfio: Failed to set resample eventfd: %m"); + qemu_set_fd_handler(*pfd, NULL, NULL, NULL); + } + return ret; +} + +/** + * vfio_start_irqfd_injection - starts irqfd injection for an IRQ + * programs VFIO driver with both the trigger and resamplefd + * programs KVM with the gsi, trigger & resample eventfds + */ +static int vfio_start_irqfd_injection(VFIOINTp *intp) +{ + struct kvm_irqfd irqfd = { + .fd = event_notifier_get_fd(&intp->interrupt), + .resamplefd = event_notifier_get_fd(&intp->unmask), + .gsi = intp->virtualID, + .flags = KVM_IRQFD_FLAG_RESAMPLE, + }; + + if (kvm_vm_ioctl(kvm_state, KVM_IRQFD, &irqfd)) { + error_report("vfio: Error: Failed to assign the irqfd: %m"); + goto fail_irqfd; + } + if (vfio_set_trigger_eventfd(intp, NULL) < 0) { + goto fail_vfio; + } + if (vfio_set_resample_eventfd(intp) < 0) { + goto fail_vfio; + } + + intp->kvm_accel = true; + trace_vfio_platform_start_irqfd_injection(intp->pin, intp->virtualID, + irqfd.fd, irqfd.resamplefd); + return 0; + +fail_vfio: + irqfd.flags = KVM_IRQFD_FLAG_DEASSIGN; + kvm_vm_ioctl(kvm_state, KVM_IRQFD, &irqfd); +fail_irqfd: + return -1; +} + +#endif + +/* * Functions used whatever the injection method */ @@ -314,6 +392,13 @@ static VFIOINTp *vfio_init_intp(VFIODevice *vbasedev, unsigned int index) error_report("vfio: Error: trigger event_notifier_init failed "); return NULL; } + /* Get an eventfd for resample/unmask */ + ret = event_notifier_init(&intp->unmask, 0); + if (ret) { + g_free(intp); + error_report("vfio: Error: resample event_notifier_init failed eoi"); + return NULL; + } /* store the new intp in qlist */ QLIST_INSERT_HEAD(&vdev->intp_list, intp, next); @@ -542,7 +627,17 @@ static void vfio_platform_realize(DeviceState *dev, Error **errp) vbasedev->type = VFIO_DEVICE_TYPE_PLATFORM; vbasedev->ops = &vfio_platform_ops; + +#ifdef CONFIG_KVM + if (kvm_irqfds_enabled() && kvm_resamplefds_enabled() && + vdev->irqfd_allowed) { + vdev->start_irq_fn = vfio_start_irqfd_injection; + } else { + vdev->start_irq_fn = vfio_start_eventfd_injection; + } +#else vdev->start_irq_fn = vfio_start_eventfd_injection; +#endif trace_vfio_platform_realize(vbasedev->name, vdev->compat); @@ -641,6 +736,7 @@ static Property vfio_platform_dev_properties[] = { DEFINE_PROP_STRING("host", VFIOPlatformDevice, vbasedev.name), DEFINE_PROP_UINT32("mmap-timeout-ms", VFIOPlatformDevice, mmap_timeout, 1100), + DEFINE_PROP_BOOL("x-irqfd", VFIOPlatformDevice, irqfd_allowed, true), DEFINE_PROP_END_OF_LIST(), }; diff --git a/include/hw/vfio/vfio-platform.h b/include/hw/vfio/vfio-platform.h index 18e6807..26ddba7 100644 --- a/include/hw/vfio/vfio-platform.h +++ b/include/hw/vfio/vfio-platform.h @@ -58,6 +58,7 @@ typedef struct VFIOPlatformDevice { QEMUTimer *mmap_timer; /* enable mmaps after periods w/o interrupts */ start_irq_fn_t start_irq_fn; QemuMutex intp_mutex; + bool irqfd_allowed; /* debug option to force irqfd on/off */ } VFIOPlatformDevice; diff --git a/trace-events b/trace-events index 54d998c..a05ed80 100644 --- a/trace-events +++ b/trace-events @@ -1439,6 +1439,8 @@ 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_platform_eoi_handle_pending(int index) "handle PENDING IRQ %d" +vfio_platform_start_irqfd_injection(int index, int gsi, int fd, int resamplefd) "IRQ index=%d, gsi =%d, fd = %d, resamplefd = %d" +vfio_start_eventfd_injection(int index, int fd) "IRQ index=%d, fd = %d" #hw/acpi/memory_hotplug.c mhp_acpi_invalid_slot_selected(uint32_t slot) "0x%"PRIx32