i386/lapic: Allow vmware with single CPU to boot SMP kernel
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Sun, 22 May 2011 11:10:10 +0000 (19:10 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Sun, 22 May 2011 11:14:05 +0000 (19:14 +0800)
It looks like that if only one CPU is configured in vmware, then
LAPIC will not work at all, so LAPIC will not be enabled if this
kind of configuration is detected.

Currently we detect vmware using cpu_feature2's CPUID2_VMM bit.

Thank swildner@ for providing necessary information on this.

sys/cpu/i386/include/specialreg.h
sys/platform/pc32/apic/lapic.c

index 1cafc55..8e5fa9f 100644 (file)
 #define        CPUID2_X2APIC   0x00200000
 #define        CPUID2_POPCNT   0x00800000
 #define        CPUID2_AESNI    0x02000000
+#define CPUID2_VMM     0x80000000
 
 /*
  * Important bits in the AMD extended cpuid flags
index b61041f..aa4a015 100644 (file)
@@ -33,6 +33,7 @@
 #include <machine/globaldata.h>
 #include <machine/smp.h>
 #include <machine/cputypes.h>
+#include <machine/specialreg.h>
 #include <machine/md_var.h>
 #include <machine/pmap.h>
 #include <machine_base/apic/lapic.h>
@@ -674,6 +675,18 @@ lapic_config(void)
                mp_naps = ap_max;
        }
 
+       if ((cpu_feature2 & CPUID2_VMM) && mp_naps == 0) {
+               /*
+                * XXX
+                * Special hack for vmware.  It looks like that
+                * if only one CPU is configured (mp_naps == 0)
+                * in vmware (cpu_feature2 & CPUID2_VMM),
+                * then LAPIC will not work at all.
+                */
+               kprintf("LAPIC: single CPU virtual machine detected, "
+                       "disable LAPIC\n");
+               return ENXIO;
+       }
        return 0;
 }