Merge tag 'for-linus-4.19-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 14 Aug 2018 23:54:22 +0000 (16:54 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 14 Aug 2018 23:54:22 +0000 (16:54 -0700)
Pull xen updates from Juergen Gross:

 - add dma-buf functionality to Xen grant table handling

 - fix for booting the kernel as Xen PVH dom0

 - fix for booting the kernel as a Xen PV guest with
   CONFIG_DEBUG_VIRTUAL enabled

 - other minor performance and style fixes

* tag 'for-linus-4.19-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip:
  xen/balloon: fix balloon initialization for PVH Dom0
  xen: don't use privcmd_call() from xen_mc_flush()
  xen/pv: Call get_cpu_address_sizes to set x86_virt/phys_bits
  xen/biomerge: Use true and false for boolean values
  xen/gntdev: don't dereference a null gntdev_dmabuf on allocation failure
  xen/spinlock: Don't use pvqspinlock if only 1 vCPU
  xen/gntdev: Implement dma-buf import functionality
  xen/gntdev: Implement dma-buf export functionality
  xen/gntdev: Add initial support for dma-buf UAPI
  xen/gntdev: Make private routines/structures accessible
  xen/gntdev: Allow mappings for DMA buffers
  xen/grant-table: Allow allocating buffers suitable for DMA
  xen/balloon: Share common memory reservation routines
  xen/grant-table: Make set/clear page private code shared

1  2 
arch/x86/kernel/cpu/common.c
arch/x86/kernel/cpu/cpu.h
arch/x86/xen/enlighten_pv.c

@@@ -661,36 -661,33 +661,36 @@@ static void cpu_detect_tlb(struct cpuin
                tlb_lld_4m[ENTRIES], tlb_lld_1g[ENTRIES]);
  }
  
 -void detect_ht(struct cpuinfo_x86 *c)
 +int detect_ht_early(struct cpuinfo_x86 *c)
  {
  #ifdef CONFIG_SMP
        u32 eax, ebx, ecx, edx;
 -      int index_msb, core_bits;
 -      static bool printed;
  
        if (!cpu_has(c, X86_FEATURE_HT))
 -              return;
 +              return -1;
  
        if (cpu_has(c, X86_FEATURE_CMP_LEGACY))
 -              goto out;
 +              return -1;
  
        if (cpu_has(c, X86_FEATURE_XTOPOLOGY))
 -              return;
 +              return -1;
  
        cpuid(1, &eax, &ebx, &ecx, &edx);
  
        smp_num_siblings = (ebx & 0xff0000) >> 16;
 -
 -      if (smp_num_siblings == 1) {
 +      if (smp_num_siblings == 1)
                pr_info_once("CPU0: Hyper-Threading is disabled\n");
 -              goto out;
 -      }
 +#endif
 +      return 0;
 +}
  
 -      if (smp_num_siblings <= 1)
 -              goto out;
 +void detect_ht(struct cpuinfo_x86 *c)
 +{
 +#ifdef CONFIG_SMP
 +      int index_msb, core_bits;
 +
 +      if (detect_ht_early(c) < 0)
 +              return;
  
        index_msb = get_count_order(smp_num_siblings);
        c->phys_proc_id = apic->phys_pkg_id(c->initial_apicid, index_msb);
  
        c->cpu_core_id = apic->phys_pkg_id(c->initial_apicid, index_msb) &
                                       ((1 << core_bits) - 1);
 -
 -out:
 -      if (!printed && (c->x86_max_cores * smp_num_siblings) > 1) {
 -              pr_info("CPU: Physical Processor ID: %d\n",
 -                      c->phys_proc_id);
 -              pr_info("CPU: Processor Core ID: %d\n",
 -                      c->cpu_core_id);
 -              printed = 1;
 -      }
  #endif
  }
  
@@@ -905,7 -911,7 +905,7 @@@ void get_cpu_cap(struct cpuinfo_x86 *c
        apply_forced_caps(c);
  }
  
