From: Andrew Morton <akpm@linux-foundation.org>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Nickolai Zeldovich <nickolai@csail.mit.edu>,
syzbot+73641b60a3bc11dfca8c@syzkaller.appspotmail.com,
Baoli Zhang <baoli.zhang@intel.com>,
stable@vger.kernel.org
Subject: [PATCH v2 2/2] xarray: initialise the offset of a new root node
Date: Sat, 21 Nov 2026 14:18:32 -0800 [thread overview]
Message-ID: <08ceefcb212e4dda9767389fe7f162a8.2@linux-foundation.org> (raw)
In-Reply-To: <08ceefcb212e4dda9767389fe7f162a8.0@linux-foundation.org>
From: Nickolai Zeldovich <nickolai@csail.mit.edu>
xas_alloc() sets node->offset only when the new node has a parent. A root
node can retain a nonzero offset from its previous use in the slab. While
xas_expand() links that root below a new one, an RCU walker can read the
stale offset and then the new parent pointer. It can resume at the wrong
slot and report an entry at the wrong index or skip entries.
Initialize the offset to zero when allocating a root. The old root
already has that offset when xas_expand() links it beneath the new root,
so remove the store to its offset during expansion.
Link: https://patch.msgid.link/20261024014344.830116-1-nickolai@csail.mit.edu
Fixes: 58d6ea3085f2 ("xarray: Add XArray unconditional store operations")
Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reported-by: <syzbot+73641b60a3bc11dfca8c@syzkaller.appspotmail.com>
Closes: https://syzkaller.appspot.com/bug?extid=73641b60a3bc11dfca8c
Tested-by: Baoli Zhang <baoli.zhang@intel.com>
Tested-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: <stable@vger.kernel.org>
---
akpm: Tested the two-patch series on x86-64, with the new test present on
both kernels. Without the fix, 64 runs of the test each failed both
root-offset checks. With the fix, neither check failed and all XArray
checks passed. Both kernels used the same configuration and test setup.
This tests the stale root offset; it does not separately reproduce the
concurrent RCU-walker failure.
lib/xarray.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
--- a/lib/xarray.c~xarray-initialise-the-offset-of-a-new-root-node
+++ a/lib/xarray.c
@@ -387,6 +387,8 @@ static void *xas_alloc(struct xa_state *
parent->count++;
XA_NODE_BUG_ON(node, parent->count > XA_CHUNK_SIZE);
xas_update(xas, parent);
+ } else {
+ node->offset = 0;
}
XA_NODE_BUG_ON(node, shift > BITS_PER_LONG);
XA_NODE_BUG_ON(node, !list_empty(&node->private_list));
@@ -617,10 +619,8 @@ static int xas_expand(struct xa_state *x
* Now that the new node is fully initialised, we can add
* it to the tree
*/
- if (xa_is_node(head)) {
- xa_to_node(head)->offset = 0;
+ if (xa_is_node(head))
rcu_assign_pointer(xa_to_node(head)->parent, node);
- }
head = xa_mk_node(node);
rcu_assign_pointer(xa->xa_head, head);
xas_update(xas, node);
_
prev parent reply other threads:[~2026-11-21 22:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 22:18 [PATCH v2 0/2] " Andrew Morton
2026-11-21 22:18 ` [PATCH v2 1/2] lib/test_xarray: check the offset of new root nodes Andrew Morton
2026-11-21 22:18 ` 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=08ceefcb212e4dda9767389fe7f162a8.2@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=baoli.zhang@intel.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nickolai@csail.mit.edu \
--cc=stable@vger.kernel.org \
--cc=syzbot+73641b60a3bc11dfca8c@syzkaller.appspotmail.com \
--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
all inboxes | Powered by JetHome®