From nobody Mon Oct 9 00:58:54 2023 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 4S3gdp6TChz4wTZ0; Mon, 9 Oct 2023 00:58:54 +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 4S3gdp5yc8z3LBm; Mon, 9 Oct 2023 00:58:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696813134; 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=RWfukQify4CTiLOLLAJYaRRn4O1pKHoWCCQoImr/cVQ=; b=OIIbsFe28J/D3oAq3mw429z7TLEy5JcYs43eGjVTFEcquo1XkeG73RIJwTBqZp68n05vrD IZGO4xa7flQo2Qj9+CIQQ/rSbTQsOlGw7UOxN+0BvUlHcESk0OXQrPBuU7SohkrzckbrsH EXasRcP86TqqUcah8eUu/zCjPrFnT9ZVAyNdjLSAQj4X6mCw4MhY8MwzmAJV3iGsnJVidM fNXtdU7m95nNPXE8PhmbBy+a/wp4aJ1klGBzYKuLRjMW1mdOaDTWv4DzEJyyK9aqZe4+J0 eJPdLbBV8asJ0gbHiL4DMYnx3U50LabQnt83KU3KqqCNkt42usjxIrdE0mMcYg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696813134; a=rsa-sha256; cv=none; b=Lapwx51BEYITpGXlFSpJKsWVi0fcVVo15dVYxJCNbxAZus56r2DWYDyXDUoCWdHkm5kaD0 a7Qfdw3Car7Tsmw3D6m4SyCPiioqAUlnzMZ2c8ZMpXuIW62e/YV7smszDePotEWfk9U16A Fhxb3YA+m3IUIzz7PwYGiyXByZAiOKXo5L3ONBjxdz+RN9IJ+SlRU6GG0r6QGDClKmZVt8 F2ZhTs3693vZatVongfG//GgH9MKgdsXng7fdS0EJpys+/hjZzrVYJcbS8cLNd3YGTJ/Sd CAGY9YNOxp7N+DeIvzfmPIr7bVkT7G2p9nXGJqZLtScL/b0cYYvSm9Dks+P3TA== 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=1696813134; 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=RWfukQify4CTiLOLLAJYaRRn4O1pKHoWCCQoImr/cVQ=; b=p7xOwpMWRlZplboR4Uf1IfHs1+9x0rN2Kt9yAAGiqUSlULFneatUDZ6/aslhB8Hcfs3Xah Vp/CKGtCm9n1dnCMXe8CZZTijNt3aEob3aNLOGMyweXpQWl32VHbmSWVwZIOYEGjzjZYPO ExySxoJfR8BPPZI16166T2zDdgKfoKPfuFf79wpKKQsThZAjbcSmUkOjZEo37chJpW/iXk cF883ydyWWzyT4Gz693OILHBRR19rc3ShmxyBYsCQAhR973hkhcE62WPmYnklaeAABLmPe mjO96l57xWF0fWfopQ4BR4shAfqH+63BusvqtUnNnJFnzWR6cwHLP/s2wNq5jQ== 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 4S3gdp53fKzb9T; Mon, 9 Oct 2023 00:58:54 +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 3990wsJ1040213; Mon, 9 Oct 2023 00:58:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3990wsmr040210; Mon, 9 Oct 2023 00:58:54 GMT (envelope-from git) Date: Mon, 9 Oct 2023 00:58:54 GMT Message-Id: <202310090058.3990wsmr040210@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: aa229a59adea - stable/14 - swap_pager: Fix a race in swap_pager_swapoff_object() 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: 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: aa229a59adeaf49517183c8117a239e2b68012f5 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=aa229a59adeaf49517183c8117a239e2b68012f5 commit aa229a59adeaf49517183c8117a239e2b68012f5 Author: Mark Johnston AuthorDate: 2023-10-02 11:49:27 +0000 Commit: Mark Johnston CommitDate: 2023-10-09 00:41:35 +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 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); /*