Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
x86/entry: Preserve PKRS MSR across exceptions
The PKRS MSR is not managed by XSAVE. It is preserved through a context switch but this support leaves exception handling code open to memory accesses during exceptions. 2 possible places for preserving this state were considered, irqentry_state_t or pt_regs.[1] pt_regs was much more complicated and was potentially fraught with unintended consequences.[2] However, Andy came up with a way to hide additional values on the stack which could be accessed as "extended_pt_regs".[3] This method allows for; any place which has struct pt_regs can get access to the extra information; no extra information is added to irq_state; and pt_regs is left intact for compatibility with outside tools like BPF. To simplify, the assembly code only adds space on the stack. The setting or use of any needed values are left to the C code. While some entry points may not use this space it is still added where ever pt_regs is passed to the C code for consistency. Each nested exception gets another copy of this extended space allowing for any number of levels of exception handling. In the assembly, a macro is defined to allow a central place to add space for other uses should the need arise. Finally export irq_[save_set|restore]_pkrs to the common code to allow it to preserve the current task's PKRS in the new extended pt_regs if enabled. Peter, Thomas, Andy, Dave, and Dan all suggested parts of the patch or aided in the development of the patch.. [1] https://lore.kernel.org/lkml/CALCETrVe1i5JdyzD_BcctxQJn+ZE3T38EFPgjxN1F577M36g+w@mail.gmail.com/ [2] https://lore.kernel.org/lkml/874kpxx4jf.fsf@nanos.tec.linutronix.de/#t [3] https://lore.kernel.org/lkml/CALCETrUHwZPic89oExMMe-WyDY8-O3W68NcZvse3=PGW+iW5=w@mail.gmail.com/ Acked-by: Dave Hansen <dave.hansen@linux.intel.com> Suggested-by: Dave Hansen <dave.hansen@linux.intel.com> Suggested-by: Dan Williams <dan.j.williams@intel.com> Suggested-by: Peter Zijlstra <peterz@infradead.org> Suggested-by: Thomas Gleixner <tglx@linutronix.de> Suggested-by: Andy Lutomirski <luto@kernel.org> Signed-off-by: Ira Weiny <ira.weiny@intel.com> --- Changes from V3: Move all extended regs stuff to pks.h From Dan Williams Move show_extended_regs_oops ifdefery to pks.h Remove a bad comment s/irq_save_set_pkrs/pkrs_save_set_irq s/irq_restore_pkrs/pkrs_restore_irq s/ARCH_HAS/ARCH_ENABLE_SUPERVISOR_PKEYS From Dave Hansen: remove extra macro parameter for most calls clarify with comments Add BUILD check for extend regs size use subq/addq vs push/pop Fix 0-day issues From Dan Williams and Dave Hansen: Use a macro call to wrap the c function calls with push/pop extended_pt_regs From Dave Hansen: Guidance on where to find each of the pt_regs being passed to C code From Thomas Gleixner: Remove unnecessary noinstr's From Andy Lutomirski: Convert to using the extended pt_regs Add in showing pks on fault through the extended pt_regs Changes from V1 remove redundant irq_state->pkrs This value is only needed for the global tracking. So it should be included in that patch and not in this one. Changes from RFC V3 Standardize on 'irq_state' variable name Per Dave Hansen irq_save_pkrs() -> irq_save_set_pkrs() Rebased based on clean up patch by Thomas Gleixner This includes moving irq_[save_set|restore]_pkrs() to the core as well.
- Loading branch information
Showing
10 changed files
with
150 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -53,4 +53,6 @@ | ||
| # define X86_CR3_PTI_PCID_USER_BIT 11 | ||
| #endif | ||
|
|
||
| #define EXTENDED_PT_REGS_SIZE 8 | ||
|
|
||
| #endif /* _ASM_X86_PROCESSOR_FLAGS_H */ | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.