Skip to content

Commit 00b276b

Browse files
zhijianli88gregkh
authored andcommitted
RDMA/rtrs: Fix rxe_dealloc_pd warning
[ Upstream commit 9c29c8c ] In current design: 1. PD and clt_path->s.dev are shared among connections. 2. every con[n]'s cleanup phase will call destroy_con_cq_qp() 3. clt_path->s.dev will be always decreased in destroy_con_cq_qp(), and when clt_path->s.dev become zero, it will destroy PD. 4. when con[1] failed to create, con[1] will not take clt_path->s.dev, but it try to decreased clt_path->s.dev So, in case create_cm(con[0]) succeeds but create_cm(con[1]) fails, destroy_con_cq_qp(con[1]) will be called first which will destroy the PD while this PD is still taken by con[0]. Here, we refactor the error path of create_cm() and init_conns(), so that we do the cleanup in the order they are created. The warning occurs when destroying RXE PD whose reference count is not zero. rnbd_client L597: Mapping device /dev/nvme0n1 on session client, (access_mode: rw, nr_poll_queues: 0) ------------[ cut here ]------------ WARNING: CPU: 0 PID: 26407 at drivers/infiniband/sw/rxe/rxe_pool.c:256 __rxe_cleanup+0x13a/0x170 [rdma_rxe] Modules linked in: rpcrdma rdma_ucm ib_iser rnbd_client libiscsi rtrs_client scsi_transport_iscsi rtrs_core rdma_cm iw_cm ib_cm crc32_generic rdma_rxe udp_tunnel ib_uverbs ib_core kmem device_dax nd_pmem dax_pmem nd_vme crc32c_intel fuse nvme_core nfit libnvdimm dm_multipath scsi_dh_rdac scsi_dh_emc scsi_dh_alua dm_mirror dm_region_hash dm_log dm_mod CPU: 0 PID: 26407 Comm: rnbd-client.sh Kdump: loaded Not tainted 6.2.0-rc6-roce-flush+ #53 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014 RIP: 0010:__rxe_cleanup+0x13a/0x170 [rdma_rxe] Code: 45 84 e4 0f 84 5a ff ff ff 48 89 ef e8 5f 18 71 f9 84 c0 75 90 be c8 00 00 00 48 89 ef e8 be 89 1f fa 85 c0 0f 85 7b ff ff ff <0f> 0b 41 bc ea ff ff ff e9 71 ff ff ff e8 84 7f 1f fa e9 d0 fe ff RSP: 0018:ffffb09880b6f5f0 EFLAGS: 00010246 RAX: 0000000000000000 RBX: ffff99401f15d6a8 RCX: 0000000000000000 RDX: 0000000000000001 RSI: ffffffffbac8234b RDI: 00000000ffffffff RBP: ffff99401f15d6d0 R08: 0000000000000001 R09: 0000000000000001 R10: 0000000000002d82 R11: 0000000000000000 R12: 0000000000000001 R13: ffff994101eff208 R14: ffffb09880b6f6a0 R15: 00000000fffffe00 FS: 00007fe113904740(0000) GS:ffff99413bc00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007ff6cde656c8 CR3: 000000001f108004 CR4: 00000000001706f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: <TASK> rxe_dealloc_pd+0x16/0x20 [rdma_rxe] ib_dealloc_pd_user+0x4b/0x80 [ib_core] rtrs_ib_dev_put+0x79/0xd0 [rtrs_core] destroy_con_cq_qp+0x8a/0xa0 [rtrs_client] init_path+0x1e7/0x9a0 [rtrs_client] ? __pfx_autoremove_wake_function+0x10/0x10 ? lock_is_held_type+0xd7/0x130 ? rcu_read_lock_sched_held+0x43/0x80 ? pcpu_alloc+0x3dd/0x7d0 ? rtrs_clt_init_stats+0x18/0x40 [rtrs_client] rtrs_clt_open+0x24f/0x5a0 [rtrs_client] ? __pfx_rnbd_clt_link_ev+0x10/0x10 [rnbd_client] rnbd_clt_map_device+0x6a5/0xe10 [rnbd_client] Fixes: 6a98d71 ("RDMA/rtrs: client: main functionality") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Li Zhijian <[email protected]> Acked-by: Jack Wang <[email protected]> Tested-by: Jack Wang <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 77226c9 commit 00b276b

File tree

1 file changed

+23
-32
lines changed

1 file changed

+23
-32
lines changed

