Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/traps: Have read_cr0() only once in the #NM handler

... instead of twice in the code. In any case, CR0 ends up being read
once anyway:

1. The CONFIG_MATH_EMULATION case does so and exits.
2. The normal case does it once too.

However, read it on function entry instead to make the code even simpler
to follow.

No functional changes.

Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Andy Lutomirski <luto@kernel.org>
Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: x86@kernel.org
Link: https://lkml.kernel.org/r/20190117120728.3811-1-bp@alien8.de

+2 -3
+2 -3
arch/x86/kernel/traps.c
··· 880 880 dotraplinkage void 881 881 do_device_not_available(struct pt_regs *regs, long error_code) 882 882 { 883 - unsigned long cr0; 883 + unsigned long cr0 = read_cr0(); 884 884 885 885 RCU_LOCKDEP_WARN(!rcu_is_watching(), "entry code didn't wake RCU"); 886 886 887 887 #ifdef CONFIG_MATH_EMULATION 888 - if (!boot_cpu_has(X86_FEATURE_FPU) && (read_cr0() & X86_CR0_EM)) { 888 + if (!boot_cpu_has(X86_FEATURE_FPU) && (cr0 & X86_CR0_EM)) { 889 889 struct math_emu_info info = { }; 890 890 891 891 cond_local_irq_enable(regs); ··· 897 897 #endif 898 898 899 899 /* This should not happen. */ 900 - cr0 = read_cr0(); 901 900 if (WARN(cr0 & X86_CR0_TS, "CR0.TS was set")) { 902 901 /* Try to fix it up and carry on. */ 903 902 write_cr0(cr0 & ~X86_CR0_TS);