From nobody Sun May 19 00:58:25 2024 X-Original-To: dev-commits-src-all@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 4Vhj4K65vbz5KMkx; Sun, 19 May 2024 00:58:25 +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 4Vhj4K5Vtpz49Xk; Sun, 19 May 2024 00:58:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716080305; 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=TohgD0pIxxTihrb2AUCtCYxGjtIdIWHkLeTOE23Bqvg=; b=G+sVQ9L8gMfXOaBJ3cjAQIh/Y3LPE3v482byGvLxVs/77+Ip1Ve+mWpDjnjkNQT109mV0f D3LnKtfFShaZh2UJbeakUL5qZKFTNk9rjek97p3Fkj22StPXu+Qc+L/jsisNBPFSugWyRO G/nie3uA19AditOMJWZSOj7pc3u+vRNkGzEYXx0cQf9dYZhPPu6D+Z/LX7Yu/Fso6Jo388 wooFJLyZiTAlbersanoxoDouOqkie6XCFIkKveGnB+0OQiex3e//5Lnx+3Nk3J6vUeF8Jz BYv4NHpx7owpVYdgIJMSNh8VcUCLfRZs4GDSoz4mPum1OSUcjAE6omlf0tAcgQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716080305; a=rsa-sha256; cv=none; b=vHaitg2ZC/wF+7MSuF1sUueOgA0NTDDuU0Jp2jMOB0cnJ1Fb84eOAlw7ipKyx7VOa1gWPJ MBHAHHr9eov+kc3n71nrnM+AVN0inzD9yPA+zRlGOsvBVSPtAytAA6IylkywDnAR+xs4Do AmV1qKh7+xyM2Nd7F9VJjxvkhSeLCIl6ex7d2CF7UVhMelVuXF52MdtWxYe1DOv0v7NpGL 9SDzO82jDkQw5eee1duc2VFA8+Iste/kTMGYlStBpqhAw99NN6eVRt46U2skU51eBvh7XR RipeDQLJfWI1BtnHdKv7jpNDcwHJud4pP68qsEAk6/7USndT/e078fqy+KLywA== 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=1716080305; 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=TohgD0pIxxTihrb2AUCtCYxGjtIdIWHkLeTOE23Bqvg=; b=GObXTBRZo6QB+wsvx3n+dQzj772Ak45ExUVC5axi/oUMTfyGsN2Q5FWtisUSxahJVIo6BN OPrhGO9GLz2viZggm2RRTzLSqzZDhy2+sV1xOkK3SFUfc1EdnzCKn0kjAf12wpSW9XmYwv 3/kfP/yb7/5wRnSUUNjjyFx00MO3/bQO3XWmtnAKcOsik3tpfC53hO0v4Mhjuec6NhvNKo /KamFQevSwjX3FUdl20vLGvUqxI0l+ZDkTyntDt9RzOSt/cDQYsHeS4HxdrOlt00H02ss8 9xaBYEWPw7po8zqoCpTdSzHjxlFX3garWEvgt1RO1aR/+eRJcZb4WSucNP0+LA== 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 4Vhj4K55hhzpGP; Sun, 19 May 2024 00:58:25 +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 44J0wPZS079728; Sun, 19 May 2024 00:58:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44J0wPb9079725; Sun, 19 May 2024 00:58:25 GMT (envelope-from git) Date: Sun, 19 May 2024 00:58:25 GMT Message-Id: <202405190058.44J0wPb9079725@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 4018bcdea8e1 - stable/14 - cdev_pager_allocate(): ensure that the cdev_pager_ops ctr is called only once List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 4018bcdea8e1934eedba4b800e6feb2099b1091d Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=4018bcdea8e1934eedba4b800e6feb2099b1091d commit 4018bcdea8e1934eedba4b800e6feb2099b1091d Author: Konstantin Belousov AuthorDate: 2024-05-07 13:23:28 +0000 Commit: Konstantin Belousov CommitDate: 2024-05-19 00:57:54 +0000 cdev_pager_allocate(): ensure that the cdev_pager_ops ctr is called only once PR: 278826 (cherry picked from commit e93404065177d6c909cd64bf7d74fe0d8df35edf) --- sys/vm/device_pager.c | 70 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 19 deletions(-) diff --git a/sys/vm/device_pager.c b/sys/vm/device_pager.c index 2d8f003c6f92..cb3b0e522d9a 100644 --- a/sys/vm/device_pager.c +++ b/sys/vm/device_pager.c @@ -118,8 +118,15 @@ cdev_pager_lookup(void *handle) { vm_object_t object; +again: mtx_lock(&dev_pager_mtx); object = vm_pager_object_lookup(&dev_pager_object_list, handle); + if (object != NULL && object->un_pager.devp.dev == NULL) { + msleep(&object->un_pager.devp.dev, &dev_pager_mtx, + PVM | PDROP, "cdplkp", 0); + vm_object_deallocate(object); + goto again; + } mtx_unlock(&dev_pager_mtx); return (object); } @@ -129,9 +136,8 @@ cdev_pager_allocate(void *handle, enum obj_type tp, const struct cdev_pager_ops *ops, vm_ooffset_t size, vm_prot_t prot, vm_ooffset_t foff, struct ucred *cred) { - vm_object_t object, object1; + vm_object_t object; vm_pindex_t pindex; - u_short color; if (tp != OBJT_DEVICE && tp != OBJT_MGTDEVICE) return (NULL); @@ -157,16 +163,16 @@ cdev_pager_allocate(void *handle, enum obj_type tp, pindex < OFF_TO_IDX(size)) return (NULL); - if (ops->cdev_pg_ctor(handle, size, prot, foff, cred, &color) != 0) - return (NULL); +again: mtx_lock(&dev_pager_mtx); /* * Look up pager, creating as necessary. */ - object1 = NULL; object = vm_pager_object_lookup(&dev_pager_object_list, handle); if (object == NULL) { + vm_object_t object1; + /* * Allocate object and associate it with the pager. Initialize * the object's pg_color based upon the physical address of the @@ -174,15 +180,19 @@ cdev_pager_allocate(void *handle, enum obj_type tp, */ mtx_unlock(&dev_pager_mtx); object1 = vm_object_allocate(tp, pindex); - object1->flags |= OBJ_COLORED; - object1->pg_color = color; - object1->handle = handle; - object1->un_pager.devp.ops = ops; - object1->un_pager.devp.dev = handle; - TAILQ_INIT(&object1->un_pager.devp.devp_pglist); mtx_lock(&dev_pager_mtx); object = vm_pager_object_lookup(&dev_pager_object_list, handle); if (object != NULL) { + object1->type = OBJT_DEAD; + vm_object_deallocate(object1); + object1 = NULL; + if (object->un_pager.devp.dev == NULL) { + msleep(&object->un_pager.devp.dev, + &dev_pager_mtx, PVM | PDROP, "cdplkp", 0); + vm_object_deallocate(object); + goto again; + } + /* * We raced with other thread while allocating object. */ @@ -194,29 +204,51 @@ cdev_pager_allocate(void *handle, enum obj_type tp, KASSERT(object->un_pager.devp.ops == ops, ("Inconsistent devops %p %p", object, ops)); } else { + u_short color; + object = object1; object1 = NULL; object->handle = handle; + object->un_pager.devp.ops = ops; + TAILQ_INIT(&object->un_pager.devp.devp_pglist); TAILQ_INSERT_TAIL(&dev_pager_object_list, object, pager_object_list); + mtx_unlock(&dev_pager_mtx); if (ops->cdev_pg_populate != NULL) vm_object_set_flag(object, OBJ_POPULATE); + if (ops->cdev_pg_ctor(handle, size, prot, foff, + cred, &color) != 0) { + mtx_lock(&dev_pager_mtx); + TAILQ_REMOVE(&dev_pager_object_list, object, + pager_object_list); + wakeup(&object->un_pager.devp.dev); + mtx_unlock(&dev_pager_mtx); + object->type = OBJT_DEAD; + vm_object_deallocate(object); + object = NULL; + mtx_lock(&dev_pager_mtx); + } else { + mtx_lock(&dev_pager_mtx); + object->flags |= OBJ_COLORED; + object->pg_color = color; + object->un_pager.devp.dev = handle; + wakeup(&object->un_pager.devp.dev); + } } + MPASS(object1 == NULL); } else { + if (object->un_pager.devp.dev == NULL) { + msleep(&object->un_pager.devp.dev, + &dev_pager_mtx, PVM | PDROP, "cdplkp", 0); + vm_object_deallocate(object); + goto again; + } if (pindex > object->size) object->size = pindex; KASSERT(object->type == tp, ("Inconsistent device pager type %p %d", object, tp)); } mtx_unlock(&dev_pager_mtx); - if (object1 != NULL) { - object1->handle = object1; - mtx_lock(&dev_pager_mtx); - TAILQ_INSERT_TAIL(&dev_pager_object_list, object1, - pager_object_list); - mtx_unlock(&dev_pager_mtx); - vm_object_deallocate(object1); - } return (object); }