From patchwork Wed Jun 28 15:03:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 9814693 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B234E60383 for ; Wed, 28 Jun 2017 15:23:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A3B0628554 for ; Wed, 28 Jun 2017 15:23:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 982CF28578; Wed, 28 Jun 2017 15:23:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E892328554 for ; Wed, 28 Jun 2017 15:23:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=dpwvQnbJhESIagWUlNUzVKrN5KiU5ibiNKoUhSt6ZvI=; b=m0xDd4wBo8ChKqIGRS8ObzrbD1 coalx8QvDU1EweONfdu2nXrpIvAxrSh1teqNOhVB24PPkoRABVc2qKWLAxQh/0/0jE25hDJ8XBuLf pZFQgq+oqHyKKZwIJk8wZEQaDJz5v4BromNwBg5SLXGKaUAM3wFMbsH1TuGO6R7fbJU/3ETt9kXUV HMXCaGniEwaSnxpmth274nJPjcEtofkXy3DjguQcmER3mhnXpPymrgkXDQ6eF8RCWahjB3W1fu+je 2+UQ0a+SPCcJycFQxkwTtpa/oCOnmT3lq78maAh3RBb6OytmepJ3c1PjRrLLGfZvNFLGdryzjpxUB iY+HJPSQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dQEog-00035v-W7; Wed, 28 Jun 2017 15:23:43 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dQEnO-0000na-NO for linux-arm-kernel@bombadil.infradead.org; Wed, 28 Jun 2017 15:22:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=dtOQSVs6E30XSvoWC3yiNxSoEKlrqLkK+6ACTRZrJZA=; b=Xk9HeKrTFMSYvAHj0zy8x40yx 3FsAuejPZpENaUdxsiPJ9uvoF8cxDkjN349rkktiq6DnZ46CZdWXi1flAEpVz8/kohqBFTpkBYJGF JWkwlkRx2+aiFqoLPQEKtyfcFRyaZiD8DQ7u14o2caUG7aGsEtXR3keE29oGu4VvtrYAfn7NXws+B WCgjfe7tuWx34c4jDm+2ovZlHyxSPObp1WBgKboLwGHF5wHTnVHhx2XSx8hM8Kouw19lf5i2Y6VAv Rwq6R5BE7AkQPEl1bPzytdAT8cv4ncyVOLjOxYgt5TInJLQnTVatENyH49qMiDExCxux8wV9d5rid XYJgJX85w==; Received: from foss.arm.com ([217.140.101.70]) by casper.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dQEWy-0001KY-5y for linux-arm-kernel@lists.infradead.org; Wed, 28 Jun 2017 15:05:26 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E9FF215BF; Wed, 28 Jun 2017 08:05:23 -0700 (PDT) Received: from approximate.cambridge.arm.com (approximate.cambridge.arm.com [10.1.207.16]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1B0A43F4FF; Wed, 28 Jun 2017 08:05:21 -0700 (PDT) From: Marc Zyngier To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Subject: [PATCH v2 27/52] irqchip/gic-v3-its: Support VPE doorbell invalidation even when !DirectLPI Date: Wed, 28 Jun 2017 16:03:46 +0100 Message-Id: <20170628150411.15846-28-marc.zyngier@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170628150411.15846-1-marc.zyngier@arm.com> References: <20170628150411.15846-1-marc.zyngier@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170628_160524_542253_285D958A X-CRM114-Status: GOOD ( 22.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Jason Cooper , Eric Auger , Christoffer Dall , Thomas Gleixner , Shanker Donthineni MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP When we don't have the DirectLPI feature, we must work around the architecture shortcomings to be able to perform the required invalidation. For this, we create a fake device whose sole purpose is to provide a way to issue a map/inv/unmap sequence (and the corresponding sync operations). That's 6 commands and a full serialization point to be able to do this. You just have to hope the hypervisor won't do that too often... Reviewed-by: Thomas Gleixner Signed-off-by: Marc Zyngier --- drivers/irqchip/irq-gic-v3-its.c | 66 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c index 64893f0427f2..4979916cd3d7 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -138,6 +138,9 @@ struct its_device { u32 device_id; }; +static struct its_device *vpe_proxy_dev; +static DEFINE_RAW_SPINLOCK(vpe_proxy_dev_lock); + static LIST_HEAD(its_nodes); static DEFINE_SPINLOCK(its_lock); static struct rdists *gic_rdists; @@ -2074,6 +2077,14 @@ static int its_msi_prepare(struct irq_domain *domain, struct device *dev, msi_info = msi_get_domain_info(domain); its = msi_info->data; + if (its->is_v4 && !gic_rdists->has_direct_lpi && + dev_id == vpe_proxy_dev->device_id) { + /* Bad luck. Get yourself a better implementation */ + WARN_ONCE(1, "DevId %x clashes with GICv4 VPE proxy device\n", + dev_id); + return -EINVAL; + } + its_dev = its_find_device(its, dev_id); if (its_dev) { /* @@ -2318,10 +2329,38 @@ static int its_vpe_set_vcpu_affinity(struct irq_data *d, void *vcpu_info) static void its_vpe_send_inv(struct irq_data *d) { struct its_vpe *vpe = irq_data_get_irq_chip_data(d); - void __iomem *rdbase; - rdbase = per_cpu_ptr(gic_rdists->rdist, vpe->col_idx)->rd_base; - gic_write_invlpir(d->hwirq, rdbase + GICR_INVLPIR); + if (gic_rdists->has_direct_lpi) { + void __iomem *rdbase; + + rdbase = per_cpu_ptr(gic_rdists->rdist, vpe->col_idx)->rd_base; + gic_write_invlpir(d->hwirq, rdbase + GICR_INVLPIR); + } else { + /* + * This is insane. + * + * If a GICv4 doesn't implement Direct LPIs, the only + * way to perform an invalidate is to use a fake + * device to issue a MAP/INV/UNMAP sequence. Since + * each of these commands has a sync operation, this + * is really fast. Not. + * + * We always use event 0, and thus serialize all VPE + * invalidations in the system. + * + * Broken by design(tm). + */ + unsigned long flags; + + raw_spin_lock_irqsave(&vpe_proxy_dev_lock, flags); + + vpe_proxy_dev->event_map.col_map[0] = vpe->col_idx; + its_send_mapti(vpe_proxy_dev, vpe->vpe_db_lpi, 0); + its_send_inv(vpe_proxy_dev, 0); + its_send_discard(vpe_proxy_dev, 0); + + raw_spin_unlock_irqrestore(&vpe_proxy_dev_lock, flags); + } } static void its_vpe_mask_irq(struct irq_data *d) @@ -2616,6 +2655,27 @@ static int its_init_domain(struct fwnode_handle *handle, struct its_node *its) static int its_init_vpe_domain(void) { + struct its_node *its; + u32 devid; + + if (gic_rdists->has_direct_lpi) { + pr_info("ITS: Using DirectLPI for VPE invalidation\n"); + return 0; + } + + /* Any ITS will do, even if not v4 */ + its = list_first_entry(&its_nodes, struct its_node, entry); + + /* Use the last possible DevID */ + devid = GENMASK(its->device_ids - 1, 0); + vpe_proxy_dev = its_create_device(its, devid, 1); + if (!vpe_proxy_dev) { + pr_err("ITS: Can't allocate GICv4 proxy device\n"); + return -ENODEV; + } + + pr_info("ITS: Allocated DevID %x as GICv4 proxy device\n", devid); + return 0; }