The Wayback Machine - https://web.archive.org/web/20240422224954/https://github.com/freebsd/freebsd-src/commit/560d5eda2cb0861d11dd055fc63199e21116f6e5

Navigation Menu

Skip to content

Commit

Permalink
Make sure all CPUID values are handled, instead of exiting the
Browse filesBrowse the repository at this point in the history
bhyve process when an unhandled one is encountered. Hide some additional capabilities from the guest (e.g. debug store). This fixes the issue with FreeBSD 9.1 MP guests exiting the VM on AP spinup (where CPUID is used when sync'ing the TSCs) and the issue with the Java build where CPUIDs are issued from a guest userspace. Submitted by: tycho nightingale at pluribusnetworks com Reviewed by: neel Reported by: many
  • Loading branch information
@grehan-freebsd
grehan-freebsd committed Jun 28, 2013
1 parent cb754f6commit 560d5ed
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions sys/amd64/vmm/x86.c
Expand Up@@ -45,7 +45,9 @@ __FBSDID("$FreeBSD$");

#defineCPUID_VM_HIGH 0x40000000

staticconstcharbhyve_id[12] ="BHyVE BHyVE ";
staticconstcharbhyve_id[12] ="bhyve bhyve ";

staticuint64_tbhyve_xcpuids;

int
x86_emulate_cpuid(structvm*vm, intvcpu_id,
Expand DownExpand Up@@ -77,15 +79,13 @@ x86_emulate_cpuid(struct vm *vm, int vcpu_id,
* no multi-core or SMT.
*/
switch (func) {
/*
* Pass these through to the guest
*/
caseCPUID_0000_0000:
caseCPUID_0000_0002:
caseCPUID_0000_0003:
caseCPUID_0000_000A:
cpuid_count(*eax, *ecx, regs);
break;

caseCPUID_8000_0000:
caseCPUID_8000_0001:
caseCPUID_8000_0002:
caseCPUID_8000_0003:
caseCPUID_8000_0004:
Expand All@@ -94,6 +94,15 @@ x86_emulate_cpuid(struct vm *vm, int vcpu_id,
cpuid_count(*eax, *ecx, regs);
break;

caseCPUID_8000_0001:
/*
* Hide rdtscp/ia32_tsc_aux until we know how
* to deal with them.
*/
cpuid_count(*eax, *ecx, regs);
regs[3] &= ~AMDID_RDTSCP;
break;

caseCPUID_8000_0007:
cpuid_count(*eax, *ecx, regs);
/*
Expand DownExpand Up@@ -150,6 +159,11 @@ x86_emulate_cpuid(struct vm *vm, int vcpu_id,
*/
regs[2] &= ~CPUID2_MON;

/*
* Hide the performance and debug features.
*/
regs[2] &= ~CPUID2_PDCM;

/*
* Hide thermal monitoring
*/
Expand All@@ -161,6 +175,11 @@ x86_emulate_cpuid(struct vm *vm, int vcpu_id,
*/
regs[3] &= ~(CPUID_MCA | CPUID_MCE | CPUID_MTRR);

/*
* Hide the debug store capability.
*/
regs[3] &= ~CPUID_DS;

/*
* Disable multi-core.
*/
Expand All@@ -180,6 +199,7 @@ x86_emulate_cpuid(struct vm *vm, int vcpu_id,

caseCPUID_0000_0006:
caseCPUID_0000_0007:
caseCPUID_0000_000A:
/*
* Handle the access, but report 0 for
* all options
Expand All@@ -203,17 +223,25 @@ x86_emulate_cpuid(struct vm *vm, int vcpu_id,
case0x40000000:
regs[0] =CPUID_VM_HIGH;
bcopy(bhyve_id, &regs[1], 4);
bcopy(bhyve_id, &regs[2], 4);
bcopy(bhyve_id, &regs[3], 4);
bcopy(bhyve_id+4, &regs[2], 4);
bcopy(bhyve_id+8, &regs[3], 4);
break;

default:
/* XXX: Leaf 5? */
return (0);
/*
* The leaf value has already been clamped so
* simply pass this through, keeping count of
* how many unhandled leaf values have been seen.
*/
atomic_add_long(&bhyve_xcpuids, 1);
cpuid_count(*eax, *ecx, regs);
break;
}

*eax=regs[0];
*ebx=regs[1];
*ecx=regs[2];
*edx=regs[3];

return (1);
}

0 comments on commit 560d5ed

Please sign in to comment.
close