License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2007-10-13 09:10:53 +08:00
|
|
|
* prepare to run common code
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
|
|
|
|
*/
|
|
|
|
|
2017-03-14 00:33:37 +08:00
|
|
|
#define DISABLE_BRANCH_PROFILING
|
2018-05-18 18:35:23 +08:00
|
|
|
|
|
|
|
/* cpu_feature_enabled() cannot be used this early */
|
|
|
|
#define USE_EARLY_PGTABLE_L5
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/linkage.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/percpu.h>
|
2008-01-30 20:30:19 +08:00
|
|
|
#include <linux/start_kernel.h>
|
2008-03-28 10:49:44 +08:00
|
|
|
#include <linux/io.h>
|
2010-08-26 04:39:17 +08:00
|
|
|
#include <linux/memblock.h>
|
2017-07-18 05:10:05 +08:00
|
|
|
#include <linux/mem_encrypt.h>
|
2020-06-09 12:32:42 +08:00
|
|
|
#include <linux/pgtable.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/proto.h>
|
|
|
|
#include <asm/smp.h>
|
|
|
|
#include <asm/setup.h>
|
|
|
|
#include <asm/desc.h>
|
2007-05-03 01:27:07 +08:00
|
|
|
#include <asm/tlbflush.h>
|
2005-11-06 00:25:53 +08:00
|
|
|
#include <asm/sections.h>
|
2008-01-30 20:30:17 +08:00
|
|
|
#include <asm/kdebug.h>
|
2017-01-27 17:27:10 +08:00
|
|
|
#include <asm/e820/api.h>
|
2009-08-29 21:03:59 +08:00
|
|
|
#include <asm/bios_ebda.h>
|
2013-01-29 17:05:24 +08:00
|
|
|
#include <asm/bootparam_utils.h>
|
2012-12-21 15:44:30 +08:00
|
|
|
#include <asm/microcode.h>
|
2015-02-14 06:39:25 +08:00
|
|
|
#include <asm/kasan.h>
|
2018-09-20 10:58:28 +08:00
|
|
|
#include <asm/fixmap.h>
|
2005-04-17 06:20:36 +08: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-25 04:19:52 +08:00
|
|
|
/*
|
|
|
|
* Manage page tables very early on.
|
|
|
|
*/
|
|
|
|
extern pmd_t early_dynamic_pgts[EARLY_DYNAMIC_PAGE_TABLES][PTRS_PER_PMD];
|
2017-06-06 19:31:26 +08:00
|
|
|
static unsigned int __initdata next_early_pgt;
|
2013-05-21 02:36:03 +08:00
|
|
|
pmdval_t early_pmd_flags = __PAGE_KERNEL_LARGE & ~(_PAGE_GLOBAL | _PAGE_NX);
|
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-25 04:19:52 +08:00
|
|
|
|
2018-02-14 19:16:51 +08:00
|
|
|
#ifdef CONFIG_X86_5LEVEL
|
2018-06-23 06:08:40 +08:00
|
|
|
unsigned int __pgtable_l5_enabled __ro_after_init;
|
2018-02-15 02:25:35 +08:00
|
|
|
unsigned int pgdir_shift __ro_after_init = 39;
|
2018-02-14 19:16:53 +08:00
|
|
|
EXPORT_SYMBOL(pgdir_shift);
|
2018-02-15 02:25:35 +08:00
|
|
|
unsigned int ptrs_per_p4d __ro_after_init = 1;
|
2018-02-14 19:16:53 +08:00
|
|
|
EXPORT_SYMBOL(ptrs_per_p4d);
|
2018-02-14 19:16:51 +08:00
|
|
|
#endif
|
|
|
|
|
2018-02-14 19:16:50 +08:00
|
|
|
#ifdef CONFIG_DYNAMIC_MEMORY_LAYOUT
|
2018-02-15 02:25:36 +08:00
|
|
|
unsigned long page_offset_base __ro_after_init = __PAGE_OFFSET_BASE_L4;
|
2018-02-14 19:16:50 +08:00
|
|
|
EXPORT_SYMBOL(page_offset_base);
|
2018-02-15 02:25:37 +08:00
|
|
|
unsigned long vmalloc_base __ro_after_init = __VMALLOC_BASE_L4;
|
2018-02-14 19:16:50 +08:00
|
|
|
EXPORT_SYMBOL(vmalloc_base);
|
2018-02-15 02:25:38 +08:00
|
|
|
unsigned long vmemmap_base __ro_after_init = __VMEMMAP_BASE_L4;
|
2018-02-14 19:16:50 +08:00
|
|
|
EXPORT_SYMBOL(vmemmap_base);
|
|
|
|
#endif
|
|
|
|
|
2017-06-16 19:30:24 +08:00
|
|
|
#define __head __section(.head.text)
|
|
|
|
|
|
|
|
static void __head *fixup_pointer(void *ptr, unsigned long physaddr)
|
2017-06-06 19:31:26 +08:00
|
|
|
{
|
|
|
|
return ptr - (void *)_text + (void *)physaddr;
|
|
|
|
}
|
|
|
|
|
2018-02-15 02:25:36 +08:00
|
|
|
static unsigned long __head *fixup_long(void *ptr, unsigned long physaddr)
|
|
|
|
{
|
|
|
|
return fixup_pointer(ptr, physaddr);
|
|
|
|
}
|
|
|
|
|
2018-02-15 02:25:34 +08:00
|
|
|
#ifdef CONFIG_X86_5LEVEL
|
|
|
|
static unsigned int __head *fixup_int(void *ptr, unsigned long physaddr)
|
|
|
|
{
|
|
|
|
return fixup_pointer(ptr, physaddr);
|
|
|
|
}
|
|
|
|
|
2018-02-15 02:25:39 +08:00
|
|
|
static bool __head check_la57_support(unsigned long physaddr)
|
2018-02-15 02:25:34 +08:00
|
|
|
{
|
2018-05-18 18:35:25 +08:00
|
|
|
/*
|
|
|
|
* 5-level paging is detected and enabled at kernel decomression
|
|
|
|
* stage. Only check if it has been enabled there.
|
|
|
|
*/
|
|
|
|
if (!(native_read_cr4() & X86_CR4_LA57))
|
2018-02-15 02:25:39 +08:00
|
|
|
return false;
|
2018-02-15 02:25:34 +08:00
|
|
|
|
2018-05-18 18:35:23 +08:00
|
|
|
*fixup_int(&__pgtable_l5_enabled, physaddr) = 1;
|
2018-02-15 02:25:35 +08:00
|
|
|
*fixup_int(&pgdir_shift, physaddr) = 48;
|
|
|
|
*fixup_int(&ptrs_per_p4d, physaddr) = 512;
|
2018-02-15 02:25:36 +08:00
|
|
|
*fixup_long(&page_offset_base, physaddr) = __PAGE_OFFSET_BASE_L5;
|
2018-02-15 02:25:37 +08:00
|
|
|
*fixup_long(&vmalloc_base, physaddr) = __VMALLOC_BASE_L5;
|
2018-02-15 02:25:38 +08:00
|
|
|
*fixup_long(&vmemmap_base, physaddr) = __VMEMMAP_BASE_L5;
|
2018-02-15 02:25:39 +08:00
|
|
|
|
|
|
|
return true;
|
2018-02-15 02:25:34 +08:00
|
|
|
}
|
|
|
|
#else
|
2018-02-15 02:25:39 +08:00
|
|
|
static bool __head check_la57_support(unsigned long physaddr)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2018-02-15 02:25:34 +08:00
|
|
|
#endif
|
|
|
|
|
2018-05-09 17:18:22 +08:00
|
|
|
/* Code in __startup_64() can be relocated during execution, but the compiler
|
|
|
|
* doesn't have to generate PC-relative relocations when accessing globals from
|
|
|
|
* that function. Clang actually does not generate them, which leads to
|
|
|
|
* boot-time crashes. To work around this problem, every global pointer must
|
|
|
|
* be adjusted using fixup_pointer().
|
|
|
|
*/
|
2017-07-18 05:10:35 +08:00
|
|
|
unsigned long __head __startup_64(unsigned long physaddr,
|
|
|
|
struct boot_params *bp)
|
2017-06-06 19:31:26 +08:00
|
|
|
{
|
2018-09-14 21:45:58 +08:00
|
|
|
unsigned long vaddr, vaddr_end;
|
2018-02-15 02:25:39 +08:00
|
|
|
unsigned long load_delta, *p;
|
2017-07-18 05:10:05 +08:00
|
|
|
unsigned long pgtable_flags;
|
2017-06-06 19:31:26 +08:00
|
|
|
pgdval_t *pgd;
|
2017-06-06 19:31:28 +08:00
|
|
|
p4dval_t *p4d;
|
2017-06-06 19:31:26 +08:00
|
|
|
pudval_t *pud;
|
|
|
|
pmdval_t *pmd, pmd_entry;
|
2018-05-09 17:18:22 +08:00
|
|
|
pteval_t *mask_ptr;
|
2018-02-15 02:25:39 +08:00
|
|
|
bool la57;
|
2017-06-06 19:31:26 +08:00
|
|
|
int i;
|
2017-08-17 03:08:08 +08:00
|
|
|
unsigned int *next_pgt_ptr;
|
2017-06-06 19:31:26 +08:00
|
|
|
|
2018-02-15 02:25:39 +08:00
|
|
|
la57 = check_la57_support(physaddr);
|
2018-02-15 02:25:34 +08:00
|
|
|
|
2017-06-06 19:31:26 +08:00
|
|
|
/* Is the address too large? */
|
|
|
|
if (physaddr >> MAX_PHYSMEM_BITS)
|
|
|
|
for (;;);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute the delta between the address I am compiled to run at
|
|
|
|
* and the address I am actually running at.
|
|
|
|
*/
|
|
|
|
load_delta = physaddr - (unsigned long)(_text - __START_KERNEL_map);
|
|
|
|
|
|
|
|
/* Is the address not 2M aligned? */
|
|
|
|
if (load_delta & ~PMD_PAGE_MASK)
|
|
|
|
for (;;);
|
|
|
|
|
2017-07-18 05:10:05 +08:00
|
|
|
/* Activate Secure Memory Encryption (SME) if supported and enabled */
|
2017-07-18 05:10:35 +08:00
|
|
|
sme_enable(bp);
|
2017-07-18 05:10:05 +08:00
|
|
|
|
|
|
|
/* Include the SME encryption mask in the fixup value */
|
|
|
|
load_delta += sme_get_me_mask();
|
|
|
|
|
2017-06-06 19:31:26 +08:00
|
|
|
/* Fixup the physical addresses in the page table */
|
|
|
|
|
2017-06-06 19:31:27 +08:00
|
|
|
pgd = fixup_pointer(&early_top_pgt, physaddr);
|
2018-02-15 02:25:39 +08:00
|
|
|
p = pgd + pgd_index(__START_KERNEL_map);
|
|
|
|
if (la57)
|
|
|
|
*p = (unsigned long)level4_kernel_pgt;
|
|
|
|
else
|
|
|
|
*p = (unsigned long)level3_kernel_pgt;
|
|
|
|
*p += _PAGE_TABLE_NOENC - __START_KERNEL_map + load_delta;
|
|
|
|
|
|
|
|
if (la57) {
|
2017-06-06 19:31:28 +08:00
|
|
|
p4d = fixup_pointer(&level4_kernel_pgt, physaddr);
|
|
|
|
p4d[511] += load_delta;
|
|
|
|
}
|
|
|
|
|
2017-06-06 19:31:26 +08:00
|
|
|
pud = fixup_pointer(&level3_kernel_pgt, physaddr);
|
|
|
|
pud[510] += load_delta;
|
|
|
|
pud[511] += load_delta;
|
|
|
|
|
|
|
|
pmd = fixup_pointer(level2_fixmap_pgt, physaddr);
|
2018-09-20 10:58:28 +08:00
|
|
|
for (i = FIXMAP_PMD_TOP; i > FIXMAP_PMD_TOP - FIXMAP_PMD_NUM; i--)
|
|
|
|
pmd[i] += load_delta;
|
2017-06-06 19:31:26 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the identity mapping for the switchover. These
|
|
|
|
* entries should *NOT* have the global bit set! This also
|
|
|
|
* creates a bunch of nonsense entries but that is fine --
|
|
|
|
* it avoids problems around wraparound.
|
|
|
|
*/
|
|
|
|
|
2017-08-17 03:08:08 +08:00
|
|
|
next_pgt_ptr = fixup_pointer(&next_early_pgt, physaddr);
|
|
|
|
pud = fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++], physaddr);
|
|
|
|
pmd = fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++], physaddr);
|
2017-06-06 19:31:26 +08:00
|
|
|
|
2017-07-18 05:10:07 +08:00
|
|
|
pgtable_flags = _KERNPG_TABLE_NOENC + sme_get_me_mask();
|
2017-06-06 19:31:26 +08:00
|
|
|
|
2018-02-15 02:25:39 +08:00
|
|
|
if (la57) {
|
2019-06-20 19:24:22 +08:00
|
|
|
p4d = fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++],
|
|
|
|
physaddr);
|
2017-06-06 19:31:28 +08:00
|
|
|
|
|
|
|
i = (physaddr >> PGDIR_SHIFT) % PTRS_PER_PGD;
|
2017-07-18 05:10:05 +08:00
|
|
|
pgd[i + 0] = (pgdval_t)p4d + pgtable_flags;
|
|
|
|
pgd[i + 1] = (pgdval_t)p4d + pgtable_flags;
|
2017-06-06 19:31:28 +08:00
|
|
|
|
2019-06-20 19:23:45 +08:00
|
|
|
i = physaddr >> P4D_SHIFT;
|
|
|
|
p4d[(i + 0) % PTRS_PER_P4D] = (pgdval_t)pud + pgtable_flags;
|
|
|
|
p4d[(i + 1) % PTRS_PER_P4D] = (pgdval_t)pud + pgtable_flags;
|
2017-06-06 19:31:28 +08:00
|
|
|
} else {
|
|
|
|
i = (physaddr >> PGDIR_SHIFT) % PTRS_PER_PGD;
|
2017-07-18 05:10:05 +08:00
|
|
|
pgd[i + 0] = (pgdval_t)pud + pgtable_flags;
|
|
|
|
pgd[i + 1] = (pgdval_t)pud + pgtable_flags;
|
2017-06-06 19:31:28 +08:00
|
|
|
}
|
2017-06-06 19:31:26 +08:00
|
|
|
|
2019-06-20 19:23:45 +08:00
|
|
|
i = physaddr >> PUD_SHIFT;
|
|
|
|
pud[(i + 0) % PTRS_PER_PUD] = (pudval_t)pmd + pgtable_flags;
|
|
|
|
pud[(i + 1) % PTRS_PER_PUD] = (pudval_t)pmd + pgtable_flags;
|
2017-06-06 19:31:26 +08:00
|
|
|
|
|
|
|
pmd_entry = __PAGE_KERNEL_LARGE_EXEC & ~_PAGE_GLOBAL;
|
2018-04-07 04:55:09 +08:00
|
|
|
/* Filter out unsupported __PAGE_KERNEL_* bits: */
|
2018-05-09 17:18:22 +08:00
|
|
|
mask_ptr = fixup_pointer(&__supported_pte_mask, physaddr);
|
|
|
|
pmd_entry &= *mask_ptr;
|
2017-07-18 05:10:05 +08:00
|
|
|
pmd_entry += sme_get_me_mask();
|
2017-06-06 19:31:26 +08:00
|
|
|
pmd_entry += physaddr;
|
|
|
|
|
|
|
|
for (i = 0; i < DIV_ROUND_UP(_end - _text, PMD_SIZE); i++) {
|
2019-06-20 19:23:45 +08:00
|
|
|
int idx = i + (physaddr >> PMD_SHIFT);
|
|
|
|
|
|
|
|
pmd[idx % PTRS_PER_PMD] = pmd_entry + i * PMD_SIZE;
|
2017-06-06 19:31:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fixup the kernel text+data virtual addresses. Note that
|
|
|
|
* we might write invalid pmds, when the kernel is relocated
|
|
|
|
* cleanup_highmap() fixes this up along with the mappings
|
|
|
|
* beyond _end.
|
x86/boot/64: Make level2_kernel_pgt pages invalid outside kernel area
Our hardware (UV aka Superdome Flex) has address ranges marked
reserved by the BIOS. Access to these ranges is caught as an error,
causing the BIOS to halt the system.
Initial page tables mapped a large range of physical addresses that
were not checked against the list of BIOS reserved addresses, and
sometimes included reserved addresses in part of the mapped range.
Including the reserved range in the map allowed processor speculative
accesses to the reserved range, triggering a BIOS halt.
Used early in booting, the page table level2_kernel_pgt addresses 1
GiB divided into 2 MiB pages, and it was set up to linearly map a full
1 GiB of physical addresses that included the physical address range
of the kernel image, as chosen by KASLR. But this also included a
large range of unused addresses on either side of the kernel image.
And unlike the kernel image's physical address range, this extra
mapped space was not checked against the BIOS tables of usable RAM
addresses. So there were times when the addresses chosen by KASLR
would result in processor accessible mappings of BIOS reserved
physical addresses.
The kernel code did not directly access any of this extra mapped
space, but having it mapped allowed the processor to issue speculative
accesses into reserved memory, causing system halts.
This was encountered somewhat rarely on a normal system boot, and much
more often when starting the crash kernel if "crashkernel=512M,high"
was specified on the command line (this heavily restricts the physical
address of the crash kernel, in our case usually within 1 GiB of
reserved space).
The solution is to invalidate the pages of this table outside the kernel
image's space before the page table is activated. It fixes this problem
on our hardware.
[ bp: Touchups. ]
Signed-off-by: Steve Wahl <steve.wahl@hpe.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: dimitri.sivanich@hpe.com
Cc: Feng Tang <feng.tang@intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jordan Borgner <mail@jordan-borgner.de>
Cc: Juergen Gross <jgross@suse.com>
Cc: mike.travis@hpe.com
Cc: russ.anderson@hpe.com
Cc: stable@vger.kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: x86-ml <x86@kernel.org>
Cc: Zhenzhong Duan <zhenzhong.duan@oracle.com>
Link: https://lkml.kernel.org/r/9c011ee51b081534a7a15065b1681d200298b530.1569358539.git.steve.wahl@hpe.com
2019-09-25 05:03:55 +08:00
|
|
|
*
|
|
|
|
* Only the region occupied by the kernel image has so far
|
|
|
|
* been checked against the table of usable memory regions
|
|
|
|
* provided by the firmware, so invalidate pages outside that
|
|
|
|
* region. A page table entry that maps to a reserved area of
|
|
|
|
* memory would allow processor speculation into that area,
|
|
|
|
* and on some hardware (particularly the UV platform) even
|
|
|
|
* speculative access to some reserved areas is caught as an
|
|
|
|
* error, causing the BIOS to halt the system.
|
2017-06-06 19:31:26 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
pmd = fixup_pointer(level2_kernel_pgt, physaddr);
|
x86/boot/64: Make level2_kernel_pgt pages invalid outside kernel area
Our hardware (UV aka Superdome Flex) has address ranges marked
reserved by the BIOS. Access to these ranges is caught as an error,
causing the BIOS to halt the system.
Initial page tables mapped a large range of physical addresses that
were not checked against the list of BIOS reserved addresses, and
sometimes included reserved addresses in part of the mapped range.
Including the reserved range in the map allowed processor speculative
accesses to the reserved range, triggering a BIOS halt.
Used early in booting, the page table level2_kernel_pgt addresses 1
GiB divided into 2 MiB pages, and it was set up to linearly map a full
1 GiB of physical addresses that included the physical address range
of the kernel image, as chosen by KASLR. But this also included a
large range of unused addresses on either side of the kernel image.
And unlike the kernel image's physical address range, this extra
mapped space was not checked against the BIOS tables of usable RAM
addresses. So there were times when the addresses chosen by KASLR
would result in processor accessible mappings of BIOS reserved
physical addresses.
The kernel code did not directly access any of this extra mapped
space, but having it mapped allowed the processor to issue speculative
accesses into reserved memory, causing system halts.
This was encountered somewhat rarely on a normal system boot, and much
more often when starting the crash kernel if "crashkernel=512M,high"
was specified on the command line (this heavily restricts the physical
address of the crash kernel, in our case usually within 1 GiB of
reserved space).
The solution is to invalidate the pages of this table outside the kernel
image's space before the page table is activated. It fixes this problem
on our hardware.
[ bp: Touchups. ]
Signed-off-by: Steve Wahl <steve.wahl@hpe.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: dimitri.sivanich@hpe.com
Cc: Feng Tang <feng.tang@intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jordan Borgner <mail@jordan-borgner.de>
Cc: Juergen Gross <jgross@suse.com>
Cc: mike.travis@hpe.com
Cc: russ.anderson@hpe.com
Cc: stable@vger.kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: x86-ml <x86@kernel.org>
Cc: Zhenzhong Duan <zhenzhong.duan@oracle.com>
Link: https://lkml.kernel.org/r/9c011ee51b081534a7a15065b1681d200298b530.1569358539.git.steve.wahl@hpe.com
2019-09-25 05:03:55 +08:00
|
|
|
|
|
|
|
/* invalidate pages before the kernel image */
|
|
|
|
for (i = 0; i < pmd_index((unsigned long)_text); i++)
|
|
|
|
pmd[i] &= ~_PAGE_PRESENT;
|
|
|
|
|
|
|
|
/* fixup pages that are part of the kernel image */
|
|
|
|
for (; i <= pmd_index((unsigned long)_end); i++)
|
2017-06-06 19:31:26 +08:00
|
|
|
if (pmd[i] & _PAGE_PRESENT)
|
|
|
|
pmd[i] += load_delta;
|
x86/boot/64: Make level2_kernel_pgt pages invalid outside kernel area
Our hardware (UV aka Superdome Flex) has address ranges marked
reserved by the BIOS. Access to these ranges is caught as an error,
causing the BIOS to halt the system.
Initial page tables mapped a large range of physical addresses that
were not checked against the list of BIOS reserved addresses, and
sometimes included reserved addresses in part of the mapped range.
Including the reserved range in the map allowed processor speculative
accesses to the reserved range, triggering a BIOS halt.
Used early in booting, the page table level2_kernel_pgt addresses 1
GiB divided into 2 MiB pages, and it was set up to linearly map a full
1 GiB of physical addresses that included the physical address range
of the kernel image, as chosen by KASLR. But this also included a
large range of unused addresses on either side of the kernel image.
And unlike the kernel image's physical address range, this extra
mapped space was not checked against the BIOS tables of usable RAM
addresses. So there were times when the addresses chosen by KASLR
would result in processor accessible mappings of BIOS reserved
physical addresses.
The kernel code did not directly access any of this extra mapped
space, but having it mapped allowed the processor to issue speculative
accesses into reserved memory, causing system halts.
This was encountered somewhat rarely on a normal system boot, and much
more often when starting the crash kernel if "crashkernel=512M,high"
was specified on the command line (this heavily restricts the physical
address of the crash kernel, in our case usually within 1 GiB of
reserved space).
The solution is to invalidate the pages of this table outside the kernel
image's space before the page table is activated. It fixes this problem
on our hardware.
[ bp: Touchups. ]
Signed-off-by: Steve Wahl <steve.wahl@hpe.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: dimitri.sivanich@hpe.com
Cc: Feng Tang <feng.tang@intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jordan Borgner <mail@jordan-borgner.de>
Cc: Juergen Gross <jgross@suse.com>
Cc: mike.travis@hpe.com
Cc: russ.anderson@hpe.com
Cc: stable@vger.kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: x86-ml <x86@kernel.org>
Cc: Zhenzhong Duan <zhenzhong.duan@oracle.com>
Link: https://lkml.kernel.org/r/9c011ee51b081534a7a15065b1681d200298b530.1569358539.git.steve.wahl@hpe.com
2019-09-25 05:03:55 +08:00
|
|
|
|
|
|
|
/* invalidate pages after the kernel image */
|
|
|
|
for (; i < PTRS_PER_PMD; i++)
|
|
|
|
pmd[i] &= ~_PAGE_PRESENT;
|
2017-06-06 19:31:26 +08:00
|
|
|
|
2017-07-18 05:10:05 +08:00
|
|
|
/*
|
|
|
|
* Fixup phys_base - remove the memory encryption mask to obtain
|
|
|
|
* the true physical address.
|
|
|
|
*/
|
2018-02-15 02:25:36 +08:00
|
|
|
*fixup_long(&phys_base, physaddr) += load_delta - sme_get_me_mask();
|
2017-07-18 05:10:05 +08:00
|
|
|
|
2018-01-11 03:26:34 +08:00
|
|
|
/* Encrypt the kernel and related (if SME is active) */
|
|
|
|
sme_encrypt_kernel(bp);
|
2017-07-18 05:10:05 +08:00
|
|
|
|
2018-09-14 21:45:58 +08:00
|
|
|
/*
|
|
|
|
* Clear the memory encryption mask from the .bss..decrypted section.
|
|
|
|
* The bss section will be memset to zero later in the initialization so
|
|
|
|
* there is no need to zero it after changing the memory encryption
|
|
|
|
* attribute.
|
|
|
|
*/
|
|
|
|
if (mem_encrypt_active()) {
|
|
|
|
vaddr = (unsigned long)__start_bss_decrypted;
|
|
|
|
vaddr_end = (unsigned long)__end_bss_decrypted;
|
|
|
|
for (; vaddr < vaddr_end; vaddr += PMD_SIZE) {
|
|
|
|
i = pmd_index(vaddr);
|
|
|
|
pmd[i] -= sme_get_me_mask();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-18 05:10:05 +08:00
|
|
|
/*
|
|
|
|
* Return the SME encryption mask (if SME is active) to be used as a
|
|
|
|
* modifier for the initial pgdir entry programmed into CR3.
|
|
|
|
*/
|
|
|
|
return sme_get_me_mask();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long __startup_secondary_64(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Return the SME encryption mask (if SME is active) to be used as a
|
|
|
|
* modifier for the initial pgdir entry programmed into CR3.
|
|
|
|
*/
|
|
|
|
return sme_get_me_mask();
|
2017-06-06 19:31:26 +08: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-25 04:19:52 +08:00
|
|
|
/* Wipe all early page tables except for the kernel symbol map */
|
|
|
|
static void __init reset_early_page_tables(void)
|
2007-05-03 01:27:07 +08:00
|
|
|
{
|
2017-06-06 19:31:27 +08:00
|
|
|
memset(early_top_pgt, 0, sizeof(pgd_t)*(PTRS_PER_PGD-1));
|
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-25 04:19:52 +08:00
|
|
|
next_early_pgt = 0;
|
2017-07-18 05:10:07 +08:00
|
|
|
write_cr3(__sme_pa_nodebug(early_top_pgt));
|
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-25 04:19:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a new PMD entry */
|
2017-07-18 05:10:11 +08:00
|
|
|
int __init __early_make_pgtable(unsigned long address, pmdval_t pmd)
|
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-25 04:19:52 +08:00
|
|
|
{
|
|
|
|
unsigned long physaddr = address - __PAGE_OFFSET;
|
|
|
|
pgdval_t pgd, *pgd_p;
|
2017-06-06 19:31:28 +08:00
|
|
|
p4dval_t p4d, *p4d_p;
|
2013-01-25 04:19:53 +08:00
|
|
|
pudval_t pud, *pud_p;
|
2017-07-18 05:10:11 +08:00
|
|
|
pmdval_t *pmd_p;
|
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-25 04:19:52 +08:00
|
|
|
|
|
|
|
/* Invalid address or early pgt is done ? */
|
2017-06-06 19:31:27 +08:00
|
|
|
if (physaddr >= MAXMEM || read_cr3_pa() != __pa_nodebug(early_top_pgt))
|
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-25 04:19:52 +08:00
|
|
|
return -1;
|
|
|
|
|
2013-01-25 04:19:53 +08:00
|
|
|
again:
|
2017-06-06 19:31:27 +08:00
|
|
|
pgd_p = &early_top_pgt[pgd_index(address)].pgd;
|
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-25 04:19:52 +08:00
|
|
|
pgd = *pgd_p;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
|
|
|
|
* critical -- __PAGE_OFFSET would point us back into the dynamic
|
|
|
|
* range and we might end up looping forever...
|
|
|
|
*/
|
2018-05-18 18:35:24 +08:00
|
|
|
if (!pgtable_l5_enabled())
|
2017-06-06 19:31:28 +08:00
|
|
|
p4d_p = pgd_p;
|
|
|
|
else if (pgd)
|
|
|
|
p4d_p = (p4dval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
|
|
|
|
else {
|
|
|
|
if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
|
|
|
|
reset_early_page_tables();
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
|
|
|
p4d_p = (p4dval_t *)early_dynamic_pgts[next_early_pgt++];
|
|
|
|
memset(p4d_p, 0, sizeof(*p4d_p) * PTRS_PER_P4D);
|
|
|
|
*pgd_p = (pgdval_t)p4d_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
|
|
|
|
}
|
|
|
|
p4d_p += p4d_index(address);
|
|
|
|
p4d = *p4d_p;
|
|
|
|
|
|
|
|
if (p4d)
|
|
|
|
pud_p = (pudval_t *)((p4d & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
|
2013-01-25 04:19:53 +08:00
|
|
|
else {
|
|
|
|
if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
|
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-25 04:19:52 +08:00
|
|
|
reset_early_page_tables();
|
2013-01-25 04:19:53 +08:00
|
|
|
goto again;
|
|
|
|
}
|
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-25 04:19:52 +08:00
|
|
|
|
|
|
|
pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
|
2016-02-09 21:44:54 +08:00
|
|
|
memset(pud_p, 0, sizeof(*pud_p) * PTRS_PER_PUD);
|
2017-06-06 19:31:28 +08:00
|
|
|
*p4d_p = (p4dval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
|
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-25 04:19:52 +08:00
|
|
|
}
|
2013-01-25 04:19:53 +08:00
|
|
|
pud_p += pud_index(address);
|
|
|
|
pud = *pud_p;
|
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-25 04:19:52 +08:00
|
|
|
|
2013-01-25 04:19:53 +08:00
|
|
|
if (pud)
|
|
|
|
pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
|
|
|
|
else {
|
|
|
|
if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
|
|
|
|
reset_early_page_tables();
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
|
|
|
pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
|
2016-02-09 21:44:54 +08:00
|
|
|
memset(pmd_p, 0, sizeof(*pmd_p) * PTRS_PER_PMD);
|
2013-01-25 04:19:53 +08:00
|
|
|
*pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
|
|
|
|
}
|
|
|
|
pmd_p[pmd_index(address)] = pmd;
|
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-25 04:19:52 +08:00
|
|
|
|
|
|
|
return 0;
|
2007-05-03 01:27:07 +08:00
|
|
|
}
|
|
|
|
|
2017-07-18 05:10:11 +08:00
|
|
|
int __init early_make_pgtable(unsigned long address)
|
|
|
|
{
|
|
|
|
unsigned long physaddr = address - __PAGE_OFFSET;
|
|
|
|
pmdval_t pmd;
|
|
|
|
|
|
|
|
pmd = (physaddr & PMD_MASK) + early_pmd_flags;
|
|
|
|
|
|
|
|
return __early_make_pgtable(address, pmd);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Don't add a printk in there. printk relies on the PDA which is not initialized
|
|
|
|
yet. */
|
|
|
|
static void __init clear_bss(void)
|
|
|
|
{
|
|
|
|
memset(__bss_start, 0,
|
2005-11-06 00:25:53 +08:00
|
|
|
(unsigned long) __bss_stop - (unsigned long) __bss_start);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2013-01-25 04:19:57 +08:00
|
|
|
static unsigned long get_cmd_line_ptr(void)
|
|
|
|
{
|
|
|
|
unsigned long cmd_line_ptr = boot_params.hdr.cmd_line_ptr;
|
|
|
|
|
2013-01-29 12:16:44 +08:00
|
|
|
cmd_line_ptr |= (u64)boot_params.ext_cmd_line_ptr << 32;
|
|
|
|
|
2013-01-25 04:19:57 +08:00
|
|
|
return cmd_line_ptr;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static void __init copy_bootdata(char *real_mode_data)
|
|
|
|
{
|
|
|
|
char * command_line;
|
2013-01-25 04:19:57 +08:00
|
|
|
unsigned long cmd_line_ptr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-07-18 05:10:11 +08:00
|
|
|
/*
|
|
|
|
* If SME is active, this will create decrypted mappings of the
|
|
|
|
* boot data in advance of the copy operations.
|
|
|
|
*/
|
|
|
|
sme_map_bootdata(real_mode_data);
|
|
|
|
|
2018-10-28 20:58:28 +08:00
|
|
|
memcpy(&boot_params, real_mode_data, sizeof(boot_params));
|
2013-01-29 17:05:24 +08:00
|
|
|
sanitize_boot_params(&boot_params);
|
2013-01-25 04:19:57 +08:00
|
|
|
cmd_line_ptr = get_cmd_line_ptr();
|
|
|
|
if (cmd_line_ptr) {
|
|
|
|
command_line = __va(cmd_line_ptr);
|
2007-10-16 08:13:22 +08:00
|
|
|
memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2017-07-18 05:10:11 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The old boot data is no longer needed and won't be reserved,
|
|
|
|
* freeing up that memory for use by the system. If SME is active,
|
|
|
|
* we need to remove the mappings that were created so that the
|
|
|
|
* memory doesn't remain mapped as decrypted.
|
|
|
|
*/
|
|
|
|
sme_unmap_bootdata(real_mode_data);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2014-05-02 06:44:37 +08:00
|
|
|
asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-02-21 20:45:16 +08:00
|
|
|
/*
|
|
|
|
* Build-time sanity checks on the kernel image and module
|
|
|
|
* area mappings. (these are purely build-time and produce no code)
|
|
|
|
*/
|
2013-03-05 04:16:17 +08:00
|
|
|
BUILD_BUG_ON(MODULES_VADDR < __START_KERNEL_map);
|
|
|
|
BUILD_BUG_ON(MODULES_VADDR - __START_KERNEL_map < KERNEL_IMAGE_SIZE);
|
2008-02-21 20:45:16 +08:00
|
|
|
BUILD_BUG_ON(MODULES_LEN + KERNEL_IMAGE_SIZE > 2*PUD_SIZE);
|
2013-03-05 04:16:17 +08:00
|
|
|
BUILD_BUG_ON((__START_KERNEL_map & ~PMD_MASK) != 0);
|
2008-02-21 20:45:16 +08:00
|
|
|
BUILD_BUG_ON((MODULES_VADDR & ~PMD_MASK) != 0);
|
|
|
|
BUILD_BUG_ON(!(MODULES_VADDR > __START_KERNEL));
|
2018-02-14 19:16:53 +08:00
|
|
|
MAYBE_BUILD_BUG_ON(!(((MODULES_END - 1) & PGDIR_MASK) ==
|
2008-02-21 20:45:16 +08:00
|
|
|
(__START_KERNEL & PGDIR_MASK)));
|
2008-07-31 23:48:31 +08:00
|
|
|
BUILD_BUG_ON(__fix_to_virt(__end_of_fixed_addresses) <= MODULES_END);
|
2008-02-21 20:45:16 +08:00
|
|
|
|
2014-10-25 06:58:08 +08:00
|
|
|
cr4_init_shadow();
|
|
|
|
|
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-25 04:19:52 +08:00
|
|
|
/* Kill off the identity-map trampoline */
|
|
|
|
reset_early_page_tables();
|
|
|
|
|
2006-12-07 09:14:12 +08:00
|
|
|
clear_bss();
|
|
|
|
|
2017-06-06 19:31:27 +08:00
|
|
|
clear_page(init_top_pgt);
|
2015-07-02 17:09:33 +08:00
|
|
|
|
2017-07-18 05:10:07 +08:00
|
|
|
/*
|
|
|
|
* SME support may update early_pmd_flags to include the memory
|
|
|
|
* encryption mask, so it needs to be called before anything
|
|
|
|
* that may generate a page fault.
|
|
|
|
*/
|
|
|
|
sme_early_init();
|
|
|
|
|
2015-07-02 17:09:34 +08:00
|
|
|
kasan_early_init();
|
|
|
|
|
2017-08-28 14:47:47 +08:00
|
|
|
idt_setup_early_handler();
|
2005-11-06 00:25:53 +08:00
|
|
|
|
2013-01-25 04:19:49 +08:00
|
|
|
copy_bootdata(__va(real_mode_data));
|
|
|
|
|
2012-12-21 15:44:30 +08:00
|
|
|
/*
|
|
|
|
* Load microcode early on BSP.
|
|
|
|
*/
|
|
|
|
load_ucode_bsp();
|
|
|
|
|
2017-06-06 19:31:27 +08:00
|
|
|
/* set init_top_pgt kernel high mapping*/
|
|
|
|
init_top_pgt[511] = early_top_pgt[511];
|
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-25 04:19:52 +08:00
|
|
|
|
2008-06-25 12:19:18 +08:00
|
|
|
x86_64_start_reservations(real_mode_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __init x86_64_start_reservations(char *real_mode_data)
|
|
|
|
{
|
2013-01-25 04:19:49 +08:00
|
|
|
/* version is always not zero if it is copied */
|
|
|
|
if (!boot_params.hdr.version)
|
|
|
|
copy_bootdata(__va(real_mode_data));
|
2008-01-30 20:30:46 +08:00
|
|
|
|
2016-04-14 08:04:34 +08:00
|
|
|
x86_early_init_platform_quirks();
|
2008-01-30 20:33:17 +08:00
|
|
|
|
2016-01-16 04:11:07 +08:00
|
|
|
switch (boot_params.hdr.hardware_subarch) {
|
|
|
|
case X86_SUBARCH_INTEL_MID:
|
|
|
|
x86_intel_mid_early_setup();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
start_kernel();
|
|
|
|
}
|