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 9C0DCC433DB for ; Tue, 30 Mar 2021 15:54:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 03428619C1 for ; Tue, 30 Mar 2021 15:54:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 03428619C1 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 412D46B0080; Tue, 30 Mar 2021 11:54:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E9786B0081; Tue, 30 Mar 2021 11:54:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D8E96B0082; Tue, 30 Mar 2021 11:54:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0107.hostedemail.com [216.40.44.107]) by kanga.kvack.org (Postfix) with ESMTP id 149BF6B0080 for ; Tue, 30 Mar 2021 11:54:50 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id CB2958123 for ; Tue, 30 Mar 2021 15:54:49 +0000 (UTC) X-FDA: 77976988698.22.C58100A Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf01.hostedemail.com (Postfix) with ESMTP id 68DAE500152E for ; Tue, 30 Mar 2021 15:54:41 +0000 (UTC) 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 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 68DAE500152E X-Stat-Signature: 6ymrtgsjxtthmm1gkhe78fbuhegf8b9r Received-SPF: none (suse.cz>: No applicable sender policy available) receiver=imf01; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: none/none X-HE-Tag: 1617119681-292286 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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); > } > >