Skip to content

Commit e140f73

Browse files
committed
Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
Pull more SCSI updates from James Bottomley: "Mostly small bug fixes and trivial updates. The major new core update is a change to the way device, target and host reference counting is done to try to make it more robust (this change has soaked for a while to try to winkle out any bugs)" * tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi: scsi: pm8001: Fix typo 'the the' in comment scsi: megaraid_sas: Remove redundant variable cmd_type scsi: FlashPoint: Remove redundant variable bm_int_st scsi: zfcp: Fix missing auto port scan and thus missing target ports scsi: core: Call blk_mq_free_tag_set() earlier scsi: core: Simplify LLD module reference counting scsi: core: Make sure that hosts outlive targets scsi: core: Make sure that targets outlive devices scsi: ufs: ufs-pci: Correct check for RESET DSM scsi: target: core: De-RCU of se_lun and se_lun acl scsi: target: core: Fix race during ACL removal scsi: ufs: core: Correct ufshcd_shutdown() flow scsi: ufs: core: Increase the maximum data buffer size scsi: lpfc: Check the return value of alloc_workqueue()
2 parents abe7a48 + c6380f9 commit e140f73

21 files changed

+124
-99
lines changed

drivers/s390/scsi/zfcp_fc.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,27 +145,33 @@ void zfcp_fc_enqueue_event(struct zfcp_adapter *adapter,
145145

146146
static int zfcp_fc_wka_port_get(struct zfcp_fc_wka_port *wka_port)
147147
{
148+
int ret = -EIO;
149+
148150
if (mutex_lock_interruptible(&wka_port->mutex))
149151
return -ERESTARTSYS;
150152

151153
if (wka_port->status == ZFCP_FC_WKA_PORT_OFFLINE ||
152154
wka_port->status == ZFCP_FC_WKA_PORT_CLOSING) {
153155
wka_port->status = ZFCP_FC_WKA_PORT_OPENING;
154-
if (zfcp_fsf_open_wka_port(wka_port))
156+
if (zfcp_fsf_open_wka_port(wka_port)) {
157+
/* could not even send request, nothing to wait for */
155158
wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
159+
goto out;
160+
}
156161
}
157162

158-
mutex_unlock(&wka_port->mutex);
159-
160-
wait_event(wka_port->completion_wq,
163+
wait_event(wka_port->opened,
161164
wka_port->status == ZFCP_FC_WKA_PORT_ONLINE ||
162165
wka_port->status == ZFCP_FC_WKA_PORT_OFFLINE);
163166

164167
if (wka_port->status == ZFCP_FC_WKA_PORT_ONLINE) {
165168
atomic_inc(&wka_port->refcount);
166-
return 0;
169+
ret = 0;
170+
goto out;
167171
}
168-
return -EIO;
172+
out:
173+
mutex_unlock(&wka_port->mutex);
174+
return ret;
169175
}
170176

171177
static void zfcp_fc_wka_port_offline(struct work_struct *work)
@@ -181,9 +187,12 @@ static void zfcp_fc_wka_port_offline(struct work_struct *work)
181187

182188
wka_port->status = ZFCP_FC_WKA_PORT_CLOSING;
183189
if (zfcp_fsf_close_wka_port(wka_port)) {
190+
/* could not even send request, nothing to wait for */
184191
wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
185-
wake_up(&wka_port->completion_wq);
192+
goto out;
186193
}
194+
wait_event(wka_port->closed,
195+
wka_port->status == ZFCP_FC_WKA_PORT_OFFLINE);
187196
out:
188197
mutex_unlock(&wka_port->mutex);
189198
}
@@ -193,13 +202,15 @@ static void zfcp_fc_wka_port_put(struct zfcp_fc_wka_port *wka_port)
193202
if (atomic_dec_return(&wka_port->refcount) != 0)
194203
return;
195204
/* wait 10 milliseconds, other reqs might pop in */
196-
schedule_delayed_work(&wka_port->work, HZ / 100);
205+
queue_delayed_work(wka_port->adapter->work_queue, &wka_port->work,
206+
msecs_to_jiffies(10));
197207
}
198208

