[PATCH v3 1/7] x86/fsgsbase/64: Introduce FS/GS base helper functions

2018-06-07 Thread Chang S. Bae
ase refers to base backed up at kernel entries and of inactive (user) task's. The bug that returns stale FS/GS base value (when index is nonzero) is preserved and will be fixed by next patch. Based-on-code-from: Andy Lutomirski Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin

[PATCH v3 2/7] x86/fsgsbase/64: Make ptrace read FS/GS base accurately

2018-06-07 Thread Chang S. Bae
-by: Andy Lutomirski [chang: Rebase and revise patch description] Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar --- arch/x86/kernel/process_64.c | 67 +--- 1 file changed, 51

[PATCH v3 0/7] x86: infrastructure to enable FSGSBASE

2018-06-07 Thread Chang S. Bae
Andy Lutomirski (1): x86/fsgsbase/64: Make ptrace read FS/GS base accurately Chang S. Bae (6): x86/fsgsbase/64: Introduce FS/GS base helper functions x86/fsgsbase/64: Use FS/GS base helpers in core dump x86/fsgsbase/64: Factor out load FS/GS segments from __switch_to x86/segments/64

[PATCH v3 3/7] x86/fsgsbase/64: Use FS/GS base helpers in core dump

2018-06-07 Thread Chang S. Bae
When new FSGSBASE instructions enabled, this read will become faster. Based-on-code-from: Andy Lutomirski Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar Reviewed-by: Andy Lutomirski --- arch/x86/include/asm/elf.h

[PATCH v3 7/7] x86/vdso: Move out the CPU number store

2018-06-07 Thread Chang S. Bae
the kernel and userspace unconditionally available much sooner. (Thanks to HPA for suggesting the cleanup) Signed-off-by: Chang S. Bae Cc: H. Peter Anvin Cc: Dave Hansen Cc: Andy Lutomirski Cc: Andi Kleen Cc: Thomas Gleixner Cc: Ingo Molnar --- arch/x86/entry/vdso/vma.c | 41

[PATCH v3 4/7] x86/fsgsbase/64: Factor out load FS/GS segments from __switch_to

2018-06-07 Thread Chang S. Bae
Instead of open code, load_fsgs() will cleanup __switch_to and symmetric with FS/GS segment save. When FSGSBASE enabled, X86_FEATURE_FSGSBASE check will be incorporated. Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar

[PATCH v3 5/7] x86/segments/64: Rename PER_CPU segment to CPU_NUMBER

2018-06-07 Thread Chang S. Bae
64-bit doesn't use the entry for per CPU data, but for CPU numbers. The change will clarify the real usage of this entry in GDT. Suggested-by: H. Peter Anvin Signed-off-by: Chang S. Bae Cc: Andi Kleen Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar Acked-by: Andy Lutomirski --- arch

[PATCH v3 6/7] x86/vdso: Introduce CPU number helper functions

2018-06-07 Thread Chang S. Bae
CPU number initialization in vDSO is now a bit cleaned up by the new helper functions. The helper functions will take care of combing CPU and node number and reading each from the combined value. Suggested-by: Andy Lutomirski Signed-off-by: Chang S. Bae Cc: H. Peter Anvin Cc: Andi Kleen Cc

[PATCH V2 09/15] x86/fsgsbase/64: Enable FSGSBASE instructions in helper functions

2018-05-31 Thread Chang S. Bae
to do that. The measured overhead was (almost) offset to the benefit. Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: Any Lutomirski Cc: H. Peter Anvin Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar --- arch/x86/include/asm/fsgsbase.h | 17 -- arch/x86/kernel/process_64

[PATCH V2 08/15] x86/fsgsbase/64: Add intrinsics/macros for FSGSBASE instructions

2018-05-31 Thread Chang S. Bae
-off-by: Andi Kleen Signed-off-by: Andy Lutomirski [chang: Replace new instruction macros with GAS-compatible and renaming. Note: if GCC supports it, we can add -mfsgsbase to CFLAGS and use the builtins here for extra performance.] Signed-off-by: Chang S. Bae Cc: H. Peter Anvin Cc: Dave Hansen

[PATCH V2 07/15] x86/fsgsbase/64: Add 'unsafe_fsgsbase' to enable CR4.FSGSBASE

2018-05-31 Thread Chang S. Bae
From: Andy Lutomirski This is temporary. It will allow the next few patches to be tested incrementally. Setting unsafe_fsgsbase is a root hole. Don't do it. Signed-off-by: Andy Lutomirski [chang: Fix the deactivated flag. Add TAINT_INSECURE flag.] Signed-off-by: Chang S. Bae Reviewed

[PATCH V2 02/15] x86/fsgsbase/64: Make ptrace read FS/GS base accurately

2018-05-31 Thread Chang S. Bae
-by: Andy Lutomirski [chang: Rebase and revise patch description] Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar --- arch/x86/kernel/process_64.c | 59 1 file changed, 49

[PATCH V2 05/15] x86/vdso: Move out the CPU number store

2018-05-31 Thread Chang S. Bae
. (Thanks to HPA for suggesting the cleanup) Signed-off-by: Chang S. Bae Cc: H. Peter Anvin Cc: Dave Hansen Cc: Andy Lutomirski Cc: Andi Kleen Cc: Thomas Gleixner Cc: Ingo Molnar --- arch/x86/entry/vdso/vgetcpu.c | 2 +- arch/x86/entry/vdso/vma.c | 38

[PATCH V2 10/15] x86/fsgsbase/64: Preserve FS/GS state in __switch_to if FSGSBASE is on

