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: 7657771 Return-Path: X-Original-To: patchwork-kvm@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 0CB06BF90C for ; Thu, 19 Nov 2015 14:54:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 158C920648 for ; Thu, 19 Nov 2015 14:54:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 77843206AD for ; Thu, 19 Nov 2015 14:54:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934296AbbKSOy3 (ORCPT ); Thu, 19 Nov 2015 09:54:29 -0500 Received: from mail-wm0-f41.google.com ([74.125.82.41]:33848 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758751AbbKSOyX (ORCPT ); Thu, 19 Nov 2015 09:54:23 -0500 Received: by wmvv187 with SMTP id v187so29524814wmv.1 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=lq1CnuLi4Vd6EaFttKtxOZ5CO4+34vA5UjPwI8aOeUrBolSP/Akhmig+/Ccfy587LA G8oXfCii4/ZwgY48MxwP56KmokZ7KWqU2//ITXpy3dMPSptwyRukXmxFy5tCdDjhnWVT x0Ju2DHlBpz+Q2MlIb+f9ltkOuExFmA0dVa+0PKewF3NCW8asDI+D9nD9hBO8rl9KM8u sbDSe/j8yqjSvdKsKNu/6T45xIt1dOIqOwF/mDTojIxUJ1+ORoaWFutfJrlca7+ZNLFe +WDvryhFdd85kYcD1UUQe3NJ3XNE1p3aMO8WPdeFCRb8X+UnpSs0ZtLY/6gk+M2qbGxw fxtg== X-Gm-Message-State: ALoCoQnf++QyDIJtxqHQfJQxBGt5CqbvvY4JviI4o1RGrMzgOXCqKTwQPlRgtyXlcWIyOuR3axuA 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 Cc: andre.przywara@arm.com, linux-kernel@vger.kernel.org, patches@linaro.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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham 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,