* [PATCH] block: null_blk: Fix null_zone_write()
@ 2022-06-02 12:03 Damien Le Moal
2022-06-02 12:28 ` Johannes Thumshirn
2022-06-02 13:12 ` Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: Damien Le Moal @ 2022-06-02 12:03 UTC (permalink / raw)
To: Jens Axboe, linux-block
The bio and rq fields of struct nullb_cmd are now overlapping in a
union. So we cannot use a test on ->bio being non-NULL to detect the
NULL_Q_BIO queue mode. null_zone_write() use such broken test to set the
sector position of a zone append write in the command bio or request.
When the null_blk device uses the NULL_Q_MQ queue mode,
null_zone_write() wrongly end up setting the bio sector position,
resulting in the command request to be broken and random crashes
following.
Fix this by testing the device queue mode directly.
Fixes: 8ba816b23abd ("null-blk: save memory footprint for struct nullb_cmd")
Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
---
drivers/block/null_blk/main.c | 6 ------
drivers/block/null_blk/null_blk.h | 7 +++++++
drivers/block/null_blk/zoned.c | 6 +++---
3 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index 539cfeac263d..6b67088f4ea7 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -77,12 +77,6 @@ enum {
NULL_IRQ_TIMER = 2,
};
-enum {
- NULL_Q_BIO = 0,
- NULL_Q_RQ = 1,
- NULL_Q_MQ = 2,
-};
-
static bool g_virt_boundary = false;
module_param_named(virt_boundary, g_virt_boundary, bool, 0444);
MODULE_PARM_DESC(virt_boundary, "Require a virtual boundary for the device. Default: False");
diff --git a/drivers/block/null_blk/null_blk.h b/drivers/block/null_blk/null_blk.h
index 4525a65e1b23..8359b43842f2 100644
--- a/drivers/block/null_blk/null_blk.h
+++ b/drivers/block/null_blk/null_blk.h
@@ -60,6 +60,13 @@ struct nullb_zone {
unsigned int capacity;
};
+/* Queue modes */
+enum {
+ NULL_Q_BIO = 0,
+ NULL_Q_RQ = 1,
+ NULL_Q_MQ = 2,
+};
+
struct nullb_device {
struct nullb *nullb;
struct config_item item;
diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c
index ed158ea4fdd1..2fdd7b20c224 100644
--- a/drivers/block/null_blk/zoned.c
+++ b/drivers/block/null_blk/zoned.c
@@ -398,10 +398,10 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector,
*/
if (append) {
sector = zone->wp;
- if (cmd->bio)
- cmd->bio->bi_iter.bi_sector = sector;
- else
+ if (dev->queue_mode == NULL_Q_MQ)
cmd->rq->__sector = sector;
+ else
+ cmd->bio->bi_iter.bi_sector = sector;
} else if (sector != zone->wp) {
ret = BLK_STS_IOERR;
goto unlock;
--
2.36.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] block: null_blk: Fix null_zone_write()
2022-06-02 12:03 [PATCH] block: null_blk: Fix null_zone_write() Damien Le Moal
@ 2022-06-02 12:28 ` Johannes Thumshirn
2022-06-02 13:12 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Johannes Thumshirn @ 2022-06-02 12:28 UTC (permalink / raw)
To: Damien Le Moal, Jens Axboe, linux-block
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] block: null_blk: Fix null_zone_write()
2022-06-02 12:03 [PATCH] block: null_blk: Fix null_zone_write() Damien Le Moal
2022-06-02 12:28 ` Johannes Thumshirn
@ 2022-06-02 13:12 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2022-06-02 13:12 UTC (permalink / raw)
To: linux-block, damien.lemoal
On Thu, 2 Jun 2022 21:03:44 +0900, Damien Le Moal wrote:
> The bio and rq fields of struct nullb_cmd are now overlapping in a
> union. So we cannot use a test on ->bio being non-NULL to detect the
> NULL_Q_BIO queue mode. null_zone_write() use such broken test to set the
> sector position of a zone append write in the command bio or request.
> When the null_blk device uses the NULL_Q_MQ queue mode,
> null_zone_write() wrongly end up setting the bio sector position,
> resulting in the command request to be broken and random crashes
> following.
>
> [...]
Applied, thanks!
[1/1] block: null_blk: Fix null_zone_write()
commit: aacae8c469f9ce4b303a2eb61593ff522c1420bc
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-02 13:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-02 12:03 [PATCH] block: null_blk: Fix null_zone_write() Damien Le Moal
2022-06-02 12:28 ` Johannes Thumshirn
2022-06-02 13:12 ` Jens Axboe
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.