2018-05-31 Thread Chang S. Bae
4.6-rc1 behavior on my Skylake laptop. Signed-off-by: Andy Lutomirski [chang: 5~10% performance improvement on context switch micro- benchmark, when FS/GS base is actively switched.] Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin Cc: Dave Hansen Cc: Thomas Gleixner Cc

[PATCH V2 06/15] taint: Add taint for insecure

2018-05-31 Thread Chang S. Bae
When adding new feature support, patches need to be incrementally applied and tested with temporal parameters. For such testing (or root-only) purposes, the new flag will serve to tag the kernel taint state properly. Suggested-by: H. Peter Anvin Signed-off-by: Chang S. Bae Cc: Andy Lutomirski

[PATCH V2 13/15] x86/fsgsbase/64: Enable FSGSBASE by default and add a chicken bit

2018-05-31 Thread Chang S. Bae
From: Andy Lutomirski Now that FSGSBASE is fully supported, remove unsafe_fsgsbase, enable FSGSBASE by default, and add nofsgsbase to disable it. Signed-off-by: Andy Lutomirski Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin Cc: Dave Hansen Cc: Thomas Gleixner Cc

[PATCH V2 11/15] x86/fsgsbase/64: When copying a thread, use FSGSBASE if enabled

2018-05-31 Thread Chang S. Bae
When FSGSBASE enabled, copy real FS/GS base values instead of approximation. Factor out to save_fsgs() does not yield the exact same behavior, because save_base_legacy() does not copy FS/GS base when index is zero. Signed-off-by: Chang S. Bae Cc: Andy Lutomirski Cc: H. Peter Anvin Cc: Andi

[PATCH V2 12/15] x86/fsgsbase/64: Use per-CPU base as GS base on paranoid_entry

2018-05-31 Thread Chang S. Bae
. GAS-compatible RDPID macro is included. Suggested-by: H. Peter Anvin Signed-off-by: Chang S. Bae Cc: Andi Kleen Cc: Andy Lutomirski Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar --- arch/x86/entry/entry_64.S | 74 + arch/x86/include/asm

[PATCH V2 14/15] x86/elf: Enumerate kernel FSGSBASE capability in AT_HWCAP2

2018-05-31 Thread Chang S. Bae
and edit the patch note accordingly] Signed-off-by: Chang S. Bae Cc: Andy Lutomirski Cc: H. Peter Anvin Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar --- arch/x86/include/uapi/asm/hwcap2.h | 3 +++ arch/x86/kernel/cpu/common.c | 4 +++- 2 files changed, 6 insertions(+), 1 deletion

[PATCH V2 15/15] x86/fsgsbase/64: Add documentation for FSGSBASE

2018-05-31 Thread Chang S. Bae
From: Andi Kleen v2: Minor updates to documentation requested in review. v3: Update for new gcc and various improvements. Signed-off-by: Andi Kleen [chang: Minor edit and include descriptions for entry changes by FSGSBASE] Signed-off-by: Chang S. Bae Cc: Andy Lutomirski Cc: H. Peter Anvin

[PATCH V2 00/15] x86: Enable FSGSBASE instructions

2018-05-31 Thread Chang S. Bae
by default and add a chicken bit Chang S. Bae (8): x86/fsgsbase/64: Introduce FS/GS base helper functions x86/fsgsbase/64: Use FS/GS base helpers in core dump x86/fsgsbase/64: Factor out load FS/GS segments from __switch_to x86/vdso: Move out the CPU number store taint: Add taint

[PATCH V2 03/15] x86/fsgsbase/64: Use FS/GS base helpers in core dump

2018-05-31 Thread Chang S. Bae
When new FSGSBASE instructions enabled, this read will be switched to be faster. Based-on-code-from: Andy Lutomirski Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar --- arch/x86/include/asm/elf.h | 6 +++--- 1 file

[PATCH V2 04/15] x86/fsgsbase/64: Factor out load FS/GS segments from __switch_to

2018-05-31 Thread Chang S. Bae
Instead of open code, load_fsgs() will cleanup __switch_to and symmetric with FS/GS segment save. When FSGSBASE enabled, X86_FEATURE_FSGSBASE check will be incorporated. Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: Andy Lutomirski Cc: H. Peter Anvin Cc: Dave Hansen Cc: Thomas

[PATCH V2 01/15] x86/fsgsbase/64: Introduce FS/GS base helper functions

2018-05-31 Thread Chang S. Bae
"inactive" are used to distinguish GS bases between "kernel" and "user". "inactive" GS base is the GS base, backed up at kernel entries, of inactive (user) task's. Based-on-code-from: Andy Lutomirski Signed-off-by: Chang S. Bae Reviewed-by: Andi Klee

[PATCH 5/6] x86/msr: write_rdtscp_aux() to use wrmsr_safe()

2018-06-04 Thread Chang S. Bae
Using wrmsr_safe() can make code a bit simpler by removing some condition check Suggested-by: H. Peter Anvin Signed-off-by: Chang S. Bae Cc: Andy Lutomirski Cc: Andi Kleen Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar --- arch/x86/include/asm/msr.h | 2 +- 1 file changed, 1

[PATCH 3/6] x86/fsgsbase/64: Use FS/GS base helpers in core dump

2018-06-04 Thread Chang S. Bae
When new FSGSBASE instructions enabled, this read will become faster. Based-on-code-from: Andy Lutomirski Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar Reviewed-by: Andy Lutomirski --- arch/x86/include/asm/elf.h

[PATCH 6/6] x86/vdso: Move out the CPU number store

2018-06-04 Thread Chang S. Bae
. (Thanks to HPA for suggesting the cleanup) Signed-off-by: Chang S. Bae Cc: H. Peter Anvin Cc: Dave Hansen Cc: Andy Lutomirski Cc: Andi Kleen Cc: Thomas Gleixner Cc: Ingo Molnar --- arch/x86/entry/vdso/vgetcpu.c | 4 ++-- arch/x86/entry/vdso/vma.c | 38

[PATCH 0/6] x86: infrastructure to enable FSGSBASE

2018-06-04 Thread Chang S. Bae
] FSGSBASE patch set V2: https://lkml.org/lkml/2018/5/31/686 Andy Lutomirski (1): x86/fsgsbase/64: Make ptrace read FS/GS base accurately Chang S. Bae (5): x86/fsgsbase/64: Introduce FS/GS base helper functions x86/fsgsbase/64: Use FS/GS base helpers in core dump x86/fsgsbase/64: Factor out

[PATCH 4/6] x86/fsgsbase/64: Factor out load FS/GS segments from __switch_to

2018-06-04 Thread Chang S. Bae
Instead of open code, load_fsgs() will cleanup __switch_to and symmetric with FS/GS segment save. When FSGSBASE enabled, X86_FEATURE_FSGSBASE check will be incorporated. Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: Andy Lutomirski Cc: H. Peter Anvin Cc: Dave Hansen Cc: Thomas

[PATCH 1/6] x86/fsgsbase/64: Introduce FS/GS base helper functions

2018-06-04 Thread Chang S. Bae
ase refers to base backed up at kernel entries and of inactive (user) task's. The bug that returns stale FS/GS base value (when index is nonzero) is preserved and will be fixed by next patch. Based-on-code-from: Andy Lutomirski Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin

[PATCH 2/6] x86/fsgsbase/64: Make ptrace read FS/GS base accurately

2018-06-04 Thread Chang S. Bae
-by: Andy Lutomirski [chang: Rebase and revise patch description] Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar --- arch/x86/kernel/process_64.c | 67 +--- 1 file changed, 51

[PATCH v2 1/8] x86/fsgsbase/64: Introduce FS/GS base helper functions

2018-06-06 Thread Chang S. Bae
ase refers to base backed up at kernel entries and of inactive (user) task's. The bug that returns stale FS/GS base value (when index is nonzero) is preserved and will be fixed by next patch. Based-on-code-from: Andy Lutomirski Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin

[PATCH v2 3/8] x86/fsgsbase/64: Use FS/GS base helpers in core dump

2018-06-06 Thread Chang S. Bae
When new FSGSBASE instructions enabled, this read will become faster. Based-on-code-from: Andy Lutomirski Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar Reviewed-by: Andy Lutomirski --- arch/x86/include/asm/elf.h

[PATCH v2 6/8] x86/segments/64: Rename PER_CPU segment to CPU_NUMBER

2018-06-06 Thread Chang S. Bae
64-bit doesn't use the entry for per CPU data, but for CPU numbers. The change will clarify the real usage of this entry in GDT. Suggested-by: H. Peter Anvin Signed-off-by: Chang S. Bae Cc: Andy Lutomirski Cc: Andi Kleen Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar --- arch/x86

[PATCH v2 0/8] x86: infrastructure to enable FSGSBASE

2018-06-06 Thread Chang S. Bae
/lkml/2018/6/4/887 Andy Lutomirski (1): x86/fsgsbase/64: Make ptrace read FS/GS base accurately Chang S. Bae (7): x86/fsgsbase/64: Introduce FS/GS base helper functions x86/fsgsbase/64: Use FS/GS base helpers in core dump x86/fsgsbase/64: Factor out load FS/GS segments from __switch_to x86

[PATCH v2 7/8] x86/segments/32: Introduce CPU_NUMBER segment

2018-06-06 Thread Chang S. Bae
(flat, initial) user space %ss. %ss is specified than %ds because it is less likely to be changed as 64-bit has %ss defined. Suggested-by: H. Peter Signed-off-by: Chang S. Bae Cc: Andy Lutomirski Cc: Andi Kleen Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar --- arch/x86/include/asm

[PATCH v2 2/8] x86/fsgsbase/64: Make ptrace read FS/GS base accurately

2018-06-06 Thread Chang S. Bae
-by: Andy Lutomirski [chang: Rebase and revise patch description] Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar --- arch/x86/kernel/process_64.c | 67 +--- 1 file changed, 51

[PATCH v2 8/8] x86/vdso: Move out the CPU number store

2018-06-06 Thread Chang S. Bae
. (Thanks to HPA for suggesting the cleanup) Signed-off-by: Chang S. Bae Cc: H. Peter Anvin Cc: Dave Hansen Cc: Andy Lutomirski Cc: Andi Kleen Cc: Thomas Gleixner Cc: Ingo Molnar --- arch/x86/entry/vdso/vgetcpu.c | 4 ++-- arch/x86/entry/vdso/vma.c | 41

[PATCH v2 5/8] x86/msr: write_rdtscp_aux() to use wrmsr_safe()

2018-06-06 Thread Chang S. Bae
Using wrmsr_safe() can make code a bit simpler by removing some condition check Suggested-by: H. Peter Anvin Signed-off-by: Chang S. Bae Cc: Andy Lutomirski Cc: Andi Kleen Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar --- arch/x86/include/asm/msr.h | 2 +- 1 file changed, 1

