Re: [PATCH 2/2] arch/x86: arch/sparc: tools/perf: fix typos in comments

2021-04-09 Thread Alexandre Chartre
++-- 4 files changed, 5 insertions(+), 5 deletions(-) Reviewed-by: Alexandre Chartre alex.

Re: [PATCH 1/2] x86/traps: call cond_local_irq_disable before returning from exc_general_protection and math_error

2021-04-09 Thread Alexandre Chartre
+-- 1 file changed, 2 insertions(+), 2 deletions(-) Reviewed-by: Alexandre Chartre And it is probably worth adding a 'Fixes:' tag: Fixes: 334872a09198 ("x86/traps: Attempt to fixup exceptions in vDSO before signaling") alex.

Re: [for-stable-4.19 PATCH 1/2] vmlinux.lds.h: Create section for protection against instrumentation

2021-03-19 Thread Alexandre Chartre
instrumentation markers are only active when CONFIG_DEBUG_ENTRY is enabled as the end marker emits a NOP to prevent the compiler from merging the annotation points. This means the objtool verification requires a kernel compiled with this option. Signed-off-by: Thomas Gleixner Reviewed-by: Alexandre

Re: [RFC][PATCH v2 12/21] x86/pti: Use PTI stack instead of trampoline stack

2020-11-19 Thread Alexandre Chartre
On 11/19/20 8:10 PM, Thomas Gleixner wrote: On Mon, Nov 16 2020 at 19:10, Alexandre Chartre wrote: On 11/16/20 5:57 PM, Andy Lutomirski wrote: On Mon, Nov 16, 2020 at 6:47 AM Alexandre Chartre wrote: When executing more code in the kernel, we are likely to reach a point where we need to

Re: [RFC][PATCH v2 12/21] x86/pti: Use PTI stack instead of trampoline stack

2020-11-19 Thread Alexandre Chartre
On 11/19/20 5:06 PM, Andy Lutomirski wrote: On Thu, Nov 19, 2020 at 4:06 AM Alexandre Chartre wrote: On 11/19/20 9:05 AM, Alexandre Chartre wrote: When entering the kernel from userland, use the per-task PTI stack instead of the per-cpu trampoline stack. Like the trampoline stack, the PTI

Re: [RFC][PATCH v2 12/21] x86/pti: Use PTI stack instead of trampoline stack

2020-11-19 Thread Alexandre Chartre
On 11/19/20 9:05 AM, Alexandre Chartre wrote: When entering the kernel from userland, use the per-task PTI stack instead of the per-cpu trampoline stack. Like the trampoline stack, the PTI stack is mapped both in the kernel and in the user page-table. Using a per-task stack which is mapped

Re: [RFC][PATCH v2 12/21] x86/pti: Use PTI stack instead of trampoline stack

2020-11-19 Thread Alexandre Chartre
On 11/19/20 2:49 AM, Andy Lutomirski wrote: On Tue, Nov 17, 2020 at 8:59 AM Alexandre Chartre wrote: On 11/17/20 4:52 PM, Andy Lutomirski wrote: On Tue, Nov 17, 2020 at 7:07 AM Alexandre Chartre wrote: On 11/16/20 7:34 PM, Andy Lutomirski wrote: On Mon, Nov 16, 2020 at 10:10 AM

Re: [RFC][PATCH v2 00/21] x86/pti: Defer CR3 switch to C code

2020-11-18 Thread Alexandre Chartre
On 11/18/20 12:29 PM, Borislav Petkov wrote: On Wed, Nov 18, 2020 at 08:41:42AM +0100, Alexandre Chartre wrote: Well, it looks like I wrongfully assume that KPTI was a well known performance overhead since it was introduced (because it adds extra page-table switches), but you are right I

Re: [RFC][PATCH v2 00/21] x86/pti: Defer CR3 switch to C code

2020-11-18 Thread Alexandre Chartre
On 11/18/20 2:22 PM, David Laight wrote: From: Alexandre Chartre Sent: 18 November 2020 10:30 ... Correct, this RFC is not changing the overhead. However, it is a step forward for being able to execute some selected syscalls or interrupt handlers without switching to the kernel page-table

Re: [RFC][PATCH v2 00/21] x86/pti: Defer CR3 switch to C code

2020-11-18 Thread Alexandre Chartre
On 11/18/20 10:30 AM, David Laight wrote: From: Alexandre Chartre Sent: 18 November 2020 07:42 On 11/17/20 10:26 PM, Borislav Petkov wrote: On Tue, Nov 17, 2020 at 07:12:07PM +0100, Alexandre Chartre wrote: Some benchmarks are available, in particular from phoronix: What I was expecting

Re: [RFC][PATCH v2 00/21] x86/pti: Defer CR3 switch to C code

2020-11-17 Thread Alexandre Chartre
On 11/17/20 10:26 PM, Borislav Petkov wrote: On Tue, Nov 17, 2020 at 07:12:07PM +0100, Alexandre Chartre wrote: Some benchmarks are available, in particular from phoronix: What I was expecting was benchmarks *you* have run which show that perf penalty, not something one can find quickly on

