Re: [PATCH v2] xarray: initialise the offset of a new root node
From: Andrew Morton
Date: Sat Nov 21 2026 - 17:17:51 EST
On Fri, 23 Oct 2026 21:43:44 -0400 Nickolai Zeldovich <nickolai@xxxxxxxxxxxxx> wrote:
> An RCU walker such as xas_find() that climbs out of the root while
> xas_expand() adds a level above it can resume in the new root at the
> wrong slot and return an entry with the wrong index.
>
> xas_alloc() sets node->offset only for a node with a parent, so a new
> root keeps the offset its slab object had before. xas_expand() stores
> 0 to the old root's offset just before linking it below the new root,
> and a walker can load the stale offset before that store and the new
> parent pointer after it.
>
> Set the offset of a node allocated without a parent to 0. The store in
> xas_expand() then writes the value the old root already has, so remove
> it.
Thanks.
I turned this into a 2-patch series. The first adds the test to
test_xarray and the second fixes the lib/xarray.c issue.
Which is arguably the wrong order - I have just created history's least
important bisection hole. But it's convenient for before-and-after
testing. I did that before-and-after testing and it all checks out.
I'll send this 2-patch series out for review.