Skip to content

Commit 7f0947e

Browse files
author
Rafael Aquini
committed
mm: open-code PageTail in folio_flags() and const_folio_flags()
JIRA: https://issues.redhat.com/browse/RHEL-84184 This patch is a backport of the following upstream commit: commit 4de22b2 Author: Matthew Wilcox (Oracle) <[email protected]> Date: Mon Nov 25 20:17:18 2024 +0000 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]> Signed-off-by: Rafael Aquini <[email protected]>
1 parent d7c46ee commit 7f0947e

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
@@ -310,7 +310,7 @@ static const unsigned long *const_folio_flags(const struct folio *folio,
310310
{
311311
const struct page *page = &folio->page;
312312

313-
VM_BUG_ON_PGFLAGS(PageTail(page), page);
313+
VM_BUG_ON_PGFLAGS(page->compound_head & 1, page);
314314
VM_BUG_ON_PGFLAGS(n > 0 && !test_bit(PG_head, &page->flags), page);
315315
return &page[n].flags;
316316
}
@@ -319,7 +319,7 @@ static unsigned long *folio_flags(struct folio *folio, unsigned n)
319319
{
320320
struct page *page = &folio->page;
321321

322-
VM_BUG_ON_PGFLAGS(PageTail(page), page);
322+
VM_BUG_ON_PGFLAGS(page->compound_head & 1, page);
323323
VM_BUG_ON_PGFLAGS(n > 0 && !test_bit(PG_head, &page->flags), page);
324324
return &page[n].flags;
325325
}

0 commit comments

Comments
 (0)