Skip to content

Commit fc93310

Browse files
committed
Merge tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
Pull SCSI fixes from James Bottomley: "Seven fixes, six of which are fairly obvious driver fixes. The one core change to the device budget depth is to try to ensure that if the default depth is large (which can produce quite a sizeable bitmap allocation per device), we give back the memory we don't need if there's a queue size reduction in slave_configure (which happens to a lot of devices)" * tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi: scsi: hisi_sas: Fix setting of hisi_sas_slot.is_internal scsi: pm8001: Fix use-after-free for aborted SSP/STP sas_task scsi: pm8001: Fix use-after-free for aborted TMF sas_task scsi: pm8001: Fix warning for undescribed param in process_one_iomb() scsi: core: Reallocate device's budget map on queue depth change scsi: bnx2fc: Make bnx2fc_recv_frame() mp safe scsi: pm80xx: Fix double completion for SATA devices
2 parents e09e1a4 + c763ec4 commit fc93310

File tree

6 files changed

+77
-67
lines changed

6 files changed

+77
-67
lines changed

drivers/scsi/bnx2fc/bnx2fc_fcoe.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,8 @@ static int bnx2fc_l2_rcv_thread(void *arg)
508508

509509
static void bnx2fc_recv_frame(struct sk_buff *skb)
510510
{
511-
u32 fr_len;
511+
u64 crc_err;
512+
u32 fr_len, fr_crc;
512513
struct fc_lport *lport;
513514
struct fcoe_rcv_info *fr;
514515
struct fc_stats *stats;
@@ -542,6 +543,11 @@ static void bnx2fc_recv_frame(struct sk_buff *skb)
542543
skb_pull(skb, sizeof(struct fcoe_hdr));
543544
fr_len = skb->len - sizeof(struct fcoe_crc_eof);
544545

546+
stats = per_cpu_ptr(lport->stats, get_cpu());
547+
stats->RxFrames++;
548+
stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
549+
put_cpu();
550+
545551
fp = (struct fc_frame *)skb;
546552
fc_frame_init(fp);
547553
fr_dev(fp) = lport;
@@ -624,16 +630,15 @@ static void bnx2fc_recv_frame(struct sk_buff *skb)
624630
return;
625631
}
626632

627-
stats = per_cpu_ptr(lport->stats, smp_processor_id());
628-
stats->RxFrames++;
629-
stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
633+
fr_crc = le32_to_cpu(fr_crc(fp));
630634