Re: [RFC][PATCH v2 00/21] x86/pti: Defer CR3 switch to C code

2020-11-17 Thread Alexandre Chartre
On 11/17/20 10:23 PM, Borislav Petkov wrote: On Tue, Nov 17, 2020 at 08:02:51PM +0100, Alexandre Chartre wrote: No. This prevents the guest VM from gathering data from the host kernel on the same cpu-thread. But there's no mitigation for a guest VM running on a cpu-thread attacking an

Re: [RFC][PATCH v2 00/21] x86/pti: Defer CR3 switch to C code

2020-11-17 Thread Alexandre Chartre
On 11/17/20 7:28 PM, Borislav Petkov wrote: On Tue, Nov 17, 2020 at 07:12:07PM +0100, Alexandre Chartre wrote: Yes. L1TF/MDS allow some inter cpu-thread attacks which are not mitigated at the moment. In particular, this allows a guest VM to attack another guest VM or the host kernel running

Re: [RFC][PATCH v2 00/21] x86/pti: Defer CR3 switch to C code

2020-11-17 Thread Alexandre Chartre
On 11/17/20 6:07 PM, Borislav Petkov wrote: On Tue, Nov 17, 2020 at 09:19:01AM +0100, Alexandre Chartre wrote: We are not reversing PTI, we are extending it. You're reversing it in the sense that you're mapping more kernel memory into the user page table than what is mapped

Re: [RFC][PATCH v2 00/21] x86/pti: Defer CR3 switch to C code

2020-11-17 Thread Alexandre Chartre
On 11/17/20 5:55 PM, Borislav Petkov wrote: On Tue, Nov 17, 2020 at 08:56:23AM +0100, Alexandre Chartre wrote: The main goal of ASI is to provide KVM address space isolation to mitigate guest-to-host speculative attacks like L1TF or MDS. Because the current L1TF and MDS mitigations are

Re: [RFC][PATCH v2 12/21] x86/pti: Use PTI stack instead of trampoline stack

2020-11-17 Thread Alexandre Chartre
On 11/17/20 4:52 PM, Andy Lutomirski wrote: On Tue, Nov 17, 2020 at 7:07 AM Alexandre Chartre wrote: On 11/16/20 7:34 PM, Andy Lutomirski wrote: On Mon, Nov 16, 2020 at 10:10 AM Alexandre Chartre wrote: On 11/16/20 5:57 PM, Andy Lutomirski wrote: On Mon, Nov 16, 2020 at 6:47 AM

Re: [RFC][PATCH v2 12/21] x86/pti: Use PTI stack instead of trampoline stack

2020-11-17 Thread Alexandre Chartre
On 11/16/20 7:34 PM, Andy Lutomirski wrote: On Mon, Nov 16, 2020 at 10:10 AM Alexandre Chartre wrote: On 11/16/20 5:57 PM, Andy Lutomirski wrote: On Mon, Nov 16, 2020 at 6:47 AM Alexandre Chartre wrote: When entering the kernel from userland, use the per-task PTI stack instead of the

Re: [RFC][PATCH v2 11/21] x86/pti: Extend PTI user mappings

2020-11-17 Thread Alexandre Chartre
On 11/17/20 12:06 AM, Andy Lutomirski wrote: On Mon, Nov 16, 2020 at 12:18 PM Alexandre Chartre wrote: On 11/16/20 8:48 PM, Andy Lutomirski wrote: On Mon, Nov 16, 2020 at 6:49 AM Alexandre Chartre wrote: Extend PTI user mappings so that more kernel entry code can be executed with the

Re: [RFC][PATCH v2 12/21] x86/pti: Use PTI stack instead of trampoline stack

2020-11-17 Thread Alexandre Chartre
On 11/16/20 10:24 PM, David Laight wrote: From: Alexandre Chartre Sent: 16 November 2020 18:10 On 11/16/20 5:57 PM, Andy Lutomirski wrote: On Mon, Nov 16, 2020 at 6:47 AM Alexandre Chartre wrote: When entering the kernel from userland, use the per-task PTI stack instead of the per-cpu

Re: [RFC][PATCH v2 00/21] x86/pti: Defer CR3 switch to C code

2020-11-17 Thread Alexandre Chartre
On 11/16/20 9:24 PM, Borislav Petkov wrote: On Mon, Nov 16, 2020 at 03:47:36PM +0100, Alexandre Chartre wrote: Deferring CR3 switch to C code means that we need to run more of the kernel entry code with the user page-table. To do so, we need to: - map more syscall, interrupt and exception

Re: [RFC][PATCH v2 00/21] x86/pti: Defer CR3 switch to C code

2020-11-16 Thread Alexandre Chartre
On 11/16/20 9:17 PM, Borislav Petkov wrote: On Mon, Nov 16, 2020 at 03:47:36PM +0100, Alexandre Chartre wrote: This RFC proposes to defer the PTI CR3 switch until we reach C code. The benefit is that this simplifies the assembly entry code, and make the PTI CR3 switch code easier to

Re: [RFC][PATCH v2 11/21] x86/pti: Extend PTI user mappings

