From patchwork Tue Oct 6 10:11:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 11818441 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 209126CA for ; Tue, 6 Oct 2020 10:13:19 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D29E72068E for ; Tue, 6 Oct 2020 10:13:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="z/dzSHG9"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="hz1S08/Y" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D29E72068E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version: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=iQj1aodOxlnfiLdzF6eZ+/KrYLaCIWq+k1LnMRvdXXA=; b=z/dzSHG9SrPOTU9lzujLL/UXF dL+vYqrtHpkr+k6Tj0+tNZ0eZqfrVx7htH9v49vI3nbxBuzuojp83IkU3HrCOPZo4h1X5RKbjuafA 9J//zZX5mrNv6cpYUJ9vcy466qvasMCjuyBS5AJHkV7sHglJTPN8LqzHAkFFiD/c+v9kFFbQ0kpyP KYRieTwPfpYTiGBoX7mi+Xn1uUm3bjwbUZDGOdyUwEWVPR5rOJ5pTCXmAH+KbMMDjnzDuYfTQStS7 ZbXdQWowhUcmqLLh5Em8egBCqctHE59vy45k1WE3tGP+mE71kCZjkrQIBJL9DqwEnVI0EEjcr89qQ wkwP5nmpw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kPjwj-0004Hn-1r; Tue, 06 Oct 2020 10:11:49 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kPjwe-0004G3-LR for linux-arm-kernel@lists.infradead.org; Tue, 06 Oct 2020 10:11:45 +0000 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 96B61206B5; Tue, 6 Oct 2020 10:11:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601979103; bh=sJ1/VY9aEX3+d4vdPHyox0QqwqED1nbmWmUgzI5Gb/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hz1S08/Yn1GBalrqs8wYvvEX3GYJ9ntC6cqgGhf4rQQHp1wgPGQ52vdfcBAk+Bklt KLjso5JpDprRs3SgZkoFZ4Z0x3p1Jr62cVwZnjUO5eTz2sEhJmGGIN+vPyFGYRk1rB i86R9yHbL2FZD/d+g+Hh+hE58CGdYxVbuXCilFoY= Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kPjwb-0002Qo-Uj; Tue, 06 Oct 2020 11:11:42 +0100 From: Marc Zyngier To: linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 1/4] genirq/irqdomain: Allow partial trimming of irq_data hierarchy Date: Tue, 6 Oct 2020 11:11:34 +0100 Message-Id: <20201006101137.1393797-2-maz@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201006101137.1393797-1-maz@kernel.org> References: <20201006101137.1393797-1-maz@kernel.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, thierry.reding@gmail.com, jonathanh@nvidia.com, digetx@gmail.com, skomatineni@nvidia.com, vreddytalla@nvidia.com, tglx@linutronix.de, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201006_061144_868260_8FCDC46D X-CRM114-Status: GOOD ( 22.98 ) X-Spam-Score: -5.9 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-5.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [198.145.29.99 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.7 DKIMWL_WL_HIGH DKIMwl.org - High trust sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Venkat Reddy Talla , Jonathan Hunter , Thierry Reding , Sowjanya Komatineni , Dmitry Osipenko , kernel-team@android.com, Thomas Gleixner Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org It appears that some HW is ugly enough that not all the interrupts connected to a particular interrupt controller end up with the same hierarchy repth (some of them are terminated early). This leaves the irqchip hacker with only two choices, both equally bad: - create discrete domain chains, one for each "hierarchy depth", which is very hard to maintain - create fake hierarchy levels for the shallow paths, leading to all kind of problems (what are the safe hwirq values for these fake levels?) Instead, let's offer the possibility to cut short a single interrupt hierarchy, exactly representing the HW. This can only be done from the .alloc() callback, before mappings can be established. Signed-off-by: Marc Zyngier --- include/linux/irqdomain.h | 3 +++ kernel/irq/irqdomain.c | 56 +++++++++++++++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h index b37350c4fe37..c6901c1bb981 100644 --- a/include/linux/irqdomain.h +++ b/include/linux/irqdomain.h @@ -509,6 +509,9 @@ extern void irq_domain_free_irqs_parent(struct irq_domain *domain, unsigned int irq_base, unsigned int nr_irqs); +extern int irq_domain_trim_hierarchy(unsigned int virq, + struct irq_domain *domain); + static inline bool irq_domain_is_hierarchy(struct irq_domain *domain) { return domain->flags & IRQ_DOMAIN_FLAG_HIERARCHY; diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index 76cd7ebd1178..d0adaeea70b6 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -1136,6 +1136,17 @@ static struct irq_data *irq_domain_insert_irq_data(struct irq_domain *domain, return irq_data; } +static void __irq_domain_free_hierarchy(struct irq_data *irq_data) +{ + struct irq_data *tmp; + + while (irq_data) { + tmp = irq_data; + irq_data = irq_data->parent_data; + kfree(tmp); + } +} + static void irq_domain_free_irq_data(unsigned int virq, unsigned int nr_irqs) { struct irq_data *irq_data, *tmp; @@ -1147,14 +1158,49 @@ static void irq_domain_free_irq_data(unsigned int virq, unsigned int nr_irqs) irq_data->parent_data = NULL; irq_data->domain = NULL; - while (tmp) { - irq_data = tmp; - tmp = tmp->parent_data; - kfree(irq_data); - } + __irq_domain_free_hierarchy(tmp); } } +/** + * irq_domain_trim_hierarchy - Trim the irq hierarchy from a particular + * irq domain + * @virq: IRQ number to trim where the hierarchy is to be trimmed + * @domain: domain from which the hierarchy gets discarded for this + * interrupt + * + * Drop the partial irq_data hierarchy from @domain (included) onward. + * + * This is only meant to be called from a .alloc() callback, when no + * actual mapping in the respective domains has been established yet. + * Its only use is to be able to trim levels of hierarchy that do not + * have any real meaning for this interrupt. + */ +int irq_domain_trim_hierarchy(unsigned int virq, struct irq_domain *domain) +{ + struct irq_data *tail, *irq_data = irq_get_irq_data(virq); + + /* It really needs to be a hierarchy, and not a single entry */ + if (WARN_ON(!irq_data->parent_data)) + return -EINVAL; + + /* Skip until we find the right domain */ + while (irq_data->parent_data && irq_data->parent_data->domain != domain) + irq_data = irq_data->parent_data; + + /* The domain doesn't exist in the hierarchy, which is pretty bad */ + if (WARN_ON(!irq_data->parent_data)) + return -ENOENT; + + /* Sever the inner part of the hierarchy... */ + tail = irq_data->parent_data; + irq_data->parent_data = NULL; + __irq_domain_free_hierarchy(tail); + + return 0; +} + + static int irq_domain_alloc_irq_data(struct irq_domain *domain, unsigned int virq, unsigned int nr_irqs) {