From nobody Tue Sep 29 11:54:40 2026 Received: from mail-wm2-f10.google.com (mail-wm2-f10.google.com [74.125.225.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 670F43BE62B for ; Sat, 8 Aug 2026 10:14:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786184080; cv=none; b=vCt4CoEvEw5/lnSVyMbFWVsOwBmONJwaw+L6BnbWteUSYIF2+oTiARZpIuFp3QUsUoju2b3fF0qiVgObm9b/7qq3ofSCtIHKbIJa4Kv4AV6NeajT+WiyCUqjutVptZAycyXOhwY+tSeCRGgMvuJo8/lKZpy+54QasuDR2Ie3yiY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786184080; c=relaxed/simple; bh=ezVHSw/zd/jzJMkbUtiVL1M284PL194y/noeVMwFtyk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=d3dEZDFuO5yzifDIlYokk2Y8W6+LzA+9Bwt2iZF9h94EG4B2/dPKZEWjWA26nWblFQiD8+zgGyFA/JwJR4fMAhyLmeUAOYpReOnF2mtUZ6BsnSdeviDA8AqgxL84y8c8l4CBZZ6JGhCH0vNjKQTGjVE/MqvzJfNz+OjeCp+0+4o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bargrove.com; spf=pass smtp.mailfrom=bargrove.com; dkim=pass (1024-bit key) header.d=bargrove.com header.i=@bargrove.com header.b=LIWlkPP5; arc=none smtp.client-ip=74.125.225.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bargrove.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bargrove.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=bargrove.com header.i=@bargrove.com header.b="LIWlkPP5" Received: by mail-wm2-f10.google.com with SMTP id 5b1f17b1804b1-495459712d2so271745e9.1 for ; Sat, 08 Aug 2026 03:14:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bargrove.com; s=google; t=1786184076; x=1786788876; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=G33fDI4Q4Iz3fkReYaBTG+WJLJUdk1aUZg4Hq/QjqM4=; b=LIWlkPP5V9H9QLB0Fs6Q0og99b1jH61GFuNVCc/oyht/ncVQAKeaSTWPeqfKCsyNOJ WaZTc0nTaoxhk/SoI9kZU7uzThzv0871XZLPWNuB8btvlfOCULUBxIN8DndMwHWY4c5m gX58S/WBUHhxcrD1LwgVbMAYFQOXPbuN2VOl0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786184076; x=1786788876; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=G33fDI4Q4Iz3fkReYaBTG+WJLJUdk1aUZg4Hq/QjqM4=; b=Ys1xVphlWcSQArL9XbIuu7ThbidvJUumHthMQ4h9HET+xQT0p1H2Q7C98j7tw3RjgQ J54+LCdfEimDY+NSfSTLH6Ct+LS8+KYPFjhH03JWd4RCAtlyWvRsv5iCj7hFxBiUG+PQ pmFMBA+HaiMW1NpcL3PCXmFJricyl+evag/lnbhHHz7D6iCZEF67abv14YJoDl7d61fp +KhcIj39ppejvTiPNXO7cHzUxzQ8vsce4vG/eOipDaRnErLJErV6LcS+wSPWyyV9bOYI c796H23gijVSFlO3U27s1kYDaczomBv+G6kjD0OtSfYY0dmBgkOrj8AYw1rlK8I6TloG zwwg== X-Forwarded-Encrypted: i=1; AHgh+Rp7qZOKmZQ1EJJnUPcnx9FKk40cohLbDK+kTJpu7ccw/GuP/kEra8eFxNmwr7fGqkQf9d9qPaV2b6GtLh0=@vger.kernel.org X-Gm-Message-State: AOJu0YyZNRzR094ZiMUTVB/KSYcz4v3SJLf4kS47N8r3qozJGIHdjrwd uwKn+xSt9e1QPEuS7ODjWlWC1qKC4F3vgAxnxzPserddAYpJLA8aE6dNqtvi9/Rxlyw= X-Gm-Gg: AR+sD10j3BX6y4kYpXc9JPxNJBDJDYEsNR/GozEv4FczgvHkUHvM37H3YLyluZQwDxZ k677Ad7mPYZiIK9QslvNPlQBvARmW8u9k1OD4f0IHf6ZFKO1npQtYDYpgXS8XgGsXaZLeykHMzF 0ODQsa3fRUfil4sJ/ISrXg+I780kCzqgnaLFfryS/1DrRdi8sLjassNbb8xZQwiG9iETV1lDkkZ ZMRsPM6B+NPjmUWSSnn6okuWVjPZADugqNqF/4qROrVRd+I6O1/If5QolQXxbXTIcLNTOYM9UlN mJ4dn9XP4350S4xGVb53xEW3R9S0dKxzDLgehqON4xW2+A4AFrs6Moqw0KzFzRr+JrWD3NhtMZx 4xoIiZoL8U7FsKJnAOytytqmd0LexvyPmFYJmuZ7AIXmAX9zQEB8tQ/e921/h+PH5TxS6i56xtc SH2ha5pQpALv63vGgeEnWA+wBBZE9BD0/fbXkWrOsNdDA0PwQVo+A1iWhAMTf95DNvOVGo9jykk uz1LIWBaXlJsYqZffXp5e77UaTh/CjnnYcnm2WiYPUOkRlMo6wIXuy6Ol7SRnE0aL9/dJXSQ/rf 6w== X-Received: by 2002:a05:600c:1c19:b0:499:5a50:b022 with SMTP id 5b1f17b1804b1-4995e07f45bmr124882655e9.3.1786184076384; Sat, 08 Aug 2026 03:14:36 -0700 (PDT) Received: from roberto-5.lan (host-78-145-240-242.as13285.net. [78.145.240.242]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4995ea2dc4esm124212205e9.13.2026.08.08.03.14.35 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 08 Aug 2026 03:14:35 -0700 (PDT) From: matthew@bargrove.com To: Ilya Dryomov , Alex Markuze , Viacheslav Dubeyko Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Matthew Brown Subject: [PATCH] ceph: fix leaked inode reference on writeback abort at umount Date: Sat, 8 Aug 2026 11:14:24 +0100 Message-ID: <20260808101425.49616-1-matthew@bargrove.com> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Matthew Brown When ceph_submit_write() fails to take an osd_stopping_blocker -- which only happens once the filesystem has begun unmounting (mdsc->stopping >=3D CEPH_MDSC_STOPPING_FLUSHING) -- it redirties and unlocks the folios it had already pulled out of ceph_process_folio_batch() via redirty_page_for_writepage(), instead of submitting them for writeback. Those folios have already been through folio_clear_dirty_for_io(), so PG_dirty is clear, but they are still "claimed" by the original ceph_dirty_folio() call: ci->i_wrbuffer_ref is still counting them, folio->private still pins a ceph_snap_context, and on the 0 -> 1 i_wrbuffer_ref transition ceph_dirty_folio() took an ihold() on the inode. None of that has been released, because the folio was never submitted, so writepages_finish() -- the only place that would release it -- never runs. redirty_page_for_writepage() calls folio_mark_dirty(), which invokes ->dirty_folio() again as soon as it observes PG_dirty clear. That re-enters ceph_dirty_folio() on a folio that is still claimed. ceph_dirty_folio() cannot distinguish "still claimed, never submitted" from "genuinely clean again": it increments i_wrbuffer_ref again and re-attaches a second snap_context reference, but does not take a second ihold(), because ihold() only fires on the 0 -> 1 transition and i_wrbuffer_ref is already non-zero. The result is two i_wrbuffer_ref increments backed by only one ihold(). When the folio is eventually written back successfully on a later, unrelated writeback pass, writepages_finish() drops exactly one wrbuffer ref for it, so i_wrbuffer_ref never returns to 0 and the iput() that should balance the original ihold() never runs. The inode's i_count stays elevated, evict_inodes() cannot free it, and generic_shutdown_super() trips: VFS: Busy inodes after unmount of ceph (ceph) kernel BUG at fs/super.c:650! (a WARNING rather than a BUG without CONFIG_BUG_ON_DATA_CORRUPTION; on an affected production node with that config set it is a fatal panic and a full node reboot). Fix it by releasing the existing wrbuffer/snap_context claim before redirtying, mirroring what ceph_invalidate_folio() and write_folio_nounlock() already do on their own abort paths. This restores the invariant that ceph_dirty_folio() only ever runs against a folio that is not already claimed, so it takes exactly one ihold() per 0 -> 1 transition and one matching wrbuffer ref per claimed folio. Only the locked_pages loop is changed here. The preceding fbatch loop is deliberately left alone: those entries can include folios that are legitimately still under a different, in-flight write, where releasing the claim would be a premature release. The two structurally similar redirty-after-clear-dirty-for-io sites in ceph_process_folio_batch() appear to share the same defect class and are left for a follow-up to keep this fix minimal. Fixes: fd7449d937e7 ("ceph: fix generic/421 test failure") Link: https://tracker.ceph.com/issues/79149 Signed-off-by: Matthew Brown --- Reproduced and verified on a 6.18.40 kernel: forcing the ceph_submit_write() osd_stopping_blocker-failure branch and unmounting a CephFS kernel-client mount with dirty pages reliably produces the "VFS: Busy inodes after unmount of ceph" / fs/super.c:650 splat on the unpatched kernel, and produces no such splat with this patch applied (identical kernel, identical trigger). The original failure was captured in production off-box via the serial console (pstore could not persist the panic). fs/ceph/addr.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index ecf33b6..97d9ef1 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1426,6 +1426,16 @@ void ceph_shift_unused_folios_left(struct folio_batc= h *fbatch) fbatch->nr =3D n; } =20 +static void ceph_undo_wrbuffer_claim(struct inode *inode, struct page *pag= e) +{ + struct ceph_snap_context *snapc =3D detach_page_private(page); + + if (!snapc) + return; + ceph_put_wrbuffer_cap_refs(ceph_inode(inode), 1, snapc); + ceph_put_snap_context(snapc); +} + static int ceph_submit_write(struct address_space *mapping, struct writeback_control *wbc, @@ -1489,6 +1499,7 @@ int ceph_submit_write(struct address_space *mapping, if (!page) continue; =20 + ceph_undo_wrbuffer_claim(inode, page); redirty_page_for_writepage(wbc, page); unlock_page(page); } --=20 2.44.0