Re: [PATCH v2 1/2] scsi: ufs: core: Defer debugfs init until after device init

From: Bart Van Assche

Date: Tue Nov 24 2026 - 13:45:40 EST


On 11/23/26 5:29 PM, Po-Wen Kao wrote:
> void ufs_debugfs_hba_exit(struct ufs_hba *hba)
> {
> debugfs_remove_recursive(hba->debugfs_root);
> - cancel_delayed_work_sync(&hba->debugfs_ee_work);
> + disable_delayed_work_sync(&hba->debugfs_ee_work);
> }

[ ... ]

> @@ -11027,6 +11023,7 @@ void ufshcd_remove(struct ufs_hba *hba)
> ufs_bsg_remove(hba);
> ufs_rpmb_remove(hba);
> ufs_sysfs_remove_nodes(hba->dev);
> + ufs_debugfs_hba_exit(hba);
> cancel_delayed_work_sync(&hba->ufs_rtc_update_work);
> blk_mq_destroy_queue(hba->tmf_queue);
> blk_put_queue(hba->tmf_queue);

Moving ufs_debugfs_hba_exit() before scsi_remove_host() and switching
from cancel_delayed_work_sync() to disable_delayed_work_sync() fixes an
existing bug: without this change the debugfs attributes and
debugfs_ee_work may call ufshcd_rpm_get_sync() after the WLUN has been
removed. Please split that change into a separate patch with a Fixes:
tag such that it can be backported independently of the new debugfs
attributes.

> @@ -11505,6 +11502,8 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
> ufs_sysfs_add_nodes(hba->dev);
> hba->dme_qos_sysfs_handle = sysfs_get_dirent(hba->dev->kobj.sd,
> "dme_qos_notification");
> + ufs_debugfs_hba_init(hba);
> + ufs_fault_inject_hba_init(hba);
> async_schedule(ufshcd_async_scan, hba);

With this change debugfs_ee_work is initialized after the UFS device
has been initialized and after exception events have been enabled. The
only reason why ufs_debugfs_exception_event() does not queue an
uninitialized delayed work if an exception event is reported before
ufs_debugfs_hba_init() has been called is that
hba->debugfs_ee_rate_limit_ms is still zero at that time. That's
fragile. Please move the INIT_DELAYED_WORK() call and the
debugfs_ee_rate_limit_ms initialization into ufshcd_init() such that
these happen before interrupts are enabled, or at least add a comment
that explains this dependency.

Additionally, hba->trigger_eh_attr and hba->timeout_attr are now
initialized later than before. I think that's fine because no SCSI
commands are queued before ufshcd_async_scan() is called, but please
mention this in the patch description.

Thanks,

Bart.