All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Matthew Wilcox <willy@infradead.org>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
	Qian Xiao <heyheyco@gmail.com>
Subject: [PATCH 3/3] xarray: keep advancing after a concurrent sibling store
Date: Wed, 02 Dec 2026 17:26:07 -0800	[thread overview]
Message-ID: <b0bf98a720f546f69ae25ce7a9ebf702.3@linux-foundation.org> (raw)
In-Reply-To: <b0bf98a720f546f69ae25ce7a9ebf702.0@linux-foundation.org>

An RCU reader in xas_find_marked() can select a marked slot and move
xa_index to it.  A concurrent multi-index store can then replace that slot
with a sibling.  The reader sees the sibling, loops, and resolves it to
its canonical slot.  That leaves xa_offset behind xa_index and can return
an entry already passed.  xa_find_after() can mistake the result for a
sibling of its starting entry and skip it.

Once the search has selected a later marked slot, keep advancing when that
slot has become a sibling.  The next search starts after the slot already
reached instead of resolving it to a lower canonical slot.  RCU iteration
may miss an entry changed concurrently, but must not move its cursor
backwards or repeatedly return an old entry.

Link: https://lore.kernel.org/r/20261127222110.3755894-1-heyheyco@gmail.com
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reported-by: <sashiko-bot@kernel.org>
Closes: <https://lore.kernel.org/sashiko-outbox-239089@kernel.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Qian Xiao <heyheyco@gmail.com>

 lib/xarray.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

--- a/lib/xarray.c~xarray-fix-index-jumping-backwards-in-xas_find_marked-fix
+++ a/lib/xarray.c
@@ -1544,8 +1544,10 @@ void *xas_find_marked(struct xa_state *x
 		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;
+		}
 		if (!xa_is_node(entry))
 			return entry;
 		if (xas->xa_offset != get_offset(xas->xa_index, xas->xa_node))
_


      parent reply	other threads:[~2026-12-03  1:26 UTC|newest]

Thread overview: 4+ 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-03  1:26 ` Andrew Morton [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=b0bf98a720f546f69ae25ce7a9ebf702.3@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=heyheyco@gmail.com \
    --cc=linux-mm@kvack.org \
    --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.