Re: [PATCH v2 2/5] mm/page_alloc: validate zonelist slots against concurrent rebuilds
From: Gregory Price (Meta)
Date: Tue Oct 20 2026 - 18:24:35 EST
On 2026-10-20 17:22 +0200, Vlastimil Babka (SUSE) wrote:
> On 10/19/26 19:23, Gregory Price (Meta) wrote:
> > Onlining the first block of a zone rebuilds every zonelist in place,
> > shifting the slots after the new zone. An in-flight walk can use a
> > zone it previously filtered. e.g.:
> > - a GFP_KERNEL request can land in ZONE_MOVABLE,
> > - a node not in the nodemask can have its zones selected.
> >
> > With kprobes holding the walk across the online, I was able to get this
> > zone/node misplacement to happen consistently across hotplug events.
> >
> > The iterator approves a slot by its zone index and node, and the
> > allocator then loads the zone pointer from the slot again:
> >
> > CPU 0 CPU 1
> > first_zones_zonelist(nodemask {1})
> > slot 0 (NORMAL1) approved
> > online_pages()
> > build_all_zonelists()
> > [NORMAL1, NORMAL2, ...]
> > -> [MOVABLE1, NORMAL1, ...]
> > get_page_from_freelist()
> > zone = zonelist_zone(slot 0) /* MOVABLE1 */
>
> Since the zonelist_zone_valid() checks you're adding happen before the
> "zone = zonelist_zone(slot 0)" part, I don't understand how they can be
> helping here. Aren't we just reapproving slot 0 when CPU 1 can mess it up
> between that reapproval and load? Am I missing something?
>
> Furthermore, since we have the zonelist_update_seq anyway, wouldn't it be
> better to use it to avoid these kinds of races rather than the more tricky
> way of relying on what exact updates in what order can derail the allocator
> side and trying to protect against those specifically?
>
This does end up cleaner. I'm going to reorder the series a bit and use
the zonelist seq count to make it a bit cleaner.
I also just noticed that the same issue is present in hugetlb (because
of course it is) so i'll probably append it there.
~Gregory
--
Gregory Price (Meta) <gourry@xxxxxxxxxx>