Skip to content

Commit 2fe2434

Browse files
John Garrymartinkpetersen
authored andcommitted
scsi: pm8001: Fix phys_to_virt() usage on dma_addr_t
The driver supports a "direct" mode of operation, where the SMP req frame is directly copied into the command payload (and vice-versa for the SMP resp). To get at the SMP req frame data in the scatterlist the driver uses phys_to_virt() on the DMA mapped memory dma_addr_t . This is broken, and subsequently crashes as follows when an IOMMU is enabled: Unable to handle kernel paging request at virtual address ffff0000fcebfb00 ... pc : pm80xx_chip_smp_req+0x2d0/0x3d0 lr : pm80xx_chip_smp_req+0xac/0x3d0 pm80xx_chip_smp_req+0x2d0/0x3d0 pm8001_task_exec.constprop.0+0x368/0x520 pm8001_queue_command+0x1c/0x30 smp_execute_task_sg+0xdc/0x204 sas_discover_expander.part.0+0xac/0x6cc sas_discover_root_expander+0x8c/0x150 sas_discover_domain+0x3ac/0x6a0 process_one_work+0x1d0/0x354 worker_thread+0x13c/0x470 kthread+0x17c/0x190 ret_from_fork+0x10/0x20 Code: 371806e1 910006d6 6b16033f 54000249 (38766b05) ---[ end trace b91d59aaee98ea2d ]--- note: kworker/u192:0[7] exited with preempt_count 1 Instead use kmap_atomic(). -- Difference to v1: - use kmap_atomic() in both locations Difference to v2: - add whitespace around arithmetic (Damien) Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Damien Le Moal <[email protected]> Signed-off-by: John Garry <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 69002c8 commit 2fe2434

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

drivers/scsi/pm8001/pm80xx_hwi.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,7 +3053,6 @@ mpi_smp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
30533053
struct smp_completion_resp *psmpPayload;
30543054
struct task_status_struct *ts;
30553055
struct pm8001_device *pm8001_dev;
3056-
char *pdma_respaddr = NULL;
30573056

30583057
psmpPayload = (struct smp_completion_resp *)(piomb + 4);
30593058
status = le32_to_cpu(psmpPayload->status);
@@ -3080,19 +3079,23 @@ mpi_smp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
30803079
if (pm8001_dev)
30813080
atomic_dec(&pm8001_dev->running_req);
30823081
if (pm8001_ha->smp_exp_mode == SMP_DIRECT) {
3082+
struct scatterlist *sg_resp = &t->smp_task.smp_resp;
3083+
u8 *payload;
3084+
void *to;
3085+
30833086
pm8001_dbg(pm8001_ha, IO,
30843087
"DIRECT RESPONSE Length:%d\n",
30853088
param);
3086-
pdma_respaddr = (char *)(phys_to_virt(cpu_to_le64
3087-
((u64)sg_dma_address
3088-
(&t->smp_task.smp_resp))));
3089+
to = kmap_atomic(sg_page(sg_resp));
3090+
payload = to + sg_resp->offset;
30893091
for (i = 0; i < param; i++) {
3090-
*(pdma_respaddr+i) = psmpPayload->_r_a[i];
3092+
*(payload + i) = psmpPayload->_r_a[i];
30913093
pm8001_dbg(pm8001_ha, IO,
30923094
"SMP Byte%d DMA data 0x%x psmp 0x%x\n",
3093-
i, *(pdma_respaddr + i),
3095+
i, *(payload + i),
30943096
psmpPayload->_r_a[i]);
30953097
}
3098+
kunmap_atomic(to);
30963099
}
30973100
break;
30983101
case IO_ABORTED:
@@ -4236,14 +4239,14 @@ static int pm80xx_chip_smp_req(struct pm8001_hba_info *pm8001_ha,
42364239
struct sas_task *task = ccb->task;
42374240
struct domain_device *dev = task->dev;
42384241
struct pm8001_device *pm8001_dev = dev->lldd_dev;
4239-
struct scatterlist *sg_req, *sg_resp;
4242+
struct scatterlist *sg_req, *sg_resp, *smp_req;
42404243
u32 req_len, resp_len;
42414244
struct smp_req smp_cmd;
42424245
u32 opc;
42434246
struct inbound_queue_table *circularQ;
4244-
char *preq_dma_addr = NULL;
4245-
__le64 tmp_addr;
42464247
u32 i, length;
4248+
u8 *payload;
4249+
u8 *to;
42474250

42484251
memset(&smp_cmd, 0, sizeof(smp_cmd));
42494252
/*
@@ -4280,16 +4283,17 @@ static int pm80xx_chip_smp_req(struct pm8001_hba_info *pm8001_ha,
42804283
pm8001_ha->smp_exp_mode = SMP_INDIRECT;
42814284

42824285

4283-
tmp_addr = cpu_to_le64((u64)sg_dma_address(&task->smp_task.smp_req));
4284-
preq_dma_addr = (char *)phys_to_virt(tmp_addr);
4286+
smp_req = &task->smp_task.smp_req;
4287+
to = kmap_atomic(sg_page(smp_req));
4288+
payload = to + smp_req->offset;
42854289

42864290
/* INDIRECT MODE command settings. Use DMA */
42874291
if (pm8001_ha->smp_exp_mode == SMP_INDIRECT) {
42884292
pm8001_dbg(pm8001_ha, IO, "SMP REQUEST INDIRECT MODE\n");
42894293
/* for SPCv indirect mode. Place the top 4 bytes of
42904294
* SMP Request header here. */
42914295
for (i = 0; i < 4; i++)
4292-
smp_cmd.smp_req16[i] = *(preq_dma_addr + i);
4296+
smp_cmd.smp_req16[i] = *(payload + i);
42934297
/* exclude top 4 bytes for SMP req header */
42944298
smp_cmd.long_smp_req.long_req_addr =
42954299
cpu_to_le64((u64)sg_dma_address
@@ -4320,20 +4324,20 @@ static int pm80xx_chip_smp_req(struct pm8001_hba_info *pm8001_ha,
43204324
pm8001_dbg(pm8001_ha, IO, "SMP REQUEST DIRECT MODE\n");
43214325
for (i = 0; i < length; i++)
43224326
if (i < 16) {
4323-
smp_cmd.smp_req16[i] = *(preq_dma_addr+i);
4327+
smp_cmd.smp_req16[i] = *(payload + i);
43244328
pm8001_dbg(pm8001_ha, IO,
43254329
"Byte[%d]:%x (DMA data:%x)\n",
43264330
i, smp_cmd.smp_req16[i],
4327-
*(preq_dma_addr));
4331+
*(payload));
43284332
} else {
4329-
smp_cmd.smp_req[i] = *(preq_dma_addr+i);
4333+
smp_cmd.smp_req[i] = *(payload + i);
43304334
pm8001_dbg(pm8001_ha, IO,
43314335
"Byte[%d]:%x (DMA data:%x)\n",
43324336
i, smp_cmd.smp_req[i],
4333-
*(preq_dma_addr));
4337+
*(payload));
43344338
}
43354339
}
4336-
4340+
kunmap_atomic(to);
43374341
build_smp_cmd(pm8001_dev->device_id, smp_cmd.tag,
43384342
&smp_cmd, pm8001_ha->smp_exp_mode, length);
43394343
rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &smp_cmd,

0 commit comments

Comments
 (0)