]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
Merge branch 'x86-boot-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 2 May 2017 03:51:12 +0000 (20:51 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 2 May 2017 03:51:12 +0000 (20:51 -0700)
Pull x86 boot updates from Ingo Molnar:
 "The biggest changes in this cycle were:

   - reworking of the e820 code: separate in-kernel and boot-ABI data
     structures and apply a whole range of cleanups to the kernel side.

     No change in functionality.

   - enable KASLR by default: it's used by all major distros and it's
     out of the experimental stage as well.

   - ... misc fixes and cleanups"

* 'x86-boot-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (63 commits)
  x86/KASLR: Fix kexec kernel boot crash when KASLR randomization fails
  x86/reboot: Turn off KVM when halting a CPU
  x86/boot: Fix BSS corruption/overwrite bug in early x86 kernel startup
  x86: Enable KASLR by default
  boot/param: Move next_arg() function to lib/cmdline.c for later reuse
  x86/boot: Fix Sparse warning by including required header file
  x86/boot/64: Rename start_cpu()
  x86/xen: Update e820 table handling to the new core x86 E820 code
  x86/boot: Fix pr_debug() API braindamage
  xen, x86/headers: Add <linux/device.h> dependency to <asm/xen/page.h>
  x86/boot/e820: Simplify e820__update_table()
  x86/boot/e820: Separate the E820 ABI structures from the in-kernel structures
  x86/boot/e820: Fix and clean up e820_type switch() statements
  x86/boot/e820: Rename the remaining E820 APIs to the e820__*() prefix
  x86/boot/e820: Remove unnecessary #include's
  x86/boot/e820: Rename e820_mark_nosave_regions() to e820__register_nosave_regions()
  x86/boot/e820: Rename e820_reserve_resources*() to e820__reserve_resources*()
  x86/boot/e820: Use bool in query APIs
  x86/boot/e820: Document e820__reserve_setup_data()
  x86/boot/e820: Clean up __e820__update_table() et al
  ...

17 files changed:
1  2 
arch/x86/Kconfig
arch/x86/configs/x86_64_defconfig
arch/x86/include/asm/pgtable.h
arch/x86/include/uapi/asm/bootparam.h
arch/x86/kernel/acpi/boot.c
arch/x86/kernel/apic/apic.c
arch/x86/kernel/apic/x2apic_uv_x.c
arch/x86/kernel/cpu/centaur.c
arch/x86/kernel/head64.c
arch/x86/kernel/smp.c
arch/x86/lguest/boot.c
arch/x86/mm/init.c
arch/x86/mm/kasan_init_64.c
arch/x86/platform/efi/efi_64.c
arch/x86/platform/efi/quirks.c
drivers/acpi/tables.c
tools/lguest/lguest.c

diff --combined arch/x86/Kconfig
index 2a00902e657a1386e0525c4f55dfa48c761824c0,dc12dddb40b2e199c77ed589329ecdd86f902185..a05571937ad33cbe5d86b956cc587c74b5db2d9b
@@@ -98,6 -98,7 +98,6 @@@ config X8
        select HAVE_ACPI_APEI_NMI               if ACPI
        select HAVE_ALIGNED_STRUCT_PAGE         if SLUB
        select HAVE_ARCH_AUDITSYSCALL
 -      select HAVE_ARCH_HARDENED_USERCOPY
        select HAVE_ARCH_HUGE_VMAP              if X86_64 || X86_PAE
        select HAVE_ARCH_JUMP_LABEL
        select HAVE_ARCH_KASAN                  if X86_64 && SPARSEMEM_VMEMMAP
@@@ -1042,14 -1043,6 +1042,14 @@@ config X86_MC
          The action the kernel takes depends on the severity of the problem,
          ranging from warning messages to halting the machine.
  
 +config X86_MCELOG_LEGACY
 +      bool "Support for deprecated /dev/mcelog character device"
 +      depends on X86_MCE
 +      ---help---
 +        Enable support for /dev/mcelog which is needed by the old mcelog
 +        userspace logging daemon. Consider switching to the new generation
 +        rasdaemon solution.
 +
  config X86_MCE_INTEL
        def_bool y
        prompt "Intel MCE features"
