From patchwork Tue Sep 9 07:31:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 37041 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f71.google.com (mail-pa0-f71.google.com [209.85.220.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 036C620491 for ; Tue, 9 Sep 2014 07:32:10 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id rd3sf21488717pab.10 for ; Tue, 09 Sep 2014 00:32:10 -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=x4l/wHIDKsD7jrt/xppceWnFHPjCXRr+XgFTpUtELMc=; b=SzTq2OUvMijCgWHg8trkj5ivMJXwz8uzylhmdy/hoPSVb3+JLGTEhpiEaSk3jiUI7i R2pjxiiWE/KNXQWl63Pj7/GKW8m3q7U/ICb3QQZ1rsWq/cPYvroVWWKjMw/eNlBp+5Us RSLtJLnwmhRP6XglKBhQidbOOP9xstvxJKW1+OTlgpPo9vL4JyO6sz2nM7xi4GYmMSx9 o0PStTIXWe0AlC1MlDzM4aSUU8dDemIoSQNUB8IpD+xiaI9bUBMPDTlXBRBmE0FUgVNV lua2NdaTquOb2Y/ZiImyQ7lh0XAmhHgK4TY7x5Hr45t/DvZuo+hGTchwjZDat5jttTeG Xxvw== X-Gm-Message-State: ALoCoQmEZiOfMns0NSyczukOhDZzzL61Rpw71B5NM3kPSX2NMoLDbj8la5XE8aXJbqw4qjAOHwr7 X-Received: by 10.70.87.202 with SMTP id ba10mr20677879pdb.1.1410247930064; Tue, 09 Sep 2014 00:32:10 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.41.211 with SMTP id z77ls2077173qgz.54.gmail; Tue, 09 Sep 2014 00:32:09 -0700 (PDT) X-Received: by 10.52.165.116 with SMTP id yx20mr24483485vdb.13.1410247929955; Tue, 09 Sep 2014 00:32:09 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id r2si5467301vda.106.2014.09.09.00.32.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Sep 2014 00:32:09 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id hy10so2919414vcb.3 for ; Tue, 09 Sep 2014 00:32:09 -0700 (PDT) X-Received: by 10.221.23.66 with SMTP id qz2mr4694304vcb.46.1410247929878; Tue, 09 Sep 2014 00:32:09 -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 uj3csp244072vcb; Tue, 9 Sep 2014 00:32:09 -0700 (PDT) X-Received: by 10.194.78.100 with SMTP id a4mr2525421wjx.106.1410247928939; Tue, 09 Sep 2014 00:32:08 -0700 (PDT) Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com [209.85.212.169]) by mx.google.com with ESMTPS id w14si16905587wiv.69.2014.09.09.00.32.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Sep 2014 00:32:08 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.169 as permitted sender) client-ip=209.85.212.169; Received: by mail-wi0-f169.google.com with SMTP id ex7so547402wid.4 for ; Tue, 09 Sep 2014 00:32:08 -0700 (PDT) X-Received: by 10.180.211.207 with SMTP id ne15mr28501992wic.29.1410247928555; Tue, 09 Sep 2014 00:32:08 -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.07 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Sep 2014 00:32:07 -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 16/16] VFIO: PLATFORM: add forwarded irq support Date: Tue, 9 Sep 2014 08:31:16 +0100 Message-Id: <1410247876-4967-17-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.172 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 a59a842..2d07d2f 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -324,6 +324,52 @@ static void vfio_fake_intp_injection(void *opaque) } /* + * 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 */ @@ -375,6 +421,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; @@ -790,6 +841,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 e896c86..6c46295 100644 --- a/include/hw/vfio/vfio-platform.h +++ b/include/hw/vfio/vfio-platform.h @@ -48,6 +48,7 @@ typedef struct VFIOINTp { QEMUTimer *fake_eoi_timer; /* timer to handle fake IRQ completion */ uint32_t fake_intp_period; /* delay between fake IRQ injections */ uint32_t fake_intp_duration; /* duration of the IRQ */ + struct kvm_arch_forwarded_irq *fwd_irq; } VFIOINTp; typedef int (*start_irq_fn_t)(VFIOINTp *intp); @@ -72,6 +73,7 @@ typedef struct VFIOPlatformDevice { uint32_t len_x_fake_period; uint32_t len_x_fake_duration; 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 1b81b66..29e03d2 100644 --- a/trace-events +++ b/trace-events @@ -1378,6 +1378,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"