Merge branch 'WIP.x86/asm' into x86/urgent, because the topic is ready
authorIngo Molnar <mingo@kernel.org>
Thu, 12 Apr 2018 07:42:34 +0000 (09:42 +0200)
committerIngo Molnar <mingo@kernel.org>
Thu, 12 Apr 2018 07:42:34 +0000 (09:42 +0200)
Signed-off-by: Ingo Molnar <mingo@kernel.org>
1  2 
arch/x86/Kconfig
arch/x86/include/asm/apic.h
arch/x86/kernel/acpi/boot.c
arch/x86/kernel/apic/x2apic_phys.c
arch/x86/xen/apic.c
lib/swiotlb.c

diff --combined arch/x86/Kconfig
@@@ -29,6 -29,7 +29,7 @@@ config X86_6
        select HAVE_ARCH_SOFT_DIRTY
        select MODULES_USE_ELF_RELA
        select X86_DEV_DMA_OPS
+       select ARCH_HAS_SYSCALL_WRAPPER
  
  #
  # Arch settings
@@@ -54,7 -55,6 +55,6 @@@ config X8
        select ARCH_HAS_FORTIFY_SOURCE
        select ARCH_HAS_GCOV_PROFILE_ALL
        select ARCH_HAS_KCOV                    if X86_64
-       select ARCH_HAS_PHYS_TO_DMA
        select ARCH_HAS_MEMBARRIER_SYNC_CORE
        select ARCH_HAS_PMEM_API                if X86_64
        select ARCH_HAS_REFCOUNT
@@@ -83,6 -83,7 +83,7 @@@
        select CLOCKSOURCE_VALIDATE_LAST_CYCLE
        select CLOCKSOURCE_WATCHDOG
        select DCACHE_WORD_ACCESS
+       select DMA_DIRECT_OPS
        select EDAC_ATOMIC_SCRUB
        select EDAC_SUPPORT
        select GENERIC_CLOCKEVENTS
@@@ -393,17 -394,6 +394,6 @@@ config X86_FEATURE_NAME
  
          If in doubt, say Y.
  
- config X86_FAST_FEATURE_TESTS
-       bool "Fast CPU feature tests" if EMBEDDED
-       default y
-       ---help---
-         Some fast-paths in the kernel depend on the capabilities of the CPU.
-         Say Y here for the kernel to patch in the appropriate code at runtime
-         based on the capabilities of the CPU. The infrastructure for patching
-         code at runtime takes up some additional space; space-constrained
-         embedded systems may wish to say N here to produce smaller, slightly
-         slower code.
  config X86_X2APIC
        bool "Support x2apic"
        depends on X86_LOCAL_APIC && X86_64 && (IRQ_REMAP || HYPERVISOR_GUEST)
@@@ -691,6 -681,7 +681,7 @@@ config X86_SUPPORTS_MEMORY_FAILUR
  config STA2X11
        bool "STA2X11 Companion Chip Support"
        depends on X86_32_NON_STANDARD && PCI
+       select ARCH_HAS_PHYS_TO_DMA
        select X86_DEV_DMA_OPS
        select X86_DMA_REMAP
        select SWIOTLB
@@@ -1472,6 -1463,8 +1463,8 @@@ config X86_PA
  
  config X86_5LEVEL
        bool "Enable 5-level page tables support"
+       select DYNAMIC_MEMORY_LAYOUT
+       select SPARSEMEM_VMEMMAP
        depends on X86_64
        ---help---
          5-level paging enables access to larger address space:
  
          It will be supported by future Intel CPUs.
  
-         Note: a kernel with this option enabled can only be booted
-         on machines that support the feature.
+         A kernel with the option enabled can be booted on machines that
+         support 4- or 5-level paging.
  
          See Documentation/x86/x86_64/5level-paging.txt for more
          information.
@@@ -1606,10 -1599,6 +1599,6 @@@ config ARCH_HAVE_MEMORY_PRESEN
        def_bool y
        depends on X86_32 && DISCONTIGMEM
  
- config NEED_NODE_MEMMAP_SIZE
-       def_bool y
-       depends on X86_32 && (DISCONTIGMEM || SPARSEMEM)
  config ARCH_FLATMEM_ENABLE
        def_bool y
        depends on X86_32 && !NUMA
@@@ -2185,10 -2174,17 +2174,17 @@@ config PHYSICAL_ALIG
  
          Don't change this unless you know what you are doing.
  
+ config DYNAMIC_MEMORY_LAYOUT
+       bool
+       ---help---
+         This option makes base addresses of vmalloc and vmemmap as well as
+         __PAGE_OFFSET movable during boot.
  config RANDOMIZE_MEMORY
        bool "Randomize the kernel memory sections"
        depends on X86_64
        depends on RANDOMIZE_BASE
