mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Cornelia Huck <cornelia.huck@de.ibm.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Tejun Heo <htejun@gmail.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Greg K-H <greg@kroah.com>, Rusty Russell <rusty@rustcorp.com.au>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>
Subject: Re: [PATCH RFD] alternative kobject release wait mechanism
Date: Wed, 18 Apr 2007 17:26:26 +0200	[thread overview]
Message-ID: <20070418172626.198b96c2@gondolin.boeblingen.de.ibm.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0704181032060.12246-100000@iolanthe.rowland.org>

On Wed, 18 Apr 2007 10:53:55 -0400 (EDT),
Alan Stern <stern@rowland.harvard.edu> wrote:

> Many drivers, especially those for hot-pluggable buses, register and
> unregister devices dynamically.  These events can occur in time-critical
> situations, where the driver cannot afford to wait for all the references
> to be dropped when unregistering a device.  It's okay to wait in a module
> exit routine, but to make things work the routine would have to wait for
> references to _all_ unregistered objects to go away, not just the
> references for the objects it unregisters at exit time.

Uh, yes, didn't think of that. I'd even say that's the majority of
devices allocated in a driver.

> BTW, Cornelia, there's a small problem with your patch set.  You have
> kobject_init() try to grab a reference to kobj->owner, but it's quite
> possible for kobj->owner to contain uninitialized garbage since the rest
> of the kernel is still unaware of its existence.  There's a patch below to
> fix things up.  I've got a second patch which makes device_initialize()  
> pass an owner to the embedded kobject, but I want to try it out a little
> before posting it.  :-)

I was relying on the object being zeroed after allocation (and the
caller of kobject_initialize already setting ->owner), but passing an
owner via the initializing routine sounds saner. Thanks for looking at
that.


> Index: usb-2.6/include/linux/kobject.h
> ===================================================================
> --- usb-2.6.orig/include/linux/kobject.h
> +++ usb-2.6/include/linux/kobject.h
> @@ -71,7 +71,8 @@ static inline const char * kobject_name(
>  	return kobj->k_name;
>  }
> 
> -extern void kobject_init(struct kobject *);
> +extern void kobject_init_owner(struct kobject *, struct module *owner);
> +#define kobject_init(kobj)	kobject_init_owner(kobj, THIS_MODULE)
>  extern void kobject_cleanup(struct kobject *);
> 
>  extern int __must_check kobject_add(struct kobject *);
> @@ -84,7 +85,9 @@ extern int __must_check kobject_shadow_r
>  						const char *new_name);
>  extern int __must_check kobject_move(struct kobject *, struct kobject *);
> 
> -extern int __must_check kobject_register(struct kobject *);
> +extern int __must_check kobject_register_owner(struct kobject *,
> +		struct module *owner);
> +#define kobject_register(kobj)	kobject_register_owner(kobj, THIS_MODULE)
>  extern void kobject_unregister(struct kobject *);
> 
>  extern struct kobject * kobject_get(struct kobject *);
> Index: usb-2.6/lib/kobject.c
> ===================================================================
> --- usb-2.6.orig/lib/kobject.c
> +++ usb-2.6/lib/kobject.c
> @@ -164,10 +164,11 @@ static void verify_dynamic_kobject_alloc
>  #endif
> 
>  /**
> - *	kobject_init - initialize object.
> + *	kobject_init_onwer - initialize object.
>   *	@kobj:	object in question.
> + *	@owner: module owning @kobj.
>   */
> -void kobject_init(struct kobject * kobj)
> +void kobject_init_owner(struct kobject * kobj, struct module *owner)
>  {
>  	if (!kobj)
>  		return;
> @@ -178,6 +179,7 @@ void kobject_init(struct kobject * kobj)
>  	init_waitqueue_head(&kobj->poll);
>  	kobj->kset = kset_get(kobj->kset);
>  	/* Attempt to grab reference of owning module's kobject. */
> +	kobj->owner = owner;
>  	mod_kobject_get(kobj->owner);
>  }
> 
> @@ -272,15 +274,16 @@ int kobject_add(struct kobject * kobj)
> 
> 
>  /**
> - *	kobject_register - initialize and add an object.
> + *	kobject_register_owner - initialize and add an object.
>   *	@kobj:	object in question.
> + *	@owner:	module owning @kobj.
>   */
> 
> -int kobject_register(struct kobject * kobj)
> +int kobject_register_owner(struct kobject * kobj, struct module *owner)
>  {
>  	int error = -EINVAL;
>  	if (kobj) {
> -		kobject_init(kobj);
> +		kobject_init_owner(kobj, owner);
>  		error = kobject_add(kobj);
>  		if (!error)
>  			kobject_uevent(kobj, KOBJ_ADD);
> @@ -750,8 +753,8 @@ void subsys_remove_file(struct subsystem
>  }
>  #endif  /*  0  */
> 
> -EXPORT_SYMBOL(kobject_init);
> -EXPORT_SYMBOL(kobject_register);
> +EXPORT_SYMBOL(kobject_init_owner);
> +EXPORT_SYMBOL(kobject_register_owner);
>  EXPORT_SYMBOL(kobject_unregister);
>  EXPORT_SYMBOL(kobject_get);
>  EXPORT_SYMBOL(kobject_put);
> 

Hm, this means we always have an owner (until we explicitely call
kobject_{init,register}_owner(kobj, NULL)) - which may be unneeded in
some cases. But better to err on the safe side, I suppose.

  reply	other threads:[~2007-04-18 15:23 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-16 17:36 [Patch -mm 0/3] RFC: module unloading vs. release function Cornelia Huck
2007-04-16 18:30 ` Dmitry Torokhov
2007-04-16 18:47   ` Greg KH
2007-04-16 19:03     ` Dmitry Torokhov
2007-04-16 19:11       ` Greg KH
2007-04-16 20:20         ` Dmitry Torokhov
2007-04-16 19:38   ` Alan Stern
2007-04-16 19:47     ` Dmitry Torokhov
2007-04-16 19:52       ` Greg KH
2007-04-16 20:18         ` Dmitry Torokhov
2007-04-16 21:02           ` Alan Stern
2007-04-17  7:49             ` Cornelia Huck
2007-04-16 20:44     ` Alexey Dobriyan
2007-04-17  2:55       ` Rusty Russell
2007-04-17  7:36     ` Cornelia Huck
2007-04-16 18:53 ` Greg KH
2007-04-17 18:41 ` [PATCH RFD] alternative kobject release wait mechanism Tejun Heo
2007-04-17 18:49   ` Tejun Heo
2007-04-18  8:11     ` Cornelia Huck
2007-04-18  8:46       ` Tejun Heo
2007-04-18  9:35         ` Cornelia Huck
2007-04-18  9:55           ` Tejun Heo
2007-04-18  8:07   ` Cornelia Huck
2007-04-18  8:36     ` Tejun Heo
2007-04-18 14:53   ` Alan Stern
2007-04-18 15:26     ` Cornelia Huck [this message]
2007-04-18 15:34     ` Tejun Heo
2007-04-18 15:45       ` Tejun Heo
2007-04-18 19:07         ` Alan Stern
2007-04-20  5:27           ` Tejun Heo
2007-04-20  9:11             ` Cornelia Huck
2007-04-20 15:01             ` Alan Stern
2007-04-20 15:57               ` Dmitry Torokhov
2007-04-21 15:19                 ` Alan Stern
2007-04-20 15:40             ` Alan Stern
2007-04-21  0:03               ` Greg KH
2007-04-21 21:36                 ` Alan Stern
2007-04-22 17:40                   ` Greg KH
2007-04-23  7:08                     ` Cornelia Huck
2007-04-23 19:47                       ` Alan Stern
2007-04-24 19:38                     ` Alan Stern
2007-04-25  9:00                       ` Cornelia Huck
2007-04-25 20:13                         ` Alan Stern
2007-04-26  8:21                           ` Cornelia Huck
2007-04-26 14:58                             ` Alan Stern
2007-04-26 15:12                               ` Cornelia Huck
2007-04-18 16:11       ` Alan Stern
2007-04-18 16:38         ` Tejun Heo
2007-04-18 16:41       ` Dmitry Torokhov
2007-04-19 12:51         ` Cornelia Huck
2007-04-19 13:13           ` Dmitry Torokhov
2007-04-19 13:48             ` Cornelia Huck
2007-04-19 14:21               ` Dmitry Torokhov
2007-04-20  5:59                 ` Tejun Heo
2007-04-20 16:35                   ` Dmitry Torokhov
2007-04-20 16:52                     ` Tejun Heo
2007-04-20 17:59                       ` Dmitry Torokhov
2007-04-23  6:40                         ` Tejun Heo
2007-04-23  6:53                           ` Greg KH
2007-04-19 17:19         ` Alan Stern
2007-04-19 18:39           ` Dmitry Torokhov
2007-04-19 22:37             ` Alan Stern
2007-04-20 16:35               ` Dmitry Torokhov
2007-04-21 15:30                 ` Alan Stern
2007-04-18 15:06   ` Cornelia Huck
2007-04-18 16:06     ` Tejun Heo
2007-04-19 13:29       ` Cornelia Huck
2007-04-19 14:20         ` Alan Stern
2007-04-19 14:49           ` Cornelia Huck
2007-04-20  9:04             ` Cornelia Huck

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=20070418172626.198b96c2@gondolin.boeblingen.de.ibm.com \
    --to=cornelia.huck@de.ibm.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=greg@kroah.com \
    --cc=htejun@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    --cc=stern@rowland.harvard.edu \
    /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®