Add accessor function for vm->maxcpus
Replace most VM_MAXCPU constant useses with an accessor function to vm->maxcpus which for now is initialized and kept at the value of VM_MAXCPUS. This is a rework of Fabian Freyer (fabian.freyer_physik.tu-berlin.de) work from D10070 to adjust it for the cpu topology changes that occured in r332298 Submitted by: Fabian Freyer (fabian.freyer_physik.tu-berlin.de) Reviewed by: Patrick Mooney <patrick.mooney@joyent.com> Approved by: bde (mentor), jhb (maintainer) MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D18755
This commit is contained in:
parent
20105d31ee
commit
a488c9c99a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=346714
@ -186,6 +186,7 @@ int vm_create(const char *name, struct vm **retvm);
|
||||
void vm_destroy(struct vm *vm);
|
||||
int vm_reinit(struct vm *vm);
|
||||
const char *vm_name(struct vm *vm);
|
||||
uint16_t vm_get_maxcpus(struct vm *vm);
|
||||
void vm_get_topology(struct vm *vm, uint16_t *sockets, uint16_t *cores,
|
||||
uint16_t *threads, uint16_t *maxcpus);
|
||||
int vm_set_topology(struct vm *vm, uint16_t sockets, uint16_t cores,
|
||||
|
@ -524,6 +524,7 @@ svm_vminit(struct vm *vm, pmap_t pmap)
|
||||
struct svm_vcpu *vcpu;
|
||||
vm_paddr_t msrpm_pa, iopm_pa, pml4_pa;
|
||||
int i;
|
||||
uint16_t maxcpus;
|
||||
|
||||
svm_sc = malloc(sizeof (*svm_sc), M_SVM, M_WAITOK | M_ZERO);
|
||||
if (((uintptr_t)svm_sc & PAGE_MASK) != 0)
|
||||
@ -577,7 +578,8 @@ svm_vminit(struct vm *vm, pmap_t pmap)
|
||||
iopm_pa = vtophys(svm_sc->iopm_bitmap);
|
||||
msrpm_pa = vtophys(svm_sc->msr_bitmap);
|
||||
pml4_pa = svm_sc->nptp;
|
||||
for (i = 0; i < VM_MAXCPU; i++) {
|
||||
maxcpus = vm_get_maxcpus(svm_sc->vm);
|
||||
for (i = 0; i < maxcpus; i++) {
|
||||
vcpu = svm_get_vcpu(svm_sc, i);
|
||||
vcpu->nextrip = ~0;
|
||||
vcpu->lastcpu = NOCPU;
|
||||
|
@ -943,6 +943,7 @@ vmx_vminit(struct vm *vm, pmap_t pmap)
|
||||
struct vmx *vmx;
|
||||
struct vmcs *vmcs;
|
||||
uint32_t exc_bitmap;
|
||||
uint16_t maxcpus;
|
||||
|
||||
vmx = malloc(sizeof(struct vmx), M_VMX, M_WAITOK | M_ZERO);
|
||||
if ((uintptr_t)vmx & PAGE_MASK) {
|
||||
@ -1004,7 +1005,8 @@ vmx_vminit(struct vm *vm, pmap_t pmap)
|
||||
KASSERT(error == 0, ("vm_map_mmio(apicbase) error %d", error));
|
||||
}
|
||||
|
||||
for (i = 0; i < VM_MAXCPU; i++) {
|
||||
maxcpus = vm_get_maxcpus(vm);
|
||||
for (i = 0; i < maxcpus; i++) {
|
||||
vmcs = &vmx->vmcs[i];
|
||||
vmcs->identifier = vmx_revision();
|
||||
error = vmclear(vmcs);
|
||||
@ -3002,11 +3004,13 @@ vmx_vmcleanup(void *arg)
|
||||
{
|
||||
int i;
|
||||
struct vmx *vmx = arg;
|
||||
uint16_t maxcpus;
|
||||
|
||||
if (apic_access_virtualization(vmx, 0))
|
||||
vm_unmap_mmio(vmx->vm, DEFAULT_APIC_BASE, PAGE_SIZE);
|
||||
|
||||
for (i = 0; i < VM_MAXCPU; i++)
|
||||
maxcpus = vm_get_maxcpus(vmx->vm);
|
||||
for (i = 0; i < maxcpus; i++)
|
||||
vpid_free(vmx->state[i].vpid);
|
||||
|
||||
free(vmx, M_VMX);
|
||||
|
@ -838,7 +838,7 @@ vlapic_calcdest(struct vm *vm, cpuset_t *dmask, uint32_t dest, bool phys,
|
||||
*/
|
||||
CPU_ZERO(dmask);
|
||||
vcpuid = vm_apicid2vcpuid(vm, dest);
|
||||
if (vcpuid < VM_MAXCPU)
|
||||
if (vcpuid < vm_get_maxcpus(vm))
|
||||
CPU_SET(vcpuid, dmask);
|
||||
} else {
|
||||
/*
|
||||
@ -965,6 +965,7 @@ vlapic_icrlo_write_handler(struct vlapic *vlapic, bool *retu)
|
||||
struct vlapic *vlapic2;
|
||||
struct vm_exit *vmexit;
|
||||
struct LAPIC *lapic;
|
||||
uint16_t maxcpus;
|
||||
|
||||
lapic = vlapic->apic_page;
|
||||
lapic->icr_lo &= ~APIC_DELSTAT_PEND;
|
||||
@ -1026,11 +1027,12 @@ vlapic_icrlo_write_handler(struct vlapic *vlapic, bool *retu)
|
||||
return (0); /* handled completely in the kernel */
|
||||
}
|
||||
|
||||
maxcpus = vm_get_maxcpus(vlapic->vm);
|
||||
if (mode == APIC_DELMODE_INIT) {
|
||||
if ((icrval & APIC_LEVEL_MASK) == APIC_LEVEL_DEASSERT)
|
||||
return (0);
|
||||
|
||||
if (vlapic->vcpuid == 0 && dest != 0 && dest < VM_MAXCPU) {
|
||||
if (vlapic->vcpuid == 0 && dest != 0 && dest < maxcpus) {
|
||||
vlapic2 = vm_lapic(vlapic->vm, dest);
|
||||
|
||||
/* move from INIT to waiting-for-SIPI state */
|
||||
@ -1043,7 +1045,7 @@ vlapic_icrlo_write_handler(struct vlapic *vlapic, bool *retu)
|
||||
}
|
||||
|
||||
if (mode == APIC_DELMODE_STARTUP) {
|
||||
if (vlapic->vcpuid == 0 && dest != 0 && dest < VM_MAXCPU) {
|
||||
if (vlapic->vcpuid == 0 && dest != 0 && dest < maxcpus) {
|
||||
vlapic2 = vm_lapic(vlapic->vm, dest);
|
||||
|
||||
/*
|
||||
@ -1447,7 +1449,8 @@ void
|
||||
vlapic_init(struct vlapic *vlapic)
|
||||
{
|
||||
KASSERT(vlapic->vm != NULL, ("vlapic_init: vm is not initialized"));
|
||||
KASSERT(vlapic->vcpuid >= 0 && vlapic->vcpuid < VM_MAXCPU,
|
||||
KASSERT(vlapic->vcpuid >= 0 &&
|
||||
vlapic->vcpuid < vm_get_maxcpus(vlapic->vm),
|
||||
("vlapic_init: vcpuid is not initialized"));
|
||||
KASSERT(vlapic->apic_page != NULL, ("vlapic_init: apic_page is not "
|
||||
"initialized"));
|
||||
|
@ -276,7 +276,7 @@ vcpu_init(struct vm *vm, int vcpu_id, bool create)
|
||||
{
|
||||
struct vcpu *vcpu;
|
||||
|
||||
KASSERT(vcpu_id >= 0 && vcpu_id < VM_MAXCPU,
|
||||
KASSERT(vcpu_id >= 0 && vcpu_id < vm->maxcpus,
|
||||
("vcpu_init: invalid vcpu %d", vcpu_id));
|
||||
|
||||
vcpu = &vm->vcpu[vcpu_id];
|
||||
@ -315,7 +315,7 @@ vm_exitinfo(struct vm *vm, int cpuid)
|
||||
{
|
||||
struct vcpu *vcpu;
|
||||
|
||||
if (cpuid < 0 || cpuid >= VM_MAXCPU)
|
||||
if (cpuid < 0 || cpuid >= vm->maxcpus)
|
||||
panic("vm_exitinfo: invalid cpuid %d", cpuid);
|
||||
|
||||
vcpu = &vm->vcpu[cpuid];
|
||||
@ -428,7 +428,7 @@ vm_init(struct vm *vm, bool create)
|
||||
vm->suspend = 0;
|
||||
CPU_ZERO(&vm->suspended_cpus);
|
||||
|
||||
for (i = 0; i < VM_MAXCPU; i++)
|
||||
for (i = 0; i < vm->maxcpus; i++)
|
||||
vcpu_init(vm, i, create);
|
||||
}
|
||||
|
||||
@ -466,7 +466,7 @@ vm_create(const char *name, struct vm **retvm)
|
||||
vm->sockets = 1;
|
||||
vm->cores = cores_per_package; /* XXX backwards compatibility */
|
||||
vm->threads = threads_per_core; /* XXX backwards compatibility */
|
||||
vm->maxcpus = 0; /* XXX not implemented */
|
||||
vm->maxcpus = VM_MAXCPU; /* XXX temp to keep code working */
|
||||
|
||||
vm_init(vm, true);
|
||||
|
||||
@ -484,19 +484,25 @@ vm_get_topology(struct vm *vm, uint16_t *sockets, uint16_t *cores,
|
||||
*maxcpus = vm->maxcpus;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
vm_get_maxcpus(struct vm *vm)
|
||||
{
|
||||
return (vm->maxcpus);
|
||||
}
|
||||
|
||||
int
|
||||
vm_set_topology(struct vm *vm, uint16_t sockets, uint16_t cores,
|
||||
uint16_t threads, uint16_t maxcpus)
|
||||
{
|
||||
if (maxcpus != 0)
|
||||
return (EINVAL); /* XXX remove when supported */
|
||||
if ((sockets * cores * threads) > VM_MAXCPU)
|
||||
if ((sockets * cores * threads) > vm->maxcpus)
|
||||
return (EINVAL);
|
||||
/* XXX need to check sockets * cores * threads == vCPU, how? */
|
||||
vm->sockets = sockets;
|
||||
vm->cores = cores;
|
||||
vm->threads = threads;
|
||||
vm->maxcpus = maxcpus;
|
||||
vm->maxcpus = VM_MAXCPU; /* XXX temp to keep code working */
|
||||
return(0);
|
||||
}
|
||||
|
||||
@ -521,7 +527,7 @@ vm_cleanup(struct vm *vm, bool destroy)
|
||||
vatpic_cleanup(vm->vatpic);
|
||||
vioapic_cleanup(vm->vioapic);
|
||||
|
||||
for (i = 0; i < VM_MAXCPU; i++)
|
||||
for (i = 0; i < vm->maxcpus; i++)
|
||||
vcpu_cleanup(vm, i, destroy);
|
||||
|
||||
VMCLEANUP(vm->cookie);
|
||||
@ -956,9 +962,9 @@ vm_gpa_hold(struct vm *vm, int vcpuid, vm_paddr_t gpa, size_t len, int reqprot,
|
||||
* guaranteed if at least one vcpu is in the VCPU_FROZEN state.
|
||||
*/
|
||||
int state;
|
||||
KASSERT(vcpuid >= -1 && vcpuid < VM_MAXCPU, ("%s: invalid vcpuid %d",
|
||||
KASSERT(vcpuid >= -1 && vcpuid < vm->maxcpus, ("%s: invalid vcpuid %d",
|
||||
__func__, vcpuid));
|
||||
for (i = 0; i < VM_MAXCPU; i++) {
|
||||
for (i = 0; i < vm->maxcpus; i++) {
|
||||
if (vcpuid != -1 && vcpuid != i)
|
||||
continue;
|
||||
state = vcpu_get_state(vm, i, NULL);
|
||||
@ -1004,7 +1010,7 @@ int
|
||||
vm_get_register(struct vm *vm, int vcpu, int reg, uint64_t *retval)
|
||||
{
|
||||
|
||||
if (vcpu < 0 || vcpu >= VM_MAXCPU)
|
||||
if (vcpu < 0 || vcpu >= vm->maxcpus)
|
||||
return (EINVAL);
|
||||
|
||||
if (reg >= VM_REG_LAST)
|
||||
@ -1019,7 +1025,7 @@ vm_set_register(struct vm *vm, int vcpuid, int reg, uint64_t val)
|
||||
struct vcpu *vcpu;
|
||||
int error;
|
||||
|
||||
if (vcpuid < 0 || vcpuid >= VM_MAXCPU)
|
||||
if (vcpuid < 0 || vcpuid >= vm->maxcpus)
|
||||
return (EINVAL);
|
||||
|
||||
if (reg >= VM_REG_LAST)
|
||||
@ -1073,7 +1079,7 @@ vm_get_seg_desc(struct vm *vm, int vcpu, int reg,
|
||||
struct seg_desc *desc)
|
||||
{
|
||||
|
||||
if (vcpu < 0 || vcpu >= VM_MAXCPU)
|
||||
if (vcpu < 0 || vcpu >= vm->maxcpus)
|
||||
return (EINVAL);
|
||||
|
||||
if (!is_segment_register(reg) && !is_descriptor_table(reg))
|
||||
@ -1086,7 +1092,7 @@ int
|
||||
vm_set_seg_desc(struct vm *vm, int vcpu, int reg,
|
||||
struct seg_desc *desc)
|
||||
{
|
||||
if (vcpu < 0 || vcpu >= VM_MAXCPU)
|
||||
if (vcpu < 0 || vcpu >= vm->maxcpus)
|
||||
return (EINVAL);
|
||||
|
||||
if (!is_segment_register(reg) && !is_descriptor_table(reg))
|
||||
@ -1258,7 +1264,7 @@ static void
|
||||
vm_handle_rendezvous(struct vm *vm, int vcpuid)
|
||||
{
|
||||
|
||||
KASSERT(vcpuid == -1 || (vcpuid >= 0 && vcpuid < VM_MAXCPU),
|
||||
KASSERT(vcpuid == -1 || (vcpuid >= 0 && vcpuid < vm->maxcpus),
|
||||
("vm_handle_rendezvous: invalid vcpuid %d", vcpuid));
|
||||
|
||||
mtx_lock(&vm->rendezvous_mtx);
|
||||
@ -1537,7 +1543,7 @@ vm_handle_suspend(struct vm *vm, int vcpuid, bool *retu)
|
||||
/*
|
||||
* Wakeup the other sleeping vcpus and return to userspace.
|
||||
*/
|
||||
for (i = 0; i < VM_MAXCPU; i++) {
|
||||
for (i = 0; i < vm->maxcpus; i++) {
|
||||
if (CPU_ISSET(i, &vm->suspended_cpus)) {
|
||||
vcpu_notify_event(vm, i, false);
|
||||
}
|
||||
@ -1579,7 +1585,7 @@ vm_suspend(struct vm *vm, enum vm_suspend_how how)
|
||||
/*
|
||||
* Notify all active vcpus that they are now suspended.
|
||||
*/
|
||||
for (i = 0; i < VM_MAXCPU; i++) {
|
||||
for (i = 0; i < vm->maxcpus; i++) {
|
||||
if (CPU_ISSET(i, &vm->active_cpus))
|
||||
vcpu_notify_event(vm, i, false);
|
||||
}
|
||||
@ -1665,7 +1671,7 @@ vm_run(struct vm *vm, struct vm_run *vmrun)
|
||||
|
||||
vcpuid = vmrun->cpuid;
|
||||
|
||||
if (vcpuid < 0 || vcpuid >= VM_MAXCPU)
|
||||
if (vcpuid < 0 || vcpuid >= vm->maxcpus)
|
||||
return (EINVAL);
|
||||
|
||||
if (!CPU_ISSET(vcpuid, &vm->active_cpus))
|
||||
@ -1766,7 +1772,7 @@ vm_restart_instruction(void *arg, int vcpuid)
|
||||
int error;
|
||||
|
||||
vm = arg;
|
||||
if (vcpuid < 0 || vcpuid >= VM_MAXCPU)
|
||||
if (vcpuid < 0 || vcpuid >= vm->maxcpus)
|
||||
return (EINVAL);
|
||||
|
||||
vcpu = &vm->vcpu[vcpuid];
|
||||
@ -1805,7 +1811,7 @@ vm_exit_intinfo(struct vm *vm, int vcpuid, uint64_t info)
|
||||
struct vcpu *vcpu;
|
||||
int type, vector;
|
||||
|
||||
if (vcpuid < 0 || vcpuid >= VM_MAXCPU)
|
||||
if (vcpuid < 0 || vcpuid >= vm->maxcpus)
|
||||
return (EINVAL);
|
||||
|
||||
vcpu = &vm->vcpu[vcpuid];
|
||||
@ -1946,7 +1952,8 @@ vm_entry_intinfo(struct vm *vm, int vcpuid, uint64_t *retinfo)
|
||||
uint64_t info1, info2;
|
||||
int valid;
|
||||
|
||||
KASSERT(vcpuid >= 0 && vcpuid < VM_MAXCPU, ("invalid vcpu %d", vcpuid));
|
||||
KASSERT(vcpuid >= 0 &&
|
||||
vcpuid < vm->maxcpus, ("invalid vcpu %d", vcpuid));
|
||||
|
||||
vcpu = &vm->vcpu[vcpuid];
|
||||
|
||||
@ -1986,7 +1993,7 @@ vm_get_intinfo(struct vm *vm, int vcpuid, uint64_t *info1, uint64_t *info2)
|
||||
{
|
||||
struct vcpu *vcpu;
|
||||
|
||||
if (vcpuid < 0 || vcpuid >= VM_MAXCPU)
|
||||
if (vcpuid < 0 || vcpuid >= vm->maxcpus)
|
||||
return (EINVAL);
|
||||
|
||||
vcpu = &vm->vcpu[vcpuid];
|
||||
@ -2003,7 +2010,7 @@ vm_inject_exception(struct vm *vm, int vcpuid, int vector, int errcode_valid,
|
||||
uint64_t regval;
|
||||
int error;
|
||||
|
||||
if (vcpuid < 0 || vcpuid >= VM_MAXCPU)
|
||||
if (vcpuid < 0 || vcpuid >= vm->maxcpus)
|
||||
return (EINVAL);
|
||||
|
||||
if (vector < 0 || vector >= 32)
|
||||
@ -2094,7 +2101,7 @@ vm_inject_nmi(struct vm *vm, int vcpuid)
|
||||
{
|
||||
struct vcpu *vcpu;
|
||||
|
||||
if (vcpuid < 0 || vcpuid >= VM_MAXCPU)
|
||||
if (vcpuid < 0 || vcpuid >= vm->maxcpus)
|
||||
return (EINVAL);
|
||||
|
||||
vcpu = &vm->vcpu[vcpuid];
|
||||
@ -2109,7 +2116,7 @@ vm_nmi_pending(struct vm *vm, int vcpuid)
|
||||
{
|
||||
struct vcpu *vcpu;
|
||||
|
||||
if (vcpuid < 0 || vcpuid >= VM_MAXCPU)
|
||||
if (vcpuid < 0 || vcpuid >= vm->maxcpus)
|
||||
panic("vm_nmi_pending: invalid vcpuid %d", vcpuid);
|
||||
|
||||
vcpu = &vm->vcpu[vcpuid];
|
||||
@ -2122,7 +2129,7 @@ vm_nmi_clear(struct vm *vm, int vcpuid)
|
||||
{
|
||||
struct vcpu *vcpu;
|
||||
|
||||
if (vcpuid < 0 || vcpuid >= VM_MAXCPU)
|
||||
if (vcpuid < 0 || vcpuid >= vm->maxcpus)
|
||||
panic("vm_nmi_pending: invalid vcpuid %d", vcpuid);
|
||||
|
||||
vcpu = &vm->vcpu[vcpuid];
|
||||
@ -2141,7 +2148,7 @@ vm_inject_extint(struct vm *vm, int vcpuid)
|
||||
{
|
||||
struct vcpu *vcpu;
|
||||
|
||||
if (vcpuid < 0 || vcpuid >= VM_MAXCPU)
|
||||
if (vcpuid < 0 || vcpuid >= vm->maxcpus)
|
||||
return (EINVAL);
|
||||
|
||||
vcpu = &vm->vcpu[vcpuid];
|
||||
@ -2156,7 +2163,7 @@ vm_extint_pending(struct vm *vm, int vcpuid)
|
||||
{
|
||||
struct vcpu *vcpu;
|
||||
|
||||
if (vcpuid < 0 || vcpuid >= VM_MAXCPU)
|
||||
if (vcpuid < 0 || vcpuid >= vm->maxcpus)
|
||||
panic("vm_extint_pending: invalid vcpuid %d", vcpuid);
|
||||
|
||||
vcpu = &vm->vcpu[vcpuid];
|
||||
@ -2169,7 +2176,7 @@ vm_extint_clear(struct vm *vm, int vcpuid)
|
||||
{
|
||||
struct vcpu *vcpu;
|
||||
|
||||
if (vcpuid < 0 || vcpuid >= VM_MAXCPU)
|
||||
if (vcpuid < 0 || vcpuid >= vm->maxcpus)
|
||||
panic("vm_extint_pending: invalid vcpuid %d", vcpuid);
|
||||
|
||||
vcpu = &vm->vcpu[vcpuid];
|
||||
@ -2184,7 +2191,7 @@ vm_extint_clear(struct vm *vm, int vcpuid)
|
||||
int
|
||||
vm_get_capability(struct vm *vm, int vcpu, int type, int *retval)
|
||||
{
|
||||
if (vcpu < 0 || vcpu >= VM_MAXCPU)
|
||||
if (vcpu < 0 || vcpu >= vm->maxcpus)
|
||||
return (EINVAL);
|
||||
|
||||
if (type < 0 || type >= VM_CAP_MAX)
|
||||
@ -2196,7 +2203,7 @@ vm_get_capability(struct vm *vm, int vcpu, int type, int *retval)
|
||||
int
|
||||
vm_set_capability(struct vm *vm, int vcpu, int type, int val)
|
||||
{
|
||||
if (vcpu < 0 || vcpu >= VM_MAXCPU)
|
||||
if (vcpu < 0 || vcpu >= vm->maxcpus)
|
||||
return (EINVAL);
|
||||
|
||||
if (type < 0 || type >= VM_CAP_MAX)
|
||||
@ -2281,7 +2288,7 @@ vcpu_set_state(struct vm *vm, int vcpuid, enum vcpu_state newstate,
|
||||
int error;
|
||||
struct vcpu *vcpu;
|
||||
|
||||
if (vcpuid < 0 || vcpuid >= VM_MAXCPU)
|
||||
if (vcpuid < 0 || vcpuid >= vm->maxcpus)
|
||||
panic("vm_set_run_state: invalid vcpuid %d", vcpuid);
|
||||
|
||||
vcpu = &vm->vcpu[vcpuid];
|
||||
@ -2299,7 +2306,7 @@ vcpu_get_state(struct vm *vm, int vcpuid, int *hostcpu)
|
||||
struct vcpu *vcpu;
|
||||
enum vcpu_state state;
|
||||
|
||||
if (vcpuid < 0 || vcpuid >= VM_MAXCPU)
|
||||
if (vcpuid < 0 || vcpuid >= vm->maxcpus)
|
||||
panic("vm_get_run_state: invalid vcpuid %d", vcpuid);
|
||||
|
||||
vcpu = &vm->vcpu[vcpuid];
|
||||
@ -2317,7 +2324,7 @@ int
|
||||
vm_activate_cpu(struct vm *vm, int vcpuid)
|
||||
{
|
||||
|
||||
if (vcpuid < 0 || vcpuid >= VM_MAXCPU)
|
||||
if (vcpuid < 0 || vcpuid >= vm->maxcpus)
|
||||
return (EINVAL);
|
||||
|
||||
if (CPU_ISSET(vcpuid, &vm->active_cpus))
|
||||
@ -2333,12 +2340,12 @@ vm_suspend_cpu(struct vm *vm, int vcpuid)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (vcpuid < -1 || vcpuid >= VM_MAXCPU)
|
||||
if (vcpuid < -1 || vcpuid >= vm->maxcpus)
|
||||
return (EINVAL);
|
||||
|
||||
if (vcpuid == -1) {
|
||||
vm->debug_cpus = vm->active_cpus;
|
||||
for (i = 0; i < VM_MAXCPU; i++) {
|
||||
for (i = 0; i < vm->maxcpus; i++) {
|
||||
if (CPU_ISSET(i, &vm->active_cpus))
|
||||
vcpu_notify_event(vm, i, false);
|
||||
}
|
||||
@ -2356,7 +2363,7 @@ int
|
||||
vm_resume_cpu(struct vm *vm, int vcpuid)
|
||||
{
|
||||
|
||||
if (vcpuid < -1 || vcpuid >= VM_MAXCPU)
|
||||
if (vcpuid < -1 || vcpuid >= vm->maxcpus)
|
||||
return (EINVAL);
|
||||
|
||||
if (vcpuid == -1) {
|
||||
@ -2408,7 +2415,7 @@ vcpu_stats(struct vm *vm, int vcpuid)
|
||||
int
|
||||
vm_get_x2apic_state(struct vm *vm, int vcpuid, enum x2apic_state *state)
|
||||
{
|
||||
if (vcpuid < 0 || vcpuid >= VM_MAXCPU)
|
||||
if (vcpuid < 0 || vcpuid >= vm->maxcpus)
|
||||
return (EINVAL);
|
||||
|
||||
*state = vm->vcpu[vcpuid].x2apic_state;
|
||||
@ -2419,7 +2426,7 @@ vm_get_x2apic_state(struct vm *vm, int vcpuid, enum x2apic_state *state)
|
||||
int
|
||||
vm_set_x2apic_state(struct vm *vm, int vcpuid, enum x2apic_state state)
|
||||
{
|
||||
if (vcpuid < 0 || vcpuid >= VM_MAXCPU)
|
||||
if (vcpuid < 0 || vcpuid >= vm->maxcpus)
|
||||
return (EINVAL);
|
||||
|
||||
if (state >= X2APIC_STATE_LAST)
|
||||
@ -2506,7 +2513,7 @@ vm_smp_rendezvous(struct vm *vm, int vcpuid, cpuset_t dest,
|
||||
* Enforce that this function is called without any locks
|
||||
*/
|
||||
WITNESS_WARN(WARN_PANIC, NULL, "vm_smp_rendezvous");
|
||||
KASSERT(vcpuid == -1 || (vcpuid >= 0 && vcpuid < VM_MAXCPU),
|
||||
KASSERT(vcpuid == -1 || (vcpuid >= 0 && vcpuid < vm->maxcpus),
|
||||
("vm_smp_rendezvous: invalid vcpuid %d", vcpuid));
|
||||
|
||||
restart:
|
||||
@ -2536,7 +2543,7 @@ vm_smp_rendezvous(struct vm *vm, int vcpuid, cpuset_t dest,
|
||||
* Wake up any sleeping vcpus and trigger a VM-exit in any running
|
||||
* vcpus so they handle the rendezvous as soon as possible.
|
||||
*/
|
||||
for (i = 0; i < VM_MAXCPU; i++) {
|
||||
for (i = 0; i < vm->maxcpus; i++) {
|
||||
if (CPU_ISSET(i, &dest))
|
||||
vcpu_notify_event(vm, i, false);
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ vcpu_lock_one(struct vmmdev_softc *sc, int vcpu)
|
||||
{
|
||||
int error;
|
||||
|
||||
if (vcpu < 0 || vcpu >= VM_MAXCPU)
|
||||
if (vcpu < 0 || vcpu >= vm_get_maxcpus(sc->vm))
|
||||
return (EINVAL);
|
||||
|
||||
error = vcpu_set_state(sc->vm, vcpu, VCPU_FROZEN, true);
|
||||
@ -136,8 +136,10 @@ static int
|
||||
vcpu_lock_all(struct vmmdev_softc *sc)
|
||||
{
|
||||
int error, vcpu;
|
||||
uint16_t maxcpus;
|
||||
|
||||
for (vcpu = 0; vcpu < VM_MAXCPU; vcpu++) {
|
||||
maxcpus = vm_get_maxcpus(sc->vm);
|
||||
for (vcpu = 0; vcpu < maxcpus; vcpu++) {
|
||||
error = vcpu_lock_one(sc, vcpu);
|
||||
if (error)
|
||||
break;
|
||||
@ -155,8 +157,10 @@ static void
|
||||
vcpu_unlock_all(struct vmmdev_softc *sc)
|
||||
{
|
||||
int vcpu;
|
||||
uint16_t maxcpus;
|
||||
|
||||
for (vcpu = 0; vcpu < VM_MAXCPU; vcpu++)
|
||||
maxcpus = vm_get_maxcpus(sc->vm);
|
||||
for (vcpu = 0; vcpu < maxcpus; vcpu++)
|
||||
vcpu_unlock_one(sc, vcpu);
|
||||
}
|
||||
|
||||
@ -191,6 +195,7 @@ vmmdev_rw(struct cdev *cdev, struct uio *uio, int flags)
|
||||
vm_paddr_t gpa, maxaddr;
|
||||
void *hpa, *cookie;
|
||||
struct vmmdev_softc *sc;
|
||||
uint16_t lastcpu;
|
||||
|
||||
error = vmm_priv_check(curthread->td_ucred);
|
||||
if (error)
|
||||
@ -203,7 +208,8 @@ vmmdev_rw(struct cdev *cdev, struct uio *uio, int flags)
|
||||
/*
|
||||
* Get a read lock on the guest memory map by freezing any vcpu.
|
||||
*/
|
||||
error = vcpu_lock_one(sc, VM_MAXCPU - 1);
|
||||
lastcpu = vm_get_maxcpus(sc->vm) - 1;
|
||||
error = vcpu_lock_one(sc, lastcpu);
|
||||
if (error)
|
||||
return (error);
|
||||
|
||||
@ -222,7 +228,8 @@ vmmdev_rw(struct cdev *cdev, struct uio *uio, int flags)
|
||||
* Since this device does not support lseek(2), dd(1) will
|
||||
* read(2) blocks of data to simulate the lseek(2).
|
||||
*/
|
||||
hpa = vm_gpa_hold(sc->vm, VM_MAXCPU - 1, gpa, c, prot, &cookie);
|
||||
hpa = vm_gpa_hold(sc->vm, lastcpu, gpa, c,
|
||||
prot, &cookie);
|
||||
if (hpa == NULL) {
|
||||
if (uio->uio_rw == UIO_READ && gpa < maxaddr)
|
||||
error = uiomove(__DECONST(void *, zero_region),
|
||||
@ -234,7 +241,7 @@ vmmdev_rw(struct cdev *cdev, struct uio *uio, int flags)
|
||||
vm_gpa_release(cookie);
|
||||
}
|
||||
}
|
||||
vcpu_unlock_one(sc, VM_MAXCPU - 1);
|
||||
vcpu_unlock_one(sc, lastcpu);
|
||||
return (error);
|
||||
}
|
||||
|
||||
@ -437,7 +444,7 @@ vmmdev_ioctl(struct cdev *cdev, u_long cmd, caddr_t data, int fflag,
|
||||
* Lock a vcpu to make sure that the memory map cannot be
|
||||
* modified while it is being inspected.
|
||||
*/
|
||||
vcpu = VM_MAXCPU - 1;
|
||||
vcpu = vm_get_maxcpus(sc->vm) - 1;
|
||||
error = vcpu_lock_one(sc, vcpu);
|
||||
if (error)
|
||||
goto done;
|
||||
@ -797,6 +804,7 @@ vmmdev_mmap_single(struct cdev *cdev, vm_ooffset_t *offset, vm_size_t mapsize,
|
||||
size_t len;
|
||||
vm_ooffset_t segoff, first, last;
|
||||
int error, found, segid;
|
||||
uint16_t lastcpu;
|
||||
bool sysmem;
|
||||
|
||||
error = vmm_priv_check(curthread->td_ucred);
|
||||
@ -817,7 +825,8 @@ vmmdev_mmap_single(struct cdev *cdev, vm_ooffset_t *offset, vm_size_t mapsize,
|
||||
/*
|
||||
* Get a read lock on the guest memory map by freezing any vcpu.
|
||||
*/
|
||||
error = vcpu_lock_one(sc, VM_MAXCPU - 1);
|
||||
lastcpu = vm_get_maxcpus(sc->vm) - 1;
|
||||
error = vcpu_lock_one(sc, lastcpu);
|
||||
if (error)
|
||||
return (error);
|
||||
|
||||
@ -846,7 +855,7 @@ vmmdev_mmap_single(struct cdev *cdev, vm_ooffset_t *offset, vm_size_t mapsize,
|
||||
error = EINVAL;
|
||||
}
|
||||
}
|
||||
vcpu_unlock_one(sc, VM_MAXCPU - 1);
|
||||
vcpu_unlock_one(sc, lastcpu);
|
||||
return (error);
|
||||
}
|
||||
|
||||
@ -1045,6 +1054,7 @@ devmem_mmap_single(struct cdev *cdev, vm_ooffset_t *offset, vm_size_t len,
|
||||
vm_ooffset_t first, last;
|
||||
size_t seglen;
|
||||
int error;
|
||||
uint16_t lastcpu;
|
||||
bool sysmem;
|
||||
|
||||
dsc = cdev->si_drv1;
|
||||
@ -1058,7 +1068,8 @@ devmem_mmap_single(struct cdev *cdev, vm_ooffset_t *offset, vm_size_t len,
|
||||
if ((nprot & PROT_EXEC) || first < 0 || first >= last)
|
||||
return (EINVAL);
|
||||
|
||||
error = vcpu_lock_one(dsc->sc, VM_MAXCPU - 1);
|
||||
lastcpu = vm_get_maxcpus(dsc->sc->vm) - 1;
|
||||
error = vcpu_lock_one(dsc->sc, lastcpu);
|
||||
if (error)
|
||||
return (error);
|
||||
|
||||
@ -1066,7 +1077,7 @@ devmem_mmap_single(struct cdev *cdev, vm_ooffset_t *offset, vm_size_t len,
|
||||
KASSERT(error == 0 && !sysmem && *objp != NULL,
|
||||
("%s: invalid devmem segment %d", __func__, dsc->segid));
|
||||
|
||||
vcpu_unlock_one(dsc->sc, VM_MAXCPU - 1);
|
||||
vcpu_unlock_one(dsc->sc, lastcpu);
|
||||
|
||||
if (seglen >= last) {
|
||||
vm_object_reference(*objp);
|
||||
|
@ -56,7 +56,7 @@ lapic_set_intr(struct vm *vm, int cpu, int vector, bool level)
|
||||
{
|
||||
struct vlapic *vlapic;
|
||||
|
||||
if (cpu < 0 || cpu >= VM_MAXCPU)
|
||||
if (cpu < 0 || cpu >= vm_get_maxcpus(vm))
|
||||
return (EINVAL);
|
||||
|
||||
/*
|
||||
@ -79,7 +79,7 @@ lapic_set_local_intr(struct vm *vm, int cpu, int vector)
|
||||
cpuset_t dmask;
|
||||
int error;
|
||||
|
||||
if (cpu < -1 || cpu >= VM_MAXCPU)
|
||||
if (cpu < -1 || cpu >= vm_get_maxcpus(vm))
|
||||
return (EINVAL);
|
||||
|
||||
if (cpu == -1)
|
||||
|
@ -88,7 +88,7 @@ vmm_stat_copy(struct vm *vm, int vcpu, int *num_stats, uint64_t *buf)
|
||||
uint64_t *stats;
|
||||
int i;
|
||||
|
||||
if (vcpu < 0 || vcpu >= VM_MAXCPU)
|
||||
if (vcpu < 0 || vcpu >= vm_get_maxcpus(vm))
|
||||
return (EINVAL);
|
||||
|
||||
/* Let stats functions update their counters */
|
||||
|
Loading…
Reference in New Issue
Block a user