From nobody Mon Oct 07 20:52:32 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 4XMrv52XSpz5YSGv; Mon, 07 Oct 2024 20:52:33 +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 4XMrv50sPLz544J; Mon, 7 Oct 2024 20:52:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728334353; 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=XXX91/icJctssQFaVf43GXa9efLBPmpUAuLlJ2Cn/ts=; b=Eq/LHf9+j2qYBR2XTufrMMDNbuakYoI69OYy0hwyZX78cVY0XlMW3kdrl1FtObXYRqysEH h79AakC+fmKb4aNLOPD0GsuTopLEokOQWY1tBKMJdyZUfPk4qELC45s5hZXGH45qk2Ud2j uUBj5c1JEMR6gRjgvEvuy8G08qbOLmOiEW1MGaY+WK0HZp14rcPn2UEs+opKxpRrILnYR5 LoujRFGuXaVRwpCFhgirLUQrC9HQPWvOBzHBjtxTunIZ3Kz7u5tSBw87BgNuekAF38vsBf oWNewc4F/1whJmeA+EDf0dJ0OKn3PzE5rUWxYoT/wkVbhZ9Ell/0/M3e+nKCcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728334353; 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=XXX91/icJctssQFaVf43GXa9efLBPmpUAuLlJ2Cn/ts=; b=pqI+aS9dgnVwUv0MNR6AG0MEKdo+RJO3P03UtOwIdZ1VEi2v7/ZQlg1SbYloUdIyiPogSx lEhR9ZSnWLWAathIthGBvB5YOB1+R0Wx9AYBN13CZgwCTpzP+YQuj7OD5N5C6VywG+OGB+ cVawPS3GFiOru9JqSPqtlaEwbSrh+yuwy16GzBLXgAEjCrHq1MfB0JedvziV062uM/+Uc4 RYV8PbAb7p8dFasmNqlsilCINdGPHnJX1TDVDxMZNelPoegAg89DPWwggaot90d0nX1oVn E6pw8qpbNrg1O3vVwr0/ne/GrV1bPaaFdClaAk2qVSZJjXYAqDi1K+rwE6+r5w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728334353; a=rsa-sha256; cv=none; b=jkVznV6wVqvDJmQrNfAmE04PjQ7nvzH3i6h0EoWZ0WXbDoRU2Oui4EAP6jGET3ZMR/6ts6 f7jqC8meVQfQqGF6ayc8stDv0LgTwxKw7puUXmlkh/R3+DPSNRlPLCrasd+2cunEt2pRXA nvA+gtZaEZdBH2DOHE2tsC9zCmeLRNFvtOFE99d/E6aC3tjQ4DRQh4xuLfjQTp9bTR7GQM 8iuAn2dd8lEg4j7nkyaWMlGvKNXs71U8GgtpQX+4Pn7zCQ03wPTsuuKMK2LxLopKVq2ue5 fL68AwCDY0vZmkfNpMlQEr7VpKQXpiYsnATHJ6LWXtZfbHwONnFLvZU9V9XcPg== 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 4XMrv5092Tz12Tc; Mon, 7 Oct 2024 20:52:33 +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 497KqWpr011369; Mon, 7 Oct 2024 20:52:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 497KqWVR011366; Mon, 7 Oct 2024 20:52:32 GMT (envelope-from git) Date: Mon, 7 Oct 2024 20:52:32 GMT Message-Id: <202410072052.497KqWVR011366@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: c59166e5b4e8 - main - vm_page: Fix a logic bug in vm_page_unwire_managed() 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c59166e5b4e8821556a3d23af7bd17ca556f2e22 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=c59166e5b4e8821556a3d23af7bd17ca556f2e22 commit c59166e5b4e8821556a3d23af7bd17ca556f2e22 Author: Mark Johnston AuthorDate: 2024-10-07 20:50:49 +0000 Commit: Mark Johnston CommitDate: 2024-10-07 20:52:15 +0000 vm_page: Fix a logic bug in vm_page_unwire_managed() When releasing a page reference, we have logic for various cases, based on the value of the counter. But, the implementation fails to take into account the possibility that the VPRC_BLOCKED flag is set, which is ORed into the counter for short windows when removing mappings of a page. If the flag is set while the last reference is being released, we may fail to add the page to a page queue when the last wiring reference is released. Fix the problem by performing comparisons with VPRC_BLOCKED masked off. While here, add a related assertion. Reviewed by: dougm, kib Tested by: pho MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D46944 --- sys/vm/vm_page.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c index 3a8d8d137dc1..1f0b364dbde2 100644 --- a/sys/vm/vm_page.c +++ b/sys/vm/vm_page.c @@ -4275,10 +4275,13 @@ vm_page_unwire_managed(vm_page_t m, uint8_t nqueue, bool noreuse) */ old = atomic_load_int(&m->ref_count); do { + u_int count; + KASSERT(VPRC_WIRE_COUNT(old) > 0, ("vm_page_unwire: wire count underflow for page %p", m)); - if (old > VPRC_OBJREF + 1) { + count = old & ~VPRC_BLOCKED; + if (count > VPRC_OBJREF + 1) { /* * The page has at least one other wiring reference. An * earlier iteration of this loop may have called @@ -4287,7 +4290,7 @@ vm_page_unwire_managed(vm_page_t m, uint8_t nqueue, bool noreuse) */ if ((vm_page_astate_load(m).flags & PGA_DEQUEUE) == 0) vm_page_aflag_set(m, PGA_DEQUEUE); - } else if (old == VPRC_OBJREF + 1) { + } else if (count == VPRC_OBJREF + 1) { /* * This is the last wiring. Clear PGA_DEQUEUE and * update the page's queue state to reflect the @@ -4296,7 +4299,7 @@ vm_page_unwire_managed(vm_page_t m, uint8_t nqueue, bool noreuse) * clear leftover queue state. */ vm_page_release_toq(m, nqueue, noreuse); - } else if (old == 1) { + } else if (count == 1) { vm_page_aflag_clear(m, PGA_DEQUEUE); } } while (!atomic_fcmpset_rel_int(&m->ref_count, &old, old - 1)); @@ -4572,6 +4575,8 @@ vm_page_try_blocked_op(vm_page_t m, void (*op)(vm_page_t)) do { KASSERT(old != 0, ("vm_page_try_blocked_op: page %p has no references", m)); + KASSERT((old & VPRC_BLOCKED) == 0, + ("vm_page_try_blocked_op: page %p blocks wirings", m)); if (VPRC_WIRE_COUNT(old) != 0) return (false); } while (!atomic_fcmpset_int(&m->ref_count, &old, old | VPRC_BLOCKED));