From patchwork Sun Nov 30 18:35:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 41742 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 54D9224001 for ; Sun, 30 Nov 2014 18:36:15 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id bs8sf5871747wib.6 for ; Sun, 30 Nov 2014 10:36:14 -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=/APtAz8Ih5plyiXOWDKt0TFJI3r+VB2gKF4OBDH134c=; b=mvA1O3LB3b7B3h/q4Bsu6VhMYLo+1vYBogbPAd0o5GHOcgtuPB/Oa/H3jAHigDwbPA ZqjrJ1pROv5uYQNhEZJs95OVdUOLiDqpiYz0hMwQoZj5e4pEomtlEIof1xot4ZlUW7FJ SZ4p1AOz8mMMuU3Bq0zK+mSg2r6/MfNYKfhTrkS13S6ZKMctI0TA2p+JdShQaUHtnkSG UXaYtd/h9uFJY2Jt16mfUyUruYRPjUy+s+QNhc3bpN2ngrE0l2I0NFl53C8b+xOh0hWN biBD37QSu14+81VX/XoS8LpVlwyZq+v1l9vPCo0WOxubDiBFD2Wd2ZhKOYaIJju1rGzr 1piA== X-Gm-Message-State: ALoCoQlJ0KTc2zp1XahXqKz8TX0+htQVJoddIo/3z64HRGsYs1dcbhmb+6RcIebwDJJjooik735U X-Received: by 10.152.5.2 with SMTP id o2mr11159909lao.1.1417372574472; Sun, 30 Nov 2014 10:36:14 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.234.104 with SMTP id ud8ls227245lac.36.gmail; Sun, 30 Nov 2014 10:36:14 -0800 (PST) X-Received: by 10.152.1.193 with SMTP id 1mr8381041lao.45.1417372574235; Sun, 30 Nov 2014 10:36:14 -0800 (PST) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id t10si1115549lae.38.2014.11.30.10.36.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 30 Nov 2014 10:36:14 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by mail-lb0-f169.google.com with SMTP id p9so7590818lbv.0 for ; Sun, 30 Nov 2014 10:36:14 -0800 (PST) X-Received: by 10.112.62.166 with SMTP id z6mr52010065lbr.74.1417372574156; Sun, 30 Nov 2014 10:36:14 -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.184.201 with SMTP id ew9csp172750lbc; Sun, 30 Nov 2014 10:36:13 -0800 (PST) X-Received: by 10.195.11.6 with SMTP id ee6mr88373375wjd.95.1417372573449; Sun, 30 Nov 2014 10:36:13 -0800 (PST) Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com. [209.85.212.171]) by mx.google.com with ESMTPS id jh3si27845872wid.46.2014.11.30.10.36.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 30 Nov 2014 10:36:13 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.171 as permitted sender) client-ip=209.85.212.171; Received: by mail-wi0-f171.google.com with SMTP id bs8so22563727wib.4 for ; Sun, 30 Nov 2014 10:36:13 -0800 (PST) X-Received: by 10.180.92.169 with SMTP id cn9mr78171451wib.26.1417372573164; Sun, 30 Nov 2014 10:36:13 -0800 (PST) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id z7sm38794058wia.22.2014.11.30.10.36.11 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 30 Nov 2014 10:36:12 -0800 (PST) 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, zhaoshenglong@huawei.com, ard.biesheuvel@linaro.org 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 v8 19/19] hw/vfio/platform: add forwarded irq support Date: Sun, 30 Nov 2014 18:35:24 +0000 Message-Id: <1417372524-12936-20-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1417372524-12936-1-git-send-email-eric.auger@linaro.org> References: <1417372524-12936-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.217.169 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: , Tests whether the forwarded IRQ modality is available. In the positive device IRQs are forwarded. This control is achieved with KVM-VFIO device. with such a modality injection still is handled through irqfds. However end of interrupt is not trapped anymore. As soon as the guest completes its virtual IRQ, the corresponding physical IRQ is completed and the same physical IRQ can hit again. A new x-forward property enables to force forwarding off although enabled by the kernel. Signed-off-by: Eric Auger --- hw/vfio/platform.c | 52 +++++++++++++++++++++++++++++++++++++++++ include/hw/vfio/vfio-platform.h | 2 ++ trace-events | 1 + 3 files changed, 55 insertions(+) diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index 97d98bf..7881b9b 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -237,6 +237,52 @@ static int vfio_start_eventfd_injection(VFIOINTp *intp) } /* + * Functions used with forwarding capability + */ + +#ifdef CONFIG_KVM + +static bool has_kvm_vfio_forward_capability(void) +{ + struct kvm_device_attr attr = { + .group = KVM_DEV_VFIO_DEVICE, + .attr = KVM_DEV_VFIO_DEVICE_FORWARD_IRQ}; + + if (ioctl(vfio_kvm_device_fd, KVM_HAS_DEVICE_ATTR, &attr) == 0) { + return true; + } else { + return false; + } +} + +static int vfio_set_forwarding(VFIOINTp *intp) +{ + int ret; + struct kvm_device_attr attr = { + .group = KVM_DEV_VFIO_DEVICE, + .attr = KVM_DEV_VFIO_DEVICE_FORWARD_IRQ}; + + intp->fwd_irq = g_malloc0(sizeof(*intp->fwd_irq)); + intp->fwd_irq->fd = intp->vdev->vbasedev.fd; + intp->fwd_irq->index = intp->pin; + intp->fwd_irq->gsi = intp->virtualID; + + attr.addr = (uint64_t)(unsigned long)intp->fwd_irq; + + if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) { + error_report("Failed to forward IRQ %d through KVM VFIO device", + intp->pin); + g_free(intp->fwd_irq); + return -errno; + } + trace_vfio_start_fwd_injection(intp->pin); + + return ret; +} + +#endif + +/* * Functions used for irqfd */ @@ -288,6 +334,11 @@ static int vfio_start_irqfd_injection(VFIOINTp *intp) .flags = KVM_IRQFD_FLAG_RESAMPLE, }; + if (has_kvm_vfio_forward_capability() && + intp->vdev->forward_allowed) { + vfio_set_forwarding(intp); + } + if (kvm_vm_ioctl(kvm_state, KVM_IRQFD, &irqfd)) { error_report("vfio: Error: Failed to assign the irqfd: %m"); goto fail_irqfd; @@ -694,6 +745,7 @@ static Property vfio_platform_dev_properties[] = { DEFINE_PROP_UINT32("mmap-timeout-ms", VFIOPlatformDevice, mmap_timeout, 1100), DEFINE_PROP_BOOL("x-irqfd", VFIOPlatformDevice, irqfd_allowed, true), + DEFINE_PROP_BOOL("x-forward", VFIOPlatformDevice, forward_allowed, true), DEFINE_PROP_END_OF_LIST(), }; diff --git a/include/hw/vfio/vfio-platform.h b/include/hw/vfio/vfio-platform.h index de0b5d5..d512bb3 100644 --- a/include/hw/vfio/vfio-platform.h +++ b/include/hw/vfio/vfio-platform.h @@ -42,6 +42,7 @@ typedef struct VFIOINTp { bool kvm_accel; /* set when QEMU bypass through KVM enabled */ uint8_t pin; /* index */ uint8_t virtualID; /* virtual IRQ */ + struct kvm_arch_forwarded_irq *fwd_irq; } VFIOINTp; typedef int (*start_irq_fn_t)(VFIOINTp *intp); @@ -59,6 +60,7 @@ typedef struct VFIOPlatformDevice { start_irq_fn_t start_irq_fn; QemuMutex intp_mutex; bool irqfd_allowed; /* debug option to force irqfd on/off */ + bool forward_allowed; /* debug option to force forwarding on/off */ } VFIOPlatformDevice; diff --git a/trace-events b/trace-events index 59a09f6..0aea358 100644 --- a/trace-events +++ b/trace-events @@ -1431,6 +1431,7 @@ vfio_get_device(const char * name, unsigned int flags, unsigned int num_regions, vfio_put_base_device(int fd) "close vdev->fd=%d" # hw/vfio/platform.c +vfio_start_fwd_injection(int pin) "forwarding set for IRQ pin %d" vfio_platform_eoi(int pin, int fd) "EOI IRQ pin %d (fd=%d)" vfio_platform_mmap_set_enabled(bool enabled) "fast path = %d" vfio_platform_intp_mmap_enable(int pin) "IRQ #%d still active, stay in slow path"