@@@ -1079,7 -1072,7 +1079,7 @@@ config X86_MCE_THRESHOL
        def_bool y
  
  config X86_MCE_INJECT
 -      depends on X86_MCE && X86_LOCAL_APIC
 +      depends on X86_MCE && X86_LOCAL_APIC && X86_MCELOG_LEGACY
        tristate "Machine check injector support"
        ---help---
          Provide support for injecting machine checks for testing purposes.
@@@ -1973,7 -1966,7 +1973,7 @@@ config RELOCATABL
  config RANDOMIZE_BASE
        bool "Randomize the address of the kernel image (KASLR)"
        depends on RELOCATABLE
-       default n
+       default y
        ---help---
          In support of Kernel Address Space Layout Randomization (KASLR),
          this randomizes the physical address at which the kernel image
          theoretically possible, but the implementations are further
          limited due to memory layouts.
  
-         If unsure, say N.
+         If unsure, say Y.
  
  # Relocation on x86 needs some additional build support
  config X86_NEED_RELOCS
@@@ -2052,7 -2045,7 +2052,7 @@@ config RANDOMIZE_MEMOR
           configuration have in average 30,000 different possible virtual
           addresses for each memory section.
  
-          If unsure, say N.
+          If unsure, say Y.
  
  config RANDOMIZE_MEMORY_PHYSICAL_PADDING
        hex "Physical memory mapping padding" if EXPERT
index 6205d3b81e6d117b4116c2fa38ea40cea4a46fb8,8a9521b6a5376c7bd6c72af53e12477abe99ccea..de45f57b410deb314ee0b6a89af702866cc23c02
@@@ -55,6 -55,8 +55,8 @@@ CONFIG_EFI=
  CONFIG_HZ_1000=y
  CONFIG_KEXEC=y
  CONFIG_CRASH_DUMP=y
+ CONFIG_RANDOMIZE_BASE=y
+ CONFIG_RANDOMIZE_MEMORY=y
  # CONFIG_COMPAT_VDSO is not set
  CONFIG_HIBERNATION=y
  CONFIG_PM_DEBUG=y
@@@ -176,7 -178,6 +178,7 @@@ CONFIG_E1000E=
  CONFIG_SKY2=y
  CONFIG_FORCEDETH=y
  CONFIG_8139TOO=y
 +CONFIG_R8169=y
  CONFIG_FDDI=y
  CONFIG_INPUT_POLLDEV=y
  # CONFIG_INPUT_MOUSEDEV_PSAUX is not set
index 585ee0d42d18fc162601ff0d8a53827f0d011f5e,eef5fbc7c67437ae40f5a8788069e3e9c3361813..2197e5322df9d8a543b0c82884b3feea8ce93e80
@@@ -2,8 -2,6 +2,6 @@@
  #define _ASM_X86_PGTABLE_H
  
  #include <asm/page.h>
- #include <asm/e820.h>
  #include <asm/pgtable_types.h>
  
  /*
@@@ -62,7 -60,7 +60,7 @@@ extern struct mm_struct *pgd_page_get_m
  # define set_pud(pudp, pud)           native_set_pud(pudp, pud)
  #endif
  
 -#ifndef __PAGETABLE_PMD_FOLDED
 +#ifndef __PAGETABLE_PUD_FOLDED
  #define pud_clear(pud)                        native_pud_clear(pud)
  #endif
  
@@@ -845,6 -843,7 +843,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. */
index 07244ea16765a6bc77e1107233c65fc7286f0e8b,41af92e473cfe8bd50f6352178dc1966893f3363..ddef37b16af2c92ccef2b23088763a211dab6ea6
@@@ -34,7 -34,6 +34,6 @@@
  #include <linux/screen_info.h>
  #include <linux/apm_bios.h>
  #include <linux/edd.h>
- #include <asm/e820.h>
  #include <asm/ist.h>
  #include <video/edid.h>
  
