Skip to content

Commit f6a3cfe

Browse files
Mike Marciniszynjgunthorpe
authored andcommitted
IB/hfi1: Fix early init panic
The following trace can be observed with an init failure such as firmware load failures: BUG: unable to handle kernel NULL pointer dereference at 0000000000000000 PGD 0 P4D 0 Oops: 0010 [#1] SMP PTI CPU: 0 PID: 537 Comm: kworker/0:3 Tainted: G OE --------- - - 4.18.0-240.el8.x86_64 #1 Workqueue: events work_for_cpu_fn RIP: 0010:0x0 Code: Bad RIP value. RSP: 0000:ffffae5f878a3c98 EFLAGS: 00010046 RAX: 0000000000000000 RBX: ffff95e48e025c00 RCX: 0000000000000000 RDX: 0000000000000001 RSI: 0000000000000000 RDI: ffff95e48e025c00 RBP: ffff95e4bf3660a4 R08: 0000000000000000 R09: ffffffff86d5e100 R10: ffff95e49e1de600 R11: 0000000000000001 R12: ffff95e4bf366180 R13: ffff95e48e025c00 R14: ffff95e4bf366028 R15: ffff95e4bf366000 FS: 0000000000000000(0000) GS:ffff95e4df200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffffffffffffffd6 CR3: 0000000f86a0a003 CR4: 00000000001606f0 Call Trace: receive_context_interrupt+0x1f/0x40 [hfi1] __free_irq+0x201/0x300 free_irq+0x2e/0x60 pci_free_irq+0x18/0x30 msix_free_irq.part.2+0x46/0x80 [hfi1] msix_clean_up_interrupts+0x2b/0x70 [hfi1] hfi1_init_dd+0x640/0x1a90 [hfi1] do_init_one.isra.19+0x34d/0x680 [hfi1] local_pci_probe+0x41/0x90 work_for_cpu_fn+0x16/0x20 process_one_work+0x1a7/0x360 worker_thread+0x1cf/0x390 ? create_worker+0x1a0/0x1a0 kthread+0x112/0x130 ? kthread_flush_work_fn+0x10/0x10 ret_from_fork+0x35/0x40 The free_irq() results in a callback to the registered interrupt handler, and rcd->do_interrupt is NULL because the receive context data structures are not fully initialized. Fix by ensuring that the do_interrupt is always assigned and adding a guards in the slow path handler to detect and handle a partially initialized receive context and noop the receive. Link: https://lore.kernel.org/r/[email protected] Cc: [email protected] Fixes: b0ba3c1 ("IB/hfi1: Move normal functions from hfi1_devdata to const array") Signed-off-by: Mike Marciniszyn <[email protected]> Signed-off-by: Dennis Dalessandro <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent b6d57e2 commit f6a3cfe

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

drivers/infiniband/hw/hfi1/chip.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8415,6 +8415,8 @@ static void receive_interrupt_common(struct hfi1_ctxtdata *rcd)
84158415
*/
84168416
static void __hfi1_rcd_eoi_intr(struct hfi1_ctxtdata *rcd)
84178417
{
8418+
if (!rcd->rcvhdrq)
8419+
return;
84188420
clear_recv_intr(rcd);
84198421
if (check_packet_present(rcd))
84208422
force_recv_intr(rcd);

drivers/infiniband/hw/hfi1/driver.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,8 @@ int handle_receive_interrupt(struct hfi1_ctxtdata *rcd, int thread)
10121012
struct hfi1_packet packet;
10131013
int skip_pkt = 0;
10141014

1015+
if (!rcd->rcvhdrq)
1016+
return RCV_PKT_OK;
10151017
/* Control context will always use the slow path interrupt handler */
10161018
needset = (rcd->ctxt == HFI1_CTRL_CTXT) ? 0 : 1;
10171019

drivers/infiniband/hw/hfi1/init.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ static int hfi1_create_kctxt(struct hfi1_devdata *dd,
113113
rcd->fast_handler = get_dma_rtail_setting(rcd) ?
114114
handle_receive_interrupt_dma_rtail :
115115
handle_receive_interrupt_nodma_rtail;
116-
rcd->slow_handler = handle_receive_interrupt;
117116

118117
hfi1_set_seq_cnt(rcd, 1);
119118

@@ -334,6 +333,8 @@ int hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, int numa,
334333
rcd->numa_id = numa;
335334
rcd->rcv_array_groups = dd->rcv_entries.ngroups;
336335
rcd->rhf_rcv_function_map = normal_rhf_rcv_functions;
336+
rcd->slow_handler = handle_receive_interrupt;
337+
rcd->do_interrupt = rcd->slow_handler;
337338
rcd->msix_intr = CCE_NUM_MSIX_VECTORS;
338339

339340
mutex_init(&rcd->exp_mutex);
@@ -898,8 +899,6 @@ int hfi1_init(struct hfi1_devdata *dd, int reinit)
898899
if (!rcd)
899900
continue;
900901

901-
rcd->do_interrupt = &handle_receive_interrupt;
902-
903902
lastfail = hfi1_create_rcvhdrq(dd, rcd);
904903
if (!lastfail)
905904
lastfail = hfi1_setup_eagerbufs(rcd);

0 commit comments

Comments
 (0)