linuxtorvalds / rpms / kernel

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