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@lst.de>,
Damien Le Moal <dlemoal@kernel.org>, Tejun Heo <tj@kernel.org>,
Keith Busch <kbusch@kernel.org>,
Chaitanya Kulkarni <kch@nvidia.com>,
Johannes Thumshirn <johannes.thumshirn@wdc.com>,
Kees Cook <kees@kernel.org>,
Genjian Zhang <zhanggenjian@kylinos.cn>,
Marco Elver <elver@google.com>
Subject: Re: [PATCH v2 20/26] null_blk: Enable lock context analysis
Date: Wed, 1 Apr 2026 15:24:13 +0530 [thread overview]
Message-ID: <25eea754-304c-4693-a2aa-0df47f1d1e0d@linux.ibm.com> (raw)
In-Reply-To: <b2160b6a-8857-4496-9453-2fcf394e9e4d@acm.org>
On 4/1/26 1:32 AM, Bart Van Assche wrote:
>
> On 3/30/26 10:37 PM, Nilay Shroff wrote:
>> On 3/30/26 9:55 PM, Bart Van Assche wrote:
>>> (+Marco)
>>>
>>> On 3/30/26 3:23 AM, Nilay Shroff wrote:
>>>> On 3/26/26 3:15 AM, Bart Van Assche wrote:
>>>>> diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/ main.c
>>>>> index f8c0fd57e041..677ac829ef80 100644
>>>>> --- a/drivers/block/null_blk/main.c
>>>>> +++ b/drivers/block/null_blk/main.c
>>>>> @@ -1004,8 +1004,7 @@ static struct nullb_page *null_lookup_page(struct nullb *nullb,
>>>>> static struct nullb_page *null_insert_page(struct nullb *nullb,
>>>>> sector_t sector, bool ignore_cache)
>>>>> - __releases(&nullb->lock)
>>>>> - __acquires(&nullb->lock)
>>>>> + __must_hold(&nullb->lock)
>>>>
>>>> This function temporarily drops the &nullb->lock and requires it.
>>>> So why do we need to replace __releases/__acquires with __must_hold?
>>>> This is not clear.
>>>
>>> __must_hold() has the same meaning as __releases() + __acquires(). The
>>> only difference between these two annotations is that __must_hold() is
>>> more compact. I can leave out this change if this change is considered
>>> confusing.
>>>
>> Hmm, but per the documentation of __must_hold() it seems that this attribute signifies the caller of the function must hold the exclusive context lock. On contrary, __releases() attribute is meant to be used when function releases a context lock exclusively and __acquires() should be used when function acquires context lock exclusively. From the above rational, it seems that
>> null_insert_page() should have all the above three attributes
>> applicable, isn't it?
>
> __must_hold() is defined as __attribute__((requires_capability(...)))
> In the Clang documentation this capability is called REQUIRES(). From
> https://clang.llvm.org/docs/ThreadSafetyAnalysis.html: "REQUIRES is an attribute on functions, methods or function parameters of reference to
> SCOPED_CAPABILITY-annotated type, which declares that the calling thread
> must have exclusive access to the given capabilities. More than one
> capability may be specified. The capabilities must be held on entry to
> the function, and must still be held on exit."
>
> To me the above text means that the __must_hold() annotation is sufficient.
>
Okay, that makes sense — using only __must_hold() is reasonable.
That said, since this function temporarily releases and then re-acquires
the lock, it may not be entirely redundant to also annotate it with
__releases() and __acquires(). Those annotations more explicitly describe
the lock transitions happening within the function body.
Still, I’m fine with keeping just __must_hold() if we prefer a more concise
annotation.
>> I am not sure why did compiler generate the above errors? If I look at the
>> macro definition then it seems __context_unsafe(/* comment */) should simply
>> expand to __no_context_analysis.
>>
>> // From include/linux/compiler-context-analysis.h:
>>
>> #define __context_unsafe(comment) __no_context_analysis
>
> I misread your previous comment. The output I shared is produced when the function body is surrounded with context_unsafe() (no leading
> underscores). Your request was to annotate the function with
> __context_unsafe() (with two leading underscores).
>
> I will consider to use __context_unsafe() instead of __no_context_analysis and a comment.
>
Thanks,
--Nilay
next prev parent reply other threads:[~2026-04-01 9:54 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-25 21:44 [PATCH v2 00/26] Enable lock context analysis Bart Van Assche
2026-03-25 21:44 ` [PATCH v2 01/26] block: Annotate the queue limits functions Bart Van Assche
2026-03-26 6:23 ` Christoph Hellwig
2026-03-25 21:44 ` [PATCH v2 02/26] block: Annotate the block device functions Bart Van Assche
2026-03-26 6:25 ` Christoph Hellwig
2026-03-26 15:55 ` Bart Van Assche
2026-03-27 18:17 ` Marco Elver
2026-03-27 18:27 ` Bart Van Assche
2026-03-30 12:33 ` Marco Elver
2026-03-25 21:44 ` [PATCH v2 03/26] block/cgroup: Split blkg_conf_prep() Bart Van Assche
2026-03-26 6:25 ` Christoph Hellwig
2026-03-25 21:44 ` [PATCH v2 04/26] block/cgroup: Split blkg_conf_exit() Bart Van Assche
2026-03-26 6:26 ` Christoph Hellwig
2026-03-25 21:44 ` [PATCH v2 05/26] block/cgroup: Modify the blkg_conf_open_bdev_frozen() calling convention Bart Van Assche
2026-03-26 6:28 ` Christoph Hellwig
2026-03-25 21:44 ` [PATCH v2 06/26] block/crypto: Annotate the crypto functions Bart Van Assche
2026-03-26 6:28 ` Christoph Hellwig
2026-03-25 21:44 ` [PATCH v2 07/26] block/blk-iocost: Add lock context annotations Bart Van Assche
2026-03-26 6:31 ` Christoph Hellwig
2026-04-01 17:01 ` Bart Van Assche
2026-03-25 21:44 ` [PATCH v2 08/26] block/blk-mq-debugfs: Improve " Bart Van Assche
2026-03-26 6:32 ` Christoph Hellwig
2026-04-01 17:04 ` Bart Van Assche
2026-03-25 21:44 ` [PATCH v2 09/26] block/blk-zoned: Add " Bart Van Assche
2026-03-26 6:42 ` Christoph Hellwig
2026-03-25 21:44 ` [PATCH v2 10/26] block/ioctl: " Bart Van Assche
2026-03-26 6:39 ` Christoph Hellwig
2026-03-25 21:44 ` [PATCH v2 11/26] block/Kyber: Make the lock context annotations compatible with Clang Bart Van Assche
2026-03-26 6:40 ` Christoph Hellwig
2026-03-25 21:44 ` [PATCH v2 12/26] block/mq-deadline: " Bart Van Assche
2026-03-25 21:44 ` [PATCH v2 13/26] block: Enable lock context analysis Bart Van Assche
2026-03-25 21:44 ` [PATCH v2 14/26] aoe: Add a lock context annotation Bart Van Assche
2026-03-26 14:13 ` Christoph Hellwig
2026-03-25 21:44 ` [PATCH v2 15/26] drbd: Balance RCU calls in drbd_adm_dump_devices() Bart Van Assche
2026-03-26 14:14 ` Christoph Hellwig
2026-03-25 21:44 ` [PATCH v2 16/26] drbd: Make the lock context annotations compatible with Clang Bart Van Assche
2026-03-26 14:18 ` Christoph Hellwig
2026-03-25 21:44 ` [PATCH v2 17/26] loop: Add lock context annotations Bart Van Assche
2026-03-26 14:18 ` Christoph Hellwig
2026-03-25 21:44 ` [PATCH v2 18/26] mtip32: Enable lock context analysis Bart Van Assche
2026-03-26 14:18 ` Christoph Hellwig
2026-03-25 21:45 ` [PATCH v2 19/26] nbd: " Bart Van Assche
2026-03-26 14:18 ` Christoph Hellwig
2026-03-25 21:45 ` [PATCH v2 20/26] null_blk: " Bart Van Assche
2026-03-26 14:19 ` Christoph Hellwig
2026-03-30 10:23 ` Nilay Shroff
2026-03-30 16:25 ` Bart Van Assche
2026-03-31 5:37 ` Nilay Shroff
2026-03-31 20:02 ` Bart Van Assche
2026-04-01 9:54 ` Nilay Shroff [this message]
2026-03-25 21:45 ` [PATCH v2 21/26] rbd: " Bart Van Assche
2026-03-25 21:45 ` [PATCH v2 22/26] ublk: " Bart Van Assche
2026-03-25 21:45 ` [PATCH v2 23/26] xen-blkback: " Bart Van Assche
2026-03-26 9:25 ` Roger Pau Monné
2026-03-25 21:45 ` [PATCH v2 24/26] zram: " Bart Van Assche
2026-03-25 21:45 ` [PATCH v2 25/26] rnbd: " Bart Van Assche
2026-03-26 6:58 ` Jinpu Wang
2026-03-25 21:45 ` [PATCH v2 26/26] block: Enable lock context analysis for all block drivers Bart Van Assche
2026-03-26 6:23 ` [PATCH v2 00/26] Enable lock context analysis Christoph Hellwig
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=25eea754-304c-4693-a2aa-0df47f1d1e0d@linux.ibm.com \
--to=nilay@linux.ibm.com \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--cc=dlemoal@kernel.org \
--cc=elver@google.com \
--cc=hch@lst.de \
--cc=johannes.thumshirn@wdc.com \
--cc=kbusch@kernel.org \
--cc=kch@nvidia.com \
--cc=kees@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=tj@kernel.org \
--cc=zhanggenjian@kylinos.cn \
/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