[PATCH 01/23] nvmet: add context annotation for nvmet_ns::bdev

Nilay Shroff nilay at linux.ibm.com
Thu Nov 12 01:04:19 PST 2026


On 11/11/26 11:30 PM, Bart Van Assche wrote:
> On 11/10/26 11:25 PM, Nilay Shroff wrote:
>> Attached the complete patch for your reference. Even after making
>> this change, clang still complains about locking violation:
>>
>> drivers/nvme/target/nvmet.h:255:13: error: reading variable 'bdev' requires holding mutex 'ns->subsys->lock' [-Werror,-Wthread-safety-precise]
>>    255 |         return ns->bdev ? disk_to_dev(ns->bdev->bd_disk) : NULL;
>>        |                    ^
>> drivers/nvme/target/nvmet.h:255:13: note: found near match 'subsys->lock'
> 
> This can be solved by adding a lockdep_assert_held(&ms->bdev->bd_disk)
> statement, isn't it?
> I think there's a typo above. I assume you're suggesting adding
lockdep_assert_held(&ns->subsys->lock) here.

And yes, adding the lockdep assertion resolves the compilation error.
As I see now (frankly I was not aware about this earlier), lockdep
internally assumes the required capability, which allows Clang's context
analyzer to satisfy the corresponding lock annotation.

So as you suggested, for complex call paths involving multiple locks,
where the same lock may be accessed through different expressions, I'll
use the appropriate lockdep_assert_held() assertions instead of explicitly
adding __assume_ctx_lock() annotations as far as possible.

Thanks,
--Nilay



More information about the Linux-nvme mailing list