From: Mike Snitzer <snitzer@redhat.com>
To: Yu Kuai <yukuai1@huaweicloud.com>
Cc: hch@lst.de, axboe@kernel.dk, agk@redhat.com, snitzer@kernel.org,
dm-devel@redhat.com, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org, yukuai3@huawei.com,
yi.zhang@huawei.com
Subject: Re: [PATCH RFC v3 05/10] dm: make sure create and remove dm device won't race with open and close table
Date: Wed, 16 Nov 2022 16:48:42 -0500 [thread overview]
Message-ID: <Y3VaunS49xJvHflm@redhat.com> (raw)
In-Reply-To: <20221115141054.1051801-6-yukuai1@huaweicloud.com>
On Tue, Nov 15 2022 at 9:10P -0500,
Yu Kuai <yukuai1@huaweicloud.com> wrote:
> From: Yu Kuai <yukuai3@huawei.com>
>
> open_table_device() and close_table_device() is protected by
> table_devices_lock, hence use it to protect add_disk() and
> del_gendisk().
>
> Prepare to track per-add_disk holder relations in dm.
>
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
> drivers/md/dm.c | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git a/drivers/md/dm.c b/drivers/md/dm.c
> index 2917700b1e15..3728b56b364b 100644
> --- a/drivers/md/dm.c
> +++ b/drivers/md/dm.c
> @@ -1952,7 +1952,14 @@ static void cleanup_mapped_device(struct mapped_device *md)
> spin_unlock(&_minor_lock);
> if (dm_get_md_type(md) != DM_TYPE_NONE) {
> dm_sysfs_exit(md);
> +
> + /*
> + * Hold lock to make sure del_gendisk() won't concurrent
> + * with open/close_table_device().
> + */
> + mutex_lock(&md->table_devices_lock);
> del_gendisk(md->disk);
> + mutex_unlock(&md->table_devices_lock);
> }
> dm_queue_destroy_crypto_profile(md->queue);
> put_disk(md->disk);
> @@ -2312,15 +2319,24 @@ int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t)
> if (r)
> return r;
>
> + /*
> + * Hold lock to make sure add_disk() and del_gendisk() won't concurrent
> + * with open_table_device() and close_table_device().
> + */
> + mutex_lock(&md->table_devices_lock);
> r = add_disk(md->disk);
> + mutex_unlock(&md->table_devices_lock);
> if (r)
> return r;
>
> r = dm_sysfs_init(md);
> if (r) {
> + mutex_lock(&md->table_devices_lock);
> del_gendisk(md->disk);
> + mutex_unlock(&md->table_devices_lock);
> return r;
> }
> +
> md->type = type;
> return 0;
> }
> --
> 2.31.1
>
In the new comments added: s/concurrent/race/ ?
But otherwise:
Reviewed-by: Mike Snitzer <snitzer@kernel.org>
next prev parent reply other threads:[~2022-11-16 21:50 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-15 14:10 [PATCH v3 00/10] fix delayed holder tracking Yu Kuai
2022-11-15 14:10 ` [PATCH v3 01/10] block: clear ->slave_dir when dropping the main slave_dir reference Yu Kuai
2022-11-16 22:10 ` Mike Snitzer
2022-11-15 14:10 ` [PATCH v3 02/10] dm: remove free_table_devices Yu Kuai
2022-11-16 21:50 ` Mike Snitzer
2022-11-15 14:10 ` [PATCH v3 03/10] dm: cleanup open_table_device Yu Kuai
2022-11-16 21:19 ` Mike Snitzer
2022-11-15 14:10 ` [PATCH v3 04/10] dm: cleanup close_table_device Yu Kuai
2022-11-16 21:46 ` Mike Snitzer
2022-11-15 14:10 ` [PATCH RFC v3 05/10] dm: make sure create and remove dm device won't race with open and close table Yu Kuai
2022-11-16 6:35 ` Christoph Hellwig
2022-11-16 21:48 ` Mike Snitzer [this message]
2022-11-15 14:10 ` [PATCH v3 06/10] dm: track per-add_disk holder relations in DM Yu Kuai
2022-11-16 21:49 ` Mike Snitzer
2022-11-15 14:10 ` [PATCH v3 07/10] block: remove delayed holder registration Yu Kuai
2022-11-15 14:10 ` [PATCH v3 08/10] block: fix use after free for bd_holder_dir Yu Kuai
2022-11-16 6:35 ` Christoph Hellwig
2022-11-15 14:10 ` [PATCH v3 09/10] block: store the holder kobject in bd_holder_disk Yu Kuai
2022-11-16 6:36 ` Christoph Hellwig
2022-11-15 14:10 ` [PATCH v3 10/10] block: don't allow a disk link holder to itself Yu Kuai
2022-11-16 6:36 ` Christoph Hellwig
2022-11-16 22:20 ` [PATCH v3 00/10] fix delayed holder tracking Jens Axboe
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=Y3VaunS49xJvHflm@redhat.com \
--to=snitzer@redhat.com \
--cc=agk@redhat.com \
--cc=axboe@kernel.dk \
--cc=dm-devel@redhat.com \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=snitzer@kernel.org \
--cc=yi.zhang@huawei.com \
--cc=yukuai1@huaweicloud.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;
as well as URLs for NNTP newsgroup(s).