From nobody Wed May 08 16:11:18 2024 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 4VZKrl5Fztz5JRMZ; Wed, 08 May 2024 16:11:19 +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 4VZKrl067fz4p2y; Wed, 8 May 2024 16:11:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715184679; 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=ceIFne8FXdZCEQ5a80vTsrZBTlV63AoCpFxHuG/YlDs=; b=QqYsc8fPYwBygn+RQBWkGwEB5LGgOdh9cFC7ZNal0BFXV4J+s9PuTvsjGqy1FvIdFxvoDw SseZ9QllH2TDvzsCSEM2vlaVCliftThkdVcSRnc6Llgd9DiVznojnjrlXim24XwqSvdGo6 scu8dNMQeVmeuXuFNhKgAtpufF1LGnbUBO59wYvfuq+Tr+pNZaRqNapPKC0KZP8PCNgxTm fWliWnn663nQzgIvMo1yo8GE4RLefR8eFWrBvkRQr+OsM+TOZ6MQk4A1dH4icYVB8g04mD TT3lEGYcCZIQDyALYF/qAiYTazciPNMiH4yF0hUz4xmP0s2uAQRmeHO//cGQzw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715184679; a=rsa-sha256; cv=none; b=xGmpX+tJjf3lqVLRe6QnjkESSC8IVNyxur4ZHgcdcSXvp0BOSjnbTu7d8dnbK3PsaS6fuO Fc2wMcA79kVaSg5tbSrACYvSXYEhrEN7i6t1SdFDT5aXi3aP7PvLJBCmJDkm3yDqvxHX2I aHGMKKDDg2U+5fOCL0ZcmzfiELmy3s1SRdpVY6D5MeQW52AiZHTmKUwSjRZys51lEUt6KI 4vrgOnQgcDfZhhEbjbH3LzvzQ/urQDwXgTvgMupIeQsYRDsCf2TJW8lrWbvMViqA84S42L 15toAoXrm8Wy+NzXyR7X8d08mWN82YzuOefBSKDo07BDWWE0VckT9XCdK4sWhA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715184679; 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=ceIFne8FXdZCEQ5a80vTsrZBTlV63AoCpFxHuG/YlDs=; b=oT0Mkz0tnryUUdsQskJZPfoQrddcy3on6wv3rNFA0Tq2gIasr5GR+B1+S6IcRD3w+d2gcE WTFq7HpLGXyXbAAWZj5q0H7WPr6qPF7WvyxFEQIKEwLHcsviEJfhcFejRat8XJdIV9zJCw AkekIWwhKicrGmbuRZkT4gVW3EOBqwoZW9dQy/JHdA7MtDZDNsissIDR49vCccav+lcrUt HHVBUxUlRMz6CAIQ28VkBlOGP1lE7SeefGaaLxLKHFOkMT7B9/GvfKM3Ejb011/ajZbKXv iohAwUB2Pw1j2kvh7WRbLyJ316uM/7PDAOr/DKRZ7Tr5HX2e5LJls8JZ1i+o0Q== 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 4VZKrk6pr4zXGr; Wed, 8 May 2024 16:11:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 448GBIok093857; Wed, 8 May 2024 16:11:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 448GBIaT093854; Wed, 8 May 2024 16:11:18 GMT (envelope-from git) Date: Wed, 8 May 2024 16:11:18 GMT Message-Id: <202405081611.448GBIaT093854@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: e3333648b75d - main - vmm: Start reconciling amd64 and arm64 copies of vmm_dev.c 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e3333648b75dc9703e54129dff56ae5b4d6f91c5 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=e3333648b75dc9703e54129dff56ae5b4d6f91c5 commit e3333648b75dc9703e54129dff56ae5b4d6f91c5 Author: Mark Johnston AuthorDate: 2024-05-08 16:02:38 +0000 Commit: Mark Johnston CommitDate: 2024-05-08 16:11:03 +0000 vmm: Start reconciling amd64 and arm64 copies of vmm_dev.c Most of the code in vmm_dev.c and vmm.c can and should be shared between amd64 and arm64 (and eventually riscv) rather than being duplicated. To the end of adding a shared implementation in sys/dev/vmm, this patch eliminates most of the differences between the two copies of vmm_dev.c. - Remove an unneeded cdefs.h include. - Simplify the amd64 implementation of vcpu_unlock_one(). - Simplify the arm64 implementation of vcpu_lock_one(). - Pass buffer sizes to alloc_memseg() and get_memseg() on arm64. On amd64 this is needed for compat ioctls, but these functions should be merged. - Make devmem_mmap_single() stricter on arm64. Reviewed by: corvink, jhb Differential Revision: https://reviews.freebsd.org/D44995 --- sys/amd64/vmm/vmm_dev.c | 15 +++++++-------- sys/arm64/vmm/vmm_dev.c | 29 +++++++++++++++-------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/sys/amd64/vmm/vmm_dev.c b/sys/amd64/vmm/vmm_dev.c index 5214cd3f1447..46cddce4e4b8 100644 --- a/sys/amd64/vmm/vmm_dev.c +++ b/sys/amd64/vmm/vmm_dev.c @@ -26,7 +26,6 @@ * SUCH DAMAGE. */ -#include #include "opt_bhyve_snapshot.h" #include @@ -163,14 +162,14 @@ vcpu_lock_one(struct vcpu *vcpu) } static void -vcpu_unlock_one(struct vmmdev_softc *sc, int vcpuid, struct vcpu *vcpu) +vcpu_unlock_one(struct vcpu *vcpu) { enum vcpu_state state; state = vcpu_get_state(vcpu, NULL); if (state != VCPU_FROZEN) { - panic("vcpu %s(%d) has invalid state %d", vm_name(sc->vm), - vcpuid, state); + panic("vcpu %s(%d) has invalid state %d", + vm_name(vcpu_vm(vcpu)), vcpu_vcpuid(vcpu), state); } vcpu_set_state(vcpu, VCPU_IDLE, false); @@ -200,7 +199,7 @@ vcpu_lock_all(struct vmmdev_softc *sc) vcpu = vm_vcpu(sc->vm, j); if (vcpu == NULL) continue; - vcpu_unlock_one(sc, j, vcpu); + vcpu_unlock_one(vcpu); } vm_unlock_vcpus(sc->vm); } @@ -219,7 +218,7 @@ vcpu_unlock_all(struct vmmdev_softc *sc) vcpu = vm_vcpu(sc->vm, i); if (vcpu == NULL) continue; - vcpu_unlock_one(sc, i, vcpu); + vcpu_unlock_one(vcpu); } vm_unlock_vcpus(sc->vm); } @@ -1086,7 +1085,7 @@ vmmdev_ioctl(struct cdev *cdev, u_long cmd, caddr_t data, int fflag, done: if (vcpus_locked == SINGLE) - vcpu_unlock_one(sc, vcpuid, vcpu); + vcpu_unlock_one(vcpu); else if (vcpus_locked == ALL) vcpu_unlock_all(sc); if (memsegs_locked) @@ -1231,7 +1230,7 @@ sysctl_vmm_destroy(SYSCTL_HANDLER_ARGS) * is scheduled for destruction. */ cdev = sc->cdev; - sc->cdev = NULL; + sc->cdev = NULL; mtx_unlock(&vmmdev_mtx); /* diff --git a/sys/arm64/vmm/vmm_dev.c b/sys/arm64/vmm/vmm_dev.c index 9f405384f2b3..946c6760f7c1 100644 --- a/sys/arm64/vmm/vmm_dev.c +++ b/sys/arm64/vmm/vmm_dev.c @@ -102,10 +102,7 @@ vmm_priv_check(struct ucred *ucred) static int vcpu_lock_one(struct vcpu *vcpu) { - int error; - - error = vcpu_set_state(vcpu, VCPU_FROZEN, true); - return (error); + return (vcpu_set_state(vcpu, VCPU_FROZEN, true)); } static void @@ -252,8 +249,10 @@ vmmdev_rw(struct cdev *cdev, struct uio *uio, int flags) return (error); } +CTASSERT(sizeof(((struct vm_memseg *)0)->name) >= VM_MAX_SUFFIXLEN + 1); + static int -get_memseg(struct vmmdev_softc *sc, struct vm_memseg *mseg) +get_memseg(struct vmmdev_softc *sc, struct vm_memseg *mseg, size_t len) { struct devmem_softc *dsc; int error; @@ -270,17 +269,16 @@ get_memseg(struct vmmdev_softc *sc, struct vm_memseg *mseg) } KASSERT(dsc != NULL, ("%s: devmem segment %d not found", __func__, mseg->segid)); - error = copystr(dsc->name, mseg->name, sizeof(mseg->name), - NULL); + error = copystr(dsc->name, mseg->name, len, NULL); } else { - bzero(mseg->name, sizeof(mseg->name)); + bzero(mseg->name, len); } return (error); } static int -alloc_memseg(struct vmmdev_softc *sc, struct vm_memseg *mseg) +alloc_memseg(struct vmmdev_softc *sc, struct vm_memseg *mseg, size_t len) { char *name; int error; @@ -296,8 +294,8 @@ alloc_memseg(struct vmmdev_softc *sc, struct vm_memseg *mseg) */ if (VM_MEMSEG_NAME(mseg)) { sysmem = false; - name = malloc(sizeof(mseg->name), M_VMMDEV, M_WAITOK); - error = copystr(mseg->name, name, sizeof(mseg->name), NULL); + name = malloc(len, M_VMMDEV, M_WAITOK); + error = copystr(mseg->name, name, len, NULL); if (error) goto done; } @@ -545,10 +543,12 @@ vmmdev_ioctl(struct cdev *cdev, u_long cmd, caddr_t data, int fflag, error = vm_munmap_memseg(sc->vm, mu->gpa, mu->len); break; case VM_ALLOC_MEMSEG: - error = alloc_memseg(sc, (struct vm_memseg *)data); + error = alloc_memseg(sc, (struct vm_memseg *)data, + sizeof(((struct vm_memseg *)0)->name)); break; case VM_GET_MEMSEG: - error = get_memseg(sc, (struct vm_memseg *)data); + error = get_memseg(sc, (struct vm_memseg *)data, + sizeof(((struct vm_memseg *)0)->name)); break; case VM_GET_REGISTER: vmreg = (struct vm_register *)data; @@ -994,7 +994,8 @@ devmem_mmap_single(struct cdev *cdev, vm_ooffset_t *offset, vm_size_t len, if (seglen >= last) vm_object_reference(*objp); else - error = 0; + error = EINVAL; + vm_unlock_memsegs(dsc->sc->vm); return (error); }