2020-11-16 Thread Alexandre Chartre
On 11/16/20 8:48 PM, Andy Lutomirski wrote: On Mon, Nov 16, 2020 at 6:49 AM Alexandre Chartre wrote: Extend PTI user mappings so that more kernel entry code can be executed with the user page-table. To do so, we need to map syscall and interrupt entry code, per cpu offsets (__per_cpu_offset

Re: [RFC][PATCH v2 12/21] x86/pti: Use PTI stack instead of trampoline stack

2020-11-16 Thread Alexandre Chartre
On 11/16/20 7:34 PM, Andy Lutomirski wrote: On Mon, Nov 16, 2020 at 10:10 AM Alexandre Chartre wrote: On 11/16/20 5:57 PM, Andy Lutomirski wrote: On Mon, Nov 16, 2020 at 6:47 AM Alexandre Chartre wrote: When entering the kernel from userland, use the per-task PTI stack instead of the

Re: [RFC][PATCH v2 21/21] x86/pti: Use a different stack canary with the user and kernel page-table

2020-11-16 Thread Alexandre Chartre
On 11/16/20 5:56 PM, Andy Lutomirski wrote: On Mon, Nov 16, 2020 at 6:48 AM Alexandre Chartre wrote: Using stack protector requires the stack canary to be mapped into the current page-table. Now that the page-table switch between the user and kernel page-table is deferred to C code, stack

Re: [RFC][PATCH v2 12/21] x86/pti: Use PTI stack instead of trampoline stack

2020-11-16 Thread Alexandre Chartre
On 11/16/20 5:57 PM, Andy Lutomirski wrote: On Mon, Nov 16, 2020 at 6:47 AM Alexandre Chartre wrote: When entering the kernel from userland, use the per-task PTI stack instead of the per-cpu trampoline stack. Like the trampoline stack, the PTI stack is mapped both in the kernel and in the

[RFC][PATCH v2 20/21] x86/pti: Defer CR3 switch to C code for non-IST and syscall entries

2020-11-16 Thread Alexandre Chartre
With PTI, syscall/interrupt/exception entries switch the CR3 register to change the page-table in assembly code. Move the CR3 register switch inside the C code of syscall/interrupt/exception entry handlers. Signed-off-by: Alexandre Chartre --- arch/x86/entry/common.c | 15

[RFC][PATCH v2 14/21] x86/pti: Execute IDT handlers on the kernel stack

2020-11-16 Thread Alexandre Chartre
kernel data leak to the userland through the stack. For now, only changes IDT handlers which have no argument other than the pt_regs registers. Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/idtentry.h | 43 +++-- arch/x86/kernel/cpu/mce/core.c | 2 +- arch

[RFC][PATCH v2 19/21] x86/pti: Defer CR3 switch to C code for IST entries

2020-11-16 Thread Alexandre Chartre
IST entries from the kernel use paranoid entry and exit assembly functions to ensure the CR3 and GS registers are updated with correct values for the kernel. Move the update of the CR3 inside the C code of IST handlers. Signed-off-by: Alexandre Chartre --- arch/x86/entry/entry_64.S | 34

[RFC][PATCH v2 09/21] x86/pti: Function to clone page-table entries from a specified mm

2020-11-16 Thread Alexandre Chartre
PTI has a function to clone page-table entries but only from the init_mm page-table. Provide a new function to clone page-table entries from a specified mm page-table. Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/pti.h | 10 ++ arch/x86/mm/pti.c | 32

[RFC][PATCH v2 06/21] x86/pti: Provide C variants of PTI switch CR3 macros

2020-11-16 Thread Alexandre Chartre
Page Table Isolation (PTI) use assembly macros to switch the CR3 register between kernel and user page-tables. Add C functions which implement the same features. For now, these C functions are not used but they will eventually replace using the assembly macros. Signed-off-by: Alexandre Chartre

[RFC][PATCH v2 17/21] x86/pti: Execute page fault handler on the kernel stack

2020-11-16 Thread Alexandre Chartre
leak to the userland through the stack. Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/idtentry.h | 17 + arch/x86/mm/fault.c | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/idtentry.h b/arch/x86/include/asm

[RFC][PATCH v2 13/21] x86/pti: Execute syscall functions on the kernel stack

2020-11-16 Thread Alexandre Chartre
userland through the stack. Signed-off-by: Alexandre Chartre --- arch/x86/entry/common.c | 11 ++- arch/x86/entry/entry_64.S| 1 + arch/x86/include/asm/irq_stack.h | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/x86/entry/common.c b/arch/x86

[RFC][PATCH v2 15/21] x86/pti: Execute IDT handlers with error code on the kernel stack

2020-11-16 Thread Alexandre Chartre
kernel data leak to the userland through the stack. Changes IDT handlers which have an error code. Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/idtentry.h | 18 -- arch/x86/kernel/traps.c | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a

[RFC][PATCH v2 16/21] x86/pti: Execute system vector handlers on the kernel stack

2020-11-16 Thread Alexandre Chartre
kernel data leak to the userland through the stack. Changes system vector handlers to execute on the kernel stack. Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/idtentry.h | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/idtentry.h b

[RFC][PATCH v2 10/21] x86/pti: Function to map per-cpu page-table entry

2020-11-16 Thread Alexandre Chartre
Wrap the code used by PTI to map a per-cpu page-table entry into a new function so that this code can be re-used to map other per-cpu entries. Signed-off-by: Alexandre Chartre --- arch/x86/mm/pti.c | 25 - 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a

[RFC][PATCH v2 02/21] x86/entry: Update asm_call_on_stack to support more function arguments

2020-11-16 Thread Alexandre Chartre
Update the asm_call_on_stack() function so that it can be invoked with a function having up to three arguments instead of only one. Signed-off-by: Alexandre Chartre --- arch/x86/entry/entry_64.S| 15 +++ arch/x86/include/asm/irq_stack.h | 8 2 files changed, 19

[RFC][PATCH v2 21/21] x86/pti: Use a different stack canary with the user and kernel page-table

2020-11-16 Thread Alexandre Chartre
page-table. To prevent leaking the stack canary used with the kernel page-table, use a different canary with the user and kernel page-table. The stack canary is changed when switching the page-table. Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/entry-common.h | 56

[RFC][PATCH v2 11/21] x86/pti: Extend PTI user mappings

2020-11-16 Thread Alexandre Chartre
). Signed-off-by: Alexandre Chartre --- arch/x86/entry/entry_64.S | 2 -- arch/x86/mm/pti.c | 19 +++ kernel/fork.c | 22 ++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index

