[PATCH 17/23] nvmet: add context annotation for nvmet_ns::device_path
Nilay Shroff
nilay at linux.ibm.com
Sun Nov 8 19:28:22 PST 2026
The nvmet_ns::device_path field is protected by
nvmet_subsys::lock. Annotate it with
__guarded_by(&subsys->lock) to allow the Clang context
analyzer to validate accesses to this field.
Some request-processing paths access ns->device_path without
holding subsys->lock. This is safe because the namespace
reference held by the request prevents the ns->device_path from
being modified while I/O is in flight. However, the context
analyzer cannot express this access pattern directly.
Introduce nvmet_ns_device_path() as an inline helper
annotated with __context_unsafe() to allow these lockless
accesses without triggering context analyzer warnings.
Additionally, update __assign_req_name() to use this accessor
when copying device_path into the trace event's request name.
This is safe because the tracing function is invoked after
the namespace reference has been acquired.
Signed-off-by: Nilay Shroff <nilay at linux.ibm.com>
---
drivers/nvme/target/nvmet.h | 4 +++-
drivers/nvme/target/trace.h | 2 +-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index a6fb3aab0c5d..fa932c1fbf29 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -176,7 +176,8 @@ struct nvmet_ns {
#define NVMET_NS_IO_LIVE 0
unsigned long flags;
struct nvmet_subsys *subsys;
- const char *device_path;
+ const char *device_path
+ __guarded_by(&subsys->lock);
struct config_group device_group;
struct config_group group;
@@ -217,6 +218,7 @@ NVMET_NS_ACCESSOR(u32, blksize_shift)
NVMET_NS_ACCESSOR(u8 *, nguid)
NVMET_NS_ACCESSOR(uuid_t, uuid)
NVMET_NS_ACCESSOR(bool, buffered_io)
+NVMET_NS_ACCESSOR(const char *, device_path)
/*
* These accessors use data_race() and READ_ONCE() to allow lockless access to
diff --git a/drivers/nvme/target/trace.h b/drivers/nvme/target/trace.h
index 7f7ebf9558e5..b15294e24793 100644
--- a/drivers/nvme/target/trace.h
+++ b/drivers/nvme/target/trace.h
@@ -59,7 +59,7 @@ static inline void __assign_req_name(char *name, struct nvmet_req *req)
return;
}
- strscpy_pad(name, req->ns->device_path, DISK_NAME_LEN);
+ strscpy_pad(name, nvmet_ns_device_path(req->ns), DISK_NAME_LEN);
}
#endif
--
2.53.0
More information about the Linux-nvme
mailing list