From nobody Mon Oct 2 11:50:46 2023 X-Original-To: dev-commits-src-main@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 4RzfRB5kBgz4w0Rl; Mon, 2 Oct 2023 11:50:46 +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 4RzfRB4zCwz3HbS; Mon, 2 Oct 2023 11:50:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696247446; 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=zQLbI1o0wxbq+n9XEuyb6CkWdBPtJ0X3rxDQYA/j2j8=; b=acTZuUXM/PTZw1XxVhkk190h8yPcQFgyryX/raFIfo8YR98oguCaYpDOcb4wqpLwpSHKYW dEVxxQ9Owh4saTmQWxaFlOCYrRK+8vObYyXRERlKP/nqTIiEbLf3rGrHfnmbWZDWkVJjRZ cWh+iyNGMsKlNmO+pBoA5mXprvXvEF/FTN73OzpG+l4pBJA+332THdhaepcRhDI53nNaBB kDB4yKAmBDGDuWTD+kRdwKWX6RaJR9act94QV9FIfztdP5+GtOHIGkOvQfO2dhdehTDdwQ 4luyp/+taq01hhW0ixy484upbXKquoqYGiNf34fy01r9raU9Gshpn4+Xr7l59Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696247446; a=rsa-sha256; cv=none; b=BttS9IN0EpD/0NdN/mnmlPmPWIidI8B9/B6Gdq5S0kGYZ6kJkbiULoX/eK4ryidj3lUsDf FyI4HGDJebpaJUcXF6w3WCleEJnXyvyl9sR4RADbRcUGFDCA+d/md8OPRXboLLk1ZZq8Sd q4olw8m1q8y9m/hfrsf4foLYSugzP4oPeFtNYTeMQiPYXisgWJabY+e5J+YZ/7PLOVKOz0 x87geTo6gqysEPrKd6pcd6GfWO5aHA02d3fMz5O87oJ1bG+uLUJIgG2FVjt1aZyq5LFDSI 7N9YHbrZVz6969+fzjeGzUEi7FP05M0/51OpADwFGwgT9S7gBUPxCKu44OqCXQ== 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=1696247446; 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=zQLbI1o0wxbq+n9XEuyb6CkWdBPtJ0X3rxDQYA/j2j8=; b=DWeRYwDlmbVrokcK7VVrn8vCZuxHVL1sdiLLXCcDSzo9NBN2ksCg6YxD5cS3sQV/VyiDix 9uY9SSjnjLg32UdIQg61btjzV6AmpvVZQpbBEoPitHOZHtQzGVCqug0tvPEiUwEERMqfEy ELco9fp6bGwgpVkLBWHhRynlAsbCAFFSChdHpH1scLhfP9WtF+1ueXBSo5aLfGszFhnQCl rMwHT2YCz3LmVvgSBiGp23RpFvYB6rNHGMiF8iQruMvbifcf2xvDip/UMeQYbxMxScayKu yLp+d1fJXDrqK+XyEqvND04GvIAaLGdQdUcMWuFpfpvqzhE3hEMl4vVSIeElIQ== 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 4RzfRB43ZJz19R9; Mon, 2 Oct 2023 11:50:46 +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 392BokwM028390; Mon, 2 Oct 2023 11:50:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 392BokhA028387; Mon, 2 Oct 2023 11:50:46 GMT (envelope-from git) Date: Mon, 2 Oct 2023 11:50:46 GMT Message-Id: <202310021150.392BokhA028387@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: e61568aeeec7 - main - swap_pager: Fix a race in swap_pager_swapoff_object() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: e61568aeeec7667789e6c9d4837e074edecc990e Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=e61568aeeec7667789e6c9d4837e074edecc990e commit e61568aeeec7667789e6c9d4837e074edecc990e Author: Mark Johnston AuthorDate: 2023-10-02 11:49:27 +0000 Commit: Mark Johnston CommitDate: 2023-10-02 11:49:52 +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 --- 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 e548c2d16a0b..38151b3be96f 100644 --- a/sys/vm/swap_pager.c +++ b/sys/vm/swap_pager.c @@ -1890,8 +1890,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); /*