From 70a9d8184ccecf7a38848531fb4767a85134f464 Mon Sep 17 00:00:00 2001 From: Ingo Molnar Date: Fri, 27 Jan 2017 09:58:02 +0100 Subject: [PATCH 0001/1358] x86/boot/e820: Introduce arch/x86/include/asm/e820/types.h First baby steps towards saner e820 headers: create an exact copy of arch/x86/include/uapi/asm/e820.h and use it from the asm/e820.h file. No other changes - this is done to decouple the code from UAPI headers, plus to make sure that subsequent modifications to the file can be more clearly seen. The plan is to keep the old UAPI header in place but the kernel won't use it anymore - and after some time we'll try to remove it. (User-space tools better have local copies of headers anyway, instead of relying on kernel headers.) This gives the kernel the freedom to reorganize the e820 code. Cc: Alex Thorlton Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Dan Williams Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Huang, Ying Cc: Josh Poimboeuf Cc: Juergen Gross Cc: Linus Torvalds Cc: Paul Jackson Cc: Peter Zijlstra Cc: Rafael J. Wysocki Cc: Tejun Heo Cc: Thomas Gleixner Cc: Wei Yang Cc: Yinghai Lu Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar --- arch/x86/include/asm/e820.h | 4 +- arch/x86/include/asm/e820/types.h | 81 +++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 arch/x86/include/asm/e820/types.h diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h index 67313f3a9874..55c1d76c169f 100644 --- a/arch/x86/include/asm/e820.h +++ b/arch/x86/include/asm/e820.h @@ -5,12 +5,12 @@ * E820_X_MAX is the maximum size of the extended E820 table. The extended * table may contain up to 3 extra E820 entries per possible NUMA node, so we * make room for 3 * MAX_NUMNODES possible entries, beyond the standard 128. - * Also note that E820_X_MAX *must* be defined before we include uapi/asm/e820.h. + * Also note that E820_X_MAX *must* be defined before we include asm/e820/types.h. */ #include #define E820_X_MAX (E820MAX + 3 * MAX_NUMNODES) -#include +#include #ifndef __ASSEMBLY__ /* see comment in arch/x86/kernel/e820.c */ diff --git a/arch/x86/include/asm/e820/types.h b/arch/x86/include/asm/e820/types.h new file mode 100644 index 000000000000..9dafe59cf6e2 --- /dev/null +++ b/arch/x86/include/asm/e820/types.h @@ -0,0 +1,81 @@ +#ifndef _UAPI_ASM_X86_E820_H +#define _UAPI_ASM_X86_E820_H +#define E820MAP 0x2d0 /* our map */ +#define E820MAX 128 /* number of entries in E820MAP */ + +/* + * Legacy E820 BIOS limits us to 128 (E820MAX) nodes due to the + * constrained space in the zeropage. If we have more nodes than + * that, and if we've booted off EFI firmware, then the EFI tables + * passed us from the EFI firmware can list more nodes. Size our + * internal memory map tables to have room for these additional + * nodes, based on up to three entries per node for which the + * kernel was built: MAX_NUMNODES == (1 << CONFIG_NODES_SHIFT), + * plus E820MAX, allowing space for the possible duplicate E820 + * entries that might need room in the same arrays, prior to the + * call to sanitize_e820_map() to remove duplicates. The allowance + * of three memory map entries per node is "enough" entries for + * the initial hardware platform motivating this mechanism to make + * use of additional EFI map entries. Future platforms may want + * to allow more than three entries per node or otherwise refine + * this size. + */ + +#ifndef __KERNEL__ +#define E820_X_MAX E820MAX +#endif + +#define E820NR 0x1e8 /* # entries in E820MAP */ + +#define E820_RAM 1 +#define E820_RESERVED 2 +#define E820_ACPI 3 +#define E820_NVS 4 +#define E820_UNUSABLE 5 +#define E820_PMEM 7 + +/* + * This is a non-standardized way to represent ADR or NVDIMM regions that + * persist over a reboot. The kernel will ignore their special capabilities + * unless the CONFIG_X86_PMEM_LEGACY option is set. + * + * ( Note that older platforms also used 6 for the same type of memory, + * but newer versions switched to 12 as 6 was assigned differently. Some + * time they will learn... ) + */ +#define E820_PRAM 12 + +/* + * reserved RAM used by kernel itself + * if CONFIG_INTEL_TXT is enabled, memory of this type will be + * included in the S3 integrity calculation and so should not include + * any memory that BIOS might alter over the S3 transition + */ +#define E820_RESERVED_KERN 128 + +#ifndef __ASSEMBLY__ +#include +struct e820entry { + __u64 addr; /* start of memory segment */ + __u64 size; /* size of memory segment */ + __u32 type; /* type of memory segment */ +} __attribute__((packed)); + +struct e820map { + __u32 nr_map; + struct e820entry map[E820_X_MAX]; +}; + +#define ISA_START_ADDRESS 0xa0000 +#define ISA_END_ADDRESS 0x100000 + +#define BIOS_BEGIN 0x000a0000 +#define BIOS_END 0x00100000 + +#define BIOS_ROM_BASE 0xffe00000 +#define BIOS_ROM_END 0xffffffff + +#endif /* __ASSEMBLY__ */ + + +#endif /* _UAPI_ASM_X86_E820_H */ From 7b80ba55aa2919d5b26021659f025905aaea44ed Mon Sep 17 00:00:00 2001 From: Ingo Molnar Date: Fri, 27 Jan 2017 10:22:23 +0100 Subject: [PATCH 0002/1358] x86/boot/e820: Clean up and improve comments in asm/e820/types.h Do some common-sense cleanups: - standardize on the kernel coding style consistently - tabulate definitions consistently - extend and clarify various descriptions - fix speling - update the header guard name according to the new position - etc. No change in functionality. Cc: Alex Thorlton Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Dan Williams Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Huang, Ying Cc: Josh Poimboeuf Cc: Juergen Gross Cc: Linus Torvalds Cc: Paul Jackson Cc: Peter Zijlstra Cc: Rafael J. Wysocki Cc: Tejun Heo Cc: Thomas Gleixner Cc: Wei Yang Cc: Yinghai Lu Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar --- arch/x86/include/asm/e820/types.h | 84 +++++++++++++++++++------------ 1 file changed, 53 insertions(+), 31 deletions(-) diff --git a/arch/x86/include/asm/e820/types.h b/arch/x86/include/asm/e820/types.h index 9dafe59cf6e2..cfa8f4a19b5d 100644 --- a/arch/x86/include/asm/e820/types.h +++ b/arch/x86/include/asm/e820/types.h @@ -1,18 +1,30 @@ -#ifndef _UAPI_ASM_X86_E820_H -#define _UAPI_ASM_X86_E820_H -#define E820MAP 0x2d0 /* our map */ -#define E820MAX 128 /* number of entries in E820MAP */ +#ifndef _ASM_E820_TYPES_H +#define _ASM_E820_TYPES_H + +/* Our map: */ +#define E820MAP 0x2d0 + +/* The maximum number of entries in E820MAP: */ +#define E820MAX 128 /* - * Legacy E820 BIOS limits us to 128 (E820MAX) nodes due to the - * constrained space in the zeropage. If we have more nodes than - * that, and if we've booted off EFI firmware, then the EFI tables - * passed us from the EFI firmware can list more nodes. Size our - * internal memory map tables to have room for these additional - * nodes, based on up to three entries per node for which the - * kernel was built: MAX_NUMNODES == (1 << CONFIG_NODES_SHIFT), - * plus E820MAX, allowing space for the possible duplicate E820 - * entries that might need room in the same arrays, prior to the + * The legacy E820 BIOS limits us to 128 (E820MAX) nodes due to the + * constrained space in the zeropage. + * + * On large systems we can easily have thousands of nodes with RAM, + * which cannot be fit into so few entries - so we have a mechanism + * to extend the e820 table size at build-time, via the E820_X_MAX + * define below. + * + * ( Those extra entries are enumerated via the EFI memory map, not + * via the legacy zeropage mechanism. ) + * + * Size our internal memory map tables to have room for these additional + * entries, based on a heuristic calculation: up to three entries per + * NUMA node, plus E820MAX for some extra space. + * + * This allows for bootstrap/firmware quirks such as possible duplicate + * E820 entries that might need room in the same arrays, prior to the * call to sanitize_e820_map() to remove duplicates. The allowance * of three memory map entries per node is "enough" entries for * the initial hardware platform motivating this mechanism to make @@ -20,19 +32,19 @@ * to allow more than three entries per node or otherwise refine * this size. */ - #ifndef __KERNEL__ -#define E820_X_MAX E820MAX +# define E820_X_MAX E820MAX #endif -#define E820NR 0x1e8 /* # entries in E820MAP */ +/* Number of entries in E820MAP: */ +#define E820NR 0x1e8 -#define E820_RAM 1 -#define E820_RESERVED 2 -#define E820_ACPI 3 -#define E820_NVS 4 -#define E820_UNUSABLE 5 -#define E820_PMEM 7 +#define E820_RAM 1 +#define E820_RESERVED 2 +#define E820_ACPI 3 +#define E820_NVS 4 +#define E820_UNUSABLE 5 +#define E820_PMEM 7 /* * This is a non-standardized way to represent ADR or NVDIMM regions that @@ -43,7 +55,7 @@ * but newer versions switched to 12 as 6 was assigned differently. Some * time they will learn... ) */ -#define E820_PRAM 12 +#define E820_PRAM 12 /* * reserved RAM used by kernel itself @@ -51,23 +63,34 @@ * included in the S3 integrity calculation and so should not include * any memory that BIOS might alter over the S3 transition */ -#define E820_RESERVED_KERN 128 +#define E820_RESERVED_KERN 128 #ifndef __ASSEMBLY__ #include + +/* + * A single E820 map entry, describing a memory range of [addr...addr+size-1], + * of 'type' memory type: + */ struct e820entry { - __u64 addr; /* start of memory segment */ - __u64 size; /* size of memory segment */ - __u32 type; /* type of memory segment */ + __u64 addr; + __u64 size; + __u32 type; } __attribute__((packed)); +/* + * The whole array of E820 entries: + */ struct e820map { __u32 nr_map; struct e820entry map[E820_X_MAX]; }; -#define ISA_START_ADDRESS 0xa0000 -#define ISA_END_ADDRESS 0x100000 +/* + * Various legacy ranges in physical memory: + */ +#define ISA_START_ADDRESS 0x000a0000 +#define ISA_END_ADDRESS 0x00100000 #define BIOS_BEGIN 0x000a0000 #define BIOS_END 0x00100000 @@ -77,5 +100,4 @@ struct e820map { #endif /* __ASSEMBLY__ */ - -#endif /* _UAPI_ASM_X86_E820_H */ +#endif /* _ASM_E820_TYPES_H */ From 66441bd3cfdcc03816b7009a296c284d70f629e1 Mon Sep 17 00:00:00 2001 From: Ingo Molnar Date: Fri, 27 Jan 2017 10:27:10 +0100 Subject: [PATCH 0003/1358] x86/boot/e820: Move asm/e820.h to asm/e820/api.h In line with asm/e820/types.h, move the e820 API declarations to asm/e820/api.h and update all usage sites. This is just a mechanical, obviously correct move & replace patch, there will be subsequent changes to clean up the code and to make better use of the new header organization. Cc: Alex Thorlton Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Dan Williams Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Huang, Ying Cc: Josh Poimboeuf Cc: Juergen Gross Cc: Linus Torvalds Cc: Paul Jackson Cc: Peter Zijlstra Cc: Rafael J. Wysocki Cc: Tejun Heo Cc: Thomas Gleixner Cc: Wei Yang Cc: Yinghai Lu Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar --- arch/x86/boot/header.S | 2 +- arch/x86/include/asm/{e820.h => e820/api.h} | 6 +++--- arch/x86/include/asm/gart.h | 2 +- arch/x86/include/asm/pgtable.h | 2 +- arch/x86/include/uapi/asm/bootparam.h | 2 +- arch/x86/kernel/aperture_64.c | 2 +- arch/x86/kernel/apic/apic_noop.c | 2 +- arch/x86/kernel/apic/probe_32.c | 2 +- arch/x86/kernel/cpu/centaur.c | 2 +- arch/x86/kernel/cpu/mtrr/cleanup.c | 2 +- arch/x86/kernel/cpu/mtrr/main.c | 2 +- arch/x86/kernel/e820.c | 2 +- arch/x86/kernel/head32.c | 2 +- arch/x86/kernel/head64.c | 2 +- arch/x86/kernel/mpparse.c | 2 +- arch/x86/kernel/probe_roms.c | 2 +- arch/x86/kernel/resource.c | 2 +- arch/x86/kernel/setup.c | 2 +- arch/x86/kernel/tboot.c | 2 +- arch/x86/kernel/x86_init.c | 2 +- arch/x86/lguest/boot.c | 2 +- arch/x86/lib/kaslr.c | 2 +- arch/x86/mm/amdtopology.c | 2 +- arch/x86/mm/init.c | 2 +- arch/x86/mm/init_32.c | 2 +- arch/x86/mm/init_64.c | 2 +- arch/x86/mm/ioremap.c | 2 +- arch/x86/mm/mmio-mod.c | 2 +- arch/x86/mm/numa.c | 2 +- arch/x86/mm/pageattr.c | 2 +- arch/x86/mm/pat.c | 2 +- arch/x86/mm/pgtable_32.c | 2 +- arch/x86/mm/srat.c | 2 +- arch/x86/pci/i386.c | 2 +- arch/x86/pci/mmconfig-shared.c | 2 +- arch/x86/pci/mmconfig_32.c | 2 +- arch/x86/pci/mmconfig_64.c | 2 +- arch/x86/platform/efi/efi_64.c | 2 +- arch/x86/xen/mmu.c | 2 +- arch/x86/xen/setup.c | 2 +- drivers/char/agp/amd64-agp.c | 2 +- 41 files changed, 43 insertions(+), 43 deletions(-) rename arch/x86/include/asm/{e820.h => e820/api.h} (96%) diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S index 3dd5be33aaa7..398b290c4c00 100644 --- a/arch/x86/boot/header.S +++ b/arch/x86/boot/header.S @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820/api.h similarity index 96% rename from arch/x86/include/asm/e820.h rename to arch/x86/include/asm/e820/api.h index 55c1d76c169f..010efbceb40c 100644 --- a/arch/x86/include/asm/e820.h +++ b/arch/x86/include/asm/e820/api.h @@ -1,5 +1,5 @@ -#ifndef _ASM_X86_E820_H -#define _ASM_X86_E820_H +#ifndef _ASM_E820_API_H +#define _ASM_E820_API_H /* * E820_X_MAX is the maximum size of the extended E820 table. The extended @@ -70,4 +70,4 @@ static inline bool is_ISA_range(u64 s, u64 e) #include #define HIGH_MEMORY (1024*1024) -#endif /* _ASM_X86_E820_H */ +#endif /* _ASM_E820_API_H */ diff --git a/arch/x86/include/asm/gart.h b/arch/x86/include/asm/gart.h index 156cd5d18d2a..e26a5d7fc368 100644 --- a/arch/x86/include/asm/gart.h +++ b/arch/x86/include/asm/gart.h @@ -1,7 +1,7 @@ #ifndef _ASM_X86_GART_H #define _ASM_X86_GART_H -#include +#include extern void set_up_gart_resume(u32, u32); diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 437feb436efa..ae0b84d8ccb5 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -2,7 +2,7 @@ #define _ASM_X86_PGTABLE_H #include -#include +#include #include diff --git a/arch/x86/include/uapi/asm/bootparam.h b/arch/x86/include/uapi/asm/bootparam.h index b10bf319ed20..2214bfc65c66 100644 --- a/arch/x86/include/uapi/asm/bootparam.h +++ b/arch/x86/include/uapi/asm/bootparam.h @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include