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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 0D4F7C433DB for ; Sat, 6 Mar 2021 01:27:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 675D364FE9 for ; Sat, 6 Mar 2021 01:27:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 675D364FE9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E823B6B0006; Fri, 5 Mar 2021 20:27:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E325C6B006C; Fri, 5 Mar 2021 20:27:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CBE3B6B006E; Fri, 5 Mar 2021 20:27:10 -0500 (EST) 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 ADCB86B0006 for ; Fri, 5 Mar 2021 20:27:10 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 678DD180388CE for ; Sat, 6 Mar 2021 01:27:10 +0000 (UTC) X-FDA: 77887711020.26.48421BD Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf01.hostedemail.com (Postfix) with ESMTP id 0D8CB200038B for ; Sat, 6 Mar 2021 01:27:09 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 4A5B865093; Sat, 6 Mar 2021 01:27:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1614994028; bh=NngIxxx12YXwN0ocivs/pfNKIcJ7UM43YAnjKQEOJfM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=fHQ7TGXNn8U+TXweUnRRhRCStjkAEL6+HZ/4g1Gp93VqrG87B849cvT2whLYOv9Jt qXUOhCwlIVGsKO8c0Ad3RRaUeEUca137dEcxq0cB25IhxtKMpRn9xEvdU5oXT+dZm/ F6QDuJmRve5IcsJIVFk/2iaHg3lHN1A2K5suOgz4= Date: Fri, 5 Mar 2021 17:27:07 -0800 From: Andrew Morton To: Andrey Konovalov Cc: Alexander Potapenko , Catalin Marinas , Will Deacon , Vincenzo Frascino , Dmitry Vyukov , Andrey Ryabinin , Marco Elver , Peter Collingbourne , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , kasan-dev , Linux ARM , Linux Memory Management List , LKML , stable Subject: Re: [PATCH v2] kasan, mm: fix crash with HW_TAGS and DEBUG_PAGEALLOC Message-Id: <20210305172707.0d16383226ce5bfa87939702@linux-foundation.org> In-Reply-To: References: <24cd7db274090f0e5bc3adcdc7399243668e3171.1614987311.git.andreyknvl@google.com> <20210305154956.3bbfcedab3f549b708d5e2fa@linux-foundation.org> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0D8CB200038B X-Stat-Signature: xtda6kkf6boqy397gnjxtrixhouniay6 Received-SPF: none (linux-foundation.org>: No applicable sender policy available) receiver=imf01; identity=mailfrom; envelope-from=""; helo=mail.kernel.org; client-ip=198.145.29.99 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614994029-9425 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 Sat, 6 Mar 2021 00:54:32 +0100 Andrey Konovalov wrote: > On Sat, Mar 6, 2021 at 12:50 AM Andrew Morton wrote: > > > > On Sat, 6 Mar 2021 00:36:33 +0100 Andrey Konovalov wrote: > > > > > Currently, kasan_free_nondeferred_pages()->kasan_free_pages() is called > > > after debug_pagealloc_unmap_pages(). This causes a crash when > > > debug_pagealloc is enabled, as HW_TAGS KASAN can't set tags on an > > > unmapped page. > > > > > > This patch puts kasan_free_nondeferred_pages() before > > > debug_pagealloc_unmap_pages() and arch_free_page(), which can also make > > > the page unavailable. > > > > > > ... > > > > > > --- a/mm/page_alloc.c > > > +++ b/mm/page_alloc.c > > > @@ -1304,6 +1304,12 @@ static __always_inline bool free_pages_prepare(struct page *page, > > > > > > kernel_poison_pages(page, 1 << order); > > > > > > + /* > > > + * With hardware tag-based KASAN, memory tags must be set before the > > > + * page becomes unavailable via debug_pagealloc or arch_free_page. > > > + */ > > > + kasan_free_nondeferred_pages(page, order, fpi_flags); > > > + > > > /* > > > * arch_free_page() can make the page's contents inaccessible. s390 > > > * does this. So nothing which can access the page's contents should > > > @@ -1313,8 +1319,6 @@ static __always_inline bool free_pages_prepare(struct page *page, > > > > > > debug_pagealloc_unmap_pages(page, 1 << order); > > > > > > - kasan_free_nondeferred_pages(page, order, fpi_flags); > > > - > > > return true; > > > } > > > > kasan_free_nondeferred_pages() has only two args in current mainline. > > Ah, yes, forgot to mention: this goes on top of: > > kasan: initialize shadow to TAG_INVALID for SW_TAGS > mm, kasan: don't poison boot memory with tag-based modes This patch (kasan, mm: fix crash with HW_TAGS and DEBUG_PAGEALLOC) is cc:stable, so it should come head of the other two lower priority patches. > > > > I fixed that in the obvious manner... > > Thanks! > > If you changed this patch, you'll also need to change the other one though. Yup.