svn commit: r268428 - in head/sys/amd64: include vmm/intel

Neel Natu neel at FreeBSD.org
Tue Jul 8 21:48:58 UTC 2014


Author: neel
Date: Tue Jul  8 21:48:57 2014
New Revision: 268428
URL: http://svnweb.freebsd.org/changeset/base/268428

Log:
  Accurately identify the vcpu's operating mode as 64-bit, compatibility,
  protected or real.

Modified:
  head/sys/amd64/include/vmm.h
  head/sys/amd64/vmm/intel/vmx.c

Modified: head/sys/amd64/include/vmm.h
==============================================================================
--- head/sys/amd64/include/vmm.h	Tue Jul  8 20:51:03 2014	(r268427)
+++ head/sys/amd64/include/vmm.h	Tue Jul  8 21:48:57 2014	(r268428)
@@ -329,6 +329,8 @@ struct seg_desc {
 #define	SEG_DESC_UNUSABLE(desc)		((desc)->access & 0x10000)
 
 enum vm_cpu_mode {
+	CPU_MODE_REAL,
+	CPU_MODE_PROTECTED,
 	CPU_MODE_COMPATIBILITY,		/* IA-32E mode (CS.L = 0) */
 	CPU_MODE_64BIT,			/* IA-32E mode (CS.L = 1) */
 };

Modified: head/sys/amd64/vmm/intel/vmx.c
==============================================================================
--- head/sys/amd64/vmm/intel/vmx.c	Tue Jul  8 20:51:03 2014	(r268427)
+++ head/sys/amd64/vmm/intel/vmx.c	Tue Jul  8 21:48:57 2014	(r268428)
@@ -1687,11 +1687,19 @@ vmx_cpl(void)
 static enum vm_cpu_mode
 vmx_cpu_mode(void)
 {
+	uint32_t csar;
 
-	if (vmcs_read(VMCS_GUEST_IA32_EFER) & EFER_LMA)
-		return (CPU_MODE_64BIT);
-	else
-		return (CPU_MODE_COMPATIBILITY);
+	if (vmcs_read(VMCS_GUEST_IA32_EFER) & EFER_LMA) {
+		csar = vmcs_read(VMCS_GUEST_CS_ACCESS_RIGHTS);
+		if (csar & 0x2000)
+			return (CPU_MODE_64BIT);	/* CS.L = 1 */
+		else
+			return (CPU_MODE_COMPATIBILITY);
+	} else if (vmcs_read(VMCS_GUEST_CR0) & CR0_PE) {
+		return (CPU_MODE_PROTECTED);
+	} else {
+		return (CPU_MODE_REAL);
+	}
 }
 
 static enum vm_paging_mode


More information about the svn-src-all mailing list