Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752560AbdFOMyD (ORCPT ); Thu, 15 Jun 2017 08:54:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53580 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752520AbdFOMyC (ORCPT ); Thu, 15 Jun 2017 08:54:02 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AA79D624C4 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eric.auger@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com AA79D624C4 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, alex.williamson@redhat.com, b.reynal@virtualopensystems.com, pbonzini@redhat.com, marc.zyngier@arm.com, christoffer.dall@linaro.org Cc: drjones@redhat.com, wei@redhat.com Subject: [PATCH v2 1/8] VFIO: platform: Differentiate auto-masking from user masking Date: Thu, 15 Jun 2017 14:52:33 +0200 Message-Id: <1497531160-29162-2-git-send-email-eric.auger@redhat.com> In-Reply-To: <1497531160-29162-1-git-send-email-eric.auger@redhat.com> References: <1497531160-29162-1-git-send-email-eric.auger@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 15 Jun 2017 12:54:02 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3496 Lines: 110 For direct EOI modality we will need to differentiate a userspace masking from the IRQ handler auto-masking. The level sensitive IRQ handler sets the automasked flag while VFIO_DEVICE_SET_IRQS with VFIO_IRQ_SET_ACTION_MASK sets the usermasked flag. VFIO_IRQ_SET_ACTION_UNMASK resets both flags. Signed-off-by: Eric Auger --- v1 -> v2: - rename maked into usermasked - add is_masked() macro - commit message reworded to better explain role of each flag - change commit title --- drivers/vfio/platform/vfio_platform_irq.c | 18 ++++++++++-------- drivers/vfio/platform/vfio_platform_private.h | 6 +++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/vfio/platform/vfio_platform_irq.c b/drivers/vfio/platform/vfio_platform_irq.c index 46d4750..6740dbe 100644 --- a/drivers/vfio/platform/vfio_platform_irq.c +++ b/drivers/vfio/platform/vfio_platform_irq.c @@ -29,9 +29,9 @@ static void vfio_platform_mask(struct vfio_platform_irq *irq_ctx) spin_lock_irqsave(&irq_ctx->lock, flags); - if (!irq_ctx->masked) { + if (!is_masked(irq_ctx)) { disable_irq_nosync(irq_ctx->hwirq); - irq_ctx->masked = true; + irq_ctx->usermasked = true; } spin_unlock_irqrestore(&irq_ctx->lock, flags); @@ -89,9 +89,10 @@ static void vfio_platform_unmask(struct vfio_platform_irq *irq_ctx) spin_lock_irqsave(&irq_ctx->lock, flags); - if (irq_ctx->masked) { + if (is_masked(irq_ctx)) { enable_irq(irq_ctx->hwirq); - irq_ctx->masked = false; + irq_ctx->usermasked = false; + irq_ctx->automasked = false; } spin_unlock_irqrestore(&irq_ctx->lock, flags); @@ -152,12 +153,12 @@ static irqreturn_t vfio_automasked_irq_handler(int irq, void *dev_id) spin_lock_irqsave(&irq_ctx->lock, flags); - if (!irq_ctx->masked) { + if (!is_masked(irq_ctx)) { ret = IRQ_HANDLED; /* automask maskable interrupts */ disable_irq_nosync(irq_ctx->hwirq); - irq_ctx->masked = true; + irq_ctx->automasked = true; } spin_unlock_irqrestore(&irq_ctx->lock, flags); @@ -217,7 +218,7 @@ static int vfio_set_trigger(struct vfio_platform_device *vdev, int index, return ret; } - if (!irq->masked) + if (!irq->usermasked) enable_irq(irq->hwirq); return 0; @@ -314,7 +315,8 @@ int vfio_platform_irq_init(struct vfio_platform_device *vdev) vdev->irqs[i].count = 1; vdev->irqs[i].hwirq = hwirq; - vdev->irqs[i].masked = false; + vdev->irqs[i].usermasked = false; + vdev->irqs[i].automasked = false; } vdev->num_irqs = cnt; diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h index 85ffe5d..e8db291 100644 --- a/drivers/vfio/platform/vfio_platform_private.h +++ b/drivers/vfio/platform/vfio_platform_private.h @@ -33,7 +33,8 @@ struct vfio_platform_irq { int hwirq; char *name; struct eventfd_ctx *trigger; - bool masked; + bool usermasked; + bool automasked; spinlock_t lock; struct virqfd *unmask; struct virqfd *mask; @@ -102,6 +103,9 @@ extern int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev, extern void __vfio_platform_register_reset(struct vfio_platform_reset_node *n); extern void vfio_platform_unregister_reset(const char *compat, vfio_platform_reset_fn_t fn); + +#define is_masked(irq) ((irq)->usermasked || (irq)->automasked) + #define vfio_platform_register_reset(__compat, __reset) \ static struct vfio_platform_reset_node __reset ## _node = { \ .owner = THIS_MODULE, \ -- 2.5.5