[PATCH v2 4/8] x86/fsgsbase/64: Factor out load FS/GS segments from __switch_to

2018-06-06 Thread Chang S. Bae
Instead of open code, load_fsgs() will cleanup __switch_to and symmetric with FS/GS segment save. When FSGSBASE enabled, X86_FEATURE_FSGSBASE check will be incorporated. Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: Andy Lutomirski Cc: H. Peter Anvin Cc: Dave Hansen Cc: Thomas

[PATCH v5 4/8] x86/fsgsbase/64: Use FS/GS base helpers in core dump

2018-06-27 Thread Chang S. Bae
The open coded access is now replaced, that might prevent from using the enhanced FSGSBASE mechanism. Based-on-code-from: Andy Lutomirski Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Reviewed-by: Andy Lutomirski Reviewed-by: Thomas Gleixner Cc: H. Peter Anvin Cc: Ingo Molnar Cc

[PATCH v5 5/8] x86/fsgsbase/64: Factor out load FS/GS segments from __switch_to

2018-06-27 Thread Chang S. Bae
Instead of open coding the calls to load_seg_legacy(), add a load_fsgs() helper to handle fs and gs. When FSGSBASE is enabled, load_fsgs() will be updated. Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Reviewed-by: Andy Lutomirski Reviewed-by: Thomas Gleixner Cc: H. Peter Anvin Cc

[PATCH v5 0/8] x86: infrastructure to enable FSGSBASE

2018-06-27 Thread Chang S. Bae
://lkml.org/lkml/2018/6/7/975 [5] V4: https://lkml.org/lkml/2018/6/20/1045 Andy Lutomirski (1): x86/arch_prctl/64: Make ptrace read FS/GS base accurately Chang S. Bae (7): x86/fsgsbase/64: Introduce FS/GS base helper functions x86/fsgsbase/64: Make ptrace use FS/GS base helpers x86/fsgsbase/64: Use

[PATCH v5 2/8] x86/fsgsbase/64: Introduce FS/GS base helper functions

2018-06-27 Thread Chang S. Bae
functions are implemented as closely coupled. When next patch makes ptrace to use the helpers, it won't be directly accessed from ptrace. Based-on-code-from: Andy Lutomirski Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Dave Hansen

[PATCH v5 6/8] x86/segments/64: Rename PER_CPU segment to CPU_NUMBER

2018-06-27 Thread Chang S. Bae
64-bit doesn't use the entry for per CPU data, but for CPU (and node) numbers. The change will clarify the real usage of this entry in GDT. Suggested-by: H. Peter Anvin Signed-off-by: Chang S. Bae Acked-by: Andy Lutomirski Reviewed-by: Thomas Gleixner Cc: Ingo Molnar Cc: Andi Kleen Cc: Dave

[PATCH v5 7/8] x86/vdso: Introduce helper functions for CPU and node number

2018-06-27 Thread Chang S. Bae
The CPU initialization in vDSO is now a bit cleaned up by the new helper functions. The helper functions will take care of combining CPU and node number and reading each from the combined value. Suggested-by: Andy Lutomirski Suggested-by: Thomas Gleixner Signed-off-by: Chang S. Bae Cc: H

[PATCH v5 8/8] x86/vdso: Move out the CPU initialization

2018-06-27 Thread Chang S. Bae
and hotplug notifier are removed. Suggested-by: H. Peter Anvin Suggested-by: Andy Lutomirski Signed-off-by: Chang S. Bae Cc: Thomas Gleixner Cc: Dave Hansen Cc: Ingo Molnar Cc: Andi Kleen --- arch/x86/entry/vdso/vma.c| 33 + arch/x86/kernel/cpu/common.c | 24

[PATCH v5 3/8] x86/fsgsbase/64: Make ptrace use FS/GS base helpers

2018-06-27 Thread Chang S. Bae
The FS/GS base helper functions are used on ptrace APIs (PTRACE_ARCH_PRCTL, PTRACE_SETREG, PTRACE_GETREG, etc). The FS/GS-update mechanism is now a bit organized. Based-on-code-from: Andy Lutomirski Signed-off-by: Chang S. Bae Cc: H. Peter Anvin Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Dave

[PATCH v5 1/8] x86/arch_prctl/64: Make ptrace read FS/GS base accurately

2018-06-27 Thread Chang S. Bae
-by: Andy Lutomirski [chang: Rebase and revise patch description] Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Dave Hansen --- arch/x86/kernel/ptrace.c | 62 1 file changed, 52

[PATCH v4 5/7] x86/segments/64: Rename PER_CPU segment to CPU_NUMBER

2018-06-20 Thread Chang S. Bae
64-bit doesn't use the entry for per CPU data, but for CPU numbers. The change will clarify the real usage of this entry in GDT. Suggested-by: H. Peter Anvin Signed-off-by: Chang S. Bae Cc: Andi Kleen Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar Acked-by: Andy Lutomirski --- arch

[PATCH v4 1/7] x86/fsgsbase/64: Introduce FS/GS base helper functions

2018-06-20 Thread Chang S. Bae
ase refers to base backed up at kernel entries and of inactive (user) task's. The bug that returns stale FS/GS base value (when index is nonzero) is preserved and will be fixed by next patch. Based-on-code-from: Andy Lutomirski Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin

[PATCH v4 2/7] x86/fsgsbase/64: Make ptrace read FS/GS base accurately

2018-06-20 Thread Chang S. Bae
-by: Andy Lutomirski [chang: Rebase and revise patch description] Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar --- arch/x86/kernel/process_64.c | 67 +--- 1 file changed, 51