@@@ -58,7 -57,7 +57,7 @@@ struct setup_header 
        __u32   header;
        __u16   version;
        __u32   realmode_swtch;
 -      __u16   start_sys;
 +      __u16   start_sys_seg;
        __u16   kernel_version;
        __u8    type_of_loader;
        __u8    loadflags;
@@@ -111,6 -110,21 +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 */
        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 boot_e820_entry e820_table[E820_MAX_ENTRIES_ZEROPAGE]; /* 0x2d0 */
        __u8  _pad8[48];                                /* 0xcd0 */
        struct edd_info eddbuf[EDDMAXNR];               /* 0xd00 */
        __u8  _pad9[276];                               /* 0xeec */
index 70854988a963fb39b2ea84f1e2dce7b51ffd8262,a468f0fdc9075bbdc04d75f5105620c97d0ddf48..6bb680671088694af194eabd987fc86b2b02441d
@@@ -37,6 -37,7 +37,7 @@@
  #include <linux/pci.h>
  #include <linux/efi-bgrt.h>
  
+ #include <asm/e820/api.h>
  #include <asm/irqdomain.h>
  #include <asm/pci_x86.h>
  #include <asm/pgtable.h>
@@@ -179,15 -180,10 +180,15 @@@ static int acpi_register_lapic(int id, 
                return -EINVAL;
        }
  
 +      if (!enabled) {
 +              ++disabled_cpus;
 +              return -EINVAL;
 +      }
 +
        if (boot_cpu_physical_apicid != -1U)
                ver = boot_cpu_apic_version;
  
 -      cpu = __generic_processor_info(id, ver, enabled);
 +      cpu = generic_processor_info(id, ver);
        if (cpu >= 0)
                early_per_cpu(x86_cpu_to_acpiid, cpu) = acpiid;
  
@@@ -715,7 -711,7 +716,7 @@@ static void __init acpi_set_irq_model_i
  #ifdef CONFIG_ACPI_HOTPLUG_CPU
  #include <acpi/processor.h>
  
 -int acpi_map_cpu2node(acpi_handle handle, int cpu, int physid)
 +static int acpi_map_cpu2node(acpi_handle handle, int cpu, int physid)
  {
  #ifdef CONFIG_ACPI_NUMA
        int nid;
@@@ -1564,6 -1560,12 +1565,6 @@@ int __init early_acpi_boot_init(void
        return 0;
  }
  
 -static int __init acpi_parse_bgrt(struct acpi_table_header *table)
 -{
 -      efi_bgrt_init(table);
 -      return 0;
 -}
 -
  int __init acpi_boot_init(void)
  {
        /* those are executed after early-quirks are executed */
@@@ -1723,6 -1725,6 +1724,6 @@@ int __acpi_release_global_lock(unsigne
  
  void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size)
  {
-       e820_add_region(addr, size, E820_ACPI);
-       update_e820();
+       e820__range_add(addr, size, E820_TYPE_ACPI);
+       e820__update_table_print();
  }
index 875091d4609d95daa37b9c46b45393e7f2fd8eac,4eca103a1e01d3473e57413530a08b0d64fe5b3a..847650b14558059f386865b838d145f490d2a3fa
@@@ -731,10 -731,8 +731,10 @@@ static int __init calibrate_APIC_clock(
                                        TICK_NSEC, lapic_clockevent.shift);
                lapic_clockevent.max_delta_ns =
                        clockevent_delta2ns(0x7FFFFF, &lapic_clockevent);
 +              lapic_clockevent.max_delta_ticks = 0x7FFFFF;
                lapic_clockevent.min_delta_ns =
                        clockevent_delta2ns(0xF, &lapic_clockevent);
 +              lapic_clockevent.min_delta_ticks = 0xF;
                lapic_clockevent.features &= ~CLOCK_EVT_FEAT_DUMMY;
                return 0;
        }
                                       lapic_clockevent.shift);
        lapic_clockevent.max_delta_ns =
                clockevent_delta2ns(0x7FFFFFFF, &lapic_clockevent);
 +      lapic_clockevent.max_delta_ticks = 0x7FFFFFFF;
        lapic_clockevent.min_delta_ns =
                clockevent_delta2ns(0xF, &lapic_clockevent);
 +      lapic_clockevent.min_delta_ticks = 0xF;
  
        lapic_timer_frequency = (delta * APIC_DIVISOR) / LAPIC_CAL_LOOPS;
  
@@@ -1614,15 -1610,24 +1614,15 @@@ static inline void try_to_enable_x2apic
  static inline void __x2apic_enable(void) { }
  #endif /* !CONFIG_X86_X2APIC */
  
 -static int __init try_to_enable_IR(void)
 -{
 -#ifdef CONFIG_X86_IO_APIC
 -      if (!x2apic_enabled() && skip_ioapic_setup) {
 -              pr_info("Not enabling interrupt remapping due to skipped IO-APIC setup\n");
 -              return -1;
 -      }
 -#endif
 -      return irq_remapping_enable();
 -}
 -
  void __init enable_IR_x2apic(void)
  {
        unsigned long flags;
        int ret, ir_stat;
  
 -      if (skip_ioapic_setup)
 +      if (skip_ioapic_setup) {
 +              pr_info("Not enabling interrupt remapping due to skipped IO-APIC setup\n");
                return;
 +      }
  
        ir_stat = irq_remapping_prepare();
        if (ir_stat < 0 && !x2apic_supported())
  
        /* If irq_remapping_prepare() succeeded, try to enable it */
        if (ir_stat >= 0)
 -              ir_stat = try_to_enable_IR();
 +              ir_stat = irq_remapping_enable();
        /* ir_stat contains the remap mode or an error code */
        try_to_enable_x2apic(ir_stat);
  
@@@ -2057,17 -2062,17 +2057,17 @@@ static int allocate_logical_cpuid(int a
  
        /* Allocate a new cpuid. */
        if (nr_logical_cpuids >= nr_cpu_ids) {
 -              WARN_ONCE(1, "Only %d processors supported."
 +              WARN_ONCE(1, "APIC: NR_CPUS/possible_cpus limit of %i reached. "
                             "Processor %d/0x%x and the rest are ignored.\n",
 -                           nr_cpu_ids - 1, nr_logical_cpuids, apicid);
 -              return -1;
 +                           nr_cpu_ids, nr_logical_cpuids, apicid);
 +              return -EINVAL;
        }
  
        cpuid_to_apicid[nr_logical_cpuids] = apicid;
        return nr_logical_cpuids++;
  }
  
 -int __generic_processor_info(int apicid, int version, bool enabled)
 +int generic_processor_info(int apicid, int version)
  {
        int cpu, max = nr_cpu_ids;
        bool boot_cpu_detected = physid_isset(boot_cpu_physical_apicid,
        if (num_processors >= nr_cpu_ids) {
                int thiscpu = max + disabled_cpus;
  
 -              if (enabled) {
 -                      pr_warning("APIC: NR_CPUS/possible_cpus limit of %i "
 -                                 "reached. Processor %d/0x%x ignored.\n",
 -                                 max, thiscpu, apicid);
 -              }
 +              pr_warning("APIC: NR_CPUS/possible_cpus limit of %i "
 +                         "reached. Processor %d/0x%x ignored.\n",
 +                         max, thiscpu, apicid);
  
                disabled_cpus++;
                return -EINVAL;
                apic->x86_32_early_logical_apicid(cpu);
  #endif
        set_cpu_possible(cpu, true);
 -
 -      if (enabled) {
 -              num_processors++;
 -              physid_set(apicid, phys_cpu_present_map);
 -              set_cpu_present(cpu, true);
 -      } else {
 -              disabled_cpus++;
 -      }
 +      physid_set(apicid, phys_cpu_present_map);
 +      set_cpu_present(cpu, true);
 +      num_processors++;
  
        return cpu;
  }
  
 -int generic_processor_info(int apicid, int version)
 -{
 -      return __generic_processor_info(apicid, version, true);
 -}
 -
  int hard_smp_processor_id(void)
  {
        return read_apic_id();
@@@ -2631,7 -2648,7 +2631,7 @@@ static int __init lapic_insert_resource
  }
  
  /*
-  * need call insert after e820_reserve_resources()
+  * need call insert after e820__reserve_resources()
   * that is using request_resource
   */
  late_initcall(lapic_insert_resource);
index 86f20cc0a65e2240b2eb5a05fa77af3e866b40d6,7f179f1c467cba9fd12125b6161689d58f7f50d6..b487b3a016153d2b5a66e0b1334fe203ed992e7e
@@@ -34,6 -34,7 +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>
@@@ -1105,8 -1106,7 +1106,8 @@@ void __init uv_init_hub_info(struct uv_
        node_id.v               = uv_read_local_mmr(UVH_NODE_ID);
        uv_cpuid.gnode_shift    = max_t(unsigned int, uv_cpuid.gnode_shift, mn.n_val);
        hi->gnode_extra         = (node_id.s.node_id & ~((1 << uv_cpuid.gnode_shift) - 1)) >> 1;
 -      hi->gnode_upper         = (unsigned long)hi->gnode_extra << mn.m_val;
 +      if (mn.m_val)
 +              hi->gnode_upper = (u64)hi->gnode_extra << mn.m_val;
  
        if (uv_gp_table) {
                hi->global_mmr_base     = uv_gp_table->mmr_base;
index 43955ee6715b1876b89ebd615b8eb171bbde1dd0,106bd3318121ae8a57758b1e4ca57606a6d87e93..44207b71fee17ca2e5eae3b4286f2056f75d1c68
@@@ -3,7 -3,7 +3,7 @@@
  #include <linux/sched/clock.h>
  
  #include <asm/cpufeature.h>
- #include <asm/e820.h>
+ #include <asm/e820/api.h>
  #include <asm/mtrr.h>
  #include <asm/msr.h>
  
@@@ -105,6 -105,8 +105,6 @@@ static void early_init_centaur(struct c
  #ifdef CONFIG_X86_64
        set_cpu_cap(c, X86_FEATURE_SYSENTER32);
  #endif
 -
 -      clear_sched_clock_stable();
  }
  
  static void init_centaur(struct cpuinfo_x86 *c)
diff --combined arch/x86/kernel/head64.c
index b5785c197e534796d5e477b6cd86a502d229db7c,baa0e7b78d80f7d803400642d0eabce82f25ccf5..43b7002f44fb5734d13f273943933d6b47b8e644
@@@ -4,7 -4,6 +4,7 @@@
   *  Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
   */
  
 +#define DISABLE_BRANCH_PROFILING
  #include <linux/init.h>
  #include <linux/linkage.h>
  #include <linux/types.h>
@@@ -24,7 -23,7 +24,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 --combined arch/x86/kernel/smp.c
index 3cab8415389a9ac445998ce8995142f4ae1be4f4,9d7223cad38922efa4db2f90fc2be66dda574438..d798c0da451c80a2e249af32758ca86f926538a3
@@@ -33,6 -33,7 +33,7 @@@
  #include <asm/mce.h>
  #include <asm/trace/irq_vectors.h>
  #include <asm/kexec.h>
+ #include <asm/virtext.h>
  
  /*
   *    Some notes on x86 processor bugs affecting SMP operation:
@@@ -124,7 -125,7 +125,7 @@@ static bool smp_no_nmi_ipi = false
  static void native_smp_send_reschedule(int cpu)
  {
        if (unlikely(cpu_is_offline(cpu))) {
 -              WARN_ON(1);
 +              WARN(1, "sched: Unexpected reschedule of offline CPU#%d!\n", cpu);
                return;
        }
        apic->send_IPI(cpu, RESCHEDULE_VECTOR);
@@@ -162,6 -163,7 +163,7 @@@ static int smp_stop_nmi_callback(unsign
        if (raw_smp_processor_id() == atomic_read(&stopping_cpu))
                return NMI_HANDLED;
  
+       cpu_emergency_vmxoff();
        stop_this_cpu(NULL);
  
        return NMI_HANDLED;
  asmlinkage __visible void smp_reboot_interrupt(void)
  {
        ipi_entering_ack_irq();
+       cpu_emergency_vmxoff();
        stop_this_cpu(NULL);
        irq_exit();
  }
diff --combined arch/x86/lguest/boot.c
index 3e4bf887a2464cef19d186e4084c3c2de7773c81,7aa6336862951a9529a9a33e9acebdf73e7f68b7..99472698c9311f1b55891a18fec1f99336c87915
@@@ -67,7 -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>
@@@ -994,9 -994,7 +994,9 @@@ static struct clock_event_device lguest
        .mult                   = 1,
        .shift                  = 0,
        .min_delta_ns           = LG_CLOCK_MIN_DELTA,
 +      .min_delta_ticks        = LG_CLOCK_MIN_DELTA,
        .max_delta_ns           = LG_CLOCK_MAX_DELTA,
 +      .max_delta_ticks        = LG_CLOCK_MAX_DELTA,
  };
  
  /*
@@@ -1180,9 -1178,9 +1180,9 @@@ static __init char *lguest_memory_setup
         * 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__range_add(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 --combined arch/x86/mm/init.c
index 889e7619a0914d87ad49dbb5b960933e5dd316ad,2193799ca800982ad9713fd03ba70fc86fce3d9a..138bad2fb6bcd364826f75fa2be42e09904718a6
@@@ -6,7 -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>
@@@ -373,14 -373,14 +373,14 @@@ static int __meminit split_mem_range(st
        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);
  
@@@ -430,7 -430,7 +430,7 @@@ unsigned long __ref init_memory_mapping
  
  /*
   * 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.
@@@ -643,40 -643,21 +643,40 @@@ void __init init_mem_mapping(void
   * devmem_is_allowed() checks to see if /dev/mem access to a certain address
   * is valid. The argument is a physical page number.
   *
 - *
 - * On x86, access has to be given to the first megabyte of ram because that area
 - * contains BIOS code and data regions used by X and dosemu and similar apps.
 - * Access has to be given to non-kernel-ram areas as well, these contain the PCI
 - * mmio resources as well as potential bios/acpi data regions.
 + * On x86, access has to be given to the first megabyte of RAM because that
 + * area traditionally contains BIOS code and data regions used by X, dosemu,
 + * and similar apps. Since they map the entire memory range, the whole range
 + * must be allowed (for mapping), but any areas that would otherwise be
 + * disallowed are flagged as being "zero filled" instead of rejected.
 + * Access has to be given to non-kernel-ram areas as well, these contain the
 + * PCI mmio resources as well as potential bios/acpi data regions.
   */
  int devmem_is_allowed(unsigned long pagenr)
  {
 -      if (pagenr < 256)
 -              return 1;
 -      if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
 +      if (page_is_ram(pagenr)) {
 +              /*
 +               * For disallowed memory regions in the low 1MB range,
 +               * request that the page be shown as all zeros.
 +               */
 +              if (pagenr < 256)
 +                      return 2;
 +
 +              return 0;
 +      }
 +
 +      /*
 +       * This must follow RAM test, since System RAM is considered a
 +       * restricted resource under CONFIG_STRICT_IOMEM.
 +       */
 +      if (iomem_is_exclusive(pagenr << PAGE_SHIFT)) {
 +              /* Low 1MB bypasses iomem restrictions. */
 +              if (pagenr < 256)
 +                      return 1;
 +
                return 0;
 -      if (!page_is_ram(pagenr))
 -              return 1;
 -      return 0;
 +      }
 +
 +      return 1;
  }
  
  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),
@@@ -743,6 -724,53 +743,53 @@@ void __init free_initrd_mem(unsigned lo
  }
  #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];
index 4c90cfdc128b832c6065cdb8830f89d16bff63dd,66d20174e35f5222a29be27553a78c54b257ca88..da92df32d0f19a82bdbbeccb0878c110946152c0
@@@ -1,4 -1,3 +1,4 @@@
 +#define DISABLE_BRANCH_PROFILING
  #define pr_fmt(fmt) "kasan: " fmt
  #include <linux/bootmem.h>
  #include <linux/kasan.h>
@@@ -8,11 -7,12 +8,12 @@@
  #include <linux/sched/task.h>
  #include <linux/vmalloc.h>
  
+ #include <asm/e820/types.h>
  #include <asm/tlbflush.h>
  #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)
  {
@@@ -104,7 -104,7 +105,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;
  
index 6cbf9e036aa84711e6d6a031928abf31edb01e08,2ee7694362a5028d6e4ecbb530444d648b58c6a6..642a8698ad61e22ceed781af013861c837368151
@@@ -35,7 -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>
@@@ -47,7 -47,7 +47,7 @@@
  #include <asm/pgalloc.h>
  
  /*
 - * We allocate runtime services regions bottom-up, starting from -4G, i.e.
 + * We allocate runtime services regions top-down, starting from -4G, i.e.
   * 0xffff_ffff_0000_0000 and limit EFI VA mapping space to 64G.
   */
  static u64 efi_va = EFI_VA_START;
index cdfe8c62895981029b8f69218b717b05d0b8961a,3c8d8e511fd495243f360f52e96674d80345a648..26615991d69cc8b024470c921aca227c2756e439
@@@ -11,6 -11,8 +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>
  
@@@ -201,10 -203,6 +203,10 @@@ void __init efi_arch_mem_reserve(phys_a
                return;
        }
  
 +      /* No need to reserve regions that will never be freed. */
 +      if (md.attribute & EFI_MEMORY_RUNTIME)
 +              return;
 +
        size += addr % EFI_PAGE_SIZE;
        size = round_up(size, EFI_PAGE_SIZE);
        addr = round_down(addr, EFI_PAGE_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_all_mapped(start, start+size, E820_RAM))
+       if (!e820__mapped_all(start, start+size, E820_TYPE_RAM))
                return false;
  
        return true;
@@@ -284,7 -282,7 +286,7 @@@ void __init efi_reserve_boot_services(v
                 * 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 --combined drivers/acpi/tables.c
index 0dae722ab2ec859a8cc937368da252f5a3c153f8,9b9ac04593fb5134e8b03f2ad5ebf9e75276b7e5..ff425390bfa8d24b6c089a8cb427210a70740ad4
@@@ -310,6 -310,22 +310,6 @@@ acpi_parse_entries_array(char *id, unsi
        return errs ? -EINVAL : count;
  }
  
 -int __init
 -acpi_parse_entries(char *id,
 -                      unsigned long table_size,
 -                      acpi_tbl_entry_handler handler,
 -                      struct acpi_table_header *table_header,
 -                      int entry_id, unsigned int max_entries)
 -{
 -      struct acpi_subtable_proc proc = {
 -              .id             = entry_id,
 -              .handler        = handler,
 -      };
 -
 -      return acpi_parse_entries_array(id, table_size, table_header,
 -                      &proc, 1, max_entries);
 -}
 -
  int __init
  acpi_table_parse_entries_array(char *id,
                         unsigned long table_size,
@@@ -540,7 -556,7 +540,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);
diff --combined tools/lguest/lguest.c
index 5d19fdf80292c226769a91ccef519a47b3788b2b,4e38ea02ef0fac1e3365d1963079fa478b5c6ae2..897cd6f3f68720342f7b11ac6e20b4e6e027bad6
@@@ -1387,7 -1387,7 +1387,7 @@@ static bool pci_data_iowrite(u16 port, 
                /* Allow writing to any other BAR, or expansion ROM */
                iowrite(portoff, val, mask, &d->config_words[reg]);
                return true;
 -              /* We let them overide latency timer and cacheline size */
 +              /* We let them override latency timer and cacheline size */
        } else if (&d->config_words[reg] == (void *)&d->config.cacheline_size) {
                /* Only let them change the first two fields. */
                if (mask == 0xFFFFFFFF)
@@@ -3339,7 -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_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.