631-
if (le32_to_cpu(fr_crc(fp)) !=
632-
~crc32(~0, skb->data, fr_len)) {
633-
if (stats->InvalidCRCCount < 5)
635+
if (unlikely(fr_crc != ~crc32(~0, skb->data, fr_len))) {
636+
stats = per_cpu_ptr(lport->stats, get_cpu());
637+
crc_err = (stats->InvalidCRCCount++);
638+
put_cpu();
639+
if (crc_err < 5)
634640
printk(KERN_WARNING PFX "dropping frame with "
635641
"CRC error\n");
636-
stats->InvalidCRCCount++;
637642
kfree_skb(skb);
638643
return;
639644
}

drivers/scsi/hisi_sas/hisi_sas_main.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,7 @@ void hisi_sas_task_deliver(struct hisi_hba *hisi_hba,
400400
struct hisi_sas_slot *slot,
401401
struct hisi_sas_dq *dq,
402402
struct hisi_sas_device *sas_dev,
403-
struct hisi_sas_internal_abort *abort,
404-
struct hisi_sas_tmf_task *tmf)
403+
struct hisi_sas_internal_abort *abort)
405404
{
406405
struct hisi_sas_cmd_hdr *cmd_hdr_base;
407406
int dlvry_queue_slot, dlvry_queue;
@@ -427,8 +426,6 @@ void hisi_sas_task_deliver(struct hisi_hba *hisi_hba,
427426
cmd_hdr_base = hisi_hba->cmd_hdr[dlvry_queue];
428427
slot->cmd_hdr = &cmd_hdr_base[dlvry_queue_slot];
429428

430-
slot->tmf = tmf;
431-
slot->is_internal = tmf;
432429
task->lldd_task = slot;
433430

434431
memset(slot->cmd_hdr, 0, sizeof(struct hisi_sas_cmd_hdr));
@@ -587,7 +584,7 @@ static int hisi_sas_task_exec(struct sas_task *task, gfp_t gfp_flags,
587584
slot->is_internal = tmf;
588585

589586
/* protect task_prep and start_delivery sequence */
590-
hisi_sas_task_deliver(hisi_hba, slot, dq, sas_dev, NULL, tmf);
587+
hisi_sas_task_deliver(hisi_hba, slot, dq, sas_dev, NULL);
591588

592589
return 0;
593590

@@ -1380,12 +1377,13 @@ static int hisi_sas_softreset_ata_disk(struct domain_device *device)
13801377
struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
13811378
struct device *dev = hisi_hba->dev;
13821379
int s = sizeof(struct host_to_dev_fis);
1380+
struct hisi_sas_tmf_task tmf = {};
13831381

13841382
ata_for_each_link(link, ap, EDGE) {
13851383
int pmp = sata_srst_pmp(link);
13861384

13871385
hisi_sas_fill_ata_reset_cmd(link->device, 1, pmp, fis);
1388-
rc = hisi_sas_exec_internal_tmf_task(device, fis, s, NULL);
1386+
rc = hisi_sas_exec_internal_tmf_task(device, fis, s, &tmf);
13891387
if (rc != TMF_RESP_FUNC_COMPLETE)
13901388
break;
13911389
}
@@ -1396,7 +1394,7 @@ static int hisi_sas_softreset_ata_disk(struct domain_device *device)
13961394

13971395
hisi_sas_fill_ata_reset_cmd(link->device, 0, pmp, fis);
13981396
rc = hisi_sas_exec_internal_tmf_task(device, fis,
1399-
s, NULL);
1397+
s, &tmf);
14001398
if (rc != TMF_RESP_FUNC_COMPLETE)
14011399
dev_err(dev, "ata disk %016llx de-reset failed\n",
14021400
SAS_ADDR(device->sas_addr));
@@ -2067,7 +2065,7 @@ hisi_sas_internal_abort_task_exec(struct hisi_hba *hisi_hba, int device_id,
20672065
slot->port = port;
20682066
slot->is_internal = true;
20692067

2070-
hisi_sas_task_deliver(hisi_hba, slot, dq, sas_dev, abort, NULL);
2068+
hisi_sas_task_deliver(hisi_hba, slot, dq, sas_dev, abort);
20712069

20722070
return 0;
20732071

drivers/scsi/pm8001/pm8001_hwi.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,7 +2692,6 @@ static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
26922692
u32 tag = le32_to_cpu(psataPayload->tag);
26932693
u32 port_id = le32_to_cpu(psataPayload->port_id);
26942694
u32 dev_id = le32_to_cpu(psataPayload->device_id);
2695-
unsigned long flags;
26962695

26972696
if (event)
26982697
pm8001_dbg(pm8001_ha, FAIL, "SATA EVENT 0x%x\n", event);
@@ -2724,8 +2723,6 @@ static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
27242723
ts->resp = SAS_TASK_COMPLETE;
27252724
ts->stat = SAS_DATA_OVERRUN;
27262725
ts->residual = 0;
2727-
if (pm8001_dev)
2728-
atomic_dec(&pm8001_dev->running_req);
27292726
break;
27302727
case IO_XFER_ERROR_BREAK:
27312728
pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
@@ -2767,7 +2764,6 @@ static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
27672764
IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
27682765
ts->resp = SAS_TASK_COMPLETE;
27692766
ts->stat = SAS_QUEUE_FULL;
2770-
pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
27712767
return;
27722768
}
27732769
break;
@@ -2853,20 +2849,6 @@ static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
28532849
ts->stat = SAS_OPEN_TO;
28542850
break;
28552851
}
2856-
spin_lock_irqsave(&t->task_state_lock, flags);
2857-
t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2858-
t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2859-
t->task_state_flags |= SAS_TASK_STATE_DONE;
2860-
if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2861-
spin_unlock_irqrestore(&t->task_state_lock, flags);
2862-
pm8001_dbg(pm8001_ha, FAIL,
2863-
"task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
2864-
t, event, ts->resp, ts->stat);
2865-
pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2866-
} else {
2867-
spin_unlock_irqrestore(&t->task_state_lock, flags);
2868-
pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
2869-
}
28702852
}
28712853

28722854
/*See the comments for mpi_ssp_completion */

drivers/scsi/pm8001/pm8001_sas.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,13 @@ static int pm8001_exec_internal_tmf_task(struct domain_device *dev,
769769
res = -TMF_RESP_FUNC_FAILED;
770770
/* Even TMF timed out, return direct. */
771771
if (task->task_state_flags & SAS_TASK_STATE_ABORTED) {
772+
struct pm8001_ccb_info *ccb = task->lldd_task;
773+
772774
pm8001_dbg(pm8001_ha, FAIL, "TMF task[%x]timeout.\n",
773775
tmf->tmf);
776+
777+
if (ccb)
778+
ccb->task = NULL;
774779
goto ex_err;
775780
}
776781

drivers/scsi/pm8001/pm80xx_hwi.c

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,9 +2185,9 @@ mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
21852185
pm8001_dbg(pm8001_ha, FAIL,
21862186
"task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
21872187
t, status, ts->resp, ts->stat);
2188+
pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
21882189
if (t->slow_task)
21892190
complete(&t->slow_task->completion);
2190-
pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
21912191
} else {
21922192
spin_unlock_irqrestore(&t->task_state_lock, flags);
21932193
pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
@@ -2794,9 +2794,9 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha,
27942794
pm8001_dbg(pm8001_ha, FAIL,
27952795
"task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
27962796
t, status, ts->resp, ts->stat);
2797+
pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
27972798
if (t->slow_task)
27982799
complete(&t->slow_task->completion);
2799-
pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
28002800
} else {
28012801
spin_unlock_irqrestore(&t->task_state_lock, flags);
28022802
spin_unlock_irqrestore(&circularQ->oq_lock,
@@ -2821,7 +2821,6 @@ static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha,
28212821
u32 tag = le32_to_cpu(psataPayload->tag);
28222822
u32 port_id = le32_to_cpu(psataPayload->port_id);
28232823
u32 dev_id = le32_to_cpu(psataPayload->device_id);
2824-
unsigned long flags;
28252824

28262825
if (event)
28272826
pm8001_dbg(pm8001_ha, FAIL, "SATA EVENT 0x%x\n", event);
@@ -2854,8 +2853,6 @@ static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha,
28542853
ts->resp = SAS_TASK_COMPLETE;
28552854
ts->stat = SAS_DATA_OVERRUN;
28562855
ts->residual = 0;
2857-
if (pm8001_dev)
2858-
atomic_dec(&pm8001_dev->running_req);
28592856
break;
28602857
case IO_XFER_ERROR_BREAK:
28612858
pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
@@ -2904,11 +2901,6 @@ static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha,
29042901
IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
29052902
ts->resp = SAS_TASK_COMPLETE;
29062903
ts->stat = SAS_QUEUE_FULL;
2907-
spin_unlock_irqrestore(&circularQ->oq_lock,
2908-
circularQ->lock_flags);
2909-
pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
2910-
spin_lock_irqsave(&circularQ->oq_lock,
2911-
circularQ->lock_flags);
29122904
return;
29132905
}
29142906
break;
@@ -3008,24 +3000,6 @@ static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha,
30083000
ts->stat = SAS_OPEN_TO;
30093001
break;
30103002
}
3011-
spin_lock_irqsave(&t->task_state_lock, flags);
3012-
t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
3013-
t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
3014-
t->task_state_flags |= SAS_TASK_STATE_DONE;
3015-
if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
3016-
spin_unlock_irqrestore(&t->task_state_lock, flags);
3017-
pm8001_dbg(pm8001_ha, FAIL,
3018-
"task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
3019-
t, event, ts->resp, ts->stat);
3020-
pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
3021-
} else {
3022-
spin_unlock_irqrestore(&t->task_state_lock, flags);
3023-
spin_unlock_irqrestore(&circularQ->oq_lock,
3024-
circularQ->lock_flags);
3025-
pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
3026-
spin_lock_irqsave(&circularQ->oq_lock,
3027-
circularQ->lock_flags);
3028-
}
30293003
}
30303004

