Skip to content

Commit b202445

Browse files
djbwJames Bottomley
authored andcommitted
[SCSI] libsas, libata: fix start of life for a sas ata_port
This changes the ordering of initialization and probing events from: 1/ allocate rphy in PORTE_BYTES_DMAED, DISCE_REVALIDATE_DOMAIN 2/ allocate ata_port and schedule port probe in DISCE_PROBE ...to: 1/ allocate ata_port in PORTE_BYTES_DMAED, DISCE_REVALIDATE_DOMAIN 2/ allocate rphy in PORTE_BYTES_DMAED, DISCE_REVALIDATE_DOMAIN 3/ schedule port probe in DISCE_PROBE This ordering prevents PHYE_SIGNAL_LOSS_EVENTS from sneaking in to destrory ata devices before they have been fully initialized: BUG: unable to handle kernel paging request at 0000000000003b10 IP: [<ffffffffa0053d7e>] sas_ata_end_eh+0x12/0x5e [libsas] ... [<ffffffffa004d1af>] sas_unregister_common_dev+0x78/0xc9 [libsas] [<ffffffffa004d4d4>] sas_unregister_dev+0x4f/0xad [libsas] [<ffffffffa004d5b1>] sas_unregister_domain_devices+0x7f/0xbf [libsas] [<ffffffffa004c487>] sas_deform_port+0x61/0x1b8 [libsas] [<ffffffffa004bed0>] sas_phye_loss_of_signal+0x29/0x2b [libsas] ...and kills the awkward "sata domain_device briefly existing in the domain without an ata_port" state. Reported-by: Michal Kosciowski <michal.kosciowski@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com> Acked-by: Jeff Garzik <jgarzik@redhat.com> Signed-off-by: James Bottomley <JBottomley@Parallels.com>
1 parent 0f3fce5 commit b202445

7 files changed

Lines changed: 54 additions & 48 deletions

File tree

‎drivers/ata/libata-scsi.c‎

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3839,18 +3839,25 @@ void ata_sas_port_stop(struct ata_port *ap)
38393839
}
38403840
EXPORT_SYMBOL_GPL(ata_sas_port_stop);
38413841

3842-
int ata_sas_async_port_init(struct ata_port *ap)
3842+
/**
3843+
* ata_sas_async_probe - simply schedule probing and return
3844+
* @ap: Port to probe
3845+
*
3846+
* For batch scheduling of probe for sas attached ata devices, assumes
3847+
* the port has already been through ata_sas_port_init()
3848+
*/
3849+
void ata_sas_async_probe(struct ata_port *ap)
38433850
{
3844-
int rc = ap->ops->port_start(ap);
3845-
3846-
if (!rc) {
3847-
ap->print_id = atomic_inc_return(&ata_print_id);
3848-
__ata_port_probe(ap);
3849-
}
3851+
__ata_port_probe(ap);
3852+
}
3853+
EXPORT_SYMBOL_GPL(ata_sas_async_probe);
38503854

3851-
return rc;
3855+
int ata_sas_sync_probe(struct ata_port *ap)
3856+
{
3857+
return ata_port_probe(ap);
38523858
}
3853-
EXPORT_SYMBOL_GPL(ata_sas_async_port_init);
3859+
EXPORT_SYMBOL_GPL(ata_sas_sync_probe);
3860+
38543861