[PATCH v4 6/7] x86/vdso: Introduce CPU number helper functions

2018-06-20 Thread Chang S. Bae
CPU number initialization in vDSO is now a bit cleaned up by the new helper functions. The helper functions will take care of combing CPU and node number and reading each from the combined value. Suggested-by: Andy Lutomirski Signed-off-by: Chang S. Bae Cc: H. Peter Anvin Cc: Andi Kleen Cc

[PATCH v4 3/7] x86/fsgsbase/64: Use FS/GS base helpers in core dump

2018-06-20 Thread Chang S. Bae
When new FSGSBASE instructions enabled, this read will become faster. Based-on-code-from: Andy Lutomirski Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar Reviewed-by: Andy Lutomirski --- arch/x86/include/asm/elf.h

[PATCH v4 4/7] x86/fsgsbase/64: Factor out load FS/GS segments from __switch_to

2018-06-20 Thread Chang S. Bae
Instead of open coding the calls to load_seg_legacy(), add a load_fsgs() helper to handle fs and gs. When FSGSBASE is enabled, load_fsgs() will be updated. Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar Reviewed

[PATCH v4 0/7] x86: infrastructure to enable FSGSBASE

2018-06-20 Thread Chang S. Bae
[3] V2: https://lkml.org/lkml/2018/6/6/582 [4] V3: https://lkml.org/lkml/2018/6/7/975 Andy Lutomirski (1): x86/fsgsbase/64: Make ptrace read FS/GS base accurately Chang S. Bae (6): x86/fsgsbase/64: Introduce FS/GS base helper functions x86/fsgsbase/64: Use FS/GS base helpers in core dump

[PATCH v4 7/7] x86/vdso: Move out the CPU number store

2018-06-20 Thread Chang S. Bae
for suggesting the cleanup) Signed-off-by: Chang S. Bae Cc: H. Peter Anvin Cc: Dave Hansen Cc: Andy Lutomirski Cc: Andi Kleen Cc: Thomas Gleixner Cc: Ingo Molnar --- arch/x86/entry/vdso/vma.c| 41 + arch/x86/kernel/cpu/common.c | 28

[RESEND PATCH V5 1/8] x86/arch_prctl/64: Make ptrace read FS/GS base accurately

2018-08-23 Thread Chang S. Bae
-by: Andy Lutomirski [chang: Rebase and revise patch description] Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Dave Hansen --- arch/x86/kernel/ptrace.c | 62 1 file changed, 52

[RESEND PATCH V5 3/8] x86/fsgsbase/64: Make ptrace use FS/GS base helpers

2018-08-23 Thread Chang S. Bae
The FS/GS base helper functions are used on ptrace APIs (PTRACE_ARCH_PRCTL, PTRACE_SETREG, PTRACE_GETREG, etc). The FS/GS-update mechanism is now a bit organized. Based-on-code-from: Andy Lutomirski Signed-off-by: Chang S. Bae Cc: H. Peter Anvin Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Dave

[RESEND PATCH V5 6/8] x86/segments/64: Rename PER_CPU segment to CPU_NUMBER

2018-08-23 Thread Chang S. Bae
64-bit doesn't use the entry for per CPU data, but for CPU (and node) numbers. The change will clarify the real usage of this entry in GDT. Suggested-by: H. Peter Anvin Signed-off-by: Chang S. Bae Acked-by: Andy Lutomirski Reviewed-by: Thomas Gleixner Cc: Ingo Molnar Cc: Andi Kleen Cc: Dave

[RESEND PATCH V5 7/8] x86/vdso: Introduce helper functions for CPU and node number

2018-08-23 Thread Chang S. Bae
The CPU initialization in vDSO is now a bit cleaned up by the new helper functions. The helper functions will take care of combining CPU and node number and reading each from the combined value. Suggested-by: Andy Lutomirski Suggested-by: Thomas Gleixner Signed-off-by: Chang S. Bae Cc: H

[RESEND PATCH V5 4/8] x86/fsgsbase/64: Use FS/GS base helpers in core dump

2018-08-23 Thread Chang S. Bae
The open coded access is now replaced, that might prevent from using the enhanced FSGSBASE mechanism. Based-on-code-from: Andy Lutomirski Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Reviewed-by: Andy Lutomirski Reviewed-by: Thomas Gleixner Cc: H. Peter Anvin Cc: Ingo Molnar Cc

[RESEND PATCH V5 5/8] x86/fsgsbase/64: Factor out load FS/GS segments from __switch_to

2018-08-23 Thread Chang S. Bae
Instead of open coding the calls to load_seg_legacy(), add a load_fsgs() helper to handle fs and gs. When FSGSBASE is enabled, load_fsgs() will be updated. Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Reviewed-by: Andy Lutomirski Reviewed-by: Thomas Gleixner Cc: H. Peter Anvin Cc

[RESEND PATCH V5 0/8] x86: infrastructure to enable FSGSBASE

2018-08-23 Thread Chang S. Bae
FS/GS base accurately Chang S. Bae (7): x86/fsgsbase/64: Introduce FS/GS base helper functions x86/fsgsbase/64: Make ptrace use FS/GS base helpers x86/fsgsbase/64: Use FS/GS base helpers in core dump x86/fsgsbase/64: Factor out load FS/GS segments from __switch_to x86/segments/64: Rename

[RESEND PATCH V5 8/8] x86/vdso: Move out the CPU initialization

