From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19E97C433E1 for ; Tue, 30 Mar 2021 16:45:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C335961883 for ; Tue, 30 Mar 2021 16:45:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232134AbhC3Qom (ORCPT ); Tue, 30 Mar 2021 12:44:42 -0400 Received: from mx2.suse.de ([195.135.220.15]:46308 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231532AbhC3Qo2 (ORCPT ); Tue, 30 Mar 2021 12:44:28 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 207D0B02D; Tue, 30 Mar 2021 16:44:10 +0000 (UTC) Subject: Re: [PATCH mm v2] mm, kasan: fix for "integrate page_alloc init with HW_TAGS" To: Andrey Konovalov , Andrew Morton Cc: Sergei Trofimovich , Alexander Potapenko , Marco Elver , Dmitry Vyukov , Andrey Ryabinin , Andrey Konovalov , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <65b6028dea2e9a6e8e2cb779b5115c09457363fc.1617122211.git.andreyknvl@google.com> From: Vlastimil Babka Message-ID: <404ad944-ab46-cffb-5fbb-3dd7ae25caaa@suse.cz> Date: Tue, 30 Mar 2021 18:44:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <65b6028dea2e9a6e8e2cb779b5115c09457363fc.1617122211.git.andreyknvl@google.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > Reported-by: Sergei Trofimovich > Signed-off-by: Andrey Konovalov 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); > } > >