nvme-multipath: revalidate zones for namespace heads
PATCH v2 1/1 nvme-multipath: revalidate zones for namespace heads
Zoned multipath namespace heads get BLK_FEAT_ZONED and their limits are refreshed from the paths, but the zone state for the head disk is never initialized. The previous nr_zones assignment only updated a single field and did not allocate or populate the block layer's per-zone state.
The failure was found with xfstests xfs/643 and xfs/646 on an NVMe ZNS multipath namespace. Tracing showed regular REQ_OP_WRITE I/O being submitted to sequential zones through the multipath head.
That leaves the head disk without valid zone condition information. Code using the head device, such as bdev_zone_is_seq(), can then treat a sequential zone as non-sequential and submit regular writes to it.
Add a small helper to run blk_revalidate_disk_zones() for a live zoned namespace head after the path limits have been committed and when a path becomes live. Return the error to the namespace update path, and keep the live path transition as a warning-only update. Drop the nr_zones copy, as blk_revalidate_disk_zones() updates it together with the rest of the zoned disk state.
---
Changes in v2:
- Move the xfstests xfs/643 and xfs/646 failure details to the commit message, as suggested by Damien.
- Add Reviewed-by tag from Damien.
Link to v1:
https://lore.kernel.org/all/[email protected]
drivers/nvme/host/core.c | 4 ++++ drivers/nvme/host/multipath.c | 24 ++++++++++++++++++++---- drivers/nvme/host/nvme.h | 9 +++++++++ 3 files changed, 33 insertions(+), 4 deletions(-)
drivers/nvme/host/core.c +4 -0
@@ -2589,11 +2589,15 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info) lim.max_write_streams = ns_lim->max_write_streams; lim.write_stream_granularity = ns_lim->write_stream_granularity; ret =queue_limits_commit_update (ns->head->disk->queue, &lim); +if (ret) + goto unfreeze_head_queue;set_capacity_and_notify (ns->head->disk,get_capacity (ns->disk));set_disk_ro (ns->head->disk,nvme_ns_is_readonly (ns, info));nvme_mpath_revalidate_paths (ns->head); + ret =nvme_mpath_revalidate_zones (ns->head); +unfreeze_head_queue:blk_mq_unfreeze_queue (ns->head->disk->queue, memflags); }
drivers/nvme/host/multipath.c +20 -4
@@ -285,6 +285,25 @@ void nvme_mpath_revalidate_paths(struct nvme_ns_head *head)kblockd_schedule_work (&head->requeue_work); } +#ifdef CONFIG_BLK_DEV_ZONED +int nvme_mpath_revalidate_zones (struct nvme_ns_head *head) +{ +struct gendisk *disk = head->disk; +int ret; + +if (!disk || !blk_queue_is_zoned (disk->queue) || + !test_bit (NVME_NSHEAD_DISK_LIVE , &head->flags)) +return 0 ; + + ret =blk_revalidate_disk_zones (disk); +if (ret) +dev_warn_ratelimited (disk_to_dev (disk), +"failed to revalidate zoned namespace head: %d\n" , + ret); +return ret; +} +#endif /* CONFIG_BLK_DEV_ZONED */ +static bool nvme_path_is_disabled (struct nvme_ns *ns) {enum nvme_ctrl_state state =nvme_ctrl_state (ns->ctrl);
@@ -812,6 +831,7 @@ static void nvme_mpath_set_live(struct nvme_ns *ns)mutex_unlock (&head->lock);synchronize_srcu (&head->srcu); +nvme_mpath_revalidate_zones (head);kblockd_schedule_work (&head->requeue_work); }
@@ -1368,10 +1388,6 @@ void nvme_mpath_add_disk(struct nvme_ns *ns, __le32 anagrpid)nvme_mpath_set_live (ns); } -#ifdef CONFIG_BLK_DEV_ZONED -if (blk_queue_is_zoned (ns->queue) && ns->head->disk) - ns->head->disk->nr_zones = ns->disk->nr_zones; -#endif }void nvme_mpath_remove_disk (struct nvme_ns_head *head)
drivers/nvme/host/nvme.h +9 -0
@@ -1181,6 +1181,15 @@ static inline bool nvme_mpath_queue_if_no_path(struct nvme_ns_head *head) }#endif /* CONFIG_NVME_MULTIPATH */ +#if defined(CONFIG_NVME_MULTIPATH ) && defined(CONFIG_BLK_DEV_ZONED ) +int nvme_mpath_revalidate_zones (struct nvme_ns_head *head); +#else +static inline int nvme_mpath_revalidate_zones (struct nvme_ns_head *head) +{ +return 0 ; +} +#endif +int nvme_ns_get_unique_id (struct nvme_ns *ns,u8 id[16 ],enum blk_unique_id type);
Signature · 1 line
2.25.1
Looks good:
Quoted 8 lines · Yao Sang
Zoned multipath namespace heads get
BLK_FEAT_ZONEDand their limits are refreshed from the paths, but the zone state for the head disk is never initialized. The previousnr_zonesassignment only updated a single field and did not allocate or populate the block layer's per-zone state.The failure was found with xfstests xfs/643 and xfs/646 on an NVMe ZNS multipath namespace. Tracing showed regular
REQ_OP_WRITEI/O being submitted to sequential zones through the multipath head.
Thanks, applied to nvme-7.3.
drivers/nvme/host/core.c static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info) · line 2601
Quoted 7 lines · Yao Sang
set_capacity_and_notify(ns->head->disk, get_capacity(ns->disk)); set_disk_ro(ns->head->disk, nvme_ns_is_readonly(ns, info)); nvme_mpath_revalidate_paths(ns->head);drivers/nvme/host/core.c +2
-0+ ret =nvme_mpath_revalidate_zones (ns->head); +unfreeze_head_queue:blk_mq_unfreeze_queue (ns->head->disk->queue, memflags);
Does the above nvme_mpath_revalidate_zones() submit I/O while the request queue is frozen? If so, is this guaranteed to trigger a deadlock? I'm wondering whether the above changes are the changes that introduced this syzbot report:
https://lore.kernel.org/linux-block/[email protected]/
From that report:
-> #2 (&q->limits_lock){+.+.}-{4:4}:
__mutex_lock_common kernel/locking/mutex.c:646 [inline]
__mutex_lock+0x197/0x15a0 kernel/locking/mutex.c:821
queue_limits_start_update include/linux/blkdev.h:1101 [inline]
disk_update_zone_resources block/blk-zoned.c:2067 [inline]
blk_revalidate_disk_zones+0xad9/0x12e0 block/blk-zoned.c:2375
nvme_mpath_revalidate_zones+0x106/0x1c0
drivers/nvme/host/multipath.c:301
nvme_update_ns_info+0x984/0x1200 drivers/nvme/host/core.c:2622
nvme_alloc_ns drivers/nvme/host/core.c:4284 [inline]
nvme_scan_ns+0x2563/0x3640 drivers/nvme/host/core.c:4471
async_run_entry_fn+0x9d/0x430 kernel/async.c:129
process_one_work kernel/workqueue.c:3399 [inline]
process_scheduled_works+0xc3d/0x1630 kernel/workqueue.c:3482
worker_thread+0xa47/0xfb0 kernel/workqueue.c:3563
kthread+0x38b/0x480 kernel/kthread.c:436
ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245Thanks,
Bart.
Hi Bart,
Thanks for pointing this out, and sorry for the regression.
I reproduced the lockdep warning and confirmed that Palla's fix resolves it in my tests:
https://lore.kernel.org/all/[email protected]/
Thanks,
Yao