Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

null_blk: fix zone read length beyond write pointer

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>
Tested-by: Bart van Assche <bvanassche@acm.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Keith Busch and committed by
Jens Axboe
3749ea4d 6d7e3870

+5 -2
+4 -1
drivers/block/null_blk/main.c
··· 1240 1240 1241 1241 p = kmap_local_page(page) + off; 1242 1242 if (!is_write) { 1243 - if (dev->zoned) 1243 + if (dev->zoned) { 1244 1244 valid_len = null_zone_valid_read_len(nullb, 1245 1245 pos >> SECTOR_SHIFT, len); 1246 + if (valid_len && valid_len != len) 1247 + valid_len -= pos & (SECTOR_SIZE - 1); 1248 + } 1246 1249 1247 1250 if (valid_len) { 1248 1251 copy_from_nullb(nullb, p, pos, valid_len);
+1 -1
drivers/block/null_blk/zoned.c
··· 242 242 { 243 243 struct nullb_device *dev = nullb->dev; 244 244 struct nullb_zone *zone = &dev->zones[null_zone_no(dev, sector)]; 245 - unsigned int nr_sectors = DIV_ROUND_UP(len, SECTOR_SHIFT); 245 + unsigned int nr_sectors = DIV_ROUND_UP(len, SECTOR_SIZE); 246 246 247 247 /* Read must be below the write pointer position */ 248 248 if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL ||