Skip to content

Commit af324e7

Browse files
urezkismb49
authored andcommitted
mm: vmalloc: check if a hash-index is in cpu_possible_mask
BugLink: https://bugs.launchpad.net/bugs/2078289 commit a34acf30b19bc4ee3ba2f1082756ea2604c19138 upstream. The problem is that there are systems where cpu_possible_mask has gaps between set CPUs, for example SPARC. In this scenario addr_to_vb_xa() hash function can return an index which accesses to not-possible and not setup CPU area using per_cpu() macro. This results in an oops on SPARC. A per-cpu vmap_block_queue is also used as hash table, incorrectly assuming the cpu_possible_mask has no gaps. Fix it by adjusting an index to a next possible CPU. Link: https://lkml.kernel.org/r/[email protected] Fixes: 062eacf ("mm: vmalloc: remove a global vmap_blocks xarray") Reported-by: Nick Bowler <[email protected]> Closes: https://lore.kernel.org/linux-kernel/ZntjIE6msJbF8zTa@MiWiFi-R3L-srv/T/ Signed-off-by: Uladzislau Rezki (Sony) <[email protected]> Reviewed-by: Baoquan He <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Hailong.Liu <[email protected]> Cc: Oleksiy Avramchenko <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Portia Stephens <[email protected]> Signed-off-by: Stefan Bader <[email protected]>
1 parent d386c4e commit af324e7

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

mm/vmalloc.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1984,7 +1984,15 @@ static DEFINE_PER_CPU(struct vmap_block_queue, vmap_block_queue);
19841984
static struct xarray *
19851985
addr_to_vb_xa(unsigned long addr)
19861986
{
1987-
int index = (addr / VMAP_BLOCK_SIZE) % num_possible_cpus();
1987+
int index = (addr / VMAP_BLOCK_SIZE) % nr_cpu_ids;
1988+
1989+
/*
1990+
* Please note, nr_cpu_ids points on a highest set
1991+
* possible bit, i.e. we never invoke cpumask_next()
1992+
* if an index points on it which is nr_cpu_ids - 1.
1993+
*/
1994+
if (!cpu_possible(index))
1995+
index = cpumask_next(index, cpu_possible_mask);
19881996

19891997
return &per_cpu(vmap_block_queue, index).vmap_blocks;
19901998
}

0 commit comments

Comments
 (0)