From patchwork Fri Feb 13 03:47:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 44652 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3260021527 for ; Fri, 13 Feb 2015 03:47:41 +0000 (UTC) Received: by mail-wi0-f198.google.com with SMTP id h11sf5060111wiw.1 for ; Thu, 12 Feb 2015 19:47:40 -0800 (PST) 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=Li70OECVznPTJTMrltNA/wNJDpaPSLXdgvhFqn9nrs4=; b=TQ2mE/0MuBkFSfefV50aKjmSqSrdfcSH9oUowb1M7xS94tUsDY1UqvfuUJg1ukAObB fyesO8qmtJr8xc12gd6AN/A3iIJuMDP1Ha+mPOaL0iFjOPkFDPCd7irHtqthaaTnE1Hp atEO7iMWMOWaJ+BEbFjs27UnPNL9aLyem9txL+UQF7E0sRoAkcbkQfNJmiL4NZ4cASWx urGEQcXYtopWNM1vvdzRkmAGYs0hK2kjkMvQsJ6J3yXLe0jVESE9/BYHw6Q3HSK7ar1r oFA+cLZKwIYSK7pYa9iIjEArocO+beFClR/gfO1bnYxs7B3R03gt6RG1qyxFp4kzrAb3 c9yQ== X-Gm-Message-State: ALoCoQlrIArVTwfRQznRfhFihq8seOXSUxmM/ZJS869uvM6UDiEtOMs2HTPrGBvRfuv99opmzZL3 X-Received: by 10.112.45.197 with SMTP id p5mr1050951lbm.18.1423799260273; Thu, 12 Feb 2015 19:47:40 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.246.11 with SMTP id xs11ls270052lac.54.gmail; Thu, 12 Feb 2015 19:47:40 -0800 (PST) X-Received: by 10.112.13.38 with SMTP id e6mr6107127lbc.31.1423799260136; Thu, 12 Feb 2015 19:47:40 -0800 (PST) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id o6si305134lao.176.2015.02.12.19.47.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Feb 2015 19:47:40 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by labge10 with SMTP id ge10so13861259lab.12 for ; Thu, 12 Feb 2015 19:47:40 -0800 (PST) X-Received: by 10.112.14.196 with SMTP id r4mr2599313lbc.86.1423799259972; Thu, 12 Feb 2015 19:47:39 -0800 (PST) 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.35.133 with SMTP id h5csp824282lbj; Thu, 12 Feb 2015 19:47:39 -0800 (PST) X-Received: by 10.194.175.202 with SMTP id cc10mr13915649wjc.27.1423799256261; Thu, 12 Feb 2015 19:47:36 -0800 (PST) Received: from mail-wg0-f48.google.com (mail-wg0-f48.google.com. [74.125.82.48]) by mx.google.com with ESMTPS id h4si1622108wiz.79.2015.02.12.19.47.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Feb 2015 19:47:36 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 74.125.82.48 as permitted sender) client-ip=74.125.82.48; Received: by mail-wg0-f48.google.com with SMTP id l18so11064238wgh.7 for ; Thu, 12 Feb 2015 19:47:36 -0800 (PST) X-Received: by 10.194.84.176 with SMTP id a16mr13502987wjz.113.1423799255943; Thu, 12 Feb 2015 19:47:35 -0800 (PST) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id fw5sm8222550wjb.14.2015.02.12.19.47.35 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 12 Feb 2015 19:47:35 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, christoffer.dall@linaro.org, qemu-devel@nongnu.org, alex.williamson@redhat.com, peter.maydell@linaro.org, agraf@suse.de, b.reynal@virtualopensystems.com, feng.wu@intel.com Cc: kvmarm@lists.cs.columbia.edu, patches@linaro.org, pbonzini@redhat.com, afaerber@suse.de, kim.phillips@freescale.com, Bharat.Bhushan@freescale.com, a.rigo@virtualopensystems.com, a.motakis@virtualopensystems.com Subject: [PATCH v10 7/7] hw/vfio/platform: add irqfd support Date: Fri, 13 Feb 2015 03:47:12 +0000 Message-Id: <1423799232-10816-8-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1423799232-10816-1-git-send-email-eric.auger@linaro.org> References: <1423799232-10816-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.53 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 Reviewed-by: Alex Bennée --- 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 | 104 +++++++++++++++++++++++++++++++++++++++- include/hw/vfio/vfio-platform.h | 1 + trace-events | 2 + 3 files changed, 106 insertions(+), 1 deletion(-) diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index 30798d8..cadc824 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -26,6 +26,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); @@ -237,6 +238,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 */ @@ -315,6 +393,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); @@ -409,7 +494,6 @@ static VFIODeviceOps vfio_platform_ops = { .vfio_compute_needs_reset = vfio_platform_compute_needs_reset, .vfio_hot_reset_multi = vfio_platform_hot_reset_multi, .vfio_eoi = vfio_platform_eoi, - .vfio_populate_device = vfio_populate_device, }; /** @@ -481,6 +565,13 @@ static int vfio_base_device_init(VFIODevice *vbasedev) error_report("vfio: failed to get device %s", path); vfio_put_group(group); } + + ret = vfio_populate_device(vbasedev); + if (ret) { + error_report("vfio: failed to populate device %s", path); + vfio_put_group(group); + } + return ret; } @@ -536,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); @@ -614,6 +715,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 bd1206e..097448b 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 d3685c9..7a6a6aa 100644 --- a/trace-events +++ b/trace-events @@ -1567,6 +1567,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