From patchwork Mon Apr 10 06:43:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zhijian X-Patchwork-Id: 13206118 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A27DC77B61 for ; Mon, 10 Apr 2023 06:43:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229714AbjDJGnf (ORCPT ); Mon, 10 Apr 2023 02:43:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229711AbjDJGne (ORCPT ); Mon, 10 Apr 2023 02:43:34 -0400 Received: from mail3.bemta32.messagelabs.com (mail3.bemta32.messagelabs.com [195.245.230.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD7402D47; Sun, 9 Apr 2023 23:43:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1681109011; i=@fujitsu.com; bh=iAKmY6Rq8qBoVB2F0jD25UDcsKK0ZHwfKH5rHjKCtoI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iHXTs0ZocBp7BXI9t24Fv1NRl28IFnlBd4lzD73WlPKfMulhkoW9ENvOzXXXYApMW 672Lpppw3M2SNmZ3kv6qjMLdGVaA6HUdItq6jk7c4olXvYHjFOOxu6CkuVgglvgC1I Fk3dw4HYjZvDUYNElXmqJWJiyCwHH9l+lHhP0St9J1ayFLxouCRmOPQ3shixL625et EtQW3/OSRImZzaY2yeDUHI0R+yRM1L4KVfH4zEHyzfv/uR9E92ISqb3tCzxTzTLqN1 bkbBCDXs/YYa5+fgv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slbSKL140zsZ1CxuWPvq4/Grcv85KgzQLdDrkPper1DTmmoXGaNoHrQ2X59h3hj Sri+flrroUSS3FGoqEWM9CZAMXtRZ+UAwAA X-Env-Sender: lizhijian@fujitsu.com X-Msg-Ref: server-15.tower-585.messagelabs.com!1681109010!186112!1 X-Originating-IP: [62.60.8.146] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.104.2; banners=-,-,- X-VirusChecked: Checked Received: (qmail 7567 invoked from network); 10 Apr 2023 06:43:30 -0000 Received: from unknown (HELO n03ukasimr02.n03.fujitsu.local) (62.60.8.146) by server-15.tower-585.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 10 Apr 2023 06:43:30 -0000 Received: from n03ukasimr02.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr02.n03.fujitsu.local (Postfix) with ESMTP id 10B55100323; Mon, 10 Apr 2023 07:43:30 +0100 (BST) Received: from R01UKEXCASM121.r01.fujitsu.local (R01UKEXCASM121 [10.183.43.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by n03ukasimr02.n03.fujitsu.local (Postfix) with ESMTPS id 021941000EE; Mon, 10 Apr 2023 07:43:30 +0100 (BST) Received: from 31d618797ed9.localdomain (10.167.226.45) by R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 10 Apr 2023 07:43:26 +0100 From: Li Zhijian To: , , , , CC: , , Li Zhijian Subject: [PATCH for-next 1/3] RDMA/rtrs: Remove duplicate cq_num assignment Date: Mon, 10 Apr 2023 06:43:02 +0000 Message-ID: <1681108984-2-2-git-send-email-lizhijian@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1681108984-2-1-git-send-email-lizhijian@fujitsu.com> References: <1681108984-2-1-git-send-email-lizhijian@fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.45] X-ClientProxiedBy: G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) To R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org line 1701 and 1713 are duplicate: > 1701 cq_num = max_send_wr + max_recv_wr; 1702 /* alloc iu to recv new rkey reply when server reports flags set */ 1703 if (clt_path->flags & RTRS_MSG_NEW_RKEY_F || con->c.cid == 0) { 1704 con->rsp_ius = rtrs_iu_alloc(cq_num, sizeof(*rsp), 1705 GFP_KERNEL, 1706 clt_path->s.dev->ib_dev, 1707 DMA_FROM_DEVICE, 1708 rtrs_clt_rdma_done); 1709 if (!con->rsp_ius) 1710 return -ENOMEM; 1711 con->queue_num = cq_num; 1712 } > 1713 cq_num = max_send_wr + max_recv_wr; Signed-off-by: Li Zhijian Acked-by: Guoqing Jiang Acked-by: Jack Wang --- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c index 80abf45a197a..c2065fc33a56 100644 --- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c @@ -1710,7 +1710,6 @@ static int create_con_cq_qp(struct rtrs_clt_con *con) return -ENOMEM; con->queue_num = cq_num; } - cq_num = max_send_wr + max_recv_wr; cq_vector = con->cpu % clt_path->s.dev->ib_dev->num_comp_vectors; if (con->c.cid >= clt_path->s.irq_con_num) err = rtrs_cq_qp_create(&clt_path->s, &con->c, max_send_sge, From patchwork Mon Apr 10 06:43:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zhijian X-Patchwork-Id: 13206119 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30A46C77B61 for ; Mon, 10 Apr 2023 06:43:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229729AbjDJGni (ORCPT ); Mon, 10 Apr 2023 02:43:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229611AbjDJGng (ORCPT ); Mon, 10 Apr 2023 02:43:36 -0400 Received: from mail3.bemta32.messagelabs.com (mail3.bemta32.messagelabs.com [195.245.230.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 233D344BB; Sun, 9 Apr 2023 23:43:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1681109014; i=@fujitsu.com; bh=+dIHCpFAvsR7hmzQAKRJUqvdCdwuxuDAD8I19Qv4+6w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eI8Ty2hDmZrMFgNY5fhbW2Rg0B1T2iiyfOW8aHk322EiJPUL809R9r3ilsBjJhatO fGSXoE8p9OUVXbY3iF66lI4ESDtarNFEI2AcMTZlEsJ+UrFQC+BMzUbIrXSPrqWR42 aVLsTAMuvVAkpT/CzPeS9UACbSzEGeRVF7pQ42KUrRCwtxjJKA00upwsNBIjGHKnFB ZkfVoz5zqbKNyCrEY5o1CYr1tRYrVLID2Rpg8oqNgfjs4pY8sxYeboLVyeEUaygAAa L6g1Ic4AXMJ+45zhwtTvNNUWuRLxorClSgeuDofy0KZnMHWQa9gDYg7E/VZRZhB0T2 4n1m0OIIlTpag== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmleJIrShJLcpLzFFi42Kxs+FI1BXdYJx icGOKvsWNaXIW205vYLeYOeMEo8XbTVNYLKb8WspscXn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1681109013!187048!1 X-Originating-IP: [62.60.8.97] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.104.2; banners=-,-,- X-VirusChecked: Checked Received: (qmail 7500 invoked from network); 10 Apr 2023 06:43:33 -0000 Received: from unknown (HELO n03ukasimr01.n03.fujitsu.local) (62.60.8.97) by server-12.tower-585.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 10 Apr 2023 06:43:33 -0000 Received: from n03ukasimr01.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr01.n03.fujitsu.local (Postfix) with ESMTP id 5181A1001B5; Mon, 10 Apr 2023 07:43:33 +0100 (BST) Received: from R01UKEXCASM121.r01.fujitsu.local (R01UKEXCASM121 [10.183.43.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by n03ukasimr01.n03.fujitsu.local (Postfix) with ESMTPS id 44F171001A5; Mon, 10 Apr 2023 07:43:33 +0100 (BST) Received: from 31d618797ed9.localdomain (10.167.226.45) by R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 10 Apr 2023 07:43:30 +0100 From: Li Zhijian To: , , , , CC: , , Li Zhijian Subject: [PATCH for-next 2/3] RDMA/rtrs: Fix rxe_dealloc_pd warning Date: Mon, 10 Apr 2023 06:43:03 +0000 Message-ID: <1681108984-2-3-git-send-email-lizhijian@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1681108984-2-1-git-send-email-lizhijian@fujitsu.com> References: <1681108984-2-1-git-send-email-lizhijian@fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.45] X-ClientProxiedBy: G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) To R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org The warning occurs when destroying PD whose reference count is not zero. Precodition: clt_path->s.con_num is 2. So 2 cm connection will be created as below: CPU0 CPU1 init_conns { | create_cm() // a. con[0] created | | a'. rtrs_clt_rdma_cm_handler() { | rtrs_rdma_addr_resolved() | create_con_cq_qp(con); << con[0] | } | in this moment, refcnt of PD was increased to 2+ | create_cm() // b. cid = 1, failed | destroy_con_cq_qp() | rtrs_ib_dev_put() | dev_free() | ib_dealloc_pd(dev->ib_pd) << PD | is destroyed, but refcnt is | still greater than 0 | } Simply, Here we can avoid this warning by introducing conn own flag to track if its cleanup should drop the PD. ----------------------------------------------- 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: 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] Signed-off-by: Li Zhijian Signed-off-by: Li Zhijian --- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 4 ++++ drivers/infiniband/ulp/rtrs/rtrs-clt.h | 1 + 2 files changed, 5 insertions(+) diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c index c2065fc33a56..4c8f42e46e2f 100644 --- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c @@ -1664,6 +1664,7 @@ static int create_con_cq_qp(struct rtrs_clt_con *con) return -ENOMEM; } clt_path->s.dev_ref = 1; + con->has_dev = true; query_fast_reg_mode(clt_path); wr_limit = clt_path->s.dev->ib_dev->attrs.max_qp_wr; /* @@ -1690,6 +1691,7 @@ static int create_con_cq_qp(struct rtrs_clt_con *con) wr_limit = clt_path->s.dev->ib_dev->attrs.max_qp_wr; /* Shared between connections */ clt_path->s.dev_ref++; + con->has_dev = true; max_send_wr = min_t(int, wr_limit, /* QD * (REQ + RSP + FR REGS or INVS) + drain */ clt_path->queue_depth * 3 + 1); @@ -1742,6 +1744,8 @@ static void destroy_con_cq_qp(struct rtrs_clt_con *con) con->rsp_ius = NULL; con->queue_num = 0; } + if (!con->has_dev) + return; if (clt_path->s.dev_ref && !--clt_path->s.dev_ref) { rtrs_ib_dev_put(clt_path->s.dev); clt_path->s.dev = NULL; diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.h b/drivers/infiniband/ulp/rtrs/rtrs-clt.h index f848c0392d98..970b75633594 100644 --- a/drivers/infiniband/ulp/rtrs/rtrs-clt.h +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.h @@ -75,6 +75,7 @@ struct rtrs_clt_con { unsigned int cpu; struct mutex con_mutex; int cm_err; + bool has_dev; }; /** From patchwork Mon Apr 10 06:43:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zhijian X-Patchwork-Id: 13206120 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E645C76196 for ; Mon, 10 Apr 2023 06:43:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229724AbjDJGnu (ORCPT ); Mon, 10 Apr 2023 02:43:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229743AbjDJGnn (ORCPT ); Mon, 10 Apr 2023 02:43:43 -0400 Received: from mail3.bemta32.messagelabs.com (mail3.bemta32.messagelabs.com [195.245.230.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 176692D6A; Sun, 9 Apr 2023 23:43:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1681109018; i=@fujitsu.com; bh=4cYvlyImJig+3PsNpJOM0kOmh8zSDTANyqqOA8qFK9o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ACGymuscUKaNZuKVvZbv+Mr7q7ojEnxrDwMItz0uwmsQeTAowFI2pVJ7pOm2jniE3 ReDK/Z4cbNV+KiKWO0FJS4eQ/CCjrdeA654lxO6YesNqL8B4jjLBs5TJYBFBW4Yjey c+ehOYtpKQi+UvYSr3JPxjMTNz2a6HmT9J/ZhzwzdCvdHKSn8WqRORhnvXcruwN2eG SrDS13OjQOhv9X0i495P15CYdpO+VUNxTBQJPMmiGP0ePavJCUj3DTm2DlTj0O8dyo w/eoX/m4UeC3UGnghI5/n7Hs/+nLQSfUdjTSTDDvmVdmNf8/qkr8nzJKUkoWaD5eq6 RFn3VWgoINvqg== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpkleJIrShJLcpLzFFi42Kxs+FI0pXcYJx i8Gwim8WNaXIW205vYLeYOeMEo8XbTVNYLKb8WspscXnXHDaLZ4d6WRzYPU6/ucPksWlVJ5vH woapzB6fN8l5bP18myWANYo1My8pvyKBNePzxO/sBTsVKxZNn8bewHhUuouRi0NIYCOjxKmPh 5ggnCVMEudWv2TvYuQEcvYzSkztrgOx2QQ0JO613GQEsUUESiUOt+0Dq2EWSJKYd/stM4gtLB ApsXdxNxOIzSKgKvF/7jYwm1fAUeJf80swW0JAQWLKw/dg9ZwCThINrRdZIXY5SlxZ38gIUS8 ocXLmExaI+RISB1+8YIboVZQ40vmXBcKukGicfghqpprE1XObmCcwCs5C0j4LSfsCRqZVjKbF qUVlqUW65npJRZnpGSW5iZk5eolVuol6qaW65anFJbqGeonlxXqpxcV6xZW5yTkpenmpJZsYg bGRUsz0bgfj8r6/eocYJTmYlER5u7iMU4T4kvJTKjMSizPii0pzUosPMcpwcChJ8H5fAJQTLE pNT61Iy8wBxilMWoKDR0mE98QyoDRvcUFibnFmOkTqFKMux4YHB/YyC7Hk5eelSonz/loHVCQ AUpRRmgc3ApYyLjHKSgnzMjIwMAjxFKQW5WaWoMq/YhTnYFQS5p0EsoonM68EbtMroCOYgI7g cjEAOaIkESEl1cD0MnqfTtQazuZdupusrplwhtqckjDP3pEiYDNh09vSR8q+rVeOrX9XI+udn LC5U3FxoNyZqnQpplsuqgrycxP+lBSeOHvtzJHibsf+/jLRE6ITOAUlbNW+3a9eeshN0NrdY8 FmkwCl/BBm6U+bqrdFXVXTOBRv/rL26082BqZY3xXt/3880JeZm/x19+R1X/40VXeWfi4591k xlPHVgylHt5i/nR3ONn37tSNzlpr8cvqum7LMgvuR/rF7fSulG2dnW+z2mD3lt/HrC11MK+xa MqMf2c1ZrTbpz73JR24zr4x6Jn5ayuaj7QrBG6szaidsfup/NLm25WO+rq1LWKTLfebwO6XuS dPPhjpbns9VYinOSDTUYi4qTgQAMVHzWpQDAAA= X-Env-Sender: lizhijian@fujitsu.com X-Msg-Ref: server-12.tower-585.messagelabs.com!1681109016!187050!1 X-Originating-IP: [62.60.8.98] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.104.2; banners=-,-,- X-VirusChecked: Checked Received: (qmail 7574 invoked from network); 10 Apr 2023 06:43:37 -0000 Received: from unknown (HELO n03ukasimr03.n03.fujitsu.local) (62.60.8.98) by server-12.tower-585.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 10 Apr 2023 06:43:37 -0000 Received: from n03ukasimr03.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr03.n03.fujitsu.local (Postfix) with ESMTP id A91CD1CD; Mon, 10 Apr 2023 07:43:36 +0100 (BST) Received: from R01UKEXCASM121.r01.fujitsu.local (R01UKEXCASM121 [10.183.43.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by n03ukasimr03.n03.fujitsu.local (Postfix) with ESMTPS id 9D5E71C7; Mon, 10 Apr 2023 07:43:36 +0100 (BST) Received: from 31d618797ed9.localdomain (10.167.226.45) by R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 10 Apr 2023 07:43:33 +0100 From: Li Zhijian To: , , , , CC: , , Li Zhijian Subject: [PATCH for-next 3/3] RDMA/rtrs: Avoid use-after-free in rtrs_clt_rdma_cm_handler Date: Mon, 10 Apr 2023 06:43:04 +0000 Message-ID: <1681108984-2-4-git-send-email-lizhijian@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1681108984-2-1-git-send-email-lizhijian@fujitsu.com> References: <1681108984-2-1-git-send-email-lizhijian@fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.45] X-ClientProxiedBy: G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) To R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Currently, con will be destroyed when wait_event_interruptible_timeout() returns ERESTARTSYS. But the in-flight event handler rtrs_clt_rdma_cm_handler() could be rescheduled/wakeup which may cause a use-after-free. WARNING: CPU: 0 PID: 14766 at drivers/infiniband/ulp/rtrs/rtrs-clt.c:1687 rtrs_clt_rdma_cm_handler+0x620/0x640 [rtrs_client] Modules linked in: rnbd_client rtrs_client rtrs_core rdma_cm iw_cm ib_cm rdma_rxe ib_uverbs ib_core libiscsi scsi_transport_iscsi crc32_generic udp_tunnel dax_pmem nd_pmem nd_btt virtiofs crc32c_intel nvme 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 [last unloaded: ib_core] CPU: 0 PID: 14766 Comm: kworker/u2:3 Kdump: loaded Tainted: G W 6.2.0-rc6-roce-flush+ #56 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014 Workqueue: ib_addr process_one_req [ib_core] RIP: 0010:rtrs_clt_rdma_cm_handler+0x620/0x640 [rtrs_client] Code: 00 0f 85 5f fd ff ff 4c 8b 23 41 bd f4 ff ff ff e9 95 fb ff ff 0f 0b 4c 89 f7 41 bd ea ff ff ff e8 75 c8 92 ec e9 4b ff ff ff <0f> 0b 4c 89 f7 41 bd ea ff ff ff e8 60 c8 92 ec e9 36 ff ff ff e8 RSP: 0018:ffffa4ef41cdbc60 EFLAGS: 00010246 RAX: 0000000000000000 RBX: ffff9372c394e600 RCX: 0000000000000001 RDX: 0000000000000000 RSI: 0000000000000001 RDI: ffffffffad634277 RBP: ffffa4ef41cdbd00 R08: 0000000000000000 R09: 0000000000000001 R10: 0000000000003ff3 R11: 0000000000000000 R12: ffff9372c3164800 R13: ffff9372c3164800 R14: ffff9372c394e640 R15: ffff9372c5219020 FS: 0000000000000000(0000) GS:ffff9372fbc00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f35bb7d5de0 CR3: 0000000020c2a006 CR4: 00000000001706f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: ? mark_held_locks+0x49/0x80 ? lock_is_held_type+0xd7/0x130 ? cma_cm_event_handler+0x49/0x200 [rdma_cm] cma_cm_event_handler+0x49/0x200 [rdma_cm] addr_handler+0xf1/0x1e0 [rdma_cm] ? lock_acquire+0xca/0x2f0 ? lock_acquire+0xda/0x2f0 process_one_req+0x43/0x170 [ib_core] process_one_work+0x274/0x590 worker_thread+0x4f/0x3d0 ? __pfx_worker_thread+0x10/0x10 kthread+0xe7/0x110 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x2c/0x50 irq event stamp: 1432669 hardirqs last enabled at (1432683): [] __up_console_sem+0x52/0x60 hardirqs last disabled at (1432698): [] __up_console_sem+0x37/0x60 softirqs last enabled at (1432518): [] __irq_exit_rcu+0xc5/0x120 softirqs last disabled at (1432509): [] __irq_exit_rcu+0xc5/0x120 ---[ end trace 0000000000000000 ]--- Signed-off-by: Li Zhijian --- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c index 4c8f42e46e2f..760a7eb51297 100644 --- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c @@ -2074,6 +2074,7 @@ static int create_cm(struct rtrs_clt_con *con) rtrs_err(s, "Failed to resolve address, err: %d\n", err); goto destroy_cm; } +again: /* * Combine connection status and session events. This is needed * for waiting two possible cases: cm_err has something meaningful @@ -2083,10 +2084,15 @@ static int create_cm(struct rtrs_clt_con *con) clt_path->state_wq, con->cm_err || clt_path->state != RTRS_CLT_CONNECTING, msecs_to_jiffies(RTRS_CONNECT_TIMEOUT_MS)); - if (err == 0 || err == -ERESTARTSYS) { - if (err == 0) - err = -ETIMEDOUT; - /* Timedout or interrupted */ + if (err == -ERESTARTSYS) { + /* interrupted, + * try again to avoid the in-flight rtrs_clt_rdma_cm_handler() + * getting a use-after-free + */ + goto again; + } else if (err == 0) { + err = -ETIMEDOUT; + /* Timedout */ goto errr; } if (con->cm_err < 0) {