From: Marc Zyngier <maz@kernel.org>
To: Dawei Li <dawei.li@shingroup.cn>
Cc: tglx@linutronix.de, yury.norov@gmail.com,
akpm@linux-foundation.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
Subject: Re: [PATCH 3/6] irqchip/gic-v3-its: Avoid explicit cpumask allocation on stack
Date: Fri, 12 Apr 2024 14:53:32 +0100 [thread overview]
Message-ID: <86il0msn4z.wl-maz@kernel.org> (raw)
In-Reply-To: <20240412105839.2896281-4-dawei.li@shingroup.cn>
On Fri, 12 Apr 2024 11:58:36 +0100,
Dawei Li <dawei.li@shingroup.cn> wrote:
>
> 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.
Define proper. Or better, define what is "improper" about the current
usage.
>
> Signed-off-by: Dawei Li <dawei.li@shingroup.cn>
> ---
> 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 = irq_data_get_irq_chip_data(d);
> - struct cpumask common, *table_mask;
> + struct cpumask *table_mask;
> unsigned long flags;
> int from, cpu;
>
> @@ -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 = cpumask_test_cpu(from, &common) ? from : cpumask_first(&common);
> + if (table_mask && cpumask_intersects(mask_val, table_mask)) {
> + cpu = cpumask_test_cpu(from, mask_val) &&
> + cpumask_test_cpu(from, table_mask) ?
> + from : cpumask_first_and(mask_val, table_mask);
So we may end-up computing the AND of the two bitmaps twice (once for
cpumask_intersects(), once for cpumask_first_and()), instead of only
doing it once.
I don't expect that to be horrible, but I also note that you don't
even talk about the trade-offs you are choosing to make.
> + }
> else
> cpu = cpumask_first(mask_val);
Please fix the coding style (if () { ... } else { ... }).
M.
--
Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2024-04-12 13:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-12 10:58 [PATCH 0/6] Remove on-stack cpumask var for irq subsystem Dawei Li
2024-04-12 10:58 ` [PATCH 1/6] cpumask: introduce cpumask_first_and_and() Dawei Li
2024-04-12 14:40 ` Yury Norov
2024-04-13 10:37 ` Dawei Li
2024-04-12 10:58 ` [PATCH 2/6] irqchip/irq-bcm6345-l1: Avoid explicit cpumask allocation on stack Dawei Li
2024-04-12 10:58 ` [PATCH 3/6] irqchip/gic-v3-its: " Dawei Li
2024-04-12 13:53 ` Marc Zyngier [this message]
2024-04-13 10:29 ` Dawei Li
2024-04-13 11:11 ` Marc Zyngier
2024-04-12 10:58 ` [PATCH 4/6] irqchip/loongson-eiointc: " Dawei Li
2024-04-12 10:58 ` [PATCH 5/6] irqchip/riscv-aplic-direct: " Dawei Li
2024-04-12 10:58 ` [PATCH 6/6] irqchip/sifive-plic: " Dawei Li
2024-04-13 17:54 ` Yury Norov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86il0msn4z.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=anup@brainfault.org \
--cc=chenhuacai@kernel.org \
--cc=dawei.li@shingroup.cn \
--cc=florian.fainelli@broadcom.com \
--cc=jiaxun.yang@flygoat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=palmer@dabbelt.com \
--cc=samuel.holland@sifive.com \
--cc=tglx@linutronix.de \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox