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.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,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 8DACDC433E0 for ; Fri, 19 Feb 2021 16:37:32 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4E76964DED for ; Fri, 19 Feb 2021 16:37:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4E76964DED Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=u6mkOczTBRiUPiNVr0tL2nSaMidJnP05Ql8CuHJbPKQ=; b=yEVvY4VmulCjo/8cp/1/EeYfl pQts/O60N6TiISKbSMASn4N0+mIakvh7lKAH8Tyo5qNhknHEDSNfVYm6ef5TgAdcOijf0B+oEJEcM UDFBj+X24r3vg4dazJywFn6qnXWaDqbIHMmvFwE0hA7CJB/tSh7oBmASnRgBc67VC8dtv6ym0Fckm tqrtpO5P+eDtbaZzsefxgKB6yypcfQRwF6fDuIfl4f7RZ1sxXiUpcTRXsEKqQu8jASIzn9hycoI8r 6DR2wLpZIsg4Dq4P9m7j9tvUWv2heFhs5rIzbTC6gRrhr+gH3puHDQmrdMxowQZFsPaTFyPBJkF5l NRVOkBsbA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lD8ke-0005hT-PL; Fri, 19 Feb 2021 16:35:32 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lD8kb-0005g9-O1 for linux-arm-kernel@lists.infradead.org; Fri, 19 Feb 2021 16:35:30 +0000 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 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-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210219_113529_869894_0DDB52DD X-CRM114-Status: GOOD ( 18.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linux ARM , Marco Elver , George Kennedy , David Hildenbrand , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev , LKML , Christoph Hellwig , Linux Memory Management List , Alexander Potapenko , Evgenii Stepanov , Konrad Rzeszutek Wilk , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Peter Collingbourne , Dmitry Vyukov Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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