From: sashiko-bot@kernel.org
To: "Andrew Morton" <akpm@linux-foundation.org>,
"Matthew Wilcox" <willy@infradead.org>
Cc: linux-mm@kvack.org, "Qian Xiao" <heyheyco@gmail.com>
Subject: Re: [PATCH 3/3] xarray: keep advancing after a concurrent sibling store
Date: Fri, 04 Dec 2026 01:26:28 +0000 [thread overview]
Message-ID: <sashiko-outbox-248891@kernel.org> (raw)
In-Reply-To: <b0bf98a720f546f69ae25ce7a9ebf702.3@linux-foundation.org>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] xarray: backward sibling resolution in xas_find_marked() on
NULL or ascent
- [Medium] xarray: in-place split in xas_find_marked() returns entry
below xa_index
--
commit 08b16eb70e7809f38ed1e7cbcf213a6ffa30db6a
Author: Andrew Morton <akpm@linux-foundation.org>
xarray: keep advancing after a concurrent sibling store
This commit sets advance to true when xas_find_marked() encounters a
sibling entry at its selected slot so the next iteration searches past
that slot instead of resolving it backwards to a lower canonical slot.
Link: https://lore.kernel.org/r/20261127222110.3755894-1-heyheyco@gmail.com
> diff --git a/lib/xarray.c b/lib/xarray.c
> index 5b68f41480610..7c820bd145186 100644
> --- a/lib/xarray.c
> +++ b/lib/xarray.c
> @@ -1544,8 +1544,10 @@ void *xas_find_marked(struct xa_state *xas, unsigned long max, xa_mark_t mark)
> entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset);
> if (!entry && !(xa_track_free(xas->xa) && mark == XA_FREE_MARK))
> continue;
> - if (xa_is_sibling(entry))
> + if (xa_is_sibling(entry)) {
> + advance = true;
> continue;
> + }
[Severity: Medium]
Can xas_find_marked() still resolve xas->xa_offset backwards behind
xas->xa_index when a selected slot is concurrently cleared to NULL before
becoming a sibling, or when ascending from a finished child node?
When xas_find_chunk() selects a later slot at offset > xas->xa_offset, it
sets advance = false and moves xas->xa_index to offset. If the reader
then sees !entry and takes the continue above, advance remains false on
the next iteration:
CPU0 (reader) CPU1 (writer)
xas_find_marked()
offset = xas_find_chunk(...)
advance = false
xas_move_index(xas, offset)
xas->xa_offset = offset
/* replaces offset with multi-index */
/* entry covering canon..offset */
rcu_assign_pointer(slot[offset], NULL)
entry = xa_entry(..., offset)
if (!entry && ...)
continue; /* advance == false */
rcu_assign_pointer(slot[offset],
xa_mk_sibling(canon))
/* mark set on canon */
if (!advance)
xas->xa_offset = canon
offset = xas_find_chunk(...) /* returns canon == xas->xa_offset */
return entry; <-- returns canon with xa_offset < xa_index
Because xas_find_chunk(xas, false, mark) starts at canon and returns
offset == xas->xa_offset, the offset > xas->xa_offset block and its
XA_RETRY_ENTRY check are bypassed. The same backward resolution happens
when finishing a child node (xas->xa_offset == XA_CHUNK_SIZE): the loop
sets xas->xa_offset = xas->xa_node->offset + 1, ascends to xa_parent(),
and sets advance = false after xas->xa_index has already moved to
child->offset + 1, so a concurrent multi-index store in the parent node
covering canon..child->offset + 1 is resolved backwards to
canon <= child->offset. Lockless RCU callers can then receive an entry
already passed, or xa_find_after() can mistake a later entry for a sibling
via xas_sibling() and skip it.
> if (!xa_is_node(entry))
> return entry;
> if (xas->xa_offset != get_offset(xas->xa_index, xas->xa_node))
[Severity: Medium]
If a marked multi-index entry is concurrently split in place into smaller
marked entries in the same node, can returning non-node entries before the
xas->xa_offset != get_offset(xas->xa_index, xas->xa_node) check return an
entry below xas->xa_index?
CPU0 (reader, xa_index at slot 2) CPU1 (writer)
xas_find_marked()
if (!advance)
/* slot 2 is sibling of 0 */
xas->xa_offset = 0
xas_split()
/* splits slots 0..3 in place into */
/* marked entries E0..E3 */
offset = xas_find_chunk(...) /* returns 0 == xas->xa_offset */
entry = xa_entry(..., 0) /* loads E0 */
if (!xa_is_node(entry))
return entry; <-- returns E0 at slot 0 < xa_index
Because E0 is not an xa_node, xas_find_marked() returns before reaching
the xas->xa_offset != get_offset(xas->xa_index, xas->xa_node) check. The
caller receives E0 below its starting index with xas->xa_offset = 0 and
xas->xa_index at slot 2, and the next advance jumps to
get_offset(xas->xa_index, xas->xa_node) + 1 (slot 3), skipping the marked
split entry E2 at slot 2.
--
Sashiko AI review · https://sashiko.dev/#/patchset/b0bf98a720f546f69ae25ce7a9ebf702.0@linux-foundation.org?part=3
prev parent reply other threads:[~2026-12-04 1:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 1:25 [PATCH 0/3] xarray: fix marked iterator index after multi-index entries Andrew Morton
2026-12-03 1:26 ` [PATCH 1/3] lib/test_xarray: check marked iteration across " Andrew Morton
2026-12-03 1:26 ` [PATCH 2/3] xarray: fix index jumping backwards in xas_find_marked() Andrew Morton
2026-12-04 1:26 ` sashiko-bot
2026-12-03 1:26 ` [PATCH 3/3] xarray: keep advancing after a concurrent sibling store Andrew Morton
2026-12-04 1:26 ` 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-248891@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=heyheyco@gmail.com \
--cc=linux-mm@kvack.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=willy@infradead.org \
/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.