From nobody Wed Aug 28 19:12:43 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 4WvDZM5S7tz5MZVv; Wed, 28 Aug 2024 19:12:43 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WvDZM3lbbz4pbY; Wed, 28 Aug 2024 19:12:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724872363; 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=sgj/UhkRUu4ZWnLOoi11yvogSw5YyLHeDqM9knZjjAc=; b=HM6PSHRQU0mJtMqTVsat10V2hyKTsS0juhr59AZtyKYfBIc3LOb5IUNZYOgm7MSg7Ipp97 TyvlxnwzDDYcKCQ35PMebDxVoz2Bvk1RsVSLnGOrTDQ5xLEXSSJPmqE2f8mvuXdagKhFn/ LvUMGZdFuEdrXSvB5UgMDS0zYwil4dxL/0L1bIqDNuOBBT2w3CHzVNeBUAeFAZ4sORpfI8 bdYJCMMmdpitOE3rXomeTZi1OsPbbPWHUq1TYwlB3kNbLqQJthx9lFwzkXPjRIUM05XBja VhRuyj2XpM8B+kvOOq6Gnhuh6rAawnHSS1L6G8u8e2mbG8ljY43Y5qIpwEartA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1724872363; a=rsa-sha256; cv=none; b=HhNyAMvrbXFbrdjHGEtlYYGu7zPyrNm/v7eBsNZAhfGC4jz9Yj2ZGHPEoM6rzy8dpOYgFM AnuN+OR+RY1qA2V3NCwnt9j11W627Vp6UoTK3Wdw0npW4DJoVV6IMqjUN1CvesKQaEv7S1 HRxATWXfw7HAUTvMpxzMuFR3PiTAWFaFvkBvFiA/ylSauQnVlE2OEsoPzHpwPpPtXIotN5 DKtHsO1Oz8oV2P+dXNuKfErAQp6LdUx1DJgMBI5Cp44A3woTu+SE7aTmtUbtHg4C5rGtmn DVaKoAe8LO07z9sE8kiUr8+Glz3lKBoY3U+GfjO8Ovkvguva/npJQ2PUyaaYoA== 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=1724872363; 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=sgj/UhkRUu4ZWnLOoi11yvogSw5YyLHeDqM9knZjjAc=; b=i8ITYCFzptePj3dAb23xN+o9vaBb9e+8ny6MEB9eKq+3yUZw2Hak1ZycEAI+XAQ/OiMf0t zSZur6kIYbSWowit6VfqHbMYSHucdyh8CdRoBIKtLKfKqvbGKbu6rbHS2fGk3RnSrP1kns TYUgXP1HK9MrFbaVOO5az7iUHZLluQogmFLo/4+CGSdnt17PDrNH9TQQa6ceTvZGYUvoIC bZu3obkHhuLRBD5PM0q8jvy+/8uaJowP0Cccdr69J9lTpFelH7CW11B81HmmXusurtOAFk ajcBgHIFLEMLFD0DUSsB4pcD/xPdRxWHLX9D8Q7jC2AmK7+M2pxhZ0uX/oYTCA== 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 4WvDZM3MGZzmLn; Wed, 28 Aug 2024 19:12:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 47SJChVw059011; Wed, 28 Aug 2024 19:12:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47SJChCA059008; Wed, 28 Aug 2024 19:12:43 GMT (envelope-from git) Date: Wed, 28 Aug 2024 19:12:43 GMT Message-Id: <202408281912.47SJChCA059008@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: 063a8bd908dd - main - vmm: Factor most of sysctl_vmm_destroy() into a separate function 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: 063a8bd908ddaae9f0ba8c7711dfe837a14f21e7 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=063a8bd908ddaae9f0ba8c7711dfe837a14f21e7 commit 063a8bd908ddaae9f0ba8c7711dfe837a14f21e7 Author: Mark Johnston AuthorDate: 2024-08-28 18:57:12 +0000 Commit: Mark Johnston CommitDate: 2024-08-28 18:57:12 +0000 vmm: Factor most of sysctl_vmm_destroy() into a separate function This will make it easy to share code with an ioctl handler which creates VMs. No functional change intended. Reviewed by: corvink, jhb Differential Revision: https://reviews.freebsd.org/D46445 --- sys/dev/vmm/vmm_dev.c | 72 ++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/sys/dev/vmm/vmm_dev.c b/sys/dev/vmm/vmm_dev.c index 94546efd03c9..6bdcb51777d4 100644 --- a/sys/dev/vmm/vmm_dev.c +++ b/sys/dev/vmm/vmm_dev.c @@ -732,12 +732,24 @@ vmmdev_mmap_single(struct cdev *cdev, vm_ooffset_t *offset, vm_size_t mapsize, } static void -vmmdev_destroy(void *arg) +vmmdev_destroy(struct vmmdev_softc *sc) { - struct vmmdev_softc *sc = arg; struct devmem_softc *dsc; int error __diagused; + /* + * Destroy all cdevs: + * + * - any new operations on the 'cdev' will return an error (ENXIO). + * + * - the 'devmem' cdevs are destroyed before the virtual machine 'cdev' + */ + SLIST_FOREACH(dsc, &sc->devmem, link) { + KASSERT(dsc->cdev != NULL, ("devmem cdev already destroyed")); + destroy_dev(dsc->cdev); + devmem_destroy(dsc); + } + vm_disable_vcpu_creation(sc->vm); error = vcpu_lock_all(sc); KASSERT(error == 0, ("%s: error %d freezing vcpus", __func__, error)); @@ -769,31 +781,16 @@ vmmdev_destroy(void *arg) } static int -sysctl_vmm_destroy(SYSCTL_HANDLER_ARGS) +vmmdev_lookup_and_destroy(const char *name, struct ucred *cred) { - struct devmem_softc *dsc; - struct vmmdev_softc *sc; struct cdev *cdev; - char *buf; - int error, buflen; - - error = vmm_priv_check(req->td->td_ucred); - if (error) - return (error); - - buflen = VM_MAX_NAMELEN + 1; - buf = malloc(buflen, M_VMMDEV, M_WAITOK | M_ZERO); - strlcpy(buf, "beavis", buflen); - error = sysctl_handle_string(oidp, buf, buflen, req); - if (error != 0 || req->newptr == NULL) - goto out; + struct vmmdev_softc *sc; mtx_lock(&vmmdev_mtx); - sc = vmmdev_lookup(buf); + sc = vmmdev_lookup(name); if (sc == NULL || sc->cdev == NULL) { mtx_unlock(&vmmdev_mtx); - error = EINVAL; - goto out; + return (EINVAL); } /* @@ -804,23 +801,28 @@ sysctl_vmm_destroy(SYSCTL_HANDLER_ARGS) sc->cdev = NULL; mtx_unlock(&vmmdev_mtx); - /* - * Destroy all cdevs: - * - * - any new operations on the 'cdev' will return an error (ENXIO). - * - * - the 'devmem' cdevs are destroyed before the virtual machine 'cdev' - */ - SLIST_FOREACH(dsc, &sc->devmem, link) { - KASSERT(dsc->cdev != NULL, ("devmem cdev already destroyed")); - destroy_dev(dsc->cdev); - devmem_destroy(dsc); - } destroy_dev(cdev); vmmdev_destroy(sc); - error = 0; -out: + return (0); +} + +static int +sysctl_vmm_destroy(SYSCTL_HANDLER_ARGS) +{ + char *buf; + int error, buflen; + + error = vmm_priv_check(req->td->td_ucred); + if (error) + return (error); + + buflen = VM_MAX_NAMELEN + 1; + buf = malloc(buflen, M_VMMDEV, M_WAITOK | M_ZERO); + strlcpy(buf, "beavis", buflen); + error = sysctl_handle_string(oidp, buf, buflen, req); + if (error == 0 && req->newptr != NULL) + error = vmmdev_lookup_and_destroy(buf, req->td->td_ucred); free(buf, M_VMMDEV); return (error); }