Re: [PATCH] mm: Handle compound pages better in __dump_page()

From: Kees Cook
Date: Sun Nov 17 2024 - 23:47:11 EST


On Mon, Nov 18, 2024 at 04:10:52AM +0000, Matthew Wilcox wrote:
> folio_test_large() does not touch page[1]. Look:

It does, though. :( It's via the PageTail(), which calls page_is_fake_head():

In function 'page_fixed_fake_head',
inlined from 'page_is_fake_head' at ../include/linux/page-flags.h:237:9,
inlined from 'PageTail' at ../include/linux/page-flags.h:281:47,
inlined from 'const_folio_flags' at ../include/linux/page-flags.h:309:2,
inlined from 'folio_test_head' at ../include/linux/page-flags.h:824:9,
inlined from 'folio_test_large' at ../include/linux/page-flags.h:845:9,
inlined from '__dump_page' at ../mm/debug.c:138:8:
../include/asm-generic/rwonce.h:44:26: error: array subscript 9 is outside array bounds of 'struct p
age[1]' [-Werror=array-bounds=]
44 | #define __READ_ONCE(x) (*(const volatile __unqual_scalar_typeof(x) *)&(x))
| ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/asm-generic/rwonce.h:50:9: note: in expansion of macro '__READ_ONCE'
50 | __READ_ONCE(x); \
| ^~~~~~~~~~~
../include/linux/page-flags.h:221:38: note: in expansion of macro 'READ_ONCE'
221 | unsigned long head = READ_ONCE(page[1].compound_head);
| ^~~~~~~~~
../mm/debug.c: In function '__dump_page':
../mm/debug.c:126:21: note: at offset 72 into object 'precise' of size 64
126 | struct page precise;
| ^~~~~~~

> > Instead, explicitly make precise 2 pages. Just open-coding page_folio()
> > isn't sufficient to avoid the warning[1].
>
> Why not? What goes wrong? I'm trying to get gcc-15 installed here now

With your original patch applied, I get the above warning.

--
Kees Cook