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 v13 2/2] block: implement NVMEM provider
Date: Tue, 24 Nov 2026 12:44:56 +0000 [thread overview]
Message-ID: <sashiko-outbox-231171@kernel.org> (raw)
In-Reply-To: <20261123-block-as-nvmem-v13-2-96ffe1f59332@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] block: async blk_nvmem_wq work races with synchronous parent
device_del()
- [High] block: bdev claiming fwnode->dev on fixed-layout node blocks
nvmem consumers
--
commit 0e36d62b71ee050cb34dcd10f5cbdc451589e7c4
Author: Loic Poulain <loic.poulain@oss.qualcomm.com>
block: implement NVMEM provider
This commit adds an NVMEM provider for block devices and partitions whose
device tree node describes an NVMEM layout, deferring NVMEM registration
and unregistration to an ordered workqueue.
> diff --git a/block/blk-nvmem.c b/block/blk-nvmem.c
> new file mode 100644
> index 0000000000000..628681f6b747b
> --- /dev/null
> +++ b/block/blk-nvmem.c
[ ... ]
> +void blk_nvmem_add(struct block_device *bdev)
> +{
> + struct device *dev = &bdev->bd_device;
> + struct device_node *np = dev_of_node(dev);
> + struct blk_nvmem *bn;
> + struct device_node *child;
> + loff_t size;
> +
> + /* skip devices which do not have a device tree node */
> + if (!np)
> + return;
> +
> + /*
> + * The layout is described either by an "nvmem-layout" child node or
> + * by the device node itself being a "fixed-layout" container.
> + */
> + child = of_get_child_by_name(np, "nvmem-layout");
> + if (child)
> + of_node_put(child);
> + else if (!of_device_is_compatible(np, "fixed-layout"))
> + return;
[Severity: High]
When np is a "fixed-layout" node itself, does &bdev->bd_device claiming
np->fwnode.dev prevent consumers of its NVMEM cells from probing under
fw_devlink?
__add_disk() and add_partition() call device_set_node() and device_add()
on &bdev->bd_device before blk_nvmem_add(), so device_add() sets
np->fwnode.dev = &bdev->bd_device. Because &bdev->bd_device has no bus
and never binds to a driver, device_links_driver_bound() never runs on it.
When nvmem_register() later creates layout->dev with the same OF node np,
device_add(&layout->dev) leaves np->fwnode.dev pointing at
&bdev->bd_device. When layout->dev binds to fixed_layout_layout,
device_links_driver_bound(&layout->dev) skips
fw_devlink_pickup_dangling_consumers():
drivers/base/core.c:device_links_driver_bound() {
...
if (dev->fwnode && dev->fwnode->dev == dev) {
fwnode_links_purge_suppliers(dev->fwnode);
fw_devlink_pickup_dangling_consumers(dev);
}
...
}
The child NVMEM cell fwnodes never get FWNODE_FLAG_NOT_DEVICE set and
their consumer fwnode_links are never converted to available device links,
leaving consumers stuck in -EPROBE_DEFER.
[ ... ]
> +void blk_nvmem_del(struct block_device *bdev)
> +{
> + struct blk_nvmem *bn = bdev->bd_nvmem;
> +
> + if (!bn)
> + return;
> +
> + bdev->bd_nvmem = NULL;
> +
> + queue_work(blk_nvmem_wq, &bn->del_work);
> +}
[Severity: High]
Can deferring nvmem_register() and nvmem_unregister() to blk_nvmem_wq race
with the synchronous device_del(&bdev->bd_device) in drop_partition() and
__del_gendisk()?
drop_partition() and __del_gendisk() call blk_nvmem_del() and then
synchronously run device_del(&bdev->bd_device) while bn->add_work and
bn->del_work are still queued or running on blk_nvmem_wq:
CPU0 kworker (blk_nvmem_wq)
drop_partition(part)
blk_nvmem_del(part)
queue_work(..., &bn->del_work)
blk_nvmem_add_work()
nvmem_register()
device_add(&nvmem->dev)
kobject_add_internal()
sysfs_create_dir_ns()
parent = kobj->parent->sd;
device_del(&part->bd_device)
kobject_del(&part->bd_device.kobj)
__kobject_del()
sysfs_remove_dir()
sysfs_put(sd) <-- frees parent sd
kernfs_create_dir_ns(parent, ...)
<-- use-after-free on parent
sysfs_create_dir_ns() reads kobj->parent->sd without a reference before
sleeping in __kernfs_new_node(), so concurrent __kobject_del() on
&bdev->bd_device can drop the parent kernfs_node refcount to 0 and free it
via RCU while nvmem_register() is still using it.
Even when blk_nvmem_add_work() finishes before removal starts,
device_del(&bdev->bd_device) runs before blk_nvmem_del_work() calls
nvmem_unregister(), deleting the parent device while its child nvmem->dev
(and grandchild layout->dev) is still registered. That removes the parent
from dpm_list ahead of its children and clears bdev->bd_device.kobj.parent
before nvmem_unregister() emits KOBJ_REMOVE uevents.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-block-as-nvmem-v13-0-96ffe1f59332@oss.qualcomm.com?part=2
prev parent reply other threads:[~2026-11-24 12:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 12:44 [PATCH v13 0/2] Support for block device NVMEM providers Loic Poulain
2026-11-23 12:44 ` [PATCH v13 1/2] block: partitions: of: Attach partition fwnode to the block device Loic Poulain
2026-11-23 12:44 ` [PATCH v13 2/2] block: implement NVMEM provider Loic Poulain
2026-11-24 12:44 ` sashiko-bot [this message]
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-231171@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox