* [PATCH] null_blk: fix zone read length beyond write pointer
@ 2025-11-12 16:42 Keith Busch
2025-11-12 17:00 ` Bart Van Assche
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Keith Busch @ 2025-11-12 16:42 UTC (permalink / raw)
To: axboe, dlemoal, johannes.thumshirn, bvanassche, linux-block; +Cc: Keith Busch
From: Keith Busch <kbusch@kernel.org>
Fix up the divisor calculating the number of zone sectors being read and
handle a read that straddles the zone write pointer. The length is
rounded up a sector boundary, so be sure to truncate any excess bytes
off to avoid copying past the data segment.
Fixes: 3451cf34f51bb70 ("null_blk: allow byte aligned memory offsets")
Signed-off-by: Keith Busch <kbusch@kernel.org>
---
drivers/block/null_blk/main.c | 5 ++++-
drivers/block/null_blk/zoned.c | 2 +-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index f1e67962ecaeb..c7c0fb79a6bf6 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -1240,9 +1240,12 @@ static blk_status_t null_transfer(struct nullb *nullb, struct page *page,
p = kmap_local_page(page) + off;
if (!is_write) {
- if (dev->zoned)
+ if (dev->zoned) {
valid_len = null_zone_valid_read_len(nullb,
pos >> SECTOR_SHIFT, len);
+ if (valid_len && valid_len != len)
+ valid_len -= pos & (SECTOR_SIZE - 1);
+ }
if (valid_len) {
copy_from_nullb(nullb, p, pos, valid_len);
diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c
index dbf292a8eae96..0ada35dc0989e 100644
--- a/drivers/block/null_blk/zoned.c
+++ b/drivers/block/null_blk/zoned.c
@@ -242,7 +242,7 @@ size_t null_zone_valid_read_len(struct nullb *nullb,
{
struct nullb_device *dev = nullb->dev;
struct nullb_zone *zone = &dev->zones[null_zone_no(dev, sector)];
- unsigned int nr_sectors = DIV_ROUND_UP(len, SECTOR_SHIFT);
+ unsigned int nr_sectors = DIV_ROUND_UP(len, SECTOR_SIZE);
/* Read must be below the write pointer position */
if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL ||
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] null_blk: fix zone read length beyond write pointer
2025-11-12 16:42 [PATCH] null_blk: fix zone read length beyond write pointer Keith Busch
@ 2025-11-12 17:00 ` Bart Van Assche
2025-11-12 17:03 ` Jens Axboe
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Bart Van Assche @ 2025-11-12 17:00 UTC (permalink / raw)
To: Keith Busch, axboe, dlemoal, johannes.thumshirn, linux-block; +Cc: Keith Busch
On 11/12/25 8:42 AM, Keith Busch wrote:
> Fix up the divisor calculating the number of zone sectors being read and
> handle a read that straddles the zone write pointer. The length is
> rounded up a sector boundary, so be sure to truncate any excess bytes
> off to avoid copying past the data segment.
Tested-by: Bart van Assche <bvanassche@acm.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] null_blk: fix zone read length beyond write pointer
2025-11-12 16:42 [PATCH] null_blk: fix zone read length beyond write pointer Keith Busch
2025-11-12 17:00 ` Bart Van Assche
@ 2025-11-12 17:03 ` Jens Axboe
2025-11-12 17:38 ` Chaitanya Kulkarni
2025-11-13 2:44 ` Damien Le Moal
3 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2025-11-12 17:03 UTC (permalink / raw)
To: dlemoal, johannes.thumshirn, bvanassche, linux-block, Keith Busch
Cc: Keith Busch
On Wed, 12 Nov 2025 08:42:18 -0800, Keith Busch wrote:
> Fix up the divisor calculating the number of zone sectors being read and
> handle a read that straddles the zone write pointer. The length is
> rounded up a sector boundary, so be sure to truncate any excess bytes
> off to avoid copying past the data segment.
>
>
Applied, thanks!
[1/1] null_blk: fix zone read length beyond write pointer
commit: 3749ea4deeba6049ea97e653d964568a45543e37
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] null_blk: fix zone read length beyond write pointer
2025-11-12 16:42 [PATCH] null_blk: fix zone read length beyond write pointer Keith Busch
2025-11-12 17:00 ` Bart Van Assche
2025-11-12 17:03 ` Jens Axboe
@ 2025-11-12 17:38 ` Chaitanya Kulkarni
2025-11-13 2:44 ` Damien Le Moal
3 siblings, 0 replies; 5+ messages in thread
From: Chaitanya Kulkarni @ 2025-11-12 17:38 UTC (permalink / raw)
To: Keith Busch, axboe@kernel.dk, dlemoal@kernel.org,
johannes.thumshirn@wdc.com, bvanassche@acm.org,
linux-block@vger.kernel.org
Cc: Keith Busch
On 11/12/25 08:42, Keith Busch wrote:
> From: Keith Busch<kbusch@kernel.org>
>
> Fix up the divisor calculating the number of zone sectors being read and
> handle a read that straddles the zone write pointer. The length is
> rounded up a sector boundary, so be sure to truncate any excess bytes
> off to avoid copying past the data segment.
>
> Fixes: 3451cf34f51bb70 ("null_blk: allow byte aligned memory offsets")
> Signed-off-by: Keith Busch<kbusch@kernel.org>
Looks good.
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
-ck
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] null_blk: fix zone read length beyond write pointer
2025-11-12 16:42 [PATCH] null_blk: fix zone read length beyond write pointer Keith Busch
` (2 preceding siblings ...)
2025-11-12 17:38 ` Chaitanya Kulkarni
@ 2025-11-13 2:44 ` Damien Le Moal
3 siblings, 0 replies; 5+ messages in thread
From: Damien Le Moal @ 2025-11-13 2:44 UTC (permalink / raw)
To: Keith Busch, axboe, johannes.thumshirn, bvanassche, linux-block
Cc: Keith Busch
On 11/13/25 01:42, Keith Busch wrote:
> From: Keith Busch <kbusch@kernel.org>
>
> Fix up the divisor calculating the number of zone sectors being read and
> handle a read that straddles the zone write pointer. The length is
> rounded up a sector boundary, so be sure to truncate any excess bytes
> off to avoid copying past the data segment.
>
> Fixes: 3451cf34f51bb70 ("null_blk: allow byte aligned memory offsets")
> Signed-off-by: Keith Busch <kbusch@kernel.org>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-11-13 2:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-12 16:42 [PATCH] null_blk: fix zone read length beyond write pointer Keith Busch
2025-11-12 17:00 ` Bart Van Assche
2025-11-12 17:03 ` Jens Axboe
2025-11-12 17:38 ` Chaitanya Kulkarni
2025-11-13 2:44 ` Damien Le Moal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox