From: sashiko-bot@kernel.org
To: "Shuai Liu" <847807867@qq.com>, "Matthew Wilcox" <willy@infradead.org>
Cc: linux-mm@kvack.org,
syzbot+cc64b6bdf649b54047e0@syzkaller.appspotmail.com,
"kernel test robot" <yi1.lai@intel.com>
Subject: Re: [PATCH v2] xarray: add READ_ONCE() in xas_find_chunk()
Date: Sun, 06 Dec 2026 09:25:13 +0000 [thread overview]
Message-ID: <sashiko-outbox-252309@kernel.org> (raw)
In-Reply-To: <tencent_13BC58D584B17B82F43C8BBF7C61D3096E06@qq.com>
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=64, BITS_PER_LONG=32) 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 = xas->xa_node->marks[(__force unsigned)mark];
> + unsigned long marks[XA_MARK_LONGS];
> unsigned int offset = xas->xa_offset;
> + int i;
>
> if (advance)
> offset++;
> + for (i = 0; i < XA_MARK_LONGS; i++)
> + marks[i] = READ_ONCE(addr[i]);
> if (XA_CHUNK_SIZE == BITS_PER_LONG) {
> if (offset < XA_CHUNK_SIZE) {
> - unsigned long data = *addr & (~0UL << offset);
> + unsigned long data = marks[0] & (~0UL << offset);
> if (data)
> return __ffs(data);
> }
> return XA_CHUNK_SIZE;
> }
>
> - 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=true when xa_offset == XA_CHUNK_MASK, so every leaf-node boundary
now performs wasted volatile loads and discards the result.
On 32-bit (XA_CHUNK_SIZE == 64, BITS_PER_LONG == 32), small_const_nbits(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 >= 32, and adds
-fstack-protector-strong overhead to callers like xas_find_marked().
Returning XA_CHUNK_SIZE when offset >= XA_CHUNK_SIZE first, using
READ_ONCE(*addr) in the XA_CHUNK_SIZE == BITS_PER_LONG branch, and scanning
words inline from offset / BITS_PER_LONG with READ_ONCE(addr[i]) would avoid
both the dead loads and the 32-bit stack spill.
--
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_13BC58D584B17B82F43C8BBF7C61D3096E06@qq.com?part=1
prev parent reply other threads:[~2026-12-06 9:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 9:24 [PATCH v2] xarray: add READ_ONCE() in xas_find_chunk() Shuai Liu
2026-12-06 9:25 ` sashiko-bot [this message]
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-252309@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=847807867@qq.com \
--cc=linux-mm@kvack.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=syzbot+cc64b6bdf649b54047e0@syzkaller.appspotmail.com \
--cc=willy@infradead.org \
--cc=yi1.lai@intel.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