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.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,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 E8DEDC433DB for ; Fri, 19 Feb 2021 16:35:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6C6BA64E15 for ; Fri, 19 Feb 2021 16:35:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6C6BA64E15 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C2EF86B006C; Fri, 19 Feb 2021 11:35:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BB9CC6B006E; Fri, 19 Feb 2021 11:35:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7FD86B0070; Fri, 19 Feb 2021 11:35:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0140.hostedemail.com [216.40.44.140]) by kanga.kvack.org (Postfix) with ESMTP id 886FD6B006C for ; Fri, 19 Feb 2021 11:35:29 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 3942C18382493 for ; Fri, 19 Feb 2021 16:35:29 +0000 (UTC) X-FDA: 77835567978.21.DD97C27 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf23.hostedemail.com (Postfix) with ESMTP id 54E70A000251 for ; Fri, 19 Feb 2021 16:35:28 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 4DE4564DF0; Fri, 19 Feb 2021 16:35:24 +0000 (UTC) Date: Fri, 19 Feb 2021 16:35:21 +0000 From: Catalin Marinas To: Andrey Konovalov Cc: Andrew Morton , Vincenzo Frascino , Will Deacon , Dmitry Vyukov , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Peter Collingbourne , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , Christoph Hellwig , kasan-dev , Linux ARM , Linux Memory Management List , LKML , David Hildenbrand , George Kennedy , Konrad Rzeszutek Wilk Subject: Re: [PATCH RESEND] mm, kasan: don't poison boot memory Message-ID: <20210219163520.GA18049@arm.com> References: <8d79640cdab4608c454310881b6c771e856dbd2e.1613595522.git.andreyknvl@google.com> <20210218104626.GA12761@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Stat-Signature: 93yhcj47fgyf31bxtzg8gedx6wq6t1wy X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 54E70A000251 Received-SPF: none (kernel.org>: No applicable sender policy available) receiver=imf23; identity=mailfrom; envelope-from=""; helo=mail.kernel.org; client-ip=198.145.29.99 X-HE-DKIM-Result: none/none X-HE-Tag: 1613752528-953553 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 Thu, Feb 18, 2021 at 09:24:49PM +0100, Andrey Konovalov wrote: > On Thu, Feb 18, 2021 at 11:46 AM Catalin Marinas > wrote: > > > > The approach looks fine to me. If you don't like the trade-off, I think > > you could still leave the kasan poisoning in if CONFIG_DEBUG_KERNEL. > > This won't work, Android enables CONFIG_DEBUG_KERNEL in GKI as it > turns out :) And does this option go into production kernels? > > For MTE, we could look at optimising the poisoning code for page size to > > use STGM or DC GZVA but I don't think we can make it unnoticeable for > > large systems (especially with DC GZVA, that's like zeroing the whole > > RAM at boot). > > https://bugzilla.kernel.org/show_bug.cgi?id=211817 A quick hack here if you can give it a try. It can be made more optimal, maybe calling the set_mem_tag_page directly from kasan: diff --git a/arch/arm64/include/asm/mte-kasan.h b/arch/arm64/include/asm/mte-kasan.h index 7ab500e2ad17..b9b9ca1976eb 100644 --- a/arch/arm64/include/asm/mte-kasan.h +++ b/arch/arm64/include/asm/mte-kasan.h @@ -48,6 +48,20 @@ static inline u8 mte_get_random_tag(void) return mte_get_ptr_tag(addr); } +static inline void __mte_set_mem_tag_page(u64 curr, u64 end) +{ + u64 bs = 4 << (read_cpuid(DCZID_EL0) & 0xf); + + do { + asm volatile(__MTE_PREAMBLE "dc gva, %0" + : + : "r" (curr) + : "memory"); + + curr += bs; + } while (curr != end); +} + /* * Assign allocation tags for a region of memory based on the pointer tag. * Note: The address must be non-NULL and MTE_GRANULE_SIZE aligned and @@ -63,6 +77,11 @@ static inline void mte_set_mem_tag_range(void *addr, size_t size, u8 tag) curr = (u64)__tag_set(addr, tag); end = curr + size; + if (IS_ALIGNED((unsigned long)addr, PAGE_SIZE) && size == PAGE_SIZE) { + __mte_set_mem_tag_page(curr, end); + return; + } + do { /* * 'asm volatile' is required to prevent the compiler to move