jianhai / rpms / kernel

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