mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhihao Cheng <chengzhihao1@huawei.com>
To: Richard Weinberger <richard@nod.at>,
	"libaokun (A)" <libaokun1@huawei.com>
Cc: Miquel Raynal <miquel.raynal@bootlin.com>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	linux-mtd <linux-mtd@lists.infradead.org>,
	linux-kernel <linux-kernel@vger.kernel.org>, <yukuai3@huawei.com>,
	Hulk Robot <hulkci@huawei.com>
Subject: Re: [PATCH -next V3] ubi: fix race condition between ctrl_cdev_ioctl and ubi_cdev_ioctl
Date: Tue, 28 Dec 2021 15:48:12 +0800	[thread overview]
Message-ID: <b8f6bbf3-cca4-9bfa-f70a-393f04edd21f@huawei.com> (raw)
In-Reply-To: <509065063.197038.1640293568550.JavaMail.zimbra@nod.at>

在 2021/12/24 5:06, Richard Weinberger 写道:
> ----- Ursprüngliche Mail -----


>>> ubi_get_device is used to prevent devices from being deleted during
>>> sysfs execution. However, now kernfs ensures that devices will not
>>> be deleted before all reference counting are released.
>>> The key process is shown in the following stack.
> 
> ubi_get_device() in dev_attribute_show() is used to detect whether
> the ubi device got detached while the sysfs file is open.
> 
> Hmm. I thought for sysfs this is not the case since sysfs does not implement
> a release() method. So kernfs_drain_open_files() will return early.
> But there is a good chance that I don't got all kernfs/sysfs details.
> 

kernfs_drain() will wait 'root->deactivate_waitq' if 
atomic_read(&kn->active) not equals to KN_DEACTIVATED_BIAS.

The UBI seq_show callback is invoked with avtive cnt taken:
vfs_read
   kernfs_fop_read_iter
     seq_read_iter
       m->op->start (kernfs_seq_start)   // kernfs_get_active(of->kn)
       kernfs_seq_show
         dev_attribute_show [ubi]
       m->op->stop (kernfs_seq_stop)     // kernfs_put_active(of->kn)

The kernfs_drain() is stuck at wait_event() until sysfs reading 
finished, in my local test.

  reply	other threads:[~2021-12-28  7:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-05  9:30 Baokun Li
2021-12-21 12:33 ` libaokun (A)
2021-12-23 21:06   ` Richard Weinberger
2021-12-28  7:48     ` Zhihao Cheng [this message]
2021-12-30 21:32       ` Richard Weinberger
2021-12-28 12:40     ` libaokun (A)

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=b8f6bbf3-cca4-9bfa-f70a-393f04edd21f@huawei.com \
    --to=chengzhihao1@huawei.com \
    --cc=hulkci@huawei.com \
    --cc=libaokun1@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --cc=vigneshr@ti.com \
    --cc=yukuai3@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

all inboxes | Powered by JetHome®