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 15:07:57 +01:00
/* SPDX-License-Identifier: GPL-2.0 */
2005-04-16 15:20:36 -07:00
/ *
2015-06-08 09:49:11 +02:00
* Copyright ( C ) 1 9 9 1 ,1 9 9 2 L i n u s T o r v a l d s
2005-04-16 15:20:36 -07:00
*
2015-06-08 09:49:11 +02:00
* entry_ 3 2 . S c o n t a i n s t h e s y s t e m - c a l l a n d l o w - l e v e l f a u l t a n d t r a p h a n d l i n g r o u t i n e s .
2005-04-16 15:20:36 -07:00
*
2015-10-05 17:48:13 -07:00
* Stack l a y o u t w h i l e r u n n i n g C c o d e :
2015-06-08 09:49:11 +02:00
* ptrace n e e d s t o h a v e a l l r e g i s t e r s o n t h e s t a c k .
* If t h e o r d e r h e r e i s c h a n g e d , i t n e e d s t o b e
* updated i n f o r k . c : c o p y _ p r o c e s s ( ) , s i g n a l . c : d o _ s i g n a l ( ) ,
2005-04-16 15:20:36 -07:00
* ptrace. c a n d p t r a c e . h
*
* 0 ( % esp) - % e b x
* 4 ( % esp) - % e c x
* 8 ( % esp) - % e d x
2015-06-08 22:35:33 +02:00
* C( % e s p ) - % e s i
2005-04-16 15:20:36 -07:00
* 1 0 ( % esp) - % e d i
* 1 4 ( % esp) - % e b p
* 1 8 ( % esp) - % e a x
* 1 C( % e s p ) - % d s
* 2 0 ( % esp) - % e s
2007-02-13 13:26:20 +01:00
* 2 4 ( % esp) - % f s
2009-02-09 22:17:40 +09:00
* 2 8 ( % esp) - % g s s a v e d i f f ! C O N F I G _ X 8 6 _ 3 2 _ L A Z Y _ G S
* 2 C( % e s p ) - o r i g _ e a x
* 3 0 ( % esp) - % e i p
* 3 4 ( % esp) - % c s
* 3 8 ( % esp) - % e f l a g s
* 3 C( % e s p ) - % o l d e s p
* 4 0 ( % esp) - % o l d s s
2005-04-16 15:20:36 -07:00
* /
# include < l i n u x / l i n k a g e . h >
2012-01-03 14:23:06 -05:00
# include < l i n u x / e r r . h >
2005-04-16 15:20:36 -07:00
# include < a s m / t h r e a d _ i n f o . h >
2006-07-03 00:24:43 -07:00
# include < a s m / i r q f l a g s . h >
2005-04-16 15:20:36 -07:00
# include < a s m / e r r n o . h >
# include < a s m / s e g m e n t . h >
# include < a s m / s m p . h >
2006-12-07 02:14:01 +01:00
# include < a s m / p e r c p u . h >
2008-03-25 22:16:32 +03:00
# include < a s m / p r o c e s s o r - f l a g s . h >
2008-05-02 20:10:09 +02:00
# include < a s m / i r q _ v e c t o r s . h >
2016-01-26 22:12:04 +01:00
# include < a s m / c p u f e a t u r e s . h >
2011-08-25 16:10:33 -04:00
# include < a s m / a l t e r n a t i v e - a s m . h >
2012-04-20 12:19:50 -07:00
# include < a s m / a s m . h >
2012-09-21 13:58:10 -07:00
# include < a s m / s m a p . h >
2016-09-21 16:04:01 -05:00
# include < a s m / f r a m e . h >
2020-02-25 23:16:11 +01:00
# include < a s m / t r a p n r . h >
2018-01-11 21:46:28 +00:00
# include < a s m / n o s p e c - b r a n c h . h >
2005-04-16 15:20:36 -07:00
2018-08-17 01:16:58 +03:00
# include " c a l l i n g . h "
2011-03-07 19:10:39 +01:00
.section .entry .text , " ax"
2006-12-07 02:14:08 +01:00
/ *
* We u s e m a c r o s f o r l o w - l e v e l o p e r a t i o n s w h i c h n e e d t o b e o v e r r i d d e n
* for p a r a v i r t u a l i z a t i o n . T h e f o l l o w i n g w i l l n e v e r c l o b b e r a n y r e g i s t e r s :
* INTERRUPT_ R E T U R N ( a k a . " i r e t " )
* GET_ C R 0 _ I N T O _ E A X ( a k a . " m o v l % c r0 , % e a x " )
2008-06-25 00:19:26 -04:00
* ENABLE_ I N T E R R U P T S _ S Y S E X I T ( a k a " s t i ; sysexit").
2006-12-07 02:14:08 +01:00
*
* For D I S A B L E _ I N T E R R U P T S / E N A B L E _ I N T E R R U P T S ( a k a " c l i " / " s t i " ) , y o u m u s t
* specify w h a t r e g i s t e r s c a n b e o v e r w r i t t e n ( C L B R _ N O N E , C L B R _ E A X / E D X / E C X / A N Y ) .
* Allowing a r e g i s t e r t o b e c l o b b e r e d c a n s h r i n k t h e p a r a v i r t r e p l a c e m e n t
* enough t o p a t c h i n l i n e , i n c r e a s i n g p e r f o r m a n c e .
* /
2019-07-26 23:19:42 +02:00
# ifdef C O N F I G _ P R E E M P T I O N
2015-06-08 09:49:11 +02:00
# define p r e e m p t _ s t o p ( c l o b b e r s ) D I S A B L E _ I N T E R R U P T S ( c l o b b e r s ) ; TRACE_IRQS_OFF
2005-04-16 15:20:36 -07:00
# else
2015-06-08 09:49:11 +02:00
# define p r e e m p t _ s t o p ( c l o b b e r s )
2005-04-16 15:20:36 -07:00
# endif
2006-07-03 00:24:43 -07:00
.macro TRACE_IRQS_IRET
# ifdef C O N F I G _ T R A C E _ I R Q F L A G S
2015-06-08 09:49:11 +02:00
testl $ X 8 6 _ E F L A G S _ I F , P T _ E F L A G S ( % e s p ) # i n t e r r u p t s o f f ?
jz 1 f
2006-07-03 00:24:43 -07:00
TRACE_ I R Q S _ O N
1 :
# endif
.endm
2018-07-18 11:40:49 +02:00
# define P T I _ S W I T C H _ M A S K ( 1 < < P A G E _ S H I F T )
2009-02-09 22:17:40 +09:00
/ *
* User g s s a v e / r e s t o r e
*
* % gs i s u s e d f o r u s e r l a n d T L S a n d k e r n e l o n l y u s e s i t f o r s t a c k
* canary w h i c h i s r e q u i r e d t o b e a t % g s : 2 0 b y g c c . R e a d t h e c o m m e n t
* at t h e t o p o f s t a c k p r o t e c t o r . h f o r m o r e i n f o .
*
* Local l a b e l s 9 8 a n d 9 9 a r e u s e d .
* /
# ifdef C O N F I G _ X 8 6 _ 3 2 _ L A Z Y _ G S
/* unfortunately push/pop can't be no-op */
.macro PUSH_GS
2015-06-08 09:49:11 +02:00
pushl $ 0
2009-02-09 22:17:40 +09:00
.endm
.macro POP_GS pop=0
2015-06-08 09:49:11 +02:00
addl $ ( 4 + \ p o p ) , % e s p
2009-02-09 22:17:40 +09: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 / * C O N F I G _ X 8 6 _ 3 2 _ L A Z Y _ G S * /
.macro PUSH_GS
2015-06-08 09:49:11 +02:00
pushl % g s
2009-02-09 22:17:40 +09:00
.endm
.macro POP_GS pop=0
2015-06-08 09:49:11 +02:00
98 : popl % g s
2009-02-09 22:17:40 +09:00
.if \ pop < > 0
2015-06-08 22:35:33 +02:00
add $ \ p o p , % e s p
2009-02-09 22:17:40 +09:00
.endif
.endm
.macro POP_GS_EX
.pushsection .fixup , " ax"
2015-06-08 09:49:11 +02:00
99 : movl $ 0 , ( % e s p )
jmp 9 8 b
2009-02-09 22:17:40 +09:00
.popsection
2015-06-08 09:49:11 +02:00
_ ASM_ E X T A B L E ( 9 8 b , 9 9 b )
2009-02-09 22:17:40 +09:00
.endm
.macro PTGS_TO_GS
2015-06-08 09:49:11 +02:00
98 : mov P T _ G S ( % e s p ) , % g s
2009-02-09 22:17:40 +09:00
.endm
.macro PTGS_TO_GS_EX
.pushsection .fixup , " ax"
2015-06-08 09:49:11 +02:00
99 : movl $ 0 , P T _ G S ( % e s p )
jmp 9 8 b
2009-02-09 22:17:40 +09:00
.popsection
2015-06-08 09:49:11 +02:00
_ ASM_ E X T A B L E ( 9 8 b , 9 9 b )
2009-02-09 22:17:40 +09:00
.endm
.macro GS_TO_REG reg
2015-06-08 09:49:11 +02:00
movl % g s , \ r e g
2009-02-09 22:17:40 +09:00
.endm
.macro REG_TO_PTGS reg
2015-06-08 09:49:11 +02:00
movl \ r e g , P T _ G S ( % e s p )
2009-02-09 22:17:40 +09:00
.endm
.macro SET_KERNEL_GS reg
2015-06-08 09:49:11 +02:00
movl $ ( _ _ K E R N E L _ S T A C K _ C A N A R Y ) , \ r e g
movl \ r e g , % g s
2009-02-09 22:17:40 +09:00
.endm
2015-06-08 09:49:11 +02:00
# endif / * C O N F I G _ X 8 6 _ 3 2 _ L A Z Y _ G S * /
2009-02-09 22:17:40 +09:00
2018-07-18 11:40:49 +02:00
/* Unconditionally switch to user cr3 */
.macro SWITCH_TO_USER_CR3 scratch_reg : req
ALTERNATIVE " j m p . L e n d _ \ @", "", X86_FEATURE_PTI
movl % c r3 , \ s c r a t c h _ r e g
orl $ P T I _ S W I T C H _ M A S K , \ s c r a t c h _ r e g
movl \ s c r a t c h _ r e g , % c r3
.Lend_ \ @:
.endm
2018-07-18 11:41:16 +02:00
.macro BUG_IF_WRONG_CR3 no_ u s e r _ c h e c k =0
# ifdef C O N F I G _ D E B U G _ E N T R Y
ALTERNATIVE " j m p . L e n d _ \ @", "", X86_FEATURE_PTI
.if \ no_ u s e r _ c h e c k = = 0
/* coming from usermode? */
2019-11-18 16:21:12 +01:00
testl $ U S E R _ S E G M E N T _ R P L _ M A S K , P T _ C S ( % e s p )
2018-07-18 11:41:16 +02:00
jz . L e n d _ \ @
.endif
/* On user-cr3? */
movl % c r3 , % e a x
testl $ P T I _ S W I T C H _ M A S K , % e a x
jnz . L e n d _ \ @
/* From userspace with kernel cr3 - BUG */
ud2
.Lend_ \ @:
# endif
.endm
2018-07-18 11:40:49 +02:00
/ *
* Switch t o k e r n e l c r3 i f n o t a l r e a d y l o a d e d a n d r e t u r n c u r r e n t c r3 i n
* \ scratch_ r e g
* /
.macro SWITCH_TO_KERNEL_CR3 scratch_reg : req
ALTERNATIVE " j m p . L e n d _ \ @", "", X86_FEATURE_PTI
movl % c r3 , \ s c r a t c h _ r e g
/* Test if we are already on kernel CR3 */
testl $ P T I _ S W I T C H _ M A S K , \ s c r a t c h _ r e g
jz . L e n d _ \ @
andl $ ( ~ P T I _ S W I T C H _ M A S K ) , \ s c r a t c h _ r e g
movl \ s c r a t c h _ r e g , % c r3
/* Return original CR3 in \scratch_reg */
orl $ P T I _ S W I T C H _ M A S K , \ s c r a t c h _ r e g
.Lend_ \ @:
.endm
2019-05-07 23:25:54 +02:00
# define C S _ F R O M _ E N T R Y _ S T A C K ( 1 < < 3 1 )
# define C S _ F R O M _ U S E R _ C R 3 ( 1 < < 3 0 )
# define C S _ F R O M _ K E R N E L ( 1 < < 2 9 )
2019-11-20 15:02:26 +01:00
# define C S _ F R O M _ E S P F I X ( 1 < < 2 8 )
2019-05-07 23:25:54 +02:00
.macro FIXUP_FRAME
/ *
* The h i g h b i t s o f t h e C S d w o r d ( _ _ c s h ) a r e u s e d f o r C S _ F R O M _ * .
* Clear t h e m i n c a s e h a r d w a r e d i d n ' t d o t h i s f o r u s .
* /
2019-11-20 09:56:36 +01:00
andl $ 0 x00 0 0 f f f f , 4 * 4 ( % e s p )
2019-05-07 23:25:54 +02:00
# ifdef C O N F I G _ V M 8 6
2019-11-20 09:56:36 +01:00
testl $ X 8 6 _ E F L A G S _ V M , 5 * 4 ( % e s p )
2019-05-07 23:25:54 +02:00
jnz . L f r o m _ u s e r m o d e _ n o _ f i x u p _ \ @
# endif
2019-11-20 09:56:36 +01:00
testl $ U S E R _ S E G M E N T _ R P L _ M A S K , 4 * 4 ( % e s p )
2019-05-07 23:25:54 +02:00
jnz . L f r o m _ u s e r m o d e _ n o _ f i x u p _ \ @
2019-11-20 09:56:36 +01:00
orl $ C S _ F R O M _ K E R N E L , 4 * 4 ( % e s p )
2019-05-07 23:25:54 +02:00
/ *
* When w e ' r e h e r e f r o m k e r n e l m o d e ; the (exception) stack looks like:
*
2019-11-20 09:56:36 +01:00
* 6 * 4 ( % esp) - < p r e v i o u s c o n t e x t >
* 5 * 4 ( % esp) - f l a g s
* 4 * 4 ( % esp) - c s
* 3 * 4 ( % esp) - i p
* 2 * 4 ( % esp) - o r i g _ e a x
* 1 * 4 ( % esp) - g s / f u n c t i o n
* 0 * 4 ( % esp) - f s
2019-05-07 23:25:54 +02:00
*
* Lets b u i l d a 5 e n t r y I R E T f r a m e a f t e r t h a t , s u c h t h a t s t r u c t p t _ r e g s
* is c o m p l e t e a n d i n p a r t i c u l a r r e g s - > s p i s c o r r e c t . T h i s g i v e s u s
2019-11-20 09:56:36 +01:00
* the o r i g i n a l 6 e n t i e s a s g a p :
2019-05-07 23:25:54 +02:00
*
2019-11-20 09:56:36 +01:00
* 1 4 * 4 ( % esp) - < p r e v i o u s c o n t e x t >
* 1 3 * 4 ( % esp) - g a p / f l a g s
* 1 2 * 4 ( % esp) - g a p / c s
* 1 1 * 4 ( % esp) - g a p / i p
* 1 0 * 4 ( % esp) - g a p / o r i g _ e a x
* 9 * 4 ( % esp) - g a p / g s / f u n c t i o n
* 8 * 4 ( % esp) - g a p / f s
* 7 * 4 ( % esp) - s s
* 6 * 4 ( % esp) - s p
* 5 * 4 ( % esp) - f l a g s
* 4 * 4 ( % esp) - c s
* 3 * 4 ( % esp) - i p
* 2 * 4 ( % esp) - o r i g _ e a x
* 1 * 4 ( % esp) - g s / f u n c t i o n
* 0 * 4 ( % esp) - f s
2019-05-07 23:25:54 +02:00
* /
pushl % s s # s s
pushl % e s p # s p ( p o i n t s a t s s )
2019-11-20 09:56:36 +01:00
addl $ 7 * 4 , ( % e s p ) # p o i n t s p b a c k a t t h e p r e v i o u s c o n t e x t
pushl 7 * 4 ( % e s p ) # f l a g s
pushl 7 * 4 ( % e s p ) # c s
pushl 7 * 4 ( % e s p ) # i p
pushl 7 * 4 ( % e s p ) # o r i g _ e a x
pushl 7 * 4 ( % e s p ) # g s / f u n c t i o n
pushl 7 * 4 ( % e s p ) # f s
2019-05-07 23:25:54 +02:00
.Lfrom_usermode_no_fixup_ \ @:
.endm
.macro IRET_FRAME
2019-11-20 09:49:33 +01:00
/ *
* We' r e c a l l e d w i t h % d s , % e s , % f s , a n d % g s f r o m t h e i n t e r r u p t e d
* frame, s o w e s h o u l d n ' t u s e t h e m . A l s o , w e m a y b e i n E S P F I X
* mode a n d t h e r e f o r e h a v e a n o n z e r o S S b a s e a n d a n o f f s e t E S P ,
* so a n y a t t e m p t t o a c c e s s t h e s t a c k n e e d s t o u s e S S . ( e x c e p t f o r
* accesses t h r o u g h % e s p , w h i c h a u t o m a t i c a l l y u s e S S . )
* /
2019-05-07 23:25:54 +02:00
testl $ C S _ F R O M _ K E R N E L , 1 * 4 ( % e s p )
jz . L f i n i s h e d _ f r a m e _ \ @
/ *
* Reconstruct t h e 3 e n t r y I R E T f r a m e r i g h t a f t e r t h e ( m o d i f i e d )
* regs- > s p w i t h o u t l o w e r i n g % e s p i n b e t w e e n , s u c h t h a t a n N M I i n t h e
* middle d o e s n ' t s c r i b b l e o u r s t a c k .
* /
pushl % e a x
pushl % e c x
movl 5 * 4 ( % e s p ) , % e a x # ( m o d i f i e d ) r e g s - > s p
movl 4 * 4 ( % e s p ) , % e c x # f l a g s
2019-11-20 09:49:33 +01:00
movl % e c x , % s s : - 1 * 4 ( % e a x )
2019-05-07 23:25:54 +02:00
movl 3 * 4 ( % e s p ) , % e c x # c s
andl $ 0 x00 0 0 f f f f , % e c x
2019-11-20 09:49:33 +01:00
movl % e c x , % s s : - 2 * 4 ( % e a x )
2019-05-07 23:25:54 +02:00
movl 2 * 4 ( % e s p ) , % e c x # i p
2019-11-20 09:49:33 +01:00
movl % e c x , % s s : - 3 * 4 ( % e a x )
2019-05-07 23:25:54 +02:00
movl 1 * 4 ( % e s p ) , % e c x # e a x
2019-11-20 09:49:33 +01:00
movl % e c x , % s s : - 4 * 4 ( % e a x )
2019-05-07 23:25:54 +02:00
popl % e c x
2019-11-20 09:49:33 +01:00
lea - 4 * 4 ( % e a x ) , % e s p
2019-05-07 23:25:54 +02:00
popl % e a x
.Lfinished_frame_ \ @:
.endm
2019-11-20 10:10:49 +01:00
.macro SAVE_ALL pt_ r e g s _ a x = % e a x s w i t c h _ s t a c k s =0 s k i p _ g s =0 u n w i n d _ e s p f i x =0
2009-02-09 22:17:40 +09:00
cld
2019-07-11 13:40:56 +02:00
.if \ skip_ g s = = 0
2009-02-09 22:17:40 +09:00
PUSH_ G S
2019-07-11 13:40:56 +02:00
.endif
2015-06-08 09:49:11 +02:00
pushl % f s
2019-11-20 10:10:49 +01:00
pushl % e a x
movl $ ( _ _ K E R N E L _ P E R C P U ) , % e a x
movl % e a x , % f s
.if \ unwind_ e s p f i x > 0
UNWIND_ E S P F I X _ S T A C K
.endif
popl % e a x
2019-11-20 09:56:36 +01:00
FIXUP_ F R A M E
2015-06-08 09:49:11 +02:00
pushl % e s
pushl % d s
2015-10-05 17:48:14 -07:00
pushl \ p t _ r e g s _ a x
2015-06-08 09:49:11 +02:00
pushl % e b p
pushl % e d i
pushl % e s i
pushl % e d x
pushl % e c x
pushl % e b x
movl $ ( _ _ U S E R _ D S ) , % e d x
movl % e d x , % d s
movl % e d x , % e s
2019-07-11 13:40:56 +02:00
.if \ skip_ g s = = 0
2009-02-09 22:17:40 +09:00
SET_ K E R N E L _ G S % e d x
2019-07-11 13:40:56 +02:00
.endif
2018-07-18 11:40:44 +02:00
/* Switch to kernel stack if necessary */
.if \ switch_ s t a c k s > 0
SWITCH_ T O _ K E R N E L _ S T A C K
.endif
2009-02-09 22:17:40 +09:00
.endm
2005-04-16 15:20:36 -07:00
2019-11-20 15:02:26 +01:00
.macro SAVE_ALL_NMI cr3_reg : req u n w i n d _ e s p f i x =0
SAVE_ A L L u n w i n d _ e s p f i x = \ u n w i n d _ e s p f i x
2018-07-18 11:40:50 +02:00
2018-07-18 11:41:16 +02:00
BUG_ I F _ W R O N G _ C R 3
2018-07-18 11:40:50 +02:00
/ *
* Now s w i t c h t h e C R 3 w h e n P T I i s e n a b l e d .
*
* We c a n e n t e r w i t h e i t h e r u s e r o r k e r n e l c r3 , t h e c o d e w i l l
* store t h e o l d c r3 i n \ c r3 _ r e g a n d s w i t c h e s t o t h e k e r n e l c r3
* if n e c e s s a r y .
* /
SWITCH_ T O _ K E R N E L _ C R 3 s c r a t c h _ r e g = \ c r3 _ r e g
.Lend_ \ @:
2018-07-18 11:40:46 +02:00
.endm
2018-07-18 11:41:16 +02:00
2009-02-09 22:17:40 +09:00
.macro RESTORE_INT_REGS
2015-06-08 09:49:11 +02:00
popl % e b x
popl % e c x
popl % e d x
popl % e s i
popl % e d i
popl % e b p
popl % e a x
2009-02-09 22:17:40 +09:00
.endm
2005-04-16 15:20:36 -07:00
2009-02-09 22:17:40 +09:00
.macro RESTORE_REGS pop=0
2009-02-09 22:17:40 +09:00
RESTORE_ I N T _ R E G S
2015-06-08 09:49:11 +02:00
1 : popl % d s
2 : popl % e s
3 : popl % f s
2009-02-09 22:17:40 +09:00
POP_ G S \ p o p
2019-11-20 13:05:06 +01:00
IRET_ F R A M E
2009-02-09 22:17:40 +09:00
.pushsection .fixup , " ax"
2015-06-08 09:49:11 +02:00
4 : movl $ 0 , ( % e s p )
jmp 1 b
5 : movl $ 0 , ( % e s p )
jmp 2 b
6 : movl $ 0 , ( % e s p )
jmp 3 b
[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 02:14:02 +01:00
.popsection
2015-06-08 09:49:11 +02:00
_ ASM_ E X T A B L E ( 1 b , 4 b )
_ ASM_ E X T A B L E ( 2 b , 5 b )
_ ASM_ E X T A B L E ( 3 b , 6 b )
2009-02-09 22:17:40 +09:00
POP_ G S _ E X
2009-02-09 22:17:40 +09:00
.endm
2005-04-16 15:20:36 -07:00
2018-07-18 11:40:50 +02:00
.macro RESTORE_ALL_NMI cr3_reg : req p o p =0
/ *
* Now s w i t c h t h e C R 3 w h e n P T I i s e n a b l e d .
*
* We e n t e r w i t h k e r n e l c r3 a n d s w i t c h t h e c r3 t o t h e v a l u e
* stored o n \ c r3 _ r e g , w h i c h i s e i t h e r a u s e r o r a k e r n e l c r3 .
* /
ALTERNATIVE " j m p . L s w i t c h e d _ \ @", "", X86_FEATURE_PTI
testl $ P T I _ S W I T C H _ M A S K , \ c r3 _ r e g
jz . L s w i t c h e d _ \ @
/* User cr3 in \cr3_reg - write it to hardware cr3 */
movl \ c r3 _ r e g , % c r3
.Lswitched_ \ @:
2018-07-18 11:41:16 +02:00
BUG_ I F _ W R O N G _ C R 3
2018-07-18 11:40:46 +02:00
RESTORE_ R E G S p o p = \ p o p
.endm
2018-07-18 11:40:41 +02:00
.macro CHECK_AND_APPLY_ESPFIX
# ifdef C O N F I G _ X 8 6 _ E S P F I X 3 2
2019-11-24 08:50:03 -08:00
# define G D T _ E S P F I X _ O F F S E T ( G D T _ E N T R Y _ E S P F I X _ S S * 8 )
# define G D T _ E S P F I X _ S S P E R _ C P U _ V A R ( g d t _ p a g e ) + G D T _ E S P F I X _ O F F S E T
2018-07-18 11:40:41 +02:00
ALTERNATIVE " j m p . L e n d _ \ @", "", X86_BUG_ESPFIX
movl P T _ E F L A G S ( % e s p ) , % e a x # m i x E F L A G S , S S a n d C S
/ *
* Warning : PT_ O L D S S ( % e s p ) c o n t a i n s t h e w r o n g / r a n d o m v a l u e s i f w e
* are r e t u r n i n g t o t h e k e r n e l .
* See c o m m e n t s i n p r o c e s s . c : c o p y _ t h r e a d ( ) f o r d e t a i l s .
* /
movb P T _ O L D S S ( % e s p ) , % a h
movb P T _ C S ( % e s p ) , % a l
andl $ ( X 8 6 _ E F L A G S _ V M | ( S E G M E N T _ T I _ M A S K < < 8 ) | S E G M E N T _ R P L _ M A S K ) , % e a x
cmpl $ ( ( S E G M E N T _ L D T < < 8 ) | U S E R _ R P L ) , % e a x
jne . L e n d _ \ @ # returning to user-space with LDT SS
/ *
* Setup a n d s w i t c h t o E S P F I X s t a c k
*
* We' r e r e t u r n i n g t o u s e r s p a c e w i t h a 1 6 b i t s t a c k . T h e C P U w i l l n o t
* restore t h e h i g h w o r d o f E S P f o r u s o n e x e c u t i n g i r e t . . . T h i s i s a n
* " official" b u g o f a l l t h e x86 - c o m p a t i b l e C P U s , w h i c h w e c a n w o r k
* around t o m a k e d o s e m u a n d w i n e h a p p y . W e d o t h i s b y p r e l o a d i n g t h e
* high w o r d o f E S P w i t h t h e h i g h w o r d o f t h e u s e r s p a c e E S P w h i l e
* compensating f o r t h e o f f s e t b y c h a n g i n g t o t h e E S P F I X s e g m e n t w i t h
* a b a s e a d d r e s s t h a t m a t c h e s f o r t h e d i f f e r e n c e .
* /
mov % e s p , % e d x / * l o a d k e r n e l e s p * /
mov P T _ O L D E S P ( % e s p ) , % e a x / * l o a d u s e r s p a c e e s p * /
mov % d x , % a x / * e a x : n e w k e r n e l e s p * /
sub % e a x , % e d x / * o f f s e t ( l o w w o r d i s 0 ) * /
shr $ 1 6 , % e d x
mov % d l , G D T _ E S P F I X _ S S + 4 / * b i t s 1 6 . . 2 3 * /
mov % d h , G D T _ E S P F I X _ S S + 7 / * b i t s 2 4 . . 3 1 * /
pushl $ _ _ E S P F I X _ S S
pushl % e a x / * n e w k e r n e l e s p * /
/ *
* Disable i n t e r r u p t s , b u t d o n o t i r q t r a c e t h i s s e c t i o n : w e
* will s o o n e x e c u t e i r e t a n d t h e t r a c e r w a s a l r e a d y s e t t o
* the i r q s t a t e a f t e r t h e I R E T :
* /
DISABLE_ I N T E R R U P T S ( C L B R _ A N Y )
lss ( % e s p ) , % e s p / * s w i t c h t o e s p f i x s e g m e n t * /
.Lend_ \ @:
# endif / * C O N F I G _ X 8 6 _ E S P F I X 3 2 * /
.endm
2018-07-18 11:40:44 +02:00
/ *
* Called w i t h p t _ r e g s f u l l y p o p u l a t e d a n d k e r n e l s e g m e n t s l o a d e d ,
* so w e c a n a c c e s s P E R _ C P U a n d u s e t h e i n t e g e r r e g i s t e r s .
*
* We n e e d t o b e v e r y c a r e f u l h e r e w i t h t h e % e s p s w i t c h , b e c a u s e a n N M I
* can h a p p e n e v e r y w h e r e . I f t h e N M I h a n d l e r f i n d s i t s e l f o n t h e
* entry- s t a c k , i t w i l l o v e r w r i t e t h e t a s k - s t a c k a n d e v e r y t h i n g w e
* copied t h e r e . S o a l l o c a t e t h e s t a c k - f r a m e o n t h e t a s k - s t a c k a n d
* switch t o i t b e f o r e w e d o a n y c o p y i n g .
* /
2018-07-18 11:40:47 +02:00
2018-07-18 11:40:44 +02:00
.macro SWITCH_TO_KERNEL_STACK
ALTERNATIVE " " , " j m p . L e n d _ \ @", X86_FEATURE_XENPV
2018-07-18 11:41:16 +02:00
BUG_ I F _ W R O N G _ C R 3
2018-07-18 11:40:49 +02:00
SWITCH_ T O _ K E R N E L _ C R 3 s c r a t c h _ r e g = % e a x
/ *
* % eax n o w c o n t a i n s t h e e n t r y c r3 a n d w e c a r r y i t f o r w a r d i n
* that r e g i s t e r f o r t h e t i m e t h i s m a c r o r u n s
* /
2018-07-18 11:40:44 +02:00
/* Are we on the entry stack? Bail out if not! */
movl P E R _ C P U _ V A R ( c p u _ e n t r y _ a r e a ) , % e c x
addl $ C P U _ E N T R Y _ A R E A _ e n t r y _ s t a c k + S I Z E O F _ e n t r y _ s t a c k , % e c x
subl % e s p , % e c x / * e c x = ( e n d o f e n t r y _ s t a c k ) - e s p * /
cmpl $ S I Z E O F _ e n t r y _ s t a c k , % e c x
jae . L e n d _ \ @
/* Load stack pointer into %esi and %edi */
movl % e s p , % e s i
movl % e s i , % e d i
/* Move %edi to the top of the entry stack */
andl $ ( M A S K _ e n t r y _ s t a c k ) , % e d i
addl $ ( S I Z E O F _ e n t r y _ s t a c k ) , % e d i
/* Load top of task-stack into %edi */
movl T S S _ e n t r y 2 t a s k _ s t a c k ( % e d i ) , % e d i
2018-07-18 11:40:47 +02:00
/* Special case - entry from kernel mode via entry stack */
2018-07-20 18:22:23 +02:00
# ifdef C O N F I G _ V M 8 6
movl P T _ E F L A G S ( % e s p ) , % e c x # m i x E F L A G S a n d C S
movb P T _ C S ( % e s p ) , % c l
andl $ ( X 8 6 _ E F L A G S _ V M | S E G M E N T _ R P L _ M A S K ) , % e c x
# else
movl P T _ C S ( % e s p ) , % e c x
andl $ S E G M E N T _ R P L _ M A S K , % e c x
# endif
cmpl $ U S E R _ R P L , % e c x
jb . L e n t r y _ f r o m _ k e r n e l _ \ @
2018-07-18 11:40:47 +02:00
2018-07-18 11:40:44 +02:00
/* Bytes to copy */
movl $ P T R E G S _ S I Z E , % e c x
# ifdef C O N F I G _ V M 8 6
testl $ X 8 6 _ E F L A G S _ V M , P T _ E F L A G S ( % e s i )
jz . L c o p y _ p t _ r e g s _ \ @
/ *
* Stack- f r a m e c o n t a i n s 4 a d d i t i o n a l s e g m e n t r e g i s t e r s w h e n
* coming f r o m V M 8 6 m o d e
* /
addl $ ( 4 * 4 ) , % e c x
# endif
2018-07-18 11:40:47 +02:00
.Lcopy_pt_regs_ \ @:
2018-07-18 11:40:44 +02:00
/* Allocate frame on task-stack */
subl % e c x , % e d i
/* Switch to task-stack */
movl % e d i , % e s p
/ *
* We a r e n o w o n t h e t a s k - s t a c k a n d c a n s a f e l y c o p y o v e r t h e
* stack- f r a m e
* /
shrl $ 2 , % e c x
cld
rep m o v s l
2018-07-18 11:40:47 +02:00
jmp . L e n d _ \ @
.Lentry_from_kernel_ \ @:
/ *
* This h a n d l e s t h e c a s e w h e n w e e n t e r t h e k e r n e l f r o m
* kernel- m o d e a n d % e s p p o i n t s t o t h e e n t r y - s t a c k . W h e n t h i s
* happens w e n e e d t o s w i t c h t o t h e t a s k - s t a c k t o r u n C c o d e ,
* but s w i t c h b a c k t o t h e e n t r y - s t a c k a g a i n w h e n w e a p p r o a c h
* iret a n d r e t u r n t o t h e i n t e r r u p t e d c o d e - p a t h . T h i s u s u a l l y
* happens w h e n w e h i t a n e x c e p t i o n w h i l e r e s t o r i n g u s e r - s p a c e
2018-07-18 11:40:49 +02:00
* segment r e g i s t e r s o n t h e w a y b a c k t o u s e r - s p a c e o r w h e n t h e
* sysenter h a n d l e r r u n s w i t h e f l a g s . t f s e t .
2018-07-18 11:40:47 +02:00
*
* When w e s w i t c h t o t h e t a s k - s t a c k h e r e , w e c a n ' t t r u s t t h e
* contents o f t h e e n t r y - s t a c k a n y m o r e , a s t h e e x c e p t i o n h a n d l e r
* might b e s c h e d u l e d o u t o r m o v e d t o a n o t h e r C P U . T h e r e f o r e w e
* copy t h e c o m p l e t e e n t r y - s t a c k t o t h e t a s k - s t a c k a n d s e t a
* marker i n t h e i r e t - f r a m e ( b i t 3 1 o f t h e C S d w o r d ) t o d e t e c t
* what w e ' v e d o n e o n t h e i r e t p a t h .
*
* On t h e i r e t p a t h w e c o p y e v e r y t h i n g b a c k a n d s w i t c h t o t h e
* entry- s t a c k , s o t h a t t h e i n t e r r u p t e d k e r n e l c o d e - p a t h
* continues o n t h e s a m e s t a c k i t w a s i n t e r r u p t e d w i t h .
*
* Be a w a r e t h a t a n N M I c a n h a p p e n a n y t i m e i n t h i s c o d e .
*
* % esi : Entry- S t a c k p o i n t e r ( s a m e a s % e s p )
* % edi : Top o f t h e t a s k s t a c k
2018-07-18 11:40:49 +02:00
* % eax : CR3 o n k e r n e l e n t r y
2018-07-18 11:40:47 +02:00
* /
/* Calculate number of bytes on the entry stack in %ecx */
movl % e s i , % e c x
/* %ecx to the top of entry-stack */
andl $ ( M A S K _ e n t r y _ s t a c k ) , % e c x
addl $ ( S I Z E O F _ e n t r y _ s t a c k ) , % e c x
/* Number of bytes on the entry stack to %ecx */
sub % e s i , % e c x
/* Mark stackframe as coming from entry stack */
orl $ C S _ F R O M _ E N T R Y _ S T A C K , P T _ C S ( % e s p )
2018-07-18 11:40:49 +02:00
/ *
* Test t h e c r3 u s e d t o e n t e r t h e k e r n e l a n d a d d a m a r k e r
* so t h a t w e c a n s w i t c h b a c k t o i t b e f o r e i r e t .
* /
testl $ P T I _ S W I T C H _ M A S K , % e a x
jz . L c o p y _ p t _ r e g s _ \ @
orl $ C S _ F R O M _ U S E R _ C R 3 , P T _ C S ( % e s p )
2018-07-18 11:40:47 +02:00
/ *
* % esi a n d % e d i a r e u n c h a n g e d , % e c x c o n t a i n s t h e n u m b e r o f
* bytes t o c o p y . T h e c o d e a t . L c o p y _ p t _ r e g s _ \ @ will allocate
* the s t a c k - f r a m e o n t a s k - s t a c k a n d c o p y e v e r y t h i n g o v e r
* /
jmp . L c o p y _ p t _ r e g s _ \ @
2018-07-18 11:40:44 +02:00
.Lend_ \ @:
.endm
2018-07-18 11:40:45 +02:00
/ *
* Switch b a c k f r o m t h e k e r n e l s t a c k t o t h e e n t r y s t a c k .
*
* The % e s p r e g i s t e r m u s t p o i n t t o p t _ r e g s o n t h e t a s k s t a c k . I t w i l l
* first c a l c u l a t e t h e s i z e o f t h e s t a c k - f r a m e t o c o p y , d e p e n d i n g o n
* whether w e r e t u r n t o V M 8 6 m o d e o r n o t . W i t h t h a t i t u s e s ' r e p m o v s l '
* to c o p y t h e c o n t e n t s o f t h e s t a c k o v e r t o t h e e n t r y s t a c k .
*
* We m u s t b e v e r y c a r e f u l h e r e , a s w e c a n ' t t r u s t t h e c o n t e n t s o f t h e
* task- s t a c k o n c e w e s w i t c h e d t o t h e e n t r y - s t a c k . W h e n a n N M I h a p p e n s
* while o n t h e e n t r y - s t a c k , t h e N M I h a n d l e r w i l l s w i t c h b a c k t o t h e t o p
* of t h e t a s k s t a c k , o v e r w r i t i n g o u r s t a c k - f r a m e w e a r e a b o u t t o c o p y .
* Therefore w e s w i t c h t h e s t a c k o n l y a f t e r e v e r y t h i n g i s c o p i e d o v e r .
* /
.macro SWITCH_TO_ENTRY_STACK
ALTERNATIVE " " , " j m p . L e n d _ \ @", X86_FEATURE_XENPV
/* Bytes to copy */
movl $ P T R E G S _ S I Z E , % e c x
# ifdef C O N F I G _ V M 8 6
testl $ ( X 8 6 _ E F L A G S _ V M ) , P T _ E F L A G S ( % e s p )
jz . L c o p y _ p t _ r e g s _ \ @
/* Additional 4 registers to copy when returning to VM86 mode */
addl $ ( 4 * 4 ) , % e c x
.Lcopy_pt_regs_ \ @:
# endif
/* Initialize source and destination for movsl */
movl P E R _ C P U _ V A R ( c p u _ t s s _ r w + T S S _ s p0 ) , % e d i
subl % e c x , % e d i
movl % e s p , % e s i
/* Save future stack pointer in %ebx */
movl % e d i , % e b x
/* Copy over the stack-frame */
shrl $ 2 , % e c x
cld
rep m o v s l
/ *
* Switch t o e n t r y - s t a c k - n e e d s t o h a p p e n a f t e r e v e r y t h i n g i s
* copied b e c a u s e t h e N M I h a n d l e r w i l l o v e r w r i t e t h e t a s k - s t a c k
* when o n e n t r y - s t a c k
* /
movl % e b x , % e s p
.Lend_ \ @:
.endm
2018-07-18 11:40:47 +02:00
/ *
* This m a c r o h a n d l e s t h e c a s e w h e n w e r e t u r n t o k e r n e l - m o d e o n t h e i r e t
2018-07-18 11:40:49 +02:00
* path a n d h a v e t o s w i t c h b a c k t o t h e e n t r y s t a c k a n d / o r u s e r - c r3
2018-07-18 11:40:47 +02:00
*
* See t h e c o m m e n t s b e l o w t h e . L e n t r y _ f r o m _ k e r n e l _ \ @ label in the
* SWITCH_ T O _ K E R N E L _ S T A C K m a c r o f o r m o r e d e t a i l s .
* /
.macro PARANOID_EXIT_TO_KERNEL_MODE
/ *
* Test i f w e e n t e r e d t h e k e r n e l w i t h t h e e n t r y - s t a c k . M o s t
* likely w e d i d n o t , b e c a u s e t h i s c o d e o n l y r u n s o n t h e
* return- t o - k e r n e l p a t h .
* /
testl $ C S _ F R O M _ E N T R Y _ S T A C K , P T _ C S ( % e s p )
jz . L e n d _ \ @
/* Unlikely slow-path */
/* Clear marker from stack-frame */
andl $ ( ~ C S _ F R O M _ E N T R Y _ S T A C K ) , P T _ C S ( % e s p )
/* Copy the remaining task-stack contents to entry-stack */
movl % e s p , % e s i
movl P E R _ C P U _ V A R ( c p u _ t s s _ r w + T S S _ s p0 ) , % e d i
/* Bytes on the task-stack to ecx */
movl P E R _ C P U _ V A R ( c p u _ t s s _ r w + T S S _ s p1 ) , % e c x
subl % e s i , % e c x
/* Allocate stack-frame on entry-stack */
subl % e c x , % e d i
/ *
* Save f u t u r e s t a c k - p o i n t e r , w e m u s t n o t s w i t c h u n t i l t h e
* copy i s d o n e , o t h e r w i s e t h e N M I h a n d l e r c o u l d d e s t r o y t h e
* contents o f t h e t a s k - s t a c k w e a r e a b o u t t o c o p y .
* /
movl % e d i , % e b x
/* Do the copy */
shrl $ 2 , % e c x
cld
rep m o v s l
/* Safe to switch to entry-stack now */
movl % e b x , % e s p
2018-07-18 11:40:49 +02:00
/ *
* We c a m e f r o m e n t r y - s t a c k a n d n e e d t o c h e c k i f w e a l s o n e e d t o
* switch b a c k t o u s e r c r3 .
* /
testl $ C S _ F R O M _ U S E R _ C R 3 , P T _ C S ( % e s p )
jz . L e n d _ \ @
/* Clear marker from stack-frame */
andl $ ( ~ C S _ F R O M _ U S E R _ C R 3 ) , P T _ C S ( % e s p )
SWITCH_ T O _ U S E R _ C R 3 s c r a t c h _ r e g = % e a x
2018-07-18 11:40:47 +02:00
.Lend_ \ @:
.endm
2020-02-25 23:16:11 +01:00
/ * *
* idtentry - M a c r o t o g e n e r a t e e n t r y s t u b s f o r s i m p l e I D T e n t r i e s
* @vector: Vector number
* @asmsym: ASM symbol for the entry point
* @cfunc: C function to be called
* @has_error_code: Hardware pushed error code on stack
* @sane: Compatibility flag with 64bit
* /
.macro idtentry vector a s m s y m c f u n c h a s _ e r r o r _ c o d e : r e q s a n e =0
SYM_ C O D E _ S T A R T ( \ a s m s y m )
ASM_ C L A C
cld
.if \ has_ e r r o r _ c o d e = = 0
pushl $ 0 / * C l e a r t h e e r r o r c o d e * /
.endif
/* Push the C-function address into the GS slot */
pushl $ \ c f u n c
/* Invoke the common exception entry */
jmp h a n d l e _ e x c e p t i o n
SYM_ C O D E _ E N D ( \ a s m s y m )
.endm
2020-02-25 23:16:12 +01:00
/ *
* Include t h e d e f i n e s w h i c h e m i t t h e i d t e n t r i e s w h i c h a r e s h a r e d
* shared b e t w e e n 3 2 a n d 6 4 b i t .
* /
# include < a s m / i d t e n t r y . h >
2016-08-13 12:38:19 -04:00
/ *
* % eax : prev t a s k
* % edx : next t a s k
* /
2020-03-25 19:47:40 +01:00
.pushsection .text , " ax"
2019-10-11 13:51:06 +02:00
SYM_ C O D E _ S T A R T ( _ _ s w i t c h _ t o _ a s m )
2016-08-13 12:38:19 -04:00
/ *
* Save c a l l e e - s a v e d r e g i s t e r s
* This m u s t m a t c h t h e o r d e r i n s t r u c t i n a c t i v e _ t a s k _ f r a m e
* /
pushl % e b p
pushl % e b x
pushl % e d i
pushl % e s i
2019-11-16 11:12:03 +01:00
/ *
* Flags a r e s a v e d t o p r e v e n t A C l e a k a g e . T h i s c o u l d g o
* away i f o b j t o o l w o u l d h a v e 3 2 b i t s u p p o r t t o v e r i f y
* the S T A C / C L A C c o r r e c t n e s s .
* /
2019-02-14 10:30:52 +01:00
pushfl
2016-08-13 12:38:19 -04:00
/* switch stack */
movl % e s p , T A S K _ t h r e a d s p ( % e a x )
movl T A S K _ t h r e a d s p ( % e d x ) , % e s p
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 12:21:18 +09:00
# ifdef C O N F I G _ S T A C K P R O T E C T O R
2016-08-13 12:38:19 -04:00
movl T A S K _ s t a c k _ c a n a r y ( % e d x ) , % e b x
movl % e b x , P E R _ C P U _ V A R ( s t a c k _ c a n a r y ) + s t a c k _ c a n a r y _ o f f s e t
# endif
2018-01-12 17:49:25 +00:00
# ifdef C O N F I G _ R E T P O L I N E
/ *
* When s w i t c h i n g f r o m a s h a l l o w e r t o a d e e p e r c a l l s t a c k
* the R S B m a y e i t h e r u n d e r f l o w o r u s e e n t r i e s p o p u l a t e d
* with u s e r s p a c e a d d r e s s e s . O n C P U s w h e r e t h o s e c o n c e r n s
* exist, o v e r w r i t e t h e R S B w i t h e n t r i e s w h i c h c a p t u r e
* speculative e x e c u t i o n t o p r e v e n t a t t a c k .
* /
2018-02-19 10:50:56 +00:00
FILL_ R E T U R N _ B U F F E R % e b x , R S B _ C L E A R _ L O O P S , X 8 6 _ F E A T U R E _ R S B _ C T X S W
2018-01-12 17:49:25 +00:00
# endif
2019-11-16 11:12:03 +01:00
/* Restore flags or the incoming task to restore AC state. */
2019-02-14 10:30:52 +01:00
popfl
2019-11-16 11:12:03 +01:00
/* restore callee-saved registers */
2016-08-13 12:38:19 -04:00
popl % e s i
popl % e d i
popl % e b x
popl % e b p
jmp _ _ s w i t c h _ t o
2019-10-11 13:51:06 +02:00
SYM_ C O D E _ E N D ( _ _ s w i t c h _ t o _ a s m )
2020-03-25 19:47:40 +01:00
.popsection
2016-08-13 12:38:19 -04:00
2017-05-23 10:37:29 -05:00
/ *
* The u n w i n d e r e x p e c t s t h e l a s t f r a m e o n t h e s t a c k t o a l w a y s b e a t t h e s a m e
* offset f r o m t h e e n d o f t h e p a g e , w h i c h a l l o w s i t t o v a l i d a t e t h e s t a c k .
* Calling s c h e d u l e _ t a i l ( ) d i r e c t l y w o u l d b r e a k t h a t c o n v e n t i o n b e c a u s e i t s a n
* asmlinkage f u n c t i o n s o i t s a r g u m e n t h a s t o b e p u s h e d o n t h e s t a c k . T h i s
* wrapper c r e a t e s a p r o p e r " e n d o f s t a c k " f r a m e h e a d e r b e f o r e t h e c a l l .
* /
2020-03-25 19:47:40 +01:00
.pushsection .text , " ax"
2019-10-11 13:51:07 +02:00
SYM_ F U N C _ S T A R T ( s c h e d u l e _ t a i l _ w r a p p e r )
2017-05-23 10:37:29 -05:00
FRAME_ B E G I N
pushl % e a x
call s c h e d u l e _ t a i l
popl % e a x
FRAME_ E N D
ret
2019-10-11 13:51:07 +02:00
SYM_ F U N C _ E N D ( s c h e d u l e _ t a i l _ w r a p p e r )
2020-03-25 19:47:40 +01:00
.popsection
2016-08-13 12:38:19 -04:00
/ *
* A n e w l y f o r k e d p r o c e s s d i r e c t l y c o n t e x t s w i t c h e s i n t o t h i s a d d r e s s .
*
* eax : prev t a s k w e s w i t c h e d f r o m
2016-08-13 12:38:20 -04:00
* ebx : kernel t h r e a d f u n c ( N U L L f o r u s e r t h r e a d )
* edi : kernel t h r e a d a r g
2016-08-13 12:38:19 -04:00
* /
2020-03-25 19:47:40 +01:00
.pushsection .text , " ax"
2019-10-11 13:51:06 +02:00
SYM_ C O D E _ S T A R T ( r e t _ f r o m _ f o r k )
2017-05-23 10:37:29 -05:00
call s c h e d u l e _ t a i l _ w r a p p e r
2015-10-05 17:48:13 -07:00
2016-08-13 12:38:20 -04:00
testl % e b x , % e b x
jnz 1 f / * k e r n e l t h r e a d s a r e u n c o m m o n * /
2 :
2015-10-05 17:48:13 -07:00
/* When we fork, we trace the syscall return in the child, too. */
2017-05-23 10:37:29 -05:00
movl % e s p , % e a x
2015-10-05 17:48:13 -07:00
call s y s c a l l _ r e t u r n _ s l o w p a t h
2020-03-04 12:51:59 +01:00
jmp . L s y s c a l l _ 3 2 _ d o n e
2015-10-05 17:48:13 -07:00
2016-08-13 12:38:20 -04:00
/* kernel thread */
1 : movl % e d i , % e a x
2020-04-22 17:16:40 +02:00
CALL_ N O S P E C e b x
2015-10-05 17:48:13 -07:00
/ *
2016-08-13 12:38:20 -04:00
* A k e r n e l t h r e a d i s a l l o w e d t o r e t u r n h e r e a f t e r s u c c e s s f u l l y
* calling d o _ e x e c v e ( ) . E x i t t o u s e r s p a c e t o c o m p l e t e t h e e x e c v e ( )
* syscall.
2015-10-05 17:48:13 -07:00
* /
2016-08-13 12:38:20 -04:00
movl $ 0 , P T _ E A X ( % e s p )
jmp 2 b
2019-10-11 13:51:06 +02:00
SYM_ C O D E _ E N D ( r e t _ f r o m _ f o r k )
2020-03-25 19:47:40 +01:00
.popsection
2012-08-02 23:05:11 +04:00
2005-04-16 15:20:36 -07:00
/ *
* Return t o u s e r m o d e i s n o t a s c o m p l e x a s a l l t h i s l o o k s ,
* but w e w a n t t h e d e f a u l t p a t h f o r a s y s t e m c a l l r e t u r n t o
* go a s q u i c k l y a s p o s s i b l e w h i c h i s w h y s o m e o f t h i s i s
* less c l e a r t h a n i t o t h e r w i s e s h o u l d b e .
* /
# userspace r e s u m p t i o n s t u b b y p a s s i n g s y s c a l l e x i t t r a c i n g
2019-10-11 13:50:50 +02:00
SYM_ C O D E _ S T A R T _ L O C A L ( r e t _ f r o m _ e x c e p t i o n )
2006-12-07 02:14:08 +01:00
preempt_ s t o p ( C L B R _ A N Y )
2005-04-16 15:20:36 -07:00
ret_from_intr :
2012-03-22 21:39:25 +01:00
# ifdef C O N F I G _ V M 8 6
2015-06-08 09:49:11 +02:00
movl P T _ E F L A G S ( % e s p ) , % e a x # m i x E F L A G S a n d C S
movb P T _ C S ( % e s p ) , % a l
andl $ ( X 8 6 _ E F L A G S _ V M | S E G M E N T _ R P L _ M A S K ) , % e a x
2012-03-22 21:39:25 +01:00
# else
/ *
2012-08-02 23:05:11 +04:00
* We c a n b e c o m i n g h e r e f r o m c h i l d s p a w n e d b y k e r n e l _ t h r e a d ( ) .
2012-03-22 21:39:25 +01:00
* /
2015-06-08 09:49:11 +02:00
movl P T _ C S ( % e s p ) , % e a x
andl $ S E G M E N T _ R P L _ M A S K , % e a x
2012-03-22 21:39:25 +01:00
# endif
2015-06-08 09:49:11 +02:00
cmpl $ U S E R _ R P L , % e a x
2019-05-07 23:25:54 +02:00
jb r e s t o r e _ a l l _ k e r n e l # n o t r e t u r n i n g t o v 8086 o r u s e r s p a c e
[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 02:14:02 +01:00
2015-07-31 14:41:09 -07:00
DISABLE_ I N T E R R U P T S ( C L B R _ A N Y )
2008-06-06 10:14:08 +02:00
TRACE_ I R Q S _ O F F
2015-07-31 14:41:09 -07:00
movl % e s p , % e a x
call p r e p a r e _ e x i t _ t o _ u s e r m o d e
2020-03-04 12:51:59 +01:00
jmp r e s t o r e _ a l l _ s w i t c h _ s t a c k
2019-10-11 13:50:50 +02:00
SYM_ C O D E _ E N D ( r e t _ f r o m _ e x c e p t i o n )
2005-04-16 15:20:36 -07:00
2019-10-11 13:50:59 +02:00
SYM_ E N T R Y ( _ _ b e g i n _ S Y S E N T E R _ s i n g l e s t e p _ r e g i o n , S Y M _ L _ G L O B A L , S Y M _ A _ N O N E )
2016-03-09 19:00:30 -08:00
/ *
* All c o d e f r o m h e r e t h r o u g h _ _ e n d _ S Y S E N T E R _ s i n g l e s t e p _ r e g i o n i s s u b j e c t
* to b e i n g s i n g l e - s t e p p e d i f a u s e r p r o g r a m s e t s T F a n d e x e c u t e s S Y S E N T E R .
* There i s a b s o l u t e l y n o t h i n g t h a t w e c a n d o t o p r e v e n t t h i s f r o m h a p p e n i n g
* ( thanks I n t e l ! ) . T o k e e p o u r h a n d l i n g o f t h i s s i t u a t i o n a s s i m p l e a s
* possible, w e h a n d l e T F j u s t l i k e A C a n d N T , e x c e p t t h a t o u r #D B h a n d l e r
* will i g n o r e a l l o f t h e s i n g l e - s t e p t r a p s g e n e r a t e d i n t h i s r a n g e .
* /
2018-08-28 09:40:12 +02:00
# ifdef C O N F I G _ X E N _ P V
2016-03-09 19:00:30 -08:00
/ *
* Xen d o e s n ' t s e t % e s p t o b e p r e c i s e l y w h a t t h e n o r m a l S Y S E N T E R
* entry p o i n t e x p e c t s , s o f i x i t u p b e f o r e u s i n g t h e n o r m a l p a t h .
* /
2019-10-11 13:51:05 +02:00
SYM_ C O D E _ S T A R T ( x e n _ s y s e n t e r _ t a r g e t )
2016-03-09 19:00:30 -08:00
addl $ 5 * 4 , % e s p / * r e m o v e x e n - p r o v i d e d f r a m e * /
2016-09-21 16:03:59 -05:00
jmp . L s y s e n t e r _ p a s t _ e s p
2019-10-11 13:51:05 +02:00
SYM_ C O D E _ E N D ( x e n _ s y s e n t e r _ t a r g e t )
2016-03-09 19:00:30 -08:00
# endif
2016-03-09 19:00:35 -08:00
/ *
* 3 2 - bit S Y S E N T E R e n t r y .
*
* 3 2 - bit s y s t e m c a l l s t h r o u g h t h e v D S O ' s _ _ k e r n e l _ v s y s c a l l e n t e r h e r e
* if X 8 6 _ F E A T U R E _ S E P i s a v a i l a b l e . T h i s i s t h e p r e f e r r e d s y s t e m c a l l
* entry o n 3 2 - b i t s y s t e m s .
*
* The S Y S E N T E R i n s t r u c t i o n , i n p r i n c i p l e , s h o u l d * o n l y * o c c u r i n t h e
* vDSO. I n p r a c t i c e , a s m a l l n u m b e r o f A n d r o i d d e v i c e s w e r e s h i p p e d
* with a c o p y o f B i o n i c t h a t i n l i n e d a S Y S E N T E R i n s t r u c t i o n . T h i s
* never h a p p e n e d i n a n y o f G o o g l e ' s B i o n i c v e r s i o n s - - i t o n l y h a p p e n e d
* in a n a r r o w r a n g e o f I n t e l - p r o v i d e d v e r s i o n s .
*
* SYSENTER l o a d s S S , E S P , C S , a n d E I P f r o m p r e v i o u s l y p r o g r a m m e d M S R s .
* IF a n d V M i n R F L A G S a r e c l e a r e d ( I O W : i n t e r r u p t s a r e o f f ) .
* SYSENTER d o e s n o t s a v e a n y t h i n g o n t h e s t a c k ,
* and d o e s n o t s a v e o l d E I P ( ! ! ! ) , E S P , o r E F L A G S .
*
* To a v o i d l o s i n g t r a c k o f E F L A G S . V M ( a n d t h u s p o t e n t i a l l y c o r r u p t i n g
* user a n d / o r v m 8 6 s t a t e ) , w e e x p l i c i t l y d i s a b l e t h e S Y S E N T E R
* instruction i n v m 8 6 m o d e b y r e p r o g r a m m i n g t h e M S R s .
*
* Arguments :
* eax s y s t e m c a l l n u m b e r
* ebx a r g 1
* ecx a r g 2
* edx a r g 3
* esi a r g 4
* edi a r g 5
* ebp u s e r s t a c k
* 0 ( % ebp) a r g 6
* /
2019-10-11 13:51:07 +02:00
SYM_ F U N C _ S T A R T ( e n t r y _ S Y S E N T E R _ 3 2 )
2018-07-18 11:40:49 +02:00
/ *
* On e n t r y - s t a c k w i t h a l l u s e r s p a c e - r e g s l i v e - s a v e a n d
* restore e f l a g s a n d % e a x t o u s e i t a s s c r a t c h - r e g f o r t h e c r3
* switch.
* /
pushfl
pushl % e a x
2018-07-18 11:41:16 +02:00
BUG_ I F _ W R O N G _ C R 3 n o _ u s e r _ c h e c k =1
2018-07-18 11:40:49 +02:00
SWITCH_ T O _ K E R N E L _ C R 3 s c r a t c h _ r e g = % e a x
popl % e a x
popfl
/* Stack empty again, switch to task stack */
2018-07-18 11:40:39 +02:00
movl T S S _ e n t r y 2 t a s k _ s t a c k ( % e s p ) , % e s p
2018-07-18 11:40:49 +02:00
2016-09-21 16:03:59 -05:00
.Lsysenter_past_esp :
2015-10-05 17:48:15 -07:00
pushl $ _ _ U S E R _ D S / * p t _ r e g s - > s s * /
2015-12-16 23:18:48 -08:00
pushl % e b p / * p t _ r e g s - > s p ( s t a s h e d i n b p ) * /
2015-10-05 17:48:15 -07:00
pushfl / * p t _ r e g s - > f l a g s ( e x c e p t I F = 0 ) * /
orl $ X 8 6 _ E F L A G S _ I F , ( % e s p ) / * F i x I F * /
pushl $ _ _ U S E R _ C S / * p t _ r e g s - > c s * /
pushl $ 0 / * p t _ r e g s - > i p = 0 ( p l a c e h o l d e r ) * /
pushl % e a x / * p t _ r e g s - > o r i g _ a x * /
2018-07-18 11:40:44 +02:00
SAVE_ A L L p t _ r e g s _ a x = $ - E N O S Y S / * s a v e r e s t , s t a c k a l r e a d y s w i t c h e d * /
2015-10-05 17:48:15 -07:00
2016-03-09 19:00:26 -08:00
/ *
2016-03-09 19:00:30 -08:00
* SYSENTER d o e s n ' t f i l t e r f l a g s , s o w e n e e d t o c l e a r N T , A C
* and T F o u r s e l v e s . T o s a v e a f e w c y c l e s , w e c a n c h e c k w h e t h e r
2016-03-09 19:00:26 -08:00
* either w a s s e t i n s t e a d o f d o i n g a n u n c o n d i t i o n a l p o p f q .
* This n e e d s t o h a p p e n b e f o r e e n a b l i n g i n t e r r u p t s s o t h a t
* we d o n ' t g e t p r e e m p t e d w i t h N T s e t .
*
2016-03-09 19:00:30 -08:00
* If T F i s s e t , w e w i l l s i n g l e - s t e p a l l t h e w a y t o h e r e - - d o _ d e b u g
* will i g n o r e a l l t h e t r a p s . ( Y e s , t h i s i s s l o w , b u t s o i s
* single- s t e p p i n g i n g e n e r a l . T h i s a l l o w s u s t o a v o i d h a v i n g
* a m o r e c o m p l i c a t e d c o d e t o h a n d l e t h e c a s e w h e r e a u s e r p r o g r a m
* forces u s t o s i n g l e - s t e p t h r o u g h t h e S Y S E N T E R e n t r y c o d e . )
*
2016-03-09 19:00:26 -08:00
* NB. : . L s y s e n t e r _ f i x _ f l a g s i s a l a b e l w i t h t h e c o d e u n d e r i t m o v e d
* out- o f - l i n e a s a n o p t i m i z a t i o n : N T i s u n l i k e l y t o b e s e t i n t h e
* majority o f t h e c a s e s a n d i n s t e a d o f p o l l u t i n g t h e I $ u n n e c e s s a r i l y ,
* we' r e k e e p i n g t h a t c o d e b e h i n d a b r a n c h w h i c h w i l l p r e d i c t a s
* not- t a k e n a n d t h e r e f o r e i t s i n s t r u c t i o n s w o n ' t b e f e t c h e d .
* /
2016-03-09 19:00:30 -08:00
testl $ X 8 6 _ E F L A G S _ N T | X 8 6 _ E F L A G S _ A C | X 8 6 _ E F L A G S _ T F , P T _ E F L A G S ( % e s p )
2016-03-09 19:00:26 -08:00
jnz . L s y s e n t e r _ f i x _ f l a g s
.Lsysenter_flags_fixed :
2015-10-05 17:48:15 -07:00
movl % e s p , % e a x
call d o _ f a s t _ s y s c a l l _ 3 2
2015-11-19 16:55:45 -05:00
/* XEN PV guests always use IRET path */
ALTERNATIVE " t e s t l % e a x , % e a x ; jz .Lsyscall_32_done", \
" jmp . L s y s c a l l _ 3 2 _ d o n e " , X 8 6 _ F E A T U R E _ X E N P V
2015-10-05 17:48:15 -07:00
2018-08-17 01:16:58 +03:00
STACKLEAK_ E R A S E
2020-03-04 12:51:59 +01:00
/* Opportunistic SYSEXIT */
2018-07-18 11:40:45 +02:00
/ *
* Setup e n t r y s t a c k - w e k e e p t h e p o i n t e r i n % e a x a n d d o t h e
* switch a f t e r a l m o s t a l l u s e r - s t a t e i s r e s t o r e d .
* /
/* Load entry stack pointer and allocate frame for eflags/eax */
movl P E R _ C P U _ V A R ( c p u _ t s s _ r w + T S S _ s p0 ) , % e a x
subl $ ( 2 * 4 ) , % e a x
/* Copy eflags and eax to entry stack */
movl P T _ E F L A G S ( % e s p ) , % e d i
movl P T _ E A X ( % e s p ) , % e s i
movl % e d i , ( % e a x )
movl % e s i , 4 ( % e a x )
/* Restore user registers and segments */
2015-10-05 17:48:15 -07:00
movl P T _ E I P ( % e s p ) , % e d x / * p t _ r e g s - > i p * /
movl P T _ O L D E S P ( % e s p ) , % e c x / * p t _ r e g s - > s p * /
2015-10-16 15:42:55 -07:00
1 : mov P T _ F S ( % e s p ) , % f s
PTGS_ T O _ G S
2018-07-18 11:40:45 +02:00
2015-10-05 17:48:15 -07:00
popl % e b x / * p t _ r e g s - > b x * /
addl $ 2 * 4 , % e s p / * s k i p p t _ r e g s - > c x a n d p t _ r e g s - > d x * /
popl % e s i / * p t _ r e g s - > s i * /
popl % e d i / * p t _ r e g s - > d i * /
popl % e b p / * p t _ r e g s - > b p * /
2018-07-18 11:40:45 +02:00
/* Switch to entry stack */
movl % e a x , % e s p
2015-10-05 17:48:15 -07:00
2018-07-18 11:40:49 +02:00
/* Now ready to switch the cr3 */
SWITCH_ T O _ U S E R _ C R 3 s c r a t c h _ r e g = % e a x
2016-03-09 19:00:27 -08:00
/ *
* Restore a l l f l a g s e x c e p t I F . ( W e r e s t o r e I F s e p a r a t e l y b e c a u s e
* STI g i v e s a o n e - i n s t r u c t i o n w i n d o w i n w h i c h w e w o n ' t b e i n t e r r u p t e d ,
* whereas P O P F d o e s n o t . )
* /
2018-06-25 04:21:59 -06:00
btrl $ X 8 6 _ E F L A G S _ I F _ B I T , ( % e s p )
2018-07-18 11:41:16 +02:00
BUG_ I F _ W R O N G _ C R 3 n o _ u s e r _ c h e c k =1
2016-03-09 19:00:27 -08:00
popfl
2018-07-18 11:40:45 +02:00
popl % e a x
2016-03-09 19:00:27 -08:00
2015-10-05 17:48:15 -07:00
/ *
* Return b a c k t o t h e v D S O , w h i c h w i l l p o p e c x a n d e d x .
* Don' t b o t h e r w i t h D S a n d E S ( t h e y a l r e a d y c o n t a i n _ _ U S E R _ D S ) .
* /
2015-11-19 16:55:46 -05:00
sti
sysexit
2008-06-24 04:16:52 -07:00
2015-06-08 09:49:11 +02:00
.pushsection .fixup , " ax"
2 : movl $ 0 , P T _ F S ( % e s p )
jmp 1 b
[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 02:14:02 +01:00
.popsection
2015-06-08 09:49:11 +02:00
_ ASM_ E X T A B L E ( 1 b , 2 b )
2009-02-09 22:17:40 +09:00
PTGS_ T O _ G S _ E X
2016-03-09 19:00:26 -08:00
.Lsysenter_fix_flags :
pushl $ X 8 6 _ E F L A G S _ F I X E D
popfl
jmp . L s y s e n t e r _ f l a g s _ f i x e d
2019-10-11 13:50:59 +02:00
SYM_ E N T R Y ( _ _ e n d _ S Y S E N T E R _ s i n g l e s t e p _ r e g i o n , S Y M _ L _ G L O B A L , S Y M _ A _ N O N E )
2019-10-11 13:51:07 +02:00
SYM_ F U N C _ E N D ( e n t r y _ S Y S E N T E R _ 3 2 )
2005-04-16 15:20:36 -07:00
2016-03-09 19:00:35 -08:00
/ *
* 3 2 - bit l e g a c y s y s t e m c a l l e n t r y .
*
* 3 2 - bit x86 L i n u x s y s t e m c a l l s t r a d i t i o n a l l y u s e d t h e I N T $ 0 x80
* instruction. I N T $ 0 x80 l a n d s h e r e .
*
* This e n t r y p o i n t c a n b e u s e d b y a n y 3 2 - b i t p e r f o r m s y s t e m c a l l s .
* Instances o f I N T $ 0 x80 c a n b e f o u n d i n l i n e i n v a r i o u s p r o g r a m s a n d
* libraries. I t i s a l s o u s e d b y t h e v D S O ' s _ _ k e r n e l _ v s y s c a l l
* fallback f o r h a r d w a r e t h a t d o e s n ' t s u p p o r t a f a s t e r e n t r y m e t h o d .
* Restarted 3 2 - b i t s y s t e m c a l l s a l s o f a l l b a c k t o I N T $ 0 x80
* regardless o f w h a t i n s t r u c t i o n w a s o r i g i n a l l y u s e d t o d o t h e s y s t e m
* call. ( 6 4 - b i t p r o g r a m s c a n u s e I N T $ 0 x80 a s w e l l , b u t t h e y c a n
* only r u n o n 6 4 - b i t k e r n e l s a n d t h e r e f o r e l a n d i n
* entry_ I N T 8 0 _ c o m p a t . )
*
* This i s c o n s i d e r e d a s l o w p a t h . I t i s n o t u s e d b y m o s t l i b c
* implementations o n m o d e r n h a r d w a r e e x c e p t d u r i n g p r o c e s s s t a r t u p .
*
* Arguments :
* eax s y s t e m c a l l n u m b e r
* ebx a r g 1
* ecx a r g 2
* edx a r g 3
* esi a r g 4
* edi a r g 5
* ebp a r g 6
* /
2019-10-11 13:51:07 +02:00
SYM_ F U N C _ S T A R T ( e n t r y _ I N T 8 0 _ 3 2 )
2012-09-21 13:58:10 -07:00
ASM_ C L A C
2015-10-05 17:48:14 -07:00
pushl % e a x / * p t _ r e g s - > o r i g _ a x * /
2018-07-18 11:40:44 +02:00
SAVE_ A L L p t _ r e g s _ a x = $ - E N O S Y S s w i t c h _ s t a c k s =1 / * s a v e r e s t * /
2015-10-05 17:48:14 -07:00
movl % e s p , % e a x
2016-03-09 13:24:32 -08:00
call d o _ i n t 8 0 _ s y s c a l l _ 3 2
2015-10-05 17:48:15 -07:00
.Lsyscall_32_done :
2018-08-17 01:16:58 +03:00
STACKLEAK_ E R A S E
2020-03-04 12:51:59 +01:00
restore_all_switch_stack :
2018-07-18 11:40:45 +02:00
SWITCH_ T O _ E N T R Y _ S T A C K
2018-07-18 11:40:41 +02:00
CHECK_ A N D _ A P P L Y _ E S P F I X
2020-03-08 23:24:02 +01:00
2018-07-18 11:40:49 +02:00
/* Switch back to user CR3 */
SWITCH_ T O _ U S E R _ C R 3 s c r a t c h _ r e g = % e a x
2018-07-18 11:41:16 +02:00
BUG_ I F _ W R O N G _ C R 3
2018-07-18 11:40:49 +02:00
/* Restore user state */
RESTORE_ R E G S p o p =4 # s k i p o r i g _ e a x / e r r o r _ c o d e
2016-09-21 16:03:59 -05: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-29 15:20:18 -05:00
/ *
* ARCH_ H A S _ M E M B A R R I E R _ S Y N C _ C O R E r e l y o n I R E T c o r e s e r i a l i z a t i o n
* when r e t u r n i n g f r o m I P I h a n d l e r a n d w h e n r e t u r n i n g f r o m
* scheduler t o u s e r - s p a c e .
* /
2008-02-09 23:24:08 +01:00
INTERRUPT_ R E T U R N
2016-09-21 16:03:59 -05:00
2018-07-18 11:40:43 +02:00
restore_all_kernel :
2019-07-26 23:19:42 +02:00
# ifdef C O N F I G _ P R E E M P T I O N
2019-05-07 23:25:54 +02:00
DISABLE_ I N T E R R U P T S ( C L B R _ A N Y )
cmpl $ 0 , P E R _ C P U _ V A R ( _ _ p r e e m p t _ c o u n t )
jnz . L n o _ p r e e m p t
testl $ X 8 6 _ E F L A G S _ I F , P T _ E F L A G S ( % e s p ) # i n t e r r u p t s o f f ( e x c e p t i o n p a t h ) ?
jz . L n o _ p r e e m p t
call p r e e m p t _ s c h e d u l e _ i r q
.Lno_preempt :
# endif
2018-07-18 11:40:43 +02:00
TRACE_ I R Q S _ I R E T
2018-07-18 11:40:47 +02:00
PARANOID_ E X I T _ T O _ K E R N E L _ M O D E
2018-07-18 11:41:16 +02:00
BUG_ I F _ W R O N G _ C R 3
2018-07-18 11:40:43 +02:00
RESTORE_ R E G S 4
jmp . L i r q _ r e t u r n
2015-06-08 09:49:11 +02:00
.section .fixup , " ax"
2020-02-25 23:16:30 +01:00
SYM_ C O D E _ S T A R T ( a s m _ i r e t _ e r r o r )
2015-06-08 09:49:11 +02:00
pushl $ 0 # n o e r r o r c o d e
2020-02-25 23:16:30 +01:00
pushl $ i r e t _ e r r o r
2018-07-18 11:41:16 +02:00
# ifdef C O N F I G _ D E B U G _ E N T R Y
/ *
* The s t a c k - f r a m e h e r e i s t h e o n e t h a t i r e t f a u l t e d o n , s o i t s a
* return- t o - u s e r f r a m e . W e a r e o n k e r n e l - c r3 b e c a u s e w e c o m e h e r e f r o m
* the f i x u p c o d e . T h i s c o n f u s e s t h e C R 3 c h e c k e r , s o s w i t c h t o u s e r - c r3
* as t h e c h e c k e r e x p e c t s i t .
* /
pushl % e a x
SWITCH_ T O _ U S E R _ C R 3 s c r a t c h _ r e g = % e a x
popl % e a x
# endif
2020-02-25 23:16:30 +01:00
jmp h a n d l e _ e x c e p t i o n
SYM_ C O D E _ E N D ( a s m _ i r e t _ e r r o r )
2005-04-16 15:20:36 -07:00
.previous
2020-02-25 23:16:30 +01:00
_ ASM_ E X T A B L E ( . L i r q _ r e t u r n , a s m _ i r e t _ e r r o r )
2019-10-11 13:51:07 +02:00
SYM_ F U N C _ E N D ( e n t r y _ I N T 8 0 _ 3 2 )
2005-04-16 15:20:36 -07:00
2009-02-09 22:17:40 +09: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 00:35:58 +02:00
/ *
* Switch b a c k f o r E S P F I X s t a c k t o t h e n o r m a l z e r o b a s e d s t a c k
*
* We c a n ' t c a l l C f u n c t i o n s u s i n g t h e E S P F I X s t a c k . T h i s c o d e r e a d s
* the h i g h w o r d o f t h e s e g m e n t b a s e f r o m t h e G D T a n d s w i c h e s t o t h e
* normal s t a c k a n d a d j u s t s E S P w i t h t h e m a t c h i n g o f f s e t .
2019-11-24 08:50:03 -08:00
*
* We m i g h t b e o n u s e r C R 3 h e r e , s o p e r c p u d a t a i s n o t m a p p e d a n d w e c a n ' t
* access t h e G D T t h r o u g h t h e p e r c p u s e g m e n t . I n s t e a d , u s e S G D T t o f i n d
* the c p u _ e n t r y _ a r e a a l i a s o f t h e G D T .
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 00:35:58 +02:00
* /
2014-05-04 10:36:22 -07:00
# ifdef C O N F I G _ X 8 6 _ E S P F I X 3 2
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 00:35:58 +02:00
/* fixup the stack */
2019-11-24 08:50:03 -08:00
pushl % e c x
subl $ 2 * 4 , % e s p
sgdt ( % e s p )
movl 2 ( % e s p ) , % e c x / * G D T a d d r e s s * /
/ *
* Careful : ECX i s a l i n e a r p o i n t e r , s o w e n e e d t o f o r c e b a s e
* zero. % c s i s t h e o n l y k n o w n - l i n e a r s e g m e n t w e h a v e r i g h t n o w .
* /
mov % c s : G D T _ E S P F I X _ O F F S E T + 4 ( % e c x ) , % a l / * b i t s 1 6 . . 2 3 * /
mov % c s : G D T _ E S P F I X _ O F F S E T + 7 ( % e c x ) , % a h / * b i t s 2 4 . . 3 1 * /
2015-06-08 22:35:33 +02:00
shl $ 1 6 , % e a x
2019-11-24 08:50:03 -08:00
addl $ 2 * 4 , % e s p
popl % e c x
2015-06-08 09:49:11 +02:00
addl % e s p , % e a x / * t h e a d j u s t e d s t a c k p o i n t e r * /
pushl $ _ _ K E R N E L _ D S
pushl % e a x
lss ( % e s p ) , % e s p / * s w i t c h t o t h e n o r m a l s t a c k s e g m e n t * /
2014-05-04 10:36:22 -07:00
# endif
2009-02-09 22:17:40 +09:00
.endm
2019-11-20 10:10:49 +01:00
2009-02-09 22:17:40 +09:00
.macro UNWIND_ESPFIX_STACK
2019-11-20 10:10:49 +01:00
/* It's safe to clobber %eax, all other regs need to be preserved */
2014-05-04 10:36:22 -07:00
# ifdef C O N F I G _ X 8 6 _ E S P F I X 3 2
2015-06-08 09:49:11 +02:00
movl % s s , % e a x
2009-02-09 22:17:40 +09:00
/* see if on espfix stack */
2015-06-08 09:49:11 +02:00
cmpw $ _ _ E S P F I X _ S S , % a x
2019-11-20 10:10:49 +01:00
jne . L n o _ f i x u p _ \ @
2009-02-09 22:17:40 +09:00
/* switch to normal stack */
FIXUP_ E S P F I X _ S T A C K
2019-11-20 10:10:49 +01:00
.Lno_fixup_ \ @:
2014-05-04 10:36:22 -07:00
# endif
2009-02-09 22:17:40 +09:00
.endm
2005-04-16 15:20:36 -07:00
/ *
2015-04-03 21:49:13 +02:00
* Build t h e e n t r y s t u b s w i t h s o m e a s s e m b l e r m a g i c .
* We p a c k 1 s t u b i n t o e v e r y 8 - b y t e b l o c k .
2005-04-16 15:20:36 -07:00
* /
2015-04-03 21:49:13 +02:00
.align 8
2019-10-11 13:51:06 +02:00
SYM_ C O D E _ S T A R T ( i r q _ e n t r i e s _ s t a r t )
2015-04-03 21:49:13 +02:00
vector=FIRST_EXTERNAL_VECTOR
.rept ( FIRST_ S Y S T E M _ V E C T O R - F I R S T _ E X T E R N A L _ V E C T O R )
2015-06-08 09:49:11 +02:00
pushl $ ( ~ v e c t o r + 0 x80 ) / * N o t e : a l w a y s i n s i g n e d b y t e r a n g e * /
2015-04-03 21:49:13 +02:00
vector=vector + 1
jmp c o m m o n _ i n t e r r u p t
.align 8
.endr
2019-10-11 13:51:06 +02:00
SYM_ C O D E _ E N D ( i r q _ e n t r i e s _ s t a r t )
2007-02-13 13:26:24 +01:00
2019-06-28 13:11:54 +02:00
# ifdef C O N F I G _ X 8 6 _ L O C A L _ A P I C
.align 8
2019-10-11 13:51:06 +02:00
SYM_ C O D E _ S T A R T ( s p u r i o u s _ e n t r i e s _ s t a r t )
2019-06-28 13:11:54 +02:00
vector=FIRST_SYSTEM_VECTOR
.rept ( NR_ V E C T O R S - F I R S T _ S Y S T E M _ V E C T O R )
pushl $ ( ~ v e c t o r + 0 x80 ) / * N o t e : a l w a y s i n s i g n e d b y t e r a n g e * /
vector=vector + 1
jmp c o m m o n _ s p u r i o u s
.align 8
.endr
2019-10-11 13:51:06 +02:00
SYM_ C O D E _ E N D ( s p u r i o u s _ e n t r i e s _ s t a r t )
2019-06-28 13:11:54 +02:00
2019-10-11 13:50:50 +02:00
SYM_ C O D E _ S T A R T _ L O C A L ( c o m m o n _ s p u r i o u s )
2019-06-28 13:11:54 +02:00
ASM_ C L A C
addl $ - 0 x80 , ( % e s p ) / * A d j u s t v e c t o r i n t o t h e [ - 2 5 6 , - 1 ] r a n g e * /
SAVE_ A L L s w i t c h _ s t a c k s =1
ENCODE_ F R A M E _ P O I N T E R
TRACE_ I R Q S _ O F F
movl % e s p , % e a x
call s m p _ s p u r i o u s _ i n t e r r u p t
jmp r e t _ f r o m _ i n t r
2019-10-11 13:50:50 +02:00
SYM_ C O D E _ E N D ( c o m m o n _ s p u r i o u s )
2019-06-28 13:11:54 +02:00
# endif
2006-07-03 00:24:43 -07:00
/ *
* the C P U a u t o m a t i c a l l y d i s a b l e s i n t e r r u p t s w h e n e x e c u t i n g a n I R Q v e c t o r ,
* so I R Q - f l a g s t r a c i n g h a s t o f o l l o w t h a t :
* /
2008-11-11 13:24:58 -08:00
.p2align CONFIG_X86_L1_CACHE_SHIFT
2019-10-11 13:50:50 +02:00
SYM_ C O D E _ S T A R T _ L O C A L ( c o m m o n _ i n t e r r u p t )
2012-09-21 13:58:10 -07:00
ASM_ C L A C
2015-06-08 09:49:11 +02:00
addl $ - 0 x80 , ( % e s p ) / * A d j u s t v e c t o r i n t o t h e [ - 2 5 6 , - 1 ] r a n g e * /
2018-07-18 11:40:44 +02:00
SAVE_ A L L s w i t c h _ s t a c k s =1
2016-10-20 11:34:40 -05:00
ENCODE_ F R A M E _ P O I N T E R
2006-07-03 00:24:43 -07:00
TRACE_ I R Q S _ O F F
2015-06-08 09:49:11 +02:00
movl % e s p , % e a x
call d o _ I R Q
jmp r e t _ f r o m _ i n t r
2019-10-11 13:50:50 +02:00
SYM_ C O D E _ E N D ( c o m m o n _ i n t e r r u p t )
2005-04-16 15:20:36 -07:00
2018-07-18 11:40:44 +02:00
# define B U I L D _ I N T E R R U P T 3 ( n a m e , n r , f n ) \
2019-10-11 13:51:07 +02:00
SYM_ F U N C _ S T A R T ( n a m e ) \
2018-07-18 11:40:44 +02:00
ASM_ C L A C ; \
pushl $ ~ ( n r ) ; \
SAVE_ A L L s w i t c h _ s t a c k s =1 ; \
ENCODE_ F R A M E _ P O I N T E R ; \
TRACE_ I R Q S _ O F F \
movl % e s p , % e a x ; \
call f n ; \
jmp r e t _ f r o m _ i n t r ; \
2019-10-11 13:51:07 +02:00
SYM_ F U N C _ E N D ( n a m e )
2005-04-16 15:20:36 -07:00
2015-06-08 09:49:11 +02:00
# define B U I L D _ I N T E R R U P T ( n a m e , n r ) \
BUILD_ I N T E R R U P T 3 ( n a m e , n r , s m p _ ## n a m e ) ; \
2009-01-21 17:26:06 +09:00
2005-04-16 15:20:36 -07:00
/* The include is where all of the SMP etc. interrupts come from */
2009-01-28 19:34:09 +01:00
# include < a s m / e n t r y _ a r c h . h >
2005-04-16 15:20:36 -07:00
2006-12-07 02:14:07 +01:00
# ifdef C O N F I G _ P A R A V I R T
2019-10-11 13:51:06 +02:00
SYM_ C O D E _ S T A R T ( n a t i v e _ i r e t )
2008-02-09 23:24:08 +01:00
iret
2020-02-25 23:16:30 +01:00
_ ASM_ E X T A B L E ( n a t i v e _ i r e t , a s m _ i r e t _ e r r o r )
2019-10-11 13:51:06 +02:00
SYM_ C O D E _ E N D ( n a t i v e _ i r e t )
2006-12-07 02:14:07 +01:00
# endif
2005-04-16 15:20:36 -07:00
2018-08-28 09:40:12 +02:00
# ifdef C O N F I G _ X E N _ P V
2019-10-11 13:51:07 +02:00
SYM_ F U N C _ S T A R T ( x e n _ h y p e r v i s o r _ c a l l b a c k )
2015-06-08 09:49:11 +02:00
/ *
* Check t o s e e i f w e g o t t h e e v e n t i n t h e c r i t i c a l
* region i n x e n _ i r e t _ d i r e c t , a f t e r w e ' v e r e e n a b l e d
* events a n d c h e c k e d f o r p e n d i n g e v e n t s . T h i s s i m u l a t e s
* iret i n s t r u c t i o n ' s b e h a v i o u r w h e r e i t d e l i v e r s a
* pending i n t e r r u p t w h e n e n a b l i n g i n t e r r u p t s :
* /
2019-11-11 15:32:12 +01:00
cmpl $ x e n _ i r e t _ s t a r t _ c r i t , ( % e s p )
2015-06-08 09:49:11 +02:00
jb 1 f
2019-11-11 15:32:12 +01:00
cmpl $ x e n _ i r e t _ e n d _ c r i t , ( % e s p )
2015-06-08 09:49:11 +02:00
jae 1 f
2019-11-11 15:32:12 +01:00
call x e n _ i r e t _ c r i t _ f i x u p
1 :
pushl $ - 1 / * o r i g _ a x = - 1 = > n o t a s y s t e m c a l l * /
SAVE_ A L L
ENCODE_ F R A M E _ P O I N T E R
TRACE_ I R Q S _ O F F
mov % e s p , % e a x
2015-06-08 09:49:11 +02:00
call x e n _ e v t c h n _ d o _ u p c a l l
2019-07-26 23:19:42 +02:00
# ifndef C O N F I G _ P R E E M P T I O N
2015-06-08 09:49:11 +02:00
call x e n _ m a y b e _ p r e e m p t _ h c a l l
2015-02-19 15:23:17 +00:00
# endif
2015-06-08 09:49:11 +02:00
jmp r e t _ f r o m _ i n t r
2019-10-11 13:51:07 +02:00
SYM_ F U N C _ E N D ( x e n _ h y p e r v i s o r _ c a l l b a c k )
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-17 18:37:04 -07:00
2015-06-08 09:49:11 +02:00
/ *
* Hypervisor u s e s t h i s f o r a p p l i c a t i o n f a u l t s w h i l e i t e x e c u t e s .
* We g e t h e r e f o r t w o r e a s o n s :
* 1 . Fault w h i l e r e l o a d i n g D S , E S , F S o r G S
* 2 . Fault w h i l e e x e c u t i n g I R E T
* Category 1 w e f i x u p b y r e a t t e m p t i n g t h e l o a d , a n d z e r o i n g t h e s e g m e n t
* register i f t h e l o a d f a i l s .
* Category 2 w e f i x u p b y j u m p i n g t o d o _ i r e t _ e r r o r . W e c a n n o t u s e t h e
* normal L i n u x r e t u r n p a t h i n t h i s c a s e b e c a u s e i f w e u s e t h e I R E T h y p e r c a l l
* to p o p t h e s t a c k f r a m e w e e n d u p i n a n i n f i n i t e l o o p o f f a i l s a f e c a l l b a c k s .
* We d i s t i n g u i s h b e t w e e n c a t e g o r i e s b y m a i n t a i n i n g a s t a t u s v a l u e i n E A X .
* /
2019-10-11 13:51:07 +02:00
SYM_ F U N C _ S T A R T ( x e n _ f a i l s a f e _ c a l l b a c k )
2015-06-08 09:49:11 +02:00
pushl % e a x
movl $ 1 , % e a x
1 : mov 4 ( % e s p ) , % d s
2 : mov 8 ( % e s p ) , % e s
3 : mov 1 2 ( % e s p ) , % f s
4 : mov 1 6 ( % e s p ) , % g s
2012-10-19 17:29:07 +01:00
/ * EAX = = 0 = > C a t e g o r y 1 ( B a d s e g m e n t )
EAX ! = 0 = > C a t e g o r y 2 ( B a d I R E T ) * /
2015-06-08 09:49:11 +02:00
testl % e a x , % e a x
popl % e a x
lea 1 6 ( % e s p ) , % e s p
jz 5 f
2020-02-25 23:16:30 +01:00
jmp a s m _ i r e t _ e r r o r
2015-06-08 09:49:11 +02:00
5 : pushl $ - 1 / * o r i g _ a x = - 1 = > n o t a s y s t e m c a l l * /
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-17 18:37:04 -07:00
SAVE_ A L L
2016-10-20 11:34:40 -05:00
ENCODE_ F R A M E _ P O I N T E R
2015-06-08 09:49:11 +02:00
jmp r e t _ f r o m _ e x c e p t i o n
.section .fixup , " ax"
6 : xorl % e a x , % e a x
movl % e a x , 4 ( % e s p )
jmp 1 b
7 : xorl % e a x , % e a x
movl % e a x , 8 ( % e s p )
jmp 2 b
8 : xorl % e a x , % e a x
movl % e a x , 1 2 ( % e s p )
jmp 3 b
9 : xorl % e a x , % e a x
movl % e a x , 1 6 ( % e s p )
jmp 4 b
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-17 18:37:04 -07:00
.previous
2015-06-08 09:49:11 +02:00
_ ASM_ E X T A B L E ( 1 b , 6 b )
_ ASM_ E X T A B L E ( 2 b , 7 b )
_ ASM_ E X T A B L E ( 3 b , 8 b )
_ ASM_ E X T A B L E ( 4 b , 9 b )
2019-10-11 13:51:07 +02:00
SYM_ F U N C _ E N D ( x e n _ f a i l s a f e _ c a l l b a c k )
2018-08-28 09:40:12 +02:00
# endif / * C O N F I G _ X E N _ P V * /
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-17 18:37:04 -07:00
2018-08-28 09:40:12 +02:00
# ifdef C O N F I G _ X E N _ P V H V M
2013-02-03 17:22:39 -08:00
BUILD_ I N T E R R U P T 3 ( x e n _ h v m _ c a l l b a c k _ v e c t o r , H Y P E R V I S O R _ C A L L B A C K _ V E C T O R ,
2017-08-28 08:47:31 +02:00
xen_ e v t c h n _ d o _ u p c a l l )
2018-08-28 09:40:12 +02:00
# endif
2010-05-14 12:40:51 +01:00
2013-02-03 17:22:39 -08:00
# if I S _ E N A B L E D ( C O N F I G _ H Y P E R V )
BUILD_ I N T E R R U P T 3 ( h y p e r v _ c a l l b a c k _ v e c t o r , H Y P E R V I S O R _ C A L L B A C K _ V E C T O R ,
2017-08-28 08:47:31 +02:00
hyperv_ v e c t o r _ h a n d l e r )
2013-02-03 17:22:39 -08:00
2018-01-24 14:23:33 +01:00
BUILD_ I N T E R R U P T 3 ( h y p e r v _ r e e n l i g h t e n m e n t _ v e c t o r , H Y P E R V _ R E E N L I G H T E N M E N T _ V E C T O R ,
hyperv_ r e e n l i g h t e n m e n t _ i n t r )
2018-03-04 22:17:18 -07:00
BUILD_ I N T E R R U P T 3 ( h v _ s t i m e r0 _ c a l l b a c k _ v e c t o r , H Y P E R V _ S T I M E R 0 _ V E C T O R ,
hv_ s t i m e r0 _ v e c t o r _ h a n d l e r )
2013-02-03 17:22:39 -08:00
# endif / * C O N F I G _ H Y P E R V * /
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-17 18:37:04 -07:00
2019-10-11 13:51:06 +02:00
SYM_ C O D E _ S T A R T ( p a g e _ f a u l t )
2012-09-21 13:58:10 -07:00
ASM_ C L A C
2019-07-23 21:20:58 -07:00
pushl $ d o _ p a g e _ f a u l t
jmp c o m m o n _ e x c e p t i o n _ r e a d _ c r2
2019-10-11 13:51:06 +02:00
SYM_ C O D E _ E N D ( p a g e _ f a u l t )
2019-07-11 13:40:59 +02:00
2019-10-11 13:50:50 +02:00
SYM_ C O D E _ S T A R T _ L O C A L _ N O A L I G N ( c o m m o n _ e x c e p t i o n _ r e a d _ c r2 )
2019-07-23 21:20:58 -07:00
/* the function address is in %gs's slot on the stack */
2019-11-20 10:10:49 +01:00
SAVE_ A L L s w i t c h _ s t a c k s =1 s k i p _ g s =1 u n w i n d _ e s p f i x =1
2019-07-11 13:40:59 +02:00
ENCODE_ F R A M E _ P O I N T E R
/* fixup %gs */
GS_ T O _ R E G % e c x
2019-07-23 21:20:58 -07:00
movl P T _ G S ( % e s p ) , % e d i
2019-07-11 13:40:59 +02:00
REG_ T O _ P T G S % e c x
SET_ K E R N E L _ G S % e c x
GET_ C R 2 _ I N T O ( % e c x ) # m i g h t c l o b b e r % e a x
/* fixup orig %eax */
movl P T _ O R I G _ E A X ( % e s p ) , % e d x # g e t t h e e r r o r c o d e
movl $ - 1 , P T _ O R I G _ E A X ( % e s p ) # n o s y s c a l l t o r e s t a r t
TRACE_ I R Q S _ O F F
movl % e s p , % e a x # p t _ r e g s p o i n t e r
2020-04-22 17:16:40 +02:00
CALL_ N O S P E C e d i
2019-07-11 13:40:59 +02:00
jmp r e t _ f r o m _ e x c e p t i o n
2019-10-11 13:50:50 +02:00
SYM_ C O D E _ E N D ( c o m m o n _ e x c e p t i o n _ r e a d _ c r2 )
2016-09-21 16:04:00 -05:00
2019-10-11 13:50:50 +02:00
SYM_ C O D E _ S T A R T _ L O C A L _ N O A L I G N ( c o m m o n _ e x c e p t i o n )
2009-02-09 22:17:40 +09:00
/* the function address is in %gs's slot on the stack */
2019-11-20 10:10:49 +01:00
SAVE_ A L L s w i t c h _ s t a c k s =1 s k i p _ g s =1 u n w i n d _ e s p f i x =1
2016-10-20 11:34:40 -05:00
ENCODE_ F R A M E _ P O I N T E R
2019-07-11 13:40:56 +02:00
/* fixup %gs */
2009-02-09 22:17:40 +09:00
GS_ T O _ R E G % e c x
2015-06-08 09:49:11 +02:00
movl P T _ G S ( % e s p ) , % e d i # g e t t h e f u n c t i o n a d d r e s s
2009-02-09 22:17:40 +09:00
REG_ T O _ P T G S % e c x
SET_ K E R N E L _ G S % e c x
2019-07-11 13:40:56 +02:00
/* fixup orig %eax */
movl P T _ O R I G _ E A X ( % e s p ) , % e d x # g e t t h e e r r o r c o d e
movl $ - 1 , P T _ O R I G _ E A X ( % e s p ) # n o s y s c a l l t o r e s t a r t
2008-11-24 15:38:45 +01:00
TRACE_ I R Q S _ O F F
2015-06-08 09:49:11 +02:00
movl % e s p , % e a x # p t _ r e g s p o i n t e r
2020-04-22 17:16:40 +02:00
CALL_ N O S P E C e d i
2015-06-08 09:49:11 +02:00
jmp r e t _ f r o m _ e x c e p t i o n
2019-10-11 13:50:50 +02:00
SYM_ C O D E _ E N D ( c o m m o n _ e x c e p t i o n )
2008-11-24 15:38:45 +01:00
2020-02-25 23:16:11 +01:00
SYM_ C O D E _ S T A R T _ L O C A L _ N O A L I G N ( h a n d l e _ e x c e p t i o n )
/* the function address is in %gs's slot on the stack */
SAVE_ A L L s w i t c h _ s t a c k s =1 s k i p _ g s =1 u n w i n d _ e s p f i x =1
ENCODE_ F R A M E _ P O I N T E R
/* fixup %gs */
GS_ T O _ R E G % e c x
movl P T _ G S ( % e s p ) , % e d i # g e t t h e f u n c t i o n a d d r e s s
REG_ T O _ P T G S % e c x
SET_ K E R N E L _ G S % e c x
/* fixup orig %eax */
movl P T _ O R I G _ E A X ( % e s p ) , % e d x # g e t t h e e r r o r c o d e
movl $ - 1 , P T _ O R I G _ E A X ( % e s p ) # n o s y s c a l l t o r e s t a r t
movl % e s p , % e a x # p t _ r e g s p o i n t e r
CALL_ N O S P E C e d i
# ifdef C O N F I G _ V M 8 6
movl P T _ E F L A G S ( % e s p ) , % e a x # m i x E F L A G S a n d C S
movb P T _ C S ( % e s p ) , % a l
andl $ ( X 8 6 _ E F L A G S _ V M | S E G M E N T _ R P L _ M A S K ) , % e a x
# else
/ *
* We c a n b e c o m i n g h e r e f r o m c h i l d s p a w n e d b y k e r n e l _ t h r e a d ( ) .
* /
movl P T _ C S ( % e s p ) , % e a x
andl $ S E G M E N T _ R P L _ M A S K , % e a x
# endif
cmpl $ U S E R _ R P L , % e a x # r e t u r n i n g t o v 8086 o r u s e r s p a c e ?
jnb r e t _ t o _ u s e r
PARANOID_ E X I T _ T O _ K E R N E L _ M O D E
BUG_ I F _ W R O N G _ C R 3
RESTORE_ R E G S 4
jmp . L i r q _ r e t u r n
ret_to_user :
movl % e s p , % e a x
jmp r e s t o r e _ a l l _ s w i t c h _ s t a c k
SYM_ C O D E _ E N D ( h a n d l e _ e x c e p t i o n )
2019-11-20 23:06:41 -08:00
SYM_ C O D E _ S T A R T ( d o u b l e _ f a u l t )
1 :
/ *
* This i s a t a s k g a t e h a n d l e r , n o t a n i n t e r r u p t g a t e h a n d l e r .
* The e r r o r c o d e i s o n t h e s t a c k , b u t t h e s t a c k i s o t h e r w i s e
* empty. I n t e r r u p t s a r e o f f . O u r s t a t e i s s a n e w i t h t h e f o l l o w i n g
* exceptions :
*
* - CR0 . T S i s s e t . " T S " l i t e r a l l y m e a n s " t a s k s w i t c h e d " .
* - EFLAGS. N T i s s e t b e c a u s e w e ' r e a " n e s t e d t a s k " .
* - The d o u b l e f a u l t T S S h a s b a c k _ l i n k s e t a n d h a s b e e n m a r k e d b u s y .
* - TR p o i n t s t o t h e d o u b l e f a u l t T S S a n d t h e n o r m a l T S S i s b u s y .
* - CR3 i s t h e n o r m a l k e r n e l P G D . T h i s w o u l d b e d e l i g h t f u l , e x c e p t
* that t h e C P U d i d n ' t b o t h e r t o s a v e t h e o l d C R 3 a n y w h e r e . T h i s
* would m a k e i t v e r y a w k w a r d t o r e t u r n b a c k t o t h e c o n t e x t w e c a m e
* from.
*
* The r e s t o f E F L A G S i s s a n i t i z e d f o r u s , s o w e d o n ' t n e e d t o
* worry a b o u t A C o r D F .
*
* Don' t e v e n b o t h e r p o p p i n g t h e e r r o r c o d e . I t ' s a l w a y s z e r o ,
* and i g n o r i n g i t m a k e s u s a b i t m o r e r o b u s t a g a i n s t b u g g y
* hypervisor t a s k g a t e i m p l e m e n t a t i o n s .
*
* We w i l l m a n u a l l y u n d o t h e t a s k s w i t c h i n s t e a d o f d o i n g a
* task- s w i t c h i n g I R E T .
* /
clts / * c l e a r C R 0 . T S * /
pushl $ X 8 6 _ E F L A G S _ F I X E D
popfl / * c l e a r E F L A G S . N T * /
call d o u b l e f a u l t _ s h i m
/* We don't support returning, so we have no IRET here. */
1 :
hlt
jmp 1 b
SYM_ C O D E _ E N D ( d o u b l e _ f a u l t )
2008-11-24 15:38:45 +01: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-09 19:00:32 -08:00
* NMI i s d o u b l y n a s t y . I t c a n h a p p e n o n t h e f i r s t i n s t r u c t i o n o f
* entry_ S Y S E N T E R _ 3 2 ( j u s t l i k e #D B ) , b u t i t c a n a l s o i n t e r r u p t t h e b e g i n n i n g
* of t h e #D B h a n d l e r e v e n i f t h a t # D B i n t u r n h i t b e f o r e e n t r y _ S Y S E N T E R _ 32
* switched s t a c k s . W e h a n d l e b o t h c o n d i t i o n s b y s i m p l y c h e c k i n g w h e t h e r w e
* interrupted k e r n e l c o d e r u n n i n g o n t h e S Y S E N T E R s t a c k .
2008-11-24 15:38:45 +01:00
* /
2020-02-25 23:33:25 +01:00
SYM_ C O D E _ S T A R T ( a s m _ e x c _ n m i )
2012-09-21 13:58:10 -07:00
ASM_ C L A C
2018-07-18 11:40:44 +02:00
2014-05-04 10:36:22 -07:00
# ifdef C O N F I G _ X 8 6 _ E S P F I X 3 2
2019-11-20 15:02:26 +01:00
/ *
* ESPFIX_ S S i s o n l y e v e r s e t o n t h e r e t u r n t o u s e r p a t h
* after w e ' v e s w i t c h e d t o t h e e n t r y s t a c k .
* /
2015-06-08 09:49:11 +02:00
pushl % e a x
movl % s s , % e a x
cmpw $ _ _ E S P F I X _ S S , % a x
popl % e a x
2016-09-21 16:03:59 -05:00
je . L n m i _ e s p f i x _ s t a c k
2014-05-04 10:36:22 -07: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-09 19:00:32 -08:00
pushl % e a x # p t _ r e g s - > o r i g _ a x
2018-07-18 11:40:50 +02:00
SAVE_ A L L _ N M I c r3 _ r e g = % e d i
2016-10-20 11:34:40 -05:00
ENCODE_ F R A M E _ P O I N T E R
2015-06-08 09:49:11 +02:00
xorl % e d x , % e d x # z e r o e r r o r c o d e
movl % e s p , % e a x # p t _ r e g s p o i n t e r
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-09 19:00:32 -08:00
/* Are we currently on the SYSENTER stack? */
2017-12-04 15:07:20 +01:00
movl P E R _ C P U _ V A R ( c p u _ e n t r y _ a r e a ) , % e c x
2017-12-04 17:25:07 -08:00
addl $ C P U _ E N T R Y _ A R E A _ e n t r y _ s t a c k + S I Z E O F _ e n t r y _ s t a c k , % e c x
subl % e a x , % e c x / * e c x = ( e n d o f e n t r y _ s t a c k ) - e s p * /
cmpl $ S I Z E O F _ e n t r y _ s t a c k , % e c x
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-09 19:00:32 -08:00
jb . L n m i _ f r o m _ s y s e n t e r _ s t a c k
/* Not on SYSENTER stack. */
2020-02-25 23:33:25 +01:00
call e x c _ n m i
2018-07-18 11:40:42 +02:00
jmp . L n m i _ r e t u r n
2008-11-24 15:38:45 +01: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-09 19:00:32 -08:00
.Lnmi_from_sysenter_stack :
/ *
* We' r e o n t h e S Y S E N T E R s t a c k . S w i t c h o f f . N o o n e ( n o t e v e n d e b u g )
* is u s i n g t h e t h r e a d s t a c k r i g h t n o w , s o i t ' s s a f e f o r u s t o u s e i t .
* /
2016-10-20 11:34:40 -05:00
movl % e s p , % e b x
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-09 19:00:32 -08:00
movl P E R _ C P U _ V A R ( c p u _ c u r r e n t _ t o p _ o f _ s t a c k ) , % e s p
2020-02-25 23:33:25 +01:00
call e x c _ n m i
2016-10-20 11:34:40 -05:00
movl % e b x , % e s p
2018-07-18 11:40:42 +02:00
.Lnmi_return :
2019-11-20 15:02:26 +01:00
# ifdef C O N F I G _ X 8 6 _ E S P F I X 3 2
testl $ C S _ F R O M _ E S P F I X , P T _ C S ( % e s p )
jnz . L n m i _ f r o m _ e s p f i x
# endif
2018-07-18 11:40:42 +02:00
CHECK_ A N D _ A P P L Y _ E S P F I X
2018-07-18 11:40:50 +02:00
RESTORE_ A L L _ N M I c r3 _ r e g = % e d i p o p =4
2018-07-18 11:40:42 +02:00
jmp . L i r q _ r e t u r n
2008-11-24 15:38:45 +01:00
2014-05-04 10:36:22 -07:00
# ifdef C O N F I G _ X 8 6 _ E S P F I X 3 2
2016-09-21 16:03:59 -05: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 12:21:47 +02:00
/ *
2019-11-20 15:02:26 +01:00
* Create t h e p o i n t e r t o L S S b a c k
2008-11-24 15:38:45 +01:00
* /
2015-06-08 09:49:11 +02:00
pushl % s s
pushl % e s p
addl $ 4 , ( % e s p )
2019-11-20 15:02:26 +01:00
/* Copy the (short) IRET frame */
pushl 4 * 4 ( % e s p ) # f l a g s
pushl 4 * 4 ( % e s p ) # c s
pushl 4 * 4 ( % e s p ) # i p
pushl % e a x # o r i g _ a x
SAVE_ A L L _ N M I c r3 _ r e g = % e d i u n w i n d _ e s p f i x =1
2016-10-20 11:34:40 -05:00
ENCODE_ F R A M E _ P O I N T E R
2019-11-20 15:02:26 +01:00
/* clear CS_FROM_KERNEL, set CS_FROM_ESPFIX */
xorl $ ( C S _ F R O M _ E S P F I X | C S _ F R O M _ K E R N E L ) , P T _ C S ( % e s p )
2015-06-08 09:49:11 +02:00
xorl % e d x , % e d x # z e r o e r r o r c o d e
2019-11-20 15:02:26 +01:00
movl % e s p , % e a x # p t _ r e g s p o i n t e r
jmp . L n m i _ f r o m _ s y s e n t e r _ s t a c k
.Lnmi_from_espfix :
2018-07-18 11:40:50 +02:00
RESTORE_ A L L _ N M I c r3 _ r e g = % e d i
2019-11-20 15:02:26 +01:00
/ *
* Because w e c l e a r e d C S _ F R O M _ K E R N E L , I R E T _ F R A M E ' f o r g o t ' t o
* fix u p t h e g a p a n d l o n g f r a m e :
*
* 3 - original f r a m e ( e x c e p t i o n )
* 2 - ESPFIX b l o c k ( a b o v e )
* 6 - gap ( F I X U P _ F R A M E )
* 5 - long f r a m e ( F I X U P _ F R A M E )
* 1 - orig_ a x
* /
lss ( 1 + 5 + 6 ) * 4 ( % e s p ) , % e s p # b a c k t o e s p f i x s t a c k
2016-09-21 16:03:59 -05:00
jmp . L i r q _ r e t u r n
2014-05-04 10:36:22 -07:00
# endif
2020-02-25 23:33:25 +01:00
SYM_ C O D E _ E N D ( a s m _ e x c _ n m i )
2008-11-24 15:38:45 +01:00
2020-03-25 19:47:40 +01:00
.pushsection .text , " ax"
2019-10-11 13:51:06 +02:00
SYM_ C O D E _ S T A R T ( r e w i n d _ s t a c k _ d o _ e x i t )
2016-07-14 13:22:55 -07:00
/* Prevent any naive code from trying to unwind to our caller. */
xorl % e b p , % e b p
movl P E R _ C P U _ V A R ( c p u _ c u r r e n t _ t o p _ o f _ s t a c k ) , % e s i
leal - T O P _ O F _ K E R N E L _ S T A C K _ P A D D I N G - P T R E G S _ S I Z E ( % e s i ) , % e s p
call d o _ e x i t
1 : jmp 1 b
2019-10-11 13:51:06 +02:00
SYM_ C O D E _ E N D ( r e w i n d _ s t a c k _ d o _ e x i t )
2020-03-25 19:47:40 +01:00
.popsection