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 D9309606A333 for ; Fri, 4 Dec 2026 16:48:27 +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=YksHw/+9 Received: by kanga.kvack.org (Postfix) id B379E6B05B5; Fri, 4 Dec 2026 11:48:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AC1726B05B7; Fri, 4 Dec 2026 11:48:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B07F6B05BA; Fri, 4 Dec 2026 11:48:22 -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 2C9606B05B5 for ; Fri, 4 Dec 2026 11:48:22 -0500 (EST) Received: from smtpin07.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B88CD804F3 for ; Fri, 4 Dec 2026 16:48:21 +0000 (UTC) X-FDA: 85506883602.07.D0EC984 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf21.hostedemail.com (Postfix) with ESMTP id 1166C1C000B for ; Fri, 4 Dec 2026 16:48:19 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b="YksHw/+9"; spf=pass (imf21.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796402900; b=X0iAVzhRr4x9uzBENUPMVzqo/ZqtniwCxZ+sAImoK+KaQicBQ7D2UZCWbqvjzHSnLKAtqp RcIBh637SgyD3H236NGPp7RqQt3nDxJJlO0fpyfpjqhVBEai2QvFZoQ2Ib4Dt84swA0ey3 tfuYenxQyo3YjK4ilQAB+bRfLV0Gqe8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796402900; 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=+U/gPduvawK5jA84Cg/c0zxCJw6VH6p4v+y0XG4qNLg=; b=dfaCh3OE2SlXUuKmMtS+W0X5eNmrjeD3cis04LCCwElOtdXpdrr1/jvtBRVktgzvpGYr54 5Tq3fm4tTSDKo98dOX2OVOxi4619YlizIRtAhk4aTduMsxOwAeDf4SlMpuvncTH1XRhadM vav/OIbhwEkPX30rL2cEmiqdHkW7HOg= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b="YksHw/+9"; spf=pass (imf21.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id EF938612A4; Fri, 4 Dec 2026 16:48:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6ED41F0093A; Fri, 4 Dec 2026 16:48:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796402898; bh=+U/gPduvawK5jA84Cg/c0zxCJw6VH6p4v+y0XG4qNLg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=YksHw/+96WrStw/XJVea5Y95UUYLaXxpjHToA31cDv9ERw4hJF64WxST29fPJyXVZ WQ2nQkeXZnHmiyvTN1mgbFhuxANF/swJEZvtv68wC4zPufD2aS/wqGbEi70cLAkdTE S3EV0271Rb0d/b4GYQqSUnc1fNk6qjo5pswAzdfQ6wPntmuYy6v5pzuditgGN7ru9i /8ZG17KNSmgy+19ZB4OP5ANah0/NnJAEm+tGSVTBkoO6sL94oU8NctqF/3JT2Wlg+3 QPRTxE+AAKDiRSp/GP8EfeMGAebqOZ4MH1Q195x3gxXuFnLZxWoha5FczzHjxz4FkJ RQZ2GL8qdYO9w== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v8 04/14] mm, swap: use a VM_SPARSE cluster array for xswap devices 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-5-baoquan.he@linux.dev> References: <20261203164336.864691-1-baoquan.he@linux.dev> <20261203164336.864691-5-baoquan.he@linux.dev> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 16:48:17 +0000 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 1166C1C000B X-Rspam-User: X-Stat-Signature: q8zcymy1ijbpw4dqrqbmi69trsa3qy5m 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: 1796402899-9713 X-HE-Meta: U2FsdGVkX19pWaO6eM8+gZqBx+hFupIsJEG5SqLqyUHjjjslotYJc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BCPxpU8DRhnHFKJo4YBWQQPkOOv9ijLwwpyNAxCEBR4tMPoelprDeb/xNEcXnSG2t0ZI0CFXewblrZTMsoLmhSvjKdb4/4NLUISe9yF4tybMw9UbB/cHorhF7xxvnuPxAtxJ5nu7cq0JGgriF+S15CyF0ORwpC0fwdAgby+/dGJczIjZ28+Hec+4j6yKTfr2MqaCvOGeGkrbAmVLPXWcyYChSHqOmREmzbU2MAMONbyNmB1JhFz8w3uhrGiihBuheDh9IIBUAxRbGpn1cH6cBFlNS3/XA746wX6R5gGvUrs98+kctThke3YWwKKdtux8UbpaawirUM8kxvRDjqVmk/rW+iR40/1ARZnNc9WqL2n2kq9mamEAvKvfvUZTafsXM1xe7XrtlwbsfnwEIKBHSohsBcxpcdYVMNjQy+5+bPI6se40KBKwPLVDBG/5nzH2cTFC4B7T+5duAyHDWvnJ4uSdfZMWHW9pbdvynePDrIuj49u8I0v0E5ku66j59i9I/NfZJ1eOTvUK7nKCXUydPnwVmoRdJibVdOsKNSIrNp0fzj76WFRQuJjVLKxNkjxrIUiMV5fRnmgU7JlFtjuJhEJ9cr2KhEr/13+L0CqUECgDqwEz0CnwjgRP0Vhjab2SAD6jokxaGzuJIsfm35P8UWRYx3XAns3xyE4NywoQ03q+r1fYWu7DrjMrdb1W1u5TMp/nlx5nMEknaPiZG8L5RQEFtUxGUUgybs4mMu0ewgWFWLuGVxiXYXdAgojLEErMWgGCoIq9L81N9/rOljC1w2mZu 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 3 potential issues to consider: - [Medium] mm: spurious SIGBUS in do_swap_page() for stale xswap entries - [Low] mm: duplicated xswap cluster setup and teardown in swapfile.c - [Low] mm: data race on area->pages in vm_area_grow_pages() vs show_busy_info() -- commit 870c51b1a2136c162ae15350e3332e819a3a39bd Author: Baoquan He mm, swap: use a VM_SPARSE cluster array for xswap devices This commit adds CONFIG_XSWAP and backs an xswap device's cluster_info array with a VM_SPARSE | VM_ALLOC vmalloc area mapped lazily in chunks. It also updates get_swap_device(), find_next_to_unuse(), wait_for_allocation(), and free_swap_cluster_info() to bound accesses by nr_clusters_mapped. > diff --git a/mm/swapfile.c b/mm/swapfile.c > index 35a079f2bb767..de2feaa2a6287 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c [ ... ] > @@ -1983,6 +1992,20 @@ struct swap_info_struct *get_swap_device(swp_entry= _t entry) > offset =3D swp_offset(entry); > if (offset >=3D si->max) > goto put_out; > +#ifdef CONFIG_XSWAP > + if (si->flags & SWP_XSWAP) { > + /* Pairs with the release store in xswap_map_clusters(). */ > + unsigned long mapped =3D smp_load_acquire(&si->nr_clusters_mapped); > + > + /* > + * xswap maps cluster_info lazily. A stale entry can point > + * past nr_clusters_mapped; reject it before anything > + * dereferences cluster_info. > + */ > + if (offset / SWAPFILE_CLUSTER >=3D mapped) > + goto put_out; > + } > +#endif > =20 > return si; [Severity: Medium] Can jumping to put_out here cause a spurious SIGBUS in do_swap_page()? CPU0 CPU1 do_swap_page() pte_unmap_same(vmf) swapoff() unuse_mm() /* mmap_read_lock */ /* replaces swap PTE */ swapon() /* xswap, reuses slot */ xswap_map_clusters() get_swap_device(entry) goto put_out <-- returns ERR_PTR(-EIO) ret =3D VM_FAULT_SIGBUS do_swap_page() drops the page table lock in pte_unmap_same() before calling get_swap_device(entry) under mmap_read_lock or the per-VMA read lock. Because unuse_mm() only takes mmap_read_lock, a concurrent swapoff() followed by swapon() of an xswap device can reuse the same swap_info[] slot with nr_clusters_mapped initialized to XSWAP_GROW_CLUSTERS. When do_swap_page() then passes the stale entry, put_out logs a "Bad swap offset entry" error and returns ERR_PTR(-EIO), which do_swap_page() turns directly into VM_FAULT_SIGBUS without re-locking the page table lock to check whether the PTE changed. [ ... ] > @@ -3724,6 +3846,69 @@ static int setup_swap_clusters_info(struct swap_in= fo_struct *si, > int err =3D -ENOMEM; > unsigned long i; > =20 > +#ifdef CONFIG_XSWAP > + if (si->flags & SWP_XSWAP) { > + unsigned long size =3D PAGE_ALIGN(nr_clusters * sizeof(*cluster_info)); > + struct vm_struct *vm; > + > + vm =3D get_vm_area(size, VM_SPARSE | VM_ALLOC); > + if (!vm) > + goto err; > + > + cluster_info =3D vm->addr; > + si->cluster_vm =3D vm; > + si->nr_clusters_max =3D nr_clusters; > + si->cluster_info =3D cluster_info; > + > + /* Must be initialized before xswap_map_clusters() locks it. */ > + mutex_init(&si->xswap_lock); > + > + err =3D xswap_map_clusters(si, 0, min_t(unsigned long, > + XSWAP_GROW_CLUSTERS, nr_clusters)); > + if (err) > + goto err_free_vm; [Severity: Low] Is there a data race on area->pages between the initial xswap_map_clusters() call and /proc/vmallocinfo? get_vm_area() inserts the vm_struct onto vn->busy.head without VM_UNINITIALIZED, making it immediately visible to show_busy_info(). On the first grow, vm_area_grow_pages() assigns area->pages without vn->busy.lock: mm/vmalloc.c:vm_area_grow_pages() { ... 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); ... } Concurrently, show_busy_info() reads v->pages under vn->busy.lock in is_vmalloc_addr(v->pages), which can trigger a KCSAN report or an inconsistent vpages tag. Taking vn->busy.lock around area->pages =3D pages in the !old branch too would close the race. [ ... ] > + INIT_LIST_HEAD(&si->free_clusters); > + INIT_LIST_HEAD(&si->full_clusters); > + INIT_LIST_HEAD(&si->discard_clusters); > + for (i =3D 0; i < SWAP_NR_ORDERS; i++) { > + INIT_LIST_HEAD(&si->nonfull_clusters[i]); > + INIT_LIST_HEAD(&si->frag_clusters[i]); > + } > + > + /* > + * Cluster 0 holds the header slot, which is marked bad, so it > + * is not entirely free. si->max is cluster aligned, so no > + * cluster holds a slot past the end of the device. > + */ > + for (i =3D 0; i < si->nr_clusters_mapped; i++) { > + struct swap_cluster_info *ci =3D &cluster_info[i]; > + > + if (ci->count) { > + ci->flags =3D CLUSTER_FLAG_NONFULL; > + list_add_tail(&ci->list, &si->nonfull_clusters[0]); > + } else { > + ci->flags =3D CLUSTER_FLAG_FREE; > + list_add_tail(&ci->list, &si->free_clusters); > + } > + } > + > + return 0; > + > +err_free_vm: > + vfree(si->cluster_info); > + si->cluster_vm =3D NULL; > + si->cluster_info =3D NULL; > + si->nr_clusters_mapped =3D 0; > + return err; > + } > +#endif /* CONFIG_XSWAP */ [Severity: Low] Can the xswap path share the cluster list initialization, insertion loop, and error cleanup with the non-xswap path below? The list setup and cluster insertion loop here duplicate the ones at the end of setup_swap_clusters_info(), and err_free_vm duplicates the xswap teardown in free_swap_cluster_info() while omitting per-cluster table cleanup, so jumping to the existing err label would also clean up cluster 0's table on error. The same per-cluster table freeing loop is also duplicated between the xswap and non-xswap branches in free_swap_cluster_info(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203164336.8646= 91-1-baoquan.he@linux.dev?part=3D4