Skip to contentSkip to conversation

ata: libata-eh: Fix link state check for IDE/PATA ports

PATCH In review Damien Le Moal 4 participants 4 messages Aug 13, 2025 libata

lore
Share & tools
lore

Damien Le Moal

author maintainer
#0 lore raw

PATCH 1/1 ata: libata-eh: Fix link state check for IDE/PATA ports

Commit 4371fe1ba400 ("ata: libata-eh: Avoid unnecessary resets when revalidating devices") replaced the call to ata_phys_link_offline() in ata_eh_revalidate_and_attach() with the new function ata_eh_link_established() which relaxes the checks on a device link state to account for low power mode transitions. However, this changed assumed that the device port has a valid scr_read method to obstain the SSTATUS register for the port. This is not always the case, especially with older IDE/PATA adapters (e.g. as emulated with qemu). For such adapter, ata_eh_link_established() will always return false, causing ata_eh_revalidate_and_attach() to go into its error path and ultimately to the device being disabled.

Avoid this by restoring the previous behavior, which is to assume that the link is online if reading the port SSTATUS register fails.

Fixes 4371fe1ba400 ("ata: libata-eh: Avoid unnecessary resets when revalidating devices")
---
 drivers/ata/libata-eh.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/ata/libata-eh.c +6 -1
index 2946ae6d4b2c..354d2c0abcf3 100644
@@ -2089,8 +2089,13 @@ static bool ata_eh_link_established(struct ata_link *link)
 	u32 sstatus;
 	u8 det, ipm;
 
+	/*
+	 * For old IDE/PATA adapters that do not have a valid scr_read method,
+	 * or if reading the SSTATUS register fails, assume that the device is
+	 * present. Device probe will determine if that is really the case.
+	 */
 	if (sata_scr_read(link, SCR_STATUS, &sstatus))
-		return false;
+		return true;
 
 	det = sstatus & 0x0f;
 	ipm = (sstatus >> 8) & 0x0f;
Signature · 1 line
2.50.1
Tested-by on v1 1/1
#1 lore raw
Quoted 12 lines · Damien Le Moal

Commit 4371fe1ba400 ("ata: libata-eh: Avoid unnecessary resets when revalidating devices") replaced the call to ata_phys_link_offline() in ata_eh_revalidate_and_attach() with the new function ata_eh_link_established() which relaxes the checks on a device link state to account for low power mode transitions. However, this changed assumed that the device port has a valid scr_read method to obstain the SSTATUS register for the port. This is not always the case, especially with older IDE/PATA adapters (e.g. as emulated with qemu). For such adapter, ata_eh_link_established() will always return false, causing ata_eh_revalidate_and_attach() to go into its error path and ultimately to the device being disabled.

Quoted 6 lines

Avoid this by restoring the previous behavior, which is to assume that the link is online if reading the port SSTATUS register fails.

Fixes 4371fe1ba400 ("ata: libata-eh: Avoid unnecessary resets when revalidating devices")

Thank you for the fix. I confirmed that this patch avoids the failure of blktests test case scsi/006 with QEMU IDE/PATA device that I reported [1].

[1] https://lore.kernel.org/linux-block/suhzith2uj75uiprq4m3cglvr7qwm3d7gi4tmjeohlxl6fcmv3@zu6zym6nmvun/T/#u

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Damien Le Moal
Quoted 5 lines · Damien Le Moal

Commit 4371fe1ba400 ("ata: libata-eh: Avoid unnecessary resets when revalidating devices") replaced the call to ata_phys_link_offline() in ata_eh_revalidate_and_attach() with the new function ata_eh_link_established() which relaxes the checks on a device link state to account for low power mode transitions. However, this changed

s/changed/change/

Quoted 1 line

assumed that the device port has a valid scr_read method to obstain the

s/obstain/obtain/

Quoted 2 lines

SSTATUS register for the port. This is not always the case, especially with older IDE/PATA adapters (e.g. as emulated with qemu). For such

s/emulated with qemu/PATA emulated with QEMU/

(QEMU also support AHCI emulation)

Quoted 10 lines

adapter, ata_eh_link_established() will always return false, causing ata_eh_revalidate_and_attach() to go into its error path and ultimately to the device being disabled.

Avoid this by restoring the previous behavior, which is to assume that the link is online if reading the port SSTATUS register fails.

Fixes 4371fe1ba400 ("ata: libata-eh: Avoid unnecessary resets when revalidating devices")
#3 lore raw
In reply to Damien Le Moal
Quoted 7 lines · Damien Le Moal

Commit 4371fe1ba400 ("ata: libata-eh: Avoid unnecessary resets when revalidating devices") replaced the call to ata_phys_link_offline() in ata_eh_revalidate_and_attach() with the new function ata_eh_link_established() which relaxes the checks on a device link state to account for low power mode transitions. However, this changed assumed that the device port has a valid scr_read method to obstain the SSTATUS register for the port. This is not always the case, especially

Hum, another nit... Don't the SATA specs call this register SStatus?

Quoted 20 lines

with older IDE/PATA adapters (e.g. as emulated with qemu). For such adapter, ata_eh_link_established() will always return false, causing ata_eh_revalidate_and_attach() to go into its error path and ultimately to the device being disabled.

Avoid this by restoring the previous behavior, which is to assume that the link is online if reading the port SSTATUS register fails.

Fixes 4371fe1ba400 ("ata: libata-eh: Avoid unnecessary resets when revalidating devices")
---
 drivers/ata/libata-eh.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/ata/libata-eh.c +0 -0
index 2946ae6d4b2c..354d2c0abcf3 100644

drivers/ata/libata-eh.c static bool ata_eh_link_established(struct ata_link *link) · line 2094

Quoted 6 lines
drivers/ata/libata-eh.c +3 -0
@@ -2089,8 +2089,13 @@ static bool ata_eh_link_established(struct ata_link *link)
 	u32 sstatus;
 	u8 det, ipm;
 
+	/*
+	 * For old IDE/PATA adapters that do not have a valid scr_read method,
+	 * or if reading the SSTATUS register fails, assume that the device is

Same comment here...

drivers/ata/libata-eh.c static bool ata_eh_link_established(struct ata_link *link) · line 2101

Quoted 8 lines
drivers/ata/libata-eh.c +3 -1
+	 * present. Device probe will determine if that is really the case.
+	 */
 	if (sata_scr_read(link, SCR_STATUS, &sstatus))
-		return false;
+		return true;
 
 	det = sstatus & 0x0f;
 	ipm = (sstatus >> 8) & 0x0f;

MBR, Sergey