[RFC][PATCH v2 18/21] x86/pti: Execute NMI handler on the kernel stack

2020-11-16 Thread Alexandre Chartre
userland through the stack. Signed-off-by: Alexandre Chartre --- arch/x86/kernel/nmi.c | 14 -- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c index 4bc77aaf1303..be0f654c3095 100644 --- a/arch/x86/kernel/nmi.c +++ b/arch

[RFC][PATCH v2 05/21] x86/entry: Implement ret_from_fork body with C code

2020-11-16 Thread Alexandre Chartre
ret_from_fork is a mix of assembly code and calls to C functions. Re-implement ret_from_fork so that it calls a single C function. Signed-off-by: Alexandre Chartre --- arch/x86/entry/common.c | 18 ++ arch/x86/entry/entry_64.S | 28 +--- 2 files changed

[RFC][PATCH v2 04/21] x86/sev-es: Define a setup stack function for the VC idtentry

2020-11-16 Thread Alexandre Chartre
is also refactored to just return the stack pointer, and the stack configuration is done in the setup stack function (so that the stack can be also be used to propagate CR3 switch information to the idtentry handler for switching CR3 back). Signed-off-by: Alexandre Chartre --- arch/x86/entry

[RFC][PATCH v2 08/21] x86/pti: Introduce per-task PTI trampoline stack

2020-11-16 Thread Alexandre Chartre
trampoline stack. This will allow running more code on the trampoline stack, in particular code that schedules the task out. Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/page_64_types.h | 36 +++- arch/x86/include/asm/processor.h | 3 +++ 2 files changed, 38

[RFC][PATCH v2 01/21] x86/syscall: Add wrapper for invoking syscall function

2020-11-16 Thread Alexandre Chartre
Add a wrapper function for invoking a syscall function. Signed-off-by: Alexandre Chartre --- arch/x86/entry/common.c | 16 +--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c index 870efeec8bda..d12908ad 100644

[RFC][PATCH v2 00/21] x86/pti: Defer CR3 switch to C code

2020-11-16 Thread Alexandre Chartre
64-bit at the moment, I haven't looked at 32-bit yet but I will definitively check it. Patches are based on v5.10-rc4. Thanks, alex. ----- Alexandre Chartre (21): x86/syscall: Add wrapper for invoking syscall function x86/entry: Update asm_call_on_stack to support more function argume

[RFC][PATCH v2 07/21] x86/entry: Fill ESPFIX stack using C code

2020-11-16 Thread Alexandre Chartre
The ESPFIX stack is filled using assembly code. Move this code to a C function so that it is easier to read and modify. Signed-off-by: Alexandre Chartre --- arch/x86/entry/entry_64.S | 62 ++--- arch/x86/kernel/espfix_64.c | 41 2 files

[RFC][PATCH v2 12/21] x86/pti: Use PTI stack instead of trampoline stack

2020-11-16 Thread Alexandre Chartre
per-cpu stack will allow executing more code before switching to the kernel stack and to the kernel page-table. Additional changes will be made to later to switch to the kernel stack (which is only mapped in the kernel page-table). Signed-off-by: Alexandre Chartre --- arch/x86/entry/entry_64.S

[RFC][PATCH v2 03/21] x86/entry: Consolidate IST entry from userspace

2020-11-16 Thread Alexandre Chartre
this code into a single assembly macro. Signed-off-by: Alexandre Chartre --- arch/x86/entry/entry_64.S | 137 +- 1 file changed, 75 insertions(+), 62 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index c42948aca0a8

Re: [PATCH v8 -tip 13/26] kernel/entry: Add support for core-wide protection of kernel-mode

