* [PATCH 0/3] xarray: fix marked iterator index after multi-index entries
@ 2026-12-03 1:25 Andrew Morton
2026-12-03 1:26 ` [PATCH 1/3] lib/test_xarray: check marked iteration across " Andrew Morton
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Andrew Morton @ 2026-12-03 1:25 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: linux-mm, Andrew Morton, Qian Xiao, stable
A marked XArray lookup can move its index backwards when the search starts
in a multi-index entry. A later search can use an offset that no longer
agrees with the index and return an entry already passed.
Add tests for lookup, splitting, pausing and advancing across marked
multi-index entries. Then apply Qian Xiao's iterator fix and prevent a
concurrent sibling store from sending an advancing search backwards.
Qian Xiao (2):
lib/test_xarray: check marked iteration across multi-index entries
xarray: fix index jumping backwards in xas_find_marked()
Andrew Morton (1):
xarray: keep advancing after a concurrent sibling store
include/linux/xarray.h | 3 +-
lib/test_xarray.c | 165 ++++++++++++++++++++++++++++++++++++++++++++
lib/xarray.c | 28 ++++++--
3 files changed, 189 insertions(+), 7 deletions(-)
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH 1/3] lib/test_xarray: check marked iteration across multi-index entries 2026-12-03 1:25 [PATCH 0/3] xarray: fix marked iterator index after multi-index entries Andrew Morton @ 2026-12-03 1:26 ` 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 ` [PATCH 3/3] xarray: keep advancing after a concurrent sibling store Andrew Morton 2 siblings, 0 replies; 6+ messages in thread From: Andrew Morton @ 2026-12-03 1:26 UTC (permalink / raw) To: Matthew Wilcox; +Cc: linux-mm, Andrew Morton, Qian Xiao From: Qian Xiao <heyheyco@gmail.com> Add Qian's test cases first. They check the index and returned entry when a lookup starts inside a marked multi-index entry, after that entry is split, and when the walk is paused or continued. They expose the existing index and offset mismatch before the iterator changes. Link: https://patch.msgid.link/20261127222110.3755894-1-heyheyco@gmail.com Signed-off-by: Qian Xiao <heyheyco@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> lib/test_xarray.c | 165 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) --- a/lib/test_xarray.c~lib-test_xarray-check-marked-iteration-across-multi-index-entries +++ a/lib/test_xarray.c @@ -1348,6 +1348,170 @@ out: #endif } +static noinline void check_multi_find_marked_nonleaf(struct xarray *xa) +{ +#ifdef CONFIG_XARRAY_MULTI + unsigned int order = XA_CHUNK_SHIFT + 1; + unsigned long next = 1UL << order; + unsigned long start = next - 1; + XA_STATE(xas, xa, start); + XA_STATE_ORDER(split, xa, 0, 0); + void *entry; + unsigned long i; + + /* Multi-index entry in two slots of a non-leaf node, both marked. */ + xa_store_order(xa, 0, order, xa_mk_index(0), GFP_KERNEL); + xa_set_mark(xa, 0, XA_MARK_0); + XA_BUG_ON(xa, xa_store_index(xa, next, GFP_KERNEL) != NULL); + xa_set_mark(xa, next, XA_MARK_0); + + rcu_read_lock(); + entry = xas_find_marked(&xas, ULONG_MAX, XA_MARK_0); + XA_BUG_ON(xa, entry != xa_mk_index(0)); + XA_BUG_ON(xa, xas.xa_index != start); + + entry = xas_find_marked(&xas, ULONG_MAX, XA_MARK_0); + XA_BUG_ON(xa, entry != xa_mk_index(next)); + XA_BUG_ON(xa, xas.xa_index != next); + + entry = xas_find_marked(&xas, ULONG_MAX, XA_MARK_0); + XA_BUG_ON(xa, entry != NULL); + rcu_read_unlock(); + + xa_destroy(xa); + XA_BUG_ON(xa, !xa_empty(xa)); + + /* Split the multi-index entry after a lookup begins inside it. */ + xa_store_order(xa, 0, order, xa_mk_index(0), GFP_KERNEL); + xa_set_mark(xa, 0, XA_MARK_0); + XA_BUG_ON(xa, xa_store_index(xa, next, GFP_KERNEL) != NULL); + xa_set_mark(xa, next, XA_MARK_0); + + xas_set(&xas, start); + rcu_read_lock(); + entry = xas_find_marked(&xas, ULONG_MAX, XA_MARK_0); + XA_BUG_ON(xa, entry != xa_mk_index(0)); + XA_BUG_ON(xa, xas.xa_index != start); + rcu_read_unlock(); + + xas_split_alloc(&split, xa_mk_index(0), order, GFP_KERNEL); + if (xas_error(&split)) { + XA_BUG_ON(xa, true); + goto out; + } + xas_lock(&split); + xas_split(&split, xa_mk_index(0), order); + for (i = 0; i < next; i++) + __xa_store(xa, i, xa_mk_index(i), 0); + xas_unlock(&split); + + rcu_read_lock(); + entry = xas_find_marked(&xas, ULONG_MAX, XA_MARK_0); + XA_BUG_ON(xa, entry != xa_mk_index(next)); + XA_BUG_ON(xa, xas.xa_index != next); + + entry = xas_find_marked(&xas, ULONG_MAX, XA_MARK_0); + XA_BUG_ON(xa, entry != NULL); + rcu_read_unlock(); + + xa_destroy(xa); + + /* Nothing marked past the index already walked. */ + xa_store_order(xa, 0, order, xa_mk_index(0), GFP_KERNEL); + xa_set_mark(xa, 0, XA_MARK_0); + XA_BUG_ON(xa, xa_store_index(xa, next, GFP_KERNEL) != NULL); + + xas_set(&xas, start); + rcu_read_lock(); + entry = xas_load(&xas); + XA_BUG_ON(xa, entry != xa_mk_index(0)); + XA_BUG_ON(xa, xas.xa_index != start); + rcu_read_unlock(); + + xas_set(&split, 0); + xas_split_alloc(&split, xa_mk_index(0), order, GFP_KERNEL); + if (xas_error(&split)) { + XA_BUG_ON(xa, true); + goto out; + } + xas_lock(&split); + xas_split(&split, xa_mk_index(0), order); + for (i = 0; i < next; i++) + __xa_store(xa, i, xa_mk_index(i), 0); + xas_unlock(&split); + + rcu_read_lock(); + entry = xas_find_marked(&xas, ULONG_MAX, XA_MARK_0); + XA_BUG_ON(xa, entry != NULL); + rcu_read_unlock(); + + xa_destroy(xa); + + /* Pausing resumes at the next marked entry, without repeating. */ + xa_store_order(xa, 0, order, xa_mk_index(0), GFP_KERNEL); + xa_set_mark(xa, 0, XA_MARK_0); + XA_BUG_ON(xa, xa_store_index(xa, next, GFP_KERNEL) != NULL); + xa_set_mark(xa, next, XA_MARK_0); + xas_set(&xas, start); + rcu_read_lock(); + entry = xas_find_marked(&xas, ULONG_MAX, XA_MARK_0); + XA_BUG_ON(xa, entry != xa_mk_index(0)); + XA_BUG_ON(xa, xas.xa_index != start); + xas_pause(&xas); + XA_BUG_ON(xa, xas.xa_index != next); + entry = xas_find_marked(&xas, ULONG_MAX, XA_MARK_0); + XA_BUG_ON(xa, entry != xa_mk_index(next)); + XA_BUG_ON(xa, xas.xa_index != next); + rcu_read_unlock(); + + xa_destroy(xa); + + /* + * A leaf multi-index entry. The next step must not use a canonical + * slot left behind by the first lookup. + */ + if (XA_CHUNK_SHIFT > 2) { + unsigned int leaf_order = 2; + unsigned long leaf_next = 1UL << leaf_order; + unsigned long leaf_start = leaf_next - 1; + + xa_store_order(xa, 0, leaf_order, xa_mk_index(0), GFP_KERNEL); + xa_set_mark(xa, 0, XA_MARK_0); + XA_BUG_ON(xa, xa_store_index(xa, leaf_next, GFP_KERNEL) != NULL); + xa_set_mark(xa, leaf_next, XA_MARK_0); + + xas_set(&xas, leaf_start); + rcu_read_lock(); + entry = xas_find_marked(&xas, ULONG_MAX, XA_MARK_0); + XA_BUG_ON(xa, entry != xa_mk_index(0)); + XA_BUG_ON(xa, xas.xa_index != leaf_start); + rcu_read_unlock(); + + xas_set(&split, 0); + xas_split_alloc(&split, xa_mk_index(0), leaf_order, GFP_KERNEL); + if (xas_error(&split)) { + XA_BUG_ON(xa, true); + goto out; + } + xas_lock(&split); + xas_split(&split, xa_mk_index(0), leaf_order); + for (i = 0; i < leaf_next; i++) + __xa_store(xa, i, xa_mk_index(i), 0); + xas_unlock(&split); + + rcu_read_lock(); + entry = xas_next_marked(&xas, ULONG_MAX, XA_MARK_0); + XA_BUG_ON(xa, entry != xa_mk_index(leaf_next)); + XA_BUG_ON(xa, xas.xa_index != leaf_next); + rcu_read_unlock(); + } + +out: + xa_destroy(xa); + XA_BUG_ON(xa, !xa_empty(xa)); +#endif +} + static noinline void check_find_1(struct xarray *xa) { unsigned long i, j, k; @@ -1472,6 +1636,7 @@ static noinline void check_find(struct x check_multi_find_2(xa); check_multi_find_3(xa); check_multi_find_4(xa); + check_multi_find_marked_nonleaf(xa); } /* See find_swap_entry() in mm/shmem.c */ _ ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/3] xarray: fix index jumping backwards in xas_find_marked() 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 ` 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 2 siblings, 1 reply; 6+ messages in thread From: Andrew Morton @ 2026-12-03 1:26 UTC (permalink / raw) To: Matthew Wilcox; +Cc: linux-mm, Andrew Morton, Qian Xiao, stable From: Qian Xiao <heyheyco@gmail.com> A page-cache scan starting inside a marked large folio can move its index backwards. If that folio is split during the scan, filemap_get_folios_tag() can return newly split folios before the requested range. Background writeback can spend its finite page budget on those folios and leave dirty folios in the requested range for a later pass. This can increase dirty-page throttling for writers. Folios under writeback cannot be split, and this review has not found a case where a data-integrity sync reports success without writing the requested dirty data. xas_find_marked() can move xa_index backwards to the canonical slot of a multi-index entry. After the cursor is walked, xa_offset can also disagree with xa_index. If that entry is split, the next search can return a marked entry below the index already reached. Keep xa_index while resolving a sibling. Align xa_offset before advancing or pausing, and make xas_next_marked() use the slower path when the two disagree. Return XA_RETRY_ENTRY if a changed tree would move the index backwards or descend into the wrong node. Have xa_find_after() handle the retry before its sibling check. Link: https://patch.msgid.link/20261127222110.3755894-1-heyheyco@gmail.com Fixes: b803b42823d0 ("xarray: Add XArray iterators") Signed-off-by: Qian Xiao <heyheyco@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: Matthew Wilcox <willy@infradead.org> Cc: <stable@vger.kernel.org> include/linux/xarray.h | 3 ++- lib/xarray.c | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) --- a/include/linux/xarray.h~xarray-fix-index-jumping-backwards-in-xas_find_marked +++ a/include/linux/xarray.h @@ -1778,7 +1778,8 @@ static inline void *xas_next_marked(stru void *entry; unsigned int offset; - if (unlikely(xas_not_node(node) || node->shift)) + if (unlikely(xas_not_node(node) || node->shift || + xas->xa_offset != (xas->xa_index & XA_CHUNK_MASK))) return xas_find_marked(xas, max, mark); offset = xas_find_chunk(xas, true, mark); xas->xa_offset = offset; --- a/lib/xarray.c~xarray-fix-index-jumping-backwards-in-xas_find_marked +++ a/lib/xarray.c @@ -1288,6 +1288,9 @@ void xas_pause(struct xa_state *xas) if (xas_invalid(xas)) return; + if (node && xas->xa_offset != get_offset(xas->xa_index, node)) + xas->xa_offset = get_offset(xas->xa_index, node); + xas->xa_node = XAS_RESTART; if (node) { unsigned long offset = xas->xa_offset; @@ -1500,6 +1503,14 @@ void *xas_find_marked(struct xa_state *x xas->xa_offset = xas->xa_index >> xas->xa_node->shift; } + if (advance && + xas->xa_offset != get_offset(xas->xa_index, xas->xa_node)) { + if (!xas->xa_node->shift) + xas->xa_offset = ((xas->xa_index - 1) & XA_CHUNK_MASK) + 1; + else + xas->xa_offset = get_offset(xas->xa_index, xas->xa_node); + } + while (xas->xa_index <= max) { if (unlikely(xas->xa_offset == XA_CHUNK_SIZE)) { xas->xa_offset = xas->xa_node->offset + 1; @@ -1512,14 +1523,14 @@ void *xas_find_marked(struct xa_state *x 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 *x 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); } @@ -2263,12 +2276,13 @@ void *xa_find_after(struct xarray *xa, u else entry = xas_find(&xas, max); + if (xas_retry(&xas, entry)) + continue; if (xas_invalid(&xas)) break; if (xas_sibling(&xas)) continue; - if (!xas_retry(&xas, entry)) - break; + break; } rcu_read_unlock(); _ ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] xarray: fix index jumping backwards in xas_find_marked() 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 0 siblings, 0 replies; 6+ messages in thread From: sashiko-bot @ 2026-12-04 1:26 UTC (permalink / raw) To: Andrew Morton, Matthew Wilcox; +Cc: linux-mm, Qian Xiao Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] xarray: missing retry check for in-place split in xas_find_marked() -- commit 0b16d0644fcf9d5b7e4eae2d0ccfab3c8c7a45b3 Author: Qian Xiao <heyheyco@gmail.com> xarray: fix index jumping backwards in xas_find_marked() This commit keeps xa_index unchanged when resolving a sibling slot in xas_find_marked(), realigns xa_offset with xa_index before advancing or pausing, and returns XA_RETRY_ENTRY if a concurrent tree change would move the search backwards or descend into the wrong node. Link: https://patch.msgid.link/20261127222110.3755894-1-heyheyco@gmail.com > 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 xas_find_marked() still return a split entry from a lower slot or skip the entry at xas->xa_index when a marked multi-index entry is split in place? Suppose a marked multi-index entry covers slots 0..3 of a node and a search starts at index 3 with advance set to false: CPU0 CPU1 xas_find_marked() entry = xa_entry(..., 3) (sibling 0) xas->xa_offset = 0 xas_split() / xas_try_split() splits slots 0..3 in place; slot 0 keeps mark and holds E0 offset = xas_find_chunk(..., false, mark) returns 0 (not > xas->xa_offset) entry = xa_entry(..., 0) (E0) if (!xa_is_node(entry)) return E0; <-- returns slot 0 with xa_index == 3, xa_offset == 0 Because offset equals xas->xa_offset, the first XA_RETRY_ENTRY check inside if (offset > xas->xa_offset) is bypassed, and because E0 is not a node, xas_find_marked() returns E0 before reaching the second XA_RETRY_ENTRY check. In xas_for_each_marked(), the caller receives E0 from slot 0 (below the starting index 3), and the next iteration realigns xas->xa_offset to xas->xa_index (3) with advance set to true, advancing to slot 4 and skipping the marked entry at slot 3. In xa_find_after(), xas_sibling() sees xas->xa_offset < get_offset(xas->xa_index, xas->xa_node), treats E0 as a sibling covering index 3, and loops again, also skipping slot 3. Similarly, if slot 0 is concurrently erased after xas_find_chunk() sees the mark, xa_entry() reads NULL and hits continue with advance still false and xas->xa_offset at 0. Follow-up commit "xarray: keep advancing after a concurrent sibling store" sets advance = true on the xa_is_sibling(entry) branch, but does not cover the non-node return or the NULL continue branch when xas->xa_offset != get_offset(xas->xa_index, xas->xa_node). -- Sashiko AI review · https://sashiko.dev/#/patchset/b0bf98a720f546f69ae25ce7a9ebf702.0@linux-foundation.org?part=2 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/3] xarray: keep advancing after a concurrent sibling store 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 2026-12-04 1:26 ` sashiko-bot 2 siblings, 1 reply; 6+ messages in thread From: Andrew Morton @ 2026-12-03 1:26 UTC (permalink / raw) To: Matthew Wilcox; +Cc: linux-mm, Andrew Morton, Qian Xiao 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)) _ ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] xarray: keep advancing after a concurrent sibling store 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 0 siblings, 0 replies; 6+ messages in thread From: sashiko-bot @ 2026-12-04 1:26 UTC (permalink / raw) To: Andrew Morton, Matthew Wilcox; +Cc: linux-mm, Qian Xiao 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-04 1:26 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox