From patchwork Fri Oct 31 14:05:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 39914 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 17C23202FE for ; Fri, 31 Oct 2014 14:06:38 +0000 (UTC) Received: by mail-wg0-f71.google.com with SMTP id b13sf3192618wgh.2 for ; Fri, 31 Oct 2014 07:06:37 -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=KYeFrIHu6vNOrC91M2Hn3DNTA4GNsFHBIgFPTpeETOE=; b=ZIG8XhDNrW9WB5/4zGIANwpZyBO2BdBaWz/3CLvAIXd8+yLuExcqdddy+oZ7fDyW0x tDRlkoJfVzi5lpgtJuWoAADgv+rpTPNd43xC1hn/t1aP1AWyu4D6etBZH898jdAAYrdd ROtBPM2VKyCcVlE0WgbV73NjLK/sEnqNN/h7e+fAsurbXePyX22tKyzuCGyobso3bBr5 IGeUZT103zKR22umjrg9eNuDaPzjfz2D4cT85KPEDPtBa8vp4r/o6rdr25ZgAEUdNBLv p0byYogbQT6puwjMBEjI2OI+u8/oqj92Cs0l7GHtQ8jQsFHbVt4TDRMeA8WdFiOKAujx +A9g== X-Gm-Message-State: ALoCoQmooEJuLiJNcAnL9u/h28tRmHTRs5VHSj4gzGaot/uddfciY/ARdyc6E0rX7JfNw1IkBTNr X-Received: by 10.112.97.35 with SMTP id dx3mr39560lbb.20.1414764397194; Fri, 31 Oct 2014 07:06:37 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.42.197 with SMTP id q5ls497230lal.39.gmail; Fri, 31 Oct 2014 07:06:36 -0700 (PDT) X-Received: by 10.153.7.107 with SMTP id db11mr26665693lad.35.1414764396808; Fri, 31 Oct 2014 07:06:36 -0700 (PDT) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id jo7si16887451lbc.39.2014.10.31.07.06.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Oct 2014 07:06:36 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by mail-la0-f45.google.com with SMTP id pn19so888275lab.4 for ; Fri, 31 Oct 2014 07:06:36 -0700 (PDT) X-Received: by 10.152.120.199 with SMTP id le7mr4030813lab.67.1414764396704; Fri, 31 Oct 2014 07:06:36 -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 c5csp207571lbz; Fri, 31 Oct 2014 07:06:36 -0700 (PDT) X-Received: by 10.194.3.78 with SMTP id a14mr3340329wja.107.1414764395531; Fri, 31 Oct 2014 07:06:35 -0700 (PDT) Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com. [209.85.212.181]) by mx.google.com with ESMTPS id hv3si9757538wib.48.2014.10.31.07.06.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Oct 2014 07:06:35 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.181 as permitted sender) client-ip=209.85.212.181; Received: by mail-wi0-f181.google.com with SMTP id n3so1397158wiv.14 for ; Fri, 31 Oct 2014 07:06:35 -0700 (PDT) X-Received: by 10.194.189.82 with SMTP id gg18mr3113300wjc.115.1414764395162; Fri, 31 Oct 2014 07:06:35 -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.34 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Oct 2014 07:06:34 -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 16/16] hw/vfio/platform: add forwarded irq support Date: Fri, 31 Oct 2014 14:05:50 +0000 Message-Id: <1414764350-5140-17-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.45 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 bdd5c93..f7ed209 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; @@ -737,6 +788,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 26ddba7..d22eb0e 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 a05ed80..df3b71b 100644 --- a/trace-events +++ b/trace-events @@ -1429,6 +1429,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"