2020-11-16 Thread Alexandre Chartre
On 11/10/20 11:42 PM, Joel Fernandes wrote: On Tue, Nov 10, 2020 at 10:35:17AM +0100, Alexandre Chartre wrote: [..] ---8<--- From b2835a587a28405ffdf8fc801e798129a014a8c8 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Mon, 27 Jul 2020 1

Re: [RFC][PATCH 13/24] x86/pti: Extend PTI user mappings

2020-11-11 Thread Alexandre Chartre
On 11/11/20 12:39 AM, Andy Lutomirski wrote: On 11/9/20 6:28 PM, Andy Lutomirski wrote: On Mon, Nov 9, 2020 at 3:22 AM Alexandre Chartre wrote: Extend PTI user mappings so that more kernel entry code can be executed with the user page-table. To do so, we need to map syscall and interrupt

Re: [PATCH v8 -tip 13/26] kernel/entry: Add support for core-wide protection of kernel-mode

2020-11-10 Thread Alexandre Chartre
On 11/3/20 2:20 AM, Joel Fernandes wrote: Hi Alexandre, Sorry for late reply as I was working on the snapshotting patch... On Fri, Oct 30, 2020 at 11:29:26AM +0100, Alexandre Chartre wrote: On 10/20/20 3:43 AM, Joel Fernandes (Google) wrote: Core-scheduling prevents hyperthreads in

Re: [RFC][PATCH 08/24] x86/entry: Add C version of SWAPGS and SWAPGS_UNSAFE_STACK

