~mhcerri/ubuntu/+source/linux/+git/azure:groovy-fsgsbase

Last commit made on 2020-09-29
Get this branch:
git clone -b groovy-fsgsbase https://git.launchpad.net/~mhcerri/ubuntu/+source/linux/+git/azure
Only Marcelo Cerri can upload to this branch. If you are Marcelo Cerri please log in for upload directions.

Branch merges

Branch information

Name:
groovy-fsgsbase
Repository:
lp:~mhcerri/ubuntu/+source/linux/+git/azure

Recent commits

6d987ef... by Andy Lutomirski <email address hidden>

x86/fsgsbase: Fix Xen PV support

BugLink: http://bugs.launchpad.net/bugs/1877425

On Xen PV, SWAPGS doesn't work. Teach __rdfsbase_inactive() and
__wrgsbase_inactive() to use rdmsrl()/wrmsrl() on Xen PV. The Xen
pvop code will understand this and issue the correct hypercalls.

Signed-off-by: Andy Lutomirski <email address hidden>
Signed-off-by: Thomas Gleixner <email address hidden>
Link: https://lkml.kernel.org<email address hidden>

(cherry picked from commit d029bff60aa6c7eab281d52602b6a7a971615324)
Signed-off-by: Marcelo Henrique Cerri <email address hidden>

10e543b... by Andy Lutomirski <email address hidden>

x86/ptrace: Fix 32-bit PTRACE_SETREGS vs fsbase and gsbase

BugLink: http://bugs.launchpad.net/bugs/1877425

Debuggers expect that doing PTRACE_GETREGS, then poking at a tracee
and maybe letting it run for a while, then doing PTRACE_SETREGS will
put the tracee back where it was. In the specific case of a 32-bit
tracer and tracee, the PTRACE_GETREGS/SETREGS data structure doesn't
have fs_base or gs_base fields, so FSBASE and GSBASE fields are
never stored anywhere. Everything used to still work because
nonzero FS or GS would result full reloads of the segment registers
when the tracee resumes, and the bases associated with FS==0 or
GS==0 are irrelevant to 32-bit code.

Adding FSGSBASE support broke this: when FSGSBASE is enabled, FSBASE
and GSBASE are now restored independently of FS and GS for all tasks
when context-switched in. This means that, if a 32-bit tracer
restores a previous state using PTRACE_SETREGS but the tracee's
pre-restore and post-restore bases don't match, then the tracee is
resumed with the wrong base.

Fix it by explicitly loading the base when a 32-bit tracer pokes FS
or GS on a 64-bit kernel.

Also add a test case.

Fixes: 673903495c85 ("x86/process/64: Use FSBSBASE in switch_to() if available")
Signed-off-by: Andy Lutomirski <email address hidden>
Signed-off-by: Thomas Gleixner <email address hidden>
Link: https://lkml.kernel.org<email address hidden>

(cherry picked from commit 40c45904f818c1f6555294ca27afc5fda4f09e68)
Signed-off-by: Marcelo Henrique Cerri <email address hidden>

b062117... by "Chang S. Bae" <email address hidden>

selftests/x86/fsgsbase: Test ptracer-induced GS base write with FSGSBASE

BugLink: http://bugs.launchpad.net/bugs/1877425

This validates that GS selector and base are independently preserved in
ptrace commands.

Suggested-by: Andy Lutomirski <email address hidden>
Signed-off-by: Chang S. Bae <email address hidden>
Signed-off-by: Sasha Levin <email address hidden>
Signed-off-by: Thomas Gleixner <email address hidden>
Reviewed-by: Tony Luck <email address hidden>
Link: https://<email address hidden>

(cherry picked from commit 5e7ec8578fa3dada50c50f5b234fa8d154b76349)
Signed-off-by: Marcelo Henrique Cerri <email address hidden>

8e185f6... by "Chang S. Bae" <email address hidden>

selftests/x86/fsgsbase: Test GS selector on ptracer-induced GS base write

BugLink: http://bugs.launchpad.net/bugs/1877425

The test validates that the selector is not changed when a ptracer writes
the ptracee's GS base.

Originally-by: Andy Lutomirski <email address hidden>
Signed-off-by: Chang S. Bae <email address hidden>
Signed-off-by: Sasha Levin <email address hidden>
Signed-off-by: Thomas Gleixner <email address hidden>
Reviewed-by: Tony Luck <email address hidden>
Link: https://<email address hidden>

(cherry picked from commit 291fd83569e10f3d305cd8adb62f6ec00f759dc6)
Signed-off-by: Marcelo Henrique Cerri <email address hidden>

eec2ae5... by tglx

Documentation/x86/64: Add documentation for GS/FS addressing mode

BugLink: http://bugs.launchpad.net/bugs/1877425

Explain how the GS/FS based addressing can be utilized in user space
applications along with the differences between the generic prctl() based
GS/FS base control and the FSGSBASE version available on newer CPUs.

Originally-by: Andi Kleen <email address hidden>
Signed-off-by: Thomas Gleixner <email address hidden>
Signed-off-by: Chang S. Bae <email address hidden>
Signed-off-by: Sasha Levin <email address hidden>
Signed-off-by: Thomas Gleixner <email address hidden>
Reviewed-by: Tony Luck <email address hidden>
Link: https://<email address hidden>

(cherry picked from commit 82c0c7d24c1a034d94af4595dbd3910d7336a6dc)
Signed-off-by: Marcelo Henrique Cerri <email address hidden>

b7421db... by Andi Kleen <email address hidden>

x86/elf: Enumerate kernel FSGSBASE capability in AT_HWCAP2

BugLink: http://bugs.launchpad.net/bugs/1877425

The kernel needs to explicitly enable FSGSBASE. So, the application needs
to know if it can safely use these instructions. Just looking at the CPUID
bit is not enough because it may be running in a kernel that does not
enable the instructions.

One way for the application would be to just try and catch the SIGILL.
But that is difficult to do in libraries which may not want to overwrite
the signal handlers of the main application.

Enumerate the enabled FSGSBASE capability in bit 1 of AT_HWCAP2 in the ELF
aux vector. AT_HWCAP2 is already used by PPC for similar purposes.

The application can access it open coded or by using the getauxval()
function in newer versions of glibc.

[ tglx: Massaged changelog ]

Signed-off-by: Andi Kleen <email address hidden>
Signed-off-by: Chang S. Bae <email address hidden>
Signed-off-by: Thomas Gleixner <email address hidden>
Signed-off-by: Sasha Levin <email address hidden>
Signed-off-by: Thomas Gleixner <email address hidden>
Link: https://lkml<email address hidden>
Link: https://<email address hidden>

(cherry picked from commit 742c45c3ecc9255e15eddbbcee44fd8de401cf1c)
Signed-off-by: Marcelo Henrique Cerri <email address hidden>

e4b4855... by Andy Lutomirski <email address hidden>

x86/cpu: Enable FSGSBASE on 64bit by default and add a chicken bit

BugLink: http://bugs.launchpad.net/bugs/1877425

Now that FSGSBASE is fully supported, remove unsafe_fsgsbase, enable
FSGSBASE by default, and add nofsgsbase to disable it.

Signed-off-by: Andy Lutomirski <email address hidden>
Signed-off-by: Chang S. Bae <email address hidden>
Signed-off-by: Thomas Gleixner <email address hidden>
Signed-off-by: Sasha Levin <email address hidden>
Signed-off-by: Thomas Gleixner <email address hidden>
Reviewed-by: Andi Kleen <email address hidden>
Link: https://lkml<email address hidden>
Link: https://<email address hidden>

(cherry picked from commit b745cfba44c152c34363eea9e052367b6b1d652b)
Signed-off-by: Marcelo Henrique Cerri <email address hidden>

1c980a1... by "Chang S. Bae" <email address hidden>

x86/entry/64: Handle FSGSBASE enabled paranoid entry/exit

BugLink: http://bugs.launchpad.net/bugs/1877425

Without FSGSBASE, user space cannot change GSBASE other than through a
PRCTL. The kernel enforces that the user space GSBASE value is postive as
negative values are used for detecting the kernel space GSBASE value in the
paranoid entry code.

If FSGSBASE is enabled, user space can set arbitrary GSBASE values without
kernel intervention, including negative ones, which breaks the paranoid
entry assumptions.

To avoid this, paranoid entry needs to unconditionally save the current
GSBASE value independent of the interrupted context, retrieve and write the
kernel GSBASE and unconditionally restore the saved value on exit. The
restore happens either in paranoid_exit or in the special exit path of the
NMI low level code.

All other entry code pathes which use unconditional SWAPGS are not affected
as they do not depend on the actual content.

[ tglx: Massaged changelogs and comments ]

Suggested-by: H. Peter Anvin <email address hidden>
Suggested-by: Andy Lutomirski <email address hidden>
Suggested-by: Thomas Gleixner <email address hidden>
Signed-off-by: Chang S. Bae <email address hidden>
Signed-off-by: Thomas Gleixner <email address hidden>
Signed-off-by: Sasha Levin <email address hidden>
Signed-off-by: Thomas Gleixner <email address hidden>
Link: https://lkml<email address hidden>
Link: https://<email address hidden>

(cherry picked from commit c82965f9e53005c1c62632c468968293262056cb)
Signed-off-by: Marcelo Henrique Cerri <email address hidden>

4ce82a8... by "Chang S. Bae" <email address hidden>

x86/entry/64: Introduce the FIND_PERCPU_BASE macro

BugLink: http://bugs.launchpad.net/bugs/1877425

GSBASE is used to find per-CPU data in the kernel. But when GSBASE is
unknown, the per-CPU base can be found from the per_cpu_offset table with a
CPU NR. The CPU NR is extracted from the limit field of the CPUNODE entry
in GDT, or by the RDPID instruction. This is a prerequisite for using
FSGSBASE in the low level entry code.

Also, add the GAS-compatible RDPID macro as binutils 2.23 do not support
it. Support is added in version 2.27.

[ tglx: Massaged changelog ]

Suggested-by: H. Peter Anvin <email address hidden>
Signed-off-by: Chang S. Bae <email address hidden>
Signed-off-by: Thomas Gleixner <email address hidden>
Signed-off-by: Sasha Levin <email address hidden>
Signed-off-by: Thomas Gleixner <email address hidden>
Link: https://lkml<email address hidden>
Link: https://<email address hidden>

(cherry picked from commit eaad981291ee36efee15a5e515d4598ae94ace07)
Signed-off-by: Marcelo Henrique Cerri <email address hidden>

0177ba8... by "Chang S. Bae" <email address hidden>

x86/entry/64: Switch CR3 before SWAPGS in paranoid entry

BugLink: http://bugs.launchpad.net/bugs/1877425

When FSGSBASE is enabled, the GSBASE handling in paranoid entry will need
to retrieve the kernel GSBASE which requires that the kernel page table is
active.

As the CR3 switch to the kernel page tables (PTI is active) does not depend
on kernel GSBASE, move the CR3 switch in front of the GSBASE handling.

Comment the EBX content while at it.

No functional change.

[ tglx: Rewrote changelog and comments ]

Signed-off-by: Chang S. Bae <email address hidden>
Signed-off-by: Thomas Gleixner <email address hidden>
Signed-off-by: Sasha Levin <email address hidden>
Signed-off-by: Thomas Gleixner <email address hidden>
Link: https://lkml<email address hidden>
Link: https://<email address hidden>

(cherry picked from commit 96b2371413e8f636a5f25c42a933af21c35a2a41)
Signed-off-by: Marcelo Henrique Cerri <email address hidden>