From patchwork Tue Sep 9 07:31:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 37038 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f69.google.com (mail-qa0-f69.google.com [209.85.216.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7723C20491 for ; Tue, 9 Sep 2014 07:32:04 +0000 (UTC) Received: by mail-qa0-f69.google.com with SMTP id x12sf20459qac.8 for ; Tue, 09 Sep 2014 00:32:04 -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=v7ep2VBmGzdSgMLvWMgT3eW49S+xIseSt7gxULniqr0=; b=KUHETtBc+POmSki0GPDmqueKDZAYBHe9yey9mG7WaXSLbM2OnPq0YPLIXYAYst3cT6 N4vL9HLKO5++Mfun7df5GTOtQoxn6sHWzYS5z266RZlFw8Oy2HpICDc130Cj8yAdT0rv 6jndpPnoLUp0Bm+eU2/x9qy8ZyYR7xjlvgQQw1R76988CcKnZZWNkWd9+LZ+8lGSgp5j hJEgecSIHRj9kPiAq9NX6XaUl7+yU+Zej2Na43AGQre/VGU/ng04uToUJDBorny8+3zk T260KgkmCxOLteLl429V0bWtb7K8Pp0Mkupom5ij1x2hmUbHVhBPgAmxbQ+Qq8JCqsVU 2lEw== X-Gm-Message-State: ALoCoQl5qQuuIuyITMUzg4wDKOC9thHC6xsocfX1RJDyv3sZqk/jYfT5T2T1B7LETPHFKyBVypui X-Received: by 10.236.150.170 with SMTP id z30mr15304yhj.58.1410247924345; Tue, 09 Sep 2014 00:32:04 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.40.180 with SMTP id x49ls1986282qgx.97.gmail; Tue, 09 Sep 2014 00:32:04 -0700 (PDT) X-Received: by 10.220.44.136 with SMTP id a8mr4668478vcf.42.1410247924253; Tue, 09 Sep 2014 00:32:04 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id be5si5537157vdb.37.2014.09.09.00.32.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Sep 2014 00:32:04 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id lf12so16411073vcb.20 for ; Tue, 09 Sep 2014 00:32:04 -0700 (PDT) X-Received: by 10.52.116.132 with SMTP id jw4mr2611498vdb.42.1410247924176; Tue, 09 Sep 2014 00:32:04 -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 uj3csp244060vcb; Tue, 9 Sep 2014 00:32:03 -0700 (PDT) X-Received: by 10.180.160.229 with SMTP id xn5mr28435921wib.64.1410247923139; Tue, 09 Sep 2014 00:32:03 -0700 (PDT) Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com [209.85.212.175]) by mx.google.com with ESMTPS id n5si16183975wja.61.2014.09.09.00.32.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Sep 2014 00:32:03 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.175 as permitted sender) client-ip=209.85.212.175; Received: by mail-wi0-f175.google.com with SMTP id ex7so3739389wid.8 for ; Tue, 09 Sep 2014 00:32:02 -0700 (PDT) X-Received: by 10.194.173.234 with SMTP id bn10mr40842620wjc.81.1410247922730; Tue, 09 Sep 2014 00:32:02 -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.32.01 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Sep 2014 00:32:01 -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 13/16] hw/vfio/platform: Add irqfd support Date: Tue, 9 Sep 2014 08:31:13 +0100 Message-Id: <1410247876-4967-14-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.175 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. --- 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 93aa94a..a59a842 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -24,6 +24,7 @@ #include "qemu/queue.h" #include "hw/sysbus.h" #include "trace.h" +#include "sysemu/kvm.h" #define MAX_FAKE_INTP 5 @@ -323,6 +324,83 @@ static void vfio_fake_intp_injection(void *opaque) } /* + * 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 */ @@ -418,6 +496,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); @@ -660,7 +745,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); @@ -694,6 +789,7 @@ static Property vfio_platform_dev_properties[] = { qdev_prop_uint32, uint32_t), 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 95ece9d..e896c86 100644 --- a/include/hw/vfio/vfio-platform.h +++ b/include/hw/vfio/vfio-platform.h @@ -71,6 +71,7 @@ typedef struct VFIOPlatformDevice { uint32_t len_x_fake_irq; uint32_t len_x_fake_period; uint32_t len_x_fake_duration; + bool irqfd_allowed; /* debug option to force irqfd on/off */ } VFIOPlatformDevice; diff --git a/trace-events b/trace-events index 61f3cba..1b81b66 100644 --- a/trace-events +++ b/trace-events @@ -1391,6 +1391,8 @@ 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" +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