Re: [PATCH v3] xarray: fix index jumping backwards in xas_find_marked()

From: Andrew Morton

Date: Sat Nov 28 2026 - 22:12:13 EST


On Fri, 27 Nov 2026 14:21:09 -0800 Qian Xiao <heyheyco@xxxxxxxxx> wrote:

> xas_find() keeps xa_index when a lookup starts inside a multi-index
> entry stored in a non-leaf node, and aligns xa_offset with that index
> before advancing. xas_find_marked() still does neither.
>
> Walking from a sibling slot to the canonical slot calls
> xas_move_index(), so a start index such as 127 becomes 0. After the
> cursor has been walked, xa_offset can also stay on the canonical slot
> while xa_index is inside a later slot of the same entry. The next
> xas_find_marked() then recomputes xa_index from the stale offset. If
> the entry is split, the call returns a marked entry below the index
> already reached. xas_find() returns the following entry in the same
> situation.
>
> Resolve the sibling without moving xa_index. Before advancing a cursor
> that has already been walked, set xa_offset from xa_index the same way
> xas_find() does. xas_next_marked() uses that path when the offset and
> index disagree, as xas_next_entry() already does. xas_pause() aligns
> xa_offset before its existing calculation, so the resume index stays at
> the end of the entry.
>
> If the tree changes while a sibling is being resolved, do not descend
> into a node that does not contain xa_index, and do not move xa_index
> backwards. Compare the next marked slot with get_offset() instead of
> recomputing xa_index with a 32-bit shift. Return XA_RETRY_ENTRY.
> xa_find_after() handles that retry before xas_sibling(), so a rewind
> that then retries restarts the walk. Callers that use xas_retry()
> restart from the same index.

What is the relationship between this and Krystian's identically-named
patch?
https://lore.kernel.org/20260904121301.200049-1-krystianmkaniewski@xxxxxxxxx

> The userspace XArray test suite passed.

> The kernel was not built.

Well that isn't encouraging :(