2018-08-23 Thread Chang S. Bae
and hotplug notifier are removed. Suggested-by: H. Peter Anvin Suggested-by: Andy Lutomirski Signed-off-by: Chang S. Bae Cc: Thomas Gleixner Cc: Dave Hansen Cc: Ingo Molnar Cc: Andi Kleen --- arch/x86/entry/vdso/vma.c| 33 + arch/x86/kernel/cpu/common.c | 24

[RESEND PATCH V5 2/8] x86/fsgsbase/64: Introduce FS/GS base helper functions

2018-08-23 Thread Chang S. Bae
functions are implemented as closely coupled. When next patch makes ptrace to use the helpers, it won't be directly accessed from ptrace. Based-on-code-from: Andy Lutomirski Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Dave Hansen

[PATCH 11/15] x86/fsgsbase/64: Preserve FS/GS state in __switch_to if FSGSBASE is on

2018-03-19 Thread Chang S. Bae
mpared to the baseline 4.6-rc1 behavior on my Skylake laptop. Signed-off-by: Andy Lutomirski <l...@kernel.org> [chang: 5~10% performance improvement on context switch micro- benchmark, when FS/GS base is actively switched.] Signed-off-by: Chang S. Bae <chang.seok@intel.com> Revie

[PATCH 07/15] x86/fsgsbase/64: putregs() in a reverse order

2018-03-19 Thread Chang S. Bae
and selector are covered. When FSGSBASE is enabled, an arbitrary base value is possible anyways, so it is going to be reasonable to write base lastly. Suggested-by: H. Peter Anvin <h...@zytor.com> Signed-off-by: Chang S. Bae <chang.seok@intel.com> Cc: Markus T. Metzger <markus.t.metz..

[PATCH 15/15] x86/fsgsbase/64: Enable FSGSBASE by default and add a chicken bit

2018-03-19 Thread Chang S. Bae
From: Andy Lutomirski <l...@kernel.org> Now that FSGSBASE is fully supported, remove unsafe_fsgsbase, enable FSGSBASE by default, and add nofsgsbase to disable it. Signed-off-by: Andy Lutomirski <l...@kernel.org> Signed-off-by: Chang S. Bae <chang.seok@intel.com> Revie

[PATCH 08/15] x86/fsgsbase/64: Add 'unsafe_fsgsbase' to enable CR4.FSGSBASE

2018-03-19 Thread Chang S. Bae
From: Andy Lutomirski <l...@kernel.org> This is temporary. It will allow the next few patches to be tested incrementally. Setting unsafe_fsgsbase is a root hole. Don't do it. Signed-off-by: Andy Lutomirski <l...@kernel.org> [chang: Fix the deactivated flag] Signed-off-by:

[PATCH 10/15] x86/fsgsbase/64: Enable FSGSBASE instructions in helper functions

2018-03-19 Thread Chang S. Bae
to do that. The measured overhead was (almost) offset to the benefit. Signed-off-by: Chang S. Bae <chang.seok@intel.com> Reviewed-by: Andi Kleen <a...@linux.intel.com> Cc: Any Lutomirski <l...@kernel.org> Cc: H. Peter Anvin <h...@zytor.com> --- arch/x86/inc

[PATCH 12/15] x86/fsgsbase/64: When copying a thread, use FSGSBASE if enabled

2018-03-19 Thread Chang S. Bae
When FSGSBASE enabled, copy real FS/GS base values instead of approximation. Factor out to save_fsgs() does not yield the exact same behavior, because save_base_legacy() does not copy FS/GS base when index is zero. Signed-off-by: Chang S. Bae <chang.seok@intel.com> Cc: Andy Lutomir

[PATCH 05/15] x86/ptrace: A new macro to get an offset of user_regs_struct

2018-03-19 Thread Chang S. Bae
Proliferation of offsetof() for user_regs_struct is trimmed down with the USER_REGS_OFFSET macro. Signed-off-by: Chang S. Bae <chang.seok@intel.com> Cc: Andi Kleen <a...@linux.intel.com> Cc: H. Peter Anvin <h...@zytor.com> cc: Andy Lutomirski <l...@kernel.org> ---

[PATCH 14/15] x86/fsgsbase/64: Support legacy behavior when FS/GS updated by ptracer

2018-03-19 Thread Chang S. Bae
GDT/LDT (legacy behavior) - When FS/GS base (regardless of selector) changed, tracee will have the base Suggested-by: Markus T. Metzger <markus.t.metz...@intel.com> Suggested-by: H. Peter Anvin <h...@zytor.com> Signed-off-by: Chang S. Bae <chang.seok@intel.com&

[PATCH 00/15] x86: Enable FSGSBASE instructions

2018-03-19 Thread Chang S. Bae
accurately x86/fsgsbase/64: Add 'unsafe_fsgsbase' to enable CR4.FSGSBASE x86/fsgsbase/64: Preserve FS/GS state in __switch_to if FSGSBASE is on x86/fsgsbase/64: Enable FSGSBASE by default and add a chicken bit Chang S. Bae (10): x86/fsgsbase/64: Introduce FS/GS base helper functions x86

[PATCH 13/15] x86/fsgsbase/64: With FSGSBASE, compare GS bases on paranoid_entry

2018-03-19 Thread Chang S. Bae
the offset table with the CPU number. GS-compatible RDPID macro is included. Suggested-by: H. Peter Anvin <h...@zytor.com> Signed-off-by: Chang S. Bae <chang.seok@intel.com> Cc: Andi Kleen <a...@linux.intel.com> Cc: Andy Lutomirski <l...@kernel.org> Cc: Dave Hansen <

