From patchwork Thu Nov 19 14:53:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 7657981 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 743C0BF90C for ; Thu, 19 Nov 2015 14:58:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9D4332063C for ; Thu, 19 Nov 2015 14:58:04 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C184E204D9 for ; Thu, 19 Nov 2015 14:58:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZzQd8-00044P-6C; Thu, 19 Nov 2015 14:56:10 +0000 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZzQbj-000190-1l for linux-arm-kernel@lists.infradead.org; Thu, 19 Nov 2015 14:54:47 +0000 Received: by wmec201 with SMTP id c201so29568770wme.0 for ; Thu, 19 Nov 2015 06:54:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kTQwXkkEc0c3f+9r4OUQ16QT3tmbGLG6MbcB5XgMLoE=; b=iCa+Yvg7PAxYj9YJmAeOIXd2z6Xf0FJz5PRLbkkr6Q2hn9gRwQMg4y7GNyH05JG99d pjr7K7Kj7lIuG+S7eCFPkCXcNXHFTCJExnzGrqtkaDnnvnQ++4xdAZH6HMVIcsW6Q17g s+Ha2T5vChxntFzerFvu06Kteej/MRfMS0XXCiCm6v/KJs9ZmxSZYbOq/iIULDdUa+fX easkVO+7ArpvnvaiI5QG94Ce216j6nzkwxJ/spg6bPjJ64+ySzOHWXAmLk/jNg0RVG9c vkf5KNW3t8LVT/FNOmdzoKayDQRQ6GyNxlb6dQ+YIpsFSbLbqftUZcnI1hjN2itoxxqM 2r5g== 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=kTQwXkkEc0c3f+9r4OUQ16QT3tmbGLG6MbcB5XgMLoE=; b=cYlu5J4Z6OXItG+350TgB2a1rbFKGwH+QB2wht9ymVk7Wyz+6IjqQrecPhYh9zOWUo MC3iZZFBMr9hMew0No6OwXugL9KrvofAKL8B+4a7TyOsG8rlk9XxCovbj4OQYAPqUSRE CGYcmmsgOhdh3M4Qv/GlcsbM78wVd8ddkF5t30wu0zI/jsQb7RIjykhVOBiCl+SjhS29 ET6av56At7UmUvfF5m5a+e8oFiOZAhEZe/VQxxWYGp0W82+JK+a29tSnAZ7294RK2ufX nt2T374bvBCXOXoShqb2j/xr75EAzwDSZJMQvF+tmjy4IBu6argSSlCmDrmVW0FE/IyF lHRw== X-Gm-Message-State: ALoCoQnMoY/p+U97qM5i1kiOY95+9aswte2dUTVSgFTQBo9hkLkbTyLcPMqgO4Hn9bHYQu021sqw X-Received: by 10.28.86.196 with SMTP id k187mr9650911wmb.61.1447944862579; Thu, 19 Nov 2015 06:54:22 -0800 (PST) Received: from new-host-3.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id h67sm34493865wmf.17.2015.11.19.06.54.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Nov 2015 06:54:21 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, alex.williamson@redhat.com, b.reynal@virtualopensystems.com, christoffer.dall@linaro.org, marc.zyngier@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Subject: [PATCH v4 07/13] VFIO: platform: add irq bypass producer management Date: Thu, 19 Nov 2015 14:53:57 +0000 Message-Id: <1447944843-17731-8-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1447944843-17731-1-git-send-email-eric.auger@linaro.org> References: <1447944843-17731-1-git-send-email-eric.auger@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151119_065443_476195_C2F7EF87 X-CRM114-Status: GOOD ( 17.21 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: andre.przywara@arm.com, linux-kernel@vger.kernel.org, patches@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch populates the IRQ bypass callacks: - stop/start producer simply consist in disabling/enabling the host irq - add/del consumer: basically set the automasked flag to false/true Signed-off-by: Eric Auger --- v3 -> v4: - use vfio_platform_set_forwarded in place of vfio_platform_set_automasked - use vfio_platform_irq_is_active and its returned value - reword comments related to auto/explicit VFIO masking v2 -> v3: - vfio_platform_irq_bypass_add_consumer now returns an error in case the IRQ is recognized as active - active boolean not set anymore - do not VFIO mask the IRQ anymore on unforward v1 -> v2: - device handle caching in vfio_platform_device is introduced in a separate patch - use container_of --- drivers/vfio/platform/vfio_platform_irq.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/platform/vfio_platform_irq.c b/drivers/vfio/platform/vfio_platform_irq.c index cb7d5e9..e486c32 100644 --- a/drivers/vfio/platform/vfio_platform_irq.c +++ b/drivers/vfio/platform/vfio_platform_irq.c @@ -224,23 +224,49 @@ out: static void vfio_platform_irq_bypass_stop(struct irq_bypass_producer *prod) { + disable_irq(prod->irq); } static void vfio_platform_irq_bypass_start(struct irq_bypass_producer *prod) { + enable_irq(prod->irq); } static int vfio_platform_irq_bypass_add_consumer( struct irq_bypass_producer *prod, struct irq_bypass_consumer *cons) { - return 0; + struct vfio_platform_irq *irq = + container_of(prod, struct vfio_platform_irq, producer); + int ret; + + /* + * if the IRQ is active at irqchip level or masked by VFIO + * this means the host IRQ may be under injection and + * it is not safe to change the forwarding state at that time. + * It is not possible to discriminate VFIO explicit masking + * from VFIO auto-masking, leading to possible false detection of + * IRQ activity. It is up to the user-space to avoid VFIO explicit + * masking situation. In case of failure, no retry is attempted and + * bypass setup simply fails. + */ + ret = vfio_platform_irq_is_active(irq); + if (ret < 0) + return ret; + else if (ret == 1) + return -EAGAIN; + + return vfio_platform_set_forwarded(irq, true); } static void vfio_platform_irq_bypass_del_consumer( struct irq_bypass_producer *prod, struct irq_bypass_consumer *cons) { + struct vfio_platform_irq *irq = + container_of(prod, struct vfio_platform_irq, producer); + + vfio_platform_set_forwarded(irq, false); } static int vfio_set_trigger(struct vfio_platform_device *vdev, int index,