Skip to content

Commit adbe552

Browse files
Ming Leimartinkpetersen
authored andcommitted
scsi: megaraid_sas: fix selection of reply queue
Since commit 84676c1 ("genirq/affinity: assign vectors to all possible CPUs") we could end up with an MSI-X vector that did not have any online CPUs mapped. This would lead to I/O hangs since there was no CPU to receive the completion. Retrieve IRQ affinity information using pci_irq_get_affinity() and use this mapping to choose a reply queue. [mkp: tweaked commit desc] Cc: Hannes Reinecke <hare@suse.de> Cc: "Martin K. Petersen" <martin.petersen@oracle.com>, Cc: James Bottomley <james.bottomley@hansenpartnership.com>, Cc: Christoph Hellwig <hch@lst.de>, Cc: Don Brace <don.brace@microsemi.com> Cc: Kashyap Desai <kashyap.desai@broadcom.com> Cc: Laurence Oberman <loberman@redhat.com> Cc: Mike Snitzer <snitzer@redhat.com> Cc: Meelis Roos <mroos@linux.ee> Cc: Artem Bityutskiy <artem.bityutskiy@intel.com> Fixes: 84676c1 ("genirq/affinity: assign vectors to all possible CPUs") Signed-off-by: Ming Lei <ming.lei@redhat.com> Acked-by: Kashyap Desai <kashyap.desai@broadcom.com> Tested-by: Kashyap Desai <kashyap.desai@broadcom.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Tested-by: Artem Bityutskiy <artem.bityutskiy@intel.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 8b834bf commit adbe552

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

drivers/scsi/megaraid/megaraid_sas.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,6 +2128,7 @@ enum MR_PD_TYPE {
21282128

21292129
struct megasas_instance {
21302130

2131+
unsigned int *reply_map;
21312132
__le32 *producer;
21322133
dma_addr_t producer_h;
21332134
__le32 *consumer;

drivers/scsi/megaraid/megaraid_sas_base.c

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5165,6 +5165,26 @@ megasas_setup_jbod_map(struct megasas_instance *instance)
51655165
instance->use_seqnum_jbod_fp = false;
51665166
}
51675167

5168+
static void megasas_setup_reply_map(struct megasas_instance *instance)
5169+
{
5170+
const struct cpumask *mask;
5171+
unsigned int queue, cpu;
5172+
5173+
for (queue = 0; queue < instance->msix_vectors; queue++) {
5174+
mask = pci_irq_get_affinity(instance->pdev, queue);
5175+
if (!mask)
5176+
goto fallback;
5177+
5178+
for_each_cpu(cpu, mask)
5179+
instance->reply_map[cpu] = queue;
5180+
}
5181+
return;
5182+
5183+
fallback:
5184+
for_each_possible_cpu(cpu)
5185+
instance->reply_map[cpu] = cpu % instance->msix_vectors;
5186+
}
5187+
51685188
/**
51695189
* megasas_init_fw - Initializes the FW
51705190
* @instance: Adapter soft state
@@ -5343,6 +5363,8 @@ static int megasas_init_fw(struct megasas_instance *instance)
53435363
goto fail_setup_irqs;
53445364
}
53455365

5366+
megasas_setup_reply_map(instance);
5367+
53465368
dev_info(&instance->pdev->dev,
53475369
"firmware supports msix\t: (%d)", fw_msix_count);
53485370
dev_info(&instance->pdev->dev,
@@ -6123,20 +6145,29 @@ static inline int megasas_alloc_mfi_ctrl_mem(struct megasas_instance *instance)
61236145
*/
61246146
static int megasas_alloc_ctrl_mem(struct megasas_instance *instance)
61256147
{
6148+
instance->reply_map = kzalloc(sizeof(unsigned int) * nr_cpu_ids,
6149+
GFP_KERNEL);
6150+
if (!instance->reply_map)
6151+
return -ENOMEM;
6152+
61266153
switch (instance->adapter_type) {
61276154
case MFI_SERIES:
61286155
if (megasas_alloc_mfi_ctrl_mem(instance))
6129-
return -ENOMEM;
6156+
goto fail;
61306157
break;
61316158
case VENTURA_SERIES:
61326159
case THUNDERBOLT_SERIES:
61336160
case INVADER_SERIES:
61346161
if (megasas_alloc_fusion_context(instance))
6135-
return -ENOMEM;
6162+
goto fail;
61366163
break;
61376164
}
61386165

61396166
return 0;
6167+
fail:
6168+
kfree(instance->reply_map);
6169+
instance->reply_map = NULL;
6170+
return -ENOMEM;
61406171
}
61416172

61426173
/*
@@ -6148,6 +6179,7 @@ static int megasas_alloc_ctrl_mem(struct megasas_instance *instance)
61486179
*/
61496180
static inline void megasas_free_ctrl_mem(struct megasas_instance *instance)
61506181
{
6182+
kfree(instance->reply_map);
61516183
if (instance->adapter_type == MFI_SERIES) {
61526184
if (instance->producer)
61536185
pci_free_consistent(instance->pdev, sizeof(u32),
@@ -6540,7 +6572,6 @@ static int megasas_probe_one(struct pci_dev *pdev,
65406572
pci_free_irq_vectors(instance->pdev);
65416573
fail_init_mfi:
65426574
scsi_host_put(host);
6543-
65446575
fail_alloc_instance:
65456576
pci_disable_device(pdev);
65466577

@@ -6746,6 +6777,8 @@ megasas_resume(struct pci_dev *pdev)
67466777
if (rval < 0)
67476778
goto fail_reenable_msix;
67486779

6780+
megasas_setup_reply_map(instance);
6781+
67496782
if (instance->adapter_type != MFI_SERIES) {
67506783
megasas_reset_reply_desc(instance);
67516784
if (megasas_ioc_init_fusion(instance)) {

drivers/scsi/megaraid/megaraid_sas_fusion.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,11 +2641,8 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
26412641
fp_possible = (io_info.fpOkForIo > 0) ? true : false;
26422642
}
26432643

2644-
/* Use raw_smp_processor_id() for now until cmd->request->cpu is CPU
2645-
id by default, not CPU group id, otherwise all MSI-X queues won't
2646-
be utilized */
2647-
cmd->request_desc->SCSIIO.MSIxIndex = instance->msix_vectors ?
2648-
raw_smp_processor_id() % instance->msix_vectors : 0;
2644+
cmd->request_desc->SCSIIO.MSIxIndex =
2645+
instance->reply_map[raw_smp_processor_id()];
26492646

26502647
praid_context = &io_request->RaidContext;
26512648

@@ -2971,10 +2968,9 @@ megasas_build_syspd_fusion(struct megasas_instance *instance,
29712968
}
29722969

29732970
cmd->request_desc->SCSIIO.DevHandle = io_request->DevHandle;
2974-
cmd->request_desc->SCSIIO.MSIxIndex =
2975-
instance->msix_vectors ?
2976-
(raw_smp_processor_id() % instance->msix_vectors) : 0;
29772971

2972+
cmd->request_desc->SCSIIO.MSIxIndex =
2973+
instance->reply_map[raw_smp_processor_id()];
29782974

29792975
if (!fp_possible) {
29802976
/* system pd firmware path */

0 commit comments

Comments
 (0)