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: Auger Eric X-Patchwork-Id: 57008 Delivered-To: patches@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp3227107lbb; Thu, 19 Nov 2015 06:54:27 -0800 (PST) X-Received: by 10.194.71.16 with SMTP id q16mr9002280wju.49.1447944862803; Thu, 19 Nov 2015 06:54:22 -0800 (PST) Return-Path: Received: from mail-wm0-x22c.google.com (mail-wm0-x22c.google.com. [2a00:1450:400c:c09::22c]) by mx.google.com with ESMTPS id t15si11732767wju.169.2015.11.19.06.54.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Nov 2015 06:54:22 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22c as permitted sender) client-ip=2a00:1450:400c:c09::22c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22c as permitted sender) smtp.mailfrom=eric.auger@linaro.org; dkim=pass header.i=@linaro-org.20150623.gappssmtp.com Received: by wmvv187 with SMTP id v187so29524810wmv.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=lkDmCP19u8JqD2TyNxE1uA0AJIuXXoVzyguo19z12siGBpWrAlm/mZXNbQ2AQfWxjL 2oESwR8+4sSIrQNGw3EUhvZEnP9Ckm5MiiiMk7VLCClqyUrMRZ+vq3hYyJc3YobXC/Bj D1IdmqO7uefadqzFUdlH2rNc+Tv50R/onkRGVChvNkSqayEHypDIMuwxNJVolf/GCcDp VjkALAp3ezI/+JOkGfUJ4lrc8VEQlyFy8nV+2WYKAnvvxx3ly6DxiYTkkPJeonW5hEQd vEqBbbh4AE+Ub+qBSuuLELUWjMGGXv3rSxcbZJRCUI23SB/mULNyZyQ2Womn34dC3S18 2b1Q== X-Gm-Message-State: ALoCoQkHAhfE+v74EiRYCAMZPM9gQ7oWxjIrUFSizUcc5IzJ/84wwVNRJOYMAnrOydjmGaDxcvYM X-Received: by 10.28.86.196 with SMTP id k187mr9650911wmb.61.1447944862579; Thu, 19 Nov 2015 06:54:22 -0800 (PST) Return-Path: 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> 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(-) -- 1.9.1 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,