Skip to content

Commit 9a293d1

Browse files
mmarcinijgunthorpe
authored andcommitted
IB/hfi1: Ensure pq is not left on waitlist
The following warning can occur when a pq is left on the dmawait list and the pq is then freed: WARNING: CPU: 47 PID: 3546 at lib/list_debug.c:29 __list_add+0x65/0xc0 list_add corruption. next->prev should be prev (ffff939228da1880), but was ffff939cabb52230. (next=ffff939cabb52230). Modules linked in: mmfs26(OE) mmfslinux(OE) tracedev(OE) 8021q garp mrp ib_isert iscsi_target_mod target_core_mod crc_t10dif crct10dif_generic opa_vnic rpcrdma ib_iser libiscsi scsi_transport_iscsi ib_ipoib(OE) bridge stp llc iTCO_wdt iTCO_vendor_support intel_powerclamp coretemp intel_rapl iosf_mbi kvm_intel kvm irqbypass crct10dif_pclmul crct10dif_common crc32_pclmul ghash_clmulni_intel aesni_intel lrw gf128mul glue_helper ablk_helper cryptd ast ttm drm_kms_helper syscopyarea sysfillrect sysimgblt fb_sys_fops drm pcspkr joydev drm_panel_orientation_quirks i2c_i801 mei_me lpc_ich mei wmi ipmi_si ipmi_devintf ipmi_msghandler nfit libnvdimm acpi_power_meter acpi_pad hfi1(OE) rdmavt(OE) rdma_ucm ib_ucm ib_uverbs ib_umad rdma_cm ib_cm iw_cm ib_core binfmt_misc numatools(OE) xpmem(OE) ip_tables nfsv3 nfs_acl nfs lockd grace sunrpc fscache igb ahci libahci i2c_algo_bit dca libata ptp pps_core crc32c_intel [last unloaded: i2c_algo_bit] CPU: 47 PID: 3546 Comm: wrf.exe Kdump: loaded Tainted: G W OE ------------ 3.10.0-957.41.1.el7.x86_64 #1 Hardware name: HPE.COM HPE SGI 8600-XA730i Gen10/X11DPT-SB-SG007, BIOS SBED1229 01/22/2019 Call Trace: [<ffffffff91f65ac0>] dump_stack+0x19/0x1b [<ffffffff91898b78>] __warn+0xd8/0x100 [<ffffffff91898bff>] warn_slowpath_fmt+0x5f/0x80 [<ffffffff91a1dabe>] ? ___slab_alloc+0x24e/0x4f0 [<ffffffff91b97025>] __list_add+0x65/0xc0 [<ffffffffc03926a5>] defer_packet_queue+0x145/0x1a0 [hfi1] [<ffffffffc0372987>] sdma_check_progress+0x67/0xa0 [hfi1] [<ffffffffc03779d2>] sdma_send_txlist+0x432/0x550 [hfi1] [<ffffffff91a20009>] ? kmem_cache_alloc+0x179/0x1f0 [<ffffffffc0392973>] ? user_sdma_send_pkts+0xc3/0x1990 [hfi1] [<ffffffffc0393e3a>] user_sdma_send_pkts+0x158a/0x1990 [hfi1] [<ffffffff918ab65e>] ? try_to_del_timer_sync+0x5e/0x90 [<ffffffff91a3fe1a>] ? __check_object_size+0x1ca/0x250 [<ffffffffc0395546>] hfi1_user_sdma_process_request+0xd66/0x1280 [hfi1] [<ffffffffc034e0da>] hfi1_aio_write+0xca/0x120 [hfi1] [<ffffffff91a4245b>] do_sync_readv_writev+0x7b/0xd0 [<ffffffff91a4409e>] do_readv_writev+0xce/0x260 [<ffffffff918df69f>] ? pick_next_task_fair+0x5f/0x1b0 [<ffffffff918db535>] ? sched_clock_cpu+0x85/0xc0 [<ffffffff91f6b16a>] ? __schedule+0x13a/0x860 [<ffffffff91a442c5>] vfs_writev+0x35/0x60 [<ffffffff91a4447f>] SyS_writev+0x7f/0x110 [<ffffffff91f78ddb>] system_call_fastpath+0x22/0x27 The issue happens when wait_event_interruptible_timeout() returns a value <= 0. In that case, the pq is left on the list. The code continues sending packets and potentially can complete the current request with the pq still on the dmawait list provided no descriptor shortage is seen. If the pq is torn down in that state, the sdma interrupt handler could find the now freed pq on the list with list corruption or memory corruption resulting. Fix by adding a flush routine to ensure that the pq is never on a list after processing a request. A follow-up patch series will address issues with seqlock surfaced in: https://lore.kernel.org/r/20200320003129.GP20941@ziepe.ca The seqlock use for sdma will then be converted to a spin lock since the list_empty() doesn't need the protection afforded by the sequence lock currently in use. Fixes: a0d4069 ("staging/rdma/hfi1: Add page lock limit check for SDMA requests") Link: https://lore.kernel.org/r/20200320200200.23203.37777.stgit@awfm-01.aw.intel.com Reviewed-by: Kaike Wan <kaike.wan@intel.com> Signed-off-by: Mike Marciniszyn <mike.marciniszyn@intel.com> Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent 941224e commit 9a293d1

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

