Re: [PATCH] jbd2: skip updating journal superblock on -ESHUTDOWN abort
From: Jan Kara
Date: Tue Dec 01 2026 - 05:29:19 EST
On Tue 01-12-26 15:35:38, Jia Zhu wrote:
> Removing a block device with a mounted ext4 filesystem can trigger a
> hung task (or hang indefinitely) in ext4_shutdown():
>
> EXT4-fs (nvme3n1p1): shut down requested (2)
> Aborting journal on device nvme3n1p1-8.
> INFO: task kworker/u456:2:885880 blocked for more than 122 seconds.
> Workqueue: kacpi_hotplug acpi_hotplug_work_fn
> Call Trace:
> __wait_on_buffer
> jbd2_write_superblock
> jbd2_journal_update_sb_errno
> jbd2_journal_abort
> ext4_force_shutdown
> ext4_shutdown
> fs_bdev_mark_dead
> bdev_mark_dead
> blk_report_disk_dead
> __del_gendisk
> del_gendisk
> nvme_ns_remove
> nvme_remove_namespaces
> nvme_remove
> pci_device_remove
> ...
> acpiphp_disable_and_eject_slot
>
> Stalling here holds sb->s_umount, device_lock, and (on ACPI/PCI hotplug)
> the ordered kacpi_hotplug workqueue and pci_rescan_remove_lock, blocking
> teardown, umount, subsequent hotplug, and device_shutdown().
>
> Commit fb7c02445c49 ("ext4: pass -ESHUTDOWN code to jbd2 layer") switched
> shutdown aborts from 0 to -ESHUTDOWN so a racing error abort could be
> cleared back to s_errno = 0, inadvertently causing an initial -ESHUTDOWN
> abort to write 0 over an already-zero s_errno (and attempt writes on
> read-only mounts or NOLOGFLUSH shutdowns).
>
> Skip jbd2_journal_update_sb_errno() on the initial abort path when errno
> is -ESHUTDOWN, leaving the existing JBD2_ABORT override path for racing
> error aborts unchanged.
>
> Fixes: fb7c02445c49 ("ext4: pass -ESHUTDOWN code to jbd2 layer")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Jia Zhu <zhujia.zj@xxxxxxxxxxxxx>
Thanks for the fix but I think instead of this special-casing of shutdown,
we should just modify jbd2_write_superblock() to properly detect dead
device and stop doing IO to it. In fact we have there such check:
/* Buffer got discarded which means block device got invalidated */
if (!buffer_mapped(bh)) {
unlock_buffer(bh);
return -EIO;
}
but it doesn't work for this shutdown path because invalidate_bdev() gets
called only after ->mark_dead() callback is done. So just enhance this
check to something like:
/*
* If buffer got discarded or gendisk is dead, the device doesn't
* exist anymore.
*/
if (!buffer_mapped(bh) || !disk_live(bh->b_bdev->bd_disk))
Honza
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index eb8e944f1f9e6..866132fbcd8c9 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -2629,9 +2629,11 @@ void jbd2_journal_abort(journal_t *journal, int errno)
>
> /*
> * Record errno to the journal super block, so that fsck and jbd2
> - * layer could realise that a filesystem check is needed.
> + * layer could realise that a filesystem check is needed. Skip
> + * -ESHUTDOWN since no error needs to be recorded on disk.
> */
> - jbd2_journal_update_sb_errno(journal);
> + if (errno != -ESHUTDOWN)
> + jbd2_journal_update_sb_errno(journal);
> mutex_unlock(&journal->j_abort_mutex);
> }
>
> --
> 2.39.5 (Apple Git-154)
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR