arm64: mte: Enable TCO in functions that can read beyond buffer limits
[linux-2.6-microblaze.git] / arch / arm64 / include / asm / uaccess.h
index 0deb884..b5f0862 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <asm/cpufeature.h>
 #include <asm/mmu.h>
+#include <asm/mte.h>
 #include <asm/ptrace.h>
 #include <asm/memory.h>
 #include <asm/extable.h>
@@ -188,6 +189,23 @@ static inline void __uaccess_enable_tco(void)
                                 ARM64_MTE, CONFIG_KASAN_HW_TAGS));
 }
 
+/*
+ * These functions disable tag checking only if in MTE async mode
+ * since the sync mode generates exceptions synchronously and the
+ * nofault or load_unaligned_zeropad can handle them.
+ */
+static inline void __uaccess_disable_tco_async(void)
+{
+       if (system_uses_mte_async_mode())
+                __uaccess_disable_tco();
+}
+
+static inline void __uaccess_enable_tco_async(void)
+{
+       if (system_uses_mte_async_mode())
+               __uaccess_enable_tco();
+}
+
 static inline void uaccess_disable_privileged(void)
 {
        __uaccess_disable_tco();
@@ -307,8 +325,10 @@ do {                                                                       \
 do {                                                                   \
        int __gkn_err = 0;                                              \
                                                                        \
+       __uaccess_enable_tco_async();                                   \
        __raw_get_mem("ldr", *((type *)(dst)),                          \
                      (__force type *)(src), __gkn_err);                \
+       __uaccess_disable_tco_async();                                  \
        if (unlikely(__gkn_err))                                        \
                goto err_label;                                         \
 } while (0)
@@ -380,8 +400,10 @@ do {                                                                       \
 do {                                                                   \
        int __pkn_err = 0;                                              \
                                                                        \
+       __uaccess_enable_tco_async();                                   \
        __raw_put_mem("str", *((type *)(src)),                          \
                      (__force type *)(dst), __pkn_err);                \
+       __uaccess_disable_tco_async();                                  \
        if (unlikely(__pkn_err))                                        \
                goto err_label;                                         \
 } while(0)