ignatenkobrain / rpms / kernel

Forked from rpms/kernel 3 years ago
Clone
e293be
diff -Naurp a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
e293be
--- a/arch/x86/kernel/cpu/bugs.c	2018-08-10 13:17:43.000000000 -0300
e293be
+++ b/arch/x86/kernel/cpu/bugs.c	2018-08-15 07:09:24.365615125 -0300
e293be
@@ -26,6 +26,70 @@
e293be
 #include <asm/spec_ctrl.h>
e293be
 #include <linux/prctl.h>
e293be
 
e293be
+static int __init no_387(char *s)
e293be
+{
e293be
+	boot_cpu_data.hard_math = 0;
e293be
+	write_cr0(X86_CR0_TS | X86_CR0_EM | X86_CR0_MP | read_cr0());
e293be
+	return 1;
e293be
+}
e293be
+
e293be
+__setup("no387", no_387);
e293be
+
e293be
+static double __initdata x = 4195835.0;
e293be
+static double __initdata y = 3145727.0;
e293be
+
e293be
+/*
e293be
+ * This used to check for exceptions..
e293be
+ * However, it turns out that to support that,
e293be
+ * the XMM trap handlers basically had to
e293be
+ * be buggy. So let's have a correct XMM trap
e293be
+ * handler, and forget about printing out
e293be
+ * some status at boot.
e293be
+ *
e293be
+ * We should really only care about bugs here
e293be
+ * anyway. Not features.
e293be
+ */
e293be
+static void __init check_fpu(void)
e293be
+{
e293be
+	s32 fdiv_bug;
e293be
+
e293be
+	if (!boot_cpu_data.hard_math) {
e293be
+#ifndef CONFIG_MATH_EMULATION
e293be
+		pr_emerg("No coprocessor found and no math emulation present\n");
e293be
+		pr_emerg("Giving up\n");
e293be
+		for (;;) ;
e293be
+#endif
e293be
+		return;
e293be
+	}
e293be
+
e293be
+	kernel_fpu_begin();
e293be
+
e293be
+	/*
e293be
+	 * trap_init() enabled FXSR and company _before_ testing for FP
e293be
+	 * problems here.
e293be
+	 *
e293be
+	 * Test for the divl bug: http://en.wikipedia.org/wiki/Fdiv_bug
e293be
+	 */
e293be
+	__asm__("fninit\n\t"
e293be
+		"fldl %1\n\t"
e293be
+		"fdivl %2\n\t"
e293be
+		"fmull %2\n\t"
e293be
+		"fldl %1\n\t"
e293be
+		"fsubp %%st,%%st(1)\n\t"
e293be
+		"fistpl %0\n\t"
e293be
+		"fwait\n\t"
e293be
+		"fninit"
e293be
+		: "=m" (*&fdiv_bug)
e293be
+		: "m" (*&x), "m" (*&y);;
e293be
+
e293be
+	kernel_fpu_end();
e293be
+
e293be
+	if (fdiv_bug) {
e293be
+		set_cpu_bug(&boot_cpu_data, X86_BUG_FDIV);
e293be
+		pr_warn("Hmm, FPU with FDIV bug\n");
e293be
+	}
e293be
+}
e293be
+
e293be
 static void __init spectre_v2_select_mitigation(void);
e293be
 static void __init ssb_parse_cmdline(void);
e293be
 void ssb_select_mitigation(void);
e293be
@@ -606,8 +670,10 @@ static ssize_t cpu_show_common(struct de
e293be
 
e293be
 	switch (bug) {
e293be
 	case X86_BUG_CPU_MELTDOWN:
e293be
+#ifdef CONFIG_KAISER
e293be
 		if (kaiser_enabled)
e293be
 			return sprintf(buf, "Mitigation: PTI\n");
e293be
+#endif
e293be
 
e293be
 		break;
e293be