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=-16.8 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_GIT 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 3DF7DC433E0 for ; Tue, 9 Mar 2021 12:26:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B17DF65268 for ; Tue, 9 Mar 2021 12:26:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B17DF65268 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 3F9B58D00E8; Tue, 9 Mar 2021 07:26:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A9BE8D007F; Tue, 9 Mar 2021 07:26:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 271368D00E8; Tue, 9 Mar 2021 07:26:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0215.hostedemail.com [216.40.44.215]) by kanga.kvack.org (Postfix) with ESMTP id 06F648D007F for ; Tue, 9 Mar 2021 07:26:07 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id BA2495DED for ; Tue, 9 Mar 2021 12:26:06 +0000 (UTC) X-FDA: 77900257932.20.DF5AF59 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf01.hostedemail.com (Postfix) with ESMTP id 916FC200039C for ; Tue, 9 Mar 2021 12:26:06 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 9D7AE64F67; Tue, 9 Mar 2021 12:26:03 +0000 (UTC) From: Catalin Marinas To: linux-arm-kernel@lists.infradead.org Cc: linux-mm@kvack.org, Anshuman Khandual , Patrick Daly , Will Deacon , Andrew Morton , Vincenzo Frascino , David Hildenbrand Subject: [PATCH] arm64: mte: Map hotplugged memory as Normal Tagged Date: Tue, 9 Mar 2021 12:26:01 +0000 Message-Id: <20210309122601.5543-1-catalin.marinas@arm.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 916FC200039C X-Stat-Signature: c6t3hnqr8o1p7ynakzwwn5grj744hm6p Received-SPF: none (kernel.org>: No applicable sender policy available) receiver=imf01; identity=mailfrom; envelope-from=""; helo=mail.kernel.org; client-ip=198.145.29.99 X-HE-DKIM-Result: none/none X-HE-Tag: 1615292766-444533 Content-Transfer-Encoding: quoted-printable 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: In a system supporting MTE, the linear map must allow reading/writing allocation tags by setting the memory type as Normal Tagged. Currently, this is only handled for memory present at boot. Hotplugged memory uses Normal non-Tagged memory. Introduce pgprot_mhp() for hotplugged memory and use it in add_memory_resource(). The arm64 code maps pgprot_mhp() to pgprot_tagged(). Note that ZONE_DEVICE memory should not be mapped as Tagged and therefore setting the memory type in arch_add_memory() is not feasible. Signed-off-by: Catalin Marinas Fixes: 0178dc761368 ("arm64: mte: Use Normal Tagged attributes for the li= near map") Reported-by: Patrick Daly Link: https://lore.kernel.org/r/1614745263-27827-1-git-send-email-pdaly@c= odeaurora.org Cc: # 5.10.x Cc: Will Deacon Cc: Andrew Morton Cc: Vincenzo Frascino Cc: David Hildenbrand --- Patrick, could you please give this patch a try on your platform? Thanks. arch/arm64/include/asm/pgtable-prot.h | 1 - arch/arm64/include/asm/pgtable.h | 3 +++ arch/arm64/mm/mmu.c | 3 ++- include/linux/pgtable.h | 4 ++++ mm/memory_hotplug.c | 2 +- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/a= sm/pgtable-prot.h index 046be789fbb4..9a65fb528110 100644 --- a/arch/arm64/include/asm/pgtable-prot.h +++ b/arch/arm64/include/asm/pgtable-prot.h @@ -66,7 +66,6 @@ extern bool arm64_use_ng_mappings; #define _PAGE_DEFAULT (_PROT_DEFAULT | PTE_ATTRINDX(MT_NORMAL)) =20 #define PAGE_KERNEL __pgprot(PROT_NORMAL) -#define PAGE_KERNEL_TAGGED __pgprot(PROT_NORMAL_TAGGED) #define PAGE_KERNEL_RO __pgprot((PROT_NORMAL & ~PTE_WRITE) | PTE_RDONLY= ) #define PAGE_KERNEL_ROX __pgprot((PROT_NORMAL & ~(PTE_WRITE | PTE_PXN))= | PTE_RDONLY) #define PAGE_KERNEL_EXEC __pgprot(PROT_NORMAL & ~PTE_PXN) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pg= table.h index e17b96d0e4b5..47027796c2f9 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -486,6 +486,9 @@ static inline pmd_t pmd_mkdevmap(pmd_t pmd) __pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_NC) | P= TE_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)= ) +#define pgprot_mhp pgprot_tagged /* * DMA allocations for non-coherent devices use what the Arm architectur= e calls * "Normal non-cacheable" memory, which permits speculation, unaligned a= ccesses diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 3802cfbdd20d..9c8aa1b44cd5 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -512,7 +512,8 @@ static void __init map_mem(pgd_t *pgdp) * if MTE is present. Otherwise, it has the same attributes as * PAGE_KERNEL. */ - __map_memblock(pgdp, start, end, PAGE_KERNEL_TAGGED, flags); + __map_memblock(pgdp, start, end, pgprot_tagged(PAGE_KERNEL), + flags); } =20 /* diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index cdfc4e9f253e..5e772392a379 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 =20 +#ifndef pgprot_mhp +#define pgprot_mhp(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..0cdbbfbc5757 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_f= lags) { - struct mhp_params params =3D { .pgprot =3D PAGE_KERNEL }; + struct mhp_params params =3D { .pgprot =3D pgprot_mhp(PAGE_KERNEL) }; u64 start, size; bool new_node =3D false; int ret; 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=-11.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 A872BC433E0 for ; Wed, 10 Mar 2021 19:25:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 00CA164FCC for ; Wed, 10 Mar 2021 19:25:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 00CA164FCC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 613F28D0204; Wed, 10 Mar 2021 14:25:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5C4EE8D01ED; Wed, 10 Mar 2021 14:25:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 417988D0204; Wed, 10 Mar 2021 14:25:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0006.hostedemail.com [216.40.44.6]) by kanga.kvack.org (Postfix) with ESMTP id 26F2F8D01ED for ; Wed, 10 Mar 2021 14:25:26 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id E0A34181AF5D0 for ; Wed, 10 Mar 2021 19:25:25 +0000 (UTC) X-FDA: 77904943410.16.990FB8F Received: from labrats.qualcomm.com (labrats.qualcomm.com [199.106.110.90]) by imf13.hostedemail.com (Postfix) with ESMTP id B4E57E000109 for ; Wed, 10 Mar 2021 19:25:22 +0000 (UTC) IronPort-SDR: rrY9iLUqVQgskxHdY0uOyrU/J2t3Sg5dYz2MMmA5t0ARCdXpGOuXWBrw3ZsKZcdv74CFJIv11l U+Qut+Wjw9oE7yHHQjzAd7ROOEyW0gaQ/j3wsgvO30tRVvg8T3wQo0xUigDa8HFiLTjibBQuNL gP+KqfzjpRt6CpvmanQu1j26GEkwMpKdUsnqfVBxJWlczQx+3dyiGXysvKuk6T6L3F/J9jUu/L eh7i3QeWp+cJWqFozGSZ1FuTB/OJTkINRbDkqekItZ6dBSUp2guXMpc19NKe6uWCUygKPJ1RJZ f3k= X-IronPort-AV: E=Sophos;i="5.81,238,1610438400"; d="scan'208";a="47808929" Received: from unknown (HELO ironmsg04-sd.qualcomm.com) ([10.53.140.144]) by labrats.qualcomm.com with ESMTP; 10 Mar 2021 11:25:23 -0800 X-QCInternal: smtphost Received: from linux-kernel-memory-lab-01.qualcomm.com ([10.63.172.21]) by ironmsg04-sd.qualcomm.com with ESMTP; 10 Mar 2021 11:25:22 -0800 Received: by linux-kernel-memory-lab-01.qualcomm.com (Postfix, from userid 98314) id C7DB921C33; Wed, 10 Mar 2021 11:25:22 -0800 (PST) From: Patrick Daly To: catalin.marinas@arm.com, linux-arm-kernel@lists.infradead.org Cc: akpm@linux-foundation.org, anshuman.khandual@arm.com, david@redhat.com, linux-mm@kvack.org, pdaly@codeaurora.org, vincenzo.frascino@arm.com, will@kernel.org Subject: [PATCH] arm64: mte: Map hotplugged memory as Normal Tagged Date: Wed, 10 Mar 2021 11:24:35 -0800 Message-ID: <20210309122601.5543-1-catalin.marinas@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <20210309122601.5543-1-catalin.marinas@arm.com> References: <20210309122601.5543-1-catalin.marinas@arm.com> Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3599CC433DB for ; Tue, 9 Mar 2021 12:27:45 +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 BCBFE6526E for ; Tue, 9 Mar 2021 12:27:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BCBFE6526E 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:MIME-Version:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=KsW2t2BqP4kHpmIkduN2EcZVCNcBaJGUnoI6GEoGzkQ=; b=iAy9OOYQY/XMmP1riD6CvP5KpL 1PzcgcgGNW0jUKt7vQY5u2K4u/I+3TpVKm4MDLV9N5a9jbdqJgGVKqsqJHCZsYft8jLoO4SHvpk5z LykyP5BEBRFwDvrFhTHjG7EFL7b4oGnAu0Z0scRK3fI/NsS+8OLrRRr0RL5nW0seS400fW5u/Kjr1 m8ztaKlDuGwTkc3gHjdRGprg1KKqSSnckk5m7jy/Q0eVVQEB/FkOh8zwgFxsWGF8CzKeUAZtuzNns 8Gm0hVekMPVqnDB0otKZXGgIUeO6JtfLrFSsOxjuHpLduq824JoBhbi73gsI8EhkoFo0jIO95qQLN YBjgw/lQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lJbRG-004SRD-6D; Tue, 09 Mar 2021 12:26:14 +0000 Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lJbRA-004SQX-Fa for linux-arm-kernel@lists.infradead.org; Tue, 09 Mar 2021 12:26:10 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9D7AE64F67; Tue, 9 Mar 2021 12:26:03 +0000 (UTC) X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Archived-At: List-Archive: Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B4E57E000109 X-Stat-Signature: 1jzjfu5qd8ujwc5d8gt3jh6n58k9bfdd Received-SPF: none (qualcomm.com>: No applicable sender policy available) receiver=imf13; identity=mailfrom; envelope-from=""; helo=labrats.qualcomm.com; client-ip=199.106.110.90 X-HE-DKIM-Result: fail/fail (message has been altered) X-HE-Tag: 1615404322-885859 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: Message-ID: <20210310192435.j_Tw_9MQwSEX-wDpdBNQN8SyfGNCQT-yYZwIqjYAD6U@z> From: Catalin Marinas > In a system supporting MTE, the linear map must allow reading/writing > allocation tags by setting the memory type as Normal Tagged. Currently, > this is only handled for memory present at boot. Hotplugged memory uses > Normal non-Tagged memory. > > Introduce pgprot_mhp() for hotplugged memory and use it in > add_memory_resource(). The arm64 code maps pgprot_mhp() to > pgprot_tagged(). > > Note that ZONE_DEVICE memory should not be mapped as Tagged and > therefore setting the memory type in arch_add_memory() is not feasible. > > Signed-off-by: Catalin Marinas > Fixes: 0178dc761368 ("arm64: mte: Use Normal Tagged attributes for the linear map") > Reported-by: Patrick Daly > Link: https://lore.kernel.org/r/1614745263-27827-1-git-send-email-pdaly@codeaurora.org > Cc: # 5.10.x > Cc: Will Deacon > Cc: Andrew Morton > Cc: Vincenzo Frascino > Cc: David Hildenbrand > --- > > Patrick, could you please give this patch a try on your platform? Thanks. It works for me. Sry for the double reply. 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=-14.2 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, UNWANTED_LANGUAGE_BODY,USER_AGENT_GIT 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 3599CC433DB for ; Tue, 9 Mar 2021 12:27:45 +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 BCBFE6526E for ; Tue, 9 Mar 2021 12:27:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BCBFE6526E 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:MIME-Version:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=KsW2t2BqP4kHpmIkduN2EcZVCNcBaJGUnoI6GEoGzkQ=; b=iAy9OOYQY/XMmP1riD6CvP5KpL 1PzcgcgGNW0jUKt7vQY5u2K4u/I+3TpVKm4MDLV9N5a9jbdqJgGVKqsqJHCZsYft8jLoO4SHvpk5z LykyP5BEBRFwDvrFhTHjG7EFL7b4oGnAu0Z0scRK3fI/NsS+8OLrRRr0RL5nW0seS400fW5u/Kjr1 m8ztaKlDuGwTkc3gHjdRGprg1KKqSSnckk5m7jy/Q0eVVQEB/FkOh8zwgFxsWGF8CzKeUAZtuzNns 8Gm0hVekMPVqnDB0otKZXGgIUeO6JtfLrFSsOxjuHpLduq824JoBhbi73gsI8EhkoFo0jIO95qQLN YBjgw/lQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lJbRG-004SRD-6D; Tue, 09 Mar 2021 12:26:14 +0000 Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lJbRA-004SQX-Fa for linux-arm-kernel@lists.infradead.org; Tue, 09 Mar 2021 12:26:10 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9D7AE64F67; Tue, 9 Mar 2021 12:26:03 +0000 (UTC) From: Catalin Marinas To: linux-arm-kernel@lists.infradead.org Cc: linux-mm@kvack.org, Anshuman Khandual , Patrick Daly , Will Deacon , Andrew Morton , Vincenzo Frascino , David Hildenbrand Subject: [PATCH] arm64: mte: Map hotplugged memory as Normal Tagged Date: Tue, 9 Mar 2021 12:26:01 +0000 Message-Id: <20210309122601.5543-1-catalin.marinas@arm.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210309_122609_010794_4545ADB4 X-CRM114-Status: GOOD ( 16.33 ) 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 In a system supporting MTE, the linear map must allow reading/writing allocation tags by setting the memory type as Normal Tagged. Currently, this is only handled for memory present at boot. Hotplugged memory uses Normal non-Tagged memory. Introduce pgprot_mhp() for hotplugged memory and use it in add_memory_resource(). The arm64 code maps pgprot_mhp() to pgprot_tagged(). Note that ZONE_DEVICE memory should not be mapped as Tagged and therefore setting the memory type in arch_add_memory() is not feasible. Signed-off-by: Catalin Marinas Fixes: 0178dc761368 ("arm64: mte: Use Normal Tagged attributes for the linear map") Reported-by: Patrick Daly Link: https://lore.kernel.org/r/1614745263-27827-1-git-send-email-pdaly@codeaurora.org Cc: # 5.10.x Cc: Will Deacon Cc: Andrew Morton Cc: Vincenzo Frascino Cc: David Hildenbrand --- Patrick, could you please give this patch a try on your platform? Thanks. arch/arm64/include/asm/pgtable-prot.h | 1 - arch/arm64/include/asm/pgtable.h | 3 +++ arch/arm64/mm/mmu.c | 3 ++- include/linux/pgtable.h | 4 ++++ mm/memory_hotplug.c | 2 +- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm/pgtable-prot.h index 046be789fbb4..9a65fb528110 100644 --- a/arch/arm64/include/asm/pgtable-prot.h +++ b/arch/arm64/include/asm/pgtable-prot.h @@ -66,7 +66,6 @@ extern bool arm64_use_ng_mappings; #define _PAGE_DEFAULT (_PROT_DEFAULT | PTE_ATTRINDX(MT_NORMAL)) #define PAGE_KERNEL __pgprot(PROT_NORMAL) -#define PAGE_KERNEL_TAGGED __pgprot(PROT_NORMAL_TAGGED) #define PAGE_KERNEL_RO __pgprot((PROT_NORMAL & ~PTE_WRITE) | PTE_RDONLY) #define PAGE_KERNEL_ROX __pgprot((PROT_NORMAL & ~(PTE_WRITE | PTE_PXN)) | PTE_RDONLY) #define PAGE_KERNEL_EXEC __pgprot(PROT_NORMAL & ~PTE_PXN) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index e17b96d0e4b5..47027796c2f9 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -486,6 +486,9 @@ 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)) +#define pgprot_mhp pgprot_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/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 3802cfbdd20d..9c8aa1b44cd5 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -512,7 +512,8 @@ static void __init map_mem(pgd_t *pgdp) * if MTE is present. Otherwise, it has the same attributes as * PAGE_KERNEL. */ - __map_memblock(pgdp, start, end, PAGE_KERNEL_TAGGED, flags); + __map_memblock(pgdp, start, end, pgprot_tagged(PAGE_KERNEL), + flags); } /* diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index cdfc4e9f253e..5e772392a379 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_mhp +#define pgprot_mhp(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..0cdbbfbc5757 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_mhp(PAGE_KERNEL) }; u64 start, size; bool new_node = false; int ret; _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel