Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=199.89.1.16 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796263277; b=R5NHPi9jvf0Xt8nfk6nxqmaJmJBFBOy4GujGI4UbiGFQngJ55Gn0OidrarO1h4TQlmLf HTe7ekySeMMuH70mgCpe30zQFUpR50kSPv3OH7nuRRsb1u1o1JO5Nm5v4A8+qxYSPxERG MUvkdqwsKeE4Q17vHPP5Zn2ken7uo9n0ksTQwUkdHnft6PC8PtENH9N1xDGoHb3R9u7zq h2aznFZFacyVBq9OZhk4T4IjxIjFHMpEp9MQuFFHu+CKCvz7c7t33X6R1VBDmqqhDvhka H3hvC03htd2vJ4UASkVd7MHjdh6vro94Ycajd8ZheIVGIC9PbHr90VMQ4vmkVpKGvIA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796263277; h=DMARC-Filter:Received:DKIM-Signature:X-Virus-Scanned:Received: Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; bh=JJJ4yoinF/cRcpVn91fHgfMZA5lJn2dhgXLBXz1LT7Y=; b=nSXJVMfh4cVoQbZxjMUApgS39jZbv4amrGW5Um6mMxYzplwrCjG/z25TVXrSNHL9Xd8R 8IEOWnx7GnPdcQ88afEmxgI2uF2InqlzBWjTGXJjFRRr/q0xqGHZ1eSgidiJrseDJaced 4LdSbBal9SgJg5ZdbO1lWHwAkXfRvV2hLQwDhffwUC/XA/6lWdgM9z30brJrNHb2q0C1X oCzExgpg2XpwypV9sgF6yyrkF/Ww1eodFLSShq8udgjiwedG5oeBi3psocuif3WS/cWzg 5thlbL8Y0ShFN+VWv6vQXPQRl0Kx+JQuloFkjB4cCe2RxrjLORcwMsiT+E8/sPp7VJw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass header.d=acm.org header.i=@acm.org header.a=rsa-sha256 header.s=mr01 header.b=YKP+joQL; arc=none smtp.remote-ip=199.89.1.16 Received: from 013.lax.mailroute.net (013.lax.mailroute.net [199.89.1.16]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF9CC606A322 for ; Thu, 3 Dec 2026 02:01:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DF9CC606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=acm.org header.i=@acm.org header.a=rsa-sha256 header.s=mr01 header.b=YKP+joQL Received: from localhost (localhost [127.0.0.1]) by 013.lax.mailroute.net (Postfix) with ESMTP id 4jfyXX0Xhwzlfl6L; Thu, 3 Dec 2026 02:01:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1796263272; x=1798855273; bh=JJJ4y oinF/cRcpVn91fHgfMZA5lJn2dhgXLBXz1LT7Y=; b=YKP+joQL8jTNuskfdKFTz vel6aGDfXfSgRAJxHzC5m/eyKS4uRw/IOF/ztf2iSHEUIfFQGn2kQAGiZkwmHpsq FX3YCc8xfMeaNRRWE2dq81cqhlg5KdvNvRVZysnwGcX8oSQ7AQSIGRHeYuPjpf1B VeSbfiFCa2KQMQMDwA4yXUB0jFtR67xz1q6nv4qqHJS8lcojRfJLPUM8aB1ho70k GZu3M7tS1wpGlqCXk2b046+tnB+DDBN9ZwRGFeWdgal+Uksa0VkQDr5PS1+vgcFE CAjTPRjbXjqR8DMsPNKrZEzInD/8jSULqpQOogPkDXA6bd7uSNTpZck5VRREAALX g== X-Virus-Scanned: by MailRoute Received: from 013.lax.mailroute.net ([127.0.0.1]) by localhost (013.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id CceTFvP1IyLF; Thu, 3 Dec 2026 02:01:12 +0000 (UTC) Received: from bvanassche.c.googlers.com.com (57.237.82.34.bc.googleusercontent.com [34.82.237.57]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 013.lax.mailroute.net (Postfix) with ESMTPSA id 4jfyXS03H8zlfpMs; Thu, 3 Dec 2026 02:01:11 +0000 (UTC) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Damien Le Moal , Bart Van Assche , Nathan Chancellor Subject: [PATCH 32/52] block: Add __must_hold() annotations in block/bdev.c Date: Wed, 2 Dec 2026 17:59:55 -0800 Message-ID: X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog In-Reply-To: References: X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Annotate the static functions in block/bdev.c that require disk->open_mutex to be held by their callers with __must_hold(&disk->open_mutex). Use __must_hold(&bdev->bd_disk->open_mute= x) for the functions that do not have a gendisk argument: bd_finish_claiming(), bd_end_claim(), bdev_writes_blocked(), bdev_block_writes(), bdev_may_open() and bdev_claim_write_access(). This enables Clang's context analysis to verify that disk->open_mutex is held by all callers. Signed-off-by: Bart Van Assche --- block/bdev.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/block/bdev.c b/block/bdev.c index d277b528759c..87dbcffb21da 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -137,6 +137,7 @@ int truncate_bdev_range(struct block_device *bdev, bl= k_mode_t mode, } =20 static void set_init_blocksize(struct gendisk *disk, struct block_device= *bdev) + __must_hold(&disk->open_mutex) { unsigned int bsize =3D bdev_logical_block_size(bdev); loff_t size =3D i_size_read(BD_INODE(bdev)); @@ -678,6 +679,7 @@ static void bd_clear_claiming(struct block_device *wh= ole, void *holder) */ static void bd_finish_claiming(struct block_device *bdev, void *holder, const struct blk_holder_ops *hops) + __must_hold(&bdev->bd_disk->open_mutex) { struct block_device *whole =3D bdev_whole(bdev); =20 @@ -716,6 +718,7 @@ void bd_abort_claiming(struct block_device *bdev, voi= d *holder) EXPORT_SYMBOL(bd_abort_claiming); =20 static void bd_end_claim(struct block_device *bdev, void *holder) + __must_hold(&bdev->bd_disk->open_mutex) { struct block_device *whole =3D bdev_whole(bdev); bool unblock =3D false; @@ -752,6 +755,7 @@ static void bd_end_claim(struct block_device *bdev, v= oid *holder) =20 static void blkdev_flush_mapping(struct gendisk *disk, struct block_device *bdev) + __must_hold(&disk->open_mutex) { WARN_ON_ONCE(bdev->bd_holders); sync_blockdev(bdev); @@ -760,6 +764,7 @@ static void blkdev_flush_mapping(struct gendisk *disk= , } =20 static void blkdev_put_whole(struct gendisk *disk, struct block_device *= bdev) + __must_hold(&disk->open_mutex) { if (atomic_dec_and_test(&bdev->bd_openers)) blkdev_flush_mapping(disk, bdev); @@ -769,6 +774,7 @@ static void blkdev_put_whole(struct gendisk *disk, st= ruct block_device *bdev) =20 static int blkdev_get_whole(struct gendisk *disk, struct block_device *b= dev, blk_mode_t mode) + __must_hold(&disk->open_mutex) { int ret; =20 @@ -802,6 +808,7 @@ static int blkdev_get_whole(struct gendisk *disk, str= uct block_device *bdev, =20 static int blkdev_get_part(struct gendisk *disk, struct block_device *pa= rt, blk_mode_t mode) + __must_hold(&disk->open_mutex) { int ret; =20 @@ -851,6 +858,7 @@ int bdev_permission(dev_t dev, blk_mode_t mode, void = *holder) } =20 static void blkdev_put_part(struct gendisk *disk, struct block_device *p= art) + __must_hold(&disk->open_mutex) { struct block_device *whole =3D bdev_whole(part); =20 @@ -891,21 +899,25 @@ void blkdev_put_no_open(struct block_device *bdev) } =20 static bool bdev_writes_blocked(struct block_device *bdev) + __must_hold(&bdev->bd_disk->open_mutex) { return bdev->bd_writers < 0; } =20 static void bdev_block_writes(struct block_device *bdev) + __must_hold(&bdev->bd_disk->open_mutex) { bdev->bd_writers--; } =20 static void bdev_unblock_writes(struct gendisk *disk, struct block_devic= e *bdev) + __must_hold(&disk->open_mutex) { bdev->bd_writers++; } =20 static bool bdev_may_open(struct block_device *bdev, blk_mode_t mode) + __must_hold(&bdev->bd_disk->open_mutex) { if (bdev_allow_write_mounted) return true; @@ -918,6 +930,7 @@ static bool bdev_may_open(struct block_device *bdev, = blk_mode_t mode) } =20 static void bdev_claim_write_access(struct block_device *bdev, blk_mode_= t mode) + __must_hold(&bdev->bd_disk->open_mutex) { if (bdev_allow_write_mounted) return; @@ -931,12 +944,14 @@ static void bdev_claim_write_access(struct block_de= vice *bdev, blk_mode_t mode) =20 static inline bool bdev_unclaimed(struct gendisk *disk, const struct file *bdev_file) + __must_hold(&disk->open_mutex) { return bdev_file->private_data =3D=3D BDEV_I(bdev_file->f_mapping->host= ); } =20 static void bdev_yield_write_access(struct gendisk *disk, struct file *bdev_file) + __must_hold(&disk->open_mutex) { struct block_device *bdev; =20 @@ -1140,6 +1155,7 @@ struct file *bdev_file_open_by_path(const char *pat= h, blk_mode_t mode, EXPORT_SYMBOL(bdev_file_open_by_path); =20 static inline void bd_yield_claim(struct gendisk *disk, struct file *bde= v_file) + __must_hold(&disk->open_mutex) { struct block_device *bdev =3D file_bdev(bdev_file); void *holder =3D bdev_file->private_data;