Skip to contentSkip to conversation

Fix an error path in disk_update_zone_resources()

PATCH Applied Bart Van Assche 4 participants 10 messages Jan 14 – Jan 20

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Fix an error path in disk_update_zone_resources()

Hi Jens,

This patch series includes a fix for an error path in disk_update_zone_resources() and also the patch with which this bug was discovered. Compile-tested only.

Please consider this patch series for inclusion in the upstream kernel.

Thanks,

Bart.

Bart Van Assche (2):
block: Annotate the queue limits functions
block: Fix an error path in disk_update_zone_resources()

 block/blk-zoned.c      | 1 +
 include/linux/blkdev.h | 8 ++++++--
 2 files changed, 7 insertions(+), 2 deletions(-)
#1 lore raw

PATCH 1/2 block: Annotate the queue limits functions

---
 include/linux/blkdev.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
include/linux/blkdev.h +6 -2
index 72e34acd439c..66bf11cfcb37 100644
@@ -1084,14 +1084,17 @@ static inline unsigned int blk_boundary_sectors_left(sector_t offset,
  */
 static inline struct queue_limits
 queue_limits_start_update(struct request_queue *q)
+	__acquires(&q->limits_lock)
 {
 	mutex_lock(&q->limits_lock);
 	return q->limits;
 }
 int queue_limits_commit_update_frozen(struct request_queue *q,
-		struct queue_limits *lim);
+		struct queue_limits *lim)
+	__releases(&q->limits_lock);
 int queue_limits_commit_update(struct request_queue *q,
-		struct queue_limits *lim);
+		struct queue_limits *lim)
+	__releases(&q->limits_lock);
 int queue_limits_set(struct request_queue *q, struct queue_limits *lim);
 int blk_validate_limits(struct queue_limits *lim);
 
@@ -1104,6 +1107,7 @@ int blk_validate_limits(struct queue_limits *lim);
  * starting update.
  */
 static inline void queue_limits_cancel_update(struct request_queue *q)
+	__releases(&q->limits_lock)
 {
 	mutex_unlock(&q->limits_lock);
 }
#2 lore raw

Re: [PATCH 1/2] block: Annotate the queue limits functions

This is missing a commit log. And not really telling what kind of annotation you're adding.

#3 lore raw

Re: [PATCH 1/2] block: Annotate the queue limits functions

Quoted 4 lines · Christoph Hellwig

This is missing a commit log. And not really telling what kind of annotation you're adding.

And we removed these previously - see c3042a5403ef2.

Does sparse now handle mutexes?

#4 lore raw

Re: [PATCH 1/2] block: Annotate the queue limits functions

Quoted 7 lines · John Garry
Quoted 2 lines · Christoph Hellwig

This is missing a commit log.  And not really telling what kind of annotation you're adding.

And we removed these previously - see c3042a5403ef2.

Does sparse now handle mutexes?

sparse is dead. The most recent commit is from February 2024 (almost two years ago). Additionally, the sparse maintainer doesn't reply anymore to emails or bug reports about sparse.

These annotations aren't for sparse - these are for clang. This patch series has been queued by Peter Zijlstra on the tip master branch and is expected to be sent to Linus during the next merge window: "[PATCH v5
00/36] Compiler-Based Context- and Locking-Analysis"
(https://lore.kernel.org/lkml/[email protected]/).

There are some subtle differences between the sparse and clang lock context attributes. Sparse only cares about lock context attributes on the function implementation. Clang respects lock context annotations whether these annotations occur on the function declaration or the function definition. The former is preferred since this ensures that the annotations are visible not only while compiling the function implementation but also when compiling all callers of a function.

Bart.

#5 lore raw

Re: [PATCH 1/2] block: Annotate the queue limits functions

Quoted 10 lines · Bart Van Assche
Quoted 7 lines · John Garry
Quoted 2 lines · Christoph Hellwig

This is missing a commit log.  And not really telling what kind of annotation you're adding.

And we removed these previously - see c3042a5403ef2.

Does sparse now handle mutexes?

sparse is dead.

It's not. And even if it was we still need it.

Quoted 2 lines

The most recent commit is from February 2024 (almost two years ago).

The repository disagrees:

commit fbdde3127b83e6d09e0ba808d7925dd84407f3c6 (origin/master, origin/HEAD)

Author: Dan Carpenter <[email protected]>
Date:   Wed Oct 15 16:08:13 2025 +0300

builtin: implement __builtin_strlen() for constants

Quoted 2 lines

Additionally, the sparse maintainer doesn't reply anymore to emails or bug reports about sparse.

While I'd love to see more activity, that is clearly untrue as well:

[PATCH v2 3/3] module: Add compile-time check for embedded NUL characters

Quoted 5 lines

These annotations aren't for sparse - these are for clang. This patch series has been queued by Peter Zijlstra on the tip master branch and is expected to be sent to Linus during the next merge window: "[PATCH v5 00/36] Compiler-Based Context- and Locking-Analysis"
(https://lore.kernel.org/lkml/[email protected]/).

Until that actually becomes mainstream we can't break the existing annotations.

#6 lore raw

Re: [PATCH 1/2] block: Annotate the queue limits functions

Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Bart Van Assche
Quoted 4 lines · John Garry
Quoted 2 lines · Christoph Hellwig

This is missing a commit log.  And not really telling what kind of annotation you're adding.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

And we removed these previously - see c3042a5403ef2.

Does sparse now handle mutexes?

sparse is dead.

It's not. And even if it was we still need it.

Is there perhaps a new official sparse git repository? What I wrote applies to the following repository:
https://github.com/lucvoo/sparse.git. After some searching, I found a repository with more recent changes:
git://git.kernel.org/pub/scm/devel/sparse/sparse.git

There are 7 commits in the latter repository that are not in Luc Voo's repository. Not much, but better than nothing.

And I found this email from September 2025: "Re: Sparse maintainership"
(https://lore.kernel.org/all/CACePvbU=fAf6nNih5r-epJwU8qpiJ4TmkU6yQg8O1hrJKznDRA@mail.gmail.com/)

Thanks,

Bart.

#7 lore raw

PATCH 2/2 block: Fix an error path in disk_update_zone_resources()

In reply to Bart Van Assche

Any queue_limits_start_update() call must be followed either by a queue_limits_commit_update() call or by a queue_limits_cancel_update() call. Make sure that the error path near the start of disk_update_zone_resources() follows this requirement. Remove the "goto unfreeze" statement from that error path to make the code easier to verify.

This was detected by annotating the queue_limits_*() calls with Clang thread-safety attributes and by building the kernel with thread-safety checking enabled. Without this patch and with thread-safety checking enabled, the following error is reported:

block/blk-zoned.c:2020:1: error: mutex 'disk->queue->limits_lock' is not held on every path through here [-Werror,-Wthread-safety-analysis]
2020 | }

      | ^

block/blk-zoned.c:1959:8: note: mutex acquired here
1959 | lim = queue_limits_start_update(q);
| ^

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Fixes bba4322e3f30 ("block: freeze queue when updating zone resources")
---
 block/blk-zoned.c | 1 +
 1 file changed, 1 insertion(+)
block/blk-zoned.c +1 -0
index 1c54678fae6b..8000c94690ee 100644
@@ -1957,6 +1957,7 @@ static int disk_update_zone_resources(struct gendisk *disk,
 
 	disk->nr_zones = args->nr_zones;
 	if (args->nr_conv_zones >= disk->nr_zones) {
+		queue_limits_cancel_update(q);
 		pr_warn("%s: Invalid number of conventional zones %u / %u\n",
 			disk->disk_name, args->nr_conv_zones, disk->nr_zones);
 		ret = -ENODEV;
maintainer Applied
#9 lore raw

Re: (subset) [PATCH 0/2] Fix an error path in disk_update_zone_resources()

In reply to Bart Van Assche
Quoted 9 lines · Bart Van Assche

This patch series includes a fix for an error path in disk_update_zone_resources() and also the patch with which this bug was discovered. Compile-tested only.

Please consider this patch series for inclusion in the upstream kernel.

Thanks,

[...]

Applied, thanks!

[2/2] block: Fix an error path in disk_update_zone_resources()

      commit: 07a1bc5c14c9ef6401b21c1873c6c087075ff292

Best regards,

Signature · 1 line
Jens Axboe