From: Nilay Shroff <nilay@linux.ibm.com>
To: Bart Van Assche <bvanassche@acm.org>, Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org,
Christoph Hellwig <hch@infradead.org>,
Damien Le Moal <dlemoal@kernel.org>,
Marco Elver <elver@google.com>, Keith Busch <kbusch@kernel.org>,
Johannes Thumshirn <johannes.thumshirn@wdc.com>,
Chaitanya Kulkarni <kch@nvidia.com>,
Hans Holmberg <hans.holmberg@wdc.com>,
Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
Kees Cook <kees@kernel.org>
Subject: Re: [PATCH v2 06/12] null_blk: Enable lock context analysis
Date: Mon, 3 Aug 2026 19:05:56 +0530 [thread overview]
Message-ID: <42987b15-44e2-4a45-bbd8-b791bbb56b6c@linux.ibm.com> (raw)
In-Reply-To: <55886b395224068987cec253192ae6257e61c960.1785440858.git.bvanassche@acm.org>
On 7/31/26 1:28 AM, Bart Van Assche wrote:
> Add __must_hold() annotations where these are missing. Because
> null_lock_zone() and null_unlock_zone() use conditional locking, instead
> of annotating these functions, introduce guard class null_zone. Replace
> null_lock_zone() and null_unlock_zone() calls with scoped_guard(null_zone,
> ...). Enable lock context analysis in the Makefile.
>
> Signed-off-by: Bart Van Assche<bvanassche@acm.org>
> ---
> drivers/block/null_blk/Makefile | 2 +
> drivers/block/null_blk/main.c | 4 ++
> drivers/block/null_blk/zoned.c | 120 ++++++++++++++------------------
> 3 files changed, 57 insertions(+), 69 deletions(-)
>
> diff --git a/drivers/block/null_blk/Makefile b/drivers/block/null_blk/Makefile
> index 84c36e512ab8..282b0d51a477 100644
> --- a/drivers/block/null_blk/Makefile
> +++ b/drivers/block/null_blk/Makefile
> @@ -1,5 +1,7 @@
> # SPDX-License-Identifier: GPL-2.0
>
> +CONTEXT_ANALYSIS := y
> +
> # needed for trace events
> ccflags-y += -I$(src)
>
> diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
> index f8c0fd57e041..baffc6c61178 100644
> --- a/drivers/block/null_blk/main.c
> +++ b/drivers/block/null_blk/main.c
> @@ -1038,6 +1038,7 @@ static struct nullb_page *null_insert_page(struct nullb *nullb,
> }
>
> static int null_flush_cache_page(struct nullb *nullb, struct nullb_page *c_page)
> + __must_hold(&nullb->lock)
> {
> int i;
> unsigned int offset;
> @@ -1087,6 +1088,7 @@ static int null_flush_cache_page(struct nullb *nullb, struct nullb_page *c_page)
> }
>
> static int null_make_cache_space(struct nullb *nullb, unsigned long n)
> + __must_hold(&nullb->lock)
> {
> int i, err, nr_pages;
> struct nullb_page *c_pages[FREE_BATCH];
> @@ -1141,6 +1143,7 @@ static int null_make_cache_space(struct nullb *nullb, unsigned long n)
>
> static blk_status_t copy_to_nullb(struct nullb *nullb, void *source,
> loff_t pos, size_t n, bool is_fua)
> + __must_hold(&nullb->lock)
> {
> size_t temp, count = 0;
> struct nullb_page *t_page;
> @@ -1242,6 +1245,7 @@ static blk_status_t null_handle_flush(struct nullb *nullb)
> static blk_status_t null_transfer(struct nullb *nullb, struct page *page,
> unsigned int len, unsigned int off, bool is_write, loff_t pos,
> bool is_fua)
> + __must_hold(&nullb->lock)
> {
> struct nullb_device *dev = nullb->dev;
> blk_status_t err = BLK_STS_OK;
> diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c
> index 384bdce6a9b7..dbae748c90ba 100644
> --- a/drivers/block/null_blk/zoned.c
> +++ b/drivers/block/null_blk/zoned.c
> @@ -30,23 +30,26 @@ static inline void null_init_zone_lock(struct nullb_device *dev,
> mutex_init(&zone->mutex);
> }
>
> -static inline void null_lock_zone(struct nullb_device *dev,
> - struct nullb_zone *zone)
> -{
> - if (!dev->memory_backed)
> - spin_lock_irq(&zone->spinlock);
> - else
> - mutex_lock(&zone->mutex);
> -}
> -
> -static inline void null_unlock_zone(struct nullb_device *dev,
> - struct nullb_zone *zone)
> -{
> - if (!dev->memory_backed)
> - spin_unlock_irq(&zone->spinlock);
> - else
> - mutex_unlock(&zone->mutex);
> -}
> +struct nullb_dev_and_zone {
> + struct nullb_device *dev;
> + struct nullb_zone *zone;
> +};
> +
> +DEFINE_CLASS(null_zone, struct nullb_dev_and_zone, ({
> + if (!_T.dev->memory_backed)
> + spin_unlock_irq(&_T.zone->spinlock);
> + else
> + mutex_unlock(&_T.zone->mutex);
> + }), ({
> + if (!dev->memory_backed)
> + spin_lock_irq(&zone->spinlock);
> + else
> + mutex_lock(&zone->mutex);
> + (struct nullb_dev_and_zone){ dev, zone };
> + }),
> + struct nullb_device *dev, struct nullb_zone *zone)
> +
> +DEFINE_CLASS_IS_UNCONDITIONAL(null_zone)
What do we gain by introducing a guard class here? Since both the constructor
and destructor are marked __context_unsafe, the lock context analysis still
won't reason about the conditional locking.
In the previous series, we annotated null_lock_zone() and null_unlock_zone()
with __context_unsafe, and from that perspective the semantics seem unchanged
by introducing the guard class.
I'm not opposed to using a guard class here, but it does make the code a bit
more complex to follow. Unless there is a specific benefit (beyond using
scoped_guard()), I think the previous approach was simpler.
Thanks,
--Nilay
next prev parent reply other threads:[~2026-08-03 13:36 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-30 19:58 [PATCH v2 00/12] Enable lock context analysis in drivers/block/ Bart Van Assche
2026-07-30 19:58 ` [PATCH v2 01/12] aoe: Enable lock context analysis Bart Van Assche
2026-08-03 12:53 ` Nilay Shroff
2026-08-03 17:24 ` Bart Van Assche
2026-08-04 5:09 ` Nilay Shroff
2026-07-30 19:58 ` [PATCH v2 02/12] loop: Remove the "bool global" function argument Bart Van Assche
2026-08-03 13:05 ` Nilay Shroff
2026-08-03 17:41 ` Bart Van Assche
2026-08-04 6:53 ` Nilay Shroff
2026-07-30 19:58 ` [PATCH v2 03/12] loop: Add lock context annotations Bart Van Assche
2026-08-03 13:11 ` Nilay Shroff
2026-08-03 17:43 ` Bart Van Assche
2026-08-04 7:02 ` Nilay Shroff
2026-07-30 19:58 ` [PATCH v2 04/12] mtip32: Enable lock context analysis Bart Van Assche
2026-08-03 13:16 ` Nilay Shroff
2026-07-30 19:58 ` [PATCH v2 05/12] nbd: " Bart Van Assche
2026-08-03 13:26 ` Nilay Shroff
2026-08-03 18:03 ` Bart Van Assche
2026-08-04 7:10 ` Nilay Shroff
2026-08-04 9:25 ` Marco Elver
2026-08-04 11:27 ` Nilay Shroff
2026-07-30 19:58 ` [PATCH v2 06/12] null_blk: " Bart Van Assche
2026-08-03 13:35 ` Nilay Shroff [this message]
2026-08-03 18:09 ` Bart Van Assche
2026-08-04 7:40 ` Nilay Shroff
2026-07-30 19:58 ` [PATCH v2 07/12] rbd: " Bart Van Assche
2026-08-03 14:03 ` Nilay Shroff
2026-08-03 19:46 ` Bart Van Assche
2026-08-04 10:48 ` Nilay Shroff
2026-08-04 18:24 ` Bart Van Assche
2026-08-06 9:27 ` Marco Elver
2026-07-30 19:58 ` [PATCH v2 08/12] ublk: " Bart Van Assche
2026-07-30 19:58 ` [PATCH v2 09/12] xen-blkback: " Bart Van Assche
2026-07-30 19:58 ` [PATCH v2 10/12] zram: " Bart Van Assche
2026-07-30 19:58 ` [PATCH v2 11/12] rnbd: " Bart Van Assche
2026-07-30 19:58 ` [PATCH v2 12/12] block: Enable lock context analysis for all block drivers Bart Van Assche
2026-08-03 14:22 ` [PATCH v2 00/12] Enable lock context analysis in drivers/block/ Nilay Shroff
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=42987b15-44e2-4a45-bbd8-b791bbb56b6c@linux.ibm.com \
--to=nilay@linux.ibm.com \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--cc=christophe.jaillet@wanadoo.fr \
--cc=dlemoal@kernel.org \
--cc=elver@google.com \
--cc=hans.holmberg@wdc.com \
--cc=hch@infradead.org \
--cc=johannes.thumshirn@wdc.com \
--cc=kbusch@kernel.org \
--cc=kch@nvidia.com \
--cc=kees@kernel.org \
--cc=linux-block@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox