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 00C6D606A31F for ; Sun, 6 Dec 2026 09:25:20 +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=AnSPAo8B Received: by kanga.kvack.org (Postfix) id 1E4016B00EF; Sun, 6 Dec 2026 04:25:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 194D36B05B1; Sun, 6 Dec 2026 04:25:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0AB596B05B6; Sun, 6 Dec 2026 04:25:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D71316B00EF for ; Sun, 6 Dec 2026 04:25:18 -0500 (EST) Received: from smtpin25.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay07.hostedemail.com (Postfix) with ESMTP id F2FEA1604FD for ; Sun, 6 Dec 2026 09:25:17 +0000 (UTC) X-FDA: 85513024674.25.A9CB765 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf18.hostedemail.com (Postfix) with ESMTP id 4ED6B1C000F for ; Sun, 6 Dec 2026 09:25:16 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=AnSPAo8B; spf=pass (imf18.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 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=1796549116; b=oMhCsFrl+7ywNBetrvJsuv4EhW1Bf4sve9A6/a3Y0IStScU3A2TFyApMdwByj9E2I8mGUV wB7sHrb9qgOOGqsmBrzgwp2J8sam1vu1yU8pXsQScR7Vz++VKxcD4jaDGIcHRLPQTrwT7N rmrFfNas/R0vawYhTJq+n2YwOjmXGaI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796549116; 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=J3l6kJii/BevWGMc7Es2qZKMbDy9FcfNR0e6vqDR39c=; b=GRkao1JtvcPNpBojoPVWfYfodOsLa8SXNFUSHeuVEOQnhM4YOM9PRZgwrh7cM29eQ+Xuqc H+jOqzkVOzFvSL8wQk0FXsLORX+lTdqqWlDXzVGPQzf44Tq+ClXh0P2zg/gOK1XwTASJ8M IYpmR+SIkmxLpZJTZSiZj8syZUHDR4c= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=AnSPAo8B; spf=pass (imf18.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 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 sea.source.kernel.org (Postfix) with ESMTP id 95D9D42E8A; Sun, 6 Dec 2026 09:25:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49F151F0093B; Sun, 6 Dec 2026 09:25:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796549114; bh=J3l6kJii/BevWGMc7Es2qZKMbDy9FcfNR0e6vqDR39c=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=AnSPAo8BI/YY3VZDNqL8WOEV5NjyjQCKPNsnwNnpyAuK+/9nED/NpztrKB6H1nKWA LsPjOXKYTwTYs9zqRx1FUnsNABWWynhgaiaYwhkl1hv5ZjHNY+iuO8rUcSqcyae9tE o3ELs1mu0tfjahqPt2ZNOh90u+oY7GPSVnw0O3+84WNbVMHt9o3UgDGDKRi384lXWB yU0fcZG/lB5U19tHOIOLtTSsE+5MEBmuE6e7gel8O6mTqa6SRLbtVPvtNFEypaexsD 5fjp3L6H4J5pKs4CBMD+kVd6EpCdLggx17ymTEd00qKP5gHAO4ZYKetUDf0ImoQyEQ a2sbaJe6G58TQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] xarray: add READ_ONCE() in xas_find_chunk() Reply-To: sashiko-reviews@lists.linux.dev To: "Shuai Liu" <847807867@qq.com>, "Matthew Wilcox" Cc: linux-mm@kvack.org, syzbot+cc64b6bdf649b54047e0@syzkaller.appspotmail.com, "kernel test robot" In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 09:25:13 +0000 X-Stat-Signature: 3kab16be93fihc14ua1bryxbjk7wzt7a X-Rspam-User: X-Rspamd-Queue-Id: 4ED6B1C000F X-Rspamd-Server: rspam09 X-Spam-Status: No, score=-11.1 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: 1796549116-299608 X-HE-Meta: U2FsdGVkX19nBdz6QSwpFJy9Uy/X/2K8LVxFdhdfhbmnT8tXzunQ1nlbf7SBqvlTHFBwr5KsPonnZDLL7ekxVbwhDs9GccGeLla+OSxVf47VOlrwVlxV8lKP9qY9+YgIEz0BcxpN3JKCeDjHES0YZ11ISW7L+8zH9NZPzWnCad66p2w5AD1lF6y5QTSS67671P0tEc4P1eZYuJ1IBsQfYZvxscTt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4K2aurNiSUKKYyxmU56oyCL7Y+5aUpMG32nHsMrhNSkFhg/imn9fvg8eymmrhlGPqbD4aOvtZ/7m4c/614I/fQVSliIYJw9NSz0JX1GkYk7Ll1/WenbnQFJaY46SGZtvDH7CETaR9wy779NHMSywGO4P2p/srX1jge7WATtA6hyhNR53XFvXn7lAVHZTZRAZWMUBY9RqSh54KAGJMu+OIRyLNXxFioBnP21/a558TiGAfEWwUWZMEPLuVkAKboH4ZQvVaPMCY2smcGz/nUBKPgFB5dUK8+Ue52kmli2xJ1VH8k4TUhfQTAG+AcbK2dkaHnXgMXTk4oM4Uu99QTYXgcsF7uvQW2Ib3IJ7jnzXYh8+itr7UpC8Z3VU2U/sWiePtvLxeQZXMFcgC9Yfs0/1ts/yuHkg1910fGtzWChy1Xoezt4eyuFoKiJPhZmFcFtU4LSlt4Q48UqrUyUaKxZF21c1sYymVCacaBvZ0Gxm9GPt0VBP0hNIv1VtUf5uYyWZ2QBbPOADcsXmij4jSC2nh0ZXjiBDJiGnzUEpyksRjjGyo29QRncljkmsyd0sJV3LemBJMsyzv/Pt/dNUOzTwgR1ih5WFMw7uwgLiGZGjg34mWPUXQZqhA2lqmy5/67Geg0A9o8nzLN3SV5 ELVR7ZQS BIvJr8T2Ec4= 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 2 potential issues to consider: - [Medium] xarray: xas_find_chunk() loads marks before bounds check and spills on 32-bit - [Low] xarray: commit message describes unmerged v1 32-bit OOB bug -- commit 60ccda285c1568ab1c0c4681e1b2cd921d031e30 Author: Shuai Liu <847807867@qq.com> xarray: add READ_ONCE() in xas_find_chunk() This commit snapshots all XA_MARK_LONGS words of xas->xa_node->marks[] with READ_ONCE() into a local array in xas_find_chunk() before scanning for the next set mark bit, fixing a KCSAN data race against concurrent mark updates. > Snapshot each marks word with READ_ONCE() into a local variable, then > do all bit operations on that snapshot. This silences KCSAN, forces a > fresh load on each call, prevents the compiler from caching a stale > value across iterations, and covers all XA_MARK_LONGS words so the > 32-bit path (XA_CHUNK_SIZE=3D64, BITS_PER_LONG=3D32) no longer reads past > a single word. [Severity: Low] Is the final clause accurate relative to the parent commit? Before this patch, xas_find_chunk() passed addr directly to find_next_bit(), which already covered all XA_MARK_LONGS words on 32-bit. Reading past a single word was only an issue in v1, so the permanent commit message should not imply the parent commit had that bug. > diff --git a/include/linux/xarray.h b/include/linux/xarray.h > index 8c42d899d94cf..95c3fc228d3da 100644 > --- a/include/linux/xarray.h > +++ b/include/linux/xarray.h > @@ -1743,20 +1743,24 @@ static inline unsigned int xas_find_chunk(struct = xa_state *xas, bool advance, > xa_mark_t mark) > { > unsigned long *addr =3D xas->xa_node->marks[(__force unsigned)mark]; > + unsigned long marks[XA_MARK_LONGS]; > unsigned int offset =3D xas->xa_offset; > + int i; > =20 > if (advance) > offset++; > + for (i =3D 0; i < XA_MARK_LONGS; i++) > + marks[i] =3D READ_ONCE(addr[i]); > if (XA_CHUNK_SIZE =3D=3D BITS_PER_LONG) { > if (offset < XA_CHUNK_SIZE) { > - unsigned long data =3D *addr & (~0UL << offset); > + unsigned long data =3D marks[0] & (~0UL << offset); > if (data) > return __ffs(data); > } > return XA_CHUNK_SIZE; > } > =20 > - return find_next_bit(addr, XA_CHUNK_SIZE, offset); > + return find_next_bit(marks, XA_CHUNK_SIZE, offset); > } [Severity: Medium] Can this bounds check run before the READ_ONCE() loop, and can the 32-bit path avoid the marks[] stack array? Because READ_ONCE() emits volatile loads, the compiler cannot sink the loop past the offset < XA_CHUNK_SIZE check. Callers like xas_next_marked() pass advance=3Dtrue when xa_offset =3D=3D XA_CHUNK_MASK, so every leaf-node boun= dary now performs wasted volatile loads and discards the result. On 32-bit (XA_CHUNK_SIZE =3D=3D 64, BITS_PER_LONG =3D=3D 32), small_const_n= bits(64) is false, so find_next_bit() passes marks[] to out-of-line _find_next_bit(). This forces a stack spill, loads both words even when offset >=3D 32, and a= dds -fstack-protector-strong overhead to callers like xas_find_marked(). Returning XA_CHUNK_SIZE when offset >=3D XA_CHUNK_SIZE first, using READ_ONCE(*addr) in the XA_CHUNK_SIZE =3D=3D BITS_PER_LONG branch, and scan= ning words inline from offset / BITS_PER_LONG with READ_ONCE(addr[i]) would avoid both the dead loads and the 32-bit stack spill. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/tencent_13BC58D584B= 17B82F43C8BBF7C61D3096E06@qq.com?part=3D1