Skip to content

Commit 317c4d8

Browse files
committed
Merge tag 'ata-6.18-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/libata/linux
Pull ata fixes from Niklas Cassel: - Add a missing refcount decrement in ata_scsi_dev_rescan() when the device or its queue is not running. In the case where the device is running, the recount is already decremented properly (Yihang Li) - Generate the proper sense code for a Security locked device. There was a regression caused by a recent change of how sense data is generated for commands that did not provide any sense data. This broke system suspend for Security locked devices. Generate the sense data that the SCSI disk driver expects for a Security locked device so that system suspend works again (me) - Set capacity to zero for a Security locked device. All I/O commands will be aborted by a Security locked device. Thus, the block layer disk partition scanning will result in a bunch of, for the user, confusing I/O errors in dmesg during boot. Since a Security locked device is unusable anyway, set the capacity to zero, to avoid the disk partition scanning during boot. We still create the block device in /dev such that the user may unlock the device using e.g. hdparm (me) * tag 'ata-6.18-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/libata/linux: ata: libata-core: Set capacity to zero for a security locked drive ata: libata-scsi: Fix system suspend for a security locked drive ata: libata-scsi: Add missing scsi_device_put() in ata_scsi_dev_rescan()
2 parents 68d804c + 91842ed commit 317c4d8

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

drivers/ata/libata-core.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3006,6 +3006,16 @@ int ata_dev_configure(struct ata_device *dev)
30063006
}
30073007

30083008
dev->n_sectors = ata_id_n_sectors(id);
3009+
if (ata_id_is_locked(id)) {
3010+
/*
3011+
* If Security locked, set capacity to zero to prevent
3012+
* any I/O, e.g. partition scanning, as any I/O to a
3013+
* locked drive will result in user visible errors.
3014+
*/
3015+
ata_dev_info(dev,
3016+
"Security locked, setting capacity to zero\n");
3017+
dev->n_sectors = 0;
3018+
}
30093019

30103020
/* get current R/W Multiple count setting */
30113021
if ((dev->id[47] >> 8) == 0x80 && (dev->id[59] & 0x100)) {

drivers/ata/libata-scsi.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,13 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc)
992992
return;
993993
}
994994

995+
if (ata_id_is_locked(dev->id)) {
996+
/* Security locked */
997+
/* LOGICAL UNIT ACCESS NOT AUTHORIZED */
998+
ata_scsi_set_sense(dev, cmd, DATA_PROTECT, 0x74, 0x71);
999+
return;
1000+
}
1001+
9951002
if (!(qc->flags & ATA_QCFLAG_RTF_FILLED)) {
9961003
ata_dev_dbg(dev,
9971004
"Missing result TF: reporting aborted command\n");
@@ -4894,8 +4901,10 @@ void ata_scsi_dev_rescan(struct work_struct *work)
48944901
spin_unlock_irqrestore(ap->lock, flags);
48954902
if (do_resume) {
48964903
ret = scsi_resume_device(sdev);
4897-
if (ret == -EWOULDBLOCK)
4904+
if (ret == -EWOULDBLOCK) {
4905+
scsi_device_put(sdev);
48984906
goto unlock_scan;
4907+
}
48994908
dev->flags &= ~ATA_DFLAG_RESUMING;
49004909
}
49014910
ret = scsi_rescan_device(sdev);

include/linux/ata.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ struct ata_bmdma_prd {
566566
#define ata_id_has_ncq(id) ((id)[ATA_ID_SATA_CAPABILITY] & (1 << 8))
567567
#define ata_id_queue_depth(id) (((id)[ATA_ID_QUEUE_DEPTH] & 0x1f) + 1)
568568
#define ata_id_removable(id) ((id)[ATA_ID_CONFIG] & (1 << 7))
569+
#define ata_id_is_locked(id) (((id)[ATA_ID_DLF] & 0x7) == 0x7)
569570
#define ata_id_has_atapi_AN(id) \
570571
((((id)[ATA_ID_SATA_CAPABILITY] != 0x0000) && \
571572
((id)[ATA_ID_SATA_CAPABILITY] != 0xffff)) && \

0 commit comments

Comments
 (0)