2011-05-13 04:54:01 +00:00
|
|
|
/*-
|
2017-11-27 15:03:07 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2011-05-13 04:54:01 +00:00
|
|
|
* Copyright (c) 2011 NetApp, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2012-09-25 22:31:35 +00:00
|
|
|
#include <sys/param.h>
|
2014-02-08 16:37:54 +00:00
|
|
|
#include <sys/pcpu.h>
|
2011-06-02 14:04:07 +00:00
|
|
|
#include <sys/systm.h>
|
2014-08-24 01:10:06 +00:00
|
|
|
#include <sys/sysctl.h>
|
2011-05-13 04:54:01 +00:00
|
|
|
|
2013-04-10 05:59:07 +00:00
|
|
|
#include <machine/clock.h>
|
2011-05-13 04:54:01 +00:00
|
|
|
#include <machine/cpufunc.h>
|
2011-06-02 14:04:07 +00:00
|
|
|
#include <machine/md_var.h>
|
2014-02-08 16:37:54 +00:00
|
|
|
#include <machine/segments.h>
|
2011-05-13 04:54:01 +00:00
|
|
|
#include <machine/specialreg.h>
|
|
|
|
|
2012-09-25 22:31:35 +00:00
|
|
|
#include <machine/vmm.h>
|
|
|
|
|
2014-02-08 16:37:54 +00:00
|
|
|
#include "vmm_host.h"
|
2014-10-16 18:13:10 +00:00
|
|
|
#include "vmm_ktr.h"
|
|
|
|
#include "vmm_util.h"
|
2011-05-13 04:54:01 +00:00
|
|
|
#include "x86.h"
|
|
|
|
|
2014-08-24 01:10:06 +00:00
|
|
|
SYSCTL_DECL(_hw_vmm);
|
|
|
|
static SYSCTL_NODE(_hw_vmm, OID_AUTO, topology, CTLFLAG_RD, 0, NULL);
|
|
|
|
|
2011-06-02 14:04:07 +00:00
|
|
|
#define CPUID_VM_HIGH 0x40000000
|
|
|
|
|
2013-06-28 06:05:33 +00:00
|
|
|
static const char bhyve_id[12] = "bhyve bhyve ";
|
|
|
|
|
|
|
|
static uint64_t bhyve_xcpuids;
|
2014-10-16 18:13:10 +00:00
|
|
|
SYSCTL_ULONG(_hw_vmm, OID_AUTO, bhyve_xcpuids, CTLFLAG_RW, &bhyve_xcpuids, 0,
|
|
|
|
"Number of times an unknown cpuid leaf was accessed");
|
2011-06-02 14:04:07 +00:00
|
|
|
|
Add the ability to control the CPU topology of created VMs
from userland without the need to use sysctls, it allows the old
sysctls to continue to function, but deprecates them at
FreeBSD_version 1200060 (Relnotes for deprecate).
The command line of bhyve is maintained in a backwards compatible way.
The API of libvmmapi is maintained in a backwards compatible way.
The sysctl's are maintained in a backwards compatible way.
Added command option looks like:
bhyve -c [[cpus=]n][,sockets=n][,cores=n][,threads=n][,maxcpus=n]
The optional parts can be specified in any order, but only a single
integer invokes the backwards compatible parse. [,maxcpus=n] is
hidden by #ifdef until kernel support is added, though the api
is put in place.
bhyvectl --get-cpu-topology option added.
Reviewed by: grehan (maintainer, earlier version),
Reviewed by: bcr (manpages)
Approved by: bde (mentor), phk (mentor)
Tested by: Oleg Ginzburg <olevole@olevole.ru> (cbsd)
MFC after: 1 week
Relnotes: Y
Differential Revision: https://reviews.freebsd.org/D9930
2018-04-08 19:24:49 +00:00
|
|
|
#if __FreeBSD_version < 1200060 /* Remove after 11 EOL helps MFCing */
|
|
|
|
extern u_int threads_per_core;
|
2014-08-24 01:10:06 +00:00
|
|
|
SYSCTL_UINT(_hw_vmm_topology, OID_AUTO, threads_per_core, CTLFLAG_RDTUN,
|
|
|
|
&threads_per_core, 0, NULL);
|
|
|
|
|
Add the ability to control the CPU topology of created VMs
from userland without the need to use sysctls, it allows the old
sysctls to continue to function, but deprecates them at
FreeBSD_version 1200060 (Relnotes for deprecate).
The command line of bhyve is maintained in a backwards compatible way.
The API of libvmmapi is maintained in a backwards compatible way.
The sysctl's are maintained in a backwards compatible way.
Added command option looks like:
bhyve -c [[cpus=]n][,sockets=n][,cores=n][,threads=n][,maxcpus=n]
The optional parts can be specified in any order, but only a single
integer invokes the backwards compatible parse. [,maxcpus=n] is
hidden by #ifdef until kernel support is added, though the api
is put in place.
bhyvectl --get-cpu-topology option added.
Reviewed by: grehan (maintainer, earlier version),
Reviewed by: bcr (manpages)
Approved by: bde (mentor), phk (mentor)
Tested by: Oleg Ginzburg <olevole@olevole.ru> (cbsd)
MFC after: 1 week
Relnotes: Y
Differential Revision: https://reviews.freebsd.org/D9930
2018-04-08 19:24:49 +00:00
|
|
|
extern u_int cores_per_package;
|
2014-08-24 01:10:06 +00:00
|
|
|
SYSCTL_UINT(_hw_vmm_topology, OID_AUTO, cores_per_package, CTLFLAG_RDTUN,
|
|
|
|
&cores_per_package, 0, NULL);
|
Add the ability to control the CPU topology of created VMs
from userland without the need to use sysctls, it allows the old
sysctls to continue to function, but deprecates them at
FreeBSD_version 1200060 (Relnotes for deprecate).
The command line of bhyve is maintained in a backwards compatible way.
The API of libvmmapi is maintained in a backwards compatible way.
The sysctl's are maintained in a backwards compatible way.
Added command option looks like:
bhyve -c [[cpus=]n][,sockets=n][,cores=n][,threads=n][,maxcpus=n]
The optional parts can be specified in any order, but only a single
integer invokes the backwards compatible parse. [,maxcpus=n] is
hidden by #ifdef until kernel support is added, though the api
is put in place.
bhyvectl --get-cpu-topology option added.
Reviewed by: grehan (maintainer, earlier version),
Reviewed by: bcr (manpages)
Approved by: bde (mentor), phk (mentor)
Tested by: Oleg Ginzburg <olevole@olevole.ru> (cbsd)
MFC after: 1 week
Relnotes: Y
Differential Revision: https://reviews.freebsd.org/D9930
2018-04-08 19:24:49 +00:00
|
|
|
#endif
|
2014-08-24 01:10:06 +00:00
|
|
|
|
|
|
|
static int cpuid_leaf_b = 1;
|
|
|
|
SYSCTL_INT(_hw_vmm_topology, OID_AUTO, cpuid_leaf_b, CTLFLAG_RDTUN,
|
|
|
|
&cpuid_leaf_b, 0, NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Round up to the next power of two, if necessary, and then take log2.
|
|
|
|
* Returns -1 if argument is zero.
|
|
|
|
*/
|
|
|
|
static __inline int
|
|
|
|
log2(u_int x)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (fls(x << (1 - powerof2(x))) - 1);
|
|
|
|
}
|
|
|
|
|
2011-05-13 04:54:01 +00:00
|
|
|
int
|
2012-09-25 22:31:35 +00:00
|
|
|
x86_emulate_cpuid(struct vm *vm, int vcpu_id,
|
|
|
|
uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
|
2011-05-13 04:54:01 +00:00
|
|
|
{
|
2014-02-08 16:37:54 +00:00
|
|
|
const struct xsave_limits *limits;
|
|
|
|
uint64_t cr4;
|
2014-08-24 01:10:06 +00:00
|
|
|
int error, enable_invpcid, level, width, x2apic_id;
|
|
|
|
unsigned int func, regs[4], logical_cpus;
|
2012-09-25 22:31:35 +00:00
|
|
|
enum x2apic_state x2apic_state;
|
Add the ability to control the CPU topology of created VMs
from userland without the need to use sysctls, it allows the old
sysctls to continue to function, but deprecates them at
FreeBSD_version 1200060 (Relnotes for deprecate).
The command line of bhyve is maintained in a backwards compatible way.
The API of libvmmapi is maintained in a backwards compatible way.
The sysctl's are maintained in a backwards compatible way.
Added command option looks like:
bhyve -c [[cpus=]n][,sockets=n][,cores=n][,threads=n][,maxcpus=n]
The optional parts can be specified in any order, but only a single
integer invokes the backwards compatible parse. [,maxcpus=n] is
hidden by #ifdef until kernel support is added, though the api
is put in place.
bhyvectl --get-cpu-topology option added.
Reviewed by: grehan (maintainer, earlier version),
Reviewed by: bcr (manpages)
Approved by: bde (mentor), phk (mentor)
Tested by: Oleg Ginzburg <olevole@olevole.ru> (cbsd)
MFC after: 1 week
Relnotes: Y
Differential Revision: https://reviews.freebsd.org/D9930
2018-04-08 19:24:49 +00:00
|
|
|
uint16_t cores, maxcpus, sockets, threads;
|
2011-05-13 04:54:01 +00:00
|
|
|
|
2014-10-16 18:13:10 +00:00
|
|
|
VCPU_CTR2(vm, vcpu_id, "cpuid %#x,%#x", *eax, *ecx);
|
|
|
|
|
2011-06-02 14:04:07 +00:00
|
|
|
/*
|
|
|
|
* Requests for invalid CPUID levels should map to the highest
|
|
|
|
* available level instead.
|
|
|
|
*/
|
|
|
|
if (cpu_exthigh != 0 && *eax >= 0x80000000) {
|
|
|
|
if (*eax > cpu_exthigh)
|
|
|
|
*eax = cpu_exthigh;
|
|
|
|
} else if (*eax >= 0x40000000) {
|
|
|
|
if (*eax > CPUID_VM_HIGH)
|
|
|
|
*eax = CPUID_VM_HIGH;
|
|
|
|
} else if (*eax > cpu_high) {
|
|
|
|
*eax = cpu_high;
|
|
|
|
}
|
2011-05-13 04:54:01 +00:00
|
|
|
|
2013-02-13 23:22:17 +00:00
|
|
|
func = *eax;
|
|
|
|
|
2011-06-02 14:04:07 +00:00
|
|
|
/*
|
|
|
|
* In general the approach used for CPU topology is to
|
|
|
|
* advertise a flat topology where all CPUs are packages with
|
|
|
|
* no multi-core or SMT.
|
|
|
|
*/
|
|
|
|
switch (func) {
|
2013-06-28 06:05:33 +00:00
|
|
|
/*
|
|
|
|
* Pass these through to the guest
|
|
|
|
*/
|
2011-05-13 04:54:01 +00:00
|
|
|
case CPUID_0000_0000:
|
|
|
|
case CPUID_0000_0002:
|
|
|
|
case CPUID_0000_0003:
|
|
|
|
case CPUID_8000_0000:
|
|
|
|
case CPUID_8000_0002:
|
|
|
|
case CPUID_8000_0003:
|
|
|
|
case CPUID_8000_0004:
|
|
|
|
case CPUID_8000_0006:
|
2014-10-16 18:13:10 +00:00
|
|
|
cpuid_count(*eax, *ecx, regs);
|
|
|
|
break;
|
2011-05-13 04:54:01 +00:00
|
|
|
case CPUID_8000_0008:
|
2011-06-02 14:04:07 +00:00
|
|
|
cpuid_count(*eax, *ecx, regs);
|
2014-10-16 18:13:10 +00:00
|
|
|
if (vmm_is_amd()) {
|
|
|
|
/*
|
|
|
|
* XXX this might appear silly because AMD
|
|
|
|
* cpus don't have threads.
|
|
|
|
*
|
|
|
|
* However this matches the logical cpus as
|
|
|
|
* advertised by leaf 0x1 and will work even
|
Add the ability to control the CPU topology of created VMs
from userland without the need to use sysctls, it allows the old
sysctls to continue to function, but deprecates them at
FreeBSD_version 1200060 (Relnotes for deprecate).
The command line of bhyve is maintained in a backwards compatible way.
The API of libvmmapi is maintained in a backwards compatible way.
The sysctl's are maintained in a backwards compatible way.
Added command option looks like:
bhyve -c [[cpus=]n][,sockets=n][,cores=n][,threads=n][,maxcpus=n]
The optional parts can be specified in any order, but only a single
integer invokes the backwards compatible parse. [,maxcpus=n] is
hidden by #ifdef until kernel support is added, though the api
is put in place.
bhyvectl --get-cpu-topology option added.
Reviewed by: grehan (maintainer, earlier version),
Reviewed by: bcr (manpages)
Approved by: bde (mentor), phk (mentor)
Tested by: Oleg Ginzburg <olevole@olevole.ru> (cbsd)
MFC after: 1 week
Relnotes: Y
Differential Revision: https://reviews.freebsd.org/D9930
2018-04-08 19:24:49 +00:00
|
|
|
* if threads is set incorrectly on an AMD host.
|
2014-10-16 18:13:10 +00:00
|
|
|
*/
|
Add the ability to control the CPU topology of created VMs
from userland without the need to use sysctls, it allows the old
sysctls to continue to function, but deprecates them at
FreeBSD_version 1200060 (Relnotes for deprecate).
The command line of bhyve is maintained in a backwards compatible way.
The API of libvmmapi is maintained in a backwards compatible way.
The sysctl's are maintained in a backwards compatible way.
Added command option looks like:
bhyve -c [[cpus=]n][,sockets=n][,cores=n][,threads=n][,maxcpus=n]
The optional parts can be specified in any order, but only a single
integer invokes the backwards compatible parse. [,maxcpus=n] is
hidden by #ifdef until kernel support is added, though the api
is put in place.
bhyvectl --get-cpu-topology option added.
Reviewed by: grehan (maintainer, earlier version),
Reviewed by: bcr (manpages)
Approved by: bde (mentor), phk (mentor)
Tested by: Oleg Ginzburg <olevole@olevole.ru> (cbsd)
MFC after: 1 week
Relnotes: Y
Differential Revision: https://reviews.freebsd.org/D9930
2018-04-08 19:24:49 +00:00
|
|
|
vm_get_topology(vm, &sockets, &cores, &threads,
|
|
|
|
&maxcpus);
|
|
|
|
logical_cpus = threads * cores;
|
2014-10-16 18:13:10 +00:00
|
|
|
regs[2] = logical_cpus - 1;
|
|
|
|
}
|
2011-05-13 04:54:01 +00:00
|
|
|
break;
|
|
|
|
|
2013-06-28 06:05:33 +00:00
|
|
|
case CPUID_8000_0001:
|
2014-10-15 04:29:03 +00:00
|
|
|
cpuid_count(*eax, *ecx, regs);
|
|
|
|
|
|
|
|
/*
|
2014-10-16 18:13:10 +00:00
|
|
|
* Hide SVM and Topology Extension features from guest.
|
2014-10-15 04:29:03 +00:00
|
|
|
*/
|
2014-10-16 18:13:10 +00:00
|
|
|
regs[2] &= ~(AMDID2_SVM | AMDID2_TOPOLOGY);
|
2014-10-15 04:29:03 +00:00
|
|
|
|
2014-10-17 03:04:38 +00:00
|
|
|
/*
|
|
|
|
* Don't advertise extended performance counter MSRs
|
|
|
|
* to the guest.
|
|
|
|
*/
|
|
|
|
regs[2] &= ~AMDID2_PCXC;
|
|
|
|
regs[2] &= ~AMDID2_PNXC;
|
|
|
|
regs[2] &= ~AMDID2_PTSCEL2I;
|
|
|
|
|
2014-10-17 06:23:04 +00:00
|
|
|
/*
|
|
|
|
* Don't advertise Instruction Based Sampling feature.
|
|
|
|
*/
|
|
|
|
regs[2] &= ~AMDID2_IBS;
|
|
|
|
|
2014-10-18 05:39:32 +00:00
|
|
|
/* NodeID MSR not available */
|
|
|
|
regs[2] &= ~AMDID2_NODE_ID;
|
|
|
|
|
2014-10-19 21:38:58 +00:00
|
|
|
/* Don't advertise the OS visible workaround feature */
|
|
|
|
regs[2] &= ~AMDID2_OSVW;
|
|
|
|
|
2017-03-16 03:21:42 +00:00
|
|
|
/* Hide mwaitx/monitorx capability from the guest */
|
|
|
|
regs[2] &= ~AMDID2_MWAITX;
|
|
|
|
|
2013-06-28 06:05:33 +00:00
|
|
|
/*
|
|
|
|
* Hide rdtscp/ia32_tsc_aux until we know how
|
|
|
|
* to deal with them.
|
|
|
|
*/
|
|
|
|
regs[3] &= ~AMDID_RDTSCP;
|
|
|
|
break;
|
|
|
|
|
2013-04-10 05:59:07 +00:00
|
|
|
case CPUID_8000_0007:
|
|
|
|
/*
|
2014-10-19 21:38:58 +00:00
|
|
|
* AMD uses this leaf to advertise the processor's
|
|
|
|
* power monitoring and RAS capabilities. These
|
|
|
|
* features are hardware-specific and exposing
|
|
|
|
* them to a guest doesn't make a lot of sense.
|
|
|
|
*
|
|
|
|
* Intel uses this leaf only to advertise the
|
|
|
|
* "Invariant TSC" feature with all other bits
|
|
|
|
* being reserved (set to zero).
|
|
|
|
*/
|
|
|
|
regs[0] = 0;
|
|
|
|
regs[1] = 0;
|
|
|
|
regs[2] = 0;
|
|
|
|
regs[3] = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "Invariant TSC" can be advertised to the guest if:
|
|
|
|
* - host TSC frequency is invariant
|
|
|
|
* - host TSCs are synchronized across physical cpus
|
2013-04-10 05:59:07 +00:00
|
|
|
*
|
|
|
|
* XXX This still falls short because the vcpu
|
|
|
|
* can observe the TSC moving backwards as it
|
|
|
|
* migrates across physical cpus. But at least
|
|
|
|
* it should discourage the guest from using the
|
|
|
|
* TSC to keep track of time.
|
|
|
|
*/
|
2014-10-19 21:38:58 +00:00
|
|
|
if (tsc_is_invariant && smp_tsc)
|
|
|
|
regs[3] |= AMDPM_TSC_INVARIANT;
|
2013-04-10 05:59:07 +00:00
|
|
|
break;
|
|
|
|
|
2011-05-13 04:54:01 +00:00
|
|
|
case CPUID_0000_0001:
|
2011-06-02 14:04:07 +00:00
|
|
|
do_cpuid(1, regs);
|
|
|
|
|
2012-09-25 22:31:35 +00:00
|
|
|
error = vm_get_x2apic_state(vm, vcpu_id, &x2apic_state);
|
|
|
|
if (error) {
|
|
|
|
panic("x86_emulate_cpuid: error %d "
|
|
|
|
"fetching x2apic state", error);
|
|
|
|
}
|
|
|
|
|
2011-05-13 04:54:01 +00:00
|
|
|
/*
|
|
|
|
* Override the APIC ID only in ebx
|
|
|
|
*/
|
2011-06-02 14:04:07 +00:00
|
|
|
regs[1] &= ~(CPUID_LOCAL_APIC_ID);
|
|
|
|
regs[1] |= (vcpu_id << CPUID_0000_0001_APICID_SHIFT);
|
2011-05-13 04:54:01 +00:00
|
|
|
|
|
|
|
/*
|
2015-05-02 19:07:49 +00:00
|
|
|
* Don't expose VMX, SpeedStep, TME or SMX capability.
|
2011-06-02 14:04:07 +00:00
|
|
|
* Advertise x2APIC capability and Hypervisor guest.
|
2011-05-13 04:54:01 +00:00
|
|
|
*/
|
2011-06-02 14:04:07 +00:00
|
|
|
regs[2] &= ~(CPUID2_VMX | CPUID2_EST | CPUID2_TM2);
|
2015-05-02 19:07:49 +00:00
|
|
|
regs[2] &= ~(CPUID2_SMX);
|
2012-09-25 22:31:35 +00:00
|
|
|
|
|
|
|
regs[2] |= CPUID2_HV;
|
|
|
|
|
|
|
|
if (x2apic_state != X2APIC_DISABLED)
|
|
|
|
regs[2] |= CPUID2_X2APIC;
|
2014-02-20 01:48:25 +00:00
|
|
|
else
|
|
|
|
regs[2] &= ~CPUID2_X2APIC;
|
2011-05-13 04:54:01 +00:00
|
|
|
|
2012-05-03 05:04:37 +00:00
|
|
|
/*
|
2014-02-08 16:37:54 +00:00
|
|
|
* Only advertise CPUID2_XSAVE in the guest if
|
|
|
|
* the host is using XSAVE.
|
2012-05-03 05:04:37 +00:00
|
|
|
*/
|
2014-02-08 16:37:54 +00:00
|
|
|
if (!(regs[2] & CPUID2_OSXSAVE))
|
|
|
|
regs[2] &= ~CPUID2_XSAVE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If CPUID2_XSAVE is being advertised and the
|
|
|
|
* guest has set CR4_XSAVE, set
|
|
|
|
* CPUID2_OSXSAVE.
|
|
|
|
*/
|
|
|
|
regs[2] &= ~CPUID2_OSXSAVE;
|
|
|
|
if (regs[2] & CPUID2_XSAVE) {
|
|
|
|
error = vm_get_register(vm, vcpu_id,
|
|
|
|
VM_REG_GUEST_CR4, &cr4);
|
|
|
|
if (error)
|
|
|
|
panic("x86_emulate_cpuid: error %d "
|
|
|
|
"fetching %%cr4", error);
|
|
|
|
if (cr4 & CR4_XSAVE)
|
|
|
|
regs[2] |= CPUID2_OSXSAVE;
|
|
|
|
}
|
2012-05-03 05:04:37 +00:00
|
|
|
|
2012-10-25 04:08:26 +00:00
|
|
|
/*
|
|
|
|
* Hide monitor/mwait until we know how to deal with
|
|
|
|
* these instructions.
|
|
|
|
*/
|
|
|
|
regs[2] &= ~CPUID2_MON;
|
|
|
|
|
2013-06-28 06:05:33 +00:00
|
|
|
/*
|
|
|
|
* Hide the performance and debug features.
|
|
|
|
*/
|
|
|
|
regs[2] &= ~CPUID2_PDCM;
|
2013-09-17 17:56:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* No TSC deadline support in the APIC yet
|
|
|
|
*/
|
|
|
|
regs[2] &= ~CPUID2_TSCDLT;
|
|
|
|
|
2011-05-19 21:53:25 +00:00
|
|
|
/*
|
|
|
|
* Hide thermal monitoring
|
|
|
|
*/
|
|
|
|
regs[3] &= ~(CPUID_ACPI | CPUID_TM);
|
2015-05-02 04:19:11 +00:00
|
|
|
|
2011-05-13 04:54:01 +00:00
|
|
|
/*
|
2015-05-02 04:19:11 +00:00
|
|
|
* Hide the debug store capability.
|
2011-05-13 04:54:01 +00:00
|
|
|
*/
|
2013-06-28 06:05:33 +00:00
|
|
|
regs[3] &= ~CPUID_DS;
|
|
|
|
|
2015-05-02 04:19:11 +00:00
|
|
|
/*
|
|
|
|
* Advertise the Machine Check and MTRR capability.
|
|
|
|
*
|
|
|
|
* Some guest OSes (e.g. Windows) will not boot if
|
|
|
|
* these features are absent.
|
|
|
|
*/
|
|
|
|
regs[3] |= (CPUID_MCA | CPUID_MCE | CPUID_MTRR);
|
|
|
|
|
Add the ability to control the CPU topology of created VMs
from userland without the need to use sysctls, it allows the old
sysctls to continue to function, but deprecates them at
FreeBSD_version 1200060 (Relnotes for deprecate).
The command line of bhyve is maintained in a backwards compatible way.
The API of libvmmapi is maintained in a backwards compatible way.
The sysctl's are maintained in a backwards compatible way.
Added command option looks like:
bhyve -c [[cpus=]n][,sockets=n][,cores=n][,threads=n][,maxcpus=n]
The optional parts can be specified in any order, but only a single
integer invokes the backwards compatible parse. [,maxcpus=n] is
hidden by #ifdef until kernel support is added, though the api
is put in place.
bhyvectl --get-cpu-topology option added.
Reviewed by: grehan (maintainer, earlier version),
Reviewed by: bcr (manpages)
Approved by: bde (mentor), phk (mentor)
Tested by: Oleg Ginzburg <olevole@olevole.ru> (cbsd)
MFC after: 1 week
Relnotes: Y
Differential Revision: https://reviews.freebsd.org/D9930
2018-04-08 19:24:49 +00:00
|
|
|
vm_get_topology(vm, &sockets, &cores, &threads,
|
|
|
|
&maxcpus);
|
|
|
|
logical_cpus = threads * cores;
|
2011-06-02 14:04:07 +00:00
|
|
|
regs[1] &= ~CPUID_HTT_CORES;
|
2014-08-24 01:10:06 +00:00
|
|
|
regs[1] |= (logical_cpus & 0xff) << 16;
|
|
|
|
regs[3] |= CPUID_HTT;
|
2011-06-02 14:04:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CPUID_0000_0004:
|
2014-08-23 22:44:31 +00:00
|
|
|
cpuid_count(*eax, *ecx, regs);
|
2011-06-02 14:04:07 +00:00
|
|
|
|
2014-08-24 01:10:06 +00:00
|
|
|
if (regs[0] || regs[1] || regs[2] || regs[3]) {
|
Add the ability to control the CPU topology of created VMs
from userland without the need to use sysctls, it allows the old
sysctls to continue to function, but deprecates them at
FreeBSD_version 1200060 (Relnotes for deprecate).
The command line of bhyve is maintained in a backwards compatible way.
The API of libvmmapi is maintained in a backwards compatible way.
The sysctl's are maintained in a backwards compatible way.
Added command option looks like:
bhyve -c [[cpus=]n][,sockets=n][,cores=n][,threads=n][,maxcpus=n]
The optional parts can be specified in any order, but only a single
integer invokes the backwards compatible parse. [,maxcpus=n] is
hidden by #ifdef until kernel support is added, though the api
is put in place.
bhyvectl --get-cpu-topology option added.
Reviewed by: grehan (maintainer, earlier version),
Reviewed by: bcr (manpages)
Approved by: bde (mentor), phk (mentor)
Tested by: Oleg Ginzburg <olevole@olevole.ru> (cbsd)
MFC after: 1 week
Relnotes: Y
Differential Revision: https://reviews.freebsd.org/D9930
2018-04-08 19:24:49 +00:00
|
|
|
vm_get_topology(vm, &sockets, &cores, &threads,
|
|
|
|
&maxcpus);
|
2014-08-24 01:10:06 +00:00
|
|
|
regs[0] &= 0x3ff;
|
Add the ability to control the CPU topology of created VMs
from userland without the need to use sysctls, it allows the old
sysctls to continue to function, but deprecates them at
FreeBSD_version 1200060 (Relnotes for deprecate).
The command line of bhyve is maintained in a backwards compatible way.
The API of libvmmapi is maintained in a backwards compatible way.
The sysctl's are maintained in a backwards compatible way.
Added command option looks like:
bhyve -c [[cpus=]n][,sockets=n][,cores=n][,threads=n][,maxcpus=n]
The optional parts can be specified in any order, but only a single
integer invokes the backwards compatible parse. [,maxcpus=n] is
hidden by #ifdef until kernel support is added, though the api
is put in place.
bhyvectl --get-cpu-topology option added.
Reviewed by: grehan (maintainer, earlier version),
Reviewed by: bcr (manpages)
Approved by: bde (mentor), phk (mentor)
Tested by: Oleg Ginzburg <olevole@olevole.ru> (cbsd)
MFC after: 1 week
Relnotes: Y
Differential Revision: https://reviews.freebsd.org/D9930
2018-04-08 19:24:49 +00:00
|
|
|
regs[0] |= (cores - 1) << 26;
|
2014-08-24 01:10:06 +00:00
|
|
|
/*
|
|
|
|
* Cache topology:
|
|
|
|
* - L1 and L2 are shared only by the logical
|
|
|
|
* processors in a single core.
|
|
|
|
* - L3 and above are shared by all logical
|
|
|
|
* processors in the package.
|
|
|
|
*/
|
Add the ability to control the CPU topology of created VMs
from userland without the need to use sysctls, it allows the old
sysctls to continue to function, but deprecates them at
FreeBSD_version 1200060 (Relnotes for deprecate).
The command line of bhyve is maintained in a backwards compatible way.
The API of libvmmapi is maintained in a backwards compatible way.
The sysctl's are maintained in a backwards compatible way.
Added command option looks like:
bhyve -c [[cpus=]n][,sockets=n][,cores=n][,threads=n][,maxcpus=n]
The optional parts can be specified in any order, but only a single
integer invokes the backwards compatible parse. [,maxcpus=n] is
hidden by #ifdef until kernel support is added, though the api
is put in place.
bhyvectl --get-cpu-topology option added.
Reviewed by: grehan (maintainer, earlier version),
Reviewed by: bcr (manpages)
Approved by: bde (mentor), phk (mentor)
Tested by: Oleg Ginzburg <olevole@olevole.ru> (cbsd)
MFC after: 1 week
Relnotes: Y
Differential Revision: https://reviews.freebsd.org/D9930
2018-04-08 19:24:49 +00:00
|
|
|
logical_cpus = threads;
|
2014-08-24 01:10:06 +00:00
|
|
|
level = (regs[0] >> 5) & 0x7;
|
|
|
|
if (level >= 3)
|
Add the ability to control the CPU topology of created VMs
from userland without the need to use sysctls, it allows the old
sysctls to continue to function, but deprecates them at
FreeBSD_version 1200060 (Relnotes for deprecate).
The command line of bhyve is maintained in a backwards compatible way.
The API of libvmmapi is maintained in a backwards compatible way.
The sysctl's are maintained in a backwards compatible way.
Added command option looks like:
bhyve -c [[cpus=]n][,sockets=n][,cores=n][,threads=n][,maxcpus=n]
The optional parts can be specified in any order, but only a single
integer invokes the backwards compatible parse. [,maxcpus=n] is
hidden by #ifdef until kernel support is added, though the api
is put in place.
bhyvectl --get-cpu-topology option added.
Reviewed by: grehan (maintainer, earlier version),
Reviewed by: bcr (manpages)
Approved by: bde (mentor), phk (mentor)
Tested by: Oleg Ginzburg <olevole@olevole.ru> (cbsd)
MFC after: 1 week
Relnotes: Y
Differential Revision: https://reviews.freebsd.org/D9930
2018-04-08 19:24:49 +00:00
|
|
|
logical_cpus *= cores;
|
2014-08-24 01:10:06 +00:00
|
|
|
regs[0] |= (logical_cpus - 1) << 14;
|
|
|
|
}
|
2011-05-13 04:54:01 +00:00
|
|
|
break;
|
|
|
|
|
2012-11-20 06:01:03 +00:00
|
|
|
case CPUID_0000_0007:
|
2013-10-16 18:20:27 +00:00
|
|
|
regs[0] = 0;
|
|
|
|
regs[1] = 0;
|
|
|
|
regs[2] = 0;
|
|
|
|
regs[3] = 0;
|
|
|
|
|
|
|
|
/* leaf 0 */
|
|
|
|
if (*ecx == 0) {
|
2014-05-27 19:04:38 +00:00
|
|
|
cpuid_count(*eax, *ecx, regs);
|
|
|
|
|
|
|
|
/* Only leaf 0 is supported */
|
|
|
|
regs[0] = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Expose known-safe features.
|
|
|
|
*/
|
|
|
|
regs[1] &= (CPUID_STDEXT_FSGSBASE |
|
|
|
|
CPUID_STDEXT_BMI1 | CPUID_STDEXT_HLE |
|
|
|
|
CPUID_STDEXT_AVX2 | CPUID_STDEXT_BMI2 |
|
|
|
|
CPUID_STDEXT_ERMS | CPUID_STDEXT_RTM |
|
|
|
|
CPUID_STDEXT_AVX512F |
|
|
|
|
CPUID_STDEXT_AVX512PF |
|
|
|
|
CPUID_STDEXT_AVX512ER |
|
|
|
|
CPUID_STDEXT_AVX512CD);
|
|
|
|
regs[2] = 0;
|
|
|
|
regs[3] = 0;
|
|
|
|
|
|
|
|
/* Advertise INVPCID if it is enabled. */
|
2013-10-16 18:20:27 +00:00
|
|
|
error = vm_get_capability(vm, vcpu_id,
|
|
|
|
VM_CAP_ENABLE_INVPCID, &enable_invpcid);
|
|
|
|
if (error == 0 && enable_invpcid)
|
|
|
|
regs[1] |= CPUID_STDEXT_INVPCID;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CPUID_0000_0006:
|
2015-03-16 11:57:03 +00:00
|
|
|
regs[0] = CPUTPM1_ARAT;
|
|
|
|
regs[1] = 0;
|
|
|
|
regs[2] = 0;
|
|
|
|
regs[3] = 0;
|
|
|
|
break;
|
|
|
|
|
2013-06-28 06:05:33 +00:00
|
|
|
case CPUID_0000_000A:
|
2011-05-19 21:53:25 +00:00
|
|
|
/*
|
|
|
|
* Handle the access, but report 0 for
|
|
|
|
* all options
|
|
|
|
*/
|
|
|
|
regs[0] = 0;
|
|
|
|
regs[1] = 0;
|
|
|
|
regs[2] = 0;
|
|
|
|
regs[3] = 0;
|
|
|
|
break;
|
|
|
|
|
2011-05-13 04:54:01 +00:00
|
|
|
case CPUID_0000_000B:
|
|
|
|
/*
|
|
|
|
* Processor topology enumeration
|
|
|
|
*/
|
Add the ability to control the CPU topology of created VMs
from userland without the need to use sysctls, it allows the old
sysctls to continue to function, but deprecates them at
FreeBSD_version 1200060 (Relnotes for deprecate).
The command line of bhyve is maintained in a backwards compatible way.
The API of libvmmapi is maintained in a backwards compatible way.
The sysctl's are maintained in a backwards compatible way.
Added command option looks like:
bhyve -c [[cpus=]n][,sockets=n][,cores=n][,threads=n][,maxcpus=n]
The optional parts can be specified in any order, but only a single
integer invokes the backwards compatible parse. [,maxcpus=n] is
hidden by #ifdef until kernel support is added, though the api
is put in place.
bhyvectl --get-cpu-topology option added.
Reviewed by: grehan (maintainer, earlier version),
Reviewed by: bcr (manpages)
Approved by: bde (mentor), phk (mentor)
Tested by: Oleg Ginzburg <olevole@olevole.ru> (cbsd)
MFC after: 1 week
Relnotes: Y
Differential Revision: https://reviews.freebsd.org/D9930
2018-04-08 19:24:49 +00:00
|
|
|
vm_get_topology(vm, &sockets, &cores, &threads,
|
|
|
|
&maxcpus);
|
2014-08-24 01:10:06 +00:00
|
|
|
if (*ecx == 0) {
|
Add the ability to control the CPU topology of created VMs
from userland without the need to use sysctls, it allows the old
sysctls to continue to function, but deprecates them at
FreeBSD_version 1200060 (Relnotes for deprecate).
The command line of bhyve is maintained in a backwards compatible way.
The API of libvmmapi is maintained in a backwards compatible way.
The sysctl's are maintained in a backwards compatible way.
Added command option looks like:
bhyve -c [[cpus=]n][,sockets=n][,cores=n][,threads=n][,maxcpus=n]
The optional parts can be specified in any order, but only a single
integer invokes the backwards compatible parse. [,maxcpus=n] is
hidden by #ifdef until kernel support is added, though the api
is put in place.
bhyvectl --get-cpu-topology option added.
Reviewed by: grehan (maintainer, earlier version),
Reviewed by: bcr (manpages)
Approved by: bde (mentor), phk (mentor)
Tested by: Oleg Ginzburg <olevole@olevole.ru> (cbsd)
MFC after: 1 week
Relnotes: Y
Differential Revision: https://reviews.freebsd.org/D9930
2018-04-08 19:24:49 +00:00
|
|
|
logical_cpus = threads;
|
2014-08-24 01:10:06 +00:00
|
|
|
width = log2(logical_cpus);
|
|
|
|
level = CPUID_TYPE_SMT;
|
|
|
|
x2apic_id = vcpu_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*ecx == 1) {
|
Add the ability to control the CPU topology of created VMs
from userland without the need to use sysctls, it allows the old
sysctls to continue to function, but deprecates them at
FreeBSD_version 1200060 (Relnotes for deprecate).
The command line of bhyve is maintained in a backwards compatible way.
The API of libvmmapi is maintained in a backwards compatible way.
The sysctl's are maintained in a backwards compatible way.
Added command option looks like:
bhyve -c [[cpus=]n][,sockets=n][,cores=n][,threads=n][,maxcpus=n]
The optional parts can be specified in any order, but only a single
integer invokes the backwards compatible parse. [,maxcpus=n] is
hidden by #ifdef until kernel support is added, though the api
is put in place.
bhyvectl --get-cpu-topology option added.
Reviewed by: grehan (maintainer, earlier version),
Reviewed by: bcr (manpages)
Approved by: bde (mentor), phk (mentor)
Tested by: Oleg Ginzburg <olevole@olevole.ru> (cbsd)
MFC after: 1 week
Relnotes: Y
Differential Revision: https://reviews.freebsd.org/D9930
2018-04-08 19:24:49 +00:00
|
|
|
logical_cpus = threads * cores;
|
2014-08-24 01:10:06 +00:00
|
|
|
width = log2(logical_cpus);
|
|
|
|
level = CPUID_TYPE_CORE;
|
|
|
|
x2apic_id = vcpu_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cpuid_leaf_b || *ecx >= 2) {
|
|
|
|
width = 0;
|
|
|
|
logical_cpus = 0;
|
|
|
|
level = 0;
|
|
|
|
x2apic_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
regs[0] = width & 0x1f;
|
|
|
|
regs[1] = logical_cpus & 0xffff;
|
|
|
|
regs[2] = (level << 8) | (*ecx & 0xff);
|
|
|
|
regs[3] = x2apic_id;
|
2011-05-13 04:54:01 +00:00
|
|
|
break;
|
|
|
|
|
2014-02-08 16:37:54 +00:00
|
|
|
case CPUID_0000_000D:
|
|
|
|
limits = vmm_get_xsave_limits();
|
|
|
|
if (!limits->xsave_enabled) {
|
|
|
|
regs[0] = 0;
|
|
|
|
regs[1] = 0;
|
|
|
|
regs[2] = 0;
|
|
|
|
regs[3] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cpuid_count(*eax, *ecx, regs);
|
|
|
|
switch (*ecx) {
|
|
|
|
case 0:
|
|
|
|
/*
|
|
|
|
* Only permit the guest to use bits
|
|
|
|
* that are active in the host in
|
|
|
|
* %xcr0. Also, claim that the
|
|
|
|
* maximum save area size is
|
|
|
|
* equivalent to the host's current
|
|
|
|
* save area size. Since this runs
|
|
|
|
* "inside" of vmrun(), it runs with
|
|
|
|
* the guest's xcr0, so the current
|
|
|
|
* save area size is correct as-is.
|
|
|
|
*/
|
|
|
|
regs[0] &= limits->xcr0_allowed;
|
|
|
|
regs[2] = limits->xsave_max_size;
|
|
|
|
regs[3] &= (limits->xcr0_allowed >> 32);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
/* Only permit XSAVEOPT. */
|
|
|
|
regs[0] &= CPUID_EXTSTATE_XSAVEOPT;
|
|
|
|
regs[1] = 0;
|
|
|
|
regs[2] = 0;
|
|
|
|
regs[3] = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* If the leaf is for a permitted feature,
|
|
|
|
* pass through as-is, otherwise return
|
|
|
|
* all zeroes.
|
|
|
|
*/
|
|
|
|
if (!(limits->xcr0_allowed & (1ul << *ecx))) {
|
|
|
|
regs[0] = 0;
|
|
|
|
regs[1] = 0;
|
|
|
|
regs[2] = 0;
|
|
|
|
regs[3] = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-06-02 14:04:07 +00:00
|
|
|
case 0x40000000:
|
|
|
|
regs[0] = CPUID_VM_HIGH;
|
|
|
|
bcopy(bhyve_id, ®s[1], 4);
|
2013-06-28 06:05:33 +00:00
|
|
|
bcopy(bhyve_id + 4, ®s[2], 4);
|
|
|
|
bcopy(bhyve_id + 8, ®s[3], 4);
|
2011-06-02 14:04:07 +00:00
|
|
|
break;
|
2013-06-28 06:05:33 +00:00
|
|
|
|
2011-05-13 04:54:01 +00:00
|
|
|
default:
|
2013-06-28 06:05:33 +00:00
|
|
|
/*
|
|
|
|
* 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;
|
2011-05-13 04:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*eax = regs[0];
|
|
|
|
*ebx = regs[1];
|
|
|
|
*ecx = regs[2];
|
|
|
|
*edx = regs[3];
|
2013-06-28 06:05:33 +00:00
|
|
|
|
2011-05-13 04:54:01 +00:00
|
|
|
return (1);
|
|
|
|
}
|
2015-05-06 05:40:20 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
vm_cpuid_capability(struct vm *vm, int vcpuid, enum vm_cpuid_capability cap)
|
|
|
|
{
|
|
|
|
bool rv;
|
|
|
|
|
|
|
|
KASSERT(cap > 0 && cap < VCC_LAST, ("%s: invalid vm_cpu_capability %d",
|
|
|
|
__func__, cap));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simply passthrough the capabilities of the host cpu for now.
|
|
|
|
*/
|
|
|
|
rv = false;
|
|
|
|
switch (cap) {
|
|
|
|
case VCC_NO_EXECUTE:
|
|
|
|
if (amd_feature & AMDID_NX)
|
|
|
|
rv = true;
|
|
|
|
break;
|
|
|
|
case VCC_FFXSR:
|
|
|
|
if (amd_feature & AMDID_FFXSR)
|
|
|
|
rv = true;
|
|
|
|
break;
|
|
|
|
case VCC_TCE:
|
|
|
|
if (amd_feature2 & AMDID2_TCE)
|
|
|
|
rv = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic("%s: unknown vm_cpu_capability %d", __func__, cap);
|
|
|
|
}
|
|
|
|
return (rv);
|
|
|
|
}
|