From patchwork Fri Feb 13 04:00:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 44655 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AE7F121527 for ; Fri, 13 Feb 2015 04:00:42 +0000 (UTC) Received: by labgm9 with SMTP id gm9sf9079421lab.2 for ; Thu, 12 Feb 2015 20:00:41 -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=Wic1Uybvb/kbb4LhFGlmABpPXTnDya49TcCA0rQNUuI=; b=faHkJJ0G4f7e+PJOxcqVMA0M9v4BM4yNHtjWFqJR5HE/SzVMNbSmGO6pnQAdepzaHO OJJi/20GoSdKIUTVbKRowGmJjnkneamo5KAIyKQFeMW17hHAIcqZ+HRuY5w9S5S+JoxY 0C0eXivtOwLJDbrdMajpFJ9sRX8fxPncn066WNfaC6aIBv/f+VkknboBn3a+0vHoGUVc qMK41LuWF0ort5fDhuYGRHv3KdaHBdssfEEGHFL3ECMRP7lLLckP2hY2/6QhlVPbbcwL 1ySKe8lUov3qWWPGRtU1/SQd1/jeq+P4Jhog6+lSeTo7Nt6L30UlwZoJP9BUuO4AbW+n nQuQ== X-Gm-Message-State: ALoCoQnk7yPi6hjVqc5dqKGe3ntirprWC7DIF6a9ebvV/ThPEBRti3iRAmQhIUCUP9xyg9OvMHfw X-Received: by 10.112.130.70 with SMTP id oc6mr1048814lbb.13.1423800041761; Thu, 12 Feb 2015 20:00:41 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.242.164 with SMTP id wr4ls303018lac.79.gmail; Thu, 12 Feb 2015 20:00:41 -0800 (PST) X-Received: by 10.152.7.101 with SMTP id i5mr6204990laa.122.1423800041559; Thu, 12 Feb 2015 20:00:41 -0800 (PST) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id uq7si642372lbb.173.2015.02.12.20.00.41 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Feb 2015 20:00:41 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by labhs14 with SMTP id hs14so13555913lab.1 for ; Thu, 12 Feb 2015 20:00:41 -0800 (PST) X-Received: by 10.112.40.201 with SMTP id z9mr5895960lbk.117.1423800041434; Thu, 12 Feb 2015 20:00:41 -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.35.133 with SMTP id h5csp828800lbj; Thu, 12 Feb 2015 20:00:40 -0800 (PST) X-Received: by 10.194.200.68 with SMTP id jq4mr13904815wjc.128.1423800033579; Thu, 12 Feb 2015 20:00:33 -0800 (PST) Received: from mail-wg0-f47.google.com (mail-wg0-f47.google.com. [74.125.82.47]) by mx.google.com with ESMTPS id da6si1670156wjb.92.2015.02.12.20.00.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Feb 2015 20:00:33 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 74.125.82.47 as permitted sender) client-ip=74.125.82.47; Received: by mail-wg0-f47.google.com with SMTP id x12so539641wgg.6 for ; Thu, 12 Feb 2015 20:00:33 -0800 (PST) X-Received: by 10.180.198.101 with SMTP id jb5mr11839963wic.92.1423800033253; Thu, 12 Feb 2015 20:00:33 -0800 (PST) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id a13sm8231982wjx.30.2015.02.12.20.00.32 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 12 Feb 2015 20:00:32 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, christoffer.dall@linaro.org, qemu-devel@nongnu.org, alex.williamson@redhat.com, peter.maydell@linaro.org, agraf@suse.de, b.reynal@virtualopensystems.com, feng.wu@intel.com Cc: kvmarm@lists.cs.columbia.edu, patches@linaro.org, pbonzini@redhat.com, afaerber@suse.de, kim.phillips@freescale.com, Bharat.Bhushan@freescale.com, a.rigo@virtualopensystems.com, a.motakis@virtualopensystems.com Subject: [RFC 3/3] hw/vfio/platform: add forwarded irq support Date: Fri, 13 Feb 2015 04:00:20 +0000 Message-Id: <1423800020-10940-4-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1423800020-10940-1-git-send-email-eric.auger@linaro.org> References: <1423800020-10940-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.46 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 --- v8 -> v9: - use new kvm_vfio_dev_irq struct --- hw/vfio/platform.c | 64 +++++++++++++++++++++++++++++++++++++++++ include/hw/vfio/vfio-platform.h | 3 ++ trace-events | 1 + 3 files changed, 68 insertions(+) diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index cadc824..b6ba5b3 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -238,6 +238,63 @@ 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 argsz; + struct kvm_device_attr attr = { + .group = KVM_DEV_VFIO_DEVICE, + .attr = KVM_DEV_VFIO_DEVICE_FORWARD_IRQ}; + __u32 *pvirq; + + if (intp->forwarded) { + return -EINVAL; + } + + argsz = sizeof(*intp->fwd_irq) + sizeof(*pvirq); + intp->fwd_irq = g_malloc0(argsz); + intp->fwd_irq->argsz = argsz; + intp->fwd_irq->fd = intp->vdev->vbasedev.fd; + intp->fwd_irq->index = intp->pin; + intp->fwd_irq->start = 0; + intp->fwd_irq->count = 1; + pvirq = (__u32 *)&intp->fwd_irq->gsi; + *pvirq = (uint32_t)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); + intp->forwarded = true; + + return 0; +} + +#endif + +/* * Functions used for irqfd */ @@ -289,6 +346,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; @@ -384,6 +446,7 @@ static VFIOINTp *vfio_init_intp(VFIODevice *vbasedev, unsigned int index) intp->vdev = vdev; intp->pin = index; intp->state = VFIO_IRQ_INACTIVE; + intp->forwarded = false; sysbus_init_irq(sbdev, &intp->qemuirq); /* Get an eventfd for trigger */ @@ -716,6 +779,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 097448b..693066d 100644 --- a/include/hw/vfio/vfio-platform.h +++ b/include/hw/vfio/vfio-platform.h @@ -42,6 +42,8 @@ typedef struct VFIOINTp { bool kvm_accel; /* set when QEMU bypass through KVM enabled */ uint8_t pin; /* index */ uint32_t virtualID; /* virtual IRQ */ + struct kvm_vfio_dev_irq *fwd_irq; + bool forwarded; } VFIOINTp; typedef int (*start_irq_fn_t)(VFIOINTp *intp); @@ -59,6 +61,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 7a6a6aa..9a138d6 100644 --- a/trace-events +++ b/trace-events @@ -1557,6 +1557,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"