* [PATCH] mm: vmalloc: Check if a hash-index is in cpu_possible_mask
@ 2024-06-26 11:43 Uladzislau Rezki (Sony)
2024-06-26 14:27 ` Baoquan He
0 siblings, 1 reply; 2+ messages in thread
From: Uladzislau Rezki (Sony) @ 2024-06-26 11:43 UTC (permalink / raw)
To: linux-mm, Andrew Morton
Cc: LKML, Baoquan He, Hailong Liu, Christoph Hellwig, Nick Bowler,
Uladzislau Rezki, Oleksiy Avramchenko
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.
A per-cpu vmap_block_queue is also used as hash table assuming
that incorrectly assumes the cpu_possible_mask has not gaps.
Fix it by adjusting an index to a next possible CPU.
Fixes: 062eacf57ad9 ("mm: vmalloc: remove a global vmap_blocks xarray")
Reported-by: Nick Bowler <nbowler@draconx.ca>
Closes: https://lore.kernel.org/linux-kernel/ZntjIE6msJbF8zTa@MiWiFi-R3L-srv/T/
Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
---
mm/vmalloc.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index b4c42da9f3901..6b783baf12a14 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2544,7 +2544,15 @@ static DEFINE_PER_CPU(struct vmap_block_queue, vmap_block_queue);
static struct xarray *
addr_to_vb_xa(unsigned long addr)
{
- int index = (addr / VMAP_BLOCK_SIZE) % num_possible_cpus();
+ int index = (addr / VMAP_BLOCK_SIZE) % nr_cpu_ids;
+
+ /*
+ * Please note, nr_cpu_ids points on a highest set
+ * possible bit, i.e. we never invoke cpumask_next()
+ * if an index points on it which is nr_cpu_ids - 1.
+ */
+ if (!cpu_possible(index))
+ index = cpumask_next(index, cpu_possible_mask);
return &per_cpu(vmap_block_queue, index).vmap_blocks;
}
--
2.39.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] mm: vmalloc: Check if a hash-index is in cpu_possible_mask
2024-06-26 11:43 [PATCH] mm: vmalloc: Check if a hash-index is in cpu_possible_mask Uladzislau Rezki (Sony)
@ 2024-06-26 14:27 ` Baoquan He
0 siblings, 0 replies; 2+ messages in thread
From: Baoquan He @ 2024-06-26 14:27 UTC (permalink / raw)
To: Uladzislau Rezki (Sony)
Cc: linux-mm, Andrew Morton, LKML, Hailong Liu, Christoph Hellwig,
Nick Bowler, Oleksiy Avramchenko
On 06/26/24 at 01:43pm, Uladzislau Rezki (Sony) wrote:
> 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.
>
> A per-cpu vmap_block_queue is also used as hash table assuming
~~~~~
> that incorrectly assumes the cpu_possible_mask has not gaps.
~~~~~~
Typo of duplicated word?
Other than above nit, this looks good to me. Thanks.
Reviewed-by: Baoquan He <bhe@redhat.com>
>
> Fix it by adjusting an index to a next possible CPU.
>
> Fixes: 062eacf57ad9 ("mm: vmalloc: remove a global vmap_blocks xarray")
> Reported-by: Nick Bowler <nbowler@draconx.ca>
> Closes: https://lore.kernel.org/linux-kernel/ZntjIE6msJbF8zTa@MiWiFi-R3L-srv/T/
> Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
> ---
> mm/vmalloc.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index b4c42da9f3901..6b783baf12a14 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -2544,7 +2544,15 @@ static DEFINE_PER_CPU(struct vmap_block_queue, vmap_block_queue);
> static struct xarray *
> addr_to_vb_xa(unsigned long addr)
> {
> - int index = (addr / VMAP_BLOCK_SIZE) % num_possible_cpus();
> + int index = (addr / VMAP_BLOCK_SIZE) % nr_cpu_ids;
> +
> + /*
> + * Please note, nr_cpu_ids points on a highest set
> + * possible bit, i.e. we never invoke cpumask_next()
> + * if an index points on it which is nr_cpu_ids - 1.
> + */
> + if (!cpu_possible(index))
> + index = cpumask_next(index, cpu_possible_mask);
>
> return &per_cpu(vmap_block_queue, index).vmap_blocks;
> }
> --
> 2.39.2
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-06-26 14:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-26 11:43 [PATCH] mm: vmalloc: Check if a hash-index is in cpu_possible_mask Uladzislau Rezki (Sony)
2024-06-26 14:27 ` Baoquan He
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox