LKML Archive on lore.kernel.org help / color / mirror / Atom feed
* [-mm PATCH] sysdev_unregister() should call kobject_del() @ 2008-02-07 23:56 Badari Pulavarty 2008-02-08 0:38 ` Greg KH 0 siblings, 1 reply; 10+ messages in thread From: Badari Pulavarty @ 2008-02-07 23:56 UTC (permalink / raw) To: Greg KH, Andrew Morton; +Cc: lkml Hi Greg, While playing with hotplug memory remove on 2.6.24-mm1, I noticed that /sysfs directory entries are not getting removed. sysdev_unregister() used to call kobject_unregister(). But in 2.6.24-mm1, its only dropping the ref. It should call kobject_del() to remove the object. Correct ? With this change, the directories are getting removed correctly. Comments ? Thanks, Badari sysdev_unregister() should call kobject_del() to remove the object. Signed-off-by: Badari Pulavarty <pbadari@us.ibm.com> --- drivers/base/sys.c | 1 + 1 file changed, 1 insertion(+) Index: linux-2.6.24/drivers/base/sys.c =================================================================== --- linux-2.6.24.orig/drivers/base/sys.c 2008-02-05 09:56:56.000000000 -0800 +++ linux-2.6.24/drivers/base/sys.c 2008-02-07 15:38:17.000000000 -0800 @@ -265,6 +265,7 @@ void sysdev_unregister(struct sys_device } mutex_unlock(&sysdev_drivers_lock); + kobject_del(&sysdev->kobj); kobject_put(&sysdev->kobj); } ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [-mm PATCH] sysdev_unregister() should call kobject_del() 2008-02-07 23:56 [-mm PATCH] sysdev_unregister() should call kobject_del() Badari Pulavarty @ 2008-02-08 0:38 ` Greg KH 2008-02-08 1:25 ` Badari Pulavarty 0 siblings, 1 reply; 10+ messages in thread From: Greg KH @ 2008-02-08 0:38 UTC (permalink / raw) To: Badari Pulavarty; +Cc: Andrew Morton, lkml On Thu, Feb 07, 2008 at 03:56:58PM -0800, Badari Pulavarty wrote: > Hi Greg, > > While playing with hotplug memory remove on 2.6.24-mm1, I > noticed that /sysfs directory entries are not getting removed. > > sysdev_unregister() used to call kobject_unregister(). > But in 2.6.24-mm1, its only dropping the ref. It should > call kobject_del() to remove the object. Correct ? > > With this change, the directories are getting removed > correctly. Comments ? Ick, no, this shouldn't be needed, someone else must be holding a reference to the kobject device somewhere. See the kobject documenation for more info. I'll try to see where we grab 2 references... Have I mentioned lately that I hate the sysdev code? ugh, greg k-h ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [-mm PATCH] sysdev_unregister() should call kobject_del() 2008-02-08 0:38 ` Greg KH @ 2008-02-08 1:25 ` Badari Pulavarty 2008-02-08 4:55 ` Greg KH 0 siblings, 1 reply; 10+ messages in thread From: Badari Pulavarty @ 2008-02-08 1:25 UTC (permalink / raw) To: Greg KH; +Cc: Andrew Morton, lkml On Thu, 2008-02-07 at 16:38 -0800, Greg KH wrote: > On Thu, Feb 07, 2008 at 03:56:58PM -0800, Badari Pulavarty wrote: > > Hi Greg, > > > > While playing with hotplug memory remove on 2.6.24-mm1, I > > noticed that /sysfs directory entries are not getting removed. > > > > sysdev_unregister() used to call kobject_unregister(). > > But in 2.6.24-mm1, its only dropping the ref. It should > > call kobject_del() to remove the object. Correct ? > > > > With this change, the directories are getting removed > > correctly. Comments ? > > Ick, no, this shouldn't be needed, someone else must be holding a > reference to the kobject device somewhere. See the kobject documenation > for more info. > > I'll try to see where we grab 2 references... I will take a closer look then. I was taking easy way out :( Thanks, Badari ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [-mm PATCH] sysdev_unregister() should call kobject_del() 2008-02-08 1:25 ` Badari Pulavarty @ 2008-02-08 4:55 ` Greg KH 2008-02-08 5:08 ` Badari Pulavarty 2008-02-08 23:22 ` Badari Pulavarty 0 siblings, 2 replies; 10+ messages in thread From: Greg KH @ 2008-02-08 4:55 UTC (permalink / raw) To: Badari Pulavarty; +Cc: Andrew Morton, lkml On Thu, Feb 07, 2008 at 05:25:46PM -0800, Badari Pulavarty wrote: > On Thu, 2008-02-07 at 16:38 -0800, Greg KH wrote: > > On Thu, Feb 07, 2008 at 03:56:58PM -0800, Badari Pulavarty wrote: > > > Hi Greg, > > > > > > While playing with hotplug memory remove on 2.6.24-mm1, I > > > noticed that /sysfs directory entries are not getting removed. > > > > > > sysdev_unregister() used to call kobject_unregister(). > > > But in 2.6.24-mm1, its only dropping the ref. It should > > > call kobject_del() to remove the object. Correct ? > > > > > > With this change, the directories are getting removed > > > correctly. Comments ? > > > > Ick, no, this shouldn't be needed, someone else must be holding a > > reference to the kobject device somewhere. See the kobject documenation > > for more info. > > > > I'll try to see where we grab 2 references... > > I will take a closer look then. I was taking easy way out :( Hm, I don't see anything obvious in the sys.c core. What code is controlling these objects that you are creating and removing from the system? thanks, greg k-h ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [-mm PATCH] sysdev_unregister() should call kobject_del() 2008-02-08 4:55 ` Greg KH @ 2008-02-08 5:08 ` Badari Pulavarty 2008-02-08 5:41 ` Greg KH 2008-02-08 23:22 ` Badari Pulavarty 1 sibling, 1 reply; 10+ messages in thread From: Badari Pulavarty @ 2008-02-08 5:08 UTC (permalink / raw) To: Greg KH; +Cc: Andrew Morton, lkml On Thu, 2008-02-07 at 20:55 -0800, Greg KH wrote: > On Thu, Feb 07, 2008 at 05:25:46PM -0800, Badari Pulavarty wrote: > > On Thu, 2008-02-07 at 16:38 -0800, Greg KH wrote: > > > On Thu, Feb 07, 2008 at 03:56:58PM -0800, Badari Pulavarty wrote: > > > > Hi Greg, > > > > > > > > While playing with hotplug memory remove on 2.6.24-mm1, I > > > > noticed that /sysfs directory entries are not getting removed. > > > > > > > > sysdev_unregister() used to call kobject_unregister(). > > > > But in 2.6.24-mm1, its only dropping the ref. It should > > > > call kobject_del() to remove the object. Correct ? > > > > > > > > With this change, the directories are getting removed > > > > correctly. Comments ? > > > > > > Ick, no, this shouldn't be needed, someone else must be holding a > > > reference to the kobject device somewhere. See the kobject documenation > > > for more info. > > > > > > I'll try to see where we grab 2 references... > > > > I will take a closer look then. I was taking easy way out :( > > Hm, I don't see anything obvious in the sys.c core. What code is > controlling these objects that you are creating and removing from the > system? add_memory_block()/register_memory() is creating sysfs entries for the memory blocks. I am trying to make use of remove_memory_block() to clean up sysfs entries. BTW, remove_memory_block() is never tested before, since we don't support memory remove yet. Thanks, Badari ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [-mm PATCH] sysdev_unregister() should call kobject_del() 2008-02-08 5:08 ` Badari Pulavarty @ 2008-02-08 5:41 ` Greg KH 2008-02-08 16:42 ` Badari Pulavarty 0 siblings, 1 reply; 10+ messages in thread From: Greg KH @ 2008-02-08 5:41 UTC (permalink / raw) To: Badari Pulavarty; +Cc: Andrew Morton, lkml On Thu, Feb 07, 2008 at 09:08:42PM -0800, Badari Pulavarty wrote: > > On Thu, 2008-02-07 at 20:55 -0800, Greg KH wrote: > > On Thu, Feb 07, 2008 at 05:25:46PM -0800, Badari Pulavarty wrote: > > > On Thu, 2008-02-07 at 16:38 -0800, Greg KH wrote: > > > > On Thu, Feb 07, 2008 at 03:56:58PM -0800, Badari Pulavarty wrote: > > > > > Hi Greg, > > > > > > > > > > While playing with hotplug memory remove on 2.6.24-mm1, I > > > > > noticed that /sysfs directory entries are not getting removed. > > > > > > > > > > sysdev_unregister() used to call kobject_unregister(). > > > > > But in 2.6.24-mm1, its only dropping the ref. It should > > > > > call kobject_del() to remove the object. Correct ? > > > > > > > > > > With this change, the directories are getting removed > > > > > correctly. Comments ? > > > > > > > > Ick, no, this shouldn't be needed, someone else must be holding a > > > > reference to the kobject device somewhere. See the kobject documenation > > > > for more info. > > > > > > > > I'll try to see where we grab 2 references... > > > > > > I will take a closer look then. I was taking easy way out :( > > > > Hm, I don't see anything obvious in the sys.c core. What code is > > controlling these objects that you are creating and removing from the > > system? > > add_memory_block()/register_memory() is creating sysfs entries > for the memory blocks. > > I am trying to make use of remove_memory_block() to clean up > sysfs entries. BTW, remove_memory_block() is never tested > before, since we don't support memory remove yet. So how are you testing the sysdev removal logic then if you can't remove memory? Oh, one thing, remove the link in unregister_memory, before you call sysdev_unregister(). You are trying to get the name of a kobject, and the whole object, that has just been blown away, not nice... Which makes me believe your statement about this never being tested before :) thanks, greg k-h ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [-mm PATCH] sysdev_unregister() should call kobject_del() 2008-02-08 5:41 ` Greg KH @ 2008-02-08 16:42 ` Badari Pulavarty 2008-02-08 21:30 ` Dave Hansen 0 siblings, 1 reply; 10+ messages in thread From: Badari Pulavarty @ 2008-02-08 16:42 UTC (permalink / raw) To: Greg KH, haveblue; +Cc: Andrew Morton, lkml On Thu, 2008-02-07 at 21:41 -0800, Greg KH wrote: > On Thu, Feb 07, 2008 at 09:08:42PM -0800, Badari Pulavarty wrote: > > > > On Thu, 2008-02-07 at 20:55 -0800, Greg KH wrote: > > > On Thu, Feb 07, 2008 at 05:25:46PM -0800, Badari Pulavarty wrote: > > > > On Thu, 2008-02-07 at 16:38 -0800, Greg KH wrote: > > > > > On Thu, Feb 07, 2008 at 03:56:58PM -0800, Badari Pulavarty wrote: > > > > > > Hi Greg, > > > > > > > > > > > > While playing with hotplug memory remove on 2.6.24-mm1, I > > > > > > noticed that /sysfs directory entries are not getting removed. > > > > > > > > > > > > sysdev_unregister() used to call kobject_unregister(). > > > > > > But in 2.6.24-mm1, its only dropping the ref. It should > > > > > > call kobject_del() to remove the object. Correct ? > > > > > > > > > > > > With this change, the directories are getting removed > > > > > > correctly. Comments ? > > > > > > > > > > Ick, no, this shouldn't be needed, someone else must be holding a > > > > > reference to the kobject device somewhere. See the kobject documenation > > > > > for more info. > > > > > > > > > > I'll try to see where we grab 2 references... > > > > > > > > I will take a closer look then. I was taking easy way out :( > > > > > > Hm, I don't see anything obvious in the sys.c core. What code is > > > controlling these objects that you are creating and removing from the > > > system? > > > > add_memory_block()/register_memory() is creating sysfs entries > > for the memory blocks. > > > > I am trying to make use of remove_memory_block() to clean up > > sysfs entries. BTW, remove_memory_block() is never tested > > before, since we don't support memory remove yet. > > So how are you testing the sysdev removal logic then if you can't remove > memory? I am now adding code to remove memory, I am making use of the existing unregister_memory() code and ran into this. > > Oh, one thing, remove the link in unregister_memory, before you call > sysdev_unregister(). You are trying to get the name of a kobject, and > the whole object, that has just been blown away, not nice... I can add remove link before unregister() as you suggested. Regarding accessing kobject after freeing up, no one calls with "root". Why not clean it up first, like this ? Dave, are you okay with this ? Thanks, Badari register_memory()/unregister_memory() never gets called with "root". unregister_memory() is accessing kobject_name of the object just freed up. Since no one uses the code, lets take the code out. And also, make register_memory() static (since unregister_memory() is already static). Signed-off-by: Badari Pulavarty <pbadari@us.ibm.com> --- drivers/base/memory.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) Index: linux-2.6.24/drivers/base/memory.c =================================================================== --- linux-2.6.24.orig/drivers/base/memory.c 2008-02-07 16:59:52.000000000 -0800 +++ linux-2.6.24/drivers/base/memory.c 2008-02-08 08:26:33.000000000 -0800 @@ -62,8 +62,8 @@ void unregister_memory_notifier(struct n /* * register_memory - Setup a sysfs device for a memory block */ -int register_memory(struct memory_block *memory, struct mem_section *section, - struct node *root) +static +int register_memory(struct memory_block *memory, struct mem_section *section) { int error; @@ -71,26 +71,16 @@ int register_memory(struct memory_block memory->sysdev.id = __section_nr(section); error = sysdev_register(&memory->sysdev); - - if (root && !error) - error = sysfs_create_link(&root->sysdev.kobj, - &memory->sysdev.kobj, - kobject_name(&memory->sysdev.kobj)); - return error; } static void -unregister_memory(struct memory_block *memory, struct mem_section *section, - struct node *root) +unregister_memory(struct memory_block *memory, struct mem_section *section) { BUG_ON(memory->sysdev.cls != &memory_sysdev_class); BUG_ON(memory->sysdev.id != __section_nr(section)); sysdev_unregister(&memory->sysdev); - if (root) - sysfs_remove_link(&root->sysdev.kobj, - kobject_name(&memory->sysdev.kobj)); } /* @@ -361,7 +351,7 @@ static int add_memory_block(unsigned lon mutex_init(&mem->state_mutex); mem->phys_device = phys_device; - ret = register_memory(mem, section, NULL); + ret = register_memory(mem, section); if (!ret) ret = mem_create_simple_file(mem, phys_index); if (!ret) @@ -415,7 +405,7 @@ int remove_memory_block(unsigned long no mem_remove_simple_file(mem, state); mem_remove_simple_file(mem, phys_device); mem_remove_simple_file(mem, removable); - unregister_memory(mem, section, NULL); + unregister_memory(mem, section); return 0; } ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [-mm PATCH] sysdev_unregister() should call kobject_del() 2008-02-08 16:42 ` Badari Pulavarty @ 2008-02-08 21:30 ` Dave Hansen 0 siblings, 0 replies; 10+ messages in thread From: Dave Hansen @ 2008-02-08 21:30 UTC (permalink / raw) To: Badari Pulavarty; +Cc: Greg KH, Andrew Morton, lkml On Fri, 2008-02-08 at 08:42 -0800, Badari Pulavarty wrote: > > I can add remove link before unregister() as you suggested. > > Regarding accessing kobject after freeing up, no one calls with > "root". > Why not clean it up first, like this ? > > Dave, are you okay with this ? Yeah, I don't see any users of it, either. It looks fine to me. -- Dave ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [-mm PATCH] sysdev_unregister() should call kobject_del() 2008-02-08 4:55 ` Greg KH 2008-02-08 5:08 ` Badari Pulavarty @ 2008-02-08 23:22 ` Badari Pulavarty 2008-02-08 23:57 ` Greg KH 1 sibling, 1 reply; 10+ messages in thread From: Badari Pulavarty @ 2008-02-08 23:22 UTC (permalink / raw) To: Greg KH, haveblue; +Cc: Andrew Morton, lkml On Thu, 2008-02-07 at 20:55 -0800, Greg KH wrote: > On Thu, Feb 07, 2008 at 05:25:46PM -0800, Badari Pulavarty wrote: > > On Thu, 2008-02-07 at 16:38 -0800, Greg KH wrote: > > > On Thu, Feb 07, 2008 at 03:56:58PM -0800, Badari Pulavarty wrote: > > > > Hi Greg, > > > > > > > > While playing with hotplug memory remove on 2.6.24-mm1, I > > > > noticed that /sysfs directory entries are not getting removed. > > > > > > > > sysdev_unregister() used to call kobject_unregister(). > > > > But in 2.6.24-mm1, its only dropping the ref. It should > > > > call kobject_del() to remove the object. Correct ? > > > > > > > > With this change, the directories are getting removed > > > > correctly. Comments ? > > > > > > Ick, no, this shouldn't be needed, someone else must be holding a > > > reference to the kobject device somewhere. See the kobject documenation > > > for more info. > > > > > > I'll try to see where we grab 2 references... > > > > I will take a closer look then. I was taking easy way out :( > > Hm, I don't see anything obvious in the sys.c core. What code is > controlling these objects that you are creating and removing from the > system? > I found the culprit. Its not in sys.c core :) remove_memory_block() takes a reference on kobject by calling find_memory_block(). It then calls unregister_memory() to free up sysfs entry. It drops only one ref (which it got at register time). So it never gets freed up. I am going to send out a separate patch for it. Thanks for your help. Thanks, Badari ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [-mm PATCH] sysdev_unregister() should call kobject_del() 2008-02-08 23:22 ` Badari Pulavarty @ 2008-02-08 23:57 ` Greg KH 0 siblings, 0 replies; 10+ messages in thread From: Greg KH @ 2008-02-08 23:57 UTC (permalink / raw) To: Badari Pulavarty; +Cc: haveblue, Andrew Morton, lkml On Fri, Feb 08, 2008 at 03:22:29PM -0800, Badari Pulavarty wrote: > > On Thu, 2008-02-07 at 20:55 -0800, Greg KH wrote: > > On Thu, Feb 07, 2008 at 05:25:46PM -0800, Badari Pulavarty wrote: > > > On Thu, 2008-02-07 at 16:38 -0800, Greg KH wrote: > > > > On Thu, Feb 07, 2008 at 03:56:58PM -0800, Badari Pulavarty wrote: > > > > > Hi Greg, > > > > > > > > > > While playing with hotplug memory remove on 2.6.24-mm1, I > > > > > noticed that /sysfs directory entries are not getting removed. > > > > > > > > > > sysdev_unregister() used to call kobject_unregister(). > > > > > But in 2.6.24-mm1, its only dropping the ref. It should > > > > > call kobject_del() to remove the object. Correct ? > > > > > > > > > > With this change, the directories are getting removed > > > > > correctly. Comments ? > > > > > > > > Ick, no, this shouldn't be needed, someone else must be holding a > > > > reference to the kobject device somewhere. See the kobject documenation > > > > for more info. > > > > > > > > I'll try to see where we grab 2 references... > > > > > > I will take a closer look then. I was taking easy way out :( > > > > Hm, I don't see anything obvious in the sys.c core. What code is > > controlling these objects that you are creating and removing from the > > system? > > > > I found the culprit. Its not in sys.c core :) Glad to hear it :) > remove_memory_block() takes a reference on kobject by calling > find_memory_block(). It then calls unregister_memory() to free up sysfs > entry. > It drops only one ref (which it got at register time). So it never gets > freed up. I am going to send out a separate patch for it. Ah, nice catch. thanks, greg k-h ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2008-02-09 0:00 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2008-02-07 23:56 [-mm PATCH] sysdev_unregister() should call kobject_del() Badari Pulavarty 2008-02-08 0:38 ` Greg KH 2008-02-08 1:25 ` Badari Pulavarty 2008-02-08 4:55 ` Greg KH 2008-02-08 5:08 ` Badari Pulavarty 2008-02-08 5:41 ` Greg KH 2008-02-08 16:42 ` Badari Pulavarty 2008-02-08 21:30 ` Dave Hansen 2008-02-08 23:22 ` Badari Pulavarty 2008-02-08 23:57 ` Greg KH
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).