linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code
@ 2017-01-28 22:11 Ingo Molnar
  2017-01-28 22:11 ` [PATCH 01/50] x86/boot/e820: Introduce arch/x86/include/asm/e820/types.h Ingo Molnar
                   ` (49 more replies)
  0 siblings, 50 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

When reviewing an E820 patch two days ago I noticed that our E820 code
in arch/x86/kernel/e820.c has bitrotten quite a bit, and started
cleaning it up a bit.

Didn't suspect that I'd end up with 50 patches, but oh well ...

The code got the usual treatments to turn it into a modern, cleanly
structured kernel facility:

 - split the e820.h header split into asm/e820/types.h and asm/e820/api.h
   and moved most of it out of the UAPI export,

 - eliminated a number of header dependency hell related
   to the E820 code,

 - clarified and standardized the API names, the variable names, the
   overall code style and the comments,

 - cleaned up and modernized the various basic types used,

 - fixed a ton of comments and weird constructs and added comments
   where they were missing.

There's a lot more: see the individual patches for details. There's no
big functional changes, but the overall diffstat is pretty significant,
due to cleaning out of 10+ years of gradually accumulated cruft.

It should now be possible for someone to understand the code from first
principles, without too much hassle.

The patches can also be accessed in the following Git tree:

   git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git WIP.x86/boot

The code has been through a fair amount of testing, but only on a limited
number of test systems.

Ingo Molnar (50):
  x86/boot/e820: Introduce arch/x86/include/asm/e820/types.h
  x86/boot/e820: Clean up and improve comments in asm/e820/types.h
  x86/boot/e820: Move asm/e820.h to asm/e820/api.h
  x86/boot/e820: Split minimal UAPI types out into uapi/asm/e820/types.h
  x86/boot/e820: Clean up the E820_X_MAX definition
  x86/boot/e820: Remove spurious asm/e820/api.h inclusions
  x86/boot/e820: Remove assembly guard from asm/e820/types.h
  x86/boot/e820: Clean up asm/e820/api.h
  x86/boot/e820: Remove unnecessary __ASSEMBLY__ guard
  x86/boot/e820: Move HIGH_MEMORY define to asm/e820/types.h
  x86/boot/e820: Rename the basic e820 data types to 'struct e820_entry' and 'struct e820_array'
  x86/boot/e820: Remove unnecessary #include <linux/ioport.h> from asm/e820/api.h
  x86/boot/e820: Remove e820_mark_nosave_regions() definition uglies
  x86/boot/e820: Rename 'e820_map' variables to 'e820_array'
  x86/boot/e820: Rename everything to e820_table
  x86/boot/e820: Harmonize the 'struct e820_table' fields
  x86/boot/e820: Rename default_machine_specific_memory_setup() to e820__memory_setup_default()
  x86/boot/e820: Rename e820_table_saved to e820_table_firmware and improve the description
  x86/boot/e820: Basic cleanup of e820.c
  x86/boot/e820: Rename memblock_x86_fill() to e820__memblock_setup() and improve the explanations
  x86/boot/e820: Consolidate 'struct e820_entry *entry' local variable names
  x86/boot/e820: Convert printk(KERN_* ...) to pr_*()
  x86/boot/e820: Move the memblock_find_dma_reserve() function and rename it to memblock_set_dma_reserve()
  x86/boot/e820: Rename parse_e820_ext() to e820__memory_setup_extended()
  x86/boot/e820: Move e820_reserve_setup_data() to e820.c
  x86/boot/e820: Clarify the role of finish_e820_parsing() and rename it to e820__finish_early_params()
  x86/boot/e820: Rename early_reserve_e820() to e820__memblock_alloc() and document it
  x86/boot/e820: Rename update_e820() to e820__update_table()
  x86/boot/e820: Rename sanitize_e820_table() to e820__update_table()
  x86/boot/e820: Rename e820_any_mapped()/e820_all_mapped() to e820__mapped_any()/e820__mapped_all()
  x86/boot/e820: Rename e820_setup_gap() to e820__setup_pci_gap()
  x86/boot/e820: Create coherent API function names for E820 range operations
  x86/boot/e820: Rename e820_print_map() to e820__print_table()
  x86/boot/e820: Reorder the function prototypes in api.h
  x86/boot/e820: Simplify e820_reserve_resources()
  x86/boot/e820: Introduce 'enum e820_type'
  x86/boot/e820: Use 'enum e820_type' in 'struct e820_entry'
  x86/boot/e820: Use 'enum e820_type' when handling the e820 region type
  x86/boot/e820: Prefix the E820_* type names with "E820_TYPE_"
  x86/boot/e820: Clean up the E820 table size define names
  x86/boot/e820: Clean up and standardize sizeof() uses
  xen, x86/boot/e820: Simplify Xen's xen_e820_table construct
  x86/boot/e820: Simplify the e820__update_table() interface
  x86/boot/e820: Clean up __e820__update_table() et al
  x86/boot/e820: Document e820__reserve_setup_data()
  x86/boot/e820: Use bool in query APIs
  x86/boot/e820: Rename e820_reserve_resources*() to e820__reserve_resources*()
  x86/boot/e820: Rename e820_mark_nosave_regions() to e820__register_nosave_regions()
  x86/boot/e820: Remove unnecessary #include's
  x86/boot/e820: Rename the remaining E820 APIs to the e820__*() prefix

 Documentation/x86/zero-page.txt        |    6 +-
 arch/x86/boot/compressed/eboot.c       |   44 +--
 arch/x86/boot/compressed/kaslr.c       |    6 +-
 arch/x86/boot/header.S                 |    1 -
 arch/x86/boot/memory.c                 |    6 +-
 arch/x86/include/asm/acpi.h            |    2 +
 arch/x86/include/asm/e820.h            |   73 ----
 arch/x86/include/asm/e820/api.h        |   50 +++
 arch/x86/include/asm/e820/types.h      |   58 +++
 arch/x86/include/asm/gart.h            |    4 +-
 arch/x86/include/asm/mpspec.h          |    4 +-
 arch/x86/include/asm/pci_x86.h         |    2 +
 arch/x86/include/asm/pgtable.h         |    3 +-
 arch/x86/include/uapi/asm/bootparam.h  |    4 +-
 arch/x86/include/uapi/asm/e820/types.h |   55 +++
 arch/x86/kernel/acpi/boot.c            |    5 +-
 arch/x86/kernel/aperture_64.c          |   10 +-
 arch/x86/kernel/apic/apic.c            |    2 +-
 arch/x86/kernel/apic/apic_noop.c       |    2 +-
 arch/x86/kernel/apic/probe_32.c        |    2 +-
 arch/x86/kernel/apic/x2apic_uv_x.c     |    1 +
 arch/x86/kernel/cpu/centaur.c          |    2 +-
 arch/x86/kernel/cpu/mtrr/cleanup.c     |    6 +-
 arch/x86/kernel/cpu/mtrr/main.c        |    2 +-
 arch/x86/kernel/crash.c                |   23 +-
 arch/x86/kernel/e820.c                 | 1032 ++++++++++++++++++++++++++--------------------------
 arch/x86/kernel/early-quirks.c         |    4 +-
 arch/x86/kernel/head32.c               |    2 +-
 arch/x86/kernel/head64.c               |    2 +-
 arch/x86/kernel/kexec-bzimage64.c      |   18 +-
 arch/x86/kernel/mpparse.c              |    6 +-
 arch/x86/kernel/probe_roms.c           |    2 +-
 arch/x86/kernel/resource.c             |    8 +-
 arch/x86/kernel/setup.c                |   78 ++--
 arch/x86/kernel/tboot.c                |   16 +-
 arch/x86/kernel/x86_init.c             |    4 +-
 arch/x86/lguest/boot.c                 |    8 +-
 arch/x86/lib/kaslr.c                   |    2 +-
 arch/x86/mm/amdtopology.c              |    2 +-
 arch/x86/mm/init.c                     |   59 ++-
 arch/x86/mm/init_32.c                  |    2 +-
 arch/x86/mm/init_64.c                  |   26 +-
 arch/x86/mm/ioremap.c                  |    3 +-
 arch/x86/mm/kasan_init_64.c            |    5 +-
 arch/x86/mm/mmio-mod.c                 |    2 +-
 arch/x86/mm/numa.c                     |    2 +-
 arch/x86/mm/pageattr.c                 |    2 +-
 arch/x86/mm/pat.c                      |    3 +-
 arch/x86/mm/pgtable_32.c               |    2 +-
 arch/x86/mm/srat.c                     |    2 +-
 arch/x86/pci/i386.c                    |    4 +-
 arch/x86/pci/mmconfig-shared.c         |   22 +-
 arch/x86/pci/mmconfig_32.c             |    2 +-
 arch/x86/pci/mmconfig_64.c             |    2 +-
 arch/x86/pci/pcbios.c                  |    2 +
 arch/x86/platform/efi/efi.c            |   19 +-
 arch/x86/platform/efi/efi_64.c         |    2 +-
 arch/x86/platform/efi/quirks.c         |    8 +-
 arch/x86/power/hibernate_64.c          |   16 +-
 arch/x86/xen/mmu.c                     |    2 +-
 arch/x86/xen/setup.c                   |   97 +++--
 drivers/acpi/tables.c                  |    2 +-
 drivers/char/agp/amd64-agp.c           |    2 +-
 include/xen/page.h                     |    2 +-
 tools/lguest/lguest.c                  |    2 +-
 65 files changed, 989 insertions(+), 860 deletions(-)
 delete mode 100644 arch/x86/include/asm/e820.h
 create mode 100644 arch/x86/include/asm/e820/api.h
 create mode 100644 arch/x86/include/asm/e820/types.h
 create mode 100644 arch/x86/include/uapi/asm/e820/types.h

-- 
2.7.4

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [PATCH 01/50] x86/boot/e820: Introduce arch/x86/include/asm/e820/types.h
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-29 17:13   ` Sam Ravnborg
  2017-01-28 22:11 ` [PATCH 02/50] x86/boot/e820: Clean up and improve comments in asm/e820/types.h Ingo Molnar
                   ` (48 subsequent siblings)
  49 siblings, 1 reply; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

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 <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820.h       |  4 +--
 arch/x86/include/asm/e820/types.h | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 83 insertions(+), 2 deletions(-)

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 <linux/numa.h>
 #define E820_X_MAX (E820MAX + 3 * MAX_NUMNODES)
 
-#include <uapi/asm/e820.h>
+#include <asm/e820/types.h>
 
 #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 <linux/types.h>
+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 */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 02/50] x86/boot/e820: Clean up and improve comments in asm/e820/types.h
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
  2017-01-28 22:11 ` [PATCH 01/50] x86/boot/e820: Introduce arch/x86/include/asm/e820/types.h Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 03/50] x86/boot/e820: Move asm/e820.h to asm/e820/api.h Ingo Molnar
                   ` (47 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

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 <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 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 <linux/types.h>
+
+/*
+ * 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 */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 03/50] x86/boot/e820: Move asm/e820.h to asm/e820/api.h
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
  2017-01-28 22:11 ` [PATCH 01/50] x86/boot/e820: Introduce arch/x86/include/asm/e820/types.h Ingo Molnar
  2017-01-28 22:11 ` [PATCH 02/50] x86/boot/e820: Clean up and improve comments in asm/e820/types.h Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 04/50] x86/boot/e820: Split minimal UAPI types out into uapi/asm/e820/types.h Ingo Molnar
                   ` (46 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

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 <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 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(-)

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 <asm/segment.h>
 #include <generated/utsrelease.h>
 #include <asm/boot.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/page_types.h>
 #include <asm/setup.h>
 #include <asm/bootparam.h>
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 <linux/ioport.h>
 
 #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 <asm/e820.h>
+#include <asm/e820/api.h>
 
 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 <asm/page.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 
 #include <asm/pgtable_types.h>
 
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 <linux/screen_info.h>
 #include <linux/apm_bios.h>
 #include <linux/edd.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/ist.h>
 #include <video/edid.h>
 
diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
index 0a2bb1f62e72..d8185a31933b 100644
--- a/arch/x86/kernel/aperture_64.c
+++ b/arch/x86/kernel/aperture_64.c
@@ -21,7 +21,7 @@
 #include <linux/pci.h>
 #include <linux/bitops.h>
 #include <linux/suspend.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/io.h>
 #include <asm/iommu.h>
 #include <asm/gart.h>
diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
index b109e4389c92..2262eb6df796 100644
--- a/arch/x86/kernel/apic/apic_noop.c
+++ b/arch/x86/kernel/apic/apic_noop.c
@@ -26,7 +26,7 @@
 
 #include <linux/interrupt.h>
 #include <asm/acpi.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 
 static void noop_init_apic_ldr(void) { }
 static void noop_send_IPI(int cpu, int vector) { }
diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
index c48264e202fd..2e8f7f048f4f 100644
--- a/arch/x86/kernel/apic/probe_32.c
+++ b/arch/x86/kernel/apic/probe_32.c
@@ -25,7 +25,7 @@
 
 #include <linux/interrupt.h>
 #include <asm/acpi.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 
 #ifdef CONFIG_HOTPLUG_CPU
 #define DEFAULT_SEND_IPI	(1)
diff --git a/arch/x86/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c
index 1661d8ec9280..48d4ff2d9798 100644
--- a/arch/x86/kernel/cpu/centaur.c
+++ b/arch/x86/kernel/cpu/centaur.c
@@ -2,7 +2,7 @@
 #include <linux/kernel.h>
 
 #include <asm/cpufeature.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/mtrr.h>
 #include <asm/msr.h>
 
diff --git a/arch/x86/kernel/cpu/mtrr/cleanup.c b/arch/x86/kernel/cpu/mtrr/cleanup.c
index 3b442b64c72d..f1a7365e14b0 100644
--- a/arch/x86/kernel/cpu/mtrr/cleanup.c
+++ b/arch/x86/kernel/cpu/mtrr/cleanup.c
@@ -27,7 +27,7 @@
 #include <linux/range.h>
 
 #include <asm/processor.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/mtrr.h>
 #include <asm/msr.h>
 
diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
index 24e87e74990d..2bce84d91c2b 100644
--- a/arch/x86/kernel/cpu/mtrr/main.c
+++ b/arch/x86/kernel/cpu/mtrr/main.c
@@ -48,7 +48,7 @@
 #include <linux/syscore_ops.h>
 
 #include <asm/cpufeature.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/mtrr.h>
 #include <asm/msr.h>
 #include <asm/pat.h>
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index b2bbad6ebe4d..49d54c5002fa 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -21,7 +21,7 @@
 #include <linux/memblock.h>
 #include <linux/sort.h>
 
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/proto.h>
 #include <asm/setup.h>
 #include <asm/cpufeature.h>
diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
index e5fb436a6548..538ec012b371 100644
--- a/arch/x86/kernel/head32.c
+++ b/arch/x86/kernel/head32.c
@@ -12,7 +12,7 @@
 
 #include <asm/setup.h>
 #include <asm/sections.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/page.h>
 #include <asm/apic.h>
 #include <asm/io_apic.h>
diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index 54a2372f5dbb..baa0e7b78d80 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -23,7 +23,7 @@
 #include <asm/tlbflush.h>
 #include <asm/sections.h>
 #include <asm/kdebug.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/bios_ebda.h>
 #include <asm/bootparam_utils.h>
 #include <asm/microcode.h>
diff --git a/arch/x86/kernel/mpparse.c b/arch/x86/kernel/mpparse.c
index 0f8d20497383..1e3320788510 100644
--- a/arch/x86/kernel/mpparse.c
+++ b/arch/x86/kernel/mpparse.c
@@ -26,7 +26,7 @@
 #include <asm/io_apic.h>
 #include <asm/proto.h>
 #include <asm/bios_ebda.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/setup.h>
 #include <asm/smp.h>
 
diff --git a/arch/x86/kernel/probe_roms.c b/arch/x86/kernel/probe_roms.c
index d5f15c3f7b25..963e3fb56437 100644
--- a/arch/x86/kernel/probe_roms.c
+++ b/arch/x86/kernel/probe_roms.c
@@ -14,7 +14,7 @@
 
 #include <asm/probe_roms.h>
 #include <asm/pci-direct.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/mmzone.h>
 #include <asm/setup.h>
 #include <asm/sections.h>
diff --git a/arch/x86/kernel/resource.c b/arch/x86/kernel/resource.c
index 2408c1603438..eb2021659c9e 100644
--- a/arch/x86/kernel/resource.c
+++ b/arch/x86/kernel/resource.c
@@ -1,5 +1,5 @@
 #include <linux/ioport.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 
 static void resource_clip(struct resource *res, resource_size_t start,
 			  resource_size_t end)
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 4cfba947d774..6e521831f6ba 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -75,7 +75,7 @@
 #include <asm/mtrr.h>
 #include <asm/apic.h>
 #include <asm/realmode.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/mpspec.h>
 #include <asm/setup.h>
 #include <asm/efi.h>
diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
index b868fa1b812b..d047da50f2de 100644
--- a/arch/x86/kernel/tboot.c
+++ b/arch/x86/kernel/tboot.c
@@ -42,7 +42,7 @@
 #include <asm/fixmap.h>
 #include <asm/proto.h>
 #include <asm/setup.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/io.h>
 
 #include "../realmode/rm/wakeup.h"
diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
index 11a93f005268..512cb45264d0 100644
--- a/arch/x86/kernel/x86_init.c
+++ b/arch/x86/kernel/x86_init.c
@@ -14,7 +14,7 @@
 #include <asm/mpspec.h>
 #include <asm/setup.h>
 #include <asm/apic.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/time.h>
 #include <asm/irq.h>
 #include <asm/io_apic.h>
diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
index d3289d7e78fa..638d997327c9 100644
--- a/arch/x86/lguest/boot.c
+++ b/arch/x86/lguest/boot.c
@@ -67,7 +67,7 @@
 #include <asm/pgtable.h>
 #include <asm/desc.h>
 #include <asm/setup.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/mce.h>
 #include <asm/io.h>
 #include <asm/fpu/api.h>
diff --git a/arch/x86/lib/kaslr.c b/arch/x86/lib/kaslr.c
index 121f59c6ee54..5761a4f19455 100644
--- a/arch/x86/lib/kaslr.c
+++ b/arch/x86/lib/kaslr.c
@@ -8,7 +8,7 @@
 #include <asm/kaslr.h>
 #include <asm/msr.h>
 #include <asm/archrandom.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/io.h>
 
 /*
diff --git a/arch/x86/mm/amdtopology.c b/arch/x86/mm/amdtopology.c
index d1c7de095808..91f501b2da3b 100644
--- a/arch/x86/mm/amdtopology.c
+++ b/arch/x86/mm/amdtopology.c
@@ -19,7 +19,7 @@
 #include <asm/types.h>
 #include <asm/mmzone.h>
 #include <asm/proto.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/pci-direct.h>
 #include <asm/numa.h>
 #include <asm/mpspec.h>
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 22af912d66d2..b7b4ad569d13 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -6,7 +6,7 @@
 #include <linux/bootmem.h>	/* for max_low_pfn */
 
 #include <asm/cacheflush.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/init.h>
 #include <asm/page.h>
 #include <asm/page_types.h>
diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
index 928d657de829..70e1ad66d34a 100644
--- a/arch/x86/mm/init_32.c
+++ b/arch/x86/mm/init_32.c
@@ -38,7 +38,7 @@
 #include <asm/pgtable.h>
 #include <asm/dma.h>
 #include <asm/fixmap.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/apic.h>
 #include <asm/bugs.h>
 #include <asm/tlb.h>
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index af85b686a7b0..ad7a477f3423 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -41,7 +41,7 @@
 #include <asm/pgalloc.h>
 #include <asm/dma.h>
 #include <asm/fixmap.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/apic.h>
 #include <asm/tlb.h>
 #include <asm/mmu_context.h>
diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index 7aaa2635862d..d4f2b40a9641 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -14,7 +14,7 @@
 #include <linux/mmiotrace.h>
 
 #include <asm/cacheflush.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/fixmap.h>
 #include <asm/pgtable.h>
 #include <asm/tlbflush.h>
diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
index bef36622e408..4d434ddb75db 100644
--- a/arch/x86/mm/mmio-mod.c
+++ b/arch/x86/mm/mmio-mod.c
@@ -32,7 +32,7 @@
 #include <linux/kallsyms.h>
 #include <asm/pgtable.h>
 #include <linux/mmiotrace.h>
-#include <asm/e820.h> /* for ISA_START_ADDRESS */
+#include <asm/e820/api.h> /* for ISA_START_ADDRESS */
 #include <linux/atomic.h>
 #include <linux/percpu.h>
 #include <linux/cpu.h>
diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
index 12dcad7297a5..f9d99535f233 100644
--- a/arch/x86/mm/numa.c
+++ b/arch/x86/mm/numa.c
@@ -12,7 +12,7 @@
 #include <linux/sched.h>
 #include <linux/topology.h>
 
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/proto.h>
 #include <asm/dma.h>
 #include <asm/amd_nb.h>
diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index 5a287e523eab..3e1577622cb0 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -15,7 +15,7 @@
 #include <linux/pci.h>
 #include <linux/vmalloc.h>
 
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/processor.h>
 #include <asm/tlbflush.h>
 #include <asm/sections.h>
diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
index efc32bc6862b..41b0f2f3d90b 100644
--- a/arch/x86/mm/pat.c
+++ b/arch/x86/mm/pat.c
@@ -23,7 +23,7 @@
 #include <asm/x86_init.h>
 #include <asm/pgtable.h>
 #include <asm/fcntl.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/mtrr.h>
 #include <asm/page.h>
 #include <asm/msr.h>
diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
index 9adce776852b..de53c52551a5 100644
--- a/arch/x86/mm/pgtable_32.c
+++ b/arch/x86/mm/pgtable_32.c
@@ -12,7 +12,7 @@
 #include <asm/pgtable.h>
 #include <asm/pgalloc.h>
 #include <asm/fixmap.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/tlb.h>
 #include <asm/tlbflush.h>
 #include <asm/io.h>
diff --git a/arch/x86/mm/srat.c b/arch/x86/mm/srat.c
index 35fe69529bc1..3ea20d61b523 100644
--- a/arch/x86/mm/srat.c
+++ b/arch/x86/mm/srat.c
@@ -18,7 +18,7 @@
 #include <linux/mm.h>
 #include <asm/proto.h>
 #include <asm/numa.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/apic.h>
 #include <asm/uv/uv.h>
 
diff --git a/arch/x86/pci/i386.c b/arch/x86/pci/i386.c
index 0a9f2caf358f..9a074431174f 100644
--- a/arch/x86/pci/i386.c
+++ b/arch/x86/pci/i386.c
@@ -34,7 +34,7 @@
 #include <linux/bootmem.h>
 
 #include <asm/pat.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/pci_x86.h>
 #include <asm/io_apic.h>
 
diff --git a/arch/x86/pci/mmconfig-shared.c b/arch/x86/pci/mmconfig-shared.c
index dd30b7e08bc2..767199edef74 100644
--- a/arch/x86/pci/mmconfig-shared.c
+++ b/arch/x86/pci/mmconfig-shared.c
@@ -18,7 +18,7 @@
 #include <linux/slab.h>
 #include <linux/mutex.h>
 #include <linux/rculist.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/pci_x86.h>
 #include <asm/acpi.h>
 
diff --git a/arch/x86/pci/mmconfig_32.c b/arch/x86/pci/mmconfig_32.c
index 43984bc1665a..3e9e166f6408 100644
--- a/arch/x86/pci/mmconfig_32.c
+++ b/arch/x86/pci/mmconfig_32.c
@@ -12,7 +12,7 @@
 #include <linux/pci.h>
 #include <linux/init.h>
 #include <linux/rcupdate.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/pci_x86.h>
 
 /* Assume systems with more busses have correct MCFG */
diff --git a/arch/x86/pci/mmconfig_64.c b/arch/x86/pci/mmconfig_64.c
index bea52496aea6..f1c1aa0430ae 100644
--- a/arch/x86/pci/mmconfig_64.c
+++ b/arch/x86/pci/mmconfig_64.c
@@ -10,7 +10,7 @@
 #include <linux/acpi.h>
 #include <linux/bitmap.h>
 #include <linux/rcupdate.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/pci_x86.h>
 
 #define PREFIX "PCI: "
diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
index 319148bd4b05..2cc992be0070 100644
--- a/arch/x86/platform/efi/efi_64.c
+++ b/arch/x86/platform/efi/efi_64.c
@@ -35,7 +35,7 @@
 
 #include <asm/setup.h>
 #include <asm/page.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/pgtable.h>
 #include <asm/tlbflush.h>
 #include <asm/proto.h>
diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
index 7d5afdb417cc..e28352ae2eca 100644
--- a/arch/x86/xen/mmu.c
+++ b/arch/x86/xen/mmu.c
@@ -58,7 +58,7 @@
 #include <asm/mmu_context.h>
 #include <asm/setup.h>
 #include <asm/paravirt.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/linkage.h>
 #include <asm/page.h>
 #include <asm/init.h>
diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
index f3f7b41116f7..dd6ec15f91d4 100644
--- a/arch/x86/xen/setup.c
+++ b/arch/x86/xen/setup.c
@@ -14,7 +14,7 @@
 
 #include <asm/elf.h>
 #include <asm/vdso.h>
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/setup.h>
 #include <asm/acpi.h>
 #include <asm/numa.h>
diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
index 0ef350010766..c99cd19d9147 100644
--- a/drivers/char/agp/amd64-agp.c
+++ b/drivers/char/agp/amd64-agp.c
@@ -14,7 +14,7 @@
 #include <linux/agp_backend.h>
 #include <linux/mmzone.h>
 #include <asm/page.h>		/* PAGE_SIZE */
-#include <asm/e820.h>
+#include <asm/e820/api.h>
 #include <asm/amd_nb.h>
 #include <asm/gart.h>
 #include "agp.h"
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 04/50] x86/boot/e820: Split minimal UAPI types out into uapi/asm/e820/types.h
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (2 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 03/50] x86/boot/e820: Move asm/e820.h to asm/e820/api.h Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 05/50] x86/boot/e820: Clean up the E820_X_MAX definition Ingo Molnar
                   ` (45 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

bootparam.h, which defines the legacy 'zeropage' boot parameter area,
requires a small amount of e280 defines in the UAPI space - provide them.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/acpi.h            |  2 ++
 arch/x86/include/asm/e820/types.h      | 15 ++-------------
 arch/x86/include/uapi/asm/bootparam.h  |  2 +-
 arch/x86/include/uapi/asm/e820/types.h | 21 +++++++++++++++++++++
 4 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/arch/x86/include/asm/acpi.h b/arch/x86/include/asm/acpi.h
index 395b69551fce..2efc768e4362 100644
--- a/arch/x86/include/asm/acpi.h
+++ b/arch/x86/include/asm/acpi.h
@@ -52,6 +52,8 @@ extern u8 acpi_sci_flags;
 extern int acpi_sci_override_gsi;
 void acpi_pic_sci_set_trigger(unsigned int, u16);
 
+struct device;
+
 extern int (*__acpi_register_gsi)(struct device *dev, u32 gsi,
 				  int trigger, int polarity);
 extern void (*__acpi_unregister_gsi)(u32 gsi);
diff --git a/arch/x86/include/asm/e820/types.h b/arch/x86/include/asm/e820/types.h
index cfa8f4a19b5d..cf73c104c041 100644
--- a/arch/x86/include/asm/e820/types.h
+++ b/arch/x86/include/asm/e820/types.h
@@ -1,12 +1,11 @@
 #ifndef _ASM_E820_TYPES_H
 #define _ASM_E820_TYPES_H
 
+#include <uapi/asm/e820/types.h>
+
 /* Our map: */
 #define E820MAP			0x2d0
 
-/* The maximum number of entries in E820MAP: */
-#define E820MAX			128
-
 /*
  * The legacy E820 BIOS limits us to 128 (E820MAX) nodes due to the
  * constrained space in the zeropage.
@@ -69,16 +68,6 @@
 #include <linux/types.h>
 
 /*
- * A single E820 map entry, describing a memory range of [addr...addr+size-1],
- * of 'type' memory type:
- */
-struct e820entry {
-	__u64 addr;
-	__u64 size;
-	__u32 type;
-} __attribute__((packed));
-
-/*
  * The whole array of E820 entries:
  */
 struct e820map {
diff --git a/arch/x86/include/uapi/asm/bootparam.h b/arch/x86/include/uapi/asm/bootparam.h
index 2214bfc65c66..742333c3ffea 100644
--- a/arch/x86/include/uapi/asm/bootparam.h
+++ b/arch/x86/include/uapi/asm/bootparam.h
@@ -34,7 +34,7 @@
 #include <linux/screen_info.h>
 #include <linux/apm_bios.h>
 #include <linux/edd.h>
-#include <asm/e820/api.h>
+#include <uapi/asm/e820/types.h>
 #include <asm/ist.h>
 #include <video/edid.h>
 
diff --git a/arch/x86/include/uapi/asm/e820/types.h b/arch/x86/include/uapi/asm/e820/types.h
new file mode 100644
index 000000000000..8e522eb120aa
--- /dev/null
+++ b/arch/x86/include/uapi/asm/e820/types.h
@@ -0,0 +1,21 @@
+#ifndef _UAPI_ASM_E820_TYPES_H
+#define _UAPI_ASM_E820_TYPES_H
+
+/* The maximum number of entries in E820MAP: */
+#define E820MAX			128
+
+#ifndef __ASSEMBLY__
+
+/*
+ * A single E820 map entry, describing a memory range of [addr...addr+size-1],
+ * of 'type' memory type:
+ */
+struct e820entry {
+	__u64 addr;
+	__u64 size;
+	__u32 type;
+} __attribute__((packed));
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _UAPI_ASM_E820_TYPES_H */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 05/50] x86/boot/e820: Clean up the E820_X_MAX definition
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (3 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 04/50] x86/boot/e820: Split minimal UAPI types out into uapi/asm/e820/types.h Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 06/50] x86/boot/e820: Remove spurious asm/e820/api.h inclusions Ingo Molnar
                   ` (44 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

E820_X_MAX is defined in a somewhat messy fashion:

 - there's a pretty pointless looking #ifndef __KERNEL__ define that
   makes no sense in the non-UAPI header anymore,

 - part of it is defined in api.h, which is not for type definitions,

 - plus it's defined in two headers and the main explanation is in the
   header where we don't have the real definition.

So move it into a single place in e820/types.h and get rid of the
!__KERNEL__ case altogether. Drop the smaller comment - the larger
one explains it just fine.

Note that the zeropage does not use E820_X_MAX, it uses the legacy
128 entries definition.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h   |  9 ---------
 arch/x86/include/asm/e820/types.h | 13 +++++++------
 2 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 010efbceb40c..e161deb5736c 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -1,15 +1,6 @@
 #ifndef _ASM_E820_API_H
 #define _ASM_E820_API_H
 
-/*
- * 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 asm/e820/types.h.
- */
-#include <linux/numa.h>
-#define E820_X_MAX (E820MAX + 3 * MAX_NUMNODES)
-
 #include <asm/e820/types.h>
 
 #ifndef __ASSEMBLY__
diff --git a/arch/x86/include/asm/e820/types.h b/arch/x86/include/asm/e820/types.h
index cf73c104c041..b05e812ff4f2 100644
--- a/arch/x86/include/asm/e820/types.h
+++ b/arch/x86/include/asm/e820/types.h
@@ -3,9 +3,6 @@
 
 #include <uapi/asm/e820/types.h>
 
-/* Our map: */
-#define E820MAP			0x2d0
-
 /*
  * The legacy E820 BIOS limits us to 128 (E820MAX) nodes due to the
  * constrained space in the zeropage.
@@ -31,9 +28,13 @@
  * to allow more than three entries per node or otherwise refine
  * this size.
  */
-#ifndef __KERNEL__
-# define E820_X_MAX		E820MAX
-#endif
+
+#include <linux/numa.h>
+
+#define E820_X_MAX		(E820MAX + 3*MAX_NUMNODES)
+
+/* Our map: */
+#define E820MAP			0x2d0
 
 /* Number of entries in E820MAP: */
 #define E820NR			0x1e8
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 06/50] x86/boot/e820: Remove spurious asm/e820/api.h inclusions
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (4 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 05/50] x86/boot/e820: Clean up the E820_X_MAX definition Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 07/50] x86/boot/e820: Remove assembly guard from asm/e820/types.h Ingo Molnar
                   ` (43 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

A commonly used lowlevel x86 header, asm/pgtable.h, includes asm/e820/api.h
spuriously, without making direct use of it.

Removing it is not simple: over the years various .c code learned to rely
on this indirect inclusion.

Remove the unnecessary include - this should speed up the kernel build a bit,
as a large header is not included anymore in totally unrelated code.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/boot/compressed/eboot.c   | 2 ++
 arch/x86/include/asm/pci_x86.h     | 2 ++
 arch/x86/include/asm/pgtable.h     | 2 --
 arch/x86/kernel/acpi/boot.c        | 1 +
 arch/x86/kernel/apic/x2apic_uv_x.c | 1 +
 arch/x86/kernel/crash.c            | 1 +
 arch/x86/kernel/kexec-bzimage64.c  | 1 +
 arch/x86/mm/kasan_init_64.c        | 1 +
 arch/x86/pci/pcbios.c              | 2 ++
 arch/x86/platform/efi/efi.c        | 1 +
 arch/x86/platform/efi/quirks.c     | 2 ++
 arch/x86/power/hibernate_64.c      | 1 +
 12 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index ff01c8fc76f7..2066f74cf9b2 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -9,7 +9,9 @@
 
 #include <linux/efi.h>
 #include <linux/pci.h>
+
 #include <asm/efi.h>
+#include <asm/e820/types.h>
 #include <asm/setup.h>
 #include <asm/desc.h>
 
diff --git a/arch/x86/include/asm/pci_x86.h b/arch/x86/include/asm/pci_x86.h
index d08eacd298c2..9f1b21f372fe 100644
--- a/arch/x86/include/asm/pci_x86.h
+++ b/arch/x86/include/asm/pci_x86.h
@@ -4,6 +4,8 @@
  *	(c) 1999 Martin Mares <mj@ucw.cz>
  */
 
+#include <linux/ioport.h>
+
 #undef DEBUG
 
 #ifdef DEBUG
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index ae0b84d8ccb5..ffaefb24891c 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -2,8 +2,6 @@
 #define _ASM_X86_PGTABLE_H
 
 #include <asm/page.h>
-#include <asm/e820/api.h>
-
 #include <asm/pgtable_types.h>
 
 /*
diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
index 64422f850e95..8048c76a4458 100644
--- a/arch/x86/kernel/acpi/boot.c
+++ b/arch/x86/kernel/acpi/boot.c
@@ -36,6 +36,7 @@
 #include <linux/ioport.h>
 #include <linux/pci.h>
 
+#include <asm/e820/api.h>
 #include <asm/irqdomain.h>
 #include <asm/pci_x86.h>
 #include <asm/pgtable.h>
diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
index 35690a168cf7..c99d9333ebac 100644
--- a/arch/x86/kernel/apic/x2apic_uv_x.c
+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
@@ -34,6 +34,7 @@
 #include <asm/uv/bios.h>
 #include <asm/uv/uv.h>
 #include <asm/apic.h>
+#include <asm/e820/api.h>
 #include <asm/ipi.h>
 #include <asm/smp.h>
 #include <asm/x86_init.h>
diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
index 3741461c63a0..60c018530379 100644
--- a/arch/x86/kernel/crash.c
+++ b/arch/x86/kernel/crash.c
@@ -29,6 +29,7 @@
 #include <asm/nmi.h>
 #include <asm/hw_irq.h>
 #include <asm/apic.h>
+#include <asm/e820/types.h>
 #include <asm/io_apic.h>
 #include <asm/hpet.h>
 #include <linux/kdebug.h>
diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
index d0a814a9d96a..2f4a3c8127f6 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -25,6 +25,7 @@
 #include <asm/setup.h>
 #include <asm/crash.h>
 #include <asm/efi.h>
+#include <asm/e820/api.h>
 #include <asm/kexec-bzimage64.h>
 
 #define MAX_ELFCOREHDR_STR_LEN	30	/* elfcorehdr=0x<64bit-value> */
diff --git a/arch/x86/mm/kasan_init_64.c b/arch/x86/mm/kasan_init_64.c
index 0493c17b8a51..bf9a511c98f3 100644
--- a/arch/x86/mm/kasan_init_64.c
+++ b/arch/x86/mm/kasan_init_64.c
@@ -6,6 +6,7 @@
 #include <linux/sched.h>
 #include <linux/vmalloc.h>
 
+#include <asm/e820/types.h>
 #include <asm/tlbflush.h>
 #include <asm/sections.h>
 
diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
index 1d97cea3b3a4..29e9ba6ace9d 100644
--- a/arch/x86/pci/pcbios.c
+++ b/arch/x86/pci/pcbios.c
@@ -7,7 +7,9 @@
 #include <linux/slab.h>
 #include <linux/module.h>
 #include <linux/uaccess.h>
+
 #include <asm/pci_x86.h>
+#include <asm/e820/types.h>
 #include <asm/pci-functions.h>
 #include <asm/cacheflush.h>
 
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index 274dfc481849..528f682ec640 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -47,6 +47,7 @@
 
 #include <asm/setup.h>
 #include <asm/efi.h>
+#include <asm/e820/api.h>
 #include <asm/time.h>
 #include <asm/cacheflush.h>
 #include <asm/tlbflush.h>
diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
index 30031d5293c4..c6a14b11f496 100644
--- a/arch/x86/platform/efi/quirks.c
+++ b/arch/x86/platform/efi/quirks.c
@@ -11,6 +11,8 @@
 #include <linux/bootmem.h>
 #include <linux/acpi.h>
 #include <linux/dmi.h>
+
+#include <asm/e820/api.h>
 #include <asm/efi.h>
 #include <asm/uv/uv.h>
 
diff --git a/arch/x86/power/hibernate_64.c b/arch/x86/power/hibernate_64.c
index ded2e8272382..13e87bf86043 100644
--- a/arch/x86/power/hibernate_64.c
+++ b/arch/x86/power/hibernate_64.c
@@ -16,6 +16,7 @@
 
 #include <crypto/hash.h>
 
+#include <asm/e820/api.h>
 #include <asm/init.h>
 #include <asm/proto.h>
 #include <asm/page.h>
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 07/50] x86/boot/e820: Remove assembly guard from asm/e820/types.h
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (5 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 06/50] x86/boot/e820: Remove spurious asm/e820/api.h inclusions Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 08/50] x86/boot/e820: Clean up asm/e820/api.h Ingo Molnar
                   ` (42 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

There's an assembly guard in asm/e820/types.h, and only
a single .S file includes this header: arch/x86/boot/header.S,
but it does not actually make use of any of the E820 defines.

Remove the inclusion and remove the assembly guard as well.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/boot/header.S            | 1 -
 arch/x86/include/asm/e820/types.h | 5 -----
 2 files changed, 6 deletions(-)

diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
index 398b290c4c00..2ed8f0c25def 100644
--- a/arch/x86/boot/header.S
+++ b/arch/x86/boot/header.S
@@ -18,7 +18,6 @@
 #include <asm/segment.h>
 #include <generated/utsrelease.h>
 #include <asm/boot.h>
-#include <asm/e820/api.h>
 #include <asm/page_types.h>
 #include <asm/setup.h>
 #include <asm/bootparam.h>
diff --git a/arch/x86/include/asm/e820/types.h b/arch/x86/include/asm/e820/types.h
index b05e812ff4f2..464cfe827396 100644
--- a/arch/x86/include/asm/e820/types.h
+++ b/arch/x86/include/asm/e820/types.h
@@ -65,9 +65,6 @@
  */
 #define E820_RESERVED_KERN	128
 
-#ifndef __ASSEMBLY__
-#include <linux/types.h>
-
 /*
  * The whole array of E820 entries:
  */
@@ -88,6 +85,4 @@ struct e820map {
 #define BIOS_ROM_BASE		0xffe00000
 #define BIOS_ROM_END		0xffffffff
 
-#endif /* __ASSEMBLY__ */
-
 #endif /* _ASM_E820_TYPES_H */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 08/50] x86/boot/e820: Clean up asm/e820/api.h
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (6 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 07/50] x86/boot/e820: Remove assembly guard from asm/e820/types.h Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 09/50] x86/boot/e820: Remove unnecessary __ASSEMBLY__ guard Ingo Molnar
                   ` (41 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

Do a number of easy cleanups:

 - remove spurious linebreaks

 - remove spurious whitespace differences and inconsistent tabulation

 - remove unused and ugly 'struct setup_data;' pre-declaration

 - make all exported functionality 'extern' consistently

 - deobfuscate the (s,e) parameters of is_ISA_range(): (start, end)

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h | 46 ++++++++++++++++++----------------------------
 1 file changed, 18 insertions(+), 28 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index e161deb5736c..88a19257abb9 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -9,52 +9,42 @@ extern struct e820map *e820;
 extern struct e820map *e820_saved;
 
 extern unsigned long pci_mem_start;
-extern int e820_any_mapped(u64 start, u64 end, unsigned type);
-extern int e820_all_mapped(u64 start, u64 end, unsigned type);
+
+extern int  e820_any_mapped(u64 start, u64 end, unsigned type);
+extern int  e820_all_mapped(u64 start, u64 end, unsigned type);
 extern void e820_add_region(u64 start, u64 size, int type);
 extern void e820_print_map(char *who);
-extern int
-sanitize_e820_map(struct e820entry *biosmap, int max_nr_map, u32 *pnr_map);
-extern u64 e820_update_range(u64 start, u64 size, unsigned old_type,
-			       unsigned new_type);
-extern u64 e820_remove_range(u64 start, u64 size, unsigned old_type,
-			     int checktype);
+extern int  sanitize_e820_map(struct e820entry *biosmap, int max_nr_map, u32 *pnr_map);
+extern u64  e820_update_range(u64 start, u64 size, unsigned old_type, unsigned new_type);
+extern u64  e820_remove_range(u64 start, u64 size, unsigned old_type, int checktype);
 extern void update_e820(void);
 extern void e820_setup_gap(void);
-struct setup_data;
 extern void parse_e820_ext(u64 phys_addr, u32 data_len);
-
-#if defined(CONFIG_X86_64) || \
-	(defined(CONFIG_X86_32) && defined(CONFIG_HIBERNATION))
-extern void e820_mark_nosave_regions(unsigned long limit_pfn);
-#else
-static inline void e820_mark_nosave_regions(unsigned long limit_pfn)
-{
-}
-#endif
-
 extern unsigned long e820_end_of_ram_pfn(void);
 extern unsigned long e820_end_of_low_ram_pfn(void);
-extern u64 early_reserve_e820(u64 sizet, u64 align);
-
-void memblock_x86_fill(void);
-void memblock_find_dma_reserve(void);
-
+extern u64  early_reserve_e820(u64 sizet, u64 align);
+extern void memblock_x86_fill(void);
+extern void memblock_find_dma_reserve(void);
 extern void finish_e820_parsing(void);
 extern void e820_reserve_resources(void);
 extern void e820_reserve_resources_late(void);
 extern void setup_memory_map(void);
 extern char *default_machine_specific_memory_setup(void);
-
 extern void e820_reallocate_tables(void);
 
+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_32) && defined(CONFIG_HIBERNATION)
+extern void e820_mark_nosave_regions(unsigned long limit_pfn);
+#else
+static inline void e820_mark_nosave_regions(unsigned long limit_pfn) { }
+#endif
+
 /*
- * Returns true iff the specified range [s,e) is completely contained inside
+ * Returns true iff the specified range [start,end) is completely contained inside
  * the ISA region.
  */
-static inline bool is_ISA_range(u64 s, u64 e)
+static inline bool is_ISA_range(u64 start, u64 end)
 {
-	return s >= ISA_START_ADDRESS && e <= ISA_END_ADDRESS;
+	return start >= ISA_START_ADDRESS && end <= ISA_END_ADDRESS;
 }
 
 #endif /* __ASSEMBLY__ */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 09/50] x86/boot/e820: Remove unnecessary __ASSEMBLY__ guard
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (7 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 08/50] x86/boot/e820: Clean up asm/e820/api.h Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 10/50] x86/boot/e820: Move HIGH_MEMORY define to asm/e820/types.h Ingo Molnar
                   ` (40 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

asm/e820/api.h had a spurious __ASSEMBLY__ guard - but the
API header is not included in any assembly files. Remove it.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 88a19257abb9..b45550b662a9 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -3,7 +3,6 @@
 
 #include <asm/e820/types.h>
 
-#ifndef __ASSEMBLY__
 /* see comment in arch/x86/kernel/e820.c */
 extern struct e820map *e820;
 extern struct e820map *e820_saved;
@@ -47,7 +46,6 @@ static inline bool is_ISA_range(u64 start, u64 end)
 	return start >= ISA_START_ADDRESS && end <= ISA_END_ADDRESS;
 }
 
-#endif /* __ASSEMBLY__ */
 #include <linux/ioport.h>
 
 #define HIGH_MEMORY	(1024*1024)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 10/50] x86/boot/e820: Move HIGH_MEMORY define to asm/e820/types.h
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (8 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 09/50] x86/boot/e820: Remove unnecessary __ASSEMBLY__ guard Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 11/50] x86/boot/e820: Rename the basic e820 data types to 'struct e820_entry' and 'struct e820_array' Ingo Molnar
                   ` (39 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

The HIGH_MEMORY define was in the API header, while it conceptually
belongs to the other physical memory ranges in the e820/types.h
header.

Move it there - and also convert the 1MB address to hexa, so that
it lines up more nicely with the other memory address values.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h   | 1 -
 arch/x86/include/asm/e820/types.h | 4 +++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index b45550b662a9..4163a83f1a37 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -48,5 +48,4 @@ static inline bool is_ISA_range(u64 start, u64 end)
 
 #include <linux/ioport.h>
 
-#define HIGH_MEMORY	(1024*1024)
 #endif /* _ASM_E820_API_H */
diff --git a/arch/x86/include/asm/e820/types.h b/arch/x86/include/asm/e820/types.h
index 464cfe827396..ce0e100b843c 100644
--- a/arch/x86/include/asm/e820/types.h
+++ b/arch/x86/include/asm/e820/types.h
@@ -74,7 +74,7 @@ struct e820map {
 };
 
 /*
- * Various legacy ranges in physical memory:
+ * Various well-known legacy memory ranges in physical memory:
  */
 #define ISA_START_ADDRESS	0x000a0000
 #define ISA_END_ADDRESS		0x00100000
@@ -82,6 +82,8 @@ struct e820map {
 #define BIOS_BEGIN		0x000a0000
 #define BIOS_END		0x00100000
 
+#define HIGH_MEMORY		0x00100000
+
 #define BIOS_ROM_BASE		0xffe00000
 #define BIOS_ROM_END		0xffffffff
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 11/50] x86/boot/e820: Rename the basic e820 data types to 'struct e820_entry' and 'struct e820_array'
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (9 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 10/50] x86/boot/e820: Move HIGH_MEMORY define to asm/e820/types.h Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 12/50] x86/boot/e820: Remove unnecessary #include <linux/ioport.h> from asm/e820/api.h Ingo Molnar
                   ` (38 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

The 'e820entry' and 'e820map' names have various annoyances:

 - the missing underscore departs from the usual kernel style
   and makes the code look weird,

 - in the past I kept confusing the 'map' with the 'entry', because
   a 'map' is ambiguous in that regard,

 - it's not really clear from the 'e820map' that this is a regular
   C array.

Rename them to 'struct e820_entry' and 'struct e820_array' accordingly.

( Leave the legacy UAPI header alone but do the rename in the bootparam.h
  and e820/types.h file - outside tools relying on these defines should
  either adjust their code, or should use the legacy header, or should
  create their private copies for the definitions. )

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 Documentation/x86/zero-page.txt        |  2 +-
 arch/x86/boot/compressed/eboot.c       | 12 +++++-----
 arch/x86/boot/compressed/kaslr.c       |  2 +-
 arch/x86/boot/memory.c                 |  4 ++--
 arch/x86/include/asm/e820/api.h        |  6 ++---
 arch/x86/include/asm/e820/types.h      |  4 ++--
 arch/x86/include/uapi/asm/bootparam.h  |  2 +-
 arch/x86/include/uapi/asm/e820/types.h |  2 +-
 arch/x86/kernel/crash.c                |  8 +++----
 arch/x86/kernel/e820.c                 | 64 +++++++++++++++++++++++++++---------------------------
 arch/x86/kernel/kexec-bzimage64.c      |  2 +-
 arch/x86/kernel/resource.c             |  2 +-
 arch/x86/kernel/setup.c                |  2 +-
 arch/x86/power/hibernate_64.c          |  6 ++---
 arch/x86/xen/setup.c                   | 12 +++++-----
 tools/lguest/lguest.c                  |  2 +-
 16 files changed, 66 insertions(+), 66 deletions(-)

diff --git a/Documentation/x86/zero-page.txt b/Documentation/x86/zero-page.txt
index 95a4d34af3fd..1746ddcfa50c 100644
--- a/Documentation/x86/zero-page.txt
+++ b/Documentation/x86/zero-page.txt
@@ -34,5 +34,5 @@ Offset	Proto	Name		Meaning
 1EF/001	ALL	sentinel	Used to detect broken bootloaders
 290/040	ALL	edd_mbr_sig_buffer EDD MBR signatures
 2D0/A00	ALL	e820_map	E820 memory map table
-				(array of struct e820entry)
+				(array of struct e820_entry)
 D00/1EC	ALL	eddbuf		EDD data (array of struct edd_info)
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index 2066f74cf9b2..e1a3e2cde5cb 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -900,7 +900,7 @@ static void add_e820ext(struct boot_params *params,
 	unsigned long size;
 
 	e820ext->type = SETUP_E820_EXT;
-	e820ext->len = nr_entries * sizeof(struct e820entry);
+	e820ext->len = nr_entries * sizeof(struct e820_entry);
 	e820ext->next = 0;
 
 	data = (struct setup_data *)(unsigned long)params->hdr.setup_data;
@@ -917,9 +917,9 @@ static void add_e820ext(struct boot_params *params,
 static efi_status_t setup_e820(struct boot_params *params,
 			       struct setup_data *e820ext, u32 e820ext_size)
 {
-	struct e820entry *e820_map = &params->e820_map[0];
+	struct e820_entry *e820_map = &params->e820_map[0];
 	struct efi_info *efi = &params->efi_info;
-	struct e820entry *prev = NULL;
+	struct e820_entry *prev = NULL;
 	u32 nr_entries;
 	u32 nr_desc;
 	int i;
@@ -983,14 +983,14 @@ static efi_status_t setup_e820(struct boot_params *params,
 		}
 
 		if (nr_entries == ARRAY_SIZE(params->e820_map)) {
-			u32 need = (nr_desc - i) * sizeof(struct e820entry) +
+			u32 need = (nr_desc - i) * sizeof(struct e820_entry) +
 				   sizeof(struct setup_data);
 
 			if (!e820ext || e820ext_size < need)
 				return EFI_BUFFER_TOO_SMALL;
 
 			/* boot_params map full, switch to e820 extended */
-			e820_map = (struct e820entry *)e820ext->data;
+			e820_map = (struct e820_entry *)e820ext->data;
 		}
 
 		e820_map->addr = d->phys_addr;
@@ -1019,7 +1019,7 @@ static efi_status_t alloc_e820ext(u32 nr_desc, struct setup_data **e820ext,
 	unsigned long size;
 
 	size = sizeof(struct setup_data) +
-		sizeof(struct e820entry) * nr_desc;
+		sizeof(struct e820_entry) * nr_desc;
 
 	if (*e820ext) {
 		efi_call_early(free_pool, *e820ext);
diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index 8b7c9e75edcb..17da12e92e99 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -426,7 +426,7 @@ static unsigned long slots_fetch_random(void)
 	return 0;
 }
 
-static void process_e820_entry(struct e820entry *entry,
+static void process_e820_entry(struct e820_entry *entry,
 			       unsigned long minimum,
 			       unsigned long image_size)
 {
diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
index db75d07c3645..331b3d831cc4 100644
--- a/arch/x86/boot/memory.c
+++ b/arch/x86/boot/memory.c
@@ -21,8 +21,8 @@ static int detect_memory_e820(void)
 {
 	int count = 0;
 	struct biosregs ireg, oreg;
-	struct e820entry *desc = boot_params.e820_map;
-	static struct e820entry buf; /* static so it is zeroed */
+	struct e820_entry *desc = boot_params.e820_map;
+	static struct e820_entry buf; /* static so it is zeroed */
 
 	initregs(&ireg);
 	ireg.ax  = 0xe820;
diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 4163a83f1a37..848b9f61808c 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -4,8 +4,8 @@
 #include <asm/e820/types.h>
 
 /* see comment in arch/x86/kernel/e820.c */
-extern struct e820map *e820;
-extern struct e820map *e820_saved;
+extern struct e820_array *e820;
+extern struct e820_array *e820_saved;
 
 extern unsigned long pci_mem_start;
 
@@ -13,7 +13,7 @@ extern int  e820_any_mapped(u64 start, u64 end, unsigned type);
 extern int  e820_all_mapped(u64 start, u64 end, unsigned type);
 extern void e820_add_region(u64 start, u64 size, int type);
 extern void e820_print_map(char *who);
-extern int  sanitize_e820_map(struct e820entry *biosmap, int max_nr_map, u32 *pnr_map);
+extern int  sanitize_e820_map(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map);
 extern u64  e820_update_range(u64 start, u64 size, unsigned old_type, unsigned new_type);
 extern u64  e820_remove_range(u64 start, u64 size, unsigned old_type, int checktype);
 extern void update_e820(void);
diff --git a/arch/x86/include/asm/e820/types.h b/arch/x86/include/asm/e820/types.h
index ce0e100b843c..05e25cabfafb 100644
--- a/arch/x86/include/asm/e820/types.h
+++ b/arch/x86/include/asm/e820/types.h
@@ -68,9 +68,9 @@
 /*
  * The whole array of E820 entries:
  */
-struct e820map {
+struct e820_array {
 	__u32 nr_map;
-	struct e820entry map[E820_X_MAX];
+	struct e820_entry map[E820_X_MAX];
 };
 
 /*
diff --git a/arch/x86/include/uapi/asm/bootparam.h b/arch/x86/include/uapi/asm/bootparam.h
index 742333c3ffea..f0a7170d5a9d 100644
--- a/arch/x86/include/uapi/asm/bootparam.h
+++ b/arch/x86/include/uapi/asm/bootparam.h
@@ -152,7 +152,7 @@ struct boot_params {
 	struct setup_header hdr;    /* setup header */	/* 0x1f1 */
 	__u8  _pad7[0x290-0x1f1-sizeof(struct setup_header)];
 	__u32 edd_mbr_sig_buffer[EDD_MBR_SIG_MAX];	/* 0x290 */
-	struct e820entry e820_map[E820MAX];		/* 0x2d0 */
+	struct e820_entry e820_map[E820MAX];		/* 0x2d0 */
 	__u8  _pad8[48];				/* 0xcd0 */
 	struct edd_info eddbuf[EDDMAXNR];		/* 0xd00 */
 	__u8  _pad9[276];				/* 0xeec */
diff --git a/arch/x86/include/uapi/asm/e820/types.h b/arch/x86/include/uapi/asm/e820/types.h
index 8e522eb120aa..54b812e80bac 100644
--- a/arch/x86/include/uapi/asm/e820/types.h
+++ b/arch/x86/include/uapi/asm/e820/types.h
@@ -10,7 +10,7 @@
  * A single E820 map entry, describing a memory range of [addr...addr+size-1],
  * of 'type' memory type:
  */
-struct e820entry {
+struct e820_entry {
 	__u64 addr;
 	__u64 size;
 	__u32 type;
diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
index 60c018530379..81b67df3b52f 100644
--- a/arch/x86/kernel/crash.c
+++ b/arch/x86/kernel/crash.c
@@ -504,7 +504,7 @@ static int prepare_elf_headers(struct kimage *image, void **addr,
 	return ret;
 }
 
-static int add_e820_entry(struct boot_params *params, struct e820entry *entry)
+static int add_e820_entry(struct boot_params *params, struct e820_entry *entry)
 {
 	unsigned int nr_e820_entries;
 
@@ -513,7 +513,7 @@ static int add_e820_entry(struct boot_params *params, struct e820entry *entry)
 		return 1;
 
 	memcpy(&params->e820_map[nr_e820_entries], entry,
-			sizeof(struct e820entry));
+			sizeof(struct e820_entry));
 	params->e820_entries++;
 	return 0;
 }
@@ -522,7 +522,7 @@ static int memmap_entry_callback(u64 start, u64 end, void *arg)
 {
 	struct crash_memmap_data *cmd = arg;
 	struct boot_params *params = cmd->params;
-	struct e820entry ei;
+	struct e820_entry ei;
 
 	ei.addr = start;
 	ei.size = end - start + 1;
@@ -561,7 +561,7 @@ int crash_setup_memmap_entries(struct kimage *image, struct boot_params *params)
 {
 	int i, ret = 0;
 	unsigned long flags;
-	struct e820entry ei;
+	struct e820_entry ei;
 	struct crash_memmap_data cmd;
 	struct crash_mem *cmem;
 
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 49d54c5002fa..eeb9c9963a6b 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -40,10 +40,10 @@
  * user can e.g. boot the original kernel with mem=1G while still booting the
  * next kernel with full memory.
  */
-static struct e820map initial_e820  __initdata;
-static struct e820map initial_e820_saved  __initdata;
-struct e820map *e820 __refdata = &initial_e820;
-struct e820map *e820_saved __refdata = &initial_e820_saved;
+static struct e820_array initial_e820  __initdata;
+static struct e820_array initial_e820_saved  __initdata;
+struct e820_array *e820 __refdata = &initial_e820;
+struct e820_array *e820_saved __refdata = &initial_e820_saved;
 
 /* For PCI or other memory-mapped resources */
 unsigned long pci_mem_start = 0xaeedbabe;
@@ -61,7 +61,7 @@ e820_any_mapped(u64 start, u64 end, unsigned type)
 	int i;
 
 	for (i = 0; i < e820->nr_map; i++) {
-		struct e820entry *ei = &e820->map[i];
+		struct e820_entry *ei = &e820->map[i];
 
 		if (type && ei->type != type)
 			continue;
@@ -84,7 +84,7 @@ int __init e820_all_mapped(u64 start, u64 end, unsigned type)
 	int i;
 
 	for (i = 0; i < e820->nr_map; i++) {
-		struct e820entry *ei = &e820->map[i];
+		struct e820_entry *ei = &e820->map[i];
 
 		if (type && ei->type != type)
 			continue;
@@ -110,7 +110,7 @@ int __init e820_all_mapped(u64 start, u64 end, unsigned type)
 /*
  * Add a memory region to the kernel e820 map.
  */
-static void __init __e820_add_region(struct e820map *e820x, u64 start, u64 size,
+static void __init __e820_add_region(struct e820_array *e820x, u64 start, u64 size,
 					 int type)
 {
 	int x = e820x->nr_map;
@@ -185,7 +185,7 @@ void __init e820_print_map(char *who)
  * numbered type.
  *
  * The input parameter biosmap points to an array of 'struct
- * e820entry' which on entry has elements in the range [0, *pnr_map)
+ * e820_entry' which on entry has elements in the range [0, *pnr_map)
  * valid, and which has space for up to max_nr_map entries.
  * On return, the resulting sanitized e820 map entries will be in
  * overwritten in the same location, starting at biosmap.
@@ -238,7 +238,7 @@ void __init e820_print_map(char *who)
  *	   ______________________4_
  */
 struct change_member {
-	struct e820entry *pbios; /* pointer to original bios entry */
+	struct e820_entry *pbios; /* pointer to original bios entry */
 	unsigned long long addr; /* address for this change point */
 };
 
@@ -259,13 +259,13 @@ static int __init cpcompare(const void *a, const void *b)
 	return (ap->addr != ap->pbios->addr) - (bp->addr != bp->pbios->addr);
 }
 
-int __init sanitize_e820_map(struct e820entry *biosmap, int max_nr_map,
+int __init sanitize_e820_map(struct e820_entry *biosmap, int max_nr_map,
 			     u32 *pnr_map)
 {
 	static struct change_member change_point_list[2*E820_X_MAX] __initdata;
 	static struct change_member *change_point[2*E820_X_MAX] __initdata;
-	static struct e820entry *overlap_list[E820_X_MAX] __initdata;
-	static struct e820entry new_bios[E820_X_MAX] __initdata;
+	static struct e820_entry *overlap_list[E820_X_MAX] __initdata;
+	static struct e820_entry new_bios[E820_X_MAX] __initdata;
 	unsigned long current_type, last_type;
 	unsigned long long last_addr;
 	int chgidx;
@@ -379,13 +379,13 @@ int __init sanitize_e820_map(struct e820entry *biosmap, int max_nr_map,
 	new_nr = new_bios_entry;
 
 	/* copy new bios mapping into original location */
-	memcpy(biosmap, new_bios, new_nr * sizeof(struct e820entry));
+	memcpy(biosmap, new_bios, new_nr * sizeof(struct e820_entry));
 	*pnr_map = new_nr;
 
 	return 0;
 }
 
-static int __init __append_e820_map(struct e820entry *biosmap, int nr_map)
+static int __init __append_e820_map(struct e820_entry *biosmap, int nr_map)
 {
 	while (nr_map) {
 		u64 start = biosmap->addr;
@@ -414,7 +414,7 @@ static int __init __append_e820_map(struct e820entry *biosmap, int nr_map)
  * will have given us a memory map that we can use to properly
  * set up memory.  If we aren't, we'll fake a memory map.
  */
-static int __init append_e820_map(struct e820entry *biosmap, int nr_map)
+static int __init append_e820_map(struct e820_entry *biosmap, int nr_map)
 {
 	/* Only one memory region (or negative)? Ignore it */
 	if (nr_map < 2)
@@ -423,7 +423,7 @@ static int __init append_e820_map(struct e820entry *biosmap, int nr_map)
 	return __append_e820_map(biosmap, nr_map);
 }
 
-static u64 __init __e820_update_range(struct e820map *e820x, u64 start,
+static u64 __init __e820_update_range(struct e820_array *e820x, u64 start,
 					u64 size, unsigned old_type,
 					unsigned new_type)
 {
@@ -445,7 +445,7 @@ static u64 __init __e820_update_range(struct e820map *e820x, u64 start,
 	printk(KERN_CONT "\n");
 
 	for (i = 0; i < e820x->nr_map; i++) {
-		struct e820entry *ei = &e820x->map[i];
+		struct e820_entry *ei = &e820x->map[i];
 		u64 final_start, final_end;
 		u64 ei_end;
 
@@ -524,7 +524,7 @@ u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type,
 	printk(KERN_CONT "\n");
 
 	for (i = 0; i < e820->nr_map; i++) {
-		struct e820entry *ei = &e820->map[i];
+		struct e820_entry *ei = &e820->map[i];
 		u64 final_start, final_end;
 		u64 ei_end;
 
@@ -535,7 +535,7 @@ u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type,
 		/* totally covered? */
 		if (ei->addr >= start && ei_end <= end) {
 			real_removed_size += ei->size;
-			memset(ei, 0, sizeof(struct e820entry));
+			memset(ei, 0, sizeof(struct e820_entry));
 			continue;
 		}
 
@@ -658,16 +658,16 @@ __init void e820_setup_gap(void)
  */
 __init void e820_reallocate_tables(void)
 {
-	struct e820map *n;
+	struct e820_array *n;
 	int size;
 
-	size = offsetof(struct e820map, map) + sizeof(struct e820entry) * e820->nr_map;
+	size = offsetof(struct e820_array, map) + sizeof(struct e820_entry) * e820->nr_map;
 	n = kmalloc(size, GFP_KERNEL);
 	BUG_ON(!n);
 	memcpy(n, e820, size);
 	e820 = n;
 
-	size = offsetof(struct e820map, map) + sizeof(struct e820entry) * e820_saved->nr_map;
+	size = offsetof(struct e820_array, map) + sizeof(struct e820_entry) * e820_saved->nr_map;
 	n = kmalloc(size, GFP_KERNEL);
 	BUG_ON(!n);
 	memcpy(n, e820_saved, size);
@@ -683,12 +683,12 @@ __init void e820_reallocate_tables(void)
 void __init parse_e820_ext(u64 phys_addr, u32 data_len)
 {
 	int entries;
-	struct e820entry *extmap;
+	struct e820_entry *extmap;
 	struct setup_data *sdata;
 
 	sdata = early_memremap(phys_addr, data_len);
-	entries = sdata->len / sizeof(struct e820entry);
-	extmap = (struct e820entry *)(sdata->data);
+	entries = sdata->len / sizeof(struct e820_entry);
+	extmap = (struct e820_entry *)(sdata->data);
 	__append_e820_map(extmap, entries);
 	sanitize_e820_map(e820->map, ARRAY_SIZE(e820->map), &e820->nr_map);
 	early_memunmap(sdata, data_len);
@@ -712,7 +712,7 @@ void __init e820_mark_nosave_regions(unsigned long limit_pfn)
 	unsigned long pfn = 0;
 
 	for (i = 0; i < e820->nr_map; i++) {
-		struct e820entry *ei = &e820->map[i];
+		struct e820_entry *ei = &e820->map[i];
 
 		if (pfn < PFN_UP(ei->addr))
 			register_nosave_region(pfn, PFN_UP(ei->addr));
@@ -738,7 +738,7 @@ static int __init e820_mark_nvs_memory(void)
 	int i;
 
 	for (i = 0; i < e820->nr_map; i++) {
-		struct e820entry *ei = &e820->map[i];
+		struct e820_entry *ei = &e820->map[i];
 
 		if (ei->type == E820_NVS)
 			acpi_nvs_register(ei->addr, ei->size);
@@ -786,7 +786,7 @@ static unsigned long __init e820_end_pfn(unsigned long limit_pfn, unsigned type)
 	unsigned long max_arch_pfn = MAX_ARCH_PFN;
 
 	for (i = 0; i < e820->nr_map; i++) {
-		struct e820entry *ei = &e820->map[i];
+		struct e820_entry *ei = &e820->map[i];
 		unsigned long start_pfn;
 		unsigned long end_pfn;
 
@@ -1040,7 +1040,7 @@ void __init e820_reserve_resources(void)
 	}
 
 	for (i = 0; i < e820_saved->nr_map; i++) {
-		struct e820entry *entry = &e820_saved->map[i];
+		struct e820_entry *entry = &e820_saved->map[i];
 		firmware_map_add_early(entry->addr,
 			entry->addr + entry->size,
 			e820_type_to_string(entry->type));
@@ -1083,7 +1083,7 @@ void __init e820_reserve_resources_late(void)
 	 * avoid stolen RAM:
 	 */
 	for (i = 0; i < e820->nr_map; i++) {
-		struct e820entry *entry = &e820->map[i];
+		struct e820_entry *entry = &e820->map[i];
 		u64 start, end;
 
 		if (entry->type != E820_RAM)
@@ -1145,7 +1145,7 @@ void __init setup_memory_map(void)
 	char *who;
 
 	who = x86_init.resources.memory_setup();
-	memcpy(e820_saved, e820, sizeof(struct e820map));
+	memcpy(e820_saved, e820, sizeof(struct e820_array));
 	printk(KERN_INFO "e820: BIOS-provided physical RAM map:\n");
 	e820_print_map(who);
 }
@@ -1163,7 +1163,7 @@ void __init memblock_x86_fill(void)
 	memblock_allow_resize();
 
 	for (i = 0; i < e820->nr_map; i++) {
-		struct e820entry *ei = &e820->map[i];
+		struct e820_entry *ei = &e820->map[i];
 
 		end = ei->addr + ei->size;
 		if (end != (resource_size_t)end)
diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
index 2f4a3c8127f6..d70e8d65cc16 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -108,7 +108,7 @@ static int setup_e820_entries(struct boot_params *params)
 
 	params->e820_entries = nr_e820_entries;
 	memcpy(&params->e820_map, &e820_saved->map,
-	       nr_e820_entries * sizeof(struct e820entry));
+	       nr_e820_entries * sizeof(struct e820_entry));
 
 	return 0;
 }
diff --git a/arch/x86/kernel/resource.c b/arch/x86/kernel/resource.c
index eb2021659c9e..06a6e8049070 100644
--- a/arch/x86/kernel/resource.c
+++ b/arch/x86/kernel/resource.c
@@ -25,7 +25,7 @@ static void resource_clip(struct resource *res, resource_size_t start,
 static void remove_e820_regions(struct resource *avail)
 {
 	int i;
-	struct e820entry *entry;
+	struct e820_entry *entry;
 
 	for (i = 0; i < e820->nr_map; i++) {
 		entry = &e820->map[i];
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 6e521831f6ba..d2bdda9c3d6f 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -459,7 +459,7 @@ static void __init e820_reserve_setup_data(void)
 	}
 
 	sanitize_e820_map(e820->map, ARRAY_SIZE(e820->map), &e820->nr_map);
-	memcpy(e820_saved, e820, sizeof(struct e820map));
+	memcpy(e820_saved, e820, sizeof(struct e820_array));
 	printk(KERN_INFO "extended physical RAM map:\n");
 	e820_print_map("reserve setup_data");
 }
diff --git a/arch/x86/power/hibernate_64.c b/arch/x86/power/hibernate_64.c
index 13e87bf86043..874aea614fcf 100644
--- a/arch/x86/power/hibernate_64.c
+++ b/arch/x86/power/hibernate_64.c
@@ -201,7 +201,7 @@ struct restore_data_record {
  * @map: the e820 map to be calculated
  * @buf: the md5 result to be stored to
  */
-static int get_e820_md5(struct e820map *map, void *buf)
+static int get_e820_md5(struct e820_array *map, void *buf)
 {
 	struct scatterlist sg;
 	struct crypto_ahash *tfm;
@@ -214,8 +214,8 @@ static int get_e820_md5(struct e820map *map, void *buf)
 
 	{
 		AHASH_REQUEST_ON_STACK(req, tfm);
-		size = offsetof(struct e820map, map)
-			+ sizeof(struct e820entry) * map->nr_map;
+		size = offsetof(struct e820_array, map)
+			+ sizeof(struct e820_entry) * map->nr_map;
 		ahash_request_set_tfm(req, tfm);
 		sg_init_one(&sg, (u8 *)map, size);
 		ahash_request_set_callback(req, 0, NULL, NULL);
diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
index dd6ec15f91d4..7386a6e4c072 100644
--- a/arch/x86/xen/setup.c
+++ b/arch/x86/xen/setup.c
@@ -41,7 +41,7 @@ struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata;
 unsigned long xen_released_pages;
 
 /* E820 map used during setting up memory. */
-static struct e820entry xen_e820_map[E820_X_MAX] __initdata;
+static struct e820_entry xen_e820_map[E820_X_MAX] __initdata;
 static u32 xen_e820_map_entries __initdata;
 
 /*
@@ -198,7 +198,7 @@ void __init xen_inv_extra_mem(void)
  */
 static unsigned long __init xen_find_pfn_range(unsigned long *min_pfn)
 {
-	const struct e820entry *entry = xen_e820_map;
+	const struct e820_entry *entry = xen_e820_map;
 	unsigned int i;
 	unsigned long done = 0;
 
@@ -457,7 +457,7 @@ static unsigned long __init xen_foreach_remap_area(unsigned long nr_pages,
 {
 	phys_addr_t start = 0;
 	unsigned long ret_val = 0;
-	const struct e820entry *entry = xen_e820_map;
+	const struct e820_entry *entry = xen_e820_map;
 	int i;
 
 	/*
@@ -601,7 +601,7 @@ static void __init xen_align_and_add_e820_region(phys_addr_t start,
 
 static void __init xen_ignore_unusable(void)
 {
-	struct e820entry *entry = xen_e820_map;
+	struct e820_entry *entry = xen_e820_map;
 	unsigned int i;
 
 	for (i = 0; i < xen_e820_map_entries; i++, entry++) {
@@ -612,7 +612,7 @@ static void __init xen_ignore_unusable(void)
 
 bool __init xen_is_e820_reserved(phys_addr_t start, phys_addr_t size)
 {
-	struct e820entry *entry;
+	struct e820_entry *entry;
 	unsigned mapcnt;
 	phys_addr_t end;
 
@@ -645,7 +645,7 @@ phys_addr_t __init xen_find_free_area(phys_addr_t size)
 {
 	unsigned mapcnt;
 	phys_addr_t addr, start;
-	struct e820entry *entry = xen_e820_map;
+	struct e820_entry *entry = xen_e820_map;
 
 	for (mapcnt = 0; mapcnt < xen_e820_map_entries; mapcnt++, entry++) {
 		if (entry->type != E820_RAM || entry->size < size)
diff --git a/tools/lguest/lguest.c b/tools/lguest/lguest.c
index 11c8d9bc762e..7deb8d4a976e 100644
--- a/tools/lguest/lguest.c
+++ b/tools/lguest/lguest.c
@@ -3339,7 +3339,7 @@ int main(int argc, char *argv[])
 	 * simple, single region.
 	 */
 	boot->e820_entries = 1;
-	boot->e820_map[0] = ((struct e820entry) { 0, mem, E820_RAM });
+	boot->e820_map[0] = ((struct e820_entry) { 0, mem, E820_RAM });
 	/*
 	 * The boot header contains a command line pointer: we put the command
 	 * line after the boot header.
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 12/50] x86/boot/e820: Remove unnecessary #include <linux/ioport.h> from asm/e820/api.h
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (10 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 11/50] x86/boot/e820: Rename the basic e820 data types to 'struct e820_entry' and 'struct e820_array' Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 13/50] x86/boot/e820: Remove e820_mark_nosave_regions() definition uglies Ingo Molnar
                   ` (37 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

There's a completely unnecessary inclusion of linux/ioport.h near
the end of the asm/e820/api.h file.

Remove it and fix up unrelated code that learned to rely on this
spurious inclusion of a generic header.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h | 2 --
 arch/x86/mm/ioremap.c           | 1 +
 arch/x86/mm/pat.c               | 1 +
 3 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 848b9f61808c..e8ad6d9c9974 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -46,6 +46,4 @@ static inline bool is_ISA_range(u64 start, u64 end)
 	return start >= ISA_START_ADDRESS && end <= ISA_END_ADDRESS;
 }
 
-#include <linux/ioport.h>
-
 #endif /* _ASM_E820_API_H */
diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index d4f2b40a9641..c43b6b33463a 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -9,6 +9,7 @@
 #include <linux/bootmem.h>
 #include <linux/init.h>
 #include <linux/io.h>
+#include <linux/ioport.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 #include <linux/mmiotrace.h>
diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
index 41b0f2f3d90b..9b78685b66e6 100644
--- a/arch/x86/mm/pat.c
+++ b/arch/x86/mm/pat.c
@@ -10,6 +10,7 @@
 #include <linux/seq_file.h>
 #include <linux/bootmem.h>
 #include <linux/debugfs.h>
+#include <linux/ioport.h>
 #include <linux/kernel.h>
 #include <linux/pfn_t.h>
 #include <linux/slab.h>
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 13/50] x86/boot/e820: Remove e820_mark_nosave_regions() definition uglies
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (11 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 12/50] x86/boot/e820: Remove unnecessary #include <linux/ioport.h> from asm/e820/api.h Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 14/50] x86/boot/e820: Rename 'e820_map' variables to 'e820_array' Ingo Molnar
                   ` (36 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

The e820_mark_nosave_regions definition has a number of ugly #ifdef
conditions that unnecessarily uglify both the header and the
e820.c file.

Make this function unconditional: most distro kernels have hibernation
enabled. If LTO functionality is added in the future it will be able
to eliminate unused functions without uglifying the source code.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h | 5 -----
 arch/x86/kernel/e820.c          | 3 ---
 2 files changed, 8 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index e8ad6d9c9974..4895544b17ab 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -30,12 +30,7 @@ extern void e820_reserve_resources_late(void);
 extern void setup_memory_map(void);
 extern char *default_machine_specific_memory_setup(void);
 extern void e820_reallocate_tables(void);
-
-#if defined(CONFIG_X86_64) || defined(CONFIG_X86_32) && defined(CONFIG_HIBERNATION)
 extern void e820_mark_nosave_regions(unsigned long limit_pfn);
-#else
-static inline void e820_mark_nosave_regions(unsigned long limit_pfn) { }
-#endif
 
 /*
  * Returns true iff the specified range [start,end) is completely contained inside
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index eeb9c9963a6b..1f75b95185b8 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -696,8 +696,6 @@ void __init parse_e820_ext(u64 phys_addr, u32 data_len)
 	e820_print_map("extended");
 }
 
-#if defined(CONFIG_X86_64) || \
-	(defined(CONFIG_X86_32) && defined(CONFIG_HIBERNATION))
 /**
  * Find the ranges of physical addresses that do not correspond to
  * e820 RAM areas and mark the corresponding pages as nosave for
@@ -726,7 +724,6 @@ void __init e820_mark_nosave_regions(unsigned long limit_pfn)
 			break;
 	}
 }
-#endif
 
 #ifdef CONFIG_ACPI
 /**
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 14/50] x86/boot/e820: Rename 'e820_map' variables to 'e820_array'
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (12 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 13/50] x86/boot/e820: Remove e820_mark_nosave_regions() definition uglies Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 15/50] x86/boot/e820: Rename everything to e820_table Ingo Molnar
                   ` (35 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

In line with the rename to 'struct e820_array', harmonize the naming of common e820
table variable names as well:

 e820          =>  e820_array
 e820_saved    =>  e820_array_saved
 e820_map      =>  e820_array
 initial_e820  =>  e820_array_init

This makes the variable names more consistent  and easier to grep for.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 Documentation/x86/zero-page.txt       |   4 +-
 arch/x86/boot/compressed/eboot.c      |  22 ++++----
 arch/x86/boot/compressed/kaslr.c      |   2 +-
 arch/x86/boot/memory.c                |   4 +-
 arch/x86/include/asm/e820/api.h       |   6 +--
 arch/x86/include/asm/e820/types.h     |   2 +-
 arch/x86/include/uapi/asm/bootparam.h |   2 +-
 arch/x86/kernel/crash.c               |   2 +-
 arch/x86/kernel/e820.c                | 148 +++++++++++++++++++++++++++---------------------------
 arch/x86/kernel/early-quirks.c        |   2 +-
 arch/x86/kernel/kexec-bzimage64.c     |  10 ++--
 arch/x86/kernel/resource.c            |   4 +-
 arch/x86/kernel/setup.c               |  10 ++--
 arch/x86/kernel/tboot.c               |   8 +--
 arch/x86/lguest/boot.c                |   6 +--
 arch/x86/platform/efi/efi.c           |   2 +-
 arch/x86/power/hibernate_64.c         |   4 +-
 arch/x86/xen/setup.c                  |  76 ++++++++++++++--------------
 tools/lguest/lguest.c                 |   2 +-
 19 files changed, 158 insertions(+), 158 deletions(-)

diff --git a/Documentation/x86/zero-page.txt b/Documentation/x86/zero-page.txt
index 1746ddcfa50c..b323b705f419 100644
--- a/Documentation/x86/zero-page.txt
+++ b/Documentation/x86/zero-page.txt
@@ -27,12 +27,12 @@ Offset	Proto	Name		Meaning
 1C0/020	ALL	efi_info	EFI 32 information (struct efi_info)
 1E0/004	ALL	alk_mem_k	Alternative mem check, in KB
 1E4/004	ALL	scratch		Scratch field for the kernel setup code
-1E8/001	ALL	e820_entries	Number of entries in e820_map (below)
+1E8/001	ALL	e820_entries	Number of entries in e820_array (below)
 1E9/001	ALL	eddbuf_entries	Number of entries in eddbuf (below)
 1EA/001	ALL	edd_mbr_sig_buf_entries	Number of entries in edd_mbr_sig_buffer
 				(below)
 1EF/001	ALL	sentinel	Used to detect broken bootloaders
 290/040	ALL	edd_mbr_sig_buffer EDD MBR signatures
-2D0/A00	ALL	e820_map	E820 memory map table
+2D0/A00	ALL	e820_array	E820 memory map table
 				(array of struct e820_entry)
 D00/1EC	ALL	eddbuf		EDD data (array of struct edd_info)
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index e1a3e2cde5cb..b5cc1e72c63a 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -917,7 +917,7 @@ static void add_e820ext(struct boot_params *params,
 static efi_status_t setup_e820(struct boot_params *params,
 			       struct setup_data *e820ext, u32 e820ext_size)
 {
-	struct e820_entry *e820_map = &params->e820_map[0];
+	struct e820_entry *e820_array = &params->e820_array[0];
 	struct efi_info *efi = &params->efi_info;
 	struct e820_entry *prev = NULL;
 	u32 nr_entries;
@@ -982,7 +982,7 @@ static efi_status_t setup_e820(struct boot_params *params,
 			continue;
 		}
 
-		if (nr_entries == ARRAY_SIZE(params->e820_map)) {
+		if (nr_entries == ARRAY_SIZE(params->e820_array)) {
 			u32 need = (nr_desc - i) * sizeof(struct e820_entry) +
 				   sizeof(struct setup_data);
 
@@ -990,18 +990,18 @@ static efi_status_t setup_e820(struct boot_params *params,
 				return EFI_BUFFER_TOO_SMALL;
 
 			/* boot_params map full, switch to e820 extended */
-			e820_map = (struct e820_entry *)e820ext->data;
+			e820_array = (struct e820_entry *)e820ext->data;
 		}
 
-		e820_map->addr = d->phys_addr;
-		e820_map->size = d->num_pages << PAGE_SHIFT;
-		e820_map->type = e820_type;
-		prev = e820_map++;
+		e820_array->addr = d->phys_addr;
+		e820_array->size = d->num_pages << PAGE_SHIFT;
+		e820_array->type = e820_type;
+		prev = e820_array++;
 		nr_entries++;
 	}
 
-	if (nr_entries > ARRAY_SIZE(params->e820_map)) {
-		u32 nr_e820ext = nr_entries - ARRAY_SIZE(params->e820_map);
+	if (nr_entries > ARRAY_SIZE(params->e820_array)) {
+		u32 nr_e820ext = nr_entries - ARRAY_SIZE(params->e820_array);
 
 		add_e820ext(params, e820ext, nr_e820ext);
 		nr_entries -= nr_e820ext;
@@ -1055,9 +1055,9 @@ static efi_status_t exit_boot_func(efi_system_table_t *sys_table_arg,
 
 	if (first) {
 		nr_desc = *map->buff_size / *map->desc_size;
-		if (nr_desc > ARRAY_SIZE(p->boot_params->e820_map)) {
+		if (nr_desc > ARRAY_SIZE(p->boot_params->e820_array)) {
 			u32 nr_e820ext = nr_desc -
-					ARRAY_SIZE(p->boot_params->e820_map);
+					ARRAY_SIZE(p->boot_params->e820_array);
 
 			status = alloc_e820ext(nr_e820ext, &p->e820ext,
 					       &p->e820ext_size);
diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index 17da12e92e99..f0e37236cfe1 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -518,7 +518,7 @@ static unsigned long find_random_phys_addr(unsigned long minimum,
 
 	/* Verify potential e820 positions, appending to slots list. */
 	for (i = 0; i < boot_params->e820_entries; i++) {
-		process_e820_entry(&boot_params->e820_map[i], minimum,
+		process_e820_entry(&boot_params->e820_array[i], minimum,
 				   image_size);
 		if (slot_area_index == MAX_SLOT_AREA) {
 			debug_putstr("Aborted e820 scan (slot_areas full)!\n");
diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
index 331b3d831cc4..f2132b3e6880 100644
--- a/arch/x86/boot/memory.c
+++ b/arch/x86/boot/memory.c
@@ -21,7 +21,7 @@ static int detect_memory_e820(void)
 {
 	int count = 0;
 	struct biosregs ireg, oreg;
-	struct e820_entry *desc = boot_params.e820_map;
+	struct e820_entry *desc = boot_params.e820_array;
 	static struct e820_entry buf; /* static so it is zeroed */
 
 	initregs(&ireg);
@@ -66,7 +66,7 @@ static int detect_memory_e820(void)
 
 		*desc++ = buf;
 		count++;
-	} while (ireg.ebx && count < ARRAY_SIZE(boot_params.e820_map));
+	} while (ireg.ebx && count < ARRAY_SIZE(boot_params.e820_array));
 
 	return boot_params.e820_entries = count;
 }
diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 4895544b17ab..0156532dd65a 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -4,8 +4,8 @@
 #include <asm/e820/types.h>
 
 /* see comment in arch/x86/kernel/e820.c */
-extern struct e820_array *e820;
-extern struct e820_array *e820_saved;
+extern struct e820_array *e820_array;
+extern struct e820_array *e820_array_saved;
 
 extern unsigned long pci_mem_start;
 
@@ -13,7 +13,7 @@ extern int  e820_any_mapped(u64 start, u64 end, unsigned type);
 extern int  e820_all_mapped(u64 start, u64 end, unsigned type);
 extern void e820_add_region(u64 start, u64 size, int type);
 extern void e820_print_map(char *who);
-extern int  sanitize_e820_map(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map);
+extern int  sanitize_e820_array(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map);
 extern u64  e820_update_range(u64 start, u64 size, unsigned old_type, unsigned new_type);
 extern u64  e820_remove_range(u64 start, u64 size, unsigned old_type, int checktype);
 extern void update_e820(void);
diff --git a/arch/x86/include/asm/e820/types.h b/arch/x86/include/asm/e820/types.h
index 05e25cabfafb..e3171867e126 100644
--- a/arch/x86/include/asm/e820/types.h
+++ b/arch/x86/include/asm/e820/types.h
@@ -21,7 +21,7 @@
  *
  * 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
+ * call to sanitize_e820_array() 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
diff --git a/arch/x86/include/uapi/asm/bootparam.h b/arch/x86/include/uapi/asm/bootparam.h
index f0a7170d5a9d..702f1c6d804e 100644
--- a/arch/x86/include/uapi/asm/bootparam.h
+++ b/arch/x86/include/uapi/asm/bootparam.h
@@ -152,7 +152,7 @@ struct boot_params {
 	struct setup_header hdr;    /* setup header */	/* 0x1f1 */
 	__u8  _pad7[0x290-0x1f1-sizeof(struct setup_header)];
 	__u32 edd_mbr_sig_buffer[EDD_MBR_SIG_MAX];	/* 0x290 */
-	struct e820_entry e820_map[E820MAX];		/* 0x2d0 */
+	struct e820_entry e820_array[E820MAX];		/* 0x2d0 */
 	__u8  _pad8[48];				/* 0xcd0 */
 	struct edd_info eddbuf[EDDMAXNR];		/* 0xd00 */
 	__u8  _pad9[276];				/* 0xeec */
diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
index 81b67df3b52f..036d9140384d 100644
--- a/arch/x86/kernel/crash.c
+++ b/arch/x86/kernel/crash.c
@@ -512,7 +512,7 @@ static int add_e820_entry(struct boot_params *params, struct e820_entry *entry)
 	if (nr_e820_entries >= E820MAX)
 		return 1;
 
-	memcpy(&params->e820_map[nr_e820_entries], entry,
+	memcpy(&params->e820_array[nr_e820_entries], entry,
 			sizeof(struct e820_entry));
 	params->e820_entries++;
 	return 0;
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 1f75b95185b8..49d47d6b1afe 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -2,7 +2,7 @@
  * Handle the memory map.
  * The functions here do the job until bootmem takes over.
  *
- *  Getting sanitize_e820_map() in sync with i386 version by applying change:
+ *  Getting sanitize_e820_array() in sync with i386 version by applying change:
  *  -  Provisions for empty E820 memory regions (reported by certain BIOSes).
  *     Alex Achenbach <xela@slit.de>, December 2002.
  *  Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
@@ -27,11 +27,11 @@
 #include <asm/cpufeature.h>
 
 /*
- * The e820 map is the map that gets modified e.g. with command line parameters
+ * The e820 table is the array that gets modified e.g. with command line parameters
  * and that is also registered with modifications in the kernel resource tree
  * with the iomem_resource as parent.
  *
- * The e820_saved is directly saved after the BIOS-provided memory map is
+ * The e820_array_saved is directly saved after the BIOS-provided memory map is
  * copied. It doesn't get modified afterwards. It's registered for the
  * /sys/firmware/memmap interface.
  *
@@ -40,10 +40,10 @@
  * user can e.g. boot the original kernel with mem=1G while still booting the
  * next kernel with full memory.
  */
-static struct e820_array initial_e820  __initdata;
-static struct e820_array initial_e820_saved  __initdata;
-struct e820_array *e820 __refdata = &initial_e820;
-struct e820_array *e820_saved __refdata = &initial_e820_saved;
+static struct e820_array e820_array_init  __initdata;
+static struct e820_array initial_e820_array_saved  __initdata;
+struct e820_array *e820_array __refdata = &e820_array_init;
+struct e820_array *e820_array_saved __refdata = &initial_e820_array_saved;
 
 /* For PCI or other memory-mapped resources */
 unsigned long pci_mem_start = 0xaeedbabe;
@@ -60,8 +60,8 @@ e820_any_mapped(u64 start, u64 end, unsigned type)
 {
 	int i;
 
-	for (i = 0; i < e820->nr_map; i++) {
-		struct e820_entry *ei = &e820->map[i];
+	for (i = 0; i < e820_array->nr_map; i++) {
+		struct e820_entry *ei = &e820_array->map[i];
 
 		if (type && ei->type != type)
 			continue;
@@ -83,8 +83,8 @@ int __init e820_all_mapped(u64 start, u64 end, unsigned type)
 {
 	int i;
 
-	for (i = 0; i < e820->nr_map; i++) {
-		struct e820_entry *ei = &e820->map[i];
+	for (i = 0; i < e820_array->nr_map; i++) {
+		struct e820_entry *ei = &e820_array->map[i];
 
 		if (type && ei->type != type)
 			continue;
@@ -130,7 +130,7 @@ static void __init __e820_add_region(struct e820_array *e820x, u64 start, u64 si
 
 void __init e820_add_region(u64 start, u64 size, int type)
 {
-	__e820_add_region(e820, start, size, type);
+	__e820_add_region(e820_array, start, size, type);
 }
 
 static void __init e820_print_type(u32 type)
@@ -166,12 +166,12 @@ void __init e820_print_map(char *who)
 {
 	int i;
 
-	for (i = 0; i < e820->nr_map; i++) {
+	for (i = 0; i < e820_array->nr_map; i++) {
 		printk(KERN_INFO "%s: [mem %#018Lx-%#018Lx] ", who,
-		       (unsigned long long) e820->map[i].addr,
+		       (unsigned long long) e820_array->map[i].addr,
 		       (unsigned long long)
-		       (e820->map[i].addr + e820->map[i].size - 1));
-		e820_print_type(e820->map[i].type);
+		       (e820_array->map[i].addr + e820_array->map[i].size - 1));
+		e820_print_type(e820_array->map[i].type);
 		printk(KERN_CONT "\n");
 	}
 }
@@ -195,7 +195,7 @@ void __init e820_print_map(char *who)
  * sanitizing succeeds the *pnr_map will be updated with the new
  * number of valid entries (something no more than max_nr_map).
  *
- * The return value from sanitize_e820_map() is zero if it
+ * The return value from sanitize_e820_array() is zero if it
  * successfully 'sanitized' the map entries passed in, and is -1
  * if it did nothing, which can happen if either of (1) it was
  * only passed one map entry, or (2) any of the input map entries
@@ -259,7 +259,7 @@ static int __init cpcompare(const void *a, const void *b)
 	return (ap->addr != ap->pbios->addr) - (bp->addr != bp->pbios->addr);
 }
 
-int __init sanitize_e820_map(struct e820_entry *biosmap, int max_nr_map,
+int __init sanitize_e820_array(struct e820_entry *biosmap, int max_nr_map,
 			     u32 *pnr_map)
 {
 	static struct change_member change_point_list[2*E820_X_MAX] __initdata;
@@ -385,7 +385,7 @@ int __init sanitize_e820_map(struct e820_entry *biosmap, int max_nr_map,
 	return 0;
 }
 
-static int __init __append_e820_map(struct e820_entry *biosmap, int nr_map)
+static int __init __append_e820_array(struct e820_entry *biosmap, int nr_map)
 {
 	while (nr_map) {
 		u64 start = biosmap->addr;
@@ -414,13 +414,13 @@ static int __init __append_e820_map(struct e820_entry *biosmap, int nr_map)
  * will have given us a memory map that we can use to properly
  * set up memory.  If we aren't, we'll fake a memory map.
  */
-static int __init append_e820_map(struct e820_entry *biosmap, int nr_map)
+static int __init append_e820_array(struct e820_entry *biosmap, int nr_map)
 {
 	/* Only one memory region (or negative)? Ignore it */
 	if (nr_map < 2)
 		return -1;
 
-	return __append_e820_map(biosmap, nr_map);
+	return __append_e820_array(biosmap, nr_map);
 }
 
 static u64 __init __e820_update_range(struct e820_array *e820x, u64 start,
@@ -495,13 +495,13 @@ static u64 __init __e820_update_range(struct e820_array *e820x, u64 start,
 u64 __init e820_update_range(u64 start, u64 size, unsigned old_type,
 			     unsigned new_type)
 {
-	return __e820_update_range(e820, start, size, old_type, new_type);
+	return __e820_update_range(e820_array, start, size, old_type, new_type);
 }
 
 static u64 __init e820_update_range_saved(u64 start, u64 size,
 					  unsigned old_type, unsigned new_type)
 {
-	return __e820_update_range(e820_saved, start, size, old_type,
+	return __e820_update_range(e820_array_saved, start, size, old_type,
 				     new_type);
 }
 
@@ -523,8 +523,8 @@ u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type,
 		e820_print_type(old_type);
 	printk(KERN_CONT "\n");
 
-	for (i = 0; i < e820->nr_map; i++) {
-		struct e820_entry *ei = &e820->map[i];
+	for (i = 0; i < e820_array->nr_map; i++) {
+		struct e820_entry *ei = &e820_array->map[i];
 		u64 final_start, final_end;
 		u64 ei_end;
 
@@ -568,15 +568,15 @@ u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type,
 
 void __init update_e820(void)
 {
-	if (sanitize_e820_map(e820->map, ARRAY_SIZE(e820->map), &e820->nr_map))
+	if (sanitize_e820_array(e820_array->map, ARRAY_SIZE(e820_array->map), &e820_array->nr_map))
 		return;
 	printk(KERN_INFO "e820: modified physical RAM map:\n");
 	e820_print_map("modified");
 }
-static void __init update_e820_saved(void)
+static void __init update_e820_array_saved(void)
 {
-	sanitize_e820_map(e820_saved->map, ARRAY_SIZE(e820_saved->map),
-				&e820_saved->nr_map);
+	sanitize_e820_array(e820_array_saved->map, ARRAY_SIZE(e820_array_saved->map),
+				&e820_array_saved->nr_map);
 }
 #define MAX_GAP_END 0x100000000ull
 /*
@@ -586,12 +586,12 @@ static int __init e820_search_gap(unsigned long *gapstart,
 		unsigned long *gapsize)
 {
 	unsigned long long last = MAX_GAP_END;
-	int i = e820->nr_map;
+	int i = e820_array->nr_map;
 	int found = 0;
 
 	while (--i >= 0) {
-		unsigned long long start = e820->map[i].addr;
-		unsigned long long end = start + e820->map[i].size;
+		unsigned long long start = e820_array->map[i].addr;
+		unsigned long long end = start + e820_array->map[i].size;
 
 		/*
 		 * Since "last" is at most 4GB, we know we'll
@@ -650,7 +650,7 @@ __init void e820_setup_gap(void)
 /*
  * Called late during init, in free_initmem().
  *
- * Initial e820 and e820_saved are largish __initdata arrays.
+ * Initial e820 and e820_array_saved are largish __initdata arrays.
  * Copy them to (usually much smaller) dynamically allocated area.
  * This is done after all tweaks we ever do to them:
  * all functions which modify them are __init functions,
@@ -661,23 +661,23 @@ __init void e820_reallocate_tables(void)
 	struct e820_array *n;
 	int size;
 
-	size = offsetof(struct e820_array, map) + sizeof(struct e820_entry) * e820->nr_map;
+	size = offsetof(struct e820_array, map) + sizeof(struct e820_entry) * e820_array->nr_map;
 	n = kmalloc(size, GFP_KERNEL);
 	BUG_ON(!n);
-	memcpy(n, e820, size);
-	e820 = n;
+	memcpy(n, e820_array, size);
+	e820_array = n;
 
-	size = offsetof(struct e820_array, map) + sizeof(struct e820_entry) * e820_saved->nr_map;
+	size = offsetof(struct e820_array, map) + sizeof(struct e820_entry) * e820_array_saved->nr_map;
 	n = kmalloc(size, GFP_KERNEL);
 	BUG_ON(!n);
-	memcpy(n, e820_saved, size);
-	e820_saved = n;
+	memcpy(n, e820_array_saved, size);
+	e820_array_saved = n;
 }
 
 /**
  * Because of the size limitation of struct boot_params, only first
  * 128 E820 memory entries are passed to kernel via
- * boot_params.e820_map, others are passed via SETUP_E820_EXT node of
+ * boot_params.e820_array, others are passed via SETUP_E820_EXT node of
  * linked list of struct setup_data, which is parsed here.
  */
 void __init parse_e820_ext(u64 phys_addr, u32 data_len)
@@ -689,8 +689,8 @@ void __init parse_e820_ext(u64 phys_addr, u32 data_len)
 	sdata = early_memremap(phys_addr, data_len);
 	entries = sdata->len / sizeof(struct e820_entry);
 	extmap = (struct e820_entry *)(sdata->data);
-	__append_e820_map(extmap, entries);
-	sanitize_e820_map(e820->map, ARRAY_SIZE(e820->map), &e820->nr_map);
+	__append_e820_array(extmap, entries);
+	sanitize_e820_array(e820_array->map, ARRAY_SIZE(e820_array->map), &e820_array->nr_map);
 	early_memunmap(sdata, data_len);
 	printk(KERN_INFO "e820: extended physical RAM map:\n");
 	e820_print_map("extended");
@@ -709,8 +709,8 @@ void __init e820_mark_nosave_regions(unsigned long limit_pfn)
 	int i;
 	unsigned long pfn = 0;
 
-	for (i = 0; i < e820->nr_map; i++) {
-		struct e820_entry *ei = &e820->map[i];
+	for (i = 0; i < e820_array->nr_map; i++) {
+		struct e820_entry *ei = &e820_array->map[i];
 
 		if (pfn < PFN_UP(ei->addr))
 			register_nosave_region(pfn, PFN_UP(ei->addr));
@@ -734,8 +734,8 @@ static int __init e820_mark_nvs_memory(void)
 {
 	int i;
 
-	for (i = 0; i < e820->nr_map; i++) {
-		struct e820_entry *ei = &e820->map[i];
+	for (i = 0; i < e820_array->nr_map; i++) {
+		struct e820_entry *ei = &e820_array->map[i];
 
 		if (ei->type == E820_NVS)
 			acpi_nvs_register(ei->addr, ei->size);
@@ -747,7 +747,7 @@ core_initcall(e820_mark_nvs_memory);
 #endif
 
 /*
- * pre allocated 4k and reserved it in memblock and e820_saved
+ * pre allocated 4k and reserved it in memblock and e820_array_saved
  */
 u64 __init early_reserve_e820(u64 size, u64 align)
 {
@@ -756,8 +756,8 @@ u64 __init early_reserve_e820(u64 size, u64 align)
 	addr = __memblock_alloc_base(size, align, MEMBLOCK_ALLOC_ACCESSIBLE);
 	if (addr) {
 		e820_update_range_saved(addr, size, E820_RAM, E820_RESERVED);
-		printk(KERN_INFO "e820: update e820_saved for early_reserve_e820\n");
-		update_e820_saved();
+		printk(KERN_INFO "e820: update e820_array_saved for early_reserve_e820\n");
+		update_e820_array_saved();
 	}
 
 	return addr;
@@ -782,8 +782,8 @@ static unsigned long __init e820_end_pfn(unsigned long limit_pfn, unsigned type)
 	unsigned long last_pfn = 0;
 	unsigned long max_arch_pfn = MAX_ARCH_PFN;
 
-	for (i = 0; i < e820->nr_map; i++) {
-		struct e820_entry *ei = &e820->map[i];
+	for (i = 0; i < e820_array->nr_map; i++) {
+		struct e820_entry *ei = &e820_array->map[i];
 		unsigned long start_pfn;
 		unsigned long end_pfn;
 
@@ -874,7 +874,7 @@ static int __init parse_memmap_one(char *p)
 		 */
 		saved_max_pfn = e820_end_of_ram_pfn();
 #endif
-		e820->nr_map = 0;
+		e820_array->nr_map = 0;
 		userdef = 1;
 		return 0;
 	}
@@ -921,8 +921,8 @@ early_param("memmap", parse_memmap_opt);
 void __init finish_e820_parsing(void)
 {
 	if (userdef) {
-		if (sanitize_e820_map(e820->map, ARRAY_SIZE(e820->map),
-					&e820->nr_map) < 0)
+		if (sanitize_e820_array(e820_array->map, ARRAY_SIZE(e820_array->map),
+					&e820_array->nr_map) < 0)
 			early_panic("Invalid user supplied memory map");
 
 		printk(KERN_INFO "e820: user-defined physical RAM map:\n");
@@ -1009,35 +1009,35 @@ void __init e820_reserve_resources(void)
 	struct resource *res;
 	u64 end;
 
-	res = alloc_bootmem(sizeof(struct resource) * e820->nr_map);
+	res = alloc_bootmem(sizeof(struct resource) * e820_array->nr_map);
 	e820_res = res;
-	for (i = 0; i < e820->nr_map; i++) {
-		end = e820->map[i].addr + e820->map[i].size - 1;
+	for (i = 0; i < e820_array->nr_map; i++) {
+		end = e820_array->map[i].addr + e820_array->map[i].size - 1;
 		if (end != (resource_size_t)end) {
 			res++;
 			continue;
 		}
-		res->name = e820_type_to_string(e820->map[i].type);
-		res->start = e820->map[i].addr;
+		res->name = e820_type_to_string(e820_array->map[i].type);
+		res->start = e820_array->map[i].addr;
 		res->end = end;
 
-		res->flags = e820_type_to_iomem_type(e820->map[i].type);
-		res->desc = e820_type_to_iores_desc(e820->map[i].type);
+		res->flags = e820_type_to_iomem_type(e820_array->map[i].type);
+		res->desc = e820_type_to_iores_desc(e820_array->map[i].type);
 
 		/*
 		 * don't register the region that could be conflicted with
 		 * pci device BAR resource and insert them later in
 		 * pcibios_resource_survey()
 		 */
-		if (do_mark_busy(e820->map[i].type, res)) {
+		if (do_mark_busy(e820_array->map[i].type, res)) {
 			res->flags |= IORESOURCE_BUSY;
 			insert_resource(&iomem_resource, res);
 		}
 		res++;
 	}
 
-	for (i = 0; i < e820_saved->nr_map; i++) {
-		struct e820_entry *entry = &e820_saved->map[i];
+	for (i = 0; i < e820_array_saved->nr_map; i++) {
+		struct e820_entry *entry = &e820_array_saved->map[i];
 		firmware_map_add_early(entry->addr,
 			entry->addr + entry->size,
 			e820_type_to_string(entry->type));
@@ -1069,7 +1069,7 @@ void __init e820_reserve_resources_late(void)
 	struct resource *res;
 
 	res = e820_res;
-	for (i = 0; i < e820->nr_map; i++) {
+	for (i = 0; i < e820_array->nr_map; i++) {
 		if (!res->parent && res->end)
 			insert_resource_expand_to_fit(&iomem_resource, res);
 		res++;
@@ -1079,8 +1079,8 @@ void __init e820_reserve_resources_late(void)
 	 * Try to bump up RAM regions to reasonable boundaries to
 	 * avoid stolen RAM:
 	 */
-	for (i = 0; i < e820->nr_map; i++) {
-		struct e820_entry *entry = &e820->map[i];
+	for (i = 0; i < e820_array->nr_map; i++) {
+		struct e820_entry *entry = &e820_array->map[i];
 		u64 start, end;
 
 		if (entry->type != E820_RAM)
@@ -1110,11 +1110,11 @@ char *__init default_machine_specific_memory_setup(void)
 	 * the next section from 1mb->appropriate_mem_k
 	 */
 	new_nr = boot_params.e820_entries;
-	sanitize_e820_map(boot_params.e820_map,
-			ARRAY_SIZE(boot_params.e820_map),
+	sanitize_e820_array(boot_params.e820_array,
+			ARRAY_SIZE(boot_params.e820_array),
 			&new_nr);
 	boot_params.e820_entries = new_nr;
-	if (append_e820_map(boot_params.e820_map, boot_params.e820_entries)
+	if (append_e820_array(boot_params.e820_array, boot_params.e820_entries)
 	  < 0) {
 		u64 mem_size;
 
@@ -1128,7 +1128,7 @@ char *__init default_machine_specific_memory_setup(void)
 			who = "BIOS-e801";
 		}
 
-		e820->nr_map = 0;
+		e820_array->nr_map = 0;
 		e820_add_region(0, LOWMEMSIZE(), E820_RAM);
 		e820_add_region(HIGH_MEMORY, mem_size << 10, E820_RAM);
 	}
@@ -1142,7 +1142,7 @@ void __init setup_memory_map(void)
 	char *who;
 
 	who = x86_init.resources.memory_setup();
-	memcpy(e820_saved, e820, sizeof(struct e820_array));
+	memcpy(e820_array_saved, e820_array, sizeof(struct e820_array));
 	printk(KERN_INFO "e820: BIOS-provided physical RAM map:\n");
 	e820_print_map(who);
 }
@@ -1159,8 +1159,8 @@ void __init memblock_x86_fill(void)
 	 */
 	memblock_allow_resize();
 
-	for (i = 0; i < e820->nr_map; i++) {
-		struct e820_entry *ei = &e820->map[i];
+	for (i = 0; i < e820_array->nr_map; i++) {
+		struct e820_entry *ei = &e820_array->map[i];
 
 		end = ei->addr + ei->size;
 		if (end != (resource_size_t)end)
diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c
index 6a08e25a48d8..31d755534c36 100644
--- a/arch/x86/kernel/early-quirks.c
+++ b/arch/x86/kernel/early-quirks.c
@@ -547,7 +547,7 @@ intel_graphics_stolen(int num, int slot, int func,
 
 	/* Mark this space as reserved */
 	e820_add_region(base, size, E820_RESERVED);
-	sanitize_e820_map(e820->map, ARRAY_SIZE(e820->map), &e820->nr_map);
+	sanitize_e820_array(e820_array->map, ARRAY_SIZE(e820_array->map), &e820_array->nr_map);
 }
 
 static void __init intel_graphics_quirks(int num, int slot, int func)
diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
index d70e8d65cc16..6bedcb9bad1e 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -100,14 +100,14 @@ static int setup_e820_entries(struct boot_params *params)
 {
 	unsigned int nr_e820_entries;
 
-	nr_e820_entries = e820_saved->nr_map;
+	nr_e820_entries = e820_array_saved->nr_map;
 
 	/* TODO: Pass entries more than E820MAX in bootparams setup data */
 	if (nr_e820_entries > E820MAX)
 		nr_e820_entries = E820MAX;
 
 	params->e820_entries = nr_e820_entries;
-	memcpy(&params->e820_map, &e820_saved->map,
+	memcpy(&params->e820_array, &e820_array_saved->map,
 	       nr_e820_entries * sizeof(struct e820_entry));
 
 	return 0;
@@ -233,10 +233,10 @@ setup_boot_parameters(struct kimage *image, struct boot_params *params,
 	nr_e820_entries = params->e820_entries;
 
 	for (i = 0; i < nr_e820_entries; i++) {
-		if (params->e820_map[i].type != E820_RAM)
+		if (params->e820_array[i].type != E820_RAM)
 			continue;
-		start = params->e820_map[i].addr;
-		end = params->e820_map[i].addr + params->e820_map[i].size - 1;
+		start = params->e820_array[i].addr;
+		end = params->e820_array[i].addr + params->e820_array[i].size - 1;
 
 		if ((start <= 0x100000) && end > 0x100000) {
 			mem_k = (end >> 10) - (0x100000 >> 10);
diff --git a/arch/x86/kernel/resource.c b/arch/x86/kernel/resource.c
index 06a6e8049070..aeec503e0a6d 100644
--- a/arch/x86/kernel/resource.c
+++ b/arch/x86/kernel/resource.c
@@ -27,8 +27,8 @@ static void remove_e820_regions(struct resource *avail)
 	int i;
 	struct e820_entry *entry;
 
-	for (i = 0; i < e820->nr_map; i++) {
-		entry = &e820->map[i];
+	for (i = 0; i < e820_array->nr_map; i++) {
+		entry = &e820_array->map[i];
 
 		resource_clip(avail, entry->addr,
 			      entry->addr + entry->size - 1);
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index d2bdda9c3d6f..a91db2edee9e 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -458,8 +458,8 @@ static void __init e820_reserve_setup_data(void)
 		early_memunmap(data, sizeof(*data));
 	}
 
-	sanitize_e820_map(e820->map, ARRAY_SIZE(e820->map), &e820->nr_map);
-	memcpy(e820_saved, e820, sizeof(struct e820_array));
+	sanitize_e820_array(e820_array->map, ARRAY_SIZE(e820_array->map), &e820_array->nr_map);
+	memcpy(e820_array_saved, e820_array, sizeof(struct e820_array));
 	printk(KERN_INFO "extended physical RAM map:\n");
 	e820_print_map("reserve setup_data");
 }
@@ -763,7 +763,7 @@ static void __init trim_bios_range(void)
 	 */
 	e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
 
-	sanitize_e820_map(e820->map, ARRAY_SIZE(e820->map), &e820->nr_map);
+	sanitize_e820_array(e820_array->map, ARRAY_SIZE(e820_array->map), &e820_array->nr_map);
 }
 
 /* called before trim_bios_range() to spare extra sanitize */
@@ -1026,7 +1026,7 @@ void __init setup_arch(char **cmdline_p)
 		early_dump_pci_devices();
 #endif
 
-	/* update the e820_saved too */
+	/* update the e820_array_saved too */
 	e820_reserve_setup_data();
 	finish_e820_parsing();
 
@@ -1056,7 +1056,7 @@ void __init setup_arch(char **cmdline_p)
 	if (ppro_with_ram_bug()) {
 		e820_update_range(0x70000000ULL, 0x40000ULL, E820_RAM,
 				  E820_RESERVED);
-		sanitize_e820_map(e820->map, ARRAY_SIZE(e820->map), &e820->nr_map);
+		sanitize_e820_array(e820_array->map, ARRAY_SIZE(e820_array->map), &e820_array->nr_map);
 		printk(KERN_INFO "fixed physical RAM map:\n");
 		e820_print_map("bad_ppro");
 	}
diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
index d047da50f2de..705f1207181a 100644
--- a/arch/x86/kernel/tboot.c
+++ b/arch/x86/kernel/tboot.c
@@ -188,12 +188,12 @@ static int tboot_setup_sleep(void)
 
 	tboot->num_mac_regions = 0;
 
-	for (i = 0; i < e820->nr_map; i++) {
-		if ((e820->map[i].type != E820_RAM)
-		 && (e820->map[i].type != E820_RESERVED_KERN))
+	for (i = 0; i < e820_array->nr_map; i++) {
+		if ((e820_array->map[i].type != E820_RAM)
+		 && (e820_array->map[i].type != E820_RESERVED_KERN))
 			continue;
 
-		add_mac_region(e820->map[i].addr, e820->map[i].size);
+		add_mac_region(e820_array->map[i].addr, e820_array->map[i].size);
 	}
 
 	tboot->acpi_sinfo.kernel_s3_resume_vector =
diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
index 638d997327c9..09226a33e418 100644
--- a/arch/x86/lguest/boot.c
+++ b/arch/x86/lguest/boot.c
@@ -1178,9 +1178,9 @@ static __init char *lguest_memory_setup(void)
 	 * The Linux bootloader header contains an "e820" memory map: the
 	 * Launcher populated the first entry with our memory limit.
 	 */
-	e820_add_region(boot_params.e820_map[0].addr,
-			  boot_params.e820_map[0].size,
-			  boot_params.e820_map[0].type);
+	e820_add_region(boot_params.e820_array[0].addr,
+			  boot_params.e820_array[0].size,
+			  boot_params.e820_array[0].type);
 
 	/* This string is for the boot messages. */
 	return "LGUEST";
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index 528f682ec640..2543a11c9df8 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -167,7 +167,7 @@ static void __init do_add_efi_memmap(void)
 		}
 		e820_add_region(start, size, e820_type);
 	}
-	sanitize_e820_map(e820->map, ARRAY_SIZE(e820->map), &e820->nr_map);
+	sanitize_e820_array(e820_array->map, ARRAY_SIZE(e820_array->map), &e820_array->nr_map);
 }
 
 int __init efi_memblock_x86_reserve_range(void)
diff --git a/arch/x86/power/hibernate_64.c b/arch/x86/power/hibernate_64.c
index 874aea614fcf..c1a245e64ed1 100644
--- a/arch/x86/power/hibernate_64.c
+++ b/arch/x86/power/hibernate_64.c
@@ -232,7 +232,7 @@ static int get_e820_md5(struct e820_array *map, void *buf)
 
 static void hibernation_e820_save(void *buf)
 {
-	get_e820_md5(e820_saved, buf);
+	get_e820_md5(e820_array_saved, buf);
 }
 
 static bool hibernation_e820_mismatch(void *buf)
@@ -245,7 +245,7 @@ static bool hibernation_e820_mismatch(void *buf)
 	if (!memcmp(result, buf, MD5_DIGEST_SIZE))
 		return false;
 
-	ret = get_e820_md5(e820_saved, result);
+	ret = get_e820_md5(e820_array_saved, result);
 	if (ret)
 		return true;
 
diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
index 7386a6e4c072..3cc90e902064 100644
--- a/arch/x86/xen/setup.c
+++ b/arch/x86/xen/setup.c
@@ -41,8 +41,8 @@ struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata;
 unsigned long xen_released_pages;
 
 /* E820 map used during setting up memory. */
-static struct e820_entry xen_e820_map[E820_X_MAX] __initdata;
-static u32 xen_e820_map_entries __initdata;
+static struct e820_entry xen_e820_array[E820_X_MAX] __initdata;
+static u32 xen_e820_array_entries __initdata;
 
 /*
  * Buffer used to remap identity mapped pages. We only need the virtual space.
@@ -198,11 +198,11 @@ void __init xen_inv_extra_mem(void)
  */
 static unsigned long __init xen_find_pfn_range(unsigned long *min_pfn)
 {
-	const struct e820_entry *entry = xen_e820_map;
+	const struct e820_entry *entry = xen_e820_array;
 	unsigned int i;
 	unsigned long done = 0;
 
-	for (i = 0; i < xen_e820_map_entries; i++, entry++) {
+	for (i = 0; i < xen_e820_array_entries; i++, entry++) {
 		unsigned long s_pfn;
 		unsigned long e_pfn;
 
@@ -457,7 +457,7 @@ static unsigned long __init xen_foreach_remap_area(unsigned long nr_pages,
 {
 	phys_addr_t start = 0;
 	unsigned long ret_val = 0;
-	const struct e820_entry *entry = xen_e820_map;
+	const struct e820_entry *entry = xen_e820_array;
 	int i;
 
 	/*
@@ -471,9 +471,9 @@ static unsigned long __init xen_foreach_remap_area(unsigned long nr_pages,
 	 * example) the DMI tables in a reserved region that begins on
 	 * a non-page boundary.
 	 */
-	for (i = 0; i < xen_e820_map_entries; i++, entry++) {
+	for (i = 0; i < xen_e820_array_entries; i++, entry++) {
 		phys_addr_t end = entry->addr + entry->size;
-		if (entry->type == E820_RAM || i == xen_e820_map_entries - 1) {
+		if (entry->type == E820_RAM || i == xen_e820_array_entries - 1) {
 			unsigned long start_pfn = PFN_DOWN(start);
 			unsigned long end_pfn = PFN_UP(end);
 
@@ -601,10 +601,10 @@ static void __init xen_align_and_add_e820_region(phys_addr_t start,
 
 static void __init xen_ignore_unusable(void)
 {
-	struct e820_entry *entry = xen_e820_map;
+	struct e820_entry *entry = xen_e820_array;
 	unsigned int i;
 
-	for (i = 0; i < xen_e820_map_entries; i++, entry++) {
+	for (i = 0; i < xen_e820_array_entries; i++, entry++) {
 		if (entry->type == E820_UNUSABLE)
 			entry->type = E820_RAM;
 	}
@@ -620,9 +620,9 @@ bool __init xen_is_e820_reserved(phys_addr_t start, phys_addr_t size)
 		return false;
 
 	end = start + size;
-	entry = xen_e820_map;
+	entry = xen_e820_array;
 
-	for (mapcnt = 0; mapcnt < xen_e820_map_entries; mapcnt++) {
+	for (mapcnt = 0; mapcnt < xen_e820_array_entries; mapcnt++) {
 		if (entry->type == E820_RAM && entry->addr <= start &&
 		    (entry->addr + entry->size) >= end)
 			return false;
@@ -645,9 +645,9 @@ phys_addr_t __init xen_find_free_area(phys_addr_t size)
 {
 	unsigned mapcnt;
 	phys_addr_t addr, start;
-	struct e820_entry *entry = xen_e820_map;
+	struct e820_entry *entry = xen_e820_array;
 
-	for (mapcnt = 0; mapcnt < xen_e820_map_entries; mapcnt++, entry++) {
+	for (mapcnt = 0; mapcnt < xen_e820_array_entries; mapcnt++, entry++) {
 		if (entry->type != E820_RAM || entry->size < size)
 			continue;
 		start = entry->addr;
@@ -750,8 +750,8 @@ char * __init xen_memory_setup(void)
 	max_pfn = min(max_pfn, xen_start_info->nr_pages);
 	mem_end = PFN_PHYS(max_pfn);
 
-	memmap.nr_entries = ARRAY_SIZE(xen_e820_map);
-	set_xen_guest_handle(memmap.buffer, xen_e820_map);
+	memmap.nr_entries = ARRAY_SIZE(xen_e820_array);
+	set_xen_guest_handle(memmap.buffer, xen_e820_array);
 
 	op = xen_initial_domain() ?
 		XENMEM_machine_memory_map :
@@ -760,16 +760,16 @@ char * __init xen_memory_setup(void)
 	if (rc == -ENOSYS) {
 		BUG_ON(xen_initial_domain());
 		memmap.nr_entries = 1;
-		xen_e820_map[0].addr = 0ULL;
-		xen_e820_map[0].size = mem_end;
+		xen_e820_array[0].addr = 0ULL;
+		xen_e820_array[0].size = mem_end;
 		/* 8MB slack (to balance backend allocations). */
-		xen_e820_map[0].size += 8ULL << 20;
-		xen_e820_map[0].type = E820_RAM;
+		xen_e820_array[0].size += 8ULL << 20;
+		xen_e820_array[0].type = E820_RAM;
 		rc = 0;
 	}
 	BUG_ON(rc);
 	BUG_ON(memmap.nr_entries == 0);
-	xen_e820_map_entries = memmap.nr_entries;
+	xen_e820_array_entries = memmap.nr_entries;
 
 	/*
 	 * Xen won't allow a 1:1 mapping to be created to UNUSABLE
@@ -783,8 +783,8 @@ char * __init xen_memory_setup(void)
 		xen_ignore_unusable();
 
 	/* Make sure the Xen-supplied memory map is well-ordered. */
-	sanitize_e820_map(xen_e820_map, ARRAY_SIZE(xen_e820_map),
-			  &xen_e820_map_entries);
+	sanitize_e820_array(xen_e820_array, ARRAY_SIZE(xen_e820_array),
+			  &xen_e820_array_entries);
 
 	max_pages = xen_get_max_pages();
 
@@ -811,13 +811,13 @@ char * __init xen_memory_setup(void)
 	extra_pages = min3(EXTRA_MEM_RATIO * min(max_pfn, PFN_DOWN(MAXMEM)),
 			   extra_pages, max_pages - max_pfn);
 	i = 0;
-	addr = xen_e820_map[0].addr;
-	size = xen_e820_map[0].size;
-	while (i < xen_e820_map_entries) {
+	addr = xen_e820_array[0].addr;
+	size = xen_e820_array[0].size;
+	while (i < xen_e820_array_entries) {
 		bool discard = false;
 
 		chunk_size = size;
-		type = xen_e820_map[i].type;
+		type = xen_e820_array[i].type;
 
 		if (type == E820_RAM) {
 			if (addr < mem_end) {
@@ -840,9 +840,9 @@ char * __init xen_memory_setup(void)
 		size -= chunk_size;
 		if (size == 0) {
 			i++;
-			if (i < xen_e820_map_entries) {
-				addr = xen_e820_map[i].addr;
-				size = xen_e820_map[i].size;
+			if (i < xen_e820_array_entries) {
+				addr = xen_e820_array[i].addr;
+				size = xen_e820_array[i].size;
 			}
 		}
 	}
@@ -861,7 +861,7 @@ char * __init xen_memory_setup(void)
 	e820_add_region(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS,
 			E820_RESERVED);
 
-	sanitize_e820_map(e820->map, ARRAY_SIZE(e820->map), &e820->nr_map);
+	sanitize_e820_array(e820_array->map, ARRAY_SIZE(e820_array->map), &e820_array->nr_map);
 
 	/*
 	 * Check whether the kernel itself conflicts with the target E820 map.
@@ -923,21 +923,21 @@ char * __init xen_auto_xlated_memory_setup(void)
 	int i;
 	int rc;
 
-	memmap.nr_entries = ARRAY_SIZE(xen_e820_map);
-	set_xen_guest_handle(memmap.buffer, xen_e820_map);
+	memmap.nr_entries = ARRAY_SIZE(xen_e820_array);
+	set_xen_guest_handle(memmap.buffer, xen_e820_array);
 
 	rc = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap);
 	if (rc < 0)
 		panic("No memory map (%d)\n", rc);
 
-	xen_e820_map_entries = memmap.nr_entries;
+	xen_e820_array_entries = memmap.nr_entries;
 
-	sanitize_e820_map(xen_e820_map, ARRAY_SIZE(xen_e820_map),
-			  &xen_e820_map_entries);
+	sanitize_e820_array(xen_e820_array, ARRAY_SIZE(xen_e820_array),
+			  &xen_e820_array_entries);
 
-	for (i = 0; i < xen_e820_map_entries; i++)
-		e820_add_region(xen_e820_map[i].addr, xen_e820_map[i].size,
-				xen_e820_map[i].type);
+	for (i = 0; i < xen_e820_array_entries; i++)
+		e820_add_region(xen_e820_array[i].addr, xen_e820_array[i].size,
+				xen_e820_array[i].type);
 
 	/* Remove p2m info, it is not needed. */
 	xen_start_info->mfn_list = 0;
diff --git a/tools/lguest/lguest.c b/tools/lguest/lguest.c
index 7deb8d4a976e..92a1fe3c07eb 100644
--- a/tools/lguest/lguest.c
+++ b/tools/lguest/lguest.c
@@ -3339,7 +3339,7 @@ int main(int argc, char *argv[])
 	 * simple, single region.
 	 */
 	boot->e820_entries = 1;
-	boot->e820_map[0] = ((struct e820_entry) { 0, mem, E820_RAM });
+	boot->e820_array[0] = ((struct e820_entry) { 0, mem, E820_RAM });
 	/*
 	 * The boot header contains a command line pointer: we put the command
 	 * line after the boot header.
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 15/50] x86/boot/e820: Rename everything to e820_table
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (13 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 14/50] x86/boot/e820: Rename 'e820_map' variables to 'e820_array' Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 16/50] x86/boot/e820: Harmonize the 'struct e820_table' fields Ingo Molnar
                   ` (34 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 Documentation/x86/zero-page.txt       |   4 +-
 arch/x86/boot/compressed/eboot.c      |  22 ++++----
 arch/x86/boot/compressed/kaslr.c      |   2 +-
 arch/x86/boot/memory.c                |   4 +-
 arch/x86/include/asm/e820/api.h       |   6 +--
 arch/x86/include/asm/e820/types.h     |   4 +-
 arch/x86/include/uapi/asm/bootparam.h |   2 +-
 arch/x86/kernel/crash.c               |   2 +-
 arch/x86/kernel/e820.c                | 152 +++++++++++++++++++++++++++---------------------------
 arch/x86/kernel/early-quirks.c        |   2 +-
 arch/x86/kernel/kexec-bzimage64.c     |  10 ++--
 arch/x86/kernel/resource.c            |   4 +-
 arch/x86/kernel/setup.c               |  10 ++--
 arch/x86/kernel/tboot.c               |   8 +--
 arch/x86/lguest/boot.c                |   6 +--
 arch/x86/platform/efi/efi.c           |   2 +-
 arch/x86/power/hibernate_64.c         |   8 +--
 arch/x86/xen/setup.c                  |  76 +++++++++++++--------------
 tools/lguest/lguest.c                 |   2 +-
 19 files changed, 163 insertions(+), 163 deletions(-)

diff --git a/Documentation/x86/zero-page.txt b/Documentation/x86/zero-page.txt
index b323b705f419..363dca7b446b 100644
--- a/Documentation/x86/zero-page.txt
+++ b/Documentation/x86/zero-page.txt
@@ -27,12 +27,12 @@ Offset	Proto	Name		Meaning
 1C0/020	ALL	efi_info	EFI 32 information (struct efi_info)
 1E0/004	ALL	alk_mem_k	Alternative mem check, in KB
 1E4/004	ALL	scratch		Scratch field for the kernel setup code
-1E8/001	ALL	e820_entries	Number of entries in e820_array (below)
+1E8/001	ALL	e820_entries	Number of entries in e820_table (below)
 1E9/001	ALL	eddbuf_entries	Number of entries in eddbuf (below)
 1EA/001	ALL	edd_mbr_sig_buf_entries	Number of entries in edd_mbr_sig_buffer
 				(below)
 1EF/001	ALL	sentinel	Used to detect broken bootloaders
 290/040	ALL	edd_mbr_sig_buffer EDD MBR signatures
-2D0/A00	ALL	e820_array	E820 memory map table
+2D0/A00	ALL	e820_table	E820 memory map table
 				(array of struct e820_entry)
 D00/1EC	ALL	eddbuf		EDD data (array of struct edd_info)
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index b5cc1e72c63a..04c406f9aee3 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -917,7 +917,7 @@ static void add_e820ext(struct boot_params *params,
 static efi_status_t setup_e820(struct boot_params *params,
 			       struct setup_data *e820ext, u32 e820ext_size)
 {
-	struct e820_entry *e820_array = &params->e820_array[0];
+	struct e820_entry *e820_table = &params->e820_table[0];
 	struct efi_info *efi = &params->efi_info;
 	struct e820_entry *prev = NULL;
 	u32 nr_entries;
@@ -982,7 +982,7 @@ static efi_status_t setup_e820(struct boot_params *params,
 			continue;
 		}
 
-		if (nr_entries == ARRAY_SIZE(params->e820_array)) {
+		if (nr_entries == ARRAY_SIZE(params->e820_table)) {
 			u32 need = (nr_desc - i) * sizeof(struct e820_entry) +
 				   sizeof(struct setup_data);
 
@@ -990,18 +990,18 @@ static efi_status_t setup_e820(struct boot_params *params,
 				return EFI_BUFFER_TOO_SMALL;
 
 			/* boot_params map full, switch to e820 extended */
-			e820_array = (struct e820_entry *)e820ext->data;
+			e820_table = (struct e820_entry *)e820ext->data;
 		}
 
-		e820_array->addr = d->phys_addr;
-		e820_array->size = d->num_pages << PAGE_SHIFT;
-		e820_array->type = e820_type;
-		prev = e820_array++;
+		e820_table->addr = d->phys_addr;
+		e820_table->size = d->num_pages << PAGE_SHIFT;
+		e820_table->type = e820_type;
+		prev = e820_table++;
 		nr_entries++;
 	}
 
-	if (nr_entries > ARRAY_SIZE(params->e820_array)) {
-		u32 nr_e820ext = nr_entries - ARRAY_SIZE(params->e820_array);
+	if (nr_entries > ARRAY_SIZE(params->e820_table)) {
+		u32 nr_e820ext = nr_entries - ARRAY_SIZE(params->e820_table);
 
 		add_e820ext(params, e820ext, nr_e820ext);
 		nr_entries -= nr_e820ext;
@@ -1055,9 +1055,9 @@ static efi_status_t exit_boot_func(efi_system_table_t *sys_table_arg,
 
 	if (first) {
 		nr_desc = *map->buff_size / *map->desc_size;
-		if (nr_desc > ARRAY_SIZE(p->boot_params->e820_array)) {
+		if (nr_desc > ARRAY_SIZE(p->boot_params->e820_table)) {
 			u32 nr_e820ext = nr_desc -
-					ARRAY_SIZE(p->boot_params->e820_array);
+					ARRAY_SIZE(p->boot_params->e820_table);
 
 			status = alloc_e820ext(nr_e820ext, &p->e820ext,
 					       &p->e820ext_size);
diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index f0e37236cfe1..a47f832664f2 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -518,7 +518,7 @@ static unsigned long find_random_phys_addr(unsigned long minimum,
 
 	/* Verify potential e820 positions, appending to slots list. */
 	for (i = 0; i < boot_params->e820_entries; i++) {
-		process_e820_entry(&boot_params->e820_array[i], minimum,
+		process_e820_entry(&boot_params->e820_table[i], minimum,
 				   image_size);
 		if (slot_area_index == MAX_SLOT_AREA) {
 			debug_putstr("Aborted e820 scan (slot_areas full)!\n");
diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
index f2132b3e6880..db62445b75aa 100644
--- a/arch/x86/boot/memory.c
+++ b/arch/x86/boot/memory.c
@@ -21,7 +21,7 @@ static int detect_memory_e820(void)
 {
 	int count = 0;
 	struct biosregs ireg, oreg;
-	struct e820_entry *desc = boot_params.e820_array;
+	struct e820_entry *desc = boot_params.e820_table;
 	static struct e820_entry buf; /* static so it is zeroed */
 
 	initregs(&ireg);
@@ -66,7 +66,7 @@ static int detect_memory_e820(void)
 
 		*desc++ = buf;
 		count++;
-	} while (ireg.ebx && count < ARRAY_SIZE(boot_params.e820_array));
+	} while (ireg.ebx && count < ARRAY_SIZE(boot_params.e820_table));
 
 	return boot_params.e820_entries = count;
 }
diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 0156532dd65a..91a5c346f765 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -4,8 +4,8 @@
 #include <asm/e820/types.h>
 
 /* see comment in arch/x86/kernel/e820.c */
-extern struct e820_array *e820_array;
-extern struct e820_array *e820_array_saved;
+extern struct e820_table *e820_table;
+extern struct e820_table *e820_table_saved;
 
 extern unsigned long pci_mem_start;
 
@@ -13,7 +13,7 @@ extern int  e820_any_mapped(u64 start, u64 end, unsigned type);
 extern int  e820_all_mapped(u64 start, u64 end, unsigned type);
 extern void e820_add_region(u64 start, u64 size, int type);
 extern void e820_print_map(char *who);
-extern int  sanitize_e820_array(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map);
+extern int  sanitize_e820_table(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map);
 extern u64  e820_update_range(u64 start, u64 size, unsigned old_type, unsigned new_type);
 extern u64  e820_remove_range(u64 start, u64 size, unsigned old_type, int checktype);
 extern void update_e820(void);
diff --git a/arch/x86/include/asm/e820/types.h b/arch/x86/include/asm/e820/types.h
index e3171867e126..ae2c4e9db0d4 100644
--- a/arch/x86/include/asm/e820/types.h
+++ b/arch/x86/include/asm/e820/types.h
@@ -21,7 +21,7 @@
  *
  * 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_array() to remove duplicates.  The allowance
+ * call to sanitize_e820_table() 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
@@ -68,7 +68,7 @@
 /*
  * The whole array of E820 entries:
  */
-struct e820_array {
+struct e820_table {
 	__u32 nr_map;
 	struct e820_entry map[E820_X_MAX];
 };
diff --git a/arch/x86/include/uapi/asm/bootparam.h b/arch/x86/include/uapi/asm/bootparam.h
index 702f1c6d804e..5f41518f7159 100644
--- a/arch/x86/include/uapi/asm/bootparam.h
+++ b/arch/x86/include/uapi/asm/bootparam.h
@@ -152,7 +152,7 @@ struct boot_params {
 	struct setup_header hdr;    /* setup header */	/* 0x1f1 */
 	__u8  _pad7[0x290-0x1f1-sizeof(struct setup_header)];
 	__u32 edd_mbr_sig_buffer[EDD_MBR_SIG_MAX];	/* 0x290 */
-	struct e820_entry e820_array[E820MAX];		/* 0x2d0 */
+	struct e820_entry e820_table[E820MAX];		/* 0x2d0 */
 	__u8  _pad8[48];				/* 0xcd0 */
 	struct edd_info eddbuf[EDDMAXNR];		/* 0xd00 */
 	__u8  _pad9[276];				/* 0xeec */
diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
index 036d9140384d..11f7eb1e2506 100644
--- a/arch/x86/kernel/crash.c
+++ b/arch/x86/kernel/crash.c
@@ -512,7 +512,7 @@ static int add_e820_entry(struct boot_params *params, struct e820_entry *entry)
 	if (nr_e820_entries >= E820MAX)
 		return 1;
 
-	memcpy(&params->e820_array[nr_e820_entries], entry,
+	memcpy(&params->e820_table[nr_e820_entries], entry,
 			sizeof(struct e820_entry));
 	params->e820_entries++;
 	return 0;
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 49d47d6b1afe..ffaf94357d15 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -2,7 +2,7 @@
  * Handle the memory map.
  * The functions here do the job until bootmem takes over.
  *
- *  Getting sanitize_e820_array() in sync with i386 version by applying change:
+ *  Getting sanitize_e820_table() in sync with i386 version by applying change:
  *  -  Provisions for empty E820 memory regions (reported by certain BIOSes).
  *     Alex Achenbach <xela@slit.de>, December 2002.
  *  Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
@@ -31,7 +31,7 @@
  * and that is also registered with modifications in the kernel resource tree
  * with the iomem_resource as parent.
  *
- * The e820_array_saved is directly saved after the BIOS-provided memory map is
+ * The e820_table_saved is directly saved after the BIOS-provided memory map is
  * copied. It doesn't get modified afterwards. It's registered for the
  * /sys/firmware/memmap interface.
  *
@@ -40,10 +40,10 @@
  * user can e.g. boot the original kernel with mem=1G while still booting the
  * next kernel with full memory.
  */
-static struct e820_array e820_array_init  __initdata;
-static struct e820_array initial_e820_array_saved  __initdata;
-struct e820_array *e820_array __refdata = &e820_array_init;
-struct e820_array *e820_array_saved __refdata = &initial_e820_array_saved;
+static struct e820_table e820_table_init  __initdata;
+static struct e820_table initial_e820_table_saved  __initdata;
+struct e820_table *e820_table __refdata = &e820_table_init;
+struct e820_table *e820_table_saved __refdata = &initial_e820_table_saved;
 
 /* For PCI or other memory-mapped resources */
 unsigned long pci_mem_start = 0xaeedbabe;
@@ -60,8 +60,8 @@ e820_any_mapped(u64 start, u64 end, unsigned type)
 {
 	int i;
 
-	for (i = 0; i < e820_array->nr_map; i++) {
-		struct e820_entry *ei = &e820_array->map[i];
+	for (i = 0; i < e820_table->nr_map; i++) {
+		struct e820_entry *ei = &e820_table->map[i];
 
 		if (type && ei->type != type)
 			continue;
@@ -83,8 +83,8 @@ int __init e820_all_mapped(u64 start, u64 end, unsigned type)
 {
 	int i;
 
-	for (i = 0; i < e820_array->nr_map; i++) {
-		struct e820_entry *ei = &e820_array->map[i];
+	for (i = 0; i < e820_table->nr_map; i++) {
+		struct e820_entry *ei = &e820_table->map[i];
 
 		if (type && ei->type != type)
 			continue;
@@ -110,7 +110,7 @@ int __init e820_all_mapped(u64 start, u64 end, unsigned type)
 /*
  * Add a memory region to the kernel e820 map.
  */
-static void __init __e820_add_region(struct e820_array *e820x, u64 start, u64 size,
+static void __init __e820_add_region(struct e820_table *e820x, u64 start, u64 size,
 					 int type)
 {
 	int x = e820x->nr_map;
@@ -130,7 +130,7 @@ static void __init __e820_add_region(struct e820_array *e820x, u64 start, u64 si
 
 void __init e820_add_region(u64 start, u64 size, int type)
 {
-	__e820_add_region(e820_array, start, size, type);
+	__e820_add_region(e820_table, start, size, type);
 }
 
 static void __init e820_print_type(u32 type)
@@ -166,12 +166,12 @@ void __init e820_print_map(char *who)
 {
 	int i;
 
-	for (i = 0; i < e820_array->nr_map; i++) {
+	for (i = 0; i < e820_table->nr_map; i++) {
 		printk(KERN_INFO "%s: [mem %#018Lx-%#018Lx] ", who,
-		       (unsigned long long) e820_array->map[i].addr,
+		       (unsigned long long) e820_table->map[i].addr,
 		       (unsigned long long)
-		       (e820_array->map[i].addr + e820_array->map[i].size - 1));
-		e820_print_type(e820_array->map[i].type);
+		       (e820_table->map[i].addr + e820_table->map[i].size - 1));
+		e820_print_type(e820_table->map[i].type);
 		printk(KERN_CONT "\n");
 	}
 }
@@ -195,7 +195,7 @@ void __init e820_print_map(char *who)
  * sanitizing succeeds the *pnr_map will be updated with the new
  * number of valid entries (something no more than max_nr_map).
  *
- * The return value from sanitize_e820_array() is zero if it
+ * The return value from sanitize_e820_table() is zero if it
  * successfully 'sanitized' the map entries passed in, and is -1
  * if it did nothing, which can happen if either of (1) it was
  * only passed one map entry, or (2) any of the input map entries
@@ -259,7 +259,7 @@ static int __init cpcompare(const void *a, const void *b)
 	return (ap->addr != ap->pbios->addr) - (bp->addr != bp->pbios->addr);
 }
 
-int __init sanitize_e820_array(struct e820_entry *biosmap, int max_nr_map,
+int __init sanitize_e820_table(struct e820_entry *biosmap, int max_nr_map,
 			     u32 *pnr_map)
 {
 	static struct change_member change_point_list[2*E820_X_MAX] __initdata;
@@ -385,7 +385,7 @@ int __init sanitize_e820_array(struct e820_entry *biosmap, int max_nr_map,
 	return 0;
 }
 
-static int __init __append_e820_array(struct e820_entry *biosmap, int nr_map)
+static int __init __append_e820_table(struct e820_entry *biosmap, int nr_map)
 {
 	while (nr_map) {
 		u64 start = biosmap->addr;
@@ -414,16 +414,16 @@ static int __init __append_e820_array(struct e820_entry *biosmap, int nr_map)
  * will have given us a memory map that we can use to properly
  * set up memory.  If we aren't, we'll fake a memory map.
  */
-static int __init append_e820_array(struct e820_entry *biosmap, int nr_map)
+static int __init append_e820_table(struct e820_entry *biosmap, int nr_map)
 {
 	/* Only one memory region (or negative)? Ignore it */
 	if (nr_map < 2)
 		return -1;
 
-	return __append_e820_array(biosmap, nr_map);
+	return __append_e820_table(biosmap, nr_map);
 }
 
-static u64 __init __e820_update_range(struct e820_array *e820x, u64 start,
+static u64 __init __e820_update_range(struct e820_table *e820x, u64 start,
 					u64 size, unsigned old_type,
 					unsigned new_type)
 {
@@ -495,13 +495,13 @@ static u64 __init __e820_update_range(struct e820_array *e820x, u64 start,
 u64 __init e820_update_range(u64 start, u64 size, unsigned old_type,
 			     unsigned new_type)
 {
-	return __e820_update_range(e820_array, start, size, old_type, new_type);
+	return __e820_update_range(e820_table, start, size, old_type, new_type);
 }
 
 static u64 __init e820_update_range_saved(u64 start, u64 size,
 					  unsigned old_type, unsigned new_type)
 {
-	return __e820_update_range(e820_array_saved, start, size, old_type,
+	return __e820_update_range(e820_table_saved, start, size, old_type,
 				     new_type);
 }
 
@@ -523,8 +523,8 @@ u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type,
 		e820_print_type(old_type);
 	printk(KERN_CONT "\n");
 
-	for (i = 0; i < e820_array->nr_map; i++) {
-		struct e820_entry *ei = &e820_array->map[i];
+	for (i = 0; i < e820_table->nr_map; i++) {
+		struct e820_entry *ei = &e820_table->map[i];
 		u64 final_start, final_end;
 		u64 ei_end;
 
@@ -568,15 +568,15 @@ u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type,
 
 void __init update_e820(void)
 {
-	if (sanitize_e820_array(e820_array->map, ARRAY_SIZE(e820_array->map), &e820_array->nr_map))
+	if (sanitize_e820_table(e820_table->map, ARRAY_SIZE(e820_table->map), &e820_table->nr_map))
 		return;
 	printk(KERN_INFO "e820: modified physical RAM map:\n");
 	e820_print_map("modified");
 }
-static void __init update_e820_array_saved(void)
+static void __init update_e820_table_saved(void)
 {
-	sanitize_e820_array(e820_array_saved->map, ARRAY_SIZE(e820_array_saved->map),
-				&e820_array_saved->nr_map);
+	sanitize_e820_table(e820_table_saved->map, ARRAY_SIZE(e820_table_saved->map),
+				&e820_table_saved->nr_map);
 }
 #define MAX_GAP_END 0x100000000ull
 /*
@@ -586,12 +586,12 @@ static int __init e820_search_gap(unsigned long *gapstart,
 		unsigned long *gapsize)
 {
 	unsigned long long last = MAX_GAP_END;
-	int i = e820_array->nr_map;
+	int i = e820_table->nr_map;
 	int found = 0;
 
 	while (--i >= 0) {
-		unsigned long long start = e820_array->map[i].addr;
-		unsigned long long end = start + e820_array->map[i].size;
+		unsigned long long start = e820_table->map[i].addr;
+		unsigned long long end = start + e820_table->map[i].size;
 
 		/*
 		 * Since "last" is at most 4GB, we know we'll
@@ -650,7 +650,7 @@ __init void e820_setup_gap(void)
 /*
  * Called late during init, in free_initmem().
  *
- * Initial e820 and e820_array_saved are largish __initdata arrays.
+ * Initial e820 and e820_table_saved are largish __initdata arrays.
  * Copy them to (usually much smaller) dynamically allocated area.
  * This is done after all tweaks we ever do to them:
  * all functions which modify them are __init functions,
@@ -658,26 +658,26 @@ __init void e820_setup_gap(void)
  */
 __init void e820_reallocate_tables(void)
 {
-	struct e820_array *n;
+	struct e820_table *n;
 	int size;
 
-	size = offsetof(struct e820_array, map) + sizeof(struct e820_entry) * e820_array->nr_map;
+	size = offsetof(struct e820_table, map) + sizeof(struct e820_entry) * e820_table->nr_map;
 	n = kmalloc(size, GFP_KERNEL);
 	BUG_ON(!n);
-	memcpy(n, e820_array, size);
-	e820_array = n;
+	memcpy(n, e820_table, size);
+	e820_table = n;
 
-	size = offsetof(struct e820_array, map) + sizeof(struct e820_entry) * e820_array_saved->nr_map;
+	size = offsetof(struct e820_table, map) + sizeof(struct e820_entry) * e820_table_saved->nr_map;
 	n = kmalloc(size, GFP_KERNEL);
 	BUG_ON(!n);
-	memcpy(n, e820_array_saved, size);
-	e820_array_saved = n;
+	memcpy(n, e820_table_saved, size);
+	e820_table_saved = n;
 }
 
 /**
  * Because of the size limitation of struct boot_params, only first
  * 128 E820 memory entries are passed to kernel via
- * boot_params.e820_array, others are passed via SETUP_E820_EXT node of
+ * boot_params.e820_table, others are passed via SETUP_E820_EXT node of
  * linked list of struct setup_data, which is parsed here.
  */
 void __init parse_e820_ext(u64 phys_addr, u32 data_len)
@@ -689,8 +689,8 @@ void __init parse_e820_ext(u64 phys_addr, u32 data_len)
 	sdata = early_memremap(phys_addr, data_len);
 	entries = sdata->len / sizeof(struct e820_entry);
 	extmap = (struct e820_entry *)(sdata->data);
-	__append_e820_array(extmap, entries);
-	sanitize_e820_array(e820_array->map, ARRAY_SIZE(e820_array->map), &e820_array->nr_map);
+	__append_e820_table(extmap, entries);
+	sanitize_e820_table(e820_table->map, ARRAY_SIZE(e820_table->map), &e820_table->nr_map);
 	early_memunmap(sdata, data_len);
 	printk(KERN_INFO "e820: extended physical RAM map:\n");
 	e820_print_map("extended");
@@ -709,8 +709,8 @@ void __init e820_mark_nosave_regions(unsigned long limit_pfn)
 	int i;
 	unsigned long pfn = 0;
 
-	for (i = 0; i < e820_array->nr_map; i++) {
-		struct e820_entry *ei = &e820_array->map[i];
+	for (i = 0; i < e820_table->nr_map; i++) {
+		struct e820_entry *ei = &e820_table->map[i];
 
 		if (pfn < PFN_UP(ei->addr))
 			register_nosave_region(pfn, PFN_UP(ei->addr));
@@ -734,8 +734,8 @@ static int __init e820_mark_nvs_memory(void)
 {
 	int i;
 
-	for (i = 0; i < e820_array->nr_map; i++) {
-		struct e820_entry *ei = &e820_array->map[i];
+	for (i = 0; i < e820_table->nr_map; i++) {
+		struct e820_entry *ei = &e820_table->map[i];
 
 		if (ei->type == E820_NVS)
 			acpi_nvs_register(ei->addr, ei->size);
@@ -747,7 +747,7 @@ core_initcall(e820_mark_nvs_memory);
 #endif
 
 /*
- * pre allocated 4k and reserved it in memblock and e820_array_saved
+ * pre allocated 4k and reserved it in memblock and e820_table_saved
  */
 u64 __init early_reserve_e820(u64 size, u64 align)
 {
@@ -756,8 +756,8 @@ u64 __init early_reserve_e820(u64 size, u64 align)
 	addr = __memblock_alloc_base(size, align, MEMBLOCK_ALLOC_ACCESSIBLE);
 	if (addr) {
 		e820_update_range_saved(addr, size, E820_RAM, E820_RESERVED);
-		printk(KERN_INFO "e820: update e820_array_saved for early_reserve_e820\n");
-		update_e820_array_saved();
+		printk(KERN_INFO "e820: update e820_table_saved for early_reserve_e820\n");
+		update_e820_table_saved();
 	}
 
 	return addr;
@@ -782,8 +782,8 @@ static unsigned long __init e820_end_pfn(unsigned long limit_pfn, unsigned type)
 	unsigned long last_pfn = 0;
 	unsigned long max_arch_pfn = MAX_ARCH_PFN;
 
-	for (i = 0; i < e820_array->nr_map; i++) {
-		struct e820_entry *ei = &e820_array->map[i];
+	for (i = 0; i < e820_table->nr_map; i++) {
+		struct e820_entry *ei = &e820_table->map[i];
 		unsigned long start_pfn;
 		unsigned long end_pfn;
 
@@ -874,7 +874,7 @@ static int __init parse_memmap_one(char *p)
 		 */
 		saved_max_pfn = e820_end_of_ram_pfn();
 #endif
-		e820_array->nr_map = 0;
+		e820_table->nr_map = 0;
 		userdef = 1;
 		return 0;
 	}
@@ -921,8 +921,8 @@ early_param("memmap", parse_memmap_opt);
 void __init finish_e820_parsing(void)
 {
 	if (userdef) {
-		if (sanitize_e820_array(e820_array->map, ARRAY_SIZE(e820_array->map),
-					&e820_array->nr_map) < 0)
+		if (sanitize_e820_table(e820_table->map, ARRAY_SIZE(e820_table->map),
+					&e820_table->nr_map) < 0)
 			early_panic("Invalid user supplied memory map");
 
 		printk(KERN_INFO "e820: user-defined physical RAM map:\n");
@@ -1009,35 +1009,35 @@ void __init e820_reserve_resources(void)
 	struct resource *res;
 	u64 end;
 
-	res = alloc_bootmem(sizeof(struct resource) * e820_array->nr_map);
+	res = alloc_bootmem(sizeof(struct resource) * e820_table->nr_map);
 	e820_res = res;
-	for (i = 0; i < e820_array->nr_map; i++) {
-		end = e820_array->map[i].addr + e820_array->map[i].size - 1;
+	for (i = 0; i < e820_table->nr_map; i++) {
+		end = e820_table->map[i].addr + e820_table->map[i].size - 1;
 		if (end != (resource_size_t)end) {
 			res++;
 			continue;
 		}
-		res->name = e820_type_to_string(e820_array->map[i].type);
-		res->start = e820_array->map[i].addr;
+		res->name = e820_type_to_string(e820_table->map[i].type);
+		res->start = e820_table->map[i].addr;
 		res->end = end;
 
-		res->flags = e820_type_to_iomem_type(e820_array->map[i].type);
-		res->desc = e820_type_to_iores_desc(e820_array->map[i].type);
+		res->flags = e820_type_to_iomem_type(e820_table->map[i].type);
+		res->desc = e820_type_to_iores_desc(e820_table->map[i].type);
 
 		/*
 		 * don't register the region that could be conflicted with
 		 * pci device BAR resource and insert them later in
 		 * pcibios_resource_survey()
 		 */
-		if (do_mark_busy(e820_array->map[i].type, res)) {
+		if (do_mark_busy(e820_table->map[i].type, res)) {
 			res->flags |= IORESOURCE_BUSY;
 			insert_resource(&iomem_resource, res);
 		}
 		res++;
 	}
 
-	for (i = 0; i < e820_array_saved->nr_map; i++) {
-		struct e820_entry *entry = &e820_array_saved->map[i];
+	for (i = 0; i < e820_table_saved->nr_map; i++) {
+		struct e820_entry *entry = &e820_table_saved->map[i];
 		firmware_map_add_early(entry->addr,
 			entry->addr + entry->size,
 			e820_type_to_string(entry->type));
@@ -1069,7 +1069,7 @@ void __init e820_reserve_resources_late(void)
 	struct resource *res;
 
 	res = e820_res;
-	for (i = 0; i < e820_array->nr_map; i++) {
+	for (i = 0; i < e820_table->nr_map; i++) {
 		if (!res->parent && res->end)
 			insert_resource_expand_to_fit(&iomem_resource, res);
 		res++;
@@ -1079,8 +1079,8 @@ void __init e820_reserve_resources_late(void)
 	 * Try to bump up RAM regions to reasonable boundaries to
 	 * avoid stolen RAM:
 	 */
-	for (i = 0; i < e820_array->nr_map; i++) {
-		struct e820_entry *entry = &e820_array->map[i];
+	for (i = 0; i < e820_table->nr_map; i++) {
+		struct e820_entry *entry = &e820_table->map[i];
 		u64 start, end;
 
 		if (entry->type != E820_RAM)
@@ -1110,11 +1110,11 @@ char *__init default_machine_specific_memory_setup(void)
 	 * the next section from 1mb->appropriate_mem_k
 	 */
 	new_nr = boot_params.e820_entries;
-	sanitize_e820_array(boot_params.e820_array,
-			ARRAY_SIZE(boot_params.e820_array),
+	sanitize_e820_table(boot_params.e820_table,
+			ARRAY_SIZE(boot_params.e820_table),
 			&new_nr);
 	boot_params.e820_entries = new_nr;
-	if (append_e820_array(boot_params.e820_array, boot_params.e820_entries)
+	if (append_e820_table(boot_params.e820_table, boot_params.e820_entries)
 	  < 0) {
 		u64 mem_size;
 
@@ -1128,7 +1128,7 @@ char *__init default_machine_specific_memory_setup(void)
 			who = "BIOS-e801";
 		}
 
-		e820_array->nr_map = 0;
+		e820_table->nr_map = 0;
 		e820_add_region(0, LOWMEMSIZE(), E820_RAM);
 		e820_add_region(HIGH_MEMORY, mem_size << 10, E820_RAM);
 	}
@@ -1142,7 +1142,7 @@ void __init setup_memory_map(void)
 	char *who;
 
 	who = x86_init.resources.memory_setup();
-	memcpy(e820_array_saved, e820_array, sizeof(struct e820_array));
+	memcpy(e820_table_saved, e820_table, sizeof(struct e820_table));
 	printk(KERN_INFO "e820: BIOS-provided physical RAM map:\n");
 	e820_print_map(who);
 }
@@ -1159,8 +1159,8 @@ void __init memblock_x86_fill(void)
 	 */
 	memblock_allow_resize();
 
-	for (i = 0; i < e820_array->nr_map; i++) {
-		struct e820_entry *ei = &e820_array->map[i];
+	for (i = 0; i < e820_table->nr_map; i++) {
+		struct e820_entry *ei = &e820_table->map[i];
 
 		end = ei->addr + ei->size;
 		if (end != (resource_size_t)end)
diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c
index 31d755534c36..a6cdf9b9c7a9 100644
--- a/arch/x86/kernel/early-quirks.c
+++ b/arch/x86/kernel/early-quirks.c
@@ -547,7 +547,7 @@ intel_graphics_stolen(int num, int slot, int func,
 
 	/* Mark this space as reserved */
 	e820_add_region(base, size, E820_RESERVED);
-	sanitize_e820_array(e820_array->map, ARRAY_SIZE(e820_array->map), &e820_array->nr_map);
+	sanitize_e820_table(e820_table->map, ARRAY_SIZE(e820_table->map), &e820_table->nr_map);
 }
 
 static void __init intel_graphics_quirks(int num, int slot, int func)
diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
index 6bedcb9bad1e..39d340ac50eb 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -100,14 +100,14 @@ static int setup_e820_entries(struct boot_params *params)
 {
 	unsigned int nr_e820_entries;
 
-	nr_e820_entries = e820_array_saved->nr_map;
+	nr_e820_entries = e820_table_saved->nr_map;
 
 	/* TODO: Pass entries more than E820MAX in bootparams setup data */
 	if (nr_e820_entries > E820MAX)
 		nr_e820_entries = E820MAX;
 
 	params->e820_entries = nr_e820_entries;
-	memcpy(&params->e820_array, &e820_array_saved->map,
+	memcpy(&params->e820_table, &e820_table_saved->map,
 	       nr_e820_entries * sizeof(struct e820_entry));
 
 	return 0;
@@ -233,10 +233,10 @@ setup_boot_parameters(struct kimage *image, struct boot_params *params,
 	nr_e820_entries = params->e820_entries;
 
 	for (i = 0; i < nr_e820_entries; i++) {
-		if (params->e820_array[i].type != E820_RAM)
+		if (params->e820_table[i].type != E820_RAM)
 			continue;
-		start = params->e820_array[i].addr;
-		end = params->e820_array[i].addr + params->e820_array[i].size - 1;
+		start = params->e820_table[i].addr;
+		end = params->e820_table[i].addr + params->e820_table[i].size - 1;
 
 		if ((start <= 0x100000) && end > 0x100000) {
 			mem_k = (end >> 10) - (0x100000 >> 10);
diff --git a/arch/x86/kernel/resource.c b/arch/x86/kernel/resource.c
index aeec503e0a6d..17b494d4bb86 100644
--- a/arch/x86/kernel/resource.c
+++ b/arch/x86/kernel/resource.c
@@ -27,8 +27,8 @@ static void remove_e820_regions(struct resource *avail)
 	int i;
 	struct e820_entry *entry;
 
-	for (i = 0; i < e820_array->nr_map; i++) {
-		entry = &e820_array->map[i];
+	for (i = 0; i < e820_table->nr_map; i++) {
+		entry = &e820_table->map[i];
 
 		resource_clip(avail, entry->addr,
 			      entry->addr + entry->size - 1);
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index a91db2edee9e..a3c1d39116b7 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -458,8 +458,8 @@ static void __init e820_reserve_setup_data(void)
 		early_memunmap(data, sizeof(*data));
 	}
 
-	sanitize_e820_array(e820_array->map, ARRAY_SIZE(e820_array->map), &e820_array->nr_map);
-	memcpy(e820_array_saved, e820_array, sizeof(struct e820_array));
+	sanitize_e820_table(e820_table->map, ARRAY_SIZE(e820_table->map), &e820_table->nr_map);
+	memcpy(e820_table_saved, e820_table, sizeof(struct e820_table));
 	printk(KERN_INFO "extended physical RAM map:\n");
 	e820_print_map("reserve setup_data");
 }
@@ -763,7 +763,7 @@ static void __init trim_bios_range(void)
 	 */
 	e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
 
-	sanitize_e820_array(e820_array->map, ARRAY_SIZE(e820_array->map), &e820_array->nr_map);
+	sanitize_e820_table(e820_table->map, ARRAY_SIZE(e820_table->map), &e820_table->nr_map);
 }
 
 /* called before trim_bios_range() to spare extra sanitize */
@@ -1026,7 +1026,7 @@ void __init setup_arch(char **cmdline_p)
 		early_dump_pci_devices();
 #endif
 
-	/* update the e820_array_saved too */
+	/* update the e820_table_saved too */
 	e820_reserve_setup_data();
 	finish_e820_parsing();
 
@@ -1056,7 +1056,7 @@ void __init setup_arch(char **cmdline_p)
 	if (ppro_with_ram_bug()) {
 		e820_update_range(0x70000000ULL, 0x40000ULL, E820_RAM,
 				  E820_RESERVED);
-		sanitize_e820_array(e820_array->map, ARRAY_SIZE(e820_array->map), &e820_array->nr_map);
+		sanitize_e820_table(e820_table->map, ARRAY_SIZE(e820_table->map), &e820_table->nr_map);
 		printk(KERN_INFO "fixed physical RAM map:\n");
 		e820_print_map("bad_ppro");
 	}
diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
index 705f1207181a..825822688aa5 100644
--- a/arch/x86/kernel/tboot.c
+++ b/arch/x86/kernel/tboot.c
@@ -188,12 +188,12 @@ static int tboot_setup_sleep(void)
 
 	tboot->num_mac_regions = 0;
 
-	for (i = 0; i < e820_array->nr_map; i++) {
-		if ((e820_array->map[i].type != E820_RAM)
-		 && (e820_array->map[i].type != E820_RESERVED_KERN))
+	for (i = 0; i < e820_table->nr_map; i++) {
+		if ((e820_table->map[i].type != E820_RAM)
+		 && (e820_table->map[i].type != E820_RESERVED_KERN))
 			continue;
 
-		add_mac_region(e820_array->map[i].addr, e820_array->map[i].size);
+		add_mac_region(e820_table->map[i].addr, e820_table->map[i].size);
 	}
 
 	tboot->acpi_sinfo.kernel_s3_resume_vector =
diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
index 09226a33e418..fc42e9604562 100644
--- a/arch/x86/lguest/boot.c
+++ b/arch/x86/lguest/boot.c
@@ -1178,9 +1178,9 @@ static __init char *lguest_memory_setup(void)
 	 * The Linux bootloader header contains an "e820" memory map: the
 	 * Launcher populated the first entry with our memory limit.
 	 */
-	e820_add_region(boot_params.e820_array[0].addr,
-			  boot_params.e820_array[0].size,
-			  boot_params.e820_array[0].type);
+	e820_add_region(boot_params.e820_table[0].addr,
+			  boot_params.e820_table[0].size,
+			  boot_params.e820_table[0].type);
 
 	/* This string is for the boot messages. */
 	return "LGUEST";
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index 2543a11c9df8..9e055f6859e5 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -167,7 +167,7 @@ static void __init do_add_efi_memmap(void)
 		}
 		e820_add_region(start, size, e820_type);
 	}
-	sanitize_e820_array(e820_array->map, ARRAY_SIZE(e820_array->map), &e820_array->nr_map);
+	sanitize_e820_table(e820_table->map, ARRAY_SIZE(e820_table->map), &e820_table->nr_map);
 }
 
 int __init efi_memblock_x86_reserve_range(void)
diff --git a/arch/x86/power/hibernate_64.c b/arch/x86/power/hibernate_64.c
index c1a245e64ed1..8fe5be0e90b2 100644
--- a/arch/x86/power/hibernate_64.c
+++ b/arch/x86/power/hibernate_64.c
@@ -201,7 +201,7 @@ struct restore_data_record {
  * @map: the e820 map to be calculated
  * @buf: the md5 result to be stored to
  */
-static int get_e820_md5(struct e820_array *map, void *buf)
+static int get_e820_md5(struct e820_table *map, void *buf)
 {
 	struct scatterlist sg;
 	struct crypto_ahash *tfm;
@@ -214,7 +214,7 @@ static int get_e820_md5(struct e820_array *map, void *buf)
 
 	{
 		AHASH_REQUEST_ON_STACK(req, tfm);
-		size = offsetof(struct e820_array, map)
+		size = offsetof(struct e820_table, map)
 			+ sizeof(struct e820_entry) * map->nr_map;
 		ahash_request_set_tfm(req, tfm);
 		sg_init_one(&sg, (u8 *)map, size);
@@ -232,7 +232,7 @@ static int get_e820_md5(struct e820_array *map, void *buf)
 
 static void hibernation_e820_save(void *buf)
 {
-	get_e820_md5(e820_array_saved, buf);
+	get_e820_md5(e820_table_saved, buf);
 }
 
 static bool hibernation_e820_mismatch(void *buf)
@@ -245,7 +245,7 @@ static bool hibernation_e820_mismatch(void *buf)
 	if (!memcmp(result, buf, MD5_DIGEST_SIZE))
 		return false;
 
-	ret = get_e820_md5(e820_array_saved, result);
+	ret = get_e820_md5(e820_table_saved, result);
 	if (ret)
 		return true;
 
diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
index 3cc90e902064..f98713e5a705 100644
--- a/arch/x86/xen/setup.c
+++ b/arch/x86/xen/setup.c
@@ -41,8 +41,8 @@ struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata;
 unsigned long xen_released_pages;
 
 /* E820 map used during setting up memory. */
-static struct e820_entry xen_e820_array[E820_X_MAX] __initdata;
-static u32 xen_e820_array_entries __initdata;
+static struct e820_entry xen_e820_table[E820_X_MAX] __initdata;
+static u32 xen_e820_table_entries __initdata;
 
 /*
  * Buffer used to remap identity mapped pages. We only need the virtual space.
@@ -198,11 +198,11 @@ void __init xen_inv_extra_mem(void)
  */
 static unsigned long __init xen_find_pfn_range(unsigned long *min_pfn)
 {
-	const struct e820_entry *entry = xen_e820_array;
+	const struct e820_entry *entry = xen_e820_table;
 	unsigned int i;
 	unsigned long done = 0;
 
-	for (i = 0; i < xen_e820_array_entries; i++, entry++) {
+	for (i = 0; i < xen_e820_table_entries; i++, entry++) {
 		unsigned long s_pfn;
 		unsigned long e_pfn;
 
@@ -457,7 +457,7 @@ static unsigned long __init xen_foreach_remap_area(unsigned long nr_pages,
 {
 	phys_addr_t start = 0;
 	unsigned long ret_val = 0;
-	const struct e820_entry *entry = xen_e820_array;
+	const struct e820_entry *entry = xen_e820_table;
 	int i;
 
 	/*
@@ -471,9 +471,9 @@ static unsigned long __init xen_foreach_remap_area(unsigned long nr_pages,
 	 * example) the DMI tables in a reserved region that begins on
 	 * a non-page boundary.
 	 */
-	for (i = 0; i < xen_e820_array_entries; i++, entry++) {
+	for (i = 0; i < xen_e820_table_entries; i++, entry++) {
 		phys_addr_t end = entry->addr + entry->size;
-		if (entry->type == E820_RAM || i == xen_e820_array_entries - 1) {
+		if (entry->type == E820_RAM || i == xen_e820_table_entries - 1) {
 			unsigned long start_pfn = PFN_DOWN(start);
 			unsigned long end_pfn = PFN_UP(end);
 
@@ -601,10 +601,10 @@ static void __init xen_align_and_add_e820_region(phys_addr_t start,
 
 static void __init xen_ignore_unusable(void)
 {
-	struct e820_entry *entry = xen_e820_array;
+	struct e820_entry *entry = xen_e820_table;
 	unsigned int i;
 
-	for (i = 0; i < xen_e820_array_entries; i++, entry++) {
+	for (i = 0; i < xen_e820_table_entries; i++, entry++) {
 		if (entry->type == E820_UNUSABLE)
 			entry->type = E820_RAM;
 	}
@@ -620,9 +620,9 @@ bool __init xen_is_e820_reserved(phys_addr_t start, phys_addr_t size)
 		return false;
 
 	end = start + size;
-	entry = xen_e820_array;
+	entry = xen_e820_table;
 
-	for (mapcnt = 0; mapcnt < xen_e820_array_entries; mapcnt++) {
+	for (mapcnt = 0; mapcnt < xen_e820_table_entries; mapcnt++) {
 		if (entry->type == E820_RAM && entry->addr <= start &&
 		    (entry->addr + entry->size) >= end)
 			return false;
@@ -645,9 +645,9 @@ phys_addr_t __init xen_find_free_area(phys_addr_t size)
 {
 	unsigned mapcnt;
 	phys_addr_t addr, start;
-	struct e820_entry *entry = xen_e820_array;
+	struct e820_entry *entry = xen_e820_table;
 
-	for (mapcnt = 0; mapcnt < xen_e820_array_entries; mapcnt++, entry++) {
+	for (mapcnt = 0; mapcnt < xen_e820_table_entries; mapcnt++, entry++) {
 		if (entry->type != E820_RAM || entry->size < size)
 			continue;
 		start = entry->addr;
@@ -750,8 +750,8 @@ char * __init xen_memory_setup(void)
 	max_pfn = min(max_pfn, xen_start_info->nr_pages);
 	mem_end = PFN_PHYS(max_pfn);
 
-	memmap.nr_entries = ARRAY_SIZE(xen_e820_array);
-	set_xen_guest_handle(memmap.buffer, xen_e820_array);
+	memmap.nr_entries = ARRAY_SIZE(xen_e820_table);
+	set_xen_guest_handle(memmap.buffer, xen_e820_table);
 
 	op = xen_initial_domain() ?
 		XENMEM_machine_memory_map :
@@ -760,16 +760,16 @@ char * __init xen_memory_setup(void)
 	if (rc == -ENOSYS) {
 		BUG_ON(xen_initial_domain());
 		memmap.nr_entries = 1;
-		xen_e820_array[0].addr = 0ULL;
-		xen_e820_array[0].size = mem_end;
+		xen_e820_table[0].addr = 0ULL;
+		xen_e820_table[0].size = mem_end;
 		/* 8MB slack (to balance backend allocations). */
-		xen_e820_array[0].size += 8ULL << 20;
-		xen_e820_array[0].type = E820_RAM;
+		xen_e820_table[0].size += 8ULL << 20;
+		xen_e820_table[0].type = E820_RAM;
 		rc = 0;
 	}
 	BUG_ON(rc);
 	BUG_ON(memmap.nr_entries == 0);
-	xen_e820_array_entries = memmap.nr_entries;
+	xen_e820_table_entries = memmap.nr_entries;
 
 	/*
 	 * Xen won't allow a 1:1 mapping to be created to UNUSABLE
@@ -783,8 +783,8 @@ char * __init xen_memory_setup(void)
 		xen_ignore_unusable();
 
 	/* Make sure the Xen-supplied memory map is well-ordered. */
-	sanitize_e820_array(xen_e820_array, ARRAY_SIZE(xen_e820_array),
-			  &xen_e820_array_entries);
+	sanitize_e820_table(xen_e820_table, ARRAY_SIZE(xen_e820_table),
+			  &xen_e820_table_entries);
 
 	max_pages = xen_get_max_pages();
 
@@ -811,13 +811,13 @@ char * __init xen_memory_setup(void)
 	extra_pages = min3(EXTRA_MEM_RATIO * min(max_pfn, PFN_DOWN(MAXMEM)),
 			   extra_pages, max_pages - max_pfn);
 	i = 0;
-	addr = xen_e820_array[0].addr;
-	size = xen_e820_array[0].size;
-	while (i < xen_e820_array_entries) {
+	addr = xen_e820_table[0].addr;
+	size = xen_e820_table[0].size;
+	while (i < xen_e820_table_entries) {
 		bool discard = false;
 
 		chunk_size = size;
-		type = xen_e820_array[i].type;
+		type = xen_e820_table[i].type;
 
 		if (type == E820_RAM) {
 			if (addr < mem_end) {
@@ -840,9 +840,9 @@ char * __init xen_memory_setup(void)
 		size -= chunk_size;
 		if (size == 0) {
 			i++;
-			if (i < xen_e820_array_entries) {
-				addr = xen_e820_array[i].addr;
-				size = xen_e820_array[i].size;
+			if (i < xen_e820_table_entries) {
+				addr = xen_e820_table[i].addr;
+				size = xen_e820_table[i].size;
 			}
 		}
 	}
@@ -861,7 +861,7 @@ char * __init xen_memory_setup(void)
 	e820_add_region(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS,
 			E820_RESERVED);
 
-	sanitize_e820_array(e820_array->map, ARRAY_SIZE(e820_array->map), &e820_array->nr_map);
+	sanitize_e820_table(e820_table->map, ARRAY_SIZE(e820_table->map), &e820_table->nr_map);
 
 	/*
 	 * Check whether the kernel itself conflicts with the target E820 map.
@@ -923,21 +923,21 @@ char * __init xen_auto_xlated_memory_setup(void)
 	int i;
 	int rc;
 
-	memmap.nr_entries = ARRAY_SIZE(xen_e820_array);
-	set_xen_guest_handle(memmap.buffer, xen_e820_array);
+	memmap.nr_entries = ARRAY_SIZE(xen_e820_table);
+	set_xen_guest_handle(memmap.buffer, xen_e820_table);
 
 	rc = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap);
 	if (rc < 0)
 		panic("No memory map (%d)\n", rc);
 
-	xen_e820_array_entries = memmap.nr_entries;
+	xen_e820_table_entries = memmap.nr_entries;
 
-	sanitize_e820_array(xen_e820_array, ARRAY_SIZE(xen_e820_array),
-			  &xen_e820_array_entries);
+	sanitize_e820_table(xen_e820_table, ARRAY_SIZE(xen_e820_table),
+			  &xen_e820_table_entries);
 
-	for (i = 0; i < xen_e820_array_entries; i++)
-		e820_add_region(xen_e820_array[i].addr, xen_e820_array[i].size,
-				xen_e820_array[i].type);
+	for (i = 0; i < xen_e820_table_entries; i++)
+		e820_add_region(xen_e820_table[i].addr, xen_e820_table[i].size,
+				xen_e820_table[i].type);
 
 	/* Remove p2m info, it is not needed. */
 	xen_start_info->mfn_list = 0;
diff --git a/tools/lguest/lguest.c b/tools/lguest/lguest.c
index 92a1fe3c07eb..3819e23a173e 100644
--- a/tools/lguest/lguest.c
+++ b/tools/lguest/lguest.c
@@ -3339,7 +3339,7 @@ int main(int argc, char *argv[])
 	 * simple, single region.
 	 */
 	boot->e820_entries = 1;
-	boot->e820_array[0] = ((struct e820_entry) { 0, mem, E820_RAM });
+	boot->e820_table[0] = ((struct e820_entry) { 0, mem, E820_RAM });
 	/*
 	 * The boot header contains a command line pointer: we put the command
 	 * line after the boot header.
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 16/50] x86/boot/e820: Harmonize the 'struct e820_table' fields
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (14 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 15/50] x86/boot/e820: Rename everything to e820_table Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 17/50] x86/boot/e820: Rename default_machine_specific_memory_setup() to e820__memory_setup_default() Ingo Molnar
                   ` (33 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

So the e820_table->map and e820_table->nr_map names are a bit
confusing, because it's not clear what a 'map' really means
(it could be a bitmap, or some other data structure), nor is
it clear what nr_map means (is it a current index, or some
other count).

Rename the fields from:

 e820_table->map        =>     e820_table->entries
 e820_table->nr_map     =>     e820_table->nr_entries

which makes it abundantly clear that these are entries
of the table, and that the size of the table is ->nr_entries.

Propagate the changes to all affected files. Where necessary,
adjust local variable names to better reflect the new field names.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/types.h |   4 +--
 arch/x86/kernel/e820.c            | 114 +++++++++++++++++++++++++++++-----------------------------
 arch/x86/kernel/early-quirks.c    |   2 +-
 arch/x86/kernel/kexec-bzimage64.c |   5 ++-
 arch/x86/kernel/resource.c        |   4 +--
 arch/x86/kernel/setup.c           |   6 ++--
 arch/x86/kernel/tboot.c           |   8 ++---
 arch/x86/platform/efi/efi.c       |   2 +-
 arch/x86/power/hibernate_64.c     |  11 +++---
 arch/x86/xen/setup.c              |   2 +-
 10 files changed, 77 insertions(+), 81 deletions(-)

diff --git a/arch/x86/include/asm/e820/types.h b/arch/x86/include/asm/e820/types.h
index ae2c4e9db0d4..e9d811afc123 100644
--- a/arch/x86/include/asm/e820/types.h
+++ b/arch/x86/include/asm/e820/types.h
@@ -69,8 +69,8 @@
  * The whole array of E820 entries:
  */
 struct e820_table {
-	__u32 nr_map;
-	struct e820_entry map[E820_X_MAX];
+	__u32 nr_entries;
+	struct e820_entry entries[E820_X_MAX];
 };
 
 /*
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index ffaf94357d15..6d73ad46ab35 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -60,8 +60,8 @@ e820_any_mapped(u64 start, u64 end, unsigned type)
 {
 	int i;
 
-	for (i = 0; i < e820_table->nr_map; i++) {
-		struct e820_entry *ei = &e820_table->map[i];
+	for (i = 0; i < e820_table->nr_entries; i++) {
+		struct e820_entry *ei = &e820_table->entries[i];
 
 		if (type && ei->type != type)
 			continue;
@@ -83,8 +83,8 @@ int __init e820_all_mapped(u64 start, u64 end, unsigned type)
 {
 	int i;
 
-	for (i = 0; i < e820_table->nr_map; i++) {
-		struct e820_entry *ei = &e820_table->map[i];
+	for (i = 0; i < e820_table->nr_entries; i++) {
+		struct e820_entry *ei = &e820_table->entries[i];
 
 		if (type && ei->type != type)
 			continue;
@@ -110,22 +110,21 @@ int __init e820_all_mapped(u64 start, u64 end, unsigned type)
 /*
  * Add a memory region to the kernel e820 map.
  */
-static void __init __e820_add_region(struct e820_table *e820x, u64 start, u64 size,
-					 int type)
+static void __init __e820_add_region(struct e820_table *table, u64 start, u64 size, int type)
 {
-	int x = e820x->nr_map;
+	int x = table->nr_entries;
 
-	if (x >= ARRAY_SIZE(e820x->map)) {
+	if (x >= ARRAY_SIZE(table->entries)) {
 		printk(KERN_ERR "e820: too many entries; ignoring [mem %#010llx-%#010llx]\n",
 		       (unsigned long long) start,
 		       (unsigned long long) (start + size - 1));
 		return;
 	}
 
-	e820x->map[x].addr = start;
-	e820x->map[x].size = size;
-	e820x->map[x].type = type;
-	e820x->nr_map++;
+	table->entries[x].addr = start;
+	table->entries[x].size = size;
+	table->entries[x].type = type;
+	table->nr_entries++;
 }
 
 void __init e820_add_region(u64 start, u64 size, int type)
@@ -166,12 +165,12 @@ void __init e820_print_map(char *who)
 {
 	int i;
 
-	for (i = 0; i < e820_table->nr_map; i++) {
+	for (i = 0; i < e820_table->nr_entries; i++) {
 		printk(KERN_INFO "%s: [mem %#018Lx-%#018Lx] ", who,
-		       (unsigned long long) e820_table->map[i].addr,
+		       (unsigned long long) e820_table->entries[i].addr,
 		       (unsigned long long)
-		       (e820_table->map[i].addr + e820_table->map[i].size - 1));
-		e820_print_type(e820_table->map[i].type);
+		       (e820_table->entries[i].addr + e820_table->entries[i].size - 1));
+		e820_print_type(e820_table->entries[i].type);
 		printk(KERN_CONT "\n");
 	}
 }
@@ -423,7 +422,7 @@ static int __init append_e820_table(struct e820_entry *biosmap, int nr_map)
 	return __append_e820_table(biosmap, nr_map);
 }
 
-static u64 __init __e820_update_range(struct e820_table *e820x, u64 start,
+static u64 __init __e820_update_range(struct e820_table *table, u64 start,
 					u64 size, unsigned old_type,
 					unsigned new_type)
 {
@@ -444,8 +443,8 @@ static u64 __init __e820_update_range(struct e820_table *e820x, u64 start,
 	e820_print_type(new_type);
 	printk(KERN_CONT "\n");
 
-	for (i = 0; i < e820x->nr_map; i++) {
-		struct e820_entry *ei = &e820x->map[i];
+	for (i = 0; i < table->nr_entries; i++) {
+		struct e820_entry *ei = &table->entries[i];
 		u64 final_start, final_end;
 		u64 ei_end;
 
@@ -462,8 +461,8 @@ static u64 __init __e820_update_range(struct e820_table *e820x, u64 start,
 
 		/* new range is totally covered? */
 		if (ei->addr < start && ei_end > end) {
-			__e820_add_region(e820x, start, size, new_type);
-			__e820_add_region(e820x, end, ei_end - end, ei->type);
+			__e820_add_region(table, start, size, new_type);
+			__e820_add_region(table, end, ei_end - end, ei->type);
 			ei->size = start - ei->addr;
 			real_updated_size += size;
 			continue;
@@ -475,7 +474,7 @@ static u64 __init __e820_update_range(struct e820_table *e820x, u64 start,
 		if (final_start >= final_end)
 			continue;
 
-		__e820_add_region(e820x, final_start, final_end - final_start,
+		__e820_add_region(table, final_start, final_end - final_start,
 				  new_type);
 
 		real_updated_size += final_end - final_start;
@@ -523,8 +522,8 @@ u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type,
 		e820_print_type(old_type);
 	printk(KERN_CONT "\n");
 
-	for (i = 0; i < e820_table->nr_map; i++) {
-		struct e820_entry *ei = &e820_table->map[i];
+	for (i = 0; i < e820_table->nr_entries; i++) {
+		struct e820_entry *ei = &e820_table->entries[i];
 		u64 final_start, final_end;
 		u64 ei_end;
 
@@ -568,15 +567,14 @@ u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type,
 
 void __init update_e820(void)
 {
-	if (sanitize_e820_table(e820_table->map, ARRAY_SIZE(e820_table->map), &e820_table->nr_map))
+	if (sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries))
 		return;
 	printk(KERN_INFO "e820: modified physical RAM map:\n");
 	e820_print_map("modified");
 }
 static void __init update_e820_table_saved(void)
 {
-	sanitize_e820_table(e820_table_saved->map, ARRAY_SIZE(e820_table_saved->map),
-				&e820_table_saved->nr_map);
+	sanitize_e820_table(e820_table_saved->entries, ARRAY_SIZE(e820_table_saved->entries), &e820_table_saved->nr_entries);
 }
 #define MAX_GAP_END 0x100000000ull
 /*
@@ -586,12 +584,12 @@ static int __init e820_search_gap(unsigned long *gapstart,
 		unsigned long *gapsize)
 {
 	unsigned long long last = MAX_GAP_END;
-	int i = e820_table->nr_map;
+	int i = e820_table->nr_entries;
 	int found = 0;
 
 	while (--i >= 0) {
-		unsigned long long start = e820_table->map[i].addr;
-		unsigned long long end = start + e820_table->map[i].size;
+		unsigned long long start = e820_table->entries[i].addr;
+		unsigned long long end = start + e820_table->entries[i].size;
 
 		/*
 		 * Since "last" is at most 4GB, we know we'll
@@ -661,13 +659,13 @@ __init void e820_reallocate_tables(void)
 	struct e820_table *n;
 	int size;
 
-	size = offsetof(struct e820_table, map) + sizeof(struct e820_entry) * e820_table->nr_map;
+	size = offsetof(struct e820_table, entries) + sizeof(struct e820_entry) * e820_table->nr_entries;
 	n = kmalloc(size, GFP_KERNEL);
 	BUG_ON(!n);
 	memcpy(n, e820_table, size);
 	e820_table = n;
 
-	size = offsetof(struct e820_table, map) + sizeof(struct e820_entry) * e820_table_saved->nr_map;
+	size = offsetof(struct e820_table, entries) + sizeof(struct e820_entry) * e820_table_saved->nr_entries;
 	n = kmalloc(size, GFP_KERNEL);
 	BUG_ON(!n);
 	memcpy(n, e820_table_saved, size);
@@ -690,7 +688,7 @@ void __init parse_e820_ext(u64 phys_addr, u32 data_len)
 	entries = sdata->len / sizeof(struct e820_entry);
 	extmap = (struct e820_entry *)(sdata->data);
 	__append_e820_table(extmap, entries);
-	sanitize_e820_table(e820_table->map, ARRAY_SIZE(e820_table->map), &e820_table->nr_map);
+	sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 	early_memunmap(sdata, data_len);
 	printk(KERN_INFO "e820: extended physical RAM map:\n");
 	e820_print_map("extended");
@@ -709,8 +707,8 @@ void __init e820_mark_nosave_regions(unsigned long limit_pfn)
 	int i;
 	unsigned long pfn = 0;
 
-	for (i = 0; i < e820_table->nr_map; i++) {
-		struct e820_entry *ei = &e820_table->map[i];
+	for (i = 0; i < e820_table->nr_entries; i++) {
+		struct e820_entry *ei = &e820_table->entries[i];
 
 		if (pfn < PFN_UP(ei->addr))
 			register_nosave_region(pfn, PFN_UP(ei->addr));
@@ -734,8 +732,8 @@ static int __init e820_mark_nvs_memory(void)
 {
 	int i;
 
-	for (i = 0; i < e820_table->nr_map; i++) {
-		struct e820_entry *ei = &e820_table->map[i];
+	for (i = 0; i < e820_table->nr_entries; i++) {
+		struct e820_entry *ei = &e820_table->entries[i];
 
 		if (ei->type == E820_NVS)
 			acpi_nvs_register(ei->addr, ei->size);
@@ -782,8 +780,8 @@ static unsigned long __init e820_end_pfn(unsigned long limit_pfn, unsigned type)
 	unsigned long last_pfn = 0;
 	unsigned long max_arch_pfn = MAX_ARCH_PFN;
 
-	for (i = 0; i < e820_table->nr_map; i++) {
-		struct e820_entry *ei = &e820_table->map[i];
+	for (i = 0; i < e820_table->nr_entries; i++) {
+		struct e820_entry *ei = &e820_table->entries[i];
 		unsigned long start_pfn;
 		unsigned long end_pfn;
 
@@ -874,7 +872,7 @@ static int __init parse_memmap_one(char *p)
 		 */
 		saved_max_pfn = e820_end_of_ram_pfn();
 #endif
-		e820_table->nr_map = 0;
+		e820_table->nr_entries = 0;
 		userdef = 1;
 		return 0;
 	}
@@ -921,8 +919,8 @@ early_param("memmap", parse_memmap_opt);
 void __init finish_e820_parsing(void)
 {
 	if (userdef) {
-		if (sanitize_e820_table(e820_table->map, ARRAY_SIZE(e820_table->map),
-					&e820_table->nr_map) < 0)
+		if (sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries),
+					&e820_table->nr_entries) < 0)
 			early_panic("Invalid user supplied memory map");
 
 		printk(KERN_INFO "e820: user-defined physical RAM map:\n");
@@ -1009,35 +1007,35 @@ void __init e820_reserve_resources(void)
 	struct resource *res;
 	u64 end;
 
-	res = alloc_bootmem(sizeof(struct resource) * e820_table->nr_map);
+	res = alloc_bootmem(sizeof(struct resource) * e820_table->nr_entries);
 	e820_res = res;
-	for (i = 0; i < e820_table->nr_map; i++) {
-		end = e820_table->map[i].addr + e820_table->map[i].size - 1;
+	for (i = 0; i < e820_table->nr_entries; i++) {
+		end = e820_table->entries[i].addr + e820_table->entries[i].size - 1;
 		if (end != (resource_size_t)end) {
 			res++;
 			continue;
 		}
-		res->name = e820_type_to_string(e820_table->map[i].type);
-		res->start = e820_table->map[i].addr;
+		res->name = e820_type_to_string(e820_table->entries[i].type);
+		res->start = e820_table->entries[i].addr;
 		res->end = end;
 
-		res->flags = e820_type_to_iomem_type(e820_table->map[i].type);
-		res->desc = e820_type_to_iores_desc(e820_table->map[i].type);
+		res->flags = e820_type_to_iomem_type(e820_table->entries[i].type);
+		res->desc = e820_type_to_iores_desc(e820_table->entries[i].type);
 
 		/*
 		 * don't register the region that could be conflicted with
 		 * pci device BAR resource and insert them later in
 		 * pcibios_resource_survey()
 		 */
-		if (do_mark_busy(e820_table->map[i].type, res)) {
+		if (do_mark_busy(e820_table->entries[i].type, res)) {
 			res->flags |= IORESOURCE_BUSY;
 			insert_resource(&iomem_resource, res);
 		}
 		res++;
 	}
 
-	for (i = 0; i < e820_table_saved->nr_map; i++) {
-		struct e820_entry *entry = &e820_table_saved->map[i];
+	for (i = 0; i < e820_table_saved->nr_entries; i++) {
+		struct e820_entry *entry = &e820_table_saved->entries[i];
 		firmware_map_add_early(entry->addr,
 			entry->addr + entry->size,
 			e820_type_to_string(entry->type));
@@ -1069,7 +1067,7 @@ void __init e820_reserve_resources_late(void)
 	struct resource *res;
 
 	res = e820_res;
-	for (i = 0; i < e820_table->nr_map; i++) {
+	for (i = 0; i < e820_table->nr_entries; i++) {
 		if (!res->parent && res->end)
 			insert_resource_expand_to_fit(&iomem_resource, res);
 		res++;
@@ -1079,8 +1077,8 @@ void __init e820_reserve_resources_late(void)
 	 * Try to bump up RAM regions to reasonable boundaries to
 	 * avoid stolen RAM:
 	 */
-	for (i = 0; i < e820_table->nr_map; i++) {
-		struct e820_entry *entry = &e820_table->map[i];
+	for (i = 0; i < e820_table->nr_entries; i++) {
+		struct e820_entry *entry = &e820_table->entries[i];
 		u64 start, end;
 
 		if (entry->type != E820_RAM)
@@ -1128,7 +1126,7 @@ char *__init default_machine_specific_memory_setup(void)
 			who = "BIOS-e801";
 		}
 
-		e820_table->nr_map = 0;
+		e820_table->nr_entries = 0;
 		e820_add_region(0, LOWMEMSIZE(), E820_RAM);
 		e820_add_region(HIGH_MEMORY, mem_size << 10, E820_RAM);
 	}
@@ -1159,8 +1157,8 @@ void __init memblock_x86_fill(void)
 	 */
 	memblock_allow_resize();
 
-	for (i = 0; i < e820_table->nr_map; i++) {
-		struct e820_entry *ei = &e820_table->map[i];
+	for (i = 0; i < e820_table->nr_entries; i++) {
+		struct e820_entry *ei = &e820_table->entries[i];
 
 		end = ei->addr + ei->size;
 		if (end != (resource_size_t)end)
diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c
index a6cdf9b9c7a9..4f52758accbc 100644
--- a/arch/x86/kernel/early-quirks.c
+++ b/arch/x86/kernel/early-quirks.c
@@ -547,7 +547,7 @@ intel_graphics_stolen(int num, int slot, int func,
 
 	/* Mark this space as reserved */
 	e820_add_region(base, size, E820_RESERVED);
-	sanitize_e820_table(e820_table->map, ARRAY_SIZE(e820_table->map), &e820_table->nr_map);
+	sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 }
 
 static void __init intel_graphics_quirks(int num, int slot, int func)
diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
index 39d340ac50eb..3e5c995e1718 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -100,15 +100,14 @@ static int setup_e820_entries(struct boot_params *params)
 {
 	unsigned int nr_e820_entries;
 
-	nr_e820_entries = e820_table_saved->nr_map;
+	nr_e820_entries = e820_table_saved->nr_entries;
 
 	/* TODO: Pass entries more than E820MAX in bootparams setup data */
 	if (nr_e820_entries > E820MAX)
 		nr_e820_entries = E820MAX;
 
 	params->e820_entries = nr_e820_entries;
-	memcpy(&params->e820_table, &e820_table_saved->map,
-	       nr_e820_entries * sizeof(struct e820_entry));
+	memcpy(&params->e820_table, &e820_table_saved->entries, nr_e820_entries*sizeof(struct e820_entry));
 
 	return 0;
 }
diff --git a/arch/x86/kernel/resource.c b/arch/x86/kernel/resource.c
index 17b494d4bb86..5ab3895516ac 100644
--- a/arch/x86/kernel/resource.c
+++ b/arch/x86/kernel/resource.c
@@ -27,8 +27,8 @@ static void remove_e820_regions(struct resource *avail)
 	int i;
 	struct e820_entry *entry;
 
-	for (i = 0; i < e820_table->nr_map; i++) {
-		entry = &e820_table->map[i];
+	for (i = 0; i < e820_table->nr_entries; i++) {
+		entry = &e820_table->entries[i];
 
 		resource_clip(avail, entry->addr,
 			      entry->addr + entry->size - 1);
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index a3c1d39116b7..c2bb2d143d70 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -458,7 +458,7 @@ static void __init e820_reserve_setup_data(void)
 		early_memunmap(data, sizeof(*data));
 	}
 
-	sanitize_e820_table(e820_table->map, ARRAY_SIZE(e820_table->map), &e820_table->nr_map);
+	sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 	memcpy(e820_table_saved, e820_table, sizeof(struct e820_table));
 	printk(KERN_INFO "extended physical RAM map:\n");
 	e820_print_map("reserve setup_data");
@@ -763,7 +763,7 @@ static void __init trim_bios_range(void)
 	 */
 	e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
 
-	sanitize_e820_table(e820_table->map, ARRAY_SIZE(e820_table->map), &e820_table->nr_map);
+	sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 }
 
 /* called before trim_bios_range() to spare extra sanitize */
@@ -1056,7 +1056,7 @@ void __init setup_arch(char **cmdline_p)
 	if (ppro_with_ram_bug()) {
 		e820_update_range(0x70000000ULL, 0x40000ULL, E820_RAM,
 				  E820_RESERVED);
-		sanitize_e820_table(e820_table->map, ARRAY_SIZE(e820_table->map), &e820_table->nr_map);
+		sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 		printk(KERN_INFO "fixed physical RAM map:\n");
 		e820_print_map("bad_ppro");
 	}
diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
index 825822688aa5..f7cba42d7807 100644
--- a/arch/x86/kernel/tboot.c
+++ b/arch/x86/kernel/tboot.c
@@ -188,12 +188,12 @@ static int tboot_setup_sleep(void)
 
 	tboot->num_mac_regions = 0;
 
-	for (i = 0; i < e820_table->nr_map; i++) {
-		if ((e820_table->map[i].type != E820_RAM)
-		 && (e820_table->map[i].type != E820_RESERVED_KERN))
+	for (i = 0; i < e820_table->nr_entries; i++) {
+		if ((e820_table->entries[i].type != E820_RAM)
+		 && (e820_table->entries[i].type != E820_RESERVED_KERN))
 			continue;
 
-		add_mac_region(e820_table->map[i].addr, e820_table->map[i].size);
+		add_mac_region(e820_table->entries[i].addr, e820_table->entries[i].size);
 	}
 
 	tboot->acpi_sinfo.kernel_s3_resume_vector =
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index 9e055f6859e5..b69199165610 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -167,7 +167,7 @@ static void __init do_add_efi_memmap(void)
 		}
 		e820_add_region(start, size, e820_type);
 	}
-	sanitize_e820_table(e820_table->map, ARRAY_SIZE(e820_table->map), &e820_table->nr_map);
+	sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 }
 
 int __init efi_memblock_x86_reserve_range(void)
diff --git a/arch/x86/power/hibernate_64.c b/arch/x86/power/hibernate_64.c
index 8fe5be0e90b2..1bfda425879c 100644
--- a/arch/x86/power/hibernate_64.c
+++ b/arch/x86/power/hibernate_64.c
@@ -196,12 +196,12 @@ struct restore_data_record {
 
 #if IS_BUILTIN(CONFIG_CRYPTO_MD5)
 /**
- * get_e820_md5 - calculate md5 according to given e820 map
+ * get_e820_md5 - calculate md5 according to given e820 table
  *
- * @map: the e820 map to be calculated
+ * @table: the e820 table to be calculated
  * @buf: the md5 result to be stored to
  */
-static int get_e820_md5(struct e820_table *map, void *buf)
+static int get_e820_md5(struct e820_table *table, void *buf)
 {
 	struct scatterlist sg;
 	struct crypto_ahash *tfm;
@@ -214,10 +214,9 @@ static int get_e820_md5(struct e820_table *map, void *buf)
 
 	{
 		AHASH_REQUEST_ON_STACK(req, tfm);
-		size = offsetof(struct e820_table, map)
-			+ sizeof(struct e820_entry) * map->nr_map;
+		size = offsetof(struct e820_table, entries) + sizeof(struct e820_entry) * table->nr_entries;
 		ahash_request_set_tfm(req, tfm);
-		sg_init_one(&sg, (u8 *)map, size);
+		sg_init_one(&sg, (u8 *)table, size);
 		ahash_request_set_callback(req, 0, NULL, NULL);
 		ahash_request_set_crypt(req, &sg, buf, size);
 
diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
index f98713e5a705..8b26b9282070 100644
--- a/arch/x86/xen/setup.c
+++ b/arch/x86/xen/setup.c
@@ -861,7 +861,7 @@ char * __init xen_memory_setup(void)
 	e820_add_region(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS,
 			E820_RESERVED);
 
-	sanitize_e820_table(e820_table->map, ARRAY_SIZE(e820_table->map), &e820_table->nr_map);
+	sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 
 	/*
 	 * Check whether the kernel itself conflicts with the target E820 map.
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 17/50] x86/boot/e820: Rename default_machine_specific_memory_setup() to e820__memory_setup_default()
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (15 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 16/50] x86/boot/e820: Harmonize the 'struct e820_table' fields Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 18/50] x86/boot/e820: Rename e820_table_saved to e820_table_firmware and improve the description Ingo Molnar
                   ` (32 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

The default_machine_specific_memory_setup() is a mouthful and despite the
many words it doesn't actually tell us clearly what it does.

The function is the x86 legacy memory layout setup code, based on
E820-formatted memory layout information passed by the bootloader
via the boot_params.

Rename it to e820__memory_setup_default() to better signal its purpose.

Also rename the related higher level function to be consistent with
this new naming:

    setup_memory_map() => e820__memory_setup()

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h | 4 ++--
 arch/x86/kernel/e820.c          | 9 +++++++--
 arch/x86/kernel/setup.c         | 2 +-
 arch/x86/kernel/x86_init.c      | 2 +-
 4 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 91a5c346f765..2a6de16ad9b5 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -27,8 +27,8 @@ extern void memblock_find_dma_reserve(void);
 extern void finish_e820_parsing(void);
 extern void e820_reserve_resources(void);
 extern void e820_reserve_resources_late(void);
-extern void setup_memory_map(void);
-extern char *default_machine_specific_memory_setup(void);
+extern void e820__memory_setup(void);
+extern char *e820__memory_setup_default(void);
 extern void e820_reallocate_tables(void);
 extern void e820_mark_nosave_regions(unsigned long limit_pfn);
 
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 6d73ad46ab35..7d12433ad056 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -1097,7 +1097,7 @@ void __init e820_reserve_resources_late(void)
 	}
 }
 
-char *__init default_machine_specific_memory_setup(void)
+char *__init e820__memory_setup_default(void)
 {
 	char *who = "BIOS-e820";
 	u32 new_nr;
@@ -1135,7 +1135,12 @@ char *__init default_machine_specific_memory_setup(void)
 	return who;
 }
 
-void __init setup_memory_map(void)
+/*
+ * Calls e820__memory_setup_default() in essence to pick up the firmware/bootloader
+ * E820 map - with an optional platform quirk available for virtual platforms
+ * to override this method of boot environment processing:
+ */
+void __init e820__memory_setup(void)
 {
 	char *who;
 
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index c2bb2d143d70..a8d0e388b358 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -937,7 +937,7 @@ void __init setup_arch(char **cmdline_p)
 	x86_init.oem.arch_setup();
 
 	iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1;
-	setup_memory_map();
+	e820__memory_setup();
 	parse_setup_data();
 
 	copy_edd();
diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
index 512cb45264d0..a088b2c47f73 100644
--- a/arch/x86/kernel/x86_init.c
+++ b/arch/x86/kernel/x86_init.c
@@ -38,7 +38,7 @@ struct x86_init_ops x86_init __initdata = {
 	.resources = {
 		.probe_roms		= probe_roms,
 		.reserve_resources	= reserve_standard_io_resources,
-		.memory_setup		= default_machine_specific_memory_setup,
+		.memory_setup		= e820__memory_setup_default,
 	},
 
 	.mpparse = {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 18/50] x86/boot/e820: Rename e820_table_saved to e820_table_firmware and improve the description
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (16 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 17/50] x86/boot/e820: Rename default_machine_specific_memory_setup() to e820__memory_setup_default() Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 19/50] x86/boot/e820: Basic cleanup of e820.c Ingo Molnar
                   ` (31 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

So the 'e820_table_saved' is a bit of a misnomer that hides its real purpose.

At first sight the name suggests that it's some sort save/restore mechanism,
as this is how we typically name such facilities in the kernel.

But that is not so, e820_table_saved is the original firmware version of the
e820 table, not modified by the kernel. This table is displayed in the
/sys/firmware/memmap file, and it's also used by the hibernation code to
calculate a physical memory layout MD5 fingerprint checksum which is
invariant of the kernel.

So rename it to 'e820_table_firmware' and update all the comments to better
describe the main e820 data strutures.

Also rename:

  'initial_e820_table_saved'  =>  'e820_table_firmware_init'
  'e820_update_range_saved'   =>  'e820_update_range_firmware'

... to better match the new nomenclature.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h   |  3 +--
 arch/x86/kernel/e820.c            | 78 +++++++++++++++++++++++++++++++++++++----------------------
 arch/x86/kernel/kexec-bzimage64.c |  4 +--
 arch/x86/kernel/setup.c           |  4 +--
 arch/x86/power/hibernate_64.c     |  4 +--
 5 files changed, 56 insertions(+), 37 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 2a6de16ad9b5..2c336d8a8593 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -3,9 +3,8 @@
 
 #include <asm/e820/types.h>
 
-/* see comment in arch/x86/kernel/e820.c */
 extern struct e820_table *e820_table;
-extern struct e820_table *e820_table_saved;
+extern struct e820_table *e820_table_firmware;
 
 extern unsigned long pci_mem_start;
 
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 7d12433ad056..86d6d823e47e 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -27,23 +27,43 @@
 #include <asm/cpufeature.h>
 
 /*
- * The e820 table is the array that gets modified e.g. with command line parameters
- * and that is also registered with modifications in the kernel resource tree
- * with the iomem_resource as parent.
+ * The firmware and bootloader passes us an E820 table that is the primary
+ * physical memory layout description available about x86 systems.
  *
- * The e820_table_saved is directly saved after the BIOS-provided memory map is
- * copied. It doesn't get modified afterwards. It's registered for the
- * /sys/firmware/memmap interface.
+ * The kernel takes the e820 memory layout and optionally modifies it with
+ * quirks and other tweaks, and feeds that into the generic Linux memory
+ * allocation code routines via a platform independent interface (memblock, etc.).
  *
- * That memory map is not modified and is used as base for kexec. The kexec'd
- * kernel should get the same memory map as the firmware provides. Then the
- * user can e.g. boot the original kernel with mem=1G while still booting the
- * next kernel with full memory.
+ * We organize the E820 table into two main data structures:
+ *
+ * - 'e820_table_firmware': the original firmware version passed to us by the
+ *   bootloader - not modified by the kernel. We use this to:
+ *
+ *       - inform the user about the firmware's notion of memory layout
+ *         via /sys/firmware/memmap
+ *
+ *       - the hibernation code uses it to generate a kernel-independent MD5
+ *         fingerprint of the physical memory layout of a system.
+ *
+ *       - kexec, which is a bootloader in disguise, uses the original e820
+ *         layout to pass to the kexec-ed kernel. This way the original kernel
+ *         can have a restricted e820 map while the kexec()-ed kexec-kernel
+ *         can have access to full memory - etc.
+ *
+ * - 'e820_table': this is the main e820 table that is massaged by the
+ *   low level x86 platform code, or modified by boot parameters, before
+ *   passed on to higher level MM layers.
+ *
+ * Once the e820 map has been converted to the standard Linux memory layout
+ * information its role stops - modifying it has no effect and does not get
+ * re-propagated. So itsmain role is a temporary bootstrap storage of firmware
+ * specific memory layout data during early bootup.
  */
-static struct e820_table e820_table_init  __initdata;
-static struct e820_table initial_e820_table_saved  __initdata;
-struct e820_table *e820_table __refdata = &e820_table_init;
-struct e820_table *e820_table_saved __refdata = &initial_e820_table_saved;
+static struct e820_table e820_table_init		__initdata;
+static struct e820_table e820_table_firmware_init	__initdata;
+
+struct e820_table *e820_table __refdata			= &e820_table_init;
+struct e820_table *e820_table_firmware __refdata	= &e820_table_firmware_init;
 
 /* For PCI or other memory-mapped resources */
 unsigned long pci_mem_start = 0xaeedbabe;
@@ -497,10 +517,10 @@ u64 __init e820_update_range(u64 start, u64 size, unsigned old_type,
 	return __e820_update_range(e820_table, start, size, old_type, new_type);
 }
 
-static u64 __init e820_update_range_saved(u64 start, u64 size,
+static u64 __init e820_update_range_firmware(u64 start, u64 size,
 					  unsigned old_type, unsigned new_type)
 {
-	return __e820_update_range(e820_table_saved, start, size, old_type,
+	return __e820_update_range(e820_table_firmware, start, size, old_type,
 				     new_type);
 }
 
@@ -572,9 +592,9 @@ void __init update_e820(void)
 	printk(KERN_INFO "e820: modified physical RAM map:\n");
 	e820_print_map("modified");
 }
-static void __init update_e820_table_saved(void)
+static void __init update_e820_table_firmware(void)
 {
-	sanitize_e820_table(e820_table_saved->entries, ARRAY_SIZE(e820_table_saved->entries), &e820_table_saved->nr_entries);
+	sanitize_e820_table(e820_table_firmware->entries, ARRAY_SIZE(e820_table_firmware->entries), &e820_table_firmware->nr_entries);
 }
 #define MAX_GAP_END 0x100000000ull
 /*
@@ -648,7 +668,7 @@ __init void e820_setup_gap(void)
 /*
  * Called late during init, in free_initmem().
  *
- * Initial e820 and e820_table_saved are largish __initdata arrays.
+ * Initial e820 and e820_table_firmware are largish __initdata arrays.
  * Copy them to (usually much smaller) dynamically allocated area.
  * This is done after all tweaks we ever do to them:
  * all functions which modify them are __init functions,
@@ -665,11 +685,11 @@ __init void e820_reallocate_tables(void)
 	memcpy(n, e820_table, size);
 	e820_table = n;
 
-	size = offsetof(struct e820_table, entries) + sizeof(struct e820_entry) * e820_table_saved->nr_entries;
+	size = offsetof(struct e820_table, entries) + sizeof(struct e820_entry) * e820_table_firmware->nr_entries;
 	n = kmalloc(size, GFP_KERNEL);
 	BUG_ON(!n);
-	memcpy(n, e820_table_saved, size);
-	e820_table_saved = n;
+	memcpy(n, e820_table_firmware, size);
+	e820_table_firmware = n;
 }
 
 /**
@@ -745,7 +765,7 @@ core_initcall(e820_mark_nvs_memory);
 #endif
 
 /*
- * pre allocated 4k and reserved it in memblock and e820_table_saved
+ * pre allocated 4k and reserved it in memblock and e820_table_firmware
  */
 u64 __init early_reserve_e820(u64 size, u64 align)
 {
@@ -753,9 +773,9 @@ u64 __init early_reserve_e820(u64 size, u64 align)
 
 	addr = __memblock_alloc_base(size, align, MEMBLOCK_ALLOC_ACCESSIBLE);
 	if (addr) {
-		e820_update_range_saved(addr, size, E820_RAM, E820_RESERVED);
-		printk(KERN_INFO "e820: update e820_table_saved for early_reserve_e820\n");
-		update_e820_table_saved();
+		e820_update_range_firmware(addr, size, E820_RAM, E820_RESERVED);
+		printk(KERN_INFO "e820: update e820_table_firmware for early_reserve_e820\n");
+		update_e820_table_firmware();
 	}
 
 	return addr;
@@ -1034,8 +1054,8 @@ void __init e820_reserve_resources(void)
 		res++;
 	}
 
-	for (i = 0; i < e820_table_saved->nr_entries; i++) {
-		struct e820_entry *entry = &e820_table_saved->entries[i];
+	for (i = 0; i < e820_table_firmware->nr_entries; i++) {
+		struct e820_entry *entry = &e820_table_firmware->entries[i];
 		firmware_map_add_early(entry->addr,
 			entry->addr + entry->size,
 			e820_type_to_string(entry->type));
@@ -1145,7 +1165,7 @@ void __init e820__memory_setup(void)
 	char *who;
 
 	who = x86_init.resources.memory_setup();
-	memcpy(e820_table_saved, e820_table, sizeof(struct e820_table));
+	memcpy(e820_table_firmware, e820_table, sizeof(struct e820_table));
 	printk(KERN_INFO "e820: BIOS-provided physical RAM map:\n");
 	e820_print_map(who);
 }
diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
index 3e5c995e1718..a8c9563557c9 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -100,14 +100,14 @@ static int setup_e820_entries(struct boot_params *params)
 {
 	unsigned int nr_e820_entries;
 
-	nr_e820_entries = e820_table_saved->nr_entries;
+	nr_e820_entries = e820_table_firmware->nr_entries;
 
 	/* TODO: Pass entries more than E820MAX in bootparams setup data */
 	if (nr_e820_entries > E820MAX)
 		nr_e820_entries = E820MAX;
 
 	params->e820_entries = nr_e820_entries;
-	memcpy(&params->e820_table, &e820_table_saved->entries, nr_e820_entries*sizeof(struct e820_entry));
+	memcpy(&params->e820_table, &e820_table_firmware->entries, nr_e820_entries*sizeof(struct e820_entry));
 
 	return 0;
 }
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index a8d0e388b358..f905430d7b04 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -459,7 +459,7 @@ static void __init e820_reserve_setup_data(void)
 	}
 
 	sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
-	memcpy(e820_table_saved, e820_table, sizeof(struct e820_table));
+	memcpy(e820_table_firmware, e820_table, sizeof(struct e820_table));
 	printk(KERN_INFO "extended physical RAM map:\n");
 	e820_print_map("reserve setup_data");
 }
@@ -1026,7 +1026,7 @@ void __init setup_arch(char **cmdline_p)
 		early_dump_pci_devices();
 #endif
 
-	/* update the e820_table_saved too */
+	/* update the e820_table_firmware too */
 	e820_reserve_setup_data();
 	finish_e820_parsing();
 
diff --git a/arch/x86/power/hibernate_64.c b/arch/x86/power/hibernate_64.c
index 1bfda425879c..053801b022dd 100644
--- a/arch/x86/power/hibernate_64.c
+++ b/arch/x86/power/hibernate_64.c
@@ -231,7 +231,7 @@ static int get_e820_md5(struct e820_table *table, void *buf)
 
 static void hibernation_e820_save(void *buf)
 {
-	get_e820_md5(e820_table_saved, buf);
+	get_e820_md5(e820_table_firmware, buf);
 }
 
 static bool hibernation_e820_mismatch(void *buf)
@@ -244,7 +244,7 @@ static bool hibernation_e820_mismatch(void *buf)
 	if (!memcmp(result, buf, MD5_DIGEST_SIZE))
 		return false;
 
-	ret = get_e820_md5(e820_table_saved, result);
+	ret = get_e820_md5(e820_table_firmware, result);
 	if (ret)
 		return true;
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 19/50] x86/boot/e820: Basic cleanup of e820.c
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (17 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 18/50] x86/boot/e820: Rename e820_table_saved to e820_table_firmware and improve the description Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 20/50] x86/boot/e820: Rename memblock_x86_fill() to e820__memblock_setup() and improve the explanations Ingo Molnar
                   ` (30 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

Over the last decade or so e820.c has become an ureadable mess of
tinkerware. Perform some very basic cleanups before doing more
intricate cleanups, so that my eyes don't start bleeding when I look at it.

Here's some of the excesses:

 - Total disregard of countless aspects of Documentation/CodingStyle.

 - Totally inconsistent hodge-podge of various coding styles and practices.

 - Gems like:

       (unsigned long long) e820_table->entries[i].addr

   ... which is a completely unnecessary type conversion of an u64 value.

 - Incomprehensible comments while there are major functions with absolutely
   no explanation - plus an armada of typos and grammar mistakes.

 - Mindless checkpatch artifacts such as:

         if (append_e820_table(boot_params.e820_table, boot_params.e820_entries)
           < 0) {

           for_each_free_mem_range(u, NUMA_NO_NODE, MEMBLOCK_NONE, &start, &end,
                                   NULL) {

 - Actively misleading comments:

        /* In case someone cares... */
        return who;

   ( The usage site of the return value just a few lines further down makes it
     clear that we very much care about the return value, we use it to print
     out the e820 map... )

 - Colorfully inconsistent capitalization and punctuation throughout.

 - etc.

This patch fixes only the worst excesses - there's more to fix.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/e820.c | 447 ++++++++++++++++++++++++++++++++-------------------------------------
 1 file changed, 207 insertions(+), 240 deletions(-)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 86d6d823e47e..624190fe86a7 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -1,12 +1,12 @@
 /*
- * Handle the memory map.
- * The functions here do the job until bootmem takes over.
+ * Low level x86 E820 memory map handling functions.
  *
- *  Getting sanitize_e820_table() in sync with i386 version by applying change:
- *  -  Provisions for empty E820 memory regions (reported by certain BIOSes).
- *     Alex Achenbach <xela@slit.de>, December 2002.
- *  Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
+ * The firmware and bootloader passes us the "E820 table", which is the primary
+ * physical memory layout description available about x86 systems.
  *
+ * The kernel takes the E820 memory layout and optionally modifies it with
+ * quirks and other tweaks, and feeds that into the generic Linux memory
+ * allocation code routines via a platform independent interface (memblock, etc.).
  */
 #include <linux/kernel.h>
 #include <linux/types.h>
@@ -27,13 +27,6 @@
 #include <asm/cpufeature.h>
 
 /*
- * The firmware and bootloader passes us an E820 table that is the primary
- * physical memory layout description available about x86 systems.
- *
- * The kernel takes the e820 memory layout and optionally modifies it with
- * quirks and other tweaks, and feeds that into the generic Linux memory
- * allocation code routines via a platform independent interface (memblock, etc.).
- *
  * We organize the E820 table into two main data structures:
  *
  * - 'e820_table_firmware': the original firmware version passed to us by the
@@ -45,16 +38,16 @@
  *       - the hibernation code uses it to generate a kernel-independent MD5
  *         fingerprint of the physical memory layout of a system.
  *
- *       - kexec, which is a bootloader in disguise, uses the original e820
+ *       - kexec, which is a bootloader in disguise, uses the original E820
  *         layout to pass to the kexec-ed kernel. This way the original kernel
- *         can have a restricted e820 map while the kexec()-ed kexec-kernel
+ *         can have a restricted E820 map while the kexec()-ed kexec-kernel
  *         can have access to full memory - etc.
  *
- * - 'e820_table': this is the main e820 table that is massaged by the
+ * - 'e820_table': this is the main E820 table that is massaged by the
  *   low level x86 platform code, or modified by boot parameters, before
  *   passed on to higher level MM layers.
  *
- * Once the e820 map has been converted to the standard Linux memory layout
+ * Once the E820 map has been converted to the standard Linux memory layout
  * information its role stops - modifying it has no effect and does not get
  * re-propagated. So itsmain role is a temporary bootstrap storage of firmware
  * specific memory layout data during early bootup.
@@ -75,8 +68,7 @@ EXPORT_SYMBOL(pci_mem_start);
  * This function checks if any part of the range <start,end> is mapped
  * with type.
  */
-int
-e820_any_mapped(u64 start, u64 end, unsigned type)
+int e820_any_mapped(u64 start, u64 end, unsigned type)
 {
 	int i;
 
@@ -94,10 +86,10 @@ e820_any_mapped(u64 start, u64 end, unsigned type)
 EXPORT_SYMBOL_GPL(e820_any_mapped);
 
 /*
- * This function checks if the entire range <start,end> is mapped with type.
+ * This function checks if the entire <start,end> range is mapped with 'type'.
  *
- * Note: this function only works correct if the e820 table is sorted and
- * not-overlapping, which is the case
+ * Note: this function only works correctly once the E820 table is sorted and
+ * not-overlapping (at least for the range specified), which is the case normally.
  */
 int __init e820_all_mapped(u64 start, u64 end, unsigned type)
 {
@@ -108,18 +100,21 @@ int __init e820_all_mapped(u64 start, u64 end, unsigned type)
 
 		if (type && ei->type != type)
 			continue;
-		/* is the region (part) in overlap with the current region ?*/
+
+		/* Is the region (part) in overlap with the current region? */
 		if (ei->addr >= end || ei->addr + ei->size <= start)
 			continue;
 
-		/* if the region is at the beginning of <start,end> we move
-		 * start to the end of the region since it's ok until there
+		/*
+		 * If the region is at the beginning of <start,end> we move
+		 * 'start' to the end of the region since it's ok until there
 		 */
 		if (ei->addr <= start)
 			start = ei->addr + ei->size;
+
 		/*
-		 * if start is now at or beyond end, we're done, full
-		 * coverage
+		 * If 'start' is now at or beyond 'end', we're done, full
+		 * coverage of the desired range exists:
 		 */
 		if (start >= end)
 			return 1;
@@ -128,16 +123,14 @@ int __init e820_all_mapped(u64 start, u64 end, unsigned type)
 }
 
 /*
- * Add a memory region to the kernel e820 map.
+ * Add a memory region to the kernel E820 map.
  */
 static void __init __e820_add_region(struct e820_table *table, u64 start, u64 size, int type)
 {
 	int x = table->nr_entries;
 
 	if (x >= ARRAY_SIZE(table->entries)) {
-		printk(KERN_ERR "e820: too many entries; ignoring [mem %#010llx-%#010llx]\n",
-		       (unsigned long long) start,
-		       (unsigned long long) (start + size - 1));
+		printk(KERN_ERR "e820: too many entries; ignoring [mem %#010llx-%#010llx]\n", start, start + size - 1);
 		return;
 	}
 
@@ -155,29 +148,15 @@ void __init e820_add_region(u64 start, u64 size, int type)
 static void __init e820_print_type(u32 type)
 {
 	switch (type) {
-	case E820_RAM:
-	case E820_RESERVED_KERN:
-		printk(KERN_CONT "usable");
-		break;
-	case E820_RESERVED:
-		printk(KERN_CONT "reserved");
-		break;
-	case E820_ACPI:
-		printk(KERN_CONT "ACPI data");
-		break;
-	case E820_NVS:
-		printk(KERN_CONT "ACPI NVS");
-		break;
-	case E820_UNUSABLE:
-		printk(KERN_CONT "unusable");
-		break;
-	case E820_PMEM:
-	case E820_PRAM:
-		printk(KERN_CONT "persistent (type %u)", type);
-		break;
-	default:
-		printk(KERN_CONT "type %u", type);
-		break;
+	case E820_RAM:			/* Fall through: */
+	case E820_RESERVED_KERN:	printk(KERN_CONT "usable");			break;
+	case E820_RESERVED:		printk(KERN_CONT "reserved");			break;
+	case E820_ACPI:			printk(KERN_CONT "ACPI data");			break;
+	case E820_NVS:			printk(KERN_CONT "ACPI NVS");			break;
+	case E820_UNUSABLE:		printk(KERN_CONT "unusable");			break;
+	case E820_PMEM:			/* Fall through: */
+	case E820_PRAM:			printk(KERN_CONT "persistent (type %u)", type);	break;
+	default:			printk(KERN_CONT "type %u", type);		break;
 	}
 }
 
@@ -187,26 +166,26 @@ void __init e820_print_map(char *who)
 
 	for (i = 0; i < e820_table->nr_entries; i++) {
 		printk(KERN_INFO "%s: [mem %#018Lx-%#018Lx] ", who,
-		       (unsigned long long) e820_table->entries[i].addr,
-		       (unsigned long long)
-		       (e820_table->entries[i].addr + e820_table->entries[i].size - 1));
+		       e820_table->entries[i].addr,
+		       e820_table->entries[i].addr + e820_table->entries[i].size - 1);
+
 		e820_print_type(e820_table->entries[i].type);
 		printk(KERN_CONT "\n");
 	}
 }
 
 /*
- * Sanitize the BIOS e820 map.
+ * Sanitize the BIOS E820 map.
  *
- * Some e820 responses include overlapping entries. The following
- * replaces the original e820 map with a new one, removing overlaps,
+ * Some E820 responses include overlapping entries. The following
+ * replaces the original E820 map with a new one, removing overlaps,
  * and resolving conflicting memory types in favor of highest
  * numbered type.
  *
  * The input parameter biosmap points to an array of 'struct
  * e820_entry' which on entry has elements in the range [0, *pnr_map)
  * valid, and which has space for up to max_nr_map entries.
- * On return, the resulting sanitized e820 map entries will be in
+ * On return, the resulting sanitized E820 map entries will be in
  * overwritten in the same location, starting at biosmap.
  *
  * The integer pointed to by pnr_map must be valid on entry (the
@@ -257,8 +236,10 @@ void __init e820_print_map(char *who)
  *	   ______________________4_
  */
 struct change_member {
-	struct e820_entry *pbios; /* pointer to original bios entry */
-	unsigned long long addr; /* address for this change point */
+	/* Pointer to the original BIOS entry: */
+	struct e820_entry	*pbios;
+	/* Address for this change point: */
+	unsigned long long	addr;
 };
 
 static int __init cpcompare(const void *a, const void *b)
@@ -268,7 +249,7 @@ static int __init cpcompare(const void *a, const void *b)
 
 	/*
 	 * Inputs are pointers to two elements of change_point[].  If their
-	 * addresses are unequal, their difference dominates.  If the addresses
+	 * addresses are not equal, their difference dominates.  If the addresses
 	 * are equal, then consider one that represents the end of its region
 	 * to be greater than one that does not.
 	 */
@@ -278,8 +259,7 @@ static int __init cpcompare(const void *a, const void *b)
 	return (ap->addr != ap->pbios->addr) - (bp->addr != bp->pbios->addr);
 }
 
-int __init sanitize_e820_table(struct e820_entry *biosmap, int max_nr_map,
-			     u32 *pnr_map)
+int __init sanitize_e820_table(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map)
 {
 	static struct change_member change_point_list[2*E820_X_MAX] __initdata;
 	static struct change_member *change_point[2*E820_X_MAX] __initdata;
@@ -293,112 +273,96 @@ int __init sanitize_e820_table(struct e820_entry *biosmap, int max_nr_map,
 	int old_nr, new_nr, chg_nr;
 	int i;
 
-	/* if there's only one memory region, don't bother */
+	/* If there's only one memory region, don't bother: */
 	if (*pnr_map < 2)
 		return -1;
 
 	old_nr = *pnr_map;
 	BUG_ON(old_nr > max_nr_map);
 
-	/* bail out if we find any unreasonable addresses in bios map */
-	for (i = 0; i < old_nr; i++)
+	/* Bail out if we find any unreasonable addresses in the BIOS map: */
+	for (i = 0; i < old_nr; i++) {
 		if (biosmap[i].addr + biosmap[i].size < biosmap[i].addr)
 			return -1;
+	}
 
-	/* create pointers for initial change-point information (for sorting) */
+	/* Create pointers for initial change-point information (for sorting): */
 	for (i = 0; i < 2 * old_nr; i++)
 		change_point[i] = &change_point_list[i];
 
-	/* record all known change-points (starting and ending addresses),
-	   omitting those that are for empty memory regions */
+	/*
+	 * Record all known change-points (starting and ending addresses),
+	 * omitting empty memory regions:
+	 */
 	chgidx = 0;
 	for (i = 0; i < old_nr; i++)	{
 		if (biosmap[i].size != 0) {
-			change_point[chgidx]->addr = biosmap[i].addr;
-			change_point[chgidx++]->pbios = &biosmap[i];
-			change_point[chgidx]->addr = biosmap[i].addr +
-				biosmap[i].size;
-			change_point[chgidx++]->pbios = &biosmap[i];
+			change_point[chgidx]->addr	= biosmap[i].addr;
+			change_point[chgidx++]->pbios	= &biosmap[i];
+			change_point[chgidx]->addr	= biosmap[i].addr + biosmap[i].size;
+			change_point[chgidx++]->pbios	= &biosmap[i];
 		}
 	}
 	chg_nr = chgidx;
 
-	/* sort change-point list by memory addresses (low -> high) */
+	/* Sort change-point list by memory addresses (low -> high): */
 	sort(change_point, chg_nr, sizeof *change_point, cpcompare, NULL);
 
-	/* create a new bios memory map, removing overlaps */
-	overlap_entries = 0;	 /* number of entries in the overlap table */
-	new_bios_entry = 0;	 /* index for creating new bios map entries */
-	last_type = 0;		 /* start with undefined memory type */
-	last_addr = 0;		 /* start with 0 as last starting address */
+	/* Create a new BIOS memory map, removing overlaps: */
+	overlap_entries = 0;	 /* Number of entries in the overlap table */
+	new_bios_entry = 0;	 /* Index for creating new bios map entries */
+	last_type = 0;		 /* Start with undefined memory type */
+	last_addr = 0;		 /* Start with 0 as last starting address */
 
-	/* loop through change-points, determining affect on the new bios map */
+	/* Loop through change-points, determining effect on the new BIOS map: */
 	for (chgidx = 0; chgidx < chg_nr; chgidx++) {
-		/* keep track of all overlapping bios entries */
-		if (change_point[chgidx]->addr ==
-		    change_point[chgidx]->pbios->addr) {
-			/*
-			 * add map entry to overlap list (> 1 entry
-			 * implies an overlap)
-			 */
-			overlap_list[overlap_entries++] =
-				change_point[chgidx]->pbios;
+		/* Keep track of all overlapping BIOS entries */
+		if (change_point[chgidx]->addr == change_point[chgidx]->pbios->addr) {
+			/* Add map entry to overlap list (> 1 entry implies an overlap) */
+			overlap_list[overlap_entries++] = change_point[chgidx]->pbios;
 		} else {
-			/*
-			 * remove entry from list (order independent,
-			 * so swap with last)
-			 */
+			/* Remove entry from list (order independent, so swap with last): */
 			for (i = 0; i < overlap_entries; i++) {
-				if (overlap_list[i] ==
-				    change_point[chgidx]->pbios)
-					overlap_list[i] =
-						overlap_list[overlap_entries-1];
+				if (overlap_list[i] == change_point[chgidx]->pbios)
+					overlap_list[i] = overlap_list[overlap_entries-1];
 			}
 			overlap_entries--;
 		}
 		/*
-		 * if there are overlapping entries, decide which
+		 * If there are overlapping entries, decide which
 		 * "type" to use (larger value takes precedence --
 		 * 1=usable, 2,3,4,4+=unusable)
 		 */
 		current_type = 0;
-		for (i = 0; i < overlap_entries; i++)
+		for (i = 0; i < overlap_entries; i++) {
 			if (overlap_list[i]->type > current_type)
 				current_type = overlap_list[i]->type;
-		/*
-		 * continue building up new bios map based on this
-		 * information
-		 */
+		}
+
+		/* Continue building up new BIOS map based on this information: */
 		if (current_type != last_type || current_type == E820_PRAM) {
 			if (last_type != 0)	 {
-				new_bios[new_bios_entry].size =
-					change_point[chgidx]->addr - last_addr;
-				/*
-				 * move forward only if the new size
-				 * was non-zero
-				 */
+				new_bios[new_bios_entry].size = change_point[chgidx]->addr - last_addr;
+				/* Move forward only if the new size was non-zero: */
 				if (new_bios[new_bios_entry].size != 0)
-					/*
-					 * no more space left for new
-					 * bios entries ?
-					 */
+					/* No more space left for new BIOS entries? */
 					if (++new_bios_entry >= max_nr_map)
 						break;
 			}
 			if (current_type != 0)	{
-				new_bios[new_bios_entry].addr =
-					change_point[chgidx]->addr;
+				new_bios[new_bios_entry].addr = change_point[chgidx]->addr;
 				new_bios[new_bios_entry].type = current_type;
 				last_addr = change_point[chgidx]->addr;
 			}
 			last_type = current_type;
 		}
 	}
-	/* retain count for new bios entries */
+
+	/* Retain count for new BIOS entries: */
 	new_nr = new_bios_entry;
 
-	/* copy new bios mapping into original location */
-	memcpy(biosmap, new_bios, new_nr * sizeof(struct e820_entry));
+	/* Copy new BIOS mapping into the original location: */
+	memcpy(biosmap, new_bios, new_nr*sizeof(struct e820_entry));
 	*pnr_map = new_nr;
 
 	return 0;
@@ -412,7 +376,7 @@ static int __init __append_e820_table(struct e820_entry *biosmap, int nr_map)
 		u64 end = start + size - 1;
 		u32 type = biosmap->type;
 
-		/* Overflow in 64 bits? Ignore the memory map. */
+		/* Ignore the entry on 64-bit overflow: */
 		if (start > end && likely(size))
 			return -1;
 
@@ -425,7 +389,7 @@ static int __init __append_e820_table(struct e820_entry *biosmap, int nr_map)
 }
 
 /*
- * Copy the BIOS e820 map into a safe place.
+ * Copy the BIOS E820 map into a safe place.
  *
  * Sanity-check it while we're at it..
  *
@@ -442,9 +406,8 @@ static int __init append_e820_table(struct e820_entry *biosmap, int nr_map)
 	return __append_e820_table(biosmap, nr_map);
 }
 
-static u64 __init __e820_update_range(struct e820_table *table, u64 start,
-					u64 size, unsigned old_type,
-					unsigned new_type)
+static u64 __init
+__e820_update_range(struct e820_table *table, u64 start, u64 size, unsigned old_type, unsigned new_type)
 {
 	u64 end;
 	unsigned int i;
@@ -456,8 +419,7 @@ static u64 __init __e820_update_range(struct e820_table *table, u64 start,
 		size = ULLONG_MAX - start;
 
 	end = start + size;
-	printk(KERN_DEBUG "e820: update [mem %#010Lx-%#010Lx] ",
-	       (unsigned long long) start, (unsigned long long) (end - 1));
+	printk(KERN_DEBUG "e820: update [mem %#010Lx-%#010Lx] ", start, end - 1);
 	e820_print_type(old_type);
 	printk(KERN_CONT " ==> ");
 	e820_print_type(new_type);
@@ -472,14 +434,15 @@ static u64 __init __e820_update_range(struct e820_table *table, u64 start,
 			continue;
 
 		ei_end = ei->addr + ei->size;
-		/* totally covered by new range? */
+
+		/* Completely covered by new range? */
 		if (ei->addr >= start && ei_end <= end) {
 			ei->type = new_type;
 			real_updated_size += ei->size;
 			continue;
 		}
 
-		/* new range is totally covered? */
+		/* New range is completely covered? */
 		if (ei->addr < start && ei_end > end) {
 			__e820_add_region(table, start, size, new_type);
 			__e820_add_region(table, end, ei_end - end, ei->type);
@@ -488,45 +451,41 @@ static u64 __init __e820_update_range(struct e820_table *table, u64 start,
 			continue;
 		}
 
-		/* partially covered */
+		/* Partially covered: */
 		final_start = max(start, ei->addr);
 		final_end = min(end, ei_end);
 		if (final_start >= final_end)
 			continue;
 
-		__e820_add_region(table, final_start, final_end - final_start,
-				  new_type);
+		__e820_add_region(table, final_start, final_end - final_start, new_type);
 
 		real_updated_size += final_end - final_start;
 
 		/*
-		 * left range could be head or tail, so need to update
-		 * size at first.
+		 * Left range could be head or tail, so need to update
+		 * its size first:
 		 */
 		ei->size -= final_end - final_start;
 		if (ei->addr < final_start)
 			continue;
+
 		ei->addr = final_end;
 	}
 	return real_updated_size;
 }
 
-u64 __init e820_update_range(u64 start, u64 size, unsigned old_type,
-			     unsigned new_type)
+u64 __init e820_update_range(u64 start, u64 size, unsigned old_type, unsigned new_type)
 {
 	return __e820_update_range(e820_table, start, size, old_type, new_type);
 }
 
-static u64 __init e820_update_range_firmware(u64 start, u64 size,
-					  unsigned old_type, unsigned new_type)
+static u64 __init e820_update_range_firmware(u64 start, u64 size, unsigned old_type, unsigned new_type)
 {
-	return __e820_update_range(e820_table_firmware, start, size, old_type,
-				     new_type);
+	return __e820_update_range(e820_table_firmware, start, size, old_type, new_type);
 }
 
-/* make e820 not cover the range */
-u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type,
-			     int checktype)
+/* Remove a range of memory from the E820 table: */
+u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type, int checktype)
 {
 	int i;
 	u64 end;
@@ -536,8 +495,7 @@ u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type,
 		size = ULLONG_MAX - start;
 
 	end = start + size;
-	printk(KERN_DEBUG "e820: remove [mem %#010Lx-%#010Lx] ",
-	       (unsigned long long) start, (unsigned long long) (end - 1));
+	printk(KERN_DEBUG "e820: remove [mem %#010Lx-%#010Lx] ", start, end - 1);
 	if (checktype)
 		e820_print_type(old_type);
 	printk(KERN_CONT "\n");
@@ -551,14 +509,15 @@ u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type,
 			continue;
 
 		ei_end = ei->addr + ei->size;
-		/* totally covered? */
+
+		/* Completely covered? */
 		if (ei->addr >= start && ei_end <= end) {
 			real_removed_size += ei->size;
 			memset(ei, 0, sizeof(struct e820_entry));
 			continue;
 		}
 
-		/* new range is totally covered? */
+		/* Is the new range completely covered? */
 		if (ei->addr < start && ei_end > end) {
 			e820_add_region(end, ei_end - end, ei->type);
 			ei->size = start - ei->addr;
@@ -566,20 +525,22 @@ u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type,
 			continue;
 		}
 
-		/* partially covered */
+		/* Partially covered: */
 		final_start = max(start, ei->addr);
 		final_end = min(end, ei_end);
 		if (final_start >= final_end)
 			continue;
+
 		real_removed_size += final_end - final_start;
 
 		/*
-		 * left range could be head or tail, so need to update
-		 * size at first.
+		 * Left range could be head or tail, so need to update
+		 * the size first:
 		 */
 		ei->size -= final_end - final_start;
 		if (ei->addr < final_start)
 			continue;
+
 		ei->addr = final_end;
 	}
 	return real_removed_size;
@@ -589,19 +550,22 @@ void __init update_e820(void)
 {
 	if (sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries))
 		return;
+
 	printk(KERN_INFO "e820: modified physical RAM map:\n");
 	e820_print_map("modified");
 }
+
 static void __init update_e820_table_firmware(void)
 {
 	sanitize_e820_table(e820_table_firmware->entries, ARRAY_SIZE(e820_table_firmware->entries), &e820_table_firmware->nr_entries);
 }
+
 #define MAX_GAP_END 0x100000000ull
+
 /*
- * Search for a gap in the e820 memory space from 0 to MAX_GAP_END.
+ * Search for a gap in the E820 memory space from 0 to MAX_GAP_END (4GB).
  */
-static int __init e820_search_gap(unsigned long *gapstart,
-		unsigned long *gapsize)
+static int __init e820_search_gap(unsigned long *gapstart, unsigned long *gapsize)
 {
 	unsigned long long last = MAX_GAP_END;
 	int i = e820_table->nr_entries;
@@ -613,7 +577,7 @@ static int __init e820_search_gap(unsigned long *gapstart,
 
 		/*
 		 * Since "last" is at most 4GB, we know we'll
-		 * fit in 32 bits if this condition is true
+		 * fit in 32 bits if this condition is true:
 		 */
 		if (last > end) {
 			unsigned long gap = last - end;
@@ -631,9 +595,11 @@ static int __init e820_search_gap(unsigned long *gapstart,
 }
 
 /*
- * Search for the biggest gap in the low 32 bits of the e820
- * memory space.  We pass this space to PCI to assign MMIO resources
- * for hotplug or unconfigured devices in.
+ * Search for the biggest gap in the low 32 bits of the E820
+ * memory space. We pass this space to the PCI subsystem, so
+ * that it can assign MMIO resources for hotplug or
+ * unconfigured devices in.
+ *
  * Hopefully the BIOS let enough space left.
  */
 __init void e820_setup_gap(void)
@@ -648,8 +614,8 @@ __init void e820_setup_gap(void)
 #ifdef CONFIG_X86_64
 		gapstart = (max_pfn << PAGE_SHIFT) + 1024*1024;
 		printk(KERN_ERR
-	"e820: cannot find a gap in the 32bit address range\n"
-	"e820: PCI devices with unassigned 32bit BARs may break!\n");
+			"e820: Cannot find an available gap in the 32-bit address range\n"
+			"e820: PCI devices with unassigned 32-bit BARs may not work!\n");
 #else
 		gapstart = 0x10000000;
 #endif
@@ -660,43 +626,44 @@ __init void e820_setup_gap(void)
 	 */
 	pci_mem_start = gapstart;
 
-	printk(KERN_INFO
-	       "e820: [mem %#010lx-%#010lx] available for PCI devices\n",
-	       gapstart, gapstart + gapsize - 1);
+	printk(KERN_INFO "e820: [mem %#010lx-%#010lx] available for PCI devices\n", gapstart, gapstart + gapsize - 1);
 }
 
 /*
  * Called late during init, in free_initmem().
  *
- * Initial e820 and e820_table_firmware are largish __initdata arrays.
- * Copy them to (usually much smaller) dynamically allocated area.
- * This is done after all tweaks we ever do to them:
- * all functions which modify them are __init functions,
- * they won't exist after this point.
+ * Initial e820_table and e820_table_firmware are largish __initdata arrays.
+ *
+ * Copy them to a (usually much smaller) dynamically allocated area that is
+ * sized precisely after the number of e820 entries.
+ *
+ * This is done after we've performed all the fixes and tweaks to the tables.
+ * All functions which modify them are __init functions, which won't exist
+ * after free_initmem().
  */
 __init void e820_reallocate_tables(void)
 {
 	struct e820_table *n;
 	int size;
 
-	size = offsetof(struct e820_table, entries) + sizeof(struct e820_entry) * e820_table->nr_entries;
+	size = offsetof(struct e820_table, entries) + sizeof(struct e820_entry)*e820_table->nr_entries;
 	n = kmalloc(size, GFP_KERNEL);
 	BUG_ON(!n);
 	memcpy(n, e820_table, size);
 	e820_table = n;
 
-	size = offsetof(struct e820_table, entries) + sizeof(struct e820_entry) * e820_table_firmware->nr_entries;
+	size = offsetof(struct e820_table, entries) + sizeof(struct e820_entry)*e820_table_firmware->nr_entries;
 	n = kmalloc(size, GFP_KERNEL);
 	BUG_ON(!n);
 	memcpy(n, e820_table_firmware, size);
 	e820_table_firmware = n;
 }
 
-/**
- * Because of the size limitation of struct boot_params, only first
- * 128 E820 memory entries are passed to kernel via
- * boot_params.e820_table, others are passed via SETUP_E820_EXT node of
- * linked list of struct setup_data, which is parsed here.
+/*
+ * Because of the small fixed size of struct boot_params, only the first
+ * 128 E820 memory entries are passed to the kernel via boot_params.e820_table,
+ * the remaining (if any) entries are passed via the SETUP_E820_EXT node of
+ * struct setup_data, which is parsed here.
  */
 void __init parse_e820_ext(u64 phys_addr, u32 data_len)
 {
@@ -707,8 +674,10 @@ void __init parse_e820_ext(u64 phys_addr, u32 data_len)
 	sdata = early_memremap(phys_addr, data_len);
 	entries = sdata->len / sizeof(struct e820_entry);
 	extmap = (struct e820_entry *)(sdata->data);
+
 	__append_e820_table(extmap, entries);
 	sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
+
 	early_memunmap(sdata, data_len);
 	printk(KERN_INFO "e820: extended physical RAM map:\n");
 	e820_print_map("extended");
@@ -716,10 +685,10 @@ void __init parse_e820_ext(u64 phys_addr, u32 data_len)
 
 /**
  * Find the ranges of physical addresses that do not correspond to
- * e820 RAM areas and mark the corresponding pages as nosave for
- * hibernation (32 bit) or software suspend and suspend to RAM (64 bit).
+ * E820 RAM areas and mark the corresponding pages as 'nosave' for
+ * hibernation (32-bit) or software suspend and suspend to RAM (64-bit).
  *
- * This function requires the e820 map to be sorted and without any
+ * This function requires the E820 map to be sorted and without any
  * overlapping entries.
  */
 void __init e820_mark_nosave_regions(unsigned long limit_pfn)
@@ -744,9 +713,9 @@ void __init e820_mark_nosave_regions(unsigned long limit_pfn)
 }
 
 #ifdef CONFIG_ACPI
-/**
- * Mark ACPI NVS memory region, so that we can save/restore it during
- * hibernation and the subsequent resume.
+/*
+ * Register ACPI NVS memory regions, so that we can save/restore them during
+ * hibernation and the subsequent resume:
  */
 static int __init e820_mark_nvs_memory(void)
 {
@@ -828,6 +797,7 @@ static unsigned long __init e820_end_pfn(unsigned long limit_pfn, unsigned type)
 			 last_pfn, max_arch_pfn);
 	return last_pfn;
 }
+
 unsigned long __init e820_end_of_ram_pfn(void)
 {
 	return e820_end_pfn(MAX_ARCH_PFN, E820_RAM);
@@ -846,7 +816,7 @@ static void __init early_panic(char *msg)
 
 static int userdef __initdata;
 
-/* "mem=nopentium" disables the 4MB page tables. */
+/* The "mem=nopentium" boot option disables 4MB page tables on 32-bit kernels: */
 static int __init parse_memopt(char *p)
 {
 	u64 mem_size;
@@ -866,9 +836,11 @@ static int __init parse_memopt(char *p)
 
 	userdef = 1;
 	mem_size = memparse(p, &p);
-	/* don't remove all of memory when handling "mem={invalid}" param */
+
+	/* Don't remove all memory when getting "mem={invalid}" parameter: */
 	if (mem_size == 0)
 		return -EINVAL;
+
 	e820_remove_range(mem_size, ULLONG_MAX - mem_size, E820_RAM, 1);
 
 	return 0;
@@ -887,7 +859,7 @@ static int __init parse_memmap_one(char *p)
 #ifdef CONFIG_CRASH_DUMP
 		/*
 		 * If we are doing a crash dump, we still need to know
-		 * the real mem size before original memory map is
+		 * the real memory size before the original memory map is
 		 * reset.
 		 */
 		saved_max_pfn = e820_end_of_ram_pfn();
@@ -915,11 +887,13 @@ static int __init parse_memmap_one(char *p)
 	} else if (*p == '!') {
 		start_at = memparse(p+1, &p);
 		e820_add_region(start_at, mem_size, E820_PRAM);
-	} else
+	} else {
 		e820_remove_range(mem_size, ULLONG_MAX - mem_size, E820_RAM, 1);
+	}
 
 	return *p == '\0' ? 0 : -EINVAL;
 }
+
 static int __init parse_memmap_opt(char *str)
 {
 	while (str) {
@@ -939,8 +913,7 @@ early_param("memmap", parse_memmap_opt);
 void __init finish_e820_parsing(void)
 {
 	if (userdef) {
-		if (sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries),
-					&e820_table->nr_entries) < 0)
+		if (sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries) < 0)
 			early_panic("Invalid user supplied memory map");
 
 		printk(KERN_INFO "e820: user-defined physical RAM map:\n");
@@ -951,49 +924,42 @@ void __init finish_e820_parsing(void)
 static const char *__init e820_type_to_string(int e820_type)
 {
 	switch (e820_type) {
-	case E820_RESERVED_KERN:
-	case E820_RAM:	return "System RAM";
-	case E820_ACPI:	return "ACPI Tables";
-	case E820_NVS:	return "ACPI Non-volatile Storage";
-	case E820_UNUSABLE:	return "Unusable memory";
-	case E820_PRAM: return "Persistent Memory (legacy)";
-	case E820_PMEM: return "Persistent Memory";
-	default:	return "reserved";
+	case E820_RESERVED_KERN: /* Fall-through: */
+	case E820_RAM:		 return "System RAM";
+	case E820_ACPI:		 return "ACPI Tables";
+	case E820_NVS:		 return "ACPI Non-volatile Storage";
+	case E820_UNUSABLE:	 return "Unusable memory";
+	case E820_PRAM:		 return "Persistent Memory (legacy)";
+	case E820_PMEM:		 return "Persistent Memory";
+	default:		 return "Reserved";
 	}
 }
 
 static unsigned long __init e820_type_to_iomem_type(int e820_type)
 {
 	switch (e820_type) {
-	case E820_RESERVED_KERN:
-	case E820_RAM:
-		return IORESOURCE_SYSTEM_RAM;
-	case E820_ACPI:
-	case E820_NVS:
-	case E820_UNUSABLE:
-	case E820_PRAM:
-	case E820_PMEM:
-	default:
-		return IORESOURCE_MEM;
+	case E820_RESERVED_KERN: /* Fall-through: */
+	case E820_RAM:		 return IORESOURCE_SYSTEM_RAM;
+	case E820_ACPI:		 /* Fall-through: */
+	case E820_NVS:		 /* Fall-through: */
+	case E820_UNUSABLE:	 /* Fall-through: */
+	case E820_PRAM:		 /* Fall-through: */
+	case E820_PMEM:		 /* Fall-through: */
+	default:		 return IORESOURCE_MEM;
 	}
 }
 
 static unsigned long __init e820_type_to_iores_desc(int e820_type)
 {
 	switch (e820_type) {
-	case E820_ACPI:
-		return IORES_DESC_ACPI_TABLES;
-	case E820_NVS:
-		return IORES_DESC_ACPI_NV_STORAGE;
-	case E820_PMEM:
-		return IORES_DESC_PERSISTENT_MEMORY;
-	case E820_PRAM:
-		return IORES_DESC_PERSISTENT_MEMORY_LEGACY;
-	case E820_RESERVED_KERN:
-	case E820_RAM:
-	case E820_UNUSABLE:
-	default:
-		return IORES_DESC_NONE;
+	case E820_ACPI:		 return IORES_DESC_ACPI_TABLES;
+	case E820_NVS:		 return IORES_DESC_ACPI_NV_STORAGE;
+	case E820_PMEM:		 return IORES_DESC_PERSISTENT_MEMORY;
+	case E820_PRAM:		 return IORES_DESC_PERSISTENT_MEMORY_LEGACY;
+	case E820_RESERVED_KERN: /* Fall-through: */
+	case E820_RAM:		 /* Fall-through: */
+	case E820_UNUSABLE:	 /* Fall-through: */
+	default:		 return IORES_DESC_NONE;
 	}
 }
 
@@ -1018,9 +984,11 @@ static bool __init do_mark_busy(u32 type, struct resource *res)
 }
 
 /*
- * Mark e820 reserved areas as busy for the resource manager.
+ * Mark E820 reserved areas as busy for the resource manager:
  */
+
 static struct resource __initdata *e820_res;
+
 void __init e820_reserve_resources(void)
 {
 	int i;
@@ -1056,9 +1024,8 @@ void __init e820_reserve_resources(void)
 
 	for (i = 0; i < e820_table_firmware->nr_entries; i++) {
 		struct e820_entry *entry = &e820_table_firmware->entries[i];
-		firmware_map_add_early(entry->addr,
-			entry->addr + entry->size,
-			e820_type_to_string(entry->type));
+
+		firmware_map_add_early(entry->addr, entry->addr + entry->size, e820_type_to_string(entry->type));
 	}
 }
 
@@ -1094,7 +1061,7 @@ void __init e820_reserve_resources_late(void)
 	}
 
 	/*
-	 * Try to bump up RAM regions to reasonable boundaries to
+	 * Try to bump up RAM regions to reasonable boundaries, to
 	 * avoid stolen RAM:
 	 */
 	for (i = 0; i < e820_table->nr_entries; i++) {
@@ -1103,24 +1070,27 @@ void __init e820_reserve_resources_late(void)
 
 		if (entry->type != E820_RAM)
 			continue;
+
 		start = entry->addr + entry->size;
 		end = round_up(start, ram_alignment(start)) - 1;
 		if (end > MAX_RESOURCE_SIZE)
 			end = MAX_RESOURCE_SIZE;
 		if (start >= end)
 			continue;
-		printk(KERN_DEBUG
-		       "e820: reserve RAM buffer [mem %#010llx-%#010llx]\n",
-		       start, end);
-		reserve_region_with_split(&iomem_resource, start, end,
-					  "RAM buffer");
+
+		printk(KERN_DEBUG "e820: reserve RAM buffer [mem %#010llx-%#010llx]\n", start, end);
+		reserve_region_with_split(&iomem_resource, start, end, "RAM buffer");
 	}
 }
 
+/*
+ * Pass the firmware (bootloader) E820 map to the kernel and process it:
+ */
 char *__init e820__memory_setup_default(void)
 {
 	char *who = "BIOS-e820";
 	u32 new_nr;
+
 	/*
 	 * Try to copy the BIOS-supplied E820-map.
 	 *
@@ -1128,17 +1098,14 @@ char *__init e820__memory_setup_default(void)
 	 * the next section from 1mb->appropriate_mem_k
 	 */
 	new_nr = boot_params.e820_entries;
-	sanitize_e820_table(boot_params.e820_table,
-			ARRAY_SIZE(boot_params.e820_table),
-			&new_nr);
+	sanitize_e820_table(boot_params.e820_table, ARRAY_SIZE(boot_params.e820_table), &new_nr);
 	boot_params.e820_entries = new_nr;
-	if (append_e820_table(boot_params.e820_table, boot_params.e820_entries)
-	  < 0) {
+
+	if (append_e820_table(boot_params.e820_table, boot_params.e820_entries) < 0) {
 		u64 mem_size;
 
-		/* compare results from other methods and take the greater */
-		if (boot_params.alt_mem_k
-		    < boot_params.screen_info.ext_mem_k) {
+		/* Compare results from other methods and take the one that gives more RAM: */
+		if (boot_params.alt_mem_k < boot_params.screen_info.ext_mem_k) {
 			mem_size = boot_params.screen_info.ext_mem_k;
 			who = "BIOS-88";
 		} else {
@@ -1151,7 +1118,6 @@ char *__init e820__memory_setup_default(void)
 		e820_add_region(HIGH_MEMORY, mem_size << 10, E820_RAM);
 	}
 
-	/* In case someone cares... */
 	return who;
 }
 
@@ -1165,7 +1131,9 @@ void __init e820__memory_setup(void)
 	char *who;
 
 	who = x86_init.resources.memory_setup();
+
 	memcpy(e820_table_firmware, e820_table, sizeof(struct e820_table));
+
 	printk(KERN_INFO "e820: BIOS-provided physical RAM map:\n");
 	e820_print_map(who);
 }
@@ -1221,8 +1189,7 @@ void __init memblock_find_dma_reserve(void)
 		nr_pages += end_pfn - start_pfn;
 	}
 
-	for_each_free_mem_range(u, NUMA_NO_NODE, MEMBLOCK_NONE, &start, &end,
-				NULL) {
+	for_each_free_mem_range(u, NUMA_NO_NODE, MEMBLOCK_NONE, &start, &end, NULL) {
 		start_pfn = min_t(unsigned long, PFN_UP(start), MAX_DMA_PFN);
 		end_pfn = min_t(unsigned long, PFN_DOWN(end), MAX_DMA_PFN);
 		if (start_pfn < end_pfn)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 20/50] x86/boot/e820: Rename memblock_x86_fill() to e820__memblock_setup() and improve the explanations
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (18 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 19/50] x86/boot/e820: Basic cleanup of e820.c Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 21/50] x86/boot/e820: Consolidate 'struct e820_entry *entry' local variable names Ingo Molnar
                   ` (29 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

So memblock_x86_fill() is another E820 code misnomer:

 - nothing in its name tells us that it's part of the E820 subsystem ...

 - The 'fill' wording is ambiguous and doesn't tell us whether it's a single
   entry or some process - while the _real_ purpose of the function is hidden,
   which is to do a complete setup of the (platform independent) memblock regions.

So rename it accordingly, to e820__memblock_setup().

Also translate this incomprehensible and misleading comment:

        /*
	 * EFI may have more than 128 entries
	 * We are safe to enable resizing, beause memblock_x86_fill()
	 * is rather later for x86
	 */
        memblock_allow_resize();

The worst aspect of this comment isn't even the sloppy typos, but that it
casually mentions a '128' number with no explanation, which makes one lead
to the assumption that this is related to the well-known limit of a maximum
of 128 E820 entries passed via legacy bootloaders.

But no, the _real_ meaning of 128 here is that of the memblock subsystem,
which too happens to have a 128 entries limit for very early memblock
regions (which is unrelated to E820), via INIT_MEMBLOCK_REGIONS ...

So change the comment to a more comprehensible version:

        /*
         * The bootstrap memblock region count maximum is 128 entries
         * (INIT_MEMBLOCK_REGIONS), but EFI might pass us more E820 entries
         * than that - so allow memblock resizing.
         *
         * This is safe, because this call happens pretty late during x86 setup,
         * so we know about reserved memory regions already. (This is important
         * so that memblock resizing does no stomp over reserved areas.)
         */
        memblock_allow_resize();

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h |  2 +-
 arch/x86/kernel/e820.c          | 14 +++++++++-----
 arch/x86/kernel/setup.c         |  4 ++--
 3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 2c336d8a8593..01698548fbc8 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -21,7 +21,7 @@ extern void parse_e820_ext(u64 phys_addr, u32 data_len);
 extern unsigned long e820_end_of_ram_pfn(void);
 extern unsigned long e820_end_of_low_ram_pfn(void);
 extern u64  early_reserve_e820(u64 sizet, u64 align);
-extern void memblock_x86_fill(void);
+extern void e820__memblock_setup(void);
 extern void memblock_find_dma_reserve(void);
 extern void finish_e820_parsing(void);
 extern void e820_reserve_resources(void);
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 624190fe86a7..b8e216b3957a 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -1138,15 +1138,19 @@ void __init e820__memory_setup(void)
 	e820_print_map(who);
 }
 
-void __init memblock_x86_fill(void)
+void __init e820__memblock_setup(void)
 {
 	int i;
 	u64 end;
 
 	/*
-	 * EFI may have more than 128 entries
-	 * We are safe to enable resizing, beause memblock_x86_fill()
-	 * is rather later for x86
+	 * The bootstrap memblock region count maximum is 128 entries
+	 * (INIT_MEMBLOCK_REGIONS), but EFI might pass us more E820 entries
+	 * than that - so allow memblock resizing.
+	 *
+	 * This is safe, because this call happens pretty late during x86 setup,
+	 * so we know about reserved memory regions already. (This is important
+	 * so that memblock resizing does no stomp over reserved areas.)
 	 */
 	memblock_allow_resize();
 
@@ -1163,7 +1167,7 @@ void __init memblock_x86_fill(void)
 		memblock_add(ei->addr, ei->size);
 	}
 
-	/* throw away partial pages */
+	/* Throw away partial pages: */
 	memblock_trim_memory(PAGE_SIZE);
 
 	memblock_dump_all();
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index f905430d7b04..838e4b5707ae 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1109,7 +1109,7 @@ void __init setup_arch(char **cmdline_p)
 	early_alloc_pgt_buf();
 
 	/*
-	 * Need to conclude brk, before memblock_x86_fill()
+	 * Need to conclude brk, before e820__memblock_setup()
 	 *  it could use memblock_find_in_range, could overlap with
 	 *  brk area.
 	 */
@@ -1118,7 +1118,7 @@ void __init setup_arch(char **cmdline_p)
 	cleanup_highmap();
 
 	memblock_set_current_limit(ISA_END_ADDRESS);
-	memblock_x86_fill();
+	e820__memblock_setup();
 
 	reserve_bios_regions();
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 21/50] x86/boot/e820: Consolidate 'struct e820_entry *entry' local variable names
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (19 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 20/50] x86/boot/e820: Rename memblock_x86_fill() to e820__memblock_setup() and improve the explanations Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 22/50] x86/boot/e820: Convert printk(KERN_* ...) to pr_*() Ingo Molnar
                   ` (28 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

So the E820 code has a lot of cases of:

	struct e820_entry *ei;

... but the 'ei' name makes very little sense if you think about it, it's
not an abbreviation of anything obviously related to E820 table entries.

This results in weird looking lines such as:

               if (type && ei->type != type)

where you might have to double check what 'ei' really means, plus
weird looking secondary variable names, such as:

	u64 ei_end;

The 'ei' name was introduced in a single function over a decade ago, and
then mindlessly cargo-copied over into other functions - with usage growing
to over 60 uses altogether (!).

( My best guess is that it might have been originally meant as abbreviation
  of 'entry interval'. )

Anyway, rename these to the much more obvious:

	struct e820_entry *entry;

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/e820.c | 110 ++++++++++++++++++++++++++++++++++-----------------------------------
 1 file changed, 55 insertions(+), 55 deletions(-)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index b8e216b3957a..48b1e36e7250 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -73,11 +73,11 @@ int e820_any_mapped(u64 start, u64 end, unsigned type)
 	int i;
 
 	for (i = 0; i < e820_table->nr_entries; i++) {
-		struct e820_entry *ei = &e820_table->entries[i];
+		struct e820_entry *entry = &e820_table->entries[i];
 
-		if (type && ei->type != type)
+		if (type && entry->type != type)
 			continue;
-		if (ei->addr >= end || ei->addr + ei->size <= start)
+		if (entry->addr >= end || entry->addr + entry->size <= start)
 			continue;
 		return 1;
 	}
@@ -96,21 +96,21 @@ int __init e820_all_mapped(u64 start, u64 end, unsigned type)
 	int i;
 
 	for (i = 0; i < e820_table->nr_entries; i++) {
-		struct e820_entry *ei = &e820_table->entries[i];
+		struct e820_entry *entry = &e820_table->entries[i];
 
-		if (type && ei->type != type)
+		if (type && entry->type != type)
 			continue;
 
 		/* Is the region (part) in overlap with the current region? */
-		if (ei->addr >= end || ei->addr + ei->size <= start)
+		if (entry->addr >= end || entry->addr + entry->size <= start)
 			continue;
 
 		/*
 		 * If the region is at the beginning of <start,end> we move
 		 * 'start' to the end of the region since it's ok until there
 		 */
-		if (ei->addr <= start)
-			start = ei->addr + ei->size;
+		if (entry->addr <= start)
+			start = entry->addr + entry->size;
 
 		/*
 		 * If 'start' is now at or beyond 'end', we're done, full
@@ -426,34 +426,34 @@ __e820_update_range(struct e820_table *table, u64 start, u64 size, unsigned old_
 	printk(KERN_CONT "\n");
 
 	for (i = 0; i < table->nr_entries; i++) {
-		struct e820_entry *ei = &table->entries[i];
+		struct e820_entry *entry = &table->entries[i];
 		u64 final_start, final_end;
-		u64 ei_end;
+		u64 entry_end;
 
-		if (ei->type != old_type)
+		if (entry->type != old_type)
 			continue;
 
-		ei_end = ei->addr + ei->size;
+		entry_end = entry->addr + entry->size;
 
 		/* Completely covered by new range? */
-		if (ei->addr >= start && ei_end <= end) {
-			ei->type = new_type;
-			real_updated_size += ei->size;
+		if (entry->addr >= start && entry_end <= end) {
+			entry->type = new_type;
+			real_updated_size += entry->size;
 			continue;
 		}
 
 		/* New range is completely covered? */
-		if (ei->addr < start && ei_end > end) {
+		if (entry->addr < start && entry_end > end) {
 			__e820_add_region(table, start, size, new_type);
-			__e820_add_region(table, end, ei_end - end, ei->type);
-			ei->size = start - ei->addr;
+			__e820_add_region(table, end, entry_end - end, entry->type);
+			entry->size = start - entry->addr;
 			real_updated_size += size;
 			continue;
 		}
 
 		/* Partially covered: */
-		final_start = max(start, ei->addr);
-		final_end = min(end, ei_end);
+		final_start = max(start, entry->addr);
+		final_end = min(end, entry_end);
 		if (final_start >= final_end)
 			continue;
 
@@ -465,11 +465,11 @@ __e820_update_range(struct e820_table *table, u64 start, u64 size, unsigned old_
 		 * Left range could be head or tail, so need to update
 		 * its size first:
 		 */
-		ei->size -= final_end - final_start;
-		if (ei->addr < final_start)
+		entry->size -= final_end - final_start;
+		if (entry->addr < final_start)
 			continue;
 
-		ei->addr = final_end;
+		entry->addr = final_end;
 	}
 	return real_updated_size;
 }
@@ -501,33 +501,33 @@ u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type, int checkty
 	printk(KERN_CONT "\n");
 
 	for (i = 0; i < e820_table->nr_entries; i++) {
-		struct e820_entry *ei = &e820_table->entries[i];
+		struct e820_entry *entry = &e820_table->entries[i];
 		u64 final_start, final_end;
-		u64 ei_end;
+		u64 entry_end;
 
-		if (checktype && ei->type != old_type)
+		if (checktype && entry->type != old_type)
 			continue;
 
-		ei_end = ei->addr + ei->size;
+		entry_end = entry->addr + entry->size;
 
 		/* Completely covered? */
-		if (ei->addr >= start && ei_end <= end) {
-			real_removed_size += ei->size;
-			memset(ei, 0, sizeof(struct e820_entry));
+		if (entry->addr >= start && entry_end <= end) {
+			real_removed_size += entry->size;
+			memset(entry, 0, sizeof(struct e820_entry));
 			continue;
 		}
 
 		/* Is the new range completely covered? */
-		if (ei->addr < start && ei_end > end) {
-			e820_add_region(end, ei_end - end, ei->type);
-			ei->size = start - ei->addr;
+		if (entry->addr < start && entry_end > end) {
+			e820_add_region(end, entry_end - end, entry->type);
+			entry->size = start - entry->addr;
 			real_removed_size += size;
 			continue;
 		}
 
 		/* Partially covered: */
-		final_start = max(start, ei->addr);
-		final_end = min(end, ei_end);
+		final_start = max(start, entry->addr);
+		final_end = min(end, entry_end);
 		if (final_start >= final_end)
 			continue;
 
@@ -537,11 +537,11 @@ u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type, int checkty
 		 * Left range could be head or tail, so need to update
 		 * the size first:
 		 */
-		ei->size -= final_end - final_start;
-		if (ei->addr < final_start)
+		entry->size -= final_end - final_start;
+		if (entry->addr < final_start)
 			continue;
 
-		ei->addr = final_end;
+		entry->addr = final_end;
 	}
 	return real_removed_size;
 }
@@ -697,15 +697,15 @@ void __init e820_mark_nosave_regions(unsigned long limit_pfn)
 	unsigned long pfn = 0;
 
 	for (i = 0; i < e820_table->nr_entries; i++) {
-		struct e820_entry *ei = &e820_table->entries[i];
+		struct e820_entry *entry = &e820_table->entries[i];
 
-		if (pfn < PFN_UP(ei->addr))
-			register_nosave_region(pfn, PFN_UP(ei->addr));
+		if (pfn < PFN_UP(entry->addr))
+			register_nosave_region(pfn, PFN_UP(entry->addr));
 
-		pfn = PFN_DOWN(ei->addr + ei->size);
+		pfn = PFN_DOWN(entry->addr + entry->size);
 
-		if (ei->type != E820_RAM && ei->type != E820_RESERVED_KERN)
-			register_nosave_region(PFN_UP(ei->addr), pfn);
+		if (entry->type != E820_RAM && entry->type != E820_RESERVED_KERN)
+			register_nosave_region(PFN_UP(entry->addr), pfn);
 
 		if (pfn >= limit_pfn)
 			break;
@@ -722,10 +722,10 @@ static int __init e820_mark_nvs_memory(void)
 	int i;
 
 	for (i = 0; i < e820_table->nr_entries; i++) {
-		struct e820_entry *ei = &e820_table->entries[i];
+		struct e820_entry *entry = &e820_table->entries[i];
 
-		if (ei->type == E820_NVS)
-			acpi_nvs_register(ei->addr, ei->size);
+		if (entry->type == E820_NVS)
+			acpi_nvs_register(entry->addr, entry->size);
 	}
 
 	return 0;
@@ -770,15 +770,15 @@ static unsigned long __init e820_end_pfn(unsigned long limit_pfn, unsigned type)
 	unsigned long max_arch_pfn = MAX_ARCH_PFN;
 
 	for (i = 0; i < e820_table->nr_entries; i++) {
-		struct e820_entry *ei = &e820_table->entries[i];
+		struct e820_entry *entry = &e820_table->entries[i];
 		unsigned long start_pfn;
 		unsigned long end_pfn;
 
-		if (ei->type != type)
+		if (entry->type != type)
 			continue;
 
-		start_pfn = ei->addr >> PAGE_SHIFT;
-		end_pfn = (ei->addr + ei->size) >> PAGE_SHIFT;
+		start_pfn = entry->addr >> PAGE_SHIFT;
+		end_pfn = (entry->addr + entry->size) >> PAGE_SHIFT;
 
 		if (start_pfn >= limit_pfn)
 			continue;
@@ -1155,16 +1155,16 @@ void __init e820__memblock_setup(void)
 	memblock_allow_resize();
 
 	for (i = 0; i < e820_table->nr_entries; i++) {
-		struct e820_entry *ei = &e820_table->entries[i];
+		struct e820_entry *entry = &e820_table->entries[i];
 
-		end = ei->addr + ei->size;
+		end = entry->addr + entry->size;
 		if (end != (resource_size_t)end)
 			continue;
 
-		if (ei->type != E820_RAM && ei->type != E820_RESERVED_KERN)
+		if (entry->type != E820_RAM && entry->type != E820_RESERVED_KERN)
 			continue;
 
-		memblock_add(ei->addr, ei->size);
+		memblock_add(entry->addr, entry->size);
 	}
 
 	/* Throw away partial pages: */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 22/50] x86/boot/e820: Convert printk(KERN_* ...) to pr_*()
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (20 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 21/50] x86/boot/e820: Consolidate 'struct e820_entry *entry' local variable names Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:59   ` Joe Perches
  2017-01-28 22:11 ` [PATCH 23/50] x86/boot/e820: Move the memblock_find_dma_reserve() function and rename it to memblock_set_dma_reserve() Ingo Molnar
                   ` (27 subsequent siblings)
  49 siblings, 1 reply; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/e820.c | 50 +++++++++++++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 48b1e36e7250..4a8d905226c9 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -130,7 +130,7 @@ static void __init __e820_add_region(struct e820_table *table, u64 start, u64 si
 	int x = table->nr_entries;
 
 	if (x >= ARRAY_SIZE(table->entries)) {
-		printk(KERN_ERR "e820: too many entries; ignoring [mem %#010llx-%#010llx]\n", start, start + size - 1);
+		pr_err("e820: too many entries; ignoring [mem %#010llx-%#010llx]\n", start, start + size - 1);
 		return;
 	}
 
@@ -149,14 +149,14 @@ static void __init e820_print_type(u32 type)
 {
 	switch (type) {
 	case E820_RAM:			/* Fall through: */
-	case E820_RESERVED_KERN:	printk(KERN_CONT "usable");			break;
-	case E820_RESERVED:		printk(KERN_CONT "reserved");			break;
-	case E820_ACPI:			printk(KERN_CONT "ACPI data");			break;
-	case E820_NVS:			printk(KERN_CONT "ACPI NVS");			break;
-	case E820_UNUSABLE:		printk(KERN_CONT "unusable");			break;
+	case E820_RESERVED_KERN:	pr_cont("usable");			break;
+	case E820_RESERVED:		pr_cont("reserved");			break;
+	case E820_ACPI:			pr_cont("ACPI data");			break;
+	case E820_NVS:			pr_cont("ACPI NVS");			break;
+	case E820_UNUSABLE:		pr_cont("unusable");			break;
 	case E820_PMEM:			/* Fall through: */
-	case E820_PRAM:			printk(KERN_CONT "persistent (type %u)", type);	break;
-	default:			printk(KERN_CONT "type %u", type);		break;
+	case E820_PRAM:			pr_cont("persistent (type %u)", type);	break;
+	default:			pr_cont("type %u", type);		break;
 	}
 }
 
@@ -165,12 +165,12 @@ void __init e820_print_map(char *who)
 	int i;
 
 	for (i = 0; i < e820_table->nr_entries; i++) {
-		printk(KERN_INFO "%s: [mem %#018Lx-%#018Lx] ", who,
+		pr_info("%s: [mem %#018Lx-%#018Lx] ", who,
 		       e820_table->entries[i].addr,
 		       e820_table->entries[i].addr + e820_table->entries[i].size - 1);
 
 		e820_print_type(e820_table->entries[i].type);
-		printk(KERN_CONT "\n");
+		pr_cont("\n");
 	}
 }
 
@@ -419,11 +419,11 @@ __e820_update_range(struct e820_table *table, u64 start, u64 size, unsigned old_
 		size = ULLONG_MAX - start;
 
 	end = start + size;
-	printk(KERN_DEBUG "e820: update [mem %#010Lx-%#010Lx] ", start, end - 1);
+	pr_debug("e820: update [mem %#010Lx-%#010Lx] ", start, end - 1);
 	e820_print_type(old_type);
-	printk(KERN_CONT " ==> ");
+	pr_cont(" ==> ");
 	e820_print_type(new_type);
-	printk(KERN_CONT "\n");
+	pr_cont("\n");
 
 	for (i = 0; i < table->nr_entries; i++) {
 		struct e820_entry *entry = &table->entries[i];
@@ -495,10 +495,10 @@ u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type, int checkty
 		size = ULLONG_MAX - start;
 
 	end = start + size;
-	printk(KERN_DEBUG "e820: remove [mem %#010Lx-%#010Lx] ", start, end - 1);
+	pr_debug("e820: remove [mem %#010Lx-%#010Lx] ", start, end - 1);
 	if (checktype)
 		e820_print_type(old_type);
-	printk(KERN_CONT "\n");
+	pr_cont("\n");
 
 	for (i = 0; i < e820_table->nr_entries; i++) {
 		struct e820_entry *entry = &e820_table->entries[i];
@@ -551,7 +551,7 @@ void __init update_e820(void)
 	if (sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries))
 		return;
 
-	printk(KERN_INFO "e820: modified physical RAM map:\n");
+	pr_info("e820: modified physical RAM map:\n");
 	e820_print_map("modified");
 }
 
@@ -613,7 +613,7 @@ __init void e820_setup_gap(void)
 	if (!found) {
 #ifdef CONFIG_X86_64
 		gapstart = (max_pfn << PAGE_SHIFT) + 1024*1024;
-		printk(KERN_ERR
+		pr_err(
 			"e820: Cannot find an available gap in the 32-bit address range\n"
 			"e820: PCI devices with unassigned 32-bit BARs may not work!\n");
 #else
@@ -626,7 +626,7 @@ __init void e820_setup_gap(void)
 	 */
 	pci_mem_start = gapstart;
 
-	printk(KERN_INFO "e820: [mem %#010lx-%#010lx] available for PCI devices\n", gapstart, gapstart + gapsize - 1);
+	pr_info("e820: [mem %#010lx-%#010lx] available for PCI devices\n", gapstart, gapstart + gapsize - 1);
 }
 
 /*
@@ -679,7 +679,7 @@ void __init parse_e820_ext(u64 phys_addr, u32 data_len)
 	sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 
 	early_memunmap(sdata, data_len);
-	printk(KERN_INFO "e820: extended physical RAM map:\n");
+	pr_info("e820: extended physical RAM map:\n");
 	e820_print_map("extended");
 }
 
@@ -743,7 +743,7 @@ u64 __init early_reserve_e820(u64 size, u64 align)
 	addr = __memblock_alloc_base(size, align, MEMBLOCK_ALLOC_ACCESSIBLE);
 	if (addr) {
 		e820_update_range_firmware(addr, size, E820_RAM, E820_RESERVED);
-		printk(KERN_INFO "e820: update e820_table_firmware for early_reserve_e820\n");
+		pr_info("e820: update e820_table_firmware for early_reserve_e820\n");
 		update_e820_table_firmware();
 	}
 
@@ -793,7 +793,7 @@ static unsigned long __init e820_end_pfn(unsigned long limit_pfn, unsigned type)
 	if (last_pfn > max_arch_pfn)
 		last_pfn = max_arch_pfn;
 
-	printk(KERN_INFO "e820: last_pfn = %#lx max_arch_pfn = %#lx\n",
+	pr_info("e820: last_pfn = %#lx max_arch_pfn = %#lx\n",
 			 last_pfn, max_arch_pfn);
 	return last_pfn;
 }
@@ -829,7 +829,7 @@ static int __init parse_memopt(char *p)
 		setup_clear_cpu_cap(X86_FEATURE_PSE);
 		return 0;
 #else
-		printk(KERN_WARNING "mem=nopentium ignored! (only supported on x86_32)\n");
+		pr_warn("mem=nopentium ignored! (only supported on x86_32)\n");
 		return -EINVAL;
 #endif
 	}
@@ -916,7 +916,7 @@ void __init finish_e820_parsing(void)
 		if (sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries) < 0)
 			early_panic("Invalid user supplied memory map");
 
-		printk(KERN_INFO "e820: user-defined physical RAM map:\n");
+		pr_info("e820: user-defined physical RAM map:\n");
 		e820_print_map("user");
 	}
 }
@@ -1078,7 +1078,7 @@ void __init e820_reserve_resources_late(void)
 		if (start >= end)
 			continue;
 
-		printk(KERN_DEBUG "e820: reserve RAM buffer [mem %#010llx-%#010llx]\n", start, end);
+		pr_debug("e820: reserve RAM buffer [mem %#010llx-%#010llx]\n", start, end);
 		reserve_region_with_split(&iomem_resource, start, end, "RAM buffer");
 	}
 }
@@ -1134,7 +1134,7 @@ void __init e820__memory_setup(void)
 
 	memcpy(e820_table_firmware, e820_table, sizeof(struct e820_table));
 
-	printk(KERN_INFO "e820: BIOS-provided physical RAM map:\n");
+	pr_info("e820: BIOS-provided physical RAM map:\n");
 	e820_print_map(who);
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 23/50] x86/boot/e820: Move the memblock_find_dma_reserve() function and rename it to memblock_set_dma_reserve()
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (21 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 22/50] x86/boot/e820: Convert printk(KERN_* ...) to pr_*() Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 24/50] x86/boot/e820: Rename parse_e820_ext() to e820__memory_setup_extended() Ingo Molnar
                   ` (26 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

We introduced memblock_find_dma_reserve() in this commit:

   6f2a75369e75 x86, memblock: Use memblock_memory_size()/memblock_free_memory_size() to get correct dma_reserve

But there's several problems with it:

 - The changelog is full of typos and is incomprehensible in general, and
   the comments in the code are not much better either.

 - The function was inexplicably placed into e820.c, while it has very
   little connection to the E820 table: when we call
   memblock_find_dma_reserve() then memblock is already set up and we
   are not using the E820 table anymore.

 - The function is a wrapper around set_dma_reserve(), but changed the 'set'
   name to 'find' - actively misleading about its primary purpose, which is
   still to set the DMA-reserve value.

 - The function is limited to 64-bit systems, but neither the changelog nor
   the comments explain why. The change would appear to be relevant to
   32-bit systems as well, as the ISA DMA zone is the first 16 MB of RAM.

So address some of these problems:

 - Move it into arch/x86/mm/init.c, next to the other zone setup related
   functions.

 - Clean up the code flow and names of local variables a bit.

 - Rename it to memblock_set_dma_reserve()

 - Improve the comments.

No change in functionality. Enabling it for 32-bit systems is left
for a separate patch.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h |  1 -
 arch/x86/include/asm/pgtable.h  |  1 +
 arch/x86/kernel/e820.c          | 31 -------------------------------
 arch/x86/mm/init.c              | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 48 insertions(+), 32 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 01698548fbc8..7c9e4bb84059 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -22,7 +22,6 @@ extern unsigned long e820_end_of_ram_pfn(void);
 extern unsigned long e820_end_of_low_ram_pfn(void);
 extern u64  early_reserve_e820(u64 sizet, u64 align);
 extern void e820__memblock_setup(void);
-extern void memblock_find_dma_reserve(void);
 extern void finish_e820_parsing(void);
 extern void e820_reserve_resources(void);
 extern void e820_reserve_resources_late(void);
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index ffaefb24891c..2d8116136f3e 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -733,6 +733,7 @@ static inline int pgd_none(pgd_t pgd)
 extern int direct_gbpages;
 void init_mem_mapping(void);
 void early_alloc_pgt_buf(void);
+extern void memblock_find_dma_reserve(void);
 
 #ifdef CONFIG_X86_64
 /* Realmode trampoline initialization. */
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 4a8d905226c9..5f8ba898e29d 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -1172,34 +1172,3 @@ void __init e820__memblock_setup(void)
 
 	memblock_dump_all();
 }
-
-void __init memblock_find_dma_reserve(void)
-{
-#ifdef CONFIG_X86_64
-	u64 nr_pages = 0, nr_free_pages = 0;
-	unsigned long start_pfn, end_pfn;
-	phys_addr_t start, end;
-	int i;
-	u64 u;
-
-	/*
-	 * need to find out used area below MAX_DMA_PFN
-	 * need to use memblock to get free size in [0, MAX_DMA_PFN]
-	 * at first, and assume boot_mem will not take below MAX_DMA_PFN
-	 */
-	for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, NULL) {
-		start_pfn = min(start_pfn, MAX_DMA_PFN);
-		end_pfn = min(end_pfn, MAX_DMA_PFN);
-		nr_pages += end_pfn - start_pfn;
-	}
-
-	for_each_free_mem_range(u, NUMA_NO_NODE, MEMBLOCK_NONE, &start, &end, NULL) {
-		start_pfn = min_t(unsigned long, PFN_UP(start), MAX_DMA_PFN);
-		end_pfn = min_t(unsigned long, PFN_DOWN(end), MAX_DMA_PFN);
-		if (start_pfn < end_pfn)
-			nr_free_pages += end_pfn - start_pfn;
-	}
-
-	set_dma_reserve(nr_pages - nr_free_pages);
-#endif
-}
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index b7b4ad569d13..922671d3af85 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -724,6 +724,53 @@ void __init free_initrd_mem(unsigned long start, unsigned long end)
 }
 #endif
 
+/*
+ * Calculate the precise size of the DMA zone (first 16 MB of RAM),
+ * and pass it to the MM layer - to help it set zone watermarks more
+ * accurately.
+ *
+ * Done on 64-bit systems only for the time being, although 32-bit systems
+ * might benefit from this as well.
+ */
+void __init memblock_find_dma_reserve(void)
+{
+#ifdef CONFIG_X86_64
+	u64 nr_pages = 0, nr_free_pages = 0;
+	unsigned long start_pfn, end_pfn;
+	phys_addr_t start_addr, end_addr;
+	int i;
+	u64 u;
+
+	/*
+	 * Iterate over all memory ranges (free and reserved ones alike),
+	 * to calculate the total number of pages in the first 16 MB of RAM:
+	 */
+	nr_pages = 0;
+	for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, NULL) {
+		start_pfn = min(start_pfn, MAX_DMA_PFN);
+		end_pfn   = min(end_pfn,   MAX_DMA_PFN);
+
+		nr_pages += end_pfn - start_pfn;
+	}
+
+	/*
+	 * Iterate over free memory ranges to calculate the number of free
+	 * pages in the DMA zone, while not counting potential partial
+	 * pages at the beginning or the end of the range:
+	 */
+	nr_free_pages = 0;
+	for_each_free_mem_range(u, NUMA_NO_NODE, MEMBLOCK_NONE, &start_addr, &end_addr, NULL) {
+		start_pfn = min_t(unsigned long, PFN_UP(start_addr), MAX_DMA_PFN);
+		end_pfn   = min_t(unsigned long, PFN_DOWN(end_addr), MAX_DMA_PFN);
+
+		if (start_pfn < end_pfn)
+			nr_free_pages += end_pfn - start_pfn;
+	}
+
+	set_dma_reserve(nr_pages - nr_free_pages);
+#endif
+}
+
 void __init zone_sizes_init(void)
 {
 	unsigned long max_zone_pfns[MAX_NR_ZONES];
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 24/50] x86/boot/e820: Rename parse_e820_ext() to e820__memory_setup_extended()
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (22 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 23/50] x86/boot/e820: Move the memblock_find_dma_reserve() function and rename it to memblock_set_dma_reserve() Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 25/50] x86/boot/e820: Move e820_reserve_setup_data() to e820.c Ingo Molnar
                   ` (25 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

parse_e820_ext() is very similar to e820__memory_setup_default(), both are
taking bootloader provided data, add it to the E820 table and then
pass it sanitize_e820_table().

Rename it to e820__memory_setup_extended() to better signal their similar role.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h | 2 +-
 arch/x86/kernel/e820.c          | 2 +-
 arch/x86/kernel/setup.c         | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 7c9e4bb84059..8c9c6054dec1 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -17,7 +17,7 @@ extern u64  e820_update_range(u64 start, u64 size, unsigned old_type, unsigned n
 extern u64  e820_remove_range(u64 start, u64 size, unsigned old_type, int checktype);
 extern void update_e820(void);
 extern void e820_setup_gap(void);
-extern void parse_e820_ext(u64 phys_addr, u32 data_len);
+extern void e820__memory_setup_extended(u64 phys_addr, u32 data_len);
 extern unsigned long e820_end_of_ram_pfn(void);
 extern unsigned long e820_end_of_low_ram_pfn(void);
 extern u64  early_reserve_e820(u64 sizet, u64 align);
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 5f8ba898e29d..d24c0f2b4a1c 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -665,7 +665,7 @@ __init void e820_reallocate_tables(void)
  * the remaining (if any) entries are passed via the SETUP_E820_EXT node of
  * struct setup_data, which is parsed here.
  */
-void __init parse_e820_ext(u64 phys_addr, u32 data_len)
+void __init e820__memory_setup_extended(u64 phys_addr, u32 data_len)
 {
 	int entries;
 	struct e820_entry *extmap;
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 838e4b5707ae..4451c3a818db 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -426,7 +426,7 @@ static void __init parse_setup_data(void)
 
 		switch (data_type) {
 		case SETUP_E820_EXT:
-			parse_e820_ext(pa_data, data_len);
+			e820__memory_setup_extended(pa_data, data_len);
 			break;
 		case SETUP_DTB:
 			add_dtb(pa_data);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 25/50] x86/boot/e820: Move e820_reserve_setup_data() to e820.c
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (23 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 24/50] x86/boot/e820: Rename parse_e820_ext() to e820__memory_setup_extended() Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 26/50] x86/boot/e820: Clarify the role of finish_e820_parsing() and rename it to e820__finish_early_params() Ingo Molnar
                   ` (24 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

The e820_reserve_setup_data() is local to arch/x86/kernel/setup.c,
but it is E820 functionality - so move it to e820.c to better
isolate E820 functionality.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h |  1 +
 arch/x86/kernel/e820.c          | 22 ++++++++++++++++++++++
 arch/x86/kernel/setup.c         | 23 -----------------------
 3 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 8c9c6054dec1..23019a696fcd 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -22,6 +22,7 @@ extern unsigned long e820_end_of_ram_pfn(void);
 extern unsigned long e820_end_of_low_ram_pfn(void);
 extern u64  early_reserve_e820(u64 sizet, u64 align);
 extern void e820__memblock_setup(void);
+extern void e820_reserve_setup_data(void);
 extern void finish_e820_parsing(void);
 extern void e820_reserve_resources(void);
 extern void e820_reserve_resources_late(void);
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index d24c0f2b4a1c..79b9401bbbea 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -910,6 +910,28 @@ static int __init parse_memmap_opt(char *str)
 }
 early_param("memmap", parse_memmap_opt);
 
+void __init e820_reserve_setup_data(void)
+{
+	struct setup_data *data;
+	u64 pa_data;
+
+	pa_data = boot_params.hdr.setup_data;
+	if (!pa_data)
+		return;
+
+	while (pa_data) {
+		data = early_memremap(pa_data, sizeof(*data));
+		e820_update_range(pa_data, sizeof(*data)+data->len, E820_RAM, E820_RESERVED_KERN);
+		pa_data = data->next;
+		early_memunmap(data, sizeof(*data));
+	}
+
+	sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
+	memcpy(e820_table_firmware, e820_table, sizeof(struct e820_table));
+	printk(KERN_INFO "extended physical RAM map:\n");
+	e820_print_map("reserve setup_data");
+}
+
 void __init finish_e820_parsing(void)
 {
 	if (userdef) {
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 4451c3a818db..7954159f0d27 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -441,29 +441,6 @@ static void __init parse_setup_data(void)
 	}
 }
 
-static void __init e820_reserve_setup_data(void)
-{
-	struct setup_data *data;
-	u64 pa_data;
-
-	pa_data = boot_params.hdr.setup_data;
-	if (!pa_data)
-		return;
-
-	while (pa_data) {
-		data = early_memremap(pa_data, sizeof(*data));
-		e820_update_range(pa_data, sizeof(*data)+data->len,
-			 E820_RAM, E820_RESERVED_KERN);
-		pa_data = data->next;
-		early_memunmap(data, sizeof(*data));
-	}
-
-	sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
-	memcpy(e820_table_firmware, e820_table, sizeof(struct e820_table));
-	printk(KERN_INFO "extended physical RAM map:\n");
-	e820_print_map("reserve setup_data");
-}
-
 static void __init memblock_x86_reserve_range_setup_data(void)
 {
 	struct setup_data *data;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 26/50] x86/boot/e820: Clarify the role of finish_e820_parsing() and rename it to e820__finish_early_params()
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (24 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 25/50] x86/boot/e820: Move e820_reserve_setup_data() to e820.c Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 27/50] x86/boot/e820: Rename early_reserve_e820() to e820__memblock_alloc() and document it Ingo Molnar
                   ` (23 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

finish_e820_parsing() is closely related to parse_early_params(), but the
name does not tell us this clearly, so rename it to e820__finish_early_params().

Also add a few comments to explain what the function does.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h | 2 +-
 arch/x86/kernel/e820.c          | 7 ++++++-
 arch/x86/kernel/setup.c         | 2 +-
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 23019a696fcd..0162581b0cae 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -23,7 +23,7 @@ extern unsigned long e820_end_of_low_ram_pfn(void);
 extern u64  early_reserve_e820(u64 sizet, u64 align);
 extern void e820__memblock_setup(void);
 extern void e820_reserve_setup_data(void);
-extern void finish_e820_parsing(void);
+extern void e820__finish_early_params(void);
 extern void e820_reserve_resources(void);
 extern void e820_reserve_resources_late(void);
 extern void e820__memory_setup(void);
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 79b9401bbbea..904ddb1343f2 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -932,7 +932,12 @@ void __init e820_reserve_setup_data(void)
 	e820_print_map("reserve setup_data");
 }
 
-void __init finish_e820_parsing(void)
+/*
+ * Called after parse_early_param(), after early parameters (such as mem=)
+ * have been processed, in which case we already have an E820 table filled in
+ * via the parameter callback function(s), but it's not sorted and printed yet:
+ */
+void __init e820__finish_early_params(void)
 {
 	if (userdef) {
 		if (sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries) < 0)
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 7954159f0d27..a121e01d8a4d 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1005,7 +1005,7 @@ void __init setup_arch(char **cmdline_p)
 
 	/* update the e820_table_firmware too */
 	e820_reserve_setup_data();
-	finish_e820_parsing();
+	e820__finish_early_params();
 
 	if (efi_enabled(EFI_BOOT))
 		efi_init();
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 27/50] x86/boot/e820: Rename early_reserve_e820() to e820__memblock_alloc() and document it
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (25 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 26/50] x86/boot/e820: Clarify the role of finish_e820_parsing() and rename it to e820__finish_early_params() Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 28/50] x86/boot/e820: Rename update_e820() to e820__update_table() Ingo Molnar
                   ` (22 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

early_reserve_e820() is an early hack for kexec that does a limited fixup of the
mptable and passes it to the kexec kernel as if it was the real thing.

For this it needs to allocate memory - but no memory allocator is available yet
beyond the memblock allocator, so early_reserve_e820() is really a wrapper
around memblock_alloc() plus a hack to update the e820_table_firmware entries.

The name 'reserve' is really a bit of a misnomer, as 'reserved' memory typically
means memory completely inaccessible to the kernel - while here what we want to do
is a special RAM allocation for our own purposes and insert that as RAM_RESERVED.

Rename the function to e820__memblock_alloc_reserved() to better signal this dual
purpose, plus document it better, which was omitted when it was merged. The barely
comprehensible and cryptic comment:

  /*
   * pre allocated 4k and reserved it in memblock and e820_table_firmware
   */
  u64 __init e820__memblock_alloc_reserved(u64 size, u64 align)

... does not count as documentation, replace it with:

  /*
   * Allocate the requested number of bytes with the requsted alignment
   * and return (the physical address) to the caller. Also register this
   * range in the 'firmware' E820 table.
   *
   * This allows kexec to fake a new mptable, as if it came from the real
   * system.
   */
  u64 __init e820__memblock_alloc_reserved(u64 size, u64 align)

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h |  2 +-
 arch/x86/include/asm/mpspec.h   |  4 ++--
 arch/x86/kernel/e820.c          | 11 ++++++++---
 arch/x86/kernel/mpparse.c       |  4 ++--
 arch/x86/kernel/setup.c         |  2 +-
 5 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 0162581b0cae..3fdc0612d762 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -20,7 +20,7 @@ extern void e820_setup_gap(void);
 extern void e820__memory_setup_extended(u64 phys_addr, u32 data_len);
 extern unsigned long e820_end_of_ram_pfn(void);
 extern unsigned long e820_end_of_low_ram_pfn(void);
-extern u64  early_reserve_e820(u64 sizet, u64 align);
+extern u64  e820__memblock_alloc_reserved(u64 sizet, u64 align);
 extern void e820__memblock_setup(void);
 extern void e820_reserve_setup_data(void);
 extern void e820__finish_early_params(void);
diff --git a/arch/x86/include/asm/mpspec.h b/arch/x86/include/asm/mpspec.h
index 32007041ef8c..831eb7895535 100644
--- a/arch/x86/include/asm/mpspec.h
+++ b/arch/x86/include/asm/mpspec.h
@@ -64,7 +64,7 @@ static inline void find_smp_config(void)
 }
 
 #ifdef CONFIG_X86_MPPARSE
-extern void early_reserve_e820_mpc_new(void);
+extern void e820__memblock_alloc_reserved_mpc_new(void);
 extern int enable_update_mptable;
 extern int default_mpc_apic_id(struct mpc_cpu *m);
 extern void default_smp_read_mpc_oem(struct mpc_table *mpc);
@@ -76,7 +76,7 @@ extern void default_mpc_oem_bus_info(struct mpc_bus *m, char *str);
 extern void default_find_smp_config(void);
 extern void default_get_smp_config(unsigned int early);
 #else
-static inline void early_reserve_e820_mpc_new(void) { }
+static inline void e820__memblock_alloc_reserved_mpc_new(void) { }
 #define enable_update_mptable 0
 #define default_mpc_apic_id NULL
 #define default_smp_read_mpc_oem NULL
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 904ddb1343f2..93b5e3e5a3f0 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -734,16 +734,21 @@ core_initcall(e820_mark_nvs_memory);
 #endif
 
 /*
- * pre allocated 4k and reserved it in memblock and e820_table_firmware
+ * Allocate the requested number of bytes with the requsted alignment
+ * and return (the physical address) to the caller. Also register this
+ * range in the 'firmware' E820 table as a reserved range.
+ *
+ * This allows kexec to fake a new mptable, as if it came from the real
+ * system.
  */
-u64 __init early_reserve_e820(u64 size, u64 align)
+u64 __init e820__memblock_alloc_reserved(u64 size, u64 align)
 {
 	u64 addr;
 
 	addr = __memblock_alloc_base(size, align, MEMBLOCK_ALLOC_ACCESSIBLE);
 	if (addr) {
 		e820_update_range_firmware(addr, size, E820_RAM, E820_RESERVED);
-		pr_info("e820: update e820_table_firmware for early_reserve_e820\n");
+		pr_info("e820: update e820_table_firmware for e820__memblock_alloc_reserved()\n");
 		update_e820_table_firmware();
 	}
 
diff --git a/arch/x86/kernel/mpparse.c b/arch/x86/kernel/mpparse.c
index 1e3320788510..0d904d759ff1 100644
--- a/arch/x86/kernel/mpparse.c
+++ b/arch/x86/kernel/mpparse.c
@@ -826,10 +826,10 @@ static int __init parse_alloc_mptable_opt(char *p)
 }
 early_param("alloc_mptable", parse_alloc_mptable_opt);
 
-void __init early_reserve_e820_mpc_new(void)
+void __init e820__memblock_alloc_reserved_mpc_new(void)
 {
 	if (enable_update_mptable && alloc_mptable)
-		mpc_new_phys = early_reserve_e820(mpc_new_length, 4);
+		mpc_new_phys = e820__memblock_alloc_reserved(mpc_new_length, 4);
 }
 
 static int __init update_mp_table(void)
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index a121e01d8a4d..a31c5bc99635 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1112,7 +1112,7 @@ void __init setup_arch(char **cmdline_p)
 	}
 
 	/* preallocate 4k for mptable mpc */
-	early_reserve_e820_mpc_new();
+	e820__memblock_alloc_reserved_mpc_new();
 
 #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION
 	setup_bios_corruption_check();
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 28/50] x86/boot/e820: Rename update_e820() to e820__update_table()
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (26 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 27/50] x86/boot/e820: Rename early_reserve_e820() to e820__memblock_alloc() and document it Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 29/50] x86/boot/e820: Rename sanitize_e820_table() " Ingo Molnar
                   ` (21 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

update_e820() should have 'e820' as a prefix as most of the other E820
functions have - but it's also a bit unclear about its purpose, as
it's unclear what is updated - the whole table, or an entry?

Also, the name does not express that it's a trivial wrapper
around sanitize_e820_table() that also prints out the resulting
table.

So rename it to e820__update_table_print(). This also makes it
harmonize with the e820__update_table_firmware() function which
has a very similar purpose.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h    | 2 +-
 arch/x86/kernel/acpi/boot.c        | 2 +-
 arch/x86/kernel/aperture_64.c      | 2 +-
 arch/x86/kernel/cpu/mtrr/cleanup.c | 2 +-
 arch/x86/kernel/e820.c             | 6 +++---
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 3fdc0612d762..6dc8570b5553 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -15,7 +15,7 @@ extern void e820_print_map(char *who);
 extern int  sanitize_e820_table(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map);
 extern u64  e820_update_range(u64 start, u64 size, unsigned old_type, unsigned new_type);
 extern u64  e820_remove_range(u64 start, u64 size, unsigned old_type, int checktype);
-extern void update_e820(void);
+extern void e820__update_table_print(void);
 extern void e820_setup_gap(void);
 extern void e820__memory_setup_extended(u64 phys_addr, u32 data_len);
 extern unsigned long e820_end_of_ram_pfn(void);
diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
index 8048c76a4458..8590f4891760 100644
--- a/arch/x86/kernel/acpi/boot.c
+++ b/arch/x86/kernel/acpi/boot.c
@@ -1716,5 +1716,5 @@ int __acpi_release_global_lock(unsigned int *lock)
 void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size)
 {
 	e820_add_region(addr, size, E820_ACPI);
-	update_e820();
+	e820__update_table_print();
 }
diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
index d8185a31933b..e21d012c557b 100644
--- a/arch/x86/kernel/aperture_64.c
+++ b/arch/x86/kernel/aperture_64.c
@@ -312,7 +312,7 @@ void __init early_gart_iommu_check(void)
 			pr_info("e820: reserve [mem %#010Lx-%#010Lx] for GART\n",
 				aper_base, aper_base + aper_size - 1);
 			e820_add_region(aper_base, aper_size, E820_RESERVED);
-			update_e820();
+			e820__update_table_print();
 		}
 	}
 
diff --git a/arch/x86/kernel/cpu/mtrr/cleanup.c b/arch/x86/kernel/cpu/mtrr/cleanup.c
index f1a7365e14b0..e201401a7ced 100644
--- a/arch/x86/kernel/cpu/mtrr/cleanup.c
+++ b/arch/x86/kernel/cpu/mtrr/cleanup.c
@@ -978,7 +978,7 @@ int __init mtrr_trim_uncached_memory(unsigned long end_pfn)
 			WARN_ON(1);
 
 		pr_info("update e820 for mtrr\n");
-		update_e820();
+		e820__update_table_print();
 
 		return 1;
 	}
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 93b5e3e5a3f0..03af13c3c431 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -546,7 +546,7 @@ u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type, int checkty
 	return real_removed_size;
 }
 
-void __init update_e820(void)
+void __init e820__update_table_print(void)
 {
 	if (sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries))
 		return;
@@ -555,7 +555,7 @@ void __init update_e820(void)
 	e820_print_map("modified");
 }
 
-static void __init update_e820_table_firmware(void)
+static void __init e820__update_table_firmware(void)
 {
 	sanitize_e820_table(e820_table_firmware->entries, ARRAY_SIZE(e820_table_firmware->entries), &e820_table_firmware->nr_entries);
 }
@@ -749,7 +749,7 @@ u64 __init e820__memblock_alloc_reserved(u64 size, u64 align)
 	if (addr) {
 		e820_update_range_firmware(addr, size, E820_RAM, E820_RESERVED);
 		pr_info("e820: update e820_table_firmware for e820__memblock_alloc_reserved()\n");
-		update_e820_table_firmware();
+		e820__update_table_firmware();
 	}
 
 	return addr;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 29/50] x86/boot/e820: Rename sanitize_e820_table() to e820__update_table()
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (27 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 28/50] x86/boot/e820: Rename update_e820() to e820__update_table() Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 30/50] x86/boot/e820: Rename e820_any_mapped()/e820_all_mapped() to e820__mapped_any()/e820__mapped_all() Ingo Molnar
                   ` (20 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

sanitize_e820_table() is a minor misnomer in that it suggests that
the E820 table requires sanitizing - which implies that it will only
do anything if the E820 table is irregular (not sane).

That is wrong, because sanitize_e820_table() also does a very regular
sorting of the E820 table, which is a necessity in the basic
append-only flow of E820 updates the kernel is allowed to perform to
it.

So rename it to e820__update_table() to include that purpose as well.

This also lines up all the table-update functions into a coherent
naming family:

  int  e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map);

  void e820__update_table_print(void);
  void e820__update_table_firmware(void);

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h   |  2 +-
 arch/x86/include/asm/e820/types.h |  2 +-
 arch/x86/kernel/e820.c            | 16 ++++++++--------
 arch/x86/kernel/early-quirks.c    |  2 +-
 arch/x86/kernel/setup.c           |  4 ++--
 arch/x86/platform/efi/efi.c       |  2 +-
 arch/x86/xen/setup.c              |  6 +++---
 7 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 6dc8570b5553..9f3917805fc6 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -12,7 +12,7 @@ extern int  e820_any_mapped(u64 start, u64 end, unsigned type);
 extern int  e820_all_mapped(u64 start, u64 end, unsigned type);
 extern void e820_add_region(u64 start, u64 size, int type);
 extern void e820_print_map(char *who);
-extern int  sanitize_e820_table(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map);
+extern int  e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map);
 extern u64  e820_update_range(u64 start, u64 size, unsigned old_type, unsigned new_type);
 extern u64  e820_remove_range(u64 start, u64 size, unsigned old_type, int checktype);
 extern void e820__update_table_print(void);
diff --git a/arch/x86/include/asm/e820/types.h b/arch/x86/include/asm/e820/types.h
index e9d811afc123..da9477d78214 100644
--- a/arch/x86/include/asm/e820/types.h
+++ b/arch/x86/include/asm/e820/types.h
@@ -21,7 +21,7 @@
  *
  * 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_table() to remove duplicates.  The allowance
+ * call to e820__update_table() 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
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 03af13c3c431..0053c9f1f6e2 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -193,7 +193,7 @@ void __init e820_print_map(char *who)
  * sanitizing succeeds the *pnr_map will be updated with the new
  * number of valid entries (something no more than max_nr_map).
  *
- * The return value from sanitize_e820_table() is zero if it
+ * The return value from e820__update_table() is zero if it
  * successfully 'sanitized' the map entries passed in, and is -1
  * if it did nothing, which can happen if either of (1) it was
  * only passed one map entry, or (2) any of the input map entries
@@ -259,7 +259,7 @@ static int __init cpcompare(const void *a, const void *b)
 	return (ap->addr != ap->pbios->addr) - (bp->addr != bp->pbios->addr);
 }
 
-int __init sanitize_e820_table(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map)
+int __init e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map)
 {
 	static struct change_member change_point_list[2*E820_X_MAX] __initdata;
 	static struct change_member *change_point[2*E820_X_MAX] __initdata;
@@ -548,7 +548,7 @@ u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type, int checkty
 
 void __init e820__update_table_print(void)
 {
-	if (sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries))
+	if (e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries))
 		return;
 
 	pr_info("e820: modified physical RAM map:\n");
@@ -557,7 +557,7 @@ void __init e820__update_table_print(void)
 
 static void __init e820__update_table_firmware(void)
 {
-	sanitize_e820_table(e820_table_firmware->entries, ARRAY_SIZE(e820_table_firmware->entries), &e820_table_firmware->nr_entries);
+	e820__update_table(e820_table_firmware->entries, ARRAY_SIZE(e820_table_firmware->entries), &e820_table_firmware->nr_entries);
 }
 
 #define MAX_GAP_END 0x100000000ull
@@ -676,7 +676,7 @@ void __init e820__memory_setup_extended(u64 phys_addr, u32 data_len)
 	extmap = (struct e820_entry *)(sdata->data);
 
 	__append_e820_table(extmap, entries);
-	sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
+	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 
 	early_memunmap(sdata, data_len);
 	pr_info("e820: extended physical RAM map:\n");
@@ -931,7 +931,7 @@ void __init e820_reserve_setup_data(void)
 		early_memunmap(data, sizeof(*data));
 	}
 
-	sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
+	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 	memcpy(e820_table_firmware, e820_table, sizeof(struct e820_table));
 	printk(KERN_INFO "extended physical RAM map:\n");
 	e820_print_map("reserve setup_data");
@@ -945,7 +945,7 @@ void __init e820_reserve_setup_data(void)
 void __init e820__finish_early_params(void)
 {
 	if (userdef) {
-		if (sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries) < 0)
+		if (e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries) < 0)
 			early_panic("Invalid user supplied memory map");
 
 		pr_info("e820: user-defined physical RAM map:\n");
@@ -1130,7 +1130,7 @@ char *__init e820__memory_setup_default(void)
 	 * the next section from 1mb->appropriate_mem_k
 	 */
 	new_nr = boot_params.e820_entries;
-	sanitize_e820_table(boot_params.e820_table, ARRAY_SIZE(boot_params.e820_table), &new_nr);
+	e820__update_table(boot_params.e820_table, ARRAY_SIZE(boot_params.e820_table), &new_nr);
 	boot_params.e820_entries = new_nr;
 
 	if (append_e820_table(boot_params.e820_table, boot_params.e820_entries) < 0) {
diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c
index 4f52758accbc..66722f447401 100644
--- a/arch/x86/kernel/early-quirks.c
+++ b/arch/x86/kernel/early-quirks.c
@@ -547,7 +547,7 @@ intel_graphics_stolen(int num, int slot, int func,
 
 	/* Mark this space as reserved */
 	e820_add_region(base, size, E820_RESERVED);
-	sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
+	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 }
 
 static void __init intel_graphics_quirks(int num, int slot, int func)
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index a31c5bc99635..e8ec0c693a77 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -740,7 +740,7 @@ static void __init trim_bios_range(void)
 	 */
 	e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
 
-	sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
+	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 }
 
 /* called before trim_bios_range() to spare extra sanitize */
@@ -1033,7 +1033,7 @@ void __init setup_arch(char **cmdline_p)
 	if (ppro_with_ram_bug()) {
 		e820_update_range(0x70000000ULL, 0x40000ULL, E820_RAM,
 				  E820_RESERVED);
-		sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
+		e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 		printk(KERN_INFO "fixed physical RAM map:\n");
 		e820_print_map("bad_ppro");
 	}
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index b69199165610..3a8f11ef6bfe 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -167,7 +167,7 @@ static void __init do_add_efi_memmap(void)
 		}
 		e820_add_region(start, size, e820_type);
 	}
-	sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
+	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 }
 
 int __init efi_memblock_x86_reserve_range(void)
diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
index 8b26b9282070..c2f8e4ab55bd 100644
--- a/arch/x86/xen/setup.c
+++ b/arch/x86/xen/setup.c
@@ -783,7 +783,7 @@ char * __init xen_memory_setup(void)
 		xen_ignore_unusable();
 
 	/* Make sure the Xen-supplied memory map is well-ordered. */
-	sanitize_e820_table(xen_e820_table, ARRAY_SIZE(xen_e820_table),
+	e820__update_table(xen_e820_table, ARRAY_SIZE(xen_e820_table),
 			  &xen_e820_table_entries);
 
 	max_pages = xen_get_max_pages();
@@ -861,7 +861,7 @@ char * __init xen_memory_setup(void)
 	e820_add_region(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS,
 			E820_RESERVED);
 
-	sanitize_e820_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
+	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 
 	/*
 	 * Check whether the kernel itself conflicts with the target E820 map.
@@ -932,7 +932,7 @@ char * __init xen_auto_xlated_memory_setup(void)
 
 	xen_e820_table_entries = memmap.nr_entries;
 
-	sanitize_e820_table(xen_e820_table, ARRAY_SIZE(xen_e820_table),
+	e820__update_table(xen_e820_table, ARRAY_SIZE(xen_e820_table),
 			  &xen_e820_table_entries);
 
 	for (i = 0; i < xen_e820_table_entries; i++)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 30/50] x86/boot/e820: Rename e820_any_mapped()/e820_all_mapped() to e820__mapped_any()/e820__mapped_all()
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (28 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 29/50] x86/boot/e820: Rename sanitize_e820_table() " Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 31/50] x86/boot/e820: Rename e820_setup_gap() to e820__setup_pci_gap() Ingo Molnar
                   ` (19 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

The 'any' and 'all' are modified to the 'mapped' concept, so move them last in the name.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h |  4 ++--
 arch/x86/include/asm/gart.h     |  2 +-
 arch/x86/kernel/aperture_64.c   |  2 +-
 arch/x86/kernel/e820.c          |  6 +++---
 arch/x86/kernel/setup.c         |  2 +-
 arch/x86/kernel/tboot.c         |  2 +-
 arch/x86/mm/init_64.c           | 12 ++++++------
 arch/x86/pci/mmconfig-shared.c  |  4 ++--
 arch/x86/platform/efi/quirks.c  |  2 +-
 9 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 9f3917805fc6..3ba95d462bbc 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -8,8 +8,8 @@ extern struct e820_table *e820_table_firmware;
 
 extern unsigned long pci_mem_start;
 
-extern int  e820_any_mapped(u64 start, u64 end, unsigned type);
-extern int  e820_all_mapped(u64 start, u64 end, unsigned type);
+extern int  e820__mapped_any(u64 start, u64 end, unsigned type);
+extern int  e820__mapped_all(u64 start, u64 end, unsigned type);
 extern void e820_add_region(u64 start, u64 size, int type);
 extern void e820_print_map(char *who);
 extern int  e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map);
diff --git a/arch/x86/include/asm/gart.h b/arch/x86/include/asm/gart.h
index e26a5d7fc368..2a3ff2ac4686 100644
--- a/arch/x86/include/asm/gart.h
+++ b/arch/x86/include/asm/gart.h
@@ -97,7 +97,7 @@ static inline int aperture_valid(u64 aper_base, u32 aper_size, u32 min_size)
 		printk(KERN_INFO "Aperture beyond 4GB. Ignoring.\n");
 		return 0;
 	}
-	if (e820_any_mapped(aper_base, aper_base + aper_size, E820_RAM)) {
+	if (e820__mapped_any(aper_base, aper_base + aper_size, E820_RAM)) {
 		printk(KERN_INFO "Aperture pointing to e820 RAM. Ignoring.\n");
 		return 0;
 	}
diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
index e21d012c557b..d027858a306e 100644
--- a/arch/x86/kernel/aperture_64.c
+++ b/arch/x86/kernel/aperture_64.c
@@ -306,7 +306,7 @@ void __init early_gart_iommu_check(void)
 		fix = 1;
 
 	if (gart_fix_e820 && !fix && aper_enabled) {
-		if (e820_any_mapped(aper_base, aper_base + aper_size,
+		if (e820__mapped_any(aper_base, aper_base + aper_size,
 				    E820_RAM)) {
 			/* reserve it, so we can reuse it in second kernel */
 			pr_info("e820: reserve [mem %#010Lx-%#010Lx] for GART\n",
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 0053c9f1f6e2..804acee76aca 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -68,7 +68,7 @@ EXPORT_SYMBOL(pci_mem_start);
  * This function checks if any part of the range <start,end> is mapped
  * with type.
  */
-int e820_any_mapped(u64 start, u64 end, unsigned type)
+int e820__mapped_any(u64 start, u64 end, unsigned type)
 {
 	int i;
 
@@ -83,7 +83,7 @@ int e820_any_mapped(u64 start, u64 end, unsigned type)
 	}
 	return 0;
 }
-EXPORT_SYMBOL_GPL(e820_any_mapped);
+EXPORT_SYMBOL_GPL(e820__mapped_any);
 
 /*
  * This function checks if the entire <start,end> range is mapped with 'type'.
@@ -91,7 +91,7 @@ EXPORT_SYMBOL_GPL(e820_any_mapped);
  * Note: this function only works correctly once the E820 table is sorted and
  * not-overlapping (at least for the range specified), which is the case normally.
  */
-int __init e820_all_mapped(u64 start, u64 end, unsigned type)
+int __init e820__mapped_all(u64 start, u64 end, unsigned type)
 {
 	int i;
 
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index e8ec0c693a77..5ea90a2b3709 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -756,7 +756,7 @@ static void __init e820_add_kernel_range(void)
 	 * exclude kernel range. If we really are running on top non-RAM,
 	 * we will crash later anyways.
 	 */
-	if (e820_all_mapped(start, start + size, E820_RAM))
+	if (e820__mapped_all(start, start + size, E820_RAM))
 		return;
 
 	pr_warn(".text .data .bss are not marked as E820_RAM!\n");
diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
index f7cba42d7807..0e2dc3831970 100644
--- a/arch/x86/kernel/tboot.c
+++ b/arch/x86/kernel/tboot.c
@@ -68,7 +68,7 @@ void __init tboot_probe(void)
 	 * also verify that it is mapped as we expect it before calling
 	 * set_fixmap(), to reduce chance of garbage value causing crash
 	 */
-	if (!e820_any_mapped(boot_params.tboot_addr,
+	if (!e820__mapped_any(boot_params.tboot_addr,
 			     boot_params.tboot_addr, E820_RESERVED)) {
 		pr_warning("non-0 tboot_addr but it is not of type E820_RESERVED\n");
 		return;
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index ad7a477f3423..cfb119e4c4d1 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -337,9 +337,9 @@ phys_pte_init(pte_t *pte_page, unsigned long paddr, unsigned long paddr_end,
 		paddr_next = (paddr & PAGE_MASK) + PAGE_SIZE;
 		if (paddr >= paddr_end) {
 			if (!after_bootmem &&
-			    !e820_any_mapped(paddr & PAGE_MASK, paddr_next,
+			    !e820__mapped_any(paddr & PAGE_MASK, paddr_next,
 					     E820_RAM) &&
-			    !e820_any_mapped(paddr & PAGE_MASK, paddr_next,
+			    !e820__mapped_any(paddr & PAGE_MASK, paddr_next,
 					     E820_RESERVED_KERN))
 				set_pte(pte, __pte(0));
 			continue;
@@ -392,9 +392,9 @@ phys_pmd_init(pmd_t *pmd_page, unsigned long paddr, unsigned long paddr_end,
 		paddr_next = (paddr & PMD_MASK) + PMD_SIZE;
 		if (paddr >= paddr_end) {
 			if (!after_bootmem &&
-			    !e820_any_mapped(paddr & PMD_MASK, paddr_next,
+			    !e820__mapped_any(paddr & PMD_MASK, paddr_next,
 					     E820_RAM) &&
-			    !e820_any_mapped(paddr & PMD_MASK, paddr_next,
+			    !e820__mapped_any(paddr & PMD_MASK, paddr_next,
 					     E820_RESERVED_KERN))
 				set_pmd(pmd, __pmd(0));
 			continue;
@@ -478,9 +478,9 @@ phys_pud_init(pud_t *pud_page, unsigned long paddr, unsigned long paddr_end,
 
 		if (paddr >= paddr_end) {
 			if (!after_bootmem &&
-			    !e820_any_mapped(paddr & PUD_MASK, paddr_next,
+			    !e820__mapped_any(paddr & PUD_MASK, paddr_next,
 					     E820_RAM) &&
-			    !e820_any_mapped(paddr & PUD_MASK, paddr_next,
+			    !e820__mapped_any(paddr & PUD_MASK, paddr_next,
 					     E820_RESERVED_KERN))
 				set_pud(pud, __pud(0));
 			continue;
diff --git a/arch/x86/pci/mmconfig-shared.c b/arch/x86/pci/mmconfig-shared.c
index 767199edef74..696b050bdc45 100644
--- a/arch/x86/pci/mmconfig-shared.c
+++ b/arch/x86/pci/mmconfig-shared.c
@@ -514,7 +514,7 @@ static int __ref pci_mmcfg_check_reserved(struct device *dev,
 	}
 
 	/*
-	 * e820_all_mapped() is marked as __init.
+	 * e820__mapped_all() is marked as __init.
 	 * All entries from ACPI MCFG table have been checked at boot time.
 	 * For MCFG information constructed from hotpluggable host bridge's
 	 * _CBA method, just assume it's reserved.
@@ -525,7 +525,7 @@ static int __ref pci_mmcfg_check_reserved(struct device *dev,
 	/* Don't try to do this check unless configuration
 	   type 1 is available. how about type 2 ?*/
 	if (raw_pci_ops)
-		return is_mmconf_reserved(e820_all_mapped, cfg, dev, 1);
+		return is_mmconf_reserved(e820__mapped_all, cfg, dev, 1);
 
 	return 0;
 }
diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
index c6a14b11f496..d4acd1668d36 100644
--- a/arch/x86/platform/efi/quirks.c
+++ b/arch/x86/platform/efi/quirks.c
@@ -249,7 +249,7 @@ static bool can_free_region(u64 start, u64 size)
 	if (start + size > __pa_symbol(_text) && start <= __pa_symbol(_end))
 		return false;
 
-	if (!e820_all_mapped(start, start+size, E820_RAM))
+	if (!e820__mapped_all(start, start+size, E820_RAM))
 		return false;
 
 	return true;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 31/50] x86/boot/e820: Rename e820_setup_gap() to e820__setup_pci_gap()
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (29 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 30/50] x86/boot/e820: Rename e820_any_mapped()/e820_all_mapped() to e820__mapped_any()/e820__mapped_all() Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 32/50] x86/boot/e820: Create coherent API function names for E820 range operations Ingo Molnar
                   ` (18 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

The e820_setup_gap() function name is unnecessarily silent about what
kind of gap it sets up. Make it clear that it's about the PCI gap.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h | 2 +-
 arch/x86/kernel/e820.c          | 2 +-
 arch/x86/kernel/setup.c         | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 3ba95d462bbc..d4374ba26472 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -16,7 +16,7 @@ extern int  e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *
 extern u64  e820_update_range(u64 start, u64 size, unsigned old_type, unsigned new_type);
 extern u64  e820_remove_range(u64 start, u64 size, unsigned old_type, int checktype);
 extern void e820__update_table_print(void);
-extern void e820_setup_gap(void);
+extern void e820__setup_pci_gap(void);
 extern void e820__memory_setup_extended(u64 phys_addr, u32 data_len);
 extern unsigned long e820_end_of_ram_pfn(void);
 extern unsigned long e820_end_of_low_ram_pfn(void);
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 804acee76aca..cb25c7248656 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -602,7 +602,7 @@ static int __init e820_search_gap(unsigned long *gapstart, unsigned long *gapsiz
  *
  * Hopefully the BIOS let enough space left.
  */
-__init void e820_setup_gap(void)
+__init void e820__setup_pci_gap(void)
 {
 	unsigned long gapstart, gapsize;
 	int found;
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 5ea90a2b3709..0fd7c0ef2716 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1241,7 +1241,7 @@ void __init setup_arch(char **cmdline_p)
 
 	x86_init.resources.reserve_resources();
 
-	e820_setup_gap();
+	e820__setup_pci_gap();
 
 #ifdef CONFIG_VT
 #if defined(CONFIG_VGA_CONSOLE)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 32/50] x86/boot/e820: Create coherent API function names for E820 range operations
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (30 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 31/50] x86/boot/e820: Rename e820_setup_gap() to e820__setup_pci_gap() Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 33/50] x86/boot/e820: Rename e820_print_map() to e820__print_table() Ingo Molnar
                   ` (17 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

We have these three related functions:

 extern void e820_add_region(u64 start, u64 size, int type);
 extern u64  e820_update_range(u64 start, u64 size, unsigned old_type, unsigned new_type);
 extern u64  e820_remove_range(u64 start, u64 size, unsigned old_type, int checktype);

But it's not clear from the naming that they are 3 operations based around the
same 'memory range' concept. Rename them to better signal this, and move
the prototypes next to each other:

 extern void e820__range_add   (u64 start, u64 size, int type);
 extern u64  e820__range_update(u64 start, u64 size, unsigned old_type, unsigned new_type);
 extern u64  e820__range_remove(u64 start, u64 size, unsigned old_type, int checktype);

Note that this improved organization of the functions shows another problem that was easy
to miss before: sometimes the E820 entry type is 'int', sometimes 'unsigned int' - but this
will be fixed in a separate patch.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h    |  8 +++++---
 arch/x86/kernel/acpi/boot.c        |  2 +-
 arch/x86/kernel/aperture_64.c      |  2 +-
 arch/x86/kernel/cpu/mtrr/cleanup.c |  2 +-
 arch/x86/kernel/e820.c             | 48 ++++++++++++++++++++++++------------------------
 arch/x86/kernel/early-quirks.c     |  2 +-
 arch/x86/kernel/setup.c            | 10 +++++-----
 arch/x86/lguest/boot.c             |  2 +-
 arch/x86/platform/efi/efi.c        |  2 +-
 arch/x86/xen/setup.c               |  6 +++---
 drivers/acpi/tables.c              |  2 +-
 11 files changed, 44 insertions(+), 42 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index d4374ba26472..1c3615825115 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -10,11 +10,13 @@ extern unsigned long pci_mem_start;
 
 extern int  e820__mapped_any(u64 start, u64 end, unsigned type);
 extern int  e820__mapped_all(u64 start, u64 end, unsigned type);
-extern void e820_add_region(u64 start, u64 size, int type);
+
+extern void e820__range_add   (u64 start, u64 size, int type);
+extern u64  e820__range_update(u64 start, u64 size, unsigned old_type, unsigned new_type);
+extern u64  e820__range_remove(u64 start, u64 size, unsigned old_type, int checktype);
+
 extern void e820_print_map(char *who);
 extern int  e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map);
-extern u64  e820_update_range(u64 start, u64 size, unsigned old_type, unsigned new_type);
-extern u64  e820_remove_range(u64 start, u64 size, unsigned old_type, int checktype);
 extern void e820__update_table_print(void);
 extern void e820__setup_pci_gap(void);
 extern void e820__memory_setup_extended(u64 phys_addr, u32 data_len);
diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
index 8590f4891760..31b350c6a3b1 100644
--- a/arch/x86/kernel/acpi/boot.c
+++ b/arch/x86/kernel/acpi/boot.c
@@ -1715,6 +1715,6 @@ int __acpi_release_global_lock(unsigned int *lock)
 
 void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size)
 {
-	e820_add_region(addr, size, E820_ACPI);
+	e820__range_add(addr, size, E820_ACPI);
 	e820__update_table_print();
 }
diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
index d027858a306e..883485684435 100644
--- a/arch/x86/kernel/aperture_64.c
+++ b/arch/x86/kernel/aperture_64.c
@@ -311,7 +311,7 @@ void __init early_gart_iommu_check(void)
 			/* reserve it, so we can reuse it in second kernel */
 			pr_info("e820: reserve [mem %#010Lx-%#010Lx] for GART\n",
 				aper_base, aper_base + aper_size - 1);
-			e820_add_region(aper_base, aper_size, E820_RESERVED);
+			e820__range_add(aper_base, aper_size, E820_RESERVED);
 			e820__update_table_print();
 		}
 	}
diff --git a/arch/x86/kernel/cpu/mtrr/cleanup.c b/arch/x86/kernel/cpu/mtrr/cleanup.c
index e201401a7ced..244aaa988ecd 100644
--- a/arch/x86/kernel/cpu/mtrr/cleanup.c
+++ b/arch/x86/kernel/cpu/mtrr/cleanup.c
@@ -860,7 +860,7 @@ real_trim_memory(unsigned long start_pfn, unsigned long limit_pfn)
 	trim_size <<= PAGE_SHIFT;
 	trim_size -= trim_start;
 
-	return e820_update_range(trim_start, trim_size, E820_RAM, E820_RESERVED);
+	return e820__range_update(trim_start, trim_size, E820_RAM, E820_RESERVED);
 }
 
 /**
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index cb25c7248656..f91901ab9263 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -125,7 +125,7 @@ int __init e820__mapped_all(u64 start, u64 end, unsigned type)
 /*
  * Add a memory region to the kernel E820 map.
  */
-static void __init __e820_add_region(struct e820_table *table, u64 start, u64 size, int type)
+static void __init __e820__range_add(struct e820_table *table, u64 start, u64 size, int type)
 {
 	int x = table->nr_entries;
 
@@ -140,9 +140,9 @@ static void __init __e820_add_region(struct e820_table *table, u64 start, u64 si
 	table->nr_entries++;
 }
 
-void __init e820_add_region(u64 start, u64 size, int type)
+void __init e820__range_add(u64 start, u64 size, int type)
 {
-	__e820_add_region(e820_table, start, size, type);
+	__e820__range_add(e820_table, start, size, type);
 }
 
 static void __init e820_print_type(u32 type)
@@ -380,7 +380,7 @@ static int __init __append_e820_table(struct e820_entry *biosmap, int nr_map)
 		if (start > end && likely(size))
 			return -1;
 
-		e820_add_region(start, size, type);
+		e820__range_add(start, size, type);
 
 		biosmap++;
 		nr_map--;
@@ -407,7 +407,7 @@ static int __init append_e820_table(struct e820_entry *biosmap, int nr_map)
 }
 
 static u64 __init
-__e820_update_range(struct e820_table *table, u64 start, u64 size, unsigned old_type, unsigned new_type)
+__e820__range_update(struct e820_table *table, u64 start, u64 size, unsigned old_type, unsigned new_type)
 {
 	u64 end;
 	unsigned int i;
@@ -444,8 +444,8 @@ __e820_update_range(struct e820_table *table, u64 start, u64 size, unsigned old_
 
 		/* New range is completely covered? */
 		if (entry->addr < start && entry_end > end) {
-			__e820_add_region(table, start, size, new_type);
-			__e820_add_region(table, end, entry_end - end, entry->type);
+			__e820__range_add(table, start, size, new_type);
+			__e820__range_add(table, end, entry_end - end, entry->type);
 			entry->size = start - entry->addr;
 			real_updated_size += size;
 			continue;
@@ -457,7 +457,7 @@ __e820_update_range(struct e820_table *table, u64 start, u64 size, unsigned old_
 		if (final_start >= final_end)
 			continue;
 
-		__e820_add_region(table, final_start, final_end - final_start, new_type);
+		__e820__range_add(table, final_start, final_end - final_start, new_type);
 
 		real_updated_size += final_end - final_start;
 
@@ -474,18 +474,18 @@ __e820_update_range(struct e820_table *table, u64 start, u64 size, unsigned old_
 	return real_updated_size;
 }
 
-u64 __init e820_update_range(u64 start, u64 size, unsigned old_type, unsigned new_type)
+u64 __init e820__range_update(u64 start, u64 size, unsigned old_type, unsigned new_type)
 {
-	return __e820_update_range(e820_table, start, size, old_type, new_type);
+	return __e820__range_update(e820_table, start, size, old_type, new_type);
 }
 
-static u64 __init e820_update_range_firmware(u64 start, u64 size, unsigned old_type, unsigned new_type)
+static u64 __init e820__range_update_firmware(u64 start, u64 size, unsigned old_type, unsigned new_type)
 {
-	return __e820_update_range(e820_table_firmware, start, size, old_type, new_type);
+	return __e820__range_update(e820_table_firmware, start, size, old_type, new_type);
 }
 
 /* Remove a range of memory from the E820 table: */
-u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type, int checktype)
+u64 __init e820__range_remove(u64 start, u64 size, unsigned old_type, int checktype)
 {
 	int i;
 	u64 end;
@@ -519,7 +519,7 @@ u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type, int checkty
 
 		/* Is the new range completely covered? */
 		if (entry->addr < start && entry_end > end) {
-			e820_add_region(end, entry_end - end, entry->type);
+			e820__range_add(end, entry_end - end, entry->type);
 			entry->size = start - entry->addr;
 			real_removed_size += size;
 			continue;
@@ -747,7 +747,7 @@ u64 __init e820__memblock_alloc_reserved(u64 size, u64 align)
 
 	addr = __memblock_alloc_base(size, align, MEMBLOCK_ALLOC_ACCESSIBLE);
 	if (addr) {
-		e820_update_range_firmware(addr, size, E820_RAM, E820_RESERVED);
+		e820__range_update_firmware(addr, size, E820_RAM, E820_RESERVED);
 		pr_info("e820: update e820_table_firmware for e820__memblock_alloc_reserved()\n");
 		e820__update_table_firmware();
 	}
@@ -846,7 +846,7 @@ static int __init parse_memopt(char *p)
 	if (mem_size == 0)
 		return -EINVAL;
 
-	e820_remove_range(mem_size, ULLONG_MAX - mem_size, E820_RAM, 1);
+	e820__range_remove(mem_size, ULLONG_MAX - mem_size, E820_RAM, 1);
 
 	return 0;
 }
@@ -882,18 +882,18 @@ static int __init parse_memmap_one(char *p)
 	userdef = 1;
 	if (*p == '@') {
 		start_at = memparse(p+1, &p);
-		e820_add_region(start_at, mem_size, E820_RAM);
+		e820__range_add(start_at, mem_size, E820_RAM);
 	} else if (*p == '#') {
 		start_at = memparse(p+1, &p);
-		e820_add_region(start_at, mem_size, E820_ACPI);
+		e820__range_add(start_at, mem_size, E820_ACPI);
 	} else if (*p == '$') {
 		start_at = memparse(p+1, &p);
-		e820_add_region(start_at, mem_size, E820_RESERVED);
+		e820__range_add(start_at, mem_size, E820_RESERVED);
 	} else if (*p == '!') {
 		start_at = memparse(p+1, &p);
-		e820_add_region(start_at, mem_size, E820_PRAM);
+		e820__range_add(start_at, mem_size, E820_PRAM);
 	} else {
-		e820_remove_range(mem_size, ULLONG_MAX - mem_size, E820_RAM, 1);
+		e820__range_remove(mem_size, ULLONG_MAX - mem_size, E820_RAM, 1);
 	}
 
 	return *p == '\0' ? 0 : -EINVAL;
@@ -926,7 +926,7 @@ void __init e820_reserve_setup_data(void)
 
 	while (pa_data) {
 		data = early_memremap(pa_data, sizeof(*data));
-		e820_update_range(pa_data, sizeof(*data)+data->len, E820_RAM, E820_RESERVED_KERN);
+		e820__range_update(pa_data, sizeof(*data)+data->len, E820_RAM, E820_RESERVED_KERN);
 		pa_data = data->next;
 		early_memunmap(data, sizeof(*data));
 	}
@@ -1146,8 +1146,8 @@ char *__init e820__memory_setup_default(void)
 		}
 
 		e820_table->nr_entries = 0;
-		e820_add_region(0, LOWMEMSIZE(), E820_RAM);
-		e820_add_region(HIGH_MEMORY, mem_size << 10, E820_RAM);
+		e820__range_add(0, LOWMEMSIZE(), E820_RAM);
+		e820__range_add(HIGH_MEMORY, mem_size << 10, E820_RAM);
 	}
 
 	return who;
diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c
index 66722f447401..81a10ab15be9 100644
--- a/arch/x86/kernel/early-quirks.c
+++ b/arch/x86/kernel/early-quirks.c
@@ -546,7 +546,7 @@ intel_graphics_stolen(int num, int slot, int func,
 	       &base, &end);
 
 	/* Mark this space as reserved */
-	e820_add_region(base, size, E820_RESERVED);
+	e820__range_add(base, size, E820_RESERVED);
 	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 }
 
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 0fd7c0ef2716..2449df3c0044 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -731,14 +731,14 @@ static void __init trim_bios_range(void)
 	 * since some BIOSes are known to corrupt low memory.  See the
 	 * Kconfig help text for X86_RESERVE_LOW.
 	 */
-	e820_update_range(0, PAGE_SIZE, E820_RAM, E820_RESERVED);
+	e820__range_update(0, PAGE_SIZE, E820_RAM, E820_RESERVED);
 
 	/*
 	 * special case: Some BIOSen report the PC BIOS
 	 * area (640->1Mb) as ram even though it is not.
 	 * take them out.
 	 */
-	e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
+	e820__range_remove(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
 
 	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 }
@@ -760,8 +760,8 @@ static void __init e820_add_kernel_range(void)
 		return;
 
 	pr_warn(".text .data .bss are not marked as E820_RAM!\n");
-	e820_remove_range(start, size, E820_RAM, 0);
-	e820_add_region(start, size, E820_RAM);
+	e820__range_remove(start, size, E820_RAM, 0);
+	e820__range_add(start, size, E820_RAM);
 }
 
 static unsigned reserve_low = CONFIG_X86_RESERVE_LOW << 10;
@@ -1031,7 +1031,7 @@ void __init setup_arch(char **cmdline_p)
 	trim_bios_range();
 #ifdef CONFIG_X86_32
 	if (ppro_with_ram_bug()) {
-		e820_update_range(0x70000000ULL, 0x40000ULL, E820_RAM,
+		e820__range_update(0x70000000ULL, 0x40000ULL, E820_RAM,
 				  E820_RESERVED);
 		e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 		printk(KERN_INFO "fixed physical RAM map:\n");
diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
index fc42e9604562..7aa633686295 100644
--- a/arch/x86/lguest/boot.c
+++ b/arch/x86/lguest/boot.c
@@ -1178,7 +1178,7 @@ static __init char *lguest_memory_setup(void)
 	 * The Linux bootloader header contains an "e820" memory map: the
 	 * Launcher populated the first entry with our memory limit.
 	 */
-	e820_add_region(boot_params.e820_table[0].addr,
+	e820__range_add(boot_params.e820_table[0].addr,
 			  boot_params.e820_table[0].size,
 			  boot_params.e820_table[0].type);
 
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index 3a8f11ef6bfe..d97c05ee9664 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -165,7 +165,7 @@ static void __init do_add_efi_memmap(void)
 			e820_type = E820_RESERVED;
 			break;
 		}
-		e820_add_region(start, size, e820_type);
+		e820__range_add(start, size, e820_type);
 	}
 	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 }
diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
index c2f8e4ab55bd..a634723e660f 100644
--- a/arch/x86/xen/setup.c
+++ b/arch/x86/xen/setup.c
@@ -596,7 +596,7 @@ static void __init xen_align_and_add_e820_region(phys_addr_t start,
 		end &= ~((phys_addr_t)PAGE_SIZE - 1);
 	}
 
-	e820_add_region(start, end - start, type);
+	e820__range_add(start, end - start, type);
 }
 
 static void __init xen_ignore_unusable(void)
@@ -858,7 +858,7 @@ char * __init xen_memory_setup(void)
 	 * reserve ISA memory anyway because too many things poke
 	 * about in there.
 	 */
-	e820_add_region(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS,
+	e820__range_add(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS,
 			E820_RESERVED);
 
 	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
@@ -936,7 +936,7 @@ char * __init xen_auto_xlated_memory_setup(void)
 			  &xen_e820_table_entries);
 
 	for (i = 0; i < xen_e820_table_entries; i++)
-		e820_add_region(xen_e820_table[i].addr, xen_e820_table[i].size,
+		e820__range_add(xen_e820_table[i].addr, xen_e820_table[i].size,
 				xen_e820_table[i].type);
 
 	/* Remove p2m info, it is not needed. */
diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
index 2604189d6cd1..9b9ac04593fb 100644
--- a/drivers/acpi/tables.c
+++ b/drivers/acpi/tables.c
@@ -556,7 +556,7 @@ void __init acpi_table_upgrade(void)
 	 * But it's not enough on X86 because ioremap will
 	 * complain later (used by acpi_os_map_memory) that the pages
 	 * that should get mapped are not marked "reserved".
-	 * Both memblock_reserve and e820_add_region (via arch_reserve_mem_area)
+	 * Both memblock_reserve and e820__range_add (via arch_reserve_mem_area)
 	 * works fine.
 	 */
 	memblock_reserve(acpi_tables_addr, all_tables_size);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 33/50] x86/boot/e820: Rename e820_print_map() to e820__print_table()
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (31 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 32/50] x86/boot/e820: Create coherent API function names for E820 range operations Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 34/50] x86/boot/e820: Reorder the function prototypes in api.h Ingo Molnar
                   ` (16 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

All other table-level methods are already named 'table' in some way,
to change this one over to the (now consistent) nomenclature.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h |  2 +-
 arch/x86/kernel/e820.c          | 12 ++++++------
 arch/x86/kernel/setup.c         |  2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 1c3615825115..d4a944884219 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -15,7 +15,7 @@ extern void e820__range_add   (u64 start, u64 size, int type);
 extern u64  e820__range_update(u64 start, u64 size, unsigned old_type, unsigned new_type);
 extern u64  e820__range_remove(u64 start, u64 size, unsigned old_type, int checktype);
 
-extern void e820_print_map(char *who);
+extern void e820__print_table(char *who);
 extern int  e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map);
 extern void e820__update_table_print(void);
 extern void e820__setup_pci_gap(void);
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index f91901ab9263..cdf224992c27 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -160,7 +160,7 @@ static void __init e820_print_type(u32 type)
 	}
 }
 
-void __init e820_print_map(char *who)
+void __init e820__print_table(char *who)
 {
 	int i;
 
@@ -552,7 +552,7 @@ void __init e820__update_table_print(void)
 		return;
 
 	pr_info("e820: modified physical RAM map:\n");
-	e820_print_map("modified");
+	e820__print_table("modified");
 }
 
 static void __init e820__update_table_firmware(void)
@@ -680,7 +680,7 @@ void __init e820__memory_setup_extended(u64 phys_addr, u32 data_len)
 
 	early_memunmap(sdata, data_len);
 	pr_info("e820: extended physical RAM map:\n");
-	e820_print_map("extended");
+	e820__print_table("extended");
 }
 
 /**
@@ -934,7 +934,7 @@ void __init e820_reserve_setup_data(void)
 	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 	memcpy(e820_table_firmware, e820_table, sizeof(struct e820_table));
 	printk(KERN_INFO "extended physical RAM map:\n");
-	e820_print_map("reserve setup_data");
+	e820__print_table("reserve setup_data");
 }
 
 /*
@@ -949,7 +949,7 @@ void __init e820__finish_early_params(void)
 			early_panic("Invalid user supplied memory map");
 
 		pr_info("e820: user-defined physical RAM map:\n");
-		e820_print_map("user");
+		e820__print_table("user");
 	}
 }
 
@@ -1167,7 +1167,7 @@ void __init e820__memory_setup(void)
 	memcpy(e820_table_firmware, e820_table, sizeof(struct e820_table));
 
 	pr_info("e820: BIOS-provided physical RAM map:\n");
-	e820_print_map(who);
+	e820__print_table(who);
 }
 
 void __init e820__memblock_setup(void)
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 2449df3c0044..0e70a7bbeeef 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1035,7 +1035,7 @@ void __init setup_arch(char **cmdline_p)
 				  E820_RESERVED);
 		e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 		printk(KERN_INFO "fixed physical RAM map:\n");
-		e820_print_map("bad_ppro");
+		e820__print_table("bad_ppro");
 	}
 #else
 	early_gart_iommu_check();
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 34/50] x86/boot/e820: Reorder the function prototypes in api.h
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (32 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 33/50] x86/boot/e820: Rename e820_print_map() to e820__print_table() Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 35/50] x86/boot/e820: Simplify e820_reserve_resources() Ingo Molnar
                   ` (15 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

Reorder the function prototypes in api.h a bit, to group related functions together.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index d4a944884219..465c32c9a0dc 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -18,18 +18,23 @@ extern u64  e820__range_remove(u64 start, u64 size, unsigned old_type, int check
 extern void e820__print_table(char *who);
 extern int  e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map);
 extern void e820__update_table_print(void);
-extern void e820__setup_pci_gap(void);
-extern void e820__memory_setup_extended(u64 phys_addr, u32 data_len);
+
 extern unsigned long e820_end_of_ram_pfn(void);
 extern unsigned long e820_end_of_low_ram_pfn(void);
+
 extern u64  e820__memblock_alloc_reserved(u64 sizet, u64 align);
 extern void e820__memblock_setup(void);
+
 extern void e820_reserve_setup_data(void);
 extern void e820__finish_early_params(void);
 extern void e820_reserve_resources(void);
 extern void e820_reserve_resources_late(void);
+
 extern void e820__memory_setup(void);
+extern void e820__memory_setup_extended(u64 phys_addr, u32 data_len);
 extern char *e820__memory_setup_default(void);
+extern void e820__setup_pci_gap(void);
+
 extern void e820_reallocate_tables(void);
 extern void e820_mark_nosave_regions(unsigned long limit_pfn);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 35/50] x86/boot/e820: Simplify e820_reserve_resources()
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (33 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 34/50] x86/boot/e820: Reorder the function prototypes in api.h Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 36/50] x86/boot/e820: Introduce 'enum e820_type' Ingo Molnar
                   ` (14 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

Remove unnecessary duplications of "e820_table->entries[i]." via a local
variable, plus pass in 'entry' to the type_to_*() functions which further
improves the readability of the code - and other small tweaks.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/e820.c | 36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index cdf224992c27..511402d88795 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -953,9 +953,9 @@ void __init e820__finish_early_params(void)
 	}
 }
 
-static const char *__init e820_type_to_string(int e820_type)
+static const char *__init e820_type_to_string(struct e820_entry *entry)
 {
-	switch (e820_type) {
+	switch (entry->type) {
 	case E820_RESERVED_KERN: /* Fall-through: */
 	case E820_RAM:		 return "System RAM";
 	case E820_ACPI:		 return "ACPI Tables";
@@ -967,9 +967,9 @@ static const char *__init e820_type_to_string(int e820_type)
 	}
 }
 
-static unsigned long __init e820_type_to_iomem_type(int e820_type)
+static unsigned long __init e820_type_to_iomem_type(struct e820_entry *entry)
 {
-	switch (e820_type) {
+	switch (entry->type) {
 	case E820_RESERVED_KERN: /* Fall-through: */
 	case E820_RAM:		 return IORESOURCE_SYSTEM_RAM;
 	case E820_ACPI:		 /* Fall-through: */
@@ -981,9 +981,9 @@ static unsigned long __init e820_type_to_iomem_type(int e820_type)
 	}
 }
 
-static unsigned long __init e820_type_to_iores_desc(int e820_type)
+static unsigned long __init e820_type_to_iores_desc(struct e820_entry *entry)
 {
-	switch (e820_type) {
+	switch (entry->type) {
 	case E820_ACPI:		 return IORES_DESC_ACPI_TABLES;
 	case E820_NVS:		 return IORES_DESC_ACPI_NV_STORAGE;
 	case E820_PMEM:		 return IORES_DESC_PERSISTENT_MEMORY;
@@ -1027,27 +1027,29 @@ void __init e820_reserve_resources(void)
 	struct resource *res;
 	u64 end;
 
-	res = alloc_bootmem(sizeof(struct resource) * e820_table->nr_entries);
+	res = alloc_bootmem(sizeof(*res) * e820_table->nr_entries);
 	e820_res = res;
+
 	for (i = 0; i < e820_table->nr_entries; i++) {
-		end = e820_table->entries[i].addr + e820_table->entries[i].size - 1;
+		struct e820_entry *entry = e820_table->entries + i;
+
+		end = entry->addr + entry->size - 1;
 		if (end != (resource_size_t)end) {
 			res++;
 			continue;
 		}
-		res->name = e820_type_to_string(e820_table->entries[i].type);
-		res->start = e820_table->entries[i].addr;
-		res->end = end;
-
-		res->flags = e820_type_to_iomem_type(e820_table->entries[i].type);
-		res->desc = e820_type_to_iores_desc(e820_table->entries[i].type);
+		res->start = entry->addr;
+		res->end   = end;
+		res->name  = e820_type_to_string(entry);
+		res->flags = e820_type_to_iomem_type(entry);
+		res->desc  = e820_type_to_iores_desc(entry);
 
 		/*
 		 * don't register the region that could be conflicted with
 		 * pci device BAR resource and insert them later in
 		 * pcibios_resource_survey()
 		 */
-		if (do_mark_busy(e820_table->entries[i].type, res)) {
+		if (do_mark_busy(entry->type, res)) {
 			res->flags |= IORESOURCE_BUSY;
 			insert_resource(&iomem_resource, res);
 		}
@@ -1055,9 +1057,9 @@ void __init e820_reserve_resources(void)
 	}
 
 	for (i = 0; i < e820_table_firmware->nr_entries; i++) {
-		struct e820_entry *entry = &e820_table_firmware->entries[i];
+		struct e820_entry *entry = e820_table_firmware->entries + i;
 
-		firmware_map_add_early(entry->addr, entry->addr + entry->size, e820_type_to_string(entry->type));
+		firmware_map_add_early(entry->addr, entry->addr + entry->size, e820_type_to_string(entry));
 	}
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 36/50] x86/boot/e820: Introduce 'enum e820_type'
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (34 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 35/50] x86/boot/e820: Simplify e820_reserve_resources() Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:11 ` [PATCH 37/50] x86/boot/e820: Use 'enum e820_type' in 'struct e820_entry' Ingo Molnar
                   ` (13 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

Use an enum instead of CPP #define.

Also fix various small annoyances in the descriptions of the
various E820 types.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/types.h | 57 +++++++++++++++++++++++++++++++--------------------------
 1 file changed, 31 insertions(+), 26 deletions(-)

diff --git a/arch/x86/include/asm/e820/types.h b/arch/x86/include/asm/e820/types.h
index da9477d78214..1c3426825535 100644
--- a/arch/x86/include/asm/e820/types.h
+++ b/arch/x86/include/asm/e820/types.h
@@ -1,6 +1,37 @@
 #ifndef _ASM_E820_TYPES_H
 #define _ASM_E820_TYPES_H
 
+enum e820_type {
+	E820_RAM		= 1,
+	E820_RESERVED		= 2,
+	E820_ACPI		= 3,
+	E820_NVS		= 4,
+	E820_UNUSABLE		= 5,
+	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=y 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... )
+	 */
+	E820_PRAM		= 12,
+
+	/*
+	 * Reserved RAM used by the kernel itself if
+	 * CONFIG_INTEL_TXT=y is enabled, memory of this type
+	 * will be included in the S3 integrity calculation
+	 * and so should not include any memory that the BIOS
+	 * might alter over the S3 transition:
+	 */
+	E820_RESERVED_KERN	= 128,
+};
+
 #include <uapi/asm/e820/types.h>
 
 /*
@@ -39,32 +70,6 @@
 /* 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
-
-/*
- * 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
-
 /*
  * The whole array of E820 entries:
  */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 37/50] x86/boot/e820: Use 'enum e820_type' in 'struct e820_entry'
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (35 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 36/50] x86/boot/e820: Introduce 'enum e820_type' Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 23:07   ` Linus Torvalds
  2017-01-28 22:11 ` [PATCH 38/50] x86/boot/e820: Use 'enum e820_type' when handling the e820 region type Ingo Molnar
                   ` (12 subsequent siblings)
  49 siblings, 1 reply; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

Use a stricter type for struct e820_entry. Add a build-time check to make
sure the compiler won't ever pack the enum into a field smaller than
'int'.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/types.h      | 31 -------------------------------
 arch/x86/include/uapi/asm/e820/types.h | 37 ++++++++++++++++++++++++++++++++++---
 arch/x86/kernel/e820.c                 |  3 +++
 3 files changed, 37 insertions(+), 34 deletions(-)

diff --git a/arch/x86/include/asm/e820/types.h b/arch/x86/include/asm/e820/types.h
index 1c3426825535..eb313b62d548 100644
--- a/arch/x86/include/asm/e820/types.h
+++ b/arch/x86/include/asm/e820/types.h
@@ -1,37 +1,6 @@
 #ifndef _ASM_E820_TYPES_H
 #define _ASM_E820_TYPES_H
 
-enum e820_type {
-	E820_RAM		= 1,
-	E820_RESERVED		= 2,
-	E820_ACPI		= 3,
-	E820_NVS		= 4,
-	E820_UNUSABLE		= 5,
-	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=y 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... )
-	 */
-	E820_PRAM		= 12,
-
-	/*
-	 * Reserved RAM used by the kernel itself if
-	 * CONFIG_INTEL_TXT=y is enabled, memory of this type
-	 * will be included in the S3 integrity calculation
-	 * and so should not include any memory that the BIOS
-	 * might alter over the S3 transition:
-	 */
-	E820_RESERVED_KERN	= 128,
-};
-
 #include <uapi/asm/e820/types.h>
 
 /*
diff --git a/arch/x86/include/uapi/asm/e820/types.h b/arch/x86/include/uapi/asm/e820/types.h
index 54b812e80bac..65c7a1beab22 100644
--- a/arch/x86/include/uapi/asm/e820/types.h
+++ b/arch/x86/include/uapi/asm/e820/types.h
@@ -6,14 +6,45 @@
 
 #ifndef __ASSEMBLY__
 
+enum e820_type {
+	E820_RAM		= 1,
+	E820_RESERVED		= 2,
+	E820_ACPI		= 3,
+	E820_NVS		= 4,
+	E820_UNUSABLE		= 5,
+	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=y 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... )
+	 */
+	E820_PRAM		= 12,
+
+	/*
+	 * Reserved RAM used by the kernel itself if
+	 * CONFIG_INTEL_TXT=y is enabled, memory of this type
+	 * will be included in the S3 integrity calculation
+	 * and so should not include any memory that the BIOS
+	 * might alter over the S3 transition:
+	 */
+	E820_RESERVED_KERN	= 128,
+};
+
 /*
  * A single E820 map entry, describing a memory range of [addr...addr+size-1],
  * of 'type' memory type:
  */
 struct e820_entry {
-	__u64 addr;
-	__u64 size;
-	__u32 type;
+	__u64			addr;
+	__u64			size;
+	enum e820_type		type;
 } __attribute__((packed));
 
 #endif /* __ASSEMBLY__ */
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 511402d88795..010a289ddd9f 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -1164,6 +1164,9 @@ void __init e820__memory_setup(void)
 {
 	char *who;
 
+	/* This is a firmware interface ABI - make sure we don't break it: */
+	BUILD_BUG_ON(sizeof(struct e820_entry) != 20);
+
 	who = x86_init.resources.memory_setup();
 
 	memcpy(e820_table_firmware, e820_table, sizeof(struct e820_table));
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 38/50] x86/boot/e820: Use 'enum e820_type' when handling the e820 region type
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (36 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 37/50] x86/boot/e820: Use 'enum e820_type' in 'struct e820_entry' Ingo Molnar
@ 2017-01-28 22:11 ` Ingo Molnar
  2017-01-28 22:12 ` [PATCH 39/50] x86/boot/e820: Prefix the E820_* type names with "E820_TYPE_" Ingo Molnar
                   ` (11 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

The E820 region type is put into four different types (!) when used in function
parameters or local variables:

	unsigned type;
	int type;
	unsigned long current_type;
	u32 type;

Use 'enum e820_type' in all these cases instead.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h | 10 +++++-----
 arch/x86/kernel/e820.c          | 22 +++++++++++-----------
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 465c32c9a0dc..4c35c36c62d5 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -8,12 +8,12 @@ extern struct e820_table *e820_table_firmware;
 
 extern unsigned long pci_mem_start;
 
-extern int  e820__mapped_any(u64 start, u64 end, unsigned type);
-extern int  e820__mapped_all(u64 start, u64 end, unsigned type);
+extern int  e820__mapped_any(u64 start, u64 end, enum e820_type type);
+extern int  e820__mapped_all(u64 start, u64 end, enum e820_type type);
 
-extern void e820__range_add   (u64 start, u64 size, int type);
-extern u64  e820__range_update(u64 start, u64 size, unsigned old_type, unsigned new_type);
-extern u64  e820__range_remove(u64 start, u64 size, unsigned old_type, int checktype);
+extern void e820__range_add   (u64 start, u64 size, enum e820_type type);
+extern u64  e820__range_update(u64 start, u64 size, enum e820_type old_type, enum e820_type new_type);
+extern u64  e820__range_remove(u64 start, u64 size, enum e820_type old_type, int checktype);
 
 extern void e820__print_table(char *who);
 extern int  e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map);
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 010a289ddd9f..79673843dc42 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -68,7 +68,7 @@ EXPORT_SYMBOL(pci_mem_start);
  * This function checks if any part of the range <start,end> is mapped
  * with type.
  */
-int e820__mapped_any(u64 start, u64 end, unsigned type)
+int e820__mapped_any(u64 start, u64 end, enum e820_type type)
 {
 	int i;
 
@@ -91,7 +91,7 @@ EXPORT_SYMBOL_GPL(e820__mapped_any);
  * Note: this function only works correctly once the E820 table is sorted and
  * not-overlapping (at least for the range specified), which is the case normally.
  */
-int __init e820__mapped_all(u64 start, u64 end, unsigned type)
+int __init e820__mapped_all(u64 start, u64 end, enum e820_type type)
 {
 	int i;
 
@@ -125,7 +125,7 @@ int __init e820__mapped_all(u64 start, u64 end, unsigned type)
 /*
  * Add a memory region to the kernel E820 map.
  */
-static void __init __e820__range_add(struct e820_table *table, u64 start, u64 size, int type)
+static void __init __e820__range_add(struct e820_table *table, u64 start, u64 size, enum e820_type type)
 {
 	int x = table->nr_entries;
 
@@ -140,12 +140,12 @@ static void __init __e820__range_add(struct e820_table *table, u64 start, u64 si
 	table->nr_entries++;
 }
 
-void __init e820__range_add(u64 start, u64 size, int type)
+void __init e820__range_add(u64 start, u64 size, enum e820_type type)
 {
 	__e820__range_add(e820_table, start, size, type);
 }
 
-static void __init e820_print_type(u32 type)
+static void __init e820_print_type(enum e820_type type)
 {
 	switch (type) {
 	case E820_RAM:			/* Fall through: */
@@ -265,7 +265,7 @@ int __init e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *p
 	static struct change_member *change_point[2*E820_X_MAX] __initdata;
 	static struct e820_entry *overlap_list[E820_X_MAX] __initdata;
 	static struct e820_entry new_bios[E820_X_MAX] __initdata;
-	unsigned long current_type, last_type;
+	enum e820_type current_type, last_type;
 	unsigned long long last_addr;
 	int chgidx;
 	int overlap_entries;
@@ -407,7 +407,7 @@ static int __init append_e820_table(struct e820_entry *biosmap, int nr_map)
 }
 
 static u64 __init
-__e820__range_update(struct e820_table *table, u64 start, u64 size, unsigned old_type, unsigned new_type)
+__e820__range_update(struct e820_table *table, u64 start, u64 size, enum e820_type old_type, enum e820_type new_type)
 {
 	u64 end;
 	unsigned int i;
@@ -474,18 +474,18 @@ __e820__range_update(struct e820_table *table, u64 start, u64 size, unsigned old
 	return real_updated_size;
 }
 
-u64 __init e820__range_update(u64 start, u64 size, unsigned old_type, unsigned new_type)
+u64 __init e820__range_update(u64 start, u64 size, enum e820_type old_type, enum e820_type new_type)
 {
 	return __e820__range_update(e820_table, start, size, old_type, new_type);
 }
 
-static u64 __init e820__range_update_firmware(u64 start, u64 size, unsigned old_type, unsigned new_type)
+static u64 __init e820__range_update_firmware(u64 start, u64 size, enum e820_type old_type, enum e820_type  new_type)
 {
 	return __e820__range_update(e820_table_firmware, start, size, old_type, new_type);
 }
 
 /* Remove a range of memory from the E820 table: */
-u64 __init e820__range_remove(u64 start, u64 size, unsigned old_type, int checktype)
+u64 __init e820__range_remove(u64 start, u64 size, enum e820_type old_type, int checktype)
 {
 	int i;
 	u64 end;
@@ -768,7 +768,7 @@ u64 __init e820__memblock_alloc_reserved(u64 size, u64 align)
 /*
  * Find the highest page frame number we have available
  */
-static unsigned long __init e820_end_pfn(unsigned long limit_pfn, unsigned type)
+static unsigned long __init e820_end_pfn(unsigned long limit_pfn, enum e820_type type)
 {
 	int i;
 	unsigned long last_pfn = 0;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 39/50] x86/boot/e820: Prefix the E820_* type names with "E820_TYPE_"
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (37 preceding siblings ...)
  2017-01-28 22:11 ` [PATCH 38/50] x86/boot/e820: Use 'enum e820_type' when handling the e820 region type Ingo Molnar
@ 2017-01-28 22:12 ` Ingo Molnar
  2017-01-28 22:12 ` [PATCH 40/50] x86/boot/e820: Clean up the E820 table size define names Ingo Molnar
                   ` (10 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:12 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

So there's a number of constants that start with "E820" but which
are not types - these create a confusing mixture when seen together
with 'enum e820_type' values:

	E820MAP
	E820NR
	E820_X_MAX
	E820MAX

To better differentiate the 'enum e820_type' values prefix them
with E820_TYPE_.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/boot/compressed/eboot.c       |  12 +++----
 arch/x86/boot/compressed/kaslr.c       |   2 +-
 arch/x86/include/asm/gart.h            |   2 +-
 arch/x86/include/uapi/asm/e820/types.h |  16 ++++-----
 arch/x86/kernel/acpi/boot.c            |   2 +-
 arch/x86/kernel/aperture_64.c          |   4 +--
 arch/x86/kernel/cpu/mtrr/cleanup.c     |   2 +-
 arch/x86/kernel/crash.c                |  10 +++---
 arch/x86/kernel/e820.c                 | 104 ++++++++++++++++++++++++++---------------------------
 arch/x86/kernel/early-quirks.c         |   2 +-
 arch/x86/kernel/kexec-bzimage64.c      |   2 +-
 arch/x86/kernel/setup.c                |  20 +++++------
 arch/x86/kernel/tboot.c                |   8 ++---
 arch/x86/mm/init.c                     |   2 +-
 arch/x86/mm/init_64.c                  |  12 +++----
 arch/x86/pci/mmconfig-shared.c         |   2 +-
 arch/x86/platform/efi/efi.c            |  14 ++++----
 arch/x86/platform/efi/quirks.c         |   6 ++--
 arch/x86/xen/setup.c                   |  22 ++++++------
 tools/lguest/lguest.c                  |   2 +-
 20 files changed, 123 insertions(+), 123 deletions(-)

diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index 04c406f9aee3..4cfba2f79dfd 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -944,15 +944,15 @@ static efi_status_t setup_e820(struct boot_params *params,
 		case EFI_MEMORY_MAPPED_IO:
 		case EFI_MEMORY_MAPPED_IO_PORT_SPACE:
 		case EFI_PAL_CODE:
-			e820_type = E820_RESERVED;
+			e820_type = E820_TYPE_RESERVED;
 			break;
 
 		case EFI_UNUSABLE_MEMORY:
-			e820_type = E820_UNUSABLE;
+			e820_type = E820_TYPE_UNUSABLE;
 			break;
 
 		case EFI_ACPI_RECLAIM_MEMORY:
-			e820_type = E820_ACPI;
+			e820_type = E820_TYPE_ACPI;
 			break;
 
 		case EFI_LOADER_CODE:
@@ -960,15 +960,15 @@ static efi_status_t setup_e820(struct boot_params *params,
 		case EFI_BOOT_SERVICES_CODE:
 		case EFI_BOOT_SERVICES_DATA:
 		case EFI_CONVENTIONAL_MEMORY:
-			e820_type = E820_RAM;
+			e820_type = E820_TYPE_RAM;
 			break;
 
 		case EFI_ACPI_MEMORY_NVS:
-			e820_type = E820_NVS;
+			e820_type = E820_TYPE_NVS;
 			break;
 
 		case EFI_PERSISTENT_MEMORY:
-			e820_type = E820_PMEM;
+			e820_type = E820_TYPE_PMEM;
 			break;
 
 		default:
diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index a47f832664f2..e8155eab5474 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -435,7 +435,7 @@ static void process_e820_entry(struct e820_entry *entry,
 	unsigned long start_orig;
 
 	/* Skip non-RAM entries. */
-	if (entry->type != E820_RAM)
+	if (entry->type != E820_TYPE_RAM)
 		return;
 
 	/* On 32-bit, ignore entries entirely above our maximum. */
diff --git a/arch/x86/include/asm/gart.h b/arch/x86/include/asm/gart.h
index 2a3ff2ac4686..1d268098ac2e 100644
--- a/arch/x86/include/asm/gart.h
+++ b/arch/x86/include/asm/gart.h
@@ -97,7 +97,7 @@ static inline int aperture_valid(u64 aper_base, u32 aper_size, u32 min_size)
 		printk(KERN_INFO "Aperture beyond 4GB. Ignoring.\n");
 		return 0;
 	}
-	if (e820__mapped_any(aper_base, aper_base + aper_size, E820_RAM)) {
+	if (e820__mapped_any(aper_base, aper_base + aper_size, E820_TYPE_RAM)) {
 		printk(KERN_INFO "Aperture pointing to e820 RAM. Ignoring.\n");
 		return 0;
 	}
diff --git a/arch/x86/include/uapi/asm/e820/types.h b/arch/x86/include/uapi/asm/e820/types.h
index 65c7a1beab22..29391386b63f 100644
--- a/arch/x86/include/uapi/asm/e820/types.h
+++ b/arch/x86/include/uapi/asm/e820/types.h
@@ -7,12 +7,12 @@
 #ifndef __ASSEMBLY__
 
 enum e820_type {
-	E820_RAM		= 1,
-	E820_RESERVED		= 2,
-	E820_ACPI		= 3,
-	E820_NVS		= 4,
-	E820_UNUSABLE		= 5,
-	E820_PMEM		= 7,
+	E820_TYPE_RAM		= 1,
+	E820_TYPE_RESERVED	= 2,
+	E820_TYPE_ACPI		= 3,
+	E820_TYPE_NVS		= 4,
+	E820_TYPE_UNUSABLE	= 5,
+	E820_TYPE_PMEM		= 7,
 
 	/*
 	 * This is a non-standardized way to represent ADR or
@@ -25,7 +25,7 @@ enum e820_type {
 	 *   type of memory, but newer versions switched to 12 as
 	 *   6 was assigned differently. Some time they will learn... )
 	 */
-	E820_PRAM		= 12,
+	E820_TYPE_PRAM		= 12,
 
 	/*
 	 * Reserved RAM used by the kernel itself if
@@ -34,7 +34,7 @@ enum e820_type {
 	 * and so should not include any memory that the BIOS
 	 * might alter over the S3 transition:
 	 */
-	E820_RESERVED_KERN	= 128,
+	E820_TYPE_RESERVED_KERN	= 128,
 };
 
 /*
diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
index 31b350c6a3b1..873552718270 100644
--- a/arch/x86/kernel/acpi/boot.c
+++ b/arch/x86/kernel/acpi/boot.c
@@ -1715,6 +1715,6 @@ int __acpi_release_global_lock(unsigned int *lock)
 
 void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size)
 {
-	e820__range_add(addr, size, E820_ACPI);
+	e820__range_add(addr, size, E820_TYPE_ACPI);
 	e820__update_table_print();
 }
diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
index 883485684435..ef2859f9fcce 100644
--- a/arch/x86/kernel/aperture_64.c
+++ b/arch/x86/kernel/aperture_64.c
@@ -307,11 +307,11 @@ void __init early_gart_iommu_check(void)
 
 	if (gart_fix_e820 && !fix && aper_enabled) {
 		if (e820__mapped_any(aper_base, aper_base + aper_size,
-				    E820_RAM)) {
+				    E820_TYPE_RAM)) {
 			/* reserve it, so we can reuse it in second kernel */
 			pr_info("e820: reserve [mem %#010Lx-%#010Lx] for GART\n",
 				aper_base, aper_base + aper_size - 1);
-			e820__range_add(aper_base, aper_size, E820_RESERVED);
+			e820__range_add(aper_base, aper_size, E820_TYPE_RESERVED);
 			e820__update_table_print();
 		}
 	}
diff --git a/arch/x86/kernel/cpu/mtrr/cleanup.c b/arch/x86/kernel/cpu/mtrr/cleanup.c
index 244aaa988ecd..765afd599039 100644
--- a/arch/x86/kernel/cpu/mtrr/cleanup.c
+++ b/arch/x86/kernel/cpu/mtrr/cleanup.c
@@ -860,7 +860,7 @@ real_trim_memory(unsigned long start_pfn, unsigned long limit_pfn)
 	trim_size <<= PAGE_SHIFT;
 	trim_size -= trim_start;
 
-	return e820__range_update(trim_start, trim_size, E820_RAM, E820_RESERVED);
+	return e820__range_update(trim_start, trim_size, E820_TYPE_RAM, E820_TYPE_RESERVED);
 }
 
 /**
diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
index 11f7eb1e2506..5feba9a21130 100644
--- a/arch/x86/kernel/crash.c
+++ b/arch/x86/kernel/crash.c
@@ -575,17 +575,17 @@ int crash_setup_memmap_entries(struct kimage *image, struct boot_params *params)
 	/* Add first 640K segment */
 	ei.addr = image->arch.backup_src_start;
 	ei.size = image->arch.backup_src_sz;
-	ei.type = E820_RAM;
+	ei.type = E820_TYPE_RAM;
 	add_e820_entry(params, &ei);
 
 	/* Add ACPI tables */
-	cmd.type = E820_ACPI;
+	cmd.type = E820_TYPE_ACPI;
 	flags = IORESOURCE_MEM | IORESOURCE_BUSY;
 	walk_iomem_res_desc(IORES_DESC_ACPI_TABLES, flags, 0, -1, &cmd,
 		       memmap_entry_callback);
 
 	/* Add ACPI Non-volatile Storage */
-	cmd.type = E820_NVS;
+	cmd.type = E820_TYPE_NVS;
 	walk_iomem_res_desc(IORES_DESC_ACPI_NV_STORAGE, flags, 0, -1, &cmd,
 			memmap_entry_callback);
 
@@ -593,7 +593,7 @@ int crash_setup_memmap_entries(struct kimage *image, struct boot_params *params)
 	if (crashk_low_res.end) {
 		ei.addr = crashk_low_res.start;
 		ei.size = crashk_low_res.end - crashk_low_res.start + 1;
-		ei.type = E820_RAM;
+		ei.type = E820_TYPE_RAM;
 		add_e820_entry(params, &ei);
 	}
 
@@ -610,7 +610,7 @@ int crash_setup_memmap_entries(struct kimage *image, struct boot_params *params)
 		if (ei.size < PAGE_SIZE)
 			continue;
 		ei.addr = cmem->ranges[i].start;
-		ei.type = E820_RAM;
+		ei.type = E820_TYPE_RAM;
 		add_e820_entry(params, &ei);
 	}
 
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 79673843dc42..90dcd240a389 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -148,14 +148,14 @@ void __init e820__range_add(u64 start, u64 size, enum e820_type type)
 static void __init e820_print_type(enum e820_type type)
 {
 	switch (type) {
-	case E820_RAM:			/* Fall through: */
-	case E820_RESERVED_KERN:	pr_cont("usable");			break;
-	case E820_RESERVED:		pr_cont("reserved");			break;
-	case E820_ACPI:			pr_cont("ACPI data");			break;
-	case E820_NVS:			pr_cont("ACPI NVS");			break;
-	case E820_UNUSABLE:		pr_cont("unusable");			break;
-	case E820_PMEM:			/* Fall through: */
-	case E820_PRAM:			pr_cont("persistent (type %u)", type);	break;
+	case E820_TYPE_RAM:		/* Fall through: */
+	case E820_TYPE_RESERVED_KERN:	pr_cont("usable");			break;
+	case E820_TYPE_RESERVED:	pr_cont("reserved");			break;
+	case E820_TYPE_ACPI:		pr_cont("ACPI data");			break;
+	case E820_TYPE_NVS:		pr_cont("ACPI NVS");			break;
+	case E820_TYPE_UNUSABLE:	pr_cont("unusable");			break;
+	case E820_TYPE_PMEM:		/* Fall through: */
+	case E820_TYPE_PRAM:		pr_cont("persistent (type %u)", type);	break;
 	default:			pr_cont("type %u", type);		break;
 	}
 }
@@ -340,7 +340,7 @@ int __init e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *p
 		}
 
 		/* Continue building up new BIOS map based on this information: */
-		if (current_type != last_type || current_type == E820_PRAM) {
+		if (current_type != last_type || current_type == E820_TYPE_PRAM) {
 			if (last_type != 0)	 {
 				new_bios[new_bios_entry].size = change_point[chgidx]->addr - last_addr;
 				/* Move forward only if the new size was non-zero: */
@@ -704,7 +704,7 @@ void __init e820_mark_nosave_regions(unsigned long limit_pfn)
 
 		pfn = PFN_DOWN(entry->addr + entry->size);
 
-		if (entry->type != E820_RAM && entry->type != E820_RESERVED_KERN)
+		if (entry->type != E820_TYPE_RAM && entry->type != E820_TYPE_RESERVED_KERN)
 			register_nosave_region(PFN_UP(entry->addr), pfn);
 
 		if (pfn >= limit_pfn)
@@ -724,7 +724,7 @@ static int __init e820_mark_nvs_memory(void)
 	for (i = 0; i < e820_table->nr_entries; i++) {
 		struct e820_entry *entry = &e820_table->entries[i];
 
-		if (entry->type == E820_NVS)
+		if (entry->type == E820_TYPE_NVS)
 			acpi_nvs_register(entry->addr, entry->size);
 	}
 
@@ -747,7 +747,7 @@ u64 __init e820__memblock_alloc_reserved(u64 size, u64 align)
 
 	addr = __memblock_alloc_base(size, align, MEMBLOCK_ALLOC_ACCESSIBLE);
 	if (addr) {
-		e820__range_update_firmware(addr, size, E820_RAM, E820_RESERVED);
+		e820__range_update_firmware(addr, size, E820_TYPE_RAM, E820_TYPE_RESERVED);
 		pr_info("e820: update e820_table_firmware for e820__memblock_alloc_reserved()\n");
 		e820__update_table_firmware();
 	}
@@ -805,12 +805,12 @@ static unsigned long __init e820_end_pfn(unsigned long limit_pfn, enum e820_type
 
 unsigned long __init e820_end_of_ram_pfn(void)
 {
-	return e820_end_pfn(MAX_ARCH_PFN, E820_RAM);
+	return e820_end_pfn(MAX_ARCH_PFN, E820_TYPE_RAM);
 }
 
 unsigned long __init e820_end_of_low_ram_pfn(void)
 {
-	return e820_end_pfn(1UL << (32 - PAGE_SHIFT), E820_RAM);
+	return e820_end_pfn(1UL << (32 - PAGE_SHIFT), E820_TYPE_RAM);
 }
 
 static void __init early_panic(char *msg)
@@ -846,7 +846,7 @@ static int __init parse_memopt(char *p)
 	if (mem_size == 0)
 		return -EINVAL;
 
-	e820__range_remove(mem_size, ULLONG_MAX - mem_size, E820_RAM, 1);
+	e820__range_remove(mem_size, ULLONG_MAX - mem_size, E820_TYPE_RAM, 1);
 
 	return 0;
 }
@@ -882,18 +882,18 @@ static int __init parse_memmap_one(char *p)
 	userdef = 1;
 	if (*p == '@') {
 		start_at = memparse(p+1, &p);
-		e820__range_add(start_at, mem_size, E820_RAM);
+		e820__range_add(start_at, mem_size, E820_TYPE_RAM);
 	} else if (*p == '#') {
 		start_at = memparse(p+1, &p);
-		e820__range_add(start_at, mem_size, E820_ACPI);
+		e820__range_add(start_at, mem_size, E820_TYPE_ACPI);
 	} else if (*p == '$') {
 		start_at = memparse(p+1, &p);
-		e820__range_add(start_at, mem_size, E820_RESERVED);
+		e820__range_add(start_at, mem_size, E820_TYPE_RESERVED);
 	} else if (*p == '!') {
 		start_at = memparse(p+1, &p);
-		e820__range_add(start_at, mem_size, E820_PRAM);
+		e820__range_add(start_at, mem_size, E820_TYPE_PRAM);
 	} else {
-		e820__range_remove(mem_size, ULLONG_MAX - mem_size, E820_RAM, 1);
+		e820__range_remove(mem_size, ULLONG_MAX - mem_size, E820_TYPE_RAM, 1);
 	}
 
 	return *p == '\0' ? 0 : -EINVAL;
@@ -926,7 +926,7 @@ void __init e820_reserve_setup_data(void)
 
 	while (pa_data) {
 		data = early_memremap(pa_data, sizeof(*data));
-		e820__range_update(pa_data, sizeof(*data)+data->len, E820_RAM, E820_RESERVED_KERN);
+		e820__range_update(pa_data, sizeof(*data)+data->len, E820_TYPE_RAM, E820_TYPE_RESERVED_KERN);
 		pa_data = data->next;
 		early_memunmap(data, sizeof(*data));
 	}
@@ -956,42 +956,42 @@ void __init e820__finish_early_params(void)
 static const char *__init e820_type_to_string(struct e820_entry *entry)
 {
 	switch (entry->type) {
-	case E820_RESERVED_KERN: /* Fall-through: */
-	case E820_RAM:		 return "System RAM";
-	case E820_ACPI:		 return "ACPI Tables";
-	case E820_NVS:		 return "ACPI Non-volatile Storage";
-	case E820_UNUSABLE:	 return "Unusable memory";
-	case E820_PRAM:		 return "Persistent Memory (legacy)";
-	case E820_PMEM:		 return "Persistent Memory";
-	default:		 return "Reserved";
+	case E820_TYPE_RESERVED_KERN:	/* Fall-through: */
+	case E820_TYPE_RAM:		return "System RAM";
+	case E820_TYPE_ACPI:		return "ACPI Tables";
+	case E820_TYPE_NVS:		return "ACPI Non-volatile Storage";
+	case E820_TYPE_UNUSABLE:	return "Unusable memory";
+	case E820_TYPE_PRAM:		return "Persistent Memory (legacy)";
+	case E820_TYPE_PMEM:		return "Persistent Memory";
+	default:			return "Reserved";
 	}
 }
 
 static unsigned long __init e820_type_to_iomem_type(struct e820_entry *entry)
 {
 	switch (entry->type) {
-	case E820_RESERVED_KERN: /* Fall-through: */
-	case E820_RAM:		 return IORESOURCE_SYSTEM_RAM;
-	case E820_ACPI:		 /* Fall-through: */
-	case E820_NVS:		 /* Fall-through: */
-	case E820_UNUSABLE:	 /* Fall-through: */
-	case E820_PRAM:		 /* Fall-through: */
-	case E820_PMEM:		 /* Fall-through: */
-	default:		 return IORESOURCE_MEM;
+	case E820_TYPE_RESERVED_KERN:	/* Fall-through: */
+	case E820_TYPE_RAM:		return IORESOURCE_SYSTEM_RAM;
+	case E820_TYPE_ACPI:		/* Fall-through: */
+	case E820_TYPE_NVS:		/* Fall-through: */
+	case E820_TYPE_UNUSABLE:	/* Fall-through: */
+	case E820_TYPE_PRAM:		/* Fall-through: */
+	case E820_TYPE_PMEM:		/* Fall-through: */
+	default:			return IORESOURCE_MEM;
 	}
 }
 
 static unsigned long __init e820_type_to_iores_desc(struct e820_entry *entry)
 {
 	switch (entry->type) {
-	case E820_ACPI:		 return IORES_DESC_ACPI_TABLES;
-	case E820_NVS:		 return IORES_DESC_ACPI_NV_STORAGE;
-	case E820_PMEM:		 return IORES_DESC_PERSISTENT_MEMORY;
-	case E820_PRAM:		 return IORES_DESC_PERSISTENT_MEMORY_LEGACY;
-	case E820_RESERVED_KERN: /* Fall-through: */
-	case E820_RAM:		 /* Fall-through: */
-	case E820_UNUSABLE:	 /* Fall-through: */
-	default:		 return IORES_DESC_NONE;
+	case E820_TYPE_ACPI:		return IORES_DESC_ACPI_TABLES;
+	case E820_TYPE_NVS:		return IORES_DESC_ACPI_NV_STORAGE;
+	case E820_TYPE_PMEM:		return IORES_DESC_PERSISTENT_MEMORY;
+	case E820_TYPE_PRAM:		return IORES_DESC_PERSISTENT_MEMORY_LEGACY;
+	case E820_TYPE_RESERVED_KERN:	/* Fall-through: */
+	case E820_TYPE_RAM:		/* Fall-through: */
+	case E820_TYPE_UNUSABLE:	/* Fall-through: */
+	default:			return IORES_DESC_NONE;
 	}
 }
 
@@ -1006,9 +1006,9 @@ static bool __init do_mark_busy(u32 type, struct resource *res)
 	 * for exclusive use of a driver
 	 */
 	switch (type) {
-	case E820_RESERVED:
-	case E820_PRAM:
-	case E820_PMEM:
+	case E820_TYPE_RESERVED:
+	case E820_TYPE_PRAM:
+	case E820_TYPE_PMEM:
 		return false;
 	default:
 		return true;
@@ -1102,7 +1102,7 @@ void __init e820_reserve_resources_late(void)
 		struct e820_entry *entry = &e820_table->entries[i];
 		u64 start, end;
 
-		if (entry->type != E820_RAM)
+		if (entry->type != E820_TYPE_RAM)
 			continue;
 
 		start = entry->addr + entry->size;
@@ -1148,8 +1148,8 @@ char *__init e820__memory_setup_default(void)
 		}
 
 		e820_table->nr_entries = 0;
-		e820__range_add(0, LOWMEMSIZE(), E820_RAM);
-		e820__range_add(HIGH_MEMORY, mem_size << 10, E820_RAM);
+		e820__range_add(0, LOWMEMSIZE(), E820_TYPE_RAM);
+		e820__range_add(HIGH_MEMORY, mem_size << 10, E820_TYPE_RAM);
 	}
 
 	return who;
@@ -1198,7 +1198,7 @@ void __init e820__memblock_setup(void)
 		if (end != (resource_size_t)end)
 			continue;
 
-		if (entry->type != E820_RAM && entry->type != E820_RESERVED_KERN)
+		if (entry->type != E820_TYPE_RAM && entry->type != E820_TYPE_RESERVED_KERN)
 			continue;
 
 		memblock_add(entry->addr, entry->size);
diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c
index 81a10ab15be9..2220a4c03adf 100644
--- a/arch/x86/kernel/early-quirks.c
+++ b/arch/x86/kernel/early-quirks.c
@@ -546,7 +546,7 @@ intel_graphics_stolen(int num, int slot, int func,
 	       &base, &end);
 
 	/* Mark this space as reserved */
-	e820__range_add(base, size, E820_RESERVED);
+	e820__range_add(base, size, E820_TYPE_RESERVED);
 	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 }
 
diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
index a8c9563557c9..3e43a7d3b191 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -232,7 +232,7 @@ setup_boot_parameters(struct kimage *image, struct boot_params *params,
 	nr_e820_entries = params->e820_entries;
 
 	for (i = 0; i < nr_e820_entries; i++) {
-		if (params->e820_table[i].type != E820_RAM)
+		if (params->e820_table[i].type != E820_TYPE_RAM)
 			continue;
 		start = params->e820_table[i].addr;
 		end = params->e820_table[i].addr + params->e820_table[i].size - 1;
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 0e70a7bbeeef..074c86a0ee86 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -119,7 +119,7 @@
  * max_low_pfn_mapped: highest direct mapped pfn under 4GB
  * max_pfn_mapped:     highest direct mapped pfn over 4GB
  *
- * The direct mapping only covers E820_RAM regions, so the ranges and gaps are
+ * The direct mapping only covers E820_TYPE_RAM regions, so the ranges and gaps are
  * represented by pfn_mapped
  */
 unsigned long max_low_pfn_mapped;
@@ -731,14 +731,14 @@ static void __init trim_bios_range(void)
 	 * since some BIOSes are known to corrupt low memory.  See the
 	 * Kconfig help text for X86_RESERVE_LOW.
 	 */
-	e820__range_update(0, PAGE_SIZE, E820_RAM, E820_RESERVED);
+	e820__range_update(0, PAGE_SIZE, E820_TYPE_RAM, E820_TYPE_RESERVED);
 
 	/*
 	 * special case: Some BIOSen report the PC BIOS
 	 * area (640->1Mb) as ram even though it is not.
 	 * take them out.
 	 */
-	e820__range_remove(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
+	e820__range_remove(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_TYPE_RAM, 1);
 
 	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 }
@@ -750,18 +750,18 @@ static void __init e820_add_kernel_range(void)
 	u64 size = __pa_symbol(_end) - start;
 
 	/*
-	 * Complain if .text .data and .bss are not marked as E820_RAM and
+	 * Complain if .text .data and .bss are not marked as E820_TYPE_RAM and
 	 * attempt to fix it by adding the range. We may have a confused BIOS,
 	 * or the user may have used memmap=exactmap or memmap=xxM$yyM to
 	 * exclude kernel range. If we really are running on top non-RAM,
 	 * we will crash later anyways.
 	 */
-	if (e820__mapped_all(start, start + size, E820_RAM))
+	if (e820__mapped_all(start, start + size, E820_TYPE_RAM))
 		return;
 
-	pr_warn(".text .data .bss are not marked as E820_RAM!\n");
-	e820__range_remove(start, size, E820_RAM, 0);
-	e820__range_add(start, size, E820_RAM);
+	pr_warn(".text .data .bss are not marked as E820_TYPE_RAM!\n");
+	e820__range_remove(start, size, E820_TYPE_RAM, 0);
+	e820__range_add(start, size, E820_TYPE_RAM);
 }
 
 static unsigned reserve_low = CONFIG_X86_RESERVE_LOW << 10;
@@ -1031,8 +1031,8 @@ void __init setup_arch(char **cmdline_p)
 	trim_bios_range();
 #ifdef CONFIG_X86_32
 	if (ppro_with_ram_bug()) {
-		e820__range_update(0x70000000ULL, 0x40000ULL, E820_RAM,
-				  E820_RESERVED);
+		e820__range_update(0x70000000ULL, 0x40000ULL, E820_TYPE_RAM,
+				  E820_TYPE_RESERVED);
 		e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 		printk(KERN_INFO "fixed physical RAM map:\n");
 		e820__print_table("bad_ppro");
diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
index 0e2dc3831970..ccccd335ae01 100644
--- a/arch/x86/kernel/tboot.c
+++ b/arch/x86/kernel/tboot.c
@@ -69,8 +69,8 @@ void __init tboot_probe(void)
 	 * set_fixmap(), to reduce chance of garbage value causing crash
 	 */
 	if (!e820__mapped_any(boot_params.tboot_addr,
-			     boot_params.tboot_addr, E820_RESERVED)) {
-		pr_warning("non-0 tboot_addr but it is not of type E820_RESERVED\n");
+			     boot_params.tboot_addr, E820_TYPE_RESERVED)) {
+		pr_warning("non-0 tboot_addr but it is not of type E820_TYPE_RESERVED\n");
 		return;
 	}
 
@@ -189,8 +189,8 @@ static int tboot_setup_sleep(void)
 	tboot->num_mac_regions = 0;
 
 	for (i = 0; i < e820_table->nr_entries; i++) {
-		if ((e820_table->entries[i].type != E820_RAM)
-		 && (e820_table->entries[i].type != E820_RESERVED_KERN))
+		if ((e820_table->entries[i].type != E820_TYPE_RAM)
+		 && (e820_table->entries[i].type != E820_TYPE_RESERVED_KERN))
 			continue;
 
 		add_mac_region(e820_table->entries[i].addr, e820_table->entries[i].size);
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 922671d3af85..158dfecdab72 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -430,7 +430,7 @@ unsigned long __ref init_memory_mapping(unsigned long start,
 
 /*
  * We need to iterate through the E820 memory map and create direct mappings
- * for only E820_RAM and E820_KERN_RESERVED regions. We cannot simply
+ * for only E820_TYPE_RAM and E820_KERN_RESERVED regions. We cannot simply
  * create direct mappings for all pfns from [0 to max_low_pfn) and
  * [4GB to max_pfn) because of possible memory holes in high addresses
  * that cannot be marked as UC by fixed/variable range MTRRs.
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index cfb119e4c4d1..94e033085f60 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -338,9 +338,9 @@ phys_pte_init(pte_t *pte_page, unsigned long paddr, unsigned long paddr_end,
 		if (paddr >= paddr_end) {
 			if (!after_bootmem &&
 			    !e820__mapped_any(paddr & PAGE_MASK, paddr_next,
-					     E820_RAM) &&
+					     E820_TYPE_RAM) &&
 			    !e820__mapped_any(paddr & PAGE_MASK, paddr_next,
-					     E820_RESERVED_KERN))
+					     E820_TYPE_RESERVED_KERN))
 				set_pte(pte, __pte(0));
 			continue;
 		}
@@ -393,9 +393,9 @@ phys_pmd_init(pmd_t *pmd_page, unsigned long paddr, unsigned long paddr_end,
 		if (paddr >= paddr_end) {
 			if (!after_bootmem &&
 			    !e820__mapped_any(paddr & PMD_MASK, paddr_next,
-					     E820_RAM) &&
+					     E820_TYPE_RAM) &&
 			    !e820__mapped_any(paddr & PMD_MASK, paddr_next,
-					     E820_RESERVED_KERN))
+					     E820_TYPE_RESERVED_KERN))
 				set_pmd(pmd, __pmd(0));
 			continue;
 		}
@@ -479,9 +479,9 @@ phys_pud_init(pud_t *pud_page, unsigned long paddr, unsigned long paddr_end,
 		if (paddr >= paddr_end) {
 			if (!after_bootmem &&
 			    !e820__mapped_any(paddr & PUD_MASK, paddr_next,
-					     E820_RAM) &&
+					     E820_TYPE_RAM) &&
 			    !e820__mapped_any(paddr & PUD_MASK, paddr_next,
-					     E820_RESERVED_KERN))
+					     E820_TYPE_RESERVED_KERN))
 				set_pud(pud, __pud(0));
 			continue;
 		}
diff --git a/arch/x86/pci/mmconfig-shared.c b/arch/x86/pci/mmconfig-shared.c
index 696b050bdc45..96057e4b6121 100644
--- a/arch/x86/pci/mmconfig-shared.c
+++ b/arch/x86/pci/mmconfig-shared.c
@@ -452,7 +452,7 @@ static int __ref is_mmconf_reserved(check_reserved_t is_reserved,
 	int num_buses;
 	char *method = with_e820 ? "E820" : "ACPI motherboard resources";
 
-	while (!is_reserved(addr, addr + size, E820_RESERVED)) {
+	while (!is_reserved(addr, addr + size, E820_TYPE_RESERVED)) {
 		size >>= 1;
 		if (size < (16UL<<20))
 			break;
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index d97c05ee9664..14d0a6b1eee1 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -140,21 +140,21 @@ static void __init do_add_efi_memmap(void)
 		case EFI_BOOT_SERVICES_DATA:
 		case EFI_CONVENTIONAL_MEMORY:
 			if (md->attribute & EFI_MEMORY_WB)
-				e820_type = E820_RAM;
+				e820_type = E820_TYPE_RAM;
 			else
-				e820_type = E820_RESERVED;
+				e820_type = E820_TYPE_RESERVED;
 			break;
 		case EFI_ACPI_RECLAIM_MEMORY:
-			e820_type = E820_ACPI;
+			e820_type = E820_TYPE_ACPI;
 			break;
 		case EFI_ACPI_MEMORY_NVS:
-			e820_type = E820_NVS;
+			e820_type = E820_TYPE_NVS;
 			break;
 		case EFI_UNUSABLE_MEMORY:
-			e820_type = E820_UNUSABLE;
+			e820_type = E820_TYPE_UNUSABLE;
 			break;
 		case EFI_PERSISTENT_MEMORY:
-			e820_type = E820_PMEM;
+			e820_type = E820_TYPE_PMEM;
 			break;
 		default:
 			/*
@@ -162,7 +162,7 @@ static void __init do_add_efi_memmap(void)
 			 * EFI_RUNTIME_SERVICES_DATA EFI_MEMORY_MAPPED_IO
 			 * EFI_MEMORY_MAPPED_IO_PORT_SPACE EFI_PAL_CODE
 			 */
-			e820_type = E820_RESERVED;
+			e820_type = E820_TYPE_RESERVED;
 			break;
 		}
 		e820__range_add(start, size, e820_type);
diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
index d4acd1668d36..3c8d8e511fd4 100644
--- a/arch/x86/platform/efi/quirks.c
+++ b/arch/x86/platform/efi/quirks.c
@@ -242,14 +242,14 @@ void __init efi_arch_mem_reserve(phys_addr_t addr, u64 size)
  * else. We must only reserve (and then free) regions:
  *
  * - Not within any part of the kernel
- * - Not the BIOS reserved area (E820_RESERVED, E820_NVS, etc)
+ * - Not the BIOS reserved area (E820_TYPE_RESERVED, E820_TYPE_NVS, etc)
  */
 static bool can_free_region(u64 start, u64 size)
 {
 	if (start + size > __pa_symbol(_text) && start <= __pa_symbol(_end))
 		return false;
 
-	if (!e820__mapped_all(start, start+size, E820_RAM))
+	if (!e820__mapped_all(start, start+size, E820_TYPE_RAM))
 		return false;
 
 	return true;
@@ -282,7 +282,7 @@ void __init efi_reserve_boot_services(void)
 		 * A good example of a critical region that must not be
 		 * freed is page zero (first 4Kb of memory), which may
 		 * contain boot services code/data but is marked
-		 * E820_RESERVED by trim_bios_range().
+		 * E820_TYPE_RESERVED by trim_bios_range().
 		 */
 		if (!already_reserved) {
 			memblock_reserve(start, size);
diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
index a634723e660f..625ceafeb7a0 100644
--- a/arch/x86/xen/setup.c
+++ b/arch/x86/xen/setup.c
@@ -206,7 +206,7 @@ static unsigned long __init xen_find_pfn_range(unsigned long *min_pfn)
 		unsigned long s_pfn;
 		unsigned long e_pfn;
 
-		if (entry->type != E820_RAM)
+		if (entry->type != E820_TYPE_RAM)
 			continue;
 
 		e_pfn = PFN_DOWN(entry->addr + entry->size);
@@ -473,11 +473,11 @@ static unsigned long __init xen_foreach_remap_area(unsigned long nr_pages,
 	 */
 	for (i = 0; i < xen_e820_table_entries; i++, entry++) {
 		phys_addr_t end = entry->addr + entry->size;
-		if (entry->type == E820_RAM || i == xen_e820_table_entries - 1) {
+		if (entry->type == E820_TYPE_RAM || i == xen_e820_table_entries - 1) {
 			unsigned long start_pfn = PFN_DOWN(start);
 			unsigned long end_pfn = PFN_UP(end);
 
-			if (entry->type == E820_RAM)
+			if (entry->type == E820_TYPE_RAM)
 				end_pfn = PFN_UP(entry->addr);
 
 			if (start_pfn < end_pfn)
@@ -591,7 +591,7 @@ static void __init xen_align_and_add_e820_region(phys_addr_t start,
 	phys_addr_t end = start + size;
 
 	/* Align RAM regions to page boundaries. */
-	if (type == E820_RAM) {
+	if (type == E820_TYPE_RAM) {
 		start = PAGE_ALIGN(start);
 		end &= ~((phys_addr_t)PAGE_SIZE - 1);
 	}
@@ -605,8 +605,8 @@ static void __init xen_ignore_unusable(void)
 	unsigned int i;
 
 	for (i = 0; i < xen_e820_table_entries; i++, entry++) {
-		if (entry->type == E820_UNUSABLE)
-			entry->type = E820_RAM;
+		if (entry->type == E820_TYPE_UNUSABLE)
+			entry->type = E820_TYPE_RAM;
 	}
 }
 
@@ -623,7 +623,7 @@ bool __init xen_is_e820_reserved(phys_addr_t start, phys_addr_t size)
 	entry = xen_e820_table;
 
 	for (mapcnt = 0; mapcnt < xen_e820_table_entries; mapcnt++) {
-		if (entry->type == E820_RAM && entry->addr <= start &&
+		if (entry->type == E820_TYPE_RAM && entry->addr <= start &&
 		    (entry->addr + entry->size) >= end)
 			return false;
 
@@ -648,7 +648,7 @@ phys_addr_t __init xen_find_free_area(phys_addr_t size)
 	struct e820_entry *entry = xen_e820_table;
 
 	for (mapcnt = 0; mapcnt < xen_e820_table_entries; mapcnt++, entry++) {
-		if (entry->type != E820_RAM || entry->size < size)
+		if (entry->type != E820_TYPE_RAM || entry->size < size)
 			continue;
 		start = entry->addr;
 		for (addr = start; addr < start + size; addr += PAGE_SIZE) {
@@ -764,7 +764,7 @@ char * __init xen_memory_setup(void)
 		xen_e820_table[0].size = mem_end;
 		/* 8MB slack (to balance backend allocations). */
 		xen_e820_table[0].size += 8ULL << 20;
-		xen_e820_table[0].type = E820_RAM;
+		xen_e820_table[0].type = E820_TYPE_RAM;
 		rc = 0;
 	}
 	BUG_ON(rc);
@@ -819,7 +819,7 @@ char * __init xen_memory_setup(void)
 		chunk_size = size;
 		type = xen_e820_table[i].type;
 
-		if (type == E820_RAM) {
+		if (type == E820_TYPE_RAM) {
 			if (addr < mem_end) {
 				chunk_size = min(size, mem_end - addr);
 			} else if (extra_pages) {
@@ -859,7 +859,7 @@ char * __init xen_memory_setup(void)
 	 * about in there.
 	 */
 	e820__range_add(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS,
-			E820_RESERVED);
+			E820_TYPE_RESERVED);
 
 	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
 
diff --git a/tools/lguest/lguest.c b/tools/lguest/lguest.c
index 3819e23a173e..4e38ea02ef0f 100644
--- a/tools/lguest/lguest.c
+++ b/tools/lguest/lguest.c
@@ -3339,7 +3339,7 @@ int main(int argc, char *argv[])
 	 * simple, single region.
 	 */
 	boot->e820_entries = 1;
-	boot->e820_table[0] = ((struct e820_entry) { 0, mem, E820_RAM });
+	boot->e820_table[0] = ((struct e820_entry) { 0, mem, E820_TYPE_RAM });
 	/*
 	 * The boot header contains a command line pointer: we put the command
 	 * line after the boot header.
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 40/50] x86/boot/e820: Clean up the E820 table size define names
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (38 preceding siblings ...)
  2017-01-28 22:12 ` [PATCH 39/50] x86/boot/e820: Prefix the E820_* type names with "E820_TYPE_" Ingo Molnar
@ 2017-01-28 22:12 ` Ingo Molnar
  2017-01-28 22:12 ` [PATCH 41/50] x86/boot/e820: Clean up and standardize sizeof() uses Ingo Molnar
                   ` (9 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:12 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

We've got a number of defines related to the E820 table and its size:

	E820MAP
	E820NR
	E820_X_MAX
	E820MAX

The first two denote byte offsets into the zeropage (struct boot_params),
and can are not used in the kernel and can be removed.

The E820_*_MAX values have an inconsistent structure and it's unclear in any
case what they mean. 'X' presuably goes for extended - but it's not very
expressive altogether.

Change these over to:

	E820_MAX_ENTRIES_ZEROPAGE
	E820_MAX_ENTRIES

... which are self-explanatory names.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/types.h      | 18 ++++++------------
 arch/x86/include/uapi/asm/bootparam.h  |  2 +-
 arch/x86/include/uapi/asm/e820/types.h |  7 +++++--
 arch/x86/kernel/crash.c                |  2 +-
 arch/x86/kernel/e820.c                 |  8 ++++----
 arch/x86/kernel/kexec-bzimage64.c      |  6 +++---
 arch/x86/mm/init.c                     |  6 +++---
 arch/x86/mm/kasan_init_64.c            |  4 ++--
 arch/x86/xen/setup.c                   |  2 +-
 include/xen/page.h                     |  2 +-
 10 files changed, 27 insertions(+), 30 deletions(-)

diff --git a/arch/x86/include/asm/e820/types.h b/arch/x86/include/asm/e820/types.h
index eb313b62d548..cf6074f8d563 100644
--- a/arch/x86/include/asm/e820/types.h
+++ b/arch/x86/include/asm/e820/types.h
@@ -4,12 +4,12 @@
 #include <uapi/asm/e820/types.h>
 
 /*
- * The legacy E820 BIOS limits us to 128 (E820MAX) nodes due to the
- * constrained space in the zeropage.
+ * The legacy E820 BIOS limits us to 128 (E820_MAX_ENTRIES_ZEROPAGE) 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
+ * to extend the e820 table size at build-time, via the E820_MAX_ENTRIES
  * define below.
  *
  * ( Those extra entries are enumerated via the EFI memory map, not
@@ -17,7 +17,7 @@
  *
  * 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.
+ * NUMA node, plus E820_MAX_ENTRIES_ZEROPAGE 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
@@ -31,20 +31,14 @@
 
 #include <linux/numa.h>
 
-#define E820_X_MAX		(E820MAX + 3*MAX_NUMNODES)
-
-/* Our map: */
-#define E820MAP			0x2d0
-
-/* Number of entries in E820MAP: */
-#define E820NR			0x1e8
+#define E820_MAX_ENTRIES	(E820_MAX_ENTRIES_ZEROPAGE + 3*MAX_NUMNODES)
 
 /*
  * The whole array of E820 entries:
  */
 struct e820_table {
 	__u32 nr_entries;
-	struct e820_entry entries[E820_X_MAX];
+	struct e820_entry entries[E820_MAX_ENTRIES];
 };
 
 /*
diff --git a/arch/x86/include/uapi/asm/bootparam.h b/arch/x86/include/uapi/asm/bootparam.h
index 5f41518f7159..7f04c45aa429 100644
--- a/arch/x86/include/uapi/asm/bootparam.h
+++ b/arch/x86/include/uapi/asm/bootparam.h
@@ -152,7 +152,7 @@ struct boot_params {
 	struct setup_header hdr;    /* setup header */	/* 0x1f1 */
 	__u8  _pad7[0x290-0x1f1-sizeof(struct setup_header)];
 	__u32 edd_mbr_sig_buffer[EDD_MBR_SIG_MAX];	/* 0x290 */
-	struct e820_entry e820_table[E820MAX];		/* 0x2d0 */
+	struct e820_entry e820_table[E820_MAX_ENTRIES_ZEROPAGE]; /* 0x2d0 */
 	__u8  _pad8[48];				/* 0xcd0 */
 	struct edd_info eddbuf[EDDMAXNR];		/* 0xd00 */
 	__u8  _pad9[276];				/* 0xeec */
diff --git a/arch/x86/include/uapi/asm/e820/types.h b/arch/x86/include/uapi/asm/e820/types.h
index 29391386b63f..3ac962f724f5 100644
--- a/arch/x86/include/uapi/asm/e820/types.h
+++ b/arch/x86/include/uapi/asm/e820/types.h
@@ -1,8 +1,11 @@
 #ifndef _UAPI_ASM_E820_TYPES_H
 #define _UAPI_ASM_E820_TYPES_H
 
-/* The maximum number of entries in E820MAP: */
-#define E820MAX			128
+/*
+ * This is the maximum number of entries in struct boot_params::e820_table (the zeropage),
+ * which is part of the x86 boot protocol ABI:
+ */
+#define E820_MAX_ENTRIES_ZEROPAGE 128
 
 #ifndef __ASSEMBLY__
 
diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
index 5feba9a21130..22217ece26c8 100644
--- a/arch/x86/kernel/crash.c
+++ b/arch/x86/kernel/crash.c
@@ -509,7 +509,7 @@ static int add_e820_entry(struct boot_params *params, struct e820_entry *entry)
 	unsigned int nr_e820_entries;
 
 	nr_e820_entries = params->e820_entries;
-	if (nr_e820_entries >= E820MAX)
+	if (nr_e820_entries >= E820_MAX_ENTRIES_ZEROPAGE)
 		return 1;
 
 	memcpy(&params->e820_table[nr_e820_entries], entry,
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 90dcd240a389..055ac2484729 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -261,10 +261,10 @@ static int __init cpcompare(const void *a, const void *b)
 
 int __init e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map)
 {
-	static struct change_member change_point_list[2*E820_X_MAX] __initdata;
-	static struct change_member *change_point[2*E820_X_MAX] __initdata;
-	static struct e820_entry *overlap_list[E820_X_MAX] __initdata;
-	static struct e820_entry new_bios[E820_X_MAX] __initdata;
+	static struct change_member change_point_list[2*E820_MAX_ENTRIES] __initdata;
+	static struct change_member *change_point[2*E820_MAX_ENTRIES] __initdata;
+	static struct e820_entry *overlap_list[E820_MAX_ENTRIES] __initdata;
+	static struct e820_entry new_bios[E820_MAX_ENTRIES] __initdata;
 	enum e820_type current_type, last_type;
 	unsigned long long last_addr;
 	int chgidx;
diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
index 3e43a7d3b191..9d7fd5e6689a 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -102,9 +102,9 @@ static int setup_e820_entries(struct boot_params *params)
 
 	nr_e820_entries = e820_table_firmware->nr_entries;
 
-	/* TODO: Pass entries more than E820MAX in bootparams setup data */
-	if (nr_e820_entries > E820MAX)
-		nr_e820_entries = E820MAX;
+	/* TODO: Pass entries more than E820_MAX_ENTRIES_ZEROPAGE in bootparams setup data */
+	if (nr_e820_entries > E820_MAX_ENTRIES_ZEROPAGE)
+		nr_e820_entries = E820_MAX_ENTRIES_ZEROPAGE;
 
 	params->e820_entries = nr_e820_entries;
 	memcpy(&params->e820_table, &e820_table_firmware->entries, nr_e820_entries*sizeof(struct e820_entry));
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 158dfecdab72..6b6b4c59cfc1 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -373,14 +373,14 @@ static int __meminit split_mem_range(struct map_range *mr, int nr_range,
 	return nr_range;
 }
 
-struct range pfn_mapped[E820_X_MAX];
+struct range pfn_mapped[E820_MAX_ENTRIES];
 int nr_pfn_mapped;
 
 static void add_pfn_range_mapped(unsigned long start_pfn, unsigned long end_pfn)
 {
-	nr_pfn_mapped = add_range_with_merge(pfn_mapped, E820_X_MAX,
+	nr_pfn_mapped = add_range_with_merge(pfn_mapped, E820_MAX_ENTRIES,
 					     nr_pfn_mapped, start_pfn, end_pfn);
-	nr_pfn_mapped = clean_sort_range(pfn_mapped, E820_X_MAX);
+	nr_pfn_mapped = clean_sort_range(pfn_mapped, E820_MAX_ENTRIES);
 
 	max_pfn_mapped = max(max_pfn_mapped, end_pfn);
 
diff --git a/arch/x86/mm/kasan_init_64.c b/arch/x86/mm/kasan_init_64.c
index bf9a511c98f3..7d02845ec456 100644
--- a/arch/x86/mm/kasan_init_64.c
+++ b/arch/x86/mm/kasan_init_64.c
@@ -11,7 +11,7 @@
 #include <asm/sections.h>
 
 extern pgd_t early_level4_pgt[PTRS_PER_PGD];
-extern struct range pfn_mapped[E820_X_MAX];
+extern struct range pfn_mapped[E820_MAX_ENTRIES];
 
 static int __init map_range(struct range *range)
 {
@@ -103,7 +103,7 @@ void __init kasan_init(void)
 	kasan_populate_zero_shadow((void *)KASAN_SHADOW_START,
 			kasan_mem_to_shadow((void *)PAGE_OFFSET));
 
-	for (i = 0; i < E820_X_MAX; i++) {
+	for (i = 0; i < E820_MAX_ENTRIES; i++) {
 		if (pfn_mapped[i].end == 0)
 			break;
 
diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
index 625ceafeb7a0..381a0d3577a7 100644
--- a/arch/x86/xen/setup.c
+++ b/arch/x86/xen/setup.c
@@ -41,7 +41,7 @@ struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata;
 unsigned long xen_released_pages;
 
 /* E820 map used during setting up memory. */
-static struct e820_entry xen_e820_table[E820_X_MAX] __initdata;
+static struct e820_entry xen_e820_table[E820_MAX_ENTRIES] __initdata;
 static u32 xen_e820_table_entries __initdata;
 
 /*
diff --git a/include/xen/page.h b/include/xen/page.h
index 9dc46cb8a0fd..064194f6453e 100644
--- a/include/xen/page.h
+++ b/include/xen/page.h
@@ -38,7 +38,7 @@ struct xen_memory_region {
 	unsigned long n_pfns;
 };
 
-#define XEN_EXTRA_MEM_MAX_REGIONS 128 /* == E820MAX */
+#define XEN_EXTRA_MEM_MAX_REGIONS 128 /* == E820_MAX_ENTRIES_ZEROPAGE */
 
 extern __initdata
 struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS];
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 41/50] x86/boot/e820: Clean up and standardize sizeof() uses
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (39 preceding siblings ...)
  2017-01-28 22:12 ` [PATCH 40/50] x86/boot/e820: Clean up the E820 table size define names Ingo Molnar
@ 2017-01-28 22:12 ` Ingo Molnar
  2017-01-28 22:12 ` [PATCH 42/50] xen, x86/boot/e820: Simplify Xen's xen_e820_table construct Ingo Molnar
                   ` (8 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:12 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

There's various sizeof() uses in e820.c - standardize on the shortest
and least error prone one, along the pattern of:

-	memset(entry, 0, sizeof(struct e820_entry));
+	memset(entry, 0, sizeof(*entry));

... because with this pattern in most cases it's immediately clear that
we have used the right type - and the pattern is robust against changing
the type as well.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/e820.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 055ac2484729..da69addf6c34 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -306,7 +306,7 @@ int __init e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *p
 	chg_nr = chgidx;
 
 	/* Sort change-point list by memory addresses (low -> high): */
-	sort(change_point, chg_nr, sizeof *change_point, cpcompare, NULL);
+	sort(change_point, chg_nr, sizeof(*change_point), cpcompare, NULL);
 
 	/* Create a new BIOS memory map, removing overlaps: */
 	overlap_entries = 0;	 /* Number of entries in the overlap table */
@@ -362,7 +362,7 @@ int __init e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *p
 	new_nr = new_bios_entry;
 
 	/* Copy new BIOS mapping into the original location: */
-	memcpy(biosmap, new_bios, new_nr*sizeof(struct e820_entry));
+	memcpy(biosmap, new_bios, new_nr*sizeof(*biosmap));
 	*pnr_map = new_nr;
 
 	return 0;
@@ -513,7 +513,7 @@ u64 __init e820__range_remove(u64 start, u64 size, enum e820_type old_type, int
 		/* Completely covered? */
 		if (entry->addr >= start && entry_end <= end) {
 			real_removed_size += entry->size;
-			memset(entry, 0, sizeof(struct e820_entry));
+			memset(entry, 0, sizeof(*entry));
 			continue;
 		}
 
@@ -672,7 +672,7 @@ void __init e820__memory_setup_extended(u64 phys_addr, u32 data_len)
 	struct setup_data *sdata;
 
 	sdata = early_memremap(phys_addr, data_len);
-	entries = sdata->len / sizeof(struct e820_entry);
+	entries = sdata->len / sizeof(*extmap);
 	extmap = (struct e820_entry *)(sdata->data);
 
 	__append_e820_table(extmap, entries);
@@ -932,7 +932,7 @@ void __init e820_reserve_setup_data(void)
 	}
 
 	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
-	memcpy(e820_table_firmware, e820_table, sizeof(struct e820_table));
+	memcpy(e820_table_firmware, e820_table, sizeof(*e820_table_firmware));
 	printk(KERN_INFO "extended physical RAM map:\n");
 	e820__print_table("reserve setup_data");
 }
@@ -1169,7 +1169,7 @@ void __init e820__memory_setup(void)
 
 	who = x86_init.resources.memory_setup();
 
-	memcpy(e820_table_firmware, e820_table, sizeof(struct e820_table));
+	memcpy(e820_table_firmware, e820_table, sizeof(*e820_table_firmware));
 
 	pr_info("e820: BIOS-provided physical RAM map:\n");
 	e820__print_table(who);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 42/50] xen, x86/boot/e820: Simplify Xen's xen_e820_table construct
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (40 preceding siblings ...)
  2017-01-28 22:12 ` [PATCH 41/50] x86/boot/e820: Clean up and standardize sizeof() uses Ingo Molnar
@ 2017-01-28 22:12 ` Ingo Molnar
  2017-01-28 22:12 ` [PATCH 43/50] x86/boot/e820: Simplify the e820__update_table() interface Ingo Molnar
                   ` (7 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:12 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

The Xen guest memory setup code has:

	static struct e820_entry xen_e820_table[E820_MAX_ENTRIES] __initdata;
	static u32 xen_e820_table_entries __initdata;

... which is really a 'struct e820_table', open-coded.

Convert the Xen code over to use a single struct e820_table, as this
will allow the simplification of the e820__update_table() API.

No intended change in functionality, but not runtime tested.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/xen/setup.c | 70 +++++++++++++++++++++++++++++++++-------------------------------------
 1 file changed, 33 insertions(+), 37 deletions(-)

diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
index 381a0d3577a7..cf29abfc392c 100644
--- a/arch/x86/xen/setup.c
+++ b/arch/x86/xen/setup.c
@@ -41,8 +41,7 @@ struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata;
 unsigned long xen_released_pages;
 
 /* E820 map used during setting up memory. */
-static struct e820_entry xen_e820_table[E820_MAX_ENTRIES] __initdata;
-static u32 xen_e820_table_entries __initdata;
+static struct e820_table xen_e820_table __initdata;
 
 /*
  * Buffer used to remap identity mapped pages. We only need the virtual space.
@@ -198,11 +197,11 @@ void __init xen_inv_extra_mem(void)
  */
 static unsigned long __init xen_find_pfn_range(unsigned long *min_pfn)
 {
-	const struct e820_entry *entry = xen_e820_table;
+	const struct e820_entry *entry = xen_e820_table.entries;
 	unsigned int i;
 	unsigned long done = 0;
 
-	for (i = 0; i < xen_e820_table_entries; i++, entry++) {
+	for (i = 0; i < xen_e820_table.nr_entries; i++, entry++) {
 		unsigned long s_pfn;
 		unsigned long e_pfn;
 
@@ -457,7 +456,7 @@ static unsigned long __init xen_foreach_remap_area(unsigned long nr_pages,
 {
 	phys_addr_t start = 0;
 	unsigned long ret_val = 0;
-	const struct e820_entry *entry = xen_e820_table;
+	const struct e820_entry *entry = xen_e820_table.entries;
 	int i;
 
 	/*
@@ -471,9 +470,9 @@ static unsigned long __init xen_foreach_remap_area(unsigned long nr_pages,
 	 * example) the DMI tables in a reserved region that begins on
 	 * a non-page boundary.
 	 */
-	for (i = 0; i < xen_e820_table_entries; i++, entry++) {
+	for (i = 0; i < xen_e820_table.nr_entries; i++, entry++) {
 		phys_addr_t end = entry->addr + entry->size;
-		if (entry->type == E820_TYPE_RAM || i == xen_e820_table_entries - 1) {
+		if (entry->type == E820_TYPE_RAM || i == xen_e820_table.nr_entries - 1) {
 			unsigned long start_pfn = PFN_DOWN(start);
 			unsigned long end_pfn = PFN_UP(end);
 
@@ -601,10 +600,10 @@ static void __init xen_align_and_add_e820_region(phys_addr_t start,
 
 static void __init xen_ignore_unusable(void)
 {
-	struct e820_entry *entry = xen_e820_table;
+	struct e820_entry *entry = xen_e820_table.entries;
 	unsigned int i;
 
-	for (i = 0; i < xen_e820_table_entries; i++, entry++) {
+	for (i = 0; i < xen_e820_table.nr_entries; i++, entry++) {
 		if (entry->type == E820_TYPE_UNUSABLE)
 			entry->type = E820_TYPE_RAM;
 	}
@@ -620,9 +619,9 @@ bool __init xen_is_e820_reserved(phys_addr_t start, phys_addr_t size)
 		return false;
 
 	end = start + size;
-	entry = xen_e820_table;
+	entry = xen_e820_table.entries;
 
-	for (mapcnt = 0; mapcnt < xen_e820_table_entries; mapcnt++) {
+	for (mapcnt = 0; mapcnt < xen_e820_table.nr_entries; mapcnt++) {
 		if (entry->type == E820_TYPE_RAM && entry->addr <= start &&
 		    (entry->addr + entry->size) >= end)
 			return false;
@@ -645,9 +644,9 @@ phys_addr_t __init xen_find_free_area(phys_addr_t size)
 {
 	unsigned mapcnt;
 	phys_addr_t addr, start;
-	struct e820_entry *entry = xen_e820_table;
+	struct e820_entry *entry = xen_e820_table.entries;
 
-	for (mapcnt = 0; mapcnt < xen_e820_table_entries; mapcnt++, entry++) {
+	for (mapcnt = 0; mapcnt < xen_e820_table.nr_entries; mapcnt++, entry++) {
 		if (entry->type != E820_TYPE_RAM || entry->size < size)
 			continue;
 		start = entry->addr;
@@ -750,8 +749,8 @@ char * __init xen_memory_setup(void)
 	max_pfn = min(max_pfn, xen_start_info->nr_pages);
 	mem_end = PFN_PHYS(max_pfn);
 
-	memmap.nr_entries = ARRAY_SIZE(xen_e820_table);
-	set_xen_guest_handle(memmap.buffer, xen_e820_table);
+	memmap.nr_entries = ARRAY_SIZE(xen_e820_table.entries);
+	set_xen_guest_handle(memmap.buffer, xen_e820_table.entries);
 
 	op = xen_initial_domain() ?
 		XENMEM_machine_memory_map :
@@ -760,16 +759,16 @@ char * __init xen_memory_setup(void)
 	if (rc == -ENOSYS) {
 		BUG_ON(xen_initial_domain());
 		memmap.nr_entries = 1;
-		xen_e820_table[0].addr = 0ULL;
-		xen_e820_table[0].size = mem_end;
+		xen_e820_table.entries[0].addr = 0ULL;
+		xen_e820_table.entries[0].size = mem_end;
 		/* 8MB slack (to balance backend allocations). */
-		xen_e820_table[0].size += 8ULL << 20;
-		xen_e820_table[0].type = E820_TYPE_RAM;
+		xen_e820_table.entries[0].size += 8ULL << 20;
+		xen_e820_table.entries[0].type = E820_TYPE_RAM;
 		rc = 0;
 	}
 	BUG_ON(rc);
 	BUG_ON(memmap.nr_entries == 0);
-	xen_e820_table_entries = memmap.nr_entries;
+	xen_e820_table.nr_entries = memmap.nr_entries;
 
 	/*
 	 * Xen won't allow a 1:1 mapping to be created to UNUSABLE
@@ -783,8 +782,7 @@ char * __init xen_memory_setup(void)
 		xen_ignore_unusable();
 
 	/* Make sure the Xen-supplied memory map is well-ordered. */
-	e820__update_table(xen_e820_table, ARRAY_SIZE(xen_e820_table),
-			  &xen_e820_table_entries);
+	e820__update_table(xen_e820_table.entries, ARRAY_SIZE(xen_e820_table.entries), &xen_e820_table.nr_entries);
 
 	max_pages = xen_get_max_pages();
 
@@ -811,13 +809,13 @@ char * __init xen_memory_setup(void)
 	extra_pages = min3(EXTRA_MEM_RATIO * min(max_pfn, PFN_DOWN(MAXMEM)),
 			   extra_pages, max_pages - max_pfn);
 	i = 0;
-	addr = xen_e820_table[0].addr;
-	size = xen_e820_table[0].size;
-	while (i < xen_e820_table_entries) {
+	addr = xen_e820_table.entries[0].addr;
+	size = xen_e820_table.entries[0].size;
+	while (i < xen_e820_table.nr_entries) {
 		bool discard = false;
 
 		chunk_size = size;
-		type = xen_e820_table[i].type;
+		type = xen_e820_table.entries[i].type;
 
 		if (type == E820_TYPE_RAM) {
 			if (addr < mem_end) {
@@ -840,9 +838,9 @@ char * __init xen_memory_setup(void)
 		size -= chunk_size;
 		if (size == 0) {
 			i++;
-			if (i < xen_e820_table_entries) {
-				addr = xen_e820_table[i].addr;
-				size = xen_e820_table[i].size;
+			if (i < xen_e820_table.nr_entries) {
+				addr = xen_e820_table.entries[i].addr;
+				size = xen_e820_table.entries[i].size;
 			}
 		}
 	}
@@ -923,21 +921,19 @@ char * __init xen_auto_xlated_memory_setup(void)
 	int i;
 	int rc;
 
-	memmap.nr_entries = ARRAY_SIZE(xen_e820_table);
-	set_xen_guest_handle(memmap.buffer, xen_e820_table);
+	memmap.nr_entries = ARRAY_SIZE(xen_e820_table.entries);
+	set_xen_guest_handle(memmap.buffer, xen_e820_table.entries);
 
 	rc = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap);
 	if (rc < 0)
 		panic("No memory map (%d)\n", rc);
 
-	xen_e820_table_entries = memmap.nr_entries;
+	xen_e820_table.nr_entries = memmap.nr_entries;
 
-	e820__update_table(xen_e820_table, ARRAY_SIZE(xen_e820_table),
-			  &xen_e820_table_entries);
+	e820__update_table(xen_e820_table.entries, ARRAY_SIZE(xen_e820_table.entries), &xen_e820_table.nr_entries);
 
-	for (i = 0; i < xen_e820_table_entries; i++)
-		e820__range_add(xen_e820_table[i].addr, xen_e820_table[i].size,
-				xen_e820_table[i].type);
+	for (i = 0; i < xen_e820_table.nr_entries; i++)
+		e820__range_add(xen_e820_table.entries[i].addr, xen_e820_table.entries[i].size, xen_e820_table.entries[i].type);
 
 	/* Remove p2m info, it is not needed. */
 	xen_start_info->mfn_list = 0;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 43/50] x86/boot/e820: Simplify the e820__update_table() interface
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (41 preceding siblings ...)
  2017-01-28 22:12 ` [PATCH 42/50] xen, x86/boot/e820: Simplify Xen's xen_e820_table construct Ingo Molnar
@ 2017-01-28 22:12 ` Ingo Molnar
  2017-01-28 22:12 ` [PATCH 44/50] x86/boot/e820: Clean up __e820__update_table() et al Ingo Molnar
                   ` (6 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:12 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

The e820__update_table() parameters are pretty complex:

  arch/x86/include/asm/e820/api.h:extern int  e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map);

But 90% of the usage is trivial:

  arch/x86/kernel/e820.c:	if (e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries))
  arch/x86/kernel/e820.c:	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
  arch/x86/kernel/e820.c:	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
  arch/x86/kernel/e820.c:		if (e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries) < 0)
  arch/x86/kernel/e820.c:	e820__update_table(boot_params.e820_table, ARRAY_SIZE(boot_params.e820_table), &new_nr);
  arch/x86/kernel/early-quirks.c:	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
  arch/x86/kernel/setup.c:	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
  arch/x86/kernel/setup.c:		e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
  arch/x86/platform/efi/efi.c:	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
  arch/x86/xen/setup.c:	e820__update_table(xen_e820_table.entries, ARRAY_SIZE(xen_e820_table.entries),
  arch/x86/xen/setup.c:	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
  arch/x86/xen/setup.c:	e820__update_table(xen_e820_table.entries, ARRAY_SIZE(xen_e820_table.entries),

as it only uses an exiting struct e820_table's entries array, its size and
its current number of entries as input and output arguments.

Only one use is non-trivial:

  arch/x86/kernel/e820.c:	e820__update_table(boot_params.e820_table, ARRAY_SIZE(boot_params.e820_table), &new_nr);

... which call updates the E820 table in the zeropage in-situ, and the layout there does not
match that of 'struct e820_table' (in particular nr_entries is at a different offset,
hardcoded by the boot protocol).

Simplify all this by introducing a low level __e820__update_table() API that
the zeropage update call can use, and simplifying the main e820__update_table()
call signature down to:

	int e820__update_table(struct e820_table *table);

This visibly simplifies all the call sites:

  arch/x86/include/asm/e820/api.h:extern int  e820__update_table(struct e820_table *table);
  arch/x86/include/asm/e820/types.h: * call to e820__update_table() to remove duplicates.  The allowance
  arch/x86/kernel/e820.c: * The return value from e820__update_table() is zero if it
  arch/x86/kernel/e820.c:int __init e820__update_table(struct e820_table *table)
  arch/x86/kernel/e820.c:	if (e820__update_table(e820_table))
  arch/x86/kernel/e820.c:	e820__update_table(e820_table_firmware);
  arch/x86/kernel/e820.c:	e820__update_table(e820_table);
  arch/x86/kernel/e820.c:	e820__update_table(e820_table);
  arch/x86/kernel/e820.c:		if (e820__update_table(e820_table) < 0)
  arch/x86/kernel/early-quirks.c:	e820__update_table(e820_table);
  arch/x86/kernel/setup.c:	e820__update_table(e820_table);
  arch/x86/kernel/setup.c:		e820__update_table(e820_table);
  arch/x86/platform/efi/efi.c:	e820__update_table(e820_table);
  arch/x86/xen/setup.c:	e820__update_table(&xen_e820_table);
  arch/x86/xen/setup.c:	e820__update_table(e820_table);
  arch/x86/xen/setup.c:	e820__update_table(&xen_e820_table);

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h |  2 +-
 arch/x86/kernel/e820.c          | 19 ++++++++++++-------
 arch/x86/kernel/early-quirks.c  |  2 +-
 arch/x86/kernel/setup.c         |  4 ++--
 arch/x86/platform/efi/efi.c     |  2 +-
 arch/x86/xen/setup.c            |  9 ++++-----
 6 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 4c35c36c62d5..7d5dfc2f9e91 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -16,7 +16,7 @@ extern u64  e820__range_update(u64 start, u64 size, enum e820_type old_type, enu
 extern u64  e820__range_remove(u64 start, u64 size, enum e820_type old_type, int checktype);
 
 extern void e820__print_table(char *who);
-extern int  e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map);
+extern int  e820__update_table(struct e820_table *table);
 extern void e820__update_table_print(void);
 
 extern unsigned long e820_end_of_ram_pfn(void);
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index da69addf6c34..49823e0a7aea 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -259,7 +259,7 @@ static int __init cpcompare(const void *a, const void *b)
 	return (ap->addr != ap->pbios->addr) - (bp->addr != bp->pbios->addr);
 }
 
-int __init e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map)
+static int __init __e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map)
 {
 	static struct change_member change_point_list[2*E820_MAX_ENTRIES] __initdata;
 	static struct change_member *change_point[2*E820_MAX_ENTRIES] __initdata;
@@ -368,6 +368,11 @@ int __init e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *p
 	return 0;
 }
 
+int __init e820__update_table(struct e820_table *table)
+{
+	return __e820__update_table(table->entries, ARRAY_SIZE(table->entries), &table->nr_entries);
+}
+
 static int __init __append_e820_table(struct e820_entry *biosmap, int nr_map)
 {
 	while (nr_map) {
@@ -548,7 +553,7 @@ u64 __init e820__range_remove(u64 start, u64 size, enum e820_type old_type, int
 
 void __init e820__update_table_print(void)
 {
-	if (e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries))
+	if (e820__update_table(e820_table))
 		return;
 
 	pr_info("e820: modified physical RAM map:\n");
@@ -557,7 +562,7 @@ void __init e820__update_table_print(void)
 
 static void __init e820__update_table_firmware(void)
 {
-	e820__update_table(e820_table_firmware->entries, ARRAY_SIZE(e820_table_firmware->entries), &e820_table_firmware->nr_entries);
+	e820__update_table(e820_table_firmware);
 }
 
 #define MAX_GAP_END 0x100000000ull
@@ -676,7 +681,7 @@ void __init e820__memory_setup_extended(u64 phys_addr, u32 data_len)
 	extmap = (struct e820_entry *)(sdata->data);
 
 	__append_e820_table(extmap, entries);
-	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
+	e820__update_table(e820_table);
 
 	early_memunmap(sdata, data_len);
 	pr_info("e820: extended physical RAM map:\n");
@@ -931,7 +936,7 @@ void __init e820_reserve_setup_data(void)
 		early_memunmap(data, sizeof(*data));
 	}
 
-	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
+	e820__update_table(e820_table);
 	memcpy(e820_table_firmware, e820_table, sizeof(*e820_table_firmware));
 	printk(KERN_INFO "extended physical RAM map:\n");
 	e820__print_table("reserve setup_data");
@@ -945,7 +950,7 @@ void __init e820_reserve_setup_data(void)
 void __init e820__finish_early_params(void)
 {
 	if (userdef) {
-		if (e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries) < 0)
+		if (e820__update_table(e820_table) < 0)
 			early_panic("Invalid user supplied memory map");
 
 		pr_info("e820: user-defined physical RAM map:\n");
@@ -1132,7 +1137,7 @@ char *__init e820__memory_setup_default(void)
 	 * the next section from 1mb->appropriate_mem_k
 	 */
 	new_nr = boot_params.e820_entries;
-	e820__update_table(boot_params.e820_table, ARRAY_SIZE(boot_params.e820_table), &new_nr);
+	__e820__update_table(boot_params.e820_table, ARRAY_SIZE(boot_params.e820_table), &new_nr);
 	boot_params.e820_entries = new_nr;
 
 	if (append_e820_table(boot_params.e820_table, boot_params.e820_entries) < 0) {
diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c
index 2220a4c03adf..ff7e4b3988ed 100644
--- a/arch/x86/kernel/early-quirks.c
+++ b/arch/x86/kernel/early-quirks.c
@@ -547,7 +547,7 @@ intel_graphics_stolen(int num, int slot, int func,
 
 	/* Mark this space as reserved */
 	e820__range_add(base, size, E820_TYPE_RESERVED);
-	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
+	e820__update_table(e820_table);
 }
 
 static void __init intel_graphics_quirks(int num, int slot, int func)
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 074c86a0ee86..acb2db02ec81 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -740,7 +740,7 @@ static void __init trim_bios_range(void)
 	 */
 	e820__range_remove(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_TYPE_RAM, 1);
 
-	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
+	e820__update_table(e820_table);
 }
 
 /* called before trim_bios_range() to spare extra sanitize */
@@ -1033,7 +1033,7 @@ void __init setup_arch(char **cmdline_p)
 	if (ppro_with_ram_bug()) {
 		e820__range_update(0x70000000ULL, 0x40000ULL, E820_TYPE_RAM,
 				  E820_TYPE_RESERVED);
-		e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
+		e820__update_table(e820_table);
 		printk(KERN_INFO "fixed physical RAM map:\n");
 		e820__print_table("bad_ppro");
 	}
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index 14d0a6b1eee1..2f7f7605fee0 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -167,7 +167,7 @@ static void __init do_add_efi_memmap(void)
 		}
 		e820__range_add(start, size, e820_type);
 	}
-	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
+	e820__update_table(e820_table);
 }
 
 int __init efi_memblock_x86_reserve_range(void)
diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
index cf29abfc392c..a5bf7c451435 100644
--- a/arch/x86/xen/setup.c
+++ b/arch/x86/xen/setup.c
@@ -782,7 +782,7 @@ char * __init xen_memory_setup(void)
 		xen_ignore_unusable();
 
 	/* Make sure the Xen-supplied memory map is well-ordered. */
-	e820__update_table(xen_e820_table.entries, ARRAY_SIZE(xen_e820_table.entries), &xen_e820_table.nr_entries);
+	e820__update_table(&xen_e820_table);
 
 	max_pages = xen_get_max_pages();
 
@@ -856,10 +856,9 @@ char * __init xen_memory_setup(void)
 	 * reserve ISA memory anyway because too many things poke
 	 * about in there.
 	 */
-	e820__range_add(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS,
-			E820_TYPE_RESERVED);
+	e820__range_add(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_TYPE_RESERVED);
 
-	e820__update_table(e820_table->entries, ARRAY_SIZE(e820_table->entries), &e820_table->nr_entries);
+	e820__update_table(e820_table);
 
 	/*
 	 * Check whether the kernel itself conflicts with the target E820 map.
@@ -930,7 +929,7 @@ char * __init xen_auto_xlated_memory_setup(void)
 
 	xen_e820_table.nr_entries = memmap.nr_entries;
 
-	e820__update_table(xen_e820_table.entries, ARRAY_SIZE(xen_e820_table.entries), &xen_e820_table.nr_entries);
+	e820__update_table(&xen_e820_table);
 
 	for (i = 0; i < xen_e820_table.nr_entries; i++)
 		e820__range_add(xen_e820_table.entries[i].addr, xen_e820_table.entries[i].size, xen_e820_table.entries[i].type);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 44/50] x86/boot/e820: Clean up __e820__update_table() et al
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (42 preceding siblings ...)
  2017-01-28 22:12 ` [PATCH 43/50] x86/boot/e820: Simplify the e820__update_table() interface Ingo Molnar
@ 2017-01-28 22:12 ` Ingo Molnar
  2017-01-28 22:12 ` [PATCH 45/50] x86/boot/e820: Document e820__reserve_setup_data() Ingo Molnar
                   ` (5 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:12 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

The __e820__update_table() function has various weirdly named variables,
such as 'pbios', 'biosmap' and 'pnr_map' which are pretty confusing
and actively misleading at times.

This weird naming found its way into other functions as well, such as
__append_e820_table() and append_e820_table().

Standardize the naming to make it all much easier to read:

	biosmap  ->  entries
	pbios    ->  entry
	nr_map   ->  nr_entries
        pnr_map  ->  nr_entries
	...

Also clean up the types used: entry indices routinely mixed u32 and int,
standardize on u32 thoughout.

Update the comments as well, while at it.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/e820.c | 120 +++++++++++++++++++++++++++++++++++----------------------------------
 1 file changed, 61 insertions(+), 59 deletions(-)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 49823e0a7aea..7dc430c03acb 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -175,23 +175,23 @@ void __init e820__print_table(char *who)
 }
 
 /*
- * Sanitize the BIOS E820 map.
+ * Sanitize an E820 map.
  *
- * Some E820 responses include overlapping entries. The following
+ * Some E820 layouts include overlapping entries. The following
  * replaces the original E820 map with a new one, removing overlaps,
  * and resolving conflicting memory types in favor of highest
  * numbered type.
  *
- * The input parameter biosmap points to an array of 'struct
- * e820_entry' which on entry has elements in the range [0, *pnr_map)
- * valid, and which has space for up to max_nr_map entries.
+ * The input parameter 'entries' points to an array of 'struct
+ * e820_entry' which on entry has elements in the range [0, *nr_entries)
+ * valid, and which has space for up to max_nr_entries entries.
  * On return, the resulting sanitized E820 map entries will be in
- * overwritten in the same location, starting at biosmap.
+ * overwritten in the same location, starting at 'entries'.
  *
- * The integer pointed to by pnr_map must be valid on entry (the
- * current number of valid entries located at biosmap). If the
- * sanitizing succeeds the *pnr_map will be updated with the new
- * number of valid entries (something no more than max_nr_map).
+ * The integer pointed to by nr_entries must be valid on entry (the
+ * current number of valid entries located at 'entries'). If the
+ * sanitizing succeeds the *nr_entries will be updated with the new
+ * number of valid entries (something no more than max_nr_entries).
  *
  * The return value from e820__update_table() is zero if it
  * successfully 'sanitized' the map entries passed in, and is -1
@@ -236,8 +236,8 @@ void __init e820__print_table(char *who)
  *	   ______________________4_
  */
 struct change_member {
-	/* Pointer to the original BIOS entry: */
-	struct e820_entry	*pbios;
+	/* Pointer to the original entry: */
+	struct e820_entry	*entry;
 	/* Address for this change point: */
 	unsigned long long	addr;
 };
@@ -256,33 +256,33 @@ static int __init cpcompare(const void *a, const void *b)
 	if (ap->addr != bp->addr)
 		return ap->addr > bp->addr ? 1 : -1;
 
-	return (ap->addr != ap->pbios->addr) - (bp->addr != bp->pbios->addr);
+	return (ap->addr != ap->entry->addr) - (bp->addr != bp->entry->addr);
 }
 
-static int __init __e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map)
+static int __init __e820__update_table(struct e820_entry *entries, u32 max_nr_entries, u32 *nr_entries)
 {
 	static struct change_member change_point_list[2*E820_MAX_ENTRIES] __initdata;
 	static struct change_member *change_point[2*E820_MAX_ENTRIES] __initdata;
 	static struct e820_entry *overlap_list[E820_MAX_ENTRIES] __initdata;
-	static struct e820_entry new_bios[E820_MAX_ENTRIES] __initdata;
+	static struct e820_entry new_entries[E820_MAX_ENTRIES] __initdata;
 	enum e820_type current_type, last_type;
 	unsigned long long last_addr;
-	int chgidx;
-	int overlap_entries;
-	int new_bios_entry;
-	int old_nr, new_nr, chg_nr;
-	int i;
+	u32 chgidx;
+	u32 overlap_entries;
+	u32 new_nr_entries;
+	u32 old_nr, new_nr, chg_nr;
+	u32 i;
 
 	/* If there's only one memory region, don't bother: */
-	if (*pnr_map < 2)
+	if (*nr_entries < 2)
 		return -1;
 
-	old_nr = *pnr_map;
-	BUG_ON(old_nr > max_nr_map);
+	old_nr = *nr_entries;
+	BUG_ON(old_nr > max_nr_entries);
 
-	/* Bail out if we find any unreasonable addresses in the BIOS map: */
+	/* Bail out if we find any unreasonable addresses in the map: */
 	for (i = 0; i < old_nr; i++) {
-		if (biosmap[i].addr + biosmap[i].size < biosmap[i].addr)
+		if (entries[i].addr + entries[i].size < entries[i].addr)
 			return -1;
 	}
 
@@ -296,11 +296,11 @@ static int __init __e820__update_table(struct e820_entry *biosmap, int max_nr_ma
 	 */
 	chgidx = 0;
 	for (i = 0; i < old_nr; i++)	{
-		if (biosmap[i].size != 0) {
-			change_point[chgidx]->addr	= biosmap[i].addr;
-			change_point[chgidx++]->pbios	= &biosmap[i];
-			change_point[chgidx]->addr	= biosmap[i].addr + biosmap[i].size;
-			change_point[chgidx++]->pbios	= &biosmap[i];
+		if (entries[i].size != 0) {
+			change_point[chgidx]->addr	= entries[i].addr;
+			change_point[chgidx++]->entry	= &entries[i];
+			change_point[chgidx]->addr	= entries[i].addr + entries[i].size;
+			change_point[chgidx++]->entry	= &entries[i];
 		}
 	}
 	chg_nr = chgidx;
@@ -308,22 +308,22 @@ static int __init __e820__update_table(struct e820_entry *biosmap, int max_nr_ma
 	/* Sort change-point list by memory addresses (low -> high): */
 	sort(change_point, chg_nr, sizeof(*change_point), cpcompare, NULL);
 
-	/* Create a new BIOS memory map, removing overlaps: */
+	/* Create a new memory map, removing overlaps: */
 	overlap_entries = 0;	 /* Number of entries in the overlap table */
-	new_bios_entry = 0;	 /* Index for creating new bios map entries */
+	new_nr_entries = 0;	 /* Index for creating new map entries */
 	last_type = 0;		 /* Start with undefined memory type */
 	last_addr = 0;		 /* Start with 0 as last starting address */
 
-	/* Loop through change-points, determining effect on the new BIOS map: */
+	/* Loop through change-points, determining effect on the new map: */
 	for (chgidx = 0; chgidx < chg_nr; chgidx++) {
-		/* Keep track of all overlapping BIOS entries */
-		if (change_point[chgidx]->addr == change_point[chgidx]->pbios->addr) {
+		/* Keep track of all overlapping entries */
+		if (change_point[chgidx]->addr == change_point[chgidx]->entry->addr) {
 			/* Add map entry to overlap list (> 1 entry implies an overlap) */
-			overlap_list[overlap_entries++] = change_point[chgidx]->pbios;
+			overlap_list[overlap_entries++] = change_point[chgidx]->entry;
 		} else {
 			/* Remove entry from list (order independent, so swap with last): */
 			for (i = 0; i < overlap_entries; i++) {
-				if (overlap_list[i] == change_point[chgidx]->pbios)
+				if (overlap_list[i] == change_point[chgidx]->entry)
 					overlap_list[i] = overlap_list[overlap_entries-1];
 			}
 			overlap_entries--;
@@ -339,31 +339,31 @@ static int __init __e820__update_table(struct e820_entry *biosmap, int max_nr_ma
 				current_type = overlap_list[i]->type;
 		}
 
-		/* Continue building up new BIOS map based on this information: */
+		/* Continue building up new map based on this information: */
 		if (current_type != last_type || current_type == E820_TYPE_PRAM) {
 			if (last_type != 0)	 {
-				new_bios[new_bios_entry].size = change_point[chgidx]->addr - last_addr;
+				new_entries[new_nr_entries].size = change_point[chgidx]->addr - last_addr;
 				/* Move forward only if the new size was non-zero: */
-				if (new_bios[new_bios_entry].size != 0)
-					/* No more space left for new BIOS entries? */
-					if (++new_bios_entry >= max_nr_map)
+				if (new_entries[new_nr_entries].size != 0)
+					/* No more space left for new entries? */
+					if (++new_nr_entries >= max_nr_entries)
 						break;
 			}
 			if (current_type != 0)	{
-				new_bios[new_bios_entry].addr = change_point[chgidx]->addr;
-				new_bios[new_bios_entry].type = current_type;
+				new_entries[new_nr_entries].addr = change_point[chgidx]->addr;
+				new_entries[new_nr_entries].type = current_type;
 				last_addr = change_point[chgidx]->addr;
 			}
 			last_type = current_type;
 		}
 	}
 
-	/* Retain count for new BIOS entries: */
-	new_nr = new_bios_entry;
+	/* Retain count for the new entries: */
+	new_nr = new_nr_entries;
 
-	/* Copy new BIOS mapping into the original location: */
-	memcpy(biosmap, new_bios, new_nr*sizeof(*biosmap));
-	*pnr_map = new_nr;
+	/* Copy the new entries into the original location: */
+	memcpy(entries, new_entries, new_nr*sizeof(*entries));
+	*nr_entries = new_nr;
 
 	return 0;
 }
@@ -373,13 +373,15 @@ int __init e820__update_table(struct e820_table *table)
 	return __e820__update_table(table->entries, ARRAY_SIZE(table->entries), &table->nr_entries);
 }
 
-static int __init __append_e820_table(struct e820_entry *biosmap, int nr_map)
+static int __init __append_e820_table(struct e820_entry *entries, u32 nr_entries)
 {
-	while (nr_map) {
-		u64 start = biosmap->addr;
-		u64 size = biosmap->size;
+	struct e820_entry *entry = entries;
+
+	while (nr_entries) {
+		u64 start = entry->addr;
+		u64 size = entry->size;
 		u64 end = start + size - 1;
-		u32 type = biosmap->type;
+		u32 type = entry->type;
 
 		/* Ignore the entry on 64-bit overflow: */
 		if (start > end && likely(size))
@@ -387,8 +389,8 @@ static int __init __append_e820_table(struct e820_entry *biosmap, int nr_map)
 
 		e820__range_add(start, size, type);
 
-		biosmap++;
-		nr_map--;
+		entry++;
+		nr_entries--;
 	}
 	return 0;
 }
@@ -402,13 +404,13 @@ static int __init __append_e820_table(struct e820_entry *biosmap, int nr_map)
  * will have given us a memory map that we can use to properly
  * set up memory.  If we aren't, we'll fake a memory map.
  */
-static int __init append_e820_table(struct e820_entry *biosmap, int nr_map)
+static int __init append_e820_table(struct e820_entry *entries, u32 nr_entries)
 {
 	/* Only one memory region (or negative)? Ignore it */
-	if (nr_map < 2)
+	if (nr_entries < 2)
 		return -1;
 
-	return __append_e820_table(biosmap, nr_map);
+	return __append_e820_table(entries, nr_entries);
 }
 
 static u64 __init
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 45/50] x86/boot/e820: Document e820__reserve_setup_data()
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (43 preceding siblings ...)
  2017-01-28 22:12 ` [PATCH 44/50] x86/boot/e820: Clean up __e820__update_table() et al Ingo Molnar
@ 2017-01-28 22:12 ` Ingo Molnar
  2017-01-28 22:12 ` [PATCH 46/50] x86/boot/e820: Use bool in query APIs Ingo Molnar
                   ` (4 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:12 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

Also clean it up a bit.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h |  4 ++--
 arch/x86/kernel/e820.c          | 11 +++++++++--
 arch/x86/kernel/setup.c         |  3 +--
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 7d5dfc2f9e91..fae7f3e11d9a 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -22,10 +22,10 @@ extern void e820__update_table_print(void);
 extern unsigned long e820_end_of_ram_pfn(void);
 extern unsigned long e820_end_of_low_ram_pfn(void);
 
-extern u64  e820__memblock_alloc_reserved(u64 sizet, u64 align);
+extern u64  e820__memblock_alloc_reserved(u64 size, u64 align);
 extern void e820__memblock_setup(void);
 
-extern void e820_reserve_setup_data(void);
+extern void e820__reserve_setup_data(void);
 extern void e820__finish_early_params(void);
 extern void e820_reserve_resources(void);
 extern void e820_reserve_resources_late(void);
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 7dc430c03acb..114625890337 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -922,7 +922,12 @@ static int __init parse_memmap_opt(char *str)
 }
 early_param("memmap", parse_memmap_opt);
 
-void __init e820_reserve_setup_data(void)
+/*
+ * Reserve all entries from the bootloader's extensible data nodes list,
+ * because if present we are going to use it later on to fetch e820
+ * entries from it:
+ */
+void __init e820__reserve_setup_data(void)
 {
 	struct setup_data *data;
 	u64 pa_data;
@@ -939,8 +944,10 @@ void __init e820_reserve_setup_data(void)
 	}
 
 	e820__update_table(e820_table);
+
 	memcpy(e820_table_firmware, e820_table, sizeof(*e820_table_firmware));
-	printk(KERN_INFO "extended physical RAM map:\n");
+
+	pr_info("extended physical RAM map:\n");
 	e820__print_table("reserve setup_data");
 }
 
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index acb2db02ec81..4ac8ae8a7573 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1003,8 +1003,7 @@ void __init setup_arch(char **cmdline_p)
 		early_dump_pci_devices();
 #endif
 
-	/* update the e820_table_firmware too */
-	e820_reserve_setup_data();
+	e820__reserve_setup_data();
 	e820__finish_early_params();
 
 	if (efi_enabled(EFI_BOOT))
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 46/50] x86/boot/e820: Use bool in query APIs
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (44 preceding siblings ...)
  2017-01-28 22:12 ` [PATCH 45/50] x86/boot/e820: Document e820__reserve_setup_data() Ingo Molnar
@ 2017-01-28 22:12 ` Ingo Molnar
  2017-01-28 22:12 ` [PATCH 47/50] x86/boot/e820: Rename e820_reserve_resources*() to e820__reserve_resources*() Ingo Molnar
                   ` (3 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:12 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

Change e820__mapped_any() and e820__mapped_all()'s return type and
e820__range_remove()'s check_type parameter to bool.

Propagate it into arch/x86/pci/mmconfig-shared.c as this change
affects a function signature there too.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h |  6 +++---
 arch/x86/kernel/e820.c          | 10 +++++-----
 arch/x86/pci/mmconfig-shared.c  | 14 +++++++-------
 3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index fae7f3e11d9a..78a0feb84c9f 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -8,12 +8,12 @@ extern struct e820_table *e820_table_firmware;
 
 extern unsigned long pci_mem_start;
 
-extern int  e820__mapped_any(u64 start, u64 end, enum e820_type type);
-extern int  e820__mapped_all(u64 start, u64 end, enum e820_type type);
+extern bool e820__mapped_any(u64 start, u64 end, enum e820_type type);
+extern bool e820__mapped_all(u64 start, u64 end, enum e820_type type);
 
 extern void e820__range_add   (u64 start, u64 size, enum e820_type type);
 extern u64  e820__range_update(u64 start, u64 size, enum e820_type old_type, enum e820_type new_type);
-extern u64  e820__range_remove(u64 start, u64 size, enum e820_type old_type, int checktype);
+extern u64  e820__range_remove(u64 start, u64 size, enum e820_type old_type, bool check_type);
 
 extern void e820__print_table(char *who);
 extern int  e820__update_table(struct e820_table *table);
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 114625890337..aa80166a0ec6 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -68,7 +68,7 @@ EXPORT_SYMBOL(pci_mem_start);
  * This function checks if any part of the range <start,end> is mapped
  * with type.
  */
-int e820__mapped_any(u64 start, u64 end, enum e820_type type)
+bool e820__mapped_any(u64 start, u64 end, enum e820_type type)
 {
 	int i;
 
@@ -91,7 +91,7 @@ EXPORT_SYMBOL_GPL(e820__mapped_any);
  * Note: this function only works correctly once the E820 table is sorted and
  * not-overlapping (at least for the range specified), which is the case normally.
  */
-int __init e820__mapped_all(u64 start, u64 end, enum e820_type type)
+bool __init e820__mapped_all(u64 start, u64 end, enum e820_type type)
 {
 	int i;
 
@@ -492,7 +492,7 @@ static u64 __init e820__range_update_firmware(u64 start, u64 size, enum e820_typ
 }
 
 /* Remove a range of memory from the E820 table: */
-u64 __init e820__range_remove(u64 start, u64 size, enum e820_type old_type, int checktype)
+u64 __init e820__range_remove(u64 start, u64 size, enum e820_type old_type, bool check_type)
 {
 	int i;
 	u64 end;
@@ -503,7 +503,7 @@ u64 __init e820__range_remove(u64 start, u64 size, enum e820_type old_type, int
 
 	end = start + size;
 	pr_debug("e820: remove [mem %#010Lx-%#010Lx] ", start, end - 1);
-	if (checktype)
+	if (check_type)
 		e820_print_type(old_type);
 	pr_cont("\n");
 
@@ -512,7 +512,7 @@ u64 __init e820__range_remove(u64 start, u64 size, enum e820_type old_type, int
 		u64 final_start, final_end;
 		u64 entry_end;
 
-		if (checktype && entry->type != old_type)
+		if (check_type && entry->type != old_type)
 			continue;
 
 		entry_end = entry->addr + entry->size;
diff --git a/arch/x86/pci/mmconfig-shared.c b/arch/x86/pci/mmconfig-shared.c
index 96057e4b6121..d1b47d5bc9c3 100644
--- a/arch/x86/pci/mmconfig-shared.c
+++ b/arch/x86/pci/mmconfig-shared.c
@@ -423,7 +423,7 @@ static acpi_status find_mboard_resource(acpi_handle handle, u32 lvl,
 	return AE_OK;
 }
 
-static int is_acpi_reserved(u64 start, u64 end, unsigned not_used)
+static bool is_acpi_reserved(u64 start, u64 end, unsigned not_used)
 {
 	struct resource mcfg_res;
 
@@ -440,11 +440,11 @@ static int is_acpi_reserved(u64 start, u64 end, unsigned not_used)
 	return mcfg_res.flags;
 }
 
-typedef int (*check_reserved_t)(u64 start, u64 end, unsigned type);
+typedef bool (*check_reserved_t)(u64 start, u64 end, unsigned type);
 
-static int __ref is_mmconf_reserved(check_reserved_t is_reserved,
-				    struct pci_mmcfg_region *cfg,
-				    struct device *dev, int with_e820)
+static bool __ref is_mmconf_reserved(check_reserved_t is_reserved,
+				     struct pci_mmcfg_region *cfg,
+				     struct device *dev, int with_e820)
 {
 	u64 addr = cfg->res.start;
 	u64 size = resource_size(&cfg->res);
@@ -494,8 +494,8 @@ static int __ref is_mmconf_reserved(check_reserved_t is_reserved,
 	return 1;
 }
 
-static int __ref pci_mmcfg_check_reserved(struct device *dev,
-		  struct pci_mmcfg_region *cfg, int early)
+static bool __ref
+pci_mmcfg_check_reserved(struct device *dev, struct pci_mmcfg_region *cfg, int early)
 {
 	if (!early && !acpi_disabled) {
 		if (is_mmconf_reserved(is_acpi_reserved, cfg, dev, 0))
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 47/50] x86/boot/e820: Rename e820_reserve_resources*() to e820__reserve_resources*()
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (45 preceding siblings ...)
  2017-01-28 22:12 ` [PATCH 46/50] x86/boot/e820: Use bool in query APIs Ingo Molnar
@ 2017-01-28 22:12 ` Ingo Molnar
  2017-01-28 22:12 ` [PATCH 48/50] x86/boot/e820: Rename e820_mark_nosave_regions() to e820__register_nosave_regions() Ingo Molnar
                   ` (2 subsequent siblings)
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:12 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

Also do some minor cleanups.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h |  4 ++--
 arch/x86/kernel/apic/apic.c     |  2 +-
 arch/x86/kernel/e820.c          | 16 +++++++++-------
 arch/x86/kernel/setup.c         |  2 +-
 arch/x86/pci/i386.c             |  2 +-
 5 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 78a0feb84c9f..7d033e9d93c4 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -27,8 +27,8 @@ extern void e820__memblock_setup(void);
 
 extern void e820__reserve_setup_data(void);
 extern void e820__finish_early_params(void);
-extern void e820_reserve_resources(void);
-extern void e820_reserve_resources_late(void);
+extern void e820__reserve_resources(void);
+extern void e820__reserve_resources_late(void);
 
 extern void e820__memory_setup(void);
 extern void e820__memory_setup_extended(u64 phys_addr, u32 data_len);
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 5b7e43eff139..4cb43df5079f 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -2647,7 +2647,7 @@ static int __init lapic_insert_resource(void)
 }
 
 /*
- * need call insert after e820_reserve_resources()
+ * need call insert after e820__reserve_resources()
  * that is using request_resource
  */
 late_initcall(lapic_insert_resource);
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index aa80166a0ec6..552cb9f74dd3 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -629,7 +629,7 @@ __init void e820__setup_pci_gap(void)
 	}
 
 	/*
-	 * e820_reserve_resources_late protect stolen RAM already
+	 * e820__reserve_resources_late() protects stolen RAM already:
 	 */
 	pci_mem_start = gapstart;
 
@@ -1035,7 +1035,7 @@ static bool __init do_mark_busy(u32 type, struct resource *res)
 
 static struct resource __initdata *e820_res;
 
-void __init e820_reserve_resources(void)
+void __init e820__reserve_resources(void)
 {
 	int i;
 	struct resource *res;
@@ -1059,9 +1059,9 @@ void __init e820_reserve_resources(void)
 		res->desc  = e820_type_to_iores_desc(entry);
 
 		/*
-		 * don't register the region that could be conflicted with
-		 * pci device BAR resource and insert them later in
-		 * pcibios_resource_survey()
+		 * Don't register the region that could be conflicted with
+		 * PCI device BAR resources and insert them later in
+		 * pcibios_resource_survey():
 		 */
 		if (do_mark_busy(entry->type, res)) {
 			res->flags |= IORESOURCE_BUSY;
@@ -1077,7 +1077,9 @@ void __init e820_reserve_resources(void)
 	}
 }
 
-/* How much should we pad RAM ending depending on where it is? */
+/*
+ * How much should we pad the end of RAM, depending on where it is?
+ */
 static unsigned long __init ram_alignment(resource_size_t pos)
 {
 	unsigned long mb = pos >> 20;
@@ -1096,7 +1098,7 @@ static unsigned long __init ram_alignment(resource_size_t pos)
 
 #define MAX_RESOURCE_SIZE ((resource_size_t)-1)
 
-void __init e820_reserve_resources_late(void)
+void __init e820__reserve_resources_late(void)
 {
 	int i;
 	struct resource *res;
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 4ac8ae8a7573..34b16fcef131 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1235,7 +1235,7 @@ void __init setup_arch(char **cmdline_p)
 
 	kvm_guest_init();
 
-	e820_reserve_resources();
+	e820__reserve_resources();
 	e820_mark_nosave_regions(max_low_pfn);
 
 	x86_init.resources.reserve_resources();
diff --git a/arch/x86/pci/i386.c b/arch/x86/pci/i386.c
index 9a074431174f..6fa84d531f4f 100644
--- a/arch/x86/pci/i386.c
+++ b/arch/x86/pci/i386.c
@@ -398,7 +398,7 @@ void __init pcibios_resource_survey(void)
 	list_for_each_entry(bus, &pci_root_buses, node)
 		pcibios_allocate_resources(bus, 1);
 
-	e820_reserve_resources_late();
+	e820__reserve_resources_late();
 	/*
 	 * Insert the IO APIC resources after PCI initialization has
 	 * occurred to handle IO APICS that are mapped in on a BAR in
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 48/50] x86/boot/e820: Rename e820_mark_nosave_regions() to e820__register_nosave_regions()
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (46 preceding siblings ...)
  2017-01-28 22:12 ` [PATCH 47/50] x86/boot/e820: Rename e820_reserve_resources*() to e820__reserve_resources*() Ingo Molnar
@ 2017-01-28 22:12 ` Ingo Molnar
  2017-01-28 22:12 ` [PATCH 49/50] x86/boot/e820: Remove unnecessary #include's Ingo Molnar
  2017-01-28 22:12 ` [PATCH 50/50] x86/boot/e820: Rename the remaining E820 APIs to the e820__*() prefix Ingo Molnar
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:12 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

This function is a minor misnomer: it is talking about 'marking' regions
as nosave - while the hibernation API is called register_nosave_region()
and the e820_mark_nosave_regions() is a wrapper around that functionality.

So name it to be in line with the API it is derived from.

( Rename e820_mark_nvs_memory() to e820__register_nvs_regions(), for similar
  reasons. )

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h |  2 +-
 arch/x86/kernel/e820.c          | 10 +++++-----
 arch/x86/kernel/setup.c         |  2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 7d033e9d93c4..2410d4cdbafc 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -36,7 +36,7 @@ extern char *e820__memory_setup_default(void);
 extern void e820__setup_pci_gap(void);
 
 extern void e820_reallocate_tables(void);
-extern void e820_mark_nosave_regions(unsigned long limit_pfn);
+extern void e820__register_nosave_regions(unsigned long limit_pfn);
 
 /*
  * Returns true iff the specified range [start,end) is completely contained inside
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 552cb9f74dd3..97d1250f7507 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -690,15 +690,15 @@ void __init e820__memory_setup_extended(u64 phys_addr, u32 data_len)
 	e820__print_table("extended");
 }
 
-/**
+/*
  * Find the ranges of physical addresses that do not correspond to
- * E820 RAM areas and mark the corresponding pages as 'nosave' for
+ * E820 RAM areas and register the corresponding pages as 'nosave' for
  * hibernation (32-bit) or software suspend and suspend to RAM (64-bit).
  *
  * This function requires the E820 map to be sorted and without any
  * overlapping entries.
  */
-void __init e820_mark_nosave_regions(unsigned long limit_pfn)
+void __init e820__register_nosave_regions(unsigned long limit_pfn)
 {
 	int i;
 	unsigned long pfn = 0;
@@ -724,7 +724,7 @@ void __init e820_mark_nosave_regions(unsigned long limit_pfn)
  * Register ACPI NVS memory regions, so that we can save/restore them during
  * hibernation and the subsequent resume:
  */
-static int __init e820_mark_nvs_memory(void)
+static int __init e820__register_nvs_regions(void)
 {
 	int i;
 
@@ -737,7 +737,7 @@ static int __init e820_mark_nvs_memory(void)
 
 	return 0;
 }
-core_initcall(e820_mark_nvs_memory);
+core_initcall(e820__register_nvs_regions);
 #endif
 
 /*
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 34b16fcef131..0e0b15b53c69 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1236,7 +1236,7 @@ void __init setup_arch(char **cmdline_p)
 	kvm_guest_init();
 
 	e820__reserve_resources();
-	e820_mark_nosave_regions(max_low_pfn);
+	e820__register_nosave_regions(max_low_pfn);
 
 	x86_init.resources.reserve_resources();
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 49/50] x86/boot/e820: Remove unnecessary #include's
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (47 preceding siblings ...)
  2017-01-28 22:12 ` [PATCH 48/50] x86/boot/e820: Rename e820_mark_nosave_regions() to e820__register_nosave_regions() Ingo Molnar
@ 2017-01-28 22:12 ` Ingo Molnar
  2017-01-28 22:12 ` [PATCH 50/50] x86/boot/e820: Rename the remaining E820 APIs to the e820__*() prefix Ingo Molnar
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:12 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

A number of headers were included into e820.c unnecessarily - remove them.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/e820.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 97d1250f7507..9d179676a89e 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -8,13 +8,8 @@
  * quirks and other tweaks, and feeds that into the generic Linux memory
  * allocation code routines via a platform independent interface (memblock, etc.).
  */
-#include <linux/kernel.h>
-#include <linux/types.h>
-#include <linux/init.h>
 #include <linux/crash_dump.h>
-#include <linux/export.h>
 #include <linux/bootmem.h>
-#include <linux/pfn.h>
 #include <linux/suspend.h>
 #include <linux/acpi.h>
 #include <linux/firmware-map.h>
@@ -22,9 +17,7 @@
 #include <linux/sort.h>
 
 #include <asm/e820/api.h>
-#include <asm/proto.h>
 #include <asm/setup.h>
-#include <asm/cpufeature.h>
 
 /*
  * We organize the E820 table into two main data structures:
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH 50/50] x86/boot/e820: Rename the remaining E820 APIs to the e820__*() prefix
  2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
                   ` (48 preceding siblings ...)
  2017-01-28 22:12 ` [PATCH 49/50] x86/boot/e820: Remove unnecessary #include's Ingo Molnar
@ 2017-01-28 22:12 ` Ingo Molnar
  49 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-28 22:12 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

Three more renames left:

   e820_end_of_ram_pfn()      =>  e820__end_of_ram_pfn()
   e820_end_of_low_ram_pfn()  =>  e820__end_of_low_ram_pfn()
   e820_reallocate_tables()   =>  e820__reallocate_tables()

After this all E820 API calls are prefixed with "e820__", making
it much easier to grep for E820 functionality in the kernel.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/e820/api.h | 6 +++---
 arch/x86/kernel/e820.c          | 8 ++++----
 arch/x86/kernel/setup.c         | 6 +++---
 arch/x86/mm/init.c              | 2 +-
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 2410d4cdbafc..8e0f8b85b209 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -19,8 +19,8 @@ extern void e820__print_table(char *who);
 extern int  e820__update_table(struct e820_table *table);
 extern void e820__update_table_print(void);
 
-extern unsigned long e820_end_of_ram_pfn(void);
-extern unsigned long e820_end_of_low_ram_pfn(void);
+extern unsigned long e820__end_of_ram_pfn(void);
+extern unsigned long e820__end_of_low_ram_pfn(void);
 
 extern u64  e820__memblock_alloc_reserved(u64 size, u64 align);
 extern void e820__memblock_setup(void);
@@ -35,7 +35,7 @@ extern void e820__memory_setup_extended(u64 phys_addr, u32 data_len);
 extern char *e820__memory_setup_default(void);
 extern void e820__setup_pci_gap(void);
 
-extern void e820_reallocate_tables(void);
+extern void e820__reallocate_tables(void);
 extern void e820__register_nosave_regions(unsigned long limit_pfn);
 
 /*
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 9d179676a89e..d2c6468a8d38 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -641,7 +641,7 @@ __init void e820__setup_pci_gap(void)
  * All functions which modify them are __init functions, which won't exist
  * after free_initmem().
  */
-__init void e820_reallocate_tables(void)
+__init void e820__reallocate_tables(void)
 {
 	struct e820_table *n;
 	int size;
@@ -803,12 +803,12 @@ static unsigned long __init e820_end_pfn(unsigned long limit_pfn, enum e820_type
 	return last_pfn;
 }
 
-unsigned long __init e820_end_of_ram_pfn(void)
+unsigned long __init e820__end_of_ram_pfn(void)
 {
 	return e820_end_pfn(MAX_ARCH_PFN, E820_TYPE_RAM);
 }
 
-unsigned long __init e820_end_of_low_ram_pfn(void)
+unsigned long __init e820__end_of_low_ram_pfn(void)
 {
 	return e820_end_pfn(1UL << (32 - PAGE_SHIFT), E820_TYPE_RAM);
 }
@@ -867,7 +867,7 @@ static int __init parse_memmap_one(char *p)
 		 * the real memory size before the original memory map is
 		 * reset.
 		 */
-		saved_max_pfn = e820_end_of_ram_pfn();
+		saved_max_pfn = e820__end_of_ram_pfn();
 #endif
 		e820_table->nr_entries = 0;
 		userdef = 1;
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 0e0b15b53c69..a1114ffff0f5 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1044,12 +1044,12 @@ void __init setup_arch(char **cmdline_p)
 	 * partially used pages are not usable - thus
 	 * we are rounding upwards:
 	 */
-	max_pfn = e820_end_of_ram_pfn();
+	max_pfn = e820__end_of_ram_pfn();
 
 	/* update e820 for memory not covered by WB MTRRs */
 	mtrr_bp_init();
 	if (mtrr_trim_uncached_memory(max_pfn))
-		max_pfn = e820_end_of_ram_pfn();
+		max_pfn = e820__end_of_ram_pfn();
 
 	max_possible_pfn = max_pfn;
 
@@ -1068,7 +1068,7 @@ void __init setup_arch(char **cmdline_p)
 	/* How many end-of-memory variables you have, grandma! */
 	/* need this before calling reserve_initrd */
 	if (max_pfn > (1UL<<(32 - PAGE_SHIFT)))
-		max_low_pfn = e820_end_of_low_ram_pfn();
+		max_low_pfn = e820__end_of_low_ram_pfn();
 	else
 		max_low_pfn = max_pfn;
 
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 6b6b4c59cfc1..2193799ca800 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -701,7 +701,7 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
 
 void __ref free_initmem(void)
 {
-	e820_reallocate_tables();
+	e820__reallocate_tables();
 
 	free_init_pages("unused kernel",
 			(unsigned long)(&__init_begin),
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* Re: [PATCH 22/50] x86/boot/e820: Convert printk(KERN_* ...) to pr_*()
  2017-01-28 22:11 ` [PATCH 22/50] x86/boot/e820: Convert printk(KERN_* ...) to pr_*() Ingo Molnar
@ 2017-01-28 22:59   ` Joe Perches
  0 siblings, 0 replies; 65+ messages in thread
From: Joe Perches @ 2017-01-28 22:59 UTC (permalink / raw)
  To: Ingo Molnar, linux-kernel
  Cc: Andrew Morton, Andy Lutomirski, Borislav Petkov, H . Peter Anvin,
	Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Yinghai Lu

On Sat, 2017-01-28 at 23:11 +0100, Ingo Molnar wrote:
> No change in functionality.

Not true.

> @@ -419,11 +419,11 @@ __e820_update_range(struct e820_table *table, u64 start, u64 size, unsigned old_
>  		size = ULLONG_MAX - start;
>  
>  	end = start + size;
> -	printk(KERN_DEBUG "e820: update [mem %#010Lx-%#010Lx] ", start, end - 1);
> +	pr_debug("e820: update [mem %#010Lx-%#010Lx] ", start, end - 1);

#define DEBUG is not set here so this conversion is
not equivalent.

pr_debug will be removed unless CONFIG_DYNAMIC_DEBUG
is enabled and also will not be enabled by default.

>  	e820_print_type(old_type);
> -	printk(KERN_CONT " ==> ");
> +	pr_cont(" ==> ");

This will always be emitted.

> @@ -495,10 +495,10 @@ u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type, int checkty
>  		size = ULLONG_MAX - start;
>  
>  	end = start + size;
> -	printk(KERN_DEBUG "e820: remove [mem %#010Lx-%#010Lx] ", start, end - 1);
> +	pr_debug("e820: remove [mem %#010Lx-%#010Lx] ", start, 

etc...

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH 37/50] x86/boot/e820: Use 'enum e820_type' in 'struct e820_entry'
  2017-01-28 22:11 ` [PATCH 37/50] x86/boot/e820: Use 'enum e820_type' in 'struct e820_entry' Ingo Molnar
@ 2017-01-28 23:07   ` Linus Torvalds
  2017-01-29  9:19     ` Ingo Molnar
  0 siblings, 1 reply; 65+ messages in thread
From: Linus Torvalds @ 2017-01-28 23:07 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Linux Kernel Mailing List, Andrew Morton, Andy Lutomirski,
	Borislav Petkov, H . Peter Anvin, Peter Zijlstra,
	Thomas Gleixner, Yinghai Lu

On Sat, Jan 28, 2017 at 2:11 PM, Ingo Molnar <mingo@kernel.org> wrote:
> Use a stricter type for struct e820_entry. Add a build-time check to make
> sure the compiler won't ever pack the enum into a field smaller than
> 'int'.

I'm not sure this is a good idea. In fact, I'm pretty sure it's a horrible idea.

The compiler that *users* use might decide that the "enum" fits in a
8-bit unsigned char, and decide to use that. The kernel build won't
notice and the BUG_ON() won't help, because we use a different
compiler.

(Or even if it's the same compiler you can have build flags - the size
of an enum very much depends on various compiler options, particularly
"--short-enums" for gcc).

Basically, we should not use "enum"s in types exported to user space.
The size just isn't sufficiently well defined, and it's a maintenance
nightmare.

Use explicitly sized members only, please. No "enum".

            Linus

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH 37/50] x86/boot/e820: Use 'enum e820_type' in 'struct e820_entry'
  2017-01-28 23:07   ` Linus Torvalds
@ 2017-01-29  9:19     ` Ingo Molnar
  2017-01-29 12:38       ` [PATCH] x86/boot/e820: Separate the E820 ABI structures from the in-kernel structures Ingo Molnar
  2017-01-29 18:53       ` [PATCH 37/50] x86/boot/e820: Use 'enum e820_type' in 'struct e820_entry' Linus Torvalds
  0 siblings, 2 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-29  9:19 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Linux Kernel Mailing List, Andrew Morton, Andy Lutomirski,
	Borislav Petkov, H . Peter Anvin, Peter Zijlstra,
	Thomas Gleixner, Yinghai Lu


* Linus Torvalds <torvalds@linux-foundation.org> wrote:

> On Sat, Jan 28, 2017 at 2:11 PM, Ingo Molnar <mingo@kernel.org> wrote:
> > Use a stricter type for struct e820_entry. Add a build-time check to make
> > sure the compiler won't ever pack the enum into a field smaller than
> > 'int'.
> 
> I'm not sure this is a good idea. In fact, I'm pretty sure it's a horrible idea.
> 
> The compiler that *users* use might decide that the "enum" fits in a
> 8-bit unsigned char, and decide to use that. The kernel build won't
> notice and the BUG_ON() won't help, because we use a different
> compiler.

Hm, good point, have not considered that.

> (Or even if it's the same compiler you can have build flags - the size
> of an enum very much depends on various compiler options, particularly
> "--short-enums" for gcc).
> 
> Basically, we should not use "enum"s in types exported to user space.
> The size just isn't sufficiently well defined, and it's a maintenance
> nightmare.
> 
> Use explicitly sized members only, please. No "enum".

Ok.

Would it be acceptable to use enum for the kernel internal representation (our 
e820_table structures never actually comes directly, we construct it ourselves), 
and maintain the very explicitly sized ABI type for the boot protocol only (i.e. 
uapi/asm/bootparam.h)?

( I actually partially implemented that originally, but chickened out after 
  running into header dependency hell - but I think it could be tackled with a bit 
  more effort. )

The vagueness of the C spec about enum size and the resulting enum auto-packing 
efforts of compilers is annoying and a real problem for ABIs, but the reason I'm 
pushing them in this case is that enums also have some advantages within the 
kernel:

 1) they are pretty good self-documenting types

 2) GCC at least has some useful enum warnings for switch() statements, one of 
    which we use in the kernel today:

       -Wswitch

           Warn whenever a "switch" statement has an index of enumerated type and 
           lacks a "case" for one or more of the named codes of that enumeration.  
           (The presence of a "default" label prevents this warning.)  "case" 
           labels outside the enumeration range also provoke warnings when this 
           option is used (even if there is a "default" label).
           This warning is enabled by -Wall.

    There are also more intrusive warnings which found/prevented quite a few bugs
    in various user-space efforts I've been involved with (such as tools/perf):

       -Wswitch-default

           Warn whenever a "switch" statement does not have a "default" case.

       -Wswitch-enum

           Warn whenever a "switch" statement has an index of enumerated type and 
           lacks a "case" for one or more of the named codes of that enumeration.  
           "case" labels outside the enumeration range also provoke warnings when 
           this option is used.  The only difference between -Wswitch and this 
           option is that this option gives a warning about an omitted enumeration 
           code even if there is a "default" label.

So if say one of the e820 functions didn't handle E820_TYPE_PMEM, we'd today 
generate this warning in the kernel build:

  arch/x86/kernel/e820.c: In function ‘e820_print_type’:
  arch/x86/kernel/e820.c:143:2: warning: enumeration value ‘E820_TYPE_PMEM’ not 
  handled in switch [-Wswitch]
    switch (type) {
    ^
  arch/x86/kernel/e820.c:143:2: warning: enumeration value ‘E820_TYPE_PRAM’ not 
  handled in switch [-Wswitch]

And in fact, we could go further than that - the kernel does not enable 
-Wswitch-enum right now (because there are valid patterns that it warns about, 
such as enums with extensive list of values where listing all the values would 
make thecode worse), but when enabled for e820.c it generates this warning:

  arch/x86/kernel/e820.c: In function ‘e820_type_to_string’:
  arch/x86/kernel/e820.c:965:2: warning: enumeration value ‘E820_TYPE_RESERVED’ not handled in switch [-Wswitch-enum]
    switch (entry->type) {
    ^

  arch/x86/kernel/e820.c: In function ‘e820_type_to_iomem_type’:
  arch/x86/kernel/e820.c:979:2: warning: enumeration value ‘E820_TYPE_RESERVED’ not handled in switch [-Wswitch-enum]
    switch (entry->type) {
    ^

  arch/x86/kernel/e820.c: In function ‘e820_type_to_iores_desc’:
  arch/x86/kernel/e820.c:993:2: warning: enumeration value ‘E820_TYPE_RESERVED’ not handled in switch [-Wswitch-enum]
    switch (entry->type) {
    ^

  arch/x86/kernel/e820.c: In function ‘do_mark_busy’:
  arch/x86/kernel/e820.c:1015:2: warning: enumeration value ‘E820_TYPE_RAM’ not handled in switch [-Wswitch-enum]
    switch (type) {
	    ^

All four warnings are interesting IMHO:

The one in e820_type_to_string() should be fixed this way I think:

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index d2c6468a8d38..20834a81854e 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -970,7 +970,8 @@ static const char *__init e820_type_to_string(struct e820_entry *entry)
 	case E820_TYPE_UNUSABLE:	return "Unusable memory";
 	case E820_TYPE_PRAM:		return "Persistent Memory (legacy)";
 	case E820_TYPE_PMEM:		return "Persistent Memory";
-	default:			return "Reserved";
+	case E820_TYPE_RESERVED:	return "Reserved";
+	default:			return "Unknown E820 type";
 	}
 }

As it's useful to have differentiation in output between a known-reserved E820 
range and a totally unknown type range (firmware special or new feature).

The ones in e820_type_to_iomem_type() and e820_type_to_iores_desc() look OK but 
interesting nevertheless, and should probably be fixed this way:

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index d2c6468a8d38..20834a81854e 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -984,6 +985,7 @@ static unsigned long __init e820_type_to_iomem_type(struct e820_entry *entry)
 	case E820_TYPE_UNUSABLE:	/* Fall-through: */
 	case E820_TYPE_PRAM:		/* Fall-through: */
 	case E820_TYPE_PMEM:		/* Fall-through: */
+	case E820_TYPE_RESERVED:	/* Fall-through: */
 	default:			return IORESOURCE_MEM;
 	}
 }
@@ -998,6 +1000,7 @@ static unsigned long __init e820_type_to_iores_desc(struct e820_entry *entry)
 	case E820_TYPE_RESERVED_KERN:	/* Fall-through: */
 	case E820_TYPE_RAM:		/* Fall-through: */
 	case E820_TYPE_UNUSABLE:	/* Fall-through: */
+	case E820_TYPE_RESERVED:	/* Fall-through: */
 	default:			return IORES_DESC_NONE;
 	}
 }

I think it's worth a mention that E820_TYPE_RESERVED is handled differently from 
E820_TYPE_RESERVED_KERN in these two functions: the reason is that 
E820_TYPE_RESERVED_KERN is really a special RAM area and probably somewhat of a 
misnomer - E820_TYPE_RAM_RESERVED might be better.

The one in do_mark_busy() is IMHO interesting as well:

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index d2c6468a8d38..20834a81854e 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -998,7 +1000,7 @@ static unsigned long __init e820_type_to_iores_desc(struct e820_entry *entry)
 	}
 }
 
-static bool __init do_mark_busy(u32 type, struct resource *res)
+static bool __init do_mark_busy(enum e820_type type, struct resource *res)
 {
 	/* this is the legacy bios/dos rom-shadow + mmio region */
 	if (res->start < (1ULL<<20))
@@ -1017,6 +1020,11 @@ static bool __init do_mark_busy(u32 type, struct resource *res)
 	case E820_TYPE_PRAM:
 	case E820_TYPE_PMEM:
 		return false;
+	case E820_TYPE_RESERVED_KERN:
+	case E820_TYPE_RAM:
+	case E820_TYPE_ACPI:
+	case E820_TYPE_NVS:
+	case E820_TYPE_UNUSABLE:
 	default:
 		return true;
 	}

(this patch keeps/documents the status quo.)

As it raises the question of why E820_TYPE_RESERVED is handled differently from 
E820_TYPE_ACPI and E820_TYPE_NVS. Shouldn't E820_TYPE_RESERVED be marked busy as 
well, or do sometimes PCI devices hide there? Even if the code is correct this 
would merit a line of documentation as well, IMHO.

( There's also the -Wswitch-default warning which is not enabled by the kernel 
  build, and which even if enabled does not trigger for e820.o but it's useful as 
  well. )

I.e. I think enum e820_type is a case where very explicit listing of all the 
values in switch() statements actively improves the code, almost unconditionally: 
it resulted in a fix, three improvements in code quality and a couple of questions 
that might result in improved comments.

None of this is possible in such an active way with CPP #defines.

So if you think isolating the enum from the ABI interface would be an acceptable 
solution to the problem we could still use the enum - eat and have the cake and 
such?

Thanks,

	Ingo

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH] x86/boot/e820: Separate the E820 ABI structures from the in-kernel structures
  2017-01-29  9:19     ` Ingo Molnar
@ 2017-01-29 12:38       ` Ingo Molnar
  2017-01-29 18:53       ` [PATCH 37/50] x86/boot/e820: Use 'enum e820_type' in 'struct e820_entry' Linus Torvalds
  1 sibling, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-29 12:38 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Linux Kernel Mailing List, Andrew Morton, Andy Lutomirski,
	Borislav Petkov, H . Peter Anvin, Peter Zijlstra,
	Thomas Gleixner, Yinghai Lu


* Ingo Molnar <mingo@kernel.org> wrote:

> > Use explicitly sized members only, please. No "enum".
> 
> Ok.
> 
> Would it be acceptable to use enum for the kernel internal representation (our 
> e820_table structures never actually comes directly, we construct it ourselves), 
                                                     ^-- from the firmware
> and maintain the very explicitly sized ABI type for the boot protocol only (i.e. 
> uapi/asm/bootparam.h)?

I.e. my proposed solution would be to decouple struct e820_table (and thus struct 
e820_entry) by making them kernel internal and thus decoupling them from the boot 
protocol (struct boot_params) - and not expose the enum to UAPI at all, only the 
raw __u32/__u64 fields of the boot protocol.

We already have some pain in the code from the fact that the e820 table of the 
boot protocol is not actually the same as e820_table: table->nr_entries is at a 
different offset in struct boot_params.h. So struct e820_table is already a de 
facto artificial in-kernel construct and has been for a decade or so.

I.e. something like the patch below. (Lightly boot tested on a couple of systems.)

This actually makes things simpler and cleaner all around:

 - Now boot_params is not modified anymore (previous we'd call 
   e820__update_table() on the boot parameters structure itself!).

 - The ugly low level __e820__update_table() is not used anymore (because all 
   e820_table structures now have a standard layout) and can be eliminated in a 
   future patch.

 - Grepping for boot_e820_entry will now actually show all the very low level E820 
   code that directly interfaces with the BIOS or the bootloader. This is a plus.

 - 'struct e820_entry' is now independent of the boot ABI. I boot tested the 
   following experimental change:

|
| --- a/arch/x86/include/asm/e820/types.h
| +++ b/arch/x86/include/asm/e820/types.h
| @@ -44,10 +44,10 @@ enum e820_type {
|   * (We pack it because there can be thousands of them on large systems.)
|   */
|  struct e820_entry {
| +	enum e820_type		type;
| 	u64			addr;
| 	u64			size;
| -	enum e820_type		type;
| -} __attribute__((packed));
| +};
| 
| /*
|  * The legacy E820 BIOS limits us to 128 (E820_MAX_ENTRIES_ZEROPAGE) nodes
|

   ... which changes both the layout and the size of e820_entry on 64-bit systems, 
   and successfully boot-tested it - which is proof that the types are decoupled 
   in practice as well.

   I don't actually think we want to change the ordering and size right now, as 
   distro kernels can have thousands of these entries and their memory efficiency
   matters, but it's nice to know that the decoupling appears to be complete. 
   Maybe some future firmware interface requires a new field, which would now be 
   possible.

 - And of course this patch should also fix the problem you pointed out, the 
   fragility of enum sizes in ABI data structures.

So ... would this be an acceptable approach? (Assuming it works on all systems, 
etc.)

Thanks,

	Ingo

==================>
>From c88a9c7e933dd665a47591ebd049a5046c7871c5 Mon Sep 17 00:00:00 2001
From: Ingo Molnar <mingo@kernel.org>
Date: Sun, 29 Jan 2017 12:56:13 +0100
Subject: [PATCH] x86/boot/e820: Separate the E820 ABI structures from the in-kernel structures

Linus pointed out that relying on the compiler to pack structures with
enums is fragile not just for the kernel, but for external tooling as
well which might rely on our UAPI headers.

So separate the two from each other: introduce 'struct boot_e820_entry',
which is the boot protocol entry format.

This actually simplifies the code, as e820__update_table() is now never
called directly with boot protocol table entries - we can rely on
append_e820_table() and do a e820__update_table() call afterwards.

( This will allow further simplifications of __e820__update_table(),
  but that will be done in a separate patch. )

This change also has the side effect of not modifying the bootparams structure
anymore - which might be useful for debugging. In theory we could even constify
the boot_params structure - at least from the E820 code's point of view.

Remove the uapi/asm/e820/types.h file, as it's not used anymore - all
kernel side E820 types are defined in asm/e820/types.h.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/boot/compressed/eboot.c       | 16 +++++-----
 arch/x86/boot/compressed/kaslr.c       |  2 +-
 arch/x86/boot/memory.c                 |  4 +--
 arch/x86/include/asm/e820/types.h      | 48 ++++++++++++++++++++++++++++-
 arch/x86/include/uapi/asm/bootparam.h  | 18 +++++++++--
 arch/x86/include/uapi/asm/e820/types.h | 55 ----------------------------------
 arch/x86/kernel/e820.c                 | 20 ++++++-------
 7 files changed, 83 insertions(+), 80 deletions(-)

diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index 4cfba2f79dfd..a6099d7c39f6 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -900,7 +900,7 @@ static void add_e820ext(struct boot_params *params,
 	unsigned long size;
 
 	e820ext->type = SETUP_E820_EXT;
-	e820ext->len = nr_entries * sizeof(struct e820_entry);
+	e820ext->len = nr_entries * sizeof(struct boot_e820_entry);
 	e820ext->next = 0;
 
 	data = (struct setup_data *)(unsigned long)params->hdr.setup_data;
@@ -917,9 +917,9 @@ static void add_e820ext(struct boot_params *params,
 static efi_status_t setup_e820(struct boot_params *params,
 			       struct setup_data *e820ext, u32 e820ext_size)
 {
-	struct e820_entry *e820_table = &params->e820_table[0];
+	struct boot_e820_entry *entry = params->e820_table;
 	struct efi_info *efi = &params->efi_info;
-	struct e820_entry *prev = NULL;
+	struct boot_e820_entry *prev = NULL;
 	u32 nr_entries;
 	u32 nr_desc;
 	int i;
@@ -990,13 +990,13 @@ static efi_status_t setup_e820(struct boot_params *params,
 				return EFI_BUFFER_TOO_SMALL;
 
 			/* boot_params map full, switch to e820 extended */
-			e820_table = (struct e820_entry *)e820ext->data;
+			entry = (struct boot_e820_entry *)e820ext->data;
 		}
 
-		e820_table->addr = d->phys_addr;
-		e820_table->size = d->num_pages << PAGE_SHIFT;
-		e820_table->type = e820_type;
-		prev = e820_table++;
+		entry->addr = d->phys_addr;
+		entry->size = d->num_pages << PAGE_SHIFT;
+		entry->type = e820_type;
+		prev = entry++;
 		nr_entries++;
 	}
 
diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index e8155eab5474..6d9a546ec7ae 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -426,7 +426,7 @@ static unsigned long slots_fetch_random(void)
 	return 0;
 }
 
-static void process_e820_entry(struct e820_entry *entry,
+static void process_e820_entry(struct boot_e820_entry *entry,
 			       unsigned long minimum,
 			       unsigned long image_size)
 {
diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
index db62445b75aa..d9c28c87e477 100644
--- a/arch/x86/boot/memory.c
+++ b/arch/x86/boot/memory.c
@@ -21,8 +21,8 @@ static int detect_memory_e820(void)
 {
 	int count = 0;
 	struct biosregs ireg, oreg;
-	struct e820_entry *desc = boot_params.e820_table;
-	static struct e820_entry buf; /* static so it is zeroed */
+	struct boot_e820_entry *desc = boot_params.e820_table;
+	static struct boot_e820_entry buf; /* static so it is zeroed */
 
 	initregs(&ireg);
 	ireg.ax  = 0xe820;
diff --git a/arch/x86/include/asm/e820/types.h b/arch/x86/include/asm/e820/types.h
index cf6074f8d563..4adeed03a9a1 100644
--- a/arch/x86/include/asm/e820/types.h
+++ b/arch/x86/include/asm/e820/types.h
@@ -1,7 +1,53 @@
 #ifndef _ASM_E820_TYPES_H
 #define _ASM_E820_TYPES_H
 
-#include <uapi/asm/e820/types.h>
+#include <uapi/asm/bootparam.h>
+
+/*
+ * These are the E820 types known to the kernel:
+ */
+enum e820_type {
+	E820_TYPE_RAM		= 1,
+	E820_TYPE_RESERVED	= 2,
+	E820_TYPE_ACPI		= 3,
+	E820_TYPE_NVS		= 4,
+	E820_TYPE_UNUSABLE	= 5,
+	E820_TYPE_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=y 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... )
+	 */
+	E820_TYPE_PRAM		= 12,
+
+	/*
+	 * Reserved RAM used by the kernel itself if
+	 * CONFIG_INTEL_TXT=y is enabled, memory of this type
+	 * will be included in the S3 integrity calculation
+	 * and so should not include any memory that the BIOS
+	 * might alter over the S3 transition:
+	 */
+	E820_TYPE_RESERVED_KERN	= 128,
+};
+
+/*
+ * A single E820 map entry, describing a memory range of [addr...addr+size-1],
+ * of 'type' memory type:
+ *
+ * (We pack it because there can be thousands of them on large systems.)
+ */
+struct e820_entry {
+	u64			addr;
+	u64			size;
+	enum e820_type		type;
+} __attribute__((packed));
 
 /*
  * The legacy E820 BIOS limits us to 128 (E820_MAX_ENTRIES_ZEROPAGE) nodes
diff --git a/arch/x86/include/uapi/asm/bootparam.h b/arch/x86/include/uapi/asm/bootparam.h
index 7f04c45aa429..2a5fd6bb0601 100644
--- a/arch/x86/include/uapi/asm/bootparam.h
+++ b/arch/x86/include/uapi/asm/bootparam.h
@@ -34,7 +34,6 @@
 #include <linux/screen_info.h>
 #include <linux/apm_bios.h>
 #include <linux/edd.h>
-#include <uapi/asm/e820/types.h>
 #include <asm/ist.h>
 #include <video/edid.h>
 
@@ -111,6 +110,21 @@ struct efi_info {
 	__u32 efi_memmap_hi;
 };
 
+/*
+ * This is the maximum number of entries in struct boot_params::e820_table
+ * (the zeropage), which is part of the x86 boot protocol ABI:
+ */
+#define E820_MAX_ENTRIES_ZEROPAGE 128
+
+/*
+ * The E820 memory region entry of the boot protocol ABI:
+ */
+struct boot_e820_entry {
+	__u64 addr;
+	__u64 size;
+	__u32 type;
+} __attribute__((packed));
+
 /* The so-called "zeropage" */
 struct boot_params {
 	struct screen_info screen_info;			/* 0x000 */
@@ -152,7 +166,7 @@ struct boot_params {
 	struct setup_header hdr;    /* setup header */	/* 0x1f1 */
 	__u8  _pad7[0x290-0x1f1-sizeof(struct setup_header)];
 	__u32 edd_mbr_sig_buffer[EDD_MBR_SIG_MAX];	/* 0x290 */
-	struct e820_entry e820_table[E820_MAX_ENTRIES_ZEROPAGE]; /* 0x2d0 */
+	struct boot_e820_entry e820_table[E820_MAX_ENTRIES_ZEROPAGE]; /* 0x2d0 */
 	__u8  _pad8[48];				/* 0xcd0 */
 	struct edd_info eddbuf[EDDMAXNR];		/* 0xd00 */
 	__u8  _pad9[276];				/* 0xeec */
diff --git a/arch/x86/include/uapi/asm/e820/types.h b/arch/x86/include/uapi/asm/e820/types.h
deleted file mode 100644
index 3ac962f724f5..000000000000
--- a/arch/x86/include/uapi/asm/e820/types.h
+++ /dev/null
@@ -1,55 +0,0 @@
-#ifndef _UAPI_ASM_E820_TYPES_H
-#define _UAPI_ASM_E820_TYPES_H
-
-/*
- * This is the maximum number of entries in struct boot_params::e820_table (the zeropage),
- * which is part of the x86 boot protocol ABI:
- */
-#define E820_MAX_ENTRIES_ZEROPAGE 128
-
-#ifndef __ASSEMBLY__
-
-enum e820_type {
-	E820_TYPE_RAM		= 1,
-	E820_TYPE_RESERVED	= 2,
-	E820_TYPE_ACPI		= 3,
-	E820_TYPE_NVS		= 4,
-	E820_TYPE_UNUSABLE	= 5,
-	E820_TYPE_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=y 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... )
-	 */
-	E820_TYPE_PRAM		= 12,
-
-	/*
-	 * Reserved RAM used by the kernel itself if
-	 * CONFIG_INTEL_TXT=y is enabled, memory of this type
-	 * will be included in the S3 integrity calculation
-	 * and so should not include any memory that the BIOS
-	 * might alter over the S3 transition:
-	 */
-	E820_TYPE_RESERVED_KERN	= 128,
-};
-
-/*
- * A single E820 map entry, describing a memory range of [addr...addr+size-1],
- * of 'type' memory type:
- */
-struct e820_entry {
-	__u64			addr;
-	__u64			size;
-	enum e820_type		type;
-} __attribute__((packed));
-
-#endif /* __ASSEMBLY__ */
-
-#endif /* _UAPI_ASM_E820_TYPES_H */
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 20834a81854e..2da2f7238a72 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -366,9 +366,9 @@ int __init e820__update_table(struct e820_table *table)
 	return __e820__update_table(table->entries, ARRAY_SIZE(table->entries), &table->nr_entries);
 }
 
-static int __init __append_e820_table(struct e820_entry *entries, u32 nr_entries)
+static int __init __append_e820_table(struct boot_e820_entry *entries, u32 nr_entries)
 {
-	struct e820_entry *entry = entries;
+	struct boot_e820_entry *entry = entries;
 
 	while (nr_entries) {
 		u64 start = entry->addr;
@@ -397,7 +397,7 @@ static int __init __append_e820_table(struct e820_entry *entries, u32 nr_entries
  * will have given us a memory map that we can use to properly
  * set up memory.  If we aren't, we'll fake a memory map.
  */
-static int __init append_e820_table(struct e820_entry *entries, u32 nr_entries)
+static int __init append_e820_table(struct boot_e820_entry *entries, u32 nr_entries)
 {
 	/* Only one memory region (or negative)? Ignore it */
 	if (nr_entries < 2)
@@ -668,12 +668,12 @@ __init void e820__reallocate_tables(void)
 void __init e820__memory_setup_extended(u64 phys_addr, u32 data_len)
 {
 	int entries;
-	struct e820_entry *extmap;
+	struct boot_e820_entry *extmap;
 	struct setup_data *sdata;
 
 	sdata = early_memremap(phys_addr, data_len);
 	entries = sdata->len / sizeof(*extmap);
-	extmap = (struct e820_entry *)(sdata->data);
+	extmap = (struct boot_e820_entry *)(sdata->data);
 
 	__append_e820_table(extmap, entries);
 	e820__update_table(e820_table);
@@ -1140,7 +1140,6 @@ void __init e820__reserve_resources_late(void)
 char *__init e820__memory_setup_default(void)
 {
 	char *who = "BIOS-e820";
-	u32 new_nr;
 
 	/*
 	 * Try to copy the BIOS-supplied E820-map.
@@ -1148,10 +1147,6 @@ char *__init e820__memory_setup_default(void)
 	 * Otherwise fake a memory map; one section from 0k->640k,
 	 * the next section from 1mb->appropriate_mem_k
 	 */
-	new_nr = boot_params.e820_entries;
-	__e820__update_table(boot_params.e820_table, ARRAY_SIZE(boot_params.e820_table), &new_nr);
-	boot_params.e820_entries = new_nr;
-
 	if (append_e820_table(boot_params.e820_table, boot_params.e820_entries) < 0) {
 		u64 mem_size;
 
@@ -1169,6 +1164,9 @@ char *__init e820__memory_setup_default(void)
 		e820__range_add(HIGH_MEMORY, mem_size << 10, E820_TYPE_RAM);
 	}
 
+	/* We just appended a lot of ranges, sanitize the table: */
+	e820__update_table(e820_table);
+
 	return who;
 }
 
@@ -1182,7 +1180,7 @@ void __init e820__memory_setup(void)
 	char *who;
 
 	/* This is a firmware interface ABI - make sure we don't break it: */
-	BUILD_BUG_ON(sizeof(struct e820_entry) != 20);
+	BUILD_BUG_ON(sizeof(struct boot_e820_entry) != 20);
 
 	who = x86_init.resources.memory_setup();
 

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* Re: [PATCH 01/50] x86/boot/e820: Introduce arch/x86/include/asm/e820/types.h
  2017-01-28 22:11 ` [PATCH 01/50] x86/boot/e820: Introduce arch/x86/include/asm/e820/types.h Ingo Molnar
@ 2017-01-29 17:13   ` Sam Ravnborg
  2017-01-30  7:58     ` Ingo Molnar
  0 siblings, 1 reply; 65+ messages in thread
From: Sam Ravnborg @ 2017-01-29 17:13 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Andrew Morton, Andy Lutomirski, Borislav Petkov,
	H . Peter Anvin, Linus Torvalds, Peter Zijlstra, Thomas Gleixner,
	Yinghai Lu

On Sat, Jan 28, 2017 at 11:11:22PM +0100, Ingo Molnar wrote:
> 
> 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.)

The idea with uapi is the the kernel provides a sane set of headers
to be used by user space.
So we avoid random copies that is maintained by random people in random
ways resulting in random bugs.

The step(s) outlined here can only result in inconsistency and
cannot benefit neither user space nor the kernel in the long run.

The uapi shall be lean and clean headers, and shall include
no info whatsoever that is not relevant for user space.

But requiring all user space programs (diverse libc variants,
other programs) to maintain their own copy can only result in
inconsistencies that is the benefit for no one.

	Sam

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH 37/50] x86/boot/e820: Use 'enum e820_type' in 'struct e820_entry'
  2017-01-29  9:19     ` Ingo Molnar
  2017-01-29 12:38       ` [PATCH] x86/boot/e820: Separate the E820 ABI structures from the in-kernel structures Ingo Molnar
@ 2017-01-29 18:53       ` Linus Torvalds
  1 sibling, 0 replies; 65+ messages in thread
From: Linus Torvalds @ 2017-01-29 18:53 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Linux Kernel Mailing List, Andrew Morton, Andy Lutomirski,
	Borislav Petkov, H . Peter Anvin, Peter Zijlstra,
	Thomas Gleixner, Yinghai Lu

On Sun, Jan 29, 2017 at 1:19 AM, Ingo Molnar <mingo@kernel.org> wrote:
>
> Would it be acceptable to use enum for the kernel internal representation (our
> e820_table structures never actually comes directly, we construct it ourselves),
> and maintain the very explicitly sized ABI type for the boot protocol only (i.e.
> uapi/asm/bootparam.h)?

I guess that would work, assuming that it doesn't cause unnecessary conversions.

Looking at the patch you sent out (assuming that's the complete deal),
it looks reasonable.

               Linus

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH 01/50] x86/boot/e820: Introduce arch/x86/include/asm/e820/types.h
  2017-01-29 17:13   ` Sam Ravnborg
@ 2017-01-30  7:58     ` Ingo Molnar
  2017-01-31  5:41       ` Sam Ravnborg
  0 siblings, 1 reply; 65+ messages in thread
From: Ingo Molnar @ 2017-01-30  7:58 UTC (permalink / raw)
  To: Sam Ravnborg
  Cc: linux-kernel, Andrew Morton, Andy Lutomirski, Borislav Petkov,
	H . Peter Anvin, Linus Torvalds, Peter Zijlstra, Thomas Gleixner,
	Yinghai Lu, Arnaldo Carvalho de Melo


* Sam Ravnborg <sam@ravnborg.org> wrote:

> On Sat, Jan 28, 2017 at 11:11:22PM +0100, Ingo Molnar wrote:
> > 
> > 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.)
> 
> The idea with uapi is the the kernel provides a sane set of headers
> to be used by user space.
> So we avoid random copies that is maintained by random people in random
> ways resulting in random bugs.

Your argument is simplistic which presents a false dichotomy: maintaining a copy 
or fully sharing the header are not the only two options available to share the 
information in the headers between the kernel and tooling: for example perf uses a 
half-automated method where headers are copied from the kernel, but also checked 
automatically against the upstream kernel, and a (non-fatal) warning is emitted 
during the build if the upstream header has changed.

For example today the perf build shows these UAPI header warnings:

 Warning: arch/powerpc/include/uapi/asm/kvm.h differs from kernel
 Warning: arch/arm/include/uapi/asm/kvm.h differs from kernel

... because new bits were added to those two UAPI headers. For example the new ARM 
bits were:

triton:~/tip/tools/perf> diff -up ../arch/arm/include/uapi/asm/kvm.h ../../arch/arm/include/uapi/asm/kvm.h
--- ../arch/arm/include/uapi/asm/kvm.h  2017-01-23 10:10:18.846003002 +0100
+++ ../../arch/arm/include/uapi/asm/kvm.h       2017-01-28 09:35:12.383587930 +0100
@@ -84,6 +84,15 @@ struct kvm_regs {
 #define KVM_VGIC_V2_DIST_SIZE          0x1000
 #define KVM_VGIC_V2_CPU_SIZE           0x2000
 
+/* Supported VGICv3 address types  */
+#define KVM_VGIC_V3_ADDR_TYPE_DIST     2
+#define KVM_VGIC_V3_ADDR_TYPE_REDIST   3
+#define KVM_VGIC_ITS_ADDR_TYPE         4
+
+#define KVM_VGIC_V3_DIST_SIZE          SZ_64K
+#define KVM_VGIC_V3_REDIST_SIZE                (2 * SZ_64K)
+#define KVM_VGIC_V3_ITS_SIZE           (2 * SZ_64K)
+
 #define KVM_ARM_VCPU_POWER_OFF         0 /* CPU is started in OFF state */
 #define KVM_ARM_VCPU_PSCI_0_2          1 /* CPU uses PSCI v0.2 */
 
... so for these changes the perf side copy can be updated safely. Had the changes 
been more intricate, the changes can be copied too - while adopting the tooling 
source code as well.

See the tools/perf/check-headers.sh script.

This IMHO is a far more intelligent and far more robust approach than blind 
sharing or detached copies, because it:

 - forces new changes from upstream to be considered and adapted by tooling

 - header (and thus ABI) synchronization is guaranteed (eventually)

 - it does not actually couple the two source code bases in a rigid fashion:

 - the upstream kernel is free to change those headers (at least from perf's POV)
   in any sane way, those changes can be adapted.

 - every step is conscious and there's no way to accidentally break tooling via
   header changes - nor does tooling hinder the kernel from progressing its source 
   code base.

It's basically a script based COW filesystem with guaranteed propagation and 
guaranteed synchronization.

> The step(s) outlined here can only result in inconsistency and
> cannot benefit neither user space nor the kernel in the long run.

That's simply not true, see above.

> The uapi shall be lean and clean headers, and shall include
> no info whatsoever that is not relevant for user space.

I agree with that characterization, and that will be even more so with my changes: 
my series makes uapi/asm/bootparam.h more self-contained, more lean - while still 
defining the full ABI.

> But requiring all user space programs (diverse libc variants,
> other programs) to maintain their own copy can only result in
> inconsistencies that is the benefit for no one.

That's simply not true, see above.

Note that my changes try to keep the 'UAPI promise' (in that the old e820.h header 
is still around), while still modifying the kernel side.

What _IS_ insane is to somehow construe the UAPI headers as a rigid construct that 
forces the kernel source to keep using poorly chosen names like 'struct e820entry' 
forever...

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH 01/50] x86/boot/e820: Introduce arch/x86/include/asm/e820/types.h
  2017-01-30  7:58     ` Ingo Molnar
@ 2017-01-31  5:41       ` Sam Ravnborg
  2017-01-31 16:35         ` Ingo Molnar
  0 siblings, 1 reply; 65+ messages in thread
From: Sam Ravnborg @ 2017-01-31  5:41 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Andrew Morton, Andy Lutomirski, Borislav Petkov,
	H . Peter Anvin, Linus Torvalds, Peter Zijlstra, Thomas Gleixner,
	Yinghai Lu, Arnaldo Carvalho de Melo

On Mon, Jan 30, 2017 at 08:58:33AM +0100, Ingo Molnar wrote:
> 
> * Sam Ravnborg <sam@ravnborg.org> wrote:
> 
> > On Sat, Jan 28, 2017 at 11:11:22PM +0100, Ingo Molnar wrote:
> > > 
> > > 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.)
> > 
> > The idea with uapi is the the kernel provides a sane set of headers
> > to be used by user space.
> > So we avoid random copies that is maintained by random people in random
> > ways resulting in random bugs.
> 
> Your argument is simplistic which presents a false dichotomy: maintaining a copy 
> or fully sharing the header are not the only two options available to share the 
> information in the headers between the kernel and tooling: for example perf uses a 
> half-automated method where headers are copied from the kernel, but also checked 
> automatically against the upstream kernel, and a (non-fatal) warning is emitted 
> during the build if the upstream header has changed.

Obvious when there are two vastly different solutions there are some
middle ground solutions too.
And perf implements a tool based method to check that the manually
copied/created/maintained headers are in sync with the kernel.
which is just another way to maintain a set of copied headers.

But this does not at all address the point which is that it is
an unessesary burden to put on all the _users_ of the kernel uapi
headers to amintain their own copy of the kernel headers
(tool assisted or not).

The rationale behind requesting the users of the kernel uapi headers
seems to be that the kernel people would like to have the freedom
to fix wrong doings in the past without violatign the uapi.
So the benefit here is simpler headers on the kernel side compared
to all users of kernel uapi heders to manually (tool assisted or not)
maintaining their own copies of the uapi kernel headers.

Heck - if this is how it should be done then the the kernel
should provide the copy of the headers that describe the
uapi and the kernel should have the tool infrastructure to check
that the headers are OK.
Not all the users outside the kernelspace.

So just to repeat - it is an error prone design to let users
of the kernel uapi maintain their own copies of the kernel
uapi header. It is the job of the kernel.

	Sam

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH 01/50] x86/boot/e820: Introduce arch/x86/include/asm/e820/types.h
  2017-01-31  5:41       ` Sam Ravnborg
@ 2017-01-31 16:35         ` Ingo Molnar
  2017-01-31 17:22           ` Sam Ravnborg
  0 siblings, 1 reply; 65+ messages in thread
From: Ingo Molnar @ 2017-01-31 16:35 UTC (permalink / raw)
  To: Sam Ravnborg
  Cc: linux-kernel, Andrew Morton, Andy Lutomirski, Borislav Petkov,
	H . Peter Anvin, Linus Torvalds, Peter Zijlstra, Thomas Gleixner,
	Yinghai Lu, Arnaldo Carvalho de Melo


* Sam Ravnborg <sam@ravnborg.org> wrote:

> Obvious when there are two vastly different solutions there are some
> middle ground solutions too.
>
> And perf implements a tool based method to check that the manually 
> copied/created/maintained headers are in sync with the kernel. which is just 
> another way to maintain a set of copied headers.
> 
> But this does not at all address the point which is that it is an unessesary 
> burden to put on all the _users_ of the kernel uapi headers to amintain their 
> own copy of the kernel headers (tool assisted or not).

In 99% of the cases it's trivial to keep them updated on the tooling side. 
Basically a copy only has to be made if a change is done - and changes are not 
that common in the ABI space.

> The rationale behind requesting the users of the kernel uapi headers seems to be 
> that the kernel people would like to have the freedom to fix wrong doings in the 
> past without violatign the uapi.
>
> So the benefit here is simpler headers on the kernel side compared
> to all users of kernel uapi heders to manually (tool assisted or not)
> maintaining their own copies of the uapi kernel headers.

I was reacting to this original claim of yours:

> > > The idea with uapi is the the kernel provides a sane set of headers to be 
> > > used by user space.
> > >
> > > So we avoid random copies that is maintained by random people in random ways 
> > > resulting in random bugs.

There's no 'random copies' - they are copies of past, valid versions of the kernel 
headers, and there's a mechanism to update them to the latest.

> Heck - if this is how it should be done then the the kernel
> should provide the copy of the headers that describe the
> uapi and the kernel should have the tool infrastructure to check
> that the headers are OK.
> Not all the users outside the kernelspace.
> 
> So just to repeat - it is an error prone design to let users
> of the kernel uapi maintain their own copies of the kernel
> uapi header. It is the job of the kernel.

But "random copies" is not what perf does. Tell me, how is the perf mechanism of 
using the headers "error-prone"? It's a delayed COW mechanism - COW is not an 
error-prone concept in any way ...

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH 01/50] x86/boot/e820: Introduce arch/x86/include/asm/e820/types.h
  2017-01-31 16:35         ` Ingo Molnar
@ 2017-01-31 17:22           ` Sam Ravnborg
  2017-01-31 18:00             ` Ingo Molnar
  0 siblings, 1 reply; 65+ messages in thread
From: Sam Ravnborg @ 2017-01-31 17:22 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Andrew Morton, Andy Lutomirski, Borislav Petkov,
	H . Peter Anvin, Linus Torvalds, Peter Zijlstra, Thomas Gleixner,
	Yinghai Lu, Arnaldo Carvalho de Melo

> > 
> > So just to repeat - it is an error prone design to let users
> > of the kernel uapi maintain their own copies of the kernel
> > uapi header. It is the job of the kernel.
> 
> But "random copies" is not what perf does. Tell me, how is the perf mechanism of 
> using the headers "error-prone"? It's a delayed COW mechanism - COW is not an 
> error-prone concept in any way ...

The whole concept that user space have the burden to maintain
a set of headers describing the uapi provided by the kernel is the point
of discussion.

The randomness come into play when a user space developer are
faced with the challenge that the programm require access to something
described by the kernel uapi and then have to hunt for a header
that describes said uapi.

In this thread we have covered one rational reason to push thus
burden to user space - to give the kernel the freedom to repair
past stupidity (being that in naming or some other sort).

So lets turn around the arguments - and from a user space
perspective what is the benefit of maintaining a set of headers
describing the kernel uapi?

Obviously this allows user space to name thing exactly the
way they like, and allows user space to put all sorts of strange
things in the header files describing the kernel uapi.

This is just not enough good reasons why the user space
developer shall create headers files describing
the kerneluapi and maintain tooling to maintain the header
files describing the kernel uapi.

Are there other benefits that is missed which makes the
concept of letting user space maintain header files describing
the kernel uapi a good idea that is missed?

	Sam

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH 01/50] x86/boot/e820: Introduce arch/x86/include/asm/e820/types.h
  2017-01-31 17:22           ` Sam Ravnborg
@ 2017-01-31 18:00             ` Ingo Molnar
  2017-01-31 18:04               ` Joe Perches
  2017-01-31 19:17               ` Sam Ravnborg
  0 siblings, 2 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-01-31 18:00 UTC (permalink / raw)
  To: Sam Ravnborg
  Cc: linux-kernel, Andrew Morton, Andy Lutomirski, Borislav Petkov,
	H . Peter Anvin, Linus Torvalds, Peter Zijlstra, Thomas Gleixner,
	Yinghai Lu, Arnaldo Carvalho de Melo


* Sam Ravnborg <sam@ravnborg.org> wrote:

> > > 
> > > So just to repeat - it is an error prone design to let users
> > > of the kernel uapi maintain their own copies of the kernel
> > > uapi header. It is the job of the kernel.
> > 
> > But "random copies" is not what perf does. Tell me, how is the perf mechanism of 
> > using the headers "error-prone"? It's a delayed COW mechanism - COW is not an 
> > error-prone concept in any way ...
> 
> The whole concept that user space have the burden to maintain a set of headers 
> describing the uapi provided by the kernel is the point of discussion.

That's your characterisation and I think it's misleading: they don't have to 
"maintain a set of headers", they can, if they'd like to:

   "maintain a _copy_ of a small number of headers that the typical user-space 
    tooling project is interested in"

which is different from how you framed it.

> The randomness come into play when a user space developer are faced with the 
> challenge that the programm require access to something described by the kernel 
> uapi and then have to hunt for a header that describes said uapi.
>
> In this thread we have covered one rational reason to push thus
> burden to user space - to give the kernel the freedom to repair
> past stupidity (being that in naming or some other sort).

There's no real "burden" for heaven's sake: it's having to execute a 'cp' every 
now and then and check whether the result still builds (it will build just fine in 
the overwhelming majority of cases).

> So lets turn around the arguments - and from a user space
> perspective what is the benefit of maintaining a set of headers
> describing the kernel uapi?

Firsty, the headers are not maintained by the user-space project, 99.999% of the 
maintenance is done by the kernel developers.

> Obviously this allows user space to name thing exactly the way they like, and 
> allows user space to put all sorts of strange things in the header files 
> describing the kernel uapi.

Huh? Again, my suggestion is to to _copy_ the kernel header the tooling project is 
interested in as-is, and this is exactly what perf does. We don't change the UAPI 
headers, we copy them verbatim and check during the build that the copy is exact.

> Are there other benefits that is missed which makes the
> concept of letting user space maintain header files describing
> the kernel uapi a good idea that is missed?

Yes, you missed a lot of the benefits.

Firstly, the user-space tooling project that relies on some UAPI header with Linux 
kernel ABI details in it, if it so wishes, maintains a _copy_ of the affected 
headers, which is vastly less work and 'burden' than 'maintaining headers'.

Secondly, doing this copy has numerous advantages over using the UAPI headers from 
the distro installation:

 - Additions to the ABI are monitored by the tooling project. Say there's 
   external tooling that relies on the perf system call, and uses a copy of 
   perf_events.h. It can see new ABI additions in new versions of the file, and 
   can add support for them. If on the other hand the file is just shared with 
   whatever distro kernel headers there are on the system, there's no information 
   about ABI progress.

   Advantage: changes to the ABI can be seen in the tool's Git repository,
              the "git log" of the header shows how the versions got updated and 
              how the tool adopted to new ABI additions.

 - The tooling project is more self-contained: it can build just fine in more 
   limited environments that don't have the kernel headers installed.

   Advantage: more robust tool build process, fewer dependencies.

 - So the tooling project can copy the kernel header _before_ the updated kernel
   header trickles through to distros. This has the advantage of being able to add
   tooling support for new ABI additions before it all goes into the 'official'
   UAPI headers a distro includes, and speeds up ABI propagation.

   Advantage: faster ABI propagation to tooling.

 - In fact this model allows the tooling project to host new kernel ABI additions 
   in its development process, so sometimes it has the new UAPI header _before_ 
   the upstream kernel has it. (Obviously the upstream kernel has to pull it for 
   it to become the official UAPI header, so this only works for subsystems where
   there's good communication between the tooling developers and the kernel 
   developers.)

   This is what tools/perf does quite often.

   Advantage: better development model where tooling can develop new kernel 
              features hand in hand with kernel developers.

I.e. most of the advantages of the copied headers are for the _tooling project_, 
not for the kernel.

Your one sided characterization of the copying method as a 'burden' ignores all 
that.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH 01/50] x86/boot/e820: Introduce arch/x86/include/asm/e820/types.h
  2017-01-31 18:00             ` Ingo Molnar
@ 2017-01-31 18:04               ` Joe Perches
  2017-01-31 19:17               ` Sam Ravnborg
  1 sibling, 0 replies; 65+ messages in thread
From: Joe Perches @ 2017-01-31 18:04 UTC (permalink / raw)
  To: Ingo Molnar, Sam Ravnborg
  Cc: linux-kernel, Andrew Morton, Andy Lutomirski, Borislav Petkov,
	H . Peter Anvin, Linus Torvalds, Peter Zijlstra, Thomas Gleixner,
	Yinghai Lu, Arnaldo Carvalho de Melo

On Tue, 2017-01-31 at 19:00 +0100, Ingo Molnar wrote:
> * Sam Ravnborg <sam@ravnborg.org> wrote:
> > In this thread we have covered one rational reason to push thus
> > burden to user space - to give the kernel the freedom to repair
> > past stupidity (being that in naming or some other sort).
> 
> There's no real "burden" for heaven's sake: it's having to execute a 'cp' every 
> now and then and check whether the result still builds (it will build just fine in 
> the overwhelming majority of cases).

Defining what is it that encompasses "userspace", the
thing that's nominally guaranteed to "not be broken",
here is the real question.

Is it just the ABI or is it more than that?

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH 01/50] x86/boot/e820: Introduce arch/x86/include/asm/e820/types.h
  2017-01-31 18:00             ` Ingo Molnar
  2017-01-31 18:04               ` Joe Perches
@ 2017-01-31 19:17               ` Sam Ravnborg
  2017-02-01  8:56                 ` Ingo Molnar
  1 sibling, 1 reply; 65+ messages in thread
From: Sam Ravnborg @ 2017-01-31 19:17 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Andrew Morton, Andy Lutomirski, Borislav Petkov,
	H . Peter Anvin, Linus Torvalds, Peter Zijlstra, Thomas Gleixner,
	Yinghai Lu, Arnaldo Carvalho de Melo

Hi Ingo.

> >
> > In this thread we have covered one rational reason to push thus
> > burden to user space - to give the kernel the freedom to repair
> > past stupidity (being that in naming or some other sort).
> 
> There's no real "burden" for heaven's sake: it's having to execute a 'cp' every 
> now and then and check whether the result still builds (it will build just fine in 
> the overwhelming majority of cases).

We are obvious so far away in our perception of what is easy for
a user-space developers that is is not even funny.

> > So lets turn around the arguments - and from a user space
> > perspective what is the benefit of maintaining a set of headers
> > describing the kernel uapi?
> 
> Firsty, the headers are not maintained by the user-space project, 99.999% of the 
> maintenance is done by the kernel developers.

In the inital mail triggering this plan was that the kernel
is moving away from having uapi headers what-so-ever.

Quoting the original mail:
"
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. 
"

Translated:
The plan is that the kernel will stop using headers from uapi/*
The headers will be left for a while and then they will be deleted.

The mail was centered about e820 - so maybe the outlined plan
was only for e820.
But I read it as a general pan - hence this mail thread.

So this is the plan that this argument is about.
No tooling will magically make files appear again.
And there is no benefit from user space that the kernel remove the files.

And the removing of files from uapi/ makes is hard for user space.
Because then a user-space developers have to find a definition
of the uapi somewhere else.

> Huh? Again, my suggestion is to to _copy_ the kernel header the tooling project is 
> interested in as-is, and this is exactly what perf does.
Here the proposal was stop using the header in uapi/ and then later delete it.
So there i no file to copy - making the copying and tooling part irrelevant.

> Yes, you missed a lot of the benefits.
> 
> Firstly, the user-space tooling project that relies on some UAPI header with Linux 
> kernel ABI details in it, if it so wishes, maintains a _copy_ of the affected 
> headers, which is vastly less work and 'burden' than 'maintaining headers'.

It is by no means a benefit to have a copy, rather than using the source.
There is a reason why we do not have multiple copies of the headers in the kernel
when we can avoid it. asm-generic is one way the kernel avoid the burden
of maintaining copies of headers.

All your remaining argumens zapped - I see the point of view.
But there are many other solutions for the same set of problems.

Perf being intimidate with the kernel is not the best example to come up with.
Think about to 100's of program that uses a few ioclt to talk with drivers etc.

	Sam

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH 01/50] x86/boot/e820: Introduce arch/x86/include/asm/e820/types.h
  2017-01-31 19:17               ` Sam Ravnborg
@ 2017-02-01  8:56                 ` Ingo Molnar
  0 siblings, 0 replies; 65+ messages in thread
From: Ingo Molnar @ 2017-02-01  8:56 UTC (permalink / raw)
  To: Sam Ravnborg
  Cc: linux-kernel, Andrew Morton, Andy Lutomirski, Borislav Petkov,
	H . Peter Anvin, Linus Torvalds, Peter Zijlstra, Thomas Gleixner,
	Yinghai Lu, Arnaldo Carvalho de Melo


* Sam Ravnborg <sam@ravnborg.org> wrote:

> > Firsty, the headers are not maintained by the user-space project, 99.999% of 
> > the maintenance is done by the kernel developers.
> 
> In the inital mail triggering this plan was that the kernel is moving away from 
> having uapi headers what-so-ever.

No, that is a misunderstanding:

> Quoting the original mail:
> "
> 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. 
> "

You misunderstood my mail and you misunderstood the patch: we transition from the 
old UAPI header to a new one, but the exported data structures are still kept!

If you check the patches you'll see that bootparam.h still exports the e820_entry 
data structure. The 'old' header is simply one that is being phased out (if we 
can) - but the information is still exported.

> Translated:
> The plan is that the kernel will stop using headers from uapi/*
> The headers will be left for a while and then they will be deleted.

No, not at all.

> Perf being intimidate with the kernel is not the best example to come up with. 

No, that's wrong too, most larger tooling projects that care about feature 
propagation latency in fact already do something quite similar to what perf does.

For example the tooling side of GPU drivers (libdrm) has a copy of all the 
relevant UAPI headers:

triton:~/libdrm/include/drm> ls -l
total 316
-rw-rw-r-- 1 mingo mingo 19119 Feb  1 09:47 amdgpu_drm.h
-rw-rw-r-- 1 mingo mingo 11850 Feb  1 09:47 drm_fourcc.h
-rw-rw-r-- 1 mingo mingo 27613 Feb  1 09:47 drm.h
-rw-rw-r-- 1 mingo mingo 18313 Feb  1 09:47 drm_mode.h
-rw-rw-r-- 1 mingo mingo  2701 Feb  1 09:47 drm_sarea.h
-rw-rw-r-- 1 mingo mingo 46684 Feb  1 09:47 i915_drm.h
-rw-rw-r-- 1 mingo mingo  7895 Feb  1 09:47 mach64_drm.h
-rw-rw-r-- 1 mingo mingo 12923 Feb  1 09:47 mga_drm.h
-rw-rw-r-- 1 mingo mingo  5662 Feb  1 09:47 nouveau_drm.h
-rw-rw-r-- 1 mingo mingo  4217 Feb  1 09:47 qxl_drm.h
-rw-rw-r-- 1 mingo mingo  9901 Feb  1 09:47 r128_drm.h
-rw-rw-r-- 1 mingo mingo 38509 Feb  1 09:47 radeon_drm.h
-rw-rw-r-- 1 mingo mingo  5201 Feb  1 09:47 README
-rw-rw-r-- 1 mingo mingo  7054 Feb  1 09:47 savage_drm.h
-rw-rw-r-- 1 mingo mingo  2534 Feb  1 09:47 sis_drm.h
-rw-rw-r-- 1 mingo mingo  5526 Feb  1 09:47 tegra_drm.h
-rw-rw-r-- 1 mingo mingo  9534 Feb  1 09:47 vc4_drm.h
-rw-rw-r-- 1 mingo mingo  8291 Feb  1 09:47 via_drm.h
-rw-rw-r-- 1 mingo mingo  4704 Feb  1 09:47 virtgpu_drm.h
-rw-rw-r-- 1 mingo mingo 31225 Feb  1 09:47 vmwgfx_drm.h

For example i915_drm.h is a copy of include/uapi/drm/i915_drm.h, which is being 
synched between the two projects regularly.

> Think about to 100's of program that uses a few ioclt to talk with drivers etc.

Those can use distro UAPI headers just fine, if they don't care about the 6-12 
months delay it takes to get updated kernel headers. I.e. what you propose works 
for well-established ABIs that have been around for years.

To actually _progress_ with a tooling project, in close cooperation with the 
kernel side, the UAPI method of sharing via distro headers as-is hinders 
development agility big time...

Distro UAPI headers work fine in a world where the kernel is a static entity and 
does not update its ABIs. I.e. it only works if there's no actual kernel side 
extensions to the ABI. The whole UAPI distro headers approach is designed for the 
case where the style of sharing the headers matters the least: for a stagnant 
kernel or a stagnant tooling project ...

Btw., his kind of rigid, suboptimal, latency laden method of sharing information 
between the kernel and tooling might be one of the reasons why in general the 
Linux tooling landscape sucks, compared to other OSs...

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 65+ messages in thread

end of thread, other threads:[~2017-02-01  8:56 UTC | newest]

Thread overview: 65+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
2017-01-28 22:11 ` [PATCH 01/50] x86/boot/e820: Introduce arch/x86/include/asm/e820/types.h Ingo Molnar
2017-01-29 17:13   ` Sam Ravnborg
2017-01-30  7:58     ` Ingo Molnar
2017-01-31  5:41       ` Sam Ravnborg
2017-01-31 16:35         ` Ingo Molnar
2017-01-31 17:22           ` Sam Ravnborg
2017-01-31 18:00             ` Ingo Molnar
2017-01-31 18:04               ` Joe Perches
2017-01-31 19:17               ` Sam Ravnborg
2017-02-01  8:56                 ` Ingo Molnar
2017-01-28 22:11 ` [PATCH 02/50] x86/boot/e820: Clean up and improve comments in asm/e820/types.h Ingo Molnar
2017-01-28 22:11 ` [PATCH 03/50] x86/boot/e820: Move asm/e820.h to asm/e820/api.h Ingo Molnar
2017-01-28 22:11 ` [PATCH 04/50] x86/boot/e820: Split minimal UAPI types out into uapi/asm/e820/types.h Ingo Molnar
2017-01-28 22:11 ` [PATCH 05/50] x86/boot/e820: Clean up the E820_X_MAX definition Ingo Molnar
2017-01-28 22:11 ` [PATCH 06/50] x86/boot/e820: Remove spurious asm/e820/api.h inclusions Ingo Molnar
2017-01-28 22:11 ` [PATCH 07/50] x86/boot/e820: Remove assembly guard from asm/e820/types.h Ingo Molnar
2017-01-28 22:11 ` [PATCH 08/50] x86/boot/e820: Clean up asm/e820/api.h Ingo Molnar
2017-01-28 22:11 ` [PATCH 09/50] x86/boot/e820: Remove unnecessary __ASSEMBLY__ guard Ingo Molnar
2017-01-28 22:11 ` [PATCH 10/50] x86/boot/e820: Move HIGH_MEMORY define to asm/e820/types.h Ingo Molnar
2017-01-28 22:11 ` [PATCH 11/50] x86/boot/e820: Rename the basic e820 data types to 'struct e820_entry' and 'struct e820_array' Ingo Molnar
2017-01-28 22:11 ` [PATCH 12/50] x86/boot/e820: Remove unnecessary #include <linux/ioport.h> from asm/e820/api.h Ingo Molnar
2017-01-28 22:11 ` [PATCH 13/50] x86/boot/e820: Remove e820_mark_nosave_regions() definition uglies Ingo Molnar
2017-01-28 22:11 ` [PATCH 14/50] x86/boot/e820: Rename 'e820_map' variables to 'e820_array' Ingo Molnar
2017-01-28 22:11 ` [PATCH 15/50] x86/boot/e820: Rename everything to e820_table Ingo Molnar
2017-01-28 22:11 ` [PATCH 16/50] x86/boot/e820: Harmonize the 'struct e820_table' fields Ingo Molnar
2017-01-28 22:11 ` [PATCH 17/50] x86/boot/e820: Rename default_machine_specific_memory_setup() to e820__memory_setup_default() Ingo Molnar
2017-01-28 22:11 ` [PATCH 18/50] x86/boot/e820: Rename e820_table_saved to e820_table_firmware and improve the description Ingo Molnar
2017-01-28 22:11 ` [PATCH 19/50] x86/boot/e820: Basic cleanup of e820.c Ingo Molnar
2017-01-28 22:11 ` [PATCH 20/50] x86/boot/e820: Rename memblock_x86_fill() to e820__memblock_setup() and improve the explanations Ingo Molnar
2017-01-28 22:11 ` [PATCH 21/50] x86/boot/e820: Consolidate 'struct e820_entry *entry' local variable names Ingo Molnar
2017-01-28 22:11 ` [PATCH 22/50] x86/boot/e820: Convert printk(KERN_* ...) to pr_*() Ingo Molnar
2017-01-28 22:59   ` Joe Perches
2017-01-28 22:11 ` [PATCH 23/50] x86/boot/e820: Move the memblock_find_dma_reserve() function and rename it to memblock_set_dma_reserve() Ingo Molnar
2017-01-28 22:11 ` [PATCH 24/50] x86/boot/e820: Rename parse_e820_ext() to e820__memory_setup_extended() Ingo Molnar
2017-01-28 22:11 ` [PATCH 25/50] x86/boot/e820: Move e820_reserve_setup_data() to e820.c Ingo Molnar
2017-01-28 22:11 ` [PATCH 26/50] x86/boot/e820: Clarify the role of finish_e820_parsing() and rename it to e820__finish_early_params() Ingo Molnar
2017-01-28 22:11 ` [PATCH 27/50] x86/boot/e820: Rename early_reserve_e820() to e820__memblock_alloc() and document it Ingo Molnar
2017-01-28 22:11 ` [PATCH 28/50] x86/boot/e820: Rename update_e820() to e820__update_table() Ingo Molnar
2017-01-28 22:11 ` [PATCH 29/50] x86/boot/e820: Rename sanitize_e820_table() " Ingo Molnar
2017-01-28 22:11 ` [PATCH 30/50] x86/boot/e820: Rename e820_any_mapped()/e820_all_mapped() to e820__mapped_any()/e820__mapped_all() Ingo Molnar
2017-01-28 22:11 ` [PATCH 31/50] x86/boot/e820: Rename e820_setup_gap() to e820__setup_pci_gap() Ingo Molnar
2017-01-28 22:11 ` [PATCH 32/50] x86/boot/e820: Create coherent API function names for E820 range operations Ingo Molnar
2017-01-28 22:11 ` [PATCH 33/50] x86/boot/e820: Rename e820_print_map() to e820__print_table() Ingo Molnar
2017-01-28 22:11 ` [PATCH 34/50] x86/boot/e820: Reorder the function prototypes in api.h Ingo Molnar
2017-01-28 22:11 ` [PATCH 35/50] x86/boot/e820: Simplify e820_reserve_resources() Ingo Molnar
2017-01-28 22:11 ` [PATCH 36/50] x86/boot/e820: Introduce 'enum e820_type' Ingo Molnar
2017-01-28 22:11 ` [PATCH 37/50] x86/boot/e820: Use 'enum e820_type' in 'struct e820_entry' Ingo Molnar
2017-01-28 23:07   ` Linus Torvalds
2017-01-29  9:19     ` Ingo Molnar
2017-01-29 12:38       ` [PATCH] x86/boot/e820: Separate the E820 ABI structures from the in-kernel structures Ingo Molnar
2017-01-29 18:53       ` [PATCH 37/50] x86/boot/e820: Use 'enum e820_type' in 'struct e820_entry' Linus Torvalds
2017-01-28 22:11 ` [PATCH 38/50] x86/boot/e820: Use 'enum e820_type' when handling the e820 region type Ingo Molnar
2017-01-28 22:12 ` [PATCH 39/50] x86/boot/e820: Prefix the E820_* type names with "E820_TYPE_" Ingo Molnar
2017-01-28 22:12 ` [PATCH 40/50] x86/boot/e820: Clean up the E820 table size define names Ingo Molnar
2017-01-28 22:12 ` [PATCH 41/50] x86/boot/e820: Clean up and standardize sizeof() uses Ingo Molnar
2017-01-28 22:12 ` [PATCH 42/50] xen, x86/boot/e820: Simplify Xen's xen_e820_table construct Ingo Molnar
2017-01-28 22:12 ` [PATCH 43/50] x86/boot/e820: Simplify the e820__update_table() interface Ingo Molnar
2017-01-28 22:12 ` [PATCH 44/50] x86/boot/e820: Clean up __e820__update_table() et al Ingo Molnar
2017-01-28 22:12 ` [PATCH 45/50] x86/boot/e820: Document e820__reserve_setup_data() Ingo Molnar
2017-01-28 22:12 ` [PATCH 46/50] x86/boot/e820: Use bool in query APIs Ingo Molnar
2017-01-28 22:12 ` [PATCH 47/50] x86/boot/e820: Rename e820_reserve_resources*() to e820__reserve_resources*() Ingo Molnar
2017-01-28 22:12 ` [PATCH 48/50] x86/boot/e820: Rename e820_mark_nosave_regions() to e820__register_nosave_regions() Ingo Molnar
2017-01-28 22:12 ` [PATCH 49/50] x86/boot/e820: Remove unnecessary #include's Ingo Molnar
2017-01-28 22:12 ` [PATCH 50/50] x86/boot/e820: Rename the remaining E820 APIs to the e820__*() prefix Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).