x86/mm: Get rid of VM_BUG_ON in switch_tlb_irqs_off()

If we hit the VM_BUG_ON(), we're detecting a genuinely bad situation,
but we're very unlikely to get a useful call trace.

Make it a warning instead.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bpetkov@suse.de>
Cc: Jiri Kosina <jikos@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/3b4e06bbb382ca54a93218407c93925ff5871546.1504847163.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Andy Lutomirski and committed by
Ingo Molnar
a376e7f9 6d8ef53e

+21 -1
+21 -1
arch/x86/mm/tlb.c
··· 121 121 * hypothetical buggy code that directly switches to swapper_pg_dir 122 122 * without going through leave_mm() / switch_mm_irqs_off() or that 123 123 * does something like write_cr3(read_cr3_pa()). 124 + * 125 + * Only do this check if CONFIG_DEBUG_VM=y because __read_cr3() 126 + * isn't free. 124 127 */ 125 - VM_BUG_ON(__read_cr3() != (__sme_pa(real_prev->pgd) | prev_asid)); 128 + #ifdef CONFIG_DEBUG_VM 129 + if (WARN_ON_ONCE(__read_cr3() != 130 + (__sme_pa(real_prev->pgd) | prev_asid))) { 131 + /* 132 + * If we were to BUG here, we'd be very likely to kill 133 + * the system so hard that we don't see the call trace. 134 + * Try to recover instead by ignoring the error and doing 135 + * a global flush to minimize the chance of corruption. 136 + * 137 + * (This is far from being a fully correct recovery. 138 + * Architecturally, the CPU could prefetch something 139 + * back into an incorrect ASID slot and leave it there 140 + * to cause trouble down the road. It's better than 141 + * nothing, though.) 142 + */ 143 + __flush_tlb_all(); 144 + } 145 + #endif 126 146 127 147 if (real_prev == next) { 128 148 VM_BUG_ON(this_cpu_read(cpu_tlbstate.ctxs[prev_asid].ctx_id) !=