Re: [PATCH v2 07/12] rbd: Enable lock context analysis
Nilay Shroff <[email protected]> Mon, 3 Aug 2026 19:33:56 +0530
| Newsgroups | org.kernel.vger.linux-block |
|---|---|
| Message-ID | <[email protected]> |
On 7/31/26 1:28 AM, Bart Van Assche wrote: > Add lock context annotations. > > Signed-off-by: Bart Van Assche <[email protected]> > --- > drivers/block/rbd.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c > index 1f1c2810f6ee..f0f7a94e3e3e 100644 > --- a/drivers/block/rbd.c > +++ b/drivers/block/rbd.c > @@ -4183,6 +4183,7 @@ static void rbd_acquire_lock(struct work_struct *work) > } > > static bool rbd_quiesce_lock(struct rbd_device *rbd_dev) > + __must_hold(&rbd_dev->lock_rwsem) > { > dout("%s rbd_dev %p\n", __func__, rbd_dev); > lockdep_assert_held_write(&rbd_dev->lock_rwsem); > @@ -4227,6 +4228,7 @@ static void __rbd_release_lock(struct rbd_device *rbd_dev) > * lock_rwsem must be held for write > */ > static void rbd_release_lock(struct rbd_device *rbd_dev) > + __must_hold(&rbd_dev->lock_rwsem) > { > if (!rbd_quiesce_lock(rbd_dev)) > return; > @@ -4583,6 +4585,7 @@ static void rbd_unregister_watch(struct rbd_device *rbd_dev) > * lock_rwsem must be held for write > */ > static void rbd_reacquire_lock(struct rbd_device *rbd_dev) > + __must_hold(&rbd_dev->lock_rwsem) > { > struct ceph_osd_client *osdc = &rbd_dev->rbd_client->client->osdc; > char cookie[32]; > @@ -6780,6 +6783,7 @@ static void rbd_dev_device_release(struct rbd_device *rbd_dev) > * upon return. > */ > static int rbd_dev_device_setup(struct rbd_device *rbd_dev) > + __releases(&rbd_dev->header_rwsem) > { > int ret; > > @@ -6881,6 +6885,7 @@ static void rbd_dev_image_release(struct rbd_device *rbd_dev) > * with @depth == 0. > */ > static int rbd_dev_image_probe(struct rbd_device *rbd_dev, int depth) > + __context_unsafe(conditional locking on @depth) > { > bool need_watch = !rbd_is_ro(rbd_dev); > int ret; > @@ -7134,6 +7139,9 @@ static ssize_t do_rbd_add(const char *buf, size_t count) > if (rc < 0) > goto err_out_rbd_dev; > > + /* Acquired by rbd_dev_image_probe(rbd_dev, 0) */ > + __acquire(&rbd_dev->header_rwsem); > + > if (rbd_dev->opts->alloc_size > rbd_dev->layout.object_size) { > rbd_warn(rbd_dev, "alloc_size adjusted to %u", > rbd_dev->layout.object_size); In addition to the above annotations, it looks like several variables and structure members are consistently protected by specific locks: 1. rbd_dev_list is guarded by rbd_dev_list_lock. 2. rbd_client_list is guarded by rbd_client_list_lock. 3. rbd_device::acquiring_list and rbd_device::running_list are guarded by rbd_device::lock_lists_lock. 4. rbd_device::object_map is guarded by rbd_device::object_map_lock. 5. rbd_device::watch_cookie, rbd_device::watch_state, and rbd_device::watch_handle are guarded by rbd_device::watch_mutex. 6. rbd_device::lock_state and rbd_device::lock_cookie are guarded by rbd_device::lock_rwsem. So I think we should add the corresponding `__guarded_by(...)` annotations for these fields as part of enabling lock context analysis for this driver. Thanks, --Nilay