| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/10/05 10:28 | flow | patch-triage |
5mArgs:null Results: {
"EnableConfigs": [
"BLK_DEV_ZONED",
"BLK_DEV_ZONED_LOOP"
],
"FocusSymbols": [
"blkdev_zone_storage_elements_ioctl",
"bdev_report_storage_elements",
"bdev_remove_storage_element",
"bdev_restore_storage_elements",
"bdev_zone_is_offline",
"disk_wait_for_se_mgmt_completion",
"zloop_report_elements",
"zloop_remove_element",
"zloop_restore_elements",
"zloop_degrade_element",
"zloop_ctl_degrade_element",
"sd_zbc_report_storage_elements",
"sd_zbc_remove_storage_element",
"sd_zbc_restore_storage_elements"
],
"KMSANReasoning": "The patch series introduces storage element management ioctls (BLKGETNRSTORELEMS, BLKREPORTSTORELEMS, BLKREMOVESTORELEM, BLKRESTORESTORELEMS) for zoned block devices, along with support in zloop and sd_zbc.\n\nAnalysis of memory safety risks:\n1. Kernel data sent to userspace:\n - In blkdev_get_nr_storage_elements_ioctl(), nr_elements is an unsigned int initialized to 0 and written via put_user().\n - In blkdev_report_storage_elements_ioctl(), the 'rep' header struct is initialized via copy_from_user() before being updated and copied back to userspace via copy_to_user().\n - The 'elements' array is allocated with kzalloc_objs(struct blk_storage_element, nr_elements), ensuring all allocated elements and fields are zero-initialized.\n - 'struct blk_storage_element' is 24 bytes long and naturally packed without any padding holes (u32 id, u32 paired_id, u64 nr_zones, u8 type, u8 status, u8 restore_allowed, u8 reserved[5]).\n2. KASAN vs KMSAN applicability:\n - A potential heap buffer overread exists in blkdev_report_storage_elements_ioctl(): if the driver's report_elements callback sets *nr_elements to the total number of elements on the device (which may exceed rep.nr_elements passed by the user and used for kzalloc_objs), copy_to_user() will read past the end of the allocated slab object. This is a slab-out-of-bounds access, which is explicitly detected by KASAN.\n - Similarly, in sd_zbc_report_storage_elements(), if the SCSI device reports a large nr_descs, reading past the 4096-byte kzalloc'd buffer is an out-of-bounds read caught by KASAN.\n - All buffers (in zloop, sd_zbc, and blk-zoned) are allocated with kzalloc/kzalloc_objs or explicitly memset/initialized before use. There are no uninitialized variables or struct padding copied to userspace or used in conditional branching.\n\nBecause all memory safety risks are out-of-bounds accesses covered by KASAN and there is no uninitialized memory usage, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false,
"Reasoning": "The patch adds support for storage element emulation and management (depopulation, restoration, and reporting) for zoned block devices. It introduces new user-facing ioctls (BLKGETNRSTORELEMS, BLKREPORTSTORELEMS, BLKREMOVESTORELEM, BLKRESTORESTORELEMS), new control operations on /dev/zloop-control, core block layer offline zone checks, asynchronous delayed work, and driver logic in zloop and SCSI ZBC. These changes are reachable from userspace and warrant fuzzing for concurrency issues, memory handling bugs, and state machine invariants.",
"WorthFuzzing": true
} |
| 1/1 | 2026/10/05 10:28 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 6033a37c315506cd3e921d4f74ddc01ec80d3808\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Mon Oct 5 10:28:25 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/Documentation/admin-guide/blockdev/zoned_loop.rst b/Documentation/admin-guide/blockdev/zoned_loop.rst\nindex 64277494fb36a..ec39f141af8d6 100644\n--- a/Documentation/admin-guide/blockdev/zoned_loop.rst\n+++ b/Documentation/admin-guide/blockdev/zoned_loop.rst\n@@ -61,7 +61,7 @@ The options available for the add command can be listed by reading the\n /dev/zloop-control device::\n \n \t$ cat /dev/zloop-control\n- add id=%d,capacity_mb=%u,zone_size_mb=%u,zone_capacity_mb=%u,conv_zones=%u,max_open_zones=%u,base_dir=%s,nr_queues=%u,queue_depth=%u,buffered_io,zone_append=%u,ordered_zone_append,discard_write_cache\n+ add id=%d,capacity_mb=%u,zone_size_mb=%u,zone_capacity_mb=%u,conv_zones=%u,max_open_zones=%u,base_dir=%s,nr_queues=%u,queue_depth=%u,buffered_io,zone_append=%u,ordered_zone_append,discard_write_cache,stor_elements=%u\n remove id=%d\n \n In more details, the options that can be used with the \"add\" command are as\n@@ -113,6 +113,12 @@ discard_write_cache Discard all data that was not explicitly persisted using a\n each zone file to the size recorded during the last flush\n operation. This simulates power fail events where\n uncommitted data is lost.\n+stor_elements Control storage element emulation. The default value is 0,\n+ indicating no emulation. A value of 1 indicates that all\n+ access storage elements (equivalent to read+write head of\n+ a disk) are emulated. A value of 2 enables fractional\n+ access storage element (equivalent to pairs of read and\n+ write heads of a disk) emulation .\n =================== =========================================================\n \n 3) Deleting a Zoned Device\ndiff --git a/block/blk-core.c b/block/blk-core.c\nindex 13dc70e8f55d9..f098a31d19aa4 100644\n--- a/block/blk-core.c\n+++ b/block/blk-core.c\n@@ -866,6 +866,11 @@ void submit_bio_noacct(struct bio *bio)\n \n \tswitch (bio_op(bio)) {\n \tcase REQ_OP_READ:\n+\t\tif (bdev_is_zoned(bdev) \u0026\u0026\n+\t\t bdev_zone_is_offline(bdev, bio-\u003ebi_iter.bi_sector)) {\n+\t\t\tbio_set_flag(bio, BIO_QUIET);\n+\t\t\tgoto end_io;\n+\t\t}\n \t\tbreak;\n \tcase REQ_OP_WRITE:\n \t\tif (bio-\u003ebi_opf \u0026 REQ_ATOMIC) {\ndiff --git a/block/blk-zoned.c b/block/blk-zoned.c\nindex 19268afb8752e..62b9cf21e9adf 100644\n--- a/block/blk-zoned.c\n+++ b/block/blk-zoned.c\n@@ -18,6 +18,8 @@\n #include \u003clinux/mempool.h\u003e\n #include \u003clinux/kthread.h\u003e\n #include \u003clinux/freezer.h\u003e\n+#include \u003clinux/delay.h\u003e\n+#include \u003clinux/uaccess.h\u003e\n \n #include \u003ctrace/events/block.h\u003e\n \n@@ -308,6 +310,24 @@ bool bdev_zone_is_seq(struct block_device *bdev, sector_t sector)\n }\n EXPORT_SYMBOL_GPL(bdev_zone_is_seq);\n \n+/**\n+ * bdev_zone_is_offline - check if a sector belongs to an offline zone\n+ * @bdev: block device to check\n+ * @sector: sector number\n+ *\n+ * Check if @sector on @bdev is contained in an offline zone.\n+ */\n+bool bdev_zone_is_offline(struct block_device *bdev, sector_t sector)\n+{\n+\tenum blk_zone_cond cond;\n+\n+\tif (!bdev_is_zoned(bdev))\n+\t\treturn false;\n+\n+\tcond = disk_zone_get_cond(bdev-\u003ebd_disk, sector);\n+\treturn cond == BLK_ZONE_COND_OFFLINE;\n+}\n+\n /**\n * bdev_zone_mgmt_allowed - check if management operations are allowed on a zone\n * @bdev: block device to check\n@@ -2700,5 +2720,283 @@ int queue_zone_wplugs_show(void *data, struct seq_file *m)\n \n \treturn 0;\n }\n-\n #endif\n+\n+static void disk_wait_for_se_mgmt_completion(struct gendisk *disk)\n+{\n+\tstruct blk_storage_element *elements, *e;\n+\tunsigned int i, nr_se, nr_elements = 0;\n+\tint ret;\n+\n+\tret = (disk-\u003efops-\u003ese_ops-\u003ereport_elements)(disk, \u0026nr_elements, NULL);\n+\tif (ret) {\n+\t\tpr_err(\"Failed to get number of storage elements\\n\");\n+\t\treturn;\n+\t}\n+\n+\telements = kzalloc_objs(struct blk_storage_element, nr_elements);\n+\tif (!elements)\n+\t\treturn;\n+\n+\twhile (1) {\n+\t\t/*\n+\t\t * Check if we have storage elements being removed or restored.\n+\t\t */\n+\t\tnr_se = nr_elements;\n+\t\tret = (disk-\u003efops-\u003ese_ops-\u003ereport_elements)(disk,\n+\t\t\t\t\t\t\u0026nr_elements, elements);\n+\t\tif (ret) {\n+\t\t\tpr_err(\"Failed to get storage elements\\n\");\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\te = elements;\n+\t\tfor (i = 0; i \u003c nr_se; i++, e++) {\n+\t\t\tif (e-\u003estatus == BLK_SE_STS_REMOVE_IN_PROGRESS ||\n+\t\t\t e-\u003estatus == BLK_SE_STS_RESTORE_IN_PROGRESS)\n+\t\t\t\tbreak;\n+\t\t}\n+\t\tif (i \u003e= nr_se)\n+\t\t\tbreak;\n+\n+\t\t/* Not done yet: wait and retry. */\n+\t\tmsleep(500);\n+\t}\n+\n+\tkfree(elements);\n+}\n+\n+/**\n+ * bdev_report_storage_elements - report the storage elements of a block device\n+ *\n+ * Fill at most @nr_elements storage element descriptors in the array @elements.\n+ * The number of storage elements filled in the array is returned using\n+ * @nr_elements. If @elements is NULL, only @nr_elements is returned.\n+ *\n+ * Returns 0 on success and a negative error code on failure.\n+ */\n+int bdev_report_storage_elements(struct block_device *bdev,\n+\t\t\t\t unsigned int *nr_elements,\n+\t\t\t\t struct blk_storage_element *elements)\n+{\n+\tstruct gendisk *disk = bdev-\u003ebd_disk;\n+\n+\tif (!bdev_is_zoned(bdev) || !disk-\u003efops-\u003ese_ops)\n+\t\treturn -EOPNOTSUPP;\n+\n+\tif (!nr_elements)\n+\t\treturn -EINVAL;\n+\n+\tif (*nr_elements \u0026\u0026 !elements)\n+\t\treturn -EINVAL;\n+\n+\treturn (disk-\u003efops-\u003ese_ops-\u003ereport_elements)(disk, nr_elements,\n+\t\t\t\t\t\t elements);\n+}\n+EXPORT_SYMBOL_GPL(bdev_report_storage_elements);\n+\n+static int blkdev_get_nr_storage_elements_ioctl(struct block_device *bdev,\n+\t\t\t\t\t\tvoid __user *argp)\n+{\n+\tunsigned int nr_elements = 0;\n+\tint ret;\n+\n+\tret = bdev_report_storage_elements(bdev, \u0026nr_elements, NULL);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tif (put_user(nr_elements, (unsigned int __user *)argp))\n+\t\treturn -EFAULT;\n+\n+\treturn 0;\n+}\n+\n+static int blkdev_report_storage_elements_ioctl(struct block_device *bdev,\n+\t\t\t\t\t\tvoid __user *argp)\n+{\n+\tstruct blk_storage_elements_report rep;\n+\tstruct blk_storage_element *elements;\n+\tunsigned int nr_elements;\n+\tunsigned long retc;\n+\tint ret;\n+\n+\tif (!argp)\n+\t\treturn -EINVAL;\n+\n+\tif (copy_from_user(\u0026rep, argp,\n+\t\t\t sizeof(struct blk_storage_elements_report)))\n+\t\treturn -EFAULT;\n+\n+\tif (!rep.nr_elements)\n+\t\treturn -EINVAL;\n+\n+\tnr_elements = rep.nr_elements;\n+\telements = kzalloc_objs(struct blk_storage_element, nr_elements);\n+\tif (!elements)\n+\t\treturn -ENOMEM;\n+\n+\tret = bdev_report_storage_elements(bdev, \u0026nr_elements, elements);\n+\tif (ret)\n+\t\tgoto free_elements;\n+\n+\tretc = copy_to_user(argp + sizeof(struct blk_storage_elements_report),\n+\t\t\t elements,\n+\t\t\t sizeof(struct blk_storage_element) * nr_elements);\n+\tif (retc) {\n+\t\tret = -EFAULT;\n+\t\tgoto free_elements;\n+\t}\n+\n+\trep.nr_elements = nr_elements;\n+\tretc = copy_to_user(argp, \u0026rep,\n+\t\t\t sizeof(struct blk_storage_elements_report));\n+\tif (retc)\n+\t\tret = -EFAULT;\n+\n+free_elements:\n+\tkfree(elements);\n+\treturn ret;\n+}\n+\n+/**\n+ * bdev_remove_storage_element - Remove (depopulate) a storage element of a\n+ *\t\t\t\t block device\n+ *\n+ * Remove (depopulate) the storage element identified by @element_id from the\n+ * block device @bdev.\n+ *\n+ * Returns 0 on success and a negative error code on failure.\n+ */\n+int bdev_remove_storage_element(struct block_device *bdev,\n+\t\t\t\tunsigned int element_id)\n+{\n+\tstruct gendisk *disk = bdev-\u003ebd_disk;\n+\tunsigned int memflags;\n+\tint ret;\n+\n+\tif (!bdev_is_zoned(bdev) || !disk-\u003efops-\u003ese_ops)\n+\t\treturn -EOPNOTSUPP;\n+\n+\t/* Zero is not a valid storage element ID. */\n+\tif (!element_id)\n+\t\treturn -EINVAL;\n+\n+\t/*\n+\t * Freeze and unfreeze the queue to flush any outstanding command.\n+\t * The caller is responsible for not queuing up more I/Os by higher\n+\t * level means.\n+\t */\n+\tmemflags = blk_mq_freeze_queue(disk-\u003equeue);\n+\tblk_mq_unfreeze_queue(disk-\u003equeue, memflags);\n+\n+\t/*\n+\t * Flush the volatile write cache if there is any. Note that this may\n+\t * lead to errors if degraded storage elements are used. So ignore\n+\t * errors here.\n+\t */\n+\tblkdev_issue_flush(disk-\u003epart0);\n+\n+\t/* Invalidate all cached data. */\n+\tinvalidate_inode_pages2_range(bdev-\u003ebd_mapping, 0,\n+\t\t\t\t get_capacity(disk) \u003c\u003c SECTOR_SHIFT);\n+\n+\tret = (disk-\u003efops-\u003ese_ops-\u003eremove_element)(disk, element_id);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t/* Revalidate the device zones once the opration completes. */\n+\tdisk_wait_for_se_mgmt_completion(disk);\n+\n+\treturn blk_revalidate_disk_zones(disk);\n+}\n+EXPORT_SYMBOL_GPL(bdev_remove_storage_element);\n+\n+static int blkdev_remove_storage_element_ioctl(struct block_device *bdev,\n+\t\t\t\t\tblk_mode_t mode, void __user *argp)\n+{\n+\tunsigned int element_id;\n+\n+\tif (!(mode \u0026 BLK_OPEN_WRITE))\n+\t\treturn -EBADF;\n+\tif (bdev_read_only(bdev))\n+\t\treturn -EPERM;\n+\n+\tif (get_user(element_id, (unsigned int __user *)argp))\n+\t\treturn -EFAULT;\n+\n+\treturn bdev_remove_storage_element(bdev, element_id);\n+}\n+\n+/**\n+ * bdev_restore_storage_elements - Restore all depopulated storage elements of a\n+ *\t\t\t\t block device\n+ *\n+ * Restore all storage elements of @bdev that have been depopulated. Not all\n+ * elements may be restored by this operation.\n+ *\n+ * Returns 0 on success and a negative error code on failure.\n+ */\n+int bdev_restore_storage_elements(struct block_device *bdev)\n+{\n+\tstruct gendisk *disk = bdev-\u003ebd_disk;\n+\tunsigned int memflags;\n+\tint ret;\n+\n+\tif (!bdev_is_zoned(bdev) || !disk-\u003efops-\u003ese_ops)\n+\t\treturn -EOPNOTSUPP;\n+\n+\t/*\n+\t * Freeze and unfreeze the queue to flush any outstanding commands.\n+\t * The caller is responsible for not queuing up more I/O by higher\n+\t * level means.\n+\t */\n+\tmemflags = blk_mq_freeze_queue(disk-\u003equeue);\n+\tblk_mq_unfreeze_queue(disk-\u003equeue, memflags);\n+\n+\t/* Invalidate all cached data. */\n+\tinvalidate_inode_pages2_range(bdev-\u003ebd_mapping, 0,\n+\t\t\t\t get_capacity(disk) \u003c\u003c SECTOR_SHIFT);\n+\n+\tret = (disk-\u003efops-\u003ese_ops-\u003erestore_elements)(disk);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tdisk_wait_for_se_mgmt_completion(disk);\n+\n+\treturn blk_revalidate_disk_zones(disk);\n+}\n+EXPORT_SYMBOL_GPL(bdev_restore_storage_elements);\n+\n+static int blkdev_restore_storage_elements_ioctl(struct block_device *bdev,\n+\t\t\t\t\t\t blk_mode_t mode)\n+{\n+\tif (!(mode \u0026 BLK_OPEN_WRITE))\n+\t\treturn -EBADF;\n+\tif (bdev_read_only(bdev))\n+\t\treturn -EPERM;\n+\n+\treturn bdev_restore_storage_elements(bdev);\n+}\n+\n+int blkdev_zone_storage_elements_ioctl(struct block_device *bdev,\n+\t\t\t\t blk_mode_t mode, unsigned int cmd,\n+\t\t\t\t void __user *argp)\n+{\n+\tif (!bdev_is_zoned(bdev) || !bdev-\u003ebd_disk-\u003efops-\u003ese_ops)\n+\t\treturn -ENOTTY;\n+\n+\tswitch (cmd) {\n+\tcase BLKGETNRSTORELEMS:\n+\t\treturn blkdev_get_nr_storage_elements_ioctl(bdev, argp);\n+\tcase BLKREPORTSTORELEMS:\n+\t\treturn blkdev_report_storage_elements_ioctl(bdev, argp);\n+\tcase BLKREMOVESTORELEM:\n+\t\treturn blkdev_remove_storage_element_ioctl(bdev, mode, argp);\n+\tcase BLKRESTORESTORELEMS:\n+\t\treturn blkdev_restore_storage_elements_ioctl(bdev, mode);\n+\tdefault:\n+\t\tbreak;\n+\t}\n+\n+\treturn -ENOTTY;\n+}\ndiff --git a/block/blk.h b/block/blk.h\nindex 2cc03aa54c532..274afb46a809a 100644\n--- a/block/blk.h\n+++ b/block/blk.h\n@@ -578,6 +578,10 @@ int blkdev_report_zones_ioctl(struct block_device *bdev, unsigned int cmd,\n int blkdev_zone_mgmt_ioctl(struct block_device *bdev, blk_mode_t mode,\n \t\tunsigned int cmd, unsigned long arg);\n bool bdev_zone_mgmt_allowed(struct block_device *bdev, sector_t sector);\n+bool bdev_zone_is_offline(struct block_device *bdev, sector_t sector);\n+int blkdev_zone_storage_elements_ioctl(struct block_device *bdev,\n+\t\t\t\t blk_mode_t mode, unsigned int cmd,\n+\t\t\t\t void __user *argp);\n #else /* CONFIG_BLK_DEV_ZONED */\n static inline void disk_init_zone_resources(struct gendisk *disk)\n {\n@@ -625,6 +629,17 @@ static inline bool bdev_zone_mgmt_allowed(struct block_device *bdev,\n {\n \treturn false;\n }\n+static inline bool bdev_zone_is_offline(struct block_device *bdev,\n+\t\t\t\t\tsector_t sector)\n+{\n+\treturn false;\n+}\n+static inline int blkdev_zone_storage_elements_ioctl(struct block_device *bdev,\n+\t\t\t\t\tblk_mode_t mode, unsigned int cmd,\n+\t\t\t\t\tvoid __user *argp)\n+{\n+\treturn -ENOTTY;\n+}\n #endif /* CONFIG_BLK_DEV_ZONED */\n \n struct block_device *bdev_alloc(struct gendisk *disk, u8 partno);\ndiff --git a/block/ioctl.c b/block/ioctl.c\nindex 64b4e6c0f6965..ccf806c2e37d1 100644\n--- a/block/ioctl.c\n+++ b/block/ioctl.c\n@@ -679,6 +679,11 @@ static int blkdev_common_ioctl(struct block_device *bdev, blk_mode_t mode,\n \t\treturn put_uint(argp, bdev_zone_sectors(bdev));\n \tcase BLKGETNRZONES:\n \t\treturn put_uint(argp, bdev_nr_zones(bdev));\n+\tcase BLKGETNRSTORELEMS:\n+\tcase BLKREPORTSTORELEMS:\n+\tcase BLKREMOVESTORELEM:\n+\tcase BLKRESTORESTORELEMS:\n+\t\treturn blkdev_zone_storage_elements_ioctl(bdev, mode, cmd, argp);\n \tcase BLKROGET:\n \t\treturn put_int(argp, bdev_read_only(bdev) != 0);\n \tcase BLKSSZGET: /* get block device logical block size */\ndiff --git a/drivers/block/zloop.c b/drivers/block/zloop.c\nindex f0ca221524db6..1d51060b832bc 100644\n--- a/drivers/block/zloop.c\n+++ b/drivers/block/zloop.c\n@@ -37,6 +37,8 @@ enum {\n \tZLOOP_OPT_ORDERED_ZONE_APPEND\t= (1 \u003c\u003c 10),\n \tZLOOP_OPT_DISCARD_WRITE_CACHE\t= (1 \u003c\u003c 11),\n \tZLOOP_OPT_MAX_OPEN_ZONES\t= (1 \u003c\u003c 12),\n+\tZLOOP_OPT_STOR_ELEMENTS\t\t= (1 \u003c\u003c 13),\n+\tZLOOP_OPT_ELEMENT_ID\t\t= (1 \u003c\u003c 14),\n };\n \n static const match_table_t zloop_opt_tokens = {\n@@ -51,11 +53,23 @@ static const match_table_t zloop_opt_tokens = {\n \t{ ZLOOP_OPT_BUFFERED_IO,\t\"buffered_io\"\t\t},\n \t{ ZLOOP_OPT_ZONE_APPEND,\t\"zone_append=%u\"\t},\n \t{ ZLOOP_OPT_ORDERED_ZONE_APPEND, \"ordered_zone_append\"\t},\n-\t{ ZLOOP_OPT_DISCARD_WRITE_CACHE, \"discard_write_cache\" },\n+\t{ ZLOOP_OPT_DISCARD_WRITE_CACHE, \"discard_write_cache\"\t},\n \t{ ZLOOP_OPT_MAX_OPEN_ZONES,\t\"max_open_zones=%u\"\t},\n+\t{ ZLOOP_OPT_STOR_ELEMENTS,\t\"stor_elements=%u\"\t},\n+\t{ ZLOOP_OPT_ELEMENT_ID,\t\t\"element_id=%u\"\t\t},\n \t{ ZLOOP_OPT_ERR,\t\tNULL\t\t\t}\n };\n \n+/* Storage elements emulation types. */\n+enum zloop_stor_elements {\n+\t/* No emulation. */\n+\tZLOOP_STOR_ELEMENTS_NONE,\n+\t/* Emulate read+write storage elements. */\n+\tZLOOP_STOR_ELEMENTS_RDWR,\n+\t/* Emulate pairs of associated read and write storage elements. */\n+\tZLOOP_STOR_ELEMENTS_PAIRS,\n+};\n+\n /* Default values for the \"add\" operation. */\n #define ZLOOP_DEF_ID\t\t\t-1\n #define ZLOOP_DEF_ZONE_SIZE\t\t((256ULL * SZ_1M) \u003e\u003e SECTOR_SHIFT)\n@@ -68,6 +82,8 @@ static const match_table_t zloop_opt_tokens = {\n #define ZLOOP_DEF_BUFFERED_IO\t\tfalse\n #define ZLOOP_DEF_ZONE_APPEND\t\ttrue\n #define ZLOOP_DEF_ORDERED_ZONE_APPEND\tfalse\n+#define ZLOOP_DEF_STOR_ELEMENTS\t\tZLOOP_STOR_ELEMENTS_NONE\n+#define ZLOOP_DEF_ELEMENT_ID\t\t0\n \n /* Arbitrary limit on the zone size (16GB). */\n #define ZLOOP_MAX_ZONE_SIZE_MB\t\t16384\n@@ -87,6 +103,8 @@ struct zloop_options {\n \tbool\t\t\tzone_append;\n \tbool\t\t\tordered_zone_append;\n \tbool\t\t\tdiscard_write_cache;\n+\tenum zloop_stor_elements stor_elements;\n+\tunsigned int\t\telement_id;\n };\n \n /*\n@@ -117,6 +135,8 @@ struct zloop_zone {\n \tenum blk_zone_cond\tcond;\n \tsector_t\t\tstart;\n \tsector_t\t\twp;\n+\tunsigned int\t\twr_se_id;\n+\tunsigned int\t\trd_se_id;\n \n \tgfp_t\t\t\told_gfp_mask;\n };\n@@ -133,6 +153,7 @@ struct zloop_device {\n \tbool\t\t\tzone_append;\n \tbool\t\t\tordered_zone_append;\n \tbool\t\t\tdiscard_write_cache;\n+\tenum zloop_stor_elements stor_elements;\n \n \tconst char\t\t*base_dir;\n \tstruct file\t\t*data_dir;\n@@ -150,6 +171,17 @@ struct zloop_device {\n \tstruct list_head\topen_zones_lru_list;\n \tunsigned int\t\tnr_open_zones;\n \n+\t/* For storage elements emulation. */\n+\tstruct mutex\t\tstor_elements_lock;\n+\tunsigned int\t\tnr_elements;\n+\tunsigned int\t\tmax_nr_removed_elements;\n+\tunsigned int\t\tnr_removed_elements;\n+\tstruct delayed_work\tremove_element_work;\n+\tunsigned int\t\tremove_element_id;\n+\tstruct delayed_work\trestore_elements_work;\n+\tbool\t\t\trestore_in_progress;\n+\tstruct blk_storage_element *elements;\n+\n \tstruct zloop_zone\tzones[] __counted_by(nr_zones);\n };\n \n@@ -173,6 +205,29 @@ static unsigned int rq_zone_no(struct request *rq)\n \treturn blk_rq_pos(rq) \u003e\u003e zlo-\u003ezone_shift;\n }\n \n+static bool zloop_zone_healthy(struct zloop_device *zlo,\n+\t\t\t struct zloop_zone *zone, bool write)\n+{\n+\tstruct blk_storage_element *se;\n+\n+\tif (!zlo-\u003enr_elements)\n+\t\treturn true;\n+\n+\t/* Check the zone condition first. */\n+\tif (zone-\u003econd == BLK_ZONE_COND_OFFLINE)\n+\t\treturn false;\n+\tif (zone-\u003econd == BLK_ZONE_COND_READONLY \u0026\u0026 write)\n+\t\treturn false;\n+\n+\t/* Check the health state of the storage element serving the zone. */\n+\tif (write)\n+\t\tse = \u0026zlo-\u003eelements[zone-\u003ewr_se_id - 1];\n+\telse\n+\t\tse = \u0026zlo-\u003eelements[zone-\u003erd_se_id - 1];\n+\n+\treturn se-\u003estatus == BLK_SE_STS_DEGRADED;\n+}\n+\n /*\n * Open an already open zone. This is mostly a no-op, except for the imp open -\u003e\n * exp open condition change that may happen. We also move a zone at the tail of\n@@ -289,22 +344,30 @@ static bool zloop_do_open_zone(struct zloop_device *zlo,\n \t}\n }\n \n-static void zloop_mark_full(struct zloop_device *zlo, struct zloop_zone *zone)\n+static void zloop_set_zone_cond(struct zloop_device *zlo,\n+\t\t\t\tstruct zloop_zone *zone,\n+\t\t\t\tenum blk_zone_cond cond)\n {\n \tlockdep_assert_held(\u0026zone-\u003ewp_lock);\n \n \tzloop_lru_remove_open_zone(zlo, zone);\n-\tzone-\u003econd = BLK_ZONE_COND_FULL;\n-\tzone-\u003ewp = ULLONG_MAX;\n+\tzone-\u003econd = cond;\n+\tif (cond == BLK_ZONE_COND_EMPTY)\n+\t\tzone-\u003ewp = zone-\u003estart;\n+\telse\n+\t\tzone-\u003ewp = ULLONG_MAX;\n }\n \n-static void zloop_mark_empty(struct zloop_device *zlo, struct zloop_zone *zone)\n+static inline void zloop_set_zone_full(struct zloop_device *zlo,\n+\t\t\t\t struct zloop_zone *zone)\n {\n-\tlockdep_assert_held(\u0026zone-\u003ewp_lock);\n+\tzloop_set_zone_cond(zlo, zone, BLK_ZONE_COND_FULL);\n+}\n \n-\tzloop_lru_remove_open_zone(zlo, zone);\n-\tzone-\u003econd = BLK_ZONE_COND_EMPTY;\n-\tzone-\u003ewp = zone-\u003estart;\n+static inline void zloop_set_zone_empty(struct zloop_device *zlo,\n+\t\t\t\t\tstruct zloop_zone *zone)\n+{\n+\tzloop_set_zone_cond(zlo, zone, BLK_ZONE_COND_EMPTY);\n }\n \n static int zloop_update_seq_zone(struct zloop_device *zlo, unsigned int zone_no)\n@@ -339,9 +402,9 @@ static int zloop_update_seq_zone(struct zloop_device *zlo, unsigned int zone_no)\n \n \tspin_lock(\u0026zone-\u003ewp_lock);\n \tif (!file_sectors) {\n-\t\tzloop_mark_empty(zlo, zone);\n+\t\tzloop_set_zone_empty(zlo, zone);\n \t} else if (file_sectors == zlo-\u003ezone_capacity) {\n-\t\tzloop_mark_full(zlo, zone);\n+\t\tzloop_set_zone_full(zlo, zone);\n \t} else {\n \t\tif (zone-\u003econd != BLK_ZONE_COND_IMP_OPEN \u0026\u0026\n \t\t zone-\u003econd != BLK_ZONE_COND_EXP_OPEN)\n@@ -363,6 +426,12 @@ static int zloop_open_zone(struct zloop_device *zlo, unsigned int zone_no)\n \n \tmutex_lock(\u0026zone-\u003elock);\n \n+\tif (zone-\u003econd == BLK_ZONE_COND_OFFLINE ||\n+\t zone-\u003econd == BLK_ZONE_COND_READONLY) {\n+\t\tret = -EIO;\n+\t\tgoto unlock;\n+\t}\n+\n \tif (test_and_clear_bit(ZLOOP_ZONE_SEQ_ERROR, \u0026zone-\u003eflags)) {\n \t\tret = zloop_update_seq_zone(zlo, zone_no);\n \t\tif (ret)\n@@ -388,6 +457,12 @@ static int zloop_close_zone(struct zloop_device *zlo, unsigned int zone_no)\n \n \tmutex_lock(\u0026zone-\u003elock);\n \n+\tif (zone-\u003econd == BLK_ZONE_COND_OFFLINE ||\n+\t zone-\u003econd == BLK_ZONE_COND_READONLY) {\n+\t\tret = -EIO;\n+\t\tgoto unlock;\n+\t}\n+\n \tif (test_and_clear_bit(ZLOOP_ZONE_SEQ_ERROR, \u0026zone-\u003eflags)) {\n \t\tret = zloop_update_seq_zone(zlo, zone_no);\n \t\tif (ret)\n@@ -420,7 +495,22 @@ static int zloop_close_zone(struct zloop_device *zlo, unsigned int zone_no)\n \treturn ret;\n }\n \n-static int zloop_reset_zone(struct zloop_device *zlo, unsigned int zone_no)\n+static int zloop_do_reset_zone(struct zloop_device *zlo,\n+\t\t\t struct zloop_zone *zone)\n+{\n+\tif (vfs_truncate(\u0026zone-\u003efile-\u003ef_path, 0))\n+\t\treturn -EIO;\n+\n+\tspin_lock(\u0026zone-\u003ewp_lock);\n+\tzloop_set_zone_empty(zlo, zone);\n+\tclear_bit(ZLOOP_ZONE_SEQ_ERROR, \u0026zone-\u003eflags);\n+\tspin_unlock(\u0026zone-\u003ewp_lock);\n+\n+\treturn 0;\n+}\n+\n+static int zloop_reset_zone(struct zloop_device *zlo, unsigned int zone_no,\n+\t\t\t bool all_zones)\n {\n \tstruct zloop_zone *zone = \u0026zlo-\u003ezones[zone_no];\n \tint ret = 0;\n@@ -430,20 +520,20 @@ static int zloop_reset_zone(struct zloop_device *zlo, unsigned int zone_no)\n \n \tmutex_lock(\u0026zone-\u003elock);\n \n+\tif (zone-\u003econd == BLK_ZONE_COND_OFFLINE ||\n+\t zone-\u003econd == BLK_ZONE_COND_READONLY) {\n+\t\tif (!all_zones)\n+\t\t\tret = -EIO;\n+\t\tgoto unlock;\n+\t}\n+\n \tif (!test_bit(ZLOOP_ZONE_SEQ_ERROR, \u0026zone-\u003eflags) \u0026\u0026\n \t zone-\u003econd == BLK_ZONE_COND_EMPTY)\n \t\tgoto unlock;\n \n-\tif (vfs_truncate(\u0026zone-\u003efile-\u003ef_path, 0)) {\n+\tret = zloop_do_reset_zone(zlo, zone);\n+\tif (ret)\n \t\tset_bit(ZLOOP_ZONE_SEQ_ERROR, \u0026zone-\u003eflags);\n-\t\tret = -EIO;\n-\t\tgoto unlock;\n-\t}\n-\n-\tspin_lock(\u0026zone-\u003ewp_lock);\n-\tzloop_mark_empty(zlo, zone);\n-\tclear_bit(ZLOOP_ZONE_SEQ_ERROR, \u0026zone-\u003eflags);\n-\tspin_unlock(\u0026zone-\u003ewp_lock);\n \n unlock:\n \tmutex_unlock(\u0026zone-\u003elock);\n@@ -457,7 +547,7 @@ static int zloop_reset_all_zones(struct zloop_device *zlo)\n \tint ret;\n \n \tfor (i = zlo-\u003enr_conv_zones; i \u003c zlo-\u003enr_zones; i++) {\n-\t\tret = zloop_reset_zone(zlo, i);\n+\t\tret = zloop_reset_zone(zlo, i, true);\n \t\tif (ret)\n \t\t\treturn ret;\n \t}\n@@ -475,6 +565,12 @@ static int zloop_finish_zone(struct zloop_device *zlo, unsigned int zone_no)\n \n \tmutex_lock(\u0026zone-\u003elock);\n \n+\tif (zone-\u003econd == BLK_ZONE_COND_OFFLINE ||\n+\t zone-\u003econd == BLK_ZONE_COND_READONLY) {\n+\t\tret = -EIO;\n+\t\tgoto unlock;\n+\t}\n+\n \tif (!test_bit(ZLOOP_ZONE_SEQ_ERROR, \u0026zone-\u003eflags) \u0026\u0026\n \t zone-\u003econd == BLK_ZONE_COND_FULL)\n \t\tgoto unlock;\n@@ -487,7 +583,7 @@ static int zloop_finish_zone(struct zloop_device *zlo, unsigned int zone_no)\n \t}\n \n \tspin_lock(\u0026zone-\u003ewp_lock);\n-\tzloop_mark_full(zlo, zone);\n+\tzloop_set_zone_full(zlo, zone);\n \tclear_bit(ZLOOP_ZONE_SEQ_ERROR, \u0026zone-\u003eflags);\n \tspin_unlock(\u0026zone-\u003ewp_lock);\n \n@@ -624,7 +720,7 @@ static int zloop_seq_write_prep(struct zloop_cmd *cmd)\n \tif (!is_append || !zlo-\u003eordered_zone_append) {\n \t\tzone-\u003ewp += nr_sectors;\n \t\tif (zone-\u003ewp == zone_end)\n-\t\t\tzloop_mark_full(zlo, zone);\n+\t\t\tzloop_set_zone_full(zlo, zone);\n \t}\n out_unlock:\n \tspin_unlock(\u0026zone-\u003ewp_lock);\n@@ -664,6 +760,9 @@ static void zloop_rw(struct zloop_cmd *cmd)\n \t\t\t zone-\u003estart + zlo-\u003ezone_size))\n \t\tgoto out;\n \n+\tif (!zloop_zone_healthy(zlo, zone, is_write))\n+\t\tgoto out;\n+\n \tif (test_and_clear_bit(ZLOOP_ZONE_SEQ_ERROR, \u0026zone-\u003eflags)) {\n \t\tmutex_lock(\u0026zone-\u003elock);\n \t\tret = zloop_update_seq_zone(zlo, zone_no);\n@@ -766,7 +865,7 @@ static void zloop_handle_cmd(struct zloop_cmd *cmd)\n \t\tcmd-\u003eret = zloop_flush(zlo);\n \t\tbreak;\n \tcase REQ_OP_ZONE_RESET:\n-\t\tcmd-\u003eret = zloop_reset_zone(zlo, rq_zone_no(rq));\n+\t\tcmd-\u003eret = zloop_reset_zone(zlo, rq_zone_no(rq), false);\n \t\tbreak;\n \tcase REQ_OP_ZONE_RESET_ALL:\n \t\tcmd-\u003eret = zloop_reset_all_zones(zlo);\n@@ -877,7 +976,7 @@ static bool zloop_set_zone_append_sector(struct request *rq)\n \trq-\u003e__sector = zone-\u003ewp;\n \tzone-\u003ewp += blk_rq_sectors(rq);\n \tif (zone-\u003ewp \u003e= zone_end)\n-\t\tzloop_mark_full(zlo, zone);\n+\t\tzloop_set_zone_full(zlo, zone);\n \n \tspin_unlock(\u0026zone-\u003ewp_lock);\n \n@@ -985,11 +1084,276 @@ static int zloop_report_zones(struct gendisk *disk, sector_t sector,\n \treturn nr_zones;\n }\n \n+static int zloop_report_elements(struct gendisk *disk,\n+\t\t\t\t unsigned int *nr_elements,\n+\t\t\t\t struct blk_storage_element *elements)\n+{\n+\tstruct zloop_device *zlo = disk-\u003eprivate_data;\n+\tunsigned int nr_report = *nr_elements;\n+\n+\tif (zlo-\u003estor_elements == ZLOOP_STOR_ELEMENTS_NONE)\n+\t\treturn -EOPNOTSUPP;\n+\n+\tmutex_lock(\u0026zlo-\u003estor_elements_lock);\n+\n+\t*nr_elements = zlo-\u003enr_elements;\n+\tif (elements) {\n+\t\tstruct blk_storage_element *se = zlo-\u003eelements;\n+\t\tunsigned int i;\n+\n+\t\tfor (i = 0; i \u003c min(nr_report, zlo-\u003enr_elements); i++, se++) {\n+\t\t\tswitch (se-\u003estatus) {\n+\t\t\tcase BLK_SE_STS_REMOVED:\n+\t\t\tcase BLK_SE_STS_RESTORE_ERROR:\n+\t\t\t\tse-\u003erestore_allowed = 1;\n+\t\t\t\tbreak;\n+\t\t\tdefault:\n+\t\t\t\tse-\u003erestore_allowed = 0;\n+\t\t\t}\n+\t\t\tmemcpy(\u0026elements[i], se,\n+\t\t\t sizeof(struct blk_storage_element));\n+\t\t}\n+\t}\n+\n+\tmutex_unlock(\u0026zlo-\u003estor_elements_lock);\n+\n+\treturn 0;\n+}\n+\n+static int zloop_degrade_element(struct zloop_device *zlo,\n+\t\t\t\t unsigned int element_id)\n+{\n+\tstruct blk_storage_element *se;\n+\tint ret = 0;\n+\n+\tif (zlo-\u003estor_elements == ZLOOP_STOR_ELEMENTS_NONE)\n+\t\treturn -EOPNOTSUPP;\n+\n+\tif (!element_id || element_id \u003e zlo-\u003enr_elements)\n+\t\treturn -EINVAL;\n+\n+\tmutex_lock(\u0026zlo-\u003estor_elements_lock);\n+\n+\tse = \u0026zlo-\u003eelements[element_id - 1];\n+\tif (se-\u003estatus == BLK_SE_STS_OK)\n+\t\tse-\u003estatus = BLK_SE_STS_DEGRADED;\n+\telse\n+\t\tret = -EINVAL;\n+\n+\tmutex_unlock(\u0026zlo-\u003estor_elements_lock);\n+\n+\treturn ret;\n+}\n+\n+static void zloop_remove_element_work(struct work_struct *work)\n+{\n+\tstruct zloop_device *zlo = container_of(work, struct zloop_device,\n+\t\t\t\t\t\tremove_element_work.work);\n+\tstruct blk_storage_element *se, *paired_se = NULL;\n+\tenum blk_zone_cond cond;\n+\tstruct zloop_zone *zone;\n+\tunsigned int i;\n+\n+\tmutex_lock(\u0026zlo-\u003estor_elements_lock);\n+\n+\t/*\n+\t * If the element to remove is a read element, zones must go offline and\n+\t * the associated write element is also removed.\n+\t */\n+\tse = \u0026zlo-\u003eelements[zlo-\u003eremove_element_id - 1];\n+\tswitch (se-\u003etype) {\n+\tcase BLK_SE_TYPE_RDWR:\n+\t\tcond = BLK_ZONE_COND_OFFLINE;\n+\t\tbreak;\n+\tcase BLK_SE_TYPE_READ:\n+\t\tcond = BLK_ZONE_COND_OFFLINE;\n+\t\tpaired_se = \u0026zlo-\u003eelements[se-\u003epaired_id - 1];\n+\t\tbreak;\n+\tcase BLK_SE_TYPE_WRITE:\n+\t\tcond = BLK_ZONE_COND_READONLY;\n+\t\tbreak;\n+\tdefault:\n+\t\tWARN_ON_ONCE(1);\n+\t}\n+\n+\t/*\n+\t * Change the condition of the zones owned by the (pair of) elements\n+\t * being removed and mark the elements removed.\n+\t */\n+\tfor (i = 0, zone = zlo-\u003ezones; i \u003c zlo-\u003enr_zones; i++, zone++) {\n+\t\tif (zone-\u003ewr_se_id != se-\u003eid \u0026\u0026 zone-\u003erd_se_id != se-\u003eid)\n+\t\t\tcontinue;\n+\t\tmutex_lock(\u0026zone-\u003elock);\n+\t\tspin_lock(\u0026zone-\u003ewp_lock);\n+\t\tzloop_set_zone_cond(zlo, zone, cond);\n+\t\tspin_unlock(\u0026zone-\u003ewp_lock);\n+\t\tmutex_unlock(\u0026zone-\u003elock);\n+\t}\n+\n+\tse-\u003estatus = BLK_SE_STS_REMOVED;\n+\n+\tzlo-\u003enr_removed_elements++;\n+\tif (paired_se) {\n+\t\tpaired_se-\u003estatus = BLK_SE_STS_REMOVED;\n+\t\tzlo-\u003enr_removed_elements++;\n+\t}\n+\n+\tzlo-\u003eremove_element_id = 0;\n+\n+\tmutex_unlock(\u0026zlo-\u003estor_elements_lock);\n+}\n+\n+static int zloop_remove_element(struct gendisk *disk, unsigned int element_id)\n+{\n+\tstruct zloop_device *zlo = disk-\u003eprivate_data;\n+\tstruct blk_storage_element *se, *paired_se = NULL;\n+\tunsigned int nr_remove = 1;\n+\tint ret = 0;\n+\n+\tif (zlo-\u003estor_elements == ZLOOP_STOR_ELEMENTS_NONE)\n+\t\treturn -EOPNOTSUPP;\n+\n+\tif (element_id \u003e zlo-\u003enr_elements)\n+\t\treturn -EINVAL;\n+\n+\tmutex_lock(\u0026zlo-\u003estor_elements_lock);\n+\n+\tif (zlo-\u003eremove_element_id || zlo-\u003erestore_in_progress) {\n+\t\tret = -EBUSY;\n+\t\tgoto unlock;\n+\t}\n+\n+\t/*\n+\t * Get the element to remove. If it is already removed, we have nothing\n+\t * to do.\n+\t */\n+\tse = \u0026zlo-\u003eelements[element_id - 1];\n+\tif (se-\u003estatus == BLK_SE_STS_REMOVED)\n+\t\tgoto unlock;\n+\n+\t/*\n+\t * If the element to remove is a read element, the associated write\n+\t * element must also be removed.\n+\t */\n+\tif (se-\u003etype == BLK_SE_TYPE_READ) {\n+\t\tpaired_se = \u0026zlo-\u003eelements[se-\u003epaired_id - 1];\n+\t\tnr_remove = 2;\n+\t}\n+\n+\tif (zlo-\u003enr_removed_elements + nr_remove \u003e\n+\t zlo-\u003emax_nr_removed_elements) {\n+\t\tret = -EBUSY;\n+\t\tgoto unlock;\n+\t}\n+\n+\t/*\n+\t * Schedule the element removal with a delay, to emulate the (generally\n+\t * short) time it takes for a real device to depopulate a head and\n+\t * modify the zones.\n+\t */\n+\tzlo-\u003eremove_element_id = element_id;\n+\tse-\u003estatus = BLK_SE_STS_REMOVE_IN_PROGRESS;\n+\tif (paired_se)\n+\t\tpaired_se-\u003estatus = BLK_SE_STS_REMOVE_IN_PROGRESS;\n+\n+\tschedule_delayed_work(\u0026zlo-\u003eremove_element_work,\n+\t\t\t msecs_to_jiffies(2000));\n+\n+unlock:\n+\tmutex_unlock(\u0026zlo-\u003estor_elements_lock);\n+\n+\treturn ret;\n+}\n+\n+static void zloop_restore_elements_work(struct work_struct *work)\n+{\n+\tstruct zloop_device *zlo = container_of(work, struct zloop_device,\n+\t\t\t\t\t\trestore_elements_work.work);\n+\tstruct zloop_zone *zone = zlo-\u003ezones;\n+\tstruct blk_storage_element *se;\n+\tunsigned int i;\n+\tint ret = 0;\n+\n+\tmutex_lock(\u0026zlo-\u003estor_elements_lock);\n+\n+\t/* Reset all zones. */\n+\tfor (i = 0; i \u003c zlo-\u003enr_zones \u0026\u0026 ret == 0; i++, zone++) {\n+\t\tmutex_lock(\u0026zone-\u003elock);\n+\t\tif (test_bit(ZLOOP_ZONE_CONV, \u0026zone-\u003eflags)) {\n+\t\t\tspin_lock(\u0026zone-\u003ewp_lock);\n+\t\t\tzloop_set_zone_cond(zlo, zone, BLK_ZONE_COND_NOT_WP);\n+\t\t\tspin_unlock(\u0026zone-\u003ewp_lock);\n+\t\t} else {\n+\t\t\tret = zloop_do_reset_zone(zlo, zone);\n+\t\t}\n+\t\tmutex_unlock(\u0026zone-\u003elock);\n+\t}\n+\n+\t/* Restore all removed elements. */\n+\tfor (i = 0, se = zlo-\u003eelements; i \u003c zlo-\u003enr_elements; i++, se++) {\n+\t\tif (se-\u003estatus != BLK_SE_STS_RESTORE_IN_PROGRESS)\n+\t\t\tcontinue;\n+\t\tif (!ret)\n+\t\t\tse-\u003estatus = BLK_SE_STS_OK;\n+\t\telse\n+\t\t\tse-\u003estatus = BLK_SE_STS_RESTORE_ERROR;\n+\t}\n+\n+\tzlo-\u003enr_removed_elements = 0;\n+\tzlo-\u003erestore_in_progress = false;\n+\n+\tmutex_unlock(\u0026zlo-\u003estor_elements_lock);\n+}\n+\n+static int zloop_restore_elements(struct gendisk *disk)\n+{\n+\tstruct zloop_device *zlo = disk-\u003eprivate_data;\n+\tstruct blk_storage_element *se;\n+\tunsigned int i;\n+\tint ret = 0;\n+\n+\tif (zlo-\u003estor_elements == ZLOOP_STOR_ELEMENTS_NONE)\n+\t\treturn -EOPNOTSUPP;\n+\n+\tmutex_lock(\u0026zlo-\u003estor_elements_lock);\n+\n+\tif (zlo-\u003eremove_element_id || zlo-\u003erestore_in_progress) {\n+\t\tret = -EBUSY;\n+\t\tgoto unlock;\n+\t}\n+\n+\t/* If we have no removed elements, we have nothing to do. */\n+\tif (!zlo-\u003enr_removed_elements)\n+\t\tgoto unlock;\n+\n+\t/*\n+\t * Schedule the elements restoration with a delay, to emulate the time\n+\t * it takes for a real device to restore all removed heads and reset\n+\t * all zones.\n+\t */\n+\tzlo-\u003erestore_in_progress = true;\n+\tfor (i = 0, se = zlo-\u003eelements; i \u003c zlo-\u003enr_elements; i++, se++) {\n+\t\tif (se-\u003estatus == BLK_SE_STS_REMOVED)\n+\t\t\tse-\u003estatus = BLK_SE_STS_RESTORE_IN_PROGRESS;\n+\t}\n+\n+\tschedule_delayed_work(\u0026zlo-\u003erestore_elements_work,\n+\t\t\t msecs_to_jiffies(5000));\n+\n+unlock:\n+\tmutex_unlock(\u0026zlo-\u003estor_elements_lock);\n+\n+\treturn ret;\n+}\n+\n static void zloop_free_disk(struct gendisk *disk)\n {\n \tstruct zloop_device *zlo = disk-\u003eprivate_data;\n \tunsigned int i;\n \n+\tcancel_delayed_work_sync(\u0026zlo-\u003eremove_element_work);\n+\tcancel_delayed_work_sync(\u0026zlo-\u003erestore_elements_work);\n+\n \tblk_mq_free_tag_set(\u0026zlo-\u003etag_set);\n \n \tfor (i = 0; i \u003c zlo-\u003enr_zones; i++) {\n@@ -1002,15 +1366,24 @@ static void zloop_free_disk(struct gendisk *disk)\n \n \tfput(zlo-\u003edata_dir);\n \tdestroy_workqueue(zlo-\u003eworkqueue);\n+\tkfree(zlo-\u003eelements);\n \tkfree(zlo-\u003ebase_dir);\n \tkvfree(zlo);\n }\n \n+\n+static const struct blk_storage_elements_ops zloop_se_ops = {\n+\t.report_elements\t= zloop_report_elements,\n+\t.remove_element\t\t= zloop_remove_element,\n+\t.restore_elements\t= zloop_restore_elements,\n+};\n+\n static const struct block_device_operations zloop_fops = {\n \t.owner\t\t\t= THIS_MODULE,\n \t.open\t\t\t= zloop_open,\n \t.report_zones\t\t= zloop_report_zones,\n \t.free_disk\t\t= zloop_free_disk,\n+\t.se_ops\t\t\t= \u0026zloop_se_ops,\n };\n \n __printf(3, 4)\n@@ -1095,6 +1468,17 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,\n \tif (!opts-\u003ebuffered_io)\n \t\toflags |= O_DIRECT;\n \n+\tif (zlo-\u003estor_elements != ZLOOP_STOR_ELEMENTS_NONE) {\n+\t\tunsigned int nr_elems = zlo-\u003enr_elements;\n+\n+\t\tif (zlo-\u003estor_elements == ZLOOP_STOR_ELEMENTS_PAIRS)\n+\t\t\tnr_elems /= 2;\n+\t\tzone-\u003ewr_se_id = (zone_no % nr_elems) + 1;\n+\t\tzone-\u003erd_se_id = zone-\u003ewr_se_id;\n+\t\tif (zlo-\u003estor_elements == ZLOOP_STOR_ELEMENTS_PAIRS)\n+\t\t\tzone-\u003erd_se_id += nr_elems;\n+\t}\n+\n \tif (zone_no \u003c zlo-\u003enr_conv_zones) {\n \t\t/* Conventional zone file. */\n \t\tset_bit(ZLOOP_ZONE_CONV, \u0026zone-\u003eflags);\n@@ -1165,6 +1549,93 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,\n \treturn ret;\n }\n \n+#define ZLOOP_MIN_STOR_ELEMENTS\t\t\t2\n+#define ZLOOP_MAX_STOR_ELEMENTS\t\t\t32\n+#define ZLOOP_MIN_ZONES_PER_STOR_ELEMENTS\t32\n+\n+static int zloop_create_storage_elements(struct zloop_device *zlo)\n+{\n+\tstruct blk_storage_element *se, *paired_se;\n+\tunsigned int i, nr_elems, nr_elements;\n+\tunsigned int nr_zones_per_element, nrz = 0;\n+\tsector_t capacity_per_element;\n+\n+\t/*\n+\t * Calculate the number of storage elements we are going to emulate.\n+\t * To achieve a somewhat realistic emulation, we want at least 2 storage\n+\t * elements, and no more than 32, targeting at least 32 zones per\n+\t * element.\n+\t */\n+\tif (zlo-\u003enr_zones \u003c= 64)\n+\t\tnr_elements = 2;\n+\telse\n+\t\tnr_elements =\n+\t\t\tmin(ZLOOP_MAX_STOR_ELEMENTS,\n+\t\t\t zlo-\u003enr_zones / ZLOOP_MIN_ZONES_PER_STOR_ELEMENTS);\n+\tnr_zones_per_element = zlo-\u003enr_zones / nr_elements;\n+\tcapacity_per_element =\n+\t\t(sector_t)nr_zones_per_element \u003c\u003c zlo-\u003ezone_shift;\n+\n+\t/*\n+\t * If we are emulating pairs of read and write storage elements, we need\n+\t * double the number of storage element descriptors.\n+\t */\n+\tnr_elems = nr_elements;\n+\tif (zlo-\u003estor_elements == ZLOOP_STOR_ELEMENTS_PAIRS)\n+\t\tnr_elems *= 2;\n+\tzlo-\u003eelements = kzalloc_objs(struct blk_storage_element, nr_elems);\n+\tif (!zlo-\u003eelements)\n+\t\treturn -ENOMEM;\n+\n+\tfor (i = 0, se = zlo-\u003eelements; i \u003c nr_elements; i++, se++) {\n+\t\tse-\u003eid = i + 1;\n+\t\tif (nrz + nr_zones_per_element \u003e zlo-\u003enr_zones)\n+\t\t\tse-\u003enr_zones = zlo-\u003enr_zones - nrz;\n+\t\telse\n+\t\t\tse-\u003enr_zones = nr_zones_per_element;\n+\n+\t\tif (zlo-\u003estor_elements == ZLOOP_STOR_ELEMENTS_PAIRS)\n+\t\t\tse-\u003etype = BLK_SE_TYPE_WRITE;\n+\t\telse\n+\t\t\tse-\u003etype = BLK_SE_TYPE_RDWR;\n+\n+\t\tse-\u003estatus = BLK_SE_STS_OK;\n+\n+\t\tnrz += nr_zones_per_element;\n+\t}\n+\n+\t/*\n+\t * If we are emulating pairs of read and write storage elements,\n+\t * initialize the read elements paired with the write elements we just\n+\t * initialized.\n+\t */\n+\tif (zlo-\u003estor_elements == ZLOOP_STOR_ELEMENTS_PAIRS) {\n+\t\tfor (i = 0; i \u003c nr_elements; i++, se++) {\n+\t\t\tse-\u003eid = nr_elements + i + 1;\n+\t\t\tpaired_se = \u0026zlo-\u003eelements[i];\n+\t\t\tse-\u003epaired_id = paired_se-\u003eid;\n+\t\t\tpaired_se-\u003epaired_id = se-\u003eid;\n+\t\t\tse-\u003enr_zones = paired_se-\u003enr_zones;\n+\t\t\tse-\u003etype = BLK_SE_TYPE_READ;\n+\t\t\tse-\u003estatus = BLK_SE_STS_OK;\n+\t\t}\n+\t}\n+\n+\t/*\n+\t * Make sure we do not allow removing all storage elements as that does\n+\t * not make any sense. This is consistent with the device advertized\n+\t * limit of SCSI and ATA devices supporting the storage element\n+\t * depopulation feature.\n+\t */\n+\tzlo-\u003enr_elements = nr_elems;\n+\tif (zlo-\u003estor_elements == ZLOOP_STOR_ELEMENTS_PAIRS)\n+\t\tzlo-\u003emax_nr_removed_elements = zlo-\u003enr_elements - 2;\n+\telse\n+\t\tzlo-\u003emax_nr_removed_elements = zlo-\u003enr_elements - 1;\n+\n+\treturn 0;\n+}\n+\n static bool zloop_dev_exists(struct zloop_device *zlo)\n {\n \tstruct file *cnv, *seq;\n@@ -1220,6 +1691,10 @@ static int zloop_ctl_add(struct zloop_options *opts)\n \tWRITE_ONCE(zlo-\u003estate, Zlo_creating);\n \tspin_lock_init(\u0026zlo-\u003eopen_zones_lock);\n \tINIT_LIST_HEAD(\u0026zlo-\u003eopen_zones_lru_list);\n+\tmutex_init(\u0026zlo-\u003estor_elements_lock);\n+\tINIT_DELAYED_WORK(\u0026zlo-\u003eremove_element_work, zloop_remove_element_work);\n+\tINIT_DELAYED_WORK(\u0026zlo-\u003erestore_elements_work,\n+\t\t\t zloop_restore_elements_work);\n \n \tret = mutex_lock_killable(\u0026zloop_ctl_mutex);\n \tif (ret)\n@@ -1253,12 +1728,19 @@ static int zloop_ctl_add(struct zloop_options *opts)\n \tif (zlo-\u003ezone_append)\n \t\tzlo-\u003eordered_zone_append = opts-\u003eordered_zone_append;\n \tzlo-\u003ediscard_write_cache = opts-\u003ediscard_write_cache;\n+\tzlo-\u003estor_elements = opts-\u003estor_elements;\n+\n+\tif (zlo-\u003estor_elements != ZLOOP_STOR_ELEMENTS_NONE) {\n+\t\tret = zloop_create_storage_elements(zlo);\n+\t\tif (ret)\n+\t\t\tgoto out_free_idr;\n+\t}\n \n \tzlo-\u003eworkqueue = alloc_workqueue(\"zloop%d\", WQ_UNBOUND | WQ_FREEZABLE,\n \t\t\t\topts-\u003enr_queues * opts-\u003equeue_depth, zlo-\u003eid);\n \tif (!zlo-\u003eworkqueue) {\n \t\tret = -ENOMEM;\n-\t\tgoto out_free_idr;\n+\t\tgoto out_destroy_storage_elements;\n \t}\n \n \tif (opts-\u003ebase_dir)\n@@ -1344,6 +1826,10 @@ static int zloop_ctl_add(struct zloop_options *opts)\n \t\tzlo-\u003eid, zlo-\u003enr_zones,\n \t\t((sector_t)zlo-\u003ezone_size \u003c\u003c SECTOR_SHIFT) \u003e\u003e 20,\n \t\tzlo-\u003eblock_size);\n+\tif (zlo-\u003enr_elements)\n+\t\tpr_info(\"zloop%d: %d storage elements\\n\",\n+\t\t\tzlo-\u003eid, zlo-\u003enr_elements);\n+\n \tpr_info(\"zloop%d: using %s%s zone append\\n\",\n \t\tzlo-\u003eid,\n \t\tzlo-\u003eordered_zone_append ? \"ordered \" : \"\",\n@@ -1367,6 +1853,8 @@ static int zloop_ctl_add(struct zloop_options *opts)\n \tkfree(zlo-\u003ebase_dir);\n out_destroy_workqueue:\n \tdestroy_workqueue(zlo-\u003eworkqueue);\n+out_destroy_storage_elements:\n+\tkfree(zlo-\u003eelements);\n out_free_idr:\n \tmutex_lock(\u0026zloop_ctl_mutex);\n \tidr_remove(\u0026zloop_index_idr, zlo-\u003eid);\n@@ -1466,6 +1954,39 @@ static int zloop_ctl_remove(struct zloop_options *opts)\n \treturn 0;\n }\n \n+static int zloop_ctl_degrade_element(struct zloop_options *opts)\n+{\n+\tstruct zloop_device *zlo;\n+\tint ret = 0;\n+\n+\tif (!(opts-\u003emask \u0026 ZLOOP_OPT_ID)) {\n+\t\tpr_err(\"No ID specified for degrade_element\\n\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (opts-\u003emask \u0026 ~(ZLOOP_OPT_ID | ZLOOP_OPT_ELEMENT_ID)) {\n+\t\tpr_err(\"Invalid option specified for degrade_element\\n\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tmutex_lock(\u0026zloop_ctl_mutex);\n+\tzlo = idr_find(\u0026zloop_index_idr, opts-\u003eid);\n+\tif (!zlo || zlo-\u003estate == Zlo_creating)\n+\t\tret = -ENODEV;\n+\telse if (zlo-\u003estate == Zlo_deleting)\n+\t\tret = -EINVAL;\n+\tmutex_unlock(\u0026zloop_ctl_mutex);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = zloop_degrade_element(zlo, opts-\u003eelement_id);\n+\tif (!ret)\n+\t\tpr_info(\"Degraded element %u of device %u\\n\",\n+\t\t\topts-\u003eid, opts-\u003eelement_id);\n+\n+\treturn ret;\n+}\n+\n static int zloop_parse_options(struct zloop_options *opts, const char *buf)\n {\n \tsubstring_t args[MAX_OPT_ARGS];\n@@ -1485,6 +2006,8 @@ static int zloop_parse_options(struct zloop_options *opts, const char *buf)\n \topts-\u003ebuffered_io = ZLOOP_DEF_BUFFERED_IO;\n \topts-\u003ezone_append = ZLOOP_DEF_ZONE_APPEND;\n \topts-\u003eordered_zone_append = ZLOOP_DEF_ORDERED_ZONE_APPEND;\n+\topts-\u003estor_elements = ZLOOP_DEF_STOR_ELEMENTS;\n+\topts-\u003eelement_id = ZLOOP_DEF_ELEMENT_ID;\n \n \tif (!buf)\n \t\treturn 0;\n@@ -1619,6 +2142,30 @@ static int zloop_parse_options(struct zloop_options *opts, const char *buf)\n \t\tcase ZLOOP_OPT_DISCARD_WRITE_CACHE:\n \t\t\topts-\u003ediscard_write_cache = true;\n \t\t\tbreak;\n+\t\tcase ZLOOP_OPT_STOR_ELEMENTS:\n+\t\t\tif (match_uint(args, \u0026token)) {\n+\t\t\t\tret = -EINVAL;\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\t\t\tswitch (token) {\n+\t\t\tcase ZLOOP_STOR_ELEMENTS_NONE:\n+\t\t\tcase ZLOOP_STOR_ELEMENTS_RDWR:\n+\t\t\tcase ZLOOP_STOR_ELEMENTS_PAIRS:\n+\t\t\t\tbreak;\n+\t\t\tdefault:\n+\t\t\t\tpr_err(\"Invalid zone_append value\\n\");\n+\t\t\t\tret = -EINVAL;\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\t\t\topts-\u003estor_elements = token;\n+\t\t\tbreak;\n+\t\tcase ZLOOP_OPT_ELEMENT_ID:\n+\t\t\tif (match_uint(args, \u0026token)) {\n+\t\t\t\tret = -EINVAL;\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\t\t\topts-\u003eelement_id = token;\n+\t\t\tbreak;\n \t\tcase ZLOOP_OPT_ERR:\n \t\tdefault:\n \t\t\tpr_warn(\"unknown parameter or missing value '%s'\\n\", p);\n@@ -1647,14 +2194,16 @@ static int zloop_parse_options(struct zloop_options *opts, const char *buf)\n enum {\n \tZLOOP_CTL_ADD,\n \tZLOOP_CTL_REMOVE,\n+\tZLOOP_CTL_DEGRADE_ELEMENT,\n };\n \n static struct zloop_ctl_op {\n \tint\t\tcode;\n \tconst char\t*name;\n } zloop_ctl_ops[] = {\n-\t{ ZLOOP_CTL_ADD,\t\"add\" },\n-\t{ ZLOOP_CTL_REMOVE,\t\"remove\" },\n+\t{ ZLOOP_CTL_ADD,\t\t\"add\" },\n+\t{ ZLOOP_CTL_REMOVE,\t\t\"remove\" },\n+\t{ ZLOOP_CTL_DEGRADE_ELEMENT,\t\"degrade_element\" },\n \t{ -1,\tNULL },\n };\n \n@@ -1702,6 +2251,9 @@ static ssize_t zloop_ctl_write(struct file *file, const char __user *ubuf,\n \tcase ZLOOP_CTL_REMOVE:\n \t\tret = zloop_ctl_remove(\u0026opts);\n \t\tbreak;\n+\tcase ZLOOP_CTL_DEGRADE_ELEMENT:\n+\t\tret = zloop_ctl_degrade_element(\u0026opts);\n+\t\tbreak;\n \tdefault:\n \t\tpr_err(\"Invalid operation\\n\");\n \t\tret = -EINVAL;\n@@ -1725,6 +2277,8 @@ static int zloop_ctl_show(struct seq_file *seq_file, void *private)\n \t\ttok = \u0026zloop_opt_tokens[i];\n \t\tif (!tok-\u003epattern)\n \t\t\tbreak;\n+\t\tif (tok-\u003etoken == ZLOOP_OPT_ELEMENT_ID)\n+\t\t\tcontinue;\n \t\tif (i)\n \t\t\tseq_putc(seq_file, ',');\n \t\tseq_puts(seq_file, tok-\u003epattern);\n@@ -1735,6 +2289,10 @@ static int zloop_ctl_show(struct seq_file *seq_file, void *private)\n \tseq_puts(seq_file, zloop_ctl_ops[1].name);\n \tseq_puts(seq_file, \" id=%d\\n\");\n \n+\t/* Degrade element operation */\n+\tseq_puts(seq_file, zloop_ctl_ops[2].name);\n+\tseq_puts(seq_file, \" id=%d,element_id=%d\\n\");\n+\n \treturn 0;\n }\n \ndiff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c\nindex a1b21ea14e549..799d2093d667b 100644\n--- a/drivers/scsi/sd.c\n+++ b/drivers/scsi/sd.c\n@@ -3937,6 +3937,7 @@ static const struct block_device_operations sd_fops = {\n \t.get_unique_id\t\t= sd_get_unique_id,\n \t.free_disk\t\t= scsi_disk_free_disk,\n \t.pr_ops\t\t\t= \u0026sd_pr_ops,\n+\t.se_ops\t\t\t= \u0026sd_zbc_se_ops,\n };\n \n /**\ndiff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h\nindex 574af82430169..16a004a1e6f1e 100644\n--- a/drivers/scsi/sd.h\n+++ b/drivers/scsi/sd.h\n@@ -156,6 +156,7 @@ struct scsi_disk {\n \tunsigned\tignore_medium_access_errors : 1;\n \tunsigned\trscs : 1; /* reduced stream control support */\n \tunsigned\tuse_atomic_write_boundary : 1;\n+\tunsigned\tmodify_zones_supported : 1;\n };\n #define to_scsi_disk(obj) container_of(obj, struct scsi_disk, disk_dev)\n \n@@ -242,6 +243,8 @@ unsigned int sd_zbc_complete(struct scsi_cmnd *cmd, unsigned int good_bytes,\n int sd_zbc_report_zones(struct gendisk *disk, sector_t sector,\n \t\tunsigned int nr_zones, struct blk_report_zones_args *args);\n \n+extern const struct blk_storage_elements_ops sd_zbc_se_ops;\n+\n #else /* CONFIG_BLK_DEV_ZONED */\n \n static inline int sd_zbc_read_zones(struct scsi_disk *sdkp,\n@@ -270,6 +273,8 @@ static inline unsigned int sd_zbc_complete(struct scsi_cmnd *cmd,\n \n #define sd_zbc_report_zones NULL\n \n+#define sd_zbc_se_ops\tNULL\n+\n #endif /* CONFIG_BLK_DEV_ZONED */\n \n void sd_print_sense_hdr(struct scsi_disk *sdkp, struct scsi_sense_hdr *sshdr);\ndiff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c\nindex 456beaf2e7690..586e0ab508edc 100644\n--- a/drivers/scsi/sd_zbc.c\n+++ b/drivers/scsi/sd_zbc.c\n@@ -516,6 +516,21 @@ static int sd_zbc_check_capacity(struct scsi_disk *sdkp, unsigned char *buf,\n \treturn 0;\n }\n \n+/*\n+ * sd_zbc_check_modify_zones - Check if the device supports depopulation\n+ * @sdkp: Target disk\n+ * @buf: command buffer\n+ *\n+ * Check if the device supports the REMOVE ELEMENT AND MODIFY ZONES command.\n+ */\n+static inline bool sd_zbc_check_modify_zones(struct scsi_disk *sdkp,\n+\t\t\t\t\t unsigned char *buf)\n+{\n+\treturn scsi_report_opcode(sdkp-\u003edevice, buf, SD_BUF_SIZE,\n+\t\t\t\t SERVICE_ACTION_IN_16,\n+\t\t\t\t SAI_REMOVE_ELEMENT_AND_MODIFY_ZONES) == 1;\n+}\n+\n static void sd_zbc_print_zones(struct scsi_disk *sdkp)\n {\n \tif (sdkp-\u003edevice-\u003etype != TYPE_ZBC || !sdkp-\u003ecapacity)\n@@ -533,6 +548,216 @@ static void sd_zbc_print_zones(struct scsi_disk *sdkp)\n \t\t\t sdkp-\u003ezone_info.zone_blocks);\n }\n \n+#define SD_ZBC_STORAGE_ELEMENTS_BUF_SIZE\t4096\n+\n+static void sd_zbc_parse_storage_element(struct scsi_disk *sdkp, u8 *desc,\n+\t\t\t\t\t struct blk_storage_element *element)\n+{\n+\tstruct scsi_device *sdp = sdkp-\u003edevice;\n+\tu64 capacity;\n+\n+\telement-\u003eid = get_unaligned_be32(\u0026desc[4]);\n+\n+\tswitch (desc[14]) {\n+\tcase SCSI_PHYS_ELEM_TYPE_ALL_ACCESS_STORAGE:\n+\t\telement-\u003epaired_id = 0;\n+\t\telement-\u003etype = BLK_SE_TYPE_RDWR;\n+\t\tcapacity = get_unaligned_be64(\u0026desc[16]);\n+\t\telement-\u003enr_zones = logical_to_sectors(sdp, capacity) \u003e\u003e\n+\t\t\tilog2(sd_zbc_zone_sectors(sdkp));\n+\t\tbreak;\n+\tcase SCSI_PHYS_ELEM_TYPE_FRAC_ACCESS_STORAGE:\n+\t\telement-\u003epaired_id = get_unaligned_be32(\u0026desc[16]);\n+\t\tif (desc[20] \u0026 0x01)\n+\t\t\telement-\u003etype = BLK_SE_TYPE_READ;\n+\t\telse\n+\t\t\telement-\u003etype = BLK_SE_TYPE_WRITE;\n+\t\telement-\u003enr_zones = get_unaligned_be64(\u0026desc[24]);\n+\t\tbreak;\n+\tdefault:\n+\t\telement-\u003etype = BLK_SE_TYPE_UNKNOWN;\n+\t}\n+\n+\tswitch (desc[15]) {\n+\tcase SCSI_PHYS_ELEM_HEALTH_WITHIN_SPEC_LIMITS:\n+\tcase SCSI_PHYS_ELEM_HEALTH_AT_SPEC_LIMITS:\n+\t\telement-\u003estatus = BLK_SE_STS_OK;\n+\t\tbreak;\n+\tcase SCSI_PHYS_ELEM_HEALTH_OUTSIDE_SPEC_LIMITS:\n+\t\telement-\u003estatus = BLK_SE_STS_DEGRADED;\n+\t\tbreak;\n+\tcase SCSI_PHYS_ELEM_HEALTH_DEPOP_REVOKE_ERR:\n+\t\telement-\u003estatus = BLK_SE_STS_RESTORE_ERROR;\n+\t\tbreak;\n+\tcase SCSI_PHYS_ELEM_HEALTH_DEPOP_REVOKE_IN_PROGRESS:\n+\t\telement-\u003estatus = BLK_SE_STS_RESTORE_IN_PROGRESS;\n+\t\tbreak;\n+\tcase SCSI_PHYS_ELEM_HEALTH_DEPOP_ERR:\n+\t\telement-\u003estatus = BLK_SE_STS_REMOVE_ERROR;\n+\t\tbreak;\n+\tcase SCSI_PHYS_ELEM_HEALTH_DEPOP_IN_PROGRESS:\n+\t\telement-\u003estatus = BLK_SE_STS_REMOVE_IN_PROGRESS;\n+\t\tbreak;\n+\tcase SCSI_PHYS_ELEM_HEALTH_DEPOP_OK:\n+\t\telement-\u003estatus = BLK_SE_STS_REMOVED;\n+\t\telement-\u003erestore_allowed = desc[13] \u0026 0x01;\n+\t\tbreak;\n+\tcase SCSI_PHYS_ELEM_HEALTH_NOT_REPORTED:\n+\tdefault:\n+\t\telement-\u003estatus = BLK_SE_STS_UNKOWN;\n+\t\tbreak;\n+\t}\n+}\n+\n+static int sd_zbc_report_storage_elements(struct gendisk *disk,\n+\t\t\t\t\t unsigned int *nr_elements,\n+\t\t\t\t\t struct blk_storage_element *elements)\n+{\n+\tstruct scsi_disk *sdkp = scsi_disk(disk);\n+\tstruct scsi_device *sdp = sdkp-\u003edevice;\n+\tconst int timeout = sdp-\u003erequest_queue-\u003erq_timeout;\n+\tstruct scsi_sense_hdr sshdr;\n+\tconst struct scsi_exec_args exec_args = {\n+\t\t.sshdr = \u0026sshdr,\n+\t};\n+\tunsigned char cmd[16];\n+\tunsigned int nr_descs;\n+\tint i, ret = 0, result;\n+\tu8 *desc, *buf;\n+\n+\tif (!sdkp-\u003emodify_zones_supported)\n+\t\treturn -EOPNOTSUPP;\n+\n+\tbuf = kzalloc(SD_ZBC_STORAGE_ELEMENTS_BUF_SIZE, GFP_KERNEL);\n+\tif (!buf)\n+\t\treturn -ENOMEM;\n+\n+\tmemset(cmd, 0, 16);\n+\tcmd[0] = SERVICE_ACTION_IN_16;\n+\tcmd[1] = SAI_GET_PHYSICAL_ELEMENT_STATUS;\n+\tput_unaligned_be32(SD_ZBC_STORAGE_ELEMENTS_BUF_SIZE, \u0026cmd[10]);\n+\n+\tresult = scsi_execute_cmd(sdp, cmd, REQ_OP_DRV_IN, buf,\n+\t\t\t\t SD_ZBC_STORAGE_ELEMENTS_BUF_SIZE,\n+\t\t\t\t timeout, 1, \u0026exec_args);\n+\tif (result) {\n+\t\tsd_printk(KERN_ERR, sdkp,\n+\t\t\t \"GET PHYSICAL ELEMENT STATUS failed\\n\");\n+\t\tsd_print_result(sdkp, \"GET PHYSICAL ELEMENT STATUS\", result);\n+\t\tif (result \u003e 0 \u0026\u0026 scsi_sense_valid(\u0026sshdr))\n+\t\t\tsd_print_sense_hdr(sdkp, \u0026sshdr);\n+\t\tret = -EIO;\n+\t\tgoto free_buf;\n+\t}\n+\n+\tnr_descs = get_unaligned_be32(\u0026buf[0]);\n+\tif (!nr_descs) {\n+\t\tsd_printk(KERN_ERR, sdkp,\n+\t\t\t \"Invalid number of phys element descriptors\\n\");\n+\t\tret = -EIO;\n+\t\tgoto free_buf;\n+\t}\n+\n+\tif (!elements) {\n+\t\t*nr_elements = nr_descs;\n+\t\tgoto free_buf;\n+\t}\n+\n+\tnr_descs = get_unaligned_be32(\u0026buf[4]);\n+\tif (!nr_descs) {\n+\t\tsd_printk(KERN_ERR, sdkp,\n+\t\t\t\"Invalid number of reported phys element descriptors\\n\");\n+\t\tret = -EIO;\n+\t\tgoto free_buf;\n+\t}\n+\n+\tdesc = \u0026buf[32];\n+\tfor (i = 0; i \u003c min(*nr_elements, nr_descs); i++, desc += 32)\n+\t\tsd_zbc_parse_storage_element(sdkp, desc, \u0026elements[i]);\n+\t*nr_elements = nr_descs;\n+\n+free_buf:\n+\tkfree(buf);\n+\n+\treturn ret;\n+}\n+\n+static int sd_zbc_remove_storage_element(struct gendisk *disk,\n+\t\t\t\t\t unsigned int element_id)\n+{\n+\tstruct scsi_disk *sdkp = scsi_disk(disk);\n+\tstruct scsi_device *sdp = sdkp-\u003edevice;\n+\tconst int timeout = sdp-\u003erequest_queue-\u003erq_timeout;\n+\tstruct scsi_sense_hdr sshdr;\n+\tconst struct scsi_exec_args exec_args = {\n+\t\t.sshdr = \u0026sshdr,\n+\t};\n+\tunsigned char cmd[16];\n+\tint result;\n+\n+\tif (!sdkp-\u003emodify_zones_supported)\n+\t\treturn -EOPNOTSUPP;\n+\n+\tmemset(cmd, 0, 16);\n+\tcmd[0] = SERVICE_ACTION_IN_16;\n+\tcmd[1] = SAI_REMOVE_ELEMENT_AND_MODIFY_ZONES;\n+\tput_unaligned_be32(element_id, \u0026cmd[10]);\n+\n+\tresult = scsi_execute_cmd(sdp, cmd, REQ_OP_DRV_IN, NULL, 0,\n+\t\t\t\t timeout, 1, \u0026exec_args);\n+\tif (result) {\n+\t\tsd_printk(KERN_ERR, sdkp,\n+\t\t\t \"REMOVE ELEMENT AND MODIFY ZONES failed\\n\");\n+\t\tsd_print_result(sdkp,\n+\t\t\t\t\"REMOVE ELEMENT AND MODIFY ZONES\", result);\n+\t\tif (result \u003e 0 \u0026\u0026 scsi_sense_valid(\u0026sshdr))\n+\t\t\tsd_print_sense_hdr(sdkp, \u0026sshdr);\n+\t\treturn -EIO;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int sd_zbc_restore_storage_elements(struct gendisk *disk)\n+{\n+\tstruct scsi_disk *sdkp = scsi_disk(disk);\n+\tstruct scsi_device *sdp = sdkp-\u003edevice;\n+\tconst int timeout = sdp-\u003erequest_queue-\u003erq_timeout;\n+\tstruct scsi_sense_hdr sshdr;\n+\tconst struct scsi_exec_args exec_args = {\n+\t\t.sshdr = \u0026sshdr,\n+\t};\n+\tunsigned char cmd[16];\n+\tint result;\n+\n+\tif (!sdkp-\u003emodify_zones_supported)\n+\t\treturn -EOPNOTSUPP;\n+\n+\tmemset(cmd, 0, 16);\n+\tcmd[0] = SERVICE_ACTION_IN_16;\n+\tcmd[1] = SAI_RESTORE_ELEMENTS_AND_REBUILD;\n+\n+\tresult = scsi_execute_cmd(sdp, cmd, REQ_OP_DRV_IN, NULL, 0,\n+\t\t\t\t timeout, 1, \u0026exec_args);\n+\tif (result) {\n+\t\tsd_printk(KERN_ERR, sdkp,\n+\t\t\t \"RESTORE ELEMENTS AND REBUILD failed\\n\");\n+\t\tsd_print_result(sdkp,\n+\t\t\t\t\"RESTORE ELEMENTS AND REBUILD\", result);\n+\t\tif (result \u003e 0 \u0026\u0026 scsi_sense_valid(\u0026sshdr))\n+\t\t\tsd_print_sense_hdr(sdkp, \u0026sshdr);\n+\t\treturn -EIO;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+const struct blk_storage_elements_ops sd_zbc_se_ops = {\n+\t.report_elements\t= sd_zbc_report_storage_elements,\n+\t.remove_element\t\t= sd_zbc_remove_storage_element,\n+\t.restore_elements\t= sd_zbc_restore_storage_elements,\n+};\n+\n /*\n * Call blk_revalidate_disk_zones() if any of the zoned disk properties have\n * changed that make it necessary to call that function. Called by\n@@ -554,9 +779,15 @@ int sd_zbc_revalidate_zones(struct scsi_disk *sdkp)\n \tif (!blk_queue_is_zoned(q))\n \t\treturn 0;\n \n+\t/*\n+\t * If the zone size and number of zones has not changed, and the disk\n+\t * does not support depopulating heads, skip the rather slow call to\n+\t * blk_revalidate_disk_zones().\n+\t */\n \tif (sdkp-\u003ezone_info.zone_blocks == zone_blocks \u0026\u0026\n \t sdkp-\u003ezone_info.nr_zones == nr_zones \u0026\u0026\n-\t disk-\u003enr_zones == nr_zones)\n+\t disk-\u003enr_zones == nr_zones \u0026\u0026\n+\t !sdkp-\u003emodify_zones_supported)\n \t\treturn 0;\n \n \tsdkp-\u003ezone_info.zone_blocks = zone_blocks;\n@@ -620,6 +851,9 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, struct queue_limits *lim,\n \tif (ret != 0)\n \t\tgoto err;\n \n+\t/* Check if REMOVE ELEMENT AND MODIFY ZONES is supported. */\n+\tsdkp-\u003emodify_zones_supported = sd_zbc_check_modify_zones(sdkp, buf);\n+\n \tnr_zones = round_up(sdkp-\u003ecapacity, zone_blocks) \u003e\u003e ilog2(zone_blocks);\n \tif (nr_zones \u003e INT_MAX) {\n \t\tsd_printk(KERN_ERR, sdkp, \"Too many zones (%llu)\\n\",\ndiff --git a/include/linux/blkdev.h b/include/linux/blkdev.h\nindex d003a9d2d1f6c..0b2013c96cad5 100644\n--- a/include/linux/blkdev.h\n+++ b/include/linux/blkdev.h\n@@ -1574,6 +1574,21 @@ enum blk_unique_id {\n \tBLK_UID_NAA\t= 3,\n };\n \n+struct blk_storage_elements_ops {\n+\tint (*report_elements)(struct gendisk *disk,\n+\t\t\t unsigned int *nr_elements,\n+\t\t\t struct blk_storage_element *elements);\n+\tint (*remove_element)(struct gendisk *disk, unsigned int element_id);\n+\tint (*restore_elements)(struct gendisk *disk);\n+};\n+\n+int bdev_report_storage_elements(struct block_device *bdev,\n+\t\t\t\t unsigned int *nr_elements,\n+\t\t\t\t struct blk_storage_element *elements);\n+int bdev_remove_storage_element(struct block_device *bdev,\n+\t\t\t\tunsigned int element_id);\n+int bdev_restore_storage_elements(struct block_device *bdev);\n+\n struct block_device_operations {\n \tvoid (*submit_bio)(struct bio *bio);\n \tint (*poll_bio)(struct bio *bio, struct io_comp_batch *iob,\n@@ -1601,6 +1616,7 @@ struct block_device_operations {\n \t\t\tenum blk_unique_id id_type);\n \tstruct module *owner;\n \tconst struct pr_ops *pr_ops;\n+\tconst struct blk_storage_elements_ops\t*se_ops;\n \n \t/*\n \t * Special callback for probing GPT entry at a given sector.\ndiff --git a/include/uapi/linux/blkzoned.h b/include/uapi/linux/blkzoned.h\nindex 6638361209667..bd2c55d1a0d26 100644\n--- a/include/uapi/linux/blkzoned.h\n+++ b/include/uapi/linux/blkzoned.h\n@@ -208,4 +208,85 @@ struct blk_zone_range {\n #define BLKFINISHZONE\t_IOW(0x12, 136, struct blk_zone_range)\n #define BLKREPORTZONEV2\t_IOWR(0x12, 142, struct blk_zone_report)\n \n+/**\n+ * enum blk_storage_element_status - Statuc of a zoned device storage elements.\n+ *\n+ * @BLK_SE_RDWR: The storage element handles both reads and writes.\n+ * @BLK_SE_READ: The storage element handles reads only.\n+ * @BLK_SE_WRITE: The storage element handles writes only.\n+ * @BLK_SE_WRITE: The storage element type is unknown.\n+ */\n+enum blk_storage_element_type {\n+\tBLK_SE_TYPE_RDWR\t\t= 0x01,\n+\tBLK_SE_TYPE_READ\t\t= 0x02,\n+\tBLK_SE_TYPE_WRITE\t\t= 0x03,\n+\tBLK_SE_TYPE_UNKNOWN\t\t= 0xFF,\n+};\n+\n+/**\n+ * enum blk_storage_element_status - Status of a zoned device storage elements.\n+ *\n+ * @BLK_SE_STS_OK: The storage element is operating normally.\n+ * @BLK_SE_STS_DEGRADED: The storage element has degraded and is not operating\n+ *\t\t\t normally.\n+ * @BLK_SE_STS_REMOVE_IN_PROGRESS: The storage element is being removed.\n+ * @BLK_SE_STS_REMOVE_ERROR: The storage element removal failed.\n+ * @BLK_SE_STS_RESTORE_IN_PROGRESS: The storage element is being restored.\n+ * @BLK_SE_STS_RESTORE_ERROR: The storage element restoration failed.\n+ * @BLK_SE_STS_REMOVED: The storage element was removed.\n+ * @BLK_SE_STS_UNKNOWN: The storage element status is unknown.\n+ */\n+enum blk_storage_element_status {\n+\tBLK_SE_STS_OK\t\t\t= 0x01,\n+\tBLK_SE_STS_DEGRADED\t\t= 0x02,\n+\tBLK_SE_STS_REMOVE_IN_PROGRESS\t= 0x03,\n+\tBLK_SE_STS_REMOVE_ERROR\t\t= 0x04,\n+\tBLK_SE_STS_RESTORE_IN_PROGRESS\t= 0x05,\n+\tBLK_SE_STS_RESTORE_ERROR\t= 0x06,\n+\tBLK_SE_STS_REMOVED\t\t= 0x07,\n+\tBLK_SE_STS_UNKOWN\t\t= 0xFF,\n+};\n+\n+/**\n+ * struct blk_storage_element - Zoned device storage element descriptor.\n+ *\n+ * @id: The ID of the element (cannot be 0).\n+ * @paired_id: The ID of the paired element for an element that is not\n+ *\t of type BLK_SE_TYPE_RDWR.\n+ * @type: The type of the storage element (enum blk_storage_element_type).\n+ * @status: The health status of the storage element\n+ *\t (enum blk_storage_element_status).\n+ * @restore_allowed: Indicate if the storage element can be restored.\n+ * @nr_zones: The number of zones that the storage element handles.\n+ */\n+struct blk_storage_element {\n+\t__u32\tid;\n+\t__u32\tpaired_id;\n+\t__u64\tnr_zones;\n+\t__u8\ttype;\n+\t__u8\tstatus;\n+\t__u8\trestore_allowed;\n+\t__u8\treserved[5];\n+};\n+\n+struct blk_storage_elements_report {\n+\t__u32\t\t\t\tnr_elements;\n+\t__u32\t\t\t\treserved;\n+\tstruct blk_storage_element\telements[];\n+};\n+\n+/**\n+ * Zoned block device storage element management ioctl's:\n+ *\n+ * @BLKGETNRSTORELEMS: Get the number of storage elements of the device.\n+ * @BLKREPORTSTORELEMS: Get the device storage elements.\n+ * @BLKREMOVESTORELEM: Remove (depopulate) one storage element of a device.\n+ * @BLKRESTORESTORELEM: Restore (repopulate if possible) all storage elements\n+ *\t\t\tthat have been removed.\n+ */\n+#define BLKGETNRSTORELEMS _IOR(0x12, 143, __u32)\n+#define BLKREPORTSTORELEMS _IOWR(0x12, 144, struct blk_storage_elements_report)\n+#define BLKREMOVESTORELEM _IOW(0x12, 145, __u32)\n+#define BLKRESTORESTORELEMS _IO(0x12, 146)\n+\n #endif /* _UAPI_BLKZONED_H */\ndiff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h\nindex 34c6f219462a5..8a979326aa7f0 100644\n--- a/include/uapi/linux/fs.h\n+++ b/include/uapi/linux/fs.h\n@@ -309,6 +309,7 @@ struct file_attr {\n /* 130-136 and 142 are used by zoned block device ioctls (uapi/linux/blkzoned.h) */\n /* 137-141 are used by blk-crypto ioctls (uapi/linux/blk-crypto.h) */\n #define BLKTRACESETUP2 _IOWR(0x12, 142, struct blk_user_trace_setup2)\n+/* 143-146 are used by storage element management for zoned block devices. */\n \n #define BMAP_IOCTL 1\t\t/* obsolete - kept for compatibility */\n #define FIBMAP\t _IO(0x00,1)\t/* bmap access */\n"
} |
| 2/1 | 2026/10/05 10:28 | agent | patch-evaluator |
1mModel:core Args: null Results: {
"EnableConfigs": [
"BLK_DEV_ZONED",
"BLK_DEV_ZONED_LOOP"
],
"FocusSymbols": [
"blkdev_zone_storage_elements_ioctl",
"bdev_report_storage_elements",
"bdev_remove_storage_element",
"bdev_restore_storage_elements",
"bdev_zone_is_offline",
"disk_wait_for_se_mgmt_completion",
"zloop_report_elements",
"zloop_remove_element",
"zloop_restore_elements",
"zloop_degrade_element",
"zloop_ctl_degrade_element",
"sd_zbc_report_storage_elements",
"sd_zbc_remove_storage_element",
"sd_zbc_restore_storage_elements"
],
"Reasoning": "The patch adds support for storage element emulation and management (depopulation, restoration, and reporting) for zoned block devices. It introduces new user-facing ioctls (BLKGETNRSTORELEMS, BLKREPORTSTORELEMS, BLKREMOVESTORELEM, BLKRESTORESTORELEMS), new control operations on /dev/zloop-control, core block layer offline zone checks, asynchronous delayed work, and driver logic in zloop and SCSI ZBC. These changes are reachable from userspace and warrant fuzzing for concurrency issues, memory handling bugs, and state machine invariants.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 6033a37c315506cd3e921d4f74ddc01ec80d3808
Author: syz-cluster <triage@syzkaller.com>
Date: Mon Oct 5 10:28:25 2026 +0000
syz-cluster: applied patch under review
diff --git a/Documentation/admin-guide/blockdev/zoned_loop.rst b/Documentation/admin-guide/blockdev/zoned_loop.rst
index 64277494fb36a..ec39f141af8d6 100644
--- a/Documentation/admin-guide/blockdev/zoned_loop.rst
+++ b/Documentation/admin-guide/blockdev/zoned_loop.rst
@@ -61,7 +61,7 @@ The options available for the add command can be listed by reading the
/dev/zloop-control device::
$ cat /dev/zloop-control
- add id=%d,capacity_mb=%u,zone_size_mb=%u,zone_capacity_mb=%u,conv_zones=%u,max_open_zones=%u,base_dir=%s,nr_queues=%u,queue_depth=%u,buffered_io,zone_append=%u,ordered_zone_append,discard_write_cache
+ add id=%d,capacity_mb=%u,zone_size_mb=%u,zone_capacity_mb=%u,conv_zones=%u,max_open_zones=%u,base_dir=%s,nr_queues=%u,queue_depth=%u,buffered_io,zone_append=%u,ordered_zone_append,discard_write_cache,stor_elements=%u
remove id=%d
In more details, the options that can be used with the "add" command are as
@@ -113,6 +113,12 @@ discard_write_cache Discard all data that was not explicitly persisted using a
each zone file to the size recorded during the last flush
operation. This simulates power fail events where
uncommitted data is lost.
+stor_elements Control storage element emulation. The default value is 0,
+ indicating no emulation. A value of 1 indicates that all
+ access storage elements (equivalent to read+write head of
+ a disk) are emulated. A value of 2 enables fractional
+ access storage element (equivalent to pairs of read and
+ write heads of a disk) emulation .
=================== =========================================================
3) Deleting a Zoned Device
diff --git a/block/blk-core.c b/block/blk-core.c
index 13dc70e8f55d9..f098a31d19aa4 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -866,6 +866,11 @@ void submit_bio_noacct(struct bio *bio)
switch (bio_op(bio)) {
case REQ_OP_READ:
+ if (bdev_is_zoned(bdev) &&
+ bdev_zone_is_offline(bdev, bio->bi_iter.bi_sector)) {
+ bio_set_flag(bio, BIO_QUIET);
+ goto end_io;
+ }
break;
case REQ_OP_WRITE:
if (bio->bi_opf & REQ_ATOMIC) {
diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 19268afb8752e..62b9cf21e9adf 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -18,6 +18,8 @@
#include <linux/mempool.h>
#include <linux/kthread.h>
#include <linux/freezer.h>
+#include <linux/delay.h>
+#include <linux/uaccess.h>
#include <trace/events/block.h>
@@ -308,6 +310,24 @@ bool bdev_zone_is_seq(struct block_device *bdev, sector_t sector)
}
EXPORT_SYMBOL_GPL(bdev_zone_is_seq);
+/**
+ * bdev_zone_is_offline - check if a sector belongs to an offline zone
+ * @bdev: block device to check
+ * @sector: sector number
+ *
+ * Check if @sector on @bdev is contained in an offline zone.
+ */
+bool bdev_zone_is_offline(struct block_device *bdev, sector_t sector)
+{
+ enum blk_zone_cond cond;
+
+ if (!bdev_is_zoned(bdev))
+ return false;
+
+ cond = disk_zone_get_cond(bdev->bd_disk, sector);
+ return cond == BLK_ZONE_COND_OFFLINE;
+}
+
/**
* bdev_zone_mgmt_allowed - check if management operations are allowed on a zone
* @bdev: block device to check
@@ -2700,5 +2720,283 @@ int queue_zone_wplugs_show(void *data, struct seq_file *m)
return 0;
}
-
#endif
+
+static void disk_wait_for_se_mgmt_completion(struct gendisk *disk)
+{
+ struct blk_storage_element *elements, *e;
+ unsigned int i, nr_se, nr_elements = 0;
+ int ret;
+
+ ret = (disk->fops->se_ops->report_elements)(disk, &nr_elements, NULL);
+ if (ret) {
+ pr_err("Failed to get number of storage elements\n");
+ return;
+ }
+
+ elements = kzalloc_objs(struct blk_storage_element, nr_elements);
+ if (!elements)
+ return;
+
+ while (1) {
+ /*
+ * Check if we have storage elements being removed or restored.
+ */
+ nr_se = nr_elements;
+ ret = (disk->fops->se_ops->report_elements)(disk,
+ &nr_elements, elements);
+ if (ret) {
+ pr_err("Failed to get storage elements\n");
+ break;
+ }
+
+ e = elements;
+ for (i = 0; i < nr_se; i++, e++) {
+ if (e->status == BLK_SE_STS_REMOVE_IN_PROGRESS ||
+ e->status == BLK_SE_STS_RESTORE_IN_PROGRESS)
+ break;
+ }
+ if (i >= nr_se)
+ break;
+
+ /* Not done yet: wait and retry. */
+ msleep(500);
+ }
+
+ kfree(elements);
+}
+
+/**
+ * bdev_report_storage_elements - report the storage elements of a block device
+ *
+ * Fill at most @nr_elements storage element descriptors in the array @elements.
+ * The number of storage elements filled in the array is returned using
+ * @nr_elements. If @elements is NULL, only @nr_elements is returned.
+ *
+ * Returns 0 on success and a negative error code on failure.
+ */
+int bdev_report_storage_elements(struct block_device *bdev,
+ unsigned int *nr_elements,
+ struct blk_storage_element *elements)
+{
+ struct gendisk *disk = bdev->bd_disk;
+
+ if (!bdev_is_zoned(bdev) || !disk->fops->se_ops)
+ return -EOPNOTSUPP;
+
+ if (!nr_elements)
+ return -EINVAL;
+
+ if (*nr_elements && !elements)
+ return -EINVAL;
+
+ return (disk->fops->se_ops->report_elements)(disk, nr_elements,
+ elements);
+}
+EXPORT_SYMBOL_GPL(bdev_report_storage_elements);
+
+static int blkdev_get_nr_storage_elements_ioctl(struct block_device *bdev,
+ void __user *argp)
+{
+ unsigned int nr_elements = 0;
+ int ret;
+
+ ret = bdev_report_storage_elements(bdev, &nr_elements, NULL);
+ if (ret)
+ return ret;
+
+ if (put_user(nr_elements, (unsigned int __user *)argp))
+ return -EFAULT;
+
+ return 0;
+}
+
+static int blkdev_report_storage_elements_ioctl(struct block_device *bdev,
+ void __user *argp)
+{
+ struct blk_storage_elements_report rep;
+ struct blk_storage_element *elements;
+ unsigned int nr_elements;
+ unsigned long retc;
+ int ret;
+
+ if (!argp)
+ return -EINVAL;
+
+ if (copy_from_user(&rep, argp,
+ sizeof(struct blk_storage_elements_report)))
+ return -EFAULT;
+
+ if (!rep.nr_elements)
+ return -EINVAL;
+
+ nr_elements = rep.nr_elements;
+ elements = kzalloc_objs(struct blk_storage_element, nr_elements);
+ if (!elements)
+ return -ENOMEM;
+
+ ret = bdev_report_storage_elements(bdev, &nr_elements, elements);
+ if (ret)
+ goto free_elements;
+
+ retc = copy_to_user(argp + sizeof(struct blk_storage_elements_report),
+ elements,
+ sizeof(struct blk_storage_element) * nr_elements);
+ if (retc) {
+ ret = -EFAULT;
+ goto free_elements;
+ }
+
+ rep.nr_elements = nr_elements;
+ retc = copy_to_user(argp, &rep,
+ sizeof(struct blk_storage_elements_report));
+ if (retc)
+ ret = -EFAULT;
+
+free_elements:
+ kfree(elements);
+ return ret;
+}
+
+/**
+ * bdev_remove_storage_element - Remove (depopulate) a storage element of a
+ * block device
+ *
+ * Remove (depopulate) the storage element identified by @element_id from the
+ * block device @bdev.
+ *
+ * Returns 0 on success and a negative error code on failure.
+ */
+int bdev_remove_storage_element(struct block_device *bdev,
+ unsigned int element_id)
+{
+ struct gendisk *disk = bdev->bd_disk;
+ unsigned int memflags;
+ int ret;
+
+ if (!bdev_is_zoned(bdev) || !disk->fops->se_ops)
+ return -EOPNOTSUPP;
+
+ /* Zero is not a valid storage element ID. */
+ if (!element_id)
+ return -EINVAL;
+
+ /*
+ * Freeze and unfreeze the queue to flush any outstanding command.
+ * The caller is responsible for not queuing up more I/Os by higher
+ * level means.
+ */
+ memflags = blk_mq_freeze_queue(disk->queue);
+ blk_mq_unfreeze_queue(disk->queue, memflags);
+
+ /*
+ * Flush the volatile write cache if there is any. Note that this may
+ * lead to errors if degraded storage elements are used. So ignore
+ * errors here.
+ */
+ blkdev_issue_flush(disk->part0);
+
+ /* Invalidate all cached data. */
+ invalidate_inode_pages2_range(bdev->bd_mapping, 0,
+ get_capacity(disk) << SECTOR_SHIFT);
+
+ ret = (disk->fops->se_ops->remove_element)(disk, element_id);
+ if (ret)
+ return ret;
+
+ /* Revalidate the device zones once the opration completes. */
+ disk_wait_for_se_mgmt_completion(disk);
+
+ return blk_revalidate_disk_zones(disk);
+}
+EXPORT_SYMBOL_GPL(bdev_remove_storage_element);
+
+static int blkdev_remove_storage_element_ioctl(struct block_device *bdev,
+ blk_mode_t mode, void __user *argp)
+{
+ unsigned int element_id;
+
+ if (!(mode & BLK_OPEN_WRITE))
+ return -EBADF;
+ if (bdev_read_only(bdev))
+ return -EPERM;
+
+ if (get_user(element_id, (unsigned int __user *)argp))
+ return -EFAULT;
+
+ return bdev_remove_storage_element(bdev, element_id);
+}
+
+/**
+ * bdev_restore_storage_elements - Restore all depopulated storage elements of a
+ * block device
+ *
+ * Restore all storage elements of @bdev that have been depopulated. Not all
+ * elements may be restored by this operation.
+ *
+ * Returns 0 on success and a negative error code on failure.
+ */
+int bdev_restore_storage_elements(struct block_device *bdev)
+{
+ struct gendisk *disk = bdev->bd_disk;
+ unsigned int memflags;
+ int ret;
+
+ if (!bdev_is_zoned(bdev) || !disk->fops->se_ops)
+ return -EOPNOTSUPP;
+
+ /*
+ * Freeze and unfreeze the queue to flush any outstanding commands.
+ * The caller is responsible for not queuing up more I/O by higher
+ * level means.
+ */
+ memflags = blk_mq_freeze_queue(disk->queue);
+ blk_mq_unfreeze_queue(disk->queue, memflags);
+
+ /* Invalidate all cached data. */
+ invalidate_inode_pages2_range(bdev->bd_mapping, 0,
+ get_capacity(disk) << SECTOR_SHIFT);
+
+ ret = (disk->fops->se_ops->restore_elements)(disk);
+ if (ret)
+ return ret;
+
+ disk_wait_for_se_mgmt_completion(disk);
+
+ return blk_revalidate_disk_zones(disk);
+}
+EXPORT_SYMBOL_GPL(bdev_restore_storage_elements);
+
+static int blkdev_restore_storage_elements_ioctl(struct block_device *bdev,
+ blk_mode_t mode)
+{
+ if (!(mode & BLK_OPEN_WRITE))
+ return -EBADF;
+ if (bdev_read_only(bdev))
+ return -EPERM;
+
+ return bdev_restore_storage_elements(bdev);
+}
+
+int blkdev_zone_storage_elements_ioctl(struct block_device *bdev,
+ blk_mode_t mode, unsigned int cmd,
+ void __user *argp)
+{
+ if (!bdev_is_zoned(bdev) || !bdev->bd_disk->fops->se_ops)
+ return -ENOTTY;
+
+ switch (cmd) {
+ case BLKGETNRSTORELEMS:
+ return blkdev_get_nr_storage_elements_ioctl(bdev, argp);
+ case BLKREPORTSTORELEMS:
+ return blkdev_report_storage_elements_ioctl(bdev, argp);
+ case BLKREMOVESTORELEM:
+ return blkdev_remove_storage_element_ioctl(bdev, mode, argp);
+ case BLKRESTORESTORELEMS:
+ return blkdev_restore_storage_elements_ioctl(bdev, mode);
+ default:
+ break;
+ }
+
+ return -ENOTTY;
+}
diff --git a/block/blk.h b/block/blk.h
index 2cc03aa54c532..274afb46a809a 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -578,6 +578,10 @@ int blkdev_report_zones_ioctl(struct block_device *bdev, unsigned int cmd,
int blkdev_zone_mgmt_ioctl(struct block_device *bdev, blk_mode_t mode,
unsigned int cmd, unsigned long arg);
bool bdev_zone_mgmt_allowed(struct block_device *bdev, sector_t sector);
+bool bdev_zone_is_offline(struct block_device *bdev, sector_t sector);
+int blkdev_zone_storage_elements_ioctl(struct block_device *bdev,
+ blk_mode_t mode, unsigned int cmd,
+ void __user *argp);
#else /* CONFIG_BLK_DEV_ZONED */
static inline void disk_init_zone_resources(struct gendisk *disk)
{
@@ -625,6 +629,17 @@ static inline bool bdev_zone_mgmt_allowed(struct block_device *bdev,
{
return false;
}
+static inline bool bdev_zone_is_offline(struct block_device *bdev,
+ sector_t sector)
+{
+ return false;
+}
+static inline int blkdev_zone_storage_elements_ioctl(struct block_device *bdev,
+ blk_mode_t mode, unsigned int cmd,
+ void __user *argp)
+{
+ return -ENOTTY;
+}
#endif /* CONFIG_BLK_DEV_ZONED */
struct block_device *bdev_alloc(struct gendisk *disk, u8 partno);
diff --git a/block/ioctl.c b/block/ioctl.c
index 64b4e6c0f6965..ccf806c2e37d1 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -679,6 +679,11 @@ static int blkdev_common_ioctl(struct block_device *bdev, blk_mode_t mode,
return put_uint(argp, bdev_zone_sectors(bdev));
case BLKGETNRZONES:
return put_uint(argp, bdev_nr_zones(bdev));
+ case BLKGETNRSTORELEMS:
+ case BLKREPORTSTORELEMS:
+ case BLKREMOVESTORELEM:
+ case BLKRESTORESTORELEMS:
+ return blkdev_zone_storage_elements_ioctl(bdev, mode, cmd, argp);
case BLKROGET:
return put_int(argp, bdev_read_only(bdev) != 0);
case BLKSSZGET: /* get block device logical block size */
diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
index f0ca221524db6..1d51060b832bc 100644
--- a/drivers/block/zloop.c
+++ b/drivers/block/zloop.c
@@ -37,6 +37,8 @@ enum {
ZLOOP_OPT_ORDERED_ZONE_APPEND = (1 << 10),
ZLOOP_OPT_DISCARD_WRITE_CACHE = (1 << 11),
ZLOOP_OPT_MAX_OPEN_ZONES = (1 << 12),
+ ZLOOP_OPT_STOR_ELEMENTS = (1 << 13),
+ ZLOOP_OPT_ELEMENT_ID = (1 << 14),
};
static const match_table_t zloop_opt_tokens = {
@@ -51,11 +53,23 @@ static const match_table_t zloop_opt_tokens = {
{ ZLOOP_OPT_BUFFERED_IO, "buffered_io" },
{ ZLOOP_OPT_ZONE_APPEND, "zone_append=%u" },
{ ZLOOP_OPT_ORDERED_ZONE_APPEND, "ordered_zone_append" },
- { ZLOOP_OPT_DISCARD_WRITE_CACHE, "discard_write_cache" },
+ { ZLOOP_OPT_DISCARD_WRITE_CACHE, "discard_write_cache" },
{ ZLOOP_OPT_MAX_OPEN_ZONES, "max_open_zones=%u" },
+ { ZLOOP_OPT_STOR_ELEMENTS, "stor_elements=%u" },
+ { ZLOOP_OPT_ELEMENT_ID, "element_id=%u" },
{ ZLOOP_OPT_ERR, NULL }
};
+/* Storage elements emulation types. */
+enum zloop_stor_elements {
+ /* No emulation. */
+ ZLOOP_STOR_ELEMENTS_NONE,
+ /* Emulate read+write storage elements. */
+ ZLOOP_STOR_ELEMENTS_RDWR,
+ /* Emulate pairs of associated read and write storage elements. */
+ ZLOOP_STOR_ELEMENTS_PAIRS,
+};
+
/* Default values for the "add" operation. */
#define ZLOOP_DEF_ID -1
#define ZLOOP_DEF_ZONE_SIZE ((256ULL * SZ_1M) >> SECTOR_SHIFT)
@@ -68,6 +82,8 @@ static const match_table_t zloop_opt_tokens = {
#define ZLOOP_DEF_BUFFERED_IO false
#define ZLOOP_DEF_ZONE_APPEND true
#define ZLOOP_DEF_ORDERED_ZONE_APPEND false
+#define ZLOOP_DEF_STOR_ELEMENTS ZLOOP_STOR_ELEMENTS_NONE
+#define ZLOOP_DEF_ELEMENT_ID 0
/* Arbitrary limit on the zone size (16GB). */
#define ZLOOP_MAX_ZONE_SIZE_MB 16384
@@ -87,6 +103,8 @@ struct zloop_options {
bool zone_append;
bool ordered_zone_append;
bool discard_write_cache;
+ enum zloop_stor_elements stor_elements;
+ unsigned int element_id;
};
/*
@@ -117,6 +135,8 @@ struct zloop_zone {
enum blk_zone_cond cond;
sector_t start;
sector_t wp;
+ unsigned int wr_se_id;
+ unsigned int rd_se_id;
gfp_t old_gfp_mask;
};
@@ -133,6 +153,7 @@ struct zloop_device {
bool zone_append;
bool ordered_zone_append;
bool discard_write_cache;
+ enum zloop_stor_elements stor_elements;
const char *base_dir;
struct file *data_dir;
@@ -150,6 +171,17 @@ struct zloop_device {
struct list_head open_zones_lru_list;
unsigned int nr_open_zones;
+ /* For storage elements emulation. */
+ struct mutex stor_elements_lock;
+ unsigned int nr_elements;
+ unsigned int max_nr_removed_elements;
+ unsigned int nr_removed_elements;
+ struct delayed_work remove_element_work;
+ unsigned int remove_element_id;
+ struct delayed_work restore_elements_work;
+ bool restore_in_progress;
+ struct blk_storage_element *elements;
+
struct zloop_zone zones[] __counted_by(nr_zones);
};
@@ -173,6 +205,29 @@ static unsigned int rq_zone_no(struct request *rq)
return blk_rq_pos(rq) >> zlo->zone_shift;
}
+static bool zloop_zone_healthy(struct zloop_device *zlo,
+ struct zloop_zone *zone, bool write)
+{
+ struct blk_storage_element *se;
+
+ if (!zlo->nr_elements)
+ return true;
+
+ /* Check the zone condition first. */
+ if (zone->cond == BLK_ZONE_COND_OFFLINE)
+ return false;
+ if (zone->cond == BLK_ZONE_COND_READONLY && write)
+ return false;
+
+ /* Check the health state of the storage element serving the zone. */
+ if (write)
+ se = &zlo->elements[zone->wr_se_id - 1];
+ else
+ se = &zlo->elements[zone->rd_se_id - 1];
+
+ return se->status == BLK_SE_STS_DEGRADED;
+}
+
/*
* Open an already open zone. This is mostly a no-op, except for the imp open ->
* exp open condition change that may happen. We also move a zone at the tail of
@@ -289,22 +344,30 @@ static bool zloop_do_open_zone(struct zloop_device *zlo,
}
}
-static void zloop_mark_full(struct zloop_device *zlo, struct zloop_zone *zone)
+static void zloop_set_zone_cond(struct zloop_device *zlo,
+ struct zloop_zone *zone,
+ enum blk_zone_cond cond)
{
lockdep_assert_held(&zone->wp_lock);
zloop_lru_remove_open_zone(zlo, zone);
- zone->cond = BLK_ZONE_COND_FULL;
- zone->wp = ULLONG_MAX;
+ zone->cond = cond;
+ if (cond == BLK_ZONE_COND_EMPTY)
+ zone->wp = zone->start;
+ else
+ zone->wp = ULLONG_MAX;
}
-static void zloop_mark_empty(struct zloop_device *zlo, struct zloop_zone *zone)
+static inline void zloop_set_zone_full(struct zloop_device *zlo,
+ struct zloop_zone *zone)
{
- lockdep_assert_held(&zone->wp_lock);
+ zloop_set_zone_cond(zlo, zone, BLK_ZONE_COND_FULL);
+}
- zloop_lru_remove_open_zone(zlo, zone);
- zone->cond = BLK_ZONE_COND_EMPTY;
- zone->wp = zone->start;
+static inline void zloop_set_zone_empty(struct zloop_device *zlo,
+ struct zloop_zone *zone)
+{
+ zloop_set_zone_cond(zlo, zone, BLK_ZONE_COND_EMPTY);
}
static int zloop_update_seq_zone(struct zloop_device *zlo, unsigned int zone_no)
@@ -339,9 +402,9 @@ static int zloop_update_seq_zone(struct zloop_device *zlo, unsigned int zone_no)
spin_lock(&zone->wp_lock);
if (!file_sectors) {
- zloop_mark_empty(zlo, zone);
+ zloop_set_zone_empty(zlo, zone);
} else if (file_sectors == zlo->zone_capacity) {
- zloop_mark_full(zlo, zone);
+ zloop_set_zone_full(zlo, zone);
} else {
if (zone->cond != BLK_ZONE_COND_IMP_OPEN &&
zone->cond != BLK_ZONE_COND_EXP_OPEN)
@@ -363,6 +426,12 @@ static int zloop_open_zone(struct zloop_device *zlo, unsigned int zone_no)
mutex_lock(&zone->lock);
+ if (zone->cond == BLK_ZONE_COND_OFFLINE ||
+ zone->cond == BLK_ZONE_COND_READONLY) {
+ ret = -EIO;
+ goto unlock;
+ }
+
if (test_and_clear_bit(ZLOOP_ZONE_SEQ_ERROR, &zone->flags)) {
ret = zloop_update_seq_zone(zlo, zone_no);
if (ret)
@@ -388,6 +457,12 @@ static int zloop_close_zone(struct zloop_device *zlo, unsigned int zone_no)
mutex_lock(&zone->lock);
+ if (zone->cond == BLK_ZONE_COND_OFFLINE ||
+ zone->cond == BLK_ZONE_COND_READONLY) {
+ ret = -EIO;
+ goto unlock;
+ }
+
if (test_and_clear_bit(ZLOOP_ZONE_SEQ_ERROR, &zone->flags)) {
ret = zloop_update_seq_zone(zlo, zone_no);
if (ret)
@@ -420,7 +495,22 @@ static int zloop_close_zone(struct zloop_device *zlo, unsigned int zone_no)
return ret;
}
-static int zloop_reset_zone(struct zloop_device *zlo, unsigned int zone_no)
+static int zloop_do_reset_zone(struct zloop_device *zlo,
+ struct zloop_zone *zone)
+{
+ if (vfs_truncate(&zone->file->f_path, 0))
+ return -EIO;
+
+ spin_lock(&zone->wp_lock);
+ zloop_set_zone_empty(zlo, zone);
+ clear_bit(ZLOOP_ZONE_SEQ_ERROR, &zone->flags);
+ spin_unlock(&zone->wp_lock);
+
+ return 0;
+}
+
+static int zloop_reset_zone(struct zloop_device *zlo, unsigned int zone_no,
+ bool all_zones)
{
struct zloop_zone *zone = &zlo->zones[zone_no];
int ret = 0;
@@ -430,20 +520,20 @@ static int zloop_reset_zone(struct zloop_device *zlo, unsigned int zone_no)
mutex_lock(&zone->lock);
+ if (zone->cond == BLK_ZONE_COND_OFFLINE ||
+ zone->cond == BLK_ZONE_COND_READONLY) {
+ if (!all_zones)
+ ret = -EIO;
+ goto unlock;
+ }
+
if (!test_bit(ZLOOP_ZONE_SEQ_ERROR, &zone->flags) &&
zone->cond == BLK_ZONE_COND_EMPTY)
goto unlock;
- if (vfs_truncate(&zone->file->f_path, 0)) {
+ ret = zloop_do_reset_zone(zlo, zone);
+ if (ret)
set_bit(ZLOOP_ZONE_SEQ_ERROR, &zone->flags);
- ret = -EIO;
- goto unlock;
- }
-
- spin_lock(&zone->wp_lock);
- zloop_mark_empty(zlo, zone);
- clear_bit(ZLOOP_ZONE_SEQ_ERROR, &zone->flags);
- spin_unlock(&zone->wp_lock);
unlock:
mutex_unlock(&zone->lock);
@@ -457,7 +547,7 @@ static int zloop_reset_all_zones(struct zloop_device *zlo)
int ret;
for (i = zlo->nr_conv_zones; i < zlo->nr_zones; i++) {
- ret = zloop_reset_zone(zlo, i);
+ ret = zloop_reset_zone(zlo, i, true);
if (ret)
return ret;
}
@@ -475,6 +565,12 @@ static int zloop_finish_zone(struct zloop_device *zlo, unsigned int zone_no)
mutex_lock(&zone->lock);
+ if (zone->cond == BLK_ZONE_COND_OFFLINE ||
+ zone->cond == BLK_ZONE_COND_READONLY) {
+ ret = -EIO;
+ goto unlock;
+ }
+
if (!test_bit(ZLOOP_ZONE_SEQ_ERROR, &zone->flags) &&
zone->cond == BLK_ZONE_COND_FULL)
goto unlock;
@@ -487,7 +583,7 @@ static int zloop_finish_zone(struct zloop_device *zlo, unsigned int zone_no)
}
spin_lock(&zone->wp_lock);
- zloop_mark_full(zlo, zone);
+ zloop_set_zone_full(zlo, zone);
clear_bit(ZLOOP_ZONE_SEQ_ERROR, &zone->flags);
spin_unlock(&zone->wp_lock);
@@ -624,7 +720,7 @@ static int zloop_seq_write_prep(struct zloop_cmd *cmd)
if (!is_append || !zlo->ordered_zone_append) {
zone->wp += nr_sectors;
if (zone->wp == zone_end)
- zloop_mark_full(zlo, zone);
+ zloop_set_zone_full(zlo, zone);
}
out_unlock:
spin_unlock(&zone->wp_lock);
@@ -664,6 +760,9 @@ static void zloop_rw(struct zloop_cmd *cmd)
zone->start + zlo->zone_size))
goto out;
+ if (!zloop_zone_healthy(zlo, zone, is_write))
+ goto out;
+
if (test_and_clear_bit(ZLOOP_ZONE_SEQ_ERROR, &zone->flags)) {
mutex_lock(&zone->lock);
ret = zloop_update_seq_zone(zlo, zone_no);
@@ -766,7 +865,7 @@ static void zloop_handle_cmd(struct zloop_cmd *cmd)
cmd->ret = zloop_flush(zlo);
break;
case REQ_OP_ZONE_RESET:
- cmd->ret = zloop_reset_zone(zlo, rq_zone_no(rq));
+ cmd->ret = zloop_reset_zone(zlo, rq_zone_no(rq), false);
break;
case REQ_OP_ZONE_RESET_ALL:
cmd->ret = zloop_reset_all_zones(zlo);
@@ -877,7 +976,7 @@ static bool zloop_set_zone_append_sector(struct request *rq)
rq->__sector = zone->wp;
zone->wp += blk_rq_sectors(rq);
if (zone->wp >= zone_end)
- zloop_mark_full(zlo, zone);
+ zloop_set_zone_full(zlo, zone);
spin_unlock(&zone->wp_lock);
@@ -985,11 +1084,276 @@ static int zloop_report_zones(struct gendisk *disk, sector_t sector,
return nr_zones;
}
+static int zloop_report_elements(struct gendisk *disk,
+ unsigned int *nr_elements,
+ struct blk_storage_element *elements)
+{
+ struct zloop_device *zlo = disk->private_data;
+ unsigned int nr_report = *nr_elements;
+
+ if (zlo->stor_elements == ZLOOP_STOR_ELEMENTS_NONE)
+ return -EOPNOTSUPP;
+
+ mutex_lock(&zlo->stor_elements_lock);
+
+ *nr_elements = zlo->nr_elements;
+ if (elements) {
+ struct blk_storage_element *se = zlo->elements;
+ unsigned int i;
+
+ for (i = 0; i < min(nr_report, zlo->nr_elements); i++, se++) {
+ switch (se->status) {
+ case BLK_SE_STS_REMOVED:
+ case BLK_SE_STS_RESTORE_ERROR:
+ se->restore_allowed = 1;
+ break;
+ default:
+ se->restore_allowed = 0;
+ }
+ memcpy(&elements[i], se,
+ sizeof(struct blk_storage_element));
+ }
+ }
+
+ mutex_unlock(&zlo->stor_elements_lock);
+
+ return 0;
+}
+
+static int zloop_degrade_element(struct zloop_device *zlo,
+ unsigned int element_id)
+{
+ struct blk_storage_element *se;
+ int ret = 0;
+
+ if (zlo->stor_elements == ZLOOP_STOR_ELEMENTS_NONE)
+ return -EOPNOTSUPP;
+
+ if (!element_id || element_id > zlo->nr_elements)
+ return -EINVAL;
+
+ mutex_lock(&zlo->stor_elements_lock);
+
+ se = &zlo->elements[element_id - 1];
+ if (se->status == BLK_SE_STS_OK)
+ se->status = BLK_SE_STS_DEGRADED;
+ else
+ ret = -EINVAL;
+
+ mutex_unlock(&zlo->stor_elements_lock);
+
+ return ret;
+}
+
+static void zloop_remove_element_work(struct work_struct *work)
+{
+ struct zloop_device *zlo = container_of(work, struct zloop_device,
+ remove_element_work.work);
+ struct blk_storage_element *se, *paired_se = NULL;
+ enum blk_zone_cond cond;
+ struct zloop_zone *zone;
+ unsigned int i;
+
+ mutex_lock(&zlo->stor_elements_lock);
+
+ /*
+ * If the element to remove is a read element, zones must go offline and
+ * the associated write element is also removed.
+ */
+ se = &zlo->elements[zlo->remove_element_id - 1];
+ switch (se->type) {
+ case BLK_SE_TYPE_RDWR:
+ cond = BLK_ZONE_COND_OFFLINE;
+ break;
+ case BLK_SE_TYPE_READ:
+ cond = BLK_ZONE_COND_OFFLINE;
+ paired_se = &zlo->elements[se->paired_id - 1];
+ break;
+ case BLK_SE_TYPE_WRITE:
+ cond = BLK_ZONE_COND_READONLY;
+ break;
+ default:
+ WARN_ON_ONCE(1);
+ }
+
+ /*
+ * Change the condition of the zones owned by the (pair of) elements
+ * being removed and mark the elements removed.
+ */
+ for (i = 0, zone = zlo->zones; i < zlo->nr_zones; i++, zone++) {
+ if (zone->wr_se_id != se->id && zone->rd_se_id != se->id)
+ continue;
+ mutex_lock(&zone->lock);
+ spin_lock(&zone->wp_lock);
+ zloop_set_zone_cond(zlo, zone, cond);
+ spin_unlock(&zone->wp_lock);
+ mutex_unlock(&zone->lock);
+ }
+
+ se->status = BLK_SE_STS_REMOVED;
+
+ zlo->nr_removed_elements++;
+ if (paired_se) {
+ paired_se->status = BLK_SE_STS_REMOVED;
+ zlo->nr_removed_elements++;
+ }
+
+ zlo->remove_element_id = 0;
+
+ mutex_unlock(&zlo->stor_elements_lock);
+}
+
+static int zloop_remove_element(struct gendisk *disk, unsigned int element_id)
+{
+ struct zloop_device *zlo = disk->private_data;
+ struct blk_storage_element *se, *paired_se = NULL;
+ unsigned int nr_remove = 1;
+ int ret = 0;
+
+ if (zlo->stor_elements == ZLOOP_STOR_ELEMENTS_NONE)
+ return -EOPNOTSUPP;
+
+ if (element_id > zlo->nr_elements)
+ return -EINVAL;
+
+ mutex_lock(&zlo->stor_elements_lock);
+
+ if (zlo->remove_element_id || zlo->restore_in_progress) {
+ ret = -EBUSY;
+ goto unlock;
+ }
+
+ /*
+ * Get the element to remove. If it is already removed, we have nothing
+ * to do.
+ */
+ se = &zlo->elements[element_id - 1];
+ if (se->status == BLK_SE_STS_REMOVED)
+ goto unlock;
+
+ /*
+ * If the element to remove is a read element, the associated write
+ * element must also be removed.
+ */
+ if (se->type == BLK_SE_TYPE_READ) {
+ paired_se = &zlo->elements[se->paired_id - 1];
+ nr_remove = 2;
+ }
+
+ if (zlo->nr_removed_elements + nr_remove >
+ zlo->max_nr_removed_elements) {
+ ret = -EBUSY;
+ goto unlock;
+ }
+
+ /*
+ * Schedule the element removal with a delay, to emulate the (generally
+ * short) time it takes for a real device to depopulate a head and
+ * modify the zones.
+ */
+ zlo->remove_element_id = element_id;
+ se->status = BLK_SE_STS_REMOVE_IN_PROGRESS;
+ if (paired_se)
+ paired_se->status = BLK_SE_STS_REMOVE_IN_PROGRESS;
+
+ schedule_delayed_work(&zlo->remove_element_work,
+ msecs_to_jiffies(2000));
+
+unlock:
+ mutex_unlock(&zlo->stor_elements_lock);
+
+ return ret;
+}
+
+static void zloop_restore_elements_work(struct work_struct *work)
+{
+ struct zloop_device *zlo = container_of(work, struct zloop_device,
+ restore_elements_work.work);
+ struct zloop_zone *zone = zlo->zones;
+ struct blk_storage_element *se;
+ unsigned int i;
+ int ret = 0;
+
+ mutex_lock(&zlo->stor_elements_lock);
+
+ /* Reset all zones. */
+ for (i = 0; i < zlo->nr_zones && ret == 0; i++, zone++) {
+ mutex_lock(&zone->lock);
+ if (test_bit(ZLOOP_ZONE_CONV, &zone->flags)) {
+ spin_lock(&zone->wp_lock);
+ zloop_set_zone_cond(zlo, zone, BLK_ZONE_COND_NOT_WP);
+ spin_unlock(&zone->wp_lock);
+ } else {
+ ret = zloop_do_reset_zone(zlo, zone);
+ }
+ mutex_unlock(&zone->lock);
+ }
+
+ /* Restore all removed elements. */
+ for (i = 0, se = zlo->elements; i < zlo->nr_elements; i++, se++) {
+ if (se->status != BLK_SE_STS_RESTORE_IN_PROGRESS)
+ continue;
+ if (!ret)
+ se->status = BLK_SE_STS_OK;
+ else
+ se->status = BLK_SE_STS_RESTORE_ERROR;
+ }
+
+ zlo->nr_removed_elements = 0;
+ zlo->restore_in_progress = false;
+
+ mutex_unlock(&zlo->stor_elements_lock);
+}
+
+static int zloop_restore_elements(struct gendisk *disk)
+{
+ struct zloop_device *zlo = disk->private_data;
+ struct blk_storage_element *se;
+ unsigned int i;
+ int ret = 0;
+
+ if (zlo->stor_elements == ZLOOP_STOR_ELEMENTS_NONE)
+ return -EOPNOTSUPP;
+
+ mutex_lock(&zlo->stor_elements_lock);
+
+ if (zlo->remove_element_id || zlo->restore_in_progress) {
+ ret = -EBUSY;
+ goto unlock;
+ }
+
+ /* If we have no removed elements, we have nothing to do. */
+ if (!zlo->nr_removed_elements)
+ goto unlock;
+
+ /*
+ * Schedule the elements restoration with a delay, to emulate the time
+ * it takes for a real device to restore all removed heads and reset
+ * all zones.
+ */
+ zlo->restore_in_progress = true;
+ for (i = 0, se = zlo->elements; i < zlo->nr_elements; i++, se++) {
+ if (se->status == BLK_SE_STS_REMOVED)
+ se->status = BLK_SE_STS_RESTORE_IN_PROGRESS;
+ }
+
+ schedule_delayed_work(&zlo->restore_elements_work,
+ msecs_to_jiffies(5000));
+
+unlock:
+ mutex_unlock(&zlo->stor_elements_lock);
+
+ return ret;
+}
+
static void zloop_free_disk(struct gendisk *disk)
{
struct zloop_device *zlo = disk->private_data;
unsigned int i;
+ cancel_delayed_work_sync(&zlo->remove_element_work);
+ cancel_delayed_work_sync(&zlo->restore_elements_work);
+
blk_mq_free_tag_set(&zlo->tag_set);
for (i = 0; i < zlo->nr_zones; i++) {
@@ -1002,15 +1366,24 @@ static void zloop_free_disk(struct gendisk *disk)
fput(zlo->data_dir);
destroy_workqueue(zlo->workqueue);
+ kfree(zlo->elements);
kfree(zlo->base_dir);
kvfree(zlo);
}
+
+static const struct blk_storage_elements_ops zloop_se_ops = {
+ .report_elements = zloop_report_elements,
+ .remove_element = zloop_remove_element,
+ .restore_elements = zloop_restore_elements,
+};
+
static const struct block_device_operations zloop_fops = {
.owner = THIS_MODULE,
.open = zloop_open,
.report_zones = zloop_report_zones,
.free_disk = zloop_free_disk,
+ .se_ops = &zloop_se_ops,
};
__printf(3, 4)
@@ -1095,6 +1468,17 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
if (!opts->buffered_io)
oflags |= O_DIRECT;
+ if (zlo->stor_elements != ZLOOP_STOR_ELEMENTS_NONE) {
+ unsigned int nr_elems = zlo->nr_elements;
+
+ if (zlo->stor_elements == ZLOOP_STOR_ELEMENTS_PAIRS)
+ nr_elems /= 2;
+ zone->wr_se_id = (zone_no % nr_elems) + 1;
+ zone->rd_se_id = zone->wr_se_id;
+ if (zlo->stor_elements == ZLOOP_STOR_ELEMENTS_PAIRS)
+ zone->rd_se_id += nr_elems;
+ }
+
if (zone_no < zlo->nr_conv_zones) {
/* Conventional zone file. */
set_bit(ZLOOP_ZONE_CONV, &zone->flags);
@@ -1165,6 +1549,93 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
return ret;
}
+#define ZLOOP_MIN_STOR_ELEMENTS 2
+#define ZLOOP_MAX_STOR_ELEMENTS 32
+#define ZLOOP_MIN_ZONES_PER_STOR_ELEMENTS 32
+
+static int zloop_create_storage_elements(struct zloop_device *zlo)
+{
+ struct blk_storage_element *se, *paired_se;
+ unsigned int i, nr_elems, nr_elements;
+ unsigned int nr_zones_per_element, nrz = 0;
+ sector_t capacity_per_element;
+
+ /*
+ * Calculate the number of storage elements we are going to emulate.
+ * To achieve a somewhat realistic emulation, we want at least 2 storage
+ * elements, and no more than 32, targeting at least 32 zones per
+ * element.
+ */
+ if (zlo->nr_zones <= 64)
+ nr_elements = 2;
+ else
+ nr_elements =
+ min(ZLOOP_MAX_STOR_ELEMENTS,
+ zlo->nr_zones / ZLOOP_MIN_ZONES_PER_STOR_ELEMENTS);
+ nr_zones_per_element = zlo->nr_zones / nr_elements;
+ capacity_per_element =
+ (sector_t)nr_zones_per_element << zlo->zone_shift;
+
+ /*
+ * If we are emulating pairs of read and write storage elements, we need
+ * double the number of storage element descriptors.
+ */
+ nr_elems = nr_elements;
+ if (zlo->stor_elements == ZLOOP_STOR_ELEMENTS_PAIRS)
+ nr_elems *= 2;
+ zlo->elements = kzalloc_objs(struct blk_storage_element, nr_elems);
+ if (!zlo->elements)
+ return -ENOMEM;
+
+ for (i = 0, se = zlo->elements; i < nr_elements; i++, se++) {
+ se->id = i + 1;
+ if (nrz + nr_zones_per_element > zlo->nr_zones)
+ se->nr_zones = zlo->nr_zones - nrz;
+ else
+ se->nr_zones = nr_zones_per_element;
+
+ if (zlo->stor_elements == ZLOOP_STOR_ELEMENTS_PAIRS)
+ se->type = BLK_SE_TYPE_WRITE;
+ else
+ se->type = BLK_SE_TYPE_RDWR;
+
+ se->status = BLK_SE_STS_OK;
+
+ nrz += nr_zones_per_element;
+ }
+
+ /*
+ * If we are emulating pairs of read and write storage elements,
+ * initialize the read elements paired with the write elements we just
+ * initialized.
+ */
+ if (zlo->stor_elements == ZLOOP_STOR_ELEMENTS_PAIRS) {
+ for (i = 0; i < nr_elements; i++, se++) {
+ se->id = nr_elements + i + 1;
+ paired_se = &zlo->elements[i];
+ se->paired_id = paired_se->id;
+ paired_se->paired_id = se->id;
+ se->nr_zones = paired_se->nr_zones;
+ se->type = BLK_SE_TYPE_READ;
+ se->status = BLK_SE_STS_OK;
+ }
+ }
+
+ /*
+ * Make sure we do not allow removing all storage elements as that does
+ * not make any sense. This is consistent with the device advertized
+ * limit of SCSI and ATA devices supporting the storage element
+ * depopulation feature.
+ */
+ zlo->nr_elements = nr_elems;
+ if (zlo->stor_elements == ZLOOP_STOR_ELEMENTS_PAIRS)
+ zlo->max_nr_removed_elements = zlo->nr_elements - 2;
+ else
+ zlo->max_nr_removed_elements = zlo->nr_elements - 1;
+
+ return 0;
+}
+
static bool zloop_dev_exists(struct zloop_device *zlo)
{
struct file *cnv, *seq;
@@ -1220,6 +1691,10 @@ static int zloop_ctl_add(struct zloop_options *opts)
WRITE_ONCE(zlo->state, Zlo_creating);
spin_lock_init(&zlo->open_zones_lock);
INIT_LIST_HEAD(&zlo->open_zones_lru_list);
+ mutex_init(&zlo->stor_elements_lock);
+ INIT_DELAYED_WORK(&zlo->remove_element_work, zloop_remove_element_work);
+ INIT_DELAYED_WORK(&zlo->restore_elements_work,
+ zloop_restore_elements_work);
ret = mutex_lock_killable(&zloop_ctl_mutex);
if (ret)
@@ -1253,12 +1728,19 @@ static int zloop_ctl_add(struct zloop_options *opts)
if (zlo->zone_append)
zlo->ordered_zone_append = opts->ordered_zone_append;
zlo->discard_write_cache = opts->discard_write_cache;
+ zlo->stor_elements = opts->stor_elements;
+
+ if (zlo->stor_elements != ZLOOP_STOR_ELEMENTS_NONE) {
+ ret = zloop_create_storage_elements(zlo);
+ if (ret)
+ goto out_free_idr;
+ }
zlo->workqueue = alloc_workqueue("zloop%d", WQ_UNBOUND | WQ_FREEZABLE,
opts->nr_queues * opts->queue_depth, zlo->id);
if (!zlo->workqueue) {
ret = -ENOMEM;
- goto out_free_idr;
+ goto out_destroy_storage_elements;
}
if (opts->base_dir)
@@ -1344,6 +1826,10 @@ static int zloop_ctl_add(struct zloop_options *opts)
zlo->id, zlo->nr_zones,
((sector_t)zlo->zone_size << SECTOR_SHIFT) >> 20,
zlo->block_size);
+ if (zlo->nr_elements)
+ pr_info("zloop%d: %d storage elements\n",
+ zlo->id, zlo->nr_elements);
+
pr_info("zloop%d: using %s%s zone append\n",
zlo->id,
zlo->ordered_zone_append ? "ordered " : "",
@@ -1367,6 +1853,8 @@ static int zloop_ctl_add(struct zloop_options *opts)
kfree(zlo->base_dir);
out_destroy_workqueue:
destroy_workqueue(zlo->workqueue);
+out_destroy_storage_elements:
+ kfree(zlo->elements);
out_free_idr:
mutex_lock(&zloop_ctl_mutex);
idr_remove(&zloop_index_idr, zlo->id);
@@ -1466,6 +1954,39 @@ static int zloop_ctl_remove(struct zloop_options *opts)
return 0;
}
+static int zloop_ctl_degrade_element(struct zloop_options *opts)
+{
+ struct zloop_device *zlo;
+ int ret = 0;
+
+ if (!(opts->mask & ZLOOP_OPT_ID)) {
+ pr_err("No ID specified for degrade_element\n");
+ return -EINVAL;
+ }
+
+ if (opts->mask & ~(ZLOOP_OPT_ID | ZLOOP_OPT_ELEMENT_ID)) {
+ pr_err("Invalid option specified for degrade_element\n");
+ return -EINVAL;
+ }
+
+ mutex_lock(&zloop_ctl_mutex);
+ zlo = idr_find(&zloop_index_idr, opts->id);
+ if (!zlo || zlo->state == Zlo_creating)
+ ret = -ENODEV;
+ else if (zlo->state == Zlo_deleting)
+ ret = -EINVAL;
+ mutex_unlock(&zloop_ctl_mutex);
+ if (ret)
+ return ret;
+
+ ret = zloop_degrade_element(zlo, opts->element_id);
+ if (!ret)
+ pr_info("Degraded element %u of device %u\n",
+ opts->id, opts->element_id);
+
+ return ret;
+}
+
static int zloop_parse_options(struct zloop_options *opts, const char *buf)
{
substring_t args[MAX_OPT_ARGS];
@@ -1485,6 +2006,8 @@ static int zloop_parse_options(struct zloop_options *opts, const char *buf)
opts->buffered_io = ZLOOP_DEF_BUFFERED_IO;
opts->zone_append = ZLOOP_DEF_ZONE_APPEND;
opts->ordered_zone_append = ZLOOP_DEF_ORDERED_ZONE_APPEND;
+ opts->stor_elements = ZLOOP_DEF_STOR_ELEMENTS;
+ opts->element_id = ZLOOP_DEF_ELEMENT_ID;
if (!buf)
return 0;
@@ -1619,6 +2142,30 @@ static int zloop_parse_options(struct zloop_options *opts, const char *buf)
case ZLOOP_OPT_DISCARD_WRITE_CACHE:
opts->discard_write_cache = true;
break;
+ case ZLOOP_OPT_STOR_ELEMENTS:
+ if (match_uint(args, &token)) {
+ ret = -EINVAL;
+ goto out;
+ }
+ switch (token) {
+ case ZLOOP_STOR_ELEMENTS_NONE:
+ case ZLOOP_STOR_ELEMENTS_RDWR:
+ case ZLOOP_STOR_ELEMENTS_PAIRS:
+ break;
+ default:
+ pr_err("Invalid zone_append value\n");
+ ret = -EINVAL;
+ goto out;
+ }
+ opts->stor_elements = token;
+ break;
+ case ZLOOP_OPT_ELEMENT_ID:
+ if (match_uint(args, &token)) {
+ ret = -EINVAL;
+ goto out;
+ }
+ opts->element_id = token;
+ break;
case ZLOOP_OPT_ERR:
default:
pr_warn("unknown parameter or missing value '%s'\n", p);
@@ -1647,14 +2194,16 @@ static int zloop_parse_options(struct zloop_options *opts, const char *buf)
enum {
ZLOOP_CTL_ADD,
ZLOOP_CTL_REMOVE,
+ ZLOOP_CTL_DEGRADE_ELEMENT,
};
static struct zloop_ctl_op {
int code;
const char *name;
} zloop_ctl_ops[] = {
- { ZLOOP_CTL_ADD, "add" },
- { ZLOOP_CTL_REMOVE, "remove" },
+ { ZLOOP_CTL_ADD, "add" },
+ { ZLOOP_CTL_REMOVE, "remove" },
+ { ZLOOP_CTL_DEGRADE_ELEMENT, "degrade_element" },
{ -1, NULL },
};
@@ -1702,6 +2251,9 @@ static ssize_t zloop_ctl_write(struct file *file, const char __user *ubuf,
case ZLOOP_CTL_REMOVE:
ret = zloop_ctl_remove(&opts);
break;
+ case ZLOOP_CTL_DEGRADE_ELEMENT:
+ ret = zloop_ctl_degrade_element(&opts);
+ break;
default:
pr_err("Invalid operation\n");
ret = -EINVAL;
@@ -1725,6 +2277,8 @@ static int zloop_ctl_show(struct seq_file *seq_file, void *private)
tok = &zloop_opt_tokens[i];
if (!tok->pattern)
break;
+ if (tok->token == ZLOOP_OPT_ELEMENT_ID)
+ continue;
if (i)
seq_putc(seq_file, ',');
seq_puts(seq_file, tok->pattern);
@@ -1735,6 +2289,10 @@ static int zloop_ctl_show(struct seq_file *seq_file, void *private)
seq_puts(seq_file, zloop_ctl_ops[1].name);
seq_puts(seq_file, " id=%d\n");
+ /* Degrade element operation */
+ seq_puts(seq_file, zloop_ctl_ops[2].name);
+ seq_puts(seq_file, " id=%d,element_id=%d\n");
+
return 0;
}
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index a1b21ea14e549..799d2093d667b 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -3937,6 +3937,7 @@ static const struct block_device_operations sd_fops = {
.get_unique_id = sd_get_unique_id,
.free_disk = scsi_disk_free_disk,
.pr_ops = &sd_pr_ops,
+ .se_ops = &sd_zbc_se_ops,
};
/**
diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h
index 574af82430169..16a004a1e6f1e 100644
--- a/drivers/scsi/sd.h
+++ b/drivers/scsi/sd.h
@@ -156,6 +156,7 @@ struct scsi_disk {
unsigned ignore_medium_access_errors : 1;
unsigned rscs : 1; /* reduced stream control support */
unsigned use_atomic_write_boundary : 1;
+ unsigned modify_zones_supported : 1;
};
#define to_scsi_disk(obj) container_of(obj, struct scsi_disk, disk_dev)
@@ -242,6 +243,8 @@ unsigned int sd_zbc_complete(struct scsi_cmnd *cmd, unsigned int good_bytes,
int sd_zbc_report_zones(struct gendisk *disk, sector_t sector,
unsigned int nr_zones, struct blk_report_zones_args *args);
+extern const struct blk_storage_elements_ops sd_zbc_se_ops;
+
#else /* CONFIG_BLK_DEV_ZONED */
static inline int sd_zbc_read_zones(struct scsi_disk *sdkp,
@@ -270,6 +273,8 @@ static inline unsigned int sd_zbc_complete(struct scsi_cmnd *cmd,
#define sd_zbc_report_zones NULL
+#define sd_zbc_se_ops NULL
+
#endif /* CONFIG_BLK_DEV_ZONED */
void sd_print_sense_hdr(struct scsi_disk *sdkp, struct scsi_sense_hdr *sshdr);
diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
index 456beaf2e7690..586e0ab508edc 100644
--- a/drivers/scsi/sd_zbc.c
+++ b/drivers/scsi/sd_zbc.c
@@ -516,6 +516,21 @@ static int sd_zbc_check_capacity(struct scsi_disk *sdkp, unsigned char *buf,
return 0;
}
+/*
+ * sd_zbc_check_modify_zones - Check if the device supports depopulation
+ * @sdkp: Target disk
+ * @buf: command buffer
+ *
+ * Check if the device supports the REMOVE ELEMENT AND MODIFY ZONES command.
+ */
+static inline bool sd_zbc_check_modify_zones(struct scsi_disk *sdkp,
+ unsigned char *buf)
+{
+ return scsi_report_opcode(sdkp->device, buf, SD_BUF_SIZE,
+ SERVICE_ACTION_IN_16,
+ SAI_REMOVE_ELEMENT_AND_MODIFY_ZONES) == 1;
+}
+
static void sd_zbc_print_zones(struct scsi_disk *sdkp)
{
if (sdkp->device->type != TYPE_ZBC || !sdkp->capacity)
@@ -533,6 +548,216 @@ static void sd_zbc_print_zones(struct scsi_disk *sdkp)
sdkp->zone_info.zone_blocks);
}
+#define SD_ZBC_STORAGE_ELEMENTS_BUF_SIZE 4096
+
+static void sd_zbc_parse_storage_element(struct scsi_disk *sdkp, u8 *desc,
+ struct blk_storage_element *element)
+{
+ struct scsi_device *sdp = sdkp->device;
+ u64 capacity;
+
+ element->id = get_unaligned_be32(&desc[4]);
+
+ switch (desc[14]) {
+ case SCSI_PHYS_ELEM_TYPE_ALL_ACCESS_STORAGE:
+ element->paired_id = 0;
+ element->type = BLK_SE_TYPE_RDWR;
+ capacity = get_unaligned_be64(&desc[16]);
+ element->nr_zones = logical_to_sectors(sdp, capacity) >>
+ ilog2(sd_zbc_zone_sectors(sdkp));
+ break;
+ case SCSI_PHYS_ELEM_TYPE_FRAC_ACCESS_STORAGE:
+ element->paired_id = get_unaligned_be32(&desc[16]);
+ if (desc[20] & 0x01)
+ element->type = BLK_SE_TYPE_READ;
+ else
+ element->type = BLK_SE_TYPE_WRITE;
+ element->nr_zones = get_unaligned_be64(&desc[24]);
+ break;
+ default:
+ element->type = BLK_SE_TYPE_UNKNOWN;
+ }
+
+ switch (desc[15]) {
+ case SCSI_PHYS_ELEM_HEALTH_WITHIN_SPEC_LIMITS:
+ case SCSI_PHYS_ELEM_HEALTH_AT_SPEC_LIMITS:
+ element->status = BLK_SE_STS_OK;
+ break;
+ case SCSI_PHYS_ELEM_HEALTH_OUTSIDE_SPEC_LIMITS:
+ element->status = BLK_SE_STS_DEGRADED;
+ break;
+ case SCSI_PHYS_ELEM_HEALTH_DEPOP_REVOKE_ERR:
+ element->status = BLK_SE_STS_RESTORE_ERROR;
+ break;
+ case SCSI_PHYS_ELEM_HEALTH_DEPOP_REVOKE_IN_PROGRESS:
+ element->status = BLK_SE_STS_RESTORE_IN_PROGRESS;
+ break;
+ case SCSI_PHYS_ELEM_HEALTH_DEPOP_ERR:
+ element->status = BLK_SE_STS_REMOVE_ERROR;
+ break;
+ case SCSI_PHYS_ELEM_HEALTH_DEPOP_IN_PROGRESS:
+ element->status = BLK_SE_STS_REMOVE_IN_PROGRESS;
+ break;
+ case SCSI_PHYS_ELEM_HEALTH_DEPOP_OK:
+ element->status = BLK_SE_STS_REMOVED;
+ element->restore_allowed = desc[13] & 0x01;
+ break;
+ case SCSI_PHYS_ELEM_HEALTH_NOT_REPORTED:
+ default:
+ element->status = BLK_SE_STS_UNKOWN;
+ break;
+ }
+}
+
+static int sd_zbc_report_storage_elements(struct gendisk *disk,
+ unsigned int *nr_elements,
+ struct blk_storage_element *elements)
+{
+ struct scsi_disk *sdkp = scsi_disk(disk);
+ struct scsi_device *sdp = sdkp->device;
+ const int timeout = sdp->request_queue->rq_timeout;
+ struct scsi_sense_hdr sshdr;
+ const struct scsi_exec_args exec_args = {
+ .sshdr = &sshdr,
+ };
+ unsigned char cmd[16];
+ unsigned int nr_descs;
+ int i, ret = 0, result;
+ u8 *desc, *buf;
+
+ if (!sdkp->modify_zones_supported)
+ return -EOPNOTSUPP;
+
+ buf = kzalloc(SD_ZBC_STORAGE_ELEMENTS_BUF_SIZE, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+
+ memset(cmd, 0, 16);
+ cmd[0] = SERVICE_ACTION_IN_16;
+ cmd[1] = SAI_GET_PHYSICAL_ELEMENT_STATUS;
+ put_unaligned_be32(SD_ZBC_STORAGE_ELEMENTS_BUF_SIZE, &cmd[10]);
+
+ result = scsi_execute_cmd(sdp, cmd, REQ_OP_DRV_IN, buf,
+ SD_ZBC_STORAGE_ELEMENTS_BUF_SIZE,
+ timeout, 1, &exec_args);
+ if (result) {
+ sd_printk(KERN_ERR, sdkp,
+ "GET PHYSICAL ELEMENT STATUS failed\n");
+ sd_print_result(sdkp, "GET PHYSICAL ELEMENT STATUS", result);
+ if (result > 0 && scsi_sense_valid(&sshdr))
+ sd_print_sense_hdr(sdkp, &sshdr);
+ ret = -EIO;
+ goto free_buf;
+ }
+
+ nr_descs = get_unaligned_be32(&buf[0]);
+ if (!nr_descs) {
+ sd_printk(KERN_ERR, sdkp,
+ "Invalid number of phys element descriptors\n");
+ ret = -EIO;
+ goto free_buf;
+ }
+
+ if (!elements) {
+ *nr_elements = nr_descs;
+ goto free_buf;
+ }
+
+ nr_descs = get_unaligned_be32(&buf[4]);
+ if (!nr_descs) {
+ sd_printk(KERN_ERR, sdkp,
+ "Invalid number of reported phys element descriptors\n");
+ ret = -EIO;
+ goto free_buf;
+ }
+
+ desc = &buf[32];
+ for (i = 0; i < min(*nr_elements, nr_descs); i++, desc += 32)
+ sd_zbc_parse_storage_element(sdkp, desc, &elements[i]);
+ *nr_elements = nr_descs;
+
+free_buf:
+ kfree(buf);
+
+ return ret;
+}
+
+static int sd_zbc_remove_storage_element(struct gendisk *disk,
+ unsigned int element_id)
+{
+ struct scsi_disk *sdkp = scsi_disk(disk);
+ struct scsi_device *sdp = sdkp->device;
+ const int timeout = sdp->request_queue->rq_timeout;
+ struct scsi_sense_hdr sshdr;
+ const struct scsi_exec_args exec_args = {
+ .sshdr = &sshdr,
+ };
+ unsigned char cmd[16];
+ int result;
+
+ if (!sdkp->modify_zones_supported)
+ return -EOPNOTSUPP;
+
+ memset(cmd, 0, 16);
+ cmd[0] = SERVICE_ACTION_IN_16;
+ cmd[1] = SAI_REMOVE_ELEMENT_AND_MODIFY_ZONES;
+ put_unaligned_be32(element_id, &cmd[10]);
+
+ result = scsi_execute_cmd(sdp, cmd, REQ_OP_DRV_IN, NULL, 0,
+ timeout, 1, &exec_args);
+ if (result) {
+ sd_printk(KERN_ERR, sdkp,
+ "REMOVE ELEMENT AND MODIFY ZONES failed\n");
+ sd_print_result(sdkp,
+ "REMOVE ELEMENT AND MODIFY ZONES", result);
+ if (result > 0 && scsi_sense_valid(&sshdr))
+ sd_print_sense_hdr(sdkp, &sshdr);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+static int sd_zbc_restore_storage_elements(struct gendisk *disk)
+{
+ struct scsi_disk *sdkp = scsi_disk(disk);
+ struct scsi_device *sdp = sdkp->device;
+ const int timeout = sdp->request_queue->rq_timeout;
+ struct scsi_sense_hdr sshdr;
+ const struct scsi_exec_args exec_args = {
+ .sshdr = &sshdr,
+ };
+ unsigned char cmd[16];
+ int result;
+
+ if (!sdkp->modify_zones_supported)
+ return -EOPNOTSUPP;
+
+ memset(cmd, 0, 16);
+ cmd[0] = SERVICE_ACTION_IN_16;
+ cmd[1] = SAI_RESTORE_ELEMENTS_AND_REBUILD;
+
+ result = scsi_execute_cmd(sdp, cmd, REQ_OP_DRV_IN, NULL, 0,
+ timeout, 1, &exec_args);
+ if (result) {
+ sd_printk(KERN_ERR, sdkp,
+ "RESTORE ELEMENTS AND REBUILD failed\n");
+ sd_print_result(sdkp,
+ "RESTORE ELEMENTS AND REBUILD", result);
+ if (result > 0 && scsi_sense_valid(&sshdr))
+ sd_print_sense_hdr(sdkp, &sshdr);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+const struct blk_storage_elements_ops sd_zbc_se_ops = {
+ .report_elements = sd_zbc_report_storage_elements,
+ .remove_element = sd_zbc_remove_storage_element,
+ .restore_elements = sd_zbc_restore_storage_elements,
+};
+
/*
* Call blk_revalidate_disk_zones() if any of the zoned disk properties have
* changed that make it necessary to call that function. Called by
@@ -554,9 +779,15 @@ int sd_zbc_revalidate_zones(struct scsi_disk *sdkp)
if (!blk_queue_is_zoned(q))
return 0;
+ /*
+ * If the zone size and number of zones has not changed, and the disk
+ * does not support depopulating heads, skip the rather slow call to
+ * blk_revalidate_disk_zones().
+ */
if (sdkp->zone_info.zone_blocks == zone_blocks &&
sdkp->zone_info.nr_zones == nr_zones &&
- disk->nr_zones == nr_zones)
+ disk->nr_zones == nr_zones &&
+ !sdkp->modify_zones_supported)
return 0;
sdkp->zone_info.zone_blocks = zone_blocks;
@@ -620,6 +851,9 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, struct queue_limits *lim,
if (ret != 0)
goto err;
+ /* Check if REMOVE ELEMENT AND MODIFY ZONES is supported. */
+ sdkp->modify_zones_supported = sd_zbc_check_modify_zones(sdkp, buf);
+
nr_zones = round_up(sdkp->capacity, zone_blocks) >> ilog2(zone_blocks);
if (nr_zones > INT_MAX) {
sd_printk(KERN_ERR, sdkp, "Too many zones (%llu)\n",
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index d003a9d2d1f6c..0b2013c96cad5 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1574,6 +1574,21 @@ enum blk_unique_id {
BLK_UID_NAA = 3,
};
+struct blk_storage_elements_ops {
+ int (*report_elements)(struct gendisk *disk,
+ unsigned int *nr_elements,
+ struct blk_storage_element *elements);
+ int (*remove_element)(struct gendisk *disk, unsigned int element_id);
+ int (*restore_elements)(struct gendisk *disk);
+};
+
+int bdev_report_storage_elements(struct block_device *bdev,
+ unsigned int *nr_elements,
+ struct blk_storage_element *elements);
+int bdev_remove_storage_element(struct block_device *bdev,
+ unsigned int element_id);
+int bdev_restore_storage_elements(struct block_device *bdev);
+
struct block_device_operations {
void (*submit_bio)(struct bio *bio);
int (*poll_bio)(struct bio *bio, struct io_comp_batch *iob,
@@ -1601,6 +1616,7 @@ struct block_device_operations {
enum blk_unique_id id_type);
struct module *owner;
const struct pr_ops *pr_ops;
+ const struct blk_storage_elements_ops *se_ops;
/*
* Special callback for probing GPT entry at a given sector.
diff --git a/include/uapi/linux/blkzoned.h b/include/uapi/linux/blkzoned.h
index 6638361209667..bd2c55d1a0d26 100644
--- a/include/uapi/linux/blkzoned.h
+++ b/include/uapi/linux/blkzoned.h
@@ -208,4 +208,85 @@ struct blk_zone_range {
#define BLKFINISHZONE _IOW(0x12, 136, struct blk_zone_range)
#define BLKREPORTZONEV2 _IOWR(0x12, 142, struct blk_zone_report)
+/**
+ * enum blk_storage_element_status - Statuc of a zoned device storage elements.
+ *
+ * @BLK_SE_RDWR: The storage element handles both reads and writes.
+ * @BLK_SE_READ: The storage element handles reads only.
+ * @BLK_SE_WRITE: The storage element handles writes only.
+ * @BLK_SE_WRITE: The storage element type is unknown.
+ */
+enum blk_storage_element_type {
+ BLK_SE_TYPE_RDWR = 0x01,
+ BLK_SE_TYPE_READ = 0x02,
+ BLK_SE_TYPE_WRITE = 0x03,
+ BLK_SE_TYPE_UNKNOWN = 0xFF,
+};
+
+/**
+ * enum blk_storage_element_status - Status of a zoned device storage elements.
+ *
+ * @BLK_SE_STS_OK: The storage element is operating normally.
+ * @BLK_SE_STS_DEGRADED: The storage element has degraded and is not operating
+ * normally.
+ * @BLK_SE_STS_REMOVE_IN_PROGRESS: The storage element is being removed.
+ * @BLK_SE_STS_REMOVE_ERROR: The storage element removal failed.
+ * @BLK_SE_STS_RESTORE_IN_PROGRESS: The storage element is being restored.
+ * @BLK_SE_STS_RESTORE_ERROR: The storage element restoration failed.
+ * @BLK_SE_STS_REMOVED: The storage element was removed.
+ * @BLK_SE_STS_UNKNOWN: The storage element status is unknown.
+ */
+enum blk_storage_element_status {
+ BLK_SE_STS_OK = 0x01,
+ BLK_SE_STS_DEGRADED = 0x02,
+ BLK_SE_STS_REMOVE_IN_PROGRESS = 0x03,
+ BLK_SE_STS_REMOVE_ERROR = 0x04,
+ BLK_SE_STS_RESTORE_IN_PROGRESS = 0x05,
+ BLK_SE_STS_RESTORE_ERROR = 0x06,
+ BLK_SE_STS_REMOVED = 0x07,
+ BLK_SE_STS_UNKOWN = 0xFF,
+};
+
+/**
+ * struct blk_storage_element - Zoned device storage element descriptor.
+ *
+ * @id: The ID of the element (cannot be 0).
+ * @paired_id: The ID of the paired element for an element that is not
+ * of type BLK_SE_TYPE_RDWR.
+ * @type: The type of the storage element (enum blk_storage_element_type).
+ * @status: The health status of the storage element
+ * (enum blk_storage_element_status).
+ * @restore_allowed: Indicate if the storage element can be restored.
+ * @nr_zones: The number of zones that the storage element handles.
+ */
+struct blk_storage_element {
+ __u32 id;
+ __u32 paired_id;
+ __u64 nr_zones;
+ __u8 type;
+ __u8 status;
+ __u8 restore_allowed;
+ __u8 reserved[5];
+};
+
+struct blk_storage_elements_report {
+ __u32 nr_elements;
+ __u32 reserved;
+ struct blk_storage_element elements[];
+};
+
+/**
+ * Zoned block device storage element management ioctl's:
+ *
+ * @BLKGETNRSTORELEMS: Get the number of storage elements of the device.
+ * @BLKREPORTSTORELEMS: Get the device storage elements.
+ * @BLKREMOVESTORELEM: Remove (depopulate) one storage element of a device.
+ * @BLKRESTORESTORELEM: Restore (repopulate if possible) all storage elements
+ * that have been removed.
+ */
+#define BLKGETNRSTORELEMS _IOR(0x12, 143, __u32)
+#define BLKREPORTSTORELEMS _IOWR(0x12, 144, struct blk_storage_elements_report)
+#define BLKREMOVESTORELEM _IOW(0x12, 145, __u32)
+#define BLKRESTORESTORELEMS _IO(0x12, 146)
+
#endif /* _UAPI_BLKZONED_H */
diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
index 34c6f219462a5..8a979326aa7f0 100644
--- a/include/uapi/linux/fs.h
+++ b/include/uapi/linux/fs.h
@@ -309,6 +309,7 @@ struct file_attr {
/* 130-136 and 142 are used by zoned block device ioctls (uapi/linux/blkzoned.h) */
/* 137-141 are used by blk-crypto ioctls (uapi/linux/blk-crypto.h) */
#define BLKTRACESETUP2 _IOWR(0x12, 142, struct blk_user_trace_setup2)
+/* 143-146 are used by storage element management for zoned block devices. */
#define BMAP_IOCTL 1 /* obsolete - kept for compatibility */
#define FIBMAP _IO(0x00,1) /* bmap access */
|
| 3/2 | 2026/10/05 10:28 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 24654 output: 34 thoughts: 765 Thoughts: **Patch Analysis: Syzkaller Fuzzing Suitability** Okay, let's break this down. My initial assessment is: should we consider this for syzkaller fuzzing? The patch seems to be introducing significant new functionality related to zoned block devices and storage element management. First, I need to get a handle on what's changed. The diff touches a bunch of files: documentation, `blk-core.c`, `blk-zoned.c`, header files, `ioctl.c`, the `zloop` driver, and even the SCSI disk code with `sd.c`. Looks like they're adding support for a zoned loop device (`zloop`) and extending zoned block device (ZBC) support for SCSI disks, which is interesting. It also appears they're adding functions for interacting with storage elements through ioctls. I'm seeing functions like `bdev_zone_is_offline()`, `blkdev_get_nr_storage_elements_ioctl()`, and operations for removing and restoring elements, etc. Now, the crucial question: can we actually *reach* this new code in a typical QEMU-based fuzzing environment? I have to look for any dependencies. Oh, wait! The `zloop` driver is a *software* zoned block device driver. That's good news! It means we *don't* need specific hardware to test this. That makes the patch much more interesting for syzkaller. Now I need to see if it can be enabled simply or if there are any hoops to jump through. I'll need to check if `zloop` is built into the kernel, or if it needs a specific configuration option. I'll need to grep for ZLOOP and look in `drivers/block/Makefile` and `Kconfig` to see what's required. |
| 4/2 | 2026/10/05 10:28 | tool | grepper |
0mArgs:{
"Expression": "CONFIG_BLK_DEV_ZLOOP|zloop",
"PathPrefix": "drivers/block"
}Results: {
"Output": "\nFull output is too long, showing 200 out of 821 lines.\nUse more precise expression if possible.\n\ndrivers/block/Kconfig=356=config BLK_DEV_ZONED_LOOP\n--\ndrivers/block/Kconfig-367-\t echo \"add id=0,zone_size_mb=256,capacity_mb=16384,conv_zones=11\" \u003e \\\ndrivers/block/Kconfig:368:\t\t/dev/zloop-control\ndrivers/block/Kconfig-369-\n--\ndrivers/block/Makefile=40=obj-$(CONFIG_BLK_DEV_UBLK)\t\t\t+= ublk_drv.o\ndrivers/block/Makefile:41:obj-$(CONFIG_BLK_DEV_ZONED_LOOP) += zloop.o\ndrivers/block/Makefile-42-\n--\ndrivers/block/zloop.c=25=enum {\n--\ndrivers/block/zloop.c-43-\ndrivers/block/zloop.c:44:static const match_table_t zloop_opt_tokens = {\ndrivers/block/zloop.c-45-\t{ ZLOOP_OPT_ID,\t\t\t\"id=%d\"\t},\n--\ndrivers/block/zloop.c-63-/* Storage elements emulation types. */\ndrivers/block/zloop.c:64:enum zloop_stor_elements {\ndrivers/block/zloop.c-65-\t/* No emulation. */\n--\ndrivers/block/zloop.c-78-#define ZLOOP_DEF_MAX_OPEN_ZONES\t0\ndrivers/block/zloop.c:79:#define ZLOOP_DEF_BASE_DIR\t\t\"/var/local/zloop\"\ndrivers/block/zloop.c-80-#define ZLOOP_DEF_NR_QUEUES\t\t1\n--\ndrivers/block/zloop.c-90-\ndrivers/block/zloop.c:91:struct zloop_options {\ndrivers/block/zloop.c-92-\tunsigned int\t\tmask;\n--\ndrivers/block/zloop.c-105-\tbool\t\t\tdiscard_write_cache;\ndrivers/block/zloop.c:106:\tenum zloop_stor_elements stor_elements;\ndrivers/block/zloop.c-107-\tunsigned int\t\telement_id;\n--\ndrivers/block/zloop.c=113=enum {\n--\ndrivers/block/zloop.c-118-\ndrivers/block/zloop.c:119:enum zloop_zone_flags {\ndrivers/block/zloop.c-120-\tZLOOP_ZONE_CONV = 0,\n--\ndrivers/block/zloop.c-127- */\ndrivers/block/zloop.c:128:struct zloop_zone {\ndrivers/block/zloop.c-129-\tstruct list_head\topen_zone_entry;\n--\ndrivers/block/zloop.c-143-\ndrivers/block/zloop.c:144:struct zloop_device {\ndrivers/block/zloop.c-145-\tunsigned int\t\tid;\n--\ndrivers/block/zloop.c-155-\tbool\t\t\tdiscard_write_cache;\ndrivers/block/zloop.c:156:\tenum zloop_stor_elements stor_elements;\ndrivers/block/zloop.c-157-\n--\ndrivers/block/zloop.c-184-\ndrivers/block/zloop.c:185:\tstruct zloop_zone\tzones[] __counted_by(nr_zones);\ndrivers/block/zloop.c-186-};\ndrivers/block/zloop.c-187-\ndrivers/block/zloop.c:188:struct zloop_cmd {\ndrivers/block/zloop.c-189-\tstruct work_struct\twork;\n--\ndrivers/block/zloop.c-197-\ndrivers/block/zloop.c:198:static DEFINE_IDR(zloop_index_idr);\ndrivers/block/zloop.c:199:static DEFINE_MUTEX(zloop_ctl_mutex);\ndrivers/block/zloop.c-200-\ndrivers/block/zloop.c=201=static unsigned int rq_zone_no(struct request *rq)\ndrivers/block/zloop.c-202-{\ndrivers/block/zloop.c:203:\tstruct zloop_device *zlo = rq-\u003eq-\u003equeuedata;\ndrivers/block/zloop.c-204-\n--\ndrivers/block/zloop.c-207-\ndrivers/block/zloop.c:208:static bool zloop_zone_healthy(struct zloop_device *zlo,\ndrivers/block/zloop.c:209:\t\t\t struct zloop_zone *zone, bool write)\ndrivers/block/zloop.c-210-{\n--\ndrivers/block/zloop.c-236- */\ndrivers/block/zloop.c:237:static inline void zloop_lru_rotate_open_zone(struct zloop_device *zlo,\ndrivers/block/zloop.c:238:\t\t\t\t\t struct zloop_zone *zone)\ndrivers/block/zloop.c-239-{\n--\ndrivers/block/zloop.c-247-\ndrivers/block/zloop.c:248:static inline void zloop_lru_remove_open_zone(struct zloop_device *zlo,\ndrivers/block/zloop.c:249:\t\t\t\t\t struct zloop_zone *zone)\ndrivers/block/zloop.c-250-{\n--\ndrivers/block/zloop.c-259-\ndrivers/block/zloop.c:260:static inline bool zloop_can_open_zone(struct zloop_device *zlo)\ndrivers/block/zloop.c-261-{\n--\ndrivers/block/zloop.c-269- */\ndrivers/block/zloop.c:270:static bool zloop_close_imp_open_zone(struct zloop_device *zlo)\ndrivers/block/zloop.c-271-{\ndrivers/block/zloop.c:272:\tstruct zloop_zone *zone;\ndrivers/block/zloop.c-273-\n--\ndrivers/block/zloop.c-275-\ndrivers/block/zloop.c:276:\tif (zloop_can_open_zone(zlo))\ndrivers/block/zloop.c-277-\t\treturn true;\n--\ndrivers/block/zloop.c-290-\ndrivers/block/zloop.c:291:static bool zloop_open_closed_or_empty_zone(struct zloop_device *zlo,\ndrivers/block/zloop.c:292:\t\t\t\t\t struct zloop_zone *zone,\ndrivers/block/zloop.c-293-\t\t\t\t\t bool explicit)\n--\ndrivers/block/zloop.c-301-\t\t */\ndrivers/block/zloop.c:302:\t\tif (!zloop_can_open_zone(zlo))\ndrivers/block/zloop.c-303-\t\t\tgoto fail;\n--\ndrivers/block/zloop.c-309-\t\t */\ndrivers/block/zloop.c:310:\t\tif (!zloop_close_imp_open_zone(zlo))\ndrivers/block/zloop.c-311-\t\t\tgoto fail;\n--\ndrivers/block/zloop.c-328-\ndrivers/block/zloop.c:329:static bool zloop_do_open_zone(struct zloop_device *zlo,\ndrivers/block/zloop.c:330:\t\t\t struct zloop_zone *zone, bool explicit)\ndrivers/block/zloop.c-331-{\n--\ndrivers/block/zloop.c-336-\t\t\tzone-\u003econd = BLK_ZONE_COND_EXP_OPEN;\ndrivers/block/zloop.c:337:\t\tzloop_lru_rotate_open_zone(zlo, zone);\ndrivers/block/zloop.c-338-\t\treturn true;\n--\ndrivers/block/zloop.c-340-\tcase BLK_ZONE_COND_CLOSED:\ndrivers/block/zloop.c:341:\t\treturn zloop_open_closed_or_empty_zone(zlo, zone, explicit);\ndrivers/block/zloop.c-342-\tdefault:\n--\ndrivers/block/zloop.c-346-\ndrivers/block/zloop.c:347:static void zloop_set_zone_cond(struct zloop_device *zlo,\ndrivers/block/zloop.c:348:\t\t\t\tstruct zloop_zone *zone,\ndrivers/block/zloop.c-349-\t\t\t\tenum blk_zone_cond cond)\n--\ndrivers/block/zloop.c-352-\ndrivers/block/zloop.c:353:\tzloop_lru_remove_open_zone(zlo, zone);\ndrivers/block/zloop.c-354-\tzone-\u003econd = cond;\n--\ndrivers/block/zloop.c-360-\ndrivers/block/zloop.c:361:static inline void zloop_set_zone_full(struct zloop_device *zlo,\ndrivers/block/zloop.c:362:\t\t\t\t struct zloop_zone *zone)\ndrivers/block/zloop.c-363-{\ndrivers/block/zloop.c:364:\tzloop_set_zone_cond(zlo, zone, BLK_ZONE_COND_FULL);\ndrivers/block/zloop.c-365-}\ndrivers/block/zloop.c-366-\ndrivers/block/zloop.c:367:static inline void zloop_set_zone_empty(struct zloop_device *zlo,\ndrivers/block/zloop.c:368:\t\t\t\t\tstruct zloop_zone *zone)\ndrivers/block/zloop.c-369-{\ndrivers/block/zloop.c:370:\tzloop_set_zone_cond(zlo, zone, BLK_ZONE_COND_EMPTY);\ndrivers/block/zloop.c-371-}\ndrivers/block/zloop.c-372-\ndrivers/block/zloop.c:373:static int zloop_update_seq_zone(struct zloop_device *zlo, unsigned int zone_no)\ndrivers/block/zloop.c-374-{\ndrivers/block/zloop.c:375:\tstruct zloop_zone *zone = \u0026zlo-\u003ezones[zone_no];\ndrivers/block/zloop.c-376-\tstruct kstat stat;\n--\ndrivers/block/zloop.c-404-\tif (!file_sectors) {\ndrivers/block/zloop.c:405:\t\tzloop_set_zone_empty(zlo, zone);\ndrivers/block/zloop.c-406-\t} else if (file_sectors == zlo-\u003ezone_capacity) {\ndrivers/block/zloop.c:407:\t\tzloop_set_zone_full(zlo, zone);\ndrivers/block/zloop.c-408-\t} else {\n--\ndrivers/block/zloop.c-418-\ndrivers/block/zloop.c:419:static int zloop_open_zone(struct zloop_device *zlo, unsigned int zone_no)\ndrivers/block/zloop.c-420-{\ndrivers/block/zloop.c:421:\tstruct zloop_zone *zone = \u0026zlo-\u003ezones[zone_no];\ndrivers/block/zloop.c-422-\tint ret = 0;\n--\ndrivers/block/zloop.c-435-\tif (test_and_clear_bit(ZLOOP_ZONE_SEQ_ERROR, \u0026zone-\u003eflags)) {\ndrivers/block/zloop.c:436:\t\tret = zloop_update_seq_zone(zlo, zone_no);\ndrivers/block/zloop.c-437-\t\tif (ret)\n--\ndrivers/block/zloop.c-440-\ndrivers/block/zloop.c:441:\tif (!zloop_do_open_zone(zlo, zone, true))\ndrivers/block/zloop.c-442-\t\tret = -EIO;\n--\ndrivers/block/zloop.c-449-\ndrivers/block/zloop.c:450:static int zloop_close_zone(struct zloop_device *zlo, unsigned int zone_no)\ndrivers/block/zloop.c-451-{\ndrivers/block/zloop.c:452:\tstruct zloop_zone *zone = \u0026zlo-\u003ezones[zone_no];\ndrivers/block/zloop.c-453-\tint ret = 0;\n--\ndrivers/block/zloop.c-466-\tif (test_and_clear_bit(ZLOOP_ZONE_SEQ_ERROR, \u0026zone-\u003eflags)) {\ndrivers/block/zloop.c:467:\t\tret = zloop_update_seq_zone(zlo, zone_no);\ndrivers/block/zloop.c-468-\t\tif (ret)\n--\ndrivers/block/zloop.c-477-\t\tspin_lock(\u0026zone-\u003ewp_lock);\ndrivers/block/zloop.c:478:\t\tzloop_lru_remove_open_zone(zlo, zone);\ndrivers/block/zloop.c-479-\t\tif (zone-\u003ewp == zone-\u003estart)\n--\ndrivers/block/zloop.c-497-\ndrivers/block/zloop.c:498:static int zloop_do_reset_zone(struct zloop_device *zlo,\ndrivers/block/zloop.c:499:\t\t\t struct zloop_zone *zone)\ndrivers/block/zloop.c-500-{\n--\ndrivers/block/zloop.c-504-\tspin_lock(\u0026zone-\u003ewp_lock);\ndrivers/block/zloop.c:505:\tzloop_set_zone_empty(zlo, zone);\ndrivers/block/zloop.c-506-\tclear_bit(ZLOOP_ZONE_SEQ_ERROR, \u0026zone-\u003eflags);\n--\ndrivers/block/zloop.c-511-\ndrivers/block/zloop.c:512:static int zloop_reset_zone(struct zloop_device *zlo, unsigned int zone_no,\ndrivers/block/zloop.c-513-\t\t\t bool all_zones)\ndrivers/block/zloop.c-514-{\ndrivers/block/zloop.c:515:\tstruct zloop_zone *zone = \u0026zlo-\u003ezones[zone_no];\ndrivers/block/zloop.c-516-\tint ret = 0;\n--\ndrivers/block/zloop.c-533-\ndrivers/block/zloop.c:534:\tret = zloop_do_reset_zone(zlo, zone);\n\n"
} |
| 5/2 | 2026/10/05 10:28 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29619 output: 34 thoughts: 17 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Diving into the Block Driver Configuration** Right, let's zero in on the block driver configuration. I need to refresh my memory on the specifics of this area. It's time to dig into the `drivers/block/Kconfig` file, and I'm thinking somewhere around line 356 should be a good starting point. I suspect that's where the relevant options or dependencies for the specific functionality I'm interested in are defined. It's often where I find the conditional logic that controls which block drivers are built or included based on hardware or other configuration settings. I'm hoping to quickly identify the relevant Kconfig symbols. |
| 6/2 | 2026/10/05 10:28 | tool | read-file |
0mArgs:{
"File": "drivers/block/Kconfig",
"FirstLine": 355,
"LineCount": 40
}Results: {
"Contents": " 355:\t\n 356:\tconfig BLK_DEV_ZONED_LOOP\n 357:\t\ttristate \"Zoned loopback device support\"\n 358:\t\tdepends on BLK_DEV_ZONED\n 359:\t\thelp\n 360:\t\t Saying Y here will allow you to use create a zoned block device using\n 361:\t\t regular files for zones (one file per zones). This is useful to test\n 362:\t\t file systems, device mapper and applications that support zoned block\n 363:\t\t devices. To create a zoned loop device, no user utility is needed, a\n 364:\t\t zoned loop device can be created (or re-started) using a command\n 365:\t\t like:\n 366:\t\n 367:\t\t echo \"add id=0,zone_size_mb=256,capacity_mb=16384,conv_zones=11\" \u003e \\\n 368:\t\t\t/dev/zloop-control\n 369:\t\n 370:\t\t See Documentation/admin-guide/blockdev/zoned_loop.rst for usage\n 371:\t\t details.\n 372:\t\n 373:\t\t If unsure, say N.\n 374:\t\n 375:\tendif # BLK_DEV\n"
} |
| 7/2 | 2026/10/05 10:28 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 30176 output: 36 thoughts: 725 Thoughts: **Diving into Zoned Block Device Interactions** Okay, so I need to understand how this zoned block device functionality is implemented. First, I'll start by tracing the code paths involved in these new IOCTL calls. I see they touch the core block layer – specifically `blk-core.c`, `blk-zoned.c`, and `ioctl.c`. These files introduce new IOCTL codes: `BLKGETNRSTORELEMS`, `BLKREPORTSTORELEMS`, `BLKREMOVESTORELEM`, and `BLKRESTORESTORELEMS`. These IOCTLs, which can be called on any zoned block device, are interesting. I notice that the `zloop` driver, the software-emulated block device, is involved here as well. That is, the virtual loop device that runs entirely in software (using regular files) and can be controlled via `/dev/zloop-control`. The SCSI ZBC driver (`sd_zbc.c`) also supports this. So it's not just a single point of interaction; it's spread across multiple subsystems. Now, a critical thought: could this code be triggered via fuzzing? And the answer is yes, this seems very accessible. Standard virtualized environments like QEMU and GCE all have block layer support, loop devices, the `zloop` driver, and SCSI disks. Any program that opens a block device and issues those new IOCTLs could hit this code path. Let's dig deeper into one of the IOCTL handlers, specifically `blkdev_zone_storage_elements_ioctl`. I see a crucial check: `!bdev_is_zoned(bdev) || !bdev->bd_disk->fops->se_ops`. If it's a zoned block device, and the `se_ops` pointer is not null, then the rest of the code is executed. That means with `zloop`, where `bdev_is_zoned(bdev)` becomes true, and `se_ops` becomes non-null, this condition can be satisfied. And I can create a `zloop` by writing to `/dev/zloop-control`! This means I'm going to investigate how `/dev/zloop-control` is handled in `drivers/block/zloop.c`. That seems like the entry point. |
| 8/2 | 2026/10/05 10:28 | tool | grepper |
0mArgs:{
"Expression": "misc_register|zloop_ctl",
"PathPrefix": "drivers/block/zloop.c"
}Results: {
"Output": "drivers/block/zloop.c=198=static DEFINE_IDR(zloop_index_idr);\ndrivers/block/zloop.c:199:static DEFINE_MUTEX(zloop_ctl_mutex);\ndrivers/block/zloop.c-200-\n--\ndrivers/block/zloop.c=1021=static int zloop_open(struct gendisk *disk, blk_mode_t mode)\n--\ndrivers/block/zloop.c-1025-\ndrivers/block/zloop.c:1026:\tret = mutex_lock_killable(\u0026zloop_ctl_mutex);\ndrivers/block/zloop.c-1027-\tif (ret)\n--\ndrivers/block/zloop.c-1031-\t\tret = -ENXIO;\ndrivers/block/zloop.c:1032:\tmutex_unlock(\u0026zloop_ctl_mutex);\ndrivers/block/zloop.c-1033-\treturn ret;\n--\ndrivers/block/zloop.c=1639=static bool zloop_dev_exists(struct zloop_device *zlo)\n--\ndrivers/block/zloop.c-1657-\ndrivers/block/zloop.c:1658:static int zloop_ctl_add(struct zloop_options *opts)\ndrivers/block/zloop.c-1659-{\n--\ndrivers/block/zloop.c-1698-\ndrivers/block/zloop.c:1699:\tret = mutex_lock_killable(\u0026zloop_ctl_mutex);\ndrivers/block/zloop.c-1700-\tif (ret)\n--\ndrivers/block/zloop.c-1711-\t}\ndrivers/block/zloop.c:1712:\tmutex_unlock(\u0026zloop_ctl_mutex);\ndrivers/block/zloop.c-1713-\tif (ret \u003c 0)\n--\ndrivers/block/zloop.c-1820-\ndrivers/block/zloop.c:1821:\tmutex_lock(\u0026zloop_ctl_mutex);\ndrivers/block/zloop.c-1822-\tWRITE_ONCE(zlo-\u003estate, Zlo_live);\ndrivers/block/zloop.c:1823:\tmutex_unlock(\u0026zloop_ctl_mutex);\ndrivers/block/zloop.c-1824-\n--\ndrivers/block/zloop.c-1858-out_free_idr:\ndrivers/block/zloop.c:1859:\tmutex_lock(\u0026zloop_ctl_mutex);\ndrivers/block/zloop.c-1860-\tidr_remove(\u0026zloop_index_idr, zlo-\u003eid);\ndrivers/block/zloop.c:1861:\tmutex_unlock(\u0026zloop_ctl_mutex);\ndrivers/block/zloop.c-1862-out_free_dev:\n--\ndrivers/block/zloop.c=1871=static void zloop_forget_cache(struct zloop_device *zlo)\n--\ndrivers/block/zloop.c-1909-\ndrivers/block/zloop.c:1910:static int zloop_ctl_remove(struct zloop_options *opts)\ndrivers/block/zloop.c-1911-{\n--\ndrivers/block/zloop.c-1924-\ndrivers/block/zloop.c:1925:\tret = mutex_lock_killable(\u0026zloop_ctl_mutex);\ndrivers/block/zloop.c-1926-\tif (ret)\n--\ndrivers/block/zloop.c-1938-\ndrivers/block/zloop.c:1939:\tmutex_unlock(\u0026zloop_ctl_mutex);\ndrivers/block/zloop.c-1940-\tif (ret)\n--\ndrivers/block/zloop.c-1956-\ndrivers/block/zloop.c:1957:static int zloop_ctl_degrade_element(struct zloop_options *opts)\ndrivers/block/zloop.c-1958-{\n--\ndrivers/block/zloop.c-1971-\ndrivers/block/zloop.c:1972:\tmutex_lock(\u0026zloop_ctl_mutex);\ndrivers/block/zloop.c-1973-\tzlo = idr_find(\u0026zloop_index_idr, opts-\u003eid);\n--\ndrivers/block/zloop.c-1977-\t\tret = -EINVAL;\ndrivers/block/zloop.c:1978:\tmutex_unlock(\u0026zloop_ctl_mutex);\ndrivers/block/zloop.c-1979-\tif (ret)\n--\ndrivers/block/zloop.c=2194=enum {\n--\ndrivers/block/zloop.c-2199-\ndrivers/block/zloop.c:2200:static struct zloop_ctl_op {\ndrivers/block/zloop.c-2201-\tint\t\tcode;\ndrivers/block/zloop.c-2202-\tconst char\t*name;\ndrivers/block/zloop.c:2203:} zloop_ctl_ops[] = {\ndrivers/block/zloop.c-2204-\t{ ZLOOP_CTL_ADD,\t\t\"add\" },\n--\ndrivers/block/zloop.c-2209-\ndrivers/block/zloop.c:2210:static ssize_t zloop_ctl_write(struct file *file, const char __user *ubuf,\ndrivers/block/zloop.c-2211-\t\t\t size_t count, loff_t *pos)\n--\ndrivers/block/zloop.c-2213-\tstruct zloop_options opts = { };\ndrivers/block/zloop.c:2214:\tstruct zloop_ctl_op *op;\ndrivers/block/zloop.c-2215-\tconst char *buf, *opts_buf;\n--\ndrivers/block/zloop.c-2224-\ndrivers/block/zloop.c:2225:\tfor (i = 0; i \u003c ARRAY_SIZE(zloop_ctl_ops); i++) {\ndrivers/block/zloop.c:2226:\t\top = \u0026zloop_ctl_ops[i];\ndrivers/block/zloop.c-2227-\t\tif (!op-\u003ename) {\n--\ndrivers/block/zloop.c-2248-\tcase ZLOOP_CTL_ADD:\ndrivers/block/zloop.c:2249:\t\tret = zloop_ctl_add(\u0026opts);\ndrivers/block/zloop.c-2250-\t\tbreak;\ndrivers/block/zloop.c-2251-\tcase ZLOOP_CTL_REMOVE:\ndrivers/block/zloop.c:2252:\t\tret = zloop_ctl_remove(\u0026opts);\ndrivers/block/zloop.c-2253-\t\tbreak;\ndrivers/block/zloop.c-2254-\tcase ZLOOP_CTL_DEGRADE_ELEMENT:\ndrivers/block/zloop.c:2255:\t\tret = zloop_ctl_degrade_element(\u0026opts);\ndrivers/block/zloop.c-2256-\t\tbreak;\n--\ndrivers/block/zloop.c-2268-\ndrivers/block/zloop.c:2269:static int zloop_ctl_show(struct seq_file *seq_file, void *private)\ndrivers/block/zloop.c-2270-{\n--\ndrivers/block/zloop.c-2274-\t/* Add operation */\ndrivers/block/zloop.c:2275:\tseq_printf(seq_file, \"%s \", zloop_ctl_ops[0].name);\ndrivers/block/zloop.c-2276-\tfor (i = 0; i \u003c ARRAY_SIZE(zloop_opt_tokens); i++) {\n--\ndrivers/block/zloop.c-2288-\t/* Remove operation */\ndrivers/block/zloop.c:2289:\tseq_puts(seq_file, zloop_ctl_ops[1].name);\ndrivers/block/zloop.c-2290-\tseq_puts(seq_file, \" id=%d\\n\");\n--\ndrivers/block/zloop.c-2292-\t/* Degrade element operation */\ndrivers/block/zloop.c:2293:\tseq_puts(seq_file, zloop_ctl_ops[2].name);\ndrivers/block/zloop.c-2294-\tseq_puts(seq_file, \" id=%d,element_id=%d\\n\");\n--\ndrivers/block/zloop.c-2298-\ndrivers/block/zloop.c:2299:static int zloop_ctl_open(struct inode *inode, struct file *file)\ndrivers/block/zloop.c-2300-{\ndrivers/block/zloop.c-2301-\tfile-\u003eprivate_data = NULL;\ndrivers/block/zloop.c:2302:\treturn single_open(file, zloop_ctl_show, NULL);\ndrivers/block/zloop.c-2303-}\ndrivers/block/zloop.c-2304-\ndrivers/block/zloop.c:2305:static int zloop_ctl_release(struct inode *inode, struct file *file)\ndrivers/block/zloop.c-2306-{\n--\ndrivers/block/zloop.c-2309-\ndrivers/block/zloop.c:2310:static const struct file_operations zloop_ctl_fops = {\ndrivers/block/zloop.c-2311-\t.owner\t\t= THIS_MODULE,\ndrivers/block/zloop.c:2312:\t.open\t\t= zloop_ctl_open,\ndrivers/block/zloop.c:2313:\t.release\t= zloop_ctl_release,\ndrivers/block/zloop.c:2314:\t.write\t\t= zloop_ctl_write,\ndrivers/block/zloop.c-2315-\t.read\t\t= seq_read,\n--\ndrivers/block/zloop.c=2318=static struct miscdevice zloop_misc = {\n--\ndrivers/block/zloop.c-2320-\t.name\t\t= \"zloop-control\",\ndrivers/block/zloop.c:2321:\t.fops\t\t= \u0026zloop_ctl_fops,\ndrivers/block/zloop.c-2322-};\n--\ndrivers/block/zloop.c=2324=static int __init zloop_init(void)\n--\ndrivers/block/zloop.c-2327-\ndrivers/block/zloop.c:2328:\tret = misc_register(\u0026zloop_misc);\ndrivers/block/zloop.c-2329-\tif (ret) {\n"
} |
| 9/2 | 2026/10/05 10:28 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 34191 output: 32 thoughts: 1639 Thoughts: **Initial Assessment of Zloop Device Storage Element Management** Okay, so `/dev/zloop-control` is a `miscdevice`. That means user space, or, more interestingly, something like syzkaller, can interact with it directly to fiddle with the storage elements of zloop devices – adding, removing, and degrading them. The code allows userspace to open the created block device, for example, `/dev/zloop0`, and perform all sorts of block device ioctls, including ones specific to storage element operations. I can use the provided ioctls like `BLKGETNRSTORELEMS`, `BLKREPORTSTORELEMS`, `BLKREMOVESTORELEM`, and `BLKRESTORESTORELEMS`, alongside standard read/write I/O, which checks `bdev_zone_is_offline`. Let's dig in and see if we can uncover anything interesting. First, I'm going to look at `bdev_remove_storage_element`. It's a key function for removing storage elements, and the code includes a queue freeze/unfreeze, a flush of the volatile write cache (potentially leading to errors if degraded elements are used – they ignore those errors), and, importantly, an `invalidate_inode_pages2_range` call. Then there is a call to `disk_wait_for_se_mgmt_completion`. Now, looking at `disk_wait_for_se_mgmt_completion`, the interesting bit is the `while` loop that polls for the storage element status with `msleep(500)`. It calls `report_elements`, and sleeps until the remove or restore operations are done. In `zloop` itself, `zloop_remove_element` schedules delayed work with a 2-second delay. So, we're likely waiting for an asynchronous operation. Let's check `blkdev_report_storage_elements_ioctl`. My attention is drawn to the `copy_to_user` call. The function copies the elements to user space, but there might be a problem with how the pointer arithmetic is handled. The code calculates the destination address as `argp + sizeof(struct blk_storage_elements_report)`. That's fine if the `argp` is correctly typed, but `argp` is of type `void __user *`, isn't pointer arithmetic on a `void *` equivalent to `sizeof(void)`? That seems suspicious. And, look: `rep.nr_elements = nr_elements;` and, more importantly: `retc = copy_to_user(argp, ...)`! That could be a bug. Finally, let's revisit `bdev_remove_storage_element` and that `invalidate_inode_pages2_range` call. The code calculates the end range using `get_capacity(disk) << SECTOR_SHIFT`. `get_capacity` returns in sectors (512 bytes), which we shift by the sector shift. `invalidate_inode_pages2_range` takes `pgoff_t` arguments that represents page offsets. Is this a page offset or a byte offset? I need to double-check that definition to be sure. This could be a potential vulnerability if the calculation isn't correct. |
| 10/2 | 2026/10/05 10:29 | tool | grepper |
0mArgs:{
"Expression": "invalidate_inode_pages2_range\\(",
"PathPrefix": "include/linux"
}Results: {
"Output": "include/linux/pagemap.h=30=int invalidate_inode_pages2(struct address_space *mapping);\ninclude/linux/pagemap.h:31:int invalidate_inode_pages2_range(struct address_space *mapping,\ninclude/linux/pagemap.h-32-\t\tpgoff_t start, pgoff_t end);\n"
} |
| 11/2 | 2026/10/05 10:29 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 36670 output: 32 thoughts: 2228 Thoughts: **Code Deep Dive and Fuzzing Considerations** Alright, let's break this down. First off, I'm concerned about `invalidate_inode_pages2_range`. The use of `get_capacity(disk) << SECTOR_SHIFT` directly translates bytes into what's being used as an index, which feels inherently risky, especially with potential 32-bit `pgoff_t` limitations. This could lead to overflows or incorrect page invalidation. I'll need to keep an eye on that. Now, let's move to `zloop_rw`. I see a health check: `zloop_zone_healthy`. Hold on, this function's logic is, frankly, bizarre. It *returns true* if the storage element's status is `BLK_SE_STS_DEGRADED`. What? Shouldn't a "healthy" zone be... well, healthy? Returning true on a degraded state means writes will *succeed* to degraded elements. A healthy element status returns `false`, which would block I/O. So, a *normal* element being healthy is considered unhealthy and would cause I/O to fail. That's a definite bug. It also raises the question: what if `zone->wr_se_id` is zero? I'll have to investigate that further. Looking at `zloop_init_zone`, if `zlo->stor_elements` is `ZLOOP_STOR_ELEMENTS_NONE`, I see that the zone is deemed healthy. That's fine. Now, for `sd_zbc_check_modify_zones` and the `zloop_ctl_degrade_element` function, I have to ensure the proper checks are happening. Then, `zloop_degrade_element` checks if the status is OK. If it *is*, then it sets to degraded. Okay. Going further, looking at `zloop_remove_element`, I see it uses the storage element ID. What happens if this ID is zero? A crucial point now: the `bdev_remove_storage_element` explicitly checks `!element_id`. However, in `zloop_remove_element_work`, I see the potential for a `WARN_ON_ONCE(1)`! This is interesting, and it triggers my fuzzing instincts. Given that I've identified multiple points of potential vulnerability and this entire patch touches core block layer functions, driver implementations in both `zloop` and `sd_zbc`, and adds new ioctls, I'm confident that this is worth fuzzing. I'll need to enable `CONFIG_BLK_DEV_ZONED` and make sure my setup is correct. |
| 12/2 | 2026/10/05 10:29 | tool | grepper |
0mArgs:{
"Expression": "config BLK_DEV_ZONED\\b",
"PathPrefix": "block"
}Results: {
"Output": "block/Kconfig=77=config BLK_DEV_WRITE_MOUNTED\n--\nblock/Kconfig-96-\nblock/Kconfig:97:config BLK_DEV_ZONED\nblock/Kconfig-98-\tbool \"Zoned block device support\"\n"
} |
| 13/2 | 2026/10/05 10:29 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 39589 output: 31 thoughts: 16 Thoughts: Okay, let's dive into this. Here's my thought process summarized, assuming I'm already pretty familiar with this codebase: **Investigating `block/Kconfig`** Alright, I need to take a look at the `block/Kconfig` file. Specifically, my hunch is that something interesting is happening around line 97. That section likely defines some configuration options related to block device handling or features. I'll need to refresh my memory on what's defined there, perhaps related to a feature flag, a default value, or a dependency condition. I'm expecting to see configuration variables and their relationships, which might give insight into a recent change or a potential issue I'm investigating. I am expecting to review a configuration which may assist in a particular aspect of a block device. |
| 14/2 | 2026/10/05 10:29 | tool | read-file |
0mArgs:{
"File": "block/Kconfig",
"FirstLine": 95,
"LineCount": 20
}Results: {
"Contents": " 95:\t\twith the bdev_allow_write_mounted boot option.\n 96:\t\n 97:\tconfig BLK_DEV_ZONED\n 98:\t\tbool \"Zoned block device support\"\n 99:\t\thelp\n 100:\t\tBlock layer zoned block device support. This option enables\n 101:\t\tsupport for ZAC/ZBC/ZNS host-managed and host-aware zoned block\n 102:\t\tdevices.\n 103:\t\n 104:\t\tSay yes here if you have a ZAC, ZBC, or ZNS storage device.\n 105:\t\n 106:\tconfig BLK_DEV_THROTTLING\n 107:\t\tbool \"Block layer bio throttling support\"\n 108:\t\tdepends on BLK_CGROUP\n 109:\t\tselect BLK_CGROUP_RWSTAT\n 110:\t\thelp\n 111:\t\tBlock layer bio throttling support. It can be used to limit\n 112:\t\tthe IO rate to a device. IO rate policies are per cgroup and\n 113:\t\tone needs to mount and use blkio cgroup controller for creating\n 114:\t\tcgroups and specifying per device IO rate policies.\n"
} |
| 15/2 | 2026/10/05 10:29 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 40122 output: 28 thoughts: 93 Thoughts: Okay, let me break this down. **Zoned Block Device Configuration Deep Dive** Alright, so `BLK_DEV_ZONED` is a straightforward boolean – no dependencies, easy enough. My next thought is, let's look at `BLK_DEV_ZONED_LOOP` within the block driver configuration. The Kconfig file in `drivers/block` should tell me the dependencies. Yep, as expected, it's reliant on `BLK_DEV_ZONED`. Now, I need to understand the relationship with the SCSI subsystem, specifically `drivers/scsi/sd_zbc.c`. I need to track how this ties together. So, I should check the `Makefile` and `Kconfig` files within the `drivers/scsi` directory. This will reveal the build process and configuration options for zoned block devices within the SCSI framework. I'm looking for the relevant dependencies and build flags to get a clear picture of the whole stack. |
| 16/2 | 2026/10/05 10:29 | tool | grepper |
0mArgs:{
"Expression": "sd_zbc",
"PathPrefix": "drivers/scsi"
}Results: {
"Output": "\nFull output is too long, showing 200 out of 273 lines.\nUse more precise expression if possible.\n\ndrivers/scsi/Makefile=36=CONTEXT_ANALYSIS_sd_dif.o := y\ndrivers/scsi/Makefile:37:CONTEXT_ANALYSIS_sd_zbc.o := y\ndrivers/scsi/Makefile-38-CONTEXT_ANALYSIS_sr.o := y\n--\ndrivers/scsi/Makefile=199=sd_mod-$(CONFIG_BLK_DEV_INTEGRITY) += sd_dif.o\ndrivers/scsi/Makefile:200:sd_mod-$(CONFIG_BLK_DEV_ZONED) += sd_zbc.o\ndrivers/scsi/Makefile-201-\n--\ndrivers/scsi/sd.c=1537=static blk_status_t sd_init_command(struct scsi_cmnd *cmd)\n--\ndrivers/scsi/sd.c-1562-\tcase REQ_OP_ZONE_RESET:\ndrivers/scsi/sd.c:1563:\t\treturn sd_zbc_setup_zone_mgmt_cmnd(cmd, ZO_RESET_WRITE_POINTER,\ndrivers/scsi/sd.c-1564-\t\t\t\t\t\t false);\ndrivers/scsi/sd.c-1565-\tcase REQ_OP_ZONE_RESET_ALL:\ndrivers/scsi/sd.c:1566:\t\treturn sd_zbc_setup_zone_mgmt_cmnd(cmd, ZO_RESET_WRITE_POINTER,\ndrivers/scsi/sd.c-1567-\t\t\t\t\t\t true);\ndrivers/scsi/sd.c-1568-\tcase REQ_OP_ZONE_OPEN:\ndrivers/scsi/sd.c:1569:\t\treturn sd_zbc_setup_zone_mgmt_cmnd(cmd, ZO_OPEN_ZONE, false);\ndrivers/scsi/sd.c-1570-\tcase REQ_OP_ZONE_CLOSE:\ndrivers/scsi/sd.c:1571:\t\treturn sd_zbc_setup_zone_mgmt_cmnd(cmd, ZO_CLOSE_ZONE, false);\ndrivers/scsi/sd.c-1572-\tcase REQ_OP_ZONE_FINISH:\ndrivers/scsi/sd.c:1573:\t\treturn sd_zbc_setup_zone_mgmt_cmnd(cmd, ZO_FINISH_ZONE, false);\ndrivers/scsi/sd.c-1574-\tdefault:\n--\ndrivers/scsi/sd.c=2369=static int sd_done(struct scsi_cmnd *SCpnt)\n--\ndrivers/scsi/sd.c-2474-\tif (sdkp-\u003edevice-\u003etype == TYPE_ZBC)\ndrivers/scsi/sd.c:2475:\t\tgood_bytes = sd_zbc_complete(SCpnt, good_bytes, \u0026sshdr);\ndrivers/scsi/sd.c-2476-\n--\ndrivers/scsi/sd.c=3773=static void sd_revalidate_disk(struct gendisk *disk)\n--\ndrivers/scsi/sd.c-3830-\t\t\tsd_read_block_characteristics(sdkp, lim);\ndrivers/scsi/sd.c:3831:\t\t\tsd_zbc_read_zones(sdkp, lim, buffer);\ndrivers/scsi/sd.c-3832-\t\t}\n--\ndrivers/scsi/sd.c-3897-\t */\ndrivers/scsi/sd.c:3898:\tif (sd_zbc_revalidate_zones(sdkp))\ndrivers/scsi/sd.c-3899-\t\tset_capacity_and_notify(disk, 0);\n--\ndrivers/scsi/sd.c=3927=static const struct block_device_operations sd_fops = {\n--\ndrivers/scsi/sd.c-3935-\t.unlock_native_capacity\t= sd_unlock_native_capacity,\ndrivers/scsi/sd.c:3936:\t.report_zones\t\t= sd_zbc_report_zones,\ndrivers/scsi/sd.c-3937-\t.get_unique_id\t\t= sd_get_unique_id,\n--\ndrivers/scsi/sd.c-3939-\t.pr_ops\t\t\t= \u0026sd_pr_ops,\ndrivers/scsi/sd.c:3940:\t.se_ops\t\t\t= \u0026sd_zbc_se_ops,\ndrivers/scsi/sd.c-3941-};\n--\ndrivers/scsi/sd.h=232=void sd_dif_config_host(struct scsi_disk *sdkp, struct queue_limits *lim);\n--\ndrivers/scsi/sd.h-235-\ndrivers/scsi/sd.h:236:int sd_zbc_read_zones(struct scsi_disk *sdkp, struct queue_limits *lim,\ndrivers/scsi/sd.h-237-\t\tu8 buf[SD_BUF_SIZE]);\ndrivers/scsi/sd.h:238:int sd_zbc_revalidate_zones(struct scsi_disk *sdkp);\ndrivers/scsi/sd.h:239:blk_status_t sd_zbc_setup_zone_mgmt_cmnd(struct scsi_cmnd *cmd,\ndrivers/scsi/sd.h-240-\t\t\t\t\t unsigned char op, bool all);\ndrivers/scsi/sd.h:241:unsigned int sd_zbc_complete(struct scsi_cmnd *cmd, unsigned int good_bytes,\ndrivers/scsi/sd.h-242-\t\t\t struct scsi_sense_hdr *sshdr);\ndrivers/scsi/sd.h:243:int sd_zbc_report_zones(struct gendisk *disk, sector_t sector,\ndrivers/scsi/sd.h-244-\t\tunsigned int nr_zones, struct blk_report_zones_args *args);\ndrivers/scsi/sd.h-245-\ndrivers/scsi/sd.h:246:extern const struct blk_storage_elements_ops sd_zbc_se_ops;\ndrivers/scsi/sd.h-247-\n--\ndrivers/scsi/sd.h-249-\ndrivers/scsi/sd.h:250:static inline int sd_zbc_read_zones(struct scsi_disk *sdkp,\ndrivers/scsi/sd.h-251-\t\tstruct queue_limits *lim, u8 buf[SD_BUF_SIZE])\n--\ndrivers/scsi/sd.h-255-\ndrivers/scsi/sd.h:256:static inline int sd_zbc_revalidate_zones(struct scsi_disk *sdkp)\ndrivers/scsi/sd.h-257-{\n--\ndrivers/scsi/sd.h-260-\ndrivers/scsi/sd.h:261:static inline blk_status_t sd_zbc_setup_zone_mgmt_cmnd(struct scsi_cmnd *cmd,\ndrivers/scsi/sd.h-262-\t\t\t\t\t\t unsigned char op,\n--\ndrivers/scsi/sd.h-267-\ndrivers/scsi/sd.h:268:static inline unsigned int sd_zbc_complete(struct scsi_cmnd *cmd,\ndrivers/scsi/sd.h-269-\t\t\tunsigned int good_bytes, struct scsi_sense_hdr *sshdr)\n--\ndrivers/scsi/sd.h-273-\ndrivers/scsi/sd.h:274:#define sd_zbc_report_zones NULL\ndrivers/scsi/sd.h-275-\ndrivers/scsi/sd.h:276:#define sd_zbc_se_ops\tNULL\ndrivers/scsi/sd.h-277-\n--\ndrivers/scsi/sd_zbc.c-26-/* Whether or not a SCSI zone descriptor describes a gap zone. */\ndrivers/scsi/sd_zbc.c:27:static bool sd_zbc_is_gap_zone(const u8 buf[64])\ndrivers/scsi/sd_zbc.c-28-{\n--\ndrivers/scsi/sd_zbc.c-32-/**\ndrivers/scsi/sd_zbc.c:33: * sd_zbc_parse_report - Parse a SCSI zone descriptor\ndrivers/scsi/sd_zbc.c-34- * @sdkp: SCSI disk pointer.\n--\ndrivers/scsi/sd_zbc.c-36- * @idx: Index of the zone relative to the first zone reported by the current\ndrivers/scsi/sd_zbc.c:37: *\tsd_zbc_report_zones() call.\ndrivers/scsi/sd_zbc.c-38- * @args: report zones arguments (callback, etc)\n--\ndrivers/scsi/sd_zbc.c-44- */\ndrivers/scsi/sd_zbc.c:45:static int sd_zbc_parse_report(struct scsi_disk *sdkp, const u8 buf[64],\ndrivers/scsi/sd_zbc.c-46-\t\t\tunsigned int idx, struct blk_report_zones_args *args)\n--\ndrivers/scsi/sd_zbc.c-51-\ndrivers/scsi/sd_zbc.c:52:\tif (WARN_ON_ONCE(sd_zbc_is_gap_zone(buf)))\ndrivers/scsi/sd_zbc.c-53-\t\treturn -EINVAL;\n--\ndrivers/scsi/sd_zbc.c-91-/**\ndrivers/scsi/sd_zbc.c:92: * sd_zbc_do_report_zones - Issue a REPORT ZONES scsi command.\ndrivers/scsi/sd_zbc.c-93- * @sdkp: The target disk\n--\ndrivers/scsi/sd_zbc.c-104- */\ndrivers/scsi/sd_zbc.c:105:static int sd_zbc_do_report_zones(struct scsi_disk *sdkp, unsigned char *buf,\ndrivers/scsi/sd_zbc.c-106-\t\t\t\t unsigned int buflen, sector_t lba,\n--\ndrivers/scsi/sd_zbc.c-149-/**\ndrivers/scsi/sd_zbc.c:150: * sd_zbc_alloc_report_buffer() - Allocate a buffer for report zones reply.\ndrivers/scsi/sd_zbc.c-151- * @sdkp: The target disk\n--\ndrivers/scsi/sd_zbc.c-161- */\ndrivers/scsi/sd_zbc.c:162:static void *sd_zbc_alloc_report_buffer(struct scsi_disk *sdkp,\ndrivers/scsi/sd_zbc.c-163-\t\t\t\t\tunsigned int nr_zones, size_t *buflen)\n--\ndrivers/scsi/sd_zbc.c-200-/**\ndrivers/scsi/sd_zbc.c:201: * sd_zbc_zone_sectors - Get the device zone size in number of 512B sectors.\ndrivers/scsi/sd_zbc.c-202- * @sdkp: The target disk\ndrivers/scsi/sd_zbc.c-203- */\ndrivers/scsi/sd_zbc.c:204:static inline sector_t sd_zbc_zone_sectors(struct scsi_disk *sdkp)\ndrivers/scsi/sd_zbc.c-205-{\n--\ndrivers/scsi/sd_zbc.c-209-/**\ndrivers/scsi/sd_zbc.c:210: * sd_zbc_report_zones - SCSI .report_zones() callback.\ndrivers/scsi/sd_zbc.c-211- * @disk: Disk to report zones for.\n--\ndrivers/scsi/sd_zbc.c-218- */\ndrivers/scsi/sd_zbc.c:219:int sd_zbc_report_zones(struct gendisk *disk, sector_t sector,\ndrivers/scsi/sd_zbc.c-220-\t\t\tunsigned int nr_zones,\n--\ndrivers/scsi/sd_zbc.c-239-\ndrivers/scsi/sd_zbc.c:240:\tbuf = sd_zbc_alloc_report_buffer(sdkp, nr_zones, \u0026buflen);\ndrivers/scsi/sd_zbc.c-241-\tif (!buf)\n--\ndrivers/scsi/sd_zbc.c-244-\twhile (zone_idx \u003c nr_zones \u0026\u0026 lba \u003c sdkp-\u003ecapacity) {\ndrivers/scsi/sd_zbc.c:245:\t\tret = sd_zbc_do_report_zones(sdkp, buf, buflen, lba, true);\ndrivers/scsi/sd_zbc.c-246-\t\tif (ret)\n--\ndrivers/scsi/sd_zbc.c-269-\t\t\tlba = start_lba + zone_length;\ndrivers/scsi/sd_zbc.c:270:\t\t\tif (sd_zbc_is_gap_zone(\u0026buf[offset])) {\ndrivers/scsi/sd_zbc.c-271-\t\t\t\tif (sdkp-\u003ezone_starting_lba_gran)\n--\ndrivers/scsi/sd_zbc.c-278-\ndrivers/scsi/sd_zbc.c:279:\t\t\tret = sd_zbc_parse_report(sdkp, buf + offset, zone_idx,\ndrivers/scsi/sd_zbc.c-280-\t\t\t\t\t\t args);\n--\ndrivers/scsi/sd_zbc.c-293-\ndrivers/scsi/sd_zbc.c:294:static blk_status_t sd_zbc_cmnd_checks(struct scsi_cmnd *cmd)\ndrivers/scsi/sd_zbc.c-295-{\n--\ndrivers/scsi/sd_zbc.c-306-\ndrivers/scsi/sd_zbc.c:307:\tif (sector \u0026 (sd_zbc_zone_sectors(sdkp) - 1))\ndrivers/scsi/sd_zbc.c-308-\t\t/* Unaligned request */\n--\ndrivers/scsi/sd_zbc.c-314-/**\ndrivers/scsi/sd_zbc.c:315: * sd_zbc_setup_zone_mgmt_cmnd - Prepare a zone ZBC_OUT command. The operations\ndrivers/scsi/sd_zbc.c-316- *\t\t\tcan be RESET WRITE POINTER, OPEN, CLOSE or FINISH.\n--\ndrivers/scsi/sd_zbc.c-323- */\ndrivers/scsi/sd_zbc.c:324:blk_status_t sd_zbc_setup_zone_mgmt_cmnd(struct scsi_cmnd *cmd,\ndrivers/scsi/sd_zbc.c-325-\t\t\t\t\t unsigned char op, bool all)\n--\ndrivers/scsi/sd_zbc.c-332-\ndrivers/scsi/sd_zbc.c:333:\tret = sd_zbc_cmnd_checks(cmd);\ndrivers/scsi/sd_zbc.c-334-\tif (ret != BLK_STS_OK)\n--\ndrivers/scsi/sd_zbc.c-354-/**\ndrivers/scsi/sd_zbc.c:355: * sd_zbc_complete - ZBC command post processing.\ndrivers/scsi/sd_zbc.c-356- * @cmd: Completed command\n--\ndrivers/scsi/sd_zbc.c-362- */\ndrivers/scsi/sd_zbc.c:363:unsigned int sd_zbc_complete(struct scsi_cmnd *cmd, unsigned int good_bytes,\ndrivers/scsi/sd_zbc.c-364-\t\t struct scsi_sense_hdr *sshdr)\n--\ndrivers/scsi/sd_zbc.c-384-/**\ndrivers/scsi/sd_zbc.c:385: * sd_zbc_check_zoned_characteristics - Check zoned block device characteristics\ndrivers/scsi/sd_zbc.c-386- * @sdkp: Target disk\n--\ndrivers/scsi/sd_zbc.c-390- */\ndrivers/scsi/sd_zbc.c:391:static int sd_zbc_check_zoned_characteristics(struct scsi_disk *sdkp,\ndrivers/scsi/sd_zbc.c-392-\t\t\t\t\t unsigned char *buf)\n--\ndrivers/scsi/sd_zbc.c-455-/**\ndrivers/scsi/sd_zbc.c:456: * sd_zbc_check_capacity - Check the device capacity\ndrivers/scsi/sd_zbc.c-457- * @sdkp: Target disk\n--\ndrivers/scsi/sd_zbc.c-466- */\ndrivers/scsi/sd_zbc.c:467:static int sd_zbc_check_capacity(struct scsi_disk *sdkp, unsigned char *buf,\ndrivers/scsi/sd_zbc.c-468-\t\t\t\t u32 *zblocks)\n--\ndrivers/scsi/sd_zbc.c-475-\t/* Do a report zone to get max_lba and the size of the first zone */\n\n"
} |
| 17/2 | 2026/10/05 10:29 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 44840 output: 333 thoughts: 1270 Thoughts: **Zoned Block Device Storage Element Feature Analysis** Okay, let's break this down. First, I see that enabling `CONFIG_BLK_DEV_ZONED` brings in `sd_zbc.o` (assuming `CONFIG_BLK_DEV_SD` is enabled), and `CONFIG_BLK_DEV_ZONED_LOOP` compiles in `drivers/block/zloop.o`. So, the critical configs are `BLK_DEV_ZONED` and `BLK_DEV_ZONED_LOOP` – no need to explicitly include `BLK_DEV_SD`, though it’s harmless. Now, the important part: selecting the `FocusSymbols`. We need to pinpoint the *specific* feature logic. I'm *not* interested in generic, widely-called functions. I'm focusing on the added or modified code that *directly* implements this zoned storage element functionality or provides the user-level entrypoints. So, here’s what I've identified: From `block/blk-zoned.c`: * `bdev_zone_is_offline` * `disk_wait_for_se_mgmt_completion` * `bdev_report_storage_elements` * `blkdev_get_nr_storage_elements_ioctl` (though this one feels redundant, the IOCTL family is important) * `blkdev_report_storage_elements_ioctl` * `bdev_remove_storage_element` * `blkdev_remove_storage_element_ioctl` * `bdev_restore_storage_elements` * `blkdev_restore_storage_elements_ioctl` * `blkdev_zone_storage_elements_ioctl` From `drivers/block/zloop.c`: * `zloop_zone_healthy` * `zloop_set_zone_cond` * `zloop_do_reset_zone` * `zloop_reset_zone` * `zloop_report_elements` * `zloop_degrade_element` * `zloop_remove_element_work` * `zloop_remove_element` * `zloop_restore_elements_work` * `zloop_restore_elements` * `zloop_create_storage_elements` * `zloop_ctl_degrade_element` From `drivers/scsi/sd_zbc.c`: * `sd_zbc_report_storage_elements` * `sd_zbc_remove_storage_element` * `sd_zbc_restore_storage_elements` I've made sure to cover both drivers (zloop and sd\_zbc) and the core block layer. This is a very targeted set, each symbol relates directly to storage element management! The ioctls themselves are of particular interest. Now, let's confirm the list against exported symbols or call points: * `blkdev_zone_storage_elements_ioctl` (called from `blkdev_common_ioctl`) * `bdev_remove_storage_element` * `bdev_restore_storage_elements` * `bdev_report_storage_elements` * `bdev_zone_is_offline` * `disk_wait_for_se_mgmt_completion` * `zloop_report_elements` * `zloop_remove_element` * `zloop_restore_elements` * `zloop_degrade_element` * `zloop_ctl_degrade_element` * `zloop_create_storage_elements` * `sd_zbc_report_storage_elements` * `sd_zbc_remove_storage_element` * `sd_zbc_restore_storage_elements` This is good. All clear! Now, let's assemble the `set-results` structure. **Configs:** * `BLK_DEV_ZONED` * `BLK_DEV_ZONED_LOOP` **FocusSymbols:** * `blkdev_zone_storage_elements_ioctl` * `bdev_report_storage_elements` * `bdev_remove_storage_element` * `bdev_restore_storage_elements` * `bdev_zone_is_offline` * `disk_wait_for_se_mgmt_completion` |
| 18/2 | 2026/10/05 10:30 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"BLK_DEV_ZONED",
"BLK_DEV_ZONED_LOOP"
],
"FocusSymbols": [
"blkdev_zone_storage_elements_ioctl",
"bdev_report_storage_elements",
"bdev_remove_storage_element",
"bdev_restore_storage_elements",
"bdev_zone_is_offline",
"disk_wait_for_se_mgmt_completion",
"zloop_report_elements",
"zloop_remove_element",
"zloop_restore_elements",
"zloop_degrade_element",
"zloop_ctl_degrade_element",
"sd_zbc_report_storage_elements",
"sd_zbc_remove_storage_element",
"sd_zbc_restore_storage_elements"
],
"Reasoning": "The patch adds support for storage element emulation and management (depopulation, restoration, and reporting) for zoned block devices. It introduces new user-facing ioctls (BLKGETNRSTORELEMS, BLKREPORTSTORELEMS, BLKREMOVESTORELEM, BLKRESTORESTORELEMS), new control operations on /dev/zloop-control, core block layer offline zone checks, asynchronous delayed work, and driver logic in zloop and SCSI ZBC. These changes are reachable from userspace and warrant fuzzing for concurrency issues, memory handling bugs, and state machine invariants.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"BLK_DEV_ZONED",
"BLK_DEV_ZONED_LOOP"
],
"FocusSymbols": [
"blkdev_zone_storage_elements_ioctl",
"bdev_report_storage_elements",
"bdev_remove_storage_element",
"bdev_restore_storage_elements",
"bdev_zone_is_offline",
"disk_wait_for_se_mgmt_completion",
"zloop_report_elements",
"zloop_remove_element",
"zloop_restore_elements",
"zloop_degrade_element",
"zloop_ctl_degrade_element",
"sd_zbc_report_storage_elements",
"sd_zbc_remove_storage_element",
"sd_zbc_restore_storage_elements"
],
"Reasoning": "The patch adds support for storage element emulation and management (depopulation, restoration, and reporting) for zoned block devices. It introduces new user-facing ioctls (BLKGETNRSTORELEMS, BLKREPORTSTORELEMS, BLKREMOVESTORELEM, BLKRESTORESTORELEMS), new control operations on /dev/zloop-control, core block layer offline zone checks, asynchronous delayed work, and driver logic in zloop and SCSI ZBC. These changes are reachable from userspace and warrant fuzzing for concurrency issues, memory handling bugs, and state machine invariants.",
"WorthFuzzing": true
} |
| 19/1 | 2026/10/05 10:30 | action | If |
3mArgs:{
"WorthFuzzing": true
}Results: null |
| 20/2 | 2026/10/05 10:30 | agent | kmsan-evaluator |
3mModel:core Args: null Results: {
"KMSANReasoning": "The patch series introduces storage element management ioctls (BLKGETNRSTORELEMS, BLKREPORTSTORELEMS, BLKREMOVESTORELEM, BLKRESTORESTORELEMS) for zoned block devices, along with support in zloop and sd_zbc.\n\nAnalysis of memory safety risks:\n1. Kernel data sent to userspace:\n - In blkdev_get_nr_storage_elements_ioctl(), nr_elements is an unsigned int initialized to 0 and written via put_user().\n - In blkdev_report_storage_elements_ioctl(), the 'rep' header struct is initialized via copy_from_user() before being updated and copied back to userspace via copy_to_user().\n - The 'elements' array is allocated with kzalloc_objs(struct blk_storage_element, nr_elements), ensuring all allocated elements and fields are zero-initialized.\n - 'struct blk_storage_element' is 24 bytes long and naturally packed without any padding holes (u32 id, u32 paired_id, u64 nr_zones, u8 type, u8 status, u8 restore_allowed, u8 reserved[5]).\n2. KASAN vs KMSAN applicability:\n - A potential heap buffer overread exists in blkdev_report_storage_elements_ioctl(): if the driver's report_elements callback sets *nr_elements to the total number of elements on the device (which may exceed rep.nr_elements passed by the user and used for kzalloc_objs), copy_to_user() will read past the end of the allocated slab object. This is a slab-out-of-bounds access, which is explicitly detected by KASAN.\n - Similarly, in sd_zbc_report_storage_elements(), if the SCSI device reports a large nr_descs, reading past the 4096-byte kzalloc'd buffer is an out-of-bounds read caught by KASAN.\n - All buffers (in zloop, sd_zbc, and blk-zoned) are allocated with kzalloc/kzalloc_objs or explicitly memset/initialized before use. There are no uninitialized variables or struct padding copied to userspace or used in conditional branching.\n\nBecause all memory safety risks are out-of-bounds accesses covered by KASAN and there is no uninitialized memory usage, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 6033a37c315506cd3e921d4f74ddc01ec80d3808
Author: syz-cluster <triage@syzkaller.com>
Date: Mon Oct 5 10:28:25 2026 +0000
syz-cluster: applied patch under review
diff --git a/Documentation/admin-guide/blockdev/zoned_loop.rst b/Documentation/admin-guide/blockdev/zoned_loop.rst
index 64277494fb36a..ec39f141af8d6 100644
--- a/Documentation/admin-guide/blockdev/zoned_loop.rst
+++ b/Documentation/admin-guide/blockdev/zoned_loop.rst
@@ -61,7 +61,7 @@ The options available for the add command can be listed by reading the
/dev/zloop-control device::
$ cat /dev/zloop-control
- add id=%d,capacity_mb=%u,zone_size_mb=%u,zone_capacity_mb=%u,conv_zones=%u,max_open_zones=%u,base_dir=%s,nr_queues=%u,queue_depth=%u,buffered_io,zone_append=%u,ordered_zone_append,discard_write_cache
+ add id=%d,capacity_mb=%u,zone_size_mb=%u,zone_capacity_mb=%u,conv_zones=%u,max_open_zones=%u,base_dir=%s,nr_queues=%u,queue_depth=%u,buffered_io,zone_append=%u,ordered_zone_append,discard_write_cache,stor_elements=%u
remove id=%d
In more details, the options that can be used with the "add" command are as
@@ -113,6 +113,12 @@ discard_write_cache Discard all data that was not explicitly persisted using a
each zone file to the size recorded during the last flush
operation. This simulates power fail events where
uncommitted data is lost.
+stor_elements Control storage element emulation. The default value is 0,
+ indicating no emulation. A value of 1 indicates that all
+ access storage elements (equivalent to read+write head of
+ a disk) are emulated. A value of 2 enables fractional
+ access storage element (equivalent to pairs of read and
+ write heads of a disk) emulation .
=================== =========================================================
3) Deleting a Zoned Device
diff --git a/block/blk-core.c b/block/blk-core.c
index 13dc70e8f55d9..f098a31d19aa4 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -866,6 +866,11 @@ void submit_bio_noacct(struct bio *bio)
switch (bio_op(bio)) {
case REQ_OP_READ:
+ if (bdev_is_zoned(bdev) &&
+ bdev_zone_is_offline(bdev, bio->bi_iter.bi_sector)) {
+ bio_set_flag(bio, BIO_QUIET);
+ goto end_io;
+ }
break;
case REQ_OP_WRITE:
if (bio->bi_opf & REQ_ATOMIC) {
diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 19268afb8752e..62b9cf21e9adf 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -18,6 +18,8 @@
#include <linux/mempool.h>
#include <linux/kthread.h>
#include <linux/freezer.h>
+#include <linux/delay.h>
+#include <linux/uaccess.h>
#include <trace/events/block.h>
@@ -308,6 +310,24 @@ bool bdev_zone_is_seq(struct block_device *bdev, sector_t sector)
}
EXPORT_SYMBOL_GPL(bdev_zone_is_seq);
+/**
+ * bdev_zone_is_offline - check if a sector belongs to an offline zone
+ * @bdev: block device to check
+ * @sector: sector number
+ *
+ * Check if @sector on @bdev is contained in an offline zone.
+ */
+bool bdev_zone_is_offline(struct block_device *bdev, sector_t sector)
+{
+ enum blk_zone_cond cond;
+
+ if (!bdev_is_zoned(bdev))
+ return false;
+
+ cond = disk_zone_get_cond(bdev->bd_disk, sector);
+ return cond == BLK_ZONE_COND_OFFLINE;
+}
+
/**
* bdev_zone_mgmt_allowed - check if management operations are allowed on a zone
* @bdev: block device to check
@@ -2700,5 +2720,283 @@ int queue_zone_wplugs_show(void *data, struct seq_file *m)
return 0;
}
-
#endif
+
+static void disk_wait_for_se_mgmt_completion(struct gendisk *disk)
+{
+ struct blk_storage_element *elements, *e;
+ unsigned int i, nr_se, nr_elements = 0;
+ int ret;
+
+ ret = (disk->fops->se_ops->report_elements)(disk, &nr_elements, NULL);
+ if (ret) {
+ pr_err("Failed to get number of storage elements\n");
+ return;
+ }
+
+ elements = kzalloc_objs(struct blk_storage_element, nr_elements);
+ if (!elements)
+ return;
+
+ while (1) {
+ /*
+ * Check if we have storage elements being removed or restored.
+ */
+ nr_se = nr_elements;
+ ret = (disk->fops->se_ops->report_elements)(disk,
+ &nr_elements, elements);
+ if (ret) {
+ pr_err("Failed to get storage elements\n");
+ break;
+ }
+
+ e = elements;
+ for (i = 0; i < nr_se; i++, e++) {
+ if (e->status == BLK_SE_STS_REMOVE_IN_PROGRESS ||
+ e->status == BLK_SE_STS_RESTORE_IN_PROGRESS)
+ break;
+ }
+ if (i >= nr_se)
+ break;
+
+ /* Not done yet: wait and retry. */
+ msleep(500);
+ }
+
+ kfree(elements);
+}
+
+/**
+ * bdev_report_storage_elements - report the storage elements of a block device
+ *
+ * Fill at most @nr_elements storage element descriptors in the array @elements.
+ * The number of storage elements filled in the array is returned using
+ * @nr_elements. If @elements is NULL, only @nr_elements is returned.
+ *
+ * Returns 0 on success and a negative error code on failure.
+ */
+int bdev_report_storage_elements(struct block_device *bdev,
+ unsigned int *nr_elements,
+ struct blk_storage_element *elements)
+{
+ struct gendisk *disk = bdev->bd_disk;
+
+ if (!bdev_is_zoned(bdev) || !disk->fops->se_ops)
+ return -EOPNOTSUPP;
+
+ if (!nr_elements)
+ return -EINVAL;
+
+ if (*nr_elements && !elements)
+ return -EINVAL;
+
+ return (disk->fops->se_ops->report_elements)(disk, nr_elements,
+ elements);
+}
+EXPORT_SYMBOL_GPL(bdev_report_storage_elements);
+
+static int blkdev_get_nr_storage_elements_ioctl(struct block_device *bdev,
+ void __user *argp)
+{
+ unsigned int nr_elements = 0;
+ int ret;
+
+ ret = bdev_report_storage_elements(bdev, &nr_elements, NULL);
+ if (ret)
+ return ret;
+
+ if (put_user(nr_elements, (unsigned int __user *)argp))
+ return -EFAULT;
+
+ return 0;
+}
+
+static int blkdev_report_storage_elements_ioctl(struct block_device *bdev,
+ void __user *argp)
+{
+ struct blk_storage_elements_report rep;
+ struct blk_storage_element *elements;
+ unsigned int nr_elements;
+ unsigned long retc;
+ int ret;
+
+ if (!argp)
+ return -EINVAL;
+
+ if (copy_from_user(&rep, argp,
+ sizeof(struct blk_storage_elements_report)))
+ return -EFAULT;
+
+ if (!rep.nr_elements)
+ return -EINVAL;
+
+ nr_elements = rep.nr_elements;
+ elements = kzalloc_objs(struct blk_storage_element, nr_elements);
+ if (!elements)
+ return -ENOMEM;
+
+ ret = bdev_report_storage_elements(bdev, &nr_elements, elements);
+ if (ret)
+ goto free_elements;
+
+ retc = copy_to_user(argp + sizeof(struct blk_storage_elements_report),
+ elements,
+ sizeof(struct blk_storage_element) * nr_elements);
+ if (retc) {
+ ret = -EFAULT;
+ goto free_elements;
+ }
+
+ rep.nr_elements = nr_elements;
+ retc = copy_to_user(argp, &rep,
+ sizeof(struct blk_storage_elements_report));
+ if (retc)
+ ret = -EFAULT;
+
+free_elements:
+ kfree(elements);
+ return ret;
+}
+
+/**
+ * bdev_remove_storage_element - Remove (depopulate) a storage element of a
+ * block device
+ *
+ * Remove (depopulate) the storage element identified by @element_id from the
+ * block device @bdev.
+ *
+ * Returns 0 on success and a negative error code on failure.
+ */
+int bdev_remove_storage_element(struct block_device *bdev,
+ unsigned int element_id)
+{
+ struct gendisk *disk = bdev->bd_disk;
+ unsigned int memflags;
+ int ret;
+
+ if (!bdev_is_zoned(bdev) || !disk->fops->se_ops)
+ return -EOPNOTSUPP;
+
+ /* Zero is not a valid storage element ID. */
+ if (!element_id)
+ return -EINVAL;
+
+ /*
+ * Freeze and unfreeze the queue to flush any outstanding command.
+ * The caller is responsible for not queuing up more I/Os by higher
+ * level means.
+ */
+ memflags = blk_mq_freeze_queue(disk->queue);
+ blk_mq_unfreeze_queue(disk->queue, memflags);
+
+ /*
+ * Flush the volatile write cache if there is any. Note that this may
+ * lead to errors if degraded storage elements are used. So ignore
+ * errors here.
+ */
+ blkdev_issue_flush(disk->part0);
+
+ /* Invalidate all cached data. */
+ invalidate_inode_pages2_range(bdev->bd_mapping, 0,
+ get_capacity(disk) << SECTOR_SHIFT);
+
+ ret = (disk->fops->se_ops->remove_element)(disk, element_id);
+ if (ret)
+ return ret;
+
+ /* Revalidate the device zones once the opration completes. */
+ disk_wait_for_se_mgmt_completion(disk);
+
+ return blk_revalidate_disk_zones(disk);
+}
+EXPORT_SYMBOL_GPL(bdev_remove_storage_element);
+
+static int blkdev_remove_storage_element_ioctl(struct block_device *bdev,
+ blk_mode_t mode, void __user *argp)
+{
+ unsigned int element_id;
+
+ if (!(mode & BLK_OPEN_WRITE))
+ return -EBADF;
+ if (bdev_read_only(bdev))
+ return -EPERM;
+
+ if (get_user(element_id, (unsigned int __user *)argp))
+ return -EFAULT;
+
+ return bdev_remove_storage_element(bdev, element_id);
+}
+
+/**
+ * bdev_restore_storage_elements - Restore all depopulated storage elements of a
+ * block device
+ *
+ * Restore all storage elements of @bdev that have been depopulated. Not all
+ * elements may be restored by this operation.
+ *
+ * Returns 0 on success and a negative error code on failure.
+ */
+int bdev_restore_storage_elements(struct block_device *bdev)
+{
+ struct gendisk *disk = bdev->bd_disk;
+ unsigned int memflags;
+ int ret;
+
+ if (!bdev_is_zoned(bdev) || !disk->fops->se_ops)
+ return -EOPNOTSUPP;
+
+ /*
+ * Freeze and unfreeze the queue to flush any outstanding commands.
+ * The caller is responsible for not queuing up more I/O by higher
+ * level means.
+ */
+ memflags = blk_mq_freeze_queue(disk->queue);
+ blk_mq_unfreeze_queue(disk->queue, memflags);
+
+ /* Invalidate all cached data. */
+ invalidate_inode_pages2_range(bdev->bd_mapping, 0,
+ get_capacity(disk) << SECTOR_SHIFT);
+
+ ret = (disk->fops->se_ops->restore_elements)(disk);
+ if (ret)
+ return ret;
+
+ disk_wait_for_se_mgmt_completion(disk);
+
+ return blk_revalidate_disk_zones(disk);
+}
+EXPORT_SYMBOL_GPL(bdev_restore_storage_elements);
+
+static int blkdev_restore_storage_elements_ioctl(struct block_device *bdev,
+ blk_mode_t mode)
+{
+ if (!(mode & BLK_OPEN_WRITE))
+ return -EBADF;
+ if (bdev_read_only(bdev))
+ return -EPERM;
+
+ return bdev_restore_storage_elements(bdev);
+}
+
+int blkdev_zone_storage_elements_ioctl(struct block_device *bdev,
+ blk_mode_t mode, unsigned int cmd,
+ void __user *argp)
+{
+ if (!bdev_is_zoned(bdev) || !bdev->bd_disk->fops->se_ops)
+ return -ENOTTY;
+
+ switch (cmd) {
+ case BLKGETNRSTORELEMS:
+ return blkdev_get_nr_storage_elements_ioctl(bdev, argp);
+ case BLKREPORTSTORELEMS:
+ return blkdev_report_storage_elements_ioctl(bdev, argp);
+ case BLKREMOVESTORELEM:
+ return blkdev_remove_storage_element_ioctl(bdev, mode, argp);
+ case BLKRESTORESTORELEMS:
+ return blkdev_restore_storage_elements_ioctl(bdev, mode);
+ default:
+ break;
+ }
+
+ return -ENOTTY;
+}
diff --git a/block/blk.h b/block/blk.h
index 2cc03aa54c532..274afb46a809a 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -578,6 +578,10 @@ int blkdev_report_zones_ioctl(struct block_device *bdev, unsigned int cmd,
int blkdev_zone_mgmt_ioctl(struct block_device *bdev, blk_mode_t mode,
unsigned int cmd, unsigned long arg);
bool bdev_zone_mgmt_allowed(struct block_device *bdev, sector_t sector);
+bool bdev_zone_is_offline(struct block_device *bdev, sector_t sector);
+int blkdev_zone_storage_elements_ioctl(struct block_device *bdev,
+ blk_mode_t mode, unsigned int cmd,
+ void __user *argp);
#else /* CONFIG_BLK_DEV_ZONED */
static inline void disk_init_zone_resources(struct gendisk *disk)
{
@@ -625,6 +629,17 @@ static inline bool bdev_zone_mgmt_allowed(struct block_device *bdev,
{
return false;
}
+static inline bool bdev_zone_is_offline(struct block_device *bdev,
+ sector_t sector)
+{
+ return false;
+}
+static inline int blkdev_zone_storage_elements_ioctl(struct block_device *bdev,
+ blk_mode_t mode, unsigned int cmd,
+ void __user *argp)
+{
+ return -ENOTTY;
+}
#endif /* CONFIG_BLK_DEV_ZONED */
struct block_device *bdev_alloc(struct gendisk *disk, u8 partno);
diff --git a/block/ioctl.c b/block/ioctl.c
index 64b4e6c0f6965..ccf806c2e37d1 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -679,6 +679,11 @@ static int blkdev_common_ioctl(struct block_device *bdev, blk_mode_t mode,
return put_uint(argp, bdev_zone_sectors(bdev));
case BLKGETNRZONES:
return put_uint(argp, bdev_nr_zones(bdev));
+ case BLKGETNRSTORELEMS:
+ case BLKREPORTSTORELEMS:
+ case BLKREMOVESTORELEM:
+ case BLKRESTORESTORELEMS:
+ return blkdev_zone_storage_elements_ioctl(bdev, mode, cmd, argp);
case BLKROGET:
return put_int(argp, bdev_read_only(bdev) != 0);
case BLKSSZGET: /* get block device logical block size */
diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
index f0ca221524db6..1d51060b832bc 100644
--- a/drivers/block/zloop.c
+++ b/drivers/block/zloop.c
@@ -37,6 +37,8 @@ enum {
ZLOOP_OPT_ORDERED_ZONE_APPEND = (1 << 10),
ZLOOP_OPT_DISCARD_WRITE_CACHE = (1 << 11),
ZLOOP_OPT_MAX_OPEN_ZONES = (1 << 12),
+ ZLOOP_OPT_STOR_ELEMENTS = (1 << 13),
+ ZLOOP_OPT_ELEMENT_ID = (1 << 14),
};
static const match_table_t zloop_opt_tokens = {
@@ -51,11 +53,23 @@ static const match_table_t zloop_opt_tokens = {
{ ZLOOP_OPT_BUFFERED_IO, "buffered_io" },
{ ZLOOP_OPT_ZONE_APPEND, "zone_append=%u" },
{ ZLOOP_OPT_ORDERED_ZONE_APPEND, "ordered_zone_append" },
- { ZLOOP_OPT_DISCARD_WRITE_CACHE, "discard_write_cache" },
+ { ZLOOP_OPT_DISCARD_WRITE_CACHE, "discard_write_cache" },
{ ZLOOP_OPT_MAX_OPEN_ZONES, "max_open_zones=%u" },
+ { ZLOOP_OPT_STOR_ELEMENTS, "stor_elements=%u" },
+ { ZLOOP_OPT_ELEMENT_ID, "element_id=%u" },
{ ZLOOP_OPT_ERR, NULL }
};
+/* Storage elements emulation types. */
+enum zloop_stor_elements {
+ /* No emulation. */
+ ZLOOP_STOR_ELEMENTS_NONE,
+ /* Emulate read+write storage elements. */
+ ZLOOP_STOR_ELEMENTS_RDWR,
+ /* Emulate pairs of associated read and write storage elements. */
+ ZLOOP_STOR_ELEMENTS_PAIRS,
+};
+
/* Default values for the "add" operation. */
#define ZLOOP_DEF_ID -1
#define ZLOOP_DEF_ZONE_SIZE ((256ULL * SZ_1M) >> SECTOR_SHIFT)
@@ -68,6 +82,8 @@ static const match_table_t zloop_opt_tokens = {
#define ZLOOP_DEF_BUFFERED_IO false
#define ZLOOP_DEF_ZONE_APPEND true
#define ZLOOP_DEF_ORDERED_ZONE_APPEND false
+#define ZLOOP_DEF_STOR_ELEMENTS ZLOOP_STOR_ELEMENTS_NONE
+#define ZLOOP_DEF_ELEMENT_ID 0
/* Arbitrary limit on the zone size (16GB). */
#define ZLOOP_MAX_ZONE_SIZE_MB 16384
@@ -87,6 +103,8 @@ struct zloop_options {
bool zone_append;
bool ordered_zone_append;
bool discard_write_cache;
+ enum zloop_stor_elements stor_elements;
+ unsigned int element_id;
};
/*
@@ -117,6 +135,8 @@ struct zloop_zone {
enum blk_zone_cond cond;
sector_t start;
sector_t wp;
+ unsigned int wr_se_id;
+ unsigned int rd_se_id;
gfp_t old_gfp_mask;
};
@@ -133,6 +153,7 @@ struct zloop_device {
bool zone_append;
bool ordered_zone_append;
bool discard_write_cache;
+ enum zloop_stor_elements stor_elements;
const char *base_dir;
struct file *data_dir;
@@ -150,6 +171,17 @@ struct zloop_device {
struct list_head open_zones_lru_list;
unsigned int nr_open_zones;
+ /* For storage elements emulation. */
+ struct mutex stor_elements_lock;
+ unsigned int nr_elements;
+ unsigned int max_nr_removed_elements;
+ unsigned int nr_removed_elements;
+ struct delayed_work remove_element_work;
+ unsigned int remove_element_id;
+ struct delayed_work restore_elements_work;
+ bool restore_in_progress;
+ struct blk_storage_element *elements;
+
struct zloop_zone zones[] __counted_by(nr_zones);
};
@@ -173,6 +205,29 @@ static unsigned int rq_zone_no(struct request *rq)
return blk_rq_pos(rq) >> zlo->zone_shift;
}
+static bool zloop_zone_healthy(struct zloop_device *zlo,
+ struct zloop_zone *zone, bool write)
+{
+ struct blk_storage_element *se;
+
+ if (!zlo->nr_elements)
+ return true;
+
+ /* Check the zone condition first. */
+ if (zone->cond == BLK_ZONE_COND_OFFLINE)
+ return false;
+ if (zone->cond == BLK_ZONE_COND_READONLY && write)
+ return false;
+
+ /* Check the health state of the storage element serving the zone. */
+ if (write)
+ se = &zlo->elements[zone->wr_se_id - 1];
+ else
+ se = &zlo->elements[zone->rd_se_id - 1];
+
+ return se->status == BLK_SE_STS_DEGRADED;
+}
+
/*
* Open an already open zone. This is mostly a no-op, except for the imp open ->
* exp open condition change that may happen. We also move a zone at the tail of
@@ -289,22 +344,30 @@ static bool zloop_do_open_zone(struct zloop_device *zlo,
}
}
-static void zloop_mark_full(struct zloop_device *zlo, struct zloop_zone *zone)
+static void zloop_set_zone_cond(struct zloop_device *zlo,
+ struct zloop_zone *zone,
+ enum blk_zone_cond cond)
{
lockdep_assert_held(&zone->wp_lock);
zloop_lru_remove_open_zone(zlo, zone);
- zone->cond = BLK_ZONE_COND_FULL;
- zone->wp = ULLONG_MAX;
+ zone->cond = cond;
+ if (cond == BLK_ZONE_COND_EMPTY)
+ zone->wp = zone->start;
+ else
+ zone->wp = ULLONG_MAX;
}
-static void zloop_mark_empty(struct zloop_device *zlo, struct zloop_zone *zone)
+static inline void zloop_set_zone_full(struct zloop_device *zlo,
+ struct zloop_zone *zone)
{
- lockdep_assert_held(&zone->wp_lock);
+ zloop_set_zone_cond(zlo, zone, BLK_ZONE_COND_FULL);
+}
- zloop_lru_remove_open_zone(zlo, zone);
- zone->cond = BLK_ZONE_COND_EMPTY;
- zone->wp = zone->start;
+static inline void zloop_set_zone_empty(struct zloop_device *zlo,
+ struct zloop_zone *zone)
+{
+ zloop_set_zone_cond(zlo, zone, BLK_ZONE_COND_EMPTY);
}
static int zloop_update_seq_zone(struct zloop_device *zlo, unsigned int zone_no)
@@ -339,9 +402,9 @@ static int zloop_update_seq_zone(struct zloop_device *zlo, unsigned int zone_no)
spin_lock(&zone->wp_lock);
if (!file_sectors) {
- zloop_mark_empty(zlo, zone);
+ zloop_set_zone_empty(zlo, zone);
} else if (file_sectors == zlo->zone_capacity) {
- zloop_mark_full(zlo, zone);
+ zloop_set_zone_full(zlo, zone);
} else {
if (zone->cond != BLK_ZONE_COND_IMP_OPEN &&
zone->cond != BLK_ZONE_COND_EXP_OPEN)
@@ -363,6 +426,12 @@ static int zloop_open_zone(struct zloop_device *zlo, unsigned int zone_no)
mutex_lock(&zone->lock);
+ if (zone->cond == BLK_ZONE_COND_OFFLINE ||
+ zone->cond == BLK_ZONE_COND_READONLY) {
+ ret = -EIO;
+ goto unlock;
+ }
+
if (test_and_clear_bit(ZLOOP_ZONE_SEQ_ERROR, &zone->flags)) {
ret = zloop_update_seq_zone(zlo, zone_no);
if (ret)
@@ -388,6 +457,12 @@ static int zloop_close_zone(struct zloop_device *zlo, unsigned int zone_no)
mutex_lock(&zone->lock);
+ if (zone->cond == BLK_ZONE_COND_OFFLINE ||
+ zone->cond == BLK_ZONE_COND_READONLY) {
+ ret = -EIO;
+ goto unlock;
+ }
+
if (test_and_clear_bit(ZLOOP_ZONE_SEQ_ERROR, &zone->flags)) {
ret = zloop_update_seq_zone(zlo, zone_no);
if (ret)
@@ -420,7 +495,22 @@ static int zloop_close_zone(struct zloop_device *zlo, unsigned int zone_no)
return ret;
}
-static int zloop_reset_zone(struct zloop_device *zlo, unsigned int zone_no)
+static int zloop_do_reset_zone(struct zloop_device *zlo,
+ struct zloop_zone *zone)
+{
+ if (vfs_truncate(&zone->file->f_path, 0))
+ return -EIO;
+
+ spin_lock(&zone->wp_lock);
+ zloop_set_zone_empty(zlo, zone);
+ clear_bit(ZLOOP_ZONE_SEQ_ERROR, &zone->flags);
+ spin_unlock(&zone->wp_lock);
+
+ return 0;
+}
+
+static int zloop_reset_zone(struct zloop_device *zlo, unsigned int zone_no,
+ bool all_zones)
{
struct zloop_zone *zone = &zlo->zones[zone_no];
int ret = 0;
@@ -430,20 +520,20 @@ static int zloop_reset_zone(struct zloop_device *zlo, unsigned int zone_no)
mutex_lock(&zone->lock);
+ if (zone->cond == BLK_ZONE_COND_OFFLINE ||
+ zone->cond == BLK_ZONE_COND_READONLY) {
+ if (!all_zones)
+ ret = -EIO;
+ goto unlock;
+ }
+
if (!test_bit(ZLOOP_ZONE_SEQ_ERROR, &zone->flags) &&
zone->cond == BLK_ZONE_COND_EMPTY)
goto unlock;
- if (vfs_truncate(&zone->file->f_path, 0)) {
+ ret = zloop_do_reset_zone(zlo, zone);
+ if (ret)
set_bit(ZLOOP_ZONE_SEQ_ERROR, &zone->flags);
- ret = -EIO;
- goto unlock;
- }
-
- spin_lock(&zone->wp_lock);
- zloop_mark_empty(zlo, zone);
- clear_bit(ZLOOP_ZONE_SEQ_ERROR, &zone->flags);
- spin_unlock(&zone->wp_lock);
unlock:
mutex_unlock(&zone->lock);
@@ -457,7 +547,7 @@ static int zloop_reset_all_zones(struct zloop_device *zlo)
int ret;
for (i = zlo->nr_conv_zones; i < zlo->nr_zones; i++) {
- ret = zloop_reset_zone(zlo, i);
+ ret = zloop_reset_zone(zlo, i, true);
if (ret)
return ret;
}
@@ -475,6 +565,12 @@ static int zloop_finish_zone(struct zloop_device *zlo, unsigned int zone_no)
mutex_lock(&zone->lock);
+ if (zone->cond == BLK_ZONE_COND_OFFLINE ||
+ zone->cond == BLK_ZONE_COND_READONLY) {
+ ret = -EIO;
+ goto unlock;
+ }
+
if (!test_bit(ZLOOP_ZONE_SEQ_ERROR, &zone->flags) &&
zone->cond == BLK_ZONE_COND_FULL)
goto unlock;
@@ -487,7 +583,7 @@ static int zloop_finish_zone(struct zloop_device *zlo, unsigned int zone_no)
}
spin_lock(&zone->wp_lock);
- zloop_mark_full(zlo, zone);
+ zloop_set_zone_full(zlo, zone);
clear_bit(ZLOOP_ZONE_SEQ_ERROR, &zone->flags);
spin_unlock(&zone->wp_lock);
@@ -624,7 +720,7 @@ static int zloop_seq_write_prep(struct zloop_cmd *cmd)
if (!is_append || !zlo->ordered_zone_append) {
zone->wp += nr_sectors;
if (zone->wp == zone_end)
- zloop_mark_full(zlo, zone);
+ zloop_set_zone_full(zlo, zone);
}
out_unlock:
spin_unlock(&zone->wp_lock);
@@ -664,6 +760,9 @@ static void zloop_rw(struct zloop_cmd *cmd)
zone->start + zlo->zone_size))
goto out;
+ if (!zloop_zone_healthy(zlo, zone, is_write))
+ goto out;
+
if (test_and_clear_bit(ZLOOP_ZONE_SEQ_ERROR, &zone->flags)) {
mutex_lock(&zone->lock);
ret = zloop_update_seq_zone(zlo, zone_no);
@@ -766,7 +865,7 @@ static void zloop_handle_cmd(struct zloop_cmd *cmd)
cmd->ret = zloop_flush(zlo);
break;
case REQ_OP_ZONE_RESET:
- cmd->ret = zloop_reset_zone(zlo, rq_zone_no(rq));
+ cmd->ret = zloop_reset_zone(zlo, rq_zone_no(rq), false);
break;
case REQ_OP_ZONE_RESET_ALL:
cmd->ret = zloop_reset_all_zones(zlo);
@@ -877,7 +976,7 @@ static bool zloop_set_zone_append_sector(struct request *rq)
rq->__sector = zone->wp;
zone->wp += blk_rq_sectors(rq);
if (zone->wp >= zone_end)
- zloop_mark_full(zlo, zone);
+ zloop_set_zone_full(zlo, zone);
spin_unlock(&zone->wp_lock);
@@ -985,11 +1084,276 @@ static int zloop_report_zones(struct gendisk *disk, sector_t sector,
return nr_zones;
}
+static int zloop_report_elements(struct gendisk *disk,
+ unsigned int *nr_elements,
+ struct blk_storage_element *elements)
+{
+ struct zloop_device *zlo = disk->private_data;
+ unsigned int nr_report = *nr_elements;
+
+ if (zlo->stor_elements == ZLOOP_STOR_ELEMENTS_NONE)
+ return -EOPNOTSUPP;
+
+ mutex_lock(&zlo->stor_elements_lock);
+
+ *nr_elements = zlo->nr_elements;
+ if (elements) {
+ struct blk_storage_element *se = zlo->elements;
+ unsigned int i;
+
+ for (i = 0; i < min(nr_report, zlo->nr_elements); i++, se++) {
+ switch (se->status) {
+ case BLK_SE_STS_REMOVED:
+ case BLK_SE_STS_RESTORE_ERROR:
+ se->restore_allowed = 1;
+ break;
+ default:
+ se->restore_allowed = 0;
+ }
+ memcpy(&elements[i], se,
+ sizeof(struct blk_storage_element));
+ }
+ }
+
+ mutex_unlock(&zlo->stor_elements_lock);
+
+ return 0;
+}
+
+static int zloop_degrade_element(struct zloop_device *zlo,
+ unsigned int element_id)
+{
+ struct blk_storage_element *se;
+ int ret = 0;
+
+ if (zlo->stor_elements == ZLOOP_STOR_ELEMENTS_NONE)
+ return -EOPNOTSUPP;
+
+ if (!element_id || element_id > zlo->nr_elements)
+ return -EINVAL;
+
+ mutex_lock(&zlo->stor_elements_lock);
+
+ se = &zlo->elements[element_id - 1];
+ if (se->status == BLK_SE_STS_OK)
+ se->status = BLK_SE_STS_DEGRADED;
+ else
+ ret = -EINVAL;
+
+ mutex_unlock(&zlo->stor_elements_lock);
+
+ return ret;
+}
+
+static void zloop_remove_element_work(struct work_struct *work)
+{
+ struct zloop_device *zlo = container_of(work, struct zloop_device,
+ remove_element_work.work);
+ struct blk_storage_element *se, *paired_se = NULL;
+ enum blk_zone_cond cond;
+ struct zloop_zone *zone;
+ unsigned int i;
+
+ mutex_lock(&zlo->stor_elements_lock);
+
+ /*
+ * If the element to remove is a read element, zones must go offline and
+ * the associated write element is also removed.
+ */
+ se = &zlo->elements[zlo->remove_element_id - 1];
+ switch (se->type) {
+ case BLK_SE_TYPE_RDWR:
+ cond = BLK_ZONE_COND_OFFLINE;
+ break;
+ case BLK_SE_TYPE_READ:
+ cond = BLK_ZONE_COND_OFFLINE;
+ paired_se = &zlo->elements[se->paired_id - 1];
+ break;
+ case BLK_SE_TYPE_WRITE:
+ cond = BLK_ZONE_COND_READONLY;
+ break;
+ default:
+ WARN_ON_ONCE(1);
+ }
+
+ /*
+ * Change the condition of the zones owned by the (pair of) elements
+ * being removed and mark the elements removed.
+ */
+ for (i = 0, zone = zlo->zones; i < zlo->nr_zones; i++, zone++) {
+ if (zone->wr_se_id != se->id && zone->rd_se_id != se->id)
+ continue;
+ mutex_lock(&zone->lock);
+ spin_lock(&zone->wp_lock);
+ zloop_set_zone_cond(zlo, zone, cond);
+ spin_unlock(&zone->wp_lock);
+ mutex_unlock(&zone->lock);
+ }
+
+ se->status = BLK_SE_STS_REMOVED;
+
+ zlo->nr_removed_elements++;
+ if (paired_se) {
+ paired_se->status = BLK_SE_STS_REMOVED;
+ zlo->nr_removed_elements++;
+ }
+
+ zlo->remove_element_id = 0;
+
+ mutex_unlock(&zlo->stor_elements_lock);
+}
+
+static int zloop_remove_element(struct gendisk *disk, unsigned int element_id)
+{
+ struct zloop_device *zlo = disk->private_data;
+ struct blk_storage_element *se, *paired_se = NULL;
+ unsigned int nr_remove = 1;
+ int ret = 0;
+
+ if (zlo->stor_elements == ZLOOP_STOR_ELEMENTS_NONE)
+ return -EOPNOTSUPP;
+
+ if (element_id > zlo->nr_elements)
+ return -EINVAL;
+
+ mutex_lock(&zlo->stor_elements_lock);
+
+ if (zlo->remove_element_id || zlo->restore_in_progress) {
+ ret = -EBUSY;
+ goto unlock;
+ }
+
+ /*
+ * Get the element to remove. If it is already removed, we have nothing
+ * to do.
+ */
+ se = &zlo->elements[element_id - 1];
+ if (se->status == BLK_SE_STS_REMOVED)
+ goto unlock;
+
+ /*
+ * If the element to remove is a read element, the associated write
+ * element must also be removed.
+ */
+ if (se->type == BLK_SE_TYPE_READ) {
+ paired_se = &zlo->elements[se->paired_id - 1];
+ nr_remove = 2;
+ }
+
+ if (zlo->nr_removed_elements + nr_remove >
+ zlo->max_nr_removed_elements) {
+ ret = -EBUSY;
+ goto unlock;
+ }
+
+ /*
+ * Schedule the element removal with a delay, to emulate the (generally
+ * short) time it takes for a real device to depopulate a head and
+ * modify the zones.
+ */
+ zlo->remove_element_id = element_id;
+ se->status = BLK_SE_STS_REMOVE_IN_PROGRESS;
+ if (paired_se)
+ paired_se->status = BLK_SE_STS_REMOVE_IN_PROGRESS;
+
+ schedule_delayed_work(&zlo->remove_element_work,
+ msecs_to_jiffies(2000));
+
+unlock:
+ mutex_unlock(&zlo->stor_elements_lock);
+
+ return ret;
+}
+
+static void zloop_restore_elements_work(struct work_struct *work)
+{
+ struct zloop_device *zlo = container_of(work, struct zloop_device,
+ restore_elements_work.work);
+ struct zloop_zone *zone = zlo->zones;
+ struct blk_storage_element *se;
+ unsigned int i;
+ int ret = 0;
+
+ mutex_lock(&zlo->stor_elements_lock);
+
+ /* Reset all zones. */
+ for (i = 0; i < zlo->nr_zones && ret == 0; i++, zone++) {
+ mutex_lock(&zone->lock);
+ if (test_bit(ZLOOP_ZONE_CONV, &zone->flags)) {
+ spin_lock(&zone->wp_lock);
+ zloop_set_zone_cond(zlo, zone, BLK_ZONE_COND_NOT_WP);
+ spin_unlock(&zone->wp_lock);
+ } else {
+ ret = zloop_do_reset_zone(zlo, zone);
+ }
+ mutex_unlock(&zone->lock);
+ }
+
+ /* Restore all removed elements. */
+ for (i = 0, se = zlo->elements; i < zlo->nr_elements; i++, se++) {
+ if (se->status != BLK_SE_STS_RESTORE_IN_PROGRESS)
+ continue;
+ if (!ret)
+ se->status = BLK_SE_STS_OK;
+ else
+ se->status = BLK_SE_STS_RESTORE_ERROR;
+ }
+
+ zlo->nr_removed_elements = 0;
+ zlo->restore_in_progress = false;
+
+ mutex_unlock(&zlo->stor_elements_lock);
+}
+
+static int zloop_restore_elements(struct gendisk *disk)
+{
+ struct zloop_device *zlo = disk->private_data;
+ struct blk_storage_element *se;
+ unsigned int i;
+ int ret = 0;
+
+ if (zlo->stor_elements == ZLOOP_STOR_ELEMENTS_NONE)
+ return -EOPNOTSUPP;
+
+ mutex_lock(&zlo->stor_elements_lock);
+
+ if (zlo->remove_element_id || zlo->restore_in_progress) {
+ ret = -EBUSY;
+ goto unlock;
+ }
+
+ /* If we have no removed elements, we have nothing to do. */
+ if (!zlo->nr_removed_elements)
+ goto unlock;
+
+ /*
+ * Schedule the elements restoration with a delay, to emulate the time
+ * it takes for a real device to restore all removed heads and reset
+ * all zones.
+ */
+ zlo->restore_in_progress = true;
+ for (i = 0, se = zlo->elements; i < zlo->nr_elements; i++, se++) {
+ if (se->status == BLK_SE_STS_REMOVED)
+ se->status = BLK_SE_STS_RESTORE_IN_PROGRESS;
+ }
+
+ schedule_delayed_work(&zlo->restore_elements_work,
+ msecs_to_jiffies(5000));
+
+unlock:
+ mutex_unlock(&zlo->stor_elements_lock);
+
+ return ret;
+}
+
static void zloop_free_disk(struct gendisk *disk)
{
struct zloop_device *zlo = disk->private_data;
unsigned int i;
+ cancel_delayed_work_sync(&zlo->remove_element_work);
+ cancel_delayed_work_sync(&zlo->restore_elements_work);
+
blk_mq_free_tag_set(&zlo->tag_set);
for (i = 0; i < zlo->nr_zones; i++) {
@@ -1002,15 +1366,24 @@ static void zloop_free_disk(struct gendisk *disk)
fput(zlo->data_dir);
destroy_workqueue(zlo->workqueue);
+ kfree(zlo->elements);
kfree(zlo->base_dir);
kvfree(zlo);
}
+
+static const struct blk_storage_elements_ops zloop_se_ops = {
+ .report_elements = zloop_report_elements,
+ .remove_element = zloop_remove_element,
+ .restore_elements = zloop_restore_elements,
+};
+
static const struct block_device_operations zloop_fops = {
.owner = THIS_MODULE,
.open = zloop_open,
.report_zones = zloop_report_zones,
.free_disk = zloop_free_disk,
+ .se_ops = &zloop_se_ops,
};
__printf(3, 4)
@@ -1095,6 +1468,17 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
if (!opts->buffered_io)
oflags |= O_DIRECT;
+ if (zlo->stor_elements != ZLOOP_STOR_ELEMENTS_NONE) {
+ unsigned int nr_elems = zlo->nr_elements;
+
+ if (zlo->stor_elements == ZLOOP_STOR_ELEMENTS_PAIRS)
+ nr_elems /= 2;
+ zone->wr_se_id = (zone_no % nr_elems) + 1;
+ zone->rd_se_id = zone->wr_se_id;
+ if (zlo->stor_elements == ZLOOP_STOR_ELEMENTS_PAIRS)
+ zone->rd_se_id += nr_elems;
+ }
+
if (zone_no < zlo->nr_conv_zones) {
/* Conventional zone file. */
set_bit(ZLOOP_ZONE_CONV, &zone->flags);
@@ -1165,6 +1549,93 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
return ret;
}
+#define ZLOOP_MIN_STOR_ELEMENTS 2
+#define ZLOOP_MAX_STOR_ELEMENTS 32
+#define ZLOOP_MIN_ZONES_PER_STOR_ELEMENTS 32
+
+static int zloop_create_storage_elements(struct zloop_device *zlo)
+{
+ struct blk_storage_element *se, *paired_se;
+ unsigned int i, nr_elems, nr_elements;
+ unsigned int nr_zones_per_element, nrz = 0;
+ sector_t capacity_per_element;
+
+ /*
+ * Calculate the number of storage elements we are going to emulate.
+ * To achieve a somewhat realistic emulation, we want at least 2 storage
+ * elements, and no more than 32, targeting at least 32 zones per
+ * element.
+ */
+ if (zlo->nr_zones <= 64)
+ nr_elements = 2;
+ else
+ nr_elements =
+ min(ZLOOP_MAX_STOR_ELEMENTS,
+ zlo->nr_zones / ZLOOP_MIN_ZONES_PER_STOR_ELEMENTS);
+ nr_zones_per_element = zlo->nr_zones / nr_elements;
+ capacity_per_element =
+ (sector_t)nr_zones_per_element << zlo->zone_shift;
+
+ /*
+ * If we are emulating pairs of read and write storage elements, we need
+ * double the number of storage element descriptors.
+ */
+ nr_elems = nr_elements;
+ if (zlo->stor_elements == ZLOOP_STOR_ELEMENTS_PAIRS)
+ nr_elems *= 2;
+ zlo->elements = kzalloc_objs(struct blk_storage_element, nr_elems);
+ if (!zlo->elements)
+ return -ENOMEM;
+
+ for (i = 0, se = zlo->elements; i < nr_elements; i++, se++) {
+ se->id = i + 1;
+ if (nrz + nr_zones_per_element > zlo->nr_zones)
+ se->nr_zones = zlo->nr_zones - nrz;
+ else
+ se->nr_zones = nr_zones_per_element;
+
+ if (zlo->stor_elements == ZLOOP_STOR_ELEMENTS_PAIRS)
+ se->type = BLK_SE_TYPE_WRITE;
+ else
+ se->type = BLK_SE_TYPE_RDWR;
+
+ se->status = BLK_SE_STS_OK;
+
+ nrz += nr_zones_per_element;
+ }
+
+ /*
+ * If we are emulating pairs of read and write storage elements,
+ * initialize the read elements paired with the write elements we just
+ * initialized.
+ */
+ if (zlo->stor_elements == ZLOOP_STOR_ELEMENTS_PAIRS) {
+ for (i = 0; i < nr_elements; i++, se++) {
+ se->id = nr_elements + i + 1;
+ paired_se = &zlo->elements[i];
+ se->paired_id = paired_se->id;
+ paired_se->paired_id = se->id;
+ se->nr_zones = paired_se->nr_zones;
+ se->type = BLK_SE_TYPE_READ;
+ se->status = BLK_SE_STS_OK;
+ }
+ }
+
+ /*
+ * Make sure we do not allow removing all storage elements as that does
+ * not make any sense. This is consistent with the device advertized
+ * limit of SCSI and ATA devices supporting the storage element
+ * depopulation feature.
+ */
+ zlo->nr_elements = nr_elems;
+ if (zlo->stor_elements == ZLOOP_STOR_ELEMENTS_PAIRS)
+ zlo->max_nr_removed_elements = zlo->nr_elements - 2;
+ else
+ zlo->max_nr_removed_elements = zlo->nr_elements - 1;
+
+ return 0;
+}
+
static bool zloop_dev_exists(struct zloop_device *zlo)
{
struct file *cnv, *seq;
@@ -1220,6 +1691,10 @@ static int zloop_ctl_add(struct zloop_options *opts)
WRITE_ONCE(zlo->state, Zlo_creating);
spin_lock_init(&zlo->open_zones_lock);
INIT_LIST_HEAD(&zlo->open_zones_lru_list);
+ mutex_init(&zlo->stor_elements_lock);
+ INIT_DELAYED_WORK(&zlo->remove_element_work, zloop_remove_element_work);
+ INIT_DELAYED_WORK(&zlo->restore_elements_work,
+ zloop_restore_elements_work);
ret = mutex_lock_killable(&zloop_ctl_mutex);
if (ret)
@@ -1253,12 +1728,19 @@ static int zloop_ctl_add(struct zloop_options *opts)
if (zlo->zone_append)
zlo->ordered_zone_append = opts->ordered_zone_append;
zlo->discard_write_cache = opts->discard_write_cache;
+ zlo->stor_elements = opts->stor_elements;
+
+ if (zlo->stor_elements != ZLOOP_STOR_ELEMENTS_NONE) {
+ ret = zloop_create_storage_elements(zlo);
+ if (ret)
+ goto out_free_idr;
+ }
zlo->workqueue = alloc_workqueue("zloop%d", WQ_UNBOUND | WQ_FREEZABLE,
opts->nr_queues * opts->queue_depth, zlo->id);
if (!zlo->workqueue) {
ret = -ENOMEM;
- goto out_free_idr;
+ goto out_destroy_storage_elements;
}
if (opts->base_dir)
@@ -1344,6 +1826,10 @@ static int zloop_ctl_add(struct zloop_options *opts)
zlo->id, zlo->nr_zones,
((sector_t)zlo->zone_size << SECTOR_SHIFT) >> 20,
zlo->block_size);
+ if (zlo->nr_elements)
+ pr_info("zloop%d: %d storage elements\n",
+ zlo->id, zlo->nr_elements);
+
pr_info("zloop%d: using %s%s zone append\n",
zlo->id,
zlo->ordered_zone_append ? "ordered " : "",
@@ -1367,6 +1853,8 @@ static int zloop_ctl_add(struct zloop_options *opts)
kfree(zlo->base_dir);
out_destroy_workqueue:
destroy_workqueue(zlo->workqueue);
+out_destroy_storage_elements:
+ kfree(zlo->elements);
out_free_idr:
mutex_lock(&zloop_ctl_mutex);
idr_remove(&zloop_index_idr, zlo->id);
@@ -1466,6 +1954,39 @@ static int zloop_ctl_remove(struct zloop_options *opts)
return 0;
}
+static int zloop_ctl_degrade_element(struct zloop_options *opts)
+{
+ struct zloop_device *zlo;
+ int ret = 0;
+
+ if (!(opts->mask & ZLOOP_OPT_ID)) {
+ pr_err("No ID specified for degrade_element\n");
+ return -EINVAL;
+ }
+
+ if (opts->mask & ~(ZLOOP_OPT_ID | ZLOOP_OPT_ELEMENT_ID)) {
+ pr_err("Invalid option specified for degrade_element\n");
+ return -EINVAL;
+ }
+
+ mutex_lock(&zloop_ctl_mutex);
+ zlo = idr_find(&zloop_index_idr, opts->id);
+ if (!zlo || zlo->state == Zlo_creating)
+ ret = -ENODEV;
+ else if (zlo->state == Zlo_deleting)
+ ret = -EINVAL;
+ mutex_unlock(&zloop_ctl_mutex);
+ if (ret)
+ return ret;
+
+ ret = zloop_degrade_element(zlo, opts->element_id);
+ if (!ret)
+ pr_info("Degraded element %u of device %u\n",
+ opts->id, opts->element_id);
+
+ return ret;
+}
+
static int zloop_parse_options(struct zloop_options *opts, const char *buf)
{
substring_t args[MAX_OPT_ARGS];
@@ -1485,6 +2006,8 @@ static int zloop_parse_options(struct zloop_options *opts, const char *buf)
opts->buffered_io = ZLOOP_DEF_BUFFERED_IO;
opts->zone_append = ZLOOP_DEF_ZONE_APPEND;
opts->ordered_zone_append = ZLOOP_DEF_ORDERED_ZONE_APPEND;
+ opts->stor_elements = ZLOOP_DEF_STOR_ELEMENTS;
+ opts->element_id = ZLOOP_DEF_ELEMENT_ID;
if (!buf)
return 0;
@@ -1619,6 +2142,30 @@ static int zloop_parse_options(struct zloop_options *opts, const char *buf)
case ZLOOP_OPT_DISCARD_WRITE_CACHE:
opts->discard_write_cache = true;
break;
+ case ZLOOP_OPT_STOR_ELEMENTS:
+ if (match_uint(args, &token)) {
+ ret = -EINVAL;
+ goto out;
+ }
+ switch (token) {
+ case ZLOOP_STOR_ELEMENTS_NONE:
+ case ZLOOP_STOR_ELEMENTS_RDWR:
+ case ZLOOP_STOR_ELEMENTS_PAIRS:
+ break;
+ default:
+ pr_err("Invalid zone_append value\n");
+ ret = -EINVAL;
+ goto out;
+ }
+ opts->stor_elements = token;
+ break;
+ case ZLOOP_OPT_ELEMENT_ID:
+ if (match_uint(args, &token)) {
+ ret = -EINVAL;
+ goto out;
+ }
+ opts->element_id = token;
+ break;
case ZLOOP_OPT_ERR:
default:
pr_warn("unknown parameter or missing value '%s'\n", p);
@@ -1647,14 +2194,16 @@ static int zloop_parse_options(struct zloop_options *opts, const char *buf)
enum {
ZLOOP_CTL_ADD,
ZLOOP_CTL_REMOVE,
+ ZLOOP_CTL_DEGRADE_ELEMENT,
};
static struct zloop_ctl_op {
int code;
const char *name;
} zloop_ctl_ops[] = {
- { ZLOOP_CTL_ADD, "add" },
- { ZLOOP_CTL_REMOVE, "remove" },
+ { ZLOOP_CTL_ADD, "add" },
+ { ZLOOP_CTL_REMOVE, "remove" },
+ { ZLOOP_CTL_DEGRADE_ELEMENT, "degrade_element" },
{ -1, NULL },
};
@@ -1702,6 +2251,9 @@ static ssize_t zloop_ctl_write(struct file *file, const char __user *ubuf,
case ZLOOP_CTL_REMOVE:
ret = zloop_ctl_remove(&opts);
break;
+ case ZLOOP_CTL_DEGRADE_ELEMENT:
+ ret = zloop_ctl_degrade_element(&opts);
+ break;
default:
pr_err("Invalid operation\n");
ret = -EINVAL;
@@ -1725,6 +2277,8 @@ static int zloop_ctl_show(struct seq_file *seq_file, void *private)
tok = &zloop_opt_tokens[i];
if (!tok->pattern)
break;
+ if (tok->token == ZLOOP_OPT_ELEMENT_ID)
+ continue;
if (i)
seq_putc(seq_file, ',');
seq_puts(seq_file, tok->pattern);
@@ -1735,6 +2289,10 @@ static int zloop_ctl_show(struct seq_file *seq_file, void *private)
seq_puts(seq_file, zloop_ctl_ops[1].name);
seq_puts(seq_file, " id=%d\n");
+ /* Degrade element operation */
+ seq_puts(seq_file, zloop_ctl_ops[2].name);
+ seq_puts(seq_file, " id=%d,element_id=%d\n");
+
return 0;
}
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index a1b21ea14e549..799d2093d667b 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -3937,6 +3937,7 @@ static const struct block_device_operations sd_fops = {
.get_unique_id = sd_get_unique_id,
.free_disk = scsi_disk_free_disk,
.pr_ops = &sd_pr_ops,
+ .se_ops = &sd_zbc_se_ops,
};
/**
diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h
index 574af82430169..16a004a1e6f1e 100644
--- a/drivers/scsi/sd.h
+++ b/drivers/scsi/sd.h
@@ -156,6 +156,7 @@ struct scsi_disk {
unsigned ignore_medium_access_errors : 1;
unsigned rscs : 1; /* reduced stream control support */
unsigned use_atomic_write_boundary : 1;
+ unsigned modify_zones_supported : 1;
};
#define to_scsi_disk(obj) container_of(obj, struct scsi_disk, disk_dev)
@@ -242,6 +243,8 @@ unsigned int sd_zbc_complete(struct scsi_cmnd *cmd, unsigned int good_bytes,
int sd_zbc_report_zones(struct gendisk *disk, sector_t sector,
unsigned int nr_zones, struct blk_report_zones_args *args);
+extern const struct blk_storage_elements_ops sd_zbc_se_ops;
+
#else /* CONFIG_BLK_DEV_ZONED */
static inline int sd_zbc_read_zones(struct scsi_disk *sdkp,
@@ -270,6 +273,8 @@ static inline unsigned int sd_zbc_complete(struct scsi_cmnd *cmd,
#define sd_zbc_report_zones NULL
+#define sd_zbc_se_ops NULL
+
#endif /* CONFIG_BLK_DEV_ZONED */
void sd_print_sense_hdr(struct scsi_disk *sdkp, struct scsi_sense_hdr *sshdr);
diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
index 456beaf2e7690..586e0ab508edc 100644
--- a/drivers/scsi/sd_zbc.c
+++ b/drivers/scsi/sd_zbc.c
@@ -516,6 +516,21 @@ static int sd_zbc_check_capacity(struct scsi_disk *sdkp, unsigned char *buf,
return 0;
}
+/*
+ * sd_zbc_check_modify_zones - Check if the device supports depopulation
+ * @sdkp: Target disk
+ * @buf: command buffer
+ *
+ * Check if the device supports the REMOVE ELEMENT AND MODIFY ZONES command.
+ */
+static inline bool sd_zbc_check_modify_zones(struct scsi_disk *sdkp,
+ unsigned char *buf)
+{
+ return scsi_report_opcode(sdkp->device, buf, SD_BUF_SIZE,
+ SERVICE_ACTION_IN_16,
+ SAI_REMOVE_ELEMENT_AND_MODIFY_ZONES) == 1;
+}
+
static void sd_zbc_print_zones(struct scsi_disk *sdkp)
{
if (sdkp->device->type != TYPE_ZBC || !sdkp->capacity)
@@ -533,6 +548,216 @@ static void sd_zbc_print_zones(struct scsi_disk *sdkp)
sdkp->zone_info.zone_blocks);
}
+#define SD_ZBC_STORAGE_ELEMENTS_BUF_SIZE 4096
+
+static void sd_zbc_parse_storage_element(struct scsi_disk *sdkp, u8 *desc,
+ struct blk_storage_element *element)
+{
+ struct scsi_device *sdp = sdkp->device;
+ u64 capacity;
+
+ element->id = get_unaligned_be32(&desc[4]);
+
+ switch (desc[14]) {
+ case SCSI_PHYS_ELEM_TYPE_ALL_ACCESS_STORAGE:
+ element->paired_id = 0;
+ element->type = BLK_SE_TYPE_RDWR;
+ capacity = get_unaligned_be64(&desc[16]);
+ element->nr_zones = logical_to_sectors(sdp, capacity) >>
+ ilog2(sd_zbc_zone_sectors(sdkp));
+ break;
+ case SCSI_PHYS_ELEM_TYPE_FRAC_ACCESS_STORAGE:
+ element->paired_id = get_unaligned_be32(&desc[16]);
+ if (desc[20] & 0x01)
+ element->type = BLK_SE_TYPE_READ;
+ else
+ element->type = BLK_SE_TYPE_WRITE;
+ element->nr_zones = get_unaligned_be64(&desc[24]);
+ break;
+ default:
+ element->type = BLK_SE_TYPE_UNKNOWN;
+ }
+
+ switch (desc[15]) {
+ case SCSI_PHYS_ELEM_HEALTH_WITHIN_SPEC_LIMITS:
+ case SCSI_PHYS_ELEM_HEALTH_AT_SPEC_LIMITS:
+ element->status = BLK_SE_STS_OK;
+ break;
+ case SCSI_PHYS_ELEM_HEALTH_OUTSIDE_SPEC_LIMITS:
+ element->status = BLK_SE_STS_DEGRADED;
+ break;
+ case SCSI_PHYS_ELEM_HEALTH_DEPOP_REVOKE_ERR:
+ element->status = BLK_SE_STS_RESTORE_ERROR;
+ break;
+ case SCSI_PHYS_ELEM_HEALTH_DEPOP_REVOKE_IN_PROGRESS:
+ element->status = BLK_SE_STS_RESTORE_IN_PROGRESS;
+ break;
+ case SCSI_PHYS_ELEM_HEALTH_DEPOP_ERR:
+ element->status = BLK_SE_STS_REMOVE_ERROR;
+ break;
+ case SCSI_PHYS_ELEM_HEALTH_DEPOP_IN_PROGRESS:
+ element->status = BLK_SE_STS_REMOVE_IN_PROGRESS;
+ break;
+ case SCSI_PHYS_ELEM_HEALTH_DEPOP_OK:
+ element->status = BLK_SE_STS_REMOVED;
+ element->restore_allowed = desc[13] & 0x01;
+ break;
+ case SCSI_PHYS_ELEM_HEALTH_NOT_REPORTED:
+ default:
+ element->status = BLK_SE_STS_UNKOWN;
+ break;
+ }
+}
+
+static int sd_zbc_report_storage_elements(struct gendisk *disk,
+ unsigned int *nr_elements,
+ struct blk_storage_element *elements)
+{
+ struct scsi_disk *sdkp = scsi_disk(disk);
+ struct scsi_device *sdp = sdkp->device;
+ const int timeout = sdp->request_queue->rq_timeout;
+ struct scsi_sense_hdr sshdr;
+ const struct scsi_exec_args exec_args = {
+ .sshdr = &sshdr,
+ };
+ unsigned char cmd[16];
+ unsigned int nr_descs;
+ int i, ret = 0, result;
+ u8 *desc, *buf;
+
+ if (!sdkp->modify_zones_supported)
+ return -EOPNOTSUPP;
+
+ buf = kzalloc(SD_ZBC_STORAGE_ELEMENTS_BUF_SIZE, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+
+ memset(cmd, 0, 16);
+ cmd[0] = SERVICE_ACTION_IN_16;
+ cmd[1] = SAI_GET_PHYSICAL_ELEMENT_STATUS;
+ put_unaligned_be32(SD_ZBC_STORAGE_ELEMENTS_BUF_SIZE, &cmd[10]);
+
+ result = scsi_execute_cmd(sdp, cmd, REQ_OP_DRV_IN, buf,
+ SD_ZBC_STORAGE_ELEMENTS_BUF_SIZE,
+ timeout, 1, &exec_args);
+ if (result) {
+ sd_printk(KERN_ERR, sdkp,
+ "GET PHYSICAL ELEMENT STATUS failed\n");
+ sd_print_result(sdkp, "GET PHYSICAL ELEMENT STATUS", result);
+ if (result > 0 && scsi_sense_valid(&sshdr))
+ sd_print_sense_hdr(sdkp, &sshdr);
+ ret = -EIO;
+ goto free_buf;
+ }
+
+ nr_descs = get_unaligned_be32(&buf[0]);
+ if (!nr_descs) {
+ sd_printk(KERN_ERR, sdkp,
+ "Invalid number of phys element descriptors\n");
+ ret = -EIO;
+ goto free_buf;
+ }
+
+ if (!elements) {
+ *nr_elements = nr_descs;
+ goto free_buf;
+ }
+
+ nr_descs = get_unaligned_be32(&buf[4]);
+ if (!nr_descs) {
+ sd_printk(KERN_ERR, sdkp,
+ "Invalid number of reported phys element descriptors\n");
+ ret = -EIO;
+ goto free_buf;
+ }
+
+ desc = &buf[32];
+ for (i = 0; i < min(*nr_elements, nr_descs); i++, desc += 32)
+ sd_zbc_parse_storage_element(sdkp, desc, &elements[i]);
+ *nr_elements = nr_descs;
+
+free_buf:
+ kfree(buf);
+
+ return ret;
+}
+
+static int sd_zbc_remove_storage_element(struct gendisk *disk,
+ unsigned int element_id)
+{
+ struct scsi_disk *sdkp = scsi_disk(disk);
+ struct scsi_device *sdp = sdkp->device;
+ const int timeout = sdp->request_queue->rq_timeout;
+ struct scsi_sense_hdr sshdr;
+ const struct scsi_exec_args exec_args = {
+ .sshdr = &sshdr,
+ };
+ unsigned char cmd[16];
+ int result;
+
+ if (!sdkp->modify_zones_supported)
+ return -EOPNOTSUPP;
+
+ memset(cmd, 0, 16);
+ cmd[0] = SERVICE_ACTION_IN_16;
+ cmd[1] = SAI_REMOVE_ELEMENT_AND_MODIFY_ZONES;
+ put_unaligned_be32(element_id, &cmd[10]);
+
+ result = scsi_execute_cmd(sdp, cmd, REQ_OP_DRV_IN, NULL, 0,
+ timeout, 1, &exec_args);
+ if (result) {
+ sd_printk(KERN_ERR, sdkp,
+ "REMOVE ELEMENT AND MODIFY ZONES failed\n");
+ sd_print_result(sdkp,
+ "REMOVE ELEMENT AND MODIFY ZONES", result);
+ if (result > 0 && scsi_sense_valid(&sshdr))
+ sd_print_sense_hdr(sdkp, &sshdr);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+static int sd_zbc_restore_storage_elements(struct gendisk *disk)
+{
+ struct scsi_disk *sdkp = scsi_disk(disk);
+ struct scsi_device *sdp = sdkp->device;
+ const int timeout = sdp->request_queue->rq_timeout;
+ struct scsi_sense_hdr sshdr;
+ const struct scsi_exec_args exec_args = {
+ .sshdr = &sshdr,
+ };
+ unsigned char cmd[16];
+ int result;
+
+ if (!sdkp->modify_zones_supported)
+ return -EOPNOTSUPP;
+
+ memset(cmd, 0, 16);
+ cmd[0] = SERVICE_ACTION_IN_16;
+ cmd[1] = SAI_RESTORE_ELEMENTS_AND_REBUILD;
+
+ result = scsi_execute_cmd(sdp, cmd, REQ_OP_DRV_IN, NULL, 0,
+ timeout, 1, &exec_args);
+ if (result) {
+ sd_printk(KERN_ERR, sdkp,
+ "RESTORE ELEMENTS AND REBUILD failed\n");
+ sd_print_result(sdkp,
+ "RESTORE ELEMENTS AND REBUILD", result);
+ if (result > 0 && scsi_sense_valid(&sshdr))
+ sd_print_sense_hdr(sdkp, &sshdr);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+const struct blk_storage_elements_ops sd_zbc_se_ops = {
+ .report_elements = sd_zbc_report_storage_elements,
+ .remove_element = sd_zbc_remove_storage_element,
+ .restore_elements = sd_zbc_restore_storage_elements,
+};
+
/*
* Call blk_revalidate_disk_zones() if any of the zoned disk properties have
* changed that make it necessary to call that function. Called by
@@ -554,9 +779,15 @@ int sd_zbc_revalidate_zones(struct scsi_disk *sdkp)
if (!blk_queue_is_zoned(q))
return 0;
+ /*
+ * If the zone size and number of zones has not changed, and the disk
+ * does not support depopulating heads, skip the rather slow call to
+ * blk_revalidate_disk_zones().
+ */
if (sdkp->zone_info.zone_blocks == zone_blocks &&
sdkp->zone_info.nr_zones == nr_zones &&
- disk->nr_zones == nr_zones)
+ disk->nr_zones == nr_zones &&
+ !sdkp->modify_zones_supported)
return 0;
sdkp->zone_info.zone_blocks = zone_blocks;
@@ -620,6 +851,9 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, struct queue_limits *lim,
if (ret != 0)
goto err;
+ /* Check if REMOVE ELEMENT AND MODIFY ZONES is supported. */
+ sdkp->modify_zones_supported = sd_zbc_check_modify_zones(sdkp, buf);
+
nr_zones = round_up(sdkp->capacity, zone_blocks) >> ilog2(zone_blocks);
if (nr_zones > INT_MAX) {
sd_printk(KERN_ERR, sdkp, "Too many zones (%llu)\n",
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index d003a9d2d1f6c..0b2013c96cad5 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1574,6 +1574,21 @@ enum blk_unique_id {
BLK_UID_NAA = 3,
};
+struct blk_storage_elements_ops {
+ int (*report_elements)(struct gendisk *disk,
+ unsigned int *nr_elements,
+ struct blk_storage_element *elements);
+ int (*remove_element)(struct gendisk *disk, unsigned int element_id);
+ int (*restore_elements)(struct gendisk *disk);
+};
+
+int bdev_report_storage_elements(struct block_device *bdev,
+ unsigned int *nr_elements,
+ struct blk_storage_element *elements);
+int bdev_remove_storage_element(struct block_device *bdev,
+ unsigned int element_id);
+int bdev_restore_storage_elements(struct block_device *bdev);
+
struct block_device_operations {
void (*submit_bio)(struct bio *bio);
int (*poll_bio)(struct bio *bio, struct io_comp_batch *iob,
@@ -1601,6 +1616,7 @@ struct block_device_operations {
enum blk_unique_id id_type);
struct module *owner;
const struct pr_ops *pr_ops;
+ const struct blk_storage_elements_ops *se_ops;
/*
* Special callback for probing GPT entry at a given sector.
diff --git a/include/uapi/linux/blkzoned.h b/include/uapi/linux/blkzoned.h
index 6638361209667..bd2c55d1a0d26 100644
--- a/include/uapi/linux/blkzoned.h
+++ b/include/uapi/linux/blkzoned.h
@@ -208,4 +208,85 @@ struct blk_zone_range {
#define BLKFINISHZONE _IOW(0x12, 136, struct blk_zone_range)
#define BLKREPORTZONEV2 _IOWR(0x12, 142, struct blk_zone_report)
+/**
+ * enum blk_storage_element_status - Statuc of a zoned device storage elements.
+ *
+ * @BLK_SE_RDWR: The storage element handles both reads and writes.
+ * @BLK_SE_READ: The storage element handles reads only.
+ * @BLK_SE_WRITE: The storage element handles writes only.
+ * @BLK_SE_WRITE: The storage element type is unknown.
+ */
+enum blk_storage_element_type {
+ BLK_SE_TYPE_RDWR = 0x01,
+ BLK_SE_TYPE_READ = 0x02,
+ BLK_SE_TYPE_WRITE = 0x03,
+ BLK_SE_TYPE_UNKNOWN = 0xFF,
+};
+
+/**
+ * enum blk_storage_element_status - Status of a zoned device storage elements.
+ *
+ * @BLK_SE_STS_OK: The storage element is operating normally.
+ * @BLK_SE_STS_DEGRADED: The storage element has degraded and is not operating
+ * normally.
+ * @BLK_SE_STS_REMOVE_IN_PROGRESS: The storage element is being removed.
+ * @BLK_SE_STS_REMOVE_ERROR: The storage element removal failed.
+ * @BLK_SE_STS_RESTORE_IN_PROGRESS: The storage element is being restored.
+ * @BLK_SE_STS_RESTORE_ERROR: The storage element restoration failed.
+ * @BLK_SE_STS_REMOVED: The storage element was removed.
+ * @BLK_SE_STS_UNKNOWN: The storage element status is unknown.
+ */
+enum blk_storage_element_status {
+ BLK_SE_STS_OK = 0x01,
+ BLK_SE_STS_DEGRADED = 0x02,
+ BLK_SE_STS_REMOVE_IN_PROGRESS = 0x03,
+ BLK_SE_STS_REMOVE_ERROR = 0x04,
+ BLK_SE_STS_RESTORE_IN_PROGRESS = 0x05,
+ BLK_SE_STS_RESTORE_ERROR = 0x06,
+ BLK_SE_STS_REMOVED = 0x07,
+ BLK_SE_STS_UNKOWN = 0xFF,
+};
+
+/**
+ * struct blk_storage_element - Zoned device storage element descriptor.
+ *
+ * @id: The ID of the element (cannot be 0).
+ * @paired_id: The ID of the paired element for an element that is not
+ * of type BLK_SE_TYPE_RDWR.
+ * @type: The type of the storage element (enum blk_storage_element_type).
+ * @status: The health status of the storage element
+ * (enum blk_storage_element_status).
+ * @restore_allowed: Indicate if the storage element can be restored.
+ * @nr_zones: The number of zones that the storage element handles.
+ */
+struct blk_storage_element {
+ __u32 id;
+ __u32 paired_id;
+ __u64 nr_zones;
+ __u8 type;
+ __u8 status;
+ __u8 restore_allowed;
+ __u8 reserved[5];
+};
+
+struct blk_storage_elements_report {
+ __u32 nr_elements;
+ __u32 reserved;
+ struct blk_storage_element elements[];
+};
+
+/**
+ * Zoned block device storage element management ioctl's:
+ *
+ * @BLKGETNRSTORELEMS: Get the number of storage elements of the device.
+ * @BLKREPORTSTORELEMS: Get the device storage elements.
+ * @BLKREMOVESTORELEM: Remove (depopulate) one storage element of a device.
+ * @BLKRESTORESTORELEM: Restore (repopulate if possible) all storage elements
+ * that have been removed.
+ */
+#define BLKGETNRSTORELEMS _IOR(0x12, 143, __u32)
+#define BLKREPORTSTORELEMS _IOWR(0x12, 144, struct blk_storage_elements_report)
+#define BLKREMOVESTORELEM _IOW(0x12, 145, __u32)
+#define BLKRESTORESTORELEMS _IO(0x12, 146)
+
#endif /* _UAPI_BLKZONED_H */
diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
index 34c6f219462a5..8a979326aa7f0 100644
--- a/include/uapi/linux/fs.h
+++ b/include/uapi/linux/fs.h
@@ -309,6 +309,7 @@ struct file_attr {
/* 130-136 and 142 are used by zoned block device ioctls (uapi/linux/blkzoned.h) */
/* 137-141 are used by blk-crypto ioctls (uapi/linux/blk-crypto.h) */
#define BLKTRACESETUP2 _IOWR(0x12, 142, struct blk_user_trace_setup2)
+/* 143-146 are used by storage element management for zoned block devices. */
#define BMAP_IOCTL 1 /* obsolete - kept for compatibility */
#define FIBMAP _IO(0x00,1) /* bmap access */
|
| 21/3 | 2026/10/05 10:30 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 23866 output: 20 thoughts: 1847 Thoughts: **KMSAN Fuzzing Evaluation - Zoned Block Device Patches** Okay, let's dive into this patch series. The goal is to figure out if we need a dedicated KMSAN fuzzing session. My first step is a thorough code analysis. This looks like it's touching zoned block device support, specifically related to storage element reporting and management, and has documentation updates too. It seems like it has additions related to offline zones. First off, there's a new `bdev_zone_is_offline()` check added within `submit_bio_noacct()` and the addition of `bdev_zone_is_offline()` itself. There's also some work in waiting for storage management to complete and the allocation of storage elements which are allocated using `kzalloc_objs`. Several IOCTLs related to storage element reporting and manipulation are being added or modified, like reporting, removing and restoring them. The zoned loop device and SCSI driver code appear to be getting storage element emulation and reporting capabilities. In particular, the ZBC SCSI code looks interesting with `sd_zbc_parse_storage_element`. Aha, hold on. The `sd_zbc_parse_storage_element` function is parsing data from the SCSI device description. There's a `switch` statement there handling different element types. It uses `get_unaligned_be32` and `get_unaligned_be64` which are prone to buffer overflows. Now, let's step back and look at where this is being used. The really interesting bit is inside `blkdev_report_storage_elements_ioctl`. We have a `copy_from_user` to initialize `rep`, which seems ok. I need to make sure I understand how it is being used, what the `rep` struct is. OK, the `elements` are allocated with `kzalloc_objs`. This means the `elements` are zero-initialized. I want to make sure I understand how `rep` is initialized. Let me check the definition of `struct blk_storage_elements_report`. It looks like it only has `nr_elements`, `reserved` and a flexible array member `elements[]`. So `sizeof(struct blk_storage_elements_report)` is 8 bytes. `copy_from_user` copies 8 bytes from userspace into `rep`. I need to remember that these 8 bytes is just `nr_elements` and `reserved`. The struct only contains the number of elements and then a flexible array member! So, the entire `rep` is initialized by the `copy_from_user`. So `elements` get zero-initialized. But is that what we want? Let's check `kzalloc_objs`. Ok, `kzalloc_objs` is using `kzalloc`. OK, so `kzalloc` is zero-initializing the elements. Now, is `copy_from_user` initializing `rep` correctly? Yes, `copy_from_user` initializes all the struct members that are present. I have to think about this...it looks like we're relying on the *user* providing the size of the elements, but we're allocating with `kzalloc`. Okay, now I have a better picture of what's going on. I'm going to look for a bug here. |
| 22/3 | 2026/10/05 10:30 | tool | grepper |
0mArgs:{
"Expression": "#define kzalloc_objs"
}Results: {
"Output": "include/linux/slab.h=1073=void *kmalloc_nolock(size_t size, gfp_t gfp_flags, int node);\n--\ninclude/linux/slab.h-1156-\t__alloc_objs(kzalloc, default_gfp(__VA_ARGS__), typeof(P), 1)\ninclude/linux/slab.h:1157:#define kzalloc_objs(P, COUNT, ...) \\\ninclude/linux/slab.h-1158-\t__alloc_objs(kzalloc, default_gfp(__VA_ARGS__), typeof(P), COUNT)\n"
} |
| 23/3 | 2026/10/05 10:30 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 26597 output: 21 thoughts: 1964 Thoughts: **Vulnerability Discovery: Heap Out-of-Bounds Read in Block Device Reporting** Okay, so `kzalloc_objs` is definitely allocating and zeroing the memory – that's good. But what's happening with `nr_elements` and `elements` within `bdev_report_storage_elements`? I need to dig deeper. I'm focusing on `blkdev_report_storage_elements_ioctl`. It allocates a buffer, `elements`, using `kzalloc_objs` based on `rep.nr_elements`. The crucial bit is how `nr_elements` is *modified* by the subsequent call to `bdev_report_storage_elements`. Let's examine `sd_zbc_report_storage_elements`. Here it is. AHA! Look at `*nr_elements = nr_descs;`. So if the userspace calls with, let's say, `rep.nr_elements = 2`, the `elements` buffer gets allocated for two elements. Then, if `nr_descs` is, say, 10 within `sd_zbc_report_storage_elements`, `*nr_elements` gets set to 10! The code proceeds to `copy_to_user` and *copies* using `nr_elements` now set to 10. But `elements` *only has space for 2 elements*. BANG! That's a heap buffer overread, an out-of-bounds read! KASAN should flag that! Now, what if `nr_elements` gets *smaller*? Let's check `zloop_report_elements`... Yes, here's another, possibly even more exploitable scenario! User calls with, say, `rep.nr_elements = 1`. `zlo->nr_elements` could be 8. In this case, `nr_report` = 1, so the `for` loop copies one element, and `*nr_elements` is set to 8. `copy_to_user` copies 8 elements from the `elements` buffer – but `elements` was only allocated for 1 element! This, again, is an out-of-bounds read on a kmalloc slab. I'm sure KASAN will catch that! Now, the question is: KASAN or KMSAN? From the instructions, it's clear: KMSAN is for *uninitialized* memory issues. If it's something KASAN or a standard detector finds, there's no need for KMSAN. I need to make sure there's no uninitialized memory. Let's inspect, field by field, every copy-to-user, all variables and structs. Let me examine `bdev_zone_is_offline` and whether values are initialized, starting with what `disk_zone_get_cond` returns. |
| 24/3 | 2026/10/05 10:31 | tool | grepper |
0mArgs:{
"Expression": "disk_zone_get_cond"
}Results: {
"Output": "block/blk-zoned.c=251=static inline u8 disk_zone_get_state(struct gendisk *disk, sector_t sector)\n--\nblock/blk-zoned.c-266-\nblock/blk-zoned.c:267:static enum blk_zone_cond disk_zone_get_cond(struct gendisk *disk,\nblock/blk-zoned.c-268-\t\t\t\t\t sector_t sector)\n--\nblock/blk-zoned.c=282=static inline bool disk_zone_is_offline_or_readonly(struct gendisk *disk,\n--\nblock/blk-zoned.c-284-{\nblock/blk-zoned.c:285:\tenum blk_zone_cond cond = disk_zone_get_cond(disk, sector);\nblock/blk-zoned.c-286-\n--\nblock/blk-zoned.c=320=bool bdev_zone_is_offline(struct block_device *bdev, sector_t sector)\n--\nblock/blk-zoned.c-326-\nblock/blk-zoned.c:327:\tcond = disk_zone_get_cond(bdev-\u003ebd_disk, sector);\nblock/blk-zoned.c-328-\treturn cond == BLK_ZONE_COND_OFFLINE;\n"
} |
| 25/3 | 2026/10/05 10:31 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29533 output: 32 thoughts: 4333 Thoughts: **Summary of My Analysis** Okay, so I've been diving deep into this code, specifically the storage element handling within the block layer, and I think I've found a critical issue. First, I confirmed how the `disk_zone_get_cond` function works, and looked at how `disk_wait_for_se_mgmt_completion` works, verifying how storage elements are reported. I then moved on to the `blkdev_get_nr_storage_elements_ioctl` and confirmed the number of elements is initialized before being passed to user space. I focused then on the `blkdev_report_storage_elements_ioctl` function, where the real potential problem lies. The core of my concern here centers around memory allocation and, more importantly, *how* the data gets copied to userspace, with a keen focus on the potential for out-of-bounds reads. Initially, `nr_elements` comes from user space via the `struct blk_storage_elements_report` structure. This value determines the size of the `elements` buffer allocated using `kzalloc_objs`. This zero-initializes the allocated memory (including any padding within the `struct blk_storage_element` structure, which I verified is 24 bytes). However, the code then calls `bdev_report_storage_elements`, and the number of storage elements reported by `zloop_report_elements` or `sd_zbc_report_storage_elements` (the underlying drivers) might *differ* from the original `nr_elements` provided by the user. If the number of elements reported is *less* than what the user requested, everything is fine. `kzalloc_objs` has been correctly initialized. However, if the number of *elements* reported is *more* than the user requested, then memory is not allocated for these elements. The crucial flaw emerges in this case: If `nr_elements` (from the driver) is greater than the allocated size, the `copy_to_user` function will *attempt to write data beyond the allocated buffer*. In essence, this results in a **slab-out-of-bounds read**. This is a serious security vulnerability! KASAN (Kernel Address Sanitizer) should detect this and flag it as a bug. This means we should set `NeedsKMSAN=false`! After this, I re-examined the changes to `drivers/block/zloop.c` to see if there were any other memory initialization issues. I checked `zloop_ctl_add` to verify initialization, and concluded that it is safe, so this memory safety issue is isolated to `blkdev_report_storage_elements_ioctl`. |
| 26/3 | 2026/10/05 10:31 | tool | grepper |
0mArgs:{
"Expression": "zlo = ",
"PathPrefix": "drivers/block/zloop.c"
}Results: {
"Output": "drivers/block/zloop.c=201=static unsigned int rq_zone_no(struct request *rq)\ndrivers/block/zloop.c-202-{\ndrivers/block/zloop.c:203:\tstruct zloop_device *zlo = rq-\u003eq-\u003equeuedata;\ndrivers/block/zloop.c-204-\n--\ndrivers/block/zloop.c=616=static int zloop_do_rw(struct zloop_cmd *cmd)\n--\ndrivers/block/zloop.c-620-\tunsigned int nr_bvec = blk_rq_nr_bvec(rq);\ndrivers/block/zloop.c:621:\tstruct zloop_device *zlo = rq-\u003eq-\u003equeuedata;\ndrivers/block/zloop.c-622-\tstruct zloop_zone *zone = \u0026zlo-\u003ezones[rq_zone_no(rq)];\n--\ndrivers/block/zloop.c=669=static int zloop_seq_write_prep(struct zloop_cmd *cmd)\n--\ndrivers/block/zloop.c-671-\tstruct request *rq = blk_mq_rq_from_pdu(cmd);\ndrivers/block/zloop.c:672:\tstruct zloop_device *zlo = rq-\u003eq-\u003equeuedata;\ndrivers/block/zloop.c-673-\tunsigned int zone_no = rq_zone_no(rq);\n--\ndrivers/block/zloop.c=730=static void zloop_rw(struct zloop_cmd *cmd)\n--\ndrivers/block/zloop.c-732-\tstruct request *rq = blk_mq_rq_from_pdu(cmd);\ndrivers/block/zloop.c:733:\tstruct zloop_device *zlo = rq-\u003eq-\u003equeuedata;\ndrivers/block/zloop.c-734-\tunsigned int zone_no = rq_zone_no(rq);\n--\ndrivers/block/zloop.c=845=static void zloop_handle_cmd(struct zloop_cmd *cmd)\n--\ndrivers/block/zloop.c-847-\tstruct request *rq = blk_mq_rq_from_pdu(cmd);\ndrivers/block/zloop.c:848:\tstruct zloop_device *zlo = rq-\u003eq-\u003equeuedata;\ndrivers/block/zloop.c-849-\n--\ndrivers/block/zloop.c=902=static void zloop_complete_rq(struct request *rq)\n--\ndrivers/block/zloop.c-904-\tstruct zloop_cmd *cmd = blk_mq_rq_to_pdu(rq);\ndrivers/block/zloop.c:905:\tstruct zloop_device *zlo = rq-\u003eq-\u003equeuedata;\ndrivers/block/zloop.c-906-\tunsigned int zone_no = cmd-\u003esector \u003e\u003e zlo-\u003ezone_shift;\n--\ndrivers/block/zloop.c=960=static bool zloop_set_zone_append_sector(struct request *rq)\ndrivers/block/zloop.c-961-{\ndrivers/block/zloop.c:962:\tstruct zloop_device *zlo = rq-\u003eq-\u003equeuedata;\ndrivers/block/zloop.c-963-\tunsigned int zone_no = rq_zone_no(rq);\n--\ndrivers/block/zloop.c=986=static blk_status_t zloop_queue_rq(struct blk_mq_hw_ctx *hctx,\n--\ndrivers/block/zloop.c-990-\tstruct zloop_cmd *cmd = blk_mq_rq_to_pdu(rq);\ndrivers/block/zloop.c:991:\tstruct zloop_device *zlo = rq-\u003eq-\u003equeuedata;\ndrivers/block/zloop.c-992-\n--\ndrivers/block/zloop.c=1021=static int zloop_open(struct gendisk *disk, blk_mode_t mode)\ndrivers/block/zloop.c-1022-{\ndrivers/block/zloop.c:1023:\tstruct zloop_device *zlo = disk-\u003eprivate_data;\ndrivers/block/zloop.c-1024-\tint ret;\n--\ndrivers/block/zloop.c=1036=static int zloop_report_zones(struct gendisk *disk, sector_t sector,\n--\ndrivers/block/zloop.c-1038-{\ndrivers/block/zloop.c:1039:\tstruct zloop_device *zlo = disk-\u003eprivate_data;\ndrivers/block/zloop.c-1040-\tstruct blk_zone blkz = {};\n--\ndrivers/block/zloop.c=1087=static int zloop_report_elements(struct gendisk *disk,\n--\ndrivers/block/zloop.c-1090-{\ndrivers/block/zloop.c:1091:\tstruct zloop_device *zlo = disk-\u003eprivate_data;\ndrivers/block/zloop.c-1092-\tunsigned int nr_report = *nr_elements;\n--\ndrivers/block/zloop.c=1148=static void zloop_remove_element_work(struct work_struct *work)\ndrivers/block/zloop.c-1149-{\ndrivers/block/zloop.c:1150:\tstruct zloop_device *zlo = container_of(work, struct zloop_device,\ndrivers/block/zloop.c-1151-\t\t\t\t\t\tremove_element_work.work);\n--\ndrivers/block/zloop.c=1206=static int zloop_remove_element(struct gendisk *disk, unsigned int element_id)\ndrivers/block/zloop.c-1207-{\ndrivers/block/zloop.c:1208:\tstruct zloop_device *zlo = disk-\u003eprivate_data;\ndrivers/block/zloop.c-1209-\tstruct blk_storage_element *se, *paired_se = NULL;\n--\ndrivers/block/zloop.c=1268=static void zloop_restore_elements_work(struct work_struct *work)\ndrivers/block/zloop.c-1269-{\ndrivers/block/zloop.c:1270:\tstruct zloop_device *zlo = container_of(work, struct zloop_device,\ndrivers/block/zloop.c-1271-\t\t\t\t\t\trestore_elements_work.work);\n--\ndrivers/block/zloop.c=1308=static int zloop_restore_elements(struct gendisk *disk)\ndrivers/block/zloop.c-1309-{\ndrivers/block/zloop.c:1310:\tstruct zloop_device *zlo = disk-\u003eprivate_data;\ndrivers/block/zloop.c-1311-\tstruct blk_storage_element *se;\n--\ndrivers/block/zloop.c=1349=static void zloop_free_disk(struct gendisk *disk)\ndrivers/block/zloop.c-1350-{\ndrivers/block/zloop.c:1351:\tstruct zloop_device *zlo = disk-\u003eprivate_data;\ndrivers/block/zloop.c-1352-\tunsigned int i;\n--\ndrivers/block/zloop.c=1658=static int zloop_ctl_add(struct zloop_options *opts)\n--\ndrivers/block/zloop.c-1685-\ndrivers/block/zloop.c:1686:\tzlo = kvzalloc_flex(*zlo, zones, nr_zones);\ndrivers/block/zloop.c-1687-\tif (!zlo) {\n--\ndrivers/block/zloop.c=1910=static int zloop_ctl_remove(struct zloop_options *opts)\n--\ndrivers/block/zloop.c-1928-\ndrivers/block/zloop.c:1929:\tzlo = idr_find(\u0026zloop_index_idr, opts-\u003eid);\ndrivers/block/zloop.c-1930-\tif (!zlo || zlo-\u003estate == Zlo_creating) {\n--\ndrivers/block/zloop.c=1957=static int zloop_ctl_degrade_element(struct zloop_options *opts)\n--\ndrivers/block/zloop.c-1972-\tmutex_lock(\u0026zloop_ctl_mutex);\ndrivers/block/zloop.c:1973:\tzlo = idr_find(\u0026zloop_index_idr, opts-\u003eid);\ndrivers/block/zloop.c-1974-\tif (!zlo || zlo-\u003estate == Zlo_creating)\n"
} |
| 27/3 | 2026/10/05 10:31 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 36665 output: 22 thoughts: 1867 Thoughts: **Analysis of Zone-Based Block Device Code** Alright, let's break this down. First, I see `zlo` being zero-allocated, and its `elements` member is also zero-allocated. Good. Now, that healthy function... `zloop_zone_healthy`. Let's dig into that. I see a check that depends on these `wr_se_id` and `rd_se_id` values. Where are those set? Ah, in `zloop_init_zone`. Got it. The IDs are derived from the zone number and the number of elements. The `zloop_zone_healthy` function can return `true` based on the status of a storage element, but... hang on. Is `BLK_SE_STS_DEGRADED` actually considered *healthy*? That's suspicious, and needs to be clarified. It looks like the state of `se->status` is always initialized to `BLK_SE_STS_OK` elsewhere, so is this a logic error? Now, onto `sd_zbc.c`. I see `sd_zbc_check_modify_zones` which is pretty straightforward. It fills a buffer, and calls `scsi_report_opcode`. The interesting one is `sd_zbc_report_storage_elements`. It `kzalloc`s a buffer (`buf`) of size `SD_ZBC_STORAGE_ELEMENTS_BUF_SIZE`. Okay, standard procedure. Then, it calls `scsi_execute_cmd` which fills `buf`. The real trouble is when we get to `sd_zbc_parse_storage_element`. The function takes `desc` as a parameter. `desc` is pointing into the buffer (`buf`). Then, we see a loop that increments `desc` by 32 bytes each time. But wait! What if the SCSI device returns a large value for the number of descriptions? `nr_descs = get_unaligned_be32(&buf[4]);` The buffer is of size 4096. But what if `nr_descs` is big? like 200? Then, 32 + 200 * 32 = 6432, which is *way* larger than 4096. That would be a *massive* out-of-bounds read, and KASAN should have been able to spot that, right? Yes! I should also check if the function initializes all fields of `element`. The `id` is initialized. The code checks `desc[14]`. It's a switch statement. The default case could cause a problem. In the default case, some fields are not set. The `paired_id` and `nr_zones` are not set. The `elements` are allocated with `kzalloc`. So, these fields will be zero. Let's see if anyone else can call `bdev_report_storage_elements`. Let's grep for that function. |
| 28/3 | 2026/10/05 10:32 | tool | grepper |
0mArgs:{
"Expression": "bdev_report_storage_elements"
}Results: {
"Output": "block/blk-zoned.c=2725=static void disk_wait_for_se_mgmt_completion(struct gendisk *disk)\n--\nblock/blk-zoned.c-2769-/**\nblock/blk-zoned.c:2770: * bdev_report_storage_elements - report the storage elements of a block device\nblock/blk-zoned.c-2771- *\n--\nblock/blk-zoned.c-2777- */\nblock/blk-zoned.c:2778:int bdev_report_storage_elements(struct block_device *bdev,\nblock/blk-zoned.c-2779-\t\t\t\t unsigned int *nr_elements,\n--\nblock/blk-zoned.c-2795-}\nblock/blk-zoned.c:2796:EXPORT_SYMBOL_GPL(bdev_report_storage_elements);\nblock/blk-zoned.c-2797-\nblock/blk-zoned.c=2798=static int blkdev_get_nr_storage_elements_ioctl(struct block_device *bdev,\n--\nblock/blk-zoned.c-2803-\nblock/blk-zoned.c:2804:\tret = bdev_report_storage_elements(bdev, \u0026nr_elements, NULL);\nblock/blk-zoned.c-2805-\tif (ret)\n--\nblock/blk-zoned.c=2814=static int blkdev_report_storage_elements_ioctl(struct block_device *bdev,\n--\nblock/blk-zoned.c-2837-\nblock/blk-zoned.c:2838:\tret = bdev_report_storage_elements(bdev, \u0026nr_elements, elements);\nblock/blk-zoned.c-2839-\tif (ret)\n--\ninclude/linux/blkdev.h=1577=struct blk_storage_elements_ops {\n--\ninclude/linux/blkdev.h-1584-\ninclude/linux/blkdev.h:1585:int bdev_report_storage_elements(struct block_device *bdev,\ninclude/linux/blkdev.h-1586-\t\t\t\t unsigned int *nr_elements,\n"
} |
| 29/3 | 2026/10/05 10:32 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 39757 output: 35 thoughts: 885 Thoughts: **Analyzing Storage Element Management in the Block Layer** Okay, let's break down this storage element interaction. My immediate focus is on how `bdev_report_storage_elements` (and `report_elements` for that matter) are called and what the implications are. From what I'm seeing, there seem to be a few key entry points. First, `disk_wait_for_se_mgmt_completion` calls it. It's called initially with a `NULL` element pointer, which is interesting - that probably serves as an initialization or a query. Then, it allocates memory using `kzalloc_objs`, and then *finally* it calls it with the allocated `elements`. Got it. Then, `blkdev_get_nr_storage_elements_ioctl` calls it too, but importantly, it also calls it with a `NULL` argument, which further confirms the initialization/query hypothesis. And finally, `blkdev_report_storage_elements_ioctl` also allocates and calls it with `elements`, which is what I would expect for reporting. Now, let's quickly check other relevant ioctls. I'm keen to understand how removal, restore, and other zone-related functions interact with storage elements. Looking at `blkdev_remove_storage_element_ioctl`, it reads `element_id` from user space using `get_user`, returning `-EFAULT` if it fails. That seems standard for user-space interaction. `blkdev_restore_storage_elements_ioctl` takes no user arguments and it seems straightforward, just a restore call. And, `blkdev_zone_storage_elements_ioctl` acts as a dispatcher for these ioctls: `BLKGETNRSTORELEMS`, `BLKREPORTSTORELEMS`, `BLKREMOVESTORELEM`, and `BLKRESTORESTORELEMS`. One more thing that piques my interest: that check in `block/blk-core.c`! I see a `bdev_zone_is_offline(...)` check within a read operation. If it's true, the `bio` is marked `BIO_QUIET` and the code jumps to `end_io`. Interesting. I need to understand what happens at `end_io` in relation to zones. Let me go find what happens at line 866 of `block/blk-core.c`. |
| 30/3 | 2026/10/05 10:32 | tool | read-file |
0mArgs:{
"File": "block/blk-core.c",
"FirstLine": 860,
"LineCount": 40
}Results: {
"Contents": " 860:\t\t\t\tif (!bio_sectors(bio)) {\n 861:\t\t\t\t\tstatus = BLK_STS_OK;\n 862:\t\t\t\t\tgoto end_io;\n 863:\t\t\t\t}\n 864:\t\t\t}\n 865:\t\t}\n 866:\t\n 867:\t\tswitch (bio_op(bio)) {\n 868:\t\tcase REQ_OP_READ:\n 869:\t\t\tif (bdev_is_zoned(bdev) \u0026\u0026\n 870:\t\t\t bdev_zone_is_offline(bdev, bio-\u003ebi_iter.bi_sector)) {\n 871:\t\t\t\tbio_set_flag(bio, BIO_QUIET);\n 872:\t\t\t\tgoto end_io;\n 873:\t\t\t}\n 874:\t\t\tbreak;\n 875:\t\tcase REQ_OP_WRITE:\n 876:\t\t\tif (bio-\u003ebi_opf \u0026 REQ_ATOMIC) {\n 877:\t\t\t\tstatus = blk_validate_atomic_write_op_size(q, bio);\n 878:\t\t\t\tif (status != BLK_STS_OK)\n 879:\t\t\t\t\tgoto end_io;\n 880:\t\t\t}\n 881:\t\t\tbreak;\n 882:\t\tcase REQ_OP_FLUSH:\n 883:\t\t\t/*\n 884:\t\t\t * REQ_OP_FLUSH can't be submitted through bios, it is only\n 885:\t\t\t * synthetized in struct request by the flush state machine.\n 886:\t\t\t */\n 887:\t\t\tgoto not_supported;\n 888:\t\tcase REQ_OP_DISCARD:\n 889:\t\t\tif (!bdev_max_discard_sectors(bdev))\n 890:\t\t\t\tgoto not_supported;\n 891:\t\t\tbreak;\n 892:\t\tcase REQ_OP_SECURE_ERASE:\n 893:\t\t\tif (!bdev_max_secure_erase_sectors(bdev))\n 894:\t\t\t\tgoto not_supported;\n 895:\t\t\tbreak;\n 896:\t\tcase REQ_OP_ZONE_APPEND:\n 897:\t\t\tstatus = blk_check_zone_append(q, bio);\n 898:\t\t\tif (status != BLK_STS_OK)\n 899:\t\t\t\tgoto end_io;\n"
} |
| 31/3 | 2026/10/05 10:32 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 41791 output: 35 thoughts: 20 Thoughts: Here's my take on those thoughts, tailored for an expert audience: **Tracing the Initialization of 'status' within `submit_bio_noacct`** Okay, so I'm diving into `submit_bio_noacct` and my immediate concern is the `status` variable. Where is this thing getting its initial value? I need to understand its lifecycle from the moment it comes into existence, because that's crucial for debugging and understanding control flow within the function. Is it a local variable being assigned directly? Is it passed in as an argument? Is it possibly a member variable of an object that's being instantiated or accessed somewhere? Is there an implied global variable? Perhaps it's being initialized by a configuration file, or another function call. I need to track down the exact point of initialization to be sure I'm not missing anything. Going to trace its scope and initialization from the top. Let's dig in. |
| 32/3 | 2026/10/05 10:32 | tool | read-file |
0mArgs:{
"File": "block/blk-core.c",
"FirstLine": 810,
"LineCount": 45
}Results: {
"Contents": " 810:\t * @bio: The bio describing the location in memory and on the device.\n 811:\t *\n 812:\t * This is a version of submit_bio() that shall only be used for I/O that is\n 813:\t * resubmitted to lower level drivers by stacking block drivers. All file\n 814:\t * systems and other upper level users of the block layer should use\n 815:\t * submit_bio() instead.\n 816:\t */\n 817:\tvoid submit_bio_noacct(struct bio *bio)\n 818:\t{\n 819:\t\tstruct block_device *bdev = bio-\u003ebi_bdev;\n 820:\t\tstruct request_queue *q = bdev_get_queue(bdev);\n 821:\t\tblk_status_t status = BLK_STS_IOERR;\n 822:\t\n 823:\t\tmight_sleep();\n 824:\t\n 825:\t\t/*\n 826:\t\t * For a REQ_NOWAIT based request, return -EOPNOTSUPP\n 827:\t\t * if queue does not support NOWAIT.\n 828:\t\t */\n 829:\t\tif ((bio-\u003ebi_opf \u0026 REQ_NOWAIT) \u0026\u0026 !bdev_nowait(bdev))\n 830:\t\t\tgoto not_supported;\n 831:\t\n 832:\t\tif (bio_has_crypt_ctx(bio)) {\n 833:\t\t\tif (WARN_ON_ONCE(!bio_has_data(bio)))\n 834:\t\t\t\tgoto end_io;\n 835:\t\t\tif (!blk_crypto_supported(bio))\n 836:\t\t\t\tgoto not_supported;\n 837:\t\t}\n 838:\t\n 839:\t\tif (should_fail_bio(bio))\n 840:\t\t\tgoto end_io;\n 841:\t\tbio_check_ro(bio);\n 842:\t\tif (!bio_flagged(bio, BIO_REMAPPED)) {\n 843:\t\t\tif (unlikely(bio_check_eod(bio)))\n 844:\t\t\t\tgoto end_io;\n 845:\t\t\tif (bdev_is_partition(bdev) \u0026\u0026\n 846:\t\t\t unlikely(blk_partition_remap(bio)))\n 847:\t\t\t\tgoto end_io;\n 848:\t\t}\n 849:\t\n 850:\t\t/*\n 851:\t\t * Filter flush bio's early so that bio based drivers without flush\n 852:\t\t * support don't have to worry about them.\n 853:\t\t */\n 854:\t\tif (op_is_flush(bio-\u003ebi_opf)) {\n"
} |
| 33/3 | 2026/10/05 10:32 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 42758 output: 27 thoughts: 3929 Thoughts: **Analysis of `blkdev_report_storage_elements_ioctl` and Related Functions** My focus is currently on understanding the potential vulnerabilities related to uninitialized memory within the block device storage element reporting. Specifically, I'm examining the `blkdev_report_storage_elements_ioctl` function and its interactions with user-space data. My initial thought was that a potential out-of-bounds read vulnerability could exist when copying the storage elements to user space. I noticed that `blkdev_report_storage_elements_ioctl` allocates a buffer (`elements`) using `kzalloc_objs` based on the user-provided `rep.nr_elements`. If the number of elements reported by the underlying device (`nr_elements`) exceeds the user's initial estimate, an overflow in the copy operation could occur, which is a significant concern. However, I confirmed that `kzalloc_objs` zero-initializes all allocated memory, which means every single byte, even if the "populated" count in the `elements` array grows beyond the `rep.nr_elements`, will be initialized. I then checked all the possible control paths through the `blkdev_report_storage_elements_ioctl`, and I could not see any uninitialized memory in the copy operations. I then revisited the details of `blkdev_report_storage_elements_ioctl`. After studying the structures and ioctl numbers, I confirmed the code's data flow. Then, I reviewed related functions like `bdev_report_storage_elements` and the `scsi_disk` functions called by other elements, but I could not find uninitialized memory issues. |
| 34/3 | 2026/10/05 10:32 | tool | grepper |
0mArgs:{
"Expression": "case BLKREPORTZONE",
"PathPrefix": "block/"
}Results: {
"Output": "block/blk-zoned.c=513=int blkdev_report_zones_ioctl(struct block_device *bdev, unsigned int cmd,\n--\nblock/blk-zoned.c-535-\tswitch (cmd) {\nblock/blk-zoned.c:536:\tcase BLKREPORTZONE:\nblock/blk-zoned.c-537-\t\tret = blkdev_report_zones(bdev, rep.sector, rep.nr_zones,\n--\nblock/blk-zoned.c-539-\t\tbreak;\nblock/blk-zoned.c:540:\tcase BLKREPORTZONEV2:\nblock/blk-zoned.c-541-\t\tif (rep.flags \u0026 ~BLK_ZONE_REPV2_INPUT_FLAGS)\n--\nblock/ioctl.c=651=static int blkdev_common_ioctl(struct block_device *bdev, blk_mode_t mode,\n--\nblock/ioctl.c-669-\t\treturn put_u64(argp, bdev-\u003ebd_disk-\u003ediskseq);\nblock/ioctl.c:670:\tcase BLKREPORTZONE:\nblock/ioctl.c:671:\tcase BLKREPORTZONEV2:\nblock/ioctl.c-672-\t\treturn blkdev_report_zones_ioctl(bdev, cmd, arg);\n"
} |
| 35/3 | 2026/10/05 10:32 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 47400 output: 34 thoughts: 336 Thoughts: **Analyzing Potential KMSAN/KASAN Issues in `blkdev_common_ioctl` and `zloop_rw`** Okay, so `blkdev_common_ioctl` is called by both the 32-bit compatibility and 64-bit ioctl paths, which is important for understanding potential issues. The structure `blk_storage_element` uses fixed-width types: `__u32`, `__u64`, and `__u8`. That's good from a portability standpoint. I'm focusing on amd64 here, so the important thing is that the alignment is identical between 32-bit and 64-bit on x86, even if there's a difference between how the `__u64` is handled. Specifically for amd64, this makes things less likely to be problematic. Now, let's look at `zloop_rw` – that's often where the interesting interactions happen. I see a call to `zloop_zone_healthy` within it. If that returns false, the code jumps to `out`, setting `cmd->ret = -EIO`. That seems straightforward. I need to go look at `zloop_rw` in `drivers/block/zloop.c` to understand the flow and the implications of `zloop_zone_healthy` returning false. It's probably the key to understanding if there's a problem here. |
| 36/3 | 2026/10/05 10:32 | tool | grepper |
0mArgs:{
"Expression": "static void zloop_rw",
"PathPrefix": "drivers/block/zloop.c"
}Results: {
"Output": "drivers/block/zloop.c=596=static void zloop_put_cmd(struct zloop_cmd *cmd)\n--\ndrivers/block/zloop.c-607-\ndrivers/block/zloop.c:608:static void zloop_rw_complete(struct kiocb *iocb, long ret)\ndrivers/block/zloop.c-609-{\n--\ndrivers/block/zloop.c=669=static int zloop_seq_write_prep(struct zloop_cmd *cmd)\n--\ndrivers/block/zloop.c-729-\ndrivers/block/zloop.c:730:static void zloop_rw(struct zloop_cmd *cmd)\ndrivers/block/zloop.c-731-{\n"
} |
| 37/3 | 2026/10/05 10:32 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 48278 output: 36 thoughts: 20 Thoughts: Okay, let's dive into this. I'm going to focus specifically on lines 730-780 of `zloop_rw`. I need to understand this section within the broader context of the read/write loop's behavior. I anticipate this range probably deals with a specific edge case or optimization within the read/write process. Knowing this library, it's likely something related to buffer management, error handling, or perhaps a particular strategy for handling partial reads or writes. My goal here isn't just to parrot the code, but to build a mental model of *why* this section exists and how it influences the overall performance and reliability of the loop. I'll be looking for any hints about concurrency, potential race conditions, or lock management if they are present. Essentially, I'm aiming to identify this segment's role in the bigger read/write picture, and its relation to the overall performance of the zloop library. |
| 38/3 | 2026/10/05 10:32 | tool | read-file |
0mArgs:{
"File": "drivers/block/zloop.c",
"FirstLine": 730,
"LineCount": 50
}Results: {
"Contents": " 730:\tstatic void zloop_rw(struct zloop_cmd *cmd)\n 731:\t{\n 732:\t\tstruct request *rq = blk_mq_rq_from_pdu(cmd);\n 733:\t\tstruct zloop_device *zlo = rq-\u003eq-\u003equeuedata;\n 734:\t\tunsigned int zone_no = rq_zone_no(rq);\n 735:\t\tsector_t nr_sectors = blk_rq_sectors(rq);\n 736:\t\tbool is_append = req_op(rq) == REQ_OP_ZONE_APPEND;\n 737:\t\tbool is_write = req_op(rq) == REQ_OP_WRITE || is_append;\n 738:\t\tstruct zloop_zone *zone;\n 739:\t\tint ret = -EIO;\n 740:\t\n 741:\t\tatomic_set(\u0026cmd-\u003eref, 2);\n 742:\t\tcmd-\u003esector = blk_rq_pos(rq);\n 743:\t\tcmd-\u003enr_sectors = nr_sectors;\n 744:\t\tcmd-\u003eret = 0;\n 745:\t\n 746:\t\tif (WARN_ON_ONCE(is_append \u0026\u0026 !zlo-\u003ezone_append))\n 747:\t\t\tgoto out;\n 748:\t\n 749:\t\t/* We should never get an I/O beyond the device capacity. */\n 750:\t\tif (WARN_ON_ONCE(zone_no \u003e= zlo-\u003enr_zones))\n 751:\t\t\tgoto out;\n 752:\t\n 753:\t\tzone = \u0026zlo-\u003ezones[zone_no];\n 754:\t\n 755:\t\t/*\n 756:\t\t * The block layer should never send requests that are not fully\n 757:\t\t * contained within the zone.\n 758:\t\t */\n 759:\t\tif (WARN_ON_ONCE(cmd-\u003esector + nr_sectors \u003e\n 760:\t\t\t\t zone-\u003estart + zlo-\u003ezone_size))\n 761:\t\t\tgoto out;\n 762:\t\n 763:\t\tif (!zloop_zone_healthy(zlo, zone, is_write))\n 764:\t\t\tgoto out;\n 765:\t\n 766:\t\tif (test_and_clear_bit(ZLOOP_ZONE_SEQ_ERROR, \u0026zone-\u003eflags)) {\n 767:\t\t\tmutex_lock(\u0026zone-\u003elock);\n 768:\t\t\tret = zloop_update_seq_zone(zlo, zone_no);\n 769:\t\t\tmutex_unlock(\u0026zone-\u003elock);\n 770:\t\t\tif (ret)\n 771:\t\t\t\tgoto out;\n 772:\t\t}\n 773:\t\n 774:\t\tif (!test_bit(ZLOOP_ZONE_CONV, \u0026zone-\u003eflags) \u0026\u0026 is_write) {\n 775:\t\t\tmutex_lock(\u0026zone-\u003elock);\n 776:\t\t\tret = zloop_seq_write_prep(cmd);\n 777:\t\t\tif (!ret)\n 778:\t\t\t\tret = zloop_do_rw(cmd);\n 779:\t\t\tmutex_unlock(\u0026zone-\u003elock);\n"
} |
| 39/3 | 2026/10/05 10:32 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 49356 output: 36 thoughts: 66 Thoughts: Here's my analysis of the provided code snippet: **Diving into Error Handling and Zone Health Checks** Okay, so I see a `ret = -EIO;` assignment on line 739. That's a classic I/O error indication – a pretty standard starting point for handling some kind of problem. Makes sense, assuming something has gone wrong early in the process. I always like to have a defined failure point. Then, on line 763, the code calls `zloop_zone_healthy`. This is critical. It's checking if a specific zone, probably within some storage loop (`zlo`), is, well, *healthy* before continuing. The `is_write` flag suggests this check might depend on whether a write operation is in progress. I need to understand what this health check entails. Is it disk checks, redundancy analysis, or something else entirely? A healthy zone is crucial for data integrity and performance; failing this check is obviously a problem. The `if` statement's `goto out;` jump is the interesting part here. So, if the zone *isn't* healthy, the code jumps to the `out` label. Now, I have to figure out what happens at `out`. What's the error handling there? Is it a graceful exit, retry logic, or an immediate panic? I need to analyze this `out` section carefully. This `goto` suggests that's where the error cleanup and return happen, which means I should look at the code there to figure out how this is handled and how to deal with this state. I need to trace the error flow to confirm my suspicions and to identify possible areas for optimization or deeper analysis. |
| 40/3 | 2026/10/05 10:32 | tool | read-file |
0mArgs:{
"File": "drivers/block/zloop.c",
"FirstLine": 780,
"LineCount": 25
}Results: {
"Contents": " 780:\t\t} else {\n 781:\t\t\tret = zloop_do_rw(cmd);\n 782:\t\t}\n 783:\tout:\n 784:\t\tif (ret != -EIOCBQUEUED)\n 785:\t\t\tzloop_rw_complete(\u0026cmd-\u003eiocb, ret);\n 786:\t\tzloop_put_cmd(cmd);\n 787:\t}\n 788:\t\n 789:\tstatic inline bool zloop_zone_is_active(struct zloop_zone *zone)\n 790:\t{\n 791:\t\tswitch (zone-\u003econd) {\n 792:\t\tcase BLK_ZONE_COND_EXP_OPEN:\n 793:\t\tcase BLK_ZONE_COND_IMP_OPEN:\n 794:\t\tcase BLK_ZONE_COND_CLOSED:\n 795:\t\t\treturn true;\n 796:\t\tdefault:\n 797:\t\t\treturn false;\n 798:\t\t}\n 799:\t}\n 800:\t\n 801:\tstatic int zloop_record_safe_wps(struct zloop_device *zlo)\n 802:\t{\n 803:\t\tunsigned int i;\n 804:\t\tint ret;\n"
} |
| 41/3 | 2026/10/05 10:32 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 50158 output: 558 thoughts: 2459 Thoughts: **Memory Safety Analysis of Storage Element Management Patch** Okay, so I've got this patch that introduces storage element management IOCTLs for zoned block devices, including zloop emulation and sd_zbc SCSI support. I need to make sure this thing isn't going to introduce any nasty memory issues. First, `zloop_rw` completes the request with `-EIO`. I'm starting by looking very closely at the memory safety implications. I've broken this down methodically. I've carefully checked all the functions and data paths. `bdev_zone_is_offline` looks safe; just a read and compare, no worries about uninitialized memory there. `disk_wait_for_se_mgmt_completion` uses `kzalloc_objs` and `kfree` with a loop checking `e->status`, seems solid. Then, in `bdev_report_storage_elements`, args are validated, and the driver's `report_elements` function is called. The `blkdev_get_nr_storage_elements_ioctl` call looks okay, initializes the counter. `blkdev_report_storage_elements_ioctl` is the key, where things get tricky. We copy data from user space, allocate memory with `kzalloc_objs` (thankfully!), and then call `bdev_report_storage_elements`. Wait a minute... I think I see it! If the user provides a small buffer size (`rep.nr_elements = 1`) but the device has many storage elements (e.g., 10), `bdev_report_storage_elements` updates the number of elements to the actual device count (10), which is fine. But when it goes to copy the `elements` back to user space: ```c retc = copy_to_user(argp + sizeof(struct blk_storage_elements_report), elements, sizeof(struct blk_storage_element) * nr_elements); ``` We're copying 10 times the size of a `blk_storage_element` from `elements`, but `elements` was only allocated for ONE element! That's a classic heap out-of-bounds read. KASAN should catch that (specifically a `slab-out-of-bounds` read), but still, we need to be very clear about it. What if the user passes an element count that's *larger* than the actual device count? Let's say, the user passes 10, but the device only has 2 elements. In that case, `elements` is still allocated for 10 elements, all zeroed. The driver then updates `*nr_elements` to 2. We're still only copying 2 elements back, and those elements are all initialized, so that's actually fine. The same goes for the error path - the copy to user is skipped and then the memory is freed. I've also gone through `bdev_remove_storage_element`, `bdev_restore_storage_elements`, `zloop.c` and `sd_zbc.c`. The `zloop_create_storage_elements` uses `kzalloc_objs`, and every field is initialized. Also, `sd_zbc.c` allocates buffers using zero initialization too. There are also no potential uninitialized memory leaks anywhere. Now, I have to go through the checklist. Are we sending uninitialized memory to user space? Let's check it: 1. `put_user`: The `nr_elements` scalar is initialized on the stack, updated in `report_elements`. 2. `copy_to_user`: The `elements` buffer is allocated via `kzalloc_objs`. The `blk_storage_element` struct is packed and initialized and there is no padding that could cause problems. 3. `copy_to_user`: The `rep` struct comes from user space via `copy_from_user` and has its own `nr_elements` member updated with the correct value. The reserved field retains its original value. Are there conditional branches? No. The calculations, conditional logic, and other operations all depend on initialized variables. No uninitialized variables are involved in conditional branches or logic. Are there bounds checks? I've double-checked, and everything's good. So, the issue isn't really uninitialized memory, it's an out-of-bounds *read* in the heap if the device has more elements than requested. KASAN detects it. And the same with the `sd_zbc_report_storage_elements`. Thus: there are no uninitialized memory risks. The *primary* risks are *out-of-bounds* accesses, caught by |
| 42/3 | 2026/10/05 10:33 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch series introduces storage element management ioctls (BLKGETNRSTORELEMS, BLKREPORTSTORELEMS, BLKREMOVESTORELEM, BLKRESTORESTORELEMS) for zoned block devices, along with support in zloop and sd_zbc.\n\nAnalysis of memory safety risks:\n1. Kernel data sent to userspace:\n - In blkdev_get_nr_storage_elements_ioctl(), nr_elements is an unsigned int initialized to 0 and written via put_user().\n - In blkdev_report_storage_elements_ioctl(), the 'rep' header struct is initialized via copy_from_user() before being updated and copied back to userspace via copy_to_user().\n - The 'elements' array is allocated with kzalloc_objs(struct blk_storage_element, nr_elements), ensuring all allocated elements and fields are zero-initialized.\n - 'struct blk_storage_element' is 24 bytes long and naturally packed without any padding holes (u32 id, u32 paired_id, u64 nr_zones, u8 type, u8 status, u8 restore_allowed, u8 reserved[5]).\n2. KASAN vs KMSAN applicability:\n - A potential heap buffer overread exists in blkdev_report_storage_elements_ioctl(): if the driver's report_elements callback sets *nr_elements to the total number of elements on the device (which may exceed rep.nr_elements passed by the user and used for kzalloc_objs), copy_to_user() will read past the end of the allocated slab object. This is a slab-out-of-bounds access, which is explicitly detected by KASAN.\n - Similarly, in sd_zbc_report_storage_elements(), if the SCSI device reports a large nr_descs, reading past the 4096-byte kzalloc'd buffer is an out-of-bounds read caught by KASAN.\n - All buffers (in zloop, sd_zbc, and blk-zoned) are allocated with kzalloc/kzalloc_objs or explicitly memset/initialized before use. There are no uninitialized variables or struct padding copied to userspace or used in conditional branching.\n\nBecause all memory safety risks are out-of-bounds accesses covered by KASAN and there is no uninitialized memory usage, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch series introduces storage element management ioctls (BLKGETNRSTORELEMS, BLKREPORTSTORELEMS, BLKREMOVESTORELEM, BLKRESTORESTORELEMS) for zoned block devices, along with support in zloop and sd_zbc.\n\nAnalysis of memory safety risks:\n1. Kernel data sent to userspace:\n - In blkdev_get_nr_storage_elements_ioctl(), nr_elements is an unsigned int initialized to 0 and written via put_user().\n - In blkdev_report_storage_elements_ioctl(), the 'rep' header struct is initialized via copy_from_user() before being updated and copied back to userspace via copy_to_user().\n - The 'elements' array is allocated with kzalloc_objs(struct blk_storage_element, nr_elements), ensuring all allocated elements and fields are zero-initialized.\n - 'struct blk_storage_element' is 24 bytes long and naturally packed without any padding holes (u32 id, u32 paired_id, u64 nr_zones, u8 type, u8 status, u8 restore_allowed, u8 reserved[5]).\n2. KASAN vs KMSAN applicability:\n - A potential heap buffer overread exists in blkdev_report_storage_elements_ioctl(): if the driver's report_elements callback sets *nr_elements to the total number of elements on the device (which may exceed rep.nr_elements passed by the user and used for kzalloc_objs), copy_to_user() will read past the end of the allocated slab object. This is a slab-out-of-bounds access, which is explicitly detected by KASAN.\n - Similarly, in sd_zbc_report_storage_elements(), if the SCSI device reports a large nr_descs, reading past the 4096-byte kzalloc'd buffer is an out-of-bounds read caught by KASAN.\n - All buffers (in zloop, sd_zbc, and blk-zoned) are allocated with kzalloc/kzalloc_objs or explicitly memset/initialized before use. There are no uninitialized variables or struct padding copied to userspace or used in conditional branching.\n\nBecause all memory safety risks are out-of-bounds accesses covered by KASAN and there is no uninitialized memory usage, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|