static void get_cpu_address_sizes(struct cpuinfo_x86 *c)
+ void get_cpu_address_sizes(struct cpuinfo_x86 *c)
  {
        u32 eax, ebx, ecx, edx;
  
@@@ -981,21 -987,6 +981,21 @@@ static const __initconst struct x86_cpu
        {}
  };
  
 +static const __initconst struct x86_cpu_id cpu_no_l1tf[] = {
 +      /* in addition to cpu_no_speculation */
 +      { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_SILVERMONT1     },
 +      { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_SILVERMONT2     },
 +      { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_AIRMONT         },
 +      { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_MERRIFIELD      },
 +      { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_MOOREFIELD      },
 +      { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_GOLDMONT        },
 +      { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_DENVERTON       },
 +      { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_GEMINI_LAKE     },
 +      { X86_VENDOR_INTEL,     6,      INTEL_FAM6_XEON_PHI_KNL         },
 +      { X86_VENDOR_INTEL,     6,      INTEL_FAM6_XEON_PHI_KNM         },
 +      {}
 +};
 +
  static void __init cpu_set_bug_bits(struct cpuinfo_x86 *c)
  {
        u64 ia32_cap = 0;
           !cpu_has(c, X86_FEATURE_AMD_SSB_NO))
                setup_force_cpu_bug(X86_BUG_SPEC_STORE_BYPASS);
  
 +      if (ia32_cap & ARCH_CAP_IBRS_ALL)
 +              setup_force_cpu_cap(X86_FEATURE_IBRS_ENHANCED);
 +
        if (x86_match_cpu(cpu_no_meltdown))
                return;
  
                return;
  
        setup_force_cpu_bug(X86_BUG_CPU_MELTDOWN);
 +
 +      if (x86_match_cpu(cpu_no_l1tf))
 +              return;
 +
 +      setup_force_cpu_bug(X86_BUG_L1TF);
 +}
 +
 +/*
 + * The NOPL instruction is supposed to exist on all CPUs of family >= 6;
 + * unfortunately, that's not true in practice because of early VIA
 + * chips and (more importantly) broken virtualizers that are not easy
 + * to detect. In the latter case it doesn't even *fail* reliably, so
 + * probing for it doesn't even work. Disable it completely on 32-bit
 + * unless we can find a reliable way to detect all the broken cases.
 + * Enable it explicitly on 64-bit for non-constant inputs of cpu_has().
 + */
 +static void detect_nopl(void)
 +{
 +#ifdef CONFIG_X86_32
 +      setup_clear_cpu_cap(X86_FEATURE_NOPL);
 +#else
 +      setup_force_cpu_cap(X86_FEATURE_NOPL);
 +#endif
  }
  
  /*
@@@ -1124,8 -1089,6 +1124,8 @@@ static void __init early_identify_cpu(s
         */
        if (!pgtable_l5_enabled())
                setup_clear_cpu_cap(X86_FEATURE_LA57);
 +
 +      detect_nopl();
  }
  
  void __init early_cpu_init(void)
        early_identify_cpu(&boot_cpu_data);
  }
  
 -/*
 - * The NOPL instruction is supposed to exist on all CPUs of family >= 6;
 - * unfortunately, that's not true in practice because of early VIA
 - * chips and (more importantly) broken virtualizers that are not easy
 - * to detect. In the latter case it doesn't even *fail* reliably, so
 - * probing for it doesn't even work. Disable it completely on 32-bit
 - * unless we can find a reliable way to detect all the broken cases.
 - * Enable it explicitly on 64-bit for non-constant inputs of cpu_has().
 - */
 -static void detect_nopl(struct cpuinfo_x86 *c)
 -{
 -#ifdef CONFIG_X86_32
 -      clear_cpu_cap(c, X86_FEATURE_NOPL);
 -#else
 -      set_cpu_cap(c, X86_FEATURE_NOPL);
 -#endif
 -}
 -
  static void detect_null_seg_behavior(struct cpuinfo_x86 *c)
  {
  #ifdef CONFIG_X86_64
@@@ -1223,6 -1204,8 +1223,6 @@@ static void generic_identify(struct cpu
  
        get_model_name(c); /* Default name */
  
 -      detect_nopl(c);
 -
        detect_null_seg_behavior(c);
  
        /*
@@@ -1821,12 -1804,11 +1821,12 @@@ void cpu_init(void
        enter_lazy_tlb(&init_mm, curr);
  
        /*
 -       * Initialize the TSS.  Don't bother initializing sp0, as the initial
 -       * task never enters user mode.
 +       * Initialize the TSS.  sp0 points to the entry trampoline stack
 +       * regardless of what task is running.
         */
        set_tss_desc(cpu, &get_cpu_entry_area(cpu)->tss.x86_tss);
        load_TR_desc();
 +      load_sp0((unsigned long)(cpu_entry_stack(cpu) + 1));
  
        load_mm_ldt(&init_mm);
  
@@@ -46,6 -46,7 +46,7 @@@ extern const struct cpu_dev *const __x8
                            *const __x86_cpu_dev_end[];
  
  extern void get_cpu_cap(struct cpuinfo_x86 *c);
+ extern void get_cpu_address_sizes(struct cpuinfo_x86 *c);
  extern void cpu_detect_cache_sizes(struct cpuinfo_x86 *c);
  extern void init_scattered_cpuid_features(struct cpuinfo_x86 *c);
  extern u32 get_scattered_cpuid_leaf(unsigned int level,
@@@ -55,9 -56,7 +56,9 @@@ extern void init_intel_cacheinfo(struc
  extern void init_amd_cacheinfo(struct cpuinfo_x86 *c);
  
  extern void detect_num_cpu_cores(struct cpuinfo_x86 *c);
 +extern int detect_extended_topology_early(struct cpuinfo_x86 *c);
  extern int detect_extended_topology(struct cpuinfo_x86 *c);
 +extern int detect_ht_early(struct cpuinfo_x86 *c);
  extern void detect_ht(struct cpuinfo_x86 *c);
  
  unsigned int aperfmperf_get_khz(int cpu);
@@@ -119,27 -119,6 +119,27 @@@ static void __init xen_banner(void
               version >> 16, version & 0xffff, extra.extraversion,
               xen_feature(XENFEAT_mmu_pt_update_preserve_ad) ? " (preserve-AD)" : "");
  }
 +
 +static void __init xen_pv_init_platform(void)
 +{
 +      set_fixmap(FIX_PARAVIRT_BOOTMAP, xen_start_info->shared_info);
 +      HYPERVISOR_shared_info = (void *)fix_to_virt(FIX_PARAVIRT_BOOTMAP);
 +
 +      /* xen clock uses per-cpu vcpu_info, need to init it for boot cpu */
 +      xen_vcpu_info_reset(0);
 +
 +      /* pvclock is in shared info area */
 +      xen_init_time_ops();
 +}
 +
 +static void __init xen_pv_guest_late_init(void)
 +{
 +#ifndef CONFIG_SMP
 +      /* Setup shared vcpu info for non-smp configurations */
 +      xen_setup_vcpu_info_placement();
 +#endif
 +}
 +
  /* Check if running on Xen version (major, minor) or later */
  bool
  xen_running_on_version_or_later(unsigned int major, unsigned int minor)
@@@ -968,8 -947,34 +968,8 @@@ static void xen_write_msr(unsigned int 
        xen_write_msr_safe(msr, low, high);
  }
  
 -void xen_setup_shared_info(void)
 -{
 -      set_fixmap(FIX_PARAVIRT_BOOTMAP, xen_start_info->shared_info);
 -
 -      HYPERVISOR_shared_info =
 -              (struct shared_info *)fix_to_virt(FIX_PARAVIRT_BOOTMAP);
 -
 -      xen_setup_mfn_list_list();
 -
 -      if (system_state == SYSTEM_BOOTING) {
 -#ifndef CONFIG_SMP
 -              /*
 -               * In UP this is as good a place as any to set up shared info.
 -               * Limit this to boot only, at restore vcpu setup is done via
 -               * xen_vcpu_restore().
 -               */
 -              xen_setup_vcpu_info_placement();
 -#endif
 -              /*
 -               * Now that shared info is set up we can start using routines
 -               * that point to pvclock area.
 -               */
 -              xen_init_time_ops();
 -      }
 -}
 -
  /* This is called once we have the cpu_possible_mask */
 -void __ref xen_setup_vcpu_info_placement(void)
 +void __init xen_setup_vcpu_info_placement(void)
  {
        int cpu;
  
@@@ -1223,8 -1228,6 +1223,8 @@@ asmlinkage __visible void __init xen_st
        x86_init.irqs.intr_mode_init    = x86_init_noop;
        x86_init.oem.arch_setup = xen_arch_setup;
        x86_init.oem.banner = xen_banner;
 +      x86_init.hyper.init_platform = xen_pv_init_platform;
 +      x86_init.hyper.guest_late_init = xen_pv_guest_late_init;
  
        /*
         * Set up some pagetable state before starting to set any ptes.
        get_cpu_cap(&boot_cpu_data);
        x86_configure_nx();
  
+       /* Determine virtual and physical address sizes */
+       get_cpu_address_sizes(&boot_cpu_data);
        /* Let's presume PV guests always boot on vCPU with id 0. */
        per_cpu(xen_vcpu_id, 0) = 0;