From: Weng Meiling <wengmeiling.weng@huawei.com>
To: Greg KH <gregkh@linuxfoundation.org>, <tj@kernel.org>,
Jens Axboe <axboe@kernel.dk>, <akpm@linux-foundation.org>,
<adilger.kernel@dilger.ca>, Jan Kara <jack@suse.cz>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Xiang Rui <rui.xiang@huawei.com>, Li Zefan <lizefan@huawei.com>,
Huang Qiang <h.huangqiang@huawei.com>,
Zhao Hongjiang <zhaohongjiang@huawei.com>
Subject: Re: Subject: [PATCH] kobject: fix the race between kobject_del and get_device_parent
Date: Thu, 16 Oct 2014 09:56:35 +0800 [thread overview]
Message-ID: <543F25D3.8010708@huawei.com> (raw)
In-Reply-To: <543E1754.8040701@huawei.com>
Hi,
Would you please give me some of your views on this issue? Any suggestion is appreciative.
Thanks!
Weng Meiling
On 2014/10/15 14:42, Weng Meiling wrote:
> When the last child kobject was deleted, it's parent kobject will be deleted,
> when removing the parent kobject if the parent kobject's sd has been set NULL
> and still not been removed from it's kset's list, at the same time another one
> trigger an device adding event, the function get_parent_device() will get the
> parent object from the kset's list for kobject_add(), but this time parent
> kobject's sd has been NULL. This race will make the sysfs_create_dir() return
> ENOENT, the new kobject will be failed to added into sysfs and trigger BUG()
> when creating attribute group under the new device's directory. So move the
> kobject removal from kset's list before kobj->sd=NULL.
>
> The race situation:
>
> path0(remove parent kobj, e.g:/sys/devices/virtual/block/) path1(register a new device)
>
> kobject_del(){ get_device_parent(){
> ... ...
> sysfs_remove_dir(kobj); //kobj->sd=NULL spin_lock(&dev->class->p->glue_dirs.list_lock);
> ... <=== list_for_each_entry(k, &dev->class->p->glue_dirs.list, entry)
> kobj_kset_leave(kobj); //remove kobj from kset list ...
> } }
>
>
> We had triggered the bug, the detail message link:
> https://lkml.org/lkml/2014/10/13/40
>
> Signed-off-by: Weng Meiling <wengmeiling.weng@huawei.com>
> ---
> lib/kobject.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/lib/kobject.c b/lib/kobject.c
> index 58751bb..af2b7bb 100644
> --- a/lib/kobject.c
> +++ b/lib/kobject.c
> @@ -560,12 +560,13 @@ void kobject_del(struct kobject *kobj)
> if (!kobj)
> return;
>
> + kobj_kset_leave(kobj);
> +
> sd = kobj->sd;
> sysfs_remove_dir(kobj);
> sysfs_put(sd);
>
> kobj->state_in_sysfs = 0;
> - kobj_kset_leave(kobj);
> kobject_put(kobj->parent);
> kobj->parent = NULL;
> }
>
next prev parent reply other threads:[~2014-10-16 1:57 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-15 6:42 Weng Meiling
2014-10-16 1:56 ` Weng Meiling [this message]
2014-10-16 7:07 ` Frans Klaver
2014-10-16 7:23 ` Weng Meiling
2014-10-16 9:13 ` Greg KH
2014-10-22 8:07 ` Weng Meiling
2014-11-04 19:15 ` Tejun Heo
2014-11-05 2:01 ` Yijing Wang
2014-11-05 3:13 ` Tejun Heo
2014-11-05 3:27 ` Yijing Wang
2014-11-05 3:29 ` Tejun Heo
2014-11-05 3:52 ` Greg KH
2014-11-05 5:14 ` Yijing Wang
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=543F25D3.8010708@huawei.com \
--to=wengmeiling.weng@huawei.com \
--cc=adilger.kernel@dilger.ca \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=gregkh@linuxfoundation.org \
--cc=h.huangqiang@huawei.com \
--cc=jack@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=rui.xiang@huawei.com \
--cc=tj@kernel.org \
--cc=zhaohongjiang@huawei.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
Powered by JetHome