Skip to contentSkip to conversation

arm64: mte: Ensure the cleared tags are visible before setting the PTE

PATCH Applied Catalin Marinas 5 participants 5 messages May 17, 2022 arm64

lore
Share & tools
lore

Catalin Marinas

author maintainer
#0 lore raw

PATCH v2 1/1 arm64: mte: Ensure the cleared tags are visible before setting the PTE

As an optimisation, only pages mapped with PROT_MTE in user space have the MTE tags zeroed. This is done lazily at the set_pte_at() time via mte_sync_tags(). However, this function is missing a barrier and another CPU may see the PTE updated before the zeroed tags are visible. Add an smp_wmb() barrier if the mapping is Normal Tagged.

Fixes 34bfeea4a9e9 ("arm64: mte: Clear the tags when a page is mapped in user-space with PROT_MTE")
Cc <[email protected]> # 5.10.x
Cc Will Deacon <[email protected]>

---

Changes in v2:
- make the barrier unconditional
- not including reviewed-by, tested-by tags for v1 as the patch is slightly different

 arch/arm64/kernel/mte.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm64/kernel/mte.c +3 -0
index 90994aca54f3..d565ae25e48f 100644
@@ -67,6 +67,9 @@ void mte_sync_tags(pte_t old_pte, pte_t pte)
 			mte_sync_page_tags(page, old_pte, check_swap,
 					   pte_is_tagged);
 	}
+
+	/* ensure the tags are visible before the PTE is set */
+	smp_wmb();
 }
 
 int memcmp_pages(struct page *page1, struct page *page2)

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Tested-by on v2 1/1
#1 lore raw
Quoted 26 lines · Catalin Marinas

As an optimisation, only pages mapped with PROT_MTE in user space have the MTE tags zeroed. This is done lazily at the set_pte_at() time via mte_sync_tags(). However, this function is missing a barrier and another CPU may see the PTE updated before the zeroed tags are visible. Add an smp_wmb() barrier if the mapping is Normal Tagged.

Fixes 34bfeea4a9e9 ("arm64: mte: Clear the tags when a page is mapped in user-space with PROT_MTE")
Cc <[email protected]> # 5.10.x
Cc Will Deacon <[email protected]>

---

Changes in v2:
- make the barrier unconditional
- not including reviewed-by, tested-by tags for v1 as the patch is slightly different

 arch/arm64/kernel/mte.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm64/kernel/mte.c +0 -0
index 90994aca54f3..d565ae25e48f 100644

arch/arm64/kernel/mte.c void mte_sync_tags(pte_t old_pte, pte_t pte) · line 75

Quoted 9 lines
arch/arm64/kernel/mte.c +3 -0
@@ -67,6 +67,9 @@ void mte_sync_tags(pte_t old_pte, pte_t pte)
 			mte_sync_page_tags(page, old_pte, check_swap,
 					   pte_is_tagged);
 	}
+
+	/* ensure the tags are visible before the PTE is set */
+	smp_wmb();
 }
 
 int memcmp_pages(struct page *page1, struct page *page2)

As I said in another e-mail this version has been tested in parallel to v1, so

Cheers
Vladimir

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Reviewed-by on v2 1/1
#2 lore raw
In reply to Catalin Marinas
Quoted 11 lines · Catalin Marinas

As an optimisation, only pages mapped with PROT_MTE in user space have the MTE tags zeroed. This is done lazily at the set_pte_at() time via mte_sync_tags(). However, this function is missing a barrier and another CPU may see the PTE updated before the zeroed tags are visible. Add an smp_wmb() barrier if the mapping is Normal Tagged.

Fixes 34bfeea4a9e9 ("arm64: mte: Clear the tags when a page is mapped in user-space with PROT_MTE")
Cc <[email protected]> # 5.10.x
Cc Will Deacon <[email protected]>
Quoted 15 lines

---

Changes in v2:
- make the barrier unconditional
- not including reviewed-by, tested-by tags for v1 as the patch is slightly different

 arch/arm64/kernel/mte.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm64/kernel/mte.c +0 -0
index 90994aca54f3..d565ae25e48f 100644

arch/arm64/kernel/mte.c void mte_sync_tags(pte_t old_pte, pte_t pte) · line 75

Quoted 9 lines
arch/arm64/kernel/mte.c +3 -0
@@ -67,6 +67,9 @@ void mte_sync_tags(pte_t old_pte, pte_t pte)
 			mte_sync_page_tags(page, old_pte, check_swap,
 					   pte_is_tagged);
 	}
+
+	/* ensure the tags are visible before the PTE is set */
+	smp_wmb();
 }
 
 int memcmp_pages(struct page *page1, struct page *page2)

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Reviewed-by on v2 1/1
#3 lore raw
In reply to Catalin Marinas
Quoted 11 lines · Catalin Marinas

As an optimisation, only pages mapped with PROT_MTE in user space have the MTE tags zeroed. This is done lazily at the set_pte_at() time via mte_sync_tags(). However, this function is missing a barrier and another CPU may see the PTE updated before the zeroed tags are visible. Add an smp_wmb() barrier if the mapping is Normal Tagged.

Fixes 34bfeea4a9e9 ("arm64: mte: Clear the tags when a page is mapped in user-space with PROT_MTE")
Cc <[email protected]> # 5.10.x
Cc Will Deacon <[email protected]>
Quoted 24 lines

---

Changes in v2:
- make the barrier unconditional
- not including reviewed-by, tested-by tags for v1 as the patch is slightly different

 arch/arm64/kernel/mte.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm64/kernel/mte.c +3 -0
index 90994aca54f3..d565ae25e48f 100644
@@ -67,6 +67,9 @@ void mte_sync_tags(pte_t old_pte, pte_t pte)
 			mte_sync_page_tags(page, old_pte, check_swap,
 					   pte_is_tagged);
 	}
+
+	/* ensure the tags are visible before the PTE is set */
+	smp_wmb();
 }
 
 int memcmp_pages(struct page *page1, struct page *page2)
Signature · 7 lines
Regards,
Vincenzo

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer Applied
#4 lore raw
In reply to Catalin Marinas
Quoted 8 lines · Catalin Marinas

As an optimisation, only pages mapped with PROT_MTE in user space have the MTE tags zeroed. This is done lazily at the set_pte_at() time via mte_sync_tags(). However, this function is missing a barrier and another CPU may see the PTE updated before the zeroed tags are visible. Add an smp_wmb() barrier if the mapping is Normal Tagged.

[...]

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

[1/1] arm64: mte: Ensure the cleared tags are visible before setting the PTE

      https://git.kernel.org/arm64/c/1d0cb4c8864a

Cheers,

Signature · 10 lines
Will

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

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel