From nobody Sun May 19 00:59:41 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 4Vhj5p0CJHz5KMxj; Sun, 19 May 2024 00:59:42 +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 4Vhj5n6WRZz4Ccg; Sun, 19 May 2024 00:59:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716080381; 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=azIyx/ndEm9iHtwBQH+IQooeVSFPn9up6VByzyrheLc=; b=nCVxOqIH1eIkBNDbq8dmRRV7QvXkbJ/lnjxz+lhaHvkzulGcrbPhp6D+hHZGH1YN7lyS0d rtXrGj1kr6IFEQ7Zp/B0DMNAyaze5jE/hKLBN+r/kWzD9Zo5vC3Dr+1KrrQx0eYYwIT4I0 C/uCHut0Gx/Pe0+k1M9jfTOjJ5UswLloRtuRwE++2+zD6JZSl1qIVqwFTMjTY/TS9e2X6k MFcwFd0AQ5qamESwCMIuyoRiZh687qpk/mIbi2v2VWYdXN6Mg4VJOqicgAdT36a1ak+8tX +FPueSmKGN7sfimBIW+/aK9Yk9+CCkBnh1uUSl9MF8gBF5KAIWo/tNW2dTdlJQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716080381; a=rsa-sha256; cv=none; b=Ui6ab4+HGmBaF6ZKkp/vhrq17YqrZEXUHbfAgAAHiEwE8Sa5TCKXLkzQGvJGAKqoRkbhPT gfILkWdJJPVfKT9gR8bj2vlftvqHDrWbLAYW+7OZpEWdyMgZcRUeJgcpc4lh96bx1mNaih OQNww8Tf9AIRnBjj5eJn1xuCZmytK3qj+MuQ3p+NRxHLbRZI7oPosRNrvFHSmriaq+Uhps sb+1da7hsOt5Ga4LU/h5qjbxB5QOla9iJKvrhw5jSuSS19NKuOjfeGQ3jrVMRHAGvi/v8c Q/5HU7lV4YM/h+GTvn0pSg+ilYpJmAqjOFpoB6S+1C+9koLIvfQoXgUrUYV2GA== 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=1716080381; 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=azIyx/ndEm9iHtwBQH+IQooeVSFPn9up6VByzyrheLc=; b=gtLG8PeMsM83K/2RUr/feyy3eVbbcoocoI1diISuxu1tF5GOQtShQlYv18x/GcN7oSL5JJ s2oZoeg4MkKfeZzP+pnBXmr90q/1n5/pLX/EiKRb3mhNzn9mfdT0rFvCNXtlfg7/S3i4dg TSAcmTwHm145H282+5Fl7RvTlQIRvILfBmjNA8Dzha7rvhGET77m5k6nNkUx/V3CMCaSNb TrCEhTfqQ0zeXqvWJ1h8AhZXhrbToznotlNNX1CAZy+HAjCWIknLfi0Kj+JknYuILjATej cdRIzcb4zXlIfnPhUEvWrpRUPNVXpE8BzrdydtBL1pMLjd0mAM5qDu1h5s7qxQ== 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 4Vhj5n66RxzpML; Sun, 19 May 2024 00:59:41 +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 44J0xfFU080305; Sun, 19 May 2024 00:59:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44J0xfx3080301; Sun, 19 May 2024 00:59:41 GMT (envelope-from git) Date: Sun, 19 May 2024 00:59:41 GMT Message-Id: <202405190059.44J0xfx3080301@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: 2eeb0e9fc130 - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: 2eeb0e9fc1306f40ec684af1ea56a8871a9a3684 Auto-Submitted: auto-generated The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=2eeb0e9fc1306f40ec684af1ea56a8871a9a3684 commit 2eeb0e9fc1306f40ec684af1ea56a8871a9a3684 Author: Konstantin Belousov AuthorDate: 2024-05-07 13:23:28 +0000 Commit: Konstantin Belousov CommitDate: 2024-05-19 00:59:13 +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); }