linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guoqing Jiang <guoqing.jiang@linux.dev>
To: bmt@zurich.ibm.com, jgg@ziepe.ca, leon@kernel.org
Cc: linux-rdma@vger.kernel.org
Subject: [PATCH 2/5] RDMA/siw: Ensure siw_destroy_cpulist can be called more than once
Date: Thu, 27 Jul 2023 22:03:46 +0800	[thread overview]
Message-ID: <20230727140349.25369-3-guoqing.jiang@linux.dev> (raw)
In-Reply-To: <20230727140349.25369-1-guoqing.jiang@linux.dev>

In case siw module can't be inserted successfully, then if remove
the module from kernel, then both siw_cm_exit and the failure path
in siw_init_module call siw_destroy_cpulist. Let's set tx_valid_cpus
and num_nodes to prevent double free issues.

[   32.197293] general protection fault, probably for non-canonical address 0xb4965e5a58a488: 0000 [#1] PREEMPT SMP NOPTI
[   32.197300] CPU: 0 PID: 1676 Comm: modprobe Tainted: G           OE      6.5.0-rc3+ #16
[   32.197304] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.16.0-0-gd239552c-rebuilt.opensuse.org 04/01/2014
[   32.197306] RIP: 0010:kfree+0x62/0x150
...
[   32.197339] Call Trace:
[   32.197341]  <TASK>
[   32.197343]  ? show_regs+0x72/0x90
[   32.197348]  ? die_addr+0x38/0xb0
[   32.197351]  ? exc_general_protection+0x1bf/0x4a0
[   32.197357]  ? asm_exc_general_protection+0x27/0x30
[   32.197362]  ? kfree+0x62/0x150
[   32.197366]  siw_exit_module+0xb8/0x590 [siw]
[   32.197376]  __do_sys_delete_module.constprop.0+0x18f/0x300

So let's set tx_valid_cpus and num_nodes to prevent the issue.

Signed-off-by: Guoqing Jiang <guoqing.jiang@linux.dev>
---
 drivers/infiniband/sw/siw/siw_main.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/infiniband/sw/siw/siw_main.c b/drivers/infiniband/sw/siw/siw_main.c
index 65b5cda5457b..b3547253c099 100644
--- a/drivers/infiniband/sw/siw/siw_main.c
+++ b/drivers/infiniband/sw/siw/siw_main.c
@@ -178,6 +178,8 @@ static void siw_destroy_cpulist(void)
 		kfree(siw_cpu_info.tx_valid_cpus[i++]);
 
 	kfree(siw_cpu_info.tx_valid_cpus);
+	siw_cpu_info.tx_valid_cpus = NULL;
+	siw_cpu_info.num_nodes = 0;
 }
 
 /*
-- 
2.34.1


  parent reply	other threads:[~2023-07-27 14:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-27 14:03 [PATCH 0/5] Fix potential issues for siw Guoqing Jiang
2023-07-27 14:03 ` [PATCH 1/5] RDMA/siw: Set siw_cm_wq to NULL after it is destroyed Guoqing Jiang
2023-07-27 14:03 ` Guoqing Jiang [this message]
2023-07-27 14:03 ` [PATCH 3/5] RDMA/siw: Initialize siw_link_ops.list Guoqing Jiang
2023-07-27 14:03 ` [PATCH 4/5] RDMA/siw: Set siw_crypto_shash to NULL after it is freed Guoqing Jiang
2023-07-27 14:03 ` [PATCH 5/5] RDMA/siw: Don't call wake_up unconditionally in siw_stop_tx_thread Guoqing Jiang
2023-07-27 17:17 ` [PATCH 0/5] Fix potential issues for siw Bernard Metzler
2023-07-27 17:29   ` Jason Gunthorpe
2023-07-27 18:15     ` Bart Van Assche
2023-07-28  1:16     ` Guoqing Jiang
2023-07-28  2:29       ` Guoqing Jiang
2023-07-28 11:10         ` Bernard Metzler
2023-07-28  9:36       ` Bernard Metzler
2023-08-09 19:04 ` Jason Gunthorpe
2023-08-10  1:14   ` Guoqing Jiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230727140349.25369-3-guoqing.jiang@linux.dev \
    --to=guoqing.jiang@linux.dev \
    --cc=bmt@zurich.ibm.com \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).