From patchwork Tue Dec 30 23:41:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138276; bh=PF66alhrTgviiShEOSruerpcHIBzo17wyUZJV0IyPyI=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=hs2k/4pApUdC6o9g2lSVLWLncVq6BTexryU0AFKRmo+FLIjJKvqKMd0QZ7geYNwfC pBgrGY/v0bAYQb8LAb6oqFBHTq5gM7e/QD7cs3AY2/cWPaevy9CXLhgs6xqFIZ114x E+1+gVCWU5s4h5jyw21PAdBAM8rw/y28DK5J/Iur2MrWjU9d30TOxG+FwrohrBtIi7 +oVYFWhcTCJkPouW1viQSXH7ASRFItMcMXfoJhrAc3tQ+2DfbAu/l4EzPaIivxvcug D9Ya5TqQpRgSw87t2JyWis77N4pwgFuC2OcaYcx09sRiSgUKaJVJ2Q40BkCks/mWsS bmOBZ+iz/nDgA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A691968C0F for ; Tue, 30 Dec 2025 16:44:36 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id wl6LQHcSA3lK for ; Tue, 30 Dec 2025 16:44:36 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138276; bh=PF66alhrTgviiShEOSruerpcHIBzo17wyUZJV0IyPyI=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=hs2k/4pApUdC6o9g2lSVLWLncVq6BTexryU0AFKRmo+FLIjJKvqKMd0QZ7geYNwfC pBgrGY/v0bAYQb8LAb6oqFBHTq5gM7e/QD7cs3AY2/cWPaevy9CXLhgs6xqFIZ114x E+1+gVCWU5s4h5jyw21PAdBAM8rw/y28DK5J/Iur2MrWjU9d30TOxG+FwrohrBtIi7 +oVYFWhcTCJkPouW1viQSXH7ASRFItMcMXfoJhrAc3tQ+2DfbAu/l4EzPaIivxvcug D9Ya5TqQpRgSw87t2JyWis77N4pwgFuC2OcaYcx09sRiSgUKaJVJ2Q40BkCks/mWsS bmOBZ+iz/nDgA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 93A1D68F6F for ; Tue, 30 Dec 2025 16:44:36 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138275; bh=A0AVBTomcXJmyx9sBpbjtSFSiwj3C835OYMLgeY+OmU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EOzsokFV8p2dCw+sTOKoKBapVoO5Hc/nz5DmmHmUYn9GXJuxKR9di0CMh8pEONRqD FwkOSq09EYyhkaAsSBlwaL82y2+ZCtaIVDLspxQc+GmLYQHJFll5FQsOqpcchnMPd3 1kojLX/nIrB4FrmyPNhPCAn+LYBKovVmG0VPhwP1+qrPLqkhlXTv5McAHmRhlXbYyk LkmDdotRZsY9OtPIPd1XK8m43w9Kai5LEFP6kDOIk1FWxE9GU5R84WWJGdWA4AGQD9 GpwrlO5m5ashFWV1CbuVoCofcrGk4U30X5sdEPwJTGhafak3f9dMlNIUM7q8seB5Tc 5pEbUmw6D6Ytw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 28CD464E2A; Tue, 30 Dec 2025 16:44:35 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id ZIrYLbiS19kx; Tue, 30 Dec 2025 16:44:35 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138271; bh=Ahe+UVMIPCr+t3cn6WfnfxusFqC5106T3M3mqOuy1XI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gpSFTZdjGIThbbbA2/K5KASs24WsqHTwPtoVQANqloizlPNdlK5v7ia9yr4EYo1J0 yUMI1steD8cxi3n+VHQ2VbYd/Y50oEznYY77Zps3Q8E8tkNi3NIIvZBmPqHvrtaOlW TbexF0YTY/lhj1mXEmNm+VEXXHdPWfOmK1L3cv+LCF1SHgILvbATsY8CKrqOYD/Ev/ tKmdYn6x9AeMl49c7pxKII9wbAST+5MXVwbJ+WqxW8HAkuPCjeuQixbD8wXu4uMsL2 +1ih7Z9/4e4cQFcPHU1j4MQVsZ9kMYQ5y6JFTlGpcbKG813YF1LDGDV2rwNFq24O3U aCnn/h0L28Cfw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id CD53D68C0F; Tue, 30 Dec 2025 16:44:30 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 30 Dec 2025 16:41:14 -0700 Message-ID: <20251230234134.906477-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251230234134.906477-1-sjg@u-boot.org> References: <20251230234134.906477-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: WILBTTFNUICIIALOLUC3FAQWC4DA65L4 X-Message-ID-Hash: WILBTTFNUICIIALOLUC3FAQWC4DA65L4 X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 02/15] ext4l: Add journal_head detection in bh_cache_clear List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass When debugging journal-cleanup issues, stale journal_head attachments on buffer_heads can cause crashes on subsequent mounts. Add detection logic in bh_cache_clear() to warn when a buffer_head still has a journal_head attached. This indicates the journal was not properly destroyed before unmount. Clear the JBD flag and pointer to prevent issues with subsequent mounts. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/support.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/fs/ext4l/support.c b/fs/ext4l/support.c index a046654ca54..127a3920c96 100644 --- a/fs/ext4l/support.c +++ b/fs/ext4l/support.c @@ -222,6 +222,29 @@ static void bh_cache_insert(struct buffer_head *bh) * * Called on unmount to free all cached buffers. */ +/** + * bh_clear_stale_jbd() - Clear stale journal_head from buffer_head + * @bh: buffer_head to check + * + * Check if the buffer still has journal_head attached. This should not happen + * if the journal was properly destroyed, but warn if it does to help debugging. + * Clear the JBD flag and b_private to prevent issues with subsequent mounts. + */ +static void bh_clear_stale_jbd(struct buffer_head *bh) +{ + if (buffer_jbd(bh)) { + log_err("bh %p block %llu still has JBD (b_private %p)\n", + bh, (unsigned long long)bh->b_blocknr, bh->b_private); + /* + * Clear the JBD flag and b_private to prevent issues. + * The journal_head itself will be freed when the + * journal_head cache is destroyed. + */ + clear_buffer_jbd(bh); + bh->b_private = NULL; + } +} + void bh_cache_clear(void) { int i; @@ -231,9 +254,12 @@ void bh_cache_clear(void) for (entry = bh_cache[i]; entry; entry = next) { next = entry->next; if (entry->bh) { + struct buffer_head *bh = entry->bh; + + bh_clear_stale_jbd(bh); /* Release the cache's reference */ - if (atomic_dec_and_test(&entry->bh->b_count)) - free_buffer_head(entry->bh); + if (atomic_dec_and_test(&bh->b_count)) + free_buffer_head(bh); } free(entry); }