Hang deleting ATA HDD device for undocking
Hi all,
On a ThinkPad T430 running Linux 6.7, when I attempt to delete the ATA device for a hard drive in the Ultrabay slot (to hotswap/undock it[1]) the process freezes in an unterruptible sleep. Specifically, if I run
echo 1 >/sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0/delete
The shell process hangs in the write(2) syscall. The last dmesg entries post hang are:
sd 1:0:0:0: [sda] Synchronizing SCSI cache
ata2: SATA link up 6.0 Gbps (SStatus 133 SControl 300)
ata2.00: ACPI cmd f5/00:00:00:00:00:a0(SECURITY FREEZE LOCK) filtered out
ata2.00: ACPI cmd ef/10:03:00:00:00:a0(SET FEATURES) filtered out
ata2.00: ACPI cmd f5/00:00:00:00:00:a0(SECURITY FREEZE LOCK) filtered out
ata2.00: ACPI cmd ef/10:03:00:00:00:a0(SET FEATURES) filtered out
ata2.00: configured for UDMA/133
ata2.00: retrying FLUSH 0xea Emask 0x0On kernel versions prior to 6.5-rc1, dmesg would subsequently contain:
sd 1:0:0:0: [sda] Stopping disk
ata2.00: disable device
Note that the hang only occurs when deleting a hard disk drive. It does not occur when deleting an optical disk drive.
I bisected the regression to 8b566edbdbfb5cde31a322c57932694ff48125ed.
I know very little about the SCSI/ATA subsystems or the internals of ATA hotswapping/undocking. I'd appreciate any help investigating the issue, or properly undocking.
Thanks,
Kevin
[1]: https://www.thinkwiki.org/wiki/How_to_hotswap_Ultrabay_devices
Quoted 30 lines · Kevin Locke
Hi all,
On a ThinkPad T430 running Linux 6.7, when I attempt to delete the ATA device for a hard drive in the Ultrabay slot (to hotswap/undock it[1]) the process freezes in an unterruptible sleep. Specifically, if I run
echo 1 >/sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0/deleteThe shell process hangs in the write(2) syscall. The last dmesg entries post hang are:
sd 1:0:0:0: [sda] Synchronizing SCSI cache ata2: SATA link up 6.0 Gbps (SStatus 133 SControl 300) ata2.00: ACPI cmd f5/00:00:00:00:00:a0(SECURITY FREEZE LOCK) filtered out ata2.00: ACPI cmd ef/10:03:00:00:00:a0(SET FEATURES) filtered out ata2.00: ACPI cmd f5/00:00:00:00:00:a0(SECURITY FREEZE LOCK) filtered out ata2.00: ACPI cmd ef/10:03:00:00:00:a0(SET FEATURES) filtered out ata2.00: configured for UDMA/133 ata2.00: retrying FLUSH 0xea Emask 0x0On kernel versions prior to 6.5-rc1, dmesg would subsequently contain:
sd 1:0:0:0: [sda] Stopping disk
ata2.00: disable deviceNote that the hang only occurs when deleting a hard disk drive. It does not occur when deleting an optical disk drive.
I bisected the regression to
8b566edbdbfb5cde31a322c57932694ff48125ed.
Quoted 8 lines
I know very little about the SCSI/ATA subsystems or the internals of ATA hotswapping/undocking. I'd appreciate any help investigating the issue, or properly undocking.
Thanks,
Kevin[1]: https://www.thinkwiki.org/wiki/How_to_hotswap_Ultrabay_devices
Hi Kevin,
Thank you for having bisected this issue.
The "Synchronizing SCSI cache" message probably comes from sd_shutdown(). sd_shutdown() is called by sd_remove(). sd_remove() is called by __scsi_remove_device(). __scsi_remove_device() is called by sdev_store_delete(). It's not clear to me how commit 8b566edbdbfb ("scsi: core: Only kick the requeue list if necessary") can affect that call path.
It would help if more information about the hang could be provided by running the following command after having reproduced the hang and by sharing the dmesg output triggered by this command:
echo w > /proc/sysrq-trigger
Thank you,
Bart.
Quoted 14 lines · Bart Van Assche
Quoted 3 lines · Kevin Locke
On a ThinkPad T430 running Linux 6.7, when I attempt to delete the ATA device for a hard drive in the Ultrabay slot (to hotswap/undock it[1]) the process freezes in an unterruptible sleep.
[...]
The "Synchronizing SCSI cache" message probably comes from
sd_shutdown().sd_shutdown()is called bysd_remove().sd_remove()is called by__scsi_remove_device().__scsi_remove_device()is called bysdev_store_delete(). It's not clear to me how commit8b566edbdbfb("scsi: core: Only kick the requeue list if necessary") can affect that call path.
Quoted 5 lines
It would help if more information about the hang could be provided by running the following command after having reproduced the hang and by sharing the dmesg output triggered by this command:
echo w >
/proc/sysrq-trigger
Hi Bart,
Thanks for helping me investigate this issue!
Relevant dmesg section after echo w > /proc/sysrq-trigger:
-8<------------------------------------------------------------------ sd 1:0:0:0: [sdb] Synchronizing SCSI cache
ata2: SATA link up 6.0 Gbps (SStatus 133 SControl 300) ata2.00: ACPI cmd f5/00:00:00:00:00:a0(SECURITY FREEZE LOCK) filtered out ata2.00: ACPI cmd ef/10:03:00:00:00:a0(SET FEATURES) filtered out ata2.00: ACPI cmd f5/00:00:00:00:00:a0(SECURITY FREEZE LOCK) filtered out ata2.00: ACPI cmd ef/10:03:00:00:00:a0(SET FEATURES) filtered out ata2.00: configured for UDMA/133
ata2.00: retrying FLUSH 0xea Emask 0x0
sysrq: Show Blocked State
task:ultrabay_eject state:D stack:0 pid:2630 tgid:2630 ppid:2629 flags:0x00004002
Call Trace: <TASK> __schedule+0x2c1/0x8a0 schedule+0x32/0xb0 schedule_timeout+0x151/0x160 io_schedule_timeout+0x50/0x80 wait_for_completion_io+0x86/0x170 blk_execute_rq+0x11e/0x1f0 scsi_execute_cmd+0xf6/0x250 [scsi_mod] sd_sync_cache+0xe6/0x1f0 [sd_mod] sd_shutdown+0x68/0x100 [sd_mod] sd_remove+0x55/0x60 [sd_mod] device_release_driver_internal+0x19f/0x200 bus_remove_device+0xc6/0x130 device_del+0x15e/0x3f0 ? mutex_lock+0x12/0x30 ? __pfx_ata_tdev_match+0x10/0x10 [libata] __scsi_remove_device+0x131/0x190 [scsi_mod] sdev_store_delete+0x6a/0xd0 [scsi_mod] kernfs_fop_write_iter+0x13d/0x1d0 vfs_write+0x23d/0x400 ksys_write+0x6f/0xf0 do_syscall_64+0x64/0x120 ? exc_page_fault+0x70/0x150 entry_SYSCALL_64_after_hwframe+0x6e/0x76 RIP: 0033:0x7fa0f8949b00 RSP: 002b:00007ffc779b8418 EFLAGS: 00000202 ORIG_RAX: 0000000000000001 RAX: ffffffffffffffda RBX: 0000000000000002 RCX: 00007fa0f8949b00 RDX: 0000000000000002 RSI: 000056549cd8fe30 RDI: 0000000000000001 RBP: 000056549cd8fe30 R08: 0000000000002000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000001 R13: 0000000000000002 R14: 0000000000000000 R15: 000056549cd8f7e8 </TASK>
-8<------------------------------------------------------------------
Thanks again,
Kevin
Quoted 28 lines · Kevin Locke
-8<------------------------------------------------------------------ sd 1:0:0:0: [sdb] Synchronizing SCSI cache
ata2: SATA link up 6.0 Gbps (SStatus 133 SControl 300) ata2.00: ACPI cmd f5/00:00:00:00:00:a0(SECURITY FREEZE LOCK) filtered out ata2.00: ACPI cmd ef/10:03:00:00:00:a0(SET FEATURES) filtered out ata2.00: ACPI cmd f5/00:00:00:00:00:a0(SECURITY FREEZE LOCK) filtered out ata2.00: ACPI cmd ef/10:03:00:00:00:a0(SET FEATURES) filtered out ata2.00: configured for UDMA/133
ata2.00: retrying FLUSH0xeaEmask0x0
sysrq: Show Blocked State
task:ultrabay_eject state:D stack:0 pid:2630 tgid:2630 ppid:2629 flags:0x00004002Call Trace: <TASK> __schedule+0x2c1/0x8a0 schedule+0x32/0xb0 schedule_timeout+0x151/0x160 io_schedule_timeout+0x50/0x80 wait_for_completion_io+0x86/0x170 blk_execute_rq+0x11e/0x1f0 scsi_execute_cmd+0xf6/0x250 [scsi_mod] sd_sync_cache+0xe6/0x1f0 [sd_mod] sd_shutdown+0x68/0x100 [sd_mod] sd_remove+0x55/0x60 [sd_mod] device_release_driver_internal+0x19f/0x200 bus_remove_device+0xc6/0x130 device_del+0x15e/0x3f0 ? mutex_lock+0x12/0x30 ? __pfx_ata_tdev_match+0x10/0x10 [libata]
Quoted 8 lines
__scsi_remove_device+0x131/0x190 [scsi_mod] sdev_store_delete+0x6a/0xd0 [scsi_mod] kernfs_fop_write_iter+0x13d/0x1d0 vfs_write+0x23d/0x400 ksys_write+0x6f/0xf0 do_syscall_64+0x64/0x120 ? exc_page_fault+0x70/0x150 entry_SYSCALL_64_after_hwframe+0x6e/0x76
I think this means that the block layer is waiting for the completion of the SYNCHRONIZE CACHE command. Can you please also share the SCSI host and device states after the hang has been reproduced, e.g. by sharing the output of the following commands (these commands require the bash shell)?
(cd /sys/class/scsi_host && grep -aH . */state)
(cd /sys/class/scsi_device && grep -aH . */device/{device_{blocked,busy},state})
Thanks,
Bart.
Quoted 38 lines · Bart Van Assche
Quoted 28 lines · Kevin Locke
-8<------------------------------------------------------------------ sd 1:0:0:0: [sdb] Synchronizing SCSI cache
ata2: SATA link up 6.0 Gbps (SStatus 133 SControl 300) ata2.00: ACPI cmd f5/00:00:00:00:00:a0(SECURITY FREEZE LOCK) filtered out ata2.00: ACPI cmd ef/10:03:00:00:00:a0(SET FEATURES) filtered out ata2.00: ACPI cmd f5/00:00:00:00:00:a0(SECURITY FREEZE LOCK) filtered out ata2.00: ACPI cmd ef/10:03:00:00:00:a0(SET FEATURES) filtered out ata2.00: configured for UDMA/133
ata2.00: retrying FLUSH0xeaEmask0x0
sysrq: Show Blocked State
task:ultrabay_eject state:D stack:0 pid:2630 tgid:2630 ppid:2629 flags:0x00004002Call Trace: <TASK> __schedule+0x2c1/0x8a0 schedule+0x32/0xb0 schedule_timeout+0x151/0x160 io_schedule_timeout+0x50/0x80 wait_for_completion_io+0x86/0x170 blk_execute_rq+0x11e/0x1f0 scsi_execute_cmd+0xf6/0x250 [scsi_mod] sd_sync_cache+0xe6/0x1f0 [sd_mod] sd_shutdown+0x68/0x100 [sd_mod] sd_remove+0x55/0x60 [sd_mod] device_release_driver_internal+0x19f/0x200 bus_remove_device+0xc6/0x130 device_del+0x15e/0x3f0 ? mutex_lock+0x12/0x30 ? __pfx_ata_tdev_match+0x10/0x10 [libata]Quoted 8 lines
__scsi_remove_device+0x131/0x190 [scsi_mod] sdev_store_delete+0x6a/0xd0 [scsi_mod] kernfs_fop_write_iter+0x13d/0x1d0 vfs_write+0x23d/0x400 ksys_write+0x6f/0xf0 do_syscall_64+0x64/0x120 ? exc_page_fault+0x70/0x150 entry_SYSCALL_64_after_hwframe+0x6e/0x76
Quoted 7 lines
I think this means that the block layer is waiting for the completion of the SYNCHRONIZE CACHE command. Can you please also share the SCSI host and device states after the hang has been reproduced, e.g. by sharing the output of the following commands (these commands require the bash shell)?
(cd
/sys/class/scsi_host&& grep -aH . */state)
(cd/sys/class/scsi_device&& grep -aH . */device/{device_{blocked,busy},state})
Sure thing. Running the above commands produced the following output:
host0/state:running
host1/state:running
host2/state:running
host3/state:running
host4/state:running
host5/state:running
0:0:0:0/device/device_blocked:0
0:0:0:0/device/device_busy:1
0:0:0:0/device/state:running
Thanks for your help,
Kevin
Quoted 6 lines · Kevin Locke
Quoted 2 lines · Bart Van Assche
(cd
/sys/class/scsi_host&& grep -aH . */state)
(cd/sys/class/scsi_device&& grep -aH . */device/{device_{blocked,busy},state})Sure thing. Running the above commands produced the following output:
Quoted 9 lines
host0/state:running
host1/state:running
host2/state:running
host3/state:running
host4/state:running
host5/state:running
0:0:0:0/device/device_blocked:0
0:0:0:0/device/device_busy:1
0:0:0:0/device/state:running
So the SCSI host state (host1) is fine but the information about the SCSI devices associated with host1 is missing, most likely because sysfs information of SCSI devices is removed before a SYNCHRONIZE CACHE command is submitted. The device_del(dev) call in __scsi_remove_device() happens after scsi_device_set_state(sdev, SDEV_CANCEL) so the SCSI device should be in the SDEV_CANCEL state. scsi_device_state_check() should translate SDEV_CANCEL into BLK_STS_OFFLINE.
There are several tests in the blktests suite that trigger SCSI device deletion, e.g. block/001. All blktests tests pass on my test setup. Additionally, I haven't seen any blktests failure reports recently that are related to device deletion. If I try to delete an ATA device in a VM, that works fine (kernel v6.7):
# dmesg -c >/dev/null # echo 1 > /sys/class/scsi_device/3:0:0:0/device/delete # dmesg -c [ 215.533228] sd 3:0:0:0: [sdb] Synchronizing SCSI cache [ 215.543932] ata3.00: Entering standby power mode
Running rescan-scsi-bus.sh -a brings this device back.
I'm not sure what I'm missing but I think that it's something ATA-specific. Since I'm not an ATA expert, I hope that an ATA expert can help. There are at least two ATA experts on the Cc-list of this email.
Thanks,
Bart.
Hello Bart,
Quoted 37 lines · Bart Van Assche
Quoted 6 lines · Kevin Locke
Quoted 2 lines · Bart Van Assche
(cd
/sys/class/scsi_host&& grep -aH . */state)
(cd/sys/class/scsi_device&& grep -aH . */device/{device_{blocked,busy},state})Sure thing. Running the above commands produced the following output:
Quoted 9 lines
host0/state:running
host1/state:running
host2/state:running
host3/state:running
host4/state:running
host5/state:running
0:0:0:0/device/device_blocked:0
0:0:0:0/device/device_busy:1
0:0:0:0/device/state:runningSo the SCSI host state (host1) is fine but the information about the SCSI devices associated with host1 is missing, most likely because sysfs information of SCSI devices is removed before a SYNCHRONIZE CACHE command is submitted. The
device_del(dev)call in__scsi_remove_device()happens afterscsi_device_set_state(sdev, SDEV_CANCEL)so the SCSI device should be in theSDEV_CANCELstate.scsi_device_state_check()should translateSDEV_CANCELintoBLK_STS_OFFLINE.There are several tests in the blktests suite that trigger SCSI device deletion, e.g. block/001. All blktests tests pass on my test setup. Additionally, I haven't seen any blktests failure reports recently that are related to device deletion. If I try to delete an ATA device in a VM, that works fine (kernel v6.7):
# dmesg -c >/dev/null # echo 1 > /sys/class/scsi_device/3:0:0:0/device/delete # dmesg -c [ 215.533228] sd 3:0:0:0: [sdb] Synchronizing SCSI cache [ 215.543932] ata3.00: Entering standby power mode
Quoted 5 lines
Running
rescan-scsi-bus.sh-a brings this device back.I'm not sure what I'm missing but I think that it's something ATA-specific. Since I'm not an ATA expert, I hope that an ATA expert can help. There are at least two ATA experts on the Cc-list of this email.
Thank you for your help debugging this.
It is easy to reproduce the hang in QEMU against a ATA device using:
# hdparm -Y /dev/sda # echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/delete
I can get it working again by simply reverting this part of your patch:
drivers/scsi/scsi_lib.c +1 -2
@@ -163,8 +163,7 @@ static void __scsi_queue_insert(struct scsi_cmnd *cmd, int reason, bool unbusy)*/ cmd->result =0 ; -blk_mq_requeue_request (scsi_cmd_to_rq (cmd), - !scsi_host_in_recovery (cmd->device->host)); +blk_mq_requeue_request (scsi_cmd_to_rq (cmd), true); }
What goes on:
When libata receives a completion for a ATA_CMD_SLEEP command, it sets flag ATA_DFLAG_SLEEPING, in order to know that the device is sleeping.
In order to take a device out of sleep a link reset is performed.
This link reset is currently performed very late in the call chain, after a new SCSI command has been translated to an ATA command, but before the ATA command is actually issued to the device. (See ata_qc_issue(), which calls ata_link_abort() if flag ATA_DFLAG_SLEEPING is set.)
While the ata_link_abort() will abort all QCs, using blk_abort_request(), (regardless if the command was issued to the device or no were issued or not), which will result in scsi_timeout() being called, which calls scsi_eh_scmd_add() for all the commands.
scsi_eh_scmd_add() sets the SCSI host state to recovery, and then adds the command to shost->eh_cmd_q.
However, after 8b566edbdbfb ("scsi: core: Only kick the requeue list if necessary"), it seems that after when libata EH strategy handler calls scsi_eh_flush_done_q(), the failed commands get requeued (scsi_eh_flush_done_q() calls scsi_queue_insert()), but the queue is never kicked after EH is done, so the command is never sent down to the device.
Most likely because scsi_eh_scmd_add(), which sets the SCSI host state to recovery, together with your modification to __scsi_queue_insert(), causes the queue to never get kicked.
I have a patch that works around this issue by instead deferring the SYNCHRONIZE CACHE command, and letting the block layer requeue the command (see patch attached at the end of this email), instead of relying on SCSI EH to requeue the command.
However, I'm worried that applying that libata patch will simply hide an actual problem in SCSI, which might lead to someone else stumbling on this SCSI bug in the future.
Thoughts?
Kind regards,
Niklas
drivers/ata/libata-core.c +0 -8
@@ -5038,14 +5038,6 @@ void ata_qc_issue(struct ata_queued_cmd *qc)if (ata_sg_setup (qc)) goto sys_err; -/* if device is sleeping, schedule reset and abort the link */ -if (unlikely (qc->dev->flags &ATA_DFLAG_SLEEPING )) { - link->eh_info.action |=ATA_EH_RESET ; -ata_ehi_push_desc (&link->eh_info,"waking up from sleep" ); -ata_link_abort (link); -return ; - } -trace_ata_qc_prep (qc); qc->err_mask |= ap->ops->qc_prep (qc);if (unlikely (qc->err_mask))
drivers/ata/libata-scsi.c +12 -1
@@ -1682,10 +1682,20 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)static int ata_scsi_translate (struct ata_device *dev,struct scsi_cmnd *cmd,ata_xlat_func_t xlat_func) { -struct ata_port *ap = dev->link->ap; +struct ata_link *link = dev->link; +struct ata_port *ap = link->ap;struct ata_queued_cmd *qc;int rc; +/* if device is sleeping, defer, schedule reset and abort the link */ +if (unlikely (dev->flags &ATA_DFLAG_SLEEPING )) { + link->eh_info.action |=ATA_EH_RESET ; +ata_ehi_push_desc (&link->eh_info,"waking up from sleep" ); +ata_link_abort (link); + rc =ATA_DEFER_LINK ; + goto defer_nofree; + } + qc =ata_scsi_qc_new (dev, cmd);if (!qc) goto err_mem;
@@ -1732,6 +1742,7 @@ static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd, defer:ata_qc_free (qc); +defer_nofree:if (rc ==ATA_DEFER_LINK )return SCSI_MLQUEUE_DEVICE_BUSY ;else
Quoted 5 lines · Niklas Cassel
However, I'm worried that applying that libata patch will simply hide an actual problem in SCSI, which might lead to someone else stumbling on this SCSI bug in the future.
Thoughts?
Since the hang is caused by submitting a SCSI pass-through command, I'm not sure this issue can be called a SCSI core bug. Aren't users on their own who mix SCSI pass-through commands with commands submitted by the sd driver?
Thanks,
Bart.
Quoted 11 lines · Bart Van Assche
Quoted 5 lines · Niklas Cassel
However, I'm worried that applying that libata patch will simply hide an actual problem in SCSI, which might lead to someone else stumbling on this SCSI bug in the future.
Thoughts?
Since the hang is caused by submitting a SCSI pass-through command, I'm not sure this issue can be called a SCSI core bug. Aren't users on their own who mix SCSI pass-through commands with commands submitted by the sd driver?
I tend to agree with you, but at the same time, it used to work, so in one way it is a regression...
(I can hear Linus's voice saying "Never break user space!"... in my head.)
And since there seems to be at least one script mixing hdparm with sysfs delete:
https://www.thinkwiki.org/wiki/How_to_hotswap_Ultrabay_devices#Script_for_Ultrabay_eject
there are probably others as well.
We can work around it in libata.
I'm just worried if there are any SCSI drivers using scsi_eh_scmd_add() together with scsi_eh_flush_done_q() that will hit this in the future.
Perhaps some libsas driver?
Kind regards,
Niklas
Quoted 11 lines · Bart Van Assche
Quoted 5 lines · Niklas Cassel
However, I'm worried that applying that libata patch will simply hide an actual problem in SCSI, which might lead to someone else stumbling on this SCSI bug in the future.
Thoughts?
Since the hang is caused by submitting a SCSI pass-through command, I'm not sure this issue can be called a SCSI core bug. Aren't users on their own who mix SCSI pass-through commands with commands submitted by the sd driver?
I would not expect a correct result from a user mixing up passthrough and regular kernel sd management, however, having the system hang is not acceptable I think. So we should fix this, avoiding this hang. Is Niklas patch OK for that ?
Signature · 2 lines
Damien Le Moal Western Digital Research
Quoted 8 lines · Damien Le Moal
Quoted 7 lines · Bart Van Assche
Quoted 5 lines · Niklas Cassel
However, I'm worried that applying that libata patch will simply hide an actual problem in SCSI, which might lead to someone else stumbling on this SCSI bug in the future.
Thoughts?
Quoted 8 lines
Quoted 4 lines
Since the hang is caused by submitting a SCSI pass-through command, I'm not sure this issue can be called a SCSI core bug. Aren't users on their own who mix SCSI pass-through commands with commands submitted by the sd driver?
I would not expect a correct result from a user mixing up passthrough and regular kernel sd management, however, having the system hang is not acceptable I think. So we should fix this, avoiding this hang. Is Niklas patch OK for that ?
Hi Damien,
There are two patches in Niklas' email so I'm not sure which patch you are referring to. I'm not enthusiast about the SCSI patch in his email because that patch would reintroduce the superfluous queue runs that I'm trying to get rid of.
Thanks,
Bart.
Damien Le Moal
maintainerQuoted 11 lines · Kevin Locke
Hi all,
On a ThinkPad T430 running Linux 6.7, when I attempt to delete the ATA device for a hard drive in the Ultrabay slot (to hotswap/undock it[1]) the process freezes in an unterruptible sleep. Specifically, if I run
echo 1 >/sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0/deleteThe shell process hangs in the write(2) syscall. The last dmesg entries post hang are:
Quoted 7 lines
sd 1:0:0:0: [sda] Synchronizing SCSI cache
ata2: SATA link up 6.0 Gbps (SStatus 133 SControl 300)
ata2.00: ACPI cmd f5/00:00:00:00:00:a0(SECURITY FREEZE LOCK) filtered out
ata2.00: ACPI cmd ef/10:03:00:00:00:a0(SET FEATURES) filtered out
ata2.00: ACPI cmd f5/00:00:00:00:00:a0(SECURITY FREEZE LOCK) filtered out
ata2.00: ACPI cmd ef/10:03:00:00:00:a0(SET FEATURES) filtered out
ata2.00: configured for UDMA/133It looks like the device was sleeping or was in standby state.
If that is the case, then we may be deadlocking with the scsi revalidate done when waking up a drive. Can you confirm what the power state of the drive was when you ran this ? Do you see an issue if you first make sure that the drive is spun-up ?
Quoted 21 lines
ata2.00: retrying FLUSH 0xea Emask 0x0On kernel versions prior to 6.5-rc1, dmesg would subsequently contain:
sd 1:0:0:0: [sda] Stopping disk
ata2.00: disable deviceNote that the hang only occurs when deleting a hard disk drive. It does not occur when deleting an optical disk drive.
I bisected the regression to
8b566edbdbfb5cde31a322c57932694ff48125ed.I know very little about the SCSI/ATA subsystems or the internals of ATA hotswapping/undocking. I'd appreciate any help investigating the issue, or properly undocking.
Thanks,
Kevin[1]: https://www.thinkwiki.org/wiki/How_to_hotswap_Ultrabay_devices
Signature · 2 lines
Damien Le Moal Western Digital Research
Quoted 18 lines · Damien Le Moal
Quoted 9 lines · Kevin Locke
On a ThinkPad T430 running Linux 6.7, when I attempt to delete the ATA device for a hard drive in the Ultrabay slot (to hotswap/undock it[1]) the process freezes in an unterruptible sleep. Specifically, if I run
echo 1 >/sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0/deleteThe shell process hangs in the write(2) syscall. The last dmesg entries post hang are:
Quoted 7 lines
sd 1:0:0:0: [sda] Synchronizing SCSI cache ata2: SATA link up 6.0 Gbps (SStatus 133 SControl 300) ata2.00: ACPI cmd f5/00:00:00:00:00:a0(SECURITY FREEZE LOCK) filtered out ata2.00: ACPI cmd ef/10:03:00:00:00:a0(SET FEATURES) filtered out ata2.00: ACPI cmd f5/00:00:00:00:00:a0(SECURITY FREEZE LOCK) filtered out ata2.00: ACPI cmd ef/10:03:00:00:00:a0(SET FEATURES) filtered out ata2.00: configured for UDMA/133
Quoted 5 lines
It looks like the device was sleeping or was in standby state.
If that is the case, then we may be deadlocking with the scsi revalidate done when waking up a drive. Can you confirm what the power state of the drive was when you ran this ? Do you see an issue if you first make sure that the drive is spun-up ?
Bingo! I can confirm that I do not experience the issue when the drive is in the active/idle state, nor in standby (hdparm -y). I only experience the issue if the drive is in the sleep (hdparm -Y) state.
Thanks for the incisive suggestion,
Kevin
P.S. The Ultrabay eject script[1] runs hdparm -Y before delete. Should that be removed (or changed to standby) to avoid unnecessary revalidation? For both HDD and SSD?
[1]: https://www.thinkwiki.org/wiki/How_to_hotswap_Ultrabay_devices#Script_for_Ultrabay_eject
Damien Le Moal
maintainerQuoted 25 lines · Kevin Locke
Quoted 18 lines · Damien Le Moal
Quoted 9 lines · Kevin Locke
On a ThinkPad T430 running Linux 6.7, when I attempt to delete the ATA device for a hard drive in the Ultrabay slot (to hotswap/undock it[1]) the process freezes in an unterruptible sleep. Specifically, if I run
echo 1 >/sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0/deleteThe shell process hangs in the write(2) syscall. The last dmesg entries post hang are:
Quoted 7 lines
sd 1:0:0:0: [sda] Synchronizing SCSI cache ata2: SATA link up 6.0 Gbps (SStatus 133 SControl 300) ata2.00: ACPI cmd f5/00:00:00:00:00:a0(SECURITY FREEZE LOCK) filtered out ata2.00: ACPI cmd ef/10:03:00:00:00:a0(SET FEATURES) filtered out ata2.00: ACPI cmd f5/00:00:00:00:00:a0(SECURITY FREEZE LOCK) filtered out ata2.00: ACPI cmd ef/10:03:00:00:00:a0(SET FEATURES) filtered out ata2.00: configured for UDMA/133Quoted 5 lines
It looks like the device was sleeping or was in standby state.
If that is the case, then we may be deadlocking with the scsi revalidate done when waking up a drive. Can you confirm what the power state of the drive was when you ran this ? Do you see an issue if you first make sure that the drive is spun-up ?
Quoted 3 lines
Bingo! I can confirm that I do not experience the issue when the drive is in the active/idle state, nor in standby (hdparm -y). I only experience the issue if the drive is in the sleep (hdparm -Y) state.
hdparm -Y does not use the kernel power management core. There is a hack in libata to track that a SLEEP command was issued to the device and then mark it with ATA_DFLAG_SLEEPING. And if this flag is set, then the port is reset to spinup the drive whenever a new command is received. That is what is causing the problem here as a reset (EH running) is not supposed to happen when the scsi drive is going away.
This all boils down to the scsi disk not being in sync with its underlying ata
device: the scsi disk is not marked as spun-down/standby and so a flush cache is issued. Problem is that it is not realistic to track and maintain the system device state by catching/parsing passthrough commands such as issued by hdparm.
That said, a hang is still not acceptable. we will see how to avoid it (it is not trivial).
Quoted 7 lines
Thanks for the incisive suggestion,
Kevin
P.S. The Ultrabay eject script[1] runshdparm -Ybefore delete. Should that be removed (or changed to standby) to avoid unnecessary revalidation? For both HDD and SSD?
Removing a scsi disk will remove and put the backing ata device in standby state. So you do not need to do that manually. Remove that "hdparm -Y" from your script.
Quoted 3 lines
[1]: https://www.thinkwiki.org/wiki/How_to_hotswap_Ultrabay_devices#Script_for_Ultrabay_eject
Signature · 2 lines
Damien Le Moal Western Digital Research