From: ChristophHellwig <hch@lst.de>
To: Liwei Song <liwei.song@windriver.com>
Cc: MiquelRaynal <miquel.raynal@bootlin.com>,
RichardWeinberger <richard@nod.at>,
VigneshRaghavendra <vigneshr@ti.com>,
ChristophHellwig <hch@lst.de>,
linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mtd_blkdevs: add mtd_table_mutex lock back to blktrans_{open, release} to avoid race condition
Date: Tue, 9 Aug 2022 10:08:09 +0200 [thread overview]
Message-ID: <20220809080809.GB14727@lst.de> (raw)
In-Reply-To: <20220809075753.21950-1-liwei.song@windriver.com>
On Tue, Aug 09, 2022 at 03:57:53PM +0800, Liwei Song wrote:
> without lock mtd_table_mutex in blktrans_{open, release}, there will
> be a race condition when access devices /dev/mtd1 and /dev/mtdblock1
> at the same time with a high frequency open and close test:
>
> kernel BUG at drivers/mtd/mtdcore.c:1221!
> lr : blktrans_release+0xb0/0x120
This does not seem on a current mainline kernel and seems to be
a somewhat incomplete backtrace. Can you send the full dmesg of
a latest mainline run and maybe share the reproducer?
> diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
> index b8ae1ec14e17..147e4a11dfe4 100644
> --- a/drivers/mtd/mtd_blkdevs.c
> +++ b/drivers/mtd/mtd_blkdevs.c
> @@ -188,6 +188,8 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode)
>
> kref_get(&dev->ref);
>
> + if (!mutex_trylock(&mtd_table_mutex))
> + return ret;
No, that's not really the solution.
Turning the kref_get above into a kref_get_unless_zero might be better
path to look into.
next prev parent reply other threads:[~2022-08-09 8:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-09 7:57 [PATCH] mtd_blkdevs: add mtd_table_mutex lock back to blktrans_{open, release} to avoid race condition Liwei Song
2022-08-09 8:08 ` ChristophHellwig [this message]
2022-08-09 9:03 ` Liwei Song
2022-08-10 7:47 ` Liwei Song
2022-09-05 8:15 ` Liwei Song
2022-09-09 14:36 ` ChristophHellwig
2022-09-13 5:52 ` Liwei Song
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=20220809080809.GB14727@lst.de \
--to=hch@lst.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=liwei.song@windriver.com \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=vigneshr@ti.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