199209
static void zfcp_fc_wka_port_init(struct zfcp_fc_wka_port *wka_port, u32 d_id,
200210
struct zfcp_adapter *adapter)
201211
{
202-
init_waitqueue_head(&wka_port->completion_wq);
212+
init_waitqueue_head(&wka_port->opened);
213+
init_waitqueue_head(&wka_port->closed);
203214

204215
wka_port->adapter = adapter;
205216
wka_port->d_id = d_id;

drivers/s390/scsi/zfcp_fc.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ enum zfcp_fc_wka_status {
185185
/**
186186
* struct zfcp_fc_wka_port - representation of well-known-address (WKA) FC port
187187
* @adapter: Pointer to adapter structure this WKA port belongs to
188-
* @completion_wq: Wait for completion of open/close command
188+
* @opened: Wait for completion of open command
189+
* @closed: Wait for completion of close command
189190
* @status: Current status of WKA port
190191
* @refcount: Reference count to keep port open as long as it is in use
191192
* @d_id: FC destination id or well-known-address
@@ -195,7 +196,8 @@ enum zfcp_fc_wka_status {
195196
*/
196197
struct zfcp_fc_wka_port {
197198
struct zfcp_adapter *adapter;
198-
wait_queue_head_t completion_wq;
199+
wait_queue_head_t opened;
200+
wait_queue_head_t closed;
199201
enum zfcp_fc_wka_status status;
200202
atomic_t refcount;
201203
u32 d_id;

drivers/s390/scsi/zfcp_fsf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,7 +1907,7 @@ static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
19071907
wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
19081908
}
19091909
out:
1910-
wake_up(&wka_port->completion_wq);
1910+
wake_up(&wka_port->opened);
19111911
}
19121912

19131913
/**
@@ -1966,7 +1966,7 @@ static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
19661966
}
19671967

19681968
wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1969-
wake_up(&wka_port->completion_wq);
1969+
wake_up(&wka_port->closed);
19701970
}
19711971

19721972
/**

drivers/scsi/FlashPoint.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ static unsigned char FlashPoint_InterruptPending(void *pCurrCard)
17121712
static int FlashPoint_HandleInterrupt(void *pcard)
17131713
{
17141714
struct sccb *currSCCB;
1715-
unsigned char thisCard, result, bm_status, bm_int_st;
1715+
unsigned char thisCard, result, bm_status;
17161716
unsigned short hp_int;
17171717
unsigned char i, target;
17181718
struct sccb_card *pCurrCard = pcard;
@@ -1723,7 +1723,7 @@ static int FlashPoint_HandleInterrupt(void *pcard)
17231723

17241724
MDISABLE_INT(ioport);
17251725

1726-
if ((bm_int_st = RD_HARPOON(ioport + hp_int_status)) & EXT_STATUS_ON)
1726+
if (RD_HARPOON(ioport + hp_int_status) & EXT_STATUS_ON)
17271727
bm_status = RD_HARPOON(ioport + hp_ext_status) &
17281728
(unsigned char)BAD_EXT_STATUS;
17291729
else

drivers/scsi/hosts.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ void scsi_remove_host(struct Scsi_Host *shost)
190190
transport_unregister_device(&shost->shost_gendev);
191191
device_unregister(&shost->shost_dev);
192192
device_del(&shost->shost_gendev);
193+
194+
/*
195+
* After scsi_remove_host() has returned the scsi LLD module can be
196+
* unloaded and/or the host resources can be released. Hence wait until
197+
* the dependent SCSI targets and devices are gone before returning.
198+
*/
199+
wait_event(shost->targets_wq, atomic_read(&shost->target_count) == 0);
200+
201+
scsi_mq_destroy_tags(shost);
193202
}
194203
EXPORT_SYMBOL(scsi_remove_host);
195204

@@ -300,8 +309,8 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,
300309
return error;
301310

302311
/*
303-
* Any host allocation in this function will be freed in
304-
* scsi_host_dev_release().
312+
* Any resources associated with the SCSI host in this function except
313+
* the tag set will be freed by scsi_host_dev_release().
305314
*/
306315
out_del_dev:
307316
device_del(&shost->shost_dev);
@@ -317,6 +326,7 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,
317326
pm_runtime_disable(&shost->shost_gendev);
318327
pm_runtime_set_suspended(&shost->shost_gendev);
319328
pm_runtime_put_noidle(&shost->shost_gendev);
329+
scsi_mq_destroy_tags(shost);
320330
fail:
321331
return error;
322332
}
@@ -350,9 +360,6 @@ static void scsi_host_dev_release(struct device *dev)
350360
kfree(dev_name(&shost->shost_dev));
351361
}
352362

