From: sashiko-bot@kernel.org
To: "Qian Xiao" <heyheyco@gmail.com>,
"Matthew Wilcox" <willy@infradead.org>,
"Andrew Morton" <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, "Krystian Kaniewski" <krystianmkaniewski@gmail.com>
Subject: Re: [PATCH v3] xarray: fix index jumping backwards in xas_find_marked()
Date: Sat, 28 Nov 2026 22:21:28 +0000 [thread overview]
Message-ID: <sashiko-outbox-239089@kernel.org> (raw)
In-Reply-To: <20261127222110.3755894-1-heyheyco@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] xarray: cursor index desync in xas_find_marked() on
concurrent sibling store
--
commit 57aa975de70fddb8babaa9a1b191b30f80289953
Author: Qian Xiao <heyheyco@gmail.com>
xarray: fix index jumping backwards in xas_find_marked()
This commit preserves xas->xa_index when resolving sibling slots in
xas_find_marked(), aligns xas->xa_offset before advancing or pausing, and
returns XA_RETRY_ENTRY when a concurrent tree modification would move the
cursor backwards or descend into the wrong node.
> diff --git a/lib/xarray.c b/lib/xarray.c
> index 8c09f6c6cd8f7..5b68f41480610 100644
> --- a/lib/xarray.c
> +++ b/lib/xarray.c
[ ... ]
> @@ -1512,14 +1523,14 @@ void *xas_find_marked(struct xa_state *xas, unsigned long max, xa_mark_t mark)
>
> if (!advance) {
> entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset);
> - if (xa_is_sibling(entry)) {
> + if (xa_is_sibling(entry))
> xas->xa_offset = xa_to_sibling(entry);
> - xas_move_index(xas, xas->xa_offset);
> - }
> }
>
> offset = xas_find_chunk(xas, advance, mark);
> if (offset > xas->xa_offset) {
> + if (offset <= get_offset(xas->xa_index, xas->xa_node))
> + return XA_RETRY_ENTRY;
> advance = false;
> xas_move_index(xas, offset);
> /* Mind the wrap */
> @@ -1537,6 +1548,8 @@ void *xas_find_marked(struct xa_state *xas, unsigned long max, xa_mark_t mark)
> continue;
> if (!xa_is_node(entry))
> return entry;
> + if (xas->xa_offset != get_offset(xas->xa_index, xas->xa_node))
> + return XA_RETRY_ENTRY;
> xas->xa_node = xa_to_node(entry);
> xas_set_offset(xas);
> }
[Severity: Medium]
Can a concurrent multi-index store after xas_move_index() desynchronize
xas->xa_offset and xas->xa_index?
CPU0 CPU1
xas_find_marked()
offset = xas_find_chunk(...)
/* offset > xas->xa_offset */
advance = false
xas_move_index(xas, offset)
xas->xa_offset = offset
xas_store()
/* multi-index store [canon..end]
* with canon < offset <= end;
* squashes mark to canon
*/
entry = xa_entry(..., offset)
/* xa_is_sibling(entry) */
continue
/* next iteration: !advance */
xas->xa_offset = canon
offset = xas_find_chunk(..., false, mark)
/* offset == canon == xas->xa_offset */
return entry <-- xa_offset = canon,
xa_index = offset << shift
Because offset == xas->xa_offset on the second iteration, the
if (offset > xas->xa_offset) block is skipped and xas_find_marked()
returns the entry at canon with xas->xa_offset == canon while
xas->xa_index remains at offset << shift.
When the search started at or below canon << shift, xa_find_after() sees
xas_sibling(&xas) as true and skips an unvisited entry after *indexp,
while xa_find() reports offset << shift instead of canon << shift. If
the cursor had already visited an entry at or above canon and entered
with advance == true, rewinding xas->xa_offset to canon also lets
xas_find_marked() return an already-visited entry again, or if a retry is
triggered after xas_move_index() has mutated xas->xa_index, xas_retry()
restarts from offset << shift and skips marked entries below it.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127222110.3755894-1-heyheyco@gmail.com?part=1
prev parent reply other threads:[~2026-11-28 22:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 21:34 [PATCH] xarray: fix index jumping backwards in xas_find_marked() Qian Xiao
2026-11-25 21:34 ` sashiko-bot
2026-11-26 19:08 ` [PATCH v2] " Qian Xiao
2026-11-27 19:09 ` sashiko-bot
2026-11-27 22:21 ` [PATCH v3] " Qian Xiao
2026-11-28 22:21 ` 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-239089@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=heyheyco@gmail.com \
--cc=krystianmkaniewski@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox