License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2015-06-08 15:49:11 +08:00
|
|
|
* Copyright (C) 1991,1992 Linus Torvalds
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2015-06-08 15:49:11 +08:00
|
|
|
* entry_32.S contains the system-call and low-level fault and trap handling routines.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2015-10-06 08:48:13 +08:00
|
|
|
* Stack layout while running C code:
|
2015-06-08 15:49:11 +08:00
|
|
|
* ptrace needs to have all registers on the stack.
|
|
|
|
* If the order here is changed, it needs to be
|
|
|
|
* updated in fork.c:copy_process(), signal.c:do_signal(),
|
2005-04-17 06:20:36 +08:00
|
|
|
* ptrace.c and ptrace.h
|
|
|
|
*
|
|
|
|
* 0(%esp) - %ebx
|
|
|
|
* 4(%esp) - %ecx
|
|
|
|
* 8(%esp) - %edx
|
2015-06-09 04:35:33 +08:00
|
|
|
* C(%esp) - %esi
|
2005-04-17 06:20:36 +08:00
|
|
|
* 10(%esp) - %edi
|
|
|
|
* 14(%esp) - %ebp
|
|
|
|
* 18(%esp) - %eax
|
|
|
|
* 1C(%esp) - %ds
|
|
|
|
* 20(%esp) - %es
|
2007-02-13 20:26:20 +08:00
|
|
|
* 24(%esp) - %fs
|
2009-02-09 21:17:40 +08:00
|
|
|
* 28(%esp) - %gs saved iff !CONFIG_X86_32_LAZY_GS
|
|
|
|
* 2C(%esp) - orig_eax
|
|
|
|
* 30(%esp) - %eip
|
|
|
|
* 34(%esp) - %cs
|
|
|
|
* 38(%esp) - %eflags
|
|
|
|
* 3C(%esp) - %oldesp
|
|
|
|
* 40(%esp) - %oldss
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/linkage.h>
|
2012-01-04 03:23:06 +08:00
|
|
|
#include <linux/err.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/thread_info.h>
|
2006-07-03 15:24:43 +08:00
|
|
|
#include <asm/irqflags.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/errno.h>
|
|
|
|
#include <asm/segment.h>
|
|
|
|
#include <asm/smp.h>
|
2006-12-07 09:14:01 +08:00
|
|
|
#include <asm/percpu.h>
|
2008-03-26 03:16:32 +08:00
|
|
|
#include <asm/processor-flags.h>
|
2008-05-03 02:10:09 +08:00
|
|
|
#include <asm/irq_vectors.h>
|
2016-01-27 05:12:04 +08:00
|
|
|
#include <asm/cpufeatures.h>
|
2011-08-26 04:10:33 +08:00
|
|
|
#include <asm/alternative-asm.h>
|
2012-04-21 03:19:50 +08:00
|
|
|
#include <asm/asm.h>
|
2012-09-22 04:58:10 +08:00
|
|
|
#include <asm/smap.h>
|
2016-09-22 05:04:01 +08:00
|
|
|
#include <asm/frame.h>
|
2018-01-12 05:46:28 +08:00
|
|
|
#include <asm/nospec-branch.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-08-17 06:16:58 +08:00
|
|
|
#include "calling.h"
|
|
|
|
|
2011-03-08 02:10:39 +08:00
|
|
|
.section .entry.text, "ax"
|
|
|
|
|
2006-12-07 09:14:08 +08:00
|
|
|
/*
|
|
|
|
* We use macros for low-level operations which need to be overridden
|
|
|
|
* for paravirtualization. The following will never clobber any registers:
|
|
|
|
* INTERRUPT_RETURN (aka. "iret")
|
|
|
|
* GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
|
2008-06-25 12:19:26 +08:00
|
|
|
* ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
|
2006-12-07 09:14:08 +08:00
|
|
|
*
|
|
|
|
* For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
|
|
|
|
* specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
|
|
|
|
* Allowing a register to be clobbered can shrink the paravirt replacement
|
|
|
|
* enough to patch inline, increasing performance.
|
|
|
|
*/
|
|
|
|
|
2019-07-27 05:19:42 +08:00
|
|
|
#ifdef CONFIG_PREEMPTION
|
2015-06-08 15:49:11 +08:00
|
|
|
# define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
|
2005-04-17 06:20:36 +08:00
|
|
|
#else
|
2015-06-08 15:49:11 +08:00
|
|
|
# define preempt_stop(clobbers)
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
2006-07-03 15:24:43 +08:00
|
|
|
.macro TRACE_IRQS_IRET
|
|
|
|
#ifdef CONFIG_TRACE_IRQFLAGS
|
2015-06-08 15:49:11 +08:00
|
|
|
testl $X86_EFLAGS_IF, PT_EFLAGS(%esp) # interrupts off?
|
|
|
|
jz 1f
|
2006-07-03 15:24:43 +08:00
|
|
|
TRACE_IRQS_ON
|
|
|
|
1:
|
|
|
|
#endif
|
|
|
|
.endm
|
|
|
|
|
2018-07-18 17:40:49 +08:00
|
|
|
#define PTI_SWITCH_MASK (1 << PAGE_SHIFT)
|
|
|
|
|
2009-02-09 21:17:40 +08:00
|
|
|
/*
|
|
|
|
* User gs save/restore
|
|
|
|
*
|
|
|
|
* %gs is used for userland TLS and kernel only uses it for stack
|
|
|
|
* canary which is required to be at %gs:20 by gcc. Read the comment
|
|
|
|
* at the top of stackprotector.h for more info.
|
|
|
|
*
|
|
|
|
* Local labels 98 and 99 are used.
|
|
|
|
*/
|
|
|
|
#ifdef CONFIG_X86_32_LAZY_GS
|
|
|
|
|
|
|
|
/* unfortunately push/pop can't be no-op */
|
|
|
|
.macro PUSH_GS
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl $0
|
2009-02-09 21:17:40 +08:00
|
|
|
.endm
|
|
|
|
.macro POP_GS pop=0
|
2015-06-08 15:49:11 +08:00
|
|
|
addl $(4 + \pop), %esp
|
2009-02-09 21:17:40 +08:00
|
|
|
.endm
|
|
|
|
.macro POP_GS_EX
|
|
|
|
.endm
|
|
|
|
|
|
|
|
/* all the rest are no-op */
|
|
|
|
.macro PTGS_TO_GS
|
|
|
|
.endm
|
|
|
|
.macro PTGS_TO_GS_EX
|
|
|
|
.endm
|
|
|
|
.macro GS_TO_REG reg
|
|
|
|
.endm
|
|
|
|
.macro REG_TO_PTGS reg
|
|
|
|
.endm
|
|
|
|
.macro SET_KERNEL_GS reg
|
|
|
|
.endm
|
|
|
|
|
|
|
|
#else /* CONFIG_X86_32_LAZY_GS */
|
|
|
|
|
|
|
|
.macro PUSH_GS
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl %gs
|
2009-02-09 21:17:40 +08:00
|
|
|
.endm
|
|
|
|
|
|
|
|
.macro POP_GS pop=0
|
2015-06-08 15:49:11 +08:00
|
|
|
98: popl %gs
|
2009-02-09 21:17:40 +08:00
|
|
|
.if \pop <> 0
|
2015-06-09 04:35:33 +08:00
|
|
|
add $\pop, %esp
|
2009-02-09 21:17:40 +08:00
|
|
|
.endif
|
|
|
|
.endm
|
|
|
|
.macro POP_GS_EX
|
|
|
|
.pushsection .fixup, "ax"
|
2015-06-08 15:49:11 +08:00
|
|
|
99: movl $0, (%esp)
|
|
|
|
jmp 98b
|
2009-02-09 21:17:40 +08:00
|
|
|
.popsection
|
2015-06-08 15:49:11 +08:00
|
|
|
_ASM_EXTABLE(98b, 99b)
|
2009-02-09 21:17:40 +08:00
|
|
|
.endm
|
|
|
|
|
|
|
|
.macro PTGS_TO_GS
|
2015-06-08 15:49:11 +08:00
|
|
|
98: mov PT_GS(%esp), %gs
|
2009-02-09 21:17:40 +08:00
|
|
|
.endm
|
|
|
|
.macro PTGS_TO_GS_EX
|
|
|
|
.pushsection .fixup, "ax"
|
2015-06-08 15:49:11 +08:00
|
|
|
99: movl $0, PT_GS(%esp)
|
|
|
|
jmp 98b
|
2009-02-09 21:17:40 +08:00
|
|
|
.popsection
|
2015-06-08 15:49:11 +08:00
|
|
|
_ASM_EXTABLE(98b, 99b)
|
2009-02-09 21:17:40 +08:00
|
|
|
.endm
|
|
|
|
|
|
|
|
.macro GS_TO_REG reg
|
2015-06-08 15:49:11 +08:00
|
|
|
movl %gs, \reg
|
2009-02-09 21:17:40 +08:00
|
|
|
.endm
|
|
|
|
.macro REG_TO_PTGS reg
|
2015-06-08 15:49:11 +08:00
|
|
|
movl \reg, PT_GS(%esp)
|
2009-02-09 21:17:40 +08:00
|
|
|
.endm
|
|
|
|
.macro SET_KERNEL_GS reg
|
2015-06-08 15:49:11 +08:00
|
|
|
movl $(__KERNEL_STACK_CANARY), \reg
|
|
|
|
movl \reg, %gs
|
2009-02-09 21:17:40 +08:00
|
|
|
.endm
|
|
|
|
|
2015-06-08 15:49:11 +08:00
|
|
|
#endif /* CONFIG_X86_32_LAZY_GS */
|
2009-02-09 21:17:40 +08:00
|
|
|
|
2018-07-18 17:40:49 +08:00
|
|
|
/* Unconditionally switch to user cr3 */
|
|
|
|
.macro SWITCH_TO_USER_CR3 scratch_reg:req
|
|
|
|
ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_PTI
|
|
|
|
|
|
|
|
movl %cr3, \scratch_reg
|
|
|
|
orl $PTI_SWITCH_MASK, \scratch_reg
|
|
|
|
movl \scratch_reg, %cr3
|
|
|
|
.Lend_\@:
|
|
|
|
.endm
|
|
|
|
|
2018-07-18 17:41:16 +08:00
|
|
|
.macro BUG_IF_WRONG_CR3 no_user_check=0
|
|
|
|
#ifdef CONFIG_DEBUG_ENTRY
|
|
|
|
ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_PTI
|
|
|
|
.if \no_user_check == 0
|
|
|
|
/* coming from usermode? */
|
2024-06-11 20:08:33 +08:00
|
|
|
testl $USER_SEGMENT_RPL_MASK, PT_CS(%esp)
|
2018-07-18 17:41:16 +08:00
|
|
|
jz .Lend_\@
|
|
|
|
.endif
|
|
|
|
/* On user-cr3? */
|
|
|
|
movl %cr3, %eax
|
|
|
|
testl $PTI_SWITCH_MASK, %eax
|
|
|
|
jnz .Lend_\@
|
|
|
|
/* From userspace with kernel cr3 - BUG */
|
|
|
|
ud2
|
|
|
|
.Lend_\@:
|
|
|
|
#endif
|
|
|
|
.endm
|
|
|
|
|
2018-07-18 17:40:49 +08:00
|
|
|
/*
|
|
|
|
* Switch to kernel cr3 if not already loaded and return current cr3 in
|
|
|
|
* \scratch_reg
|
|
|
|
*/
|
|
|
|
.macro SWITCH_TO_KERNEL_CR3 scratch_reg:req
|
|
|
|
ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_PTI
|
|
|
|
movl %cr3, \scratch_reg
|
|
|
|
/* Test if we are already on kernel CR3 */
|
|
|
|
testl $PTI_SWITCH_MASK, \scratch_reg
|
|
|
|
jz .Lend_\@
|
|
|
|
andl $(~PTI_SWITCH_MASK), \scratch_reg
|
|
|
|
movl \scratch_reg, %cr3
|
|
|
|
/* Return original CR3 in \scratch_reg */
|
|
|
|
orl $PTI_SWITCH_MASK, \scratch_reg
|
|
|
|
.Lend_\@:
|
|
|
|
.endm
|
|
|
|
|
2019-05-08 05:25:54 +08:00
|
|
|
#define CS_FROM_ENTRY_STACK (1 << 31)
|
|
|
|
#define CS_FROM_USER_CR3 (1 << 30)
|
|
|
|
#define CS_FROM_KERNEL (1 << 29)
|
2024-06-11 20:08:33 +08:00
|
|
|
#define CS_FROM_ESPFIX (1 << 28)
|
2019-05-08 05:25:54 +08:00
|
|
|
|
|
|
|
.macro FIXUP_FRAME
|
|
|
|
/*
|
|
|
|
* The high bits of the CS dword (__csh) are used for CS_FROM_*.
|
|
|
|
* Clear them in case hardware didn't do this for us.
|
|
|
|
*/
|
2024-06-11 20:08:33 +08:00
|
|
|
andl $0x0000ffff, 4*4(%esp)
|
2019-05-08 05:25:54 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_VM86
|
2024-06-11 20:08:33 +08:00
|
|
|
testl $X86_EFLAGS_VM, 5*4(%esp)
|
2019-05-08 05:25:54 +08:00
|
|
|
jnz .Lfrom_usermode_no_fixup_\@
|
|
|
|
#endif
|
2024-06-11 20:08:33 +08:00
|
|
|
testl $USER_SEGMENT_RPL_MASK, 4*4(%esp)
|
2019-05-08 05:25:54 +08:00
|
|
|
jnz .Lfrom_usermode_no_fixup_\@
|
|
|
|
|
2024-06-11 20:08:33 +08:00
|
|
|
orl $CS_FROM_KERNEL, 4*4(%esp)
|
2019-05-08 05:25:54 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* When we're here from kernel mode; the (exception) stack looks like:
|
|
|
|
*
|
2024-06-11 20:08:33 +08:00
|
|
|
* 6*4(%esp) - <previous context>
|
|
|
|
* 5*4(%esp) - flags
|
|
|
|
* 4*4(%esp) - cs
|
|
|
|
* 3*4(%esp) - ip
|
|
|
|
* 2*4(%esp) - orig_eax
|
|
|
|
* 1*4(%esp) - gs / function
|
|
|
|
* 0*4(%esp) - fs
|
2019-05-08 05:25:54 +08:00
|
|
|
*
|
|
|
|
* Lets build a 5 entry IRET frame after that, such that struct pt_regs
|
|
|
|
* is complete and in particular regs->sp is correct. This gives us
|
2024-06-11 20:08:33 +08:00
|
|
|
* the original 6 enties as gap:
|
2019-05-08 05:25:54 +08:00
|
|
|
*
|
2024-06-11 20:08:33 +08:00
|
|
|
* 14*4(%esp) - <previous context>
|
|
|
|
* 13*4(%esp) - gap / flags
|
|
|
|
* 12*4(%esp) - gap / cs
|
|
|
|
* 11*4(%esp) - gap / ip
|
|
|
|
* 10*4(%esp) - gap / orig_eax
|
|
|
|
* 9*4(%esp) - gap / gs / function
|
|
|
|
* 8*4(%esp) - gap / fs
|
|
|
|
* 7*4(%esp) - ss
|
|
|
|
* 6*4(%esp) - sp
|
|
|
|
* 5*4(%esp) - flags
|
|
|
|
* 4*4(%esp) - cs
|
|
|
|
* 3*4(%esp) - ip
|
|
|
|
* 2*4(%esp) - orig_eax
|
|
|
|
* 1*4(%esp) - gs / function
|
|
|
|
* 0*4(%esp) - fs
|
2019-05-08 05:25:54 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
pushl %ss # ss
|
|
|
|
pushl %esp # sp (points at ss)
|
2024-06-11 20:08:33 +08:00
|
|
|
addl $7*4, (%esp) # point sp back at the previous context
|
|
|
|
pushl 7*4(%esp) # flags
|
|
|
|
pushl 7*4(%esp) # cs
|
|
|
|
pushl 7*4(%esp) # ip
|
|
|
|
pushl 7*4(%esp) # orig_eax
|
|
|
|
pushl 7*4(%esp) # gs / function
|
|
|
|
pushl 7*4(%esp) # fs
|
2019-05-08 05:25:54 +08:00
|
|
|
.Lfrom_usermode_no_fixup_\@:
|
|
|
|
.endm
|
|
|
|
|
|
|
|
.macro IRET_FRAME
|
2024-06-11 20:08:33 +08:00
|
|
|
/*
|
|
|
|
* We're called with %ds, %es, %fs, and %gs from the interrupted
|
|
|
|
* frame, so we shouldn't use them. Also, we may be in ESPFIX
|
|
|
|
* mode and therefore have a nonzero SS base and an offset ESP,
|
|
|
|
* so any attempt to access the stack needs to use SS. (except for
|
|
|
|
* accesses through %esp, which automatically use SS.)
|
|
|
|
*/
|
2019-05-08 05:25:54 +08:00
|
|
|
testl $CS_FROM_KERNEL, 1*4(%esp)
|
|
|
|
jz .Lfinished_frame_\@
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reconstruct the 3 entry IRET frame right after the (modified)
|
|
|
|
* regs->sp without lowering %esp in between, such that an NMI in the
|
|
|
|
* middle doesn't scribble our stack.
|
|
|
|
*/
|
|
|
|
pushl %eax
|
|
|
|
pushl %ecx
|
|
|
|
movl 5*4(%esp), %eax # (modified) regs->sp
|
|
|
|
|
|
|
|
movl 4*4(%esp), %ecx # flags
|
2024-06-11 20:08:33 +08:00
|
|
|
movl %ecx, %ss:-1*4(%eax)
|
2019-05-08 05:25:54 +08:00
|
|
|
|
|
|
|
movl 3*4(%esp), %ecx # cs
|
|
|
|
andl $0x0000ffff, %ecx
|
2024-06-11 20:08:33 +08:00
|
|
|
movl %ecx, %ss:-2*4(%eax)
|
2019-05-08 05:25:54 +08:00
|
|
|
|
|
|
|
movl 2*4(%esp), %ecx # ip
|
2024-06-11 20:08:33 +08:00
|
|
|
movl %ecx, %ss:-3*4(%eax)
|
2019-05-08 05:25:54 +08:00
|
|
|
|
|
|
|
movl 1*4(%esp), %ecx # eax
|
2024-06-11 20:08:33 +08:00
|
|
|
movl %ecx, %ss:-4*4(%eax)
|
2019-05-08 05:25:54 +08:00
|
|
|
|
|
|
|
popl %ecx
|
2024-06-11 20:08:33 +08:00
|
|
|
lea -4*4(%eax), %esp
|
2019-05-08 05:25:54 +08:00
|
|
|
popl %eax
|
|
|
|
.Lfinished_frame_\@:
|
|
|
|
.endm
|
|
|
|
|
2024-06-11 20:08:33 +08:00
|
|
|
.macro SAVE_ALL pt_regs_ax=%eax switch_stacks=0 skip_gs=0 unwind_espfix=0
|
2009-02-09 21:17:40 +08:00
|
|
|
cld
|
2019-07-11 19:40:56 +08:00
|
|
|
.if \skip_gs == 0
|
2009-02-09 21:17:40 +08:00
|
|
|
PUSH_GS
|
2019-07-11 19:40:56 +08:00
|
|
|
.endif
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl %fs
|
2024-06-11 20:08:33 +08:00
|
|
|
|
|
|
|
pushl %eax
|
|
|
|
movl $(__KERNEL_PERCPU), %eax
|
|
|
|
movl %eax, %fs
|
|
|
|
.if \unwind_espfix > 0
|
|
|
|
UNWIND_ESPFIX_STACK
|
|
|
|
.endif
|
|
|
|
popl %eax
|
|
|
|
|
|
|
|
FIXUP_FRAME
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl %es
|
|
|
|
pushl %ds
|
2015-10-06 08:48:14 +08:00
|
|
|
pushl \pt_regs_ax
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl %ebp
|
|
|
|
pushl %edi
|
|
|
|
pushl %esi
|
|
|
|
pushl %edx
|
|
|
|
pushl %ecx
|
|
|
|
pushl %ebx
|
|
|
|
movl $(__USER_DS), %edx
|
|
|
|
movl %edx, %ds
|
|
|
|
movl %edx, %es
|
2019-07-11 19:40:56 +08:00
|
|
|
.if \skip_gs == 0
|
2009-02-09 21:17:40 +08:00
|
|
|
SET_KERNEL_GS %edx
|
2019-07-11 19:40:56 +08:00
|
|
|
.endif
|
2018-07-18 17:40:44 +08:00
|
|
|
/* Switch to kernel stack if necessary */
|
|
|
|
.if \switch_stacks > 0
|
|
|
|
SWITCH_TO_KERNEL_STACK
|
|
|
|
.endif
|
2009-02-09 21:17:40 +08:00
|
|
|
.endm
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2024-06-11 20:08:33 +08:00
|
|
|
.macro SAVE_ALL_NMI cr3_reg:req unwind_espfix=0
|
|
|
|
SAVE_ALL unwind_espfix=\unwind_espfix
|
2018-07-18 17:40:50 +08:00
|
|
|
|
2018-07-18 17:41:16 +08:00
|
|
|
BUG_IF_WRONG_CR3
|
|
|
|
|
2018-07-18 17:40:50 +08:00
|
|
|
/*
|
|
|
|
* Now switch the CR3 when PTI is enabled.
|
|
|
|
*
|
|
|
|
* We can enter with either user or kernel cr3, the code will
|
|
|
|
* store the old cr3 in \cr3_reg and switches to the kernel cr3
|
|
|
|
* if necessary.
|
|
|
|
*/
|
|
|
|
SWITCH_TO_KERNEL_CR3 scratch_reg=\cr3_reg
|
|
|
|
|
|
|
|
.Lend_\@:
|
2018-07-18 17:40:46 +08:00
|
|
|
.endm
|
2018-07-18 17:41:16 +08:00
|
|
|
|
2009-02-09 21:17:40 +08:00
|
|
|
.macro RESTORE_INT_REGS
|
2015-06-08 15:49:11 +08:00
|
|
|
popl %ebx
|
|
|
|
popl %ecx
|
|
|
|
popl %edx
|
|
|
|
popl %esi
|
|
|
|
popl %edi
|
|
|
|
popl %ebp
|
|
|
|
popl %eax
|
2009-02-09 21:17:40 +08:00
|
|
|
.endm
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-02-09 21:17:40 +08:00
|
|
|
.macro RESTORE_REGS pop=0
|
2009-02-09 21:17:40 +08:00
|
|
|
RESTORE_INT_REGS
|
2015-06-08 15:49:11 +08:00
|
|
|
1: popl %ds
|
|
|
|
2: popl %es
|
|
|
|
3: popl %fs
|
2009-02-09 21:17:40 +08:00
|
|
|
POP_GS \pop
|
2024-06-11 20:08:33 +08:00
|
|
|
IRET_FRAME
|
2009-02-09 21:17:40 +08:00
|
|
|
.pushsection .fixup, "ax"
|
2015-06-08 15:49:11 +08:00
|
|
|
4: movl $0, (%esp)
|
|
|
|
jmp 1b
|
|
|
|
5: movl $0, (%esp)
|
|
|
|
jmp 2b
|
|
|
|
6: movl $0, (%esp)
|
|
|
|
jmp 3b
|
[PATCH] i386: Use %gs as the PDA base-segment in the kernel
This patch is the meat of the PDA change. This patch makes several related
changes:
1: Most significantly, %gs is now used in the kernel. This means that on
entry, the old value of %gs is saved away, and it is reloaded with
__KERNEL_PDA.
2: entry.S constructs the stack in the shape of struct pt_regs, and this
is passed around the kernel so that the process's saved register
state can be accessed.
Unfortunately struct pt_regs doesn't currently have space for %gs
(or %fs). This patch extends pt_regs to add space for gs (no space
is allocated for %fs, since it won't be used, and it would just
complicate the code in entry.S to work around the space).
3: Because %gs is now saved on the stack like %ds, %es and the integer
registers, there are a number of places where it no longer needs to
be handled specially; namely context switch, and saving/restoring the
register state in a signal context.
4: And since kernel threads run in kernel space and call normal kernel
code, they need to be created with their %gs == __KERNEL_PDA.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Andi Kleen <ak@suse.de>
Cc: Chuck Ebbert <76306.1226@compuserve.com>
Cc: Zachary Amsden <zach@vmware.com>
Cc: Jan Beulich <jbeulich@novell.com>
Cc: Andi Kleen <ak@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
2006-12-07 09:14:02 +08:00
|
|
|
.popsection
|
2015-06-08 15:49:11 +08:00
|
|
|
_ASM_EXTABLE(1b, 4b)
|
|
|
|
_ASM_EXTABLE(2b, 5b)
|
|
|
|
_ASM_EXTABLE(3b, 6b)
|
2009-02-09 21:17:40 +08:00
|
|
|
POP_GS_EX
|
2009-02-09 21:17:40 +08:00
|
|
|
.endm
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-07-18 17:40:50 +08:00
|
|
|
.macro RESTORE_ALL_NMI cr3_reg:req pop=0
|
|
|
|
/*
|
|
|
|
* Now switch the CR3 when PTI is enabled.
|
|
|
|
*
|
|
|
|
* We enter with kernel cr3 and switch the cr3 to the value
|
|
|
|
* stored on \cr3_reg, which is either a user or a kernel cr3.
|
|
|
|
*/
|
|
|
|
ALTERNATIVE "jmp .Lswitched_\@", "", X86_FEATURE_PTI
|
|
|
|
|
|
|
|
testl $PTI_SWITCH_MASK, \cr3_reg
|
|
|
|
jz .Lswitched_\@
|
|
|
|
|
|
|
|
/* User cr3 in \cr3_reg - write it to hardware cr3 */
|
|
|
|
movl \cr3_reg, %cr3
|
|
|
|
|
|
|
|
.Lswitched_\@:
|
|
|
|
|
2018-07-18 17:41:16 +08:00
|
|
|
BUG_IF_WRONG_CR3
|
|
|
|
|
2018-07-18 17:40:46 +08:00
|
|
|
RESTORE_REGS pop=\pop
|
|
|
|
.endm
|
|
|
|
|
2018-07-18 17:40:41 +08:00
|
|
|
.macro CHECK_AND_APPLY_ESPFIX
|
|
|
|
#ifdef CONFIG_X86_ESPFIX32
|
2024-06-11 20:08:33 +08:00
|
|
|
#define GDT_ESPFIX_OFFSET (GDT_ENTRY_ESPFIX_SS * 8)
|
|
|
|
#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + GDT_ESPFIX_OFFSET
|
2018-07-18 17:40:41 +08:00
|
|
|
|
|
|
|
ALTERNATIVE "jmp .Lend_\@", "", X86_BUG_ESPFIX
|
|
|
|
|
|
|
|
movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
|
|
|
|
/*
|
|
|
|
* Warning: PT_OLDSS(%esp) contains the wrong/random values if we
|
|
|
|
* are returning to the kernel.
|
|
|
|
* See comments in process.c:copy_thread() for details.
|
|
|
|
*/
|
|
|
|
movb PT_OLDSS(%esp), %ah
|
|
|
|
movb PT_CS(%esp), %al
|
|
|
|
andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
|
|
|
|
cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
|
|
|
|
jne .Lend_\@ # returning to user-space with LDT SS
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup and switch to ESPFIX stack
|
|
|
|
*
|
|
|
|
* We're returning to userspace with a 16 bit stack. The CPU will not
|
|
|
|
* restore the high word of ESP for us on executing iret... This is an
|
|
|
|
* "official" bug of all the x86-compatible CPUs, which we can work
|
|
|
|
* around to make dosemu and wine happy. We do this by preloading the
|
|
|
|
* high word of ESP with the high word of the userspace ESP while
|
|
|
|
* compensating for the offset by changing to the ESPFIX segment with
|
|
|
|
* a base address that matches for the difference.
|
|
|
|
*/
|
|
|
|
mov %esp, %edx /* load kernel esp */
|
|
|
|
mov PT_OLDESP(%esp), %eax /* load userspace esp */
|
|
|
|
mov %dx, %ax /* eax: new kernel esp */
|
|
|
|
sub %eax, %edx /* offset (low word is 0) */
|
|
|
|
shr $16, %edx
|
|
|
|
mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
|
|
|
|
mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
|
|
|
|
pushl $__ESPFIX_SS
|
|
|
|
pushl %eax /* new kernel esp */
|
|
|
|
/*
|
|
|
|
* Disable interrupts, but do not irqtrace this section: we
|
|
|
|
* will soon execute iret and the tracer was already set to
|
|
|
|
* the irqstate after the IRET:
|
|
|
|
*/
|
|
|
|
DISABLE_INTERRUPTS(CLBR_ANY)
|
|
|
|
lss (%esp), %esp /* switch to espfix segment */
|
|
|
|
.Lend_\@:
|
|
|
|
#endif /* CONFIG_X86_ESPFIX32 */
|
|
|
|
.endm
|
2018-07-18 17:40:44 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Called with pt_regs fully populated and kernel segments loaded,
|
|
|
|
* so we can access PER_CPU and use the integer registers.
|
|
|
|
*
|
|
|
|
* We need to be very careful here with the %esp switch, because an NMI
|
|
|
|
* can happen everywhere. If the NMI handler finds itself on the
|
|
|
|
* entry-stack, it will overwrite the task-stack and everything we
|
|
|
|
* copied there. So allocate the stack-frame on the task-stack and
|
|
|
|
* switch to it before we do any copying.
|
|
|
|
*/
|
2018-07-18 17:40:47 +08:00
|
|
|
|
2018-07-18 17:40:44 +08:00
|
|
|
.macro SWITCH_TO_KERNEL_STACK
|
|
|
|
|
|
|
|
ALTERNATIVE "", "jmp .Lend_\@", X86_FEATURE_XENPV
|
|
|
|
|
2018-07-18 17:41:16 +08:00
|
|
|
BUG_IF_WRONG_CR3
|
|
|
|
|
2018-07-18 17:40:49 +08:00
|
|
|
SWITCH_TO_KERNEL_CR3 scratch_reg=%eax
|
|
|
|
|
|
|
|
/*
|
|
|
|
* %eax now contains the entry cr3 and we carry it forward in
|
|
|
|
* that register for the time this macro runs
|
|
|
|
*/
|
|
|
|
|
2018-07-18 17:40:44 +08:00
|
|
|
/* Are we on the entry stack? Bail out if not! */
|
|
|
|
movl PER_CPU_VAR(cpu_entry_area), %ecx
|
|
|
|
addl $CPU_ENTRY_AREA_entry_stack + SIZEOF_entry_stack, %ecx
|
|
|
|
subl %esp, %ecx /* ecx = (end of entry_stack) - esp */
|
|
|
|
cmpl $SIZEOF_entry_stack, %ecx
|
|
|
|
jae .Lend_\@
|
|
|
|
|
|
|
|
/* Load stack pointer into %esi and %edi */
|
|
|
|
movl %esp, %esi
|
|
|
|
movl %esi, %edi
|
|
|
|
|
|
|
|
/* Move %edi to the top of the entry stack */
|
|
|
|
andl $(MASK_entry_stack), %edi
|
|
|
|
addl $(SIZEOF_entry_stack), %edi
|
|
|
|
|
|
|
|
/* Load top of task-stack into %edi */
|
|
|
|
movl TSS_entry2task_stack(%edi), %edi
|
|
|
|
|
2018-07-18 17:40:47 +08:00
|
|
|
/* Special case - entry from kernel mode via entry stack */
|
2018-07-21 00:22:23 +08:00
|
|
|
#ifdef CONFIG_VM86
|
|
|
|
movl PT_EFLAGS(%esp), %ecx # mix EFLAGS and CS
|
|
|
|
movb PT_CS(%esp), %cl
|
|
|
|
andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %ecx
|
|
|
|
#else
|
|
|
|
movl PT_CS(%esp), %ecx
|
|
|
|
andl $SEGMENT_RPL_MASK, %ecx
|
|
|
|
#endif
|
|
|
|
cmpl $USER_RPL, %ecx
|
|
|
|
jb .Lentry_from_kernel_\@
|
2018-07-18 17:40:47 +08:00
|
|
|
|
2018-07-18 17:40:44 +08:00
|
|
|
/* Bytes to copy */
|
|
|
|
movl $PTREGS_SIZE, %ecx
|
|
|
|
|
|
|
|
#ifdef CONFIG_VM86
|
|
|
|
testl $X86_EFLAGS_VM, PT_EFLAGS(%esi)
|
|
|
|
jz .Lcopy_pt_regs_\@
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stack-frame contains 4 additional segment registers when
|
|
|
|
* coming from VM86 mode
|
|
|
|
*/
|
|
|
|
addl $(4 * 4), %ecx
|
|
|
|
|
|
|
|
#endif
|
2018-07-18 17:40:47 +08:00
|
|
|
.Lcopy_pt_regs_\@:
|
2018-07-18 17:40:44 +08:00
|
|
|
|
|
|
|
/* Allocate frame on task-stack */
|
|
|
|
subl %ecx, %edi
|
|
|
|
|
|
|
|
/* Switch to task-stack */
|
|
|
|
movl %edi, %esp
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We are now on the task-stack and can safely copy over the
|
|
|
|
* stack-frame
|
|
|
|
*/
|
|
|
|
shrl $2, %ecx
|
|
|
|
cld
|
|
|
|
rep movsl
|
|
|
|
|
2018-07-18 17:40:47 +08:00
|
|
|
jmp .Lend_\@
|
|
|
|
|
|
|
|
.Lentry_from_kernel_\@:
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This handles the case when we enter the kernel from
|
|
|
|
* kernel-mode and %esp points to the entry-stack. When this
|
|
|
|
* happens we need to switch to the task-stack to run C code,
|
|
|
|
* but switch back to the entry-stack again when we approach
|
|
|
|
* iret and return to the interrupted code-path. This usually
|
|
|
|
* happens when we hit an exception while restoring user-space
|
2018-07-18 17:40:49 +08:00
|
|
|
* segment registers on the way back to user-space or when the
|
|
|
|
* sysenter handler runs with eflags.tf set.
|
2018-07-18 17:40:47 +08:00
|
|
|
*
|
|
|
|
* When we switch to the task-stack here, we can't trust the
|
|
|
|
* contents of the entry-stack anymore, as the exception handler
|
|
|
|
* might be scheduled out or moved to another CPU. Therefore we
|
|
|
|
* copy the complete entry-stack to the task-stack and set a
|
|
|
|
* marker in the iret-frame (bit 31 of the CS dword) to detect
|
|
|
|
* what we've done on the iret path.
|
|
|
|
*
|
|
|
|
* On the iret path we copy everything back and switch to the
|
|
|
|
* entry-stack, so that the interrupted kernel code-path
|
|
|
|
* continues on the same stack it was interrupted with.
|
|
|
|
*
|
|
|
|
* Be aware that an NMI can happen anytime in this code.
|
|
|
|
*
|
|
|
|
* %esi: Entry-Stack pointer (same as %esp)
|
|
|
|
* %edi: Top of the task stack
|
2018-07-18 17:40:49 +08:00
|
|
|
* %eax: CR3 on kernel entry
|
2018-07-18 17:40:47 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Calculate number of bytes on the entry stack in %ecx */
|
|
|
|
movl %esi, %ecx
|
|
|
|
|
|
|
|
/* %ecx to the top of entry-stack */
|
|
|
|
andl $(MASK_entry_stack), %ecx
|
|
|
|
addl $(SIZEOF_entry_stack), %ecx
|
|
|
|
|
|
|
|
/* Number of bytes on the entry stack to %ecx */
|
|
|
|
sub %esi, %ecx
|
|
|
|
|
|
|
|
/* Mark stackframe as coming from entry stack */
|
|
|
|
orl $CS_FROM_ENTRY_STACK, PT_CS(%esp)
|
|
|
|
|
2018-07-18 17:40:49 +08:00
|
|
|
/*
|
|
|
|
* Test the cr3 used to enter the kernel and add a marker
|
|
|
|
* so that we can switch back to it before iret.
|
|
|
|
*/
|
|
|
|
testl $PTI_SWITCH_MASK, %eax
|
|
|
|
jz .Lcopy_pt_regs_\@
|
|
|
|
orl $CS_FROM_USER_CR3, PT_CS(%esp)
|
|
|
|
|
2018-07-18 17:40:47 +08:00
|
|
|
/*
|
|
|
|
* %esi and %edi are unchanged, %ecx contains the number of
|
|
|
|
* bytes to copy. The code at .Lcopy_pt_regs_\@ will allocate
|
|
|
|
* the stack-frame on task-stack and copy everything over
|
|
|
|
*/
|
|
|
|
jmp .Lcopy_pt_regs_\@
|
|
|
|
|
2018-07-18 17:40:44 +08:00
|
|
|
.Lend_\@:
|
|
|
|
.endm
|
|
|
|
|
2018-07-18 17:40:45 +08:00
|
|
|
/*
|
|
|
|
* Switch back from the kernel stack to the entry stack.
|
|
|
|
*
|
|
|
|
* The %esp register must point to pt_regs on the task stack. It will
|
|
|
|
* first calculate the size of the stack-frame to copy, depending on
|
|
|
|
* whether we return to VM86 mode or not. With that it uses 'rep movsl'
|
|
|
|
* to copy the contents of the stack over to the entry stack.
|
|
|
|
*
|
|
|
|
* We must be very careful here, as we can't trust the contents of the
|
|
|
|
* task-stack once we switched to the entry-stack. When an NMI happens
|
|
|
|
* while on the entry-stack, the NMI handler will switch back to the top
|
|
|
|
* of the task stack, overwriting our stack-frame we are about to copy.
|
|
|
|
* Therefore we switch the stack only after everything is copied over.
|
|
|
|
*/
|
|
|
|
.macro SWITCH_TO_ENTRY_STACK
|
|
|
|
|
|
|
|
ALTERNATIVE "", "jmp .Lend_\@", X86_FEATURE_XENPV
|
|
|
|
|
|
|
|
/* Bytes to copy */
|
|
|
|
movl $PTREGS_SIZE, %ecx
|
|
|
|
|
|
|
|
#ifdef CONFIG_VM86
|
|
|
|
testl $(X86_EFLAGS_VM), PT_EFLAGS(%esp)
|
|
|
|
jz .Lcopy_pt_regs_\@
|
|
|
|
|
|
|
|
/* Additional 4 registers to copy when returning to VM86 mode */
|
|
|
|
addl $(4 * 4), %ecx
|
|
|
|
|
|
|
|
.Lcopy_pt_regs_\@:
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Initialize source and destination for movsl */
|
|
|
|
movl PER_CPU_VAR(cpu_tss_rw + TSS_sp0), %edi
|
|
|
|
subl %ecx, %edi
|
|
|
|
movl %esp, %esi
|
|
|
|
|
|
|
|
/* Save future stack pointer in %ebx */
|
|
|
|
movl %edi, %ebx
|
|
|
|
|
|
|
|
/* Copy over the stack-frame */
|
|
|
|
shrl $2, %ecx
|
|
|
|
cld
|
|
|
|
rep movsl
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Switch to entry-stack - needs to happen after everything is
|
|
|
|
* copied because the NMI handler will overwrite the task-stack
|
|
|
|
* when on entry-stack
|
|
|
|
*/
|
|
|
|
movl %ebx, %esp
|
|
|
|
|
|
|
|
.Lend_\@:
|
|
|
|
.endm
|
|
|
|
|
2018-07-18 17:40:47 +08:00
|
|
|
/*
|
|
|
|
* This macro handles the case when we return to kernel-mode on the iret
|
2018-07-18 17:40:49 +08:00
|
|
|
* path and have to switch back to the entry stack and/or user-cr3
|
2018-07-18 17:40:47 +08:00
|
|
|
*
|
|
|
|
* See the comments below the .Lentry_from_kernel_\@ label in the
|
|
|
|
* SWITCH_TO_KERNEL_STACK macro for more details.
|
|
|
|
*/
|
|
|
|
.macro PARANOID_EXIT_TO_KERNEL_MODE
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test if we entered the kernel with the entry-stack. Most
|
|
|
|
* likely we did not, because this code only runs on the
|
|
|
|
* return-to-kernel path.
|
|
|
|
*/
|
|
|
|
testl $CS_FROM_ENTRY_STACK, PT_CS(%esp)
|
|
|
|
jz .Lend_\@
|
|
|
|
|
|
|
|
/* Unlikely slow-path */
|
|
|
|
|
|
|
|
/* Clear marker from stack-frame */
|
|
|
|
andl $(~CS_FROM_ENTRY_STACK), PT_CS(%esp)
|
|
|
|
|
|
|
|
/* Copy the remaining task-stack contents to entry-stack */
|
|
|
|
movl %esp, %esi
|
|
|
|
movl PER_CPU_VAR(cpu_tss_rw + TSS_sp0), %edi
|
|
|
|
|
|
|
|
/* Bytes on the task-stack to ecx */
|
|
|
|
movl PER_CPU_VAR(cpu_tss_rw + TSS_sp1), %ecx
|
|
|
|
subl %esi, %ecx
|
|
|
|
|
|
|
|
/* Allocate stack-frame on entry-stack */
|
|
|
|
subl %ecx, %edi
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save future stack-pointer, we must not switch until the
|
|
|
|
* copy is done, otherwise the NMI handler could destroy the
|
|
|
|
* contents of the task-stack we are about to copy.
|
|
|
|
*/
|
|
|
|
movl %edi, %ebx
|
|
|
|
|
|
|
|
/* Do the copy */
|
|
|
|
shrl $2, %ecx
|
|
|
|
cld
|
|
|
|
rep movsl
|
|
|
|
|
|
|
|
/* Safe to switch to entry-stack now */
|
|
|
|
movl %ebx, %esp
|
|
|
|
|
2018-07-18 17:40:49 +08:00
|
|
|
/*
|
|
|
|
* We came from entry-stack and need to check if we also need to
|
|
|
|
* switch back to user cr3.
|
|
|
|
*/
|
|
|
|
testl $CS_FROM_USER_CR3, PT_CS(%esp)
|
|
|
|
jz .Lend_\@
|
|
|
|
|
|
|
|
/* Clear marker from stack-frame */
|
|
|
|
andl $(~CS_FROM_USER_CR3), PT_CS(%esp)
|
|
|
|
|
|
|
|
SWITCH_TO_USER_CR3 scratch_reg=%eax
|
|
|
|
|
2018-07-18 17:40:47 +08:00
|
|
|
.Lend_\@:
|
|
|
|
.endm
|
2016-08-14 00:38:19 +08:00
|
|
|
/*
|
|
|
|
* %eax: prev task
|
|
|
|
* %edx: next task
|
|
|
|
*/
|
|
|
|
ENTRY(__switch_to_asm)
|
|
|
|
/*
|
|
|
|
* Save callee-saved registers
|
|
|
|
* This must match the order in struct inactive_task_frame
|
|
|
|
*/
|
|
|
|
pushl %ebp
|
|
|
|
pushl %ebx
|
|
|
|
pushl %edi
|
|
|
|
pushl %esi
|
2019-02-14 17:30:52 +08:00
|
|
|
pushfl
|
2016-08-14 00:38:19 +08:00
|
|
|
|
|
|
|
/* switch stack */
|
|
|
|
movl %esp, TASK_threadsp(%eax)
|
|
|
|
movl TASK_threadsp(%edx), %esp
|
|
|
|
|
Kbuild: rename CC_STACKPROTECTOR[_STRONG] config variables
The changes to automatically test for working stack protector compiler
support in the Kconfig files removed the special STACKPROTECTOR_AUTO
option that picked the strongest stack protector that the compiler
supported.
That was all a nice cleanup - it makes no sense to have the AUTO case
now that the Kconfig phase can just determine the compiler support
directly.
HOWEVER.
It also meant that doing "make oldconfig" would now _disable_ the strong
stackprotector if you had AUTO enabled, because in a legacy config file,
the sane stack protector configuration would look like
CONFIG_HAVE_CC_STACKPROTECTOR=y
# CONFIG_CC_STACKPROTECTOR_NONE is not set
# CONFIG_CC_STACKPROTECTOR_REGULAR is not set
# CONFIG_CC_STACKPROTECTOR_STRONG is not set
CONFIG_CC_STACKPROTECTOR_AUTO=y
and when you ran this through "make oldconfig" with the Kbuild changes,
it would ask you about the regular CONFIG_CC_STACKPROTECTOR (that had
been renamed from CONFIG_CC_STACKPROTECTOR_REGULAR to just
CONFIG_CC_STACKPROTECTOR), but it would think that the STRONG version
used to be disabled (because it was really enabled by AUTO), and would
disable it in the new config, resulting in:
CONFIG_HAVE_CC_STACKPROTECTOR=y
CONFIG_CC_HAS_STACKPROTECTOR_NONE=y
CONFIG_CC_STACKPROTECTOR=y
# CONFIG_CC_STACKPROTECTOR_STRONG is not set
CONFIG_CC_HAS_SANE_STACKPROTECTOR=y
That's dangerously subtle - people could suddenly find themselves with
the weaker stack protector setup without even realizing.
The solution here is to just rename not just the old RECULAR stack
protector option, but also the strong one. This does that by just
removing the CC_ prefix entirely for the user choices, because it really
is not about the compiler support (the compiler support now instead
automatially impacts _visibility_ of the options to users).
This results in "make oldconfig" actually asking the user for their
choice, so that we don't have any silent subtle security model changes.
The end result would generally look like this:
CONFIG_HAVE_CC_STACKPROTECTOR=y
CONFIG_CC_HAS_STACKPROTECTOR_NONE=y
CONFIG_STACKPROTECTOR=y
CONFIG_STACKPROTECTOR_STRONG=y
CONFIG_CC_HAS_SANE_STACKPROTECTOR=y
where the "CC_" versions really are about internal compiler
infrastructure, not the user selections.
Acked-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-06-14 11:21:18 +08:00
|
|
|
#ifdef CONFIG_STACKPROTECTOR
|
2016-08-14 00:38:19 +08:00
|
|
|
movl TASK_stack_canary(%edx), %ebx
|
|
|
|
movl %ebx, PER_CPU_VAR(stack_canary)+stack_canary_offset
|
|
|
|
#endif
|
|
|
|
|
2018-01-13 01:49:25 +08:00
|
|
|
/*
|
|
|
|
* When switching from a shallower to a deeper call stack
|
|
|
|
* the RSB may either underflow or use entries populated
|
|
|
|
* with userspace addresses. On CPUs where those concerns
|
|
|
|
* exist, overwrite the RSB with entries which capture
|
|
|
|
* speculative execution to prevent attack.
|
|
|
|
*/
|
2018-02-19 18:50:56 +08:00
|
|
|
FILL_RETURN_BUFFER %ebx, RSB_CLEAR_LOOPS, X86_FEATURE_RSB_CTXSW
|
2018-01-13 01:49:25 +08:00
|
|
|
|
2016-08-14 00:38:19 +08:00
|
|
|
/* restore callee-saved registers */
|
2019-02-14 17:30:52 +08:00
|
|
|
popfl
|
2016-08-14 00:38:19 +08:00
|
|
|
popl %esi
|
|
|
|
popl %edi
|
|
|
|
popl %ebx
|
|
|
|
popl %ebp
|
|
|
|
|
|
|
|
jmp __switch_to
|
|
|
|
END(__switch_to_asm)
|
|
|
|
|
2017-05-23 23:37:29 +08:00
|
|
|
/*
|
|
|
|
* The unwinder expects the last frame on the stack to always be at the same
|
|
|
|
* offset from the end of the page, which allows it to validate the stack.
|
|
|
|
* Calling schedule_tail() directly would break that convention because its an
|
|
|
|
* asmlinkage function so its argument has to be pushed on the stack. This
|
|
|
|
* wrapper creates a proper "end of stack" frame header before the call.
|
|
|
|
*/
|
|
|
|
ENTRY(schedule_tail_wrapper)
|
|
|
|
FRAME_BEGIN
|
|
|
|
|
|
|
|
pushl %eax
|
|
|
|
call schedule_tail
|
|
|
|
popl %eax
|
|
|
|
|
|
|
|
FRAME_END
|
|
|
|
ret
|
|
|
|
ENDPROC(schedule_tail_wrapper)
|
2016-08-14 00:38:19 +08:00
|
|
|
/*
|
|
|
|
* A newly forked process directly context switches into this address.
|
|
|
|
*
|
|
|
|
* eax: prev task we switched from
|
2016-08-14 00:38:20 +08:00
|
|
|
* ebx: kernel thread func (NULL for user thread)
|
|
|
|
* edi: kernel thread arg
|
2016-08-14 00:38:19 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
ENTRY(ret_from_fork)
|
2017-05-23 23:37:29 +08:00
|
|
|
call schedule_tail_wrapper
|
2015-10-06 08:48:13 +08:00
|
|
|
|
2016-08-14 00:38:20 +08:00
|
|
|
testl %ebx, %ebx
|
|
|
|
jnz 1f /* kernel threads are uncommon */
|
|
|
|
|
|
|
|
2:
|
2015-10-06 08:48:13 +08:00
|
|
|
/* When we fork, we trace the syscall return in the child, too. */
|
2017-05-23 23:37:29 +08:00
|
|
|
movl %esp, %eax
|
2015-10-06 08:48:13 +08:00
|
|
|
call syscall_return_slowpath
|
2018-08-17 06:16:58 +08:00
|
|
|
STACKLEAK_ERASE
|
2015-10-06 08:48:13 +08:00
|
|
|
jmp restore_all
|
|
|
|
|
2016-08-14 00:38:20 +08:00
|
|
|
/* kernel thread */
|
|
|
|
1: movl %edi, %eax
|
2018-01-12 05:46:28 +08:00
|
|
|
CALL_NOSPEC %ebx
|
2015-10-06 08:48:13 +08:00
|
|
|
/*
|
2016-08-14 00:38:20 +08:00
|
|
|
* A kernel thread is allowed to return here after successfully
|
|
|
|
* calling do_execve(). Exit to userspace to complete the execve()
|
|
|
|
* syscall.
|
2015-10-06 08:48:13 +08:00
|
|
|
*/
|
2016-08-14 00:38:20 +08:00
|
|
|
movl $0, PT_EAX(%esp)
|
|
|
|
jmp 2b
|
|
|
|
END(ret_from_fork)
|
2012-08-03 03:05:11 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Return to user mode is not as complex as all this looks,
|
|
|
|
* but we want the default path for a system call return to
|
|
|
|
* go as quickly as possible which is why some of this is
|
|
|
|
* less clear than it otherwise should be.
|
|
|
|
*/
|
|
|
|
|
|
|
|
# userspace resumption stub bypassing syscall exit tracing
|
|
|
|
ALIGN
|
|
|
|
ret_from_exception:
|
2006-12-07 09:14:08 +08:00
|
|
|
preempt_stop(CLBR_ANY)
|
2005-04-17 06:20:36 +08:00
|
|
|
ret_from_intr:
|
2012-03-23 04:39:25 +08:00
|
|
|
#ifdef CONFIG_VM86
|
2015-06-08 15:49:11 +08:00
|
|
|
movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
|
|
|
|
movb PT_CS(%esp), %al
|
|
|
|
andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
|
2012-03-23 04:39:25 +08:00
|
|
|
#else
|
|
|
|
/*
|
2012-08-03 03:05:11 +08:00
|
|
|
* We can be coming here from child spawned by kernel_thread().
|
2012-03-23 04:39:25 +08:00
|
|
|
*/
|
2015-06-08 15:49:11 +08:00
|
|
|
movl PT_CS(%esp), %eax
|
|
|
|
andl $SEGMENT_RPL_MASK, %eax
|
2012-03-23 04:39:25 +08:00
|
|
|
#endif
|
2015-06-08 15:49:11 +08:00
|
|
|
cmpl $USER_RPL, %eax
|
2019-05-08 05:25:54 +08:00
|
|
|
jb restore_all_kernel # not returning to v8086 or userspace
|
[PATCH] i386: Use %gs as the PDA base-segment in the kernel
This patch is the meat of the PDA change. This patch makes several related
changes:
1: Most significantly, %gs is now used in the kernel. This means that on
entry, the old value of %gs is saved away, and it is reloaded with
__KERNEL_PDA.
2: entry.S constructs the stack in the shape of struct pt_regs, and this
is passed around the kernel so that the process's saved register
state can be accessed.
Unfortunately struct pt_regs doesn't currently have space for %gs
(or %fs). This patch extends pt_regs to add space for gs (no space
is allocated for %fs, since it won't be used, and it would just
complicate the code in entry.S to work around the space).
3: Because %gs is now saved on the stack like %ds, %es and the integer
registers, there are a number of places where it no longer needs to
be handled specially; namely context switch, and saving/restoring the
register state in a signal context.
4: And since kernel threads run in kernel space and call normal kernel
code, they need to be created with their %gs == __KERNEL_PDA.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Andi Kleen <ak@suse.de>
Cc: Chuck Ebbert <76306.1226@compuserve.com>
Cc: Zachary Amsden <zach@vmware.com>
Cc: Jan Beulich <jbeulich@novell.com>
Cc: Andi Kleen <ak@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
2006-12-07 09:14:02 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
ENTRY(resume_userspace)
|
2015-08-01 05:41:09 +08:00
|
|
|
DISABLE_INTERRUPTS(CLBR_ANY)
|
2008-06-06 16:14:08 +08:00
|
|
|
TRACE_IRQS_OFF
|
2015-08-01 05:41:09 +08:00
|
|
|
movl %esp, %eax
|
|
|
|
call prepare_exit_to_usermode
|
2015-06-08 15:49:11 +08:00
|
|
|
jmp restore_all
|
2007-02-13 20:26:24 +08:00
|
|
|
END(ret_from_exception)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-03-10 11:00:30 +08:00
|
|
|
GLOBAL(__begin_SYSENTER_singlestep_region)
|
|
|
|
/*
|
|
|
|
* All code from here through __end_SYSENTER_singlestep_region is subject
|
|
|
|
* to being single-stepped if a user program sets TF and executes SYSENTER.
|
|
|
|
* There is absolutely nothing that we can do to prevent this from happening
|
|
|
|
* (thanks Intel!). To keep our handling of this situation as simple as
|
|
|
|
* possible, we handle TF just like AC and NT, except that our #DB handler
|
|
|
|
* will ignore all of the single-step traps generated in this range.
|
|
|
|
*/
|
|
|
|
|
2018-08-28 15:40:12 +08:00
|
|
|
#ifdef CONFIG_XEN_PV
|
2016-03-10 11:00:30 +08:00
|
|
|
/*
|
|
|
|
* Xen doesn't set %esp to be precisely what the normal SYSENTER
|
|
|
|
* entry point expects, so fix it up before using the normal path.
|
|
|
|
*/
|
2024-06-11 20:26:44 +08:00
|
|
|
SYM_CODE_START(xen_sysenter_target)
|
2016-03-10 11:00:30 +08:00
|
|
|
addl $5*4, %esp /* remove xen-provided frame */
|
2016-09-22 05:03:59 +08:00
|
|
|
jmp .Lsysenter_past_esp
|
2024-06-11 20:26:44 +08:00
|
|
|
SYM_CODE_END(xen_sysenter_target)
|
2016-03-10 11:00:30 +08:00
|
|
|
#endif
|
|
|
|
|
2016-03-10 11:00:35 +08:00
|
|
|
/*
|
|
|
|
* 32-bit SYSENTER entry.
|
|
|
|
*
|
|
|
|
* 32-bit system calls through the vDSO's __kernel_vsyscall enter here
|
|
|
|
* if X86_FEATURE_SEP is available. This is the preferred system call
|
|
|
|
* entry on 32-bit systems.
|
|
|
|
*
|
|
|
|
* The SYSENTER instruction, in principle, should *only* occur in the
|
|
|
|
* vDSO. In practice, a small number of Android devices were shipped
|
|
|
|
* with a copy of Bionic that inlined a SYSENTER instruction. This
|
|
|
|
* never happened in any of Google's Bionic versions -- it only happened
|
|
|
|
* in a narrow range of Intel-provided versions.
|
|
|
|
*
|
|
|
|
* SYSENTER loads SS, ESP, CS, and EIP from previously programmed MSRs.
|
|
|
|
* IF and VM in RFLAGS are cleared (IOW: interrupts are off).
|
|
|
|
* SYSENTER does not save anything on the stack,
|
|
|
|
* and does not save old EIP (!!!), ESP, or EFLAGS.
|
|
|
|
*
|
|
|
|
* To avoid losing track of EFLAGS.VM (and thus potentially corrupting
|
|
|
|
* user and/or vm86 state), we explicitly disable the SYSENTER
|
|
|
|
* instruction in vm86 mode by reprogramming the MSRs.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* eax system call number
|
|
|
|
* ebx arg1
|
|
|
|
* ecx arg2
|
|
|
|
* edx arg3
|
|
|
|
* esi arg4
|
|
|
|
* edi arg5
|
|
|
|
* ebp user stack
|
|
|
|
* 0(%ebp) arg6
|
|
|
|
*/
|
2015-06-08 14:33:56 +08:00
|
|
|
ENTRY(entry_SYSENTER_32)
|
2018-07-18 17:40:49 +08:00
|
|
|
/*
|
|
|
|
* On entry-stack with all userspace-regs live - save and
|
|
|
|
* restore eflags and %eax to use it as scratch-reg for the cr3
|
|
|
|
* switch.
|
|
|
|
*/
|
|
|
|
pushfl
|
|
|
|
pushl %eax
|
2018-07-18 17:41:16 +08:00
|
|
|
BUG_IF_WRONG_CR3 no_user_check=1
|
2018-07-18 17:40:49 +08:00
|
|
|
SWITCH_TO_KERNEL_CR3 scratch_reg=%eax
|
|
|
|
popl %eax
|
|
|
|
popfl
|
|
|
|
|
|
|
|
/* Stack empty again, switch to task stack */
|
2018-07-18 17:40:39 +08:00
|
|
|
movl TSS_entry2task_stack(%esp), %esp
|
2018-07-18 17:40:49 +08:00
|
|
|
|
2016-09-22 05:03:59 +08:00
|
|
|
.Lsysenter_past_esp:
|
2015-10-06 08:48:15 +08:00
|
|
|
pushl $__USER_DS /* pt_regs->ss */
|
2015-12-17 15:18:48 +08:00
|
|
|
pushl %ebp /* pt_regs->sp (stashed in bp) */
|
2015-10-06 08:48:15 +08:00
|
|
|
pushfl /* pt_regs->flags (except IF = 0) */
|
|
|
|
orl $X86_EFLAGS_IF, (%esp) /* Fix IF */
|
|
|
|
pushl $__USER_CS /* pt_regs->cs */
|
|
|
|
pushl $0 /* pt_regs->ip = 0 (placeholder) */
|
|
|
|
pushl %eax /* pt_regs->orig_ax */
|
2018-07-18 17:40:44 +08:00
|
|
|
SAVE_ALL pt_regs_ax=$-ENOSYS /* save rest, stack already switched */
|
2015-10-06 08:48:15 +08:00
|
|
|
|
2016-03-10 11:00:26 +08:00
|
|
|
/*
|
2016-03-10 11:00:30 +08:00
|
|
|
* SYSENTER doesn't filter flags, so we need to clear NT, AC
|
|
|
|
* and TF ourselves. To save a few cycles, we can check whether
|
2016-03-10 11:00:26 +08:00
|
|
|
* either was set instead of doing an unconditional popfq.
|
|
|
|
* This needs to happen before enabling interrupts so that
|
|
|
|
* we don't get preempted with NT set.
|
|
|
|
*
|
2016-03-10 11:00:30 +08:00
|
|
|
* If TF is set, we will single-step all the way to here -- do_debug
|
|
|
|
* will ignore all the traps. (Yes, this is slow, but so is
|
|
|
|
* single-stepping in general. This allows us to avoid having
|
|
|
|
* a more complicated code to handle the case where a user program
|
|
|
|
* forces us to single-step through the SYSENTER entry code.)
|
|
|
|
*
|
2016-03-10 11:00:26 +08:00
|
|
|
* NB.: .Lsysenter_fix_flags is a label with the code under it moved
|
|
|
|
* out-of-line as an optimization: NT is unlikely to be set in the
|
|
|
|
* majority of the cases and instead of polluting the I$ unnecessarily,
|
|
|
|
* we're keeping that code behind a branch which will predict as
|
|
|
|
* not-taken and therefore its instructions won't be fetched.
|
|
|
|
*/
|
2016-03-10 11:00:30 +08:00
|
|
|
testl $X86_EFLAGS_NT|X86_EFLAGS_AC|X86_EFLAGS_TF, PT_EFLAGS(%esp)
|
2016-03-10 11:00:26 +08:00
|
|
|
jnz .Lsysenter_fix_flags
|
|
|
|
.Lsysenter_flags_fixed:
|
|
|
|
|
2006-07-03 15:24:43 +08:00
|
|
|
/*
|
2015-10-06 08:48:15 +08:00
|
|
|
* User mode is traced as though IRQs are on, and SYSENTER
|
|
|
|
* turned them off.
|
[PATCH] vdso: randomize the i386 vDSO by moving it into a vma
Move the i386 VDSO down into a vma and thus randomize it.
Besides the security implications, this feature also helps debuggers, which
can COW a vma-backed VDSO just like a normal DSO and can thus do
single-stepping and other debugging features.
It's good for hypervisors (Xen, VMWare) too, which typically live in the same
high-mapped address space as the VDSO, hence whenever the VDSO is used, they
get lots of guest pagefaults and have to fix such guest accesses up - which
slows things down instead of speeding things up (the primary purpose of the
VDSO).
There's a new CONFIG_COMPAT_VDSO (default=y) option, which provides support
for older glibcs that still rely on a prelinked high-mapped VDSO. Newer
distributions (using glibc 2.3.3 or later) can turn this option off. Turning
it off is also recommended for security reasons: attackers cannot use the
predictable high-mapped VDSO page as syscall trampoline anymore.
There is a new vdso=[0|1] boot option as well, and a runtime
/proc/sys/vm/vdso_enabled sysctl switch, that allows the VDSO to be turned
on/off.
(This version of the VDSO-randomization patch also has working ELF
coredumping, the previous patch crashed in the coredumping code.)
This code is a combined work of the exec-shield VDSO randomization
code and Gerd Hoffmann's hypervisor-centric VDSO patch. Rusty Russell
started this patch and i completed it.
[akpm@osdl.org: cleanups]
[akpm@osdl.org: compile fix]
[akpm@osdl.org: compile fix 2]
[akpm@osdl.org: compile fix 3]
[akpm@osdl.org: revernt MAXMEM change]
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Arjan van de Ven <arjan@infradead.org>
Cc: Gerd Hoffmann <kraxel@suse.de>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Zachary Amsden <zach@vmware.com>
Cc: Andi Kleen <ak@muc.de>
Cc: Jan Beulich <jbeulich@novell.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-06-27 17:53:50 +08:00
|
|
|
*/
|
2006-07-03 15:24:43 +08:00
|
|
|
TRACE_IRQS_OFF
|
2015-10-06 08:48:15 +08:00
|
|
|
|
|
|
|
movl %esp, %eax
|
|
|
|
call do_fast_syscall_32
|
2015-11-20 05:55:45 +08:00
|
|
|
/* XEN PV guests always use IRET path */
|
|
|
|
ALTERNATIVE "testl %eax, %eax; jz .Lsyscall_32_done", \
|
|
|
|
"jmp .Lsyscall_32_done", X86_FEATURE_XENPV
|
2015-10-06 08:48:15 +08:00
|
|
|
|
2018-08-17 06:16:58 +08:00
|
|
|
STACKLEAK_ERASE
|
|
|
|
|
2015-10-06 08:48:15 +08:00
|
|
|
/* Opportunistic SYSEXIT */
|
|
|
|
TRACE_IRQS_ON /* User mode traces as IRQs on. */
|
2018-07-18 17:40:45 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup entry stack - we keep the pointer in %eax and do the
|
|
|
|
* switch after almost all user-state is restored.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Load entry stack pointer and allocate frame for eflags/eax */
|
|
|
|
movl PER_CPU_VAR(cpu_tss_rw + TSS_sp0), %eax
|
|
|
|
subl $(2*4), %eax
|
|
|
|
|
|
|
|
/* Copy eflags and eax to entry stack */
|
|
|
|
movl PT_EFLAGS(%esp), %edi
|
|
|
|
movl PT_EAX(%esp), %esi
|
|
|
|
movl %edi, (%eax)
|
|
|
|
movl %esi, 4(%eax)
|
|
|
|
|
|
|
|
/* Restore user registers and segments */
|
2015-10-06 08:48:15 +08:00
|
|
|
movl PT_EIP(%esp), %edx /* pt_regs->ip */
|
|
|
|
movl PT_OLDESP(%esp), %ecx /* pt_regs->sp */
|
2015-10-17 06:42:55 +08:00
|
|
|
1: mov PT_FS(%esp), %fs
|
|
|
|
PTGS_TO_GS
|
2018-07-18 17:40:45 +08:00
|
|
|
|
2015-10-06 08:48:15 +08:00
|
|
|
popl %ebx /* pt_regs->bx */
|
|
|
|
addl $2*4, %esp /* skip pt_regs->cx and pt_regs->dx */
|
|
|
|
popl %esi /* pt_regs->si */
|
|
|
|
popl %edi /* pt_regs->di */
|
|
|
|
popl %ebp /* pt_regs->bp */
|
2018-07-18 17:40:45 +08:00
|
|
|
|
|
|
|
/* Switch to entry stack */
|
|
|
|
movl %eax, %esp
|
2015-10-06 08:48:15 +08:00
|
|
|
|
2018-07-18 17:40:49 +08:00
|
|
|
/* Now ready to switch the cr3 */
|
|
|
|
SWITCH_TO_USER_CR3 scratch_reg=%eax
|
|
|
|
|
2016-03-10 11:00:27 +08:00
|
|
|
/*
|
|
|
|
* Restore all flags except IF. (We restore IF separately because
|
|
|
|
* STI gives a one-instruction window in which we won't be interrupted,
|
|
|
|
* whereas POPF does not.)
|
|
|
|
*/
|
2018-06-25 18:21:59 +08:00
|
|
|
btrl $X86_EFLAGS_IF_BIT, (%esp)
|
2018-07-18 17:41:16 +08:00
|
|
|
BUG_IF_WRONG_CR3 no_user_check=1
|
2016-03-10 11:00:27 +08:00
|
|
|
popfl
|
2018-07-18 17:40:45 +08:00
|
|
|
popl %eax
|
2016-03-10 11:00:27 +08:00
|
|
|
|
2015-10-06 08:48:15 +08:00
|
|
|
/*
|
|
|
|
* Return back to the vDSO, which will pop ecx and edx.
|
|
|
|
* Don't bother with DS and ES (they already contain __USER_DS).
|
|
|
|
*/
|
2015-11-20 05:55:46 +08:00
|
|
|
sti
|
|
|
|
sysexit
|
2008-06-24 19:16:52 +08:00
|
|
|
|
2015-06-08 15:49:11 +08:00
|
|
|
.pushsection .fixup, "ax"
|
|
|
|
2: movl $0, PT_FS(%esp)
|
|
|
|
jmp 1b
|
[PATCH] i386: Use %gs as the PDA base-segment in the kernel
This patch is the meat of the PDA change. This patch makes several related
changes:
1: Most significantly, %gs is now used in the kernel. This means that on
entry, the old value of %gs is saved away, and it is reloaded with
__KERNEL_PDA.
2: entry.S constructs the stack in the shape of struct pt_regs, and this
is passed around the kernel so that the process's saved register
state can be accessed.
Unfortunately struct pt_regs doesn't currently have space for %gs
(or %fs). This patch extends pt_regs to add space for gs (no space
is allocated for %fs, since it won't be used, and it would just
complicate the code in entry.S to work around the space).
3: Because %gs is now saved on the stack like %ds, %es and the integer
registers, there are a number of places where it no longer needs to
be handled specially; namely context switch, and saving/restoring the
register state in a signal context.
4: And since kernel threads run in kernel space and call normal kernel
code, they need to be created with their %gs == __KERNEL_PDA.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Andi Kleen <ak@suse.de>
Cc: Chuck Ebbert <76306.1226@compuserve.com>
Cc: Zachary Amsden <zach@vmware.com>
Cc: Jan Beulich <jbeulich@novell.com>
Cc: Andi Kleen <ak@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
2006-12-07 09:14:02 +08:00
|
|
|
.popsection
|
2015-06-08 15:49:11 +08:00
|
|
|
_ASM_EXTABLE(1b, 2b)
|
2009-02-09 21:17:40 +08:00
|
|
|
PTGS_TO_GS_EX
|
2016-03-10 11:00:26 +08:00
|
|
|
|
|
|
|
.Lsysenter_fix_flags:
|
|
|
|
pushl $X86_EFLAGS_FIXED
|
|
|
|
popfl
|
|
|
|
jmp .Lsysenter_flags_fixed
|
2016-03-10 11:00:30 +08:00
|
|
|
GLOBAL(__end_SYSENTER_singlestep_region)
|
2015-06-08 14:33:56 +08:00
|
|
|
ENDPROC(entry_SYSENTER_32)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-03-10 11:00:35 +08:00
|
|
|
/*
|
|
|
|
* 32-bit legacy system call entry.
|
|
|
|
*
|
|
|
|
* 32-bit x86 Linux system calls traditionally used the INT $0x80
|
|
|
|
* instruction. INT $0x80 lands here.
|
|
|
|
*
|
|
|
|
* This entry point can be used by any 32-bit perform system calls.
|
|
|
|
* Instances of INT $0x80 can be found inline in various programs and
|
|
|
|
* libraries. It is also used by the vDSO's __kernel_vsyscall
|
|
|
|
* fallback for hardware that doesn't support a faster entry method.
|
|
|
|
* Restarted 32-bit system calls also fall back to INT $0x80
|
|
|
|
* regardless of what instruction was originally used to do the system
|
|
|
|
* call. (64-bit programs can use INT $0x80 as well, but they can
|
|
|
|
* only run on 64-bit kernels and therefore land in
|
|
|
|
* entry_INT80_compat.)
|
|
|
|
*
|
|
|
|
* This is considered a slow path. It is not used by most libc
|
|
|
|
* implementations on modern hardware except during process startup.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* eax system call number
|
|
|
|
* ebx arg1
|
|
|
|
* ecx arg2
|
|
|
|
* edx arg3
|
|
|
|
* esi arg4
|
|
|
|
* edi arg5
|
|
|
|
* ebp arg6
|
|
|
|
*/
|
2015-06-08 14:42:03 +08:00
|
|
|
ENTRY(entry_INT80_32)
|
2012-09-22 04:58:10 +08:00
|
|
|
ASM_CLAC
|
2015-10-06 08:48:14 +08:00
|
|
|
pushl %eax /* pt_regs->orig_ax */
|
2018-07-18 17:40:44 +08:00
|
|
|
|
|
|
|
SAVE_ALL pt_regs_ax=$-ENOSYS switch_stacks=1 /* save rest */
|
2015-10-06 08:48:14 +08:00
|
|
|
|
|
|
|
/*
|
2016-03-10 05:24:32 +08:00
|
|
|
* User mode is traced as though IRQs are on, and the interrupt gate
|
|
|
|
* turned them off.
|
2015-10-06 08:48:14 +08:00
|
|
|
*/
|
2016-03-10 05:24:32 +08:00
|
|
|
TRACE_IRQS_OFF
|
2015-10-06 08:48:14 +08:00
|
|
|
|
|
|
|
movl %esp, %eax
|
2016-03-10 05:24:32 +08:00
|
|
|
call do_int80_syscall_32
|
2015-10-06 08:48:15 +08:00
|
|
|
.Lsyscall_32_done:
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-08-17 06:16:58 +08:00
|
|
|
STACKLEAK_ERASE
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
restore_all:
|
i386: fix return to 16-bit stack from NMI handler
Returning to a task with a 16-bit stack requires special care: the iret
instruction does not restore the high word of esp in that case. The
espfix code fixes this, but currently is not invoked on NMIs. This means
that a running task gets the upper word of esp clobbered due intervening
NMIs. To reproduce, compile and run the following program with the nmi
watchdog enabled (nmi_watchdog=2 on the command line). Using gdb you can
see that the high bits of esp contain garbage, while the low bits are
still correct.
This patch puts the espfix code back into the NMI code path.
The patch is slightly complicated due to the irqtrace infrastructure not
being NMI-safe. The NMI return path cannot call TRACE_IRQS_IRET.
Otherwise, the tail of the normal iret-code is correct for the nmi code
path too. To be able to share this code-path, the TRACE_IRQS_IRET was
move up a bit. The espfix code exists after the TRACE_IRQS_IRET, but
this code explicitly disables interrupts. This short interrupts-off
section is now not traced anymore. The return-to-kernel path now always
includes the preliminary test to decide if the espfix code should be
called. This is never the case, but doing it this way keeps the patch as
simple as possible and the few extra instructions should not affect
timing in any significant way.
#define _GNU_SOURCE
#include <stdio.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <asm/ldt.h>
int modify_ldt(int func, void *ptr, unsigned long bytecount)
{
return syscall(SYS_modify_ldt, func, ptr, bytecount);
}
/* this is assumed to be usable */
#define SEGBASEADDR 0x10000
#define SEGLIMIT 0x20000
/* 16-bit segment */
struct user_desc desc = {
.entry_number = 0,
.base_addr = SEGBASEADDR,
.limit = SEGLIMIT,
.seg_32bit = 0,
.contents = 0, /* ??? */
.read_exec_only = 0,
.limit_in_pages = 0,
.seg_not_present = 0,
.useable = 1
};
int main(void)
{
setvbuf(stdout, NULL, _IONBF, 0);
/* map a 64 kb segment */
char *pointer = mmap((void *)SEGBASEADDR, SEGLIMIT+1,
PROT_EXEC|PROT_READ|PROT_WRITE,
MAP_SHARED|MAP_ANONYMOUS, -1, 0);
if (pointer == NULL) {
printf("could not map space\n");
return 0;
}
/* write ldt, new mode */
int err = modify_ldt(0x11, &desc, sizeof(desc));
if (err) {
printf("error modifying ldt: %i\n", err);
return 0;
}
for (int i=0; i<1000; i++) {
asm volatile (
"pusha\n\t"
"mov %ss, %eax\n\t" /* preserve ss:esp */
"mov %esp, %ebp\n\t"
"push $7\n\t" /* index 0, ldt, user mode */
"push $65536-4096\n\t" /* esp */
"lss (%esp), %esp\n\t" /* switch to new stack */
"push %eax\n\t" /* save old ss:esp on new stack */
"push %ebp\n\t"
"add $17*65536, %esp\n\t" /* set high bits */
"mov %esp, %edx\n\t"
"mov $10000000, %ecx\n\t" /* wait... */
"1: loop 1b\n\t" /* ... a bit */
"cmp %esp, %edx\n\t"
"je 1f\n\t"
"ud2\n\t" /* esp changed inexplicably! */
"1:\n\t"
"sub $17*65536, %esp\n\t" /* restore high bits */
"lss (%esp), %esp\n\t" /* restore old ss:esp */
"popa\n\t");
printf("\rx%ix", i);
}
return 0;
}
Signed-off-by: Alexander van Heukelum <heukelum@fastmail.fm>
Acked-by: Stas Sergeev <stsp@aknet.ru>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-18 06:35:57 +08:00
|
|
|
TRACE_IRQS_IRET
|
2018-07-18 17:40:45 +08:00
|
|
|
SWITCH_TO_ENTRY_STACK
|
2016-09-22 05:03:59 +08:00
|
|
|
.Lrestore_all_notrace:
|
2018-07-18 17:40:41 +08:00
|
|
|
CHECK_AND_APPLY_ESPFIX
|
2016-09-22 05:03:59 +08:00
|
|
|
.Lrestore_nocheck:
|
2018-07-18 17:40:49 +08:00
|
|
|
/* Switch back to user CR3 */
|
|
|
|
SWITCH_TO_USER_CR3 scratch_reg=%eax
|
|
|
|
|
2018-07-18 17:41:16 +08:00
|
|
|
BUG_IF_WRONG_CR3
|
|
|
|
|
2018-07-18 17:40:49 +08:00
|
|
|
/* Restore user state */
|
|
|
|
RESTORE_REGS pop=4 # skip orig_eax/error_code
|
2016-09-22 05:03:59 +08:00
|
|
|
.Lirq_return:
|
membarrier/x86: Provide core serializing command
There are two places where core serialization is needed by membarrier:
1) When returning from the membarrier IPI,
2) After scheduler updates curr to a thread with a different mm, before
going back to user-space, since the curr->mm is used by membarrier to
check whether it needs to send an IPI to that CPU.
x86-32 uses IRET as return from interrupt, and both IRET and SYSEXIT to go
back to user-space. The IRET instruction is core serializing, but not
SYSEXIT.
x86-64 uses IRET as return from interrupt, which takes care of the IPI.
However, it can return to user-space through either SYSRETL (compat
code), SYSRETQ, or IRET. Given that SYSRET{L,Q} is not core serializing,
we rely instead on write_cr3() performed by switch_mm() to provide core
serialization after changing the current mm, and deal with the special
case of kthread -> uthread (temporarily keeping current mm into
active_mm) by adding a sync_core() in that specific case.
Use the new sync_core_before_usermode() to guarantee this.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andrea Parri <parri.andrea@gmail.com>
Cc: Andrew Hunter <ahh@google.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Avi Kivity <avi@scylladb.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Dave Watson <davejwatson@fb.com>
Cc: David Sehr <sehr@google.com>
Cc: Greg Hackmann <ghackmann@google.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Maged Michael <maged.michael@gmail.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Will Deacon <will.deacon@arm.com>
Cc: linux-api@vger.kernel.org
Cc: linux-arch@vger.kernel.org
Link: http://lkml.kernel.org/r/20180129202020.8515-10-mathieu.desnoyers@efficios.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2018-01-30 04:20:18 +08:00
|
|
|
/*
|
|
|
|
* ARCH_HAS_MEMBARRIER_SYNC_CORE rely on IRET core serialization
|
|
|
|
* when returning from IPI handler and when returning from
|
|
|
|
* scheduler to user-space.
|
|
|
|
*/
|
2008-02-10 06:24:08 +08:00
|
|
|
INTERRUPT_RETURN
|
2016-09-22 05:03:59 +08:00
|
|
|
|
2018-07-18 17:40:43 +08:00
|
|
|
restore_all_kernel:
|
2019-07-27 05:19:42 +08:00
|
|
|
#ifdef CONFIG_PREEMPTION
|
2019-05-08 05:25:54 +08:00
|
|
|
DISABLE_INTERRUPTS(CLBR_ANY)
|
|
|
|
cmpl $0, PER_CPU_VAR(__preempt_count)
|
|
|
|
jnz .Lno_preempt
|
|
|
|
testl $X86_EFLAGS_IF, PT_EFLAGS(%esp) # interrupts off (exception path) ?
|
|
|
|
jz .Lno_preempt
|
|
|
|
call preempt_schedule_irq
|
|
|
|
.Lno_preempt:
|
|
|
|
#endif
|
2018-07-18 17:40:43 +08:00
|
|
|
TRACE_IRQS_IRET
|
2018-07-18 17:40:47 +08:00
|
|
|
PARANOID_EXIT_TO_KERNEL_MODE
|
2018-07-18 17:41:16 +08:00
|
|
|
BUG_IF_WRONG_CR3
|
2018-07-18 17:40:43 +08:00
|
|
|
RESTORE_REGS 4
|
|
|
|
jmp .Lirq_return
|
|
|
|
|
2015-06-08 15:49:11 +08:00
|
|
|
.section .fixup, "ax"
|
|
|
|
ENTRY(iret_exc )
|
|
|
|
pushl $0 # no error code
|
|
|
|
pushl $do_iret_error
|
2018-07-18 17:41:16 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_ENTRY
|
|
|
|
/*
|
|
|
|
* The stack-frame here is the one that iret faulted on, so its a
|
|
|
|
* return-to-user frame. We are on kernel-cr3 because we come here from
|
|
|
|
* the fixup code. This confuses the CR3 checker, so switch to user-cr3
|
|
|
|
* as the checker expects it.
|
|
|
|
*/
|
|
|
|
pushl %eax
|
|
|
|
SWITCH_TO_USER_CR3 scratch_reg=%eax
|
|
|
|
popl %eax
|
|
|
|
#endif
|
|
|
|
|
2016-09-22 05:04:00 +08:00
|
|
|
jmp common_exception
|
2005-04-17 06:20:36 +08:00
|
|
|
.previous
|
2016-09-22 05:03:59 +08:00
|
|
|
_ASM_EXTABLE(.Lirq_return, iret_exc)
|
2015-06-08 14:42:03 +08:00
|
|
|
ENDPROC(entry_INT80_32)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-02-09 21:17:40 +08:00
|
|
|
.macro FIXUP_ESPFIX_STACK
|
i386: fix/simplify espfix stack switching, move it into assembly
The espfix code triggers if we have a protected mode userspace
application with a 16-bit stack. On returning to userspace, with iret,
the CPU doesn't restore the high word of the stack pointer. This is an
"official" bug, and the work-around used in the kernel is to temporarily
switch to a 32-bit stack segment/pointer pair where the high word of the
pointer is equal to the high word of the userspace stackpointer.
The current implementation uses THREAD_SIZE to determine the cut-off,
but there is no good reason not to use the more natural 64kb... However,
implementing this by simply substituting THREAD_SIZE with 65536 in
patch_espfix_desc crashed the test application. patch_espfix_desc tries
to do what is described above, but gets it subtly wrong if the userspace
stack pointer is just below a multiple of THREAD_SIZE: an overflow
occurs to bit 13... With a bit of luck, when the kernelspace
stackpointer is just below a 64kb-boundary, the overflow then ripples
trough to bit 16 and userspace will see its stack pointer changed by
65536.
This patch moves all espfix code into entry_32.S. Selecting a 16-bit
cut-off simplifies the code. The game with changing the limit dynamically
is removed too. It complicates matters and I see no value in it. Changing
only the top 16-bit word of ESP is one instruction and it also implies
that only two bytes of the ESPFIX GDT entry need to be changed and this
can be implemented in just a handful simple to understand instructions.
As a side effect, the operation to compute the original ESP from the
ESPFIX ESP and the GDT entry simplifies a bit too, and the remaining
three instructions have been expanded inline in entry_32.S.
impact: can now reliably run userspace with ESP=xxxxfffc on 16-bit
stack segment
Signed-off-by: Alexander van Heukelum <heukelum@fastmail.fm>
Acked-by: Stas Sergeev <stsp@aknet.ru>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-18 06:35:58 +08:00
|
|
|
/*
|
|
|
|
* Switch back for ESPFIX stack to the normal zerobased stack
|
|
|
|
*
|
|
|
|
* We can't call C functions using the ESPFIX stack. This code reads
|
|
|
|
* the high word of the segment base from the GDT and swiches to the
|
|
|
|
* normal stack and adjusts ESP with the matching offset.
|
2024-06-11 20:08:33 +08:00
|
|
|
*
|
|
|
|
* We might be on user CR3 here, so percpu data is not mapped and we can't
|
|
|
|
* access the GDT through the percpu segment. Instead, use SGDT to find
|
|
|
|
* the cpu_entry_area alias of the GDT.
|
i386: fix/simplify espfix stack switching, move it into assembly
The espfix code triggers if we have a protected mode userspace
application with a 16-bit stack. On returning to userspace, with iret,
the CPU doesn't restore the high word of the stack pointer. This is an
"official" bug, and the work-around used in the kernel is to temporarily
switch to a 32-bit stack segment/pointer pair where the high word of the
pointer is equal to the high word of the userspace stackpointer.
The current implementation uses THREAD_SIZE to determine the cut-off,
but there is no good reason not to use the more natural 64kb... However,
implementing this by simply substituting THREAD_SIZE with 65536 in
patch_espfix_desc crashed the test application. patch_espfix_desc tries
to do what is described above, but gets it subtly wrong if the userspace
stack pointer is just below a multiple of THREAD_SIZE: an overflow
occurs to bit 13... With a bit of luck, when the kernelspace
stackpointer is just below a 64kb-boundary, the overflow then ripples
trough to bit 16 and userspace will see its stack pointer changed by
65536.
This patch moves all espfix code into entry_32.S. Selecting a 16-bit
cut-off simplifies the code. The game with changing the limit dynamically
is removed too. It complicates matters and I see no value in it. Changing
only the top 16-bit word of ESP is one instruction and it also implies
that only two bytes of the ESPFIX GDT entry need to be changed and this
can be implemented in just a handful simple to understand instructions.
As a side effect, the operation to compute the original ESP from the
ESPFIX ESP and the GDT entry simplifies a bit too, and the remaining
three instructions have been expanded inline in entry_32.S.
impact: can now reliably run userspace with ESP=xxxxfffc on 16-bit
stack segment
Signed-off-by: Alexander van Heukelum <heukelum@fastmail.fm>
Acked-by: Stas Sergeev <stsp@aknet.ru>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-18 06:35:58 +08:00
|
|
|
*/
|
2014-05-05 01:36:22 +08:00
|
|
|
#ifdef CONFIG_X86_ESPFIX32
|
i386: fix/simplify espfix stack switching, move it into assembly
The espfix code triggers if we have a protected mode userspace
application with a 16-bit stack. On returning to userspace, with iret,
the CPU doesn't restore the high word of the stack pointer. This is an
"official" bug, and the work-around used in the kernel is to temporarily
switch to a 32-bit stack segment/pointer pair where the high word of the
pointer is equal to the high word of the userspace stackpointer.
The current implementation uses THREAD_SIZE to determine the cut-off,
but there is no good reason not to use the more natural 64kb... However,
implementing this by simply substituting THREAD_SIZE with 65536 in
patch_espfix_desc crashed the test application. patch_espfix_desc tries
to do what is described above, but gets it subtly wrong if the userspace
stack pointer is just below a multiple of THREAD_SIZE: an overflow
occurs to bit 13... With a bit of luck, when the kernelspace
stackpointer is just below a 64kb-boundary, the overflow then ripples
trough to bit 16 and userspace will see its stack pointer changed by
65536.
This patch moves all espfix code into entry_32.S. Selecting a 16-bit
cut-off simplifies the code. The game with changing the limit dynamically
is removed too. It complicates matters and I see no value in it. Changing
only the top 16-bit word of ESP is one instruction and it also implies
that only two bytes of the ESPFIX GDT entry need to be changed and this
can be implemented in just a handful simple to understand instructions.
As a side effect, the operation to compute the original ESP from the
ESPFIX ESP and the GDT entry simplifies a bit too, and the remaining
three instructions have been expanded inline in entry_32.S.
impact: can now reliably run userspace with ESP=xxxxfffc on 16-bit
stack segment
Signed-off-by: Alexander van Heukelum <heukelum@fastmail.fm>
Acked-by: Stas Sergeev <stsp@aknet.ru>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-18 06:35:58 +08:00
|
|
|
/* fixup the stack */
|
2024-06-11 20:08:33 +08:00
|
|
|
pushl %ecx
|
|
|
|
subl $2*4, %esp
|
|
|
|
sgdt (%esp)
|
|
|
|
movl 2(%esp), %ecx /* GDT address */
|
|
|
|
/*
|
|
|
|
* Careful: ECX is a linear pointer, so we need to force base
|
|
|
|
* zero. %cs is the only known-linear segment we have right now.
|
|
|
|
*/
|
|
|
|
mov %cs:GDT_ESPFIX_OFFSET + 4(%ecx), %al /* bits 16..23 */
|
|
|
|
mov %cs:GDT_ESPFIX_OFFSET + 7(%ecx), %ah /* bits 24..31 */
|
2015-06-09 04:35:33 +08:00
|
|
|
shl $16, %eax
|
2024-06-11 20:08:33 +08:00
|
|
|
addl $2*4, %esp
|
|
|
|
popl %ecx
|
2015-06-08 15:49:11 +08:00
|
|
|
addl %esp, %eax /* the adjusted stack pointer */
|
|
|
|
pushl $__KERNEL_DS
|
|
|
|
pushl %eax
|
|
|
|
lss (%esp), %esp /* switch to the normal stack segment */
|
2014-05-05 01:36:22 +08:00
|
|
|
#endif
|
2009-02-09 21:17:40 +08:00
|
|
|
.endm
|
2024-06-11 20:08:33 +08:00
|
|
|
|
2009-02-09 21:17:40 +08:00
|
|
|
.macro UNWIND_ESPFIX_STACK
|
2024-06-11 20:08:33 +08:00
|
|
|
/* It's safe to clobber %eax, all other regs need to be preserved */
|
2014-05-05 01:36:22 +08:00
|
|
|
#ifdef CONFIG_X86_ESPFIX32
|
2015-06-08 15:49:11 +08:00
|
|
|
movl %ss, %eax
|
2009-02-09 21:17:40 +08:00
|
|
|
/* see if on espfix stack */
|
2015-06-08 15:49:11 +08:00
|
|
|
cmpw $__ESPFIX_SS, %ax
|
2024-06-11 20:08:33 +08:00
|
|
|
jne .Lno_fixup_\@
|
2009-02-09 21:17:40 +08:00
|
|
|
/* switch to normal stack */
|
|
|
|
FIXUP_ESPFIX_STACK
|
2024-06-11 20:08:33 +08:00
|
|
|
.Lno_fixup_\@:
|
2014-05-05 01:36:22 +08:00
|
|
|
#endif
|
2009-02-09 21:17:40 +08:00
|
|
|
.endm
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
2015-04-04 03:49:13 +08:00
|
|
|
* Build the entry stubs with some assembler magic.
|
|
|
|
* We pack 1 stub into every 8-byte block.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2015-04-04 03:49:13 +08:00
|
|
|
.align 8
|
2005-04-17 06:20:36 +08:00
|
|
|
ENTRY(irq_entries_start)
|
2015-04-04 03:49:13 +08:00
|
|
|
vector=FIRST_EXTERNAL_VECTOR
|
|
|
|
.rept (FIRST_SYSTEM_VECTOR - FIRST_EXTERNAL_VECTOR)
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl $(~vector+0x80) /* Note: always in signed byte range */
|
2015-04-04 03:49:13 +08:00
|
|
|
vector=vector+1
|
|
|
|
jmp common_interrupt
|
|
|
|
.align 8
|
|
|
|
.endr
|
2007-02-13 20:26:24 +08:00
|
|
|
END(irq_entries_start)
|
|
|
|
|
2019-06-28 19:11:54 +08:00
|
|
|
#ifdef CONFIG_X86_LOCAL_APIC
|
|
|
|
.align 8
|
|
|
|
ENTRY(spurious_entries_start)
|
|
|
|
vector=FIRST_SYSTEM_VECTOR
|
|
|
|
.rept (NR_VECTORS - FIRST_SYSTEM_VECTOR)
|
|
|
|
pushl $(~vector+0x80) /* Note: always in signed byte range */
|
|
|
|
vector=vector+1
|
|
|
|
jmp common_spurious
|
|
|
|
.align 8
|
|
|
|
.endr
|
|
|
|
END(spurious_entries_start)
|
|
|
|
|
|
|
|
common_spurious:
|
|
|
|
ASM_CLAC
|
|
|
|
addl $-0x80, (%esp) /* Adjust vector into the [-256, -1] range */
|
|
|
|
SAVE_ALL switch_stacks=1
|
|
|
|
ENCODE_FRAME_POINTER
|
|
|
|
TRACE_IRQS_OFF
|
|
|
|
movl %esp, %eax
|
|
|
|
call smp_spurious_interrupt
|
|
|
|
jmp ret_from_intr
|
2019-07-09 14:34:02 +08:00
|
|
|
ENDPROC(common_spurious)
|
2019-06-28 19:11:54 +08:00
|
|
|
#endif
|
|
|
|
|
2006-07-03 15:24:43 +08:00
|
|
|
/*
|
|
|
|
* the CPU automatically disables interrupts when executing an IRQ vector,
|
|
|
|
* so IRQ-flags tracing has to follow that:
|
|
|
|
*/
|
2008-11-12 05:24:58 +08:00
|
|
|
.p2align CONFIG_X86_L1_CACHE_SHIFT
|
2005-04-17 06:20:36 +08:00
|
|
|
common_interrupt:
|
2012-09-22 04:58:10 +08:00
|
|
|
ASM_CLAC
|
2015-06-08 15:49:11 +08:00
|
|
|
addl $-0x80, (%esp) /* Adjust vector into the [-256, -1] range */
|
2018-07-18 17:40:44 +08:00
|
|
|
|
|
|
|
SAVE_ALL switch_stacks=1
|
2016-10-21 00:34:40 +08:00
|
|
|
ENCODE_FRAME_POINTER
|
2006-07-03 15:24:43 +08:00
|
|
|
TRACE_IRQS_OFF
|
2015-06-08 15:49:11 +08:00
|
|
|
movl %esp, %eax
|
|
|
|
call do_IRQ
|
|
|
|
jmp ret_from_intr
|
2007-02-13 20:26:24 +08:00
|
|
|
ENDPROC(common_interrupt)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-07-18 17:40:44 +08:00
|
|
|
#define BUILD_INTERRUPT3(name, nr, fn) \
|
|
|
|
ENTRY(name) \
|
|
|
|
ASM_CLAC; \
|
|
|
|
pushl $~(nr); \
|
|
|
|
SAVE_ALL switch_stacks=1; \
|
|
|
|
ENCODE_FRAME_POINTER; \
|
|
|
|
TRACE_IRQS_OFF \
|
|
|
|
movl %esp, %eax; \
|
|
|
|
call fn; \
|
|
|
|
jmp ret_from_intr; \
|
2007-02-13 20:26:24 +08:00
|
|
|
ENDPROC(name)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-06-08 15:49:11 +08:00
|
|
|
#define BUILD_INTERRUPT(name, nr) \
|
|
|
|
BUILD_INTERRUPT3(name, nr, smp_##name); \
|
2009-01-21 16:26:06 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* The include is where all of the SMP etc. interrupts come from */
|
2009-01-29 02:34:09 +08:00
|
|
|
#include <asm/entry_arch.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ENTRY(coprocessor_error)
|
2012-09-22 04:58:10 +08:00
|
|
|
ASM_CLAC
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl $0
|
|
|
|
pushl $do_coprocessor_error
|
2016-09-22 05:04:00 +08:00
|
|
|
jmp common_exception
|
2007-02-13 20:26:24 +08:00
|
|
|
END(coprocessor_error)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ENTRY(simd_coprocessor_error)
|
2012-09-22 04:58:10 +08:00
|
|
|
ASM_CLAC
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl $0
|
2010-03-21 21:00:43 +08:00
|
|
|
#ifdef CONFIG_X86_INVD_BUG
|
|
|
|
/* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */
|
2015-06-08 15:49:11 +08:00
|
|
|
ALTERNATIVE "pushl $do_general_protection", \
|
|
|
|
"pushl $do_simd_coprocessor_error", \
|
2015-01-18 19:35:55 +08:00
|
|
|
X86_FEATURE_XMM
|
2010-03-21 21:00:43 +08:00
|
|
|
#else
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl $do_simd_coprocessor_error
|
2010-03-21 21:00:43 +08:00
|
|
|
#endif
|
2016-09-22 05:04:00 +08:00
|
|
|
jmp common_exception
|
2007-02-13 20:26:24 +08:00
|
|
|
END(simd_coprocessor_error)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ENTRY(device_not_available)
|
2012-09-22 04:58:10 +08:00
|
|
|
ASM_CLAC
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl $-1 # mark this as an int
|
|
|
|
pushl $do_device_not_available
|
2016-09-22 05:04:00 +08:00
|
|
|
jmp common_exception
|
2007-02-13 20:26:24 +08:00
|
|
|
END(device_not_available)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-12-07 09:14:07 +08:00
|
|
|
#ifdef CONFIG_PARAVIRT
|
|
|
|
ENTRY(native_iret)
|
2008-02-10 06:24:08 +08:00
|
|
|
iret
|
2012-04-21 03:19:50 +08:00
|
|
|
_ASM_EXTABLE(native_iret, iret_exc)
|
2007-02-13 20:26:24 +08:00
|
|
|
END(native_iret)
|
2006-12-07 09:14:07 +08:00
|
|
|
#endif
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
ENTRY(overflow)
|
2012-09-22 04:58:10 +08:00
|
|
|
ASM_CLAC
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl $0
|
|
|
|
pushl $do_overflow
|
2016-09-22 05:04:00 +08:00
|
|
|
jmp common_exception
|
2007-02-13 20:26:24 +08:00
|
|
|
END(overflow)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ENTRY(bounds)
|
2012-09-22 04:58:10 +08:00
|
|
|
ASM_CLAC
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl $0
|
|
|
|
pushl $do_bounds
|
2016-09-22 05:04:00 +08:00
|
|
|
jmp common_exception
|
2007-02-13 20:26:24 +08:00
|
|
|
END(bounds)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ENTRY(invalid_op)
|
2012-09-22 04:58:10 +08:00
|
|
|
ASM_CLAC
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl $0
|
|
|
|
pushl $do_invalid_op
|
2016-09-22 05:04:00 +08:00
|
|
|
jmp common_exception
|
2007-02-13 20:26:24 +08:00
|
|
|
END(invalid_op)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ENTRY(coprocessor_segment_overrun)
|
2012-09-22 04:58:10 +08:00
|
|
|
ASM_CLAC
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl $0
|
|
|
|
pushl $do_coprocessor_segment_overrun
|
2016-09-22 05:04:00 +08:00
|
|
|
jmp common_exception
|
2007-02-13 20:26:24 +08:00
|
|
|
END(coprocessor_segment_overrun)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ENTRY(invalid_TSS)
|
2012-09-22 04:58:10 +08:00
|
|
|
ASM_CLAC
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl $do_invalid_TSS
|
2016-09-22 05:04:00 +08:00
|
|
|
jmp common_exception
|
2007-02-13 20:26:24 +08:00
|
|
|
END(invalid_TSS)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ENTRY(segment_not_present)
|
2012-09-22 04:58:10 +08:00
|
|
|
ASM_CLAC
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl $do_segment_not_present
|
2016-09-22 05:04:00 +08:00
|
|
|
jmp common_exception
|
2007-02-13 20:26:24 +08:00
|
|
|
END(segment_not_present)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ENTRY(stack_segment)
|
2012-09-22 04:58:10 +08:00
|
|
|
ASM_CLAC
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl $do_stack_segment
|
2016-09-22 05:04:00 +08:00
|
|
|
jmp common_exception
|
2007-02-13 20:26:24 +08:00
|
|
|
END(stack_segment)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ENTRY(alignment_check)
|
2012-09-22 04:58:10 +08:00
|
|
|
ASM_CLAC
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl $do_alignment_check
|
2016-09-22 05:04:00 +08:00
|
|
|
jmp common_exception
|
2007-02-13 20:26:24 +08:00
|
|
|
END(alignment_check)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
[PATCH] x86: error_code is not safe for kprobes
This patch moves the entry.S:error_entry to .kprobes.text section,
since code marked unsafe for kprobes jumps directly to entry.S::error_entry,
that must be marked unsafe as well.
This patch also moves all the ".previous.text" asm directives to ".previous"
for kprobes section.
AK: Following a similar i386 patch from Chuck Ebbert
AK: Also merged Jeremy's fix in.
+From: Jeremy Fitzhardinge <jeremy@goop.org>
KPROBE_ENTRY does a .section .kprobes.text, and expects its users to
do a .previous at the end of the function.
Unfortunately, if any code within the function switches sections, for
example .fixup, then the .previous ends up putting all subsequent code
into .fixup. Worse, any subsequent .fixup code gets intermingled with
the code its supposed to be fixing (which is also in .fixup). It's
surprising this didn't cause more havok.
The fix is to use .pushsection/.popsection, so this stuff nests
properly. A further cleanup would be to get rid of all
.section/.previous pairs, since they're inherently fragile.
+From: Chuck Ebbert <76306.1226@compuserve.com>
Because code marked unsafe for kprobes jumps directly to
entry.S::error_code, that must be marked unsafe as well.
The easiest way to do that is to move the page fault entry
point to just before error_code and let it inherit the same
section.
Also moved all the ".previous" asm directives for kprobes
sections to column 1 and removed ".text" from them.
Signed-off-by: Chuck Ebbert <76306.1226@compuserve.com>
Signed-off-by: Andi Kleen <ak@suse.de>
2006-09-26 16:52:34 +08:00
|
|
|
ENTRY(divide_error)
|
2012-09-22 04:58:10 +08:00
|
|
|
ASM_CLAC
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl $0 # no error code
|
|
|
|
pushl $do_divide_error
|
2016-09-22 05:04:00 +08:00
|
|
|
jmp common_exception
|
2007-02-13 20:26:24 +08:00
|
|
|
END(divide_error)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_X86_MCE
|
|
|
|
ENTRY(machine_check)
|
2012-09-22 04:58:10 +08:00
|
|
|
ASM_CLAC
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl $0
|
|
|
|
pushl machine_check_vector
|
2016-09-22 05:04:00 +08:00
|
|
|
jmp common_exception
|
2007-02-13 20:26:24 +08:00
|
|
|
END(machine_check)
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
ENTRY(spurious_interrupt_bug)
|
2012-09-22 04:58:10 +08:00
|
|
|
ASM_CLAC
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl $0
|
|
|
|
pushl $do_spurious_interrupt_bug
|
2016-09-22 05:04:00 +08:00
|
|
|
jmp common_exception
|
2007-02-13 20:26:24 +08:00
|
|
|
END(spurious_interrupt_bug)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-08-28 15:40:12 +08:00
|
|
|
#ifdef CONFIG_XEN_PV
|
xen: Core Xen implementation
This patch is a rollup of all the core pieces of the Xen
implementation, including:
- booting and setup
- pagetable setup
- privileged instructions
- segmentation
- interrupt flags
- upcalls
- multicall batching
BOOTING AND SETUP
The vmlinux image is decorated with ELF notes which tell the Xen
domain builder what the kernel's requirements are; the domain builder
then constructs the address space accordingly and starts the kernel.
Xen has its own entrypoint for the kernel (contained in an ELF note).
The ELF notes are set up by xen-head.S, which is included into head.S.
In principle it could be linked separately, but it seems to provoke
lots of binutils bugs.
Because the domain builder starts the kernel in a fairly sane state
(32-bit protected mode, paging enabled, flat segments set up), there's
not a lot of setup needed before starting the kernel proper. The main
steps are:
1. Install the Xen paravirt_ops, which is simply a matter of a
structure assignment.
2. Set init_mm to use the Xen-supplied pagetables (analogous to the
head.S generated pagetables in a native boot).
3. Reserve address space for Xen, since it takes a chunk at the top
of the address space for its own use.
4. Call start_kernel()
PAGETABLE SETUP
Once we hit the main kernel boot sequence, it will end up calling back
via paravirt_ops to set up various pieces of Xen specific state. One
of the critical things which requires a bit of extra care is the
construction of the initial init_mm pagetable. Because Xen places
tight constraints on pagetables (an active pagetable must always be
valid, and must always be mapped read-only to the guest domain), we
need to be careful when constructing the new pagetable to keep these
constraints in mind. It turns out that the easiest way to do this is
use the initial Xen-provided pagetable as a template, and then just
insert new mappings for memory where a mapping doesn't already exist.
This means that during pagetable setup, it uses a special version of
xen_set_pte which ignores any attempt to remap a read-only page as
read-write (since Xen will map its own initial pagetable as RO), but
lets other changes to the ptes happen, so that things like NX are set
properly.
PRIVILEGED INSTRUCTIONS AND SEGMENTATION
When the kernel runs under Xen, it runs in ring 1 rather than ring 0.
This means that it is more privileged than user-mode in ring 3, but it
still can't run privileged instructions directly. Non-performance
critical instructions are dealt with by taking a privilege exception
and trapping into the hypervisor and emulating the instruction, but
more performance-critical instructions have their own specific
paravirt_ops. In many cases we can avoid having to do any hypercalls
for these instructions, or the Xen implementation is quite different
from the normal native version.
The privileged instructions fall into the broad classes of:
Segmentation: setting up the GDT and the GDT entries, LDT,
TLS and so on. Xen doesn't allow the GDT to be directly
modified; all GDT updates are done via hypercalls where the new
entries can be validated. This is important because Xen uses
segment limits to prevent the guest kernel from damaging the
hypervisor itself.
Traps and exceptions: Xen uses a special format for trap entrypoints,
so when the kernel wants to set an IDT entry, it needs to be
converted to the form Xen expects. Xen sets int 0x80 up specially
so that the trap goes straight from userspace into the guest kernel
without going via the hypervisor. sysenter isn't supported.
Kernel stack: The esp0 entry is extracted from the tss and provided to
Xen.
TLB operations: the various TLB calls are mapped into corresponding
Xen hypercalls.
Control registers: all the control registers are privileged. The most
important is cr3, which points to the base of the current pagetable,
and we handle it specially.
Another instruction we treat specially is CPUID, even though its not
privileged. We want to control what CPU features are visible to the
rest of the kernel, and so CPUID ends up going into a paravirt_op.
Xen implements this mainly to disable the ACPI and APIC subsystems.
INTERRUPT FLAGS
Xen maintains its own separate flag for masking events, which is
contained within the per-cpu vcpu_info structure. Because the guest
kernel runs in ring 1 and not 0, the IF flag in EFLAGS is completely
ignored (and must be, because even if a guest domain disables
interrupts for itself, it can't disable them overall).
(A note on terminology: "events" and interrupts are effectively
synonymous. However, rather than using an "enable flag", Xen uses a
"mask flag", which blocks event delivery when it is non-zero.)
There are paravirt_ops for each of cli/sti/save_fl/restore_fl, which
are implemented to manage the Xen event mask state. The only thing
worth noting is that when events are unmasked, we need to explicitly
see if there's a pending event and call into the hypervisor to make
sure it gets delivered.
UPCALLS
Xen needs a couple of upcall (or callback) functions to be implemented
by each guest. One is the event upcalls, which is how events
(interrupts, effectively) are delivered to the guests. The other is
the failsafe callback, which is used to report errors in either
reloading a segment register, or caused by iret. These are
implemented in i386/kernel/entry.S so they can jump into the normal
iret_exc path when necessary.
MULTICALL BATCHING
Xen provides a multicall mechanism, which allows multiple hypercalls
to be issued at once in order to mitigate the cost of trapping into
the hypervisor. This is particularly useful for context switches,
since the 4-5 hypercalls they would normally need (reload cr3, update
TLS, maybe update LDT) can be reduced to one. This patch implements a
generic batching mechanism for hypercalls, which gets used in many
places in the Xen code.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ian Pratt <ian.pratt@xensource.com>
Cc: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Cc: Adrian Bunk <bunk@stusta.de>
2007-07-18 09:37:04 +08:00
|
|
|
ENTRY(xen_hypervisor_callback)
|
2015-06-08 15:49:11 +08:00
|
|
|
/*
|
|
|
|
* Check to see if we got the event in the critical
|
|
|
|
* region in xen_iret_direct, after we've reenabled
|
|
|
|
* events and checked for pending events. This simulates
|
|
|
|
* iret instruction's behaviour where it delivers a
|
|
|
|
* pending interrupt when enabling interrupts:
|
|
|
|
*/
|
2024-06-11 20:08:33 +08:00
|
|
|
cmpl $xen_iret_start_crit, (%esp)
|
2015-06-08 15:49:11 +08:00
|
|
|
jb 1f
|
2024-06-11 20:08:33 +08:00
|
|
|
cmpl $xen_iret_end_crit, (%esp)
|
2015-06-08 15:49:11 +08:00
|
|
|
jae 1f
|
2024-06-11 20:08:33 +08:00
|
|
|
call xen_iret_crit_fixup
|
|
|
|
1:
|
|
|
|
pushl $-1 /* orig_ax = -1 => not a system call */
|
|
|
|
SAVE_ALL
|
|
|
|
ENCODE_FRAME_POINTER
|
|
|
|
TRACE_IRQS_OFF
|
|
|
|
mov %esp, %eax
|
2015-06-08 15:49:11 +08:00
|
|
|
call xen_evtchn_do_upcall
|
2019-07-27 05:19:42 +08:00
|
|
|
#ifndef CONFIG_PREEMPTION
|
2015-06-08 15:49:11 +08:00
|
|
|
call xen_maybe_preempt_hcall
|
2015-02-19 23:23:17 +08:00
|
|
|
#endif
|
2015-06-08 15:49:11 +08:00
|
|
|
jmp ret_from_intr
|
xen: Core Xen implementation
This patch is a rollup of all the core pieces of the Xen
implementation, including:
- booting and setup
- pagetable setup
- privileged instructions
- segmentation
- interrupt flags
- upcalls
- multicall batching
BOOTING AND SETUP
The vmlinux image is decorated with ELF notes which tell the Xen
domain builder what the kernel's requirements are; the domain builder
then constructs the address space accordingly and starts the kernel.
Xen has its own entrypoint for the kernel (contained in an ELF note).
The ELF notes are set up by xen-head.S, which is included into head.S.
In principle it could be linked separately, but it seems to provoke
lots of binutils bugs.
Because the domain builder starts the kernel in a fairly sane state
(32-bit protected mode, paging enabled, flat segments set up), there's
not a lot of setup needed before starting the kernel proper. The main
steps are:
1. Install the Xen paravirt_ops, which is simply a matter of a
structure assignment.
2. Set init_mm to use the Xen-supplied pagetables (analogous to the
head.S generated pagetables in a native boot).
3. Reserve address space for Xen, since it takes a chunk at the top
of the address space for its own use.
4. Call start_kernel()
PAGETABLE SETUP
Once we hit the main kernel boot sequence, it will end up calling back
via paravirt_ops to set up various pieces of Xen specific state. One
of the critical things which requires a bit of extra care is the
construction of the initial init_mm pagetable. Because Xen places
tight constraints on pagetables (an active pagetable must always be
valid, and must always be mapped read-only to the guest domain), we
need to be careful when constructing the new pagetable to keep these
constraints in mind. It turns out that the easiest way to do this is
use the initial Xen-provided pagetable as a template, and then just
insert new mappings for memory where a mapping doesn't already exist.
This means that during pagetable setup, it uses a special version of
xen_set_pte which ignores any attempt to remap a read-only page as
read-write (since Xen will map its own initial pagetable as RO), but
lets other changes to the ptes happen, so that things like NX are set
properly.
PRIVILEGED INSTRUCTIONS AND SEGMENTATION
When the kernel runs under Xen, it runs in ring 1 rather than ring 0.
This means that it is more privileged than user-mode in ring 3, but it
still can't run privileged instructions directly. Non-performance
critical instructions are dealt with by taking a privilege exception
and trapping into the hypervisor and emulating the instruction, but
more performance-critical instructions have their own specific
paravirt_ops. In many cases we can avoid having to do any hypercalls
for these instructions, or the Xen implementation is quite different
from the normal native version.
The privileged instructions fall into the broad classes of:
Segmentation: setting up the GDT and the GDT entries, LDT,
TLS and so on. Xen doesn't allow the GDT to be directly
modified; all GDT updates are done via hypercalls where the new
entries can be validated. This is important because Xen uses
segment limits to prevent the guest kernel from damaging the
hypervisor itself.
Traps and exceptions: Xen uses a special format for trap entrypoints,
so when the kernel wants to set an IDT entry, it needs to be
converted to the form Xen expects. Xen sets int 0x80 up specially
so that the trap goes straight from userspace into the guest kernel
without going via the hypervisor. sysenter isn't supported.
Kernel stack: The esp0 entry is extracted from the tss and provided to
Xen.
TLB operations: the various TLB calls are mapped into corresponding
Xen hypercalls.
Control registers: all the control registers are privileged. The most
important is cr3, which points to the base of the current pagetable,
and we handle it specially.
Another instruction we treat specially is CPUID, even though its not
privileged. We want to control what CPU features are visible to the
rest of the kernel, and so CPUID ends up going into a paravirt_op.
Xen implements this mainly to disable the ACPI and APIC subsystems.
INTERRUPT FLAGS
Xen maintains its own separate flag for masking events, which is
contained within the per-cpu vcpu_info structure. Because the guest
kernel runs in ring 1 and not 0, the IF flag in EFLAGS is completely
ignored (and must be, because even if a guest domain disables
interrupts for itself, it can't disable them overall).
(A note on terminology: "events" and interrupts are effectively
synonymous. However, rather than using an "enable flag", Xen uses a
"mask flag", which blocks event delivery when it is non-zero.)
There are paravirt_ops for each of cli/sti/save_fl/restore_fl, which
are implemented to manage the Xen event mask state. The only thing
worth noting is that when events are unmasked, we need to explicitly
see if there's a pending event and call into the hypervisor to make
sure it gets delivered.
UPCALLS
Xen needs a couple of upcall (or callback) functions to be implemented
by each guest. One is the event upcalls, which is how events
(interrupts, effectively) are delivered to the guests. The other is
the failsafe callback, which is used to report errors in either
reloading a segment register, or caused by iret. These are
implemented in i386/kernel/entry.S so they can jump into the normal
iret_exc path when necessary.
MULTICALL BATCHING
Xen provides a multicall mechanism, which allows multiple hypercalls
to be issued at once in order to mitigate the cost of trapping into
the hypervisor. This is particularly useful for context switches,
since the 4-5 hypercalls they would normally need (reload cr3, update
TLS, maybe update LDT) can be reduced to one. This patch implements a
generic batching mechanism for hypercalls, which gets used in many
places in the Xen code.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ian Pratt <ian.pratt@xensource.com>
Cc: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Cc: Adrian Bunk <bunk@stusta.de>
2007-07-18 09:37:04 +08:00
|
|
|
ENDPROC(xen_hypervisor_callback)
|
|
|
|
|
2015-06-08 15:49:11 +08:00
|
|
|
/*
|
|
|
|
* Hypervisor uses this for application faults while it executes.
|
|
|
|
* We get here for two reasons:
|
|
|
|
* 1. Fault while reloading DS, ES, FS or GS
|
|
|
|
* 2. Fault while executing IRET
|
|
|
|
* Category 1 we fix up by reattempting the load, and zeroing the segment
|
|
|
|
* register if the load fails.
|
|
|
|
* Category 2 we fix up by jumping to do_iret_error. We cannot use the
|
|
|
|
* normal Linux return path in this case because if we use the IRET hypercall
|
|
|
|
* to pop the stack frame we end up in an infinite loop of failsafe callbacks.
|
|
|
|
* We distinguish between categories by maintaining a status value in EAX.
|
|
|
|
*/
|
xen: Core Xen implementation
This patch is a rollup of all the core pieces of the Xen
implementation, including:
- booting and setup
- pagetable setup
- privileged instructions
- segmentation
- interrupt flags
- upcalls
- multicall batching
BOOTING AND SETUP
The vmlinux image is decorated with ELF notes which tell the Xen
domain builder what the kernel's requirements are; the domain builder
then constructs the address space accordingly and starts the kernel.
Xen has its own entrypoint for the kernel (contained in an ELF note).
The ELF notes are set up by xen-head.S, which is included into head.S.
In principle it could be linked separately, but it seems to provoke
lots of binutils bugs.
Because the domain builder starts the kernel in a fairly sane state
(32-bit protected mode, paging enabled, flat segments set up), there's
not a lot of setup needed before starting the kernel proper. The main
steps are:
1. Install the Xen paravirt_ops, which is simply a matter of a
structure assignment.
2. Set init_mm to use the Xen-supplied pagetables (analogous to the
head.S generated pagetables in a native boot).
3. Reserve address space for Xen, since it takes a chunk at the top
of the address space for its own use.
4. Call start_kernel()
PAGETABLE SETUP
Once we hit the main kernel boot sequence, it will end up calling back
via paravirt_ops to set up various pieces of Xen specific state. One
of the critical things which requires a bit of extra care is the
construction of the initial init_mm pagetable. Because Xen places
tight constraints on pagetables (an active pagetable must always be
valid, and must always be mapped read-only to the guest domain), we
need to be careful when constructing the new pagetable to keep these
constraints in mind. It turns out that the easiest way to do this is
use the initial Xen-provided pagetable as a template, and then just
insert new mappings for memory where a mapping doesn't already exist.
This means that during pagetable setup, it uses a special version of
xen_set_pte which ignores any attempt to remap a read-only page as
read-write (since Xen will map its own initial pagetable as RO), but
lets other changes to the ptes happen, so that things like NX are set
properly.
PRIVILEGED INSTRUCTIONS AND SEGMENTATION
When the kernel runs under Xen, it runs in ring 1 rather than ring 0.
This means that it is more privileged than user-mode in ring 3, but it
still can't run privileged instructions directly. Non-performance
critical instructions are dealt with by taking a privilege exception
and trapping into the hypervisor and emulating the instruction, but
more performance-critical instructions have their own specific
paravirt_ops. In many cases we can avoid having to do any hypercalls
for these instructions, or the Xen implementation is quite different
from the normal native version.
The privileged instructions fall into the broad classes of:
Segmentation: setting up the GDT and the GDT entries, LDT,
TLS and so on. Xen doesn't allow the GDT to be directly
modified; all GDT updates are done via hypercalls where the new
entries can be validated. This is important because Xen uses
segment limits to prevent the guest kernel from damaging the
hypervisor itself.
Traps and exceptions: Xen uses a special format for trap entrypoints,
so when the kernel wants to set an IDT entry, it needs to be
converted to the form Xen expects. Xen sets int 0x80 up specially
so that the trap goes straight from userspace into the guest kernel
without going via the hypervisor. sysenter isn't supported.
Kernel stack: The esp0 entry is extracted from the tss and provided to
Xen.
TLB operations: the various TLB calls are mapped into corresponding
Xen hypercalls.
Control registers: all the control registers are privileged. The most
important is cr3, which points to the base of the current pagetable,
and we handle it specially.
Another instruction we treat specially is CPUID, even though its not
privileged. We want to control what CPU features are visible to the
rest of the kernel, and so CPUID ends up going into a paravirt_op.
Xen implements this mainly to disable the ACPI and APIC subsystems.
INTERRUPT FLAGS
Xen maintains its own separate flag for masking events, which is
contained within the per-cpu vcpu_info structure. Because the guest
kernel runs in ring 1 and not 0, the IF flag in EFLAGS is completely
ignored (and must be, because even if a guest domain disables
interrupts for itself, it can't disable them overall).
(A note on terminology: "events" and interrupts are effectively
synonymous. However, rather than using an "enable flag", Xen uses a
"mask flag", which blocks event delivery when it is non-zero.)
There are paravirt_ops for each of cli/sti/save_fl/restore_fl, which
are implemented to manage the Xen event mask state. The only thing
worth noting is that when events are unmasked, we need to explicitly
see if there's a pending event and call into the hypervisor to make
sure it gets delivered.
UPCALLS
Xen needs a couple of upcall (or callback) functions to be implemented
by each guest. One is the event upcalls, which is how events
(interrupts, effectively) are delivered to the guests. The other is
the failsafe callback, which is used to report errors in either
reloading a segment register, or caused by iret. These are
implemented in i386/kernel/entry.S so they can jump into the normal
iret_exc path when necessary.
MULTICALL BATCHING
Xen provides a multicall mechanism, which allows multiple hypercalls
to be issued at once in order to mitigate the cost of trapping into
the hypervisor. This is particularly useful for context switches,
since the 4-5 hypercalls they would normally need (reload cr3, update
TLS, maybe update LDT) can be reduced to one. This patch implements a
generic batching mechanism for hypercalls, which gets used in many
places in the Xen code.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ian Pratt <ian.pratt@xensource.com>
Cc: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Cc: Adrian Bunk <bunk@stusta.de>
2007-07-18 09:37:04 +08:00
|
|
|
ENTRY(xen_failsafe_callback)
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl %eax
|
|
|
|
movl $1, %eax
|
|
|
|
1: mov 4(%esp), %ds
|
|
|
|
2: mov 8(%esp), %es
|
|
|
|
3: mov 12(%esp), %fs
|
|
|
|
4: mov 16(%esp), %gs
|
2012-10-20 00:29:07 +08:00
|
|
|
/* EAX == 0 => Category 1 (Bad segment)
|
|
|
|
EAX != 0 => Category 2 (Bad IRET) */
|
2015-06-08 15:49:11 +08:00
|
|
|
testl %eax, %eax
|
|
|
|
popl %eax
|
|
|
|
lea 16(%esp), %esp
|
|
|
|
jz 5f
|
|
|
|
jmp iret_exc
|
|
|
|
5: pushl $-1 /* orig_ax = -1 => not a system call */
|
xen: Core Xen implementation
This patch is a rollup of all the core pieces of the Xen
implementation, including:
- booting and setup
- pagetable setup
- privileged instructions
- segmentation
- interrupt flags
- upcalls
- multicall batching
BOOTING AND SETUP
The vmlinux image is decorated with ELF notes which tell the Xen
domain builder what the kernel's requirements are; the domain builder
then constructs the address space accordingly and starts the kernel.
Xen has its own entrypoint for the kernel (contained in an ELF note).
The ELF notes are set up by xen-head.S, which is included into head.S.
In principle it could be linked separately, but it seems to provoke
lots of binutils bugs.
Because the domain builder starts the kernel in a fairly sane state
(32-bit protected mode, paging enabled, flat segments set up), there's
not a lot of setup needed before starting the kernel proper. The main
steps are:
1. Install the Xen paravirt_ops, which is simply a matter of a
structure assignment.
2. Set init_mm to use the Xen-supplied pagetables (analogous to the
head.S generated pagetables in a native boot).
3. Reserve address space for Xen, since it takes a chunk at the top
of the address space for its own use.
4. Call start_kernel()
PAGETABLE SETUP
Once we hit the main kernel boot sequence, it will end up calling back
via paravirt_ops to set up various pieces of Xen specific state. One
of the critical things which requires a bit of extra care is the
construction of the initial init_mm pagetable. Because Xen places
tight constraints on pagetables (an active pagetable must always be
valid, and must always be mapped read-only to the guest domain), we
need to be careful when constructing the new pagetable to keep these
constraints in mind. It turns out that the easiest way to do this is
use the initial Xen-provided pagetable as a template, and then just
insert new mappings for memory where a mapping doesn't already exist.
This means that during pagetable setup, it uses a special version of
xen_set_pte which ignores any attempt to remap a read-only page as
read-write (since Xen will map its own initial pagetable as RO), but
lets other changes to the ptes happen, so that things like NX are set
properly.
PRIVILEGED INSTRUCTIONS AND SEGMENTATION
When the kernel runs under Xen, it runs in ring 1 rather than ring 0.
This means that it is more privileged than user-mode in ring 3, but it
still can't run privileged instructions directly. Non-performance
critical instructions are dealt with by taking a privilege exception
and trapping into the hypervisor and emulating the instruction, but
more performance-critical instructions have their own specific
paravirt_ops. In many cases we can avoid having to do any hypercalls
for these instructions, or the Xen implementation is quite different
from the normal native version.
The privileged instructions fall into the broad classes of:
Segmentation: setting up the GDT and the GDT entries, LDT,
TLS and so on. Xen doesn't allow the GDT to be directly
modified; all GDT updates are done via hypercalls where the new
entries can be validated. This is important because Xen uses
segment limits to prevent the guest kernel from damaging the
hypervisor itself.
Traps and exceptions: Xen uses a special format for trap entrypoints,
so when the kernel wants to set an IDT entry, it needs to be
converted to the form Xen expects. Xen sets int 0x80 up specially
so that the trap goes straight from userspace into the guest kernel
without going via the hypervisor. sysenter isn't supported.
Kernel stack: The esp0 entry is extracted from the tss and provided to
Xen.
TLB operations: the various TLB calls are mapped into corresponding
Xen hypercalls.
Control registers: all the control registers are privileged. The most
important is cr3, which points to the base of the current pagetable,
and we handle it specially.
Another instruction we treat specially is CPUID, even though its not
privileged. We want to control what CPU features are visible to the
rest of the kernel, and so CPUID ends up going into a paravirt_op.
Xen implements this mainly to disable the ACPI and APIC subsystems.
INTERRUPT FLAGS
Xen maintains its own separate flag for masking events, which is
contained within the per-cpu vcpu_info structure. Because the guest
kernel runs in ring 1 and not 0, the IF flag in EFLAGS is completely
ignored (and must be, because even if a guest domain disables
interrupts for itself, it can't disable them overall).
(A note on terminology: "events" and interrupts are effectively
synonymous. However, rather than using an "enable flag", Xen uses a
"mask flag", which blocks event delivery when it is non-zero.)
There are paravirt_ops for each of cli/sti/save_fl/restore_fl, which
are implemented to manage the Xen event mask state. The only thing
worth noting is that when events are unmasked, we need to explicitly
see if there's a pending event and call into the hypervisor to make
sure it gets delivered.
UPCALLS
Xen needs a couple of upcall (or callback) functions to be implemented
by each guest. One is the event upcalls, which is how events
(interrupts, effectively) are delivered to the guests. The other is
the failsafe callback, which is used to report errors in either
reloading a segment register, or caused by iret. These are
implemented in i386/kernel/entry.S so they can jump into the normal
iret_exc path when necessary.
MULTICALL BATCHING
Xen provides a multicall mechanism, which allows multiple hypercalls
to be issued at once in order to mitigate the cost of trapping into
the hypervisor. This is particularly useful for context switches,
since the 4-5 hypercalls they would normally need (reload cr3, update
TLS, maybe update LDT) can be reduced to one. This patch implements a
generic batching mechanism for hypercalls, which gets used in many
places in the Xen code.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ian Pratt <ian.pratt@xensource.com>
Cc: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Cc: Adrian Bunk <bunk@stusta.de>
2007-07-18 09:37:04 +08:00
|
|
|
SAVE_ALL
|
2016-10-21 00:34:40 +08:00
|
|
|
ENCODE_FRAME_POINTER
|
2015-06-08 15:49:11 +08:00
|
|
|
jmp ret_from_exception
|
|
|
|
|
|
|
|
.section .fixup, "ax"
|
|
|
|
6: xorl %eax, %eax
|
|
|
|
movl %eax, 4(%esp)
|
|
|
|
jmp 1b
|
|
|
|
7: xorl %eax, %eax
|
|
|
|
movl %eax, 8(%esp)
|
|
|
|
jmp 2b
|
|
|
|
8: xorl %eax, %eax
|
|
|
|
movl %eax, 12(%esp)
|
|
|
|
jmp 3b
|
|
|
|
9: xorl %eax, %eax
|
|
|
|
movl %eax, 16(%esp)
|
|
|
|
jmp 4b
|
xen: Core Xen implementation
This patch is a rollup of all the core pieces of the Xen
implementation, including:
- booting and setup
- pagetable setup
- privileged instructions
- segmentation
- interrupt flags
- upcalls
- multicall batching
BOOTING AND SETUP
The vmlinux image is decorated with ELF notes which tell the Xen
domain builder what the kernel's requirements are; the domain builder
then constructs the address space accordingly and starts the kernel.
Xen has its own entrypoint for the kernel (contained in an ELF note).
The ELF notes are set up by xen-head.S, which is included into head.S.
In principle it could be linked separately, but it seems to provoke
lots of binutils bugs.
Because the domain builder starts the kernel in a fairly sane state
(32-bit protected mode, paging enabled, flat segments set up), there's
not a lot of setup needed before starting the kernel proper. The main
steps are:
1. Install the Xen paravirt_ops, which is simply a matter of a
structure assignment.
2. Set init_mm to use the Xen-supplied pagetables (analogous to the
head.S generated pagetables in a native boot).
3. Reserve address space for Xen, since it takes a chunk at the top
of the address space for its own use.
4. Call start_kernel()
PAGETABLE SETUP
Once we hit the main kernel boot sequence, it will end up calling back
via paravirt_ops to set up various pieces of Xen specific state. One
of the critical things which requires a bit of extra care is the
construction of the initial init_mm pagetable. Because Xen places
tight constraints on pagetables (an active pagetable must always be
valid, and must always be mapped read-only to the guest domain), we
need to be careful when constructing the new pagetable to keep these
constraints in mind. It turns out that the easiest way to do this is
use the initial Xen-provided pagetable as a template, and then just
insert new mappings for memory where a mapping doesn't already exist.
This means that during pagetable setup, it uses a special version of
xen_set_pte which ignores any attempt to remap a read-only page as
read-write (since Xen will map its own initial pagetable as RO), but
lets other changes to the ptes happen, so that things like NX are set
properly.
PRIVILEGED INSTRUCTIONS AND SEGMENTATION
When the kernel runs under Xen, it runs in ring 1 rather than ring 0.
This means that it is more privileged than user-mode in ring 3, but it
still can't run privileged instructions directly. Non-performance
critical instructions are dealt with by taking a privilege exception
and trapping into the hypervisor and emulating the instruction, but
more performance-critical instructions have their own specific
paravirt_ops. In many cases we can avoid having to do any hypercalls
for these instructions, or the Xen implementation is quite different
from the normal native version.
The privileged instructions fall into the broad classes of:
Segmentation: setting up the GDT and the GDT entries, LDT,
TLS and so on. Xen doesn't allow the GDT to be directly
modified; all GDT updates are done via hypercalls where the new
entries can be validated. This is important because Xen uses
segment limits to prevent the guest kernel from damaging the
hypervisor itself.
Traps and exceptions: Xen uses a special format for trap entrypoints,
so when the kernel wants to set an IDT entry, it needs to be
converted to the form Xen expects. Xen sets int 0x80 up specially
so that the trap goes straight from userspace into the guest kernel
without going via the hypervisor. sysenter isn't supported.
Kernel stack: The esp0 entry is extracted from the tss and provided to
Xen.
TLB operations: the various TLB calls are mapped into corresponding
Xen hypercalls.
Control registers: all the control registers are privileged. The most
important is cr3, which points to the base of the current pagetable,
and we handle it specially.
Another instruction we treat specially is CPUID, even though its not
privileged. We want to control what CPU features are visible to the
rest of the kernel, and so CPUID ends up going into a paravirt_op.
Xen implements this mainly to disable the ACPI and APIC subsystems.
INTERRUPT FLAGS
Xen maintains its own separate flag for masking events, which is
contained within the per-cpu vcpu_info structure. Because the guest
kernel runs in ring 1 and not 0, the IF flag in EFLAGS is completely
ignored (and must be, because even if a guest domain disables
interrupts for itself, it can't disable them overall).
(A note on terminology: "events" and interrupts are effectively
synonymous. However, rather than using an "enable flag", Xen uses a
"mask flag", which blocks event delivery when it is non-zero.)
There are paravirt_ops for each of cli/sti/save_fl/restore_fl, which
are implemented to manage the Xen event mask state. The only thing
worth noting is that when events are unmasked, we need to explicitly
see if there's a pending event and call into the hypervisor to make
sure it gets delivered.
UPCALLS
Xen needs a couple of upcall (or callback) functions to be implemented
by each guest. One is the event upcalls, which is how events
(interrupts, effectively) are delivered to the guests. The other is
the failsafe callback, which is used to report errors in either
reloading a segment register, or caused by iret. These are
implemented in i386/kernel/entry.S so they can jump into the normal
iret_exc path when necessary.
MULTICALL BATCHING
Xen provides a multicall mechanism, which allows multiple hypercalls
to be issued at once in order to mitigate the cost of trapping into
the hypervisor. This is particularly useful for context switches,
since the 4-5 hypercalls they would normally need (reload cr3, update
TLS, maybe update LDT) can be reduced to one. This patch implements a
generic batching mechanism for hypercalls, which gets used in many
places in the Xen code.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ian Pratt <ian.pratt@xensource.com>
Cc: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Cc: Adrian Bunk <bunk@stusta.de>
2007-07-18 09:37:04 +08:00
|
|
|
.previous
|
2015-06-08 15:49:11 +08:00
|
|
|
_ASM_EXTABLE(1b, 6b)
|
|
|
|
_ASM_EXTABLE(2b, 7b)
|
|
|
|
_ASM_EXTABLE(3b, 8b)
|
|
|
|
_ASM_EXTABLE(4b, 9b)
|
xen: Core Xen implementation
This patch is a rollup of all the core pieces of the Xen
implementation, including:
- booting and setup
- pagetable setup
- privileged instructions
- segmentation
- interrupt flags
- upcalls
- multicall batching
BOOTING AND SETUP
The vmlinux image is decorated with ELF notes which tell the Xen
domain builder what the kernel's requirements are; the domain builder
then constructs the address space accordingly and starts the kernel.
Xen has its own entrypoint for the kernel (contained in an ELF note).
The ELF notes are set up by xen-head.S, which is included into head.S.
In principle it could be linked separately, but it seems to provoke
lots of binutils bugs.
Because the domain builder starts the kernel in a fairly sane state
(32-bit protected mode, paging enabled, flat segments set up), there's
not a lot of setup needed before starting the kernel proper. The main
steps are:
1. Install the Xen paravirt_ops, which is simply a matter of a
structure assignment.
2. Set init_mm to use the Xen-supplied pagetables (analogous to the
head.S generated pagetables in a native boot).
3. Reserve address space for Xen, since it takes a chunk at the top
of the address space for its own use.
4. Call start_kernel()
PAGETABLE SETUP
Once we hit the main kernel boot sequence, it will end up calling back
via paravirt_ops to set up various pieces of Xen specific state. One
of the critical things which requires a bit of extra care is the
construction of the initial init_mm pagetable. Because Xen places
tight constraints on pagetables (an active pagetable must always be
valid, and must always be mapped read-only to the guest domain), we
need to be careful when constructing the new pagetable to keep these
constraints in mind. It turns out that the easiest way to do this is
use the initial Xen-provided pagetable as a template, and then just
insert new mappings for memory where a mapping doesn't already exist.
This means that during pagetable setup, it uses a special version of
xen_set_pte which ignores any attempt to remap a read-only page as
read-write (since Xen will map its own initial pagetable as RO), but
lets other changes to the ptes happen, so that things like NX are set
properly.
PRIVILEGED INSTRUCTIONS AND SEGMENTATION
When the kernel runs under Xen, it runs in ring 1 rather than ring 0.
This means that it is more privileged than user-mode in ring 3, but it
still can't run privileged instructions directly. Non-performance
critical instructions are dealt with by taking a privilege exception
and trapping into the hypervisor and emulating the instruction, but
more performance-critical instructions have their own specific
paravirt_ops. In many cases we can avoid having to do any hypercalls
for these instructions, or the Xen implementation is quite different
from the normal native version.
The privileged instructions fall into the broad classes of:
Segmentation: setting up the GDT and the GDT entries, LDT,
TLS and so on. Xen doesn't allow the GDT to be directly
modified; all GDT updates are done via hypercalls where the new
entries can be validated. This is important because Xen uses
segment limits to prevent the guest kernel from damaging the
hypervisor itself.
Traps and exceptions: Xen uses a special format for trap entrypoints,
so when the kernel wants to set an IDT entry, it needs to be
converted to the form Xen expects. Xen sets int 0x80 up specially
so that the trap goes straight from userspace into the guest kernel
without going via the hypervisor. sysenter isn't supported.
Kernel stack: The esp0 entry is extracted from the tss and provided to
Xen.
TLB operations: the various TLB calls are mapped into corresponding
Xen hypercalls.
Control registers: all the control registers are privileged. The most
important is cr3, which points to the base of the current pagetable,
and we handle it specially.
Another instruction we treat specially is CPUID, even though its not
privileged. We want to control what CPU features are visible to the
rest of the kernel, and so CPUID ends up going into a paravirt_op.
Xen implements this mainly to disable the ACPI and APIC subsystems.
INTERRUPT FLAGS
Xen maintains its own separate flag for masking events, which is
contained within the per-cpu vcpu_info structure. Because the guest
kernel runs in ring 1 and not 0, the IF flag in EFLAGS is completely
ignored (and must be, because even if a guest domain disables
interrupts for itself, it can't disable them overall).
(A note on terminology: "events" and interrupts are effectively
synonymous. However, rather than using an "enable flag", Xen uses a
"mask flag", which blocks event delivery when it is non-zero.)
There are paravirt_ops for each of cli/sti/save_fl/restore_fl, which
are implemented to manage the Xen event mask state. The only thing
worth noting is that when events are unmasked, we need to explicitly
see if there's a pending event and call into the hypervisor to make
sure it gets delivered.
UPCALLS
Xen needs a couple of upcall (or callback) functions to be implemented
by each guest. One is the event upcalls, which is how events
(interrupts, effectively) are delivered to the guests. The other is
the failsafe callback, which is used to report errors in either
reloading a segment register, or caused by iret. These are
implemented in i386/kernel/entry.S so they can jump into the normal
iret_exc path when necessary.
MULTICALL BATCHING
Xen provides a multicall mechanism, which allows multiple hypercalls
to be issued at once in order to mitigate the cost of trapping into
the hypervisor. This is particularly useful for context switches,
since the 4-5 hypercalls they would normally need (reload cr3, update
TLS, maybe update LDT) can be reduced to one. This patch implements a
generic batching mechanism for hypercalls, which gets used in many
places in the Xen code.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ian Pratt <ian.pratt@xensource.com>
Cc: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Cc: Adrian Bunk <bunk@stusta.de>
2007-07-18 09:37:04 +08:00
|
|
|
ENDPROC(xen_failsafe_callback)
|
2018-08-28 15:40:12 +08:00
|
|
|
#endif /* CONFIG_XEN_PV */
|
xen: Core Xen implementation
This patch is a rollup of all the core pieces of the Xen
implementation, including:
- booting and setup
- pagetable setup
- privileged instructions
- segmentation
- interrupt flags
- upcalls
- multicall batching
BOOTING AND SETUP
The vmlinux image is decorated with ELF notes which tell the Xen
domain builder what the kernel's requirements are; the domain builder
then constructs the address space accordingly and starts the kernel.
Xen has its own entrypoint for the kernel (contained in an ELF note).
The ELF notes are set up by xen-head.S, which is included into head.S.
In principle it could be linked separately, but it seems to provoke
lots of binutils bugs.
Because the domain builder starts the kernel in a fairly sane state
(32-bit protected mode, paging enabled, flat segments set up), there's
not a lot of setup needed before starting the kernel proper. The main
steps are:
1. Install the Xen paravirt_ops, which is simply a matter of a
structure assignment.
2. Set init_mm to use the Xen-supplied pagetables (analogous to the
head.S generated pagetables in a native boot).
3. Reserve address space for Xen, since it takes a chunk at the top
of the address space for its own use.
4. Call start_kernel()
PAGETABLE SETUP
Once we hit the main kernel boot sequence, it will end up calling back
via paravirt_ops to set up various pieces of Xen specific state. One
of the critical things which requires a bit of extra care is the
construction of the initial init_mm pagetable. Because Xen places
tight constraints on pagetables (an active pagetable must always be
valid, and must always be mapped read-only to the guest domain), we
need to be careful when constructing the new pagetable to keep these
constraints in mind. It turns out that the easiest way to do this is
use the initial Xen-provided pagetable as a template, and then just
insert new mappings for memory where a mapping doesn't already exist.
This means that during pagetable setup, it uses a special version of
xen_set_pte which ignores any attempt to remap a read-only page as
read-write (since Xen will map its own initial pagetable as RO), but
lets other changes to the ptes happen, so that things like NX are set
properly.
PRIVILEGED INSTRUCTIONS AND SEGMENTATION
When the kernel runs under Xen, it runs in ring 1 rather than ring 0.
This means that it is more privileged than user-mode in ring 3, but it
still can't run privileged instructions directly. Non-performance
critical instructions are dealt with by taking a privilege exception
and trapping into the hypervisor and emulating the instruction, but
more performance-critical instructions have their own specific
paravirt_ops. In many cases we can avoid having to do any hypercalls
for these instructions, or the Xen implementation is quite different
from the normal native version.
The privileged instructions fall into the broad classes of:
Segmentation: setting up the GDT and the GDT entries, LDT,
TLS and so on. Xen doesn't allow the GDT to be directly
modified; all GDT updates are done via hypercalls where the new
entries can be validated. This is important because Xen uses
segment limits to prevent the guest kernel from damaging the
hypervisor itself.
Traps and exceptions: Xen uses a special format for trap entrypoints,
so when the kernel wants to set an IDT entry, it needs to be
converted to the form Xen expects. Xen sets int 0x80 up specially
so that the trap goes straight from userspace into the guest kernel
without going via the hypervisor. sysenter isn't supported.
Kernel stack: The esp0 entry is extracted from the tss and provided to
Xen.
TLB operations: the various TLB calls are mapped into corresponding
Xen hypercalls.
Control registers: all the control registers are privileged. The most
important is cr3, which points to the base of the current pagetable,
and we handle it specially.
Another instruction we treat specially is CPUID, even though its not
privileged. We want to control what CPU features are visible to the
rest of the kernel, and so CPUID ends up going into a paravirt_op.
Xen implements this mainly to disable the ACPI and APIC subsystems.
INTERRUPT FLAGS
Xen maintains its own separate flag for masking events, which is
contained within the per-cpu vcpu_info structure. Because the guest
kernel runs in ring 1 and not 0, the IF flag in EFLAGS is completely
ignored (and must be, because even if a guest domain disables
interrupts for itself, it can't disable them overall).
(A note on terminology: "events" and interrupts are effectively
synonymous. However, rather than using an "enable flag", Xen uses a
"mask flag", which blocks event delivery when it is non-zero.)
There are paravirt_ops for each of cli/sti/save_fl/restore_fl, which
are implemented to manage the Xen event mask state. The only thing
worth noting is that when events are unmasked, we need to explicitly
see if there's a pending event and call into the hypervisor to make
sure it gets delivered.
UPCALLS
Xen needs a couple of upcall (or callback) functions to be implemented
by each guest. One is the event upcalls, which is how events
(interrupts, effectively) are delivered to the guests. The other is
the failsafe callback, which is used to report errors in either
reloading a segment register, or caused by iret. These are
implemented in i386/kernel/entry.S so they can jump into the normal
iret_exc path when necessary.
MULTICALL BATCHING
Xen provides a multicall mechanism, which allows multiple hypercalls
to be issued at once in order to mitigate the cost of trapping into
the hypervisor. This is particularly useful for context switches,
since the 4-5 hypercalls they would normally need (reload cr3, update
TLS, maybe update LDT) can be reduced to one. This patch implements a
generic batching mechanism for hypercalls, which gets used in many
places in the Xen code.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ian Pratt <ian.pratt@xensource.com>
Cc: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Cc: Adrian Bunk <bunk@stusta.de>
2007-07-18 09:37:04 +08:00
|
|
|
|
2018-08-28 15:40:12 +08:00
|
|
|
#ifdef CONFIG_XEN_PVHVM
|
2013-02-04 09:22:39 +08:00
|
|
|
BUILD_INTERRUPT3(xen_hvm_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
|
2017-08-28 14:47:31 +08:00
|
|
|
xen_evtchn_do_upcall)
|
2018-08-28 15:40:12 +08:00
|
|
|
#endif
|
2010-05-14 19:40:51 +08:00
|
|
|
|
2013-02-04 09:22:39 +08:00
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_HYPERV)
|
|
|
|
|
|
|
|
BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
|
2017-08-28 14:47:31 +08:00
|
|
|
hyperv_vector_handler)
|
2013-02-04 09:22:39 +08:00
|
|
|
|
2018-01-24 21:23:33 +08:00
|
|
|
BUILD_INTERRUPT3(hyperv_reenlightenment_vector, HYPERV_REENLIGHTENMENT_VECTOR,
|
|
|
|
hyperv_reenlightenment_intr)
|
|
|
|
|
2018-03-05 13:17:18 +08:00
|
|
|
BUILD_INTERRUPT3(hv_stimer0_callback_vector, HYPERV_STIMER0_VECTOR,
|
|
|
|
hv_stimer0_vector_handler)
|
|
|
|
|
2013-02-04 09:22:39 +08:00
|
|
|
#endif /* CONFIG_HYPERV */
|
xen: Core Xen implementation
This patch is a rollup of all the core pieces of the Xen
implementation, including:
- booting and setup
- pagetable setup
- privileged instructions
- segmentation
- interrupt flags
- upcalls
- multicall batching
BOOTING AND SETUP
The vmlinux image is decorated with ELF notes which tell the Xen
domain builder what the kernel's requirements are; the domain builder
then constructs the address space accordingly and starts the kernel.
Xen has its own entrypoint for the kernel (contained in an ELF note).
The ELF notes are set up by xen-head.S, which is included into head.S.
In principle it could be linked separately, but it seems to provoke
lots of binutils bugs.
Because the domain builder starts the kernel in a fairly sane state
(32-bit protected mode, paging enabled, flat segments set up), there's
not a lot of setup needed before starting the kernel proper. The main
steps are:
1. Install the Xen paravirt_ops, which is simply a matter of a
structure assignment.
2. Set init_mm to use the Xen-supplied pagetables (analogous to the
head.S generated pagetables in a native boot).
3. Reserve address space for Xen, since it takes a chunk at the top
of the address space for its own use.
4. Call start_kernel()
PAGETABLE SETUP
Once we hit the main kernel boot sequence, it will end up calling back
via paravirt_ops to set up various pieces of Xen specific state. One
of the critical things which requires a bit of extra care is the
construction of the initial init_mm pagetable. Because Xen places
tight constraints on pagetables (an active pagetable must always be
valid, and must always be mapped read-only to the guest domain), we
need to be careful when constructing the new pagetable to keep these
constraints in mind. It turns out that the easiest way to do this is
use the initial Xen-provided pagetable as a template, and then just
insert new mappings for memory where a mapping doesn't already exist.
This means that during pagetable setup, it uses a special version of
xen_set_pte which ignores any attempt to remap a read-only page as
read-write (since Xen will map its own initial pagetable as RO), but
lets other changes to the ptes happen, so that things like NX are set
properly.
PRIVILEGED INSTRUCTIONS AND SEGMENTATION
When the kernel runs under Xen, it runs in ring 1 rather than ring 0.
This means that it is more privileged than user-mode in ring 3, but it
still can't run privileged instructions directly. Non-performance
critical instructions are dealt with by taking a privilege exception
and trapping into the hypervisor and emulating the instruction, but
more performance-critical instructions have their own specific
paravirt_ops. In many cases we can avoid having to do any hypercalls
for these instructions, or the Xen implementation is quite different
from the normal native version.
The privileged instructions fall into the broad classes of:
Segmentation: setting up the GDT and the GDT entries, LDT,
TLS and so on. Xen doesn't allow the GDT to be directly
modified; all GDT updates are done via hypercalls where the new
entries can be validated. This is important because Xen uses
segment limits to prevent the guest kernel from damaging the
hypervisor itself.
Traps and exceptions: Xen uses a special format for trap entrypoints,
so when the kernel wants to set an IDT entry, it needs to be
converted to the form Xen expects. Xen sets int 0x80 up specially
so that the trap goes straight from userspace into the guest kernel
without going via the hypervisor. sysenter isn't supported.
Kernel stack: The esp0 entry is extracted from the tss and provided to
Xen.
TLB operations: the various TLB calls are mapped into corresponding
Xen hypercalls.
Control registers: all the control registers are privileged. The most
important is cr3, which points to the base of the current pagetable,
and we handle it specially.
Another instruction we treat specially is CPUID, even though its not
privileged. We want to control what CPU features are visible to the
rest of the kernel, and so CPUID ends up going into a paravirt_op.
Xen implements this mainly to disable the ACPI and APIC subsystems.
INTERRUPT FLAGS
Xen maintains its own separate flag for masking events, which is
contained within the per-cpu vcpu_info structure. Because the guest
kernel runs in ring 1 and not 0, the IF flag in EFLAGS is completely
ignored (and must be, because even if a guest domain disables
interrupts for itself, it can't disable them overall).
(A note on terminology: "events" and interrupts are effectively
synonymous. However, rather than using an "enable flag", Xen uses a
"mask flag", which blocks event delivery when it is non-zero.)
There are paravirt_ops for each of cli/sti/save_fl/restore_fl, which
are implemented to manage the Xen event mask state. The only thing
worth noting is that when events are unmasked, we need to explicitly
see if there's a pending event and call into the hypervisor to make
sure it gets delivered.
UPCALLS
Xen needs a couple of upcall (or callback) functions to be implemented
by each guest. One is the event upcalls, which is how events
(interrupts, effectively) are delivered to the guests. The other is
the failsafe callback, which is used to report errors in either
reloading a segment register, or caused by iret. These are
implemented in i386/kernel/entry.S so they can jump into the normal
iret_exc path when necessary.
MULTICALL BATCHING
Xen provides a multicall mechanism, which allows multiple hypercalls
to be issued at once in order to mitigate the cost of trapping into
the hypervisor. This is particularly useful for context switches,
since the 4-5 hypercalls they would normally need (reload cr3, update
TLS, maybe update LDT) can be reduced to one. This patch implements a
generic batching mechanism for hypercalls, which gets used in many
places in the Xen code.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ian Pratt <ian.pratt@xensource.com>
Cc: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Cc: Adrian Bunk <bunk@stusta.de>
2007-07-18 09:37:04 +08:00
|
|
|
|
2008-11-24 22:38:45 +08:00
|
|
|
ENTRY(page_fault)
|
2012-09-22 04:58:10 +08:00
|
|
|
ASM_CLAC
|
2019-07-24 12:20:58 +08:00
|
|
|
pushl $do_page_fault
|
|
|
|
jmp common_exception_read_cr2
|
|
|
|
END(page_fault)
|
2019-07-11 19:40:59 +08:00
|
|
|
|
2019-07-24 12:20:58 +08:00
|
|
|
common_exception_read_cr2:
|
|
|
|
/* the function address is in %gs's slot on the stack */
|
2024-06-11 20:08:33 +08:00
|
|
|
SAVE_ALL switch_stacks=1 skip_gs=1 unwind_espfix=1
|
2019-07-11 19:40:59 +08:00
|
|
|
|
|
|
|
ENCODE_FRAME_POINTER
|
|
|
|
|
|
|
|
/* fixup %gs */
|
|
|
|
GS_TO_REG %ecx
|
2019-07-24 12:20:58 +08:00
|
|
|
movl PT_GS(%esp), %edi
|
2019-07-11 19:40:59 +08:00
|
|
|
REG_TO_PTGS %ecx
|
|
|
|
SET_KERNEL_GS %ecx
|
|
|
|
|
|
|
|
GET_CR2_INTO(%ecx) # might clobber %eax
|
|
|
|
|
|
|
|
/* fixup orig %eax */
|
|
|
|
movl PT_ORIG_EAX(%esp), %edx # get the error code
|
|
|
|
movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
|
|
|
|
|
|
|
|
TRACE_IRQS_OFF
|
|
|
|
movl %esp, %eax # pt_regs pointer
|
2019-07-24 12:20:58 +08:00
|
|
|
CALL_NOSPEC %edi
|
2019-07-11 19:40:59 +08:00
|
|
|
jmp ret_from_exception
|
2019-07-24 12:20:58 +08:00
|
|
|
END(common_exception_read_cr2)
|
2016-09-22 05:04:00 +08:00
|
|
|
|
|
|
|
common_exception:
|
2009-02-09 21:17:40 +08:00
|
|
|
/* the function address is in %gs's slot on the stack */
|
2024-06-11 20:08:33 +08:00
|
|
|
SAVE_ALL switch_stacks=1 skip_gs=1 unwind_espfix=1
|
2016-10-21 00:34:40 +08:00
|
|
|
ENCODE_FRAME_POINTER
|
2019-07-11 19:40:56 +08:00
|
|
|
|
|
|
|
/* fixup %gs */
|
2009-02-09 21:17:40 +08:00
|
|
|
GS_TO_REG %ecx
|
2015-06-08 15:49:11 +08:00
|
|
|
movl PT_GS(%esp), %edi # get the function address
|
2009-02-09 21:17:40 +08:00
|
|
|
REG_TO_PTGS %ecx
|
|
|
|
SET_KERNEL_GS %ecx
|
2019-07-11 19:40:56 +08:00
|
|
|
|
|
|
|
/* fixup orig %eax */
|
|
|
|
movl PT_ORIG_EAX(%esp), %edx # get the error code
|
|
|
|
movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
|
|
|
|
|
2008-11-24 22:38:45 +08:00
|
|
|
TRACE_IRQS_OFF
|
2015-06-08 15:49:11 +08:00
|
|
|
movl %esp, %eax # pt_regs pointer
|
2018-01-12 05:46:28 +08:00
|
|
|
CALL_NOSPEC %edi
|
2015-06-08 15:49:11 +08:00
|
|
|
jmp ret_from_exception
|
2016-09-22 05:04:00 +08:00
|
|
|
END(common_exception)
|
2008-11-24 22:38:45 +08:00
|
|
|
|
|
|
|
ENTRY(debug)
|
x86/entry/32: Simplify and fix up the SYSENTER stack #DB/NMI fixup
Right after SYSENTER, we can get a #DB or NMI. On x86_32, there's no IST,
so the exception handler is invoked on the temporary SYSENTER stack.
Because the SYSENTER stack is very small, we have a fixup to switch
off the stack quickly when this happens. The old fixup had several issues:
1. It checked the interrupt frame's CS and EIP. This wasn't
obviously correct on Xen or if vm86 mode was in use [1].
2. In the NMI handler, it did some frightening digging into the
stack frame. I'm not convinced this digging was correct.
3. The fixup didn't switch stacks and then switch back. Instead, it
synthesized a brand new stack frame that would redirect the IRET
back to the SYSENTER code. That frame was highly questionable.
For one thing, if NMI nested inside #DB, we would effectively
abort the #DB prologue, which was probably safe but was
frightening. For another, the code used PUSHFL to write the
FLAGS portion of the frame, which was simply bogus -- by the time
PUSHFL was called, at least TF, NT, VM, and all of the arithmetic
flags were clobbered.
Simplify this considerably. Instead of looking at the saved frame
to see where we came from, check the hardware ESP register against
the SYSENTER stack directly. Malicious user code cannot spoof the
kernel ESP register, and by moving the check after SAVE_ALL, we can
use normal PER_CPU accesses to find all the relevant addresses.
With this patch applied, the improved syscall_nt_32 test finally
passes on 32-bit kernels.
[1] It isn't obviously correct, but it is nonetheless safe from vm86
shenanigans as far as I can tell. A user can't point EIP at
entry_SYSENTER_32 while in vm86 mode because entry_SYSENTER_32,
like all kernel addresses, is greater than 0xffff and would thus
violate the CS segment limit.
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/b2cdbc037031c07ecf2c40a96069318aec0e7971.1457578375.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-03-10 11:00:32 +08:00
|
|
|
/*
|
2018-07-18 17:40:48 +08:00
|
|
|
* Entry from sysenter is now handled in common_exception
|
x86/entry/32: Simplify and fix up the SYSENTER stack #DB/NMI fixup
Right after SYSENTER, we can get a #DB or NMI. On x86_32, there's no IST,
so the exception handler is invoked on the temporary SYSENTER stack.
Because the SYSENTER stack is very small, we have a fixup to switch
off the stack quickly when this happens. The old fixup had several issues:
1. It checked the interrupt frame's CS and EIP. This wasn't
obviously correct on Xen or if vm86 mode was in use [1].
2. In the NMI handler, it did some frightening digging into the
stack frame. I'm not convinced this digging was correct.
3. The fixup didn't switch stacks and then switch back. Instead, it
synthesized a brand new stack frame that would redirect the IRET
back to the SYSENTER code. That frame was highly questionable.
For one thing, if NMI nested inside #DB, we would effectively
abort the #DB prologue, which was probably safe but was
frightening. For another, the code used PUSHFL to write the
FLAGS portion of the frame, which was simply bogus -- by the time
PUSHFL was called, at least TF, NT, VM, and all of the arithmetic
flags were clobbered.
Simplify this considerably. Instead of looking at the saved frame
to see where we came from, check the hardware ESP register against
the SYSENTER stack directly. Malicious user code cannot spoof the
kernel ESP register, and by moving the check after SAVE_ALL, we can
use normal PER_CPU accesses to find all the relevant addresses.
With this patch applied, the improved syscall_nt_32 test finally
passes on 32-bit kernels.
[1] It isn't obviously correct, but it is nonetheless safe from vm86
shenanigans as far as I can tell. A user can't point EIP at
entry_SYSENTER_32 while in vm86 mode because entry_SYSENTER_32,
like all kernel addresses, is greater than 0xffff and would thus
violate the CS segment limit.
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/b2cdbc037031c07ecf2c40a96069318aec0e7971.1457578375.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-03-10 11:00:32 +08:00
|
|
|
*/
|
2012-09-22 04:58:10 +08:00
|
|
|
ASM_CLAC
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl $-1 # mark this as an int
|
2018-07-18 17:40:48 +08:00
|
|
|
pushl $do_debug
|
|
|
|
jmp common_exception
|
2008-11-24 22:38:45 +08:00
|
|
|
END(debug)
|
|
|
|
|
|
|
|
/*
|
x86/entry/32: Simplify and fix up the SYSENTER stack #DB/NMI fixup
Right after SYSENTER, we can get a #DB or NMI. On x86_32, there's no IST,
so the exception handler is invoked on the temporary SYSENTER stack.
Because the SYSENTER stack is very small, we have a fixup to switch
off the stack quickly when this happens. The old fixup had several issues:
1. It checked the interrupt frame's CS and EIP. This wasn't
obviously correct on Xen or if vm86 mode was in use [1].
2. In the NMI handler, it did some frightening digging into the
stack frame. I'm not convinced this digging was correct.
3. The fixup didn't switch stacks and then switch back. Instead, it
synthesized a brand new stack frame that would redirect the IRET
back to the SYSENTER code. That frame was highly questionable.
For one thing, if NMI nested inside #DB, we would effectively
abort the #DB prologue, which was probably safe but was
frightening. For another, the code used PUSHFL to write the
FLAGS portion of the frame, which was simply bogus -- by the time
PUSHFL was called, at least TF, NT, VM, and all of the arithmetic
flags were clobbered.
Simplify this considerably. Instead of looking at the saved frame
to see where we came from, check the hardware ESP register against
the SYSENTER stack directly. Malicious user code cannot spoof the
kernel ESP register, and by moving the check after SAVE_ALL, we can
use normal PER_CPU accesses to find all the relevant addresses.
With this patch applied, the improved syscall_nt_32 test finally
passes on 32-bit kernels.
[1] It isn't obviously correct, but it is nonetheless safe from vm86
shenanigans as far as I can tell. A user can't point EIP at
entry_SYSENTER_32 while in vm86 mode because entry_SYSENTER_32,
like all kernel addresses, is greater than 0xffff and would thus
violate the CS segment limit.
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/b2cdbc037031c07ecf2c40a96069318aec0e7971.1457578375.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-03-10 11:00:32 +08:00
|
|
|
* NMI is doubly nasty. It can happen on the first instruction of
|
|
|
|
* entry_SYSENTER_32 (just like #DB), but it can also interrupt the beginning
|
|
|
|
* of the #DB handler even if that #DB in turn hit before entry_SYSENTER_32
|
|
|
|
* switched stacks. We handle both conditions by simply checking whether we
|
|
|
|
* interrupted kernel code running on the SYSENTER stack.
|
2008-11-24 22:38:45 +08:00
|
|
|
*/
|
|
|
|
ENTRY(nmi)
|
2012-09-22 04:58:10 +08:00
|
|
|
ASM_CLAC
|
2018-07-18 17:40:44 +08:00
|
|
|
|
2014-05-05 01:36:22 +08:00
|
|
|
#ifdef CONFIG_X86_ESPFIX32
|
2024-06-11 20:08:33 +08:00
|
|
|
/*
|
|
|
|
* ESPFIX_SS is only ever set on the return to user path
|
|
|
|
* after we've switched to the entry stack.
|
|
|
|
*/
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl %eax
|
|
|
|
movl %ss, %eax
|
|
|
|
cmpw $__ESPFIX_SS, %ax
|
|
|
|
popl %eax
|
2016-09-22 05:03:59 +08:00
|
|
|
je .Lnmi_espfix_stack
|
2014-05-05 01:36:22 +08:00
|
|
|
#endif
|
x86/entry/32: Simplify and fix up the SYSENTER stack #DB/NMI fixup
Right after SYSENTER, we can get a #DB or NMI. On x86_32, there's no IST,
so the exception handler is invoked on the temporary SYSENTER stack.
Because the SYSENTER stack is very small, we have a fixup to switch
off the stack quickly when this happens. The old fixup had several issues:
1. It checked the interrupt frame's CS and EIP. This wasn't
obviously correct on Xen or if vm86 mode was in use [1].
2. In the NMI handler, it did some frightening digging into the
stack frame. I'm not convinced this digging was correct.
3. The fixup didn't switch stacks and then switch back. Instead, it
synthesized a brand new stack frame that would redirect the IRET
back to the SYSENTER code. That frame was highly questionable.
For one thing, if NMI nested inside #DB, we would effectively
abort the #DB prologue, which was probably safe but was
frightening. For another, the code used PUSHFL to write the
FLAGS portion of the frame, which was simply bogus -- by the time
PUSHFL was called, at least TF, NT, VM, and all of the arithmetic
flags were clobbered.
Simplify this considerably. Instead of looking at the saved frame
to see where we came from, check the hardware ESP register against
the SYSENTER stack directly. Malicious user code cannot spoof the
kernel ESP register, and by moving the check after SAVE_ALL, we can
use normal PER_CPU accesses to find all the relevant addresses.
With this patch applied, the improved syscall_nt_32 test finally
passes on 32-bit kernels.
[1] It isn't obviously correct, but it is nonetheless safe from vm86
shenanigans as far as I can tell. A user can't point EIP at
entry_SYSENTER_32 while in vm86 mode because entry_SYSENTER_32,
like all kernel addresses, is greater than 0xffff and would thus
violate the CS segment limit.
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/b2cdbc037031c07ecf2c40a96069318aec0e7971.1457578375.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-03-10 11:00:32 +08:00
|
|
|
|
|
|
|
pushl %eax # pt_regs->orig_ax
|
2018-07-18 17:40:50 +08:00
|
|
|
SAVE_ALL_NMI cr3_reg=%edi
|
2016-10-21 00:34:40 +08:00
|
|
|
ENCODE_FRAME_POINTER
|
2015-06-08 15:49:11 +08:00
|
|
|
xorl %edx, %edx # zero error code
|
|
|
|
movl %esp, %eax # pt_regs pointer
|
x86/entry/32: Simplify and fix up the SYSENTER stack #DB/NMI fixup
Right after SYSENTER, we can get a #DB or NMI. On x86_32, there's no IST,
so the exception handler is invoked on the temporary SYSENTER stack.
Because the SYSENTER stack is very small, we have a fixup to switch
off the stack quickly when this happens. The old fixup had several issues:
1. It checked the interrupt frame's CS and EIP. This wasn't
obviously correct on Xen or if vm86 mode was in use [1].
2. In the NMI handler, it did some frightening digging into the
stack frame. I'm not convinced this digging was correct.
3. The fixup didn't switch stacks and then switch back. Instead, it
synthesized a brand new stack frame that would redirect the IRET
back to the SYSENTER code. That frame was highly questionable.
For one thing, if NMI nested inside #DB, we would effectively
abort the #DB prologue, which was probably safe but was
frightening. For another, the code used PUSHFL to write the
FLAGS portion of the frame, which was simply bogus -- by the time
PUSHFL was called, at least TF, NT, VM, and all of the arithmetic
flags were clobbered.
Simplify this considerably. Instead of looking at the saved frame
to see where we came from, check the hardware ESP register against
the SYSENTER stack directly. Malicious user code cannot spoof the
kernel ESP register, and by moving the check after SAVE_ALL, we can
use normal PER_CPU accesses to find all the relevant addresses.
With this patch applied, the improved syscall_nt_32 test finally
passes on 32-bit kernels.
[1] It isn't obviously correct, but it is nonetheless safe from vm86
shenanigans as far as I can tell. A user can't point EIP at
entry_SYSENTER_32 while in vm86 mode because entry_SYSENTER_32,
like all kernel addresses, is greater than 0xffff and would thus
violate the CS segment limit.
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/b2cdbc037031c07ecf2c40a96069318aec0e7971.1457578375.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-03-10 11:00:32 +08:00
|
|
|
|
|
|
|
/* Are we currently on the SYSENTER stack? */
|
2017-12-04 22:07:20 +08:00
|
|
|
movl PER_CPU_VAR(cpu_entry_area), %ecx
|
2017-12-05 09:25:07 +08:00
|
|
|
addl $CPU_ENTRY_AREA_entry_stack + SIZEOF_entry_stack, %ecx
|
|
|
|
subl %eax, %ecx /* ecx = (end of entry_stack) - esp */
|
|
|
|
cmpl $SIZEOF_entry_stack, %ecx
|
x86/entry/32: Simplify and fix up the SYSENTER stack #DB/NMI fixup
Right after SYSENTER, we can get a #DB or NMI. On x86_32, there's no IST,
so the exception handler is invoked on the temporary SYSENTER stack.
Because the SYSENTER stack is very small, we have a fixup to switch
off the stack quickly when this happens. The old fixup had several issues:
1. It checked the interrupt frame's CS and EIP. This wasn't
obviously correct on Xen or if vm86 mode was in use [1].
2. In the NMI handler, it did some frightening digging into the
stack frame. I'm not convinced this digging was correct.
3. The fixup didn't switch stacks and then switch back. Instead, it
synthesized a brand new stack frame that would redirect the IRET
back to the SYSENTER code. That frame was highly questionable.
For one thing, if NMI nested inside #DB, we would effectively
abort the #DB prologue, which was probably safe but was
frightening. For another, the code used PUSHFL to write the
FLAGS portion of the frame, which was simply bogus -- by the time
PUSHFL was called, at least TF, NT, VM, and all of the arithmetic
flags were clobbered.
Simplify this considerably. Instead of looking at the saved frame
to see where we came from, check the hardware ESP register against
the SYSENTER stack directly. Malicious user code cannot spoof the
kernel ESP register, and by moving the check after SAVE_ALL, we can
use normal PER_CPU accesses to find all the relevant addresses.
With this patch applied, the improved syscall_nt_32 test finally
passes on 32-bit kernels.
[1] It isn't obviously correct, but it is nonetheless safe from vm86
shenanigans as far as I can tell. A user can't point EIP at
entry_SYSENTER_32 while in vm86 mode because entry_SYSENTER_32,
like all kernel addresses, is greater than 0xffff and would thus
violate the CS segment limit.
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/b2cdbc037031c07ecf2c40a96069318aec0e7971.1457578375.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-03-10 11:00:32 +08:00
|
|
|
jb .Lnmi_from_sysenter_stack
|
|
|
|
|
|
|
|
/* Not on SYSENTER stack. */
|
2015-06-08 15:49:11 +08:00
|
|
|
call do_nmi
|
2018-07-18 17:40:42 +08:00
|
|
|
jmp .Lnmi_return
|
2008-11-24 22:38:45 +08:00
|
|
|
|
x86/entry/32: Simplify and fix up the SYSENTER stack #DB/NMI fixup
Right after SYSENTER, we can get a #DB or NMI. On x86_32, there's no IST,
so the exception handler is invoked on the temporary SYSENTER stack.
Because the SYSENTER stack is very small, we have a fixup to switch
off the stack quickly when this happens. The old fixup had several issues:
1. It checked the interrupt frame's CS and EIP. This wasn't
obviously correct on Xen or if vm86 mode was in use [1].
2. In the NMI handler, it did some frightening digging into the
stack frame. I'm not convinced this digging was correct.
3. The fixup didn't switch stacks and then switch back. Instead, it
synthesized a brand new stack frame that would redirect the IRET
back to the SYSENTER code. That frame was highly questionable.
For one thing, if NMI nested inside #DB, we would effectively
abort the #DB prologue, which was probably safe but was
frightening. For another, the code used PUSHFL to write the
FLAGS portion of the frame, which was simply bogus -- by the time
PUSHFL was called, at least TF, NT, VM, and all of the arithmetic
flags were clobbered.
Simplify this considerably. Instead of looking at the saved frame
to see where we came from, check the hardware ESP register against
the SYSENTER stack directly. Malicious user code cannot spoof the
kernel ESP register, and by moving the check after SAVE_ALL, we can
use normal PER_CPU accesses to find all the relevant addresses.
With this patch applied, the improved syscall_nt_32 test finally
passes on 32-bit kernels.
[1] It isn't obviously correct, but it is nonetheless safe from vm86
shenanigans as far as I can tell. A user can't point EIP at
entry_SYSENTER_32 while in vm86 mode because entry_SYSENTER_32,
like all kernel addresses, is greater than 0xffff and would thus
violate the CS segment limit.
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/b2cdbc037031c07ecf2c40a96069318aec0e7971.1457578375.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-03-10 11:00:32 +08:00
|
|
|
.Lnmi_from_sysenter_stack:
|
|
|
|
/*
|
|
|
|
* We're on the SYSENTER stack. Switch off. No one (not even debug)
|
|
|
|
* is using the thread stack right now, so it's safe for us to use it.
|
|
|
|
*/
|
2016-10-21 00:34:40 +08:00
|
|
|
movl %esp, %ebx
|
x86/entry/32: Simplify and fix up the SYSENTER stack #DB/NMI fixup
Right after SYSENTER, we can get a #DB or NMI. On x86_32, there's no IST,
so the exception handler is invoked on the temporary SYSENTER stack.
Because the SYSENTER stack is very small, we have a fixup to switch
off the stack quickly when this happens. The old fixup had several issues:
1. It checked the interrupt frame's CS and EIP. This wasn't
obviously correct on Xen or if vm86 mode was in use [1].
2. In the NMI handler, it did some frightening digging into the
stack frame. I'm not convinced this digging was correct.
3. The fixup didn't switch stacks and then switch back. Instead, it
synthesized a brand new stack frame that would redirect the IRET
back to the SYSENTER code. That frame was highly questionable.
For one thing, if NMI nested inside #DB, we would effectively
abort the #DB prologue, which was probably safe but was
frightening. For another, the code used PUSHFL to write the
FLAGS portion of the frame, which was simply bogus -- by the time
PUSHFL was called, at least TF, NT, VM, and all of the arithmetic
flags were clobbered.
Simplify this considerably. Instead of looking at the saved frame
to see where we came from, check the hardware ESP register against
the SYSENTER stack directly. Malicious user code cannot spoof the
kernel ESP register, and by moving the check after SAVE_ALL, we can
use normal PER_CPU accesses to find all the relevant addresses.
With this patch applied, the improved syscall_nt_32 test finally
passes on 32-bit kernels.
[1] It isn't obviously correct, but it is nonetheless safe from vm86
shenanigans as far as I can tell. A user can't point EIP at
entry_SYSENTER_32 while in vm86 mode because entry_SYSENTER_32,
like all kernel addresses, is greater than 0xffff and would thus
violate the CS segment limit.
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/b2cdbc037031c07ecf2c40a96069318aec0e7971.1457578375.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-03-10 11:00:32 +08:00
|
|
|
movl PER_CPU_VAR(cpu_current_top_of_stack), %esp
|
|
|
|
call do_nmi
|
2016-10-21 00:34:40 +08:00
|
|
|
movl %ebx, %esp
|
2018-07-18 17:40:42 +08:00
|
|
|
|
|
|
|
.Lnmi_return:
|
2024-06-11 20:08:33 +08:00
|
|
|
#ifdef CONFIG_X86_ESPFIX32
|
|
|
|
testl $CS_FROM_ESPFIX, PT_CS(%esp)
|
|
|
|
jnz .Lnmi_from_espfix
|
|
|
|
#endif
|
|
|
|
|
2018-07-18 17:40:42 +08:00
|
|
|
CHECK_AND_APPLY_ESPFIX
|
2018-07-18 17:40:50 +08:00
|
|
|
RESTORE_ALL_NMI cr3_reg=%edi pop=4
|
2018-07-18 17:40:42 +08:00
|
|
|
jmp .Lirq_return
|
2008-11-24 22:38:45 +08:00
|
|
|
|
2014-05-05 01:36:22 +08:00
|
|
|
#ifdef CONFIG_X86_ESPFIX32
|
2016-09-22 05:03:59 +08:00
|
|
|
.Lnmi_espfix_stack:
|
x86/debug: Remove perpetually broken, unmaintainable dwarf annotations
So the dwarf2 annotations in low level assembly code have
become an increasing hindrance: unreadable, messy macros
mixed into some of the most security sensitive code paths
of the Linux kernel.
These debug info annotations don't even buy the upstream
kernel anything: dwarf driven stack unwinding has caused
problems in the past so it's out of tree, and the upstream
kernel only uses the much more robust framepointers based
stack unwinding method.
In addition to that there's a steady, slow bitrot going
on with these annotations, requiring frequent fixups.
There's no tooling and no functionality upstream that
keeps it correct.
So burn down the sick forest, allowing new, healthier growth:
27 files changed, 350 insertions(+), 1101 deletions(-)
Someone who has the willingness and time to do this
properly can attempt to reintroduce dwarf debuginfo in x86
assembly code plus dwarf unwinding from first principles,
with the following conditions:
- it should be maximally readable, and maximally low-key to
'ordinary' code reading and maintenance.
- find a build time method to insert dwarf annotations
automatically in the most common cases, for pop/push
instructions that manipulate the stack pointer. This could
be done for example via a preprocessing step that just
looks for common patterns - plus special annotations for
the few cases where we want to depart from the default.
We have hundreds of CFI annotations, so automating most of
that makes sense.
- it should come with build tooling checks that ensure that
CFI annotations are sensible. We've seen such efforts from
the framepointer side, and there's no reason it couldn't be
done on the dwarf side.
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jan Beulich <JBeulich@suse.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-28 18:21:47 +08:00
|
|
|
/*
|
2024-06-11 20:08:33 +08:00
|
|
|
* Create the pointer to LSS back
|
2008-11-24 22:38:45 +08:00
|
|
|
*/
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl %ss
|
|
|
|
pushl %esp
|
|
|
|
addl $4, (%esp)
|
2024-06-11 20:08:33 +08:00
|
|
|
|
|
|
|
/* Copy the (short) IRET frame */
|
|
|
|
pushl 4*4(%esp) # flags
|
|
|
|
pushl 4*4(%esp) # cs
|
|
|
|
pushl 4*4(%esp) # ip
|
|
|
|
|
|
|
|
pushl %eax # orig_ax
|
|
|
|
|
|
|
|
SAVE_ALL_NMI cr3_reg=%edi unwind_espfix=1
|
2016-10-21 00:34:40 +08:00
|
|
|
ENCODE_FRAME_POINTER
|
2024-06-11 20:08:33 +08:00
|
|
|
|
|
|
|
/* clear CS_FROM_KERNEL, set CS_FROM_ESPFIX */
|
|
|
|
xorl $(CS_FROM_ESPFIX | CS_FROM_KERNEL), PT_CS(%esp)
|
|
|
|
|
2015-06-08 15:49:11 +08:00
|
|
|
xorl %edx, %edx # zero error code
|
2024-06-11 20:08:33 +08:00
|
|
|
movl %esp, %eax # pt_regs pointer
|
|
|
|
jmp .Lnmi_from_sysenter_stack
|
|
|
|
|
|
|
|
.Lnmi_from_espfix:
|
2018-07-18 17:40:50 +08:00
|
|
|
RESTORE_ALL_NMI cr3_reg=%edi
|
2024-06-11 20:08:33 +08:00
|
|
|
/*
|
|
|
|
* Because we cleared CS_FROM_KERNEL, IRET_FRAME 'forgot' to
|
|
|
|
* fix up the gap and long frame:
|
|
|
|
*
|
|
|
|
* 3 - original frame (exception)
|
|
|
|
* 2 - ESPFIX block (above)
|
|
|
|
* 6 - gap (FIXUP_FRAME)
|
|
|
|
* 5 - long frame (FIXUP_FRAME)
|
|
|
|
* 1 - orig_ax
|
|
|
|
*/
|
|
|
|
lss (1+5+6)*4(%esp), %esp # back to espfix stack
|
2016-09-22 05:03:59 +08:00
|
|
|
jmp .Lirq_return
|
2014-05-05 01:36:22 +08:00
|
|
|
#endif
|
2008-11-24 22:38:45 +08:00
|
|
|
END(nmi)
|
|
|
|
|
|
|
|
ENTRY(int3)
|
2012-09-22 04:58:10 +08:00
|
|
|
ASM_CLAC
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl $-1 # mark this as an int
|
2018-07-18 17:40:44 +08:00
|
|
|
|
|
|
|
SAVE_ALL switch_stacks=1
|
2016-10-21 00:34:40 +08:00
|
|
|
ENCODE_FRAME_POINTER
|
2008-11-24 22:38:45 +08:00
|
|
|
TRACE_IRQS_OFF
|
2015-06-08 15:49:11 +08:00
|
|
|
xorl %edx, %edx # zero error code
|
|
|
|
movl %esp, %eax # pt_regs pointer
|
|
|
|
call do_int3
|
|
|
|
jmp ret_from_exception
|
2008-11-24 22:38:45 +08:00
|
|
|
END(int3)
|
|
|
|
|
|
|
|
ENTRY(general_protection)
|
2024-06-11 20:26:44 +08:00
|
|
|
ASM_CLAC
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl $do_general_protection
|
2016-09-22 05:04:00 +08:00
|
|
|
jmp common_exception
|
2008-11-24 22:38:45 +08:00
|
|
|
END(general_protection)
|
|
|
|
|
2010-10-14 17:22:52 +08:00
|
|
|
#ifdef CONFIG_KVM_GUEST
|
|
|
|
ENTRY(async_page_fault)
|
2012-09-22 04:58:10 +08:00
|
|
|
ASM_CLAC
|
2015-06-08 15:49:11 +08:00
|
|
|
pushl $do_async_page_fault
|
2019-07-24 12:20:58 +08:00
|
|
|
jmp common_exception_read_cr2
|
2011-03-09 05:39:24 +08:00
|
|
|
END(async_page_fault)
|
2010-10-14 17:22:52 +08:00
|
|
|
#endif
|
2016-07-15 04:22:55 +08:00
|
|
|
|
2024-06-12 13:13:20 +08:00
|
|
|
ENTRY(rewind_stack_and_make_dead)
|
2016-07-15 04:22:55 +08:00
|
|
|
/* Prevent any naive code from trying to unwind to our caller. */
|
|
|
|
xorl %ebp, %ebp
|
|
|
|
|
|
|
|
movl PER_CPU_VAR(cpu_current_top_of_stack), %esi
|
|
|
|
leal -TOP_OF_KERNEL_STACK_PADDING-PTREGS_SIZE(%esi), %esp
|
|
|
|
|
2024-06-12 13:13:20 +08:00
|
|
|
call make_task_dead
|
2016-07-15 04:22:55 +08:00
|
|
|
1: jmp 1b
|
2024-06-12 13:13:20 +08:00
|
|
|
END(rewind_stack_and_make_dead)
|