Skip to content

Commit fcb8af4

Browse files
Dawei LiKAGA-KOKO
authored andcommitted
irqchip/gic-v3-its: Avoid explicit cpumask allocation on stack
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 cpumask_any_and() to address it. Signed-off-by: Dawei Li <dawei.li@shingroup.cn> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20240416085454.3547175-4-dawei.li@shingroup.cn
1 parent 6a9a52f commit fcb8af4

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

drivers/irqchip/irq-gic-v3-its.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3826,9 +3826,9 @@ static int its_vpe_set_affinity(struct irq_data *d,
38263826
bool force)
38273827
{
38283828
struct its_vpe *vpe = irq_data_get_irq_chip_data(d);
3829-
struct cpumask common, *table_mask;
3829+
unsigned int from, cpu = nr_cpu_ids;
3830+
struct cpumask *table_mask;
38303831
unsigned long flags;
3831-
int from, cpu;
38323832

38333833
/*
38343834
* Changing affinity is mega expensive, so let's be as lazy as
@@ -3850,10 +3850,15 @@ static int its_vpe_set_affinity(struct irq_data *d,
38503850
* If we are offered another CPU in the same GICv4.1 ITS
38513851
* affinity, pick this one. Otherwise, any CPU will do.
38523852
*/
3853-
if (table_mask && cpumask_and(&common, mask_val, table_mask))
3854-
cpu = cpumask_test_cpu(from, &common) ? from : cpumask_first(&common);
3855-
else
3853+
if (table_mask)
3854+
cpu = cpumask_any_and(mask_val, table_mask);
3855+
if (cpu < nr_cpu_ids) {
3856+
if (cpumask_test_cpu(from, mask_val) &&
3857+
cpumask_test_cpu(from, table_mask))
3858+
cpu = from;
3859+
} else {
38563860
cpu = cpumask_first(mask_val);
3861+
}
38573862

38583863
if (from == cpu)
38593864
goto out;

0 commit comments

Comments
 (0)