Re: [PATCH v3 02/12] block/bdev: Annotate the blk_holder_ops callback invocations

Bart Van Assche
2026-04-10T17:17:45Z

On 4/9/26 6:27 AM, Marco Elver wrote:
> On Thu, 9 Apr 2026 at 08:42, Christoph Hellwig <hch@lst.de> wrote:
>> On Thu, Apr 02, 2026 at 11:39:34AM -0700, Bart Van Assche wrote:
>>> The four callback functions in blk_holder_ops all release the
>>> bd_holder_lock. Add __release() annotations where appropriate to prepare
>>> for enabling thread-safety analysis. Explicit __release() annotations have
>>> been added since Clang does not support adding a __releases() annotation
>>> to a function pointer.
>>
>> I have to say I still hate this with passion. If we can't propagate
>> the lock context over function pointers it isn't ready for prime time
>> unfortunately, as much as I'm looking forward to it.
>
> Let's see if we can land this: https://github.com/llvm/llvm-project/pull/191187
>
> I think we'll be bumping min Clang version to 23 for context analysis,
> so hopefully it'll be included in Clang 23 and should solve the
> function pointer false positives.

That LLVM patch does not seem sufficient to address Christoph's concern.
If I apply that LLVM patch on my local LLVM tree, and if I apply the
following patch to the Linux kernel source tree:

diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index e354b771a8ad..81b8064b4612 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1741,22 +1741,26 @@ void blkdev_show(struct seq_file *seqf, off_t
offset);
#endif

struct blk_holder_ops {
- void (*mark_dead)(struct block_device *bdev, bool surprise);
+ void (*mark_dead)(struct block_device *bdev, bool surprise)
+ __releases(&bdev->bd_holder_lock);

/*
* Sync the file system mounted on the block device.
*/
- void (*sync)(struct block_device *bdev);
+ void (*sync)(struct block_device *bdev)
+ __releases(&bdev->bd_holder_lock);

/*
* Freeze the file system mounted on the block device.
*/
- int (*freeze)(struct block_device *bdev);
+ int (*freeze)(struct block_device *bdev)
+ __releases(&bdev->bd_holder_lock);

/*
* Thaw the file system mounted on the block device.
*/
- int (*thaw)(struct block_device *bdev);
+ int (*thaw)(struct block_device *bdev)
+ __releases(&bdev->bd_holder_lock);
};

/*

then the following errors appear while building the Linux kernel tree
with Clang:

In file included from block/blk-core.c:18:
./include/linux/blkdev.h:1745:15: error: use of undeclared identifier 'bdev'
1745 | __releases(&bdev->bd_holder_lock);
| ^~~~
./include/linux/blkdev.h:1751:15: error: use of undeclared identifier 'bdev'
1751 | __releases(&bdev->bd_holder_lock);
| ^~~~
./include/linux/blkdev.h:1757:15: error: use of undeclared identifier 'bdev'
1757 | __releases(&bdev->bd_holder_lock);
| ^~~~
./include/linux/blkdev.h:1763:15: error: use of undeclared identifier 'bdev'
1763 | __releases(&bdev->bd_holder_lock);
| ^~~~

Thanks,

Bart.