30313005
/*See the comments for mpi_ssp_completion */
@@ -3931,6 +3905,7 @@ static int ssp_coalesced_comp_resp(struct pm8001_hba_info *pm8001_ha,
39313905
/**
39323906
* process_one_iomb - process one outbound Queue memory block
39333907
* @pm8001_ha: our hba card information
3908+
* @circularQ: outbound circular queue
39343909
* @piomb: IO message buffer
39353910
*/
39363911
static void process_one_iomb(struct pm8001_hba_info *pm8001_ha,

drivers/scsi/scsi_scan.c

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,48 @@ static void scsi_unlock_floptical(struct scsi_device *sdev,
214214
SCSI_TIMEOUT, 3, NULL);
215215
}
216216

217+
static int scsi_realloc_sdev_budget_map(struct scsi_device *sdev,
218+
unsigned int depth)
219+
{
220+
int new_shift = sbitmap_calculate_shift(depth);
221+
bool need_alloc = !sdev->budget_map.map;
222+
bool need_free = false;
223+
int ret;
224+
struct sbitmap sb_backup;
225+
226+
/*
227+
* realloc if new shift is calculated, which is caused by setting
228+
* up one new default queue depth after calling ->slave_configure
229+
*/
230+
if (!need_alloc && new_shift != sdev->budget_map.shift)
231+
need_alloc = need_free = true;
232+
233+
if (!need_alloc)
234+
return 0;
235+
236+
/*
237+
* Request queue has to be frozen for reallocating budget map,
238+
* and here disk isn't added yet, so freezing is pretty fast
239+
*/
240+
if (need_free) {
241+
blk_mq_freeze_queue(sdev->request_queue);
242+
sb_backup = sdev->budget_map;
243+
}
244+
ret = sbitmap_init_node(&sdev->budget_map,
245+
scsi_device_max_queue_depth(sdev),
246+
new_shift, GFP_KERNEL,
247+
sdev->request_queue->node, false, true);
248+
if (need_free) {
249+
if (ret)
250+
sdev->budget_map = sb_backup;
251+
else
252+
sbitmap_free(&sb_backup);
253+
ret = 0;
254+
blk_mq_unfreeze_queue(sdev->request_queue);
255+
}
256+
return ret;
257+
}
258+
217259
/**
218260
* scsi_alloc_sdev - allocate and setup a scsi_Device
219261
* @starget: which target to allocate a &scsi_device for
@@ -306,11 +348,7 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
306348
* default device queue depth to figure out sbitmap shift
307349
* since we use this queue depth most of times.
308350
*/
309-
if (sbitmap_init_node(&sdev->budget_map,
310-
scsi_device_max_queue_depth(sdev),
311-
sbitmap_calculate_shift(depth),
312-
GFP_KERNEL, sdev->request_queue->node,
313-
false, true)) {
351+
if (scsi_realloc_sdev_budget_map(sdev, depth)) {
314352
put_device(&starget->dev);
315353
kfree(sdev);
316354
goto out;
@@ -1017,6 +1055,13 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
10171055
}
10181056
return SCSI_SCAN_NO_RESPONSE;
10191057
}
1058+
1059+
/*
1060+
* The queue_depth is often changed in ->slave_configure.
1061+
* Set up budget map again since memory consumption of
1062+
* the map depends on actual queue depth.
1063+
*/
1064+
scsi_realloc_sdev_budget_map(sdev, sdev->queue_depth);
10201065
}
10211066

10221067
if (sdev->scsi_level >= SCSI_3)

0 commit comments

Comments
 (0)