[PATCH 09/15] x86/fsgsbase/64: Add intrinsics/macros for FSGSBASE instructions

2018-03-19 Thread Chang S. Bae
2: Use __always_inline Signed-off-by: Andi Kleen <a...@linux.intel.com> Signed-off-by: Andy Lutomirski <l...@kernel.org> [chang: Replace new instruction macros with GAS-compatible and renaming] Signed-off-by: Chang S. Bae <chang.seok@intel.com> Cc: H. Peter Anvin <h...@zytor

[PATCH 06/15] x86/fsgsbase/64: Add putregs() to handle multiple elements' setting

2018-03-19 Thread Chang S. Bae
putregs() can be used to handle multiple elements flexibly. It is useful when inter-dependency lies in updating a group of context entries. There will be a case with FSGSBASE. Signed-off-by: Chang S. Bae <chang.seok@intel.com> Cc: Markus T. Metzger <markus.t.metz...@intel.com>

[PATCH 01/15] x86/fsgsbase/64: Introduce FS/GS base helper functions

2018-03-19 Thread Chang S. Bae
nd "shadow" are used to distinguish GS bases between "kernel" and "user". "shadow" GS base refers to the GS base backed up at kernel entries; inactive (user) task's GS base. Based-on-code-from: Andy Lutomirski <l...@kernel.org> Signed-off-by: Chang S

[PATCH 04/15] x86/fsgsbase/64: Factor out load FS/GS segments from __switch_to

2018-03-19 Thread Chang S. Bae
Instead of open code, load_fsgs() will cleanup __switch_to and symmetric with FS/GS segment save. When FSGSBASE enabled, X86_FEATURE_FSGSBASE check will be incorporated. Signed-off-by: Chang S. Bae <chang.seok@intel.com> Reviewed-by: Andi Kleen <a...@linux.intel.com> Cc: Andy L

[PATCH 03/15] x86/fsgsbase/64: Use FS/GS base helpers in core dump

2018-03-19 Thread Chang S. Bae
When new FSGSBASE instructions enabled, this read will be switched to be faster. Based-on-code-from: Andy Lutomirski <l...@kernel.org> Signed-off-by: Chang S. Bae <chang.seok@intel.com> Reviewed-by: Andi Kleen <a...@linux.intel.com> Cc: H. Peter Anvin <h...@zytor.com&g

[PATCH 02/15] x86/fsgsbase/64: Make ptrace read FS/GS base accurately

2018-03-19 Thread Chang S. Bae
nd etc). Signed-off-by: Andy Lutomirski <l...@kernel.org> [chang: Rebase and revise patch description] Signed-off-by: Chang S. Bae <chang.seok@intel.com> Reviewed-by: Andi Kleen <a...@linux.intel.com> Cc: H. Peter Anvin <h...@zytor.com> --- arc

[v3 08/12] x86/fsgsbase/64: Use the per-CPU base as GSBASE at the paranoid_entry

2018-10-23 Thread Chang S. Bae
GSBASE read into a new macro, READ_MSR_GSBASE. Suggested-by: H. Peter Anvin Signed-off-by: Chang S. Bae Cc: Andi Kleen Cc: Andy Lutomirski Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar --- arch/x86/entry/entry_64.S | 73 ++--- arch/x86/include/asm

[v3 12/12] x86/fsgsbase/64: Add documentation for FSGSBASE

2018-10-23 Thread Chang S. Bae
From: Andi Kleen v2: Minor updates to documentation requested in review. v3: Update for new gcc and various improvements. [ chang: Fix some typo. Fix the example code. ] Signed-off-by: Andi Kleen Signed-off-by: Chang S. Bae Cc: Andy Lutomirski Cc: H. Peter Anvin Cc: Thomas Gleixner Cc

[v3 10/12] x86/fsgsbase/64: Enable FSGSBASE by default and add a chicken bit

2018-10-23 Thread Chang S. Bae
From: Andy Lutomirski Now that FSGSBASE is fully supported, remove unsafe_fsgsbase, enable FSGSBASE by default, and add nofsgsbase to disable it. Signed-off-by: Andy Lutomirski Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin Cc: Thomas Gleixner Cc: Ingo Molnar Cc

[v3 05/12] x86/fsgsbase/64: Preserve FS/GS state in __switch_to() if FSGSBASE is on

2018-10-23 Thread Chang S. Bae
to the baseline 4.6-rc1 behavior on my Skylake laptop. [ chang: 5~10% performance improvements were seen by a context switch benchmark that ran threads with different FS/GSBASE values. Minor edit on the changelog. ] Signed-off-by: Andy Lutomirski Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H

[v3 07/12] x86/fsgsbase/64: Introduce the new FIND_PERCPU_BASE macro

2018-10-23 Thread Chang S. Bae
. The new macro will be used on a following patch. Suggested-by: H. Peter Anvin Signed-off-by: Chang S. Bae Cc: Andi Kleen Cc: Andy Lutomirski Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar --- arch/x86/include/asm/fsgsbase.h | 52 + arch/x86/include/asm

[v3 11/12] x86/elf: Enumerate kernel FSGSBASE capability in AT_HWCAP2

2018-10-23 Thread Chang S. Bae
accordingly. ] Signed-off-by: Andi Kleen Signed-off-by: Chang S. Bae Cc: Andy Lutomirski Cc: H. Peter Anvin Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Dave Hansen --- arch/x86/include/uapi/asm/hwcap2.h | 3 +++ arch/x86/kernel/cpu/common.c | 4 +++- 2 files changed, 6 insertions(+), 1

