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-01-28 00:16:28 +06:00
* linux/ a r c h / x86 / k e r n e l / h e a d _ 6 4 . S - - s t a r t i n 3 2 b i t a n d s w i t c h t o 6 4 b i t
2005-04-16 15:20:36 -07:00
*
* Copyright ( C ) 2 0 0 0 A n d r e a A r c a n g e l i < a n d r e a @suse.de> SuSE
* Copyright ( C ) 2 0 0 0 P a v e l M a c h e k < p a v e l @suse.cz>
* Copyright ( C ) 2 0 0 0 K a r s t e n K e i l < k k e i l @suse.de>
* Copyright ( C ) 2 0 0 1 ,2 0 0 2 A n d i K l e e n < a k @suse.de>
2007-05-02 19:27:07 +02:00
* Copyright ( C ) 2 0 0 5 E r i c B i e d e r m a n < e b i e d e r m @xmission.com>
2005-04-16 15:20:36 -07:00
* /
# include < l i n u x / l i n k a g e . h >
# include < l i n u x / t h r e a d s . h >
2005-11-05 17:25:53 +01:00
# include < l i n u x / i n i t . h >
2020-06-08 21:32:38 -07:00
# include < l i n u x / p g t a b l e . h >
2020-06-08 21:32:42 -07:00
# include < a s m / s e g m e n t . h >
2005-04-16 15:20:36 -07:00
# include < a s m / p a g e . h >
# include < a s m / m s r . h >
# include < a s m / c a c h e . h >
2008-05-12 15:43:38 +02:00
# include < a s m / p r o c e s s o r - f l a g s . h >
2009-01-13 20:41:35 +09:00
# include < a s m / p e r c p u . h >
2012-04-18 17:16:49 -07:00
# include < a s m / n o p s . h >
2016-04-02 07:01:32 -07:00
# include " . . / e n t r y / c a l l i n g . h "
2016-01-11 11:04:34 -05:00
# include < a s m / e x p o r t . h >
2018-01-16 10:38:09 +01:00
# include < a s m / n o s p e c - b r a n c h . h >
2018-09-20 10:58:28 +08:00
# include < a s m / f i x m a p . h >
2007-05-02 19:27:07 +02:00
2020-05-21 22:05:46 +02:00
/ *
* We a r e n o t a b l e t o s w i t c h i n o n e s t e p t o t h e f i n a l K E R N E L A D D R E S S S P A C E
2007-05-02 19:27:07 +02:00
* because w e n e e d i d e n t i t y - m a p p e d p a g e s .
2005-04-16 15:20:36 -07:00
* /
2018-02-16 14:49:46 +03:00
# define l 4 _ i n d e x ( x ) ( ( ( x ) > > 3 9 ) & 5 1 1 )
2008-06-25 00:19:16 -04:00
# define p u d _ i n d e x ( x ) ( ( ( x ) > > P U D _ S H I F T ) & ( P T R S _ P E R _ P U D - 1 ) )
2018-02-16 14:49:46 +03:00
L4 _ P A G E _ O F F S E T = l 4 _ i n d e x ( _ _ P A G E _ O F F S E T _ B A S E _ L 4 )
L4 _ S T A R T _ K E R N E L = l 4 _ i n d e x ( _ _ S T A R T _ K E R N E L _ m a p )
2008-06-25 00:19:16 -04:00
L3 _ S T A R T _ K E R N E L = p u d _ i n d e x ( _ _ S T A R T _ K E R N E L _ m a p )
2005-04-16 15:20:36 -07:00
.text
2009-09-16 16:44:28 -04:00
_ _ HEAD
2007-05-02 19:27:07 +02:00
.code64
2019-10-11 13:50:56 +02:00
SYM_ C O D E _ S T A R T _ N O A L I G N ( s t a r t u p _ 6 4 )
2017-09-18 21:43:37 -05:00
UNWIND_ H I N T _ E M P T Y
2005-04-16 15:20:36 -07:00
/ *
2013-02-25 15:54:10 -05:00
* At t h i s p o i n t t h e C P U r u n s i n 6 4 b i t m o d e C S . L = 1 C S . D = 0 ,
2007-05-02 19:27:07 +02:00
* and s o m e o n e h a s l o a d e d a n i d e n t i t y m a p p e d p a g e t a b l e
* for u s . T h e s e i d e n t i t y m a p p e d p a g e t a b l e s m a p a l l o f t h e
* kernel p a g e s a n d p o s s i b l y a l l o f m e m o r y .
*
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
* % rsi h o l d s a p h y s i c a l p o i n t e r t o r e a l _ m o d e _ d a t a .
2007-05-02 19:27:07 +02:00
*
* We c o m e h e r e e i t h e r d i r e c t l y f r o m a 6 4 b i t b o o t l o a d e r , o r f r o m
2015-01-28 00:16:28 +06:00
* arch/ x86 / b o o t / c o m p r e s s e d / h e a d _ 6 4 . S .
2007-05-02 19:27:07 +02:00
*
* We o n l y c o m e h e r e i n i t i a l l y a t b o o t n o t h i n g e l s e c o m e s h e r e .
*
* Since w e m a y b e l o a d e d a t a n a d d r e s s d i f f e r e n t f r o m w h a t w e w e r e
* compiled t o r u n a t w e f i r s t f i x u p t h e p h y s i c a l a d d r e s s e s i n o u r p a g e
* tables a n d t h e n r e l o a d t h e m .
2005-04-16 15:20:36 -07:00
* /
2016-09-21 16:04:06 -05:00
/* Set up the stack for verify_cpu(), similar to initial_stack below */
leaq ( _ _ e n d _ i n i t _ t a s k - S I Z E O F _ P T R E G S ) ( % r i p ) , % r s p
2016-03-31 16:21:02 +02:00
2020-09-07 15:15:30 +02:00
leaq _ t e x t ( % r i p ) , % r d i
pushq % r s i
call s t a r t u p _ 6 4 _ s e t u p _ e n v
popq % r s i
/* Now switch to __KERNEL_CS so IRET works reliably */
pushq $ _ _ K E R N E L _ C S
leaq . L o n _ k e r n e l _ c s ( % r i p ) , % r a x
pushq % r a x
lretq
.Lon_kernel_cs :
UNWIND_ H I N T _ E M P T Y
2015-11-05 16:57:56 +01:00
/* Sanitize CPU configuration */
call v e r i f y _ c p u
2017-07-17 16:10:05 -05:00
/ *
* Perform p a g e t a b l e f i x u p s . A d d i t i o n a l l y , i f S M E i s a c t i v e , e n c r y p t
* the k e r n e l a n d r e t r i e v e t h e m o d i f i e r ( S M E e n c r y p t i o n m a s k i f S M E
* is a c t i v e ) t o b e a d d e d t o t h e i n i t i a l p g d i r e n t r y t h a t w i l l b e
* programmed i n t o C R 3 .
* /
2007-05-02 19:27:07 +02:00
leaq _ t e x t ( % r i p ) , % r d i
2017-06-06 14:31:26 +03:00
pushq % r s i
call _ _ s t a r t u p _ 6 4
popq % r s i
2005-04-16 15:20:36 -07:00
2017-07-17 16:10:05 -05:00
/* Form the CR3 value being sure to include the CR3 modifier */
addq $ ( e a r l y _ t o p _ p g t - _ _ S T A R T _ K E R N E L _ m a p ) , % r a x
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
jmp 1 f
2019-10-11 13:50:56 +02:00
SYM_ C O D E _ E N D ( s t a r t u p _ 6 4 )
2019-10-11 13:51:03 +02:00
SYM_ C O D E _ S T A R T ( s e c o n d a r y _ s t a r t u p _ 6 4 )
2017-09-18 21:43:37 -05:00
UNWIND_ H I N T _ E M P T Y
2007-05-02 19:27:07 +02:00
/ *
2013-02-25 15:54:10 -05:00
* At t h i s p o i n t t h e C P U r u n s i n 6 4 b i t m o d e C S . L = 1 C S . D = 0 ,
2007-05-02 19:27:07 +02:00
* and s o m e o n e h a s l o a d e d a m a p p e d p a g e t a b l e .
*
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
* % rsi h o l d s a p h y s i c a l p o i n t e r t o r e a l _ m o d e _ d a t a .
2007-05-02 19:27:07 +02:00
*
* We c o m e h e r e e i t h e r f r o m s t a r t u p _ 6 4 ( u s i n g p h y s i c a l a d d r e s s e s )
* or f r o m t r a m p o l i n e . S ( u s i n g v i r t u a l a d d r e s s e s ) .
*
* Using v i r t u a l a d d r e s s e s f r o m t r a m p o l i n e . S r e m o v e s t h e n e e d
* to h a v e a n y i d e n t i t y m a p p e d p a g e s i n t h e k e r n e l p a g e t a b l e
* after t h e b o o t p r o c e s s o r e x e c u t e s t h i s c o d e .
2005-04-16 15:20:36 -07:00
* /
2015-11-05 16:57:56 +01:00
/* Sanitize CPU configuration */
call v e r i f y _ c p u
2020-09-07 15:16:09 +02:00
/ *
* The s e c o n d a r y _ s t a r t u p _ 6 4 _ n o _ v e r i f y e n t r y p o i n t i s o n l y u s e d b y
* SEV- E S g u e s t s . I n t h o s e g u e s t s t h e c a l l t o v e r i f y _ c p u ( ) w o u l d c a u s e
* # VC e x c e p t i o n s w h i c h c a n n o t b e h a n d l e d a t t h i s s t a g e o f s e c o n d a r y
* CPU b r i n g u p .
*
* All n o n S E V - E S s y s t e m s , e s p e c i a l l y I n t e l s y s t e m s , n e e d t o e x e c u t e
* verify_ c p u ( ) a b o v e t o m a k e s u r e N X i s e n a b l e d .
* /
SYM_ I N N E R _ L A B E L ( s e c o n d a r y _ s t a r t u p _ 6 4 _ n o _ v e r i f y , S Y M _ L _ G L O B A L )
UNWIND_ H I N T _ E M P T Y
2017-07-17 16:10:05 -05:00
/ *
* Retrieve t h e m o d i f i e r ( S M E e n c r y p t i o n m a s k i f S M E i s a c t i v e ) t o b e
* added t o t h e i n i t i a l p g d i r e n t r y t h a t w i l l b e p r o g r a m m e d i n t o C R 3 .
* /
pushq % r s i
call _ _ s t a r t u p _ s e c o n d a r y _ 6 4
popq % r s i
/* Form the CR3 value being sure to include the CR3 modifier */
addq $ ( i n i t _ t o p _ p g t - _ _ S T A R T _ K E R N E L _ m a p ) , % r a x
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
1 :
2017-06-06 14:31:28 +03:00
/* Enable PAE mode, PGE and LA57 */
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
movl $ ( X 8 6 _ C R 4 _ P A E | X 8 6 _ C R 4 _ P G E ) , % e c x
2017-06-06 14:31:28 +03:00
# ifdef C O N F I G _ X 8 6 _ 5 L E V E L
x86/mm: Optimize boot-time paging mode switching cost
By this point we have functioning boot-time switching between 4- and
5-level paging mode. But naive approach comes with cost.
Numbers below are for kernel build, allmodconfig, 5 times.
CONFIG_X86_5LEVEL=n:
Performance counter stats for 'sh -c make -j100 -B -k >/dev/null' (5 runs):
17308719.892691 task-clock:u (msec) # 26.772 CPUs utilized ( +- 0.11% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
331,993,164 page-faults:u # 0.019 M/sec ( +- 0.01% )
43,614,978,867,455 cycles:u # 2.520 GHz ( +- 0.01% )
39,371,534,575,126 stalled-cycles-frontend:u # 90.27% frontend cycles idle ( +- 0.09% )
28,363,350,152,428 instructions:u # 0.65 insn per cycle
# 1.39 stalled cycles per insn ( +- 0.00% )
6,316,784,066,413 branches:u # 364.948 M/sec ( +- 0.00% )
250,808,144,781 branch-misses:u # 3.97% of all branches ( +- 0.01% )
646.531974142 seconds time elapsed ( +- 1.15% )
CONFIG_X86_5LEVEL=y:
Performance counter stats for 'sh -c make -j100 -B -k >/dev/null' (5 runs):
17411536.780625 task-clock:u (msec) # 26.426 CPUs utilized ( +- 0.10% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
331,868,663 page-faults:u # 0.019 M/sec ( +- 0.01% )
43,865,909,056,301 cycles:u # 2.519 GHz ( +- 0.01% )
39,740,130,365,581 stalled-cycles-frontend:u # 90.59% frontend cycles idle ( +- 0.05% )
28,363,358,997,959 instructions:u # 0.65 insn per cycle
# 1.40 stalled cycles per insn ( +- 0.00% )
6,316,784,937,460 branches:u # 362.793 M/sec ( +- 0.00% )
251,531,919,485 branch-misses:u # 3.98% of all branches ( +- 0.00% )
658.886307752 seconds time elapsed ( +- 0.92% )
The patch tries to fix the performance regression by using
cpu_feature_enabled(X86_FEATURE_LA57) instead of pgtable_l5_enabled in
all hot code paths. These will statically patch the target code for
additional performance.
CONFIG_X86_5LEVEL=y + the patch:
Performance counter stats for 'sh -c make -j100 -B -k >/dev/null' (5 runs):
17381990.268506 task-clock:u (msec) # 26.907 CPUs utilized ( +- 0.19% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
331,862,625 page-faults:u # 0.019 M/sec ( +- 0.01% )
43,697,726,320,051 cycles:u # 2.514 GHz ( +- 0.03% )
39,480,408,690,401 stalled-cycles-frontend:u # 90.35% frontend cycles idle ( +- 0.05% )
28,363,394,221,388 instructions:u # 0.65 insn per cycle
# 1.39 stalled cycles per insn ( +- 0.00% )
6,316,794,985,573 branches:u # 363.410 M/sec ( +- 0.00% )
251,013,232,547 branch-misses:u # 3.97% of all branches ( +- 0.01% )
645.991174661 seconds time elapsed ( +- 1.19% )
Unfortunately, this approach doesn't help with text size:
vmlinux.before .text size: 8190319
vmlinux.after .text size: 8200623
The .text section is increased by about 4k. Not sure if we can do anything
about this.
Signed-off-by: Kirill A. Shuemov <kirill.shutemov@linux.intel.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arjan van de Ven <arjan@linux.intel.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Borislav Petkov <bp@suse.de>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: David Woodhouse <dwmw2@infradead.org>
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-mm@kvack.org
Link: http://lkml.kernel.org/r/20180216114948.68868-4-kirill.shutemov@linux.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2018-02-16 14:49:48 +03:00
testl $ 1 , _ _ p g t a b l e _ l 5 _ e n a b l e d ( % r i p )
2018-02-14 21:25:39 +03:00
jz 1 f
2017-06-06 14:31:28 +03:00
orl $ X 8 6 _ C R 4 _ L A 5 7 , % e c x
2018-02-14 21:25:39 +03:00
1 :
2017-06-06 14:31:28 +03:00
# endif
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
movq % r c x , % c r4
2005-04-16 15:20:36 -07:00
2017-06-06 14:31:28 +03:00
/* Setup early boot stage 4-/5-level pagetables. */
2007-05-02 19:27:07 +02:00
addq p h y s _ b a s e ( % r i p ) , % r a x
2020-10-28 17:46:58 +01:00
/ *
* For S E V g u e s t s : V e r i f y t h a t t h e C - b i t i s c o r r e c t . A m a l i c i o u s
* hypervisor c o u l d l i e a b o u t t h e C - b i t p o s i t i o n t o p e r f o r m a R O P
* attack o n t h e g u e s t b y w r i t i n g t o t h e u n e n c r y p t e d s t a c k a n d w a i t f o r
* the n e x t R E T i n s t r u c t i o n .
* % rsi c a r r i e s p o i n t e r t o r e a l m o d e d a t a a n d i s c a l l e e - c l o b b e r e d . S a v e
* and r e s t o r e i t .
* /
pushq % r s i
movq % r a x , % r d i
call s e v _ v e r i f y _ c b i t
popq % r s i
/* Switch to new page-table */
2005-04-16 15:20:36 -07:00
movq % r a x , % c r3
2007-05-02 19:27:07 +02:00
/* Ensure I am executing from virtual addresses */
movq $ 1 f , % r a x
2018-01-16 10:38:09 +01:00
ANNOTATE_ R E T P O L I N E _ S A F E
2007-05-02 19:27:07 +02:00
jmp * % r a x
1 :
2017-09-18 21:43:37 -05:00
UNWIND_ H I N T _ E M P T Y
2007-05-02 19:27:07 +02:00
2020-09-07 15:15:31 +02:00
/ *
* We m u s t s w i t c h t o a n e w d e s c r i p t o r i n k e r n e l s p a c e f o r t h e G D T
* because s o o n t h e k e r n e l w o n ' t h a v e a c c e s s a n y m o r e t o t h e u s e r s p a c e
* addresses w h e r e w e ' r e c u r r e n t l y r u n n i n g o n . W e h a v e t o d o t h a t h e r e
* because i n 3 2 b i t w e c o u l d n ' t l o a d a 6 4 b i t l i n e a r a d d r e s s .
* /
lgdt e a r l y _ g d t _ d e s c r ( % r i p )
2020-09-07 15:15:32 +02:00
/* set up data segments */
xorl % e a x ,% e a x
movl % e a x ,% d s
movl % e a x ,% s s
movl % e a x ,% e s
/ *
* We d o n ' t r e a l l y n e e d t o l o a d % f s o r % g s , b u t l o a d t h e m a n y w a y
* to k i l l a n y s t a l e r e a l m o d e s e l e c t o r s . T h i s a l l o w s e x e c u t i o n
* under V T h a r d w a r e .
* /
movl % e a x ,% f s
movl % e a x ,% g s
/ * Set u p % g s .
*
* The b a s e o f % g s a l w a y s p o i n t s t o f i x e d _ p e r c p u _ d a t a . I f t h e
* stack p r o t e c t o r c a n a r y i s e n a b l e d , i t i s l o c a t e d a t % g s : 4 0 .
* Note t h a t , o n S M P , t h e b o o t c p u u s e s i n i t d a t a s e c t i o n u n t i l
* the p e r c p u a r e a s a r e s e t u p .
* /
movl $ M S R _ G S _ B A S E ,% e c x
movl i n i t i a l _ g s ( % r i p ) ,% e a x
movl i n i t i a l _ g s + 4 ( % r i p ) ,% e d x
wrmsr
2020-09-07 15:15:33 +02:00
/ *
* Setup a b o o t t i m e s t a c k - A n y s e c o n d a r y C P U w i l l h a v e l o s t i t s s t a c k
* by n o w b e c a u s e t h e c r3 - s w i t c h a b o v e u n m a p s t h e r e a l - m o d e s t a c k
* /
movq i n i t i a l _ s t a c k ( % r i p ) , % r s p
2020-09-07 15:15:34 +02:00
/* Setup and Load IDT */
pushq % r s i
call e a r l y _ s e t u p _ i d t
popq % r s i
2005-04-16 15:20:36 -07:00
/* Check if nx is implemented */
movl $ 0 x80 0 0 0 0 0 1 , % e a x
cpuid
movl % e d x ,% e d i
/* Setup EFER (Extended Feature Enable Register) */
movl $ M S R _ E F E R , % e c x
rdmsr
2007-05-02 19:27:07 +02:00
btsl $ _ E F E R _ S C E , % e a x / * E n a b l e S y s t e m C a l l * /
btl $ 2 0 ,% e d i / * N o E x e c u t e s u p p o r t e d ? * /
2005-04-16 15:20:36 -07:00
jnc 1 f
btsl $ _ E F E R _ N X , % e a x
2013-05-02 10:33:46 -07:00
btsq $ _ P A G E _ B I T _ N X ,e a r l y _ p m d _ f l a g s ( % r i p )
2007-05-02 19:27:07 +02:00
1 : wrmsr / * M a k e c h a n g e s e f f e c t i v e * /
2005-04-16 15:20:36 -07:00
/* Setup cr0 */
2008-05-12 15:43:38 +02:00
movl $ C R 0 _ S T A T E , % e a x
2005-04-16 15:20:36 -07:00
/* Make changes effective */
movq % r a x , % c r0
/* zero EFLAGS after setting rsp */
pushq $ 0
popfq
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
/ * rsi i s p o i n t e r t o r e a l m o d e s t r u c t u r e w i t h i n t e r e s t i n g i n f o .
2005-04-16 15:20:36 -07:00
pass i t t o C * /
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
movq % r s i , % r d i
2016-09-21 16:04:04 -05:00
2017-03-04 10:56:10 +01:00
.Ljump_to_C_code :
2016-09-21 16:04:04 -05:00
/ *
* Jump t o r u n C c o d e a n d t o b e o n a r e a l k e r n e l a d d r e s s .
2005-04-16 15:20:36 -07:00
* Since w e a r e r u n n i n g o n i d e n t i t y - m a p p e d s p a c e w e h a v e t o j u m p
2006-09-26 10:52:38 +02:00
* to t h e f u l l 6 4 b i t a d d r e s s , t h i s i s o n l y p o s s i b l e a s i n d i r e c t
* jump. I n a d d i t i o n w e n e e d t o e n s u r e % c s i s s e t s o w e m a k e t h i s
* a f a r r e t u r n .
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
*
* Note : do n o t c h a n g e t o f a r j u m p i n d i r e c t w i t h 6 4 b i t o f f s e t .
*
* AMD d o e s n o t s u p p o r t f a r j u m p i n d i r e c t w i t h 6 4 b i t o f f s e t .
* AMD6 4 A r c h i t e c t u r e P r o g r a m m e r ' s M a n u a l , V o l u m e 3 : s t a t e s o n l y
* JMP F A R m e m 1 6 : 1 6 F F / 5 F a r j u m p i n d i r e c t ,
* with t h e t a r g e t s p e c i f i e d b y a f a r p o i n t e r i n m e m o r y .
* JMP F A R m e m 1 6 : 3 2 F F / 5 F a r j u m p i n d i r e c t ,
* with t h e t a r g e t s p e c i f i e d b y a f a r p o i n t e r i n m e m o r y .
*
* Intel6 4 d o e s s u p p o r t 6 4 b i t o f f s e t .
* Software D e v e l o p e r M a n u a l V o l 2 : s t a t e s :
* FF / 5 J M P m 1 6 : 1 6 J u m p f a r , a b s o l u t e i n d i r e c t ,
* address g i v e n i n m 1 6 : 1 6
* FF / 5 J M P m 1 6 : 3 2 J u m p f a r , a b s o l u t e i n d i r e c t ,
* address g i v e n i n m 1 6 : 3 2 .
* REX. W + F F / 5 J M P m 1 6 : 6 4 J u m p f a r , a b s o l u t e i n d i r e c t ,
* address g i v e n i n m 1 6 : 6 4 .
2005-04-16 15:20:36 -07:00
* /
2016-12-13 21:25:36 -06:00
pushq $ . L a f t e r _ l r e t # p u t r e t u r n a d d r e s s o n s t a c k f o r u n w i n d e r
2018-07-02 04:31:54 -06:00
xorl % e b p , % e b p # c l e a r f r a m e p o i n t e r
2016-09-21 16:04:05 -05:00
movq i n i t i a l _ c o d e ( % r i p ) , % r a x
2006-09-26 10:52:38 +02:00
pushq $ _ _ K E R N E L _ C S # s e t c o r r e c t c s
pushq % r a x # t a r g e t a d d r e s s i n n e g a t i v e s p a c e
lretq
2016-12-13 21:25:36 -06:00
.Lafter_lret :
2019-10-11 13:51:03 +02:00
SYM_ C O D E _ E N D ( s e c o n d a r y _ s t a r t u p _ 6 4 )
2005-04-16 15:20:36 -07:00
2015-11-05 16:57:56 +01:00
# include " v e r i f y _ c p u . S "
2020-10-28 17:46:58 +01:00
# include " s e v _ v e r i f y _ c b i t . S "
2015-11-05 16:57:56 +01:00
2012-11-13 11:32:44 -08:00
# ifdef C O N F I G _ H O T P L U G _ C P U
/ *
* Boot C P U 0 e n t r y p o i n t . I t ' s c a l l e d f r o m p l a y _ d e a d ( ) . E v e r y t h i n g h a s b e e n s e t
* up a l r e a d y e x c e p t s t a c k . W e j u s t s e t u p s t a c k h e r e . T h e n c a l l
2017-03-04 10:56:10 +01:00
* start_ s e c o n d a r y ( ) v i a . L j u m p _ t o _ C _ c o d e .
2012-11-13 11:32:44 -08:00
* /
2019-10-11 13:51:03 +02:00
SYM_ C O D E _ S T A R T ( s t a r t _ c p u 0 )
2017-09-18 21:43:37 -05:00
UNWIND_ H I N T _ E M P T Y
2019-07-17 20:36:41 -05:00
movq i n i t i a l _ s t a c k ( % r i p ) , % r s p
2017-03-04 10:56:10 +01:00
jmp . L j u m p _ t o _ C _ c o d e
2019-10-11 13:51:03 +02:00
SYM_ C O D E _ E N D ( s t a r t _ c p u 0 )
2020-09-08 14:38:16 +02:00
# endif
# ifdef C O N F I G _ A M D _ M E M _ E N C R Y P T
/ *
* VC E x c e p t i o n h a n d l e r u s e d d u r i n g e a r l y b o o t w h e n r u n n i n g o n k e r n e l
* addresses, b u t b e f o r e t h e s w i t c h t o t h e i d t _ t a b l e c a n b e m a d e .
* The e a r l y _ i d t _ h a n d l e r _ a r r a y c a n ' t b e u s e d h e r e b e c a u s e i t c a l l s i n t o a l o t
* of _ _ i n i t c o d e a n d t h i s h a n d l e r i s a l s o u s e d d u r i n g C P U o f f l i n i n g / o n l i n i n g .
* Therefore t h i s h a n d l e r e n d s u p i n t h e . t e x t s e c t i o n s o t h a t i t s t a y s a r o u n d
* when . i n i t . t e x t i s f r e e d .
* /
SYM_ C O D E _ S T A R T _ N O A L I G N ( v c _ b o o t _ g h c b )
UNWIND_ H I N T _ I R E T _ R E G S o f f s e t =8
/* Build pt_regs */
PUSH_ A N D _ C L E A R _ R E G S
/* Call C handler */
movq % r s p , % r d i
movq O R I G _ R A X ( % r s p ) , % r s i
movq i n i t i a l _ v c _ h a n d l e r ( % r i p ) , % r a x
ANNOTATE_ R E T P O L I N E _ S A F E
call * % r a x
/* Unwind pt_regs */
POP_ R E G S
/* Remove Error Code */
addq $ 8 , % r s p
/* Pure iret required here - don't use INTERRUPT_RETURN */
iretq
SYM_ C O D E _ E N D ( v c _ b o o t _ g h c b )
2012-11-13 11:32:44 -08:00
# endif
2016-08-18 10:59:03 -05:00
/* Both SMP bootup and ACPI suspend change these variables */
2008-02-17 13:22:59 +01:00
_ _ REFDATA
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
.balign 8
2019-10-11 13:50:51 +02:00
SYM_ D A T A ( i n i t i a l _ c o d e , . q u a d x86 _ 6 4 _ s t a r t _ k e r n e l )
SYM_ D A T A ( i n i t i a l _ g s , . q u a d I N I T _ P E R _ C P U _ V A R ( f i x e d _ p e r c p u _ d a t a ) )
2020-09-08 14:38:16 +02:00
# ifdef C O N F I G _ A M D _ M E M _ E N C R Y P T
SYM_ D A T A ( i n i t i a l _ v c _ h a n d l e r , . q u a d h a n d l e _ v c _ b o o t _ g h c b )
# endif
2019-10-11 13:50:51 +02:00
/ *
* The S I Z E O F _ P T R E G S g a p i s a c o n v e n t i o n w h i c h h e l p s t h e i n - k e r n e l u n w i n d e r
* reliably d e t e c t t h e e n d o f t h e s t a c k .
* /
SYM_ D A T A ( i n i t i a l _ s t a c k , . q u a d i n i t _ t h r e a d _ u n i o n + T H R E A D _ S I Z E - S I Z E O F _ P T R E G S )
2009-10-14 14:46:55 -07:00
_ _ FINITDATA
2005-04-16 15:20:36 -07:00
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
_ _ INIT
2019-10-11 13:51:03 +02:00
SYM_ C O D E _ S T A R T ( e a r l y _ i d t _ h a n d l e r _ a r r a y )
2008-03-11 02:23:22 +01:00
i = 0
.rept NUM_EXCEPTION_VECTORS
2017-10-20 11:21:35 -05:00
.if ( ( EXCEPTION_ E R R C O D E _ M A S K > > i ) & 1 ) = = 0
2017-09-18 21:43:37 -05:00
UNWIND_ H I N T _ I R E T _ R E G S
pushq $ 0 # D u m m y e r r o r c o d e , t o m a k e s t a c k f r a m e u n i f o r m
.else
UNWIND_ H I N T _ I R E T _ R E G S o f f s e t =8
2012-04-18 17:16:49 -07:00
.endif
pushq $ i # 72 ( % r s p ) V e c t o r n u m b e r
2015-05-22 16:15:47 -07:00
jmp e a r l y _ i d t _ h a n d l e r _ c o m m o n
2017-09-18 21:43:37 -05:00
UNWIND_ H I N T _ I R E T _ R E G S
2008-03-11 02:23:22 +01:00
i = i + 1
2015-05-22 16:15:47 -07:00
.fill early_idt_handler_array + i* E A R L Y _ I D T _ H A N D L E R _ S I Z E - . , 1 , 0 x c c
2008-03-11 02:23:22 +01:00
.endr
2017-09-18 21:43:37 -05:00
UNWIND_ H I N T _ I R E T _ R E G S o f f s e t =16
2019-10-11 13:51:03 +02:00
SYM_ C O D E _ E N D ( e a r l y _ i d t _ h a n d l e r _ a r r a y )
2008-01-30 13:33:06 +01:00
2019-10-11 13:50:45 +02:00
SYM_ C O D E _ S T A R T _ L O C A L ( e a r l y _ i d t _ h a n d l e r _ c o m m o n )
2015-05-22 16:15:47 -07:00
/ *
* The s t a c k i s t h e h a r d w a r e f r a m e , a n e r r o r c o d e o r z e r o , a n d t h e
* vector n u m b e r .
* /
2012-04-18 17:16:49 -07:00
cld
2005-04-16 15:25:00 -07:00
incl e a r l y _ r e c u r s i o n _ f l a g ( % r i p )
2012-04-18 17:16:49 -07:00
2016-04-02 07:01:32 -07:00
/* The vector number is currently in the pt_regs->di slot. */
pushq % r s i / * p t _ r e g s - > s i * /
movq 8 ( % r s p ) , % r s i / * R S I = v e c t o r n u m b e r * /
movq % r d i , 8 ( % r s p ) / * p t _ r e g s - > d i = R D I * /
pushq % r d x / * p t _ r e g s - > d x * /
pushq % r c x / * p t _ r e g s - > c x * /
pushq % r a x / * p t _ r e g s - > a x * /
pushq % r8 / * p t _ r e g s - > r8 * /
pushq % r9 / * p t _ r e g s - > r9 * /
pushq % r10 / * p t _ r e g s - > r10 * /
pushq % r11 / * p t _ r e g s - > r11 * /
pushq % r b x / * p t _ r e g s - > b x * /
pushq % r b p / * p t _ r e g s - > b p * /
pushq % r12 / * p t _ r e g s - > r12 * /
pushq % r13 / * p t _ r e g s - > r13 * /
pushq % r14 / * p t _ r e g s - > r14 * /
pushq % r15 / * p t _ r e g s - > r15 * /
2017-09-18 21:43:37 -05:00
UNWIND_ H I N T _ R E G S
2016-04-02 07:01:32 -07:00
movq % r s p ,% r d i / * R D I = p t _ r e g s ; RSI is already trapnr */
2020-09-07 15:15:36 +02:00
call d o _ e a r l y _ e x c e p t i o n
2008-01-30 13:33:06 +01:00
2012-04-18 17:16:49 -07:00
decl e a r l y _ r e c u r s i o n _ f l a g ( % r i p )
2017-11-02 00:58:59 -07:00
jmp r e s t o r e _ r e g s _ a n d _ r e t u r n _ t o _ k e r n e l
2019-10-11 13:50:45 +02:00
SYM_ C O D E _ E N D ( e a r l y _ i d t _ h a n d l e r _ c o m m o n )
2012-04-18 17:16:49 -07:00
2020-09-08 14:35:17 +02:00
# ifdef C O N F I G _ A M D _ M E M _ E N C R Y P T
/ *
* VC E x c e p t i o n h a n d l e r u s e d d u r i n g v e r y e a r l y b o o t . T h e
* early_ i d t _ h a n d l e r _ a r r a y c a n ' t b e u s e d b e c a u s e i t r e t u r n s v i a t h e
* paravirtualized I N T E R R U P T _ R E T U R N a n d p v - o p s d o n ' t w o r k t h a t e a r l y .
*
* This h a n d l e r w i l l e n d u p i n t h e . i n i t . t e x t s e c t i o n a n d n o t b e
* available t o b o o t s e c o n d a r y C P U s .
* /
SYM_ C O D E _ S T A R T _ N O A L I G N ( v c _ n o _ g h c b )
UNWIND_ H I N T _ I R E T _ R E G S o f f s e t =8
/* Build pt_regs */
PUSH_ A N D _ C L E A R _ R E G S
/* Call C handler */
movq % r s p , % r d i
movq O R I G _ R A X ( % r s p ) , % r s i
call d o _ v c _ n o _ g h c b
/* Unwind pt_regs */
POP_ R E G S
/* Remove Error Code */
addq $ 8 , % r s p
/* Pure iret required here - don't use INTERRUPT_RETURN */
iretq
SYM_ C O D E _ E N D ( v c _ n o _ g h c b )
# endif
2019-10-11 13:50:51 +02:00
# define S Y M _ D A T A _ S T A R T _ P A G E _ A L I G N E D ( n a m e ) \
SYM_ S T A R T ( n a m e , S Y M _ L _ G L O B A L , . b a l i g n P A G E _ S I Z E )
2006-01-17 07:03:32 +01:00
2017-12-04 15:07:39 +01:00
# ifdef C O N F I G _ P A G E _ T A B L E _ I S O L A T I O N
/ *
* Each P G D n e e d s t o b e 8 k l o n g a n d 8 k a l i g n e d . W e d o n o t
* ever g o o u t t o u s e r s p a c e w i t h t h e s e , s o w e d o n o t
* strictly * n e e d * t h e s e c o n d p a g e , b u t t h i s a l l o w s u s t o
* have a s i n g l e s e t _ p g d ( ) i m p l e m e n t a t i o n t h a t d o e s n o t
* need t o w o r r y a b o u t w h e t h e r i t h a s 4 k o r 8 k t o w o r k
* with.
*
* This e n s u r e s P G D s a r e 8 k l o n g :
* /
# define P T I _ U S E R _ P G D _ F I L L 5 1 2
/* This ensures they are 8k-aligned: */
2019-10-11 13:50:51 +02:00
# define S Y M _ D A T A _ S T A R T _ P T I _ A L I G N E D ( n a m e ) \
SYM_ S T A R T ( n a m e , S Y M _ L _ G L O B A L , . b a l i g n 2 * P A G E _ S I Z E )
2017-12-04 15:07:39 +01:00
# else
2019-10-11 13:50:51 +02:00
# define S Y M _ D A T A _ S T A R T _ P T I _ A L I G N E D ( n a m e ) \
SYM_ D A T A _ S T A R T _ P A G E _ A L I G N E D ( n a m e )
2017-12-04 15:07:39 +01:00
# define P T I _ U S E R _ P G D _ F I L L 0
# endif
2007-05-02 19:27:06 +02:00
/* Automate the creation of 1 to 1 mapping pmd entries */
2008-05-13 20:55:40 +04:00
# define P M D S ( S T A R T , P E R M , C O U N T ) \
i = 0 ; \
.rept ( COUNT) ; \
.quad ( START) + ( i < < P M D _ S H I F T ) + ( P E R M ) ; \
i = i + 1 ; \
2007-05-02 19:27:06 +02:00
.endr
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
_ _ INITDATA
2019-10-03 11:52:37 +02:00
.balign 4
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ S T A R T _ P T I _ A L I G N E D ( e a r l y _ t o p _ p g t )
2018-02-14 21:25:39 +03:00
.fill 5 1 2 , 8 , 0
2017-12-04 15:07:39 +01:00
.fill PTI_ U S E R _ P G D _ F I L L ,8 ,0
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ E N D ( e a r l y _ t o p _ p g t )
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ S T A R T _ P A G E _ A L I G N E D ( e a r l y _ d y n a m i c _ p g t s )
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
.fill 5 1 2 * EARLY_ D Y N A M I C _ P A G E _ T A B L E S ,8 ,0
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ E N D ( e a r l y _ d y n a m i c _ p g t s )
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
2019-10-11 13:50:51 +02:00
SYM_ D A T A ( e a r l y _ r e c u r s i o n _ f l a g , . l o n g 0 )
2019-10-03 11:52:37 +02:00
2009-10-14 14:46:55 -07:00
.data
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
2018-12-10 11:07:28 -08:00
# if d e f i n e d ( C O N F I G _ X E N _ P V ) | | d e f i n e d ( C O N F I G _ P V H )
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ S T A R T _ P T I _ A L I G N E D ( i n i t _ t o p _ p g t )
2017-07-17 16:10:07 -05:00
.quad level3_ident_pgt - _ _ START_ K E R N E L _ m a p + _ K E R N P G _ T A B L E _ N O E N C
2018-02-16 14:49:46 +03:00
.org init_top_pgt + L4 _ P A G E _ O F F S E T * 8 , 0
2017-07-17 16:10:07 -05:00
.quad level3_ident_pgt - _ _ START_ K E R N E L _ m a p + _ K E R N P G _ T A B L E _ N O E N C
2018-02-16 14:49:46 +03:00
.org init_top_pgt + L4 _ S T A R T _ K E R N E L * 8 , 0
2007-05-02 19:27:07 +02:00
/* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
2017-07-17 16:10:07 -05:00
.quad level3_kernel_pgt - _ _ START_ K E R N E L _ m a p + _ P A G E _ T A B L E _ N O E N C
2017-12-04 15:07:39 +01:00
.fill PTI_ U S E R _ P G D _ F I L L ,8 ,0
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ E N D ( i n i t _ t o p _ p g t )
2005-04-16 15:20:36 -07:00
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ S T A R T _ P A G E _ A L I G N E D ( l e v e l 3 _ i d e n t _ p g t )
2017-07-17 16:10:07 -05:00
.quad level2_ident_pgt - _ _ START_ K E R N E L _ m a p + _ K E R N P G _ T A B L E _ N O E N C
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
.fill 5 1 1 , 8 , 0
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ E N D ( l e v e l 3 _ i d e n t _ p g t )
SYM_ D A T A _ S T A R T _ P A G E _ A L I G N E D ( l e v e l 2 _ i d e n t _ p g t )
2018-04-06 13:55:13 -07:00
/ *
* Since I e a s i l y c a n , m a p t h e f i r s t 1 G .
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
* Don' t s e t N X b e c a u s e c o d e r u n s f r o m t h e s e p a g e s .
2018-04-06 13:55:13 -07:00
*
* Note : This s e t s _ P A G E _ G L O B A L d e s p i t e w h e t h e r
* the C P U s u p p o r t s i t o r i t i s e n a b l e d . B u t ,
* the C P U s h o u l d i g n o r e t h e b i t .
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
* /
PMDS( 0 , _ _ P A G E _ K E R N E L _ I D E N T _ L A R G E _ E X E C , P T R S _ P E R _ P M D )
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ E N D ( l e v e l 2 _ i d e n t _ p g t )
2017-09-29 17:08:19 +03:00
# else
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ S T A R T _ P T I _ A L I G N E D ( i n i t _ t o p _ p g t )
2017-09-29 17:08:19 +03:00
.fill 5 1 2 , 8 , 0
2017-12-04 15:07:39 +01:00
.fill PTI_ U S E R _ P G D _ F I L L ,8 ,0
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ E N D ( i n i t _ t o p _ p g t )
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
# endif
2005-04-16 15:20:36 -07:00
2017-06-06 14:31:28 +03:00
# ifdef C O N F I G _ X 8 6 _ 5 L E V E L
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ S T A R T _ P A G E _ A L I G N E D ( l e v e l 4 _ k e r n e l _ p g t )
2017-06-06 14:31:28 +03:00
.fill 5 1 1 , 8 , 0
2017-07-17 16:10:07 -05:00
.quad level3_kernel_pgt - _ _ START_ K E R N E L _ m a p + _ P A G E _ T A B L E _ N O E N C
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ E N D ( l e v e l 4 _ k e r n e l _ p g t )
2017-06-06 14:31:28 +03:00
# endif
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ S T A R T _ P A G E _ A L I G N E D ( l e v e l 3 _ k e r n e l _ p g t )
2008-06-25 00:19:16 -04:00
.fill L3 _ S T A R T _ K E R N E L ,8 ,0
2005-04-16 15:20:36 -07:00
/* (2^48-(2*1024*1024*1024)-((2^39)*511))/(2^30) = 510 */
2017-07-17 16:10:07 -05:00
.quad level2_kernel_pgt - _ _ START_ K E R N E L _ m a p + _ K E R N P G _ T A B L E _ N O E N C
.quad level2_fixmap_pgt - _ _ START_ K E R N E L _ m a p + _ P A G E _ T A B L E _ N O E N C
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ E N D ( l e v e l 3 _ k e r n e l _ p g t )
2007-07-15 23:37:28 -07:00
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ S T A R T _ P A G E _ A L I G N E D ( l e v e l 2 _ k e r n e l _ p g t )
2008-02-21 11:04:11 +01:00
/ *
x86/build: Fix vmlinux size check on 64-bit
Commit
b4e0409a36f4 ("x86: check vmlinux limits, 64-bit")
added a check that the size of the 64-bit kernel is less than
KERNEL_IMAGE_SIZE.
The check uses (_end - _text), but this is not enough. The initial
PMD used in startup_64() (level2_kernel_pgt) can only map upto
KERNEL_IMAGE_SIZE from __START_KERNEL_map, not from _text, and the
modules area (MODULES_VADDR) starts at KERNEL_IMAGE_SIZE.
The correct check is what is currently done for 32-bit, since
LOAD_OFFSET is defined appropriately for the two architectures. Just
check (_end - LOAD_OFFSET) against KERNEL_IMAGE_SIZE unconditionally.
Note that on 32-bit, the limit is not strict: KERNEL_IMAGE_SIZE is not
really used by the main kernel. The higher the kernel is located, the
less the space available for the vmalloc area. However, it is used by
KASLR in the compressed stub to limit the maximum address of the kernel
to a safe value.
Clean up various comments to clarify that despite the name,
KERNEL_IMAGE_SIZE is not a limit on the size of the kernel image, but a
limit on the maximum virtual address that the image can occupy.
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20201029161903.2553528-1-nivedita@alum.mit.edu
2020-10-29 12:19:03 -04:00
* Kernel h i g h m a p p i n g .
2008-02-21 11:04:11 +01:00
*
x86/build: Fix vmlinux size check on 64-bit
Commit
b4e0409a36f4 ("x86: check vmlinux limits, 64-bit")
added a check that the size of the 64-bit kernel is less than
KERNEL_IMAGE_SIZE.
The check uses (_end - _text), but this is not enough. The initial
PMD used in startup_64() (level2_kernel_pgt) can only map upto
KERNEL_IMAGE_SIZE from __START_KERNEL_map, not from _text, and the
modules area (MODULES_VADDR) starts at KERNEL_IMAGE_SIZE.
The correct check is what is currently done for 32-bit, since
LOAD_OFFSET is defined appropriately for the two architectures. Just
check (_end - LOAD_OFFSET) against KERNEL_IMAGE_SIZE unconditionally.
Note that on 32-bit, the limit is not strict: KERNEL_IMAGE_SIZE is not
really used by the main kernel. The higher the kernel is located, the
less the space available for the vmalloc area. However, it is used by
KASLR in the compressed stub to limit the maximum address of the kernel
to a safe value.
Clean up various comments to clarify that despite the name,
KERNEL_IMAGE_SIZE is not a limit on the size of the kernel image, but a
limit on the maximum virtual address that the image can occupy.
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20201029161903.2553528-1-nivedita@alum.mit.edu
2020-10-29 12:19:03 -04:00
* The k e r n e l c o d e + d a t a + b s s m u s t b e l o c a t e d b e l o w K E R N E L _ I M A G E _ S I Z E i n
* virtual a d d r e s s s p a c e , w h i c h i s 1 G i B i f R A N D O M I Z E _ B A S E i s e n a b l e d ,
* 5 1 2 MiB o t h e r w i s e .
2008-02-21 11:04:11 +01:00
*
x86/build: Fix vmlinux size check on 64-bit
Commit
b4e0409a36f4 ("x86: check vmlinux limits, 64-bit")
added a check that the size of the 64-bit kernel is less than
KERNEL_IMAGE_SIZE.
The check uses (_end - _text), but this is not enough. The initial
PMD used in startup_64() (level2_kernel_pgt) can only map upto
KERNEL_IMAGE_SIZE from __START_KERNEL_map, not from _text, and the
modules area (MODULES_VADDR) starts at KERNEL_IMAGE_SIZE.
The correct check is what is currently done for 32-bit, since
LOAD_OFFSET is defined appropriately for the two architectures. Just
check (_end - LOAD_OFFSET) against KERNEL_IMAGE_SIZE unconditionally.
Note that on 32-bit, the limit is not strict: KERNEL_IMAGE_SIZE is not
really used by the main kernel. The higher the kernel is located, the
less the space available for the vmalloc area. However, it is used by
KASLR in the compressed stub to limit the maximum address of the kernel
to a safe value.
Clean up various comments to clarify that despite the name,
KERNEL_IMAGE_SIZE is not a limit on the size of the kernel image, but a
limit on the maximum virtual address that the image can occupy.
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20201029161903.2553528-1-nivedita@alum.mit.edu
2020-10-29 12:19:03 -04:00
* ( NOTE : after t h a t s t a r t s t h e m o d u l e a r e a , s e e M O D U L E S _ V A D D R . )
2018-04-06 13:55:13 -07:00
*
x86/build: Fix vmlinux size check on 64-bit
Commit
b4e0409a36f4 ("x86: check vmlinux limits, 64-bit")
added a check that the size of the 64-bit kernel is less than
KERNEL_IMAGE_SIZE.
The check uses (_end - _text), but this is not enough. The initial
PMD used in startup_64() (level2_kernel_pgt) can only map upto
KERNEL_IMAGE_SIZE from __START_KERNEL_map, not from _text, and the
modules area (MODULES_VADDR) starts at KERNEL_IMAGE_SIZE.
The correct check is what is currently done for 32-bit, since
LOAD_OFFSET is defined appropriately for the two architectures. Just
check (_end - LOAD_OFFSET) against KERNEL_IMAGE_SIZE unconditionally.
Note that on 32-bit, the limit is not strict: KERNEL_IMAGE_SIZE is not
really used by the main kernel. The higher the kernel is located, the
less the space available for the vmalloc area. However, it is used by
KASLR in the compressed stub to limit the maximum address of the kernel
to a safe value.
Clean up various comments to clarify that despite the name,
KERNEL_IMAGE_SIZE is not a limit on the size of the kernel image, but a
limit on the maximum virtual address that the image can occupy.
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20201029161903.2553528-1-nivedita@alum.mit.edu
2020-10-29 12:19:03 -04:00
* This t a b l e i s e v e n t u a l l y u s e d b y t h e k e r n e l d u r i n g n o r m a l r u n t i m e .
* Care m u s t b e t a k e n t o c l e a r o u t u n d e s i r e d b i t s l a t e r , l i k e _ P A G E _ R W
* or _ P A G E _ G L O B A L i n s o m e c a s e s .
2008-02-21 11:04:11 +01:00
* /
x86/build: Fix vmlinux size check on 64-bit
Commit
b4e0409a36f4 ("x86: check vmlinux limits, 64-bit")
added a check that the size of the 64-bit kernel is less than
KERNEL_IMAGE_SIZE.
The check uses (_end - _text), but this is not enough. The initial
PMD used in startup_64() (level2_kernel_pgt) can only map upto
KERNEL_IMAGE_SIZE from __START_KERNEL_map, not from _text, and the
modules area (MODULES_VADDR) starts at KERNEL_IMAGE_SIZE.
The correct check is what is currently done for 32-bit, since
LOAD_OFFSET is defined appropriately for the two architectures. Just
check (_end - LOAD_OFFSET) against KERNEL_IMAGE_SIZE unconditionally.
Note that on 32-bit, the limit is not strict: KERNEL_IMAGE_SIZE is not
really used by the main kernel. The higher the kernel is located, the
less the space available for the vmalloc area. However, it is used by
KASLR in the compressed stub to limit the maximum address of the kernel
to a safe value.
Clean up various comments to clarify that despite the name,
KERNEL_IMAGE_SIZE is not a limit on the size of the kernel image, but a
limit on the maximum virtual address that the image can occupy.
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20201029161903.2553528-1-nivedita@alum.mit.edu
2020-10-29 12:19:03 -04:00
PMDS( 0 , _ _ P A G E _ K E R N E L _ L A R G E _ E X E C , K E R N E L _ I M A G E _ S I Z E / P M D _ S I Z E )
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ E N D ( l e v e l 2 _ k e r n e l _ p g t )
2005-04-16 15:20:36 -07:00
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ S T A R T _ P A G E _ A L I G N E D ( l e v e l 2 _ f i x m a p _ p g t )
2018-09-20 10:58:28 +08:00
.fill ( 5 1 2 - 4 - FIXMAP_ P M D _ N U M ) ,8 ,0
pgtno = 0
.rept ( FIXMAP_ P M D _ N U M )
.quad level1_fixmap_pgt + ( pgtno < < P A G E _ S H I F T ) - _ _ S T A R T _ K E R N E L _ m a p \
+ _ PAGE_ T A B L E _ N O E N C ;
pgtno = p g t n o + 1
.endr
/* 6 MB reserved space + a 2MB hole */
.fill 4 , 8 , 0
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ E N D ( l e v e l 2 _ f i x m a p _ p g t )
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ S T A R T _ P A G E _ A L I G N E D ( l e v e l 1 _ f i x m a p _ p g t )
2018-09-20 10:58:28 +08:00
.rept ( FIXMAP_ P M D _ N U M )
x86, 64bit: Use a #PF handler to materialize early mappings on demand
Linear mode (CR0.PG = 0) is mutually exclusive with 64-bit mode; all
64-bit code has to use page tables. This makes it awkward before we
have first set up properly all-covering page tables to access objects
that are outside the static kernel range.
So far we have dealt with that simply by mapping a fixed amount of
low memory, but that fails in at least two upcoming use cases:
1. We will support load and run kernel, struct boot_params, ramdisk,
command line, etc. above the 4 GiB mark.
2. need to access ramdisk early to get microcode to update that as
early possible.
We could use early_iomap to access them too, but it will make code to
messy and hard to be unified with 32 bit.
Hence, set up a #PF table and use a fixed number of buffers to set up
page tables on demand. If the buffers fill up then we simply flush
them and start over. These buffers are all in __initdata, so it does
not increase RAM usage at runtime.
Thus, with the help of the #PF handler, we can set the final kernel
mapping from blank, and switch to init_level4_pgt later.
During the switchover in head_64.S, before #PF handler is available,
we use three pages to handle kernel crossing 1G, 512G boundaries with
sharing page by playing games with page aliasing: the same page is
mapped twice in the higher-level tables with appropriate wraparound.
The kernel region itself will be properly mapped; other mappings may
be spurious.
early_make_pgtable is using kernel high mapping address to access pages
to set page table.
-v4: Add phys_base offset to make kexec happy, and add
init_mapping_kernel() - Yinghai
-v5: fix compiling with xen, and add back ident level3 and level2 for xen
also move back init_level4_pgt from BSS to DATA again.
because we have to clear it anyway. - Yinghai
-v6: switch to init_level4_pgt in init_mem_mapping. - Yinghai
-v7: remove not needed clear_page for init_level4_page
it is with fill 512,8,0 already in head_64.S - Yinghai
-v8: we need to keep that handler alive until init_mem_mapping and don't
let early_trap_init to trash that early #PF handler.
So split early_trap_pf_init out and move it down. - Yinghai
-v9: switchover only cover kernel space instead of 1G so could avoid
touch possible mem holes. - Yinghai
-v11: change far jmp back to far return to initial_code, that is needed
to fix failure that is reported by Konrad on AMD systems. - Yinghai
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-12-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-01-24 12:19:52 -08:00
.fill 5 1 2 , 8 , 0
2018-09-20 10:58:28 +08:00
.endr
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ E N D ( l e v e l 1 _ f i x m a p _ p g t )
2007-05-02 19:27:07 +02:00
2007-05-02 19:27:06 +02:00
# undef P M D S
2005-04-16 15:20:36 -07:00
2006-01-17 07:03:32 +01:00
.data
2005-04-16 15:20:36 -07:00
.align 16
2019-10-11 13:50:51 +02:00
SYM_ D A T A ( e a r l y _ g d t _ d e s c r , . w o r d G D T _ E N T R I E S * 8 - 1 )
SYM_ D A T A _ L O C A L ( e a r l y _ g d t _ d e s c r _ b a s e , . q u a d I N I T _ P E R _ C P U _ V A R ( g d t _ p a g e ) )
.align 16
/* This must match the first entry in level2_kernel_pgt */
SYM_ D A T A ( p h y s _ b a s e , . q u a d 0 x0 )
2016-01-11 11:04:34 -05:00
EXPORT_ S Y M B O L ( p h y s _ b a s e )
2007-05-02 19:27:07 +02:00
2008-07-08 15:06:44 -07:00
# include " . . / . . / x86 / x e n / x e n - h e a d . S "
2017-09-18 21:43:37 -05:00
2009-09-20 18:14:14 -04:00
_ _ PAGE_ A L I G N E D _ B S S
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ S T A R T _ P A G E _ A L I G N E D ( e m p t y _ z e r o _ p a g e )
2006-03-25 16:30:01 +01:00
.skip PAGE_SIZE
2019-10-11 13:50:51 +02:00
SYM_ D A T A _ E N D ( e m p t y _ z e r o _ p a g e )
2016-01-11 11:04:34 -05:00
EXPORT_ S Y M B O L ( e m p t y _ z e r o _ p a g e )
2015-02-13 14:39:25 -08:00