From: Cornelia Huck <cornelia.huck@de.ibm.com>
To: Tejun Heo <tj@kernel.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Jens Axboe <jens.axboe@oracle.com>, Greg K-H <greg@kroah.com>
Subject: Re: [PATCH] block: fix block_class iteration locking
Date: Mon, 14 Jul 2008 13:42:28 +0200 [thread overview]
Message-ID: <20080714134228.1079c6f7@gondolin.boeblingen.de.ibm.com> (raw)
In-Reply-To: <487AECD0.5010602@kernel.org>
On Mon, 14 Jul 2008 15:06:08 +0900,
Tejun Heo <tj@kernel.org> wrote:
> genhd.c used block_class_lock when it wants to iterate over
> block_class.devices list. This is incorrect as block_class_lock has
> nothing to do with synchronization around block_class.devices list, so
> there's a window, albeit small, where the list can change while it's
> being iterated over. Fix it by using block_class.sem instead.
>
> Signed-off-by: Tejun Heo <tj@kernel.org>
Greg has some patches sitting in his tree that convert those functions
to use class_{for_each,find}_device() instead - and that looks like the
clean solution, especially since the class implementation details will
be moved into a private structure. One worry though...
> @@ -285,7 +285,7 @@ static void *part_start(struct seq_file *part, loff_t *pos)
> loff_t k = *pos;
> struct device *dev;
>
> - mutex_lock(&block_class_lock);
> + down(&block_class.sem);
> list_for_each_entry(dev, &block_class.devices, node) {
> if (dev->type != &disk_type)
> continue;
> @@ -311,7 +311,7 @@ static void *part_next(struct seq_file *part, void *v, loff_t *pos)
>
> static void part_stop(struct seq_file *part, void *v)
> {
> - mutex_unlock(&block_class_lock);
> + up(&block_class.sem);
> }
>
> static int show_partition(struct seq_file *part, void *v)
> @@ -533,7 +533,7 @@ static void *diskstats_start(struct seq_file *part, loff_t *pos)
> loff_t k = *pos;
> struct device *dev;
>
> - mutex_lock(&block_class_lock);
> + down(&block_class.sem);
> list_for_each_entry(dev, &block_class.devices, node) {
> if (dev->type != &disk_type)
> continue;
> @@ -560,7 +560,7 @@ static void *diskstats_next(struct seq_file *part, void *v, loff_t *pos)
>
> static void diskstats_stop(struct seq_file *part, void *v)
> {
> - mutex_unlock(&block_class_lock);
> + up(&block_class.sem);
> }
>
> static int diskstats_show(struct seq_file *s, void *v)
With your patch, you protect against adding/removing devices to/from
the class between _start and _stop. This wasn't done previously, and
won't be done with Greg's patches (which leaves in the
locking/unlocking of block_class_lock). Not sure if I'm missing
something here...
next prev parent reply other threads:[~2008-07-14 11:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-14 6:06 Tejun Heo
2008-07-14 11:42 ` Cornelia Huck [this message]
2008-07-14 11:50 ` Tejun Heo
2008-07-21 17:34 ` 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=20080714134228.1079c6f7@gondolin.boeblingen.de.ibm.com \
--to=cornelia.huck@de.ibm.com \
--cc=greg@kroah.com \
--cc=jens.axboe@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.org \
/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®