Skip to content

Commit d54820b

Browse files
lnocturnomartinkpetersen
authored andcommitted
scsi: qla2xxx: Fix NULL pointer dereference in target mode
When target mode is enabled, the pci_irq_get_affinity() function may return a NULL value in qla_mapq_init_qp_cpu_map() due to the qla24xx_enable_msix() code that handles IRQ settings for target mode. This leads to a crash due to a NULL pointer dereference. This patch fixes the issue by adding a check for the NULL value returned by pci_irq_get_affinity() and introducing a 'cpu_mapped' boolean flag to the qla_qpair structure, ensuring that the qpair's CPU affinity is updated when it has not been mapped to a CPU. Fixes: 1d201c8 ("scsi: qla2xxx: Select qpair depending on which CPU post_cmd() gets called") Signed-off-by: Gleb Chesnokov <gleb.chesnokov@scst.dev> Link: https://lore.kernel.org/r/56b416f2-4e0f-b6cf-d6d5-b7c372e3c6a2@scst.dev Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 2a737d3 commit d54820b

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

drivers/scsi/qla2xxx/qla_def.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3796,6 +3796,7 @@ struct qla_qpair {
37963796
uint64_t retry_term_jiff;
37973797
struct qla_tgt_counters tgt_counters;
37983798
uint16_t cpuid;
3799+
bool cpu_mapped;
37993800
struct qla_fw_resources fwres ____cacheline_aligned;
38003801
struct qla_buf_pool buf_pool;
38013802
u32 cmd_cnt;

drivers/scsi/qla2xxx/qla_init.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9426,6 +9426,9 @@ struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
94269426
qpair->rsp->req = qpair->req;
94279427
qpair->rsp->qpair = qpair;
94289428

9429+
if (!qpair->cpu_mapped)
9430+
qla_cpu_update(qpair, raw_smp_processor_id());
9431+
94299432
if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
94309433
if (ha->fw_attributes & BIT_4)
94319434
qpair->difdix_supported = 1;

drivers/scsi/qla2xxx/qla_inline.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,14 @@ qla_mapq_init_qp_cpu_map(struct qla_hw_data *ha,
539539
if (!ha->qp_cpu_map)
540540
return;
541541
mask = pci_irq_get_affinity(ha->pdev, msix->vector_base0);
542+
if (!mask)
543+
return;
542544
qpair->cpuid = cpumask_first(mask);
543545
for_each_cpu(cpu, mask) {
544546
ha->qp_cpu_map[cpu] = qpair;
545547
}
546548
msix->cpuid = qpair->cpuid;
549+
qpair->cpu_mapped = true;
547550
}
548551

549552
static inline void

drivers/scsi/qla2xxx/qla_isr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3770,6 +3770,9 @@ void qla24xx_process_response_queue(struct scsi_qla_host *vha,
37703770

37713771
if (rsp->qpair->cpuid != smp_processor_id() || !rsp->qpair->rcv_intr) {
37723772
rsp->qpair->rcv_intr = 1;
3773+
3774+
if (!rsp->qpair->cpu_mapped)
3775+
qla_cpu_update(rsp->qpair, raw_smp_processor_id());
37733776
}
37743777

37753778
#define __update_rsp_in(_is_shadow_hba, _rsp, _rsp_in) \

0 commit comments

Comments
 (0)