config HAVE_SYSCALL
bool
default n
+
+config HAVE_X86PKU
+ bool
+ default n
}
#endif /* CONFIG_HAVE_SYSCALL */
+#if CONFIG_HAVE_X86PKU
+static inline void _check_ospke(void)
+{
+ __u32 eax, ebx, ecx, edx;
+ cpuid(0x7, 0, &eax, &ebx, &ecx, &edx);
+ if (!(ecx & X86_CPUID7_ECX_OSPKE)) {
+ /* if PKU is not enabled, abort the boot process. Images
+ * compiled with HAVE_X86PKU are *specialized* to be executed on
+ * PKU-enabled hardware. This allows us to avoid checks later at
+ * runtime. */
+ UK_CRASH("CPU does not support PKU!\n");
+ }
+}
+#endif /* CONFIG_HAVE_X86PKU */
+
#endif /* __PLAT_COMMON_X86_CPU_H__ */
#define X86_CR4_OSXMMEXCPT (1 << 10) /* OS support for FP exceptions */
#define X86_CR4_FSGSBASE (1 << 16) /* enable FSGSBASE*/
#define X86_CR4_OSXSAVE (1 << 18) /* enable XSAVE, extended states */
+#define X86_CR4_PKE (1 << 22) /* enable protection keys */
/*
* Intel CPU features in EFER
#define X86_CPUID1_EDX_SSE (1 << 25)
/* CPUID feature bits in EBX and ECX when EAX=7, ECX=0 */
#define X86_CPUID7_EBX_FSGSBASE (1 << 0)
+#define X86_CPUID7_ECX_PKU (1 << 3)
+#define X86_CPUID7_ECX_OSPKE (1 << 4)
/* CPUID feature bits when EAX=0xd, ECX=1 */
#define X86_CPUIDD1_EAX_XSAVEOPT (1<<0)
/* CPUID 80000001H:EDX feature list */
#include <kvm-x86/traps.h>
#include <kvm-x86/multiboot_defs.h>
+/* necessary for CONFIG_ macros to be accessible */
+#include <uk/config.h>
+
#define ENTRY(x) .globl x; .type x,%function; x:
#define END(x) .size x, . - x
orl $(X86_CR4_FSGSBASE), %edi
movq %rdi, %cr4
nofsgsbase:
+#if CONFIG_HAVE_X86PKU
+ /* check for Memory Protection Keys (PKU) */
+ testl $(X86_CPUID7_ECX_PKU), %ecx
+ jz nopku
+ /* if PKU is supported, enable it via CR4 */
+ orl $(X86_CR4_PKE), %edi
+ movq %rdi, %cr4
+nopku:
+#endif /* CONFIG_HAVE_X86PKU */
/* done setting up CPU capabilities */
/* read multiboot info pointer */
_init_syscall();
#endif /* CONFIG_HAVE_SYSCALL */
+#if CONFIG_HAVE_X86PKU
+ _check_ospke();
+#endif /* CONFIG_HAVE_X86PKU */
+
/*
* Switch away from the bootstrap stack as early as possible.
*/