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: Tue, 4 Aug 2026 13:10:23 +0530 [thread overview]
Message-ID: <2db07e75-0e92-438f-89e7-85189a017a62@linux.ibm.com> (raw)
In-Reply-To: <4fdcc4f4-819c-4878-96ee-9493ce4c5886@acm.org>
On 8/3/26 11:39 PM, Bart Van Assche wrote:
>
> On 8/3/26 6:35 AM, Nilay Shroff wrote:
>> On 7/31/26 1:28 AM, Bart Van Assche wrote:
>>> +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?
>
> What we gain is that __context_unsafe() annotations are avoided
> entirely. __context_unsafe() is a big hammer that shouldn't be used
> unless absolutely necessary. Additionally, introducing this class makes
> it possible to convert multiple goto statements into return statements.
> I think that's a significant improvement.
>
That's a fair statement.
>> Since both the constructor and destructor are marked
>> __context_unsafe, the lock context analysis still
>> won't reason about the conditional locking.
>
> Such reasoning is not needed when using guard() or scoped_guard() since
> these macro's make it impossible to leave a scope without releasing the
> acquired synchronization object.
>
Okay got it.
>> I'm not opposed to using a guard class here, but it does make the
>> code a bit more complex to follow.
>
> Hmm ... I think this means that you are not familiar yet with
> DEFINE_CLASS(). The code that uses the null_zone class becomes simpler.
>
Yes, I may just need to get more familiar with DEFINE_CLASS() :-)
Regarding the proposed null_zone class implementation, could we at least
move the constructor and destructor logic into separate helper functions
instead of embedding it directly in the DEFINE_CLASS() arguments?
I understand that DEFINE_CLASS() supports statement expressions for these
arguments, but with the conditional spinlock/mutex handling here, I find
separate helpers easier to read and follow. For example, the class definition
itself would then remain fairly compact while the locking logic is kept in
regular functions. What do you think?
Thanks,
--Nilay
next prev parent reply other threads:[~2026-08-04 7:40 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
2026-08-03 18:09 ` Bart Van Assche
2026-08-04 7:40 ` Nilay Shroff [this message]
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=2db07e75-0e92-438f-89e7-85189a017a62@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