[PATCH] arm64: mte: Use PAGE_KERNEL_TAGGED in arch_add_memory

Patrick Daly pdaly at codeaurora.org
Wed Mar 3 04:21:03 GMT 2021


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 <pdaly at codeaurora.org>
---
 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);
 
 	memblock_clear_nomap(start, size);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project




More information about the linux-arm-kernel mailing list