Hi Nitesh,
kernel test robot noticed the following build warnings:
[auto build test WARNING on f7dc24b3413851109c4047b22997bd0d95ed52a2]
url: https://github.com/intel-lab-lkp/linux/commits/Nitesh-Shetty/block-Introduce-queue-limits-and-sysfs-for-copy-offload-support/20230811-192259
base: f7dc24b3413851109c4047b22997bd0d95ed52a2
patch link: https://lore.kernel.org/r/20230811105300.15889-12-nj.shetty%40samsung.com
patch subject: [PATCH v14 11/11] null_blk: add support for copy offload
config: hexagon-randconfig-r032-20230811 (https://download.01.org/0day-ci/archive/20230812/202308120029.elW3y1RM-lkp@intel.com/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a)
reproduce: (https://download.01.org/0day-ci/archive/20230812/202308120029.elW3y1RM-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202308120029.elW3y1RM-lkp@intel.com/
All warnings (new ones prefixed by >>):
In file included from drivers/block/null_blk/main.c:12:
In file included from drivers/block/null_blk/null_blk.h:8:
In file included from include/linux/blkdev.h:9:
In file included from include/linux/blk_types.h:10:
In file included from include/linux/bvec.h:10:
In file included from include/linux/highmem.h:12:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/hexagon/include/asm/io.h:337:
include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
547 | val = __raw_readb(PCI_IOBASE + addr);
| ~~~~~~~~~~ ^
include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
560 | val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
| ~~~~~~~~~~ ^
include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
| ^
In file included from drivers/block/null_blk/main.c:12:
In file included from drivers/block/null_blk/null_blk.h:8:
In file included from include/linux/blkdev.h:9:
In file included from include/linux/blk_types.h:10:
In file included from include/linux/bvec.h:10:
In file included from include/linux/highmem.h:12:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/hexagon/include/asm/io.h:337:
include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
573 | val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
| ~~~~~~~~~~ ^
include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
| ^
In file included from drivers/block/null_blk/main.c:12:
In file included from drivers/block/null_blk/null_blk.h:8:
In file included from include/linux/blkdev.h:9:
In file included from include/linux/blk_types.h:10:
In file included from include/linux/bvec.h:10:
In file included from include/linux/highmem.h:12:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/hexagon/include/asm/io.h:337:
include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
584 | __raw_writeb(value, PCI_IOBASE + addr);
| ~~~~~~~~~~ ^
include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
594 | __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
| ~~~~~~~~~~ ^
include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
604 | __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
| ~~~~~~~~~~ ^
>> drivers/block/null_blk/main.c:1303:2: warning: variable 'sector_in' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
1303 | __rq_for_each_bio(bio, req) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/blk-mq.h:1008:6: note: expanded from macro '__rq_for_each_bio'
1008 | if ((rq->bio)) \
| ^~~~~~~~~
drivers/block/null_blk/main.c:1316:8: note: uninitialized use occurs here
1316 | sector_in << SECTOR_SHIFT, rem);
| ^~~~~~~~~
drivers/block/null_blk/main.c:1303:2: note: remove the 'if' if its condition is always true
1303 | __rq_for_each_bio(bio, req) {
| ^
include/linux/blk-mq.h:1008:2: note: expanded from macro '__rq_for_each_bio'
1008 | if ((rq->bio)) \
| ^
drivers/block/null_blk/main.c:1287:20: note: initialize the variable 'sector_in' to silence this warning
1287 | sector_t sector_in, sector_out;
| ^
| = 0
>> drivers/block/null_blk/main.c:1303:2: warning: variable 'sector_out' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
1303 | __rq_for_each_bio(bio, req) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/blk-mq.h:1008:6: note: expanded from macro '__rq_for_each_bio'
1008 | if ((rq->bio)) \
| ^~~~~~~~~
drivers/block/null_blk/main.c:1315:27: note: uninitialized use occurs here
1315 | trace_nullb_copy_op(req, sector_out << SECTOR_SHIFT,
| ^~~~~~~~~~
drivers/block/null_blk/main.c:1303:2: note: remove the 'if' if its condition is always true
1303 | __rq_for_each_bio(bio, req) {
| ^
include/linux/blk-mq.h:1008:2: note: expanded from macro '__rq_for_each_bio'
1008 | if ((rq->bio)) \
| ^
drivers/block/null_blk/main.c:1287:32: note: initialize the variable 'sector_out' to silence this warning
1287 | sector_t sector_in, sector_out;
| ^
| = 0
8 warnings generated.
vim +1303 drivers/block/null_blk/main.c
1283
1284 static inline int nullb_setup_copy(struct nullb *nullb, struct request *req,
1285 bool is_fua)
1286 {
1287 sector_t sector_in, sector_out;
1288 loff_t offset_in, offset_out;
1289 void *in, *out;
1290 ssize_t chunk, rem = 0;
1291 struct bio *bio;
1292 struct nullb_page *t_page_in, *t_page_out;
1293 u16 seg = 1;
1294 int status = -EIO;
1295
1296 if (blk_rq_nr_phys_segments(req) != COPY_MAX_SEGMENTS)
1297 return status;
1298
1299 /*
1300 * First bio contains information about source and last bio contains
1301 * information about destination.
1302 */
> 1303 __rq_for_each_bio(bio, req) {
1304 if (seg == blk_rq_nr_phys_segments(req)) {
1305 sector_out = bio->bi_iter.bi_sector;
1306 if (rem != bio->bi_iter.bi_size)
1307 return status;
1308 } else {
1309 sector_in = bio->bi_iter.bi_sector;
1310 rem = bio->bi_iter.bi_size;
1311 }
1312 seg++;
1313 }
1314
1315 trace_nullb_copy_op(req, sector_out << SECTOR_SHIFT,
1316 sector_in << SECTOR_SHIFT, rem);
1317
1318 spin_lock_irq(&nullb->lock);
1319 while (rem > 0) {
1320 chunk = min_t(size_t, nullb->dev->blocksize, rem);
1321 offset_in = (sector_in & SECTOR_MASK) << SECTOR_SHIFT;
1322 offset_out = (sector_out & SECTOR_MASK) << SECTOR_SHIFT;
1323
1324 if (null_cache_active(nullb) && !is_fua)
1325 null_make_cache_space(nullb, PAGE_SIZE);
1326
1327 t_page_in = null_lookup_page(nullb, sector_in, false,
1328 !null_cache_active(nullb));
1329 if (!t_page_in)
1330 goto err;
1331 t_page_out = null_insert_page(nullb, sector_out,
1332 !null_cache_active(nullb) ||
1333 is_fua);
1334 if (!t_page_out)
1335 goto err;
1336
1337 in = kmap_local_page(t_page_in->page);
1338 out = kmap_local_page(t_page_out->page);
1339
1340 memcpy(out + offset_out, in + offset_in, chunk);
1341 kunmap_local(out);
1342 kunmap_local(in);
1343 __set_bit(sector_out & SECTOR_MASK, t_page_out->bitmap);
1344
1345 if (is_fua)
1346 null_free_sector(nullb, sector_out, true);
1347
1348 rem -= chunk;
1349 sector_in += chunk >> SECTOR_SHIFT;
1350 sector_out += chunk >> SECTOR_SHIFT;
1351 }
1352
1353 status = 0;
1354 err:
1355 spin_unlock_irq(&nullb->lock);
1356 return status;
1357 }
1358
@@ -149,3 +149,8 @@ zone_size=[MB]: Default: 256
zone_nr_conv=[nr_conv]: Default: 0
The number of conventional zones to create when block device is zoned. If
zone_nr_conv >= nr_zones, it will be reduced to nr_zones - 1.
+
+copy_max_bytes=[size in bytes]: Default: COPY_MAX_BYTES
+ A module and configfs parameter which can be used to set hardware/driver
+ supported maximum copy offload limit.
+ COPY_MAX_BYTES(=128MB at present) is defined in fs.h
@@ -11,6 +11,8 @@
#include <linux/init.h>
#include "null_blk.h"
+#include "trace.h"
+
#undef pr_fmt
#define pr_fmt(fmt) "null_blk: " fmt
@@ -157,6 +159,10 @@ static int g_max_sectors;
module_param_named(max_sectors, g_max_sectors, int, 0444);
MODULE_PARM_DESC(max_sectors, "Maximum size of a command (in 512B sectors)");
+static unsigned long g_copy_max_bytes = COPY_MAX_BYTES;
+module_param_named(copy_max_bytes, g_copy_max_bytes, ulong, 0444);
+MODULE_PARM_DESC(copy_max_bytes, "Maximum size of a copy command (in bytes)");
+
static unsigned int nr_devices = 1;
module_param(nr_devices, uint, 0444);
MODULE_PARM_DESC(nr_devices, "Number of devices to register");
@@ -409,6 +415,7 @@ NULLB_DEVICE_ATTR(home_node, uint, NULL);
NULLB_DEVICE_ATTR(queue_mode, uint, NULL);
NULLB_DEVICE_ATTR(blocksize, uint, NULL);
NULLB_DEVICE_ATTR(max_sectors, uint, NULL);
+NULLB_DEVICE_ATTR(copy_max_bytes, uint, NULL);
NULLB_DEVICE_ATTR(irqmode, uint, NULL);
NULLB_DEVICE_ATTR(hw_queue_depth, uint, NULL);
NULLB_DEVICE_ATTR(index, uint, NULL);
@@ -550,6 +557,7 @@ static struct configfs_attribute *nullb_device_attrs[] = {
&nullb_device_attr_queue_mode,
&nullb_device_attr_blocksize,
&nullb_device_attr_max_sectors,
+ &nullb_device_attr_copy_max_bytes,
&nullb_device_attr_irqmode,
&nullb_device_attr_hw_queue_depth,
&nullb_device_attr_index,
@@ -656,7 +664,8 @@ static ssize_t memb_group_features_show(struct config_item *item, char *page)
"poll_queues,power,queue_mode,shared_tag_bitmap,size,"
"submit_queues,use_per_node_hctx,virt_boundary,zoned,"
"zone_capacity,zone_max_active,zone_max_open,"
- "zone_nr_conv,zone_offline,zone_readonly,zone_size\n");
+ "zone_nr_conv,zone_offline,zone_readonly,zone_size,"
+ "copy_max_bytes\n");
}
CONFIGFS_ATTR_RO(memb_group_, features);
@@ -722,6 +731,7 @@ static struct nullb_device *null_alloc_dev(void)
dev->queue_mode = g_queue_mode;
dev->blocksize = g_bs;
dev->max_sectors = g_max_sectors;
+ dev->copy_max_bytes = g_copy_max_bytes;
dev->irqmode = g_irqmode;
dev->hw_queue_depth = g_hw_queue_depth;
dev->blocking = g_blocking;
@@ -1271,6 +1281,81 @@ static int null_transfer(struct nullb *nullb, struct page *page,
return err;
}
+static inline int nullb_setup_copy(struct nullb *nullb, struct request *req,
+ bool is_fua)
+{
+ sector_t sector_in, sector_out;
+ loff_t offset_in, offset_out;
+ void *in, *out;
+ ssize_t chunk, rem = 0;
+ struct bio *bio;
+ struct nullb_page *t_page_in, *t_page_out;
+ u16 seg = 1;
+ int status = -EIO;
+
+ if (blk_rq_nr_phys_segments(req) != COPY_MAX_SEGMENTS)
+ return status;
+
+ /*
+ * First bio contains information about source and last bio contains
+ * information about destination.
+ */
+ __rq_for_each_bio(bio, req) {
+ if (seg == blk_rq_nr_phys_segments(req)) {
+ sector_out = bio->bi_iter.bi_sector;
+ if (rem != bio->bi_iter.bi_size)
+ return status;
+ } else {
+ sector_in = bio->bi_iter.bi_sector;
+ rem = bio->bi_iter.bi_size;
+ }
+ seg++;
+ }
+
+ trace_nullb_copy_op(req, sector_out << SECTOR_SHIFT,
+ sector_in << SECTOR_SHIFT, rem);
+
+ spin_lock_irq(&nullb->lock);
+ while (rem > 0) {
+ chunk = min_t(size_t, nullb->dev->blocksize, rem);
+ offset_in = (sector_in & SECTOR_MASK) << SECTOR_SHIFT;
+ offset_out = (sector_out & SECTOR_MASK) << SECTOR_SHIFT;
+
+ if (null_cache_active(nullb) && !is_fua)
+ null_make_cache_space(nullb, PAGE_SIZE);
+
+ t_page_in = null_lookup_page(nullb, sector_in, false,
+ !null_cache_active(nullb));
+ if (!t_page_in)
+ goto err;
+ t_page_out = null_insert_page(nullb, sector_out,
+ !null_cache_active(nullb) ||
+ is_fua);
+ if (!t_page_out)
+ goto err;
+
+ in = kmap_local_page(t_page_in->page);
+ out = kmap_local_page(t_page_out->page);
+
+ memcpy(out + offset_out, in + offset_in, chunk);
+ kunmap_local(out);
+ kunmap_local(in);
+ __set_bit(sector_out & SECTOR_MASK, t_page_out->bitmap);
+
+ if (is_fua)
+ null_free_sector(nullb, sector_out, true);
+
+ rem -= chunk;
+ sector_in += chunk >> SECTOR_SHIFT;
+ sector_out += chunk >> SECTOR_SHIFT;
+ }
+
+ status = 0;
+err:
+ spin_unlock_irq(&nullb->lock);
+ return status;
+}
+
static int null_handle_rq(struct nullb_cmd *cmd)
{
struct request *rq = cmd->rq;
@@ -1280,13 +1365,16 @@ static int null_handle_rq(struct nullb_cmd *cmd)
sector_t sector = blk_rq_pos(rq);
struct req_iterator iter;
struct bio_vec bvec;
+ bool fua = rq->cmd_flags & REQ_FUA;
+
+ if (op_is_copy(req_op(rq)))
+ return nullb_setup_copy(nullb, rq, fua);
spin_lock_irq(&nullb->lock);
rq_for_each_segment(bvec, rq, iter) {
len = bvec.bv_len;
err = null_transfer(nullb, bvec.bv_page, len, bvec.bv_offset,
- op_is_write(req_op(rq)), sector,
- rq->cmd_flags & REQ_FUA);
+ op_is_write(req_op(rq)), sector, fua);
if (err) {
spin_unlock_irq(&nullb->lock);
return err;
@@ -2042,6 +2130,9 @@ static int null_validate_conf(struct nullb_device *dev)
return -EINVAL;
}
+ if (dev->queue_mode == NULL_Q_BIO)
+ dev->copy_max_bytes = 0;
+
return 0;
}
@@ -2161,6 +2252,8 @@ static int null_add_dev(struct nullb_device *dev)
dev->max_sectors = queue_max_hw_sectors(nullb->q);
dev->max_sectors = min(dev->max_sectors, BLK_DEF_MAX_SECTORS);
blk_queue_max_hw_sectors(nullb->q, dev->max_sectors);
+ blk_queue_max_copy_hw_sectors(nullb->q,
+ dev->copy_max_bytes >> SECTOR_SHIFT);
if (dev->virt_boundary)
blk_queue_virt_boundary(nullb->q, PAGE_SIZE - 1);
@@ -107,6 +107,7 @@ struct nullb_device {
unsigned int queue_mode; /* block interface */
unsigned int blocksize; /* block size */
unsigned int max_sectors; /* Max sectors per command */
+ unsigned long copy_max_bytes; /* Max copy offload length in bytes */
unsigned int irqmode; /* IRQ completion handler */
unsigned int hw_queue_depth; /* queue depth */
unsigned int index; /* index of the disk, only valid with a disk */
@@ -68,6 +68,29 @@ TRACE_EVENT(nullb_report_zones,
__print_disk_name(__entry->disk), __entry->nr_zones)
);
+TRACE_EVENT(nullb_copy_op,
+ TP_PROTO(struct request *req,
+ sector_t dst, sector_t src, size_t len),
+ TP_ARGS(req, dst, src, len),
+ TP_STRUCT__entry(
+ __array(char, disk, DISK_NAME_LEN)
+ __field(enum req_op, op)
+ __field(sector_t, dst)
+ __field(sector_t, src)
+ __field(size_t, len)
+ ),
+ TP_fast_assign(
+ __entry->op = req_op(req);
+ __assign_disk_name(__entry->disk, req->q->disk);
+ __entry->dst = dst;
+ __entry->src = src;
+ __entry->len = len;
+ ),
+ TP_printk("%s req=%-15s: dst=%llu, src=%llu, len=%lu",
+ __print_disk_name(__entry->disk),
+ blk_op_str(__entry->op),
+ __entry->dst, __entry->src, __entry->len)
+);
#endif /* _TRACE_NULLB_H */
#undef TRACE_INCLUDE_PATH