From patchwork Thu Jul 2 13:17:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 50591 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 70485214B3 for ; Thu, 2 Jul 2015 13:18:51 +0000 (UTC) Received: by lagh6 with SMTP id h6sf20040363lag.0 for ; Thu, 02 Jul 2015 06:18:50 -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=NaN0wPKZrPYubAj9q0um9fJqg8TgGLL2Az5yU6/bOx8=; b=BTPkbeMilUYdRBfledcILjL+gp5csmJnPvrlxsssgxl2TEVkCR9hGLQV5I+c93u1vX CIcmuBAJbCepczxzgkXH7qM+45siFMxLIZiCodJyB2aL5nMJnqbNKNuhhiI+Nd9Nt4n8 IWbz/Q0YBVGWrJDkSeDFkz0iV1ymqSBs9oGLCPLxy+dJPn80wXXNeQuMqzUcOr+JCgDY aqkJLahLWaV3QuBc6Im8gEq1jE8fbBeWzsfo0R47SsnpbBwsj8PUxIMM9aKZfrtGiUSu 6tG5pBd/nPrF37fzDA+j8ZoGzmyaFZPuOGL3MT5Xc4UNYECEek2LhV2Xo0LURZvmTwd0 IAqA== X-Gm-Message-State: ALoCoQnVurY5IaNXWT02EBQeM2FkODYIgRh3IW/ic7DCwMx39iGKKqUHljToxwz6vIAL2ciiQmvo X-Received: by 10.180.87.201 with SMTP id ba9mr4697501wib.3.1435843130432; Thu, 02 Jul 2015 06:18:50 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.10 with SMTP id p10ls342784lag.29.gmail; Thu, 02 Jul 2015 06:18:50 -0700 (PDT) X-Received: by 10.152.203.162 with SMTP id kr2mr30606555lac.57.1435843130269; Thu, 02 Jul 2015 06:18:50 -0700 (PDT) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id bb9si4448484lab.89.2015.07.02.06.18.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Jul 2015 06:18:50 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by lagh6 with SMTP id h6so60897309lag.2 for ; Thu, 02 Jul 2015 06:18:50 -0700 (PDT) X-Received: by 10.112.219.70 with SMTP id pm6mr29827985lbc.41.1435843129681; Thu, 02 Jul 2015 06:18:49 -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.108.230 with SMTP id hn6csp476570lbb; Thu, 2 Jul 2015 06:18:49 -0700 (PDT) X-Received: by 10.180.11.239 with SMTP id t15mr16457350wib.63.1435843109470; Thu, 02 Jul 2015 06:18:29 -0700 (PDT) Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com. [209.85.212.175]) by mx.google.com with ESMTPS id j17si9423459wic.99.2015.07.02.06.18.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Jul 2015 06:18:29 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.175 as permitted sender) client-ip=209.85.212.175; Received: by wiwl6 with SMTP id l6so196709675wiw.0 for ; Thu, 02 Jul 2015 06:18:29 -0700 (PDT) X-Received: by 10.180.109.136 with SMTP id hs8mr16337466wib.73.1435843109159; Thu, 02 Jul 2015 06:18:29 -0700 (PDT) Received: from gnx2579.home (LCaen-156-56-7-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by mx.google.com with ESMTPSA id tl3sm8157099wjc.20.2015.07.02.06.18.27 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Jul 2015 06:18:28 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, christoffer.dall@linaro.org, marc.zyngier@arm.com, alex.williamson@redhat.com, pbonzini@redhat.com, avi.kivity@gmail.com, mtosatti@redhat.com, feng.wu@intel.com, joro@8bytes.org, b.reynal@virtualopensystems.com Cc: linux-kernel@vger.kernel.org, patches@linaro.org Subject: [RFC 17/17] VFIO: platform: add irq bypass producer management Date: Thu, 2 Jul 2015 15:17:27 +0200 Message-Id: <1435843047-6327-18-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1435843047-6327-1-git-send-email-eric.auger@linaro.org> References: <1435843047-6327-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.50 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: , This patch adds irq_bypass_producer registration/unregistration. VFIO producer callbacks are populated: - stop/resume producer simply consist in disabling/enabling the host irq - add/del consumer: basically set the automasked flag to false/true The vfio_platform_device pointer is passed as producer opaque. We also cache the device handle in vfio_platform_device. This makes possible to easily retrieve the vfio_device at registration. Signed-off-by: Eric Auger --- drivers/vfio/platform/vfio_platform_common.c | 2 + drivers/vfio/platform/vfio_platform_irq.c | 83 +++++++++++++++++++++++++++ drivers/vfio/platform/vfio_platform_private.h | 2 + 3 files changed, 87 insertions(+) diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c index 9acfca6..12d4540 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c @@ -546,6 +546,8 @@ int vfio_platform_probe_common(struct vfio_platform_device *vdev, if (!vdev) return -EINVAL; + vdev->dev = dev; + group = iommu_group_get(dev); if (!group) { pr_err("VFIO: No IOMMU group for device %s\n", vdev->name); diff --git a/drivers/vfio/platform/vfio_platform_irq.c b/drivers/vfio/platform/vfio_platform_irq.c index f6d83ed..0061e6e 100644 --- a/drivers/vfio/platform/vfio_platform_irq.c +++ b/drivers/vfio/platform/vfio_platform_irq.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "vfio_platform_private.h" @@ -185,6 +186,70 @@ static irqreturn_t vfio_handler(int irq, void *dev_id) return ret; } +static void vfio_platform_stop_producer(struct irq_bypass_producer *prod) +{ + pr_info("%s disable %d\n", __func__, prod->irq); + disable_irq(prod->irq); +} + +static void vfio_platform_resume_producer(struct irq_bypass_producer *prod) +{ + pr_info("%s enable %d\n", __func__, prod->irq); + enable_irq(prod->irq); +} + +static void vfio_platform_add_consumer(struct irq_bypass_producer *prod, + struct irq_bypass_consumer *cons) +{ + int i, ret; + struct vfio_platform_device *vdev = + (struct vfio_platform_device *)prod->opaque; + + pr_info("%s irq=%d gsi =%d\n", __func__, prod->irq, cons->gsi); + + for (i = 0; i < vdev->num_irqs; i++) { + if (vdev->irqs[i].prod == prod) + break; + } + WARN_ON(i == vdev->num_irqs); + + //TODO + /* + * if the IRQ is active at irqchip level or VFIO (auto)masked + * this means the host IRQ is already under injection in the + * guest and this not safe to change the forwarding state at + * that stage. + * It is not possible to differentiate user-space masking + * from auto-masking, leading to possible false detection of + * active state. + */ + prod->active = vfio_external_is_active(prod->vdev, i, 0, 0); + + ret = vfio_external_set_automasked(prod->vdev, i, 0, 0, false); + WARN_ON(ret); +} + +static void vfio_platform_del_consumer(struct irq_bypass_producer *prod, + struct irq_bypass_consumer *cons) +{ + int i; + struct vfio_platform_device *vdev = + (struct vfio_platform_device *)prod->opaque; + + pr_info("%s irq=%d gsi =%d\n", __func__, prod->irq, cons->gsi); + + for (i = 0; i < vdev->num_irqs; i++) { + if (vdev->irqs[i].prod == prod) + break; + } + WARN_ON(i == vdev->num_irqs); + + if (prod->active) + vfio_external_mask(prod->vdev, i, 0, 0); + + vfio_external_set_automasked(prod->vdev, i, 0, 0, true); +} + static int vfio_set_trigger(struct vfio_platform_device *vdev, int index, int fd, irq_handler_t handler) { @@ -192,8 +257,11 @@ static int vfio_set_trigger(struct vfio_platform_device *vdev, int index, struct eventfd_ctx *trigger; int ret; + if (irq->trigger) { free_irq(irq->hwirq, irq); + irq_bypass_unregister_producer(irq->prod); + kfree(irq->prod); kfree(irq->name); eventfd_ctx_put(irq->trigger); irq->trigger = NULL; @@ -225,6 +293,21 @@ static int vfio_set_trigger(struct vfio_platform_device *vdev, int index, return ret; } + irq->prod = kzalloc(sizeof(struct irq_bypass_producer), + GFP_KERNEL); + if (!irq->prod) + return -ENOMEM; + irq->prod->token = (void *)trigger; + irq->prod->irq = irq->hwirq; + irq->prod->vdev = vfio_device_get_from_dev(vdev->dev); + irq->prod->opaque = (void *)vdev; + irq->prod->add_consumer = vfio_platform_add_consumer; + irq->prod->del_consumer = vfio_platform_del_consumer; + irq->prod->stop_producer = vfio_platform_stop_producer; + irq->prod->resume_producer = vfio_platform_resume_producer; + ret = irq_bypass_register_producer(irq->prod); + WARN_ON(ret); + if (!irq->masked) enable_irq(irq->hwirq); diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h index 5f46c68..1255306 100644 --- a/drivers/vfio/platform/vfio_platform_private.h +++ b/drivers/vfio/platform/vfio_platform_private.h @@ -38,6 +38,7 @@ struct vfio_platform_irq { struct virqfd *unmask; struct virqfd *mask; irqreturn_t (*handler)(int irq, void *dev_id); + struct irq_bypass_producer *prod; }; struct vfio_platform_region { @@ -57,6 +58,7 @@ struct vfio_platform_device { u32 num_irqs; int refcnt; struct mutex igate; + struct device *dev; /* * These fields should be filled by the bus specific binder