All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Bart Van Assche <bvanassche@acm.org>
Cc: Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Damien Le Moal <dlemoal@kernel.org>, Tejun Heo <tj@kernel.org>,
	Nathan Chancellor <nathan@kernel.org>
Subject: Re: [PATCH v2 09/26] block/blk-zoned: Add lock context annotations
Date: Thu, 26 Mar 2026 07:42:39 +0100	[thread overview]
Message-ID: <20260326064239.GA24534@lst.de> (raw)
In-Reply-To: <20260325214518.2854494-10-bvanassche@acm.org>

On Wed, Mar 25, 2026 at 02:44:50PM -0700, Bart Van Assche wrote:
>  int blkdev_zone_mgmt_ioctl(struct block_device *bdev, blk_mode_t mode,
>  			   unsigned int cmd, unsigned long arg)
> +	__cond_acquires(0, bdev->bd_mapping->host->i_rwsem)
>  {
>  	void __user *argp = (void __user *)arg;
>  	struct blk_zone_range zrange;

This looks wrong, the lock is just conditionally taken inside the
function and dropped again.  This cleanup should fix the lock annotation
issues:

---
From 99e701882a9026f56cf6940d858e92ce51d86638 Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <hch@lst.de>
Date: Thu, 26 Mar 2026 07:37:43 +0100
Subject: block: refactor blkdev_zone_mgmt_ioctl

Split the zone reset case into a separate helper so that the conditional
locking goes away.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/blk-zoned.c | 41 ++++++++++++++++++-----------------------
 1 file changed, 18 insertions(+), 23 deletions(-)

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 9d1dd6ccfad7..d370d871d019 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -412,20 +412,32 @@ int blkdev_report_zones_ioctl(struct block_device *bdev, unsigned int cmd,
 	return 0;
 }
 
-static int blkdev_truncate_zone_range(struct block_device *bdev,
-		blk_mode_t mode, const struct blk_zone_range *zrange)
+static int blkdev_reset_zone(struct block_device *bdev, blk_mode_t mode,
+			     struct blk_zone_range *zrange)
 {
 	loff_t start, end;
+	int ret = -EINVAL;
 
+	inode_lock(bdev->bd_mapping->host);
+	filemap_invalidate_lock(bdev->bd_mapping);
 	if (zrange->sector + zrange->nr_sectors <= zrange->sector ||
 	    zrange->sector + zrange->nr_sectors > get_capacity(bdev->bd_disk))
 		/* Out of range */
-		return -EINVAL;
+		goto out_unlock;
 
 	start = zrange->sector << SECTOR_SHIFT;
 	end = ((zrange->sector + zrange->nr_sectors) << SECTOR_SHIFT) - 1;
 
-	return truncate_bdev_range(bdev, mode, start, end);
+	ret = truncate_bdev_range(bdev, mode, start, end);
+	if (ret)
+		goto out_unlock;
+
+	ret = blkdev_zone_mgmt(bdev, REQ_OP_ZONE_RESET, zrange->sector,
+			       zrange->nr_sectors);
+out_unlock:
+	filemap_invalidate_unlock(bdev->bd_mapping);
+	inode_unlock(bdev->bd_mapping->host);
+	return ret;
 }
 
 /*
@@ -438,7 +450,6 @@ int blkdev_zone_mgmt_ioctl(struct block_device *bdev, blk_mode_t mode,
 	void __user *argp = (void __user *)arg;
 	struct blk_zone_range zrange;
 	enum req_op op;
-	int ret;
 
 	if (!argp)
 		return -EINVAL;
@@ -454,15 +465,7 @@ int blkdev_zone_mgmt_ioctl(struct block_device *bdev, blk_mode_t mode,
 
 	switch (cmd) {
 	case BLKRESETZONE:
-		op = REQ_OP_ZONE_RESET;
-
-		/* Invalidate the page cache, including dirty pages. */
-		inode_lock(bdev->bd_mapping->host);
-		filemap_invalidate_lock(bdev->bd_mapping);
-		ret = blkdev_truncate_zone_range(bdev, mode, &zrange);
-		if (ret)
-			goto fail;
-		break;
+		return blkdev_reset_zone(bdev, mode, &zrange);
 	case BLKOPENZONE:
 		op = REQ_OP_ZONE_OPEN;
 		break;
@@ -476,15 +479,7 @@ int blkdev_zone_mgmt_ioctl(struct block_device *bdev, blk_mode_t mode,
 		return -ENOTTY;
 	}
 
-	ret = blkdev_zone_mgmt(bdev, op, zrange.sector, zrange.nr_sectors);
-
-fail:
-	if (cmd == BLKRESETZONE) {
-		filemap_invalidate_unlock(bdev->bd_mapping);
-		inode_unlock(bdev->bd_mapping->host);
-	}
-
-	return ret;
+	return blkdev_zone_mgmt(bdev, op, zrange.sector, zrange.nr_sectors);
 }
 
 static bool disk_zone_is_last(struct gendisk *disk, struct blk_zone *zone)
-- 
2.47.3


  reply	other threads:[~2026-03-26  6:42 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 [this message]
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
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=20260326064239.GA24534@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=dlemoal@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=nathan@kernel.org \
    --cc=tj@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.