Skip to contentSkip to conversation

arm64: mte: Make mte_check_tfsr_*() conditional on KASAN instead of MTE

PATCH Applied Peter Collingbourne 3 participants 4 messages May 28, 2024 – Jun 12, 2024 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: mte: Make mte_check_tfsr_*() conditional on KASAN instead of MTE

The check in mte_check_tfsr_el1() is only necessary if HW tag based KASAN is enabled. However, we were also executing the check if MTE is enabled and KASAN is enabled at build time but disabled at runtime. This turned out to cause a measurable increase in power consumption on a specific microarchitecture after enabling MTE. Moreover, on the same system, an increase in invalid syscall latency (as measured by [1]) of around 20-30% (depending on the cluster) was observed after enabling MTE; this almost entirely goes away after removing this check. Therefore, make the check conditional on whether KASAN is enabled rather than on whether MTE is enabled.

[1] https://lore.kernel.org/all/CAMn1gO4MwRV8bmFJ_SeY5tsYNPn2ZP56LjAhafygjFaKuu5ouw@mail.gmail.com/

---
 arch/arm64/include/asm/mte.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/include/asm/mte.h +2 -2
index 91fbd5c8a3911..0f84518632b4a 100644
@@ -182,7 +182,7 @@ void mte_check_tfsr_el1(void);
 
 static inline void mte_check_tfsr_entry(void)
 {
-	if (!system_supports_mte())
+	if (!kasan_hw_tags_enabled())
 		return;
 
 	mte_check_tfsr_el1();
@@ -190,7 +190,7 @@ static inline void mte_check_tfsr_entry(void)
 
 static inline void mte_check_tfsr_exit(void)
 {
-	if (!system_supports_mte())
+	if (!kasan_hw_tags_enabled())
 		return;
 
 	/*
Signature · 7 lines
2.45.1.288.g0e0cd299f1-goog


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#1 lore raw
Quoted 11 lines · Peter Collingbourne

The check in mte_check_tfsr_el1() is only necessary if HW tag based KASAN is enabled. However, we were also executing the check if MTE is enabled and KASAN is enabled at build time but disabled at runtime. This turned out to cause a measurable increase in power consumption on a specific microarchitecture after enabling MTE. Moreover, on the same system, an increase in invalid syscall latency (as measured by [1]) of around 20-30% (depending on the cluster) was observed after enabling MTE; this almost entirely goes away after removing this check. Therefore, make the check conditional on whether KASAN is enabled rather than on whether MTE is enabled.

Ping.

Peter

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

Reviewed-by on v1 1/1
#2 lore raw
In reply to Peter Collingbourne

Hi,

Quoted 33 lines · Peter Collingbourne

The check in mte_check_tfsr_el1() is only necessary if HW tag based KASAN is enabled. However, we were also executing the check if MTE is enabled and KASAN is enabled at build time but disabled at runtime. This turned out to cause a measurable increase in power consumption on a specific microarchitecture after enabling MTE. Moreover, on the same system, an increase in invalid syscall latency (as measured by [1]) of around 20-30% (depending on the cluster) was observed after enabling MTE; this almost entirely goes away after removing this check. Therefore, make the check conditional on whether KASAN is enabled rather than on whether MTE is enabled.

[1] https://lore.kernel.org/all/CAMn1gO4MwRV8bmFJ_SeY5tsYNPn2ZP56LjAhafygjFaKuu5ouw@mail.gmail.com/

---
 arch/arm64/include/asm/mte.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/include/asm/mte.h +1 -1
index 91fbd5c8a3911..0f84518632b4a 100644
@@ -182,7 +182,7 @@ void mte_check_tfsr_el1(void);
 
 static inline void mte_check_tfsr_entry(void)
 {
-	if (!system_supports_mte())
+	if (!kasan_hw_tags_enabled())
 		return;
 
 	mte_check_tfsr_el1();

arch/arm64/include/asm/mte.h static inline void mte_check_tfsr_entry(void) · line 194

Quoted 6 lines
arch/arm64/include/asm/mte.h +1 -1
@@ -190,7 +190,7 @@ static inline void mte_check_tfsr_entry(void)
 
 static inline void mte_check_tfsr_exit(void)
 {
-	if (!system_supports_mte())
+	if (!kasan_hw_tags_enabled())
 		return;

The change looks correct to me - tag check faults for the kernel are enabled only when hw kasan is enabled. The functions are already compiled only when CONFIG_KASAN_HW_TAGS=y, so it makes sense to further restrict them based on kasan_hw_tags_enabled():

Can't speak for the performance results, altough skipping the dsb + isb on the exit path sure looks nice.

Thanks,
Alex

Quoted 5 lines
arch/arm64/include/asm/mte.h +0 -0
 	/*
Signature · 1 line
2.45.1.288.g0e0cd299f1-goog

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

maintainer Applied
#3 lore raw
In reply to Peter Collingbourne
Quoted 11 lines · Peter Collingbourne

The check in mte_check_tfsr_el1() is only necessary if HW tag based KASAN is enabled. However, we were also executing the check if MTE is enabled and KASAN is enabled at build time but disabled at runtime. This turned out to cause a measurable increase in power consumption on a specific microarchitecture after enabling MTE. Moreover, on the same system, an increase in invalid syscall latency (as measured by [1]) of around 20-30% (depending on the cluster) was observed after enabling MTE; this almost entirely goes away after removing this check. Therefore, make the check conditional on whether KASAN is enabled rather than on whether MTE is enabled.

Quoted 1 line

[...]

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

[1/1] arm64: mte: Make mte_check_tfsr_*() conditional on KASAN instead of MTE

      https://git.kernel.org/arm64/c/26ca4423604f
Signature · 1 line
Catalin