[PATCH 13/23] nvmet: add context annotation for nvmet_ns::buffered_io
Nilay Shroff
nilay at linux.ibm.com
Sun Nov 8 19:28:18 PST 2026
The nvmet_ns::buffered_io field is protected by nvmet_subsys::lock.
Annotate it with __guarded_by(&subsys->lock) so that the clang context
analyzer can validate accesses to this field.
Some accesses to nvmet_ns::buffered_io in the I/O hotpath do not require
holding nvmet_subsys::lock, as the namespace reference guarantees that
the namespace remains valid and the field is not modified while I/O is
in flight. However, the clang context analyzer cannot express this
access pattern directly.
Introduce nvmet_ns_buffered_io() as an inline helper annotated with
__context_unsafe() to allow these accesses without requiring the
subsystem lock. Convert the relevant accesses in the I/O hotpath and
request-processing paths to use this helper.
Signed-off-by: Nilay Shroff <nilay at linux.ibm.com>
---
drivers/nvme/target/io-cmd-file.c | 2 +-
drivers/nvme/target/nvmet.h | 4 +++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c
index 224b7423b780..295203f10c2e 100644
--- a/drivers/nvme/target/io-cmd-file.c
+++ b/drivers/nvme/target/io-cmd-file.c
@@ -239,7 +239,7 @@ static void nvmet_file_execute_rw(struct nvmet_req *req)
} else
req->f.mpool_alloc = false;
- if (req->ns->buffered_io) {
+ if (nvmet_ns_buffered_io(req->ns)) {
if (likely(!req->f.mpool_alloc) &&
(nvmet_ns_file(req->ns)->f_mode & FMODE_NOWAIT) &&
nvmet_file_execute_io(req, IOCB_NOWAIT))
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 3e18c36e83c8..572f495b06df 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -169,7 +169,8 @@ struct nvmet_ns {
__guarded_by(&subsys->lock);
u32 anagrpid;
- bool buffered_io;
+ bool buffered_io
+ __guarded_by(&subsys->lock);
bool enabled;
#define NVMET_NS_IO_LIVE 0
unsigned long flags;
@@ -214,6 +215,7 @@ NVMET_NS_ACCESSOR(u32, nsid)
NVMET_NS_ACCESSOR(u32, blksize_shift)
NVMET_NS_ACCESSOR(u8 *, nguid)
NVMET_NS_ACCESSOR(uuid_t, uuid)
+NVMET_NS_ACCESSOR(bool, buffered_io)
/*
* These accessors use data_race() and READ_ONCE() to allow lockless access to
--
2.53.0
More information about the Linux-nvme
mailing list