Re: [PATCH v2] mm/filemap: stop fault-around when the walk steps back
From: Krystian Kaniewski
Date: Fri Nov 06 2026 - 06:44:39 EST
On 11/5/26 23:43, Jose Fernandez (Anthropic) wrote:
> On Thu, 5 Nov 2026 12:19:13 +0000, Pedro Falcato wrote:
>> Thank you. So, if I'm not mistaken, this is the race:
>> First, you map/see this:
>> [folio pgoff 4, length 4]
>> Then, at some point in time, someone punches the hole:
>> [no folios here]
>> Then, at some point in time, someone faults another folio in the range:
>> [folio pgoff 0, length 8]
>> so you step backwards. Is this correct? Or am I misunderstanding this?
>
> Not quite. In my test a large folio goes away and a small one comes back
> below where the walk started. If that happens during the walk's first
> lookup, the walk can step back. Krystian's fix doesn't cover that
> lookup.
>
Right. My patch only covers the case where the walk has already
returned an entry. The first lookup, and every lookup after xas_retry(),
starts in the XAS_RESTART branch. My patch does not change that branch.
There, xas_load() can read the sibling slot of the start index before
a concurrent erase, and the canonical slot after it. In that case it
returns NULL, but xa_offset still points to the canonical slot.
xas_find() then moves on to the slot after the canonical slot. That
slot can be below the start index.
I tested this in the userspace XArray harness. I wrote that state into
a node and called xas_find() from XAS_RESTART. It returned an index
below the start, with and without my patch.
Andrew, Jose's Tested-by for the xarray patch is on the filemap patch
in mm-hotfixes-unstable.
--
Krystian Kaniewski