Merge commit 'v2.6.31-rc7' into x86/cleanups
authorIngo Molnar <mingo@elte.hu>
Mon, 24 Aug 2009 10:25:44 +0000 (12:25 +0200)
committerIngo Molnar <mingo@elte.hu>
Mon, 24 Aug 2009 10:25:54 +0000 (12:25 +0200)
Merge reason: we were on -rc1 before - go up to -rc7

Signed-off-by: Ingo Molnar <mingo@elte.hu>
1  2 
arch/x86/kernel/apic/ipi.c
arch/x86/kernel/cpu/amd.c
arch/x86/kernel/cpu/common.c
arch/x86/kernel/cpu/perfctr-watchdog.c
arch/x86/kvm/x86.c

index e6b4f517fcfec971df1a1bf47434da9f91c983d6,6ef00ba4c8864c2c0c9b7c6ece3266a15d224404..08385e090a6f2fa830d796a67709ede023b1f6c5
@@@ -106,6 -106,9 +106,9 @@@ void default_send_IPI_mask_logical(cons
        unsigned long mask = cpumask_bits(cpumask)[0];
        unsigned long flags;
  
+       if (WARN_ONCE(!mask, "empty IPI mask"))
+               return;
        local_irq_save(flags);
        WARN_ON(mask & ~cpumask_bits(cpu_online_mask)[0]);
        __default_send_IPI_dest_field(mask, vector, apic->dest_logical);
@@@ -150,7 -153,7 +153,7 @@@ int safe_smp_processor_id(void
  {
        int apicid, cpuid;
  
 -      if (!boot_cpu_has(X86_FEATURE_APIC))
 +      if (!cpu_has_apic)
                return 0;
  
        apicid = hard_smp_processor_id();
index c6eb02e698753cee4ea834fcc30ccac641bfd27b,63fddcd082cdf2a3b4cc261d54608ec2dac07b64..83b217c7225fb2d02d83941a514884539daae0e5
@@@ -2,7 -2,7 +2,7 @@@
  #include <linux/bitops.h>
  #include <linux/mm.h>
  
 -#include <asm/io.h>
 +#include <linux/io.h>
  #include <asm/processor.h>
  #include <asm/apic.h>
  #include <asm/cpu.h>
@@@ -45,8 -45,8 +45,8 @@@ static void __cpuinit init_amd_k5(struc
  #define CBAR_ENB      (0x80000000)
  #define CBAR_KEY      (0X000000CB)
        if (c->x86_model == 9 || c->x86_model == 10) {
 -              if (inl (CBAR) & CBAR_ENB)
 -                      outl (0 | CBAR_KEY, CBAR);
 +              if (inl(CBAR) & CBAR_ENB)
 +                      outl(0 | CBAR_KEY, CBAR);
        }
  }
  
@@@ -87,10 -87,9 +87,10 @@@ static void __cpuinit init_amd_k6(struc
                d = d2-d;
  
                if (d > 20*K6_BUG_LOOP)
 -                      printk("system stability may be impaired when more than 32 MB are used.\n");
 +                      printk(KERN_CONT
 +                              "system stability may be impaired when more than 32 MB are used.\n");
                else
 -                      printk("probably OK (after B9730xxxx).\n");
 +                      printk(KERN_CONT "probably OK (after B9730xxxx).\n");
                printk(KERN_INFO "Please see http://membres.lycos.fr/poulot/k6bug.html\n");
        }
  
@@@ -220,9 -219,8 +220,9 @@@ static void __cpuinit init_amd_k7(struc
        if ((c->x86_model == 8 && c->x86_mask >= 1) || (c->x86_model > 8)) {
                rdmsr(MSR_K7_CLK_CTL, l, h);
                if ((l & 0xfff00000) != 0x20000000) {
 -                      printk ("CPU: CLK_CTL MSR was %x. Reprogramming to %x\n", l,
 -                              ((l & 0x000fffff)|0x20000000));
 +                      printk(KERN_INFO
 +                          "CPU: CLK_CTL MSR was %x. Reprogramming to %x\n",
 +                                      l, ((l & 0x000fffff)|0x20000000));
                        wrmsr(MSR_K7_CLK_CTL, (l & 0x000fffff)|0x20000000, h);
                }
        }
@@@ -358,7 -356,7 +358,7 @@@ static void __cpuinit early_init_amd(st
  #endif
  #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_PCI)
        /* check CPU config space for extended APIC ID */
-       if (c->x86 >= 0xf) {
+       if (cpu_has_apic && c->x86 >= 0xf) {
                unsigned int val;
                val = read_pci_config(0, 24, 0, 0x68);
                if ((val & ((1 << 17) | (1 << 18))) == ((1 << 17) | (1 << 18)))
@@@ -400,8 -398,15 +400,15 @@@ static void __cpuinit init_amd(struct c
                u32 level;
  
                level = cpuid_eax(1);
 -              if((level >= 0x0f48 && level < 0x0f50) || level >= 0x0f58)
 +              if ((level >= 0x0f48 && level < 0x0f50) || level >= 0x0f58)
                        set_cpu_cap(c, X86_FEATURE_REP_GOOD);
+               /*
+                * Some BIOSes incorrectly force this feature, but only K8
+                * revision D (model = 0x14) and later actually support it.
+                */
+               if (c->x86_model < 0x14)
+                       clear_cpu_cap(c, X86_FEATURE_LAHF_LM);
        }
        if (c->x86 == 0x10 || c->x86 == 0x11)
                set_cpu_cap(c, X86_FEATURE_REP_GOOD);
                 * benefit in doing so.
                 */
                if (!rdmsrl_safe(MSR_K8_TSEG_ADDR, &tseg)) {
 -                  printk(KERN_DEBUG "tseg: %010llx\n", tseg);
 -                  if ((tseg>>PMD_SHIFT) <
 +                      printk(KERN_DEBUG "tseg: %010llx\n", tseg);
 +                      if ((tseg>>PMD_SHIFT) <
                                (max_low_pfn_mapped>>(PMD_SHIFT-PAGE_SHIFT)) ||
 -                      ((tseg>>PMD_SHIFT) <
 +                              ((tseg>>PMD_SHIFT) <
                                (max_pfn_mapped>>(PMD_SHIFT-PAGE_SHIFT)) &&
 -                       (tseg>>PMD_SHIFT) >= (1ULL<<(32 - PMD_SHIFT))))
 -                      set_memory_4k((unsigned long)__va(tseg), 1);
 +                              (tseg>>PMD_SHIFT) >= (1ULL<<(32 - PMD_SHIFT))))
 +                              set_memory_4k((unsigned long)__va(tseg), 1);
                }
        }
  #endif
  }
  
  #ifdef CONFIG_X86_32
 -static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
 +static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
 +                                                      unsigned int size)
  {
        /* AMD errata T13 (order #21922) */
        if ((c->x86 == 6)) {
 -              if (c->x86_model == 3 && c->x86_mask == 0)      /* Duron Rev A0 */
 +              /* Duron Rev A0 */
 +              if (c->x86_model == 3 && c->x86_mask == 0)
                        size = 64;
 +              /* Tbird rev A1/A2 */
                if (c->x86_model == 4 &&
 -                  (c->x86_mask == 0 || c->x86_mask == 1))     /* Tbird rev A1/A2 */
 +                      (c->x86_mask == 0 || c->x86_mask == 1))
                        size = 256;
        }
        return size;
index c96ea44928bfdbc70d1d57085291fb68c636a5c3,5ce60a88027b16a46edf3b1afb3430d550cd5012..734eaad936567d4d72865c2c2d446d1ea75b3eda
@@@ -18,8 -18,8 +18,8 @@@
  #include <asm/hypervisor.h>
  #include <asm/processor.h>
  #include <asm/sections.h>
 -#include <asm/topology.h>
 -#include <asm/cpumask.h>
 +#include <linux/topology.h>
 +#include <linux/cpumask.h>
  #include <asm/pgtable.h>
  #include <asm/atomic.h>
  #include <asm/proto.h>
  #include <asm/desc.h>
  #include <asm/i387.h>
  #include <asm/mtrr.h>
 -#include <asm/numa.h>
 +#include <linux/numa.h>
  #include <asm/asm.h>
  #include <asm/cpu.h>
  #include <asm/mce.h>
  #include <asm/msr.h>
  #include <asm/pat.h>
 -#include <asm/smp.h>
 +#include <linux/smp.h>
  
  #ifdef CONFIG_X86_LOCAL_APIC
  #include <asm/uv/uv.h>
@@@ -59,7 -59,30 +59,30 @@@ void __init setup_cpu_local_masks(void
        alloc_bootmem_cpumask_var(&cpu_sibling_setup_mask);
  }
  
- static const struct cpu_dev *this_cpu __cpuinitdata;
+ static void __cpuinit default_init(struct cpuinfo_x86 *c)
+ {
+ #ifdef CONFIG_X86_64
+       display_cacheinfo(c);
+ #else
+       /* Not much we can do here... */
+       /* Check if at least it has cpuid */
+       if (c->cpuid_level == -1) {
+               /* No cpuid. It must be an ancient CPU */
+               if (c->x86 == 4)
+                       strcpy(c->x86_model_id, "486");
+               else if (c->x86 == 3)
+                       strcpy(c->x86_model_id, "386");
+       }
+ #endif
+ }
+ static const struct cpu_dev __cpuinitconst default_cpu = {
+       .c_init         = default_init,
+       .c_vendor       = "Unknown",
+       .c_x86_vendor   = X86_VENDOR_UNKNOWN,
+ };
+ static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
  
  DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
  #ifdef CONFIG_X86_64
@@@ -332,29 -355,6 +355,6 @@@ void switch_to_new_gdt(int cpu
  
  static const struct cpu_dev *__cpuinitdata cpu_devs[X86_VENDOR_NUM] = {};
  
- static void __cpuinit default_init(struct cpuinfo_x86 *c)
- {
- #ifdef CONFIG_X86_64
-       display_cacheinfo(c);
- #else
-       /* Not much we can do here... */
-       /* Check if at least it has cpuid */
-       if (c->cpuid_level == -1) {
-               /* No cpuid. It must be an ancient CPU */
-               if (c->x86 == 4)
-                       strcpy(c->x86_model_id, "486");
-               else if (c->x86 == 3)
-                       strcpy(c->x86_model_id, "386");
-       }
- #endif
- }
- static const struct cpu_dev __cpuinitconst default_cpu = {
-       .c_init = default_init,
-       .c_vendor = "Unknown",
-       .c_x86_vendor = X86_VENDOR_UNKNOWN,
- };
  static void __cpuinit get_model_name(struct cpuinfo_x86 *c)
  {
        unsigned int *v;
@@@ -982,7 -982,7 +982,7 @@@ static __init int setup_disablecpuid(ch
  __setup("clearcpuid=", setup_disablecpuid);
  
  #ifdef CONFIG_X86_64
 -struct desc_ptr idt_descr = { 256 * 16 - 1, (unsigned long) idt_table };
 +struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
  
  DEFINE_PER_CPU_FIRST(union irq_stack_union,
                     irq_stack_union) __aligned(PAGE_SIZE);
index 8100a29c854ff5d65a0ebb0817fbc084422af87b,e60ed740d2b3f4aa49412b47a97656eef07e8952..392bea43b890ba63746640e0bad2a77b2b775427
@@@ -68,16 -68,16 +68,16 @@@ static inline unsigned int nmi_perfctr_
        /* returns the bit offset of the performance counter register */
        switch (boot_cpu_data.x86_vendor) {
        case X86_VENDOR_AMD:
 -              return (msr - MSR_K7_PERFCTR0);
 +              return msr - MSR_K7_PERFCTR0;
        case X86_VENDOR_INTEL:
                if (cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON))
 -                      return (msr - MSR_ARCH_PERFMON_PERFCTR0);
 +                      return msr - MSR_ARCH_PERFMON_PERFCTR0;
  
                switch (boot_cpu_data.x86) {
                case 6:
 -                      return (msr - MSR_P6_PERFCTR0);
 +                      return msr - MSR_P6_PERFCTR0;
                case 15:
 -                      return (msr - MSR_P4_BPU_PERFCTR0);
 +                      return msr - MSR_P4_BPU_PERFCTR0;
                }
        }
        return 0;
@@@ -92,16 -92,16 +92,16 @@@ static inline unsigned int nmi_evntsel_
        /* returns the bit offset of the event selection register */
        switch (boot_cpu_data.x86_vendor) {
        case X86_VENDOR_AMD:
 -              return (msr - MSR_K7_EVNTSEL0);
 +              return msr - MSR_K7_EVNTSEL0;
        case X86_VENDOR_INTEL:
                if (cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON))
 -                      return (msr - MSR_ARCH_PERFMON_EVENTSEL0);
 +                      return msr - MSR_ARCH_PERFMON_EVENTSEL0;
  
                switch (boot_cpu_data.x86) {
                case 6:
 -                      return (msr - MSR_P6_EVNTSEL0);
 +                      return msr - MSR_P6_EVNTSEL0;
                case 15:
 -                      return (msr - MSR_P4_BSU_ESCR0);
 +                      return msr - MSR_P4_BSU_ESCR0;
                }
        }
        return 0;
@@@ -113,7 -113,7 +113,7 @@@ int avail_to_resrv_perfctr_nmi_bit(unsi
  {
        BUG_ON(counter > NMI_MAX_COUNTER_BITS);
  
 -      return (!test_bit(counter, perfctr_nmi_owner));
 +      return !test_bit(counter, perfctr_nmi_owner);
  }
  
  /* checks the an msr for availability */
@@@ -124,7 -124,7 +124,7 @@@ int avail_to_resrv_perfctr_nmi(unsigne
        counter = nmi_perfctr_msr_to_bit(msr);
        BUG_ON(counter > NMI_MAX_COUNTER_BITS);
  
 -      return (!test_bit(counter, perfctr_nmi_owner));
 +      return !test_bit(counter, perfctr_nmi_owner);
  }
  EXPORT_SYMBOL(avail_to_resrv_perfctr_nmi_bit);
  
@@@ -237,7 -237,7 +237,7 @@@ static unsigned int adjust_for_32bit_ct
         */
        counter_val = (u64)cpu_khz * 1000;
        do_div(counter_val, retval);
 -      if (counter_val > 0x7fffffffULL) {
 +      if (counter_val > 0x7fffffffULL) {
                u64 count = (u64)cpu_khz * 1000;
                do_div(count, 0x7fffffffUL);
                retval = count + 1;
@@@ -251,7 -251,7 +251,7 @@@ static void write_watchdog_counter(unsi
        u64 count = (u64)cpu_khz * 1000;
  
        do_div(count, nmi_hz);
 -      if(descr)
 +      if (descr)
                pr_debug("setting %s to -0x%08Lx\n", descr, count);
        wrmsrl(perfctr_msr, 0 - count);
  }
@@@ -262,7 -262,7 +262,7 @@@ static void write_watchdog_counter32(un
        u64 count = (u64)cpu_khz * 1000;
  
        do_div(count, nmi_hz);
 -      if(descr)
 +      if (descr)
                pr_debug("setting %s to -0x%08Lx\n", descr, count);
        wrmsr(perfctr_msr, (u32)(-count), 0);
  }
@@@ -296,7 -296,7 +296,7 @@@ static int setup_k7_watchdog(unsigned n
  
        /* setup the timer */
        wrmsr(evntsel_msr, evntsel, 0);
 -      write_watchdog_counter(perfctr_msr, "K7_PERFCTR0",nmi_hz);
 +      write_watchdog_counter(perfctr_msr, "K7_PERFCTR0", nmi_hz);
  
        /* initialize the wd struct before enabling */
        wd->perfctr_msr = perfctr_msr;
@@@ -387,7 -387,7 +387,7 @@@ static int setup_p6_watchdog(unsigned n
        /* setup the timer */
        wrmsr(evntsel_msr, evntsel, 0);
        nmi_hz = adjust_for_32bit_ctr(nmi_hz);
 -      write_watchdog_counter32(perfctr_msr, "P6_PERFCTR0",nmi_hz);
 +      write_watchdog_counter32(perfctr_msr, "P6_PERFCTR0", nmi_hz);
  
        /* initialize the wd struct before enabling */
        wd->perfctr_msr = perfctr_msr;
@@@ -415,7 -415,7 +415,7 @@@ static void __kprobes p6_rearm(struct n
        apic_write(APIC_LVTPC, APIC_DM_NMI);
  
        /* P6/ARCH_PERFMON has 32 bit counter write */
 -      write_watchdog_counter32(wd->perfctr_msr, NULL,nmi_hz);
 +      write_watchdog_counter32(wd->perfctr_msr, NULL, nmi_hz);
  }
  
  static const struct wd_ops p6_wd_ops = {
@@@ -490,9 -490,9 +490,9 @@@ static int setup_p4_watchdog(unsigned n
        if (smp_num_siblings == 2) {
                unsigned int ebx, apicid;
  
 -              ebx = cpuid_ebx(1);
 -              apicid = (ebx >> 24) & 0xff;
 -              ht_num = apicid & 1;
 +              ebx = cpuid_ebx(1);
 +              apicid = (ebx >> 24) & 0xff;
 +              ht_num = apicid & 1;
        } else
  #endif
                ht_num = 0;
        }
  
        evntsel = P4_ESCR_EVENT_SELECT(0x3F)
 -              | P4_ESCR_OS
 +              | P4_ESCR_OS
                | P4_ESCR_USR;
  
        cccr_val |= P4_CCCR_THRESHOLD(15)
@@@ -612,7 -612,7 +612,7 @@@ static void __kprobes p4_rearm(struct n
  {
        unsigned dummy;
        /*
 -       * P4 quirks:
 +       * P4 quirks:
         * - An overflown perfctr will assert its interrupt
         *   until the OVF flag in its CCCR is cleared.
         * - LVTPC is masked on interrupt and must be
@@@ -662,8 -662,7 +662,8 @@@ static int setup_intel_arch_watchdog(un
         * NOTE: Corresponding bit = 0 in ebx indicates event present.
         */
        cpuid(10, &(eax.full), &ebx, &unused, &unused);
 -      if ((eax.split.mask_length < (ARCH_PERFMON_UNHALTED_CORE_CYCLES_INDEX+1)) ||
 +      if ((eax.split.mask_length <
 +                      (ARCH_PERFMON_UNHALTED_CORE_CYCLES_INDEX+1)) ||
            (ebx & ARCH_PERFMON_UNHALTED_CORE_CYCLES_PRESENT))
                return 0;
  
@@@ -804,8 -803,3 +804,3 @@@ int __kprobes lapic_wd_event(unsigned n
        wd_ops->rearm(wd, nmi_hz);
        return 1;
  }
- int lapic_watchdog_ok(void)
- {
-       return wd_ops != NULL;
- }
diff --combined arch/x86/kvm/x86.c
index 0572c90f0c84b6243925f89fd993a23add970f39,3d45290118284223ffc1c3d2c66fa0ffd08ba1cf..633ccc7400a43ea230e3c02b252d4b80ff838140
@@@ -704,11 -704,48 +704,48 @@@ static bool msr_mtrr_valid(unsigned msr
        return false;
  }
  
+ static bool valid_pat_type(unsigned t)
+ {
+       return t < 8 && (1 << t) & 0xf3; /* 0, 1, 4, 5, 6, 7 */
+ }
+ static bool valid_mtrr_type(unsigned t)
+ {
+       return t < 8 && (1 << t) & 0x73; /* 0, 1, 4, 5, 6 */
+ }
+ static bool mtrr_valid(struct kvm_vcpu *vcpu, u32 msr, u64 data)
+ {
+       int i;
+       if (!msr_mtrr_valid(msr))
+               return false;
+       if (msr == MSR_IA32_CR_PAT) {
+               for (i = 0; i < 8; i++)
+                       if (!valid_pat_type((data >> (i * 8)) & 0xff))
+                               return false;
+               return true;
+       } else if (msr == MSR_MTRRdefType) {
+               if (data & ~0xcff)
+                       return false;
+               return valid_mtrr_type(data & 0xff);
+       } else if (msr >= MSR_MTRRfix64K_00000 && msr <= MSR_MTRRfix4K_F8000) {
+               for (i = 0; i < 8 ; i++)
+                       if (!valid_mtrr_type((data >> (i * 8)) & 0xff))
+                               return false;
+               return true;
+       }
+       /* variable MTRRs */
+       return valid_mtrr_type(data & 0xff);
+ }
  static int set_msr_mtrr(struct kvm_vcpu *vcpu, u32 msr, u64 data)
  {
        u64 *p = (u64 *)&vcpu->arch.mtrr_state.fixed_ranges;
  
-       if (!msr_mtrr_valid(msr))
+       if (!mtrr_valid(vcpu, msr, data))
                return 1;
  
        if (msr == MSR_MTRRdefType) {
@@@ -1079,14 -1116,13 +1116,13 @@@ long kvm_arch_dev_ioctl(struct file *fi
                if (copy_to_user(user_msr_list, &msr_list, sizeof msr_list))
                        goto out;
                r = -E2BIG;
-               if (n < num_msrs_to_save)
+               if (n < msr_list.nmsrs)
                        goto out;
                r = -EFAULT;
                if (copy_to_user(user_msr_list->indices, &msrs_to_save,
                                 num_msrs_to_save * sizeof(u32)))
                        goto out;
-               if (copy_to_user(user_msr_list->indices
-                                + num_msrs_to_save * sizeof(u32),
+               if (copy_to_user(user_msr_list->indices + num_msrs_to_save,
                                 &emulated_msrs,
                                 ARRAY_SIZE(emulated_msrs) * sizeof(u32)))
                        goto out;
@@@ -2261,7 -2297,12 +2297,7 @@@ static int emulator_cmpxchg_emulated(un
                                     unsigned int bytes,
                                     struct kvm_vcpu *vcpu)
  {
 -      static int reported;
 -
 -      if (!reported) {
 -              reported = 1;
 -              printk(KERN_WARNING "kvm: emulating exchange as write\n");
 -      }
 +      printk_once(KERN_WARNING "kvm: emulating exchange as write\n");
  #ifndef CONFIG_X86_64
        /* guests cmpxchg8b have to be emulated atomically */
        if (bytes == 8) {