[v3 04/12] x86/fsgsbase/64: Enable FSGSBASE instructions in the helper functions

2018-10-23 Thread Chang S. Bae
. However, it seems to spend more cycles for savings and restorations. Little or no benefit was measured from experiments. Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: Any Lutomirski Cc: H. Peter Anvin Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Dave Hansen --- arch/x86/include/asm

[v3 09/12] selftests/x86/fsgsbase: Test WRGSBASE

2018-10-23 Thread Chang S. Bae
From: Andy Lutomirski This validates that GS and GSBASE are independently preserved across context switches. Signed-off-by: Andy Lutomirski Reviewed-by: Andi Kleen Signed-off-by: Chang S. Bae Cc: H. Peter Anvin Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Dave Hansen --- tools/testing

[v3 06/12] x86/fsgsbase/64: When copying a thread, use the FSGSBASE instructions if available

2018-10-23 Thread Chang S. Bae
Copy real FS/GSBASE values instead of approximation when FSGSBASE is enabled. Factoring out to save_fsgs() does not result in the same behavior because save_base_legacy() does not copy FS/GSBASE when the index is zero. Signed-off-by: Chang S. Bae Cc: Andy Lutomirski Cc: H. Peter Anvin Cc

[v3 00/12] x86: Enable FSGSBASE instructions

2018-10-23 Thread Chang S. Bae
state in __switch_to() if FSGSBASE is on selftests/x86/fsgsbase: Test WRGSBASE x86/fsgsbase/64: Enable FSGSBASE by default and add a chicken bit Chang S. Bae (5): taint: Introduce a new taint flag (insecure) x86/fsgsbase/64: Enable FSGSBASE instructions in the helper functions x86

[v3 02/12] x86/fsgsbase/64: Add 'unsafe_fsgsbase' to enable CR4.FSGSBASE

2018-10-23 Thread Chang S. Bae
From: Andy Lutomirski This is temporary. It will allow the next few patches to be tested incrementally. Setting unsafe_fsgsbase is a root hole. Don't do it. [ chang: Minor fix. Add the TAINT_INSECURE flag. ] Signed-off-by: Andy Lutomirski Signed-off-by: Chang S. Bae Reviewed-by: Andi

[v3 03/12] x86/fsgsbase/64: Add intrinsics/macros for FSGSBASE instructions

2018-10-23 Thread Chang S. Bae
[ chang: Revise the changelog. Place them in . Replace the macros with GAS-compatible ones. ] If GCC supports it, we can add -mfsgsbase to CFLAGS and use the builtins here for extra performance. Signed-off-by: Andi Kleen Signed-off-by: Andy Lutomirski Signed-off-by: Chang S. Bae Cc: H. Peter Anvin

[v3 01/12] taint: Introduce a new taint flag (insecure)

2018-10-23 Thread Chang S. Bae
-by: Chang S. Bae Cc: Andy Lutomirski Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Andi Kleen Cc: Dave Hansen --- Documentation/sysctl/kernel.txt | 1 + include/linux/kernel.h | 3 ++- kernel/panic.c | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git

[PATCH] x86/fsgsbase/64: Fix the base write helper functions

2018-10-31 Thread Chang S. Bae
task, but a stopped task. v2: Fix further on the task write functions. Revert the changes on the task read helpers. Suggested-by: Andy Lutomirski Signed-off-by: Chang S. Bae Cc: Ingo Molnar Cc: Thomas Gleixner Cc: H. Peter Anvin Cc: Andi Kleen Cc: Dave Hansen --- arch/x86/kernel/process_64

[PATCH v2] x86/fsgsbase/64: Fix the base write helper functions

2018-10-31 Thread Chang S. Bae
task, but a stopped task. v2: Fix further on the task write functions. Revert the changes on the task read helpers. Suggested-by: Andy Lutomirski Signed-off-by: Chang S. Bae Cc: Ingo Molnar Cc: Thomas Gleixner Cc: H. Peter Anvin Cc: Andi Kleen Cc: Dave Hansen --- arch/x86/kernel/process_64

[PATCH] x86/fsgsbase/64: Fix the base write helper functions

2018-10-30 Thread Chang S. Bae
to change the index. putreg() in ptrace does not write the current task, but a stopped task. Suggested-by: Andy Lutomirski Signed-off-by: Chang S. Bae Cc: Ingo Molnar Cc: Thomas Gleixner Cc: H. Peter Anvin Cc: Andi Kleen Cc: Dave Hansen --- arch/x86/kernel/process_64.c | 67

[PATCH v3] x86/fsgsbase/64: Fix the base write helper functions

2018-11-01 Thread Chang S. Bae
the changes on the task read helpers. v3: Fix putreg(). Edit the changelog. Suggested-by: Andy Lutomirski Signed-off-by: Chang S. Bae Cc: Ingo Molnar Cc: Thomas Gleixner Cc: H. Peter Anvin Cc: Andi Kleen Cc: Dave Hansen --- arch/x86/kernel/process_64.c | 48

[PATCH v4] x86/fsgsbase/64: Fix the base write helper functions

2018-11-14 Thread Chang S. Bae
and do_arch_prctl_64(). Fix the comment in putreg(). Suggested-by: Andy Lutomirski Signed-off-by: Chang S. Bae Cc: Ingo Molnar Cc: Thomas Gleixner Cc: H. Peter Anvin Cc: Andi Kleen Cc: Dave Hansen --- arch/x86/include/asm/fsgsbase.h | 15 -- arch/x86/kernel/process_64.c| 84

  1   2   3   4   5   6   >