Re: [PATCH v2 02/26] block: Annotate the block device functions

Christoph Hellwig
2026-03-26T06:25:10Z

On Wed, Mar 25, 2026 at 02:44:43PM -0700, Bart Van Assche wrote:
> Prepare for enabling thread-safety analysis by adding __release()
> annotations where appropriate. Explicit __release() annotations have
> been added since Clang does not support adding a __releases() annotation
> to a function pointer.
>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
> block/bdev.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/block/bdev.c b/block/bdev.c
> index ed022f8c48c7..1f710b8bfb9f 100644
> --- a/block/bdev.c
> +++ b/block/bdev.c
> @@ -312,7 +312,9 @@ int bdev_freeze(struct block_device *bdev)
> mutex_lock(&bdev->bd_holder_lock);
> if (bdev->bd_holder_ops && bdev->bd_holder_ops->freeze) {
> error = bdev->bd_holder_ops->freeze(bdev);
> + /* bdev->bd_holder_ops->freeze() released bd_holder_lock */
> lockdep_assert_not_held(&bdev->bd_holder_lock);
> + __release(&bdev->bd_holder_lock);
> } else {
> mutex_unlock(&bdev->bd_holder_lock);
> error = sync_blockdev(bdev);
> @@ -355,7 +357,9 @@ int bdev_thaw(struct block_device *bdev)
> mutex_lock(&bdev->bd_holder_lock);
> if (bdev->bd_holder_ops && bdev->bd_holder_ops->thaw) {
> error = bdev->bd_holder_ops->thaw(bdev);
> + /* bdev->bd_holder_ops->freeze() released bd_holder_lock */
> lockdep_assert_not_held(&bdev->bd_holder_lock);
> + __release(&bdev->bd_holder_lock);
> } else {
> mutex_unlock(&bdev->bd_holder_lock);
> }
> @@ -1254,9 +1258,11 @@ EXPORT_SYMBOL(lookup_bdev);
> void bdev_mark_dead(struct block_device *bdev, bool surprise)
> {
> mutex_lock(&bdev->bd_holder_lock);
> - if (bdev->bd_holder_ops && bdev->bd_holder_ops->mark_dead)
> + if (bdev->bd_holder_ops && bdev->bd_holder_ops->mark_dead) {
> bdev->bd_holder_ops->mark_dead(bdev, surprise);
> - else {
> + /* bdev->bd_holder_ops->mark_dead() released bd_holder_lock */
> + __release(&bdev->bd_holder_lock);

This sounds like ->mark_dead also needs matching annotations. Or
can we have a way to annotate the expexcted lock context changes on
indirect function calls, as that would be very useful in general.