mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Petr Mladek <pmladek@suse.com>,
	linux-kernel@vger.kernel.org,
	Luis Chamberlain <mcgrof@kernel.org>,
	Ming Lei <ming.lei@redhat.com>
Subject: [PATCH V2 1/2] kobject: don't delay to cleanup module kobject
Date: Mon, 29 Nov 2021 11:45:08 +0800	[thread overview]
Message-ID: <20211129034509.2646872-2-ming.lei@redhat.com> (raw)
In-Reply-To: <20211129034509.2646872-1-ming.lei@redhat.com>

CONFIG_DEBUG_KOBJECT_RELEASE is used for debugging kobject release and
cleanup issue. The module kobject is released after module_exit() returns.
If this kobject is delayed too much, and may cause other kobjects cleaned
up a bit earlier before freeing module, then real issue is hidden.

So don't delay module kobject's cleanup, meantime module kobject is
always cleaned up synchronously, and CONFIG_DEBUG_KOBJECT_RELEASE is
actually needless for module kobject.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 lib/kobject.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/lib/kobject.c b/lib/kobject.c
index 4a56f519139d..b81319b0bd5a 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -16,6 +16,7 @@
 #include <linux/stat.h>
 #include <linux/slab.h>
 #include <linux/random.h>
+#include <linux/module.h>
 
 /**
  * kobject_namespace() - Return @kobj's namespace tag.
@@ -727,6 +728,19 @@ static void kobject_release(struct kref *kref)
 	struct kobject *kobj = container_of(kref, struct kobject, kref);
 #ifdef CONFIG_DEBUG_KOBJECT_RELEASE
 	unsigned long delay = HZ + HZ * (get_random_int() & 0x3);
+
+	/*
+	 * Don't delay to release module kobject so that we can detect late
+	 * kobject release more effectively because module unloading waits
+	 * for completion of module kobject release, see mod_kobject_put.
+	 *
+	 * Meantime mod_kobject_put() always waits for completion of module
+	 * kobject's release, CONFIG_DEBUG_KOBJECT_RELEASE is basically
+	 * useless for debugging module kobject's release.
+	 */
+	if (kobj->ktype == &module_ktype)
+		delay = 0;
+
 	pr_info("kobject: '%s' (%p): %s, parent %p (delayed %ld)\n",
 		 kobject_name(kobj), kobj, __func__, kobj->parent, delay);
 	INIT_DELAYED_WORK(&kobj->release, kobject_delayed_cleanup);
-- 
2.31.1


  reply	other threads:[~2021-11-29  3:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-29  3:45 [PATCH V2 0/2] kobject: avoid to cleanup kobject after module is unloaded Ming Lei
2021-11-29  3:45 ` Ming Lei [this message]
2021-12-03 15:08   ` [PATCH V2 1/2] kobject: don't delay to cleanup module kobject Greg Kroah-Hartman
2021-12-07 13:58   ` kernel test robot
2021-11-29  3:45 ` [PATCH V2 2/2] kobject: wait until kobject is cleaned up before freeing module Ming Lei
2021-12-03 15:07   ` Greg Kroah-Hartman
2021-12-06  2:13     ` Ming Lei
2021-12-06  8:04       ` Greg Kroah-Hartman
2021-12-07  1:50         ` Ming Lei
2021-12-07 10:32         ` Petr Mladek
2021-12-07 12:51           ` Ming Lei
2021-12-07 14:02             ` Petr Mladek
2022-07-07  4:54               ` Ming Lei

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=20211129034509.2646872-2-ming.lei@redhat.com \
    --to=ming.lei@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=pmladek@suse.com \
    /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

all inboxes | Powered by JetHome®