Skip to content

Commit c46e5dc

Browse files
committed
vmm: Move vm_maxcpu handling into MI code
No functional change intended. Reviewed by: corvink MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D53477
1 parent 7214e04 commit c46e5dc

File tree

7 files changed

+27
-67
lines changed

7 files changed

+27
-67
lines changed

sys/amd64/include/vmm.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,6 @@ struct vmm_ops {
206206
extern const struct vmm_ops vmm_ops_intel;
207207
extern const struct vmm_ops vmm_ops_amd;
208208

209-
extern u_int vm_maxcpu; /* maximum virtual cpus */
210-
211209
int vm_create(const char *name, struct vm **retvm);
212210
struct vcpu *vm_alloc_vcpu(struct vm *vm, int vcpuid);
213211
void vm_disable_vcpu_creation(struct vm *vm);

sys/amd64/vmm/intel/vmx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
* SUCH DAMAGE.
2828
*/
2929

30-
#include <sys/cdefs.h>
3130
#include "opt_bhyve_snapshot.h"
3231

3332
#include <sys/param.h>
@@ -58,6 +57,7 @@
5857
#include <machine/vmm_instruction_emul.h>
5958
#include <machine/vmm_snapshot.h>
6059

60+
#include <dev/vmm/vmm_dev.h>
6161
#include <dev/vmm/vmm_ktr.h>
6262
#include <dev/vmm/vmm_mem.h>
6363

sys/amd64/vmm/vmm.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,6 @@ static int trap_wbinvd;
267267
SYSCTL_INT(_hw_vmm, OID_AUTO, trap_wbinvd, CTLFLAG_RDTUN, &trap_wbinvd, 0,
268268
"WBINVD triggers a VM-exit");
269269

270-
u_int vm_maxcpu;
271-
SYSCTL_UINT(_hw_vmm, OID_AUTO, maxcpu, CTLFLAG_RDTUN | CTLFLAG_NOFETCH,
272-
&vm_maxcpu, 0, "Maximum number of vCPUs");
273-
274270
static void vcpu_notify_event_locked(struct vcpu *vcpu);
275271

276272
/* global statistics */
@@ -296,14 +292,6 @@ VMM_STAT(VMEXIT_USERSPACE, "number of vm exits handled in userspace");
296292
VMM_STAT(VMEXIT_RENDEZVOUS, "number of times rendezvous pending at exit");
297293
VMM_STAT(VMEXIT_EXCEPTION, "number of vm exits due to exceptions");
298294

299-
/*
300-
* Upper limit on vm_maxcpu. Limited by use of uint16_t types for CPU
301-
* counts as well as range of vpid values for VT-x and by the capacity
302-
* of cpuset_t masks. The call to new_unrhdr() in vpid_init() in
303-
* vmx.c requires 'vm_maxcpu + 1 <= 0xffff', hence the '- 1' below.
304-
*/
305-
#define VM_MAXCPU MIN(0xffff - 1, CPU_SETSIZE)
306-
307295
#ifdef KTR
308296
static const char *
309297
vcpu_state2str(enum vcpu_state state)
@@ -405,16 +393,6 @@ vmm_modinit(void)
405393
if (!vmm_is_hw_supported())
406394
return (ENXIO);
407395

408-
vm_maxcpu = mp_ncpus;
409-
TUNABLE_INT_FETCH("hw.vmm.maxcpu", &vm_maxcpu);
410-
411-
if (vm_maxcpu > VM_MAXCPU) {
412-
printf("vmm: vm_maxcpu clamped to %u\n", VM_MAXCPU);
413-
vm_maxcpu = VM_MAXCPU;
414-
}
415-
if (vm_maxcpu == 0)
416-
vm_maxcpu = 1;
417-
418396
vmm_host_state_init();
419397

420398
vmm_ipinum = lapic_ipi_alloc(pti ? &IDTVEC(justreturn1_pti) :

sys/arm64/vmm/vmm.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,6 @@ static const struct vmm_regs vmm_arch_regs_masks = {
205205
/* Host registers masked by vmm_arch_regs_masks. */
206206
static struct vmm_regs vmm_arch_regs;
207207

208-
u_int vm_maxcpu;
209-
SYSCTL_UINT(_hw_vmm, OID_AUTO, maxcpu, CTLFLAG_RDTUN | CTLFLAG_NOFETCH,
210-
&vm_maxcpu, 0, "Maximum number of vCPUs");
211-
212208
static void vcpu_notify_event_locked(struct vcpu *vcpu);
213209

214210
/* global statistics */
@@ -228,12 +224,6 @@ VMM_STAT(VMEXIT_SS, "number of vmexits for a single-step exception");
228224
VMM_STAT(VMEXIT_UNHANDLED_EL2, "number of vmexits for an unhandled EL2 exception");
229225
VMM_STAT(VMEXIT_UNHANDLED, "number of vmexits for an unhandled exception");
230226

231-
/*
232-
* Upper limit on vm_maxcpu. We could increase this to 28 bits, but this
233-
* is a safe value for now.
234-
*/
235-
#define VM_MAXCPU MIN(0xffff - 1, CPU_SETSIZE)
236-
237227
static int
238228
vmm_regs_init(struct vmm_regs *regs, const struct vmm_regs *masks)
239229
{
@@ -329,16 +319,6 @@ vmm_modinit(void)
329319
if (error != 0)
330320
return (error);
331321

332-
vm_maxcpu = mp_ncpus;
333-
TUNABLE_INT_FETCH("hw.vmm.maxcpu", &vm_maxcpu);
334-
335-
if (vm_maxcpu > VM_MAXCPU) {
336-
printf("vmm: vm_maxcpu clamped to %u\n", VM_MAXCPU);
337-
vm_maxcpu = VM_MAXCPU;
338-
}
339-
if (vm_maxcpu == 0)
340-
vm_maxcpu = 1;
341-
342322
error = vmm_regs_init(&vmm_arch_regs, &vmm_arch_regs_masks);
343323
if (error != 0)
344324
return (error);

sys/dev/vmm/vmm_dev.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <sys/priv.h>
1919
#include <sys/proc.h>
2020
#include <sys/queue.h>
21+
#include <sys/smp.h>
2122
#include <sys/sx.h>
2223
#include <sys/sysctl.h>
2324
#include <sys/ucred.h>
@@ -91,6 +92,10 @@ static MALLOC_DEFINE(M_VMMDEV, "vmmdev", "vmmdev");
9192

9293
SYSCTL_DECL(_hw_vmm);
9394

95+
u_int vm_maxcpu;
96+
SYSCTL_UINT(_hw_vmm, OID_AUTO, maxcpu, CTLFLAG_RDTUN | CTLFLAG_NOFETCH,
97+
&vm_maxcpu, 0, "Maximum number of vCPUs");
98+
9499
static void devmem_destroy(void *arg);
95100
static int devmem_create_cdev(struct vmmdev_softc *sc, int id, char *devmem);
96101

@@ -1158,6 +1163,16 @@ vmm_handler(module_t mod, int what, void *arg)
11581163
error = vmmdev_init();
11591164
if (error != 0)
11601165
break;
1166+
1167+
vm_maxcpu = mp_ncpus;
1168+
TUNABLE_INT_FETCH("hw.vmm.maxcpu", &vm_maxcpu);
1169+
if (vm_maxcpu > VM_MAXCPU) {
1170+
printf("vmm: vm_maxcpu clamped to %u\n", VM_MAXCPU);
1171+
vm_maxcpu = VM_MAXCPU;
1172+
}
1173+
if (vm_maxcpu == 0)
1174+
vm_maxcpu = 1;
1175+
11611176
error = vmm_modinit();
11621177
if (error == 0)
11631178
vmm_initialized = true;

sys/dev/vmm/vmm_dev.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ struct vmmdev_ioctl {
5757
extern const struct vmmdev_ioctl vmmdev_machdep_ioctls[];
5858
extern const size_t vmmdev_machdep_ioctl_count;
5959

60+
/*
61+
* Upper limit on vm_maxcpu. Limited by use of uint16_t types for CPU counts as
62+
* well as range of vpid values for VT-x on amd64 and by the capacity of
63+
* cpuset_t masks. The call to new_unrhdr() in vpid_init() in vmx.c requires
64+
* 'vm_maxcpu + 1 <= 0xffff', hence the '- 1' below.
65+
*/
66+
#define VM_MAXCPU MIN(0xffff - 1, CPU_SETSIZE)
67+
68+
/* Maximum number of vCPUs in a single VM. */
69+
extern u_int vm_maxcpu;
70+
6071
#endif /* _KERNEL */
6172

6273
struct vmmctl_vm_create {

sys/riscv/vmm/vmm.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -143,23 +143,13 @@ static int vmm_ipinum;
143143
SYSCTL_INT(_hw_vmm, OID_AUTO, ipinum, CTLFLAG_RD, &vmm_ipinum, 0,
144144
"IPI vector used for vcpu notifications");
145145

146-
u_int vm_maxcpu;
147-
SYSCTL_UINT(_hw_vmm, OID_AUTO, maxcpu, CTLFLAG_RDTUN | CTLFLAG_NOFETCH,
148-
&vm_maxcpu, 0, "Maximum number of vCPUs");
149-
150146
static void vcpu_notify_event_locked(struct vcpu *vcpu);
151147

152148
/* global statistics */
153149
VMM_STAT(VMEXIT_COUNT, "total number of vm exits");
154150
VMM_STAT(VMEXIT_IRQ, "number of vmexits for an irq");
155151
VMM_STAT(VMEXIT_UNHANDLED, "number of vmexits for an unhandled exception");
156152

157-
/*
158-
* Upper limit on vm_maxcpu. We could increase this to 28 bits, but this
159-
* is a safe value for now.
160-
*/
161-
#define VM_MAXCPU MIN(0xffff - 1, CPU_SETSIZE)
162-
163153
static void
164154
vcpu_cleanup(struct vcpu *vcpu, bool destroy)
165155
{
@@ -210,18 +200,6 @@ vm_exitinfo(struct vcpu *vcpu)
210200
int
211201
vmm_modinit(void)
212202
{
213-
vm_maxcpu = mp_ncpus;
214-
215-
TUNABLE_INT_FETCH("hw.vmm.maxcpu", &vm_maxcpu);
216-
217-
if (vm_maxcpu > VM_MAXCPU) {
218-
printf("vmm: vm_maxcpu clamped to %u\n", VM_MAXCPU);
219-
vm_maxcpu = VM_MAXCPU;
220-
}
221-
222-
if (vm_maxcpu == 0)
223-
vm_maxcpu = 1;
224-
225203
return (vmmops_modinit());
226204
}
227205

0 commit comments

Comments
 (0)