From: sashiko-bot@kernel.org
To: "Baoquan He" <baoquan.he@linux.dev>, linux-mm@kvack.org
Cc: akpm@linux-foundation.org, david@kernel.org, corbet@lwn.net,
chrisl@kernel.org, kasong@tencent.com, urezki@gmail.com,
hannes@cmpxchg.org, yosry@kernel.org, nphamcs@gmail.com,
baohua@kernel.org, youngjun.park@lge.com, kunwu.chan@gmail.com,
klarasmodin@gmail.com, "Baoquan He" <hebaoquan@kylinos.cn>
Subject: Re: [PATCH v8 01/14] mm/vmalloc: support vmalloc-backed VM_SPARSE areas
Date: Fri, 04 Dec 2026 16:48:13 +0000 [thread overview]
Message-ID: <sashiko-outbox-250219@kernel.org> (raw)
In-Reply-To: <20261203164336.864691-2-baoquan.he@linux.dev>
Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [Medium] mm/vmalloc: missing alloc_hooks() instrumentation in
vm_area_grow_pages()
- [Medium] mm: vm_area_grow_pages() infers pages[] capacity from
area->nr_pages
- [Low] mm/vmalloc: unlocked area->pages write in vm_area_grow_pages()
- [Low] mm: vm_area_grow_pages() end parameter unit conflicts with
vmalloc.h APIs
- [Low] mm/vmalloc: vm_area_grow_pages() omits sleepable vfree() context
requirement
- [Low] mm/vmalloc: VM_SPARSE | VM_ALLOC areas keep KASAN_TAG_KERNEL
under SW_TAGS
--
commit 41b3c2f65a0817d28ac0086fc5899b3fa86f007c
Author: Baoquan He <hebaoquan@kylinos.cn>
mm/vmalloc: support vmalloc-backed VM_SPARSE areas
This commit adds vm_area_grow_pages() and vm_area_shrink_pages() to lazily
back and unmap pages from the start of VM_SPARSE | VM_ALLOC areas, and
updates vread_iter(), check_sparse_vm_area(), and free_vm_area() to handle
them.
> diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
> index 034a693777ca0..9f40edcddfa8a 100644
> --- a/include/linux/vmalloc.h
> +++ b/include/linux/vmalloc.h
> @@ -296,6 +296,8 @@ int vm_area_map_pages(struct vm_struct *area, unsigned long start,
> unsigned long end, struct page **pages);
> void vm_area_unmap_pages(struct vm_struct *area, unsigned long start,
> unsigned long end);
> +int vm_area_grow_pages(struct vm_struct *area, unsigned long end, gfp_t gfp);
> +void vm_area_shrink_pages(struct vm_struct *area, unsigned long end);
> void vunmap_range(unsigned long addr, unsigned long end);
[Severity: Low]
Should the end parameter use the same unit as the adjacent vmalloc.h APIs,
or be renamed?
vm_area_map_pages(), vm_area_unmap_pages(), and vunmap_range() all treat
end as a kernel virtual address, whereas vm_area_grow_pages() and
vm_area_shrink_pages() take a byte offset from area->addr. The kernel-doc
@end descriptions do not state that it is an offset, and the commit message
mixes page counts and byte offsets ([nr_pages, end)).
In addition, vm_area_shrink_pages() omits the end > get_vm_area_size(area)
check that vm_area_grow_pages() performs. Renaming end to size (or
new_size), or taking a virtual address end to match vm_area_map_pages(),
would avoid the unit mismatch.
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index aeb1cd4a53850..dd8d0c30e22f0 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
[ ... ]
> @@ -4173,6 +4175,148 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
[ ... ]
> + * The area must be released with vfree(@area->addr). Callers must
> + * serialize calls to this function.
> + *
> + * Return: 0 on success, -errno on failure.
> + */
> +int vm_area_grow_pages(struct vm_struct *area, unsigned long end, gfp_t gfp)
[Severity: Low]
Should this comment note that vfree() must be called from sleepable
context?
Unlike normal vmalloc() areas, a VM_SPARSE | VM_ALLOC area can have
nr_pages == 0 with offset 0 unmapped (immediately after get_vm_area(),
after a failed grow, or after vm_area_shrink_pages(area, 0)). vfree() is
documented as callable from interrupt context, where it delegates to
vfree_atomic() and writes a struct llist_node directly into *addr, which
would page-fault if offset 0 is unmapped.
[ ... ]
> + nr_end = end >> PAGE_SHIFT;
> + cap = roundup_pow_of_two(nr_end);
> + vn = addr_to_node(addr);
> + if (!area->pages ||
> + cap > (area->nr_pages ? roundup_pow_of_two(area->nr_pages) : 0)) {
> + struct page **old = area->pages;
> +
> + pages = kvmalloc_array(cap, sizeof(*pages), nested_gfp);
> + if (!pages)
> + return -ENOMEM;
[Severity: Medium]
Can inferring area->pages capacity from area->nr_pages cause repeated
reallocations?
If kvmalloc_array() expands area->pages across a power-of-two boundary and
the subsequent vm_area_alloc_pages() fails, area->nr_pages is left
unchanged while area->pages already has cap slots. Every retry under
memory pressure then allocates another cap-sized array, copies the
pointers, and frees the old one; once cap * sizeof(*pages) exceeds
PAGE_SIZE, each retry becomes a nested vmalloc()/vfree() cycle. Shrinking
with vm_area_shrink_pages() and growing back across a power-of-two boundary
hits the same churn.
cap is also not clamped to get_vm_area_size(area) >> PAGE_SHIFT, which can
over-allocate area->pages by up to nearly 2x for non-power-of-two areas.
Tracking the allocated capacity in struct vm_struct and clamping cap would
avoid both.
> + if (!old) {
> + area->pages = pages;
> + } else {
> + memcpy(pages, old, area->nr_pages * sizeof(*pages));
> + spin_lock(&vn->busy.lock);
> + area->pages = pages;
> + spin_unlock(&vn->busy.lock);
> + kvfree(old);
> + }
> + }
[Severity: Low]
Does the unlocked write to area->pages race with show_busy_info()?
CPU0 CPU1
vm_area_grow_pages() show_busy_info()
spin_lock(&vn->busy.lock)
area->pages = pages; <-- data race
if (is_vmalloc_addr(v->pages))
spin_unlock(&vn->busy.lock)
A VM_SPARSE | VM_ALLOC area from get_vm_area() is linked into vn->busy.head
without VM_UNINITIALIZED, so /proc/vmallocinfo readers in show_busy_info()
read v->pages under vn->busy.lock even when v->nr_pages is 0. This causes
a KCSAN data race and can transiently misreport the vpages flag. Taking
vn->busy.lock unconditionally around area->pages = pages avoids the race.
[ ... ]
> + nr_pages = (end - start) >> PAGE_SHIFT;
> + nr_allocated = vm_area_alloc_pages(vmalloc_gfp_adjust(gfp, 0),
> + NUMA_NO_NODE, 0, nr_pages,
> + area->pages + (start >> PAGE_SHIFT));
[Severity: Medium]
Is vm_area_grow_pages() missing alloc_hooks() instrumentation?
vm_area_alloc_pages() calls *_noprof page allocator helpers directly, so
without an alloc_hooks() wrapper on vm_area_grow_pages(), current->alloc_tag
is unset. Under CONFIG_MEM_ALLOC_PROFILING, the backing pages are omitted
from /proc/allocinfo and area->pages is billed to vm_area_grow_pages()
instead of its caller; under CONFIG_MEM_ALLOC_PROFILING_DEBUG, the first
grow triggers WARN_ONCE(!tag, "current->alloc_tag not set\n") in
alloc_tag_add_check() and freeing those pages warns in
alloc_tag_sub_check().
Exposing vm_area_grow_pages_noprof() wrapped with alloc_hooks() in
include/linux/vmalloc.h and calling kvmalloc_array_noprof() inside it would
match the other page-allocating vmalloc APIs.
[ ... ]
> + kasan_unpoison_vmalloc((void *)(addr + start), end - start,
> + KASAN_VMALLOC_PROT_NORMAL |
> + KASAN_VMALLOC_KEEP_TAG);
[Severity: Low]
Does passing KASAN_VMALLOC_KEEP_TAG here disable CONFIG_KASAN_SW_TAGS
checks?
__get_vm_area_node() skips kasan_unpoison_vmalloc() when VM_ALLOC is set,
so area->addr still carries the match-all KASAN_TAG_KERNEL tag (0xFF).
Passing KASAN_VMALLOC_KEEP_TAG writes that tag into shadow memory instead
of assigning a random tag, and kasan_check_range() short-circuits all
checks for KASAN_TAG_KERNEL pointers, silently disabling out-of-bounds and
use-after-free detection on these areas.
Assigning a random tag to area->addr at reservation time (without
unpoisoning unbacked pages) and using kasan_reset_tag(area->addr) before
addr_to_node(), __vmap_pages_range(), and vunmap_range() would restore
tag-based checking.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203164336.864691-1-baoquan.he@linux.dev?part=1
next prev parent reply other threads:[~2026-12-04 16:48 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 16:43 [PATCH v8 00/14] mm, swap: extendable swap devices (xswap phase I) Baoquan He
2026-12-03 16:43 ` [PATCH v8 01/14] mm/vmalloc: support vmalloc-backed VM_SPARSE areas Baoquan He
2026-12-04 16:48 ` sashiko-bot [this message]
2026-12-03 16:43 ` [PATCH v8 02/14] mm: xswap support for zswap Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 03/14] mm, swap: refactor free_swap_cluster_info to take swap_info_struct Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 04/14] mm, swap: use a VM_SPARSE cluster array for xswap devices Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 05/14] mm, swap: widen swap_info_struct max/pages to unsigned long Baoquan He
2026-12-03 16:43 ` [PATCH v8 06/14] mm, swap: create the xswap device from swapon(2) Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 07/14] mm, swap: refactor swapoff and add xswap_destroy Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 08/14] mm, swap: require zswap for xswap devices Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 09/14] mm, swap: let the command line set the xswap device size Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 10/14] mm, swap: add CONFIG_XSWAP_DEFAULT_MAX Baoquan He
2026-12-03 16:43 ` [PATCH v8 11/14] mm, swap: add xswap grow trigger on cluster allocation Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 12/14] mm, swap: add debugfs counters for xswap Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 13/14] mm, swap: do not give an xswap slot to a cgroup that cannot zswap Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 14/14] mm, swap: skip the overcommit probe when removing xswap Baoquan He
2026-12-04 16:48 ` sashiko-bot
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=sashiko-outbox-250219@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baoquan.he@linux.dev \
--cc=chrisl@kernel.org \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hebaoquan@kylinos.cn \
--cc=kasong@tencent.com \
--cc=klarasmodin@gmail.com \
--cc=kunwu.chan@gmail.com \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=urezki@gmail.com \
--cc=yosry@kernel.org \
--cc=youngjun.park@lge.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.