Message ID | 65b6028dea2e9a6e8e2cb779b5115c09457363fc.1617122211.git.andreyknvl@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [mm,v2] mm, kasan: fix for "integrate page_alloc init with HW_TAGS" | expand |
On 3/30/21 6:37 PM, Andrey Konovalov wrote: > My commit "integrate page_alloc init with HW_TAGS" changed the order of > kernel_unpoison_pages() and kernel_init_free_pages() calls. This leads > to complaints from the page unpoisoning code, as the poison pattern gets > overwritten for __GFP_ZERO allocations. > > Fix by restoring the initial order. Also add a warning comment. > > Reported-by: Vlastimil Babka <vbabka@suse.cz> > Reported-by: Sergei Trofimovich <slyfox@gentoo.org> > Signed-off-by: Andrey Konovalov <andreyknvl@google.com> Tested that the bug indeed occurs in -next and is fixed by this. Thanks. > --- > mm/page_alloc.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 033bd92e8398..d2c020563c0b 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -2328,6 +2328,13 @@ inline void post_alloc_hook(struct page *page, unsigned int order, > arch_alloc_page(page, order); > debug_pagealloc_map_pages(page, 1 << order); > > + /* > + * Page unpoisoning must happen before memory initialization. > + * Otherwise, the poison pattern will be overwritten for __GFP_ZERO > + * allocations and the page unpoisoning code will complain. > + */ > + kernel_unpoison_pages(page, 1 << order); > + > /* > * As memory initialization might be integrated into KASAN, > * kasan_alloc_pages and kernel_init_free_pages must be > @@ -2338,7 +2345,6 @@ inline void post_alloc_hook(struct page *page, unsigned int order, > if (init && !kasan_has_integrated_init()) > kernel_init_free_pages(page, 1 << order); > > - kernel_unpoison_pages(page, 1 << order); > set_page_owner(page, order, gfp_flags); > } > >
On Tue, 30 Mar 2021 18:44:09 +0200 Vlastimil Babka <vbabka@suse.cz> wrote: > On 3/30/21 6:37 PM, Andrey Konovalov wrote: > > My commit "integrate page_alloc init with HW_TAGS" changed the order of > > kernel_unpoison_pages() and kernel_init_free_pages() calls. This leads > > to complaints from the page unpoisoning code, as the poison pattern gets > > overwritten for __GFP_ZERO allocations. > > > > Fix by restoring the initial order. Also add a warning comment. > > > > Reported-by: Vlastimil Babka <vbabka@suse.cz> > > Reported-by: Sergei Trofimovich <slyfox@gentoo.org> > > Signed-off-by: Andrey Konovalov <andreyknvl@google.com> > > Tested that the bug indeed occurs in -next and is fixed by this. Thanks. Reviewed-by: Sergei Trofimovich <slyfox@gentoo.org> > > --- > > mm/page_alloc.c | 8 +++++++- > > 1 file changed, 7 insertions(+), 1 deletion(-) > > > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > > index 033bd92e8398..d2c020563c0b 100644 > > --- a/mm/page_alloc.c > > +++ b/mm/page_alloc.c > > @@ -2328,6 +2328,13 @@ inline void post_alloc_hook(struct page *page, unsigned int order, > > arch_alloc_page(page, order); > > debug_pagealloc_map_pages(page, 1 << order); > > > > + /* > > + * Page unpoisoning must happen before memory initialization. > > + * Otherwise, the poison pattern will be overwritten for __GFP_ZERO > > + * allocations and the page unpoisoning code will complain. > > + */ > > + kernel_unpoison_pages(page, 1 << order); > > + > > /* > > * As memory initialization might be integrated into KASAN, > > * kasan_alloc_pages and kernel_init_free_pages must be > > @@ -2338,7 +2345,6 @@ inline void post_alloc_hook(struct page *page, unsigned int order, > > if (init && !kasan_has_integrated_init()) > > kernel_init_free_pages(page, 1 << order); > > > > - kernel_unpoison_pages(page, 1 << order); > > set_page_owner(page, order, gfp_flags); > > } > > > > >
diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 033bd92e8398..d2c020563c0b 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2328,6 +2328,13 @@ inline void post_alloc_hook(struct page *page, unsigned int order, arch_alloc_page(page, order); debug_pagealloc_map_pages(page, 1 << order); + /* + * Page unpoisoning must happen before memory initialization. + * Otherwise, the poison pattern will be overwritten for __GFP_ZERO + * allocations and the page unpoisoning code will complain. + */ + kernel_unpoison_pages(page, 1 << order); + /* * As memory initialization might be integrated into KASAN, * kasan_alloc_pages and kernel_init_free_pages must be @@ -2338,7 +2345,6 @@ inline void post_alloc_hook(struct page *page, unsigned int order, if (init && !kasan_has_integrated_init()) kernel_init_free_pages(page, 1 << order); - kernel_unpoison_pages(page, 1 << order); set_page_owner(page, order, gfp_flags); }
My commit "integrate page_alloc init with HW_TAGS" changed the order of kernel_unpoison_pages() and kernel_init_free_pages() calls. This leads to complaints from the page unpoisoning code, as the poison pattern gets overwritten for __GFP_ZERO allocations. Fix by restoring the initial order. Also add a warning comment. Reported-by: Vlastimil Babka <vbabka@suse.cz> Reported-by: Sergei Trofimovich <slyfox@gentoo.org> Signed-off-by: Andrey Konovalov <andreyknvl@google.com> --- mm/page_alloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)