drivers/infiniband/hw/hfi1/user_sdma.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ static int defer_packet_queue(
141141
*/
142142
xchg(&pq->state, SDMA_PKT_Q_DEFERRED);
143143
if (list_empty(&pq->busy.list)) {
144+
pq->busy.lock = &sde->waitlock;
144145
iowait_get_priority(&pq->busy);
145146
iowait_queue(pkts_sent, &pq->busy, &sde->dmawait);
146147
}
@@ -155,6 +156,7 @@ static void activate_packet_queue(struct iowait *wait, int reason)
155156
{
156157
struct hfi1_user_sdma_pkt_q *pq =
157158
container_of(wait, struct hfi1_user_sdma_pkt_q, busy);
159+
pq->busy.lock = NULL;
158160
xchg(&pq->state, SDMA_PKT_Q_ACTIVE);
159161
wake_up(&wait->wait_dma);
160162
};
@@ -256,6 +258,21 @@ int hfi1_user_sdma_alloc_queues(struct hfi1_ctxtdata *uctxt,
256258
return ret;
257259
}
258260

261+
static void flush_pq_iowait(struct hfi1_user_sdma_pkt_q *pq)
262+
{
263+
unsigned long flags;
264+
seqlock_t *lock = pq->busy.lock;
265+
266+
if (!lock)
267+
return;
268+
write_seqlock_irqsave(lock, flags);
269+
if (!list_empty(&pq->busy.list)) {
270+
list_del_init(&pq->busy.list);
271+
pq->busy.lock = NULL;
272+
}
273+
write_sequnlock_irqrestore(lock, flags);
274+
}
275+
259276
int hfi1_user_sdma_free_queues(struct hfi1_filedata *fd,
260277
struct hfi1_ctxtdata *uctxt)
261278
{
@@ -281,6 +298,7 @@ int hfi1_user_sdma_free_queues(struct hfi1_filedata *fd,
281298
kfree(pq->reqs);
282299
kfree(pq->req_in_use);
283300
kmem_cache_destroy(pq->txreq_cache);
301+
flush_pq_iowait(pq);
284302
kfree(pq);
285303
} else {
286304
spin_unlock(&fd->pq_rcu_lock);
@@ -587,11 +605,12 @@ int hfi1_user_sdma_process_request(struct hfi1_filedata *fd,
587605
if (ret < 0) {
588606
if (ret != -EBUSY)
589607
goto free_req;
590-
wait_event_interruptible_timeout(
608+
if (wait_event_interruptible_timeout(
591609
pq->busy.wait_dma,
592-
(pq->state == SDMA_PKT_Q_ACTIVE),
610+
pq->state == SDMA_PKT_Q_ACTIVE,
593611
msecs_to_jiffies(
594-
SDMA_IOWAIT_TIMEOUT));
612+
SDMA_IOWAIT_TIMEOUT)) <= 0)
613+
flush_pq_iowait(pq);
595614
}
596615
}
597616
*count += idx;

0 commit comments

Comments
 (0)