linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] arm64: mte: Ensure the cleared tags are visible before setting the PTE
@ 2022-05-17  9:35 Catalin Marinas
  2022-05-17  9:39 ` Vladimir Murzin
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Catalin Marinas @ 2022-05-17  9:35 UTC (permalink / raw)
  To: Will Deacon
  Cc: linux-arm-kernel, Steven Price, Vincenzo Frascino, Vladimir Murzin

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.

Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Fixes: 34bfeea4a9e9 ("arm64: mte: Clear the tags when a page is mapped in user-space with PROT_MTE")
Cc: <stable@vger.kernel.org> # 5.10.x
Reported-by: Vladimir Murzin <vladimir.murzin@arm.com>
Cc: Will Deacon <will@kernel.org>
---

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(+)

diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c
index 90994aca54f3..d565ae25e48f 100644
--- a/arch/arm64/kernel/mte.c
+++ b/arch/arm64/kernel/mte.c
@@ -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
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] arm64: mte: Ensure the cleared tags are visible before setting the PTE
  2022-05-17  9:35 [PATCH v2] arm64: mte: Ensure the cleared tags are visible before setting the PTE Catalin Marinas
@ 2022-05-17  9:39 ` Vladimir Murzin
  2022-05-17 10:23 ` Steven Price
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Vladimir Murzin @ 2022-05-17  9:39 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon
  Cc: linux-arm-kernel, Steven Price, Vincenzo Frascino

On 5/17/22 10:35, Catalin Marinas wrote:
> 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.
> 
> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
> Fixes: 34bfeea4a9e9 ("arm64: mte: Clear the tags when a page is mapped in user-space with PROT_MTE")
> Cc: <stable@vger.kernel.org> # 5.10.x
> Reported-by: Vladimir Murzin <vladimir.murzin@arm.com>
> Cc: Will Deacon <will@kernel.org>
> ---
> 
> 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(+)
> 
> diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c
> index 90994aca54f3..d565ae25e48f 100644
> --- a/arch/arm64/kernel/mte.c
> +++ b/arch/arm64/kernel/mte.c
> @@ -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

Tested-by: Vladimir Murzin <vladimir.murzin@arm.com>

Cheers
Vladimir

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] arm64: mte: Ensure the cleared tags are visible before setting the PTE
  2022-05-17  9:35 [PATCH v2] arm64: mte: Ensure the cleared tags are visible before setting the PTE Catalin Marinas
  2022-05-17  9:39 ` Vladimir Murzin
@ 2022-05-17 10:23 ` Steven Price
  2022-05-17 13:16 ` Vincenzo Frascino
  2022-05-17 14:04 ` Will Deacon
  3 siblings, 0 replies; 5+ messages in thread
From: Steven Price @ 2022-05-17 10:23 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon
  Cc: linux-arm-kernel, Vincenzo Frascino, Vladimir Murzin

On 17/05/2022 10:35, Catalin Marinas wrote:
> 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.
> 
> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
> Fixes: 34bfeea4a9e9 ("arm64: mte: Clear the tags when a page is mapped in user-space with PROT_MTE")
> Cc: <stable@vger.kernel.org> # 5.10.x
> Reported-by: Vladimir Murzin <vladimir.murzin@arm.com>
> Cc: Will Deacon <will@kernel.org>

Reviewed-by: Steven Price <steven.price@arm.com>



> ---
> 
> 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(+)
> 
> diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c
> index 90994aca54f3..d565ae25e48f 100644
> --- a/arch/arm64/kernel/mte.c
> +++ b/arch/arm64/kernel/mte.c
> @@ -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
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] arm64: mte: Ensure the cleared tags are visible before setting the PTE
  2022-05-17  9:35 [PATCH v2] arm64: mte: Ensure the cleared tags are visible before setting the PTE Catalin Marinas
  2022-05-17  9:39 ` Vladimir Murzin
  2022-05-17 10:23 ` Steven Price
@ 2022-05-17 13:16 ` Vincenzo Frascino
  2022-05-17 14:04 ` Will Deacon
  3 siblings, 0 replies; 5+ messages in thread
From: Vincenzo Frascino @ 2022-05-17 13:16 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon
  Cc: linux-arm-kernel, Steven Price, Vladimir Murzin



On 5/17/22 10:35, Catalin Marinas wrote:
> 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.
> 
> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
> Fixes: 34bfeea4a9e9 ("arm64: mte: Clear the tags when a page is mapped in user-space with PROT_MTE")
> Cc: <stable@vger.kernel.org> # 5.10.x
> Reported-by: Vladimir Murzin <vladimir.murzin@arm.com>
> Cc: Will Deacon <will@kernel.org>

Reviewed-by: Vincenzo Frascino <vincenzo.frascino@arm.com>

> ---
> 
> 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(+)
> 
> diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c
> index 90994aca54f3..d565ae25e48f 100644
> --- a/arch/arm64/kernel/mte.c
> +++ b/arch/arm64/kernel/mte.c
> @@ -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)

-- 
Regards,
Vincenzo

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] arm64: mte: Ensure the cleared tags are visible before setting the PTE
  2022-05-17  9:35 [PATCH v2] arm64: mte: Ensure the cleared tags are visible before setting the PTE Catalin Marinas
                   ` (2 preceding siblings ...)
  2022-05-17 13:16 ` Vincenzo Frascino
@ 2022-05-17 14:04 ` Will Deacon
  3 siblings, 0 replies; 5+ messages in thread
From: Will Deacon @ 2022-05-17 14:04 UTC (permalink / raw)
  To: Catalin Marinas
  Cc: kernel-team, Will Deacon, Steven Price, Vladimir Murzin,
	linux-arm-kernel, Vincenzo Frascino

On Tue, 17 May 2022 10:35:32 +0100, Catalin Marinas wrote:
> 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,
-- 
Will

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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-05-17 14:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-17  9:35 [PATCH v2] arm64: mte: Ensure the cleared tags are visible before setting the PTE Catalin Marinas
2022-05-17  9:39 ` Vladimir Murzin
2022-05-17 10:23 ` Steven Price
2022-05-17 13:16 ` Vincenzo Frascino
2022-05-17 14:04 ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).