Skip to content

Commit 95289e4

Browse files
committed
Merge tag 'ata-6.6-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/dlemoal/libata
Pull ATA fixes from Damien Le Moal: "A larger than usual set of fixes for 6.6-rc4 due to the unexpected number of fixes needed to address ATA disks suspend/resume issues. In more detail: - Add missing additionalProperties on child nodes to the pata-common DT bindings (Rob) - Fix handling of the REPORT SUPPORTED OPERATION CODES command to ignore reserved bits (Niklas) - Increase port multiplier soft reset timeout to accomodate slow devices and avoid issues on wakeup (Matthias) - A couple of minor code fixes to avoid compilation warnings in libata-core and libata-eh (me) - Many patches from me to address suspend/resume issues, and in particular a potential deadlock on resume due to the SCSI disk driver resume operation not being synchronized with libata EH port resume handling. This is addressed by changing the scsi disk driver disk start/stop control to allow libata to execute disk suspend (spin down) and resume (spin up) on its own during system suspend/resume. Runtime suspend/resume control remains with the SCSI disk driver. Other fixes include: - Fix libata power management request issuing to avoid races - Establish a link between ATA ports and SCSI devices to order PM operations - Fix device removal to avoid issues with driver rmmod removal - Fix synchronization of libata device rescan and SCSI disk resume operation - Remove libsas PM operations as suspend/resume is handled directly by the sas controller resume - Fix the SCSI disk driver to not issue commands to suspended disks, thus avoiding potential system lock-up on resume" * tag 'ata-6.6-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/dlemoal/libata: ata: libata-eh: Fix compilation warning in ata_eh_link_report() ata: libata-core: Fix compilation warning in ata_dev_config_ncq() scsi: sd: Do not issue commands to suspended disks on shutdown ata: libata-core: Do not register PM operations for SAS ports ata: libata-scsi: Fix delayed scsi_rescan_device() execution scsi: Do not attempt to rescan suspended devices ata: libata-scsi: Disable scsi device manage_system_start_stop scsi: sd: Differentiate system and runtime start/stop management ata: libata-scsi: link ata port and scsi device ata: libata-core: Fix port and device removal ata: libata-core: Fix ata_port_request_pm() locking ata: libata-sata: increase PMP SRST timeout to 10s ata: libata-scsi: ignore reserved bits for REPORT SUPPORTED OPERATION CODES dt-bindings: ata: pata-common: Add missing additionalProperties on child nodes
2 parents eafdc50 + 49728bd commit 95289e4

File tree

13 files changed

+378
-76
lines changed

13 files changed

+378
-76
lines changed

Documentation/devicetree/bindings/ata/pata-common.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ patternProperties:
3838
ID number 0 and the slave drive will have ID number 1. The PATA port
3939
nodes will be named "ide-port".
4040
type: object
41+
additionalProperties: false
4142

4243
properties:
4344
reg:

drivers/ata/libata-core.c

Lines changed: 137 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,6 +1972,96 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
19721972
return rc;
19731973
}
19741974

1975+
/**
1976+
* ata_dev_power_set_standby - Set a device power mode to standby
1977+
* @dev: target device
1978+
*
1979+
* Issue a STANDBY IMMEDIATE command to set a device power mode to standby.
1980+
* For an HDD device, this spins down the disks.
1981+
*
1982+
* LOCKING:
1983+
* Kernel thread context (may sleep).
1984+
*/
1985+
void ata_dev_power_set_standby(struct ata_device *dev)
1986+
{
1987+
unsigned long ap_flags = dev->link->ap->flags;
1988+
struct ata_taskfile tf;
1989+
unsigned int err_mask;
1990+
1991+
/* Issue STANDBY IMMEDIATE command only if supported by the device */
1992+
if (dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC)
1993+
return;
1994+
1995+
/*
1996+
* Some odd clown BIOSes issue spindown on power off (ACPI S4 or S5)
1997+
* causing some drives to spin up and down again. For these, do nothing
1998+
* if we are being called on shutdown.
1999+
*/
2000+
if ((ap_flags & ATA_FLAG_NO_POWEROFF_SPINDOWN) &&
2001+
system_state == SYSTEM_POWER_OFF)
2002+
return;
2003+
2004+
if ((ap_flags & ATA_FLAG_NO_HIBERNATE_SPINDOWN) &&
2005+
system_entering_hibernation())
2006+
return;
2007+
2008+
ata_tf_init(dev, &tf);
2009+
tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR;
2010+
tf.protocol = ATA_PROT_NODATA;
2011+
tf.command = ATA_CMD_STANDBYNOW1;
2012+
2013+
ata_dev_notice(dev, "Entering standby power mode\n");
2014+
2015+
err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0);
2016+
if (err_mask)
2017+
ata_dev_err(dev, "STANDBY IMMEDIATE failed (err_mask=0x%x)\n",
2018+
err_mask);
2019+
}
2020+
2021+
/**
2022+
* ata_dev_power_set_active - Set a device power mode to active
2023+
* @dev: target device
2024+
*
2025+
* Issue a VERIFY command to enter to ensure that the device is in the
2026+
* active power mode. For a spun-down HDD (standby or idle power mode),
2027+
* the VERIFY command will complete after the disk spins up.
2028+
*
2029+
* LOCKING:
2030+
* Kernel thread context (may sleep).
2031+
*/
2032+
void ata_dev_power_set_active(struct ata_device *dev)
2033+
{
2034+
struct ata_taskfile tf;
2035+
unsigned int err_mask;
2036+
2037+
/*
2038+
* Issue READ VERIFY SECTORS command for 1 sector at lba=0 only
2039+
* if supported by the device.
2040+
*/
2041+
if (dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC)
2042+
return;
2043+
2044+
ata_tf_init(dev, &tf);
2045+
tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR;
2046+
tf.protocol = ATA_PROT_NODATA;
2047+
tf.command = ATA_CMD_VERIFY;
2048+
tf.nsect = 1;
2049+
if (dev->flags & ATA_DFLAG_LBA) {
2050+
tf.flags |= ATA_TFLAG_LBA;
2051+
tf.device |= ATA_LBA;
2052+
} else {
2053+
/* CHS */
2054+
tf.lbal = 0x1; /* sect */
2055+
}
2056+
2057+
ata_dev_notice(dev, "Entering active power mode\n");
2058+
2059+
err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0);
2060+
if (err_mask)
2061+
ata_dev_err(dev, "VERIFY failed (err_mask=0x%x)\n",
2062+
err_mask);
2063+
}
2064+
19752065
/**
19762066
* ata_read_log_page - read a specific log page
19772067
* @dev: target device
@@ -2529,7 +2619,7 @@ static int ata_dev_config_lba(struct ata_device *dev)
25292619
{
25302620
const u16 *id = dev->id;
25312621
const char *lba_desc;
2532-
char ncq_desc[24];
2622+
char ncq_desc[32];
25332623
int ret;
25342624

25352625
dev->flags |= ATA_DFLAG_LBA;
@@ -5037,17 +5127,19 @@ static void ata_port_request_pm(struct ata_port *ap, pm_message_t mesg,
50375127
struct ata_link *link;
50385128
unsigned long flags;
50395129

5040-
/* Previous resume operation might still be in
5041-
* progress. Wait for PM_PENDING to clear.
5130+
spin_lock_irqsave(ap->lock, flags);
5131+
5132+
/*
5133+
* A previous PM operation might still be in progress. Wait for
5134+
* ATA_PFLAG_PM_PENDING to clear.
50425135
*/
50435136
if (ap->pflags & ATA_PFLAG_PM_PENDING) {
5137+
spin_unlock_irqrestore(ap->lock, flags);
50445138
ata_port_wait_eh(ap);
5045-
WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING);
5139+
spin_lock_irqsave(ap->lock, flags);
50465140
}
50475141

5048-
/* request PM ops to EH */
5049-
spin_lock_irqsave(ap->lock, flags);
5050-
5142+
/* Request PM operation to EH */
50515143
ap->pm_mesg = mesg;
50525144
ap->pflags |= ATA_PFLAG_PM_PENDING;
50535145
ata_for_each_link(link, ap, HOST_FIRST) {
@@ -5059,10 +5151,8 @@ static void ata_port_request_pm(struct ata_port *ap, pm_message_t mesg,
50595151

50605152
spin_unlock_irqrestore(ap->lock, flags);
50615153

5062-
if (!async) {
5154+
if (!async)
50635155
ata_port_wait_eh(ap);
5064-
WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING);
5065-
}
50665156
}
50675157

50685158
/*
@@ -5078,11 +5168,27 @@ static const unsigned int ata_port_suspend_ehi = ATA_EHI_QUIET
50785168

50795169
static void ata_port_suspend(struct ata_port *ap, pm_message_t mesg)
50805170
{
5171+
/*
5172+
* We are about to suspend the port, so we do not care about
5173+
* scsi_rescan_device() calls scheduled by previous resume operations.
5174+
* The next resume will schedule the rescan again. So cancel any rescan
5175+
* that is not done yet.
5176+
*/
5177+
cancel_delayed_work_sync(&ap->scsi_rescan_task);
5178+
50815179
ata_port_request_pm(ap, mesg, 0, ata_port_suspend_ehi, false);
50825180
}
50835181

50845182
static void ata_port_suspend_async(struct ata_port *ap, pm_message_t mesg)
50855183
{
5184+
/*
5185+
* We are about to suspend the port, so we do not care about
5186+
* scsi_rescan_device() calls scheduled by previous resume operations.
5187+
* The next resume will schedule the rescan again. So cancel any rescan
5188+
* that is not done yet.
5189+
*/
5190+
cancel_delayed_work_sync(&ap->scsi_rescan_task);
5191+
50865192
ata_port_request_pm(ap, mesg, 0, ata_port_suspend_ehi, true);
50875193
}
50885194

@@ -5229,7 +5335,7 @@ EXPORT_SYMBOL_GPL(ata_host_resume);
52295335
#endif
52305336

52315337
const struct device_type ata_port_type = {
5232-
.name = "ata_port",
5338+
.name = ATA_PORT_TYPE_NAME,
52335339
#ifdef CONFIG_PM
52345340
.pm = &ata_port_pm_ops,
52355341
#endif
@@ -5948,11 +6054,30 @@ static void ata_port_detach(struct ata_port *ap)
59486054
struct ata_link *link;
59496055
struct ata_device *dev;
59506056

5951-
/* tell EH we're leaving & flush EH */
6057+
/* Wait for any ongoing EH */
6058+
ata_port_wait_eh(ap);
6059+
6060+
mutex_lock(&ap->scsi_scan_mutex);
59526061
spin_lock_irqsave(ap->lock, flags);
6062+
6063+
/* Remove scsi devices */
6064+
ata_for_each_link(link, ap, HOST_FIRST) {
6065+
ata_for_each_dev(dev, link, ALL) {
6066+
if (dev->sdev) {
6067+
spin_unlock_irqrestore(ap->lock, flags);
6068+
scsi_remove_device(dev->sdev);
6069+
spin_lock_irqsave(ap->lock, flags);
6070+
dev->sdev = NULL;
6071+
}
6072+
}
6073+
}
6074+
6075+
/* Tell EH to disable all devices */
59536076
ap->pflags |= ATA_PFLAG_UNLOADING;
59546077
ata_port_schedule_eh(ap);
6078+
59556079
spin_unlock_irqrestore(ap->lock, flags);
6080+
mutex_unlock(&ap->scsi_scan_mutex);
59566081

59576082
/* wait till EH commits suicide */
59586083
ata_port_wait_eh(ap);

drivers/ata/libata-eh.c

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ ata_eh_cmd_timeout_table[ATA_EH_CMD_TIMEOUT_TABLE_SIZE] = {
147147
.timeouts = ata_eh_other_timeouts, },
148148
{ .commands = CMDS(ATA_CMD_FLUSH, ATA_CMD_FLUSH_EXT),
149149
.timeouts = ata_eh_flush_timeouts },
150+
{ .commands = CMDS(ATA_CMD_VERIFY),
151+
.timeouts = ata_eh_reset_timeouts },
150152
};
151153
#undef CMDS
152154

@@ -498,7 +500,19 @@ static void ata_eh_unload(struct ata_port *ap)
498500
struct ata_device *dev;
499501
unsigned long flags;
500502

501-
/* Restore SControl IPM and SPD for the next driver and
503+
/*
504+
* Unless we are restarting, transition all enabled devices to
505+
* standby power mode.
506+
*/
507+
if (system_state != SYSTEM_RESTART) {
508+
ata_for_each_link(link, ap, PMP_FIRST) {
509+
ata_for_each_dev(dev, link, ENABLED)
510+
ata_dev_power_set_standby(dev);
511+
}
512+
}
513+
514+
/*
515+
* Restore SControl IPM and SPD for the next driver and
502516
* disable attached devices.
503517
*/
504518
ata_for_each_link(link, ap, PMP_FIRST) {
@@ -684,6 +698,10 @@ void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap)
684698
ehc->saved_xfer_mode[devno] = dev->xfer_mode;
685699
if (ata_ncq_enabled(dev))
686700
ehc->saved_ncq_enabled |= 1 << devno;
701+
702+
/* If we are resuming, wake up the device */
703+
if (ap->pflags & ATA_PFLAG_RESUMING)
704+
ehc->i.dev_action[devno] |= ATA_EH_SET_ACTIVE;
687705
}
688706
}
689707

@@ -743,6 +761,8 @@ void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap)
743761
/* clean up */
744762
spin_lock_irqsave(ap->lock, flags);
745763

764+
ap->pflags &= ~ATA_PFLAG_RESUMING;
765+
746766
if (ap->pflags & ATA_PFLAG_LOADING)
747767
ap->pflags &= ~ATA_PFLAG_LOADING;
748768
else if ((ap->pflags & ATA_PFLAG_SCSI_HOTPLUG) &&
@@ -1218,6 +1238,13 @@ void ata_eh_detach_dev(struct ata_device *dev)
12181238
struct ata_eh_context *ehc = &link->eh_context;
12191239
unsigned long flags;
12201240

1241+
/*
1242+
* If the device is still enabled, transition it to standby power mode
1243+
* (i.e. spin down HDDs).
1244+
*/
1245+
if (ata_dev_enabled(dev))
1246+
ata_dev_power_set_standby(dev);
1247+
12211248
ata_dev_disable(dev);
12221249

12231250
spin_lock_irqsave(ap->lock, flags);
@@ -2305,7 +2332,7 @@ static void ata_eh_link_report(struct ata_link *link)
23052332
struct ata_eh_context *ehc = &link->eh_context;
23062333
struct ata_queued_cmd *qc;
23072334
const char *frozen, *desc;
2308-
char tries_buf[6] = "";
2335+
char tries_buf[16] = "";
23092336
int tag, nr_failed = 0;
23102337

23112338
if (ehc->i.flags & ATA_EHI_QUIET)
@@ -3016,6 +3043,15 @@ static int ata_eh_revalidate_and_attach(struct ata_link *link,
30163043
if (ehc->i.flags & ATA_EHI_DID_RESET)
30173044
readid_flags |= ATA_READID_POSTRESET;
30183045

3046+
/*
3047+
* When resuming, before executing any command, make sure to
3048+
* transition the device to the active power mode.
3049+
*/
3050+
if ((action & ATA_EH_SET_ACTIVE) && ata_dev_enabled(dev)) {
3051+
ata_dev_power_set_active(dev);
3052+
ata_eh_done(link, dev, ATA_EH_SET_ACTIVE);
3053+
}
3054+
30193055
if ((action & ATA_EH_REVALIDATE) && ata_dev_enabled(dev)) {
30203056
WARN_ON(dev->class == ATA_DEV_PMP);
30213057

@@ -3989,6 +4025,7 @@ static void ata_eh_handle_port_suspend(struct ata_port *ap)
39894025
unsigned long flags;
39904026
int rc = 0;
39914027
struct ata_device *dev;
4028+
struct ata_link *link;
39924029

39934030
/* are we suspending? */
39944031
spin_lock_irqsave(ap->lock, flags);
@@ -4001,6 +4038,12 @@ static void ata_eh_handle_port_suspend(struct ata_port *ap)
40014038

40024039
WARN_ON(ap->pflags & ATA_PFLAG_SUSPENDED);
40034040

4041+
/* Set all devices attached to the port in standby mode */
4042+
ata_for_each_link(link, ap, HOST_FIRST) {
4043+
ata_for_each_dev(dev, link, ENABLED)
4044+
ata_dev_power_set_standby(dev);
4045+
}
4046+
40044047
/*
40054048
* If we have a ZPODD attached, check its zero
40064049
* power ready status before the port is frozen.
@@ -4083,6 +4126,7 @@ static void ata_eh_handle_port_resume(struct ata_port *ap)
40834126
/* update the flags */
40844127
spin_lock_irqsave(ap->lock, flags);
40854128
ap->pflags &= ~(ATA_PFLAG_PM_PENDING | ATA_PFLAG_SUSPENDED);
4129+
ap->pflags |= ATA_PFLAG_RESUMING;
40864130
spin_unlock_irqrestore(ap->lock, flags);
40874131
}
40884132
#endif /* CONFIG_PM */

0 commit comments

Comments
 (0)