From nobody Fri Feb 13 05:47:35 2026 Received: from bg5.exmail.qq.com (bg5.exmail.qq.com [43.154.197.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17835548EF for ; Fri, 12 Apr 2024 10:59:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=43.154.197.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712919570; cv=none; b=WinS7GlpwLpJ3SCM0bS1uQX31UfKzOauFX9+yXOrPbkdpd65LQm56GBcBthDif7sja1eE2U1ncNEozmxMx8BpZYs5GxCs0aXs2ywcQayRvTP/UPKn+t05u4S3jK0/xyMgdwpDBxUaehf2aKoqfsPTolN5ejr7+pHXYgOLFuA0fg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712919570; c=relaxed/simple; bh=1sBhyvz1fxNkFqL0yFOzYr/XO/zKc8UzE3DM3vAvTsQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=q0LrPTfdJt/oqbxGt+/lXh7IXbiJML6yZTbgKmEL1X/TuovIhe1Gr5jNMyPVPNqcLNBI3BzWRdJBACJw5045u39YhzCt8P68dzNgLXNYvyJAqUnQ0XH7XKbCe9uKIbRon4YvZek0r7EZY3qSLdOieQnlEfqm4JMvun9OtlG+DG0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn; spf=pass smtp.mailfrom=shingroup.cn; arc=none smtp.client-ip=43.154.197.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shingroup.cn X-QQ-mid: bizesmtp80t1712919542t285z4q0 X-QQ-Originating-IP: P9W5CUCzmo74STeBAOKXjWV3lnnaXjPFC+yITRe8kF8= Received: from localhost ( [112.0.147.129]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 12 Apr 2024 18:59:00 +0800 (CST) X-QQ-SSF: 01400000000000903000000A0000000 X-QQ-FEAT: w1YG9MRGEBJKkTAyBrDV6RT3dBhtX93mXW6fSIaKArDqK5i71v7BXONlHvAty ahwXzLDzb0jWTi9IQTMfjoZJ8MJW2EKCnAMgLstA65WAoqS9U5i2pCOEaAArM3E+pHxuawt bAVfJIswMUzXEZkhbDjioNdgd8Pa1douq9gDNJjmiNRlsah0tGjUjSmCbWVZnDSqbMt2DWA Q1o0CfEludca8M917Fav6gdTOryyUMCmcVuprHlJ2ZqCsgsNHXIP0gPB8t3dnPvSGII57hR cIpNScuJshdwyMLU5Dsk7wRCWvMVeNh8VoNJUB10kl4y578ijfDDKL/8bPtxZ6mHUCoEQ21 aq66GP/zopHDICRpL973vsg1bwlH8FsLdZYEBR/GOPvfg3UKOsHS7DnXRPUcraVSNadZJko +8TxBYoGcZQxdhpugT27RQ== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 1337422365451864841 From: Dawei Li To: tglx@linutronix.de, yury.norov@gmail.com Cc: akpm@linux-foundation.org, maz@kernel.org, florian.fainelli@broadcom.com, chenhuacai@kernel.org, jiaxun.yang@flygoat.com, anup@brainfault.org, palmer@dabbelt.com, samuel.holland@sifive.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, Dawei Li Subject: [PATCH 1/6] cpumask: introduce cpumask_first_and_and() Date: Fri, 12 Apr 2024 18:58:34 +0800 Message-Id: <20240412105839.2896281-2-dawei.li@shingroup.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240412105839.2896281-1-dawei.li@shingroup.cn> References: <20240412105839.2896281-1-dawei.li@shingroup.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:shingroup.cn:qybglogicsvrgz:qybglogicsvrgz5a-1 Content-Type: text/plain; charset="utf-8" For some cases, it's required to make intersection between 3 cpumasks and return possible cpu bit. Current implementation for these cases are allocating a temporary cpumask var(sometimes on stack) storing intermediate calculation result. Introduce cpumask_first_and_and() to get rid of this intermediate orinted approach. Instead, cpumask_first_and_and() works in-place with all inputs and produce desired output directly. Signed-off-by: Dawei Li --- include/linux/cpumask.h | 17 +++++++++++++++++ include/linux/find.h | 29 +++++++++++++++++++++++++++++ lib/find_bit.c | 14 ++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 1c29947db848..c46f9e9e1d66 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -187,6 +187,23 @@ unsigned int cpumask_first_and(const struct cpumask *s= rcp1, const struct cpumask return find_first_and_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), small= _cpumask_bits); } =20 +/** + * cpumask_first_and_and - return the first cpu from *srcp1 & *srcp2 & *sr= cp3 + * @srcp1: the first input + * @srcp2: the second input + * @srcp3: the third input + * + * Return: >=3D nr_cpu_ids if no cpus set in all. + */ +static inline +unsigned int cpumask_first_and_and(const struct cpumask *srcp1, + const struct cpumask *srcp2, + const struct cpumask *srcp3) +{ + return find_first_and_and_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), + cpumask_bits(srcp3), small_cpumask_bits); +} + /** * cpumask_last - get the last CPU in a cpumask * @srcp: - the cpumask pointer diff --git a/include/linux/find.h b/include/linux/find.h index c69598e383c1..047081c6b9f7 100644 --- a/include/linux/find.h +++ b/include/linux/find.h @@ -29,6 +29,8 @@ unsigned long __find_nth_and_andnot_bit(const unsigned lo= ng *addr1, const unsign unsigned long n); extern unsigned long _find_first_and_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long size); +unsigned long _find_first_and_and_bit(const unsigned long *addr1, const un= signed long *addr2, + const unsigned long *addr3, unsigned long size); extern unsigned long _find_first_zero_bit(const unsigned long *addr, unsig= ned long size); extern unsigned long _find_last_bit(const unsigned long *addr, unsigned lo= ng size); =20 @@ -345,6 +347,33 @@ unsigned long find_first_and_bit(const unsigned long *= addr1, } #endif =20 +#ifndef find_first_and_and_bit +/** + * find_first_and_and_bit - find the first set bit in 3 memory regions + * @addr1: The first address to base the search on + * @addr2: The second address to base the search on + * @addr3: The third address to base the search on + * @size: The bitmap size in bits + * + * Returns the bit number for the first set bit + * If no bits are set, returns @size. + */ +static inline +unsigned long find_first_and_and_bit(const unsigned long *addr1, + const unsigned long *addr2, + const unsigned long *addr3, + unsigned long size) +{ + if (small_const_nbits(size)) { + unsigned long val =3D *addr1 & *addr2 & *addr3 & GENMASK(size - 1, 0); + + return val ? __ffs(val) : size; + } + + return _find_first_and_and_bit(addr1, addr2, addr3, size); +} +#endif + #ifndef find_first_zero_bit /** * find_first_zero_bit - find the first cleared bit in a memory region diff --git a/lib/find_bit.c b/lib/find_bit.c index 32f99e9a670e..fdc5c4117e8b 100644 --- a/lib/find_bit.c +++ b/lib/find_bit.c @@ -116,6 +116,20 @@ unsigned long _find_first_and_bit(const unsigned long = *addr1, EXPORT_SYMBOL(_find_first_and_bit); #endif =20 +#ifndef find_first_and_and_bit +/* + * Find the first set bit in three memory regions. + */ +unsigned long _find_first_and_and_bit(const unsigned long *addr1, + const unsigned long *addr2, + const unsigned long *addr3, + unsigned long size) +{ + return FIND_FIRST_BIT(addr1[idx] & addr2[idx] & addr3[idx], /* nop */, si= ze); +} +EXPORT_SYMBOL(_find_first_and_and_bit); +#endif + #ifndef find_first_zero_bit /* * Find the first cleared bit in a memory region. --=20 2.27.0 From nobody Fri Feb 13 05:47:35 2026 Received: from bg1.exmail.qq.com (bg1.exmail.qq.com [114.132.67.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B318B5491B for ; Fri, 12 Apr 2024 10:59:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.132.67.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712919572; cv=none; b=Mw4MS/LeSvx9avKtv0lItPX8s3hju6/bfzPFgm3BepinatUKFAoERtqSPaToVXhp38T8x9muzoN3E/FPgghIZJfflksui+KMcR2hJF6p4es5UUhHcm0cjPUZaO9htsNrEdv7sbltNkPPtc7Vt05Ws/4i/ChCLnYdEkwkI4KS0TA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712919572; c=relaxed/simple; bh=89OWL6oKQL9eoj0BTb0SEH2HgmwDSvtWGUqC2G83MKw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ueqPK0YCwF0cwzumd1llzmZ93fauA2GTfWHslPCeBDqlzVhkg8srsLP/yjAcaNR/BAnZq14XJjju5Ruy6H96WkCXwVjzngqquYDt6DIc0fy06RxswYLHKL2QRwc/3vylqknZbDYyyAb49Zz2pftMl1StmUq5ngv4VjiII93KDi0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn; spf=pass smtp.mailfrom=shingroup.cn; arc=none smtp.client-ip=114.132.67.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shingroup.cn X-QQ-mid: bizesmtp82t1712919548twkgcxfw X-QQ-Originating-IP: cTu8bWC6MQj9EpB/V8OFtgVpRbN3pOE3oBFgWv0OihE= Received: from localhost ( [112.0.147.129]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 12 Apr 2024 18:59:07 +0800 (CST) X-QQ-SSF: 01400000000000903000000A0000000 X-QQ-FEAT: RrZlkntZBfmamcRyuPfoyReZ1wjERGVK+iTPLZgwTojoaJ8M98IfPlIFJMjVP VYRr+4hX1twh8sTPH2sdFyggPmEN+vCMbfTm885aXD4a0kazTTdZYBVaqTzVPWzQjWxSMr6 tCkKOIki8KkWyQ9eYJ2d8gea8uBIcX/IUNMf/u+IQXQfpKUE6vfLkoChCJsH7k/9uL4QT0J Z75YR/YFWJ+oXLNuCiW0O2eAOQ5VqElPIbxPzTV7WHPkLDlqxNMtQu7hqYuJaMi6LanxywJ 0TIyujtEQGZqknhgAQe+VVYCrZ4uw81UkVBi5/SnpkjpuTZjZJoTlx+G+4M4mpBi0dKvBag cF1YgsBIFhCt/9yMwPcmTmA8Jy7W3LkIz+uhphaycwLywOD4OaZxcUwn1byriJ1sykK+kaU NQqNqjmjqCcRVKAl3Nr9oVLLRH4ebc+y X-QQ-GoodBg: 2 X-BIZMAIL-ID: 11251082261756714604 From: Dawei Li To: tglx@linutronix.de, yury.norov@gmail.com Cc: akpm@linux-foundation.org, maz@kernel.org, florian.fainelli@broadcom.com, chenhuacai@kernel.org, jiaxun.yang@flygoat.com, anup@brainfault.org, palmer@dabbelt.com, samuel.holland@sifive.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, Dawei Li Subject: [PATCH 2/6] irqchip/irq-bcm6345-l1: Avoid explicit cpumask allocation on stack Date: Fri, 12 Apr 2024 18:58:35 +0800 Message-Id: <20240412105839.2896281-3-dawei.li@shingroup.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240412105839.2896281-1-dawei.li@shingroup.cn> References: <20240412105839.2896281-1-dawei.li@shingroup.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:shingroup.cn:qybglogicsvrgz:qybglogicsvrgz5a-1 Content-Type: text/plain; charset="utf-8" In general it's preferable to avoid placing cpumasks on the stack, as for large values of NR_CPUS these can consume significant amounts of stack space and make stack overflows more likely. Use cpumask_first_and_and() to avoid the need for a temporary cpumask on the stack. Signed-off-by: Dawei Li --- drivers/irqchip/irq-bcm6345-l1.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/irqchip/irq-bcm6345-l1.c b/drivers/irqchip/irq-bcm6345= -l1.c index eb02d203c963..6df37957b39c 100644 --- a/drivers/irqchip/irq-bcm6345-l1.c +++ b/drivers/irqchip/irq-bcm6345-l1.c @@ -192,14 +192,11 @@ static int bcm6345_l1_set_affinity(struct irq_data *d, u32 mask =3D BIT(d->hwirq % IRQS_PER_WORD); unsigned int old_cpu =3D cpu_for_irq(intc, d); unsigned int new_cpu; - struct cpumask valid; unsigned long flags; bool enabled; =20 - if (!cpumask_and(&valid, &intc->cpumask, dest)) - return -EINVAL; - - new_cpu =3D cpumask_any_and(&valid, cpu_online_mask); + new_cpu =3D cpumask_first_and_and(&intc->cpumask, dest, + cpu_online_mask); if (new_cpu >=3D nr_cpu_ids) return -EINVAL; =20 --=20 2.27.0 From nobody Fri Feb 13 05:47:35 2026 Received: from smtpbgjp3.qq.com (smtpbgjp3.qq.com [54.92.39.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1C2F40C15 for ; Fri, 12 Apr 2024 10:59:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.92.39.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712919566; cv=none; b=NOF76q9ALABopXwxmnzzUfogu0uQLH7qg0zP7wJbEo7JeEnStDI93viwaIt9AHIEX4dJBaKeF/9wiyhKrwQwA6vkgA6TcauW3SyHnM65quaTnIBzSeWoH2Q5F0FyXyWfWqefpH7CmC7I7kHxxsbT+lxH2zxMZNlN8cnRic+8ThM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712919566; c=relaxed/simple; bh=Y2Fr2z85GiqrsspK1EWPARCrG8qEAgI0otN5jcdYGbA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pvZ0q5PDKE/SYXKWk+UM3XAtElrcbL/3ddn/jgZUMjBFbrdHI9pB0aGGbFoCwA7NVZkmyLTZMDvkguPg7tApfcxA8nzZcWYgi0gZjVkzT41UO6Y3gKLF6PR0RaQAPbn8wN6devTFSiTFpXty6MZKvpPmf/H7Folx4goI6rURgJs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn; spf=pass smtp.mailfrom=shingroup.cn; arc=none smtp.client-ip=54.92.39.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shingroup.cn X-QQ-mid: bizesmtpsz12t1712919554t1sc4f X-QQ-Originating-IP: XtOo9MhHpQmv59Q3FjqVGhMpUYTa/sen1b4+R/N3Lyg= Received: from localhost ( [112.0.147.129]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 12 Apr 2024 18:59:12 +0800 (CST) X-QQ-SSF: 01400000000000903000000A0000000 X-QQ-FEAT: vrqOr+ppv0swERXAarxGZQvyAMZZ/l6B37dFgG2uQThzhiA2EgalD6ig2x8OV NSQ75IlmVX14Xw2yeqH+ooyMOCVMRuqE6/VRs6tGFwE+f6A/aOB8LJl1+k1lZGTERf36BF4 9IU5PXB9teHLdp0oWbRPjFJFJEUp5Cqxjoj5MEInMdenxQdYYvO0qg1JJoc7ov9kXkWOITT z+sMmqpVKdwFA6E1iiUi3dTJjTlbYDhME+SwkD7oWhx2zob5q9iQZ0LlPpxsDZ0/ufsF++V 4LBjVzJhfblyUIslnzRaqm3Dkg/idVALMz306M7CEkk17p2bYeSJLUQWywONh73BCpI88pc /9u6T2QfAuX/ZvO00x42zBDIgY09+6A9cLXXM85TYmzcU6pVx9RuhFK9zOj6LCrCLl1HoDV 3UcfBM8Is3Flu7zkZtLRBA== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 10109608025486522936 From: Dawei Li To: tglx@linutronix.de, yury.norov@gmail.com Cc: akpm@linux-foundation.org, maz@kernel.org, florian.fainelli@broadcom.com, chenhuacai@kernel.org, jiaxun.yang@flygoat.com, anup@brainfault.org, palmer@dabbelt.com, samuel.holland@sifive.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, Dawei Li Subject: [PATCH 3/6] irqchip/gic-v3-its: Avoid explicit cpumask allocation on stack Date: Fri, 12 Apr 2024 18:58:36 +0800 Message-Id: <20240412105839.2896281-4-dawei.li@shingroup.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240412105839.2896281-1-dawei.li@shingroup.cn> References: <20240412105839.2896281-1-dawei.li@shingroup.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpsz:shingroup.cn:qybglogicsvrgz:qybglogicsvrgz5a-1 Content-Type: text/plain; charset="utf-8" In general it's preferable to avoid placing cpumasks on the stack, as for large values of NR_CPUS these can consume significant amounts of stack space and make stack overflows more likely. Remove cpumask var on stack and use proper cpumask API to address it. Signed-off-by: Dawei Li --- drivers/irqchip/irq-gic-v3-its.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-= its.c index fca888b36680..a821396c4261 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -3826,7 +3826,7 @@ static int its_vpe_set_affinity(struct irq_data *d, bool force) { struct its_vpe *vpe =3D irq_data_get_irq_chip_data(d); - struct cpumask common, *table_mask; + struct cpumask *table_mask; unsigned long flags; int from, cpu; =20 @@ -3850,8 +3850,11 @@ static int its_vpe_set_affinity(struct irq_data *d, * If we are offered another CPU in the same GICv4.1 ITS * affinity, pick this one. Otherwise, any CPU will do. */ - if (table_mask && cpumask_and(&common, mask_val, table_mask)) - cpu =3D cpumask_test_cpu(from, &common) ? from : cpumask_first(&common); + if (table_mask && cpumask_intersects(mask_val, table_mask)) { + cpu =3D cpumask_test_cpu(from, mask_val) && + cpumask_test_cpu(from, table_mask) ? + from : cpumask_first_and(mask_val, table_mask); + } else cpu =3D cpumask_first(mask_val); =20 --=20 2.27.0 From nobody Fri Feb 13 05:47:35 2026 Received: from smtpbgeu1.qq.com (smtpbgeu1.qq.com [52.59.177.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 846C754F83 for ; Fri, 12 Apr 2024 10:59:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.59.177.22 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712919575; cv=none; b=pqA44nC+ciXKjLjSMwSijcFgT2ZNqYadweN7PKRr0FpNSreLV43x1OdycoQvvdQW//Rka2r2ApQpogVQgkBq44kBIgpDaSdqY5+yaDDIULd7fuPFPPQz7znTwDI/mSeCNQVIBVIsuOZvdT4i8yysAw7y1sprMWMlJ9Apxzmv8nI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712919575; c=relaxed/simple; bh=YU9GY9kwwCwrYvzSsJ4J9pmYsZAzvBbQ+w74pN74GBI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mZ+HH0TvKXKyDaFpw9CddZTM+ktQlfMHdgEQPUxcq3Bc3LDoncC4QekRFzWov+2ucxPx3YASdUviOQ2qeasARQMF/oIKCd5lZkV65Qunp6xsaJy85HP3mz/+ZLYGlN8SOBCrPX/XjdHhqqs3a2tiaHGwJpTA0d1cIjagt1dE5QE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn; spf=pass smtp.mailfrom=shingroup.cn; arc=none smtp.client-ip=52.59.177.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shingroup.cn X-QQ-mid: bizesmtpsz8t1712919561ta68hir X-QQ-Originating-IP: ZWB/B4IyZ0qUnNOZL+Tpusla3oVf3Lb8ZOYZb7lrUJE= Received: from localhost ( [112.0.147.129]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 12 Apr 2024 18:59:19 +0800 (CST) X-QQ-SSF: 01400000000000903000000A0000000 X-QQ-FEAT: RrZlkntZBfm95kGRViz3aLor3/0FhwLyKZAXNIWQAgktxGh8r1b1zwap8vw9f Sm7//RYKxkWd50EwrJamIXK/afovqE2m1EnTP1keOpm2u6LKwYAlec6U8lCuxCFoNbEqLFK JMJYDu/+a/G8St6t/wgv1GGjPxkI12MNlRFKu/YLQxitghtm0MLzWi9QUUI/P1HxoCslPtG yiTwRDkVWzneMoNTAnx5Tfc18AlWPitA/HWMHCoYtigHAn4Cw6CV1ao9mECd3JmzvltHDTg 10w60sutnatI1p88Xyy6bihEWyLqaqDDw44AE0gCacHTJW0+vIS2anqKRyZN7JuzAqTQxIt fyMMzqxGr6r7A2hxvDU670s6a7nmYTc7a0XrqSgkqepMamFlhOk6zrP0lklCnYEHvuvdhFC ODD5wSMhesmr5DJ8GCH79rEIhfQoowb3 X-QQ-GoodBg: 2 X-BIZMAIL-ID: 845724314838511748 From: Dawei Li To: tglx@linutronix.de, yury.norov@gmail.com Cc: akpm@linux-foundation.org, maz@kernel.org, florian.fainelli@broadcom.com, chenhuacai@kernel.org, jiaxun.yang@flygoat.com, anup@brainfault.org, palmer@dabbelt.com, samuel.holland@sifive.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, Dawei Li Subject: [PATCH 4/6] irqchip/loongson-eiointc: Avoid explicit cpumask allocation on stack Date: Fri, 12 Apr 2024 18:58:37 +0800 Message-Id: <20240412105839.2896281-5-dawei.li@shingroup.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240412105839.2896281-1-dawei.li@shingroup.cn> References: <20240412105839.2896281-1-dawei.li@shingroup.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpsz:shingroup.cn:qybglogicsvrgz:qybglogicsvrgz5a-1 Content-Type: text/plain; charset="utf-8" In general it's preferable to avoid placing cpumasks on the stack, as for large values of NR_CPUS these can consume significant amounts of stack space and make stack overflows more likely. Use cpumask_first_and_and() to avoid the need for a temporary cpumask on the stack. Signed-off-by: Dawei Li --- drivers/irqchip/irq-loongson-eiointc.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/irqchip/irq-loongson-eiointc.c b/drivers/irqchip/irq-l= oongson-eiointc.c index b64cbe3052e8..c9f30e96b5b5 100644 --- a/drivers/irqchip/irq-loongson-eiointc.c +++ b/drivers/irqchip/irq-loongson-eiointc.c @@ -92,19 +92,16 @@ static int eiointc_set_irq_affinity(struct irq_data *d,= const struct cpumask *af unsigned int cpu; unsigned long flags; uint32_t vector, regaddr; - struct cpumask intersect_affinity; struct eiointc_priv *priv =3D d->domain->host_data; =20 raw_spin_lock_irqsave(&affinity_lock, flags); =20 - cpumask_and(&intersect_affinity, affinity, cpu_online_mask); - cpumask_and(&intersect_affinity, &intersect_affinity, &priv->cpuspan_map); - - if (cpumask_empty(&intersect_affinity)) { + cpu =3D cpumask_first_and_and(&priv->cpuspan_map, affinity, + cpu_online_mask); + if (cpu >=3D nr_cpu_ids) { raw_spin_unlock_irqrestore(&affinity_lock, flags); return -EINVAL; } - cpu =3D cpumask_first(&intersect_affinity); =20 vector =3D d->hwirq; regaddr =3D EIOINTC_REG_ENABLE + ((vector >> 5) << 2); --=20 2.27.0 From nobody Fri Feb 13 05:47:35 2026 Received: from smtpbgbr1.qq.com (smtpbgbr1.qq.com [54.207.19.206]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D257BDDC5 for ; Fri, 12 Apr 2024 10:59:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.207.19.206 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712919590; cv=none; b=RxLwPfUmSDDgX1+c1k4Qd8s61rbWnoLHh9EpH+4BQTMPd4L6W3Y0D1WDQvbJnJHvovg/AsjhZhYvIqHEsOm6cRBBSqnkm/uLyRMxqK4kAlD3G8mrsGN7HP4hnUzPe0Kb7W0ZlY3r0XVYMuqJSgK+RZVchgfPc7NpMqo3f2cMZ6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712919590; c=relaxed/simple; bh=ggMgO+rPt995T4KEcdHnayNEfdGMBP7YG5dHKBPxkoE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gEEBuuj54AyNsrCfBHAGR2z52GwxiRQms23o8XPRMK74NQrBZpcrNbBvel/982ncgBHwK1iiPh6wjr/Utxch6VjoY/JPhrK2tyfDrKYP5QCx/WR+h+L7dS3BPyPacm98DSbdOwjNVWW0G3ucF6HvXDexK5/35PSQ8i2qG5Ivsfg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn; spf=pass smtp.mailfrom=shingroup.cn; arc=none smtp.client-ip=54.207.19.206 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shingroup.cn X-QQ-mid: bizesmtpsz3t1712919567tlajsji X-QQ-Originating-IP: psS1oMW7E8PBAWnFJBeHeyKOLljD1luV7VQtmuiQGkw= Received: from localhost ( [112.0.147.129]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 12 Apr 2024 18:59:25 +0800 (CST) X-QQ-SSF: 01400000000000903000000B0000000 X-QQ-FEAT: W+onFc5Tw4PeenFYVlUR8av8LbV2OBRzlmy0ixoe643FNskMz0uQ9ivffAsVd 4mWzHF/s0tdV7VhrpWwjIZ2rgSxhGPk6Y7ERINCjxfgv9sgxAGIk+1nROFRtw+C14wvKukN 1mz2maxW9/6Hf46dMfisbAbwJZ0xeXUoHeb5FYGhyrQPp4LysbBwZdrHUWixnkzWAOgbeLH 5hXnxXCdACikme/nqhEuURbEm9aY2mgQEN1ADiNdfLURJo3YrcxqDuVTIRv9sJgtIrjtzSi T7RK/RF/cfuoDH6jsRF/2q+ZS14wR7iyY43I6HzEq3YEMWfEQw1R5VBqmmQrh6A+EknE9DW HT26qX+cAqhx7MpDONdtxxzMMmJ3MUnl7b3F4pdQHujq7PLgSDs+TgdHytqEaCpFHnaQUcc zzaZR0LW+egQrjQcgZyj4h9xcYqfLOM/ X-QQ-GoodBg: 2 X-BIZMAIL-ID: 10082534612301943581 From: Dawei Li To: tglx@linutronix.de, yury.norov@gmail.com Cc: akpm@linux-foundation.org, maz@kernel.org, florian.fainelli@broadcom.com, chenhuacai@kernel.org, jiaxun.yang@flygoat.com, anup@brainfault.org, palmer@dabbelt.com, samuel.holland@sifive.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, Dawei Li Subject: [PATCH 5/6] irqchip/riscv-aplic-direct: Avoid explicit cpumask allocation on stack Date: Fri, 12 Apr 2024 18:58:38 +0800 Message-Id: <20240412105839.2896281-6-dawei.li@shingroup.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240412105839.2896281-1-dawei.li@shingroup.cn> References: <20240412105839.2896281-1-dawei.li@shingroup.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpsz:shingroup.cn:qybglogicsvrgz:qybglogicsvrgz5a-1 Content-Type: text/plain; charset="utf-8" In general it's preferable to avoid placing cpumasks on the stack, as for large values of NR_CPUS these can consume significant amounts of stack space and make stack overflows more likely. Use cpumask_first_and_and() to avoid the need for a temporary cpumask on the stack. Signed-off-by: Dawei Li --- drivers/irqchip/irq-riscv-aplic-direct.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/irqchip/irq-riscv-aplic-direct.c b/drivers/irqchip/irq= -riscv-aplic-direct.c index 06bace9b7497..5cb7d74d0927 100644 --- a/drivers/irqchip/irq-riscv-aplic-direct.c +++ b/drivers/irqchip/irq-riscv-aplic-direct.c @@ -54,15 +54,13 @@ static int aplic_direct_set_affinity(struct irq_data *d= , const struct cpumask *m struct aplic_direct *direct =3D container_of(priv, struct aplic_direct, p= riv); struct aplic_idc *idc; unsigned int cpu, val; - struct cpumask amask; void __iomem *target; =20 - cpumask_and(&amask, &direct->lmask, mask_val); - if (force) - cpu =3D cpumask_first(&amask); + cpu =3D cpumask_first_and(&direct->lmask, mask_val); else - cpu =3D cpumask_any_and(&amask, cpu_online_mask); + cpu =3D cpumask_first_and_and(&direct->lmask, mask_val, + cpu_online_mask); =20 if (cpu >=3D nr_cpu_ids) return -EINVAL; --=20 2.27.0 From nobody Fri Feb 13 05:47:35 2026 Received: from smtpbgbr2.qq.com (smtpbgbr2.qq.com [54.207.22.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 34DD5548E3 for ; Fri, 12 Apr 2024 10:59:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.207.22.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712919600; cv=none; b=WPES0sUxHLH+2e42eti1g+uUFSvfW6sUQSOIiuALKBSOWxxyYM169UZVqp+YMxLeFauGrFFSICtth8JczjHOvcgsT+MLOK35LHSfluXXmdut7BWBTXHF1F1tk9FXlLOPBZI5k15KWnEwgh2Qf+efDC+dQbUV7aRwKdNA0vPbFgY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712919600; c=relaxed/simple; bh=07NTM88QwRzoo390ZLemINoqh6/jCN/PfEP7yU0wEwI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PtaSO6fF5bIN/MYCa2SB4S4zu5n5HAAIt1j4AVFHPnkGEqTszQTPdzJvqcVH+BMqRkTCVx5ZASOwvH0NH950Pa4BrBDIJcxTDt5HmuKrxnWfEYNnk4L9Kt6Qn5/jsCMSEg7C/cDvcZ7DgdqzdWFi3Vk1z8PmnGWbu17PvULgIms= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn; spf=pass smtp.mailfrom=shingroup.cn; arc=none smtp.client-ip=54.207.22.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shingroup.cn X-QQ-mid: bizesmtpsz2t1712919573t6idgx7 X-QQ-Originating-IP: epgQDvPTX2f4nlnGaXUhvRLzY2bOY8814GkkAA2Z0gE= Received: from localhost ( [112.0.147.129]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 12 Apr 2024 18:59:31 +0800 (CST) X-QQ-SSF: 01400000000000903000000A0000000 X-QQ-FEAT: aEYUFldOyMp/nydjx6hhyShFrAjETMenuO2m1lkToK8BDMN65Wz87U1LGva1P SJTxf4Tys6KTeVMEnKTjN+lnkdO9yEuULZWIp0ivGAYN0ye4g/JW/eCpgKAXXc7gs8f2u2/ oOhl3Iv5F1Mmvel5E/u2SV1DrvTAUOBQNDcwE+APnG+EU5+LeJAladVFSygvYvQmI58v6Fa /7LBGexoai35+1NGyhmsFqVaUVm63IsCoLqM9CxbmzTy2KHPY3iJIULqdWKzqEdlVDYGrEs gRvLgWIVMfR780jHJA1ADL2afvR42kvanTByg7gVYVEgovPui4/LRgyCRwHzmhEDUKj02OU UatbOK/N6Jh94CbV338lW1zS5t/yNKVW2FyHbQ4pJQVfuN6etlydIUV2q+hhYlrJHl01Kt9 6B9N1DNgnTVU78jfyC8DdaHHfZ97Y5g5 X-QQ-GoodBg: 2 X-BIZMAIL-ID: 11278858222069621144 From: Dawei Li To: tglx@linutronix.de, yury.norov@gmail.com Cc: akpm@linux-foundation.org, maz@kernel.org, florian.fainelli@broadcom.com, chenhuacai@kernel.org, jiaxun.yang@flygoat.com, anup@brainfault.org, palmer@dabbelt.com, samuel.holland@sifive.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, Dawei Li Subject: [PATCH 6/6] irqchip/sifive-plic: Avoid explicit cpumask allocation on stack Date: Fri, 12 Apr 2024 18:58:39 +0800 Message-Id: <20240412105839.2896281-7-dawei.li@shingroup.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240412105839.2896281-1-dawei.li@shingroup.cn> References: <20240412105839.2896281-1-dawei.li@shingroup.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpsz:shingroup.cn:qybglogicsvrgz:qybglogicsvrgz5a-1 Content-Type: text/plain; charset="utf-8" In general it's preferable to avoid placing cpumasks on the stack, as for large values of NR_CPUS these can consume significant amounts of stack space and make stack overflows more likely. Use cpumask_first_and_and() to avoid the need for a temporary cpumask on the stack. Signed-off-by: Dawei Li --- drivers/irqchip/irq-sifive-plic.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive= -plic.c index f3d4cb9e34f7..bf5d2fc6396e 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -164,15 +164,13 @@ static int plic_set_affinity(struct irq_data *d, const struct cpumask *mask_val, bool force) { unsigned int cpu; - struct cpumask amask; struct plic_priv *priv =3D irq_data_get_irq_chip_data(d); =20 - cpumask_and(&amask, &priv->lmask, mask_val); - if (force) - cpu =3D cpumask_first(&amask); + cpu =3D cpumask_first_and(&priv->lmask, mask_val); else - cpu =3D cpumask_any_and(&amask, cpu_online_mask); + cpu =3D cpumask_first_and_and(&priv->lmask, mask_val, + cpu_online_mask); =20 if (cpu >=3D nr_cpu_ids) return -EINVAL; --=20 2.27.0