2 * Copyright(c) 2017 Intel Corporation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * This code is based in part on work published here:
15 * https://github.com/IAIK/KAISER
17 * The original work was written by and and signed off by for the Linux
20 * Signed-off-by: Richard Fellner <richard.fellner@student.tugraz.at>
21 * Signed-off-by: Moritz Lipp <moritz.lipp@iaik.tugraz.at>
22 * Signed-off-by: Daniel Gruss <daniel.gruss@iaik.tugraz.at>
23 * Signed-off-by: Michael Schwarz <michael.schwarz@iaik.tugraz.at>
25 * Major changes to the original code by: Dave Hansen <dave.hansen@intel.com>
26 * Mostly rewritten by Thomas Gleixner <tglx@linutronix.de> and
27 * Andy Lutomirsky <luto@amacapital.net>
29 #include <linux/kernel.h>
30 #include <linux/errno.h>
31 #include <linux/string.h>
32 #include <linux/types.h>
33 #include <linux/bug.h>
34 #include <linux/init.h>
35 #include <linux/spinlock.h>
37 #include <linux/uaccess.h>
39 #include <asm/cpufeature.h>
40 #include <asm/hypervisor.h>
41 #include <asm/cmdline.h>
43 #include <asm/pgtable.h>
44 #include <asm/pgalloc.h>
45 #include <asm/tlbflush.h>
49 #define pr_fmt(fmt) "Kernel/User page tables isolation: " fmt
51 static void __init pti_print_if_insecure(const char *reason)
53 if (boot_cpu_has_bug(X86_BUG_CPU_INSECURE))
54 pr_info("%s\n", reason);
57 static void __init pti_print_if_secure(const char *reason)
59 if (!boot_cpu_has_bug(X86_BUG_CPU_INSECURE))
60 pr_info("%s\n", reason);
63 void __init pti_check_boottime_disable(void)
68 if (hypervisor_is_type(X86_HYPER_XEN_PV)) {
69 pti_print_if_insecure("disabled on XEN PV.");
73 ret = cmdline_find_option(boot_command_line, "pti", arg, sizeof(arg));
75 if (ret == 3 && !strncmp(arg, "off", 3)) {
76 pti_print_if_insecure("disabled on command line.");
79 if (ret == 2 && !strncmp(arg, "on", 2)) {
80 pti_print_if_secure("force enabled on command line.");
83 if (ret == 4 && !strncmp(arg, "auto", 4))
87 if (cmdline_find_option_bool(boot_command_line, "nopti")) {
88 pti_print_if_insecure("disabled on command line.");
93 if (!boot_cpu_has_bug(X86_BUG_CPU_INSECURE))
96 setup_force_cpu_cap(X86_FEATURE_PTI);
100 * Initialize kernel page table isolation
102 void __init pti_init(void)
104 if (!static_cpu_has(X86_FEATURE_PTI))
107 pr_info("enabled\n");