linux-kernel.vger.kernel.org archive mirror
 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>,
	Joe Lawrence <joe.lawrence@redhat.com>
Subject: Re: [PATCH 1/2] kobject: don't delay to cleanup module kobject
Date: Mon, 29 Nov 2021 10:38:26 +0800	[thread overview]
Message-ID: <YaQ9Iq3qF6H76Pzt@T590> (raw)
In-Reply-To: <YaEMaWMT+PmMvSwg@kroah.com>

On Fri, Nov 26, 2021 at 05:33:45PM +0100, Greg Kroah-Hartman wrote:
> On Sat, Nov 27, 2021 at 12:28:48AM +0800, Ming Lei wrote:
> > On Fri, Nov 26, 2021 at 05:08:16PM +0100, Greg Kroah-Hartman wrote:
> > > On Fri, Nov 05, 2021 at 02:37:09PM +0800, Ming Lei wrote:
> > > > CONFIG_DEBUG_KOBJECT_RELEASE is used for debugging kobject release/cleanup
> > > > issue. The module kobject is released after module_exit() returns. If
> > > > this kobject is delayed too much, and may cause other kobject's
> > > > 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 we needn't module kobject's
> > > > cleanup.
> > > > 
> > > > Signed-off-by: Ming Lei <ming.lei@redhat.com>
> > > > ---
> > > >  lib/kobject.c | 5 +++++
> > > >  1 file changed, 5 insertions(+)
> > > > 
> > > > diff --git a/lib/kobject.c b/lib/kobject.c
> > > > index ea53b30cf483..4c0dbe11be3d 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,10 @@ 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);
> > > > +
> > > > +	if (kobj->ktype == &module_ktype)
> > > > +		delay = 0;
> > > 
> > > No, there should not be anything "special" about module kobjects to get
> > > this kind of treatment.  They should work like any other kobject and
> > > clean up properly when needed.
> > 
> > Here setting 0 delay for module kobject is just for making DEBUG_KOBJECT_RELEASE
> > reliable to detect/report issues. Otherwise if the random delay for module
> > kobject is bigger than other kobjects, potential use-after-after won't
> > be exposed.
> 
> So you now can not debug the module kobject code?

So far, module kobject code is always released in sync way, see
mod_kobject_put(), and CONFIG_DEBUG_KOBJECT_RELEASE is basically useless
for module kobject.

> 
> This needs to be documented really really really well why this kobject
> type is somehow "special" in the code.  We should not special-case these
> things unless you have a great reason, and I am not yet convinced.

OK, I will add comment on this special usage in V2 so that you can
review it further.


Thanks,
Ming


  reply	other threads:[~2021-11-29  2:40 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-05  6:37 [PATCH 0/2] kobject: avoid to cleanup kobject after module is unloaded Ming Lei
2021-11-05  6:37 ` [PATCH 1/2] kobject: don't delay to cleanup module kobject Ming Lei
2021-11-26 16:08   ` Greg Kroah-Hartman
2021-11-26 16:28     ` Ming Lei
2021-11-26 16:33       ` Greg Kroah-Hartman
2021-11-29  2:38         ` Ming Lei [this message]
2021-11-05  6:37 ` [PATCH 2/2] kobject: wait until kobject is cleaned up before freeing module Ming Lei
2021-11-05 14:10   ` kernel test robot
2021-11-05 14:54     ` Ming Lei
2021-11-08 17:26   ` Petr Mladek
2021-11-09  2:00     ` Ming Lei
2021-11-09 13:14       ` Petr Mladek
2021-11-10  1:20         ` Ming Lei
2021-11-10  7:03           ` Greg Kroah-Hartman
2021-11-10  9:05             ` Petr Mladek
2021-11-10  9:19               ` Greg Kroah-Hartman

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=YaQ9Iq3qF6H76Pzt@T590 \
    --to=ming.lei@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=joe.lawrence@redhat.com \
    --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;
as well as URLs for NNTP newsgroup(s).