From nobody Fri Oct 11 17:48:19 2024 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 4XQDch1DkPz5ZBdQ; Fri, 11 Oct 2024 17:48:20 +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 4XQDch0l7Dz3xZL; Fri, 11 Oct 2024 17:48:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728668900; 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=TmiDNzRjtgm8A6dCFwG5rgO6SlchpS/AJM+uTQsZS4A=; b=iDsO5TirZJjpbr9OCwaxLmIeX54cYC+43pSHLsDmXXs1mVN5RemeDEGhb6rB0QctW67svZ EUu2WUfzFYtG+8N7RNYZNdkCH5CEeHsVHO3QnNclAniIot3WgbIhpnlHyZxI4NDdu81trd HlMfBXmTGbHiKuAPzzkUmS5SFiPKc1qHQQPBiczAnnFskH3q8//qoLmGLio3Gnm9Dsdnta DK4d8wE1psfyDkkLsTdPuovb9Lk6yvNirXqL+xFozP23H3WOfVeCLCZ77YNKY9JuX5/HgU HBdqPjA5XA+UmmPEjh+vyoIsa3DV1yjx6V8Av7IUwvL+lxa6RZzo4Os3wC+X2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728668900; 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=TmiDNzRjtgm8A6dCFwG5rgO6SlchpS/AJM+uTQsZS4A=; b=YrK2XSua22SgUU9W/nnmf9/9kHkLjjXwRclpNCsRISaoVzOpQUYrlQbl2AVFKYZ5nxfgdd GqPEVogxDmqFDeBFkwjZgUlvkDnMYL7p74eW6sZVICI06CwxteaqmQoVU62SRZbWU2mK0E 8NW7EIxXJvvAUS3gUauNGj5esjSFhGMfe1tqQMwJzElfHyhWDsVjyVAM5bPivG7rnAf9Uu dm+hKXdPenBCSrM/wDCEvhM1a0LaKXTNrZTy3jmrnquzg/SHgD89xijdkVLR2eoDGohsEH 3cPOuP+6+qi6+eJfknO+U9SPkivyiG7vkYlLuHpOXlDFuYWc8stidFe4+AkAVQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728668900; a=rsa-sha256; cv=none; b=mo0fapiSjHClqIhR+l+Efv14by3eCMa8u2ViGc30trkLo56bQEd7pD6I7P98x0RsLKdFcT rAeB4aqm0BZjgkRp8InXio43q432zjFphx2QLa8Lozu9k+Q91CjTEWBnnqEB1eIo/Ty7wK lCzegaTqP63/+zkHEdJcz0t0p8gVgtT4oPzWmkBdf/HwmPWrmrDhG+aZv2/rgHKim2MxwP nrUQ470lEygEvCfK3m7TWJeTs6bWm0RxhYSix3zapFrGkU5XLkVFzyy/LEpIuVKfFJjvWi VYf2Zn5GcPC2dFj/GqhZ4z05gCb7h0ySH3/SPFSAcbIcqTfbP94t059Uh+RhBA== 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 4XQDch09twzrD9; Fri, 11 Oct 2024 17:48:20 +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 49BHmJRL077035; Fri, 11 Oct 2024 17:48:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49BHmJAp077032; Fri, 11 Oct 2024 17:48:19 GMT (envelope-from git) Date: Fri, 11 Oct 2024 17:48:19 GMT Message-Id: <202410111748.49BHmJAp077032@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Doug Moore Subject: git: 1107834090be - main - swap_pager: swapoff detecting object death 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dougm X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1107834090be4df01070028f6a8cdb37ff1f51f1 Auto-Submitted: auto-generated The branch main has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=1107834090be4df01070028f6a8cdb37ff1f51f1 commit 1107834090be4df01070028f6a8cdb37ff1f51f1 Author: Doug Moore AuthorDate: 2024-10-11 17:45:54 +0000 Commit: Doug Moore CommitDate: 2024-10-11 17:45:54 +0000 swap_pager: swapoff detecting object death In swap_pager_swapoff_object, the object is initially not dead, and can only become dead while the object lock is not held. Move the test for object-death so that it is right after the early loop-break that happens after lock re-acquisition, and before the iterator is re-initialized, which fails an assertion when the object is dead, and not swap. Addresses a problem produced in testing by @pho and diagnosed by @kib. Reported by: pho Reviewed by: alc, kib Differential Revision: https://reviews.freebsd.org/D47064 --- sys/vm/swap_pager.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c index f4db46a32dee..23b5e1c34b07 100644 --- a/sys/vm/swap_pager.c +++ b/sys/vm/swap_pager.c @@ -1910,6 +1910,8 @@ swap_pager_swapoff_object(struct swdevt *sp, vm_object_t object) VM_OBJECT_ASSERT_WLOCKED(object); KASSERT((object->flags & OBJ_SWAP) != 0, ("%s: Object not swappable", __func__)); + KASSERT((object->flags & OBJ_DEAD) == 0, + ("%s: Object already dead", __func__)); KASSERT((sp->sw_flags & SW_CLOSING) != 0, ("%s: Device not blocking further allocations", __func__)); @@ -1917,15 +1919,6 @@ swap_pager_swapoff_object(struct swdevt *sp, vm_object_t object) swp_pager_init_freerange(&range); sb = swblk_iter_init(&blks, object, 0); while (sb != NULL) { - if ((object->flags & OBJ_DEAD) != 0) { - /* - * Make sure that pending writes finish before - * returning. - */ - vm_object_pip_wait(object, "swpoff"); - swp_pager_meta_free_all(object); - break; - } sb_empty = true; for (i = 0; i < SWAP_META_PAGES; i++) { /* Skip an invalid block. */ @@ -1983,8 +1976,21 @@ swap_pager_swapoff_object(struct swdevt *sp, vm_object_t object) } if (i < SWAP_META_PAGES) { /* - * With the object lock released and regained, the - * swapblk could have been freed, so reset the pages + * The object lock has been released and regained. + * Perhaps the object is now dead. + */ + if ((object->flags & OBJ_DEAD) != 0) { + /* + * Make sure that pending writes finish before + * returning. + */ + vm_object_pip_wait(object, "swpoff"); + swp_pager_meta_free_all(object); + break; + } + + /* + * The swapblk could have been freed, so reset the pages * iterator and search again for the first swblk at or * after blks.index. */