From patchwork Mon Jan 22 08:57:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dawei Li X-Patchwork-Id: 13524972 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EFD54C47DAF for ; Mon, 22 Jan 2024 09:00:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ovUJAYErD8IQDxM/ARkmO0dmtXiSsTyJ+BYPeWiGeK0=; b=qpnKKMJQ3Z9CEP IsMupXIr4+Yme1Lrbg7J7O7T6jYT318jBxLfMhXhtNVImalqabGhp6DGrehsDueatZvJ3tGF4q8EW gekN7VAIOjW/3oC9CXLHxWFYTYYbq3gisAA1wnaFQiYBw/+xBOgLAD1x7ZmMps+MOpfv+k8xBbUWH EZO0BoHnt8j/lmBUdc8P9xI59m2nTBJiroZbOdIcxxJ/aNuzo+cPpmNyxQ8WYJsWSM7i5uQhGB+81 lq2frttYPxIgYngFYpjf1grCmAjmV99CNyV8KZumiP+7Vj2y9xnEsj5661/oaoLz04fAmVvNEqaW/ 2zOZG2y7EvTJ592Ydesw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rRq9Q-00BB2C-2S; Mon, 22 Jan 2024 08:59:28 +0000 Received: from smtpbguseast2.qq.com ([54.204.34.130]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rRq9N-00BAze-2g for linux-arm-kernel@lists.infradead.org; Mon, 22 Jan 2024 08:59:27 +0000 X-QQ-mid: bizesmtp75t1705913948tfi179xy X-QQ-Originating-IP: i6JR3JSt3cx8j++LW7stv6+R9DhNrBauvB6V63faj80= Received: from localhost ( [183.209.108.228]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 22 Jan 2024 16:59:06 +0800 (CST) X-QQ-SSF: 01400000000000504000000A0000000 X-QQ-FEAT: hUW8LCq5FglZ2z+ojiA3s/8JPKADLltKuo8EOcgk5msgqoe62zuiEGg6SlCHi 6xpSw7HQ/6r00e0SG9EC5RqgvQYBXdxFdi5RDepHdoDaO6vnArAjkdqWn8v94RjAqQePshU 38XwU7VNCKsCS78/KkXygITyYGrpscfRaNSow/O5FWqicd5LarvNGa0JRr3FZsPl3gwGmZi uXyLQayzaVLcLq/QNJtaGltRk3S+wEk7WUJ88R6IHiY7Zv4x/SecMwIIdi9mI9lk/X8SjHp lSzSzo3BBw4+7uhYWxt3jXiBUGO3GpMkStQTahVxYwjiawW+ahRSlGYBM0cuzGJFRwL/mcP oSxMJwaFBRtFWMZOqWy5n4VwSOuAb1zhyybsqNxWQw6OoTo3mQJuTdXp4Wvql6LJSOrLyyC eTZIm8xcyFFSEwdIDfbVpg== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 17265005081318603409 From: Dawei Li To: tglx@linutronix.de, maz@kernel.org Cc: sdonthineni@nvidia.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, dawei.li@shingroup.cn, set_pte_at@outlook.com Subject: [PATCH v2 1/5] irqchip/gic-v3: Implement read polling with dedicated API Date: Mon, 22 Jan 2024 16:57:12 +0800 Message-Id: <20240122085716.2999875-2-dawei.li@shingroup.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240122085716.2999875-1-dawei.li@shingroup.cn> References: <20240122085716.2999875-1-dawei.li@shingroup.cn> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:shingroup.cn:qybglogicsvrgz:qybglogicsvrgz5a-1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240122_005926_334484_7B8E20F2 X-CRM114-Status: GOOD ( 13.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Kernel provide read*_poll_* API family to support looping based polling code pattern like below: while (...) { val = op(addr); condition = cond(val); if (condition) break; /* Maybe some timeout handling stuff */ cpu_relax(); udelay(); } As such, use readl_relaxed_poll_timeout_atomic() to implement atomic register polling logic in gic-v3. It's worth noting that this conversion would be impossilbe without support of commit 7349a69cf312 ("iopoll: Do not use timekeeping in read_poll_timeout_atomic()"), which remove time keeping code from read_poll_timeout_atomic(), reason below: Compared to other 'ordinary' device driver, IRQ chip driver is kinda special, whose initialization(via init_IRQ()) happens pretty early, even before timekeeping_init(). As a result, calling time keeping code in irq chip init code is bogus. Signed-off-by: Dawei Li --- drivers/irqchip/irq-gic-v3.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c index 98b0329b7154..020a67195b16 100644 --- a/drivers/irqchip/irq-gic-v3.c +++ b/drivers/irqchip/irq-gic-v3.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -251,17 +252,16 @@ static inline void __iomem *gic_dist_base(struct irq_data *d) static void gic_do_wait_for_rwp(void __iomem *base, u32 bit) { - u32 count = 1000000; /* 1s! */ + u32 val; + int ret; - while (readl_relaxed(base + GICD_CTLR) & bit) { - count--; - if (!count) { - pr_err_ratelimited("RWP timeout, gone fishing\n"); - return; - } - cpu_relax(); - udelay(1); - } + ret = readl_relaxed_poll_timeout_atomic(base + GICD_CTLR, + val, + !(val & bit), + 1, + USEC_PER_SEC); + if (ret == -ETIMEDOUT) + pr_err_ratelimited("RWP timeout, gone fishing\n"); } /* Wait for completion of a distributor change */ @@ -279,8 +279,8 @@ static void gic_redist_wait_for_rwp(void) static void gic_enable_redist(bool enable) { void __iomem *rbase; - u32 count = 1000000; /* 1s! */ u32 val; + int ret; if (gic_data.flags & FLAGS_WORKAROUND_GICR_WAKER_MSM8996) return; @@ -301,14 +301,12 @@ static void gic_enable_redist(bool enable) return; /* No PM support in this redistributor */ } - while (--count) { - val = readl_relaxed(rbase + GICR_WAKER); - if (enable ^ (bool)(val & GICR_WAKER_ChildrenAsleep)) - break; - cpu_relax(); - udelay(1); - } - if (!count) + ret = readl_relaxed_poll_timeout_atomic(rbase + GICR_WAKER, + val, + enable ^ (bool)(val & GICR_WAKER_ChildrenAsleep), + 1, + USEC_PER_SEC); + if (ret == -ETIMEDOUT) pr_err_ratelimited("redistributor failed to %s...\n", enable ? "wakeup" : "sleep"); } From patchwork Mon Jan 22 08:57:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dawei Li X-Patchwork-Id: 13524973 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 122D9C47DAF for ; Mon, 22 Jan 2024 09:00:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SfoDwUpA5//7eaFCywjiS+KSluoHawo59VUV2zQqDt4=; b=Z5VP78jDMTgsVF eTUauFdDuaPO1Av+XNTnlEJMQan7Dn6vabS79pX2AswjdVe/Q5XJuY1mZGDYzx8+MNTYUVdAtORlw lJ9K+ru1nKlmHknY8u/L8hpAxniM9b5Vt2Icyi2Y2ojwLomHx7xhOiU+HItsZiIByFv9FvkFaTj0i I9KNWlm+pFfCvs8+JaiM1o1Jrw3kwTj3hyZhAYNfQRR5rNXPkFEdgeEtxNOI9kF/xCJ5ObaNvIraw 2B2NNXWbxWjYmjEfFdj6MZrkMgl7qvZgvlyBwsN08Ofli+XCNaVl/HBCS9XxCj4eTsZJaXadVbBCx bEwhFBP8AJyFF8M843hQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rRq9W-00BB4A-0I; Mon, 22 Jan 2024 08:59:34 +0000 Received: from smtpbgau1.qq.com ([54.206.16.166]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rRq9R-00BB0m-19 for linux-arm-kernel@lists.infradead.org; Mon, 22 Jan 2024 08:59:31 +0000 X-QQ-mid: bizesmtp71t1705913955tp7l95fl X-QQ-Originating-IP: mRqY/56D25rXn1dtjsDHZjwbILtFFtCIuoelvrp9ScE= Received: from localhost ( [183.209.108.228]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 22 Jan 2024 16:59:14 +0800 (CST) X-QQ-SSF: 01400000000000504000000A0000000 X-QQ-FEAT: 7jw2iSiCazrhE3SL65waJ5hi4B26LQXMtfFvfm57A7zCqfqh4nhbiM0mUWsGj UF7tZcfaQavPQS7f76Z99gEn6cs+9FuqADs7dymzmeQ1PLWvQSqp3DiR2Y0YyIFj6wrqQue WNu85dOH1gsCGCjw2y+sfEy+PTXZnJKyornIm+vjxB6VlqWlc6q/1VdxJNz4yadfudeVMte Fu2RZHVPB0w8xJoQsBt1KtcSVNWEOXVcDQOmpKF1wBwaKr3qiQo4gbIPc72Lun9iGQSe9EX gjxEzysR8NsUZUFQxQkpPPA3fzioMNGUfn+nBpw/0fGfjwObjaCgY/icDpiEkpa0QIm94zR I3FbbKXawUgBPRolg35rp+r1ZwFoNp1LGdzH63D9by77DdPY+TMD5+Sa2f03lbrZZrs+WsX rn3QQ1ZE47IYTktYUMs3mw== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 3206202564206613781 From: Dawei Li To: tglx@linutronix.de, maz@kernel.org Cc: sdonthineni@nvidia.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, dawei.li@shingroup.cn, set_pte_at@outlook.com Subject: [PATCH v2 2/5] irqchip/gic(v3): Replace gic_irq() with irqd_to_hwirq() Date: Mon, 22 Jan 2024 16:57:13 +0800 Message-Id: <20240122085716.2999875-3-dawei.li@shingroup.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240122085716.2999875-1-dawei.li@shingroup.cn> References: <20240122085716.2999875-1-dawei.li@shingroup.cn> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:shingroup.cn:qybglogicsvrgz:qybglogicsvrgz5a-1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240122_005929_802617_276F1E03 X-CRM114-Status: GOOD ( 17.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org GIC & GIC-v3 share same gic_irq() implementations, both of which serve exact same purpose of irqd_to_hwirq(). irqd_to_hwirq() is a generic and top level API of interrupt subsystem, it's independent of any chip implementation. As such, replace gic_irq() with irqd_to_hwirq() in gic(v3) code. Also, convert the type of struct irq_data::hwirq to irq_hw_number_t explicitly. Suggested-by: Marc Zyngier Signed-off-by: Dawei Li --- drivers/irqchip/irq-gic-v3.c | 19 +++++++------------ drivers/irqchip/irq-gic.c | 27 ++++++++++++--------------- include/linux/irq.h | 2 +- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c index 020a67195b16..b6cc23e393e3 100644 --- a/drivers/irqchip/irq-gic-v3.c +++ b/drivers/irqchip/irq-gic-v3.c @@ -181,11 +181,6 @@ static enum gic_intid_range get_intid_range(struct irq_data *d) return __get_intid_range(d->hwirq); } -static inline unsigned int gic_irq(struct irq_data *d) -{ - return d->hwirq; -} - static inline bool gic_irq_in_rdist(struct irq_data *d) { switch (get_intid_range(d)) { @@ -546,7 +541,7 @@ static int gic_irq_nmi_setup(struct irq_data *d) * A secondary irq_chip should be in charge of LPI request, * it should not be possible to get there */ - if (WARN_ON(gic_irq(d) >= 8192)) + if (WARN_ON(irqd_to_hwirq(d) >= 8192)) return -EINVAL; /* desc lock should already be held */ @@ -586,7 +581,7 @@ static void gic_irq_nmi_teardown(struct irq_data *d) * A secondary irq_chip should be in charge of LPI request, * it should not be possible to get there */ - if (WARN_ON(gic_irq(d) >= 8192)) + if (WARN_ON(irqd_to_hwirq(d) >= 8192)) return; /* desc lock should already be held */ @@ -624,7 +619,7 @@ static bool gic_arm64_erratum_2941627_needed(struct irq_data *d) static void gic_eoi_irq(struct irq_data *d) { - write_gicreg(gic_irq(d), ICC_EOIR1_EL1); + write_gicreg(irqd_to_hwirq(d), ICC_EOIR1_EL1); isb(); if (gic_arm64_erratum_2941627_needed(d)) { @@ -644,19 +639,19 @@ static void gic_eoimode1_eoi_irq(struct irq_data *d) * No need to deactivate an LPI, or an interrupt that * is is getting forwarded to a vcpu. */ - if (gic_irq(d) >= 8192 || irqd_is_forwarded_to_vcpu(d)) + if (irqd_to_hwirq(d) >= 8192 || irqd_is_forwarded_to_vcpu(d)) return; if (!gic_arm64_erratum_2941627_needed(d)) - gic_write_dir(gic_irq(d)); + gic_write_dir(irqd_to_hwirq(d)); else gic_poke_irq(d, GICD_ICACTIVER); } static int gic_set_type(struct irq_data *d, unsigned int type) { + irq_hw_number_t irq = irqd_to_hwirq(d); enum gic_intid_range range; - unsigned int irq = gic_irq(d); void __iomem *base; u32 offset, index; int ret; @@ -682,7 +677,7 @@ static int gic_set_type(struct irq_data *d, unsigned int type) ret = gic_configure_irq(index, type, base + offset, NULL); if (ret && (range == PPI_RANGE || range == EPPI_RANGE)) { /* Misconfigured PPIs are usually not fatal */ - pr_warn("GIC: PPI INTID%d is secure or misconfigured\n", irq); + pr_warn("GIC: PPI INTID%ld is secure or misconfigured\n", irq); ret = 0; } diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c index 412196a7dad5..98aa383e39db 100644 --- a/drivers/irqchip/irq-gic.c +++ b/drivers/irqchip/irq-gic.c @@ -162,11 +162,6 @@ static inline void __iomem *gic_cpu_base(struct irq_data *d) return gic_data_cpu_base(gic_data); } -static inline unsigned int gic_irq(struct irq_data *d) -{ - return d->hwirq; -} - static inline bool cascading_gic_irq(struct irq_data *d) { void *data = irq_data_get_irq_handler_data(d); @@ -183,14 +178,16 @@ static inline bool cascading_gic_irq(struct irq_data *d) */ static void gic_poke_irq(struct irq_data *d, u32 offset) { - u32 mask = 1 << (gic_irq(d) % 32); - writel_relaxed(mask, gic_dist_base(d) + offset + (gic_irq(d) / 32) * 4); + u32 mask = 1 << (irqd_to_hwirq(d) % 32); + + writel_relaxed(mask, gic_dist_base(d) + offset + (irqd_to_hwirq(d) / 32) * 4); } static int gic_peek_irq(struct irq_data *d, u32 offset) { - u32 mask = 1 << (gic_irq(d) % 32); - return !!(readl_relaxed(gic_dist_base(d) + offset + (gic_irq(d) / 32) * 4) & mask); + u32 mask = 1 << (irqd_to_hwirq(d) % 32); + + return !!(readl_relaxed(gic_dist_base(d) + offset + (irqd_to_hwirq(d) / 32) * 4) & mask); } static void gic_mask_irq(struct irq_data *d) @@ -220,7 +217,7 @@ static void gic_unmask_irq(struct irq_data *d) static void gic_eoi_irq(struct irq_data *d) { - u32 hwirq = gic_irq(d); + irq_hw_number_t hwirq = irqd_to_hwirq(d); if (hwirq < 16) hwirq = this_cpu_read(sgi_intid); @@ -230,7 +227,7 @@ static void gic_eoi_irq(struct irq_data *d) static void gic_eoimode1_eoi_irq(struct irq_data *d) { - u32 hwirq = gic_irq(d); + irq_hw_number_t hwirq = irqd_to_hwirq(d); /* Do not deactivate an IRQ forwarded to a vcpu. */ if (irqd_is_forwarded_to_vcpu(d)) @@ -293,8 +290,8 @@ static int gic_irq_get_irqchip_state(struct irq_data *d, static int gic_set_type(struct irq_data *d, unsigned int type) { + irq_hw_number_t gicirq = irqd_to_hwirq(d); void __iomem *base = gic_dist_base(d); - unsigned int gicirq = gic_irq(d); int ret; /* Interrupt configuration for SGIs can't be changed */ @@ -309,7 +306,7 @@ static int gic_set_type(struct irq_data *d, unsigned int type) ret = gic_configure_irq(gicirq, type, base + GIC_DIST_CONFIG, NULL); if (ret && gicirq < 32) { /* Misconfigured PPIs are usually not fatal */ - pr_warn("GIC: PPI%d is secure or misconfigured\n", gicirq - 16); + pr_warn("GIC: PPI%ld is secure or misconfigured\n", gicirq - 16); ret = 0; } @@ -319,7 +316,7 @@ static int gic_set_type(struct irq_data *d, unsigned int type) static int gic_irq_set_vcpu_affinity(struct irq_data *d, void *vcpu) { /* Only interrupts on the primary GIC can be forwarded to a vcpu. */ - if (cascading_gic_irq(d) || gic_irq(d) < 16) + if (cascading_gic_irq(d) || irqd_to_hwirq(d) < 16) return -EINVAL; if (vcpu) @@ -796,7 +793,7 @@ static void rmw_writeb(u8 bval, void __iomem *addr) static int gic_set_affinity(struct irq_data *d, const struct cpumask *mask_val, bool force) { - void __iomem *reg = gic_dist_base(d) + GIC_DIST_TARGET + gic_irq(d); + void __iomem *reg = gic_dist_base(d) + GIC_DIST_TARGET + irqd_to_hwirq(d); struct gic_chip_data *gic = irq_data_get_irq_chip_data(d); unsigned int cpu; diff --git a/include/linux/irq.h b/include/linux/irq.h index 90081afa10ce..97baa937ab5b 100644 --- a/include/linux/irq.h +++ b/include/linux/irq.h @@ -179,7 +179,7 @@ struct irq_common_data { struct irq_data { u32 mask; unsigned int irq; - unsigned long hwirq; + irq_hw_number_t hwirq; struct irq_common_data *common; struct irq_chip *chip; struct irq_domain *domain; From patchwork Mon Jan 22 08:57:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dawei Li X-Patchwork-Id: 13524974 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A7B0EC47DAF for ; Mon, 22 Jan 2024 09:00:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HI0HQ+Xd1X9HwTfuOGkZRLuTdqRdIY8XBgRfiFTiW/E=; b=B8OGRBV/kAps8J YVZnSWvO99WLZhwkrUzk6wrEmlYBJKO0DxidiFt61rzdca0SOCfl8M648CML1I/H1Epy9/EzAyh8T Ag4qG1GNZtnkywJI53quixbcRkCnx5mCj+WCVdmbvjcXB1R+uCE7BsL4p3ADBMZC8CfZGeS6hFRDm ZEweQRKdr/3PkKePO6ma3btq2ULw4Ei5dlQ5zmLnoWpVYWIaZ8PpnwyGslgUDiCotkBkS50pbABm/ DSMnDcwR4Bc2/d9cDDWViPwDgdEgiY7/cLTl+A+HmHMCpCu9PCOnsz2JAXsKd4fRvit7KPbq9yS6n SixcFQKHuewhT8ryRQLA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rRq9i-00BB9W-00; Mon, 22 Jan 2024 08:59:46 +0000 Received: from smtpbg153.qq.com ([13.245.218.24]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rRq9c-00BB1W-2K for linux-arm-kernel@lists.infradead.org; Mon, 22 Jan 2024 08:59:44 +0000 X-QQ-mid: bizesmtp67t1705913961t85cfrv6 X-QQ-Originating-IP: Zbqb4cYRrAfjgdkohOYDHL1acuGqxCL9qIdSGxPWK34= Received: from localhost ( [183.209.108.228]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 22 Jan 2024 16:59:20 +0800 (CST) X-QQ-SSF: 01400000000000504000000A0000000 X-QQ-FEAT: IcCSTr/hHjMffnhAik5vVQWmaGruOwvbYfTo1SfI6PpCNqAHo+YFVhP6/2EVs OvyWr6QV8R9qZ4irF4Ej2pLyo52eCxA4oFcYLvNb57Ub1ZUHXR7Os2AcCRq0O8Mx4iOQDhX tKBK1G/DetFIa4bmLR4/942oRRCAMw82GYsIs9pxgswpRCrsuvvEOaP40u0pTOVuYdhVZaw adJKmSGHazuAlTR0Q4oxmQ0yeOzv8WBW8h+dZHNuByhtxZwkqoXxfIPvDyOqab/E1Sza4xD NXcYEzOxyjoqdrM/47njdBzZcugj7EtGPY4ZavaWgr+ggVM7GAJDJGUdmA3NyO8D/lgzin9 VcCBzAKd+xA/jOknqYgNY2xXInfmtUd8Jd+nZE2IzGN9jBuBWRB5+OI8+ieLQZyvlZ3ep8L 1bhxTPYF4dUS+0i3GlOsZM/mMBVm0MG1 X-QQ-GoodBg: 2 X-BIZMAIL-ID: 2264952194026769334 From: Dawei Li To: tglx@linutronix.de, maz@kernel.org Cc: sdonthineni@nvidia.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, dawei.li@shingroup.cn, set_pte_at@outlook.com Subject: [PATCH v2 3/5] genirq: Remove unneeded forward declaration Date: Mon, 22 Jan 2024 16:57:14 +0800 Message-Id: <20240122085716.2999875-4-dawei.li@shingroup.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240122085716.2999875-1-dawei.li@shingroup.cn> References: <20240122085716.2999875-1-dawei.li@shingroup.cn> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:shingroup.cn:qybglogicsvrgz:qybglogicsvrgz5a-1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240122_005941_650928_3CF84ABB X-CRM114-Status: UNSURE ( 9.08 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Protoype of irq_flow_handler_t is independent of irq_data, so remove unneeded forward declaration. Signed-off-by: Dawei Li --- include/linux/irqhandler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/irqhandler.h b/include/linux/irqhandler.h index c30f454a9518..72dd1eb3a0e7 100644 --- a/include/linux/irqhandler.h +++ b/include/linux/irqhandler.h @@ -8,7 +8,7 @@ */ struct irq_desc; -struct irq_data; + typedef void (*irq_flow_handler_t)(struct irq_desc *desc); #endif From patchwork Mon Jan 22 08:57:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dawei Li X-Patchwork-Id: 13524975 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5C5F3C47DAF for ; Mon, 22 Jan 2024 09:00:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BrTA9x7I+Fw96Vur28SPVJelP7nVWd1v0ttGW/1BRHY=; b=eh3rOsmIIXE/nx r3wvUELd3FA1wI996LL4Isu1n3nzj+5s/Z6YCGrwbOwnWEC6KTq1obWWGz6JHINXMYHRNR9xsliEy Mug5PZVFwABznUTLTHAapxuNx2L0+vQULcwukNLMEbVaPLW42W7Oo1wCYlwbFYe9M6K5tmVAx7yDc c1LLmQg9xfmNXDby//FUlF0O8D7VxqTq1zUOjH4ELyoukZLcWgpw4p4fPychWt6iW0qEhIwtW13U6 Opz6CTUgb7tHB5G8eBawwwAmsx/UQy7Hdn/+xyDFA7xENA/8KU6DuPCRweCbrKp4dwwYZmgPYUZbf +jHwso0W69GnC2ndx11w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rRq9m-00BBCC-2M; Mon, 22 Jan 2024 08:59:50 +0000 Received: from smtpbgsg2.qq.com ([54.254.200.128]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rRq9j-00BB59-0n for linux-arm-kernel@lists.infradead.org; Mon, 22 Jan 2024 08:59:48 +0000 X-QQ-mid: bizesmtp69t1705913968t4x91ja8 X-QQ-Originating-IP: gUy0qjJACJmrxRTWjfX/xlWmCxQVo4qzhx3gV7F419E= Received: from localhost ( [183.209.108.228]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 22 Jan 2024 16:59:26 +0800 (CST) X-QQ-SSF: 01400000000000504000000A0000000 X-QQ-FEAT: IcCSTr/hHjNrGNwJGBhoO6iQm9TbZEJVmwOVI/u90M+u6dL3vPHrcIcOGVpYE 3xnlu/yVMyOGkIJ66R4R6neq8C/BM94XzIVAWppJE1t5/EBTlH16aGVL2ZG2Cuq7ti6EHEl dICnf+4WHwFK2FYyeN5SAYUWxzfnnyd+Y4EdNv/RTyv4+OwaNrW5RuUvfC6oPlrh6jOAj9g Jjv0kMj4f2l6sbW8lZtbreylbZqv4IS/lw4sRpztsh+MVPGhtuBoaJdGFTIH8IYChJnPA+I Uc0R9vTKFF4jdMVoEjWkQYeAHzWOAoP2dWvlvtCtRlQFgdM62WGIZ0CiL1H/D39d3hcp37b 2vO55zzySM78h8yB8PZ6DQ34ZuhIanlAE9x6s82ulILRUbuhe0MPtyJk47ESPwippLBb2of wwXoP/E3Xepk6H1MgSGFig== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 16519766725060776921 From: Dawei Li To: tglx@linutronix.de, maz@kernel.org Cc: sdonthineni@nvidia.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, dawei.li@shingroup.cn, set_pte_at@outlook.com, stable@vger.kernel.org Subject: [PATCH v2 4/5] genirq: Initialize resend_node hlist for all irq_desc Date: Mon, 22 Jan 2024 16:57:15 +0800 Message-Id: <20240122085716.2999875-5-dawei.li@shingroup.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240122085716.2999875-1-dawei.li@shingroup.cn> References: <20240122085716.2999875-1-dawei.li@shingroup.cn> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:shingroup.cn:qybglogicsvrgz:qybglogicsvrgz5a-1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240122_005947_640791_0CD0C4AA X-CRM114-Status: GOOD ( 10.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org For !CONFIG_SPARSE_IRQ kernel, early_irq_init() is supposed to initialize all the desc entries in system, desc->resend_node included. Thus, initialize desc->resend_node for all irq_desc entries, rather than irq_desc[0] only, which is the current implementation is about. Fixes: bc06a9e08742 ("genirq: Use hlist for managing resend handlers") Cc: stable@vger.kernel.org Acked-by: Marc Zyngier Signed-off-by: Dawei Li --- kernel/irq/irqdesc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index 27ca1c866f29..371eb1711d34 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -600,7 +600,7 @@ int __init early_irq_init(void) mutex_init(&desc[i].request_mutex); init_waitqueue_head(&desc[i].wait_for_threads); desc_set_defaults(i, &desc[i], node, NULL, NULL); - irq_resend_init(desc); + irq_resend_init(&desc[i]); } return arch_early_irq_init(); } From patchwork Mon Jan 22 08:57:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dawei Li X-Patchwork-Id: 13524976 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 412E4C47DAF for ; Mon, 22 Jan 2024 09:00:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=DYx/3fHYCiXhvVGja/uaQ5pn137SjIn+C78DamzCYjg=; b=0nEMfSnV6iu6Ih Wm0skzlwzX7n+Z+F782w1sEQwWj2bfB21mESPTMpoCOC5CR9PC89bJt7+j8IZMLndXQnD14IrW+yV v18zmPc/2HlRgFkOkdQJKwX1Aut6jLG+cm3vduMdI6p90/BgzdYGMYV/DV4DLo6YqaoXHh8lzpdjZ sDtAeVj8/Ou48LdqQ1m8Ix0JceyPfFyP8dWfW/JvP/mud4VgNjJVVr+t9FD96Oivth5CW0Lcti39h Y5H+gPcWjE+AjlZmTt+0izOAfFvI9ces6zwGQs94QUEBL3+Wsyk6vO852oIhKwCOt3/euF7zqLsrA KTzmLRGJRWge9JiAy1Yg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rRq9s-00BBG3-1z; Mon, 22 Jan 2024 08:59:56 +0000 Received: from smtpbg151.qq.com ([18.169.211.239]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rRq9m-00BB6I-0p for linux-arm-kernel@lists.infradead.org; Mon, 22 Jan 2024 08:59:53 +0000 X-QQ-mid: bizesmtp78t1705913974t57cu8k8 X-QQ-Originating-IP: s/TlBuwIYZZTyK7aGHMX5P4SXDcbXIo8PDZLExa747k= Received: from localhost ( [183.209.108.228]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 22 Jan 2024 16:59:33 +0800 (CST) X-QQ-SSF: 01400000000000504000000A0000000 X-QQ-FEAT: XBN7tc9DADK7QBXL2kByKL2tvBKd77LE3lWppuxmnlTTAGPJhU5/1Q2qHw60Y vIpo+KzaBtErcYPYaqZ5kMN9JoyroipuWSBY9bTq1MnBlHXOc4wj/7GCXFjQcbjnK656Ot+ GOrqeCsTY8psboq1gwc7tlKlEERzJirpC9jBKJKAlcHAS1doAU9Agq7iimlBkrHbtWogeRP 1WWUE4N0fKjo3z4MKkAfC23FHZM271cwYzdrLDfB7a2PWtAffqjoQwYkTIJIKG46JF2yvDr QAjkU8yYTmCVPxDGhcHe7rV2/JhTzeNWFsLUv7JTlicTn9tDf2mLvINCbdfUcSMucSbuR5E cKj5IIixcjoz7fGFWh1TxrE+JWWJaRNErJUhT5zPtCV1ganS8EMW8dZKObTBFL8vDelCtVH PqsVCfytt640sX5QmlZfYA== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 6969862050616083631 From: Dawei Li To: tglx@linutronix.de, maz@kernel.org Cc: sdonthineni@nvidia.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, dawei.li@shingroup.cn, set_pte_at@outlook.com Subject: [PATCH v2 5/5] genirq: Introduce generic init_desc() Date: Mon, 22 Jan 2024 16:57:16 +0800 Message-Id: <20240122085716.2999875-6-dawei.li@shingroup.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240122085716.2999875-1-dawei.li@shingroup.cn> References: <20240122085716.2999875-1-dawei.li@shingroup.cn> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:shingroup.cn:qybglogicsvrgz:qybglogicsvrgz5a-1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240122_005950_851719_8C7A9751 X-CRM114-Status: GOOD ( 15.51 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Those two functions below share much duplicated codes for initialization for irq_desc: - alloc_desc() CONFIG_SPARSE_IRQ - early_irq_init() !CONFIG_SPARSE_IRQ Implement a dedicated function to fully initialize irq_desc. Also, make free_masks() global to implement exception handling in early_irq_init. Suggested-by: Marc Zyngier Signed-off-by: Dawei Li --- kernel/irq/irqdesc.c | 112 ++++++++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 48 deletions(-) diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index 371eb1711d34..4c6b32318ce3 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -92,11 +92,23 @@ static void desc_smp_init(struct irq_desc *desc, int node, #endif } +static void free_masks(struct irq_desc *desc) +{ +#ifdef CONFIG_GENERIC_PENDING_IRQ + free_cpumask_var(desc->pending_mask); +#endif + free_cpumask_var(desc->irq_common_data.affinity); +#ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK + free_cpumask_var(desc->irq_common_data.effective_affinity); +#endif +} + #else static inline int alloc_masks(struct irq_desc *desc, int node) { return 0; } static inline void desc_smp_init(struct irq_desc *desc, int node, const struct cpumask *affinity) { } +static inline void free_masks(struct irq_desc *desc) { } #endif static void desc_set_defaults(unsigned int irq, struct irq_desc *desc, int node, @@ -165,6 +177,39 @@ static void delete_irq_desc(unsigned int irq) mas_erase(&mas); } +#ifdef CONFIG_SPARSE_IRQ +static const struct kobj_type irq_kobj_type; +#endif + +static int init_desc(struct irq_desc *desc, int irq, int node, + unsigned int flags, + const struct cpumask *affinity, + struct module *owner) +{ + desc->kstat_irqs = alloc_percpu(unsigned int); + if (!desc->kstat_irqs) + return -ENOMEM; + + if (alloc_masks(desc, node)) { + free_percpu(desc->kstat_irqs); + return -ENOMEM; + } + + raw_spin_lock_init(&desc->lock); + lockdep_set_class(&desc->lock, &irq_desc_lock_class); + mutex_init(&desc->request_mutex); + init_waitqueue_head(&desc->wait_for_threads); + desc_set_defaults(irq, desc, node, affinity, owner); + irqd_set(&desc->irq_data, flags); + irq_resend_init(desc); +#ifdef CONFIG_SPARSE_IRQ + kobject_init(&desc->kobj, &irq_kobj_type); + init_rcu_head(&desc->rcu); +#endif + + return 0; +} + #ifdef CONFIG_SPARSE_IRQ static void irq_kobj_release(struct kobject *kobj); @@ -384,21 +429,6 @@ struct irq_desc *irq_to_desc(unsigned int irq) EXPORT_SYMBOL_GPL(irq_to_desc); #endif -#ifdef CONFIG_SMP -static void free_masks(struct irq_desc *desc) -{ -#ifdef CONFIG_GENERIC_PENDING_IRQ - free_cpumask_var(desc->pending_mask); -#endif - free_cpumask_var(desc->irq_common_data.affinity); -#ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK - free_cpumask_var(desc->irq_common_data.effective_affinity); -#endif -} -#else -static inline void free_masks(struct irq_desc *desc) { } -#endif - void irq_lock_sparse(void) { mutex_lock(&sparse_irq_lock); @@ -414,36 +444,19 @@ static struct irq_desc *alloc_desc(int irq, int node, unsigned int flags, struct module *owner) { struct irq_desc *desc; + int ret; desc = kzalloc_node(sizeof(*desc), GFP_KERNEL, node); if (!desc) return NULL; - /* allocate based on nr_cpu_ids */ - desc->kstat_irqs = alloc_percpu(unsigned int); - if (!desc->kstat_irqs) - goto err_desc; - - if (alloc_masks(desc, node)) - goto err_kstat; - raw_spin_lock_init(&desc->lock); - lockdep_set_class(&desc->lock, &irq_desc_lock_class); - mutex_init(&desc->request_mutex); - init_rcu_head(&desc->rcu); - init_waitqueue_head(&desc->wait_for_threads); - - desc_set_defaults(irq, desc, node, affinity, owner); - irqd_set(&desc->irq_data, flags); - kobject_init(&desc->kobj, &irq_kobj_type); - irq_resend_init(desc); + ret = init_desc(desc, irq, node, flags, affinity, owner); + if (unlikely(ret)) { + kfree(desc); + return NULL; + } return desc; - -err_kstat: - free_percpu(desc->kstat_irqs); -err_desc: - kfree(desc); - return NULL; } static void irq_kobj_release(struct kobject *kobj) @@ -583,26 +596,29 @@ struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = { int __init early_irq_init(void) { int count, i, node = first_online_node; - struct irq_desc *desc; + int ret; init_irq_default_affinity(); printk(KERN_INFO "NR_IRQS: %d\n", NR_IRQS); - desc = irq_desc; count = ARRAY_SIZE(irq_desc); for (i = 0; i < count; i++) { - desc[i].kstat_irqs = alloc_percpu(unsigned int); - alloc_masks(&desc[i], node); - raw_spin_lock_init(&desc[i].lock); - lockdep_set_class(&desc[i].lock, &irq_desc_lock_class); - mutex_init(&desc[i].request_mutex); - init_waitqueue_head(&desc[i].wait_for_threads); - desc_set_defaults(i, &desc[i], node, NULL, NULL); - irq_resend_init(&desc[i]); + ret = init_desc(irq_desc + i, i, node, 0, NULL, NULL); + if (unlikely(ret)) + goto __free_desc_res; } + return arch_early_irq_init(); + +__free_desc_res: + while (--i >= 0) { + free_masks(irq_desc + i); + free_percpu(irq_desc[i].kstat_irqs); + } + + return ret; } struct irq_desc *irq_to_desc(unsigned int irq)