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=-17.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, 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 53B6DC433DB for ; Fri, 5 Mar 2021 15:55:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D9AF164EBA for ; Fri, 5 Mar 2021 15:55:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D9AF164EBA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 743F46B0074; Fri, 5 Mar 2021 10:55:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 71A556B0075; Fri, 5 Mar 2021 10:55:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 592296B0078; Fri, 5 Mar 2021 10:55:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0205.hostedemail.com [216.40.44.205]) by kanga.kvack.org (Postfix) with ESMTP id 3BC1B6B0074 for ; Fri, 5 Mar 2021 10:55:52 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id E3F9A180ACF86 for ; Fri, 5 Mar 2021 15:55:51 +0000 (UTC) X-FDA: 77886271302.08.4BF2FBB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 351ADA0049DD for ; Fri, 5 Mar 2021 15:55:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614959737; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sLwq5l3qqhMxFe28uHW3nAdGJtoOa87DfrLUINTrfaM=; b=UChvRFhiSseHjGO9MW1lZGyb5XP2vADL2RH9X3kAB178r76LSqd4I3JhFKYh84dZhocS4q nB9HakKVZMUg7R2mA+y//btJQQY9nhqXxspQCyrQrcIpwP77Bbh8vgPHJwzYV257QOi+jm pzrFCX9D8SjP1txWh9aO66si8ZUsfho= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-426-H5-kcfe6PcaLwUUfl-TG6w-1; Fri, 05 Mar 2021 10:55:33 -0500 X-MC-Unique: H5-kcfe6PcaLwUUfl-TG6w-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3677C1966324; Fri, 5 Mar 2021 15:55:32 +0000 (UTC) Received: from [10.36.112.194] (ovpn-112-194.ams2.redhat.com [10.36.112.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9982660843; Fri, 5 Mar 2021 15:55:29 +0000 (UTC) Subject: Re: [PATCH] arm64: mte: Use PAGE_KERNEL_TAGGED in arch_add_memory To: Catalin Marinas , Patrick Daly Cc: linux-arm-kernel@lists.infradead.org, Will Deacon , Vincenzo Frascino , Anshuman Khandual , linux-mm@kvack.org References: <1614745263-27827-1-git-send-email-pdaly@codeaurora.org> <20210305111908.GA23855@arm.com> <20210305154340.GC23855@arm.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <3dae4529-6c73-d4c0-3fa6-6c2bda6518c9@redhat.com> Date: Fri, 5 Mar 2021 16:55:28 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <20210305154340.GC23855@arm.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 351ADA0049DD X-Stat-Signature: 18rat8fxetmxeqgmt9kag76ke5spcjp9 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf24; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=63.128.21.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614959737-225367 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 05.03.21 16:43, Catalin Marinas wrote: > On Fri, Mar 05, 2021 at 11:19:08AM +0000, Catalin Marinas wrote: >> On Tue, Mar 02, 2021 at 08:21:03PM -0800, Patrick Daly wrote: >>> In a system which supports MTE, the linear kernel region must allow >>> reading/writing allocation tags. For memory present at boot this >>> is already being done in map_mem(). Add the same in arch_add_memory(). >>> >>> Signed-off-by: Patrick Daly >>> --- >>> arch/arm64/mm/mmu.c | 12 +++++++++++- >>> 1 file changed, 11 insertions(+), 1 deletion(-) >>> >>> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c >>> index 9b25d60b..0fcfe90 100644 >>> --- a/arch/arm64/mm/mmu.c >>> +++ b/arch/arm64/mm/mmu.c >>> @@ -1463,6 +1463,7 @@ int arch_add_memory(int nid, u64 start, u64 size, >>> struct mhp_params *params) >>> { >>> int ret, flags = 0; >>> + pgprot_t pgprot; >>> >>> if (!inside_linear_region(start, size)) { >>> pr_err("[%llx %llx] is outside linear mapping region\n", start, start + size); >>> @@ -1477,8 +1478,17 @@ int arch_add_memory(int nid, u64 start, u64 size, >>> IS_ENABLED(CONFIG_KFENCE)) >>> flags = NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; >>> >>> + /* >>> + * The linear map must allow allocation tags reading/writing >>> + * if MTE is present. Otherwise, it has the same attributes as >>> + * PAGE_KERNEL. >>> + */ >>> + pgprot = params->pgprot; >>> + if (pgprot_val(pgprot) == pgprot_val(PAGE_KERNEL)) >>> + pgprot = PAGE_KERNEL_TAGGED; >>> + >>> __create_pgd_mapping(swapper_pg_dir, start, __phys_to_virt(start), >>> - size, params->pgprot, __pgd_pgtable_alloc, >>> + size, pgprot, __pgd_pgtable_alloc, >>> flags); >> >> We'll need a similar pattern for vmalloc() once we have the khwasan >> support in place. So we could add a pgprot_tagged() function (similar to >> pgprot_writecombine() etc.) which does the above check and returns >> PAGE_KERNEL_TAGGED, maybe only checking the PTE_ATTRINDX_MASK bits >> rather than the whole prot bits. >> >> However, the bigger problem is that arch_add_memory() is also called for >> ZONE_DEVICE mappings and we can't always guarantee that such range >> supports tagging (most likely it doesn't, e.g. persistent memory), >> leading to potential external aborts. >> >> One option is to expand mhp_params to pass additional information so >> that the arch code can make the right decision. Another option is to >> make PAGE_KERNEL_TAGGED global which is just PAGE_KERNEL for all the >> other architectures and use it in the core code. >> >> Yet another option which we haven't fully explored with MTE is to have >> PAGE_KERNEL always tagged but add a new PAGE_KERNEL_DEVICE (or >> _UNTAGGED) for specific cases like ZONE_DEVICE. We need to make sure >> that PAGE_KERNEL doesn't end up in places where the backing memory does >> not support tags. >> >> I'll give the last option a quick try and see if it falls apart (just >> changing PAGE_KERNEL to tagged). In terms of tag cache usage, it >> probably won't have much of an impact since the whole of the linear map >> is tagged already. > > I played with this a bit and the last option is not really feasible. > There are several places in the kernel where PAGE_KERNEL is used just > because the expectation is for write-back memory. For MTE, we need > tagged memory either because the kernel allocators need it (with > KASAN_HW_TAGS) or because it is shared with the user, potentially mapped > as tagged in user space and such tags need to be preserved by the > kernel. So for the latter, only the linear map needs to be tagged (and > memory hotplug falls into this category). > > This leaves us with one of the first two options. I think the easiest > is: > > ---------------8<------------------------------- > diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h > index e17b96d0e4b5..5c78b92d9ec5 100644 > --- a/arch/arm64/include/asm/pgtable.h > +++ b/arch/arm64/include/asm/pgtable.h > @@ -486,6 +486,8 @@ static inline pmd_t pmd_mkdevmap(pmd_t pmd) > __pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_NC) | PTE_PXN | PTE_UXN) > #define pgprot_device(prot) \ > __pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_DEVICE_nGnRE) | PTE_PXN | PTE_UXN) > +#define pgprot_tagged(prot) \ > + __pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_TAGGED)) > /* > * DMA allocations for non-coherent devices use what the Arm architecture calls > * "Normal non-cacheable" memory, which permits speculation, unaligned accesses > diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h > index cdfc4e9f253e..f5f5044db2ce 100644 > --- a/include/linux/pgtable.h > +++ b/include/linux/pgtable.h > @@ -904,6 +904,10 @@ static inline void ptep_modify_prot_commit(struct vm_area_struct *vma, > #define pgprot_device pgprot_noncached > #endif > > +#ifndef pgprot_tagged > +#define pgprot_tagged(prot) (prot) > +#endif > + > #ifdef CONFIG_MMU > #ifndef pgprot_modify > #define pgprot_modify pgprot_modify > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index 5ba51a8bdaeb..4253d80a59ba 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -1072,7 +1072,7 @@ static int online_memory_block(struct memory_block *mem, void *arg) > */ > int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) > { > - struct mhp_params params = { .pgprot = PAGE_KERNEL }; > + struct mhp_params params = { .pgprot = pgprot_tagged(PAGE_KERNEL) }; This looks like we're pushing arch specific stuff ("tagged") in here. Can't we generalize this to something like pgprot_mhp_default (or a better name) that defaults to PAGE_KERNEL on all architectures except arm64 which overwrites this somehow? -- Thanks, David / dhildenb