From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC644606A32C for ; Fri, 4 Dec 2026 16:48:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=i8AV5J+h Received: by kanga.kvack.org (Postfix) id C490F6B05B2; Fri, 4 Dec 2026 11:48:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BF9A16B05B3; Fri, 4 Dec 2026 11:48:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B10906B05B4; Fri, 4 Dec 2026 11:48:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8789F6B05B2 for ; Fri, 4 Dec 2026 11:48:17 -0500 (EST) Received: from smtpin18.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 223D9A8034 for ; Fri, 4 Dec 2026 16:48:17 +0000 (UTC) X-FDA: 85506883434.18.B26A1CA Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf23.hostedemail.com (Postfix) with ESMTP id 779AB14000C for ; Fri, 4 Dec 2026 16:48:15 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=i8AV5J+h; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf23.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796402895; b=7qlW50aoSjLNsY7LtBOR3tjsiRDpNsCUzul1zl6Y/DxryCCuBoN8/5doqOsar315NEPBfJ vxOsr3MjNHSc0lA5xQFM9xjsDLCYZxw/hqnDobV9ZrRpKFR94suUH/bXJmtllknVinN1au ISL+u7N30DwwxLEltGeOoyPRaqGzVUY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796402895; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=iS7v3Sg608Du1zlpLT5PyqG2xFEcX8M6kYD3h2svQfg=; b=A5ZBI/vdh8ol1iFfJl0kZ1mYDCPGu/5dMbU59qiLsvBYMqtTRaHCgrDx50wNuamy2hJyVl ESHe2/MEhZk27jcD9fiG7V2LbScIpK7gwy2dPfd28KabQgMjAQMHlBRAKUVSSShYL/hBjR Wd4kj3a55i6QG2q61HzdbJHucVRBN/I= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=i8AV5J+h; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf23.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 5879B4556E; Fri, 4 Dec 2026 16:48:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC84D1F00897; Fri, 4 Dec 2026 16:48:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796402894; bh=iS7v3Sg608Du1zlpLT5PyqG2xFEcX8M6kYD3h2svQfg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=i8AV5J+hxfhIsMaIEU1C+vJAx2JAHN0sC002SQMjlhq3nt99KJwBO1iNXG3RyJlCX B/kw96DslihfWaR84wr4YUtFA+lxkbybzaSCsRmVBX/JXcJAoagT/gsyROdRgQYmq9 pxu78YeuCULOvuLjF+Xiv7Wd8zRD+MWv51PIiKloH/ketjjRkA8IGVFVPbL9yaXnad TilzhilQEjarzV//lBvXLZbENipKO03dt5o7Tv1KtXkg5OBDodEIPXgLFs6lcJvFEP zeRuwD4nQ1N7u/cxfJ0ksOVTZqCQy1MhB2LbZtTbCX9tWvYzEG8GLE11fsd5NJTAlo MDKzRn6Wz+dBA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v8 01/14] mm/vmalloc: support vmalloc-backed VM_SPARSE areas Reply-To: sashiko-reviews@lists.linux.dev To: "Baoquan He" , 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" In-Reply-To: <20261203164336.864691-2-baoquan.he@linux.dev> References: <20261203164336.864691-1-baoquan.he@linux.dev> <20261203164336.864691-2-baoquan.he@linux.dev> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 16:48:13 +0000 X-Rspamd-Server: rspam04 X-Rspam-User: X-Rspamd-Queue-Id: 779AB14000C X-Stat-Signature: ddyguf3m9hodyxb98zmmeckshti846hs X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796402895-214226 X-HE-Meta: U2FsdGVkX18QUDA6pSsri0p6rmSxQRIKweQnODY1qIul2BhdGpVEOmtH4UW8XUAGvC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SAm6X/IH8Be5iXT5pjnlx1sLhqlXUdq+WHyt9xUElBIr/adQZmy97sz1CwncL0jkxJByaq5BswG0ubZYylqNjJ/qLO8xfFiyFytaHOCT9ypG+TpINbaQWTPehVOr5oN2pnA74LkiKl0bx5nY7sZCjveeE2Vib8wDyfJg2sXvXfwJEcgnna8GOnYTa/mK6A6kjpeQ4Qg3THqZBKwdkUuhSy8+yOgvHFjiE5Yng02rNtDoavxH2WP2oeeQShznzxwT03Gs25KKISKSxwmuqf6/2naFOaFV3Mz6Baf49LlGHCjU4yI7GmokNxUVlGxd1+YunjBAAK7zjY4lCugToLGzUKclgliYHAN7eMGqv91Yeknr+TWX+hpHMiz71tFOcdvVhkDqrEybLKpgsC4Av9jiC2oj6OvQiczkpnkwvL1owywfeN8TBc3vBLdJj8e77iLTdbVIVXZ5hlKlz2qeFU998gvhmr3riCdAsSypP/0UrAFr6O8FXo7Xqp2Ft1HjjPLZpbIdWAksLeibn+6uH214p5ykas7bfRzdwQ7DFmMPnYdtZuakNwDgOjonSvb4MfTVKURXcsGd/sl4P/0h+Qm9SOm+ZWByboNupwYPpwsvTwKo09EuSJNSw+Ft195R21Fh2NnjiIuGqAjySOPDRdYZsoVd6/jNq8I0M9lmLkjcfovjGXasf28Xnnz4fRtjS+AIgeEfOZpwTvXJYdWmcYVaKE1EUuE7SYowHbmrjh5DM6MM0Ch2FjM4JB3GKTVVPUrJpDn2ZzX50jq/9LzNB2y Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: 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 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, unsigne= d 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 =3D=3D 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 =3D end >> PAGE_SHIFT; > + cap =3D roundup_pow_of_two(nr_end); > + vn =3D addr_to_node(addr); > + if (!area->pages || > + cap > (area->nr_pages ? roundup_pow_of_two(area->nr_pages) : 0)) { > + struct page **old =3D area->pages; > + > + pages =3D 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 =3D pages; > + } else { > + memcpy(pages, old, area->nr_pages * sizeof(*pages)); > + spin_lock(&vn->busy.lock); > + area->pages =3D 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 =3D 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 =3D pages avoids the race. [ ... ] > + nr_pages =3D (end - start) >> PAGE_SHIFT; > + nr_allocated =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203164336.8646= 91-1-baoquan.he@linux.dev?part=3D1