From nobody Mon Oct 09 00:59:02 2023 X-Original-To: dev-commits-src-branches@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 4S3gdy6Vppz4wTj8; Mon, 9 Oct 2023 00:59:02 +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 4S3gdy5SmCz3LkP; Mon, 9 Oct 2023 00:59:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696813142; 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=kZ8rVBrMwDAgYKpWCDPn6tWfaK4w1r0BmOmB+lZYkYo=; b=hImUsidYkKvMJC79zXKr3ETZt/8qfr0vW3A83eDvHjbRkt/Y5porItUZtL72mU3rNMVnnO TFTyjGznIzJLXU9FzZIljq+O7PIL4xQM59DVejlYggfikwyDjItSQPmtH5aQaG/t0odMkA xphK3slw6+xZPD7Vs3CV/SmdylfvB7n2UO3u2X5KMKXt4GVYc5rW4aplRBEf8qSYUyApo8 W31mfShnk80qmD0jzJoQithvwnehQGGDRNcg+H23WPXizH8vlatEglxBa5gbtPjwHxll/J w5xqwGFBJX9+RN8jTRkh+MnWj8Eu78mgEnIfktnz8lIUhi+oWOOMuYFkIhD0pA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696813142; a=rsa-sha256; cv=none; b=be0l1xAsEZWH29L59sbbVmhn//DeSyo0fy8H7dH2uwdCGxZJEZJzZntDfVVjZ7Jkf+miOt yYInyqT/pUsN1pQrdpqjjADd5Q5gSQfKSQQJsU9MT/f8O+7iS4lTSrTxvn6tUxL0Zv/KAK 4TVx7OS91gj2ktJAzAkoLkh3ztDFmzSI6VQsFtOvasacnk6OQboq1YcwjZ8xWRCAzLctMn aLvexQWhe+Ji5BezEv9ITwDfaFCSxpK+7lelOyVD6LdUUqJBwoe5aUHAA7Wdd+eo2h+Bxz t+QZ7byW4T+eh/2bwMMAhuyVOvX8QH0GdNSzVXE6oTPRo6jNBrO0WOk2qHWx0w== 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=1696813142; 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=kZ8rVBrMwDAgYKpWCDPn6tWfaK4w1r0BmOmB+lZYkYo=; b=GEEr3hzvqMgc129IR5eFx7c+MEQYI/ZImpEl0CLfWF6ArOejtk4zMqbs0ovNErTjkmINZc r+qxo/QOYJEylKNf7uS0aA8wnmu8f8gxjHfospUryvxgs8vUL+GCQoG/UhNDdKaQJ6b9fk W3WYOntEPACO+68kkfPXT57qKU3ZqkCymCSZShNeVb/4MXZTWDmwuwSudOcIjv46bLraGf hwerGg0tEnfgi7p2oT15q9Z3NcuW9sZsJGf6ttsJlX62KNUcabhjB4tEuJhkiYj+wIKaa2 COmSBMTSmVkBxve24o9SUY7AMcPZ0ue/AvKwDEUWoJMaVcRv1nCP9DctOeaW7g== 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 4S3gdy4ZTHzbZZ; Mon, 9 Oct 2023 00:59:02 +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 3990x2Ju040504; Mon, 9 Oct 2023 00:59:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3990x2ZE040501; Mon, 9 Oct 2023 00:59:02 GMT (envelope-from git) Date: Mon, 9 Oct 2023 00:59:02 GMT Message-Id: <202310090059.3990x2ZE040501@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: d8cb6c173417 - stable/13 - swap_pager: Fix a race in swap_pager_swapoff_object() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/13 X-Git-Reftype: branch X-Git-Commit: d8cb6c173417f47b2337c12ab662a13c6e147789 Auto-Submitted: auto-generated The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=d8cb6c173417f47b2337c12ab662a13c6e147789 commit d8cb6c173417f47b2337c12ab662a13c6e147789 Author: Mark Johnston AuthorDate: 2023-10-02 11:49:27 +0000 Commit: Mark Johnston CommitDate: 2023-10-09 00:42:30 +0000 swap_pager: Fix a race in swap_pager_swapoff_object() When we disable swapping to a device, we scan the full VM object list looking for objects with swap trie nodes that reference the device in question. The pages corresponding to those nodes are paged in. While paging in, we drop the VM object lock. Moreover, we do not hold a reference for the object; swap_pager_swapoff_object() merely bumps the paging-in-progress counter. vm_object_terminate() waits for this counter to drain before proceeding and freeing pages. However, swap_pager_swapoff_object() decrements the counter before re-acquiring the VM object lock, which means that vm_object_terminate() can race to acquire the lock and free the pages. Then, swap_pager_swapoff_object() ends up unbusying a freed page. Fix the problem by acquiring the lock before waking up sleepers. PR: 273610 Reported by: Graham Perrin Reviewed by: kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D42029 (cherry picked from commit e61568aeeec7667789e6c9d4837e074edecc990e) --- sys/vm/swap_pager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c index 7e5fa90efd16..dd7fecc066c4 100644 --- a/sys/vm/swap_pager.c +++ b/sys/vm/swap_pager.c @@ -1897,8 +1897,8 @@ swap_pager_swapoff_object(struct swdevt *sp, vm_object_t object) if (rv != VM_PAGER_OK) panic("%s: read from swap failed: %d", __func__, rv); - vm_object_pip_wakeupn(object, 1); VM_OBJECT_WLOCK(object); + vm_object_pip_wakeupn(object, 1); vm_page_xunbusy(m); /*