* [PATCH] dax/bus: Fix size_store() error path locking
@ 2026-11-29 23:29 Bart Van Assche
2026-11-29 23:34 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Bart Van Assche @ 2026-11-29 23:29 UTC (permalink / raw)
To: Vishal Verma, Dave Jiang, Alison Schofield
Cc: nvdimm, linux-cxl, linux-kernel, Bart Van Assche, Dan Williams
If down_write_killable(&dax_dev_rwsem) fails, size_store() jumps to the
err_dev label and calls up_write(&dax_dev_rwsem) on a rwsem it does not
hold. Jump to err_region instead such that only dax_region_rwsem is
released on that error path. This locking bug was detected by the Clang
thread-safety analyzer.
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Vishal Verma <vishal.l.verma@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Alison Schofield <alison.schofield@intel.com>
Cc: nvdimm@lists.linux.dev
Cc: linux-cxl@vger.kernel.org
Fixes: c05ae9d85b47 ("dax/bus.c: replace driver-core lock usage by a local rwsem")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/dax/bus.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c
index e40c25401cf0..fc83be5d6663 100644
--- a/drivers/dax/bus.c
+++ b/drivers/dax/bus.c
@@ -1129,11 +1129,10 @@ static ssize_t size_store(struct device *dev, struct device_attribute *attr,
}
rc = down_write_killable(&dax_dev_rwsem);
if (rc)
- goto err_dev;
+ goto err_region;
rc = dev_dax_resize(dax_region, dev_dax, val);
-err_dev:
up_write(&dax_dev_rwsem);
err_region:
up_write(&dax_region_rwsem);
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] dax/bus: Fix size_store() error path locking
2026-11-29 23:29 [PATCH] dax/bus: Fix size_store() error path locking Bart Van Assche
@ 2026-11-29 23:34 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-29 23:34 UTC (permalink / raw)
To: Bart Van Assche; +Cc: nvdimm, linux-cxl
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] dax/bus: self-deadlock in __devm_create_dev_dax() [1]
--
commit 7b62e0aebcb009f3fd5163ad1f5b0fe4c39c45b9
Author: Bart Van Assche <bvanassche@acm.org>
dax/bus: Fix size_store() error path locking
This commit fixes the error path in size_store() when acquiring
dax_dev_rwsem fails so that it does not unlock dax_dev_rwsem without
holding it.
> diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c
> index e40c25401cf06..fc83be5d6663c 100644
> --- a/drivers/dax/bus.c
> +++ b/drivers/dax/bus.c
> @@ -1129,11 +1129,10 @@ static ssize_t size_store(struct device *dev, struct device_attribute *attr,
> }
> rc = down_write_killable(&dax_dev_rwsem);
> if (rc)
> - goto err_dev;
> + goto err_region;
>
> rc = dev_dax_resize(dax_region, dev_dax, val);
>
> -err_dev:
> up_write(&dax_dev_rwsem);
> err_region:
> up_write(&dax_region_rwsem);
[Severity: High]
This problem wasn't introduced by this patch, but can
__devm_create_dev_dax() self-deadlock on dax_region_rwsem [1] when
devm_add_action_or_reset() fails?
Both devm_create_dev_dax() and create_store() hold dax_region_rwsem for
write while calling __devm_create_dev_dax():
drivers/dax/bus.c:__devm_create_dev_dax() {
...
rc = devm_add_action_or_reset(dax_region->dev, unregister_dev_dax, dev);
if (rc)
return ERR_PTR(rc);
...
}
If the devres allocation fails, devm_add_action_or_reset() synchronously
calls unregister_dev_dax(), which calls down_write(&dax_region_rwsem) and
deadlocks against the caller.
[1] https://sashiko.dev/#/bug/linux-be038c5a-8c27-4fcf-8ee1-010658394459
--
Sashiko AI review · https://sashiko.dev/#/patchset/1c8cdb292623bfb846b1b8c7256a1002f7eedd6b.1795994997.git.bvanassche@acm.org?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-29 23:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 23:29 [PATCH] dax/bus: Fix size_store() error path locking Bart Van Assche
2026-11-29 23:34 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox