Re: [PATCH v2 12/19] maple_tree: Catch race in mas_alloc_cyclic()

From: Chuck Lever

Date: Tue Jun 30 2026 - 15:42:06 EST



On Tue, Jun 30, 2026, at 3:08 PM, Liam R. Howlett (Oracle) wrote:
> If mas_alloc_cyclic() is called during a low memory situation, it is
> possible the lock may be dropped so reclaim can occur. There is a
> window where some other task may allocate the same id and cause the
> mas_insert() to fail with -EEXIST. In this scenario the function will
> return -EEXIST, which is not expected.
>
> Modifying the retry on mas_nomem() to re-search for a slot means that
> any race with other writes will not matter as the lock will be held
> between finding the index and writing the index.
>
> Moving the flag logic avoids cases where the flag is modified on drop
> lock/reacquire or when the write fails after clearing the flag.
>
> No existing users are exposed to this issue.
>
> Fixes: 9b6713cc75229 ("maple_tree: Add mtree_alloc_cyclic()")
> Reported-by: Chris Mason <clm@xxxxxxxx>
> Cc: Chuck Lever <cel@xxxxxxxxxx>
> Signed-off-by: Liam R. Howlett (Oracle) <liam@xxxxxxxxxxxxx>

Reviewed-by: Chuck Lever <cel@xxxxxxxxxx>

--
Chuck Lever