mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
lib/group_cpus: Let group_cpu_evenly() return the number of initialized masks
group_cpu_evenly() might have allocated less groups then requested:
group_cpu_evenly()
__group_cpus_evenly()
alloc_nodes_groups()
# allocated total groups may be less than numgrps when
# active total CPU number is less then numgrps
In this case, the caller will do an out of bound access because the
caller assumes the masks returned has numgrps.
Return the number of groups created so the caller can limit the access
range accordingly.
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Daniel Wagner <wagi@kernel.org>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20250617-isolcpus-queue-counters-v1-1-13923686b54b@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
committed by
Jens Axboe
parent
857f431824
commit
b6139a6abf
@@ -332,9 +332,11 @@ static int __group_cpus_evenly(unsigned int startgrp, unsigned int numgrps,
|
||||
/**
|
||||
* group_cpus_evenly - Group all CPUs evenly per NUMA/CPU locality
|
||||
* @numgrps: number of groups
|
||||
* @nummasks: number of initialized cpumasks
|
||||
*
|
||||
* Return: cpumask array if successful, NULL otherwise. And each element
|
||||
* includes CPUs assigned to this group
|
||||
* includes CPUs assigned to this group. nummasks contains the number
|
||||
* of initialized masks which can be less than numgrps.
|
||||
*
|
||||
* Try to put close CPUs from viewpoint of CPU and NUMA locality into
|
||||
* same group, and run two-stage grouping:
|
||||
@@ -344,7 +346,7 @@ static int __group_cpus_evenly(unsigned int startgrp, unsigned int numgrps,
|
||||
* We guarantee in the resulted grouping that all CPUs are covered, and
|
||||
* no same CPU is assigned to multiple groups
|
||||
*/
|
||||
struct cpumask *group_cpus_evenly(unsigned int numgrps)
|
||||
struct cpumask *group_cpus_evenly(unsigned int numgrps, unsigned int *nummasks)
|
||||
{
|
||||
unsigned int curgrp = 0, nr_present = 0, nr_others = 0;
|
||||
cpumask_var_t *node_to_cpumask;
|
||||
@@ -389,7 +391,7 @@ struct cpumask *group_cpus_evenly(unsigned int numgrps)
|
||||
ret = __group_cpus_evenly(curgrp, numgrps, node_to_cpumask,
|
||||
npresmsk, nmsk, masks);
|
||||
if (ret < 0)
|
||||
goto fail_build_affinity;
|
||||
goto fail_node_to_cpumask;
|
||||
nr_present = ret;
|
||||
|
||||
/*
|
||||
@@ -408,10 +410,6 @@ struct cpumask *group_cpus_evenly(unsigned int numgrps)
|
||||
if (ret >= 0)
|
||||
nr_others = ret;
|
||||
|
||||
fail_build_affinity:
|
||||
if (ret >= 0)
|
||||
WARN_ON(nr_present + nr_others < numgrps);
|
||||
|
||||
fail_node_to_cpumask:
|
||||
free_node_to_cpumask(node_to_cpumask);
|
||||
|
||||
@@ -424,10 +422,11 @@ struct cpumask *group_cpus_evenly(unsigned int numgrps)
|
||||
kfree(masks);
|
||||
return NULL;
|
||||
}
|
||||
*nummasks = min(nr_present + nr_others, numgrps);
|
||||
return masks;
|
||||
}
|
||||
#else /* CONFIG_SMP */
|
||||
struct cpumask *group_cpus_evenly(unsigned int numgrps)
|
||||
struct cpumask *group_cpus_evenly(unsigned int numgrps, unsigned int *nummasks)
|
||||
{
|
||||
struct cpumask *masks;
|
||||
|
||||
@@ -440,6 +439,7 @@ struct cpumask *group_cpus_evenly(unsigned int numgrps)
|
||||
|
||||
/* assign all CPUs(cpu 0) to the 1st group only */
|
||||
cpumask_copy(&masks[0], cpu_possible_mask);
|
||||
*nummasks = 1;
|
||||
return masks;
|
||||
}
|
||||
#endif /* CONFIG_SMP */
|
||||
|
||||
Reference in New Issue
Block a user