arm64: mte: Ensure the cleared tags are visible before setting the PTE
Catalin Marinas
maintainerPATCH 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.
---
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
@@ -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
Quoted 26 lines · Catalin Marinas
As an optimisation, only pages mapped with
PROT_MTEin user space have the MTE tags zeroed. This is done lazily at theset_pte_at()time viamte_sync_tags(). However, this function is missing a barrier and another CPU may see the PTE updated before the zeroed tags are visible. Add ansmp_wmb()barrier if the mapping is Normal Tagged.Signed-off-by Catalin Marinas <[email protected]>Fixes 34bfeea4a9e9 ("arm64: mte: Clear the tags when a page is mapped in user-space with PROT_MTE")Cc <[email protected]> # 5.10.xReported-by Vladimir Murzin <[email protected]>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 differentarch/arm64/kernel/mte.c | 3 +++ 1 file changed, 3 insertions(+)arch/arm64/kernel/mte.c +0
-0
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
Quoted 11 lines · Catalin Marinas
As an optimisation, only pages mapped with
PROT_MTEin user space have the MTE tags zeroed. This is done lazily at theset_pte_at()time viamte_sync_tags(). However, this function is missing a barrier and another CPU may see the PTE updated before the zeroed tags are visible. Add ansmp_wmb()barrier if the mapping is Normal Tagged.Signed-off-by Catalin Marinas <[email protected]>Fixes 34bfeea4a9e9 ("arm64: mte: Clear the tags when a page is mapped in user-space with PROT_MTE")Cc <[email protected]> # 5.10.xReported-by Vladimir Murzin <[email protected]>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 differentarch/arm64/kernel/mte.c | 3 +++ 1 file changed, 3 insertions(+)arch/arm64/kernel/mte.c +0
-0
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
Quoted 11 lines · Catalin Marinas
As an optimisation, only pages mapped with
PROT_MTEin user space have the MTE tags zeroed. This is done lazily at theset_pte_at()time viamte_sync_tags(). However, this function is missing a barrier and another CPU may see the PTE updated before the zeroed tags are visible. Add ansmp_wmb()barrier if the mapping is Normal Tagged.Signed-off-by Catalin Marinas <[email protected]>Fixes 34bfeea4a9e9 ("arm64: mte: Clear the tags when a page is mapped in user-space with PROT_MTE")Cc <[email protected]> # 5.10.xReported-by Vladimir Murzin <[email protected]>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 differentarch/arm64/kernel/mte.c | 3 +++ 1 file changed, 3 insertions(+)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)
Signature · 7 lines
Regards, Vincenzo _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 8 lines · Catalin Marinas
As an optimisation, only pages mapped with
PROT_MTEin user space have the MTE tags zeroed. This is done lazily at theset_pte_at()time viamte_sync_tags(). However, this function is missing a barrier and another CPU may see the PTE updated before the zeroed tags are visible. Add ansmp_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