Skip to content

Commit 27fa826

Browse files
committed
Merge tag 'ata-7.1-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/libata/linux
Pull ata fixes from Niklas Cassel: - Make sure that the issuing of a deferred non-NCQ command via workqueue feature is only used when mixing NCQ and non-NCQ commands to the same link (i.e. return value ATA_DEFER_LINK), and nothing else. This way we will not incorrectly try to use the feature for e.g. PATA drivers - The deferred non-NCQ command was stored in a per-port struct. When using Port Multipliers with FIS-Based Switching, we would thus needlessly defer commands to all other links. Store the deferred QC in a per-link struct, such that Port Multipliers with FBS will get the same performance as before - The issuing of a deferred non-NCQ command via workqueue feature broke support for Port Multipliers using Command-Based Switching. The issuing of a deferred non-NCQ command via workqueue feature is not compatible with the use of ap->excl_link, which PMPs with CBS use for fairness (using implicit round robin) * tag 'ata-7.1-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/libata/linux: ata: libata-scsi: do not needlessly defer commands when using PMP with FBS ata: libata-scsi: do not use the deferred QC feature on PMPs with CBS ata: libata-scsi: do not use the deferred QC feature for ATA_DEFER_PORT ata: libata-scsi: improve readability of ata_scsi_qc_issue()
2 parents 1a2ab0f + 759e875 commit 27fa826

6 files changed

Lines changed: 87 additions & 50 deletions

File tree

drivers/ata/libata-core.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5584,6 +5584,7 @@ void ata_link_init(struct ata_port *ap, struct ata_link *link, int pmp)
55845584
link->pmp = pmp;
55855585
link->active_tag = ATA_TAG_POISON;
55865586
link->hw_sata_spd_limit = UINT_MAX;
5587+
INIT_WORK(&link->deferred_qc_work, ata_scsi_deferred_qc_work);
55875588

55885589
/* can't use iterator, ap isn't initialized yet */
55895590
for (i = 0; i < ATA_MAX_DEVICES; i++) {
@@ -5666,7 +5667,6 @@ struct ata_port *ata_port_alloc(struct ata_host *host)
56665667
mutex_init(&ap->scsi_scan_mutex);
56675668
INIT_DELAYED_WORK(&ap->hotplug_task, ata_scsi_hotplug);
56685669
INIT_DELAYED_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan);
5669-
INIT_WORK(&ap->deferred_qc_work, ata_scsi_deferred_qc_work);
56705670
INIT_LIST_HEAD(&ap->eh_done_q);
56715671
init_waitqueue_head(&ap->eh_wait_q);
56725672
init_completion(&ap->park_req_pending);
@@ -6291,12 +6291,15 @@ static void ata_port_detach(struct ata_port *ap)
62916291

62926292
/* It better be dead now and not have any remaining deferred qc. */
62936293
WARN_ON(!(ap->pflags & ATA_PFLAG_UNLOADED));
6294-
WARN_ON(ap->deferred_qc);
62956294

6296-
cancel_work_sync(&ap->deferred_qc_work);
62976295
cancel_delayed_work_sync(&ap->hotplug_task);
62986296
cancel_delayed_work_sync(&ap->scsi_rescan_task);
62996297

6298+
ata_for_each_link(link, ap, PMP_FIRST) {
6299+
WARN_ON(link->deferred_qc);
6300+
cancel_work_sync(&link->deferred_qc_work);
6301+
}
6302+
63006303
/* Delete port multiplier link transport devices */
63016304
if (ap->pmp_link) {
63026305
int i;

drivers/ata/libata-eh.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -651,11 +651,11 @@ int ata_scsi_cmd_error_handler(struct Scsi_Host *host, struct ata_port *ap,
651651
if (qc->scsicmd != scmd)
652652
continue;
653653
if ((qc->flags & ATA_QCFLAG_ACTIVE) ||
654-
qc == ap->deferred_qc)
654+
qc == qc->dev->link->deferred_qc)
655655
break;
656656
}
657657

658-
if (i < ATA_MAX_QUEUE && qc == ap->deferred_qc) {
658+
if (i < ATA_MAX_QUEUE && qc == qc->dev->link->deferred_qc) {
659659
/*
660660
* This is a deferred command that timed out while
661661
* waiting for the command queue to drain. Since the qc
@@ -666,8 +666,8 @@ int ata_scsi_cmd_error_handler(struct Scsi_Host *host, struct ata_port *ap,
666666
* deferred qc work from issuing this qc.
667667
*/
668668
WARN_ON_ONCE(qc->flags & ATA_QCFLAG_ACTIVE);
669-
ap->deferred_qc = NULL;
670-
cancel_work(&ap->deferred_qc_work);
669+
qc->dev->link->deferred_qc = NULL;
670+
cancel_work(&qc->dev->link->deferred_qc_work);
671671
set_host_byte(scmd, DID_TIME_OUT);
672672
scsi_eh_finish_cmd(scmd, &ap->eh_done_q);
673673
} else if (i < ATA_MAX_QUEUE) {

drivers/ata/libata-pmp.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,24 @@ int sata_pmp_qc_defer_cmd_switch(struct ata_queued_cmd *qc)
110110
{
111111
struct ata_link *link = qc->dev->link;
112112
struct ata_port *ap = link->ap;
113+
int ret;
113114

114115
if (ap->excl_link == NULL || ap->excl_link == link) {
115116
if (ap->nr_active_links == 0 || ata_link_active(link)) {
116117
qc->flags |= ATA_QCFLAG_CLEAR_EXCL;
117-
return ata_std_qc_defer(qc);
118+
ret = ata_std_qc_defer(qc);
119+
if (ret == ATA_DEFER_LINK)
120+
return ATA_DEFER_LINK_EXCL;
121+
return ret;
118122
}
119123

124+
/*
125+
* Note: ap->excl_link contains the link that is next in line,
126+
* i.e. implicit round robin. If there is only one link
127+
* dispatching, ap->excl_link will be left unclaimed, allowing
128+
* other links to set ap->excl_link, ensuring that the currently
129+
* active link cannot queue any more.
130+
*/
120131
ap->excl_link = link;
121132
}
122133

@@ -571,8 +582,11 @@ static void sata_pmp_detach(struct ata_device *dev)
571582
if (ap->ops->pmp_detach)
572583
ap->ops->pmp_detach(ap);
573584

574-
ata_for_each_link(tlink, ap, EDGE)
585+
ata_for_each_link(tlink, ap, EDGE) {
586+
WARN_ON(tlink->deferred_qc);
587+
cancel_work_sync(&tlink->deferred_qc_work);
575588
ata_eh_detach_dev(tlink->device);
589+
}
576590

577591
spin_lock_irqsave(ap->lock, flags);
578592
ap->nr_pmp_links = 0;

drivers/ata/libata-scsi.c

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,8 +1664,9 @@ static void ata_scsi_qc_done(struct ata_queued_cmd *qc, bool set_result,
16641664

16651665
void ata_scsi_deferred_qc_work(struct work_struct *work)
16661666
{
1667-
struct ata_port *ap =
1668-
container_of(work, struct ata_port, deferred_qc_work);
1667+
struct ata_link *link =
1668+
container_of(work, struct ata_link, deferred_qc_work);
1669+
struct ata_port *ap = link->ap;
16691670
struct ata_queued_cmd *qc;
16701671
unsigned long flags;
16711672

@@ -1676,10 +1677,10 @@ void ata_scsi_deferred_qc_work(struct work_struct *work)
16761677
* such case, we should not need any more deferring the qc, so warn if
16771678
* qc_defer() says otherwise.
16781679
*/
1679-
qc = ap->deferred_qc;
1680+
qc = link->deferred_qc;
16801681
if (qc && !ata_port_eh_scheduled(ap)) {
16811682
WARN_ON_ONCE(ap->ops->qc_defer(qc));
1682-
ap->deferred_qc = NULL;
1683+
link->deferred_qc = NULL;
16831684
ata_qc_issue(qc);
16841685
}
16851686

@@ -1688,7 +1689,7 @@ void ata_scsi_deferred_qc_work(struct work_struct *work)
16881689

16891690
void ata_scsi_requeue_deferred_qc(struct ata_port *ap)
16901691
{
1691-
struct ata_queued_cmd *qc = ap->deferred_qc;
1692+
struct ata_link *link;
16921693

16931694
lockdep_assert_held(ap->lock);
16941695

@@ -1697,16 +1698,21 @@ void ata_scsi_requeue_deferred_qc(struct ata_port *ap)
16971698
* do not try to be smart about what to do with this deferred command
16981699
* and simply requeue it by completing it with DID_REQUEUE.
16991700
*/
1700-
if (qc) {
1701-
ap->deferred_qc = NULL;
1702-
cancel_work(&ap->deferred_qc_work);
1703-
ata_scsi_qc_done(qc, true, DID_REQUEUE << 16);
1701+
ata_for_each_link(link, ap, PMP_FIRST) {
1702+
struct ata_queued_cmd *qc = link->deferred_qc;
1703+
1704+
if (qc) {
1705+
link->deferred_qc = NULL;
1706+
cancel_work(&link->deferred_qc_work);
1707+
ata_scsi_qc_done(qc, true, DID_REQUEUE << 16);
1708+
}
17041709
}
17051710
}
17061711

1707-
static void ata_scsi_schedule_deferred_qc(struct ata_port *ap)
1712+
static void ata_scsi_schedule_deferred_qc(struct ata_link *link)
17081713
{
1709-
struct ata_queued_cmd *qc = ap->deferred_qc;
1714+
struct ata_queued_cmd *qc = link->deferred_qc;
1715+
struct ata_port *ap = link->ap;
17101716

17111717
lockdep_assert_held(ap->lock);
17121718

@@ -1723,12 +1729,12 @@ static void ata_scsi_schedule_deferred_qc(struct ata_port *ap)
17231729
return;
17241730
}
17251731
if (!ap->ops->qc_defer(qc))
1726-
queue_work(system_highpri_wq, &ap->deferred_qc_work);
1732+
queue_work(system_highpri_wq, &link->deferred_qc_work);
17271733
}
17281734

17291735
static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
17301736
{
1731-
struct ata_port *ap = qc->ap;
1737+
struct ata_link *link = qc->dev->link;
17321738
struct scsi_cmnd *cmd = qc->scsicmd;
17331739
u8 *cdb = cmd->cmnd;
17341740
bool have_sense = qc->flags & ATA_QCFLAG_SENSE_VALID;
@@ -1759,22 +1765,23 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
17591765

17601766
ata_scsi_qc_done(qc, false, 0);
17611767

1762-
ata_scsi_schedule_deferred_qc(ap);
1768+
ata_scsi_schedule_deferred_qc(link);
17631769
}
17641770

17651771
static int ata_scsi_qc_issue(struct ata_port *ap, struct ata_queued_cmd *qc)
17661772
{
1773+
struct ata_link *link = qc->dev->link;
17671774
int ret;
17681775

17691776
if (!ap->ops->qc_defer)
1770-
goto issue;
1777+
goto issue_qc;
17711778

17721779
/*
17731780
* If we already have a deferred qc, then rely on the SCSI layer to
17741781
* requeue and defer all incoming commands until the deferred qc is
17751782
* processed, once all on-going commands complete.
17761783
*/
1777-
if (ap->deferred_qc) {
1784+
if (link->deferred_qc) {
17781785
ata_qc_free(qc);
17791786
return SCSI_MLQUEUE_DEVICE_BUSY;
17801787
}
@@ -1786,38 +1793,46 @@ static int ata_scsi_qc_issue(struct ata_port *ap, struct ata_queued_cmd *qc)
17861793
break;
17871794
case ATA_DEFER_LINK:
17881795
ret = SCSI_MLQUEUE_DEVICE_BUSY;
1789-
break;
1796+
goto defer_qc;
1797+
case ATA_DEFER_LINK_EXCL:
1798+
/*
1799+
* Drivers making use of ap->excl_link cannot store the QC in
1800+
* link->deferred_qc, because the ap->excl_link handling is
1801+
* incompatible with the link->deferred_qc workqueue handling.
1802+
*/
1803+
ret = SCSI_MLQUEUE_DEVICE_BUSY;
1804+
goto free_qc;
17901805
case ATA_DEFER_PORT:
17911806
ret = SCSI_MLQUEUE_HOST_BUSY;
1792-
break;
1807+
goto free_qc;
17931808
default:
17941809
WARN_ON_ONCE(1);
17951810
ret = SCSI_MLQUEUE_HOST_BUSY;
1796-
break;
1811+
goto free_qc;
17971812
}
17981813

1799-
if (ret) {
1800-
/*
1801-
* We must defer this qc: if this is not an NCQ command, keep
1802-
* this qc as a deferred one and report to the SCSI layer that
1803-
* we issued it so that it is not requeued. The deferred qc will
1804-
* be issued with the port deferred_qc_work once all on-going
1805-
* commands complete.
1806-
*/
1807-
if (!ata_is_ncq(qc->tf.protocol)) {
1808-
ap->deferred_qc = qc;
1809-
return 0;
1810-
}
1814+
issue_qc:
1815+
ata_qc_issue(qc);
1816+
return 0;
18111817

1812-
/* Force a requeue of the command to defer its execution. */
1813-
ata_qc_free(qc);
1814-
return ret;
1818+
defer_qc:
1819+
/*
1820+
* We must defer this qc: if this is not an NCQ command, keep
1821+
* this qc as a deferred one and report to the SCSI layer that
1822+
* we issued it so that it is not requeued. The deferred qc will
1823+
* be issued with the port deferred_qc_work once all on-going
1824+
* commands complete.
1825+
*/
1826+
if (!ata_is_ncq(qc->tf.protocol)) {
1827+
link->deferred_qc = qc;
1828+
return 0;
18151829
}
18161830

1817-
issue:
1818-
ata_qc_issue(qc);
1831+
free_qc:
1832+
/* Force a requeue of the command to defer its execution. */
1833+
ata_qc_free(qc);
18191834

1820-
return 0;
1835+
return ret;
18211836
}
18221837

18231838
/**

drivers/ata/sata_sil24.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ static int sil24_qc_defer(struct ata_queued_cmd *qc)
789789
struct ata_link *link = qc->dev->link;
790790
struct ata_port *ap = link->ap;
791791
u8 prot = qc->tf.protocol;
792+
int ret;
792793

793794
/*
794795
* There is a bug in the chip:
@@ -826,7 +827,10 @@ static int sil24_qc_defer(struct ata_queued_cmd *qc)
826827
qc->flags |= ATA_QCFLAG_CLEAR_EXCL;
827828
}
828829

829-
return ata_std_qc_defer(qc);
830+
ret = ata_std_qc_defer(qc);
831+
if (ret == ATA_DEFER_LINK)
832+
return ATA_DEFER_LINK_EXCL;
833+
return ret;
830834
}
831835

832836
static enum ata_completion_errors sil24_qc_prep(struct ata_queued_cmd *qc)

include/linux/libata.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ enum {
371371
/* return values for ->qc_defer */
372372
ATA_DEFER_LINK = 1,
373373
ATA_DEFER_PORT = 2,
374+
ATA_DEFER_LINK_EXCL = 3,
374375

375376
/* desc_len for ata_eh_info and context */
376377
ATA_EH_DESC_LEN = 80,
@@ -854,6 +855,9 @@ struct ata_link {
854855
unsigned int sata_spd; /* current SATA PHY speed */
855856
enum ata_lpm_policy lpm_policy;
856857

858+
struct work_struct deferred_qc_work;
859+
struct ata_queued_cmd *deferred_qc;
860+
857861
/* record runtime error info, protected by host_set lock */
858862
struct ata_eh_info eh_info;
859863
/* EH context */
@@ -899,9 +903,6 @@ struct ata_port {
899903
u64 qc_active;
900904
int nr_active_links; /* #links with active qcs */
901905

902-
struct work_struct deferred_qc_work;
903-
struct ata_queued_cmd *deferred_qc;
904-
905906
struct ata_link link; /* host default link */
906907
struct ata_link *slave_link; /* see ata_slave_link_init() */
907908

0 commit comments

Comments
 (0)