drivers/infiniband/ulp/rtrs/rtrs-clt.c

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,7 @@ static int rtrs_clt_rdma_cm_handler(struct rdma_cm_id *cm_id,
20422042
return 0;
20432043
}
20442044

2045+
/* The caller should do the cleanup in case of error */
20452046
static int create_cm(struct rtrs_clt_con *con)
20462047
{
20472048
struct rtrs_path *s = con->c.path;
@@ -2064,14 +2065,14 @@ static int create_cm(struct rtrs_clt_con *con)
20642065
err = rdma_set_reuseaddr(cm_id, 1);
20652066
if (err != 0) {
20662067
rtrs_err(s, "Set address reuse failed, err: %d\n", err);
2067-
goto destroy_cm;
2068+
return err;
20682069
}
20692070
err = rdma_resolve_addr(cm_id, (struct sockaddr *)&clt_path->s.src_addr,
20702071
(struct sockaddr *)&clt_path->s.dst_addr,
20712072
RTRS_CONNECT_TIMEOUT_MS);
20722073
if (err) {
20732074
rtrs_err(s, "Failed to resolve address, err: %d\n", err);
2074-
goto destroy_cm;
2075+
return err;
20752076
}
20762077
/*
20772078
* Combine connection status and session events. This is needed
@@ -2086,29 +2087,15 @@ static int create_cm(struct rtrs_clt_con *con)
20862087
if (err == 0)
20872088
err = -ETIMEDOUT;
20882089
/* Timedout or interrupted */
2089-
goto errr;
2090-
}
2091-
if (con->cm_err < 0) {
2092-
err = con->cm_err;
2093-
goto errr;
2090+
return err;
20942091
}
2095-
if (READ_ONCE(clt_path->state) != RTRS_CLT_CONNECTING) {
2092+
if (con->cm_err < 0)
2093+
return con->cm_err;
2094+
if (READ_ONCE(clt_path->state) != RTRS_CLT_CONNECTING)
20962095
/* Device removal */
2097-
err = -ECONNABORTED;
2098-
goto errr;
2099-
}
2096+
return -ECONNABORTED;
21002097

21012098
return 0;
2102-
2103-
errr:
2104-
stop_cm(con);
2105-
mutex_lock(&con->con_mutex);
2106-
destroy_con_cq_qp(con);
2107-
mutex_unlock(&con->con_mutex);
2108-
destroy_cm:
2109-
destroy_cm(con);
2110-
2111-
return err;
21122099
}
21132100

21142101
static void rtrs_clt_path_up(struct rtrs_clt_path *clt_path)
@@ -2336,7 +2323,7 @@ static void rtrs_clt_close_work(struct work_struct *work)
23362323
static int init_conns(struct rtrs_clt_path *clt_path)
23372324
{
23382325
unsigned int cid;
2339-
int err;
2326+
int err, i;
23402327

23412328
/*
23422329
* On every new session connections increase reconnect counter
@@ -2352,10 +2339,8 @@ static int init_conns(struct rtrs_clt_path *clt_path)
23522339
goto destroy;
23532340

23542341
err = create_cm(to_clt_con(clt_path->s.con[cid]));
2355-
if (err) {
2356-
destroy_con(to_clt_con(clt_path->s.con[cid]));
2342+
if (err)
23572343
goto destroy;
2358-
}
23592344
}
23602345
err = alloc_path_reqs(clt_path);
23612346
if (err)
@@ -2366,15 +2351,21 @@ static int init_conns(struct rtrs_clt_path *clt_path)
23662351
return 0;
23672352

23682353
destroy:
2369-
while (cid--) {
2370-
struct rtrs_clt_con *con = to_clt_con(clt_path->s.con[cid]);
2354+
/* Make sure we do the cleanup in the order they are created */
2355+
for (i = 0; i <= cid; i++) {
2356+
struct rtrs_clt_con *con;
23712357

2372-
stop_cm(con);
2358+
if (!clt_path->s.con[i])
2359+
break;
23732360

2374-
mutex_lock(&con->con_mutex);
2375-
destroy_con_cq_qp(con);
2376-
mutex_unlock(&con->con_mutex);
2377-
destroy_cm(con);
2361+
con = to_clt_con(clt_path->s.con[i]);
2362+
if (con->c.cm_id) {
2363+
stop_cm(con);
2364+
mutex_lock(&con->con_mutex);
2365+
destroy_con_cq_qp(con);
2366+
mutex_unlock(&con->con_mutex);
2367+
destroy_cm(con);
2368+
}
23782369
destroy_con(con);
23792370
}
23802371
/*

0 commit comments

Comments
 (0)