All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nilay Shroff <nilay@linux.ibm.com>
To: kbusch@kernel.org, hch@lst.de, bvanassche@acm.org,
	sagi@grimberg.me, axboe@kernel.dk, chaitanyak@nvidia.com
Cc: gjoyce@linux.ibm.com, elver@google.com,
	linux-nvme@lists.infradead.org,
	Nilay Shroff <nilay@linux.ibm.com>
Subject: [PATCH v2 19/22] nvmet: add context annotation for integrity params in struct nvmet_ns
Date: Wed, 18 Nov 2026 13:05:00 +0530	[thread overview]
Message-ID: <20261118073505.288910-20-nilay@linux.ibm.com> (raw)
In-Reply-To: <20261118073505.288910-1-nilay@linux.ibm.com>

The nvmet_ns::pi_type and nvmet_ns::metadata_size fields are protected
by nvmet_subsys::lock. Annotate them with __guarded_by(&subsys->lock)
to allow the Clang context analyzer to validate accesses to these fields.

Some request-processing and I/O paths access these fields without
holding subsys->lock. This is safe because the namespace reference held
by the request prevents the integrity parameters from being modified
while I/O is in flight. However, the context analyzer cannot express
this access pattern directly.

Introduce nvmet_ns_pi_type() and nvmet_ns_metadata_size() as inline
helpers annotated with __context_unsafe() to allow these lockless
accesses without triggering context analyzer warnings.

Use these helpers in the namespace identify path, metadata length
calculation, PI capability check, and RDMA signature attribute setup.

Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
---
 drivers/nvme/target/admin-cmd.c |  4 ++--
 drivers/nvme/target/nvmet.h     | 13 +++++++++----
 drivers/nvme/target/rdma.c      |  2 +-
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
index 75a833253545..ea43d83d269b 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -939,9 +939,9 @@ static void nvmet_execute_identify_ns(struct nvmet_req *req)
 			  NVME_NS_DPC_PI_TYPE1 | NVME_NS_DPC_PI_TYPE2 |
 			  NVME_NS_DPC_PI_TYPE3;
 		id->mc = NVME_MC_EXTENDED_LBA;
-		id->dps = req->ns->pi_type;
+		id->dps = nvmet_ns_pi_type(req->ns);
 		id->flbas = NVME_NS_FLBAS_META_EXT;
-		id->lbaf[0].ms = cpu_to_le16(req->ns->metadata_size);
+		id->lbaf[0].ms = cpu_to_le16(nvmet_ns_metadata_size(req->ns));
 	}
 
 	if (nvmet_ns_readonly(req->ns))
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 08cf6364c4a6..1da9cfacfc4c 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -188,8 +188,10 @@ struct nvmet_ns {
 		__guarded_by(&subsys->lock);
 	int			use_p2pmem
 		__guarded_by(&subsys->lock);
-	int			pi_type;
-	int			metadata_size;
+	int			pi_type
+		__guarded_by(&subsys->lock);
+	int			metadata_size
+		__guarded_by(&subsys->lock);
 	u8			csi;
 	struct nvmet_pr		pr;
 	struct xarray		pr_per_ctrl_refs;
@@ -219,6 +221,8 @@ NVMET_NS_ACCESSOR(u8 *, nguid)
 NVMET_NS_ACCESSOR(uuid_t, uuid)
 NVMET_NS_ACCESSOR(bool, buffered_io)
 NVMET_NS_ACCESSOR(const char *, device_path)
+NVMET_NS_ACCESSOR(int, pi_type)
+NVMET_NS_ACCESSOR(int, metadata_size)
 
 /*
  * These accessors use data_race() and READ_ONCE() marker to allow lockless
@@ -830,7 +834,7 @@ static inline u32 nvmet_rw_metadata_len(struct nvmet_req *req)
 	if (!IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY))
 		return 0;
 	return ((u32)le16_to_cpu(req->cmd->rw.length) + 1) *
-			req->ns->metadata_size;
+			nvmet_ns_metadata_size(req->ns);
 }
 
 static inline u32 nvmet_dsm_len(struct nvmet_req *req)
@@ -1010,7 +1014,8 @@ static inline bool nvmet_ns_has_pi(struct nvmet_ns *ns)
 {
 	if (!IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY))
 		return false;
-	return ns->pi_type && ns->metadata_size == sizeof(struct t10_pi_tuple);
+	return nvmet_ns_pi_type(ns) &&
+	       nvmet_ns_metadata_size(ns) == sizeof(struct t10_pi_tuple);
 }
 
 static inline __le64 nvmet_sect_to_lba(struct nvmet_ns *ns, sector_t sect)
diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c
index 0b351d39340c..2cec457f12fd 100644
--- a/drivers/nvme/target/rdma.c
+++ b/drivers/nvme/target/rdma.c
@@ -591,7 +591,7 @@ static void nvmet_rdma_set_sig_attrs(struct nvmet_req *req,
 {
 	struct nvme_command *cmd = req->cmd;
 	u16 control = le16_to_cpu(cmd->rw.control);
-	u8 pi_type = req->ns->pi_type;
+	u8 pi_type = nvmet_ns_pi_type(req->ns);
 	struct blk_integrity *bi;
 
 	bi = bdev_get_integrity(nvmet_ns_bdev(req->ns));
-- 
2.53.0



  parent reply	other threads:[~2026-11-18  7:38 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  7:34 [PATCH v2 00/22] nvmet: add context annotation for params in struct nvmet_ns Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 01/22] nvmet: add context annotation for nvmet_ns::bdev Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 02/22] nvmet: fix nvmet_ns::bdev access using nvmet_subsys::lock Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 03/22] nvmet: add context annotation for nvmet_ns::file Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 04/22] nvmet: add context annotation for nvmet_ns::bdev_file Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 05/22] nvmet: add context annotation for nvmet_ns::readonly Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 06/22] nvmet: add context annotation for nvmet_ns::blksize_shift Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 07/22] nvmet: add context annotation for nvmet_ns::size Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 09/22] nvmet: add context annotation for nvmet_ns::uuid Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 10/22] nvmet: fix nvmet_ns::uuid access using nvmet_subsys::lock Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 11/22] nvmet: add context annotation for nvmet_ns::buffered_io Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 12/22] nvmet: fix nvmet_ns::buffered_io access using nvmet_subsys::lock Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 13/22] nvmet: add context annotation for nvmet_ns::enabled Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 14/22] nvmet: fix nvmet_ns::enable access using nvmet_subsys::lock Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 15/22] nvmet: add context annotation for nvmet_ns::device_path Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 16/22] nvmet: fix nvmet_ns::device_path access using nvmet_subsys::lock Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 17/22] nvmet: add context annotation for PCI P2P parameters in struct nvmet_ns Nilay Shroff
2026-11-18  7:35 ` Nilay Shroff [this message]
2026-11-18  7:35 ` [PATCH v2 20/22] nvmet: add context annotation for nvmet_ns::csi Nilay Shroff
2026-11-18  7:35 ` [PATCH v2 21/22] nvmet: fix nvmet_ns::csi access using nvmet_subsys::lock Nilay Shroff
2026-11-18  7:35 ` [PATCH v2 22/22] nvmet: add context annotation for nvmet_ns::debugfs_dir Nilay Shroff

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261118073505.288910-20-nilay@linux.ibm.com \
    --to=nilay@linux.ibm.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=chaitanyak@nvidia.com \
    --cc=elver@google.com \
    --cc=gjoyce@linux.ibm.com \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.