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 E7147C433DB for ; Tue, 30 Mar 2021 15:55:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 930F7619C7 for ; Tue, 30 Mar 2021 15:55:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232240AbhC3PzF (ORCPT ); Tue, 30 Mar 2021 11:55:05 -0400 Received: from mx2.suse.de ([195.135.220.15]:45704 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232201AbhC3Pyf (ORCPT ); Tue, 30 Mar 2021 11:54:35 -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 44DADAF10; Tue, 30 Mar 2021 15:54:34 +0000 (UTC) Subject: Re: [PATCH mm] 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: <2e5e80481533e73876d5d187d1f278f9656df73a.1617118134.git.andreyknvl@google.com> From: Vlastimil Babka Message-ID: <115c3cd4-a5ec-ea4c-fdc8-a17a0990bd30@suse.cz> Date: Tue, 30 Mar 2021 17:54:33 +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: <2e5e80481533e73876d5d187d1f278f9656df73a.1617118134.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 5:31 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 __GFP_ZERO allocations being incorrectly poisoned when page poisoning > is enabled. Correction: This leads to check_poison_mem() complain about memory corruption because the poison pattern has already been overwritten by zeroes. > Fix by restoring the initial order. Also add a warning comment. > > Reported-by: Vlastimil Babka > Reported-by: Sergei Trofimovich > Signed-off-by: Andrey Konovalov I expect this will be folded to your patch in mmotm anyway, so the changelog is not as important... > --- > mm/page_alloc.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 033bd92e8398..1fc5061f8ca1 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -2328,6 +2328,12 @@ 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, a __GFP_ZERO allocation will not be initialized. ... but the comment should be corrected too: "Otherwise, a __GFP_ZERO allocation will trigger a memory corruption report during unpoisoning." Thanks. > + */ > + 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 +2344,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); > } > >