Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Feb 2015 18:54:42 +0200
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        John Baldwin <jhb@freebsd.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, trasz@freebsd.org, Rui Paulo <rpaulo@me.com>
Subject:   Re: svn commit: r278473 - in head/sys: amd64/amd64 amd64/include amd64/vmm contrib/dev/acpica/include i386/i386 i386/include x86/acpica x86/include x86/x86 x86/xen
Message-ID:  <20150211165442.GT42409@kib.kiev.ua>
In-Reply-To: <6564436.fIAEJlraDt@ralph.baldwin.cx>
References:  <bbbead6b-64da-4f0d-8821-98d79319aecf@me.com> <20150211083200.GO42409@kib.kiev.ua> <6564436.fIAEJlraDt@ralph.baldwin.cx>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Feb 11, 2015 at 10:20:03AM -0500, John Baldwin wrote:
> On Wednesday, February 11, 2015 10:32:00 AM Konstantin Belousov wrote:
> > On Wed, Feb 11, 2015 at 12:43:39AM +0000, Rui Paulo wrote:
> > > On Feb 09, 2015, at 01:01 PM, Konstantin Belousov <kib@FreeBSD.org> wrote:
> > > 
> > > Author: kib
> > > Date: Mon Feb 9 21:00:56 2015
> > > New Revision: 278473
> > > URL: https://svnweb.freebsd.org/changeset/base/278473
> > > 
> > > Log:
> > > Add x2APIC support. Enable it by default if CPU is capable. The
> > > hw.x2apic_enable tunable allows disabling it from the loader prompt.
> > >  
> > > This breaks VMware Fusion when the host CPU has x2APIC support.  In
> > > my case, mpt(4) was unable to receive interrupts and USB was similarly
> > > broken.  It's possible that this is a VMware bug, but you might want to
> > > avoid turning this on when running under the VMware hypervisor.
> > 
> > Neel pointed this out to me when the patch was reviewed.
> > He told me that x2APIC does not work in Fusion 5.x, while it seems
> > to be fixed in 7.x.
> > https://communities.vmware.com/message/2173695?tstart=0
> > 
> > Upon further discussion with Neel and Peter, it was suggested that we
> > enable enable x2APIC unconditionally, which seems what is done for
> > Linux benchmarks.
> > 
> > Is vmware 5.x is used while there is already at least version 7.x ?
> > I have no idea about vmware product nomenclature and lifecycle.
> 
> I believe we can ask vmware what version it is when we notice we are running 
> under it (which we already detect for TSC purposes).  We could quirk for that 
> case, or even just disable for VM_GUEST_VMWARE for now.
> 

Ok, https://lkml.org/lkml/2013/1/17/552

Patch is below. Please, users of VMWare, test it.

diff --git a/sys/x86/acpica/madt.c b/sys/x86/acpica/madt.c
index f20b735..c3df686 100644
--- a/sys/x86/acpica/madt.c
+++ b/sys/x86/acpica/madt.c
@@ -31,6 +31,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/systm.h>
 #include <sys/bus.h>
 #include <sys/kernel.h>
+#include <sys/limits.h>
 #include <sys/malloc.h>
 #include <sys/smp.h>
 #include <vm/vm.h>
@@ -40,6 +41,7 @@ __FBSDID("$FreeBSD$");
 #include <machine/intr_machdep.h>
 #include <x86/apicvar.h>
 #include <machine/md_var.h>
+#include <x86/vmware.h>
 
 #include <contrib/dev/acpica/include/acpi.h>
 #include <contrib/dev/acpica/include/actables.h>
@@ -130,6 +132,7 @@ madt_setup_local(void)
 {
 	ACPI_TABLE_DMAR *dmartbl;
 	vm_paddr_t dmartbl_physaddr;
+	u_int p[4];
 
 	madt = pmap_mapbios(madt_physaddr, madt_length);
 	if ((cpu_feature2 & CPUID2_X2APIC) != 0) {
@@ -146,6 +149,16 @@ madt_setup_local(void)
 			}
 			acpi_unmap_table(dmartbl);
 		}
+		if (vm_guest == VM_GUEST_VMWARE) {
+			vmware_hvcall(VMW_HVCMD_GETVCPU_INFO, p);
+			if ((p[0] & VMW_VCPUINFO_VCPU_RESERVED) != 0 ||
+			    (p[0] & VMW_VCPUINFO_LEGACY_X2APIC) == 0) {
+				x2apic_mode = 0;
+				if (bootverbose)
+					printf(
+       "x2APIC available but disabled inside VMWare without intr redirection\n");
+			}
+		}
 		TUNABLE_INT_FETCH("hw.x2apic_enable", &x2apic_mode);
 	}
 
diff --git a/sys/x86/include/vmware.h b/sys/x86/include/vmware.h
index c72f48d..d3d7e2d 100644
--- a/sys/x86/include/vmware.h
+++ b/sys/x86/include/vmware.h
@@ -31,8 +31,13 @@
 
 #define	VMW_HVMAGIC		0x564d5868
 #define	VMW_HVPORT		0x5658
+
 #define	VMW_HVCMD_GETVERSION	10
 #define	VMW_HVCMD_GETHZ		45
+#define	VMW_HVCMD_GETVCPU_INFO	68
+
+#define	VMW_VCPUINFO_LEGACY_X2APIC	(1 << 3)
+#define	VMW_VCPUINFO_VCPU_RESERVED	(1 << 31)
 
 static __inline void
 vmware_hvcall(u_int cmd, u_int *p)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150211165442.GT42409>