2020-11-09 Thread Alexandre Chartre
[Copying the reply to Andy in the thread with the right email addresses] On 11/9/20 6:38 PM, Andy Lutomirski wrote: On Mon, Nov 9, 2020 at 3:22 AM Alexandre Chartre wrote: SWAPGS and SWAPGS_UNSAFE_STACK are assembly macros. Add C versions of these macros (swapgs() and swapgs_unsafe_stack

Re: [RFC][PATCH 13/24] x86/pti: Extend PTI user mappings

2020-11-09 Thread Alexandre Chartre
[Copying the reply to Andy in the thread with the right email addresses] On 11/9/20 6:28 PM, Andy Lutomirski wrote: On Mon, Nov 9, 2020 at 3:22 AM Alexandre Chartre wrote: Extend PTI user mappings so that more kernel entry code can be executed with the user page-table. To do so, we need to

Re: [RFC][PATCH 00/24] x86/pti: Defer CR3 switch to C code

2020-11-09 Thread Alexandre Chartre
On 11/9/20 8:35 PM, Dave Hansen wrote: On 11/9/20 6:44 AM, Alexandre Chartre wrote: - map more syscall, interrupt and exception entry code into the user page-table (map all noinstr code); This seems like the thing we'd want to tag explicitly rather than make it implicit with &#x

Re: [RFC][PATCH 08/24] x86/entry: Add C version of SWAPGS and SWAPGS_UNSAFE_STACK

2020-11-09 Thread Alexandre Chartre
On 11/9/20 6:38 PM, Andy Lutomirski wrote: On Mon, Nov 9, 2020 at 3:22 AM Alexandre Chartre wrote: SWAPGS and SWAPGS_UNSAFE_STACK are assembly macros. Add C versions of these macros (swapgs() and swapgs_unsafe_stack()). This needs a very good justification. It also needs some kind of

Re: [RFC][PATCH 13/24] x86/pti: Extend PTI user mappings

2020-11-09 Thread Alexandre Chartre
On 11/9/20 6:28 PM, Andy Lutomirski wrote: On Mon, Nov 9, 2020 at 3:22 AM Alexandre Chartre wrote: Extend PTI user mappings so that more kernel entry code can be executed with the user page-table. To do so, we need to map syscall and interrupt entry code, Probably fine. per cpu offsets

Re: [RFC][PATCH 01/24] x86/syscall: Add wrapper for invoking syscall function

2020-11-09 Thread Alexandre Chartre
not me. Can you fix this? I known, I messed up :-( I have already resent the entire RFC with correct addresses. Sorry about that. alex. On Mon, Nov 9, 2020 at 3:21 AM Alexandre Chartre wrote: Add a wrapper function for invoking a syscall function. This needs some explanation of why.

[RFC][PATCH 15/24] x86/pti: Execute syscall functions on the kernel stack

2020-11-09 Thread Alexandre Chartre
userland through the stack. Signed-off-by: Alexandre Chartre --- arch/x86/entry/common.c | 11 ++- arch/x86/entry/entry_64.S| 1 + arch/x86/include/asm/irq_stack.h | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/x86/entry/common.c b/arch/x86

[RFC][PATCH 18/24] x86/pti: Execute system vector handlers on the kernel stack

2020-11-09 Thread Alexandre Chartre
kernel data leak to the userland through the stack. Changes system vector handlers to execute on the kernel stack. Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/idtentry.h | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/idtentry.h b

[RFC][PATCH 12/24] x86/pti: Function to map per-cpu page-table entry

2020-11-09 Thread Alexandre Chartre
Wrap the code used by PTI to map a per-cpu page-table entry into a new function so that this code can be re-used to map other per-cpu entries. Signed-off-by: Alexandre Chartre --- arch/x86/mm/pti.c | 25 - 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a

[RFC][PATCH 11/24] x86/pti: Function to clone page-table entries from a specified mm

2020-11-09 Thread Alexandre Chartre
PTI has a function to clone page-table entries but only from the init_mm page-table. Provide a new function to clone page-table entries from a specified mm page-table. Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/pti.h | 10 ++ arch/x86/mm/pti.c | 32

[RFC][PATCH 17/24] x86/pti: Execute IDT handlers with error code on the kernel stack

2020-11-09 Thread Alexandre Chartre
kernel data leak to the userland through the stack. Changes IDT handlers which have an error code. Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/idtentry.h | 18 -- arch/x86/kernel/traps.c | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a

[RFC][PATCH 24/24] x86/pti: Defer CR3 switch to C code for non-IST and syscall entries

2020-11-09 Thread Alexandre Chartre
With PTI, syscall/interrupt/exception entries switch the CR3 register to change the page-table in assembly code. Move the CR3 register switch inside the C code of syscall/interrupt/exception entry handlers. Signed-off-by: Alexandre Chartre --- arch/x86/entry/common.c | 15

[RFC][PATCH 23/24] x86/entry: Remove paranoid_entry and paranoid_exit

2020-11-09 Thread Alexandre Chartre
The paranoid_entry and paranoid_exit assembly functions have been replaced by the kernel_paranoid_entry() and kernel_paranoid_exit() C functions. Now paranoid_entry/exit are not used anymore and can be removed. Signed-off-by: Alexandre Chartre --- arch/x86/entry/entry_64.S | 131

[RFC][PATCH 22/24] x86/entry: Defer paranoid entry/exit to C code

2020-11-09 Thread Alexandre Chartre
IST entries from the kernel use paranoid entry and exit assembly functions to ensure the CR3 and GS registers are updated with correct values for the kernel. Move the update of the CR3 and GS registers inside the C code of IST handlers. Signed-off-by: Alexandre Chartre --- arch/x86/entry

[RFC][PATCH 14/24] x86/pti: Use PTI stack instead of trampoline stack

2020-11-09 Thread Alexandre Chartre
per-cpu stack will allow executing more code before switching to the kernel stack and to the kernel page-table. Additional changes will be made to later to switch to the kernel stack (which is only mapped in the kernel page-table). Signed-off-by: Alexandre Chartre --- arch/x86/entry/entry_64.S

[RFC][PATCH 21/24] x86/entry: Disable stack-protector for IST entry C handlers

2020-11-09 Thread Alexandre Chartre
entry C handlers where the GS register setup will eventually happen. Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/idtentry.h | 25 - arch/x86/kernel/nmi.c | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm

[RFC][PATCH 08/24] x86/entry: Add C version of SWAPGS and SWAPGS_UNSAFE_STACK

2020-11-09 Thread Alexandre Chartre
SWAPGS and SWAPGS_UNSAFE_STACK are assembly macros. Add C versions of these macros (swapgs() and swapgs_unsafe_stack()). Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/paravirt.h | 15 +++ arch/x86/include/asm/paravirt_types.h | 17 - 2 files changed

[RFC][PATCH 05/24] x86/entry: Implement ret_from_fork body with C code

2020-11-09 Thread Alexandre Chartre
ret_from_fork is a mix of assembly code and calls to C functions. Re-implement ret_from_fork so that it calls a single C function. Signed-off-by: Alexandre Chartre --- arch/x86/entry/common.c | 18 ++ arch/x86/entry/entry_64.S | 28 +--- 2 files changed

[RFC][PATCH 13/24] x86/pti: Extend PTI user mappings

2020-11-09 Thread Alexandre Chartre
). Signed-off-by: Alexandre Chartre --- arch/x86/entry/entry_64.S | 2 -- arch/x86/mm/pti.c | 14 ++ kernel/fork.c | 22 ++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index

[RFC][PATCH 10/24] x86/pti: Introduce per-task PTI trampoline stack

2020-11-09 Thread Alexandre Chartre
trampoline stack. This will allow running more code on the trampoline stack, in particular code that schedules the task out. Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/page_64_types.h | 36 +++- arch/x86/include/asm/processor.h | 3 +++ 2 files changed, 38

[RFC][PATCH 19/24] x86/pti: Execute page fault handler on the kernel stack

2020-11-09 Thread Alexandre Chartre
leak to the userland through the stack. Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/idtentry.h | 17 + arch/x86/mm/fault.c | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/idtentry.h b/arch/x86/include/asm

[RFC][PATCH 20/24] x86/pti: Execute NMI handler on the kernel stack

2020-11-09 Thread Alexandre Chartre
userland through the stack. Signed-off-by: Alexandre Chartre --- arch/x86/kernel/nmi.c | 14 -- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c index 4bc77aaf1303..be0f654c3095 100644 --- a/arch/x86/kernel/nmi.c +++ b/arch

[RFC][PATCH 16/24] x86/pti: Execute IDT handlers on the kernel stack

2020-11-09 Thread Alexandre Chartre
kernel data leak to the userland through the stack. For now, only changes IDT handlers which have no argument other than the pt_regs registers. Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/idtentry.h | 43 +++-- arch/x86/kernel/cpu/mce/core.c | 2 +- arch

[RFC][PATCH 06/24] x86/pti: Provide C variants of PTI switch CR3 macros

2020-11-09 Thread Alexandre Chartre
Page Table Isolation (PTI) use assembly macros to switch the CR3 register between kernel and user page-tables. Add C functions which implement the same features. For now, these C functions are not used but they will eventually replace using the assembly macros. Signed-off-by: Alexandre Chartre

[RFC][PATCH 04/24] x86/sev-es: Define a setup stack function for the VC idtentry

2020-11-09 Thread Alexandre Chartre
is also refactored to just return the stack pointer, and the stack configuration is done in the setup stack function (so that the stack can be also be used to propagate CR3 switch information to the idtentry handler for switching CR3 back). Signed-off-by: Alexandre Chartre --- arch/x86/entry

[RFC][PATCH 02/24] x86/entry: Update asm_call_on_stack to support more function arguments

2020-11-09 Thread Alexandre Chartre
Update the asm_call_on_stack() function so that it can be invoked with a function having up to three arguments instead of only one. Signed-off-by: Alexandre Chartre --- arch/x86/entry/entry_64.S| 15 +++ arch/x86/include/asm/irq_stack.h | 8 2 files changed, 19

[RFC][PATCH 07/24] x86/entry: Fill ESPFIX stack using C code

2020-11-09 Thread Alexandre Chartre
The ESPFIX stack is filled using assembly code. Move this code to a C function so that it is easier to read and modify. Signed-off-by: Alexandre Chartre --- arch/x86/entry/entry_64.S | 62 ++--- arch/x86/kernel/espfix_64.c | 41 2 files

[RFC][PATCH 09/24] x86/entry: Add C version of paranoid_entry/exit

2020-11-09 Thread Alexandre Chartre
does. Signed-off-by: Alexandre Chartre --- arch/x86/entry/common.c | 157 arch/x86/include/asm/entry-common.h | 10 ++ 2 files changed, 167 insertions(+) diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c index d09b1ded5287..54d0931801e1 100644

[RFC][PATCH 03/24] x86/entry: Consolidate IST entry from userspace

2020-11-09 Thread Alexandre Chartre
this code into a single assembly macro. Signed-off-by: Alexandre Chartre --- arch/x86/entry/entry_64.S | 137 +- 1 file changed, 75 insertions(+), 62 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index c42948aca0a8

[RFC][PATCH 00/24] x86/pti: Defer CR3 switch to C code

2020-11-09 Thread Alexandre Chartre
The code survives running a kernel build and LTP. Note that changes are only for 64-bit at the moment, I haven't looked at 32-bit yet but I will definitively check it. Code is based on v5.10-rc3. Thanks, alex. ----- Alexandre Chartre (24): x86/syscall: Add wrapper for invoking syscall funct

[RFC][PATCH 01/24] x86/syscall: Add wrapper for invoking syscall function

2020-11-09 Thread Alexandre Chartre
Add a wrapper function for invoking a syscall function. Signed-off-by: Alexandre Chartre --- arch/x86/entry/common.c | 16 +--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c index 870efeec8bda..d12908ad 100644

Re: [RFC][PATCH 00/24] x86/pti: Defer CR3 switch to C code

2020-11-09 Thread Alexandre Chartre
n 11/9/20 12:22 PM, Alexandre Chartre wrote: With Page Table Isolation (PTI), syscalls as well as interrupts and exceptions occurring in userspace enter the kernel with a user page-table. The kernel entry code will then switch the page-table from the user page-table to the kernel page-table by u

[RFC][PATCH 15/24] x86/pti: Execute syscall functions on the kernel stack

2020-11-09 Thread Alexandre Chartre
userland through the stack. Signed-off-by: Alexandre Chartre --- arch/x86/entry/common.c | 11 ++- arch/x86/entry/entry_64.S| 1 + arch/x86/include/asm/irq_stack.h | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/x86/entry/common.c b/arch/x86

[RFC][PATCH 12/24] x86/pti: Function to map per-cpu page-table entry

2020-11-09 Thread Alexandre Chartre
Wrap the code used by PTI to map a per-cpu page-table entry into a new function so that this code can be re-used to map other per-cpu entries. Signed-off-by: Alexandre Chartre --- arch/x86/mm/pti.c | 25 - 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a

[RFC][PATCH 10/24] x86/pti: Introduce per-task PTI trampoline stack

2020-11-09 Thread Alexandre Chartre
trampoline stack. This will allow running more code on the trampoline stack, in particular code that schedules the task out. Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/page_64_types.h | 36 +++- arch/x86/include/asm/processor.h | 3 +++ 2 files changed, 38

[RFC][PATCH 11/24] x86/pti: Function to clone page-table entries from a specified mm

2020-11-09 Thread Alexandre Chartre
PTI has a function to clone page-table entries but only from the init_mm page-table. Provide a new function to clone page-table entries from a specified mm page-table. Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/pti.h | 10 ++ arch/x86/mm/pti.c | 32

[RFC][PATCH 03/24] x86/entry: Consolidate IST entry from userspace

2020-11-09 Thread Alexandre Chartre
this code into a single assembly macro. Signed-off-by: Alexandre Chartre --- arch/x86/entry/entry_64.S | 137 +- 1 file changed, 75 insertions(+), 62 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index c42948aca0a8

[RFC][PATCH 05/24] x86/entry: Implement ret_from_fork body with C code

2020-11-09 Thread Alexandre Chartre
ret_from_fork is a mix of assembly code and calls to C functions. Re-implement ret_from_fork so that it calls a single C function. Signed-off-by: Alexandre Chartre --- arch/x86/entry/common.c | 18 ++ arch/x86/entry/entry_64.S | 28 +--- 2 files changed

[RFC][PATCH 09/24] x86/entry: Add C version of paranoid_entry/exit

2020-11-09 Thread Alexandre Chartre
does. Signed-off-by: Alexandre Chartre --- arch/x86/entry/common.c | 157 arch/x86/include/asm/entry-common.h | 10 ++ 2 files changed, 167 insertions(+) diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c index d09b1ded5287..54d0931801e1 100644

[RFC][PATCH 04/24] x86/sev-es: Define a setup stack function for the VC idtentry

2020-11-09 Thread Alexandre Chartre
is also refactored to just return the stack pointer, and the stack configuration is done in the setup stack function (so that the stack can be also be used to propagate CR3 switch information to the idtentry handler for switching CR3 back). Signed-off-by: Alexandre Chartre --- arch/x86/entry

[RFC][PATCH 22/24] x86/entry: Defer paranoid entry/exit to C code

2020-11-09 Thread Alexandre Chartre
IST entries from the kernel use paranoid entry and exit assembly functions to ensure the CR3 and GS registers are updated with correct values for the kernel. Move the update of the CR3 and GS registers inside the C code of IST handlers. Signed-off-by: Alexandre Chartre --- arch/x86/entry

[RFC][PATCH 24/24] x86/pti: Defer CR3 switch to C code for non-IST and syscall entries

2020-11-09 Thread Alexandre Chartre
With PTI, syscall/interrupt/exception entries switch the CR3 register to change the page-table in assembly code. Move the CR3 register switch inside the C code of syscall/interrupt/exception entry handlers. Signed-off-by: Alexandre Chartre --- arch/x86/entry/common.c | 15

[RFC][PATCH 18/24] x86/pti: Execute system vector handlers on the kernel stack

2020-11-09 Thread Alexandre Chartre
kernel data leak to the userland through the stack. Changes system vector handlers to execute on the kernel stack. Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/idtentry.h | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/idtentry.h b

[RFC][PATCH 23/24] x86/entry: Remove paranoid_entry and paranoid_exit

2020-11-09 Thread Alexandre Chartre
The paranoid_entry and paranoid_exit assembly functions have been replaced by the kernel_paranoid_entry() and kernel_paranoid_exit() C functions. Now paranoid_entry/exit are not used anymore and can be removed. Signed-off-by: Alexandre Chartre --- arch/x86/entry/entry_64.S | 131

[RFC][PATCH 20/24] x86/pti: Execute NMI handler on the kernel stack

2020-11-09 Thread Alexandre Chartre
userland through the stack. Signed-off-by: Alexandre Chartre --- arch/x86/kernel/nmi.c | 14 -- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c index 4bc77aaf1303..be0f654c3095 100644 --- a/arch/x86/kernel/nmi.c +++ b/arch

[RFC][PATCH 14/24] x86/pti: Use PTI stack instead of trampoline stack

2020-11-09 Thread Alexandre Chartre
per-cpu stack will allow executing more code before switching to the kernel stack and to the kernel page-table. Additional changes will be made to later to switch to the kernel stack (which is only mapped in the kernel page-table). Signed-off-by: Alexandre Chartre --- arch/x86/entry/entry_64.S

[RFC][PATCH 16/24] x86/pti: Execute IDT handlers on the kernel stack

2020-11-09 Thread Alexandre Chartre
kernel data leak to the userland through the stack. For now, only changes IDT handlers which have no argument other than the pt_regs registers. Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/idtentry.h | 43 +++-- arch/x86/kernel/cpu/mce/core.c | 2 +- arch

[RFC][PATCH 19/24] x86/pti: Execute page fault handler on the kernel stack

2020-11-09 Thread Alexandre Chartre
leak to the userland through the stack. Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/idtentry.h | 17 + arch/x86/mm/fault.c | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/idtentry.h b/arch/x86/include/asm

[RFC][PATCH 21/24] x86/entry: Disable stack-protector for IST entry C handlers

2020-11-09 Thread Alexandre Chartre
entry C handlers where the GS register setup will eventually happen. Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/idtentry.h | 25 - arch/x86/kernel/nmi.c | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm

[RFC][PATCH 17/24] x86/pti: Execute IDT handlers with error code on the kernel stack

2020-11-09 Thread Alexandre Chartre
kernel data leak to the userland through the stack. Changes IDT handlers which have an error code. Signed-off-by: Alexandre Chartre --- arch/x86/include/asm/idtentry.h | 18 -- arch/x86/kernel/traps.c | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a

  1   2   3   >