[PATCH 20/23] nvmet: fix PCI P2P parameters access using nvmet_subsys::lock
Nilay Shroff
nilay at linux.ibm.com
Sun Nov 8 19:28:25 PST 2026
The nvmet_ns::p2p_dev and nvmet_ns::use_p2pmem fields are protected by
nvmet_subsys::lock. However, nvmet_ns_p2pmem_show() accesses these
fields without holding the corresponding lock, triggering Clang context
analyzer errors:
drivers/nvme/target/configfs.c:587:42: error: reading variable 'p2p_dev' requires holding mutex 'to_nvmet_ns(item).subsys->lock'
[-Werror,-Wthread-safety-analysis]
587 | return pci_p2pdma_enable_show(page, ns->p2p_dev, ns->use_p2pmem);
| ^
drivers/nvme/target/configfs.c:587:55: error: reading variable 'use_p2pmem' requires holding mutex 'to_nvmet_ns(item).subsys->lock'
[-Werror,-Wthread-safety-analysis]
587 | return pci_p2pdma_enable_show(page, ns->p2p_dev, ns->use_p2pmem);
| ^
Fix the above errors by acquiring ns->subsys->lock before accessing
PCI P2P parameters in nvmet_ns_p2pmem_show().
Signed-off-by: Nilay Shroff <nilay at linux.ibm.com>
---
drivers/nvme/target/configfs.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index a87917381093..7245db64b8dc 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -582,8 +582,13 @@ CONFIGFS_ATTR(nvmet_ns_, device_path);
static ssize_t nvmet_ns_p2pmem_show(struct config_item *item, char *page)
{
struct nvmet_ns *ns = to_nvmet_ns(item);
+ ssize_t ret;
- return pci_p2pdma_enable_show(page, ns->p2p_dev, ns->use_p2pmem);
+ mutex_lock(&ns->subsys->lock);
+ ret = pci_p2pdma_enable_show(page, ns->p2p_dev, ns->use_p2pmem);
+ mutex_unlock(&ns->subsys->lock);
+
+ return ret;
}
static ssize_t nvmet_ns_p2pmem_store(struct config_item *item,
--
2.53.0
More information about the Linux-nvme
mailing list