38553862
/**
38563863
* ata_sas_port_init - Initialize a SATA device
@@ -3867,12 +3874,10 @@ int ata_sas_port_init(struct ata_port *ap)
38673874
{
38683875
int rc = ap->ops->port_start(ap);
38693876

3870-
if (!rc) {
3871-
ap->print_id = atomic_inc_return(&ata_print_id);
3872-
rc = ata_port_probe(ap);
3873-
}
3874-
3875-
return rc;
3877+
if (rc)
3878+
return rc;
3879+
ap->print_id = atomic_inc_return(&ata_print_id);
3880+
return 0;
38763881
}
38773882
EXPORT_SYMBOL_GPL(ata_sas_port_init);
38783883

‎drivers/scsi/ipr.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4549,8 +4549,12 @@ static int ipr_ata_slave_alloc(struct scsi_device *sdev)
45494549
ENTER;
45504550
if (sdev->sdev_target)
45514551
sata_port = sdev->sdev_target->hostdata;
4552-
if (sata_port)
4552+
if (sata_port) {
45534553
rc = ata_sas_port_init(sata_port->ap);
4554+
if (rc == 0)
4555+
rc = ata_sas_sync_probe(sata_port->ap);
4556+
}
4557+
45544558
if (rc)
45554559
ipr_slave_destroy(sdev);
45564560

‎drivers/scsi/libsas/sas_ata.c‎

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -546,11 +546,12 @@ static struct ata_port_info sata_port_info = {
546546
.port_ops = &sas_sata_ops
547547
};
548548

549-
int sas_ata_init_host_and_port(struct domain_device *found_dev)
549+
int sas_ata_init(struct domain_device *found_dev)
550550
{
551551
struct sas_ha_struct *ha = found_dev->port->ha;
552552
struct Scsi_Host *shost = ha->core.shost;
553553
struct ata_port *ap;
554+
int rc;
554555

555556
ata_host_init(&found_dev->sata_dev.ata_host,
556557
ha->dev,
@@ -567,8 +568,11 @@ int sas_ata_init_host_and_port(struct domain_device *found_dev)
567568
ap->private_data = found_dev;
568569
ap->cbl = ATA_CBL_SATA;
569570
ap->scsi_host = shost;
570-
/* publish initialized ata port */
571-
smp_wmb();
571+
rc = ata_sas_port_init(ap);
572+
if (rc) {
573+
ata_sas_port_destroy(ap);
574+
return rc;
575+
}
572576
found_dev->sata_dev.ap = ap;
573577

574578
return 0;
@@ -648,18 +652,13 @@ static void sas_get_ata_command_set(struct domain_device *dev)
648652
void sas_probe_sata(struct asd_sas_port *port)
649653
{
650654
struct domain_device *dev, *n;
651-
int err;
652655

653656
mutex_lock(&port->ha->disco_mutex);
654-
list_for_each_entry_safe(dev, n, &port->disco_list, disco_list_node) {
657+
list_for_each_entry(dev, &port->disco_list, disco_list_node) {
655658
if (!dev_is_sata(dev))
656659
continue;
657660

658-
err = sas_ata_init_host_and_port(dev);
659-
if (err)
660-
sas_fail_probe(dev, __func__, err);
661-
else
662-
ata_sas_async_port_init(dev->sata_dev.ap);
661+
ata_sas_async_probe(dev->sata_dev.ap);
663662
}
664663
mutex_unlock(&port->ha->disco_mutex);
665664

@@ -718,18 +717,6 @@ static void async_sas_ata_eh(void *data, async_cookie_t cookie)
718717
sas_put_device(dev);
719718
}
720719

721-
static bool sas_ata_dev_eh_valid(struct domain_device *dev)
722-
{
723-
struct ata_port *ap;
724-
725-
if (!dev_is_sata(dev))
726-
return false;
727-
ap = dev->sata_dev.ap;
728-
/* consume fully initialized ata ports */
729-
smp_rmb();
730-
return !!ap;
731-
}
732-
733720
void sas_ata_strategy_handler(struct Scsi_Host *shost)
734721
{
735722
struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost);
@@ -753,7 +740,7 @@ void sas_ata_strategy_handler(struct Scsi_Host *shost)
753740

754741
spin_lock(&port->dev_list_lock);
755742
list_for_each_entry(dev, &port->dev_list, dev_list_node) {
756-
if (!sas_ata_dev_eh_valid(dev))
743+
if (!dev_is_sata(dev))
757744
continue;
758745
async_schedule_domain(async_sas_ata_eh, dev, &async);
759746
}

‎drivers/scsi/libsas/sas_discover.c‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static int sas_get_port_device(struct asd_sas_port *port)
7272
struct asd_sas_phy *phy;
7373
struct sas_rphy *rphy;
7474
struct domain_device *dev;
75+
int rc = -ENODEV;
7576

7677
dev = sas_alloc_device();
7778
if (!dev)
@@ -110,9 +111,16 @@ static int sas_get_port_device(struct asd_sas_port *port)
110111

111112
sas_init_dev(dev);
112113

114+
dev->port = port;
113115
switch (dev->dev_type) {
114-
case SAS_END_DEV:
115116
case SATA_DEV:
117+
rc = sas_ata_init(dev);
118+
if (rc) {
119+
rphy = NULL;
120+
break;
121+
}
122+
/* fall through */
123+
case SAS_END_DEV:
116124
rphy = sas_end_device_alloc(port->port);
117125
break;
118126
case EDGE_DEV:
@@ -131,15 +139,14 @@ static int sas_get_port_device(struct asd_sas_port *port)
131139

132140
if (!rphy) {
133141
sas_put_device(dev);
134-
return -ENODEV;
142+
return rc;
135143
}
136144

137145
rphy->identify.phy_identifier = phy->phy->identify.phy_identifier;
138146
memcpy(dev->sas_addr, port->attached_sas_addr, SAS_ADDR_SIZE);
139147
sas_fill_in_rphy(dev, rphy);
140148
sas_hash_addr(dev->hashed_sas_addr, dev->sas_addr);
141149
port->port_dev = dev;
142-
dev->port = port;
143150
dev->linkrate = port->linkrate;
144151
dev->min_linkrate = port->linkrate;
145152
dev->max_linkrate = port->linkrate;

‎drivers/scsi/libsas/sas_expander.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,12 +790,14 @@ static struct domain_device *sas_ex_discover_end_dev(
790790
if (res)
791791
goto out_free;
792792

793+
sas_init_dev(child);
794+
res = sas_ata_init(child);
795+
if (res)
796+
goto out_free;
793797
rphy = sas_end_device_alloc(phy->port);
794-
if (unlikely(!rphy))
798+
if (!rphy)
795799
goto out_free;
796800

797-
sas_init_dev(child);
798-
799801
child->rphy = rphy;
800802
get_device(&rphy->dev);
801803

‎include/linux/libata.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,8 @@ extern int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *dev,
996996
extern void ata_sas_port_destroy(struct ata_port *);
997997
extern struct ata_port *ata_sas_port_alloc(struct ata_host *,
998998
struct ata_port_info *, struct Scsi_Host *);
999-
extern int ata_sas_async_port_init(struct ata_port *);
999+
extern void ata_sas_async_probe(struct ata_port *ap);
1000+
extern int ata_sas_sync_probe(struct ata_port *ap);
10001001
extern int ata_sas_port_init(struct ata_port *);
10011002
extern int ata_sas_port_start(struct ata_port *ap);
10021003
extern void ata_sas_port_stop(struct ata_port *ap);

‎include/scsi/sas_ata.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static inline int dev_is_sata(struct domain_device *dev)
3737
}
3838

3939
int sas_get_ata_info(struct domain_device *dev, struct ex_phy *phy);
40-
int sas_ata_init_host_and_port(struct domain_device *found_dev);
40+
int sas_ata_init(struct domain_device *dev);
4141
void sas_ata_task_abort(struct sas_task *task);
4242
void sas_ata_strategy_handler(struct Scsi_Host *shost);
4343
void sas_ata_eh(struct Scsi_Host *shost, struct list_head *work_q,
@@ -52,7 +52,7 @@ static inline int dev_is_sata(struct domain_device *dev)
5252
{
5353
return 0;
5454
}
55-
static inline int sas_ata_init_host_and_port(struct domain_device *found_dev)
55+
static inline int sas_ata_init(struct domain_device *dev)
5656
{
5757
return 0;
5858
}

0 commit comments

Comments
 (0)