Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp8152656pxb; Fri, 19 Feb 2021 08:37:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxTsZt7PqQqNW9eDZLJwKvNqTR79iP8kvrZCaKjKh8mYwZLLPzMkUPB0Qd7R5ve5bZbJL3u X-Received: by 2002:a05:6402:35ca:: with SMTP id z10mr10266771edc.174.1613752655723; Fri, 19 Feb 2021 08:37:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613752655; cv=none; d=google.com; s=arc-20160816; b=GPOPbKTb+AaLbwtiQsUG6sdRDspyeWT3hvFlbXBbORdjIABrTHG7TI3+c2EobJ4vAu 6/htUQ5BiZGIOm4npyGL5Rtxn+714eoRl96RzQZgUKJJ0gCmQxzd0aHmDNwMu35nMDPt hliA6c8lJNH0fDWU3LTc15f/ctn4w50JMMH99o0BtTUhPmTHNijUlfgl71nVvrdVUQLF ic1jJvHKdfTKb1bcSODJbD/YLoEJdpBB/gM/C10ZilYyZk+pJHhQWQ6eqJMXpyxIdXr3 oNfAxMMO8B3dCbouW9+HZf2zSOozRV5ZdtmC+tto3GLmxQldHnZvb7JCT2npLwLcBCsT IIrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=Y8WUeVCSfZ0MLyF0l+HhKZtFOCIfftBPcvPseN2dtyc=; b=TAI22oqOTX6myCnmjLcsdQuPA3OjXotmjBcm9wsu/dIIeRlAYnU+Dl/E/2lPKEriM9 DJDm/Yihg6h3uc7crcRIJ9n6zukS9YW91fUSZAYJNPS+FlBU1rOa6oIHboiSpqameCPU KVp0WI2wwdvYoqzqCfQ5k4t2LtWAd6OplSLs3q3JNnofDu89kkFW3KFwBsT4D38xAOWi /lZNTWkDULfSryFjk/QrS9POqN3lRtIpynMmkhLecKQ0e4F+lpM4AmiBMC/rcZMC9n8D Dqf12lczEHZ5/PSe7tNVu9HsZaAbk4LnLa6Op4DHq97kRAZx6jJNzUkX69NOCMaqeRHl U3Iw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jz9si5924303ejb.510.2021.02.19.08.37.06; Fri, 19 Feb 2021 08:37:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229952AbhBSQgL (ORCPT + 99 others); Fri, 19 Feb 2021 11:36:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:54600 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229868AbhBSQgJ (ORCPT ); Fri, 19 Feb 2021 11:36:09 -0500 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) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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