aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Hansen <dave.hansen@intel.com>2017-11-06 17:29:53 -0800
committerDave Hansen <dave.hansen@intel.com>2017-11-06 17:29:53 -0800
commitf880b0e248a1760ac626ae19b6d7d6b236c80b89 (patch)
tree5e0b51f65620cf75aa49ae6a710bf48dd76e8656
parent66c2620dc495d74ae0456e9f192410a0a89ee432 (diff)
downloadx86-kaiser-f880b0e248a1760ac626ae19b6d7d6b236c80b89.tar.gz
x86, kaiser: map GDT into user page tables
From: Dave Hansen <dave.hansen@linux.intel.com> The GDT is used to control the x86 segmentation mechanism. It must be virtually mapped when switching segments or at IRET time when switching between userspace and kernel. The original KAISER patch did not do this. I have no ide how it ever worked. Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Cc: Moritz Lipp <moritz.lipp@iaik.tugraz.at> Cc: Daniel Gruss <daniel.gruss@iaik.tugraz.at> Cc: Michael Schwarz <michael.schwarz@iaik.tugraz.at> Cc: Richard Fellner <richard.fellner@student.tugraz.at> Cc: Andy Lutomirski <luto@kernel.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Kees Cook <keescook@google.com> Cc: Hugh Dickins <hughd@google.com> Cc: x86@kernel.org
-rw-r--r--arch/x86/kernel/cpu/common.c15
-rw-r--r--arch/x86/mm/kaiser.c10
2 files changed, 25 insertions, 0 deletions
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 14df4e64680774..0054887900dbf5 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -5,6 +5,7 @@
#include <linux/export.h>
#include <linux/percpu.h>
#include <linux/string.h>
+#include <linux/kaiser.h>
#include <linux/ctype.h>
#include <linux/delay.h>
#include <linux/sched/mm.h>
@@ -487,6 +488,20 @@ static inline void setup_fixmap_gdt(int cpu)
#endif
__set_fixmap(get_cpu_gdt_ro_index(cpu), get_cpu_gdt_paddr(cpu), prot);
+
+ /* CPU 0's mapping is done in kaiser_init() */
+ if (cpu) {
+ int ret;
+
+ ret = kaiser_add_mapping((unsigned long) get_cpu_gdt_ro(cpu),
+ PAGE_SIZE, __PAGE_KERNEL_RO);
+ /*
+ * We do not have a good way to fail CPU bringup.
+ * Just WARN about it and hope we boot far enough
+ * to get a good log out.
+ */
+ WARN_ON(ret);
+ }
}
/* Load the original GDT from the per-cpu structure */
diff --git a/arch/x86/mm/kaiser.c b/arch/x86/mm/kaiser.c
index 8683359a381226..d3f5b889e49e88 100644
--- a/arch/x86/mm/kaiser.c
+++ b/arch/x86/mm/kaiser.c
@@ -356,6 +356,16 @@ void __init kaiser_init(void)
kaiser_add_user_map_early((void *)idt_descr.address,
sizeof(gate_desc) * NR_VECTORS,
__PAGE_KERNEL_RO | _PAGE_GLOBAL);
+
+ /*
+ * We could theoretically do this in setup_fixmap_gdt().
+ * But, we would need to rewrite the above page table
+ * allocation code to use the bootmem allocator. The
+ * buddy allocator is not available at the time that we
+ * call setup_fixmap_gdt() for CPU 0.
+ */
+ kaiser_add_user_map_early(get_cpu_gdt_ro(0), PAGE_SIZE,
+ __PAGE_KERNEL_RO | _PAGE_GLOBAL);
}
int kaiser_add_mapping(unsigned long addr, unsigned long size,