linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zqiang <qiang1.zhang@intel.com>
To: paulmck@kernel.org, frederic@kernel.org, joel@joelfernandes.org
Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] srcu: Fix flush sup work warning in cleanup_srcu_struct()
Date: Tue, 21 Mar 2023 16:13:46 +0800	[thread overview]
Message-ID: <20230321081346.192000-1-qiang1.zhang@intel.com> (raw)

insmod rcutorture.ko
rmmod rcutorture.ko

[  209.437327] WARNING: CPU: 0 PID: 508 at kernel/workqueue.c:3167 __flush_work+0x50a/0x540
[  209.437346] Modules linked in: rcutorture(-) torture [last unloaded: rcutorture]
[  209.437382] CPU: 0 PID: 508 Comm: rmmod Tainted: G  W  6.3.0-rc1-yocto-standard+
[  209.437406] RIP: 0010:__flush_work+0x50a/0x540
.....
[  209.437758]  flush_delayed_work+0x36/0x90
[  209.437776]  cleanup_srcu_struct+0x68/0x2e0
[  209.437817]  srcu_module_notify+0x71/0x140
[  209.437854]  blocking_notifier_call_chain+0x9d/0xd0
[  209.437880]  __x64_sys_delete_module+0x223/0x2e0
[  209.438046]  do_syscall_64+0x43/0x90
[  209.438062]  entry_SYSCALL_64_after_hwframe+0x72/0xdc

For srcu objects defined with DEFINE_SRCU() or DEFINE_STATIC_SRCU(),
when compiling and loading as modules, the srcu_module_coming() is invoked,
allocate memory for srcu structure's->sda and initialize sda structure,
due to not fully initialize srcu structure's->sup, so at this time the
sup structure's->delaywork.func is null, if not invoke init_srcu_struct_fields()
before unloading modules, in srcu_module_going() the __flush_work() find
work->func is empty, will raise the warning above.

This commit add init_srcu_struct_fields() to initialize srcu structure's->sup,
in srcu_module_coming().

Signed-off-by: Zqiang <qiang1.zhang@intel.com>
---
 kernel/rcu/srcutree.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index 1fb078abbdc9..42d8720e016c 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -1921,7 +1921,8 @@ static int srcu_module_coming(struct module *mod)
 		ssp->sda = alloc_percpu(struct srcu_data);
 		if (WARN_ON_ONCE(!ssp->sda))
 			return -ENOMEM;
-		init_srcu_struct_data(ssp);
+		if (WARN_ON_ONCE(init_srcu_struct_fields(ssp, true)))
+			return -ENOMEM;
 	}
 	return 0;
 }
@@ -1931,9 +1932,13 @@ static void srcu_module_going(struct module *mod)
 {
 	int i;
 	struct srcu_struct **sspp = mod->srcu_struct_ptrs;
+	struct srcu_struct *ssp;
 
-	for (i = 0; i < mod->num_srcu_structs; i++)
-		cleanup_srcu_struct(*(sspp++));
+	for (i = 0; i < mod->num_srcu_structs; i++) {
+		ssp = *(sspp++);
+		cleanup_srcu_struct(ssp);
+		free_percpu(ssp->sda);
+	}
 }
 
 /* Handle one module, either coming or going. */
-- 
2.25.1


             reply	other threads:[~2023-03-21  8:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-21  8:13 Zqiang [this message]
2023-03-21 15:04 ` [PATCH] srcu: Fix flush sup work warning in cleanup_srcu_struct() Paul E. McKenney
2023-03-21 15:06   ` Paul E. McKenney
2023-03-22  1:15   ` Zhang, Qiang1
2023-03-22  3:54     ` Paul E. McKenney
2023-03-22  4:38       ` Zhang, Qiang1
2023-03-22 14:57         ` Paul E. McKenney
2023-03-22 22:08           ` Zhang, Qiang1
2023-03-22 23:10             ` Paul E. McKenney
2023-03-22 23:45               ` Zhang, Qiang1
2023-03-22 23:52                 ` Zhang, Qiang1
2023-03-23  0:07                   ` Paul E. McKenney
2023-03-23  0:40                     ` Zhang, Qiang1
2023-03-23  3:39                       ` Zhang, Qiang1
2023-03-23  5:07                         ` Paul E. McKenney
2023-03-23  6:21                           ` Zhang, Qiang1

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=20230321081346.192000-1-qiang1.zhang@intel.com \
    --to=qiang1.zhang@intel.com \
    --cc=frederic@kernel.org \
    --cc=joel@joelfernandes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=rcu@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).