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=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 EDF70C433E0 for ; Fri, 5 Mar 2021 17:44:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 90EA7650A3 for ; Fri, 5 Mar 2021 17:44:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 90EA7650A3 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 1E3D26B005D; Fri, 5 Mar 2021 12:44:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 16C6D6B006C; Fri, 5 Mar 2021 12:44:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F288E6B006E; Fri, 5 Mar 2021 12:44:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0229.hostedemail.com [216.40.44.229]) by kanga.kvack.org (Postfix) with ESMTP id D60136B005D for ; Fri, 5 Mar 2021 12:44:21 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 96FF38249980 for ; Fri, 5 Mar 2021 17:44:21 +0000 (UTC) X-FDA: 77886544722.26.8285EE1 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf29.hostedemail.com (Postfix) with ESMTP id 4007523B8 for ; Fri, 5 Mar 2021 17:44:17 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id D6CD965085; Fri, 5 Mar 2021 17:44:15 +0000 (UTC) Date: Fri, 5 Mar 2021 17:44:13 +0000 From: Catalin Marinas To: David Hildenbrand Cc: Patrick Daly , linux-arm-kernel@lists.infradead.org, Will Deacon , Vincenzo Frascino , Anshuman Khandual , linux-mm@kvack.org Subject: Re: [PATCH] arm64: mte: Use PAGE_KERNEL_TAGGED in arch_add_memory Message-ID: <20210305174413.GF23855@arm.com> References: <1614745263-27827-1-git-send-email-pdaly@codeaurora.org> <20210305111908.GA23855@arm.com> <20210305154340.GC23855@arm.com> <3dae4529-6c73-d4c0-3fa6-6c2bda6518c9@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3dae4529-6c73-d4c0-3fa6-6c2bda6518c9@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 4007523B8 X-Stat-Signature: qy3huhwitagihdy6kszj6uq1zbnd5pas Received-SPF: none (kernel.org>: No applicable sender policy available) receiver=imf29; identity=mailfrom; envelope-from=""; helo=mail.kernel.org; client-ip=198.145.29.99 X-HE-DKIM-Result: none/none X-HE-Tag: 1614966257-493728 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 Fri, Mar 05, 2021 at 04:55:28PM +0100, David Hildenbrand wrote: > 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); [...] > > ---------------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? It works for me but I prefer the prot modification style similar to pgprot_writecombine() etc. (i.e. takes a parameter like PAGE_KERNEL and just changes bits of it). Thanks. -- Catalin 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=-15.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable 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 8AAF0C433DB for ; Fri, 5 Mar 2021 17:46:03 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 0188D650A1 for ; Fri, 5 Mar 2021 17:46:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0188D650A1 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=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc: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=gSDCEzSP9IqvvWWkqotALdUIHD88dvqj8hkk+U6Q4VM=; b=PNeqdgYGJfSjh3f9hIObZ7YTb liBBXJ53ruoUyC+EbrtIzN09AUjNSI1kdvwWkCjFeGplnb9bhXvpGl95VD1JA47f8sTMO0HtwvP8b pGnmO2eCewFZSES4TsTPc6efvq6E79RAzxhSfQoFfsIRpHZKQgOm35u3e3D33o7n/OCKjC31LSdSS WZOJkY0I6APU2YV3NEdQzQrRVdxIsJpEuYs2xG339J/9O3IgfTeBWdcGjW+HWOKDGURMh8PPxw1Wb qkoFEvXv1GapxQPNL9j7LkFM5f2WW1McR22VtKfOucFOntCWCjNpOY0jxtfVQUKmdx/78rqbCglkN zKSUzlbPg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lIEUz-00FqFp-SC; Fri, 05 Mar 2021 17:44:26 +0000 Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lIEUs-00FqEt-SD for linux-arm-kernel@lists.infradead.org; Fri, 05 Mar 2021 17:44:22 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id D6CD965085; Fri, 5 Mar 2021 17:44:15 +0000 (UTC) Date: Fri, 5 Mar 2021 17:44:13 +0000 From: Catalin Marinas To: David Hildenbrand Cc: Patrick Daly , linux-arm-kernel@lists.infradead.org, Will Deacon , Vincenzo Frascino , Anshuman Khandual , linux-mm@kvack.org Subject: Re: [PATCH] arm64: mte: Use PAGE_KERNEL_TAGGED in arch_add_memory Message-ID: <20210305174413.GF23855@arm.com> References: <1614745263-27827-1-git-send-email-pdaly@codeaurora.org> <20210305111908.GA23855@arm.com> <20210305154340.GC23855@arm.com> <3dae4529-6c73-d4c0-3fa6-6c2bda6518c9@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <3dae4529-6c73-d4c0-3fa6-6c2bda6518c9@redhat.com> 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-20210305_174420_257224_090D9023 X-CRM114-Status: GOOD ( 27.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 Fri, Mar 05, 2021 at 04:55:28PM +0100, David Hildenbrand wrote: > 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); [...] > > ---------------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? It works for me but I prefer the prot modification style similar to pgprot_writecombine() etc. (i.e. takes a parameter like PAGE_KERNEL and just changes bits of it). Thanks. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel