Re: [PATCH v4 16/20] nvme: add context annotations in rdma.c

From: Christoph Hellwig

Date: Wed Jul 22 2026 - 08:25:18 EST


On Mon, Jul 13, 2026 at 05:24:17PM +0530, Nilay Shroff wrote:
> device_list and nvme_rdma_device::entry are protected by
> device_list_mutex. Define device_list using
> LIST_HEAD_GUARDED(device_list, device_list_mutex) and annotate
> nvme_rdma_device::entry with __guarded_by(&device_list_mutex) so that
> Clang's context analysis can validate accesses against the corresponding
> locking requirements.
>
> Similarly, nvme_rdma_ctrl_list and nvme_rdma_ctrl::list are
> protected by nvme_rdma_ctrl_mutex. Define nvme_rdma_ctrl_list using
> LIST_HEAD_GUARDED(nvme_rdma_ctrl_list, nvme_rdma_ctrl_mutex) and
> annotate nvme_rdma_ctrl::list with __guarded_by(&nvme_rdma_ctrl_mutex).
>
> It is safe to initialize nvme_rdma_ctrl::list while allocating the
> controller object because the list entry has not yet been added to
> nvme_rdma_ctrl_list. Annotate the initialization with context_unsafe()
> to suppress the corresponding Clang context analysis warning.

I still wish the lock context handling in clang could just do the
right thing for fields initialized before the protecting lock,
so we would not need all this unsafe magic.

But to get things going for now:

Reviewed-by: Christoph Hellwig <hch@xxxxxx>