From nobody Thu Jan 26 22:11:36 2023 X-Original-To: dev-commits-src-branches@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 4P2w0S40ycz3c85v; Thu, 26 Jan 2023 22:11:36 +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 4P2w0S3C4sz3tfl; Thu, 26 Jan 2023 22:11:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674771096; 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=RR4oSIT5rpa1nodk8FKbfgqTvzv5+Dt77g1qUb189XU=; b=Iz/+jBvvh1CCcODE8KkTGfYcRT+MqPlgU7HqAYflqkS6SwvaXvUybJHMC0Cc2BtMShLJ7u DuUEn5iEIm8K5SUFC6UQfv+bkrbp6V1Uur4FT5ebqO+Z3IRLvrgQq73DMuAVtooQCogX72 FFrncwfGrRyZ22t1hi/fT/eU9qZAxmQg7v6UepHWf2Xdmi6fTry3FrApHJQyNlz/U6UASz VoQYyzKqWb24+5JtHUhTyKQ/3YQLQaTd05uVwR2hq54RIk+5+4llMX29EbrOWwLA6tiet4 OG5QajQ6GDstC4hpYbZdKZj1ugG1cqRiHr4iMnHEInlswEyq3EyDXMsjZB4s8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674771096; 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=RR4oSIT5rpa1nodk8FKbfgqTvzv5+Dt77g1qUb189XU=; b=SZYVOxPdNKRwkE3psHuu4QIGKXQ40jyfhQ+GtCC5VpWzR8hu0jctLqOv3BS0zVbBV4dvL5 6KzNE7oM0DLba/f9++luBjYkWf/t4xZAZ9QW6CqcBR0zQkqNCMclRR5uJM3DiZx75o61XC I+iwyjpwuyvk60IpNITHr9zL0Bx6LeeWYOQ5Rh2VRn9Ls2AlrpRlUHMuXQ2J3Mqf+1x+L8 5aiDvGOSj9KNu+3HXXD454Vr9mg2WS/W/UvvOB+x0sA7gbVxX37IquEDTTHITu6QjNDhPG Waq003EJ49cFEwM6AnwDikUcZUADDT7qkyBbL8ScgirWfM9LHemGGQUljXNmcw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674771096; a=rsa-sha256; cv=none; b=eCEi2QS9LLriecFZXzO8Y/YujjtallsA1MOchxwuS35x4NqAqMo89iRy+nMeq7v9e62/lc pX4BWnBl4YDaRMwmfxXPtOwxqxb+/vnLL3lWvH+9OYUSvkPC3gqaV7S6FiGTv1luSWbddo NZnS21neifLP/bhBr6NObfPG3P5uTOKsgD57VOaLsleB5Dr5zqQUrHg6RembecuefzNLPl u1cpXZqSjXH6jKh8LahidyNn0qDdsQbNGtOSP1zQjaOkxlUDfO9JVt+qpBpwsIkbV4j1Iq iam99A5EyLA84YohbdGx9/PqM4mOdLaZ3AFlEJ7Og4cZi+1ArDzUGVv5wymx7g== 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 4P2w0S1rPHzm4b; Thu, 26 Jan 2023 22:11:36 +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 30QMBaYm018481; Thu, 26 Jan 2023 22:11:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30QMBanV018480; Thu, 26 Jan 2023 22:11:36 GMT (envelope-from git) Date: Thu, 26 Jan 2023 22:11:36 GMT Message-Id: <202301262211.30QMBanV018480@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 80cce0a3610b - stable/13 - vmm: Use vm_get_maxcpus() instead of VM_MAXCPU in various places. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 80cce0a3610b8dd3a85a8d6d71e5d8f4025e3b29 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=80cce0a3610b8dd3a85a8d6d71e5d8f4025e3b29 commit 80cce0a3610b8dd3a85a8d6d71e5d8f4025e3b29 Author: John Baldwin AuthorDate: 2022-11-18 17:57:38 +0000 Commit: John Baldwin CommitDate: 2023-01-26 21:43:33 +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 (cherry picked from commit 35abc6c238e98e313c5b1cb5ed18b8ed68615abc) --- 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 3ec34a1f3336..9b285df04092 100644 --- a/sys/amd64/vmm/vmm.c +++ b/sys/amd64/vmm/vmm.c @@ -2804,11 +2804,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); @@ -2850,11 +2851,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 " @@ -2919,7 +2922,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]; @@ -2931,9 +2934,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(); @@ -2941,7 +2945,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 -