[RFC PATCH v2 3/6] x86/pti: add a per-cpu variable pti_disable

From: Willy Tarreau
Date: Tue Jan 09 2018 - 07:57:55 EST


This one is updated upon each context switch to reflect the
crrent mm's pti_disable field.

Signed-off-by: Willy Tarreau <w@xxxxxx>
Cc: Andy Lutomirski <luto@xxxxxxxxxx>
Cc: Borislav Petkov <bp@xxxxxxxxx>
Cc: Brian Gerst <brgerst@xxxxxxxxx>
Cc: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
Cc: Kees Cook <keescook@xxxxxxxxxxxx>
---
arch/x86/kernel/process_64.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index 9516310..9bb5908 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -61,6 +61,10 @@

__visible DEFINE_PER_CPU(unsigned long, rsp_scratch);

+#ifdef CONFIG_PAGE_TABLE_ISOLATION
+__visible DEFINE_PER_CPU(unsigned char, pti_disable);
+#endif
+
/* Prints also some state that isn't saved in the pt_regs */
void __show_regs(struct pt_regs *regs, int all)
{
@@ -473,6 +477,11 @@ void compat_start_thread(struct pt_regs *regs, u32 new_ip, u32 new_sp)
task_thread_info(prev_p)->flags & _TIF_WORK_CTXSW_PREV))
__switch_to_xtra(prev_p, next_p, tss);

+#ifdef CONFIG_PAGE_TABLE_ISOLATION
+ this_cpu_write(pti_disable,
+ next_p->mm && next_p->mm->context.pti_disable);
+#endif
+
#ifdef CONFIG_XEN_PV
/*
* On Xen PV, IOPL bits in pt_regs->flags have no effect, and
--
1.7.12.1