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: Eric Auger X-Patchwork-Id: 416248 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B1DE01400EA for ; Mon, 1 Dec 2014 05:47:30 +1100 (AEDT) Received: from localhost ([::1]:51385 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xv9Wq-00067m-W1 for incoming@patchwork.ozlabs.org; Sun, 30 Nov 2014 13:47:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xv9M3-0006B1-Ro for qemu-devel@nongnu.org; Sun, 30 Nov 2014 13:36:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xv9Lx-0002Iy-UI for qemu-devel@nongnu.org; Sun, 30 Nov 2014 13:36:19 -0500 Received: from mail-wi0-f173.google.com ([209.85.212.173]:45397) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xv9Lx-0002IM-MT for qemu-devel@nongnu.org; Sun, 30 Nov 2014 13:36:13 -0500 Received: by mail-wi0-f173.google.com with SMTP id r20so22580028wiv.0 for ; Sun, 30 Nov 2014 10:36:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/APtAz8Ih5plyiXOWDKt0TFJI3r+VB2gKF4OBDH134c=; b=N8aBsiEFRct8zb+9NTS1eYEGSeU4vgpK2NfxEjW6iXNv9bw1BYIZV1fzPLJJTMtHao 5JStJ5HYfvfnyuUKIh+d7EH64iW245j6oKSsuZ2ni2mOsPu8bBa68yJYNOc3CV4Ba3tB wNMWA3MKuyQ/f7wAuNAXr1Mj9ug3gOlNFVicR/nn5J8KZiBXI/KiN5IJI/ZoWYZTL1bS X1X4PA5GfDsADdC4sMHAaM2X7HjhvlVLZh46NOkN5wg2n1e47UUrMFs9rAGqcHgWc2hH T9qUSdj4Ksy/G+nTa7Mk7W3MEAfHFAw5vMWmC+w/LTEDCaGRMBVRt6+4zbBPV5xHuDNB MV/Q== X-Gm-Message-State: ALoCoQkifYTkpqEe21aO9Q4k5Pgk6BkJ95kp3DCfPK0r8CPQm99Nt7pS6GA+60J5VbnegJ0IRW+c 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 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-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.212.173 Cc: peter.maydell@linaro.org, patches@linaro.org, eric.auger@linaro.org, will.deacon@arm.com, stuart.yoder@freescale.com, Bharat.Bhushan@freescale.com, alex.williamson@redhat.com, a.motakis@virtualopensystems.com, kvmarm@lists.cs.columbia.edu Subject: [Qemu-devel] [PATCH v8 19/19] hw/vfio/platform: add forwarded irq support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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"