Skip to content

Commit 4de22b2

Browse files
Matthew Wilcox (Oracle)akpm00
authored andcommitted
mm: open-code PageTail in folio_flags() and const_folio_flags()
It is unsafe to call PageTail() in dump_page() as page_is_fake_head() will almost certainly return true when called on a head page that is copied to the stack. That will cause the VM_BUG_ON_PGFLAGS() in const_folio_flags() to trigger when it shouldn't. Fortunately, we don't need to call PageTail() here; it's fine to have a pointer to a virtual alias of the page's flag word rather than the real page's flag word. Link: https://lkml.kernel.org/r/[email protected] Fixes: fae7d83 ("mm: add __dump_folio()") Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Cc: Kees Cook <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent d699440 commit 4de22b2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

include/linux/page-flags.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ static const unsigned long *const_folio_flags(const struct folio *folio,
306306
{
307307
const struct page *page = &folio->page;
308308

309-
VM_BUG_ON_PGFLAGS(PageTail(page), page);
309+
VM_BUG_ON_PGFLAGS(page->compound_head & 1, page);
310310
VM_BUG_ON_PGFLAGS(n > 0 && !test_bit(PG_head, &page->flags), page);
311311
return &page[n].flags;
312312
}
@@ -315,7 +315,7 @@ static unsigned long *folio_flags(struct folio *folio, unsigned n)
315315
{
316316
struct page *page = &folio->page;
317317

318-
VM_BUG_ON_PGFLAGS(PageTail(page), page);
318+
VM_BUG_ON_PGFLAGS(page->compound_head & 1, page);
319319
VM_BUG_ON_PGFLAGS(n > 0 && !test_bit(PG_head, &page->flags), page);
320320
return &page[n].flags;
321321
}

0 commit comments

Comments
 (0)