hitmoon / rpms / kernel

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