Skip to content

nvmet: add context annotation for params in struct nvmet_ns

Nilay Shroff linux-nvme 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest22 patches 7 repliesIn review
  2. v123 patches 16 repliesSuperseded

Changes in v2 from the cover letter

- Dropped patches #6/23 and #7/23, which annotated ns->nsid with __guarded_by(&ns->subsys->lock). Since ns->nsid is immutable during the lifetime of a namespace, it does not require additional protection (Bart Van Assche)
- Since the Clang context analyzer cannot infer that the same lock is

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/22nvmet: add context annotation for nvmet_ns::bdevdrivers/nvme/target/admin-cmd.c drivers/nvme/target/core.c drivers/nvme/target/io-cmd-bdev.c +3 more+163 -1215 replies
2/22nvmet: fix nvmet_ns::bdev access using nvmet_subsys::lockdrivers/nvme/target/admin-cmd.c+15 -12 replies
3/22nvmet: add context annotation for nvmet_ns::filedrivers/nvme/target/admin-cmd.c drivers/nvme/target/core.c drivers/nvme/target/io-cmd-file.c +1 more+24 -170 replies
4/22nvmet: add context annotation for nvmet_ns::bdev_filedrivers/nvme/target/nvmet.h+2 -10 replies
5/22nvmet: add context annotation for nvmet_ns::readonlydrivers/nvme/target/admin-cmd.c drivers/nvme/target/core.c drivers/nvme/target/nvmet.h+25 -100 replies
6/22nvmet: add context annotation for nvmet_ns::blksize_shiftdrivers/nvme/target/admin-cmd.c drivers/nvme/target/io-cmd-bdev.c drivers/nvme/target/io-cmd-file.c +2 more+15 -120 replies
7/22nvmet: add context annotation for nvmet_ns::sizedrivers/nvme/target/admin-cmd.c drivers/nvme/target/core.c drivers/nvme/target/io-cmd-bdev.c +2 more+13 -90 replies
8/22nvmet: add context annotation for nvmet_ns::nguiddrivers/nvme/target/admin-cmd.c drivers/nvme/target/configfs.c drivers/nvme/target/nvmet.h+15 -50 replies
9/22nvmet: add context annotation for nvmet_ns::uuiddrivers/nvme/target/admin-cmd.c drivers/nvme/target/configfs.c drivers/nvme/target/nvmet.h+15 -40 replies
10/22nvmet: fix nvmet_ns::uuid access using nvmet_subsys::lockdrivers/nvme/target/configfs.c drivers/nvme/target/core.c drivers/nvme/target/nvmet.h+33 -190 replies
11/22nvmet: add context annotation for nvmet_ns::buffered_iodrivers/nvme/target/io-cmd-file.c drivers/nvme/target/nvmet.h+4 -20 replies
12/22nvmet: fix nvmet_ns::buffered_io access using nvmet_subsys::lockdrivers/nvme/target/configfs.c+8 -10 replies
13/22nvmet: add context annotation for nvmet_ns::enableddrivers/nvme/target/nvmet.h+2 -10 replies
14/22nvmet: fix nvmet_ns::enable access using nvmet_subsys::lockdrivers/nvme/target/configfs.c+8 -10 replies
15/22nvmet: add context annotation for nvmet_ns::device_pathdrivers/nvme/target/nvmet.h drivers/nvme/target/trace.h+4 -20 replies
16/22nvmet: fix nvmet_ns::device_path access using nvmet_subsys::lockdrivers/nvme/target/configfs.c drivers/nvme/target/core.c+9 -20 replies
17/22nvmet: add context annotation for PCI P2P parameters in struct nvmet_nsdrivers/nvme/target/nvmet.h+4 -20 replies
18/22nvmet: fix PCI P2P parameters access using nvmet_subsys::lockdrivers/nvme/target/configfs.c+6 -10 replies
19/22nvmet: add context annotation for integrity params in struct nvmet_nsdrivers/nvme/target/admin-cmd.c drivers/nvme/target/nvmet.h drivers/nvme/target/rdma.c+12 -70 replies
20/22nvmet: add context annotation for nvmet_ns::csidrivers/nvme/target/admin-cmd.c drivers/nvme/target/core.c drivers/nvme/target/nvmet.h+7 -30 replies
21/22nvmet: fix nvmet_ns::csi access using nvmet_subsys::lockdrivers/nvme/target/admin-cmd.c+16 -50 replies
22/22nvmet: add context annotation for nvmet_ns::debugfs_dirdrivers/nvme/target/debugfs.h drivers/nvme/target/nvmet.h+6 -30 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 00/22] nvmet: add context annotation for params in struct nvmet_ns

Hi,

This series adds Clang context annotations to fields in struct nvmet_ns that are protected by nvmet_subsys::lock.

The goal is to incrementally introduce context annotations throughout the NVMe target code. Covering the entire nvmet subsystem in a single series would result in a very large patchset with dozens of patches, making focused review difficult. To keep the changes manageable, I have split the work into multiple series, each focusing on a specific subset of context annotations.

This series focuses on fields in struct nvmet_ns protected by nvmet_subsys::lock. Subsequent series will expand the scope to other structures and locks.

The patches are organized so that each field is handled incrementally:
first, a field is annotated with __guarded_by(&subsys->lock), and then any access violations reported by the Clang context analyzer are addressed in follow-up patches. Not every field annotation necessarily triggers analyzer warnings. In such cases, the series simply moves on to the next field.

This approach keeps individual patches focused and makes it easier to review the annotations and the corresponding locking changes independently.

As always, review feedback, comments, and suggestions are very welcome!

Changes from v1:
- Dropped patches #6/23 and #7/23, which annotated ns->nsid with __guarded_by(&ns->subsys->lock). Since ns->nsid is immutable during the lifetime of a namespace, it does not require additional protection (Bart Van Assche)
- Since the Clang context analyzer cannot infer that the same lock is

    being accessed through different expressions (e.g., subsys->lock and
    ns->subsys->lock), pass subsys as an additional argument through the
    relevant function call chains and use lockdep_assert_held(&ns->subsys->lock)
    instead of __assume_ctx_lock() wherever possible (Bart Van Assche).

Link to v1: https://lore.kernel.org/all/[email protected]/

Nilay Shroff (22):
nvmet: add context annotation for nvmet_ns::bdev
nvmet: fix nvmet_ns::bdev access using nvmet_subsys::lock
nvmet: add context annotation for nvmet_ns::file
nvmet: add context annotation for nvmet_ns::bdev_file
nvmet: add context annotation for nvmet_ns::readonly
nvmet: add context annotation for nvmet_ns::blksize_shift
nvmet: add context annotation for nvmet_ns::size
nvmet: add context annotation for nvmet_ns::nguid
nvmet: add context annotation for nvmet_ns::uuid
nvmet: fix nvmet_ns::uuid access using nvmet_subsys::lock
nvmet: add context annotation for nvmet_ns::buffered_io
nvmet: fix nvmet_ns::buffered_io access using nvmet_subsys::lock
nvmet: add context annotation for nvmet_ns::enabled
nvmet: fix nvmet_ns::enable access using nvmet_subsys::lock
nvmet: add context annotation for nvmet_ns::device_path
nvmet: fix nvmet_ns::device_path access using nvmet_subsys::lock
nvmet: add context annotation for PCI P2P parameters in struct
nvmet_ns
nvmet: fix PCI P2P parameters access using nvmet_subsys::lock
nvmet: add context annotation for integrity params in struct nvmet_ns
nvmet: add context annotation for nvmet_ns::csi
nvmet: fix nvmet_ns::csi access using nvmet_subsys::lock
nvmet: add context annotation for nvmet_ns::debugfs_dir

 drivers/nvme/target/admin-cmd.c   | 135 ++++++++++-------
 drivers/nvme/target/configfs.c    |  54 ++++++-
 drivers/nvme/target/core.c        |  88 +++++++----
 drivers/nvme/target/debugfs.h     |   6 +-
 drivers/nvme/target/io-cmd-bdev.c |  30 ++--
 drivers/nvme/target/io-cmd-file.c |  35 +++--
 drivers/nvme/target/nvmet.h       | 233 +++++++++++++++++++-----------
 drivers/nvme/target/rdma.c        |   4 +-
 drivers/nvme/target/trace.h       |   2 +-
 drivers/nvme/target/zns.c         |  46 +++---
 10 files changed, 405 insertions(+), 228 deletions(-)

base-commit: 68099cf27253a8c89d703a282d3d811446d9453b

Signature · 1 line
2.53.0