public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dennis Chen <xschen@tnsoft.com.cn>
To: Tejun Heo <tj@kernel.org>
Cc: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org,
	xiyou.wangcong@gmail.com
Subject: Re: [PATCH] race condition fixing in sysfs_create_dir
Date: Tue, 30 Jul 2013 14:34:56 +0800	[thread overview]
Message-ID: <51F75E90.2090908@tnsoft.com.cn> (raw)
In-Reply-To: <20130726133856.GD3013@htj.dyndns.org>

On 07/26/2013 09:38 PM, Tejun Heo wrote:
> Hello,
>
> On Fri, Jul 26, 2013 at 05:59:00PM +0800, Dennis Chen wrote:
>> On 07/26/2013 05:49 PM, Dennis Chen wrote:
>>
>>> The patch is trying its best to avoid creating a dir under a parent dir which is removing from
>>> the system:
>>>      PATH0 (create a dir under 'PARENT/...')         PATH1 (remove the 'PARENT/...')
>>>           sysfs_create_dir() {                         sysfs_remove_dir() {
>>>           ...                                          ...
>>>           if (kobj->parent)                            spin_lock(&sysfs_assoc_lock);
>>>          parent_sd = kobj->parent->sd;  <----- kobj->sd = NULL;
>>>       else                                         spin_unlock(&sysfs_assoc_lock);
>>>          parent_sd = &sysfs_root;
>>> Suppose PATH1 enter the critical section first, then PATH0 begin to execute before kobj->sd
>>> has been reset to NULL, possibly PATH0 will get a non-NULL parent_sd since lack of the
>>> sysfs_assoc_lock protection in PATH0. In this case, PATH0 think it has a valid parent_sd which
>>> can be freed by PATH1 in the followed, refer to the comments in the patch. Maybe we need
>>> to figure out a perfect solution to solve the race condition, although the codes in question are
>>> in slow path...
> I don't think sysfs is supposed to handle multiple actors trying to
> populate and destroy the directory at the same time at all, so this
> seems kinda moot.  Do you have a case where this actually matters?
>
> Thanks.
>
hello,Tejun. Nice. But seems I still have different opinion :). If you look at the 'sysfs_do_create_link_sd()'
code, you will find a comment "target->sd can go away beneath us but is protected with sysfs_assoc_lock.
Fetch target_sd from it", don't you think the sysfs_create_dir is the same as the sysfs_do_create_link_sd()
essentially? if the answer is yes meaning the parent dir can go away when its sub-dir is creating by sysfs_create_dir,
then the similar action should be taken as sysfs_create_link does. right?

  


  parent reply	other threads:[~2013-07-30  6:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-26  9:49 [PATCH] race condition fixing in sysfs_create_dir Dennis Chen
2013-07-26  9:59 ` Dennis Chen
2013-07-26 13:38   ` Tejun Heo
2013-07-26 13:41     ` Tejun Heo
2013-07-30  6:34     ` Dennis Chen [this message]
2013-07-30 14:10       ` Tejun Heo

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=51F75E90.2090908@tnsoft.com.cn \
    --to=xschen@tnsoft.com.cn \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.org \
    --cc=xiyou.wangcong@gmail.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