kasan, arm64: allow using KUnit tests with HW_TAGS mode
[linux-2.6-microblaze.git] / arch / arm64 / mm / fault.c
index 2e339f0..dc9f964 100644 (file)
@@ -302,12 +302,24 @@ static void die_kernel_fault(const char *msg, unsigned long addr,
 static void report_tag_fault(unsigned long addr, unsigned int esr,
                             struct pt_regs *regs)
 {
-       bool is_write  = ((esr & ESR_ELx_WNR) >> ESR_ELx_WNR_SHIFT) != 0;
+       static bool reported;
+       bool is_write;
+
+       if (READ_ONCE(reported))
+               return;
+
+       /*
+        * This is used for KASAN tests and assumes that no MTE faults
+        * happened before running the tests.
+        */
+       if (mte_report_once())
+               WRITE_ONCE(reported, true);
 
        /*
         * SAS bits aren't set for all faults reported in EL1, so we can't
         * find out access size.
         */
+       is_write = !!(esr & ESR_ELx_WNR);
        kasan_report(addr, 0, is_write, regs->pc);
 }
 #else
@@ -319,12 +331,8 @@ static inline void report_tag_fault(unsigned long addr, unsigned int esr,
 static void do_tag_recovery(unsigned long addr, unsigned int esr,
                           struct pt_regs *regs)
 {
-       static bool reported;
 
-       if (!READ_ONCE(reported)) {
-               report_tag_fault(addr, esr, regs);
-               WRITE_ONCE(reported, true);
-       }
+       report_tag_fault(addr, esr, regs);
 
        /*
         * Disable MTE Tag Checking on the local CPU for the current EL.