linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: eric.auger@linaro.org (Eric Auger)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC 17/17] VFIO: platform: add irq bypass producer management
Date: Thu,  2 Jul 2015 15:17:27 +0200	[thread overview]
Message-ID: <1435843047-6327-18-git-send-email-eric.auger@linaro.org> (raw)
In-Reply-To: <1435843047-6327-1-git-send-email-eric.auger@linaro.org>

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 <eric.auger@linaro.org>
---
 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 <linux/types.h>
 #include <linux/vfio.h>
 #include <linux/irq.h>
+#include <linux/irqbypass.h>
 
 #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
-- 
1.9.1

      parent reply	other threads:[~2015-07-02 13:17 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-02 13:17 [RFC 00/17] ARM IRQ forward control based on IRQ bypass manager Eric Auger
2015-07-02 13:17 ` [RFC 01/17] VFIO: platform: test forwarded state when selecting IRQ handler Eric Auger
2015-07-02 13:17 ` [RFC 02/17] VFIO: platform: single handler using function pointer Eric Auger
2015-07-02 13:17 ` [RFC 03/17] VFIO: Introduce vfio_device_external_ops Eric Auger
2015-07-02 13:17 ` [RFC 04/17] VFIO: pci: initialize vfio_device_external_ops Eric Auger
2015-07-02 13:17 ` [RFC 05/17] VFIO: platform: implement vfio_device_external_ops callbacks Eric Auger
2015-07-02 13:17 ` [RFC 06/17] VFIO: add vfio_external_{mask|is_active|set_automasked} Eric Auger
2015-07-02 13:17 ` [RFC 07/17] KVM: arm: rename pause into power_off Eric Auger
2015-07-02 13:17 ` [RFC 08/17] kvm: arm/arm64: implement kvm_arm_[halt,resume]_guest Eric Auger
2015-07-03 11:55   ` [RFC 08/17] kvm: arm/arm64: implement kvm_arm_[halt, resume]_guest Eric Auger
2015-07-03 12:14     ` Marc Zyngier
2015-07-02 13:17 ` [RFC 09/17] bypass: IRQ bypass manager proto by Alex Eric Auger
2015-07-03  2:16   ` Wu, Feng
2015-07-03  5:32     ` Eric Auger
2015-07-02 13:17 ` [RFC 10/17] KVM: arm: select IRQ_BYPASS_MANAGER Eric Auger
2015-07-02 13:17 ` [RFC 11/17] VFIO: platform: " Eric Auger
2015-07-02 13:17 ` [RFC 12/17] irq: bypass: Extend skeleton for ARM forwarding control Eric Auger
2015-07-02 13:40   ` Paolo Bonzini
2015-07-03  2:19     ` Wu, Feng
2015-07-03  2:24       ` Wu, Feng
2015-07-03  6:54         ` Eric Auger
2015-07-03  7:02           ` Paolo Bonzini
2015-07-03 13:12     ` Eric Auger
2015-07-03 17:20       ` Paolo Bonzini
2015-07-03 17:23         ` Eric Auger
2015-07-03  2:43   ` Wu, Feng
2015-07-03  6:52     ` Paolo Bonzini
2015-07-03  7:00       ` Wu, Feng
2015-07-03  7:06         ` Paolo Bonzini
2015-07-03  7:16           ` Wu, Feng
2015-07-03  7:08   ` Paolo Bonzini
2015-07-02 13:17 ` [RFC 13/17] KVM: introduce kvm_arch functions for IRQ bypass Eric Auger
2015-07-02 13:41   ` Paolo Bonzini
2015-07-02 13:17 ` [RFC 14/17] KVM: arm/arm64: vgic: forwarding control Eric Auger
2015-07-02 13:17 ` [RFC 15/17] KVM: arm/arm64: implement IRQ bypass consumer functions Eric Auger
2015-07-02 13:17 ` [RFC 16/17] KVM: eventfd: add irq bypass consumer management Eric Auger
2015-07-02 13:42   ` Paolo Bonzini
2015-07-02 13:53     ` Eric Auger
2015-07-06  7:55   ` Wu, Feng
2015-07-06 11:19     ` Eric Auger
2015-07-06 12:17       ` Wu, Feng
2015-07-02 13:17 ` Eric Auger [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1435843047-6327-18-git-send-email-eric.auger@linaro.org \
    --to=eric.auger@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).