struct hash_pte *Hash, *Hash_end;
 unsigned long Hash_size, Hash_mask;
 unsigned long _SDR1;
+static unsigned int hash_mb, hash_mb2;
 
 struct ppc_bat BATS[8][2];     /* 8 pairs of IBAT, DBAT */
 
  */
 void __init MMU_init_hw(void)
 {
-       unsigned int hmask, mb, mb2;
        unsigned int n_hpteg, lg_n_hpteg;
 
        if (!mmu_has_feature(MMU_FTR_HPTE_TABLE))
               (unsigned long long)(total_memory >> 20), Hash_size >> 10, Hash);
 
 
-       /*
-        * Patch up the instructions in hashtable.S:create_hpte
-        */
-       if ( ppc_md.progress ) ppc_md.progress("hash:patch", 0x345);
        Hash_mask = n_hpteg - 1;
-       hmask = Hash_mask >> (16 - LG_HPTEG_SIZE);
-       mb2 = mb = 32 - LG_HPTEG_SIZE - lg_n_hpteg;
+       hash_mb2 = hash_mb = 32 - LG_HPTEG_SIZE - lg_n_hpteg;
        if (lg_n_hpteg > 16)
-               mb2 = 16 - LG_HPTEG_SIZE;
+               hash_mb2 = 16 - LG_HPTEG_SIZE;
+}
+
+void __init MMU_init_hw_patch(void)
+{
+       unsigned int hmask = Hash_mask >> (16 - LG_HPTEG_SIZE);
 
+       if (ppc_md.progress)
+               ppc_md.progress("hash:patch", 0x345);
+       if (ppc_md.progress)
+               ppc_md.progress("hash:done", 0x205);
+
+       /* WARNING: Make sure nothing can trigger a KASAN check past this point */
+
+       /*
+        * Patch up the instructions in hashtable.S:create_hpte
+        */
        modify_instruction_site(&patch__hash_page_A0, 0xffff,
                                ((unsigned int)Hash - PAGE_OFFSET) >> 16);
-       modify_instruction_site(&patch__hash_page_A1, 0x7c0, mb << 6);
-       modify_instruction_site(&patch__hash_page_A2, 0x7c0, mb2 << 6);
+       modify_instruction_site(&patch__hash_page_A1, 0x7c0, hash_mb << 6);
+       modify_instruction_site(&patch__hash_page_A2, 0x7c0, hash_mb2 << 6);
        modify_instruction_site(&patch__hash_page_B, 0xffff, hmask);
        modify_instruction_site(&patch__hash_page_C, 0xffff, hmask);
 
         */
        modify_instruction_site(&patch__flush_hash_A0, 0xffff,
                                ((unsigned int)Hash - PAGE_OFFSET) >> 16);
-       modify_instruction_site(&patch__flush_hash_A1, 0x7c0, mb << 6);
-       modify_instruction_site(&patch__flush_hash_A2, 0x7c0, mb2 << 6);
+       modify_instruction_site(&patch__flush_hash_A1, 0x7c0, hash_mb << 6);
+       modify_instruction_site(&patch__flush_hash_A2, 0x7c0, hash_mb2 << 6);
        modify_instruction_site(&patch__flush_hash_B, 0xffff, hmask);
-
-       if ( ppc_md.progress ) ppc_md.progress("hash:done", 0x205);
 }
 
 void setup_initial_memory_limit(phys_addr_t first_memblock_base,