Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

percpu: clean up all mappings when pcpu_map_pages() fails

In pcpu_map_pages(), if __pcpu_map_pages() fails on a CPU, we call
__pcpu_unmap_pages() to clean up mappings on all CPUs where mappings were
created, but not on the CPU where __pcpu_map_pages() fails.

__pcpu_map_pages() and __pcpu_unmap_pages() are wrappers around
vmap_pages_range_noflush() and vunmap_range_noflush(). All other callers
of vmap_pages_range_noflush() call vunmap_range_noflush() when mapping
fails, except pcpu_map_pages(). The reason could be that partial mappings
may be left behind from a failed mapping attempt.

Call __pcpu_unmap_pages() for the failed CPU as well in pcpu_map_pages().

This was found by code inspection, no failures or bugs were observed.

Link: https://lkml.kernel.org/r/20240311194346.2291333-1-yosryahmed@google.com
Signed-off-by: Yosry Ahmed <yosryahmed@google.com>
Acked-by: Dennis Zhou <dennis@kernel.org>
Cc: Christoph Lameter (Ampere) <cl@linux.com>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Yosry Ahmed and committed by
Andrew Morton
2ccd48ce 133d04b1

+2 -2
+2 -2
mm/percpu-vm.c
··· 231 231 return 0; 232 232 err: 233 233 for_each_possible_cpu(tcpu) { 234 - if (tcpu == cpu) 235 - break; 236 234 __pcpu_unmap_pages(pcpu_chunk_addr(chunk, tcpu, page_start), 237 235 page_end - page_start); 236 + if (tcpu == cpu) 237 + break; 238 238 } 239 239 pcpu_post_unmap_tlb_flush(chunk, page_start, page_end); 240 240 return err;