[PATCH 05/15] nvme: add Clang context annotations for nvme_ns_head::current_path

From: Nilay Shroff

Date: Wed Jun 10 2026 - 10:38:16 EST


Annotate nvme_ns_head::current_path[] with __rcu_guarded so that
Clang's context analysis can validate accesses to the SRCU/RCU
protected pointer.

The nvme_mpath_clear_current_path() helper only compares the
current_path[] pointer value using rcu_access_pointer() and does not
dereference the referenced namespace. Annotate this access with
context_unsafe() to suppress the corresponding context analysis
warning.

Signed-off-by: Nilay Shroff <nilay@xxxxxxxxxxxxx>
---
drivers/nvme/host/multipath.c | 10 +++++++++-
drivers/nvme/host/nvme.h | 2 +-
2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index 985a8c693c6f..ef072588eca0 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -231,8 +231,16 @@ bool nvme_mpath_clear_current_path(struct nvme_ns *ns)
bool changed = false;
int node;

+ /*
+ * This helper is used by namespace failover/teardown and I/O policy
+ * update paths. We only compare the head->current_path[] pointer value
+ * and do not dereference the referenced namespace, so suppress the
+ * context analysis warning for this lockless inspection of the
+ * __rcu_guarded pointer.
+ */
for_each_node(node) {
- if (ns == rcu_access_pointer(head->current_path[node])) {
+ if (context_unsafe(ns ==
+ rcu_access_pointer(head->current_path[node]))) {
rcu_assign_pointer(head->current_path[node], NULL);
changed = true;
}
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index f60852944709..41f42f1aee09 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -565,7 +565,7 @@ struct nvme_ns_head {
unsigned int delayed_removal_secs;
#define NVME_NSHEAD_DISK_LIVE 0
#define NVME_NSHEAD_QUEUE_IF_NO_PATH 1
- struct nvme_ns __rcu *current_path[];
+ struct nvme_ns __rcu_guarded *current_path[];
#endif
};

--
2.53.0