353-
if (shost->tag_set.tags)
354-
scsi_mq_destroy_tags(shost);
355-
356363
kfree(shost->shost_data);
357364

358365
ida_free(&host_index_ida, shost->host_no);
@@ -399,6 +406,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
399406
INIT_LIST_HEAD(&shost->starved_list);
400407
init_waitqueue_head(&shost->host_wait);
401408
mutex_init(&shost->scan_mutex);
409+
init_waitqueue_head(&shost->targets_wq);
402410

403411
index = ida_alloc(&host_index_ida, GFP_KERNEL);
404412
if (index < 0) {

drivers/scsi/lpfc/lpfc_init.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7948,6 +7948,8 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
79487948

79497949
/* The lpfc_wq workqueue for deferred irq use */
79507950
phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0);
7951+
if (!phba->wq)
7952+
return -ENOMEM;
79517953

79527954
/*
79537955
* Initialize timers used by driver

drivers/scsi/megaraid/megaraid_sas_fusion.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3199,7 +3199,6 @@ megasas_build_io_fusion(struct megasas_instance *instance,
31993199
struct megasas_cmd_fusion *cmd)
32003200
{
32013201
int sge_count;
3202-
u8 cmd_type;
32033202
u16 pd_index = 0;
32043203
u8 drive_type = 0;
32053204
struct MPI2_RAID_SCSI_IO_REQUEST *io_request = cmd->io_request;
@@ -3225,7 +3224,7 @@ megasas_build_io_fusion(struct megasas_instance *instance,
32253224
*/
32263225
io_request->IoFlags = cpu_to_le16(scp->cmd_len);
32273226

3228-
switch (cmd_type = megasas_cmd_type(scp)) {
3227+
switch (megasas_cmd_type(scp)) {
32293228
case READ_WRITE_LDIO:
32303229
megasas_build_ldio_fusion(instance, scp, cmd);
32313230
break;

drivers/scsi/pm8001/pm8001_hwi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3138,7 +3138,7 @@ int pm8001_mpi_local_phy_ctl(struct pm8001_hba_info *pm8001_ha, void *piomb)
31383138
*
31393139
* when HBA driver received the identify done event or initiate FIS received
31403140
* event(for SATA), it will invoke this function to notify the sas layer that
3141-
* the sas toplogy has formed, please discover the the whole sas domain,
3141+
* the sas toplogy has formed, please discover the whole sas domain,
31423142
* while receive a broadcast(change) primitive just tell the sas
31433143
* layer to discover the changed domain rather than the whole domain.
31443144
*/

drivers/scsi/scsi.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,13 @@ EXPORT_SYMBOL(scsi_device_get);
586586
*/
587587
void scsi_device_put(struct scsi_device *sdev)
588588
{
589-
struct module *mod = sdev->host->hostt->module;
590-
589+
/*
590+
* Decreasing the module reference count before the device reference
591+
* count is safe since scsi_remove_host() only returns after all
592+
* devices have been removed.
593+
*/
594+
module_put(sdev->host->hostt->module);
591595
put_device(&sdev->sdev_gendev);
592-
module_put(mod);
593596
}
594597
EXPORT_SYMBOL(scsi_device_put);
595598

drivers/scsi/scsi_scan.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,14 @@ static void scsi_target_destroy(struct scsi_target *starget)
406406
static void scsi_target_dev_release(struct device *dev)
407407
{
408408
struct device *parent = dev->parent;
409+
struct Scsi_Host *shost = dev_to_shost(parent);
409410
struct scsi_target *starget = to_scsi_target(dev);
410411

411412
kfree(starget);
413+
414+
if (atomic_dec_return(&shost->target_count) == 0)
415+
wake_up(&shost->targets_wq);
416+
412417
put_device(parent);
413418
}
414419

@@ -521,6 +526,10 @@ static struct scsi_target *scsi_alloc_target(struct device *parent,
521526
starget->state = STARGET_CREATED;
522527
starget->scsi_level = SCSI_2;
523528
starget->max_target_blocked = SCSI_DEFAULT_TARGET_BLOCKED;
529+
init_waitqueue_head(&starget->sdev_wq);
530+
531+
atomic_inc(&shost->target_count);
532+
524533
retry:
525534
spin_lock_irqsave(shost->host_lock, flags);
526535

0 commit comments

Comments
 (0)