+       select DYNAMIC_MEMORY_LAYOUT
        default RANDOMIZE_BASE
        ---help---
           Randomizes the base virtual address of kernel memory sections
@@@ -2307,7 -2303,7 +2303,7 @@@ choic
          it can be used to assist security vulnerability exploitation.
  
          This setting can be changed at boot time via the kernel command
-         line parameter vsyscall=[native|emulate|none].
+         line parameter vsyscall=[emulate|none].
  
          On a system with recent enough glibc (2.14 or newer) and no
          static binaries, you can say None without a performance penalty
  
          If unsure, select "Emulate".
  
-       config LEGACY_VSYSCALL_NATIVE
-               bool "Native"
-               help
-                 Actual executable code is located in the fixed vsyscall
-                 address mapping, implementing time() efficiently. Since
-                 this makes the mapping executable, it can be used during
-                 security vulnerability exploitation (traditionally as
-                 ROP gadgets). This configuration is not recommended.
        config LEGACY_VSYSCALL_EMULATE
                bool "Emulate"
                help
@@@ -2641,8 -2628,10 +2628,10 @@@ config PCI_DIREC
        depends on PCI && (X86_64 || (PCI_GODIRECT || PCI_GOANY || PCI_GOOLPC || PCI_GOMMCONFIG))
  
  config PCI_MMCONFIG
-       def_bool y
-       depends on X86_32 && PCI && (ACPI || SFI) && (PCI_GOMMCONFIG || PCI_GOANY)
+       bool "Support mmconfig PCI config space access" if X86_64
+       default y
+       depends on PCI && (ACPI || SFI || JAILHOUSE_GUEST)
+       depends on X86_64 || (PCI_GOANY || PCI_GOMMCONFIG)
  
  config PCI_OLPC
        def_bool y
@@@ -2657,9 -2646,9 +2646,9 @@@ config PCI_DOMAIN
        def_bool y
        depends on PCI
  
- config PCI_MMCONFIG
-       bool "Support mmconfig PCI config space access"
-       depends on X86_64 && PCI && ACPI
+ config MMCONF_FAM10H
+       def_bool y
+       depends on X86_64 && PCI_MMCONFIG && ACPI
  
  config PCI_CNB20LE_QUIRK
        bool "Read CNB20LE Host Bridge Windows" if EXPERT
@@@ -2770,9 -2759,11 +2759,9 @@@ config OLPC_XO1_RT
  
  config OLPC_XO1_SCI
        bool "OLPC XO-1 SCI extras"
 -      depends on OLPC && OLPC_XO1_PM
 +      depends on OLPC && OLPC_XO1_PM && GPIO_CS5535=y
        depends on INPUT=y
        select POWER_SUPPLY
 -      select GPIO_CS5535
 -      select MFD_CORE
        ---help---
          Add support for SCI-based features of the OLPC XO-1 laptop:
           - EC-driven system wakeups
@@@ -138,7 -138,6 +138,6 @@@ extern void lapic_shutdown(void)
  extern void sync_Arb_IDs(void);
  extern void init_bsp_APIC(void);
  extern void apic_intr_mode_init(void);
- extern void setup_local_APIC(void);
  extern void init_apic_mappings(void);
  void register_lapic_address(unsigned long address);
  extern void setup_boot_APIC_clock(void);
@@@ -183,6 -182,7 +182,7 @@@ static inline void disable_local_APIC(v
  # define setup_boot_APIC_clock x86_init_noop
  # define setup_secondary_APIC_clock x86_init_noop
  static inline void lapic_update_tsc_freq(void) { }
+ static inline void init_bsp_APIC(void) { }
  static inline void apic_intr_mode_init(void) { }
  static inline void lapic_assign_system_vectors(void) { }
  static inline void lapic_assign_legacy_vector(unsigned int i, bool r) { }
@@@ -304,12 -304,6 +304,6 @@@ struct apic 
        u32     irq_delivery_mode;
        u32     irq_dest_mode;
  
-       /* Functions and data related to vector allocation */
-       void    (*vector_allocation_domain)(int cpu, struct cpumask *retmask,
-                                           const struct cpumask *mask);
-       int     (*cpu_mask_to_apicid)(const struct cpumask *cpumask,
-                                     struct irq_data *irqdata,
-                                     unsigned int *apicid);
        u32     (*calc_dest_apicid)(unsigned int cpu);
  
        /* ICR related functions */
        /* Probe, setup and smpboot functions */
        int     (*probe)(void);
        int     (*acpi_madt_oem_check)(char *oem_id, char *oem_table_id);
 -      int     (*apic_id_valid)(int apicid);
 +      int     (*apic_id_valid)(u32 apicid);
        int     (*apic_id_registered)(void);
  
        bool    (*check_apicid_used)(physid_mask_t *map, int apicid);
@@@ -492,24 -486,14 +486,14 @@@ static inline unsigned int read_apic_id
        return apic->get_apic_id(reg);
  }
  
 -extern int default_apic_id_valid(int apicid);
 +extern int default_apic_id_valid(u32 apicid);
  extern int default_acpi_madt_oem_check(char *, char *);
  extern void default_setup_apic_routing(void);
  
  extern u32 apic_default_calc_apicid(unsigned int cpu);
  extern u32 apic_flat_calc_apicid(unsigned int cpu);
  
- extern int flat_cpu_mask_to_apicid(const struct cpumask *cpumask,
-                                  struct irq_data *irqdata,
-                                  unsigned int *apicid);
- extern int default_cpu_mask_to_apicid(const struct cpumask *cpumask,
-                                     struct irq_data *irqdata,
-                                     unsigned int *apicid);
  extern bool default_check_apicid_used(physid_mask_t *map, int apicid);
- extern void flat_vector_allocation_domain(int cpu, struct cpumask *retmask,
-                                  const struct cpumask *mask);
- extern void default_vector_allocation_domain(int cpu, struct cpumask *retmask,
-                                     const struct cpumask *mask);
  extern void default_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap);
  extern int default_cpu_present_to_apicid(int mps_cpu);
  extern int default_check_phys_apicid_present(int phys_apicid);
@@@ -200,7 -200,7 +200,7 @@@ acpi_parse_x2apic(struct acpi_subtable_
  {
        struct acpi_madt_local_x2apic *processor = NULL;
  #ifdef CONFIG_X86_X2APIC
 -      int apic_id;
 +      u32 apic_id;
        u8 enabled;
  #endif
  
         * to not preallocating memory for all NR_CPUS
         * when we use CPU hotplug.
         */
 -      if (!apic->apic_id_valid(apic_id) && enabled)
 -              printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
 -      else
 -              acpi_register_lapic(apic_id, processor->uid, enabled);
 +      if (!apic->apic_id_valid(apic_id)) {
 +              if (enabled)
 +                      pr_warn(PREFIX "x2apic entry ignored\n");
 +              return 0;
 +      }
 +
 +      acpi_register_lapic(apic_id, processor->uid, enabled);
  #else
        printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
  #endif
@@@ -1379,17 -1376,21 +1379,21 @@@ static int __init dmi_ignore_irq0_timer
   *
   * We initialize the Hardware-reduced ACPI model here:
   */
+ void __init acpi_generic_reduced_hw_init(void)
+ {
+       /*
+        * Override x86_init functions and bypass legacy PIC in
+        * hardware reduced ACPI mode.
+        */
+       x86_init.timers.timer_init      = x86_init_noop;
+       x86_init.irqs.pre_vector_init   = x86_init_noop;
+       legacy_pic                      = &null_legacy_pic;
+ }
  static void __init acpi_reduced_hw_init(void)
  {
-       if (acpi_gbl_reduced_hardware) {
-               /*
-                * Override x86_init functions and bypass legacy pic
-                * in Hardware-reduced ACPI mode
-                */
-               x86_init.timers.timer_init      = x86_init_noop;
-               x86_init.irqs.pre_vector_init   = x86_init_noop;
-               legacy_pic                      = &null_legacy_pic;
-       }
+       if (acpi_gbl_reduced_hardware)
+               x86_init.acpi.reduced_hw_early_init();
  }
  
  /*
@@@ -14,7 -14,7 +14,7 @@@ int x2apic_phys
  
  static struct apic apic_x2apic_phys;
  
- static int set_x2apic_phys_mode(char *arg)
+ static int __init set_x2apic_phys_mode(char *arg)
  {
        x2apic_phys = 1;
        return 0;
@@@ -101,7 -101,7 +101,7 @@@ static int x2apic_phys_probe(void
  }
  
  /* Common x2apic functions, also used by x2apic_cluster */
 -int x2apic_apic_id_valid(int apicid)
 +int x2apic_apic_id_valid(u32 apicid)
  {
        return 1;
  }
diff --combined arch/x86/xen/apic.c
@@@ -112,7 -112,7 +112,7 @@@ static int xen_madt_oem_check(char *oem
        return xen_pv_domain();
  }
  
 -static int xen_id_always_valid(int apicid)
 +static int xen_id_always_valid(u32 apicid)
  {
        return 1;
  }
@@@ -215,7 -215,7 +215,7 @@@ static void __init xen_apic_check(void
  }
  void __init xen_init_apic(void)
  {
-       x86_io_apic_ops.read = xen_io_apic_read;
+       x86_apic_ops.io_apic_read = xen_io_apic_read;
        /* On PV guests the APIC CPUID bit is disabled so none of the
         * routines end up executing. */
        if (!xen_initial_domain())
diff --combined lib/swiotlb.c
@@@ -31,6 -31,7 +31,7 @@@
  #include <linux/gfp.h>
  #include <linux/scatterlist.h>
  #include <linux/mem_encrypt.h>
+ #include <linux/set_memory.h>
  
  #include <asm/io.h>
  #include <asm/dma.h>
@@@ -156,22 -157,6 +157,6 @@@ unsigned long swiotlb_size_or_default(v
        return size ? size : (IO_TLB_DEFAULT_SIZE);
  }
  
- void __weak swiotlb_set_mem_attributes(void *vaddr, unsigned long size) { }
- /* For swiotlb, clear memory encryption mask from dma addresses */
- static dma_addr_t swiotlb_phys_to_dma(struct device *hwdev,
-                                     phys_addr_t address)
- {
-       return __sme_clr(phys_to_dma(hwdev, address));
- }
- /* Note that this doesn't work with highmem page */
- static dma_addr_t swiotlb_virt_to_bus(struct device *hwdev,
-                                     volatile void *address)
- {
-       return phys_to_dma(hwdev, virt_to_phys(address));
- }
  static bool no_iotlb_memory;
  
  void swiotlb_print_info(void)
@@@ -209,12 -194,12 +194,12 @@@ void __init swiotlb_update_mem_attribut
  
        vaddr = phys_to_virt(io_tlb_start);
        bytes = PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT);
-       swiotlb_set_mem_attributes(vaddr, bytes);
+       set_memory_decrypted((unsigned long)vaddr, bytes >> PAGE_SHIFT);
        memset(vaddr, 0, bytes);
  
        vaddr = phys_to_virt(io_tlb_overflow_buffer);
        bytes = PAGE_ALIGN(io_tlb_overflow);
-       swiotlb_set_mem_attributes(vaddr, bytes);
+       set_memory_decrypted((unsigned long)vaddr, bytes >> PAGE_SHIFT);
        memset(vaddr, 0, bytes);
  }
  
@@@ -355,7 -340,7 +340,7 @@@ swiotlb_late_init_with_tbl(char *tlb, u
        io_tlb_start = virt_to_phys(tlb);
        io_tlb_end = io_tlb_start + bytes;
  
-       swiotlb_set_mem_attributes(tlb, bytes);
+       set_memory_decrypted((unsigned long)tlb, bytes >> PAGE_SHIFT);
        memset(tlb, 0, bytes);
  
        /*
        if (!v_overflow_buffer)
                goto cleanup2;
  
-       swiotlb_set_mem_attributes(v_overflow_buffer, io_tlb_overflow);
+       set_memory_decrypted((unsigned long)v_overflow_buffer,
+                       io_tlb_overflow >> PAGE_SHIFT);
        memset(v_overflow_buffer, 0, io_tlb_overflow);
        io_tlb_overflow_buffer = virt_to_phys(v_overflow_buffer);
  
@@@ -622,7 -608,7 +608,7 @@@ map_single(struct device *hwdev, phys_a
                return SWIOTLB_MAP_ERROR;
        }
  
-       start_dma_addr = swiotlb_phys_to_dma(hwdev, io_tlb_start);
+       start_dma_addr = __phys_to_dma(hwdev, io_tlb_start);
        return swiotlb_tbl_map_single(hwdev, start_dma_addr, phys, size,
                                      dir, attrs);
  }
@@@ -706,6 -692,7 +692,7 @@@ void swiotlb_tbl_sync_single(struct dev
        }
  }
  
+ #ifdef CONFIG_DMA_DIRECT_OPS
  static inline bool dma_coherent_ok(struct device *dev, dma_addr_t addr,
                size_t size)
  {
@@@ -726,12 -713,12 +713,12 @@@ swiotlb_alloc_buffer(struct device *dev
                goto out_warn;
  
        phys_addr = swiotlb_tbl_map_single(dev,
-                       swiotlb_phys_to_dma(dev, io_tlb_start),
+                       __phys_to_dma(dev, io_tlb_start),
                        0, size, DMA_FROM_DEVICE, 0);
        if (phys_addr == SWIOTLB_MAP_ERROR)
                goto out_warn;
  
-       *dma_handle = swiotlb_phys_to_dma(dev, phys_addr);
+       *dma_handle = __phys_to_dma(dev, phys_addr);
        if (dma_coherent_ok(dev, *dma_handle, size))
                goto out_unmap;
  
@@@ -759,28 -746,6 +746,6 @@@ out_warn
        return NULL;
  }
  
- void *
- swiotlb_alloc_coherent(struct device *hwdev, size_t size,
-                      dma_addr_t *dma_handle, gfp_t flags)
- {
-       int order = get_order(size);
-       unsigned long attrs = (flags & __GFP_NOWARN) ? DMA_ATTR_NO_WARN : 0;
-       void *ret;
-       ret = (void *)__get_free_pages(flags, order);
-       if (ret) {
-               *dma_handle = swiotlb_virt_to_bus(hwdev, ret);
-               if (dma_coherent_ok(hwdev, *dma_handle, size)) {
-                       memset(ret, 0, size);
-                       return ret;
-               }
-               free_pages((unsigned long)ret, order);
-       }
-       return swiotlb_alloc_buffer(hwdev, size, dma_handle, attrs);
- }
- EXPORT_SYMBOL(swiotlb_alloc_coherent);
  static bool swiotlb_free_buffer(struct device *dev, size_t size,
                dma_addr_t dma_addr)
  {
                                 DMA_ATTR_SKIP_CPU_SYNC);
        return true;
  }
- void
- swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
-                     dma_addr_t dev_addr)
- {
-       if (!swiotlb_free_buffer(hwdev, size, dev_addr))
-               free_pages((unsigned long)vaddr, get_order(size));
- }
- EXPORT_SYMBOL(swiotlb_free_coherent);
+ #endif
  
  static void
  swiotlb_full(struct device *dev, size_t size, enum dma_data_direction dir,
@@@ -867,10 -824,10 +824,10 @@@ dma_addr_t swiotlb_map_page(struct devi
        map = map_single(dev, phys, size, dir, attrs);
        if (map == SWIOTLB_MAP_ERROR) {
                swiotlb_full(dev, size, dir, 1);
-               return swiotlb_phys_to_dma(dev, io_tlb_overflow_buffer);
+               return __phys_to_dma(dev, io_tlb_overflow_buffer);
        }
  
-       dev_addr = swiotlb_phys_to_dma(dev, map);
+       dev_addr = __phys_to_dma(dev, map);
  
        /* Ensure that the address returned is DMA'ble */
        if (dma_capable(dev, dev_addr, size))
        attrs |= DMA_ATTR_SKIP_CPU_SYNC;
        swiotlb_tbl_unmap_single(dev, map, size, dir, attrs);
  
-       return swiotlb_phys_to_dma(dev, io_tlb_overflow_buffer);
+       return __phys_to_dma(dev, io_tlb_overflow_buffer);
  }
  
  /*
@@@ -1009,7 -966,7 +966,7 @@@ swiotlb_map_sg_attrs(struct device *hwd
                                sg_dma_len(sgl) = 0;
                                return 0;
                        }
-                       sg->dma_address = swiotlb_phys_to_dma(hwdev, map);
+                       sg->dma_address = __phys_to_dma(hwdev, map);
                } else
                        sg->dma_address = dev_addr;
                sg_dma_len(sg) = sg->length;
@@@ -1073,7 -1030,7 +1030,7 @@@ swiotlb_sync_sg_for_device(struct devic
  int
  swiotlb_dma_mapping_error(struct device *hwdev, dma_addr_t dma_addr)
  {
-       return (dma_addr == swiotlb_phys_to_dma(hwdev, io_tlb_overflow_buffer));
+       return (dma_addr == __phys_to_dma(hwdev, io_tlb_overflow_buffer));
  }
  
  /*
  int
  swiotlb_dma_supported(struct device *hwdev, u64 mask)
  {
-       return swiotlb_phys_to_dma(hwdev, io_tlb_end - 1) <= mask;
+       return __phys_to_dma(hwdev, io_tlb_end - 1) <= mask;
  }
  
  #ifdef CONFIG_DMA_DIRECT_OPS
@@@ -1130,6 -1087,6 +1087,6 @@@ const struct dma_map_ops swiotlb_dma_op
        .unmap_sg               = swiotlb_unmap_sg_attrs,
        .map_page               = swiotlb_map_page,
        .unmap_page             = swiotlb_unmap_page,
 -      .dma_supported          = swiotlb_dma_supported,
 +      .dma_supported          = dma_direct_supported,
  };
  #endif /* CONFIG_DMA_DIRECT_OPS */