Skip to contentSkip to conversation

arm64: mte: Map hotplugged memory as Normal Tagged

PATCH Applied Catalin Marinas 6 participants 6 messages Mar 9, 2021 – Mar 10, 2021

Subsystems (4)
lore
Share & tools
lore

Catalin Marinas

author maintainer
#0 lore raw

PATCH 1/1 arm64: mte: Map hotplugged memory as Normal Tagged

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.

Fixes 0178dc761368 ("arm64: mte: Use Normal Tagged attributes for the linear map")
Cc <[email protected]> # 5.10.x
Cc Will Deacon <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Vincenzo Frascino <[email protected]>
Cc David Hildenbrand <[email protected]>

---

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(-)
arch/arm64/include/asm/pgtable-prot.h +0 -1
index 046be789fbb4..9a65fb528110 100644
@@ -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)
arch/arm64/include/asm/pgtable.h +3 -0
index e17b96d0e4b5..47027796c2f9 100644
@@ -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
arch/arm64/mm/mmu.c +2 -1
index 3802cfbdd20d..9c8aa1b44cd5 100644
@@ -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);
 	}
 
 	/*
include/linux/pgtable.h +4 -0
index cdfc4e9f253e..5e772392a379 100644
@@ -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
mm/memory_hotplug.c +1 -1
index 5ba51a8bdaeb..0cdbbfbc5757 100644
@@ -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;
Reviewed-by on v1 1/1
#1 lore raw
Quoted 93 lines · 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.

Fixes 0178dc761368 ("arm64: mte: Use Normal Tagged attributes for the linear map")
Cc <[email protected]> # 5.10.x
Cc Will Deacon <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Vincenzo Frascino <[email protected]>
Cc David Hildenbrand <[email protected]>

---

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(-)
arch/arm64/include/asm/pgtable-prot.h +0 -1
index 046be789fbb4..9a65fb528110 100644
@@ -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)
arch/arm64/include/asm/pgtable.h +3 -0
index e17b96d0e4b5..47027796c2f9 100644
@@ -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
arch/arm64/mm/mmu.c +2 -1
index 3802cfbdd20d..9c8aa1b44cd5 100644
@@ -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);
  	}
 
  	/*
include/linux/pgtable.h +4 -0
index cdfc4e9f253e..5e772392a379 100644
@@ -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
mm/memory_hotplug.c +0 -0
index 5ba51a8bdaeb..0cdbbfbc5757 100644

mm/memory_hotplug.c static int online_memory_block(struct memory_block *mem, void *arg) · line 1078

Quoted 8 lines
mm/memory_hotplug.c +1 -1
@@ -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;
Signature · 3 lines
Thanks,

David / dhildenb
Reviewed-by on v1 1/1
#2 lore raw
In reply to Catalin Marinas
Quoted 12 lines · 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.

Quoted 9 lines
Fixes 0178dc761368 ("arm64: mte: Use Normal Tagged attributes for the linear map")
Cc <[email protected]> # 5.10.x
Cc Will Deacon <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Vincenzo Frascino <[email protected]>
Cc David Hildenbrand <[email protected]>
Quoted 80 lines

---

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(-)
arch/arm64/include/asm/pgtable-prot.h +0 -1
index 046be789fbb4..9a65fb528110 100644
@@ -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)
arch/arm64/include/asm/pgtable.h +3 -0
index e17b96d0e4b5..47027796c2f9 100644
@@ -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
arch/arm64/mm/mmu.c +2 -1
index 3802cfbdd20d..9c8aa1b44cd5 100644
@@ -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);
 	}
 
 	/*
include/linux/pgtable.h +4 -0
index cdfc4e9f253e..5e772392a379 100644
@@ -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
mm/memory_hotplug.c +1 -1
index 5ba51a8bdaeb..0cdbbfbc5757 100644
@@ -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;
Signature · 2 lines
Regards,
Vincenzo
#3 lore raw
In reply to Catalin Marinas
Quoted 21 lines · 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.

Fixes 0178dc761368 ("arm64: mte: Use Normal Tagged attributes for the linear map")
Cc <[email protected]> # 5.10.x
Cc Will Deacon <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Vincenzo Frascino <[email protected]>
Cc David Hildenbrand <[email protected]>
Quoted 4 lines

---

Patrick, could you please give this patch a try on your platform? Thanks.

Worked for me.

Quoted 75 lines
 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(-)
arch/arm64/include/asm/pgtable-prot.h +0 -1
index 046be789fbb4..9a65fb528110 100644
@@ -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)
arch/arm64/include/asm/pgtable.h +3 -0
index e17b96d0e4b5..47027796c2f9 100644
@@ -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
arch/arm64/mm/mmu.c +2 -1
index 3802cfbdd20d..9c8aa1b44cd5 100644
@@ -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);
 	}
 
 	/*
include/linux/pgtable.h +4 -0
index cdfc4e9f253e..5e772392a379 100644
@@ -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
mm/memory_hotplug.c +1 -1
index 5ba51a8bdaeb..0cdbbfbc5757 100644
@@ -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;
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
Reviewed-by on v1 1/1
#4 lore raw
In reply to Catalin Marinas
Quoted 12 lines · 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.

Quoted 9 lines
Fixes 0178dc761368 ("arm64: mte: Use Normal Tagged attributes for the linear map")
Cc <[email protected]> # 5.10.x
Cc Will Deacon <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Vincenzo Frascino <[email protected]>
Cc David Hildenbrand <[email protected]>
maintainer Applied
#5 lore raw
In reply to Catalin Marinas
Quoted 10 lines · 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().

[...]

Applied to arm64 (for-next/fixes), thanks!

[1/1] arm64: mte: Map hotplugged memory as Normal Tagged

      https://git.kernel.org/arm64/c/d15dfd31384b

Cheers,

Signature · 5 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev