* [PATCH 2/2] ata: libata-core: Set capacity to zero for a security locked drive
2025-11-19 14:13 [PATCH 1/2] ata: libata-scsi: Fix system suspend for a security locked drive Niklas Cassel
@ 2025-11-19 14:13 ` Niklas Cassel
2025-11-20 3:31 ` Damien Le Moal
` (2 more replies)
2025-11-20 3:29 ` [PATCH 1/2] ata: libata-scsi: Fix system suspend " Damien Le Moal
` (3 subsequent siblings)
4 siblings, 3 replies; 9+ messages in thread
From: Niklas Cassel @ 2025-11-19 14:13 UTC (permalink / raw)
To: Hannes Reinecke, Martin K. Petersen, Damien Le Moal,
Niklas Cassel
Cc: Ilia Baryshnikov, linux-ide
For Security locked drives (drives that have Security enabled, and have
not been Security unlocked by boot firmware), the automatic partition
scanning will result in the user being spammed with errors such as:
ata5.00: failed command: READ DMA
ata5.00: cmd c8/00:08:00:00:00/00:00:00:00:00/e0 tag 7 dma 4096 in
res 51/04:08:00:00:00/00:00:00:00:00/e0 Emask 0x1 (device error)
ata5.00: status: { DRDY ERR }
ata5.00: error: { ABRT }
sd 4:0:0:0: [sda] tag#7 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK cmd_age=0s
sd 4:0:0:0: [sda] tag#7 Sense Key : Aborted Command [current]
sd 4:0:0:0: [sda] tag#7 Add. Sense: No additional sense information
during boot, because most commands except for IDENTIFY will be aborted by
a Security locked drive.
For a Security locked drive, set capacity to zero, so that no automatic
partition scanning will happen.
If the user later unlocks the drive using e.g. hdparm, the close() by the
user space application should trigger a revalidation of the drive.
Signed-off-by: Niklas Cassel <cassel@kernel.org>
---
drivers/ata/libata-core.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 2a210719c4ce..f48fb63d7e85 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -3006,6 +3006,16 @@ int ata_dev_configure(struct ata_device *dev)
}
dev->n_sectors = ata_id_n_sectors(id);
+ if (ata_id_is_locked(id)) {
+ /*
+ * If Security locked, set capacity to zero to prevent
+ * any I/O, e.g. partition scanning, as any I/O to a
+ * locked drive will result in user visible errors.
+ */
+ ata_dev_info(dev,
+ "Security locked, setting capacity to zero\n");
+ dev->n_sectors = 0;
+ }
/* get current R/W Multiple count setting */
if ((dev->id[47] >> 8) == 0x80 && (dev->id[59] & 0x100)) {
--
2.51.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH 2/2] ata: libata-core: Set capacity to zero for a security locked drive
2025-11-19 14:13 ` [PATCH 2/2] ata: libata-core: Set capacity to zero " Niklas Cassel
@ 2025-11-20 3:31 ` Damien Le Moal
2025-11-20 3:49 ` Martin K. Petersen
2025-11-20 7:24 ` Hannes Reinecke
2 siblings, 0 replies; 9+ messages in thread
From: Damien Le Moal @ 2025-11-20 3:31 UTC (permalink / raw)
To: Niklas Cassel, Hannes Reinecke, Martin K. Petersen
Cc: Ilia Baryshnikov, linux-ide
On 11/19/25 11:13 PM, Niklas Cassel wrote:
> For Security locked drives (drives that have Security enabled, and have
> not been Security unlocked by boot firmware), the automatic partition
> scanning will result in the user being spammed with errors such as:
>
> ata5.00: failed command: READ DMA
> ata5.00: cmd c8/00:08:00:00:00/00:00:00:00:00/e0 tag 7 dma 4096 in
> res 51/04:08:00:00:00/00:00:00:00:00/e0 Emask 0x1 (device error)
> ata5.00: status: { DRDY ERR }
> ata5.00: error: { ABRT }
> sd 4:0:0:0: [sda] tag#7 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK cmd_age=0s
> sd 4:0:0:0: [sda] tag#7 Sense Key : Aborted Command [current]
> sd 4:0:0:0: [sda] tag#7 Add. Sense: No additional sense information
>
> during boot, because most commands except for IDENTIFY will be aborted by
> a Security locked drive.
>
> For a Security locked drive, set capacity to zero, so that no automatic
> partition scanning will happen.
>
> If the user later unlocks the drive using e.g. hdparm, the close() by the
> user space application should trigger a revalidation of the drive.
>
> Signed-off-by: Niklas Cassel <cassel@kernel.org>
Looks good.
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 2/2] ata: libata-core: Set capacity to zero for a security locked drive
2025-11-19 14:13 ` [PATCH 2/2] ata: libata-core: Set capacity to zero " Niklas Cassel
2025-11-20 3:31 ` Damien Le Moal
@ 2025-11-20 3:49 ` Martin K. Petersen
2025-11-20 7:24 ` Hannes Reinecke
2 siblings, 0 replies; 9+ messages in thread
From: Martin K. Petersen @ 2025-11-20 3:49 UTC (permalink / raw)
To: Niklas Cassel
Cc: Hannes Reinecke, Martin K. Petersen, Damien Le Moal,
Ilia Baryshnikov, linux-ide
Niklas,
> For Security locked drives (drives that have Security enabled, and have
> not been Security unlocked by boot firmware), the automatic partition
> scanning will result in the user being spammed with errors such as:
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
--
Martin K. Petersen
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] ata: libata-core: Set capacity to zero for a security locked drive
2025-11-19 14:13 ` [PATCH 2/2] ata: libata-core: Set capacity to zero " Niklas Cassel
2025-11-20 3:31 ` Damien Le Moal
2025-11-20 3:49 ` Martin K. Petersen
@ 2025-11-20 7:24 ` Hannes Reinecke
2 siblings, 0 replies; 9+ messages in thread
From: Hannes Reinecke @ 2025-11-20 7:24 UTC (permalink / raw)
To: Niklas Cassel, Martin K. Petersen, Damien Le Moal
Cc: Ilia Baryshnikov, linux-ide
On 11/19/25 15:13, Niklas Cassel wrote:
> For Security locked drives (drives that have Security enabled, and have
> not been Security unlocked by boot firmware), the automatic partition
> scanning will result in the user being spammed with errors such as:
>
> ata5.00: failed command: READ DMA
> ata5.00: cmd c8/00:08:00:00:00/00:00:00:00:00/e0 tag 7 dma 4096 in
> res 51/04:08:00:00:00/00:00:00:00:00/e0 Emask 0x1 (device error)
> ata5.00: status: { DRDY ERR }
> ata5.00: error: { ABRT }
> sd 4:0:0:0: [sda] tag#7 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK cmd_age=0s
> sd 4:0:0:0: [sda] tag#7 Sense Key : Aborted Command [current]
> sd 4:0:0:0: [sda] tag#7 Add. Sense: No additional sense information
>
> during boot, because most commands except for IDENTIFY will be aborted by
> a Security locked drive.
>
> For a Security locked drive, set capacity to zero, so that no automatic
> partition scanning will happen.
>
> If the user later unlocks the drive using e.g. hdparm, the close() by the
> user space application should trigger a revalidation of the drive.
>
> Signed-off-by: Niklas Cassel <cassel@kernel.org>
> ---
> drivers/ata/libata-core.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
> index 2a210719c4ce..f48fb63d7e85 100644
> --- a/drivers/ata/libata-core.c
> +++ b/drivers/ata/libata-core.c
> @@ -3006,6 +3006,16 @@ int ata_dev_configure(struct ata_device *dev)
> }
>
> dev->n_sectors = ata_id_n_sectors(id);
> + if (ata_id_is_locked(id)) {
> + /*
> + * If Security locked, set capacity to zero to prevent
> + * any I/O, e.g. partition scanning, as any I/O to a
> + * locked drive will result in user visible errors.
> + */
> + ata_dev_info(dev,
> + "Security locked, setting capacity to zero\n");
> + dev->n_sectors = 0;
> + }
>
> /* get current R/W Multiple count setting */
> if ((dev->id[47] >> 8) == 0x80 && (dev->id[59] & 0x100)) {
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] ata: libata-scsi: Fix system suspend for a security locked drive
2025-11-19 14:13 [PATCH 1/2] ata: libata-scsi: Fix system suspend for a security locked drive Niklas Cassel
2025-11-19 14:13 ` [PATCH 2/2] ata: libata-core: Set capacity to zero " Niklas Cassel
@ 2025-11-20 3:29 ` Damien Le Moal
2025-11-20 3:48 ` Martin K. Petersen
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Damien Le Moal @ 2025-11-20 3:29 UTC (permalink / raw)
To: Niklas Cassel, Hannes Reinecke, Martin K. Petersen
Cc: Ilia Baryshnikov, stable, linux-ide
On 11/19/25 11:13 PM, Niklas Cassel wrote:
> Commit cf3fc037623c ("ata: libata-scsi: Fix ata_to_sense_error() status
> handling") fixed ata_to_sense_error() to properly generate sense key
> ABORTED COMMAND (without any additional sense code), instead of the
> previous bogus sense key ILLEGAL REQUEST with the additional sense code
> UNALIGNED WRITE COMMAND, for a failed command.
>
> However, this broke suspend for Security locked drives (drives that have
> Security enabled, and have not been Security unlocked by boot firmware).
>
> The reason for this is that the SCSI disk driver, for the Synchronize
> Cache command only, treats any sense data with sense key ILLEGAL REQUEST
> as a successful command (regardless of ASC / ASCQ).
>
> After commit cf3fc037623c ("ata: libata-scsi: Fix ata_to_sense_error()
> status handling") the code that treats any sense data with sense key
> ILLEGAL REQUEST as a successful command is no longer applicable, so the
> command fails, which causes the system suspend to be aborted:
>
> sd 1:0:0:0: PM: dpm_run_callback(): scsi_bus_suspend returns -5
> sd 1:0:0:0: PM: failed to suspend async: error -5
> PM: Some devices failed to suspend, or early wake event detected
>
> To make suspend work once again, for a Security locked device only,
> return sense data LOGICAL UNIT ACCESS NOT AUTHORIZED, the actual sense
> data which a real SCSI device would have returned if locked.
> The SCSI disk driver treats this sense data as a successful command.
>
> Cc: stable@vger.kernel.org
> Reported-by: Ilia Baryshnikov <qwelias@gmail.com>
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220704
> Fixes: cf3fc037623c ("ata: libata-scsi: Fix ata_to_sense_error() status handling")
> Signed-off-by: Niklas Cassel <cassel@kernel.org>
I think that adding this to ata_scsi_flush_xlat() would be better, but this way
may be able to catch more cases like sync failure. So for now, let's go with this.
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 1/2] ata: libata-scsi: Fix system suspend for a security locked drive
2025-11-19 14:13 [PATCH 1/2] ata: libata-scsi: Fix system suspend for a security locked drive Niklas Cassel
2025-11-19 14:13 ` [PATCH 2/2] ata: libata-core: Set capacity to zero " Niklas Cassel
2025-11-20 3:29 ` [PATCH 1/2] ata: libata-scsi: Fix system suspend " Damien Le Moal
@ 2025-11-20 3:48 ` Martin K. Petersen
2025-11-20 7:24 ` Hannes Reinecke
2025-11-20 12:45 ` Niklas Cassel
4 siblings, 0 replies; 9+ messages in thread
From: Martin K. Petersen @ 2025-11-20 3:48 UTC (permalink / raw)
To: Niklas Cassel
Cc: Hannes Reinecke, Martin K. Petersen, Damien Le Moal,
Ilia Baryshnikov, stable, linux-ide
Niklas,
> Commit cf3fc037623c ("ata: libata-scsi: Fix ata_to_sense_error()
> status handling") fixed ata_to_sense_error() to properly generate
> sense key ABORTED COMMAND (without any additional sense code), instead
> of the previous bogus sense key ILLEGAL REQUEST with the additional
> sense code UNALIGNED WRITE COMMAND, for a failed command.
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
--
Martin K. Petersen
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 1/2] ata: libata-scsi: Fix system suspend for a security locked drive
2025-11-19 14:13 [PATCH 1/2] ata: libata-scsi: Fix system suspend for a security locked drive Niklas Cassel
` (2 preceding siblings ...)
2025-11-20 3:48 ` Martin K. Petersen
@ 2025-11-20 7:24 ` Hannes Reinecke
2025-11-20 12:45 ` Niklas Cassel
4 siblings, 0 replies; 9+ messages in thread
From: Hannes Reinecke @ 2025-11-20 7:24 UTC (permalink / raw)
To: Niklas Cassel, Martin K. Petersen, Damien Le Moal
Cc: Ilia Baryshnikov, stable, linux-ide
On 11/19/25 15:13, Niklas Cassel wrote:
> Commit cf3fc037623c ("ata: libata-scsi: Fix ata_to_sense_error() status
> handling") fixed ata_to_sense_error() to properly generate sense key
> ABORTED COMMAND (without any additional sense code), instead of the
> previous bogus sense key ILLEGAL REQUEST with the additional sense code
> UNALIGNED WRITE COMMAND, for a failed command.
>
> However, this broke suspend for Security locked drives (drives that have
> Security enabled, and have not been Security unlocked by boot firmware).
>
> The reason for this is that the SCSI disk driver, for the Synchronize
> Cache command only, treats any sense data with sense key ILLEGAL REQUEST
> as a successful command (regardless of ASC / ASCQ).
>
> After commit cf3fc037623c ("ata: libata-scsi: Fix ata_to_sense_error()
> status handling") the code that treats any sense data with sense key
> ILLEGAL REQUEST as a successful command is no longer applicable, so the
> command fails, which causes the system suspend to be aborted:
>
> sd 1:0:0:0: PM: dpm_run_callback(): scsi_bus_suspend returns -5
> sd 1:0:0:0: PM: failed to suspend async: error -5
> PM: Some devices failed to suspend, or early wake event detected
>
> To make suspend work once again, for a Security locked device only,
> return sense data LOGICAL UNIT ACCESS NOT AUTHORIZED, the actual sense
> data which a real SCSI device would have returned if locked.
> The SCSI disk driver treats this sense data as a successful command.
>
> Cc: stable@vger.kernel.org
> Reported-by: Ilia Baryshnikov <qwelias@gmail.com>
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220704
> Fixes: cf3fc037623c ("ata: libata-scsi: Fix ata_to_sense_error() status handling")
> Signed-off-by: Niklas Cassel <cassel@kernel.org>
> ---
> drivers/ata/libata-scsi.c | 7 +++++++
> include/linux/ata.h | 1 +
> 2 files changed, 8 insertions(+)
>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 1/2] ata: libata-scsi: Fix system suspend for a security locked drive
2025-11-19 14:13 [PATCH 1/2] ata: libata-scsi: Fix system suspend for a security locked drive Niklas Cassel
` (3 preceding siblings ...)
2025-11-20 7:24 ` Hannes Reinecke
@ 2025-11-20 12:45 ` Niklas Cassel
4 siblings, 0 replies; 9+ messages in thread
From: Niklas Cassel @ 2025-11-20 12:45 UTC (permalink / raw)
To: Hannes Reinecke, Martin K. Petersen, Damien Le Moal,
Niklas Cassel
Cc: Ilia Baryshnikov, stable, linux-ide
On Wed, 19 Nov 2025 15:13:14 +0100, Niklas Cassel wrote:
> Commit cf3fc037623c ("ata: libata-scsi: Fix ata_to_sense_error() status
> handling") fixed ata_to_sense_error() to properly generate sense key
> ABORTED COMMAND (without any additional sense code), instead of the
> previous bogus sense key ILLEGAL REQUEST with the additional sense code
> UNALIGNED WRITE COMMAND, for a failed command.
>
> However, this broke suspend for Security locked drives (drives that have
> Security enabled, and have not been Security unlocked by boot firmware).
>
> [...]
Applied to libata/linux.git (for-6.18-fixes), thanks!
[1/2] ata: libata-scsi: Fix system suspend for a security locked drive
https://git.kernel.org/libata/linux/c/b1189068
[2/2] ata: libata-core: Set capacity to zero for a security locked drive
https://git.kernel.org/libata/linux/c/91842ed8
Kind regards,
Niklas
^ permalink raw reply [flat|nested] 9+ messages in thread