From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Wen Jiang <jiangwenxiaomi@gmail.com>,
akpm@linux-foundation.org, catalin.marinas@arm.com,
will@kernel.org, urezki@gmail.com, linux-mm@kvack.org
Cc: baohua@kernel.org, dev.jain@arm.com, ryan.roberts@arm.com,
anshuman.khandual@arm.com, rppt@kernel.org, leo.yan@arm.com,
xueyuan.chen21@gmail.com, chleroy@kernel.org,
maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com,
ajd@linux.ibm.com, jiangwen6@xiaomi.com,
linux-arm-kernel@lists.infradead.org,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v12 09/10] mm/vmalloc: map contiguous pages in batches for vmap() if possible
Date: Wed, 2 Dec 2026 10:13:34 +0100 [thread overview]
Message-ID: <949c3260-6740-4dfd-9ab7-b50c3f471497@kernel.org> (raw)
In-Reply-To: <20261107134953.748622-10-jiangwenxiaomi@gmail.com>
On 11/7/26 14:49, Wen Jiang wrote:
> From: "Barry Song (Xiaomi)" <baohua@kernel.org>
>
> In many cases, the pages passed to vmap() may include high-order
> pages. For example, the systemheap often allocates pages in descending
> order: order 8, then 4, then 0. Currently, vmap() iterates over every
> page individually—even pages inside a high-order block are handled
> one by one.
>
> This patch detects physically contiguous pages (regardless of whether
> they are compound or non-compound) by scanning with
> num_pages_contiguous(), and maps them as a single contiguous block
> whenever possible. The mapping order is determined by taking the
> minimum of the contiguous page count and the pfn alignment, allowing
> graceful degradation when pfn alignment is less than the contiguous
> range.
>
> Pages with the same page_shift are coalesced and mapped via
> vmap_pages_range_noflush_walk() to avoid page table rewalk.
>
> As users typically allocate memory in descending orders (e.g.
> 8 → 4 → 0), once an order-0 page is encountered, we stop scanning
> for contiguous pages since subsequent pages are likely order-0 as well.
>
> With large mappings, vmap_try_huge_pmd() may free an empty PTE table
> left behind by an earlier vunmap() and install a PMD while vread_iter()
> walks the same range without the mmap lock. Set VM_UNINITIALIZED on the
> area until the mapping is complete, as __vmalloc_node_range_noprof()
> already does, so that vread_iter() skips it.
>
> Signed-off-by: Barry Song (Xiaomi) <baohua@kernel.org>
> Co-developed-by: Dev Jain <dev.jain@arm.com>
> Signed-off-by: Dev Jain <dev.jain@arm.com>
> Signed-off-by: Wen Jiang <jiangwen6@xiaomi.com>
> Tested-by: Xueyuan Chen <xueyuan.chen21@gmail.com>
> Tested-by: Leo Yan <leo.yan@arm.com>
> Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
> ---
Apparently this thing here fixes an issue:
When CONFIG_PROC_FS and CONFIG_NUMA are enabled, a race between vmap()
called with VM_MAP_PUT_PAGES and a concurrent /proc/vmallocinfo read can
cause a NULL pointer dereference in show_numa_info():
CPU 0 CPU 1 (/proc/vmallocinfo)
----- -------------------------
vmap(..., VM_MAP_PUT_PAGES, ...)
area = get_vm_area_caller(...)
alloc_vmap_area()
// publishes va->vm into
// vn->busy.head without
// VM_UNINITIALIZED
vmap_pages_range_batched(...)
area->pages = pages;
area->nr_pages = count;
show_busy_info()
spin_lock(&vn->busy.lock);
// v->flags lacks VM_UNINITIALIZED
smp_rmb();
show_numa_info(m, v, counters)
for (i = 0; i < v->nr_pages; ...)
v->pages[i] // NULL dereference
In vmap(), get_vm_area_caller() allocates a zero-initialized vm_struct
without setting VM_UNINITIALIZED in area->flags and links it into
vn->busy.head via alloc_vmap_area(). When VM_MAP_PUT_PAGES is set, vmap()
subsequently assigns area->pages and area->nr_pages without holding
vn->busy.lock, without using VM_UNINITIALIZED and
clear_vm_uninitialized_flag(), and without a write memory barrier ordering
the two stores. When show_busy_info() concurrently traverses vn->busy.head
under vn->busy.lock, it sees VM_UNINITIALIZED clear on v->flags and invokes
show_numa_info(). Because the stores to area->pages and area->nr_pages are
unserialized and unordered, compiler or CPU reordering allows
show_numa_info() to observe a non-zero v->nr_pages while v->pages is still
NULL, crashing the kernel when dereferencing v->pages[i].
--
Cheers,
David
next prev parent reply other threads:[~2026-12-02 9:13 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 13:49 [PATCH v12 00/10] mm/vmalloc: Speed up ioremap, vmalloc and vmap with contiguous memory Wen Jiang
2026-11-07 13:49 ` [PATCH v12 01/10] arm64/mm: add vmap_pte_set_huge() and vmap_pte_clear_huge() Wen Jiang
2026-11-07 13:49 ` [PATCH v12 02/10] powerpc/8xx: add vmap_pte_set_huge() Wen Jiang
2026-11-07 13:49 ` [PATCH v12 03/10] mm/vmalloc: use vmap_pte_set_huge()/vmap_pte_clear_huge() for PTE-level block mappings Wen Jiang
2026-11-07 13:49 ` [PATCH v12 04/10] arm64/hugetlb: drop the init_mm special case in clear_flush() Wen Jiang
2026-11-07 13:49 ` [PATCH v12 05/10] arm64/vmalloc: allow arch_vmap_pte_range_map_size() to batch multiple CONT_PTE Wen Jiang
2026-11-07 13:49 ` [PATCH v12 06/10] mm/vmalloc: extract vmap_set_ptes() to consolidate PTE mapping logic Wen Jiang
2026-11-07 13:49 ` [PATCH v12 07/10] mm/vmalloc: extend page table walk to support larger page_shift sizes and eliminate page table rewalk Wen Jiang
2026-11-11 3:09 ` Wen Jiang
2026-11-07 13:49 ` [PATCH v12 08/10] mm/vmalloc: extract vm_shift() to consolidate mapping shift selection Wen Jiang
2026-11-07 13:49 ` [PATCH v12 09/10] mm/vmalloc: map contiguous pages in batches for vmap() if possible Wen Jiang
2026-12-02 9:13 ` David Hildenbrand (Arm) [this message]
2026-11-07 13:49 ` [PATCH v12 10/10] mm/vmalloc: align vm_area so vmap() can batch mappings Wen Jiang
2026-11-09 7:08 ` [PATCH v12 00/10] mm/vmalloc: Speed up ioremap, vmalloc and vmap with contiguous memory Andrew Morton
2026-11-09 11:07 ` Wen Jiang
2026-11-09 11:38 ` Uladzislau Rezki
2026-11-09 14:02 ` Leo Yan
2026-11-09 17:24 ` Andrew Morton
2026-11-11 3:08 ` Wen Jiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=949c3260-6740-4dfd-9ab7-b50c3f471497@kernel.org \
--to=david@kernel.org \
--cc=ajd@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=anshuman.khandual@arm.com \
--cc=baohua@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=chleroy@kernel.org \
--cc=dev.jain@arm.com \
--cc=jiangwen6@xiaomi.com \
--cc=jiangwenxiaomi@gmail.com \
--cc=leo.yan@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=urezki@gmail.com \
--cc=will@kernel.org \
--cc=xueyuan.chen21@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox