From: Brian Foster <bfoster@redhat.com>
To: linux-block@vger.kernel.org
Cc: Nico Pache <npache@redhat.com>, Joel Savitz <jsavitz@redhat.com>
Subject: [PATCH] block: avoid sign extend problem with default queue flags mask
Date: Fri, 30 Sep 2022 11:03:45 -0400 [thread overview]
Message-ID: <20220930150345.854021-1-bfoster@redhat.com> (raw)
request_queue->queue_flags is an 8-byte field. Most queue flag
modifications occur through bit field helpers, but default flags can
be logically OR'd via the QUEUE_FLAG_MQ_DEFAULT mask. If this mask
happens to include bit 31, the assignment can sign extend the field
and set all upper 32 bits.
This exact problem has been observed on a downstream kernel that
happens to use bit 31 for QUEUE_FLAG_NOWAIT. This is not an
immediate problem for current upstream because bit 31 is not
included in the default flag assignment (and is not used at all,
actually). Regardless, fix up the QUEUE_FLAG_MQ_DEFAULT mask
definition to avoid the landmine in the future.
Signed-off-by: Brian Foster <bfoster@redhat.com>
---
Just to elaborate, I ran a quick test to change QUEUE_FLAG_NOWAIT to use
bit 31. With that change but without this patch, I see the following
queue state:
# cat /sys/kernel/debug/block/vda/state
SAME_COMP|IO_STAT|INIT_DONE|WC|STATS|REGISTERED|30|NOWAIT|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63
And then with the patch applied:
# cat /sys/kernel/debug/block/vda/state
SAME_COMP|IO_STAT|INIT_DONE|WC|STATS|REGISTERED|30|NOWAIT
Thanks.
Brian
include/linux/blkdev.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 84b13fdd34a7..28c3037cb25c 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -580,9 +580,9 @@ struct request_queue {
#define QUEUE_FLAG_NOWAIT 29 /* device supports NOWAIT */
#define QUEUE_FLAG_SQ_SCHED 30 /* single queue style io dispatch */
-#define QUEUE_FLAG_MQ_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \
- (1 << QUEUE_FLAG_SAME_COMP) | \
- (1 << QUEUE_FLAG_NOWAIT))
+#define QUEUE_FLAG_MQ_DEFAULT ((1ULL << QUEUE_FLAG_IO_STAT) | \
+ (1ULL << QUEUE_FLAG_SAME_COMP) | \
+ (1ULL << QUEUE_FLAG_NOWAIT))
void blk_queue_flag_set(unsigned int flag, struct request_queue *q);
void blk_queue_flag_clear(unsigned int flag, struct request_queue *q);
--
2.37.2
next reply other threads:[~2022-09-30 15:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-30 15:03 Brian Foster [this message]
2022-09-30 18:45 ` [PATCH] block: avoid sign extend problem with default queue flags mask Joel Savitz
2022-09-30 18:49 ` Nico Pache
2022-09-30 21:33 ` Jens Axboe
2022-10-03 12:52 ` Brian Foster
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=20220930150345.854021-1-bfoster@redhat.com \
--to=bfoster@redhat.com \
--cc=jsavitz@redhat.com \
--cc=linux-block@vger.kernel.org \
--cc=npache@redhat.com \
/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