From nobody Sun Sep 01 14:09:44 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 4WxYfw3xq9z5VGnN; Sun, 01 Sep 2024 14:09:44 +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 4WxYfw1PTPz4Qd5; Sun, 1 Sep 2024 14:09:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725199784; 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=SWcGKZsDMXGZ8ju+UCTOZlIicu/oKFKVKWTqN7tPIrk=; b=SJ4UErBF9jDGqGBBuTa6j+NfCpbRaSypObgx4WkR9ZWJWh87vFx9vr/+WqNQyAdNZcSx6K HQoedNjQ+UdfvUQ6GvwcM0Rphtx/De6QFnyXZou9omH84KiVeYwcpSxlKg8efvJCSVUpmH NXPGXlp5qEoC4SwXe6hue94Tc9kglx3c07uITZFged70MU4qJJcbZ1+EwMlck3IBDp3hZN KZvtJlqDD6zOviQnQWJeMY7C3wVSjrfI1k4z4cTsxa7KXb/imClsiOUU/rZ+znwnYYOX4L sBMn7T4SlqAbpUTfTcIdw5LBUspLjPjF9Gw6c1maup9f8xNwGeKZitYmhKu5Fw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725199784; a=rsa-sha256; cv=none; b=C8oXWfUtNULB0jasvKZyOF4zHgQFKALGmORs7fzPWAWR85sdtOdULQZl2CuqAc2qs4nxYL 4c4UNlXwTztUmeJfLVVRR7GidkJicNi4IGh8fD9VTzvqdBGfnGjxMoUix7gBiaBmh+OHVS CqY2eQ+0dIg9zGFP6UPRX+Wi0y4Xy4YZuGN3RZ3vBmodOpo5ou+mYZ64KIETVTSicYD3ip 2EN53gokA47w3JsKxqD2Fqm5O3ISZuR9T+xu9RbxfbszJZSe8mEWMh92+eMaLuXPOtBaFR USVxEIWLeDGEzhIy7r5TUQW59nSs7RmLUoGJIAeaYaWTnTiX4bdgetAbQUntwQ== 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=1725199784; 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=SWcGKZsDMXGZ8ju+UCTOZlIicu/oKFKVKWTqN7tPIrk=; b=e7ZIWspJDtSJ6j1oShc0z93wRB9Jv1oVlQcGGVNuwqnQ5feSNiC+D3UCy9hMeWBNz28UG2 HzZDVa/J65dR856gPRXUsSphFYOyg2NkPlUE2s1TFisj62dYJLqYq+syS2c8ft175q6Hbm Ohx0cT3VJaDUEtPRBA3eDk7/VDW9vjN4qmsq46c5BLsJf193o34JvEwmbnb3KXCzymqoGQ 9Oh1/aoWhnrazWDqC/yFB0B8IGo+9OatS4OgUVQzlB9bgd0PDrFkJ6lTKs5ZYvOH0NW3aW 0gKHAa9Z8GFZnrut+fOUEG/P0Xb+lweldSygZIjQ8J/Qth8F1FiAaWozbkhDrQ== 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 4WxYfw0zBQzX4m; Sun, 1 Sep 2024 14:09:44 +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 481E9ifg099704; Sun, 1 Sep 2024 14:09:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 481E9ixt099701; Sun, 1 Sep 2024 14:09:44 GMT (envelope-from git) Date: Sun, 1 Sep 2024 14:09:44 GMT Message-Id: <202409011409.481E9ixt099701@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: 887c0877a642 - main - vmm: Use an sx lock for vmmdev_mtx 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: 887c0877a642c7427aff0cfd0d844b2711e71e1e Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=887c0877a642c7427aff0cfd0d844b2711e71e1e commit 887c0877a642c7427aff0cfd0d844b2711e71e1e Author: Mark Johnston AuthorDate: 2024-09-01 14:00:36 +0000 Commit: Mark Johnston CommitDate: 2024-09-01 14:03:16 +0000 vmm: Use an sx lock for vmmdev_mtx This will make it easier to atomically create the device file and set its si_drv1 member. Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D46487 --- sys/dev/vmm/vmm_dev.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/sys/dev/vmm/vmm_dev.c b/sys/dev/vmm/vmm_dev.c index b4ae2997006f..91d33ccba261 100644 --- a/sys/dev/vmm/vmm_dev.c +++ b/sys/dev/vmm/vmm_dev.c @@ -13,9 +13,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -63,8 +63,8 @@ struct vmmdev_softc { static SLIST_HEAD(, vmmdev_softc) head; static unsigned pr_allow_flag; -static struct mtx vmmdev_mtx; -MTX_SYSINIT(vmmdev_mtx, &vmmdev_mtx, "vmm device mutex", MTX_DEF); +static struct sx vmmdev_mtx; +SX_SYSINIT(vmmdev_mtx, &vmmdev_mtx, "vmm device mutex"); static MALLOC_DEFINE(M_VMMDEV, "vmmdev", "vmmdev"); @@ -156,7 +156,7 @@ vmmdev_lookup(const char *name, struct ucred *cred) { struct vmmdev_softc *sc; - mtx_assert(&vmmdev_mtx, MA_OWNED); + sx_assert(&vmmdev_mtx, SA_XLOCKED); SLIST_FOREACH(sc, &head, link) { if (strcmp(name, vm_name(sc->vm)) == 0) @@ -785,9 +785,9 @@ vmmdev_destroy(struct vmmdev_softc *sc) crfree(sc->ucred); if ((sc->flags & VSC_LINKED) != 0) { - mtx_lock(&vmmdev_mtx); + sx_xlock(&vmmdev_mtx); SLIST_REMOVE(&head, sc, vmmdev_softc, link); - mtx_unlock(&vmmdev_mtx); + sx_xunlock(&vmmdev_mtx); } free(sc, M_VMMDEV); @@ -799,10 +799,10 @@ vmmdev_lookup_and_destroy(const char *name, struct ucred *cred) struct cdev *cdev; struct vmmdev_softc *sc; - mtx_lock(&vmmdev_mtx); + sx_xlock(&vmmdev_mtx); sc = vmmdev_lookup(name, cred); if (sc == NULL || sc->cdev == NULL) { - mtx_unlock(&vmmdev_mtx); + sx_xunlock(&vmmdev_mtx); return (EINVAL); } @@ -812,7 +812,7 @@ vmmdev_lookup_and_destroy(const char *name, struct ucred *cred) */ cdev = sc->cdev; sc->cdev = NULL; - mtx_unlock(&vmmdev_mtx); + sx_xunlock(&vmmdev_mtx); destroy_dev(cdev); vmmdev_destroy(sc); @@ -874,9 +874,9 @@ vmmdev_create(const char *name, struct ucred *cred) struct vm *vm; int error; - mtx_lock(&vmmdev_mtx); + sx_xlock(&vmmdev_mtx); sc = vmmdev_lookup(name, cred); - mtx_unlock(&vmmdev_mtx); + sx_xunlock(&vmmdev_mtx); if (sc != NULL) return (EEXIST); @@ -890,16 +890,16 @@ vmmdev_create(const char *name, struct ucred *cred) * Lookup the name again just in case somebody sneaked in when we * dropped the lock. */ - mtx_lock(&vmmdev_mtx); + sx_xlock(&vmmdev_mtx); sc2 = vmmdev_lookup(name, cred); if (sc2 != NULL) { - mtx_unlock(&vmmdev_mtx); + sx_xunlock(&vmmdev_mtx); vmmdev_destroy(sc); return (EEXIST); } sc->flags |= VSC_LINKED; SLIST_INSERT_HEAD(&head, sc, link); - mtx_unlock(&vmmdev_mtx); + sx_xunlock(&vmmdev_mtx); error = make_dev_p(MAKEDEV_CHECKNAME, &cdev, &vmmdevsw, sc->ucred, UID_ROOT, GID_WHEEL, 0600, "vmm/%s", name); @@ -908,10 +908,10 @@ vmmdev_create(const char *name, struct ucred *cred) return (error); } - mtx_lock(&vmmdev_mtx); + sx_xlock(&vmmdev_mtx); sc->cdev = cdev; sc->cdev->si_drv1 = sc; - mtx_unlock(&vmmdev_mtx); + sx_xunlock(&vmmdev_mtx); return (0); } @@ -1019,10 +1019,10 @@ devmem_create_cdev(struct vmmdev_softc *sc, int segid, char *devname) dsc = malloc(sizeof(struct devmem_softc), M_VMMDEV, M_WAITOK | M_ZERO); - mtx_lock(&vmmdev_mtx); + sx_xlock(&vmmdev_mtx); if (sc->cdev == NULL) { /* virtual machine is being created or destroyed */ - mtx_unlock(&vmmdev_mtx); + sx_xunlock(&vmmdev_mtx); free(dsc, M_VMMDEV); destroy_dev_sched_cb(cdev, NULL, 0); return (ENODEV); @@ -1033,7 +1033,7 @@ devmem_create_cdev(struct vmmdev_softc *sc, int segid, char *devname) dsc->cdev = cdev; dsc->sc = sc; SLIST_INSERT_HEAD(&sc->devmem, dsc, link); - mtx_unlock(&vmmdev_mtx); + sx_xunlock(&vmmdev_mtx); /* The 'cdev' is ready for use after 'si_drv1' is initialized */ cdev->si_drv1 = dsc;