All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Loic Poulain" <loic.poulain@oss.qualcomm.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v11 3/7] block: implement NVMEM provider
Date: Fri, 16 Oct 2026 14:26:43 +0000	[thread overview]
Message-ID: <sashiko-outbox-174445@kernel.org> (raw)
In-Reply-To: <20261015-block-as-nvmem-v11-3-f890ac74f87d@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] block: AB-BA deadlock and self-deadlock due to disk->open_mutex and NVMEM SRCU
- [Medium] block: delayed release of exclusive claim causes spurious -EBUSY on open
--

commit 163603c5c331585f01bddc0cceeabc4bb95a5455
Author: Loic Poulain <loic.poulain@oss.qualcomm.com>

block: implement NVMEM provider

This commit implements a block device NVMEM provider, allowing partitions
to expose factory-provisioned data like MAC addresses to consuming drivers.
The NVMEM accesses use BLK_OPEN_EXCL to keep other exclusive openers away
during the reads.

> diff --git a/block/blk-nvmem.c b/block/blk-nvmem.c
> new file mode 100644
> index 0000000000000..69b69184e1630
> --- /dev/null
> +++ b/block/blk-nvmem.c
[ ... ]
> +static int blk_nvmem_reg_read(void *priv, unsigned int from,
> +			      void *val, size_t bytes)
> +{
> +	struct block_device *bdev = priv;
> +	struct file *bdev_file;
> +	loff_t pos = from;
> +	ssize_t ret;
> +
> +	/* open and prevent other exclusive openers */
> +	bdev_file = bdev_file_open_by_dev(bdev->bd_dev,
> +					  BLK_OPEN_READ | BLK_OPEN_EXCL,
> +					  blk_nvmem_reg_read, NULL);
> +	if (IS_ERR(bdev_file))
> +		return PTR_ERR(bdev_file);
> +
> +	if (file_bdev(bdev_file) != bdev) {
> +		fput(bdev_file);
> +		return -ENODEV;
> +	}
> +
> +	ret = kernel_read(bdev_file, val, bytes, &pos);
> +	fput(bdev_file);

[Severity: Medium]
Will using fput() here and in the error path above defer the release of the
block device's exclusive claim?

Because fput() delegates the file release to task work or a workqueue, the
exclusive claim won't be yielded synchronously. If a process or script reads
the NVMEM cell and immediately tries to open the same block device
exclusively (e.g., to mount it), could it spuriously fail with -EBUSY?

Should this use bdev_fput() instead, which calls bdev_yield_claim()
synchronously before fput()?

> diff --git a/block/partitions/core.c b/block/partitions/core.c
> index eee954df1ac6e..c83227710584a 100644
> --- a/block/partitions/core.c
> +++ b/block/partitions/core.c
[ ... ]
> @@ -289,6 +289,8 @@ void drop_partition(struct block_device *part)
>  	xa_erase(&part->bd_disk->part_tbl, bdev_partno(part));
>  	kobject_put(part->bd_holder_dir);
>  
> +	blk_nvmem_del(part);

[Severity: High]
Can this create an AB-BA deadlock with concurrent NVMEM readers?

drop_partition() is called with disk->open_mutex held. blk_nvmem_del() calls
nvmem_unregister(), which waits for active readers via
synchronize_srcu(&nvmem->srcu).

If an untrusted user space process is reading the NVMEM sysfs file while
the block device is being removed, the concurrent reader executing
__nvmem_reg_read() holds srcu_read_lock(&nvmem->srcu) and calls
bdev_file_open_by_dev(), which blocks on disk->open_mutex.

Won't the teardown thread and the reader thread deadlock waiting for
each other's locks?

[ ... ]
> @@ -406,6 +408,9 @@ static struct block_device *add_partition(struct gendisk *disk, int partno,
>  	/* suppress uevent if the disk suppresses it */
>  	if (!dev_get_uevent_suppress(ddev))
>  		kobject_uevent(&pdev->kobj, KOBJ_ADD);
> +
> +	blk_nvmem_add(bdev);

[Severity: High]
Could this result in a self-deadlock during partition creation?

add_partition() executes with disk->open_mutex held. If the NVMEM device
requires layout parsing (e.g., reading ONIE TLV data), the NVMEM core
will read from the device during nvmem_register() via __nvmem_reg_read().

This invokes blk_nvmem_reg_read(), which opens the block device via
bdev_file_open_by_dev() and blocks attempting to acquire the already held
disk->open_mutex.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261015-block-as-nvmem-v11-0-f890ac74f87d@oss.qualcomm.com?part=3

  reply	other threads:[~2026-10-16 14:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15 14:25 [PATCH v11 0/7] Support for block device NVMEM providers Loic Poulain
2026-10-15 14:26 ` [PATCH v11 1/7] dt-bindings: bluetooth: qcom: Add NVMEM BD address cell Loic Poulain
2026-10-15 16:44   ` Support for block device NVMEM providers bluez.test.bot
2026-10-15 14:26 ` [PATCH v11 2/7] block: partitions: of: Attach partition fwnode to the block device Loic Poulain
2026-10-16 14:26   ` sashiko-bot
2026-10-15 14:26 ` [PATCH v11 3/7] block: implement NVMEM provider Loic Poulain
2026-10-16 14:26   ` sashiko-bot [this message]
2026-10-15 14:26 ` [PATCH v11 4/7] net: of_net: Add of_get_nvmem_eui48() helper for EUI-48 lookup Loic Poulain
2026-10-15 14:26 ` [PATCH v11 5/7] Bluetooth: hci_sync: Add NVMEM-backed BD address retrieval Loic Poulain
2026-10-15 14:26 ` [PATCH v11 6/7] Bluetooth: qca: Set NVMEM BD address quirks when address is invalid Loic Poulain
2026-10-15 14:26 ` [PATCH v11 7/7] arm64: dts: qcom: arduino-imola: Add NVMEM layout for WiFi/BT Loic Poulain

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=sashiko-outbox-174445@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=loic.poulain@oss.qualcomm.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.