Re: [PATCH v2] mm, dump_page: do not crash with bad compound_mapcount()

From: Kirill A. Shutemov
Date: Fri Aug 07 2020 - 12:48:11 EST


On Fri, Aug 07, 2020 at 04:10:29PM +0100, Matthew Wilcox wrote:
> On Fri, Aug 07, 2020 at 05:35:04PM +0300, Kirill A. Shutemov wrote:
> > On Tue, Aug 04, 2020 at 02:48:07PM -0700, John Hubbard wrote:
> > > If a compound page is being split while dump_page() is being run on that
> > > page, we can end up calling compound_mapcount() on a page that is no
> > > longer compound. This leads to a crash (already seen at least once in
> > > the field), due to the VM_BUG_ON_PAGE() assertion inside
> > > compound_mapcount().
>
> [...]
> > > +static inline int head_mapcount(struct page *head)
> > > +{
> >
> > Do we want VM_BUG_ON_PAGE(!PageHead(head), head) here?
>
> Well, no. That was the point of the bug report -- by the time we called
> compound_mapcount, the page was no longer a head page.

Right. VM_BUG_ON_PAGE(PageTail(head), head)?

> > > A similar problem is possible, via compound_pincount() instead of
> > > compound_mapcount().
> > >
> > > In order to avoid this kind of crash, make dump_page() slightly more
> > > robust, by providing a pair of simpler routines that don't contain
> > > assertions: head_mapcount() and head_pincount().
> >
> > I find naming misleading. head_mapcount() and head_pincount() sounds like
> > a mapcount/pincount of the head page, but it's not. It's mapcount and
> > pincount of the compound page.
>
> OK, point taken. I might go for head_compound_mapcount()? Or as I
> originally suggested, just opencoding it like we do in __page_mapcount().

I'm fine either way.

--
Kirill A. Shutemov