History

Merge tag 'ata-6.4-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/dlemoal/libata

Pull ata fix from Damien Le Moal: - Avoid deadlocks on resume from sleep by delaying scsi rescan until the scsi device is also fully resumed. * tag 'ata-6.4-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/dlemoal/libata: ata: libata-scsi: Avoid deadlock on rescan after device resume

Linus Torvalds committed 3 years ago

Commit ecbcffe2 parents 1dbbfe2 6aa03654 files · +25 −4Browse files

Unified · Split

4 files
  1. drivers/ata/libata-core.c +2 −1
  2. drivers/ata/libata-eh.c +1 −1
  3. drivers/ata/libata-scsi.c +21 −1
  4. include/linux/libata.h +1 −1
drivers/ata/libata-core.c+2−1
@@ -5348,7 +5348,7 @@ struct ata_port *ata_port_alloc(struct ata_host *host) · 5347 unmodified lines
5348 5348
5349 mutex_init(&ap->scsi_scan_mutex);5349 mutex_init(&ap->scsi_scan_mutex);
5350 INIT_DELAYED_WORK(&ap->hotplug_task, ata_scsi_hotplug);5350 INIT_DELAYED_WORK(&ap->hotplug_task, ata_scsi_hotplug);
5351 INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan);5351 INIT_DELAYED_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan);
5352 INIT_LIST_HEAD(&ap->eh_done_q);5352 INIT_LIST_HEAD(&ap->eh_done_q);
5353 init_waitqueue_head(&ap->eh_wait_q);5353 init_waitqueue_head(&ap->eh_wait_q);
5354 init_completion(&ap->park_req_pending);5354 init_completion(&ap->park_req_pending);
@@ -5954,6 +5954,7 @@ static void ata_port_detach(struct ata_port *ap) · 599 unmodified lines
5954 WARN_ON(!(ap->pflags & ATA_PFLAG_UNLOADED));5954 WARN_ON(!(ap->pflags & ATA_PFLAG_UNLOADED));
5955 5955
5956 cancel_delayed_work_sync(&ap->hotplug_task);5956 cancel_delayed_work_sync(&ap->hotplug_task);
5957 cancel_delayed_work_sync(&ap->scsi_rescan_task);
5957 5958
5958 skip_eh:5959 skip_eh:
5959 /* clean up zpodd on port removal */5960 /* clean up zpodd on port removal */
drivers/ata/libata-eh.c+1−1
@@ -2984,7 +2984,7 @@ static int ata_eh_revalidate_and_attach(struct ata_link *link, · 2983 unmodified lines
2984 ehc->i.flags |= ATA_EHI_SETMODE;2984 ehc->i.flags |= ATA_EHI_SETMODE;
2985 2985
2986 /* schedule the scsi_rescan_device() here */2986 /* schedule the scsi_rescan_device() here */
2987 schedule_work(&(ap->scsi_rescan_task));2987 schedule_delayed_work(&ap->scsi_rescan_task, 0);
2988 } else if (dev->class == ATA_DEV_UNKNOWN &&2988 } else if (dev->class == ATA_DEV_UNKNOWN &&
2989 ehc->tries[dev->devno] &&2989 ehc->tries[dev->devno] &&
2990 ata_class_enabled(ehc->classes[dev->devno])) {2990 ata_class_enabled(ehc->classes[dev->devno])) {
drivers/ata/libata-scsi.c+21−1
@@ -4597,10 +4597,11 @@ int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel, · 4596 unmodified lines
4597void ata_scsi_dev_rescan(struct work_struct *work)4597void ata_scsi_dev_rescan(struct work_struct *work)
4598{4598{
4599 struct ata_port *ap =4599 struct ata_port *ap =
4600 container_of(work, struct ata_port, scsi_rescan_task);4600 container_of(work, struct ata_port, scsi_rescan_task.work);
4601 struct ata_link *link;4601 struct ata_link *link;
4602 struct ata_device *dev;4602 struct ata_device *dev;
4603 unsigned long flags;4603 unsigned long flags;
4604 bool delay_rescan = false;
4604 4605
4605 mutex_lock(&ap->scsi_scan_mutex);4606 mutex_lock(&ap->scsi_scan_mutex);
4606 spin_lock_irqsave(ap->lock, flags);4607 spin_lock_irqsave(ap->lock, flags);
@@ -4614,6 +4615,21 @@ void ata_scsi_dev_rescan(struct work_struct *work) · 7 unmodified lines
4614 if (scsi_device_get(sdev))4615 if (scsi_device_get(sdev))
4615 continue;4616 continue;
4616 4617
4618 /*
4619 * If the rescan work was scheduled because of a resume
4620 * event, the port is already fully resumed, but the
4621 * SCSI device may not yet be fully resumed. In such
4622 * case, executing scsi_rescan_device() may cause a
4623 * deadlock with the PM code on device_lock(). Prevent
4624 * this by giving up and retrying rescan after a short
4625 * delay.
4626 */
4627 delay_rescan = sdev->sdev_gendev.power.is_suspended;
4628 if (delay_rescan) {
4629 scsi_device_put(sdev);
4630 break;
4631 }
4632
4617 spin_unlock_irqrestore(ap->lock, flags);4633 spin_unlock_irqrestore(ap->lock, flags);
4618 scsi_rescan_device(&(sdev->sdev_gendev));4634 scsi_rescan_device(&(sdev->sdev_gendev));
4619 scsi_device_put(sdev);4635 scsi_device_put(sdev);
@@ -4623,4 +4639,8 @@ void ata_scsi_dev_rescan(struct work_struct *work) · 3 unmodified lines
4623 4639
4624 spin_unlock_irqrestore(ap->lock, flags);4640 spin_unlock_irqrestore(ap->lock, flags);
4625 mutex_unlock(&ap->scsi_scan_mutex);4641 mutex_unlock(&ap->scsi_scan_mutex);
4642
4643 if (delay_rescan)
4644 schedule_delayed_work(&ap->scsi_rescan_task,
4645 msecs_to_jiffies(5));
4626}4646}
include/linux/libata.h+1−1
@@ -836,7 +836,7 @@ struct ata_port { · 835 unmodified lines
836 836
837 struct mutex scsi_scan_mutex;837 struct mutex scsi_scan_mutex;
838 struct delayed_work hotplug_task;838 struct delayed_work hotplug_task;
839 struct work_struct scsi_rescan_task;839 struct delayed_work scsi_rescan_task;
840 840
841 unsigned int hsm_task_state;841 unsigned int hsm_task_state;
842 842