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=-8.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,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 7B0E3C3F2D1 for ; Thu, 5 Mar 2020 16:21:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 43A2B2166E for ; Thu, 5 Mar 2020 16:21:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 43A2B2166E Authentication-Results: mail.kernel.org; dmarc=none (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 CC8ED6B0006; Thu, 5 Mar 2020 11:21:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C79CC6B0007; Thu, 5 Mar 2020 11:21:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8F0B6B0008; Thu, 5 Mar 2020 11:21:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0075.hostedemail.com [216.40.44.75]) by kanga.kvack.org (Postfix) with ESMTP id 9F6846B0006 for ; Thu, 5 Mar 2020 11:21:40 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id EBAB6499610 for ; Thu, 5 Mar 2020 16:21:39 +0000 (UTC) X-FDA: 76561824318.22.twig39_2b854d08a1924 X-HE-Tag: twig39_2b854d08a1924 X-Filterd-Recvd-Size: 4626 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Thu, 5 Mar 2020 16:21:38 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2002530E; Thu, 5 Mar 2020 08:21:37 -0800 (PST) Received: from [10.1.195.32] (e112269-lin.cambridge.arm.com [10.1.195.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C34233F534; Thu, 5 Mar 2020 08:21:35 -0800 (PST) Subject: Re: [PATCH v2 04/19] arm64: mte: Use Normal Tagged attributes for the linear map To: Catalin Marinas , linux-arm-kernel@lists.infradead.org Cc: linux-arch@vger.kernel.org, Richard Earnshaw , Szabolcs Nagy , Andrey Konovalov , Kevin Brodsky , Peter Collingbourne , linux-mm@kvack.org, Vincenzo Frascino , Will Deacon References: <20200226180526.3272848-1-catalin.marinas@arm.com> <20200226180526.3272848-5-catalin.marinas@arm.com> From: Steven Price Message-ID: <946fcd05-ba8f-90ec-d30b-458b327df59c@arm.com> Date: Thu, 5 Mar 2020 16:21:34 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200226180526.3272848-5-catalin.marinas@arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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 26/02/2020 18:05, Catalin Marinas wrote: > Once user space is given access to tagged memory, the kernel must be > able to clear/save/restore tags visible to the user. This is done via > the linear mapping, therefore map it as such. The new MT_NORMAL_TAGGED > index for MAIR_EL1 is initially mapped as Normal memory and later > changed to Normal Tagged via the cpufeature infrastructure. From a > mismatched attribute aliases perspective, the Tagged memory is > considered a permission and it won't lead to undefined behaviour. > > The empty_zero_page is cleared to ensure that the tags it contains are > already zeroed. The actual tags-aware clear_page() implementation is > part of a subsequent patch. > > Signed-off-by: Catalin Marinas > --- > arch/arm64/include/asm/memory.h | 1 + > arch/arm64/include/asm/pgtable-prot.h | 2 ++ > arch/arm64/kernel/cpufeature.c | 30 +++++++++++++++++++++++++++ > arch/arm64/mm/dump.c | 4 ++++ > arch/arm64/mm/mmu.c | 22 ++++++++++++++++++-- > arch/arm64/mm/proc.S | 8 +++++-- > 6 files changed, 63 insertions(+), 4 deletions(-) > [...] > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > index 128f70852bf3..a2c206444e47 100644 > --- a/arch/arm64/mm/mmu.c > +++ b/arch/arm64/mm/mmu.c > @@ -120,7 +120,7 @@ static bool pgattr_change_is_safe(u64 old, u64 new) > * The following mapping attributes may be updated in live > * kernel mappings without the need for break-before-make. > */ > - static const pteval_t mask = PTE_PXN | PTE_RDONLY | PTE_WRITE | PTE_NG; > + pteval_t mask = PTE_PXN | PTE_RDONLY | PTE_WRITE | PTE_NG; > > /* creating or taking down mappings is always safe */ > if (old == 0 || new == 0) > @@ -134,6 +134,19 @@ static bool pgattr_change_is_safe(u64 old, u64 new) > if (old & ~new & PTE_NG) > return false; > > + if (system_supports_mte()) { > + /* > + * Changing the memory type between Normal and Normal-Tagged > + * is safe since Tagged is considered a permission attribute > + * from the mismatched attribute aliases perspective. > + */ > + if ((old & PTE_ATTRINDX_MASK) == PTE_ATTRINDX(MT_NORMAL) || > + (old & PTE_ATTRINDX_MASK) == PTE_ATTRINDX(MT_NORMAL_TAGGED) || > + (new & PTE_ATTRINDX_MASK) == PTE_ATTRINDX(MT_NORMAL) || > + (new & PTE_ATTRINDX_MASK) == PTE_ATTRINDX(MT_NORMAL_TAGGED)) > + mask |= PTE_ATTRINDX_MASK; > + } > + > return ((old ^ new) & ~mask) == 0; > } This is much more permissive than I would expect. If either the old or new memory type is NORMAL (or NORMAL_TAGGED) then the memory type is ignored altogether. Should this check be: if (((old & PTE_ATTRINDX_MASK) == PTE_ATTRINDX(MT_NORMAL) || (old & PTE_ATTRINDX_MASK) == PTE_ATTRINDX(MT_NORMAL_TAGGED)) && ((new & PTE_ATTRINDX_MASK) == PTE_ATTRINDX(MT_NORMAL) || (new & PTE_ATTRINDX_MASK) == PTE_ATTRINDX(MT_NORMAL_TAGGED))) Steve