From nobody Fri Nov 18 18:26:22 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NDQGQ6wWpz4d7rW; Fri, 18 Nov 2022 18:26:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NDQGQ5kzDz4GyF; Fri, 18 Nov 2022 18:26:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668795982; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dFloC1k+Wf2ax8SB5xO4hbopU8qAdIW5ifJ6xNzttko=; b=myl3KLVeSg6BUe6YY1EOdb+6qVWDplsrIc630Y2BvzyKAqIuVEzok1sMFUGXpu08FmxIgM ejtqKpC9NZFSCftku6qvhET1f8u+pbfIRx0xCePnSLgpnRbq3i6EfGMlC7sJyj4vBK1uMp 3oSqg+BgckugqQMzvzvYy3eGKMrPMXEat//q0mQj607OuRCNlPCXX7QjCEM6K/e5DnevPV e7Ck1ocfWfX1V0TLhMqH8S0V8t0Wz6cuI8ybSq25TRMz4Biv5EkZLf9MihVJSctLZEKYiH oObM7ZLt9e8VNMnO94+HWa26fHhjW3uSj44hC+ra8p9e4j6q1SD9iHEdaeNYKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668795982; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dFloC1k+Wf2ax8SB5xO4hbopU8qAdIW5ifJ6xNzttko=; b=ipGZqfsLE9DXjWQxNFzP3z0AL7U/9+/lYVtGplosN/sLFBqxUHhBfJafPc2Pi1pCPuBaBN ZNcHYdY2gFsFfDHoUf6uVr4PXdUyUm6u06dhNPf8yHZVsOOeVatqtAeneFFtlHfaek+M5B GBKLPMoejSbL/Vg27L1EhG1ub4eFbqEkQtQV/TlFwYpv6r+/apb7hHj2mtE1NxmDgsYf8/ 5x/pj3NOpSTPx1nv3+rzBaPnfq1nHbbkqoWL4gHIhRcnU4uJK2LjYIenyhpFO7gs/lncG1 xJsK3dTVxaLUKN7YInO8WOUi9WRX4FQnCt67A9SgihkkBmqt/kdGMJnT2VkU9w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1668795982; a=rsa-sha256; cv=none; b=wmqLHQm1pgi6TiuPxOx8En/TiGgJha9a3N5S+FAbR0YZOJyx7V+9IgQqwWkd3tXJxiksI4 Rk7AH7EjD50F2avewfsFdHrd5ENTYK9tnC7aoHzaTWFHnWnaOlPDKgMpCgOjr8sdPP8HI1 gOErETi9LSFWVi/Yx+uZ7vbOeXvCk3+OfRFBdwMCRwI2rsyEfpQrt/kD6Fy69w7hHmnz4Y 3LwDUT6YteALg3jFd/zGmGQ1pFMqmpyAt6XOPEh2/q0JjhErDzCpQN/gZ/oXrsxjWo9lLH UCeEXrzAGUBbF0ja0P2S3sLakU3F9Da7461N6+TiXPNqCgUasYO6tLIx8FvBmw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NDQGQ4BrZzFVn; Fri, 18 Nov 2022 18:26:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2AIIQM6P029882; Fri, 18 Nov 2022 18:26:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AIIQMoW029881; Fri, 18 Nov 2022 18:26:22 GMT (envelope-from git) Date: Fri, 18 Nov 2022 18:26:22 GMT Message-Id: <202211181826.2AIIQMoW029881@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 35abc6c238e9 - main - vmm: Use vm_get_maxcpus() instead of VM_MAXCPU in various places. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 35abc6c238e98e313c5b1cb5ed18b8ed68615abc Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=35abc6c238e98e313c5b1cb5ed18b8ed68615abc commit 35abc6c238e98e313c5b1cb5ed18b8ed68615abc Author: John Baldwin AuthorDate: 2022-11-18 17:57:38 +0000 Commit: John Baldwin CommitDate: 2022-11-18 18:25:34 +0000 vmm: Use vm_get_maxcpus() instead of VM_MAXCPU in various places. Mostly these are loops that iterate over all possible vCPU IDs for a specific virtual machine. Reviewed by: corvink, markj Differential Revision: https://reviews.freebsd.org/D37147 --- sys/amd64/vmm/amd/svm.c | 5 +++-- sys/amd64/vmm/amd/vmcb.c | 4 ++-- sys/amd64/vmm/intel/vmx.c | 12 ++++++------ sys/amd64/vmm/io/vlapic.c | 6 ++++-- sys/amd64/vmm/vmm.c | 19 ++++++++++++------- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/sys/amd64/vmm/amd/svm.c b/sys/amd64/vmm/amd/svm.c index 4195cc5bd049..1a7990383b09 100644 --- a/sys/amd64/vmm/amd/svm.c +++ b/sys/amd64/vmm/amd/svm.c @@ -2422,14 +2422,15 @@ svm_snapshot(void *arg, struct vm_snapshot_meta *meta) /* struct svm_softc is AMD's representation for SVM softc */ struct svm_softc *sc; struct svm_vcpu *vcpu; - int i; int ret; + uint16_t i, maxcpus; sc = arg; KASSERT(sc != NULL, ("%s: arg was NULL", __func__)); - for (i = 0; i < VM_MAXCPU; i++) { + maxcpus = vm_get_maxcpus(sc->vm); + for (i = 0; i < maxcpus; i++) { vcpu = &sc->vcpu[i]; /* Snapshot swctx for virtual cpu i */ diff --git a/sys/amd64/vmm/amd/vmcb.c b/sys/amd64/vmm/amd/vmcb.c index 0341e4e6c07c..69fe853ca843 100644 --- a/sys/amd64/vmm/amd/vmcb.c +++ b/sys/amd64/vmm/amd/vmcb.c @@ -463,7 +463,7 @@ vmcb_getany(struct svm_softc *sc, int vcpu, int ident, uint64_t *val) { int error = 0; - if (vcpu < 0 || vcpu >= VM_MAXCPU) { + if (vcpu < 0 || vcpu >= vm_get_maxcpus(sc->vm)) { error = EINVAL; goto err; } @@ -484,7 +484,7 @@ vmcb_setany(struct svm_softc *sc, int vcpu, int ident, uint64_t val) { int error = 0; - if (vcpu < 0 || vcpu >= VM_MAXCPU) { + if (vcpu < 0 || vcpu >= vm_get_maxcpus(sc->vm)) { error = EINVAL; goto err; } diff --git a/sys/amd64/vmm/intel/vmx.c b/sys/amd64/vmm/intel/vmx.c index 857028dcd0f1..104df77b351c 100644 --- a/sys/amd64/vmm/intel/vmx.c +++ b/sys/amd64/vmm/intel/vmx.c @@ -1029,12 +1029,12 @@ vmx_setup_cr_shadow(int which, struct vmcs *vmcs, uint32_t initial) static void * vmx_init(struct vm *vm, pmap_t pmap) { - uint16_t vpid[VM_MAXCPU]; int i, error; struct vmx *vmx; struct vmcs *vmcs; uint32_t exc_bitmap; - uint16_t maxcpus; + uint16_t maxcpus = vm_get_maxcpus(vm); + uint16_t vpid[maxcpus]; vmx = malloc(sizeof(struct vmx), M_VMX, M_WAITOK | M_ZERO); if ((uintptr_t)vmx & PAGE_MASK) { @@ -1097,7 +1097,7 @@ vmx_init(struct vm *vm, pmap_t pmap) ((cap_rdpid || cap_rdtscp) && guest_msr_ro(vmx, MSR_TSC_AUX))) panic("vmx_init: error setting guest msr access"); - vpid_alloc(vpid, VM_MAXCPU); + vpid_alloc(vpid, maxcpus); if (virtual_interrupt_delivery) { error = vm_map_mmio(vm, DEFAULT_APIC_BASE, PAGE_SIZE, @@ -1106,7 +1106,6 @@ vmx_init(struct vm *vm, pmap_t pmap) KASSERT(error == 0, ("vm_map_mmio(apicbase) error %d", error)); } - maxcpus = vm_get_maxcpus(vm); for (i = 0; i < maxcpus; i++) { vmcs = &vmx->vmcs[i]; vmcs->identifier = vmx_revision(); @@ -4074,14 +4073,15 @@ vmx_snapshot(void *arg, struct vm_snapshot_meta *meta) { struct vmx *vmx; struct vmxctx *vmxctx; - int i; int ret; + uint16_t i, maxcpus; vmx = arg; KASSERT(vmx != NULL, ("%s: arg was NULL", __func__)); - for (i = 0; i < VM_MAXCPU; i++) { + maxcpus = vm_get_maxcpus(vmx->vm); + for (i = 0; i < maxcpus; i++) { SNAPSHOT_BUF_OR_LEAVE(vmx->guest_msrs[i], sizeof(vmx->guest_msrs[i]), meta, ret, done); diff --git a/sys/amd64/vmm/io/vlapic.c b/sys/amd64/vmm/io/vlapic.c index 0e1fb1bbf006..76e3cd14a8f5 100644 --- a/sys/amd64/vmm/io/vlapic.c +++ b/sys/amd64/vmm/io/vlapic.c @@ -1857,16 +1857,18 @@ vlapic_reset_callout(struct vlapic *vlapic, uint32_t ccr) int vlapic_snapshot(struct vm *vm, struct vm_snapshot_meta *meta) { - int i, ret; + int ret; struct vlapic *vlapic; struct LAPIC *lapic; uint32_t ccr; + uint16_t i, maxcpus; KASSERT(vm != NULL, ("%s: arg was NULL", __func__)); ret = 0; - for (i = 0; i < VM_MAXCPU; i++) { + maxcpus = vm_get_maxcpus(vm); + for (i = 0; i < maxcpus; i++) { vlapic = vm_lapic(vm, i); /* snapshot the page first; timer period depends on icr_timer */ diff --git a/sys/amd64/vmm/vmm.c b/sys/amd64/vmm/vmm.c index 124fffec0d9e..da1db09bdf58 100644 --- a/sys/amd64/vmm/vmm.c +++ b/sys/amd64/vmm/vmm.c @@ -2806,11 +2806,12 @@ vm_snapshot_vcpus(struct vm *vm, struct vm_snapshot_meta *meta) { uint64_t tsc, now; int ret; - int i; struct vcpu *vcpu; + uint16_t i, maxcpus; now = rdtsc(); - for (i = 0; i < VM_MAXCPU; i++) { + maxcpus = vm_get_maxcpus(vm); + for (i = 0; i < maxcpus; i++) { vcpu = &vm->vcpu[i]; SNAPSHOT_VAR_OR_LEAVE(vcpu->x2apic_state, meta, ret, done); @@ -2852,11 +2853,13 @@ done: static int vm_snapshot_vmcx(struct vm *vm, struct vm_snapshot_meta *meta) { - int i, error; + int error; + uint16_t i, maxcpus; error = 0; - for (i = 0; i < VM_MAXCPU; i++) { + maxcpus = vm_get_maxcpus(vm); + for (i = 0; i < maxcpus; i++) { error = vmmops_vmcx_snapshot(vm->cookie, meta, i); if (error != 0) { printf("%s: failed to snapshot vmcs/vmcb data for " @@ -2921,7 +2924,7 @@ vm_set_tsc_offset(struct vm *vm, int vcpuid, uint64_t offset) { struct vcpu *vcpu; - if (vcpuid < 0 || vcpuid >= VM_MAXCPU) + if (vcpuid < 0 || vcpuid >= vm_get_maxcpus(vm)) return (EINVAL); vcpu = &vm->vcpu[vcpuid]; @@ -2933,9 +2936,10 @@ vm_set_tsc_offset(struct vm *vm, int vcpuid, uint64_t offset) int vm_restore_time(struct vm *vm) { - int error, i; + int error; uint64_t now; struct vcpu *vcpu; + uint16_t i, maxcpus; now = rdtsc(); @@ -2943,7 +2947,8 @@ vm_restore_time(struct vm *vm) if (error) return (error); - for (i = 0; i < nitems(vm->vcpu); i++) { + maxcpus = vm_get_maxcpus(vm); + for (i = 0; i < maxcpus; i++) { vcpu = &vm->vcpu[i]; error = vmmops_restore_tsc(vm->cookie, i, vcpu->tsc_offset -