[PATCH v2 22/26] ublk: Enable lock context analysis

Bart Van Assche
2026-03-25T21:46:36Z

Add the lock context annotations that are required by Clang and enable
lock context analysis.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/block/ublk_drv.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 3ba7da94d314..14b59e13b16f 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -353,11 +353,13 @@ static inline bool ublk_support_batch_io(const struct ublk_queue *ubq)
}

static inline void ublk_io_lock(struct ublk_io *io)
+ __acquires(&io->lock)
{
spin_lock(&io->lock);
}

static inline void ublk_io_unlock(struct ublk_io *io)
+ __releases(&io->lock)
{
spin_unlock(&io->lock);
}
@@ -3166,6 +3168,7 @@ static int ublk_check_fetch_buf(const struct ublk_device *ub, __u64 buf_addr)

static int __ublk_fetch(struct io_uring_cmd *cmd, struct ublk_device *ub,
struct ublk_io *io, u16 q_id)
+ __must_hold(&ub->mutex)
{
/* UBLK_IO_FETCH_REQ is only allowed before dev is setup */
if (ublk_dev_ready(ub))
@@ -3587,6 +3590,7 @@ static void ublk_batch_revert_prep_cmd(struct ublk_batch_io_iter *iter,
static int ublk_batch_prep_io(struct ublk_queue *ubq,
const struct ublk_batch_io_data *data,
const struct ublk_elem_header *elem)
+ __must_hold(&data->ub->mutex)
{
struct ublk_io *io = &ubq->ios[elem->tag];
const struct ublk_batch_io *uc = &data->header;