From: Bill Wendling <morbo@google.com>
To: linux-kernel@vger.kernel.org
Cc: Bill Wendling <morbo@google.com>, Jens Axboe <axboe@kernel.dk>,
Kees Cook <kees@kernel.org>,
Gogul Balakrishnan <bgogul@google.com>,
Arman Hasanzadeh <armanihm@google.com>,
linux-block@vger.kernel.org
Subject: [PATCH] blkdev: Annotate struct request_queue with __counted_by_ptr
Date: Thu, 19 Feb 2026 00:49:35 +0000 [thread overview]
Message-ID: <20260219004940.2594201-1-morbo@google.com> (raw)
The queue_hw_ctx field in struct request_queue is an array of pointers to
struct blk_mq_hw_ctx. The number of elements in this array is tracked by
the nr_hw_queues field.
The array is allocated in __blk_mq_realloc_hw_ctxs() using kcalloc_node()
with set->nr_hw_queues elements. q->nr_hw_queues is subsequently updated
to set->nr_hw_queues.
When growing the array, the new array is assigned to queue_hw_ctx before
nr_hw_queues is updated. This is safe because nr_hw_queues (the old
smaller count) is used for bounds checking, which is within the new
larger allocation.
When shrinking the array, nr_hw_queues is updated to the smaller value,
while queue_hw_ctx retains the larger allocation. This is also safe as
the count is within the allocation bounds.
Annotating queue_hw_ctx with __counted_by_ptr(nr_hw_queues) allows the
compiler (with kSAN) to verify that accesses to queue_hw_ctx are within
the valid range defined by nr_hw_queues.
This patch was generated by Gemini and reviewed by Bill Wendling.
Tested with bootup and running selftests.
Signed-off-by: Bill Wendling <morbo@google.com>
---
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Kees Cook <kees@kernel.org>
Cc: Gogul Balakrishnan <bgogul@google.com>
Cc: Arman Hasanzadeh <armanihm@google.com>
Cc: linux-block@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
include/linux/blkdev.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index d463b9b5a0a5..540c2c6c9afd 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -502,7 +502,7 @@ struct request_queue {
/* hw dispatch queues */
unsigned int nr_hw_queues;
- struct blk_mq_hw_ctx * __rcu *queue_hw_ctx;
+ struct blk_mq_hw_ctx * __rcu *queue_hw_ctx __counted_by_ptr(nr_hw_queues);
struct percpu_ref q_usage_counter;
struct lock_class_key io_lock_cls_key;
--
2.43.0
next reply other threads:[~2026-02-19 0:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-19 0:49 Bill Wendling [this message]
2026-02-19 12:14 ` [PATCH] blkdev: Annotate struct request_queue with __counted_by_ptr Daniel Wagner
2026-02-19 17:02 ` Bill Wendling
2026-02-19 17:23 ` Daniel Wagner
2026-02-23 22:47 ` Bill Wendling
2026-02-24 8:55 ` Daniel Wagner
2026-02-25 18:26 ` Bill Wendling
2026-02-25 18:53 ` Jens Axboe
2026-02-25 19:00 ` Daniel Wagner
2026-02-25 20:45 ` Bill Wendling
2026-02-25 20:51 ` [PATCH v2] " Bill Wendling
2026-02-26 15:41 ` Jens Axboe
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=20260219004940.2594201-1-morbo@google.com \
--to=morbo@google.com \
--cc=armanihm@google.com \
--cc=axboe@kernel.dk \
--cc=bgogul@google.com \
--cc=kees@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox