From nobody Sat Oct 26 12:59:59 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 4XbKW34tv0z5Zjyt; Sat, 26 Oct 2024 12:59:59 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XbKW341Qqz4H7m; Sat, 26 Oct 2024 12:59:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729947599; 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=P9SeMhLiRpP8TB8SSgj0MHrzGsYIyb7zm++jN56Yflw=; b=KZVkVUyMwsVrz+JujAr/v8d0h+kZIYQP+CXJr3dfTZZE8ej51CKeOK8YxqsIGHhktSqWkh 80HUzfwRPcB5vOMSf2FeYavelMWtbb6GCgJBkJq+f2Cpgvj6ofid3c52RhN1qEn1C1B8Di ypKSiUxyowt9432An9yNkuNwoVBvMeqKk55QmVHpIFE9kBDScwCliAQsRZDcWbGwSVx1bp LhxK2r+jmfye3BMBhVtipsAq3itiMy5fGnfc/KwDXm37EHIHpx0Y9xBCyyKt7gmkqPbl9E KK2wIFcHVM5qG2pWcq9Tqt19upOVE7Sg4wl8rZ1zH/3iyA7/pUdeV10wFpSGrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729947599; 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=P9SeMhLiRpP8TB8SSgj0MHrzGsYIyb7zm++jN56Yflw=; b=f30ekdsD/krOHS0Is6Ygo32f5JGDteLTsZogcsnTnSnlwJBLMdkrSNyHiMFgwUheRz4Z7+ 97IeC86wk3DWaCpxLEVifBvA8SmeIs3e2tolRW4AFmz1X/4HcR4kHAz0VE/1btjIdM0KNH beXTHthmEGrBCC2IVvOPkRInHQ3xQqaRpj4aNhH/a+S/i0XBR7IuT3/1aqjaagfbPMhSwQ RExN8/Xj7ugtLJdlRdCRD6qS1oDMF1TIRtQCKRN39fwZ0Hu+K+NCqju8fYmK+fV19wG+zJ POLoV2Ra+RX1F4ovOZHVaNQ2pRhQ6vcAK0OEVf+rgXu/WPkGph/4iAVjy+CJuQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729947599; a=rsa-sha256; cv=none; b=uU1HhjXctvvNz9Fqrmqp0r3vKarwLZzC8TLGpfDlS7Q+uLMZXOoYVP0prdOXEM6K9rtMdz 0oCzI/JHy0iQI7HmnG/hawcIAT6r7bgFRZHcdvmDUSBi3Hl5xUoCm3MftvZ/WmMCwwYmqV z0CAkZzwrUb7KpeL4eLp3se2H8SoWMP5XQT7FHlk9CCd5/092LpZfOKAUlURZW9EIj6NVu 3EOyE9wKeGCUgA1vTPWx8TvhewbS8wtDkZL0gN1hpC2LImndkTYMqsEKFnOApD1O9+ScYE v2mz2QBl8khiKTe/j6uSB+tpkgm/UU0uwneXWsQZPkC+dwmNf/Piiw9lbh3q0g== 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 4XbKW33N6xz19gH; Sat, 26 Oct 2024 12:59:59 +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 49QCxx7V062613; Sat, 26 Oct 2024 12:59:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49QCxxA8062610; Sat, 26 Oct 2024 12:59:59 GMT (envelope-from git) Date: Sat, 26 Oct 2024 12:59:59 GMT Message-Id: <202410261259.49QCxxA8062610@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: b947b53f0f9f - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: b947b53f0f9fc7a9ab265dfaf1548e1a1d96e2f3 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=b947b53f0f9fc7a9ab265dfaf1548e1a1d96e2f3 commit b947b53f0f9fc7a9ab265dfaf1548e1a1d96e2f3 Author: Mark Johnston AuthorDate: 2024-10-07 20:50:49 +0000 Commit: Mark Johnston CommitDate: 2024-10-26 12:58:50 +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 (cherry picked from commit c59166e5b4e8821556a3d23af7bd17ca556f2e22) --- 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 7c3083de42de..3713fe17dd13 100644 --- a/sys/vm/vm_page.c +++ b/sys/vm/vm_page.c @@ -4090,10 +4090,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 @@ -4102,7 +4105,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 @@ -4111,7 +4114,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)); @@ -4387,6 +4390,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));