From b1d1f6b1ee03285690f12c2ebf23616416e6d881 Mon Sep 17 00:00:00 2001 From: Christian Aurich Zanettini Martins Date: Fri, 30 Oct 2026 14:01:51 -0300 Subject: [PATCH 01/52] nvme-tcp: fix use-after-free in nvme_tcp_free_ctrl() nvme_tcp_free_ctrl() reads ctrl->ctrl.opts to know how many queue mutexes to destroy. When creating the controller fails, nvmf_create_ctrl() frees opts as soon as nvme_tcp_create_ctrl() returns, but a concurrent open of the character device can hold the last reference to the controller. With CONFIG_DEBUG_KOBJECT_RELEASE, which delays the release, every failed connect reads freed memory: BUG: KASAN: slab-use-after-free in nvme_tcp_free_ctrl+0x38b/0x430 Read of size 4 at addr ffff888005b93740 by task kworker/2:1/51 Keep the size of the queue array in the controller and use it instead. Fixes: 2eeeaa9c1ff0 ("nvme-tcp: Validate the queue state under the queue lock in the address attribute") Cc: stable@vger.kernel.org Reviewed-by: Nilay Shroff Signed-off-by: Christian Aurich Zanettini Martins Signed-off-by: Keith Busch --- drivers/nvme/host/tcp.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index bc46e5f3eaa7..7ecc6c007f8d 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -199,6 +199,7 @@ struct nvme_tcp_ctrl { struct delayed_work connect_work; struct nvme_tcp_request async_req; u32 io_queues[HCTX_MAX_TYPES]; + unsigned int nr_allocated_queues; struct net *net; }; @@ -2848,8 +2849,6 @@ static void nvme_tcp_stop_ctrl(struct nvme_ctrl *ctrl) static void nvme_tcp_free_ctrl(struct nvme_ctrl *nctrl) { struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl); - /* the same count used to size and initialize the queue array */ - unsigned int nr_queues = NVME_TCP_OPT_NR_QUEUES(nctrl->opts); unsigned int i; if (list_empty_careful(&ctrl->list)) @@ -2862,7 +2861,7 @@ static void nvme_tcp_free_ctrl(struct nvme_ctrl *nctrl) nvmf_free_options(nctrl->opts); free_ctrl: put_net(ctrl->net); - for (i = 0; i < nr_queues; i++) + for (i = 0; i < ctrl->nr_allocated_queues; i++) nvme_tcp_exit_queue(ctrl, i); kfree(ctrl->queues); kfree(ctrl); @@ -3256,13 +3255,14 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(struct device *dev, goto out_free_ctrl; } - ctrl->queues = kzalloc_objs(*ctrl->queues, ctrl->ctrl.queue_count); + ctrl->nr_allocated_queues = ctrl->ctrl.queue_count; + ctrl->queues = kzalloc_objs(*ctrl->queues, ctrl->nr_allocated_queues); if (!ctrl->queues) { ret = -ENOMEM; goto out_free_ctrl; } - for (i = 0; i < ctrl->ctrl.queue_count; i++) + for (i = 0; i < ctrl->nr_allocated_queues; i++) nvme_tcp_init_queue(ctrl, i); ctrl->net = get_net(current->nsproxy->net_ns); From 3ee50a2d76f278ea0ced45716a62730059283787 Mon Sep 17 00:00:00 2001 From: Christian Aurich Zanettini Martins Date: Thu, 29 Oct 2026 11:19:57 -0300 Subject: [PATCH 02/52] nvme-rdma: fix NULL queue->ctrl dereference on reconnect Since commit 2a8513091d2f ("nvme-rdma: parallelize I/O queue allocation and startup"), a reconnect that gets more I/O queues than before grows the tag set before the new queues are set up. queue->ctrl is only set by nvme_rdma_setup_io_queues(), so I/O submitted in between reaches nvme_rdma_queue_rq() on a queue that was never allocated and dereferences a NULL queue->ctrl: BUG: kernel NULL pointer dereference, address: 000000000000034c RIP: 0010:nvme_rdma_queue_rq+0x52/0xb90 Set queue->ctrl for every queue when allocating the controller. Such requests are then requeued like on any other queue that is not live. Fixes: 2a8513091d2f ("nvme-rdma: parallelize I/O queue allocation and startup") Cc: stable@vger.kernel.org Reviewed-by: Nilay Shroff Signed-off-by: Christian Aurich Zanettini Martins Signed-off-by: Keith Busch --- drivers/nvme/host/rdma.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c index 07216890f75c..32189fdfc0f5 100644 --- a/drivers/nvme/host/rdma.c +++ b/drivers/nvme/host/rdma.c @@ -735,7 +735,6 @@ static int nvme_rdma_setup_io_queues(struct nvme_rdma_ctrl *ctrl, for (i = 0; i < nr_queues; i++) { struct nvme_rdma_queue *queue = &ctrl->queues[first + i]; - queue->ctrl = ctrl; queue->queue_size = queue_size; ctxs[i].queue = queue; @@ -798,7 +797,6 @@ static int nvme_rdma_configure_admin_queue(struct nvme_rdma_ctrl *ctrl, bool pi_capable = false; int error; - ctrl->queues[0].ctrl = ctrl; ctrl->queues[0].queue_size = NVME_AQ_DEPTH; error = nvme_rdma_alloc_queue(&ctrl->queues[0]); if (error) @@ -2284,7 +2282,7 @@ static struct nvme_rdma_ctrl *nvme_rdma_alloc_ctrl(struct device *dev, struct nvmf_ctrl_options *opts) { struct nvme_rdma_ctrl *ctrl; - int ret; + int ret, i; ctrl = kzalloc_obj(*ctrl); if (!ctrl) @@ -2343,6 +2341,9 @@ static struct nvme_rdma_ctrl *nvme_rdma_alloc_ctrl(struct device *dev, if (!ctrl->queues) goto out_free_ctrl; + for (i = 0; i < ctrl->ctrl.queue_count; i++) + ctrl->queues[i].ctrl = ctrl; + ret = nvme_init_ctrl(&ctrl->ctrl, dev, &nvme_rdma_ctrl_ops, 0 /* no quirks, we're perfect! */); if (ret) From a9d431124fb2e58215daf0299d6fcf47bbc2d6b1 Mon Sep 17 00:00:00 2001 From: Daejun Park Date: Thu, 29 Oct 2026 09:51:24 +0900 Subject: [PATCH 03/52] nvme: unregister when pr_register() is given a zero new key The block layer PR API defines a zero new_key in pr_register() as unregistering old_key. nvme_pr_register() sends Replace Reservation Key with a zero NRKEY instead. The host stays registered with key 0, and its next registration with another key fails with Reservation Conflict. The pNFS SCSI layout client unregisters this way at umount. A later mount cannot register and sends all I/O through the metadata server. Send Unregister Reservation Key when new_key is zero. Fixes: 1d277a637a71 ("NVMe: Add persistent reservation ops") Cc: stable@vger.kernel.org Reviewed-by: Christoph Hellwig Signed-off-by: Daejun Park Signed-off-by: Keith Busch --- drivers/nvme/host/pr.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/host/pr.c b/drivers/nvme/host/pr.c index fe7dbe264815..d8b6ac4d83bb 100644 --- a/drivers/nvme/host/pr.c +++ b/drivers/nvme/host/pr.c @@ -128,8 +128,12 @@ static int nvme_pr_register(struct block_device *bdev, u64 old_key, u64 new_key, data.crkey = cpu_to_le64(old_key); data.nrkey = cpu_to_le64(new_key); - cdw10 = old_key ? NVME_PR_REGISTER_ACT_REPLACE : - NVME_PR_REGISTER_ACT_REG; + if (!new_key) + cdw10 = NVME_PR_REGISTER_ACT_UNREG; + else if (old_key) + cdw10 = NVME_PR_REGISTER_ACT_REPLACE; + else + cdw10 = NVME_PR_REGISTER_ACT_REG; cdw10 |= (flags & PR_FL_IGNORE_KEY) ? NVME_PR_IGNORE_KEY : 0; cdw10 |= NVME_PR_CPTPL_PERSIST; From 7dfe79db5615df8d37ae7de6d3ec099b71bf3e03 Mon Sep 17 00:00:00 2001 From: Yuqiang Sun Date: Mon, 2 Nov 2026 17:50:15 +0800 Subject: [PATCH 04/52] nvme: Do not drop the cdev reference twice when cdev_device_add() fails Since commit 9952f3882ecb ("nvme: fix cdev lifetime"), nvme_add_ns_cdev() and nvme_add_ns_head_cdev() take a reference to the namespace (or namespace head) before calling nvme_cdev_add(), to be dropped by the char device's release, nvme_cdev_rel(), and drop it themselves when nvme_cdev_add() fails. But when cdev_device_add() fails, nvme_cdev_add() has already put the device, and nvme_cdev_rel() has already dropped that reference: the caller drops it a second time. With one allocation failure injected into cdev_device_add() for a namespace on an NVMe over loop controller, deleting the controller gives, with native multipath: BUG: KASAN: slab-use-after-free in nvme_put_ns_head+0x21/0x140 Write of size 4 at addr ff1100000a4ea078 by task init/1 nvme_put_ns_head nvme_put_ns nvme_remove_namespaces nvme_do_delete_ctrl nvme_delete_ctrl_sync nvme_sysfs_delete Freed by task 1: kfree nvme_ns_remove nvme_remove_namespaces refcount_t: underflow; use-after-free. Take the reference in nvme_cdev_add() instead, right before cdev_device_add(), and let the callers neither take nor drop it. Add nvme_is_ns_cdev() for the check that nvme_cdev_rel() and nvme_cdev_add() now share. Fixes: 9952f3882ecb ("nvme: fix cdev lifetime") Cc: stable@vger.kernel.org Reviewed-by: John Garry Signed-off-by: Yuqiang Sun Signed-off-by: Keith Busch --- drivers/nvme/host/core.c | 18 +++++++++++++++--- drivers/nvme/host/multipath.c | 2 -- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index af71d02b8476..9ea9db0271c2 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -3941,10 +3941,16 @@ static int nvme_subsys_check_duplicate_ids(struct nvme_subsystem *subsys, return 0; } +/* The char device of a namespace rather than of a namespace head */ +static bool nvme_is_ns_cdev(struct device *dev) +{ + return dev->parent->class == &nvme_class; +} + static void nvme_cdev_rel(struct device *dev) { ida_free(&nvme_ns_chr_minor_ida, MINOR(dev->devt)); - if (dev->parent->class == &nvme_class) + if (nvme_is_ns_cdev(dev)) nvme_put_ns(container_of(dev, struct nvme_ns, cdev_device)); else nvme_put_ns_head(container_of(dev, struct nvme_ns_head, @@ -3978,6 +3984,14 @@ int nvme_cdev_add(struct cdev *cdev, struct device *cdev_device, device_initialize(cdev_device); cdev_init(cdev, fops); cdev->owner = owner; + /* Undone in nvme_cdev_rel() */ + if (nvme_is_ns_cdev(cdev_device)) + nvme_get_ns(container_of(cdev_device, struct nvme_ns, + cdev_device)); + else + nvme_get_ns_head(container_of(cdev_device, + struct nvme_ns_head, + cdev_device)); ret = cdev_device_add(cdev, cdev_device); if (ret) put_device(cdev_device); @@ -4010,13 +4024,11 @@ static void nvme_add_ns_cdev(struct nvme_ns *ns) { ns->cdev_device.parent = ns->ctrl->device; - nvme_get_ns(ns); /* Undone in nvme_cdev_rel() */ if (nvme_cdev_add(&ns->cdev, &ns->cdev_device, &nvme_ns_chr_fops, ns->ctrl->ops->module, ns->ctrl->instance, ns->head->instance)) { dev_err(ns->ctrl->device, "Unable to create the ng%dn%d device\n", ns->ctrl->instance, ns->head->instance); - nvme_put_ns(ns); return; } set_bit(NVME_NS_CDEV_LIVE, &ns->flags); diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c index 9e0a0fd77c56..ae8059366b57 100644 --- a/drivers/nvme/host/multipath.c +++ b/drivers/nvme/host/multipath.c @@ -681,14 +681,12 @@ static void nvme_add_ns_head_cdev(struct nvme_ns_head *head) { head->cdev_device.parent = &head->subsys->dev; - nvme_get_ns_head(head); /* Undone in nvme_cdev_rel() */ if (nvme_cdev_add(&head->cdev, &head->cdev_device, &nvme_ns_head_chr_fops, THIS_MODULE, head->subsys->instance, head->instance)) { dev_err(disk_to_dev(head->disk), "Unable to create the ng%dn%d device\n", head->subsys->instance, head->instance); - nvme_put_ns_head(head); return; } set_bit(NVME_NSHEAD_CDEV_LIVE, &head->flags); From e67cb6ed40e7f45912b63d7d575f18dfd2ebc98a Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Thu, 29 Oct 2026 20:01:10 +0000 Subject: [PATCH 05/52] blk-mq: end the request if getting a keyslot fails When blk_crypto_rq_get_keyslot() fails, blk_mq_submit_bio() ends the bio by hand and frees the request. By then blk_mq_bio_to_request() has done the IO accounting, which blk_mq_free_request() doesn't undo, so the in_flight counter never drops and iostat shows a device that is 100% busy. If the bio went through zone write plugging the zone stays plugged as well, and every later write to it waits forever. Use blk_mq_end_request() like the dispatch path does for a request the driver rejected, after marking it for zone write plugging. Move the call to blk_zone_write_plug_init_request() before blk_crypto_rq_get_keyslot() so that it doesn't need to be duplicated. It doesn't depend on the keyslot. Fixes: 99dc422335d8 ("block: support to account io_ticks precisely") Fixes: dd291d77cc90 ("block: Introduce zone write plugging") Cc: stable@vger.kernel.org Signed-off-by: Josef Bacik Signed-off-by: Eric Biggers Reviewed-by: Christoph Hellwig Link: https://patch.msgid.link/20261029200110.1328103-1-ebiggers@kernel.org Signed-off-by: Jens Axboe --- block/blk-mq.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index d9ab295be4d9..e5b9898cede9 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3209,16 +3209,15 @@ new_request: blk_mq_bio_to_request(rq, bio, nr_segs); - ret = blk_crypto_rq_get_keyslot(rq); - if (ret != BLK_STS_OK) { - bio_endio_status(bio, ret); - blk_mq_free_request(rq); - return; - } - if (bio_zone_write_plugging(bio)) blk_zone_write_plug_init_request(rq); + ret = blk_crypto_rq_get_keyslot(rq); + if (ret != BLK_STS_OK) { + blk_mq_end_request(rq, ret); + return; + } + if (op_is_flush(bio->bi_opf) && blk_insert_flush(rq)) return; From 5a4236bf22622c291a96c139bfe54117f4cf1af6 Mon Sep 17 00:00:00 2001 From: "Baek Kyu, Kim" Date: Mon, 26 Oct 2026 01:11:33 +0900 Subject: [PATCH 06/52] null_blk: reset cache state before device setup The CACHE flag belongs to nullb_device, which outlives each powered-on nullb instance. Power-off discards the runtime cache but leaves the flag set. If cache_size changes from 1 to 0 before the next power-on, the queue advertises write-through while new page writes still go into the cache tree. A completed write can then disappear at the next power-off. Clear CACHE before creating the new instance. The existing cache_size setup sets it again when the new instance needs a cache. Signed-off-by: Baek Kyu, Kim Reviewed-by: Christoph Hellwig Link: https://patch.msgid.link/20261025161133.59344-1-pocj8ur4in@gmail.com Signed-off-by: Jens Axboe --- drivers/block/null_blk/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c index 6beb1f5b71ac..ec0d7ba4d938 100644 --- a/drivers/block/null_blk/main.c +++ b/drivers/block/null_blk/main.c @@ -1976,6 +1976,7 @@ static int null_add_dev(struct nullb_device *dev) rv = null_validate_conf(dev); if (rv) return rv; + clear_bit(NULLB_DEV_FL_CACHE, &dev->flags); nullb = kzalloc_node(sizeof(*nullb), GFP_KERNEL, dev->home_node); if (!nullb) { From 6c6dec7883f8eb10b326bc9d109a4990c885d949 Mon Sep 17 00:00:00 2001 From: Cong Zhang Date: Tue, 3 Nov 2026 18:32:21 +0800 Subject: [PATCH 07/52] virtio_blk: use synchronous quiesce in virtblk_freeze_priv() blk_mq_run_work_fn() can call blk_mq_sched_dispatch_requests() through blk_mq_run_dispatch_ops(). The dispatcher checks QUEUE_FLAG_QUIESCED while the flag is clear. It can then be preempted before it gets a request. At that time, it has no queue usage reference, so blk_mq_freeze_queue() does not wait for it. virtblk_freeze_priv() then calls blk_mq_quiesce_queue_nowait() and blk_mq_unfreeze_queue(). A new request can enter the queue. The old dispatcher can run again, use its old flag check, get the new request, and call virtio_queue_rq(). At the same time, virtblk_freeze_priv() can reset the device, delete the virtqueues, and free vblk->vqs. The old dispatcher can then use a deleted virtqueue or a NULL vblk->vqs, and the kernel can crash. Fix this by using blk_mq_quiesce_queue(), which waits for dispatch code that was already running. Keep the existing freeze and unfreeze order. The queue remains quiesced until virtblk_restore_priv() calls blk_mq_unquiesce_queue(). Fixes: 7678abee0867 ("virtio-blk: don't keep queue frozen during system suspend") Cc: stable@vger.kernel.org Acked-by: Jason Wang Reviewed-by: Stefan Hajnoczi Signed-off-by: Cong Zhang Link: https://lore.kernel.org/20260911-virtblk_sync_quiesce-v1-1-a883f8f31258@oss.qualcomm.com Link: https://patch.msgid.link/20261103-virtblk_sync_quiesce-v3-1-f40233f9bdd9@oss.qualcomm.com Signed-off-by: Jens Axboe --- drivers/block/virtio_blk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index c8bfbf8435ac..10ba8b0b863b 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -1596,7 +1596,7 @@ static int virtblk_freeze_priv(struct virtio_device *vdev) /* Ensure no requests in virtqueues before deleting vqs. */ memflags = blk_mq_freeze_queue(q); - blk_mq_quiesce_queue_nowait(q); + blk_mq_quiesce_queue(q); blk_mq_unfreeze_queue(q, memflags); /* Ensure we don't receive any more interrupts */ From 57cd1a08717690e5ea01d7ac7a96bb33a2dca117 Mon Sep 17 00:00:00 2001 From: Hungyu Lin Date: Fri, 23 Oct 2026 15:36:45 +0000 Subject: [PATCH 08/52] block: Return the soft block size for compat BLKBSZGET BLKBSZGET returns the block device's soft block size, while BLKSSZGET returns its logical sector size. The compat BLKBSZGET_32 handler uses bdev_logical_block_size(), so it returns the wrong value when these sizes differ. For example, on an x86_64 kernel a native query of a RAM or loop device with 512-byte logical sectors returns the initial soft block size of 4096 bytes, but an i386 process gets 512 bytes. This makes 32-bit blockdev --getbsz and the BSZ column of --report disagree with native queries, even without a preceding BLKBSZSET. Use block_size() as the native handler and the pre-regression compat handler do, and correct the case comment to describe the soft size. Fixes: 9b81648cb5e3 ("compat_ioctl: simplify up block/ioctl.c") Cc: stable@vger.kernel.org Signed-off-by: Hungyu Lin Reviewed-by: Christoph Hellwig Reviewed-by: Arnd Bergmann Link: https://patch.msgid.link/20261023153645.37546-1-dennylin0707@gmail.com Signed-off-by: Jens Axboe --- block/ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/ioctl.c b/block/ioctl.c index 64b4e6c0f696..fb2f4b4d2505 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -835,8 +835,8 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) return compat_put_ulong(argp, bdev_nr_sectors(bdev)); /* The data is compatible, but the command number is different */ - case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */ - return put_int(argp, bdev_logical_block_size(bdev)); + case BLKBSZGET_32: /* get the soft block size (cf. BLKSSZGET) */ + return put_int(argp, block_size(bdev)); case BLKBSZSET_32: return blkdev_bszset(file, mode, argp); case BLKGETSIZE64_32: From 3a9892bca4dd0182db61702e131cad569b1d71e6 Mon Sep 17 00:00:00 2001 From: Jianan Huang Date: Fri, 23 Oct 2026 17:26:11 +0800 Subject: [PATCH 09/52] blk-mq: reset queue state on scheduler teardown We observed I/O timeouts with requests stalled in per-CPU software queues. The affected queue had no elevator, but QUEUE_FLAG_SQ_SCHED remained set. A failed elevator switch can leave this state when falling back to none without clearing the flag. With empty hctx dispatch lists, a queue-wide restart on CPU4 would skip requests pending in ctx5/ctx7: CPU4: blk_mq_run_hw_queues(q) sq_hctx = hctx4 hctx4: no pending requests -> selected hctx5: 9 reads in ctx5 -> skipped hctx7: 3 writes in ctx7 -> skipped The pending requests may remain undispatched until another event runs their hardware queues. Clear the flag and restore nr_requests and async_depth to the driver queue depth in the common scheduler teardown path, covering both scheduler exit and failed initialization. Fixes: 4d337cebcb1c ("blk-mq: avoid to touch q->elevator without any protection") Assisted-by: LLM Signed-off-by: Jianan Huang Reviewed-by: Christoph Hellwig Link: https://patch.msgid.link/20261023092611.116795-1-jnhuang95@gmail.com Signed-off-by: Jens Axboe --- block/blk-mq-sched.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/block/blk-mq-sched.c b/block/blk-mq-sched.c index 0a00f5a76f5a..d7b45778732b 100644 --- a/block/blk-mq-sched.c +++ b/block/blk-mq-sched.c @@ -374,7 +374,7 @@ bool blk_mq_sched_try_insert_merge(struct request_queue *q, struct request *rq, } EXPORT_SYMBOL_GPL(blk_mq_sched_try_insert_merge); -/* called in queue's release handler, tagset has gone away */ +/* Clear scheduler tags and reset queue state. */ static void blk_mq_sched_tags_teardown(struct request_queue *q, unsigned int flags) { struct blk_mq_hw_ctx *hctx; @@ -385,6 +385,10 @@ static void blk_mq_sched_tags_teardown(struct request_queue *q, unsigned int fla if (blk_mq_is_shared_tags(flags)) q->sched_shared_tags = NULL; + + blk_queue_flag_clear(QUEUE_FLAG_SQ_SCHED, q); + q->nr_requests = q->tag_set->queue_depth; + q->async_depth = q->tag_set->queue_depth; } void blk_mq_sched_reg_debugfs(struct request_queue *q) From 08a6572441a4e646c96c2b8d8ead9eea0e458332 Mon Sep 17 00:00:00 2001 From: Shao Mingyin Date: Mon, 26 Oct 2026 19:55:19 +0800 Subject: [PATCH 10/52] virtio-blk: Fix zone append sector reporting in batched completion For zone append, the block layer copies req->__sector back into the bio in blk_zone_append_update_request_bio(), so the driver must update req->__sector with the sector reported by the device. virtblk_request_done() does that, but the batched completion path used by virtblk_poll() only unmaps and cleans up the requests before calling blk_mq_end_request_batch(). A zone append completed through polling therefore keeps the sector that was assigned at submission time, and the file system or application sees the wrong LBA for the written data. Move the sector update into a helper and call it from both completion paths. Fixes: 95bfec41bd3d ("virtio-blk: add support for zoned block devices") Signed-off-by: Shao Mingyin Acked-by: Michael S. Tsirkin Reviewed-by: Stefan Hajnoczi Reviewed-by: Christoph Hellwig Link: https://patch.msgid.link/202610261955196384aSLGuy3_0MiTvlYXVdiC@zte.com.cn Signed-off-by: Jens Axboe --- drivers/block/virtio_blk.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 10ba8b0b863b..9e152acd69ad 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -331,18 +331,25 @@ static inline u8 virtblk_vbr_status(struct virtblk_req *vbr) return *((u8 *)&vbr->in_hdr + vbr->in_hdr_len - 1); } -static inline void virtblk_request_done(struct request *req) +static inline void virtblk_update_zone_append_sector(struct request *req, + struct virtblk_req *vbr) { - struct virtblk_req *vbr = blk_mq_rq_to_pdu(req); - blk_status_t status = virtblk_result(virtblk_vbr_status(vbr)); struct virtio_blk *vblk = req->mq_hctx->queue->queuedata; - virtblk_unmap_data(req, vbr); - virtblk_cleanup_cmd(req); - if (req_op(req) == REQ_OP_ZONE_APPEND) req->__sector = virtio64_to_cpu(vblk->vdev, vbr->in_hdr.zone_append.sector); +} + +static inline void virtblk_request_done(struct request *req) +{ + struct virtblk_req *vbr = blk_mq_rq_to_pdu(req); + blk_status_t status = virtblk_result(virtblk_vbr_status(vbr)); + + virtblk_unmap_data(req, vbr); + virtblk_cleanup_cmd(req); + + virtblk_update_zone_append_sector(req, vbr); blk_mq_end_request(req, status); } @@ -1196,8 +1203,11 @@ static void virtblk_complete_batch(struct io_comp_batch *iob) struct request *req; rq_list_for_each(&iob->req_list, req) { - virtblk_unmap_data(req, blk_mq_rq_to_pdu(req)); + struct virtblk_req *vbr = blk_mq_rq_to_pdu(req); + + virtblk_unmap_data(req, vbr); virtblk_cleanup_cmd(req); + virtblk_update_zone_append_sector(req, vbr); } blk_mq_end_request_batch(iob); } From 7e3801d12ebabaa3db6e2685ccc80b6e6f6d1ff7 Mon Sep 17 00:00:00 2001 From: Zizhi Wo Date: Mon, 2 Nov 2026 16:04:42 +0800 Subject: [PATCH 11/52] block: partitions: reject GPT entries with starting_lba > ending_lba A GPT entry whose starting_lba is greater than its ending_lba is accepted, and the kernel creates a partition with a bogus size. The bogus sector count defeats the end-of-device check, so I/O through that partition is not confined to it and can access sectors outside the partition on the same disk. is_pte_valid() only rejects an entry when its type is NULL or when starting_lba or ending_lba is greater than lastlba; it never checks that starting_lba <= ending_lba. For a reversed entry both field checks still pass, but efi_partition() computes size = ending_lba - starting_lba + 1 in u64, which underflows to a huge value. That value also wraps in the end-of-device check in blk_add_partition() (from + size) and does not fit the signed i_size, which turns negative. Reject entries with starting_lba > ending_lba in is_pte_valid(), matching the head-level check against last_usable_lba < first_usable_lba. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Zizhi Wo Reviewed-by: Christoph Hellwig Link: https://patch.msgid.link/20261102080442.3775061-1-wozizhi@huaweicloud.com Signed-off-by: Jens Axboe --- block/partitions/efi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/partitions/efi.c b/block/partitions/efi.c index 9865d59093fa..b31227a13db0 100644 --- a/block/partitions/efi.c +++ b/block/partitions/efi.c @@ -460,6 +460,7 @@ static inline int is_pte_valid(const gpt_entry *pte, const u64 lastlba) { if ((!efi_guidcmp(pte->partition_type_guid, NULL_GUID)) || + le64_to_cpu(pte->starting_lba) > le64_to_cpu(pte->ending_lba) || le64_to_cpu(pte->starting_lba) > lastlba || le64_to_cpu(pte->ending_lba) > lastlba) return 0; From d734b6433b2fd248bc25a2ea1fa60c34b40ba15c Mon Sep 17 00:00:00 2001 From: Kyle Bader Date: Thu, 29 Oct 2026 15:58:21 +0000 Subject: [PATCH 12/52] block: only fail dma-buf bios that need block layer PI All dma-buf (P2P) I/O to a device with integrity data is rejected today, at registration and in blk_mq_submit_bio(). Only a bio for which the block layer generates or verifies PI needs that. The block layer then walks the bio_vecs, and a dma-buf bio has none. Reject only those bios, and remove the check at registration. Then a submitter that attaches its own PI, for example with IORING_RW_ATTR_FLAG_PI, can do dma-buf I/O to such a device. Link: https://lore.kernel.org/all/bbb87d6b-b7a3-487a-8be4-27f3f9ce4a1b@samsung.com/ Assisted-by: LLM Reviewed-by: Anuj Gupta Signed-off-by: Kyle Bader Reviewed-by: Christoph Hellwig Reviewed-by: Pavel Begunkov Link: https://patch.msgid.link/20261029155821.2983229-1-kbader@redhat.com Signed-off-by: Jens Axboe --- block/blk-mq.c | 9 ++++++++- block/fops.c | 2 -- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index e5b9898cede9..8512c643afbb 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3160,8 +3160,15 @@ void blk_mq_submit_bio(struct bio *bio) goto queue_exit; } + /* + * The block layer cannot generate or verify PI for a dma-buf bio, as + * that walks the data pages. Only fail the bio if it needs that, not + * if the submitter attached its own integrity payload or if PI + * generation or verification is turned off for the device. + */ if (unlikely(op_is_dmabuf(bio->bi_opf) && - bdev_has_integrity_csum(bio->bi_bdev))) { + bdev_has_integrity_csum(bio->bi_bdev) && + (bio_integrity_action(bio) & BI_ACT_CHECK))) { bio_endio_status(bio, BLK_STS_NOTSUPP); goto queue_exit; } diff --git a/block/fops.c b/block/fops.c index e5c27cc35ca1..a0ccadaa9c79 100644 --- a/block/fops.c +++ b/block/fops.c @@ -1018,8 +1018,6 @@ static int blkdev_init_dma_buf_io_ctx(struct file *file, return -EINVAL; if (!disk->fops->init_dma_buf_io_ctx) return -EOPNOTSUPP; - if (bdev_has_integrity_csum(bdev)) - return -EOPNOTSUPP; return disk->fops->init_dma_buf_io_ctx(bdev, ctx); } From 2516f0413f8704a7370ef8a2eeae26c9bc438978 Mon Sep 17 00:00:00 2001 From: Avi Weiss Date: Sat, 31 Oct 2026 12:20:24 +0200 Subject: [PATCH 13/52] block: report the correct discard alignment in sysfs disk_discard_alignment_show() reports the physical I/O alignment offset instead of the discard alignment. Devices can specify these offsets independently, so the discard_alignment sysfs attribute can report the wrong value. Use bdev_discard_alignment() for the whole-disk attribute, as is already done for partitions. Fixes: 4e1462ffe899 ("block: remove queue_discard_alignment") Signed-off-by: Avi Weiss Reviewed-by: Christoph Hellwig Link: https://patch.msgid.link/20261031102023.3644494-2-thnkslprpt@gmail.com Signed-off-by: Jens Axboe --- block/genhd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/genhd.c b/block/genhd.c index 10ca8b4d6eea..69204d44adae 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1146,7 +1146,7 @@ static ssize_t disk_discard_alignment_show(struct device *dev, { struct gendisk *disk = dev_to_disk(dev); - return sysfs_emit(buf, "%d\n", bdev_alignment_offset(disk->part0)); + return sysfs_emit(buf, "%u\n", bdev_discard_alignment(disk->part0)); } static ssize_t diskseq_show(struct device *dev, From 703f6aee8d8d1cb6227af56169be6b1dc4d3c4d5 Mon Sep 17 00:00:00 2001 From: Shao Mingyin Date: Sat, 31 Oct 2026 22:17:37 +0800 Subject: [PATCH 14/52] zloop: fix the error code in the blk_mq_alloc_disk message When blk_mq_alloc_disk() fails, "ret" still holds the zero returned by the preceding blk_mq_alloc_tag_set() call, so the error message always reports "err=0". Save PTR_ERR(zlo->disk) in "ret" before printing it, like the blk_mq_alloc_tag_set() and add_disk() failure paths do. Fixes: eb0570c7df23 ("block: new zoned loop block device driver") Signed-off-by: Shao Mingyin Reviewed-by: Christoph Hellwig Reviewed-by: Damien Le Moal Link: https://patch.msgid.link/20261031221737569WQ3bg8y80Ht7JdTCWwlkL@zte.com.cn Signed-off-by: Jens Axboe --- drivers/block/zloop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c index 65634a39b0bf..71612dbf8ccd 100644 --- a/drivers/block/zloop.c +++ b/drivers/block/zloop.c @@ -1339,8 +1339,8 @@ static int zloop_ctl_add(struct zloop_options *opts) zlo->disk = blk_mq_alloc_disk(&zlo->tag_set, &lim, zlo); if (IS_ERR(zlo->disk)) { - pr_err("blk_mq_alloc_disk failed (err=%d)\n", ret); ret = PTR_ERR(zlo->disk); + pr_err("blk_mq_alloc_disk failed (err=%d)\n", ret); goto out_cleanup_tags; } zlo->disk->flags = GENHD_FL_NO_PART; From 603523fd54664f17630f742229166278568c3ce8 Mon Sep 17 00:00:00 2001 From: Laveesh Bansal Date: Fri, 30 Oct 2026 21:41:41 -0700 Subject: [PATCH 15/52] block: only serialize elevator switches of the same queue Since commit 4ff58d6bc9dd ("block: serialize elevator changes for the same queue using a writer lock"), a write to queue/scheduler fails with -EBUSY whenever something else holds set->update_nr_hwq_lock. That commit takes the lock for write, and it has to be a trylock because of commit ce8ee8583ed8 ("block: use trylock to avoid lockdep circular dependency in sysfs"). The lock covers the whole tag set, so it is easy to hit. A scheduler write fails while another queue of the set is switching, or while a sibling disk of the same SCSI host or NVMe controller is added or removed. This matches the udev failures reported on 7.2. Go back to taking the lock for read. The write lock was there to keep two switches of one queue from overlapping in elevator_change_done(), which touches the elevator sysfs and debugfs entries outside of q->elevator_lock. Use QUEUE_FLAG_NO_ELV_SWITCH for that instead: a write sets it before elevator_change() and clears it afterwards, and a write that finds it set returns -EBUSY. Disk removal already sets the flag under the write lock, so no switch can start once it has run. Writes to the same queue, and writes that race with an nr_hw_queues update, an nr_requests write or disk removal, can still get -EBUSY, as with 4ff58d6bc9dd. A write to a disk that is being removed now gets -EBUSY instead of -ENOENT. Fixes: 4ff58d6bc9dd ("block: serialize elevator changes for the same queue using a writer lock") Cc: stable@vger.kernel.org # v7.2+ Reported-by: Reindl Harald Closes: https://lore.kernel.org/r/077dd42e-cbc9-4c23-a5ef-3d20e4fc7757@thelounge.net Suggested-by: Nilay Shroff Assisted-by: LLM Signed-off-by: Laveesh Bansal Reviewed-by: Nilay Shroff Link: https://patch.msgid.link/20261031044141.5569-1-laveeshb@laveeshbansal.com Signed-off-by: Jens Axboe --- block/elevator.c | 32 ++++++++++++++++++-------------- include/linux/blkdev.h | 4 +--- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/block/elevator.c b/block/elevator.c index 2161b6eea680..66edf1a5768a 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -812,25 +812,29 @@ ssize_t elv_iosched_store(struct gendisk *disk, const char *buf, * reference during concurrent disk deletion: * update_nr_hwq_lock -> kn->active (via del_gendisk -> kobject_del) * kn->active -> update_nr_hwq_lock (via this sysfs write path) - * - * Use the writer lock instead of the reader lock of update_nr_hwq_lock - * to serialize the two-stage elevator switch steps in - * elevator_change(): the core switch step under the elevator lock and - * the elevator_change_done() step outside the elevator lock. */ - if (!down_write_trylock(&set->update_nr_hwq_lock)) { + if (!down_read_trylock(&set->update_nr_hwq_lock)) { ret = -EBUSY; goto out; } - if (!blk_queue_no_elv_switch(q)) { - ret = elevator_change(q, &ctx); - if (!ret) - ret = count; - } else { - ret = -ENOENT; - } - up_write(&set->update_nr_hwq_lock); + /* + * The reader lock is shared, so use QUEUE_FLAG_NO_ELV_SWITCH to allow + * only one switch of this queue at a time, and none once the disk is + * going away. + */ + if (test_and_set_bit(QUEUE_FLAG_NO_ELV_SWITCH, &q->queue_flags)) { + ret = -EBUSY; + goto out_unlock; + } + + ret = elevator_change(q, &ctx); + if (!ret) + ret = count; + + blk_queue_flag_clear(QUEUE_FLAG_NO_ELV_SWITCH, q); +out_unlock: + up_read(&set->update_nr_hwq_lock); out: if (ctx.type) elevator_put(ctx.type); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 0c2010230632..215753171cef 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -678,7 +678,7 @@ enum { QUEUE_FLAG_HCTX_ACTIVE, /* at least one blk-mq hctx is active */ QUEUE_FLAG_SQ_SCHED, /* single queue style io dispatch */ QUEUE_FLAG_DISABLE_WBT_DEF, /* for sched to disable/enable wbt */ - QUEUE_FLAG_NO_ELV_SWITCH, /* can't switch elevator any more */ + QUEUE_FLAG_NO_ELV_SWITCH, /* a switch is running or disk is going away */ QUEUE_FLAG_QOS_ENABLED, /* qos is enabled */ QUEUE_FLAG_BIO_ISSUE_TIME, /* record bio->issue_time_ns */ QUEUE_FLAG_ZONED_QD1_WRITES, /* Limit zoned devices writes to QD=1 */ @@ -719,8 +719,6 @@ void blk_queue_flag_clear(unsigned int flag, struct request_queue *q); ((q)->limits.features & BLK_FEAT_SKIP_TAGSET_QUIESCE) #define blk_queue_disable_wbt(q) \ test_bit(QUEUE_FLAG_DISABLE_WBT_DEF, &(q)->queue_flags) -#define blk_queue_no_elv_switch(q) \ - test_bit(QUEUE_FLAG_NO_ELV_SWITCH, &(q)->queue_flags) #define blk_queue_zoned_qd1_writes(q) \ test_bit(QUEUE_FLAG_ZONED_QD1_WRITES, &(q)->queue_flags) From 09c2e203e0ea8b68e7c9500401fa0ab60baf1a9d Mon Sep 17 00:00:00 2001 From: Shao Mingyin Date: Sat, 31 Oct 2026 22:16:10 +0800 Subject: [PATCH 16/52] zloop: reject mismatched conventional zone files on restore When restoring a zloop device, zloop_init_zone() checks that the size of each conventional zone file matches the configured zone size. The check prints an error and then jumps to out_fput, which releases the zone file and returns the value left in "ret" by the preceding vfs_getattr() call, that is, zero. zloop_ctl_add() therefore treats the zone as initialized and continues with a zone->file pointer that was already released; any I/O to that zone then dereferences it. Return -EINVAL, like the sequential zone path does for the same kind of inconsistency. While at it, print the zone size that is actually compared instead of the zone capacity, which may be smaller and only made the message confusing. Fixes: eb0570c7df23 ("block: new zoned loop block device driver") Signed-off-by: Shao Mingyin Reviewed-by: Christoph Hellwig Reviewed-by: Damien Le Moal Link: https://patch.msgid.link/20261031221610676B5VoVcwMgkoDNVZH2bVDO@zte.com.cn Signed-off-by: Jens Axboe --- drivers/block/zloop.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c index 71612dbf8ccd..578a8a5cf1eb 100644 --- a/drivers/block/zloop.c +++ b/drivers/block/zloop.c @@ -1161,7 +1161,8 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts, if (restore && file_sectors != zlo->zone_size) { pr_err("Invalid conventional zone %u file size (%llu sectors != %llu)\n", - zone_no, file_sectors, zlo->zone_capacity); + zone_no, file_sectors, zlo->zone_size); + ret = -EINVAL; goto out_fput; } From 8fbee85a90789d367c347b1cfd5a5ef37f3a934a Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Mon, 2 Nov 2026 06:55:58 +0100 Subject: [PATCH 17/52] zloop: fix block size query The block size obviously needs to be queried when it is not set, not when it already is set. Reported: Damien Le Moal Fixes: 5e9929e2f03c ("zloop: share more code for opening a zone backing file") Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Link: https://patch.msgid.link/20261102055558.3212814-1-hch@lst.de Signed-off-by: Jens Axboe --- drivers/block/zloop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c index 578a8a5cf1eb..96666742523b 100644 --- a/drivers/block/zloop.c +++ b/drivers/block/zloop.c @@ -1137,7 +1137,7 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts, goto out_fput; } - if (zlo->block_size) { + if (!zlo->block_size) { ret = zloop_get_block_size(zlo, zone); if (ret) goto out_fput; From d53c1a12ff1cfdb12770ddcfdf5603915d0ba0d8 Mon Sep 17 00:00:00 2001 From: Yunye Zhao Date: Mon, 2 Nov 2026 21:37:40 +0800 Subject: [PATCH 18/52] virtio_blk: freeze the virtqueue layout at probe time init_vq() reads the writable num_request_queues and poll_queues module parameters both at probe and when recreating virtqueues after suspend or reset. However, virtio-blk does not update the blk-mq hardware queue count or queue maps on restore. Increasing poll_queues can therefore remove the completion callback from a virtqueue still used for interrupt-driven I/O, leaving requests uncompleted. Reducing the effective request queue count through num_request_queues can instead leave existing hardware contexts indexing beyond the reallocated vblk->vqs array. Determine the virtqueue count and the split between interrupt-driven and polling queues once at probe, and reuse this layout when recreating the virtqueues. Changes to these module parameters then affect only subsequently probed devices. Fixes: 0989c41bed96 ("virtio-blk: add num_request_queues module parameter") Signed-off-by: Yunye Zhao Reviewed-by: Stefan Hajnoczi Link: https://patch.msgid.link/20261102133740.88919-1-yunye.zhao@linux.alibaba.com Signed-off-by: Jens Axboe --- drivers/block/virtio_blk.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 9e152acd69ad..6568ee276329 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -965,16 +965,13 @@ static void virtblk_config_changed(struct virtio_device *vdev) queue_work(virtblk_wq, &vblk->config_work); } -static int init_vq(struct virtio_blk *vblk) +/* Keep the queue layout unchanged for the lifetime of the tag set. */ +static int virtblk_init_queue_layout(struct virtio_blk *vblk) { - int err; - unsigned short i; - struct virtqueue_info *vqs_info; - struct virtqueue **vqs; + struct virtio_device *vdev = vblk->vdev; unsigned short num_vqs; unsigned short num_poll_vqs; - struct virtio_device *vdev = vblk->vdev; - struct irq_affinity desc = { 0, }; + int err; err = virtio_cread_feature(vdev, VIRTIO_BLK_F_MQ, struct virtio_blk_config, num_queues, @@ -992,6 +989,7 @@ static int init_vq(struct virtio_blk *vblk) num_poll_vqs = min_t(unsigned int, poll_queues, num_vqs - 1); + vblk->num_vqs = num_vqs; vblk->io_queues[HCTX_TYPE_DEFAULT] = num_vqs - num_poll_vqs; vblk->io_queues[HCTX_TYPE_READ] = 0; vblk->io_queues[HCTX_TYPE_POLL] = num_poll_vqs; @@ -1001,6 +999,20 @@ static int init_vq(struct virtio_blk *vblk) vblk->io_queues[HCTX_TYPE_READ], vblk->io_queues[HCTX_TYPE_POLL]); + return 0; +} + +static int init_vq(struct virtio_blk *vblk) +{ + int err; + unsigned short i; + struct virtqueue_info *vqs_info; + struct virtqueue **vqs; + unsigned short num_vqs = vblk->num_vqs; + unsigned short num_poll_vqs = vblk->io_queues[HCTX_TYPE_POLL]; + struct virtio_device *vdev = vblk->vdev; + struct irq_affinity desc = { 0, }; + vblk->vqs = kmalloc_objs(*vblk->vqs, num_vqs); if (!vblk->vqs) return -ENOMEM; @@ -1032,7 +1044,6 @@ static int init_vq(struct virtio_blk *vblk) spin_lock_init(&vblk->vqs[i].lock); vblk->vqs[i].vq = vqs[i]; } - vblk->num_vqs = num_vqs; out: kfree(vqs); @@ -1480,6 +1491,10 @@ static int virtblk_probe(struct virtio_device *vdev) INIT_WORK(&vblk->config_work, virtblk_config_changed_work); + err = virtblk_init_queue_layout(vblk); + if (err) + goto out_free_vblk; + err = init_vq(vblk); if (err) goto out_free_vblk; From 894e4e6084924cfd590968d45fad20908e02ddae Mon Sep 17 00:00:00 2001 From: Krystian Kaniewski Date: Wed, 14 Oct 2026 19:05:36 +0200 Subject: [PATCH 19/52] blk-mq: fix out-of-bounds read in blk_mq_free_rqs A KASAN slab-out-of-bounds read can occur in blk_mq_free_rqs() when there is a mismatch between the number of hardware queues allocated for the IO scheduler (et->nr_hw_queues) and the number of hardware queues in the block tag set (set->nr_hw_queues). This mismatch can happen if blk_mq_update_nr_hw_queues() fails halfway through (e.g., due to memory pressure during blk_mq_prealloc_tag_set_tags()). In this error path, the elevator is restored with a larger number of hardware queues than the block tag set actually has. When the elevator is later freed, blk_mq_free_sched_tags() iterates up to the new et->nr_hw_queues and calls blk_mq_free_rqs(). In blk_mq_free_rqs(), it attempts to access set->tags[hctx_idx] to get the driver tags. Because set->nr_hw_queues was not updated due to the earlier failure, set->tags still has the old (smaller) size, leading to an out-of-bounds read. BUG: KASAN: slab-out-of-bounds in blk_mq_free_rqs+0xde/0x680 Read of size 8 at addr ffff88818d67fc28 by task syz-executor117/5839 Call Trace: blk_mq_free_rqs+0xde/0x680 blk_mq_free_map_and_rqs+0x40/0xf0 blk_mq_free_sched_tags blk_mq_free_sched_res+0xeb/0x280 elevator_change_done+0x1d2/0x5c0 elevator_change+0x34f/0x480 elv_iosched_store+0x504/0x630 queue_attr_store+0x207/0x2b0 To fix this, explicitly check if hctx_idx < set->nr_hw_queues before accessing set->tags[hctx_idx]. If hctx_idx >= set->nr_hw_queues, the hardware queue doesn't exist in the tag set, meaning there are no driver tags to clear mappings from. In this case, safely set drv_tags to NULL. The subsequent call to blk_mq_clear_rq_mapping() already handles a NULL drv_tags pointer and will safely return. Fixes: 04225d13aef1 ("block: fix potential deadlock while running nr_hw_queue update") Assisted-by: Gemini:gemini-3.5-flash Gemini:gemini-3.1-pro-preview syzbot Reported-by: syzbot+e90526cab23b9efcd03c@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=e90526cab23b9efcd03c Link: https://syzkaller.appspot.com/ai_job?id=827b5760-86a0-4f44-9c69-430b572eac12 Reviewed-by: Nilay Shorff Cc: stable@vger.kernel.org # 6.17+ Signed-off-by: Krystian Kaniewski Tested-by: syzbot@syzkaller.appspotmail.com Link: https://patch.msgid.link/20261014170538.1089448-1-krystianmkaniewski@gmail.com Signed-off-by: Jens Axboe --- block/blk-mq.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 8512c643afbb..5ae22d556540 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3507,8 +3507,10 @@ void blk_mq_free_rqs(struct blk_mq_tag_set *set, struct blk_mq_tags *tags, if (blk_mq_is_shared_tags(set->flags)) drv_tags = set->shared_tags; - else + else if (hctx_idx < set->nr_hw_queues) drv_tags = set->tags[hctx_idx]; + else + drv_tags = NULL; if (tags->static_rqs && set->ops->exit_request) { int i; From 6f2b59737bf9cf3623719857ac149f0d431db109 Mon Sep 17 00:00:00 2001 From: Niklas Cassel Date: Thu, 22 Oct 2026 11:22:00 +0200 Subject: [PATCH 20/52] null_blk: fix opening closed zones at the active zone limit When the open zone limit is reached, null_check_open() closes an implicitly open zone only if the active zone limit is not reached. Closing an implicitly open zone does not change the number of active zones, so this check is wrong. For an empty zone, the active zone limit was already checked by null_check_zone_resources(). For a closed zone, the check makes writing to, opening or finishing the zone fail with BLK_STS_ZONE_OPEN_RESOURCE at the active zone limit, whereas ZBC-3 (4.5.3.2.7.2) and NVMe ZNS (2.1.1.4.1) require closing an implicitly open zone instead. Remove the check, and update the comment above null_check_zone_resources() accordingly. Fixes: dc4d137ee3b7 ("null_blk: add support for max open/active zone limit for zoned devices") Reviewed-by: Damien Le Moal Signed-off-by: Niklas Cassel Link: https://patch.msgid.link/20261022092158.2248831-6-cassel@kernel.org Signed-off-by: Jens Axboe --- drivers/block/null_blk/zoned.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c index 7e9b5ffb9e84..ecdc8d68ca2a 100644 --- a/drivers/block/null_blk/zoned.c +++ b/drivers/block/null_blk/zoned.c @@ -311,10 +311,8 @@ static blk_status_t null_check_open(struct nullb_device *dev) return BLK_STS_OK; if (dev->nr_zones_imp_open) { - if (null_check_active(dev) == BLK_STS_OK) { - null_close_imp_open_zone(dev); - return BLK_STS_OK; - } + null_close_imp_open_zone(dev); + return BLK_STS_OK; } return BLK_STS_ZONE_OPEN_RESOURCE; @@ -330,8 +328,11 @@ static blk_status_t null_check_open(struct nullb_device *dev) * * ZBC states that an implicit open zone shall be closed only if there is not * room within the open limit. However, with the addition of an active limit, - * it is not certain that closing an implicit open zone will allow a new zone - * to be opened, since we might already be at the active limit capacity. + * it is not certain that closing an implicit open zone will allow an empty + * zone to be opened, since we might already be at the active limit capacity. + * Therefore, the active limit is checked first for an empty zone. A closed + * zone already holds an active zone resource, so only the open limit has to + * be checked for a closed zone. */ static blk_status_t null_check_zone_resources(struct nullb_device *dev, struct nullb_zone *zone) From 973bf587d79f061beffdd392e77012a07f25fcd6 Mon Sep 17 00:00:00 2001 From: Niklas Cassel Date: Thu, 22 Oct 2026 11:22:01 +0200 Subject: [PATCH 21/52] null_blk: don't finish zones to set them read-only or offline null_set_zone_cond() calls null_finish_zone() to release the zone resources held by a zone before setting it read-only or offline. For an empty or closed zone, null_finish_zone() first runs the zone resource checks, which can close an unrelated implicitly open zone, or fail. As the error is ignored, a failure for a closed zone leaks nr_zones_closed, permanently lowering the effective active zone limit. Setting a zone read-only or offline requires no zone resources, so release the zone resources held by the zone directly instead, using a new helper, null_release_zone_resources(). Fixes: d3a5738849e0 ("null_blk: support read-only and offline zone conditions") Reviewed-by: Damien Le Moal Signed-off-by: Niklas Cassel Link: https://patch.msgid.link/20261022092158.2248831-7-cassel@kernel.org Signed-off-by: Jens Axboe --- drivers/block/null_blk/zoned.c | 35 +++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c index ecdc8d68ca2a..015f5d304c7c 100644 --- a/drivers/block/null_blk/zoned.c +++ b/drivers/block/null_blk/zoned.c @@ -743,6 +743,33 @@ blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd, enum req_op op, } } +/* + * Release the zone resources held by a zone, before changing the condition of + * the zone to a condition that does not hold any zone resources. + */ +static void null_release_zone_resources(struct nullb_device *dev, + struct nullb_zone *zone) +{ + if (!dev->need_zone_res_mgmt) + return; + + spin_lock(&dev->zone_res_lock); + switch (zone->cond) { + case BLK_ZONE_COND_IMP_OPEN: + dev->nr_zones_imp_open--; + break; + case BLK_ZONE_COND_EXP_OPEN: + dev->nr_zones_exp_open--; + break; + case BLK_ZONE_COND_CLOSED: + dev->nr_zones_closed--; + break; + default: + break; + } + spin_unlock(&dev->zone_res_lock); +} + /* * Set a zone in the read-only or offline condition. */ @@ -759,8 +786,8 @@ static void null_set_zone_cond(struct nullb_device *dev, * If the read-only condition is requested again to zones already in * read-only condition, restore back normal empty condition. Do the same * if the offline condition is requested for offline zones. Otherwise, - * set the specified zone condition to the zones. Finish the zones - * beforehand to free up zone resources. + * set the specified zone condition to the zones. Release the zone + * resources held by the zones beforehand. */ if (zone->cond == cond) { zone->cond = BLK_ZONE_COND_EMPTY; @@ -768,9 +795,7 @@ static void null_set_zone_cond(struct nullb_device *dev, if (dev->memory_backed) null_handle_discard(dev, zone->start, zone->len); } else { - if (zone->cond != BLK_ZONE_COND_READONLY && - zone->cond != BLK_ZONE_COND_OFFLINE) - null_finish_zone(dev, zone); + null_release_zone_resources(dev, zone); zone->cond = cond; zone->wp = NULL_ZONE_INVALID_WP; } From 304b850e02fbbd72974a2bd0f88b0510f14867a9 Mon Sep 17 00:00:00 2001 From: Niklas Cassel Date: Thu, 22 Oct 2026 11:22:02 +0200 Subject: [PATCH 22/52] null_blk: clean up setting zones read-only or offline null_set_zone_cond() takes a zone condition, even though read-only and offline are the only zone conditions that it can set. Because of this, it needs a WARN_ON_ONCE() to reject any other zone condition, and its name suggests a generic helper that can set any zone condition. Rename null_set_zone_cond() to null_set_zone_readonly_or_offline(), and replace its zone condition argument with a bool, set_offline, which selects between the read-only and offline conditions. Also remove the comment above the function, as it only repeats the new function name. zone_cond_store() keeps taking a zone condition, as it, unlike null_set_zone_readonly_or_offline(), contains generic code, and might be extended to support additional zone conditions in the future. No functional change, as zone_cond_store() is only called with the read-only or offline condition. Suggested-by: Damien Le Moal Signed-off-by: Niklas Cassel Reviewed-by: Damien Le Moal Link: https://patch.msgid.link/20261022092158.2248831-8-cassel@kernel.org Signed-off-by: Jens Axboe --- drivers/block/null_blk/zoned.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c index 015f5d304c7c..b271d0a88ff2 100644 --- a/drivers/block/null_blk/zoned.c +++ b/drivers/block/null_blk/zoned.c @@ -770,15 +770,12 @@ static void null_release_zone_resources(struct nullb_device *dev, spin_unlock(&dev->zone_res_lock); } -/* - * Set a zone in the read-only or offline condition. - */ -static void null_set_zone_cond(struct nullb_device *dev, - struct nullb_zone *zone, enum blk_zone_cond cond) +static void null_set_zone_readonly_or_offline(struct nullb_device *dev, + struct nullb_zone *zone, + bool set_offline) { - if (WARN_ON_ONCE(cond != BLK_ZONE_COND_READONLY && - cond != BLK_ZONE_COND_OFFLINE)) - return; + enum blk_zone_cond cond = + set_offline ? BLK_ZONE_COND_OFFLINE : BLK_ZONE_COND_READONLY; null_lock_zone(dev, zone); @@ -814,6 +811,11 @@ ssize_t zone_cond_store(struct nullb_device *dev, const char *page, unsigned int zone_no; int ret; + /* Read-only and offline are the only conditions supported for now */ + if (WARN_ON_ONCE(cond != BLK_ZONE_COND_READONLY && + cond != BLK_ZONE_COND_OFFLINE)) + return -EINVAL; + if (!dev->zoned) { pr_err("null_blk device is not zoned\n"); return -EINVAL; @@ -839,7 +841,8 @@ ssize_t zone_cond_store(struct nullb_device *dev, const char *page, return -EINVAL; } - null_set_zone_cond(dev, &dev->zones[zone_no], cond); + null_set_zone_readonly_or_offline(dev, &dev->zones[zone_no], + cond == BLK_ZONE_COND_OFFLINE); return count; } From 603e66e8dd6adf2bad54bb27f4b690eacba3745e Mon Sep 17 00:00:00 2001 From: Sergii Ushakov Date: Fri, 18 Sep 2026 15:51:20 +0200 Subject: [PATCH 23/52] virtio-blk: clamp max_segments to virtqueue ring size In virtblk_add_req(), each request consumes 2 extra descriptors (out_hdr and in_hdr) in addition to the data scatter-gather segments. When a hypervisor (e.g. QNX Hypervisor) advertises VIRTIO_BLK_F_SEG_MAX with seg_max = 1024 alongside a 1024-entry split ring (vring.num = 1024) and VIRTIO_RING_F_INDIRECT_DESC disabled, lim->max_segments is set to 1024. When the block layer submits requests with 1023 or 1024 data segments, total_sg reaches 1025 or 1026. This exceeds vring.num (1024), causing virtqueue_add_split() to return -ENOSPC and permanently wedge the blk-mq queue. Furthermore, the Virtio specification (2.7.5.3.1) requires that a descriptor chain never exceed the Queue Size, and virtqueue_add_split() falls back to direct descriptors if indirect table allocation fails. Fix this by: 1. Rejecting queues with ring_size < 3 at probe, or ring_size < (queue_max_segments + 2) during resume/reset recovery in init_vq(). 2. Unconditionally clamping sg_elems to (ring_size - 2) across all virtqueues in virtblk_read_limits(). Fixes: 0864b79a1533 ("virtio: block: dynamic maximum segments") Signed-off-by: Sergii Ushakov Link: https://patch.msgid.link/20260918135120.1261150-1-sergiiushakov@google.com Signed-off-by: Jens Axboe --- drivers/block/virtio_blk.c | 44 +++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 6568ee276329..13ef4e136014 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -1041,6 +1041,30 @@ static int init_vq(struct virtio_blk *vblk) goto out; for (i = 0; i < num_vqs; i++) { + unsigned int ring_size = virtqueue_get_vring_size(vqs[i]); + /* + * Each request consumes 2 extra descriptors (out_hdr and + * in_hdr) in addition to the data segments. + * + * At initial probe (!vblk->disk), each virtqueue must fit at + * least 1 data segment + 2 header descriptors (3). + * On resume/recovery (vblk->disk), each virtqueue must fit the + * existing queue_max_segments() + 2 header descriptors. + */ + unsigned int min_ring_size = 3; + + if (vblk->disk) + min_ring_size = queue_max_segments(vblk->disk->queue) + 2; + + if (ring_size < min_ring_size) { + dev_err(&vdev->dev, + "virtqueue %u ring size %u is smaller than minimum %u\n", + i, ring_size, min_ring_size); + vdev->config->del_vqs(vdev); + err = -EINVAL; + goto out; + } + spin_lock_init(&vblk->vqs[i].lock); vblk->vqs[i].vq = vqs[i]; } @@ -1275,7 +1299,7 @@ static int virtblk_read_limits(struct virtio_blk *vblk, u16 min_io_size; u8 physical_block_exp, alignment_offset; size_t max_dma_size; - int err; + int err, i; /* We need to know how many segments before we allocate. */ err = virtio_cread_feature(vdev, VIRTIO_BLK_F_SEG_MAX, @@ -1289,6 +1313,23 @@ static int virtblk_read_limits(struct virtio_blk *vblk, /* Prevent integer overflows and honor max vq size */ sg_elems = min_t(u32, sg_elems, VIRTIO_BLK_MAX_SG_ELEMS - 2); + /* + * virtblk_add_req() uses separate outgoing and incoming header + * descriptors (out_hdr and in_hdr), consuming 2 extra descriptors + * per request in addition to the data segments. + * + * Per virtio specification (2.7.5.3.1), a driver MUST NOT create a + * descriptor chain longer than the Queue Size of the device. + * + * Clamp max_segments to (ring_size - 2) across all virtqueues so + * that a request never exceeds the ring size of any queue. + */ + for (i = 0; i < vblk->num_vqs; i++) { + u32 ring_size = virtqueue_get_vring_size(vblk->vqs[i].vq); + + sg_elems = min_t(u32, sg_elems, ring_size - 2); + } + /* We can handle whatever the host told us to handle. */ lim->max_segments = sg_elems; @@ -1488,6 +1529,7 @@ static int virtblk_probe(struct virtio_device *vdev) mutex_init(&vblk->vdev_mutex); vblk->vdev = vdev; + vblk->disk = NULL; INIT_WORK(&vblk->config_work, virtblk_config_changed_work); From e9804489e27dd6e33aec5511fe3780ff3009f57f Mon Sep 17 00:00:00 2001 From: Zhe Liu Date: Mon, 2 Nov 2026 14:18:02 +0800 Subject: [PATCH 24/52] blk-iocost: account flush sequence latency only once A flush sequence with a DATA phase can complete its original request twice. Both completions invoke ioc_rqos_done(), causing the request to contribute two latency samples and adding the same queue wait time twice. This gives such requests disproportionate weight compared to ordinary writes, distorting the device-wide latency and queue wait feedback used to adjust iocost's virtual time rate. Skip requests marked RQF_FLUSH_SEQ in ioc_rqos_done(). The flag is set when the request enters the flush machinery and is still set when the data phase completes; blk_flush_restore_request() clears it before the final completion, so accounting happens only once, after the whole sequence finishes. The remaining sample covers the request's lifetime through any postflush, and its queue wait time is accumulated only once. Fixes: 7caa47151ab2e ("blkcg: implement blk-iocost") Cc: stable@vger.kernel.org Signed-off-by: Zhe Liu Acked-by: Tejun Heo Link: https://patch.msgid.link/20261102061802.408173-1-liuzhe1@kylinos.cn Signed-off-by: Jens Axboe --- block/blk-iocost.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/blk-iocost.c b/block/blk-iocost.c index 1c1fe07a96ea..1c1025157d8e 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -2936,6 +2936,9 @@ static void ioc_rqos_done(struct rq_qos *rqos, struct request *rq) if (!ioc->enabled || !rq->alloc_time_ns || !rq->start_time_ns) return; + if (unlikely(rq->rq_flags & RQF_FLUSH_SEQ)) + return; + switch (req_op(rq)) { case REQ_OP_READ: pidx = QOS_RLAT; From 801bddbf1e4147a69b811c548c35a06a157941b4 Mon Sep 17 00:00:00 2001 From: Anuj Gupta Date: Thu, 29 Oct 2026 16:23:30 +0530 Subject: [PATCH 25/52] block: don't use the bvec fast path for dma-buf bios bio_may_need_split() reads bi_io_vec, which for dma-buf bios aliases bi_dmabuf_map, and interprets the map as a bvec. Always run the full split check for dma-buf bios. Fixes: d88e44f43e93 ("block: introduce dma map backed bio type") Signed-off-by: Anuj Gupta Reviewed-by: Pavel Begunkov Link: https://patch.msgid.link/20261029105330.1427462-1-anuj1072538@gmail.com Signed-off-by: Jens Axboe --- block/blk.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block/blk.h b/block/blk.h index ed2172472622..0e38e4b88cf5 100644 --- a/block/blk.h +++ b/block/blk.h @@ -418,6 +418,8 @@ static inline bool bio_may_need_split(struct bio *bio, if (!bio->bi_io_vec) return true; + if (op_is_dmabuf(bio->bi_opf)) + return true; bv = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter); if (bio->bi_iter.bi_size > bv->bv_len - bio->bi_iter.bi_offset) From 96ae13f40ce5930cd58c43128e385131476f2a66 Mon Sep 17 00:00:00 2001 From: Yingjie Wang <1075151112@qq.com> Date: Fri, 30 Oct 2026 16:46:22 +0800 Subject: [PATCH 26/52] nvmet: reject keep-alive timeouts that would overflow nvmet_set_feat_kato() and nvmet_alloc_ctrl() convert the 32-bit millisecond KATO from the host to seconds with DIV_ROUND_UP(kato, 1000). The addition in DIV_ROUND_UP() is done in 32 bits, so any KATO above 4294966296 ms wraps around and rounds to 0 seconds. A Set Features command with KATO 0xffffffff then succeeds but disables the keep-alive timer: Get Features returns 0 and Keep Alive fails with Keep Alive Timeout Invalid. A Connect command with such a KATO creates a controller without a keep-alive timer. The converted value has more consumers that can overflow. Get Features multiplies it by 1000, and the timer paths multiply it by HZ in 32 bits and arm a delay that must not exceed MAX_JIFFY_OFFSET. Reject a KATO whose rounded value does not fit all of these. Return Keep Alive Timeout Invalid from both Set Features and Connect. Validate Set Features before stopping the current timer so a failed update leaves its timeout unchanged. Round in 64 bits. A KATO of 0 keeps its current meaning. Fixes: a07b4970f464 ("nvmet: add a generic NVMe target") Cc: stable@vger.kernel.org Reviewed-by: Christoph Hellwig Signed-off-by: Yingjie Wang <1075151112@qq.com> Signed-off-by: Keith Busch --- drivers/nvme/target/admin-cmd.c | 7 ++++++- drivers/nvme/target/core.c | 8 +++++++- drivers/nvme/target/nvmet.h | 8 ++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c index 26028be8fe4d..a06cff8304db 100644 --- a/drivers/nvme/target/admin-cmd.c +++ b/drivers/nvme/target/admin-cmd.c @@ -1227,8 +1227,13 @@ u16 nvmet_set_feat_kato(struct nvmet_req *req) { u32 val32 = le32_to_cpu(req->cmd->common.cdw11); + if (val32 > NVMET_MAX_KATO * MSEC_PER_SEC) { + req->error_loc = offsetof(struct nvme_common_command, cdw11); + return NVME_SC_KA_TIMEOUT_INVALID | NVME_STATUS_DNR; + } + nvmet_stop_keep_alive_timer(req->sq->ctrl); - req->sq->ctrl->kato = DIV_ROUND_UP(val32, 1000); + req->sq->ctrl->kato = DIV_ROUND_UP_ULL(val32, MSEC_PER_SEC); nvmet_start_keep_alive_timer(req->sq->ctrl); nvmet_set_result(req, req->sq->ctrl->kato); diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c index a8171b88035c..1dede04c204a 100644 --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c @@ -1620,6 +1620,12 @@ struct nvmet_ctrl *nvmet_alloc_ctrl(struct nvmet_alloc_ctrl_args *args) u8 dhchap_status; int ret; + if (kato > NVMET_MAX_KATO * MSEC_PER_SEC) { + args->status = NVME_SC_KA_TIMEOUT_INVALID | NVME_STATUS_DNR; + args->error_loc = offsetof(struct nvmf_connect_command, kato); + return NULL; + } + args->status = NVME_SC_CONNECT_INVALID_PARAM | NVME_STATUS_DNR; subsys = nvmet_find_get_subsys(args->port, args->subsysnqn); if (!subsys) { @@ -1694,7 +1700,7 @@ struct nvmet_ctrl *nvmet_alloc_ctrl(struct nvmet_alloc_ctrl_args *args) kato = NVMET_DISC_KATO_MS; /* keep-alive timeout in seconds */ - ctrl->kato = DIV_ROUND_UP(kato, 1000); + ctrl->kato = DIV_ROUND_UP_ULL(kato, MSEC_PER_SEC); ctrl->err_counter = 0; spin_lock_init(&ctrl->error_lock); diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index d7804bf91aaa..3cd58e813aa7 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -7,6 +7,7 @@ #define _NVMET_H #include +#include #include #include #include @@ -714,6 +715,13 @@ void nvmet_add_async_event(struct nvmet_ctrl *ctrl, u8 event_type, #define NVMET_KAS 10 #define NVMET_DISC_KATO_MS 120000 +/* + * Largest keep-alive timeout in seconds that can be reported back in + * milliseconds and converted to jiffies without overflowing. + */ +#define NVMET_MAX_KATO \ + min3(U32_MAX / MSEC_PER_SEC, U32_MAX / HZ, MAX_JIFFY_OFFSET / HZ) + int __init nvmet_init_configfs(void); void __exit nvmet_exit_configfs(void); From 6976a9b8dc71bb3b6e5dd563e35510461bea29d4 Mon Sep 17 00:00:00 2001 From: James Fantin-Hardesty Date: Fri, 30 Oct 2026 13:18:53 -0600 Subject: [PATCH 27/52] nvmet: fix arbitration burst field mask The Arbitration Burst (AB) field of the Arbitration feature is CDW11 bits 2:0 (NVMe Base Specification 2.1, Feature 01h), but nvmet incorrectly masks it with 0x3. Use 0x7 for both set and get. Fixes: a0ed77d4c9a7 ("nvmet: Implement arbitration feature support") Reviewed-by: Christoph Hellwig Reviewed-by: Damien Le Moal Signed-off-by: James Fantin-Hardesty Signed-off-by: Keith Busch --- drivers/nvme/target/admin-cmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c index a06cff8304db..97ffca29f5cc 100644 --- a/drivers/nvme/target/admin-cmd.c +++ b/drivers/nvme/target/admin-cmd.c @@ -1331,7 +1331,7 @@ static u16 nvmet_set_feat_arbitration(struct nvmet_req *req) .hpw = (cdw11 >> 24) & 0xff, .mpw = (cdw11 >> 16) & 0xff, .lpw = (cdw11 >> 8) & 0xff, - .ab = cdw11 & 0x3, + .ab = cdw11 & 0x7, }; if (!ctrl->ops->set_feature) { @@ -1486,7 +1486,7 @@ static u16 nvmet_get_feat_arbitration(struct nvmet_req *req) ((u32)arb.hpw << 24) | ((u32)arb.mpw << 16) | ((u32)arb.lpw << 8) | - (arb.ab & 0x3)); + (arb.ab & 0x7)); return NVME_SC_SUCCESS; } From 29e027774324dbd5321a67bbd16840e8f7bcd189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Jean?= Date: Mon, 2 Nov 2026 13:24:19 +0000 Subject: [PATCH 28/52] nvmet-auth: reject incomplete DHCHAP messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit c9359401036e ("nvmet-auth: reject undersized AUTH_SEND payloads") only ensures that AUTH_SEND has auth_type and auth_id before nvmet_execute_auth_send() starts parsing the payload, but the DHCHAP path reads t_id before it verifies message lengths. A two-byte DHCHAP NEGOTIATE payload can therefore still trigger an OOB read that KASAN reports as: BUG: KASAN: slab-out-of-bounds in nvmet_execute_auth_send Read of size 2 at addr ffff8880030d8364 Require the payload to cover the minimum DHCHAP message length before parsing it. Fixes: c9359401036e ("nvmet-auth: reject undersized AUTH_SEND payloads") Cc: stable@vger.kernel.org Reviewed-by: Christoph Hellwig Reviewed-by: Hannes Reinecke Signed-off-by: Jérémy Jean Signed-off-by: Keith Busch --- drivers/nvme/target/fabrics-cmd-auth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/nvme/target/fabrics-cmd-auth.c b/drivers/nvme/target/fabrics-cmd-auth.c index 70136f6c22e8..a15f21fc41e4 100644 --- a/drivers/nvme/target/fabrics-cmd-auth.c +++ b/drivers/nvme/target/fabrics-cmd-auth.c @@ -301,7 +301,7 @@ void nvmet_execute_auth_send(struct nvmet_req *req) nvmet_check_transfer_len(req, tl); return; } - if (tl < offsetof(struct nvmf_auth_dhchap_success2_data, rsvd1)) { + if (tl < sizeof(struct nvmf_auth_dhchap_failure_data)) { status = NVME_SC_INVALID_FIELD | NVME_STATUS_DNR; req->error_loc = offsetof(struct nvmf_auth_send_command, tl); From 1607f2acc37afcf52048209f81ba1f5b724c5c0c Mon Sep 17 00:00:00 2001 From: Christophe JAILLET Date: Sat, 31 Oct 2026 22:36:43 +0100 Subject: [PATCH 29/52] nvmet: pci-epf: Constify struct pci_epf_ops 'struct pci_epf_ops' is not modified in this driver. Constifying this structure moves some data to a read-only section, so increases overall security, especially when the structure holds some function pointers. On a x86_64, with allmodconfig: Before: ====== text data bss dec hex filename 90026 19680 768 110474 1af8a drivers/nvme/target/pci-epf.o After: ===== text data bss dec hex filename 90090 19616 768 110474 1af8a drivers/nvme/target/pci-epf.o Reviewed-by: Christoph Hellwig Signed-off-by: Christophe JAILLET Signed-off-by: Keith Busch --- drivers/nvme/target/pci-epf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/nvme/target/pci-epf.c b/drivers/nvme/target/pci-epf.c index a8df176c1a57..cfc52454325b 100644 --- a/drivers/nvme/target/pci-epf.c +++ b/drivers/nvme/target/pci-epf.c @@ -2611,7 +2611,7 @@ static const struct pci_epf_device_id nvmet_pci_epf_ids[] = { {}, }; -static struct pci_epf_ops nvmet_pci_epf_ops = { +static const struct pci_epf_ops nvmet_pci_epf_ops = { .bind = nvmet_pci_epf_bind, .unbind = nvmet_pci_epf_unbind, .add_cfs = nvmet_pci_epf_add_cfs, From 5641f1304930c3101a2fb47568d539ec4b1b4462 Mon Sep 17 00:00:00 2001 From: Sreeraj S Kurup Date: Sat, 31 Oct 2026 08:17:51 +0000 Subject: [PATCH 30/52] nvmet: use appropriate types for authentication payload lengths The authentication payload length is obtained as a u32 value from the NVMe command, but nvmet_auth_challenge() and nvmet_auth_success1() accept it as a signed int. Use u32 for the payload length parameters in both functions to keep their types consistent with the value returned by nvmet_auth_receive_data_len() and avoid an unnecessary conversion from unsigned to signed. Also, use size_t for data_size in nvmet_auth_challenge(), since the calculation includes sizeof(), which returns size_t. This avoids implicitly narrowing the calculated payload size to int. These changes make the payload length handling consistent with the underlying types and avoid potential signedness and narrowing issues. Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Signed-off-by: Sreeraj S Kurup Signed-off-by: Keith Busch --- drivers/nvme/target/fabrics-cmd-auth.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/nvme/target/fabrics-cmd-auth.c b/drivers/nvme/target/fabrics-cmd-auth.c index a15f21fc41e4..34c2e14d0bd9 100644 --- a/drivers/nvme/target/fabrics-cmd-auth.c +++ b/drivers/nvme/target/fabrics-cmd-auth.c @@ -448,18 +448,18 @@ complete: nvmet_req_complete(req, status); } -static int nvmet_auth_challenge(struct nvmet_req *req, void *d, int al) +static int nvmet_auth_challenge(struct nvmet_req *req, void *d, u32 al) { struct nvmf_auth_dhchap_challenge_data *data = d; struct nvmet_ctrl *ctrl = req->sq->ctrl; int ret = 0; int hash_len = nvme_auth_hmac_hash_len(ctrl->shash_id); - int data_size = sizeof(*data) + hash_len; + size_t data_size = sizeof(*data) + hash_len; if (ctrl->dh_tfm) data_size += ctrl->dh_keysize; if (al < data_size) { - pr_debug("%s: buffer too small (al %d need %d)\n", __func__, + pr_debug("%s: buffer too small (al %u need %zu)\n", __func__, al, data_size); return -EINVAL; } @@ -488,7 +488,7 @@ static int nvmet_auth_challenge(struct nvmet_req *req, void *d, int al) return ret; } -static int nvmet_auth_success1(struct nvmet_req *req, void *d, int al) +static int nvmet_auth_success1(struct nvmet_req *req, void *d, u32 al) { struct nvmf_auth_dhchap_success1_data *data = d; struct nvmet_ctrl *ctrl = req->sq->ctrl; From ca7e6a9a693240f059a0b47726f64a3f0573011a Mon Sep 17 00:00:00 2001 From: Guixin Liu Date: Tue, 3 Nov 2026 15:33:07 +0800 Subject: [PATCH 31/52] nvmet-rdma: remove dead allocated field in nvmet_rdma_rsp Commit 40f0e5dc2f3c ("nvmet-rdma: use sbitmap to replace rsp free list") replaced the ->allocated flag with the discrete tag value NVMET_RDMA_DISCRETE_RSP_TAG, but left the field behind. Nothing references it anymore, so drop it. Reviewed-by: Christoph Hellwig Reviewed-by: Nilay Shroff Reviewed-by: Daniel Wagner Signed-off-by: Guixin Liu Signed-off-by: Keith Busch --- drivers/nvme/target/rdma.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c index b9e39d1657d2..b645e103d6aa 100644 --- a/drivers/nvme/target/rdma.c +++ b/drivers/nvme/target/rdma.c @@ -71,7 +71,6 @@ struct nvmet_rdma_rsp { struct nvmet_req req; - bool allocated; u8 n_rdma; u32 flags; u32 invalidate_rkey; From bc2170d365861d29dce20f982093873baad09804 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Wed, 28 Oct 2026 10:41:49 -0600 Subject: [PATCH 32/52] nvme-loop: delete the controller if a reset fails If the reconnect of a reset fails, nvme_loop_reset_ctrl_work() tears the controller down by hand with nvme_uninit_ctrl(). Since that was split from nvme_stop_ctrl() it no longer removes the namespaces, which hold references to the controller. A reset while the target no longer accepts the host (allow_any_host 0) is enough to get there: a sysfs reset hangs in kernfs_drain(), an ioctl reset leaves a controller stuck in CONNECTING with its block devices, the cntlid can't be reused, and module unload deletes the controller a second time and hits a use-after-free. Do what the other fabrics drivers do and call nvme_delete_ctrl(). The delete path quiesces the admin queue and only unquiesces it if the queue is live, which it isn't after a failed reset, so unquiesce it unconditionally before destroying it so a stuck request can't block the freeze. Fixes: d09f2b45f346 ("nvme: split nvme_uninit_ctrl into stop and uninit") Cc: Christoph Hellwig Cc: Sagi Grimberg Cc: Chaitanya Kulkarni Reviewed-by: Christoph Hellwig Signed-off-by: Josef Bacik Signed-off-by: Jens Axboe Signed-off-by: Keith Busch --- drivers/nvme/target/loop.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/target/loop.c b/drivers/nvme/target/loop.c index e579a307798b..80b67608eb15 100644 --- a/drivers/nvme/target/loop.c +++ b/drivers/nvme/target/loop.c @@ -420,6 +420,8 @@ static void nvme_loop_shutdown_ctrl(struct nvme_loop_ctrl *ctrl) static void nvme_loop_delete_ctrl_host(struct nvme_ctrl *ctrl) { nvme_loop_shutdown_ctrl(to_loop_ctrl(ctrl)); + /* Left quiesced if a failed reset has left no admin queue behind */ + nvme_unquiesce_admin_queue(ctrl); nvme_remove_admin_tag_set(ctrl); } @@ -483,9 +485,8 @@ out_destroy_admin: nvme_cancel_admin_tagset(&ctrl->ctrl); nvme_loop_destroy_admin_queue(ctrl); out_disable: - nvme_remove_admin_tag_set(&ctrl->ctrl); dev_warn(ctrl->ctrl.device, "Removing after reset failure\n"); - nvme_uninit_ctrl(&ctrl->ctrl); + nvme_delete_ctrl(&ctrl->ctrl); } static const struct nvme_ctrl_ops nvme_loop_ctrl_ops = { From 77f72de389e3774dc95d7cd03a98a73e47013abd Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Wed, 28 Oct 2026 10:41:52 -0600 Subject: [PATCH 33/52] nvmet-tcp: ask for the TLS record type on every receive nvmet_tcp_alloc_cmd() points recv_msg.msg_control at recv_cbuf once. The first receive that stores a record type there advances msg_control and leaves msg_controllen at 0 for the lifetime of the command. From then on nvmet_tcp_try_recv_data() sees the record type of that first receive: if it was an alert, all later data is dropped as alerts and the queue stalls, if it was data, a later alert can't be reported and tls_sw_recvmsg() fails with -EIO. Set up the control buffer before each receive, like the other receive paths do. Fixes: a1c5dd8355b1 ("nvmet-tcp: control messages for recvmsg()") Cc: Christoph Hellwig Cc: Sagi Grimberg Cc: Chaitanya Kulkarni Reviewed-by: Hannes Reinecke Signed-off-by: Josef Bacik Signed-off-by: Jens Axboe Signed-off-by: Keith Busch --- drivers/nvme/target/tcp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index 8092ce4914b6..158e422851a4 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -1302,6 +1302,11 @@ static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue) int len, ret; while (msg_data_left(&cmd->recv_msg)) { + if (queue->tls_pskid) { + /* The last receive has used it up */ + cmd->recv_msg.msg_control = cmd->recv_cbuf; + cmd->recv_msg.msg_controllen = sizeof(cmd->recv_cbuf); + } len = sock_recvmsg(cmd->queue->sock, &cmd->recv_msg, cmd->recv_msg.msg_flags); if (len <= 0) From 41ad4af45ac90259c652135b24539a08a92a7491 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Wed, 28 Oct 2026 10:42:07 -0600 Subject: [PATCH 34/52] nvmet-auth: keep the old keys if the new ones fail AUTH_Negotiate on the admin queue has nvmet_setup_auth() reload the host's keys, and it frees the old host key first. If decoding the new secret fails, or an allocation does, the controller is left without a host key, which means no authentication at all: nvmet_check_auth_status() passes everything and I/O queue Connects no longer ask for it. configfs accepts any string starting with "DHHC-1:" and a digit, so one typo while changing a secret opens the namespaces to any connected admin queue. Decode the new keys first and only then replace the old ones. Fixes: db1312dd9548 ("nvmet: implement basic In-Band Authentication") Cc: Hannes Reinecke Cc: Christoph Hellwig Cc: Sagi Grimberg Cc: Chaitanya Kulkarni Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Signed-off-by: Josef Bacik Signed-off-by: Jens Axboe Signed-off-by: Keith Busch --- drivers/nvme/target/auth.c | 69 ++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 41 deletions(-) diff --git a/drivers/nvme/target/auth.c b/drivers/nvme/target/auth.c index 574025730834..ccba84b1344e 100644 --- a/drivers/nvme/target/auth.c +++ b/drivers/nvme/target/auth.c @@ -135,6 +135,7 @@ u8 nvmet_setup_auth(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq, bool reset) int ret = 0; struct nvmet_host_link *p; struct nvmet_host *host = NULL; + struct nvme_dhchap_key *host_key, *ctrl_key = NULL; down_read(&nvmet_config_sem); if (nvmet_is_disc_subsys(ctrl->subsys)) @@ -172,55 +173,41 @@ u8 nvmet_setup_auth(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq, bool reset) goto out_unlock; } - if (host->dhchap_hash_id == ctrl->shash_id) { - pr_debug("Re-use existing hash ID %d\n", - ctrl->shash_id); - } else { - ctrl->shash_id = host->dhchap_hash_id; - } - - /* Skip the 'DHHC-1:XX:' prefix */ - nvme_auth_free_key(ctrl->host_key); - ctrl->host_key = nvme_auth_extract_key(host->dhchap_secret + 10, - host->dhchap_key_hash); - if (IS_ERR(ctrl->host_key)) { + /* + * Skip the 'DHHC-1:XX:' prefix. Keep the old keys until the new ones + * are there: a controller without a host key needs no authentication. + */ + host_key = nvme_auth_extract_key(host->dhchap_secret + 10, + host->dhchap_key_hash); + if (IS_ERR(host_key)) { ret = NVME_AUTH_DHCHAP_FAILURE_NOT_USABLE; - ctrl->host_key = NULL; - goto out_free_hash; + goto out_unlock; } + if (host->dhchap_ctrl_secret) { + ctrl_key = nvme_auth_extract_key(host->dhchap_ctrl_secret + 10, + host->dhchap_ctrl_key_hash); + if (IS_ERR(ctrl_key)) { + nvme_auth_free_key(host_key); + ret = NVME_AUTH_DHCHAP_FAILURE_NOT_USABLE; + goto out_unlock; + } + } + nvme_auth_free_key(ctrl->host_key); + ctrl->host_key = host_key; + nvme_auth_free_key(ctrl->ctrl_key); + ctrl->ctrl_key = ctrl_key; + ctrl->shash_id = host->dhchap_hash_id; #ifdef CONFIG_NVME_TARGET_AUTH_DEBUG pr_debug("%s: using hash %s key %*ph\n", __func__, ctrl->host_key->hash > 0 ? nvme_auth_hmac_name(ctrl->host_key->hash) : "none", (int)ctrl->host_key->len, ctrl->host_key->key); + if (ctrl->ctrl_key) + pr_debug("%s: using ctrl hash %s key %*ph\n", __func__, + ctrl->ctrl_key->hash > 0 ? + nvme_auth_hmac_name(ctrl->ctrl_key->hash) : "none", + (int)ctrl->ctrl_key->len, ctrl->ctrl_key->key); #endif - nvme_auth_free_key(ctrl->ctrl_key); - if (!host->dhchap_ctrl_secret) { - ctrl->ctrl_key = NULL; - goto out_unlock; - } - - ctrl->ctrl_key = nvme_auth_extract_key(host->dhchap_ctrl_secret + 10, - host->dhchap_ctrl_key_hash); - if (IS_ERR(ctrl->ctrl_key)) { - ret = NVME_AUTH_DHCHAP_FAILURE_NOT_USABLE; - ctrl->ctrl_key = NULL; - goto out_free_hash; - } -#ifdef CONFIG_NVME_TARGET_AUTH_DEBUG - pr_debug("%s: using ctrl hash %s key %*ph\n", __func__, - ctrl->ctrl_key->hash > 0 ? - nvme_auth_hmac_name(ctrl->ctrl_key->hash) : "none", - (int)ctrl->ctrl_key->len, ctrl->ctrl_key->key); -#endif -out_free_hash: - if (ret) { - if (ctrl->host_key) { - nvme_auth_free_key(ctrl->host_key); - ctrl->host_key = NULL; - } - ctrl->shash_id = 0; - } out_unlock: up_read(&nvmet_config_sem); From 000a9f4492abad6008682b55571ddc31941963e3 Mon Sep 17 00:00:00 2001 From: Chris Mason Date: Wed, 28 Oct 2026 10:42:27 -0600 Subject: [PATCH 35/52] nvmet-rdma: disconnect only established queues Over iWARP, rdma_disconnect() sleeps in iw_cm_disconnect() until the ESTABLISHED event of the connection has been handled, and iw_cm handles all events of all connections one at a time on iw_cm_wq. nvmet_rdma_destroy_port_queues(), nvmet_rdma_remove_one() and nvmet_rdma_delete_ctrl() walk the queue list with nvmet_rdma_queue_mutex held and call rdma_disconnect() for each, while nvmet_rdma_cm_handler() takes the same mutex. If the walk sleeps on a queue whose ESTABLISHED is queued behind another queue's event, both are stuck and iWARP connection handling is dead until reboot. A peer sets that up by connecting in a loop, or over siw by asking for MPA peer-to-peer mode and then staying silent, which delays ESTABLISHED indefinitely. Only call rdma_disconnect() for a queue in NVMET_RDMA_Q_LIVE, which the handler sets when it gets ESTABLISHED. A queue that never got there is left to the release work: ib_drain_qp() moves the QP to the error state, which ends the connection, and rdma_destroy_id() tells the peer. Over IB and RoCE the skipped call did nothing more than that. Fixes: f1d4ef7d8883 ("nvmet-rdma: register ib_client to not deadlock in device removal") Fixes: fcf73a804c7d ("nvmet-rdma: fix use-after-free when a port is removed") Cc: Christoph Hellwig Cc: Sagi Grimberg Cc: Chaitanya Kulkarni Reviewed-by: Christoph Hellwig Signed-off-by: Chris Mason Signed-off-by: Jens Axboe Signed-off-by: Keith Busch --- drivers/nvme/target/rdma.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c index b645e103d6aa..e33a4436b9ee 100644 --- a/drivers/nvme/target/rdma.c +++ b/drivers/nvme/target/rdma.c @@ -1693,7 +1693,7 @@ out_unlock: static void __nvmet_rdma_queue_disconnect(struct nvmet_rdma_queue *queue) { - bool disconnect = false; + bool disconnect = false, live = false; unsigned long flags; pr_debug("cm_id= %p queue->state= %d\n", queue->cm_id, queue->state); @@ -1712,6 +1712,7 @@ static void __nvmet_rdma_queue_disconnect(struct nvmet_rdma_queue *queue) } fallthrough; case NVMET_RDMA_Q_LIVE: + live = queue->state == NVMET_RDMA_Q_LIVE; queue->state = NVMET_RDMA_Q_DISCONNECTING; disconnect = true; break; @@ -1721,7 +1722,17 @@ static void __nvmet_rdma_queue_disconnect(struct nvmet_rdma_queue *queue) spin_unlock_irqrestore(&queue->state_lock, flags); if (disconnect) { - rdma_disconnect(queue->cm_id); + /* + * Over iWARP rdma_disconnect() sleeps until the CM has handled + * the ESTABLISHED event of this connection. The CM handles the + * events of all connections one at a time, and our handler + * takes nvmet_rdma_queue_mutex, which callers of this function + * hold. So a queue that has not seen the event is left to the + * release work: ib_drain_qp() moves the queue pair to the error + * state, which ends the connection. + */ + if (live) + rdma_disconnect(queue->cm_id); queue_work(nvmet_wq, &queue->release_work); } } From a029f1b2fb13e6ac6e1c2f27fba1d80b6e7cac51 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Wed, 28 Oct 2026 10:42:20 -0600 Subject: [PATCH 36/52] nvmet-tcp: limit the connections accepted per work run nvmet_tcp_accept_work() loops until there's nothing left to accept, and anyone opening and closing connections fast enough keeps it running indefinitely, since tearing down a dead connection takes long enough for more to arrive. Whoever flushes nvmet_wq waits for it: removing any other port of the target does in nvmet_port_release(), and so does unloading the rdma and fc modules. Accept a bounded number of connections per run and requeue the work. A flush doesn't wait for work queued behind it. Fixes: 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver") Cc: Christoph Hellwig Cc: Sagi Grimberg Cc: Chaitanya Kulkarni Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Signed-off-by: Josef Bacik Signed-off-by: Jens Axboe Signed-off-by: Keith Busch --- drivers/nvme/target/tcp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index 158e422851a4..5105317cc61e 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -102,6 +102,7 @@ MODULE_PARM_DESC(tls_handshake_timeout, #define NVMET_TCP_RECV_BUDGET 8 #define NVMET_TCP_SEND_BUDGET 8 #define NVMET_TCP_IO_WORK_BUDGET 64 +#define NVMET_TCP_ACCEPT_BUDGET 16 enum nvmet_tcp_send_state { NVMET_TCP_SEND_DATA_PDU, @@ -2073,9 +2074,9 @@ static void nvmet_tcp_accept_work(struct work_struct *w) struct nvmet_tcp_port *port = container_of(w, struct nvmet_tcp_port, accept_work); struct socket *newsock; - int ret; + int ret, i; - while (true) { + for (i = 0; i < NVMET_TCP_ACCEPT_BUDGET; i++) { ret = kernel_accept(port->sock, &newsock, O_NONBLOCK); if (ret < 0) { if (ret != -EAGAIN) @@ -2084,6 +2085,9 @@ static void nvmet_tcp_accept_work(struct work_struct *w) } nvmet_tcp_alloc_queue(port, newsock); } + + /* There may be more. Come to an end for those who flush nvmet_wq. */ + queue_work(nvmet_wq, &port->accept_work); } static void nvmet_tcp_listen_data_ready(struct sock *sk) From 86ae3841aea4e29d7ac08d5614ca3823dc8dfbc9 Mon Sep 17 00:00:00 2001 From: Chris Mason Date: Wed, 28 Oct 2026 10:42:28 -0600 Subject: [PATCH 37/52] nvmet-rdma: take a device off the list last nvmet_rdma_remove_one() disconnects the queues of a device and flushes nvmet-wq, but since commit a3dd7d0022c3 it returns right away if the device isn't on device_list. nvmet_rdma_free_dev(), run by the release work of the last queue, takes the device off that list first and frees the SRQs and the PD afterwards. A device removal in between finds nothing on the list, returns, and the RDMA core frees the device under ib_dealloc_pd(). Free the SRQs and the PD first and unlist the device last, so the remove callback finds it and its flush waits for the release work. Fixes: a3dd7d0022c3 ("nvmet-rdma: Don't flush system_wq by default during remove_one") Cc: Christoph Hellwig Cc: Sagi Grimberg Cc: Chaitanya Kulkarni Reviewed-by: Christoph Hellwig Signed-off-by: Chris Mason Signed-off-by: Jens Axboe Signed-off-by: Keith Busch --- drivers/nvme/target/rdma.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c index e33a4436b9ee..3c40109d8f3b 100644 --- a/drivers/nvme/target/rdma.c +++ b/drivers/nvme/target/rdma.c @@ -1196,13 +1196,18 @@ static void nvmet_rdma_free_dev(struct kref *ref) struct nvmet_rdma_device *ndev = container_of(ref, struct nvmet_rdma_device, ref); + nvmet_rdma_destroy_srqs(ndev); + ib_dealloc_pd(ndev->pd); + + /* + * Only delete from the device list once all RDMA resources are torn + * down because nvmet_rdma_remove_one waits for the release work only + * if the device still is on the list. + */ mutex_lock(&device_list_mutex); list_del(&ndev->entry); mutex_unlock(&device_list_mutex); - nvmet_rdma_destroy_srqs(ndev); - ib_dealloc_pd(ndev->pd); - kfree(ndev); } From 80095787f776967361cca76357f19e5445e0cd75 Mon Sep 17 00:00:00 2001 From: Chris Mason Date: Wed, 28 Oct 2026 10:42:29 -0600 Subject: [PATCH 38/52] nvmet-rdma: queue the release work under the mutex nvmet_rdma_remove_one() takes the queue mutex, unlists each queue of the device and queues its release work, then flushes nvmet-wq. So a queue that still holds objects on the device must either be on the list or have its release work queued. nvmet_rdma_queue_disconnect() breaks that: it unlists the queue under the mutex, drops it, and only then calls __nvmet_rdma_queue_disconnect() to queue the work. A device removal in that window finds nothing to wait for, and the release work then destroys the QP and CQ share on a freed device. Queue the work before dropping the mutex, as nvmet_rdma_remove_one() itself does. That's safe now that rdma_disconnect() no longer sleeps on an iWARP event that needs the same mutex. Fixes: f1d4ef7d8883 ("nvmet-rdma: register ib_client to not deadlock in device removal") Cc: Christoph Hellwig Cc: Sagi Grimberg Cc: Chaitanya Kulkarni Reviewed-by: Christoph Hellwig Signed-off-by: Chris Mason Signed-off-by: Jens Axboe Signed-off-by: Keith Busch --- drivers/nvme/target/rdma.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c index 3c40109d8f3b..3b10877e7b6a 100644 --- a/drivers/nvme/target/rdma.c +++ b/drivers/nvme/target/rdma.c @@ -1744,17 +1744,17 @@ static void __nvmet_rdma_queue_disconnect(struct nvmet_rdma_queue *queue) static void nvmet_rdma_queue_disconnect(struct nvmet_rdma_queue *queue) { - bool disconnect = false; - + /* + * Queue the release work with &nvmet_rdma_queue_mutex held, so that + * nvmet_rdma_remove_one() either finds the queue on the list or the + * work has already been queued. + */ mutex_lock(&nvmet_rdma_queue_mutex); if (!list_empty(&queue->queue_list)) { list_del_init(&queue->queue_list); - disconnect = true; + __nvmet_rdma_queue_disconnect(queue); } mutex_unlock(&nvmet_rdma_queue_mutex); - - if (disconnect) - __nvmet_rdma_queue_disconnect(queue); } static void nvmet_rdma_queue_connect_fail(struct rdma_cm_id *cm_id, From a4387799d4228866dc1746b466cd17e1c638d050 Mon Sep 17 00:00:00 2001 From: Chris Mason Date: Wed, 28 Oct 2026 10:42:30 -0600 Subject: [PATCH 39/52] nvmet-rdma: disconnect a queue on device removal cma_remove_one() sends DEVICE_REMOVAL to the owner of every cm_id on the device and then waits, without timeout, until they're all destroyed. nvmet_rdma_device_removal() does nothing for a queue cm_id and leaves the queues to nvmet_rdma_remove_one(), which only works if that runs first. As a module it does, nvmet-rdma registers after rdma_cm. Built in, both register at the same initcall level and drivers/Makefile lists nvme/ ahead of infiniband/, so cma_remove_one() runs first and waits for cm_ids that only the later callback would destroy. Since the RDMA CM drops all later events for a cm_id once it has sent DEVICE_REMOVAL, a peer closing its connection doesn't help either. One connection from anyone who can reach the port hangs "rdma link delete" until something else ends the queue. Call nvmet_rdma_queue_disconnect() for the queue. It unlists the queue and queues the release work, which destroys the cm_id. Don't wait for it, rdma_destroy_id() waits for the handler to return, which was the deadlock before commit f1d4ef7d8883. Fixes: f1d4ef7d8883 ("nvmet-rdma: register ib_client to not deadlock in device removal") Cc: Christoph Hellwig Cc: Sagi Grimberg Cc: Chaitanya Kulkarni Reviewed-by: Christoph Hellwig Signed-off-by: Chris Mason Signed-off-by: Jens Axboe Signed-off-by: Keith Busch --- drivers/nvme/target/rdma.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c index 3b10877e7b6a..f386c388da18 100644 --- a/drivers/nvme/target/rdma.c +++ b/drivers/nvme/target/rdma.c @@ -1781,10 +1781,13 @@ static void nvmet_rdma_queue_connect_fail(struct rdma_cm_id *cm_id, * queue cm_id and/or a device bound listener cm_id (where in this * case queue will be null). * - * We registered an ib_client to handle device removal for queues, - * so we only need to handle the listening port cm_ids. In this case - * we nullify the priv to prevent double cm_id destruction and destroying - * the cm_id implicitly by returning a non-zero rc to the callout. + * The RDMA CM waits until each cm_id of the device is destroyed, so a queue + * has to go now. Our ib_client also removes the queues, but it cannot be + * relied on here: built in, it is called after the RDMA CM's client. + * + * For a listening port cm_id we nullify the priv to prevent double cm_id + * destruction and destroying the cm_id implicitly by returning a non-zero + * rc to the callout. */ static int nvmet_rdma_device_removal(struct rdma_cm_id *cm_id, struct nvmet_rdma_queue *queue) @@ -1792,11 +1795,7 @@ static int nvmet_rdma_device_removal(struct rdma_cm_id *cm_id, struct nvmet_rdma_port *port; if (queue) { - /* - * This is a queue cm_id. we have registered - * an ib_client to handle queues removal - * so don't interfere and just return. - */ + nvmet_rdma_queue_disconnect(queue); return 0; } From 3197517875fdcfae1e9b5a4dcaf35cbbd66c413c Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Tue, 3 Nov 2026 11:39:28 -0500 Subject: [PATCH 40/52] selftests: ublk: fix the build and file offsets on 32-bit kublk puts pointers into 64-bit UAPI and SQE fields with a plain (__u64) cast. ublk builds with -Werror, so it fails to build on 32-bit architectures: batch.c:379:42: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast] Cast through uintptr_t. kublk also passes 64-bit user copy offsets, which start at UBLKSRV_IO_BUF_OFFSET (2 GB), to pread() and pwrite(), and with glibc those are truncated to a 32-bit off_t there. Build with -D_FILE_OFFSET_BITS=64 as well. Signed-off-by: Sasha Levin Reviewed-by: Ming Lei Link: https://patch.msgid.link/20261103163928.641519-1-sashal@kernel.org Signed-off-by: Jens Axboe --- tools/testing/selftests/ublk/Makefile | 1 + tools/testing/selftests/ublk/batch.c | 6 +++--- tools/testing/selftests/ublk/ctrl.c | 2 +- tools/testing/selftests/ublk/kublk.c | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/ublk/Makefile b/tools/testing/selftests/ublk/Makefile index fc64b8f02833..1a50d4695c9f 100644 --- a/tools/testing/selftests/ublk/Makefile +++ b/tools/testing/selftests/ublk/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 CFLAGS += -O3 -Wl,-no-as-needed -Wall -I $(top_srcdir)/usr/include +CFLAGS += -D_FILE_OFFSET_BITS=64 ifneq ($(WERROR),0) CFLAGS += -Werror endif diff --git a/tools/testing/selftests/ublk/batch.c b/tools/testing/selftests/ublk/batch.c index dfc81ee17d07..625a9c32a80b 100644 --- a/tools/testing/selftests/ublk/batch.c +++ b/tools/testing/selftests/ublk/batch.c @@ -376,10 +376,10 @@ static int __ublk_batch_queue_prep_io_cmds(struct ublk_thread *t, struct ublk_qu if (ublk_queue_use_auto_zc(q)) elem->buf_index = ublk_batch_io_buf_idx(t, q, i); else if (!ublk_queue_no_buf(q)) - elem->buf_addr = (__u64)io->buf_addr; + elem->buf_addr = (__u64)(uintptr_t)io->buf_addr; } - sqe->addr = (__u64)buf; + sqe->addr = (__u64)(uintptr_t)buf; sqe->len = t->commit_buf_elem_size * nr_elem; ublk_init_batch_cmd(t, q->q_id, sqe, UBLK_U_IO_PREP_IO_CMDS, @@ -473,7 +473,7 @@ static void __ublk_batch_commit_io_cmds(struct ublk_thread *t, ublk_io_alloc_sqes(t, &sqe, 1); buf_idx = cb->buf_idx; - sqe->addr = (__u64)cb->elem; + sqe->addr = (__u64)(uintptr_t)cb->elem; sqe->len = nr_elem * t->commit_buf_elem_size; /* commit isn't per-queue command */ diff --git a/tools/testing/selftests/ublk/ctrl.c b/tools/testing/selftests/ublk/ctrl.c index 53d54799f909..5e0762cfc4ea 100644 --- a/tools/testing/selftests/ublk/ctrl.c +++ b/tools/testing/selftests/ublk/ctrl.c @@ -204,7 +204,7 @@ int ublk_ctrl_get_params(struct ublk_dev *dev, struct ublk_ctrl_cmd_data data = { .cmd_op = UBLK_U_CMD_GET_PARAMS, .flags = CTRL_CMD_HAS_BUF, - .addr = (__u64)params, + .addr = (__u64)(uintptr_t)params, .len = sizeof(*params), }; diff --git a/tools/testing/selftests/ublk/kublk.c b/tools/testing/selftests/ublk/kublk.c index 5a4ff689c1f7..115f25351d30 100644 --- a/tools/testing/selftests/ublk/kublk.c +++ b/tools/testing/selftests/ublk/kublk.c @@ -148,7 +148,7 @@ static int ublk_ctrl_get_affinity(struct ublk_dev *ctrl_dev, cpu_set_t **ptr_buf for (i = 0; i < ctrl_dev->dev_info.nr_hw_queues; i++) { data.data[0] = i; data.len = sizeof(cpu_set_t); - data.addr = (__u64)&buf[i]; + data.addr = (__u64)(uintptr_t)&buf[i]; ret = __ublk_ctrl_cmd(ctrl_dev, &data); if (ret < 0) { From e6ac1da6a53c5f670bf09e60a2500d15be68d2fc Mon Sep 17 00:00:00 2001 From: Yitang Yang Date: Tue, 1 Sep 2026 22:24:38 +0800 Subject: [PATCH 41/52] ublk: add missing DEL_DEV_ASYNC to unprivileged permission check ublk_ctrl_uring_cmd_permission() is missing the UBLK_CMD_DEL_DEV_ASYNC case, causing the command to always return -EINVAL for unprivileged ublk devices. Fix it by adding the missing case. Fixes: 13fe8e6825e4 ("ublk: add UBLK_CMD_DEL_DEV_ASYNC") Cc: stable@vger.kernel.org Signed-off-by: Yitang Yang Reviewed-by: Ming Lei Link: https://patch.msgid.link/20260901142438.237586-1-yi1tang.yang@gmail.com Signed-off-by: Jens Axboe --- drivers/block/ublk_drv.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 72e9c435208c..3d322fa1bc83 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -5878,6 +5878,7 @@ static int ublk_ctrl_uring_cmd_permission(struct ublk_device *ub, case UBLK_CMD_STOP_DEV: case UBLK_CMD_ADD_DEV: case UBLK_CMD_DEL_DEV: + case UBLK_CMD_DEL_DEV_ASYNC: case UBLK_CMD_SET_PARAMS: case UBLK_CMD_START_USER_RECOVERY: case UBLK_CMD_END_USER_RECOVERY: From 404a8f6caa63822c1d2a45adbf07fd9c0567a7ef Mon Sep 17 00:00:00 2001 From: Jarkko Sakkinen Date: Tue, 3 Nov 2026 05:02:07 +0200 Subject: [PATCH 42/52] nvme-keyring: Add a missing key_put() call to nvme_tls_key_lookup() Call key_put() before returning -EKEYREVOKED, as the reference count gets incremented by key_lookup(). Cc: stable@vger.kernel.org # v6.12+ Fixes: 5bc46b49c828 ("nvme-tcp: check for invalidated or revoked key") Reviewed-by: Hannes Reinecke Signed-off-by: Jarkko Sakkinen Signed-off-by: Keith Busch --- drivers/nvme/common/keyring.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/nvme/common/keyring.c b/drivers/nvme/common/keyring.c index 32d16c53133b..87cb51e1f5a7 100644 --- a/drivers/nvme/common/keyring.c +++ b/drivers/nvme/common/keyring.c @@ -35,6 +35,7 @@ struct key *nvme_tls_key_lookup(key_serial_t key_id) } if (nvme_tls_psk_revoked(key)) { pr_err("key id %08x revoked\n", key_id); + key_put(key); return ERR_PTR(-EKEYREVOKED); } return key; From 1ac7efbea82562f4b1eded4de7cb37540061fb05 Mon Sep 17 00:00:00 2001 From: Qiliang Yuan Date: Wed, 4 Nov 2026 01:31:28 -0500 Subject: [PATCH 43/52] nvmet: drop the extra RCU grace period in nvmet_ns_disable() nvmet_ns_disable() kills the namespace's percpu ref, waits in synchronize_rcu() for anyone looking the namespace up under rcu_read_lock(), and then waits for the ref to drop to zero. Killing a percpu ref that is still in percpu mode, as the namespace ref always is until then, switches it to atomic mode from an RCU callback, so the ref can't drop to zero before a grace period has passed since the kill. synchronize_rcu() thus adds a second grace period in a row, about 4 ms here, and disabling the namespaces of a subsystem one by one takes about 9 ms each. Drop synchronize_rcu() and rely on the wait for the ref to cover the RCU readers as well. Disabling 64 namespaces through configfs, median of 3 runs on each of two boots per kernel: host connected before after none 588 / 590 ms 409 / 409 ms nvme-tcp 617 / 619 ms 542 / 511 ms Reviewed-by: Christoph Hellwig Signed-off-by: Qiliang Yuan Signed-off-by: Keith Busch --- drivers/nvme/target/core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c index 1dede04c204a..eadab017c70b 100644 --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c @@ -669,13 +669,15 @@ void nvmet_ns_disable(struct nvmet_ns *ns) /* * Now that we removed the namespaces from the lookup list, we * can kill the per_cpu ref and wait for any remaining references - * to be dropped, as well as a RCU grace period for anyone only - * using the namespace under rcu_read_lock(). Note that we can't - * use call_rcu here as we need to ensure the namespaces have - * been fully destroyed before unloading the module. + * to be dropped. Rely on that wait for anyone only using the + * namespace under rcu_read_lock() too: the ref can't drop to zero + * before an RCU grace period has passed since the kill. This only + * holds as long as nothing switches the ref to atomic mode before + * the kill; bring back synchronize_rcu() here if that changes. + * Note that we can't use call_rcu here as we need to ensure the + * namespaces have been fully destroyed before unloading the module. */ percpu_ref_kill(&ns->ref); - synchronize_rcu(); wait_for_completion(&ns->disable_done); percpu_ref_exit(&ns->ref); From f4ae106069982da3e36293d8e627cb9a540034a0 Mon Sep 17 00:00:00 2001 From: Hugo Deco Date: Tue, 3 Nov 2026 10:12:04 -0800 Subject: [PATCH 44/52] nvme-pci: add NO_FUA quirk for ADATA XPG GAMMIX S70 BLADE On the ADATA XPG GAMMIX S70 BLADE (PCI 1cc1:5370, firmware 03020P5E) every Write with the FUA bit set takes 200, 400 or 600 ms to complete, always a multiple of ~200 ms, while a plain Write completes in 0.0-0.4 ms and a Flush in ~1.3 ms. Tracing nvme_setup_cmd and nvme_complete_rq shows the whole delay is between submission and completion, i.e. inside the device (e.g. FUA write, control 0x4000: 598.3 ms). Because ext4/jbd2 issue FUA for every journal commit, fsync() on this drive stalls for 250-890 ms and desktop applications freeze. Add NVME_QUIRK_NO_FUA, which stops advertising BLK_FEAT_FUA while keeping the volatile write cache enabled, so the block layer emulates FUA with a Write followed by a Flush. Durability semantics are unchanged. Apply it to the S70 BLADE through nvme_id_table. With the quirk applied, 4 KiB O_DIRECT|O_DSYNC writes and create+write+fsync drop from 250-890 ms to a 0.82-0.85 ms median (30 samples, two partitions on the same drive). Reviewed-by: Christoph Hellwig Signed-off-by: Hugo Deco Signed-off-by: Keith Busch --- drivers/nvme/host/core.c | 2 ++ drivers/nvme/host/nvme.h | 8 ++++++++ drivers/nvme/host/pci.c | 2 ++ 3 files changed, 12 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 9ea9db0271c2..da2322da4252 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2482,6 +2482,8 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns, lim.features |= BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA; else lim.features &= ~(BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA); + if (ns->ctrl->quirks & NVME_QUIRK_NO_FUA) + lim.features &= ~BLK_FEAT_FUA; if (info->is_rotational) lim.features |= BLK_FEAT_ROTATIONAL; diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 92c048002ecd..82cdc7d32b22 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -183,6 +183,12 @@ enum nvme_quirks { * Admin queue DMA buffers must be page aligned */ NVME_QUIRK_ADMIN_PAGE_ALIGN = (1 << 23), + + /* + * The device is extremely slow on FUA writes but fast on Flush; + * do not advertise FUA so the block layer emulates it. + */ + NVME_QUIRK_NO_FUA = (1 << 24), }; static inline char *nvme_quirk_name(enum nvme_quirks q) @@ -236,6 +242,8 @@ static inline char *nvme_quirk_name(enum nvme_quirks q) return "dmapool_align_512"; case NVME_QUIRK_ADMIN_PAGE_ALIGN: return "admin_page_align"; + case NVME_QUIRK_NO_FUA: + return "no_fua"; } return "unknown"; diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 8a90639789c9..4f1fbc1c5e1e 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -4251,6 +4251,8 @@ static const struct pci_device_id nvme_id_table[] = { .driver_data = NVME_QUIRK_BOGUS_NID, }, { PCI_DEVICE(0x1cc1, 0x5350), /* ADATA XPG GAMMIX S50 */ .driver_data = NVME_QUIRK_BOGUS_NID, }, + { PCI_DEVICE(0x1cc1, 0x5370), /* ADATA XPG GAMMIX S70 BLADE */ + .driver_data = NVME_QUIRK_NO_FUA, }, { PCI_DEVICE(0x1dbe, 0x5216), /* Acer/INNOGRIT FA100/5216 NVMe SSD */ .driver_data = NVME_QUIRK_BOGUS_NID, }, { PCI_DEVICE(0x1dbe, 0x5236), /* ADATA XPG GAMMIX S70 */ From 29b8758b4700357909f06705a0c48c7a60c556d5 Mon Sep 17 00:00:00 2001 From: "Ewan D. Milne" Date: Wed, 4 Nov 2026 12:28:33 -0500 Subject: [PATCH 45/52] nvmet: don't return memory contents beyond valid data when reading ANA log page The host side does not know how much valid data will be returned by the target so it will typically provide a buffer larger than the amount of valid data in the ANA log page. The memory allocation used by the target does not guarantee that prior kernel memory contents will not be returned past the end of the valid page data. Fix this to ensure that the SGL is zeroed before copying the data. Fixes: 72efd25dcf4f ("nvmet: add minimal ANA support") Cc: stable@vger.kernel.org Signed-off-by: Ewan D. Milne Signed-off-by: Keith Busch --- drivers/nvme/target/admin-cmd.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c index 97ffca29f5cc..f12d83098644 100644 --- a/drivers/nvme/target/admin-cmd.c +++ b/drivers/nvme/target/admin-cmd.c @@ -543,6 +543,15 @@ static void nvmet_execute_get_log_page_ana(struct nvmet_req *req) u16 ngrps = 0; u16 status; + /* + * The header and one descriptor per enabled group are the only bytes + * written below; zero the whole transfer first so the unwritten tail + * does not leak stale kernel memory to the host. + */ + status = nvmet_zero_sgl(req, 0, req->transfer_len); + if (status) + goto out; + status = NVME_SC_INTERNAL; desc = kmalloc_flex(*desc, nsids, NVMET_MAX_NAMESPACES); if (!desc) From c64d9b2c1f4fd1d8fa52dab37b48428a99c4d58d Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Wed, 4 Nov 2026 07:18:16 -0500 Subject: [PATCH 46/52] nvme-pci: add NVME_QUIRK_DMAPOOL_ALIGN_512 for KIOXIA XG10d The KIOXIA XG10d reads past the end of a PRP list that completely fills a 256 byte small pool block. When that block is the last one in its dmapool page, the read lands on the next page, which usually isn't mapped. The IOMMU faults it and the controller craps itself: arm-smmu-v3 arm-smmu-v3.0.auto: event: F_TRANSLATION client: 0001:09:00.0 sid: 0x20900 ssid: 0x0 iova: 0xff7fe000 ipa: 0x0 nvme nvme0: controller is down; will reset: CSTS=0xffffffff, PCI_STATUS=0xffff Filling the block requires a slightly larger write, and those became common with commit 2e8e30b3cf9f ("Revert "nvme-pci: clamp max_hw_sectors based on DMA optimized limitation""). Do what we do for other disks and use 512 byte aligned small pool blocks for this controller. Cc: stable@vger.kernel.org # 6.4.x Signed-off-by: Sasha Levin Signed-off-by: Keith Busch --- drivers/nvme/host/pci.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 4f1fbc1c5e1e..eade0b1188ac 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -4198,6 +4198,8 @@ static const struct pci_device_id nvme_id_table[] = { .driver_data = NVME_QUIRK_BOGUS_NID, }, { PCI_DEVICE(0x1344, 0x6004), /* Micron 4100AT */ .driver_data = NVME_QUIRK_DMAPOOL_ALIGN_512, }, + { PCI_DEVICE(0x1e0f, 0x0032), /* KIOXIA XG10d */ + .driver_data = NVME_QUIRK_DMAPOOL_ALIGN_512, }, { PCI_DEVICE(0x1c5c, 0x1504), /* SK Hynix PC400 */ .driver_data = NVME_QUIRK_DISABLE_WRITE_ZEROES, }, { PCI_DEVICE(0x1c5c, 0x174a), /* SK Hynix P31 SSD */ From d06917d0ba226206dbd606330d73a8eb1e3029c1 Mon Sep 17 00:00:00 2001 From: Qiliang Yuan Date: Wed, 4 Nov 2026 01:30:39 -0500 Subject: [PATCH 47/52] srcu: Add list_splice_init_srcu() list_splice_init_rcu() makes a list look empty to new readers, waits for the current ones with the given sync function, and only then links the entries into the new list. The sync function takes no argument, so it can wait for RCU readers but not for the readers of an srcu_struct. Passing synchronize_rcu() for a list read under SRCU still builds, but leaves SRCU readers on the entries while the last one's next pointer is moved onto the new list head. nvme_remove_namespaces() does this today. Add list_splice_init_srcu(), which waits for the readers of the given srcu_struct instead. Cc: stable@vger.kernel.org Suggested-by: Christoph Hellwig Signed-off-by: Qiliang Yuan Reviewed-by: Paul E. McKenney Reviewed-by: Christoph Hellwig Signed-off-by: Keith Busch --- include/linux/srcu.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/include/linux/srcu.h b/include/linux/srcu.h index 1a8a465a5650..d4dcaeb83e2b 100644 --- a/include/linux/srcu.h +++ b/include/linux/srcu.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -118,6 +119,41 @@ void cleanup_srcu_struct(struct srcu_struct *ssp); void synchronize_srcu(struct srcu_struct *ssp); void synchronize_srcu_atomic(struct srcu_struct *ssp); +/** + * list_splice_init_srcu - splice an SRCU-protected list into an existing list + * @list: the SRCU-protected list to splice + * @head: the place in the existing list to splice the first list into + * @ssp: the srcu_struct that readers of @list use + * + * Like list_splice_init_rcu(), but wait for the SRCU readers of @list + * instead of RCU ones, so that none of them can follow a next pointer + * onto @head. + * + * Note that this function blocks, and that the caller must prevent any + * other updates to @list. + */ +static inline void list_splice_init_srcu(struct list_head *list, + struct list_head *head, + struct srcu_struct *ssp) +{ + struct list_head *first = list->next; + struct list_head *last = list->prev; + struct list_head *next = head->next; + + if (list_empty(list)) + return; + + INIT_LIST_HEAD_RCU(list); + synchronize_srcu(ssp); + ASSERT_EXCLUSIVE_ACCESS(*first); + ASSERT_EXCLUSIVE_ACCESS(*last); + + last->next = next; + rcu_assign_pointer(list_next_rcu(head), first); + first->prev = head; + next->prev = last; +} + #define SRCU_GET_STATE_COMPLETED 0x1 /** From 8a0449832b50cd4f99f2d2952cfc1476e5f26d0f Mon Sep 17 00:00:00 2001 From: Qiliang Yuan Date: Wed, 4 Nov 2026 01:30:40 -0500 Subject: [PATCH 48/52] nvme: wait for SRCU readers before splicing the namespace list Readers walk ctrl->namespaces under ctrl->srcu, and some of them sleep there, e.g. nvme_wait_freeze() waiting for I/O to drain. nvme_remove_namespaces() moves the list onto its on-stack ns_list with list_splice_init_rcu(), which only waits for RCU readers before relinking the entries. A reader still on the last namespace then follows its next pointer to ns_list instead of ctrl->namespaces and treats the stack as a namespace. Deleting a controller while a Format NVM passthrough waits for a delayed read on the last namespace gives: BUG: KASAN: stack-out-of-bounds in nvme_wait_freeze+0x102/0x120 Read of size 8 at addr ff110001d2f3fc38 by task nvme/4413 Call Trace: nvme_wait_freeze nvme_passthru_start nvme_submit_user_cmd nvme_user_cmd nvme_dev_ioctl BUG: unable to handle page fault for address: ffffffff8af04850 Use list_splice_init_srcu() instead, which waits for the SRCU readers. This also takes the RCU grace period out of every controller deletion. Deleting 64 tcp controllers with one namespace each, median of 3 runs on each of two boots per kernel: before after nvme disconnect-all (ms) 3491 / 3509 2996 / 3165 nvme_remove_namespaces() avg (ms) 39.0 / 40.5 31.9 / 34.7 Fixes: be647e2c76b2 ("nvme: use srcu for iterating namespace list") Cc: stable@vger.kernel.org Signed-off-by: Qiliang Yuan Reviewed-by: Christoph Hellwig Signed-off-by: Keith Busch --- drivers/nvme/host/core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index da2322da4252..03671bba1754 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -4757,9 +4757,8 @@ void nvme_remove_namespaces(struct nvme_ctrl *ctrl) nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING_NOIO); mutex_lock(&ctrl->namespaces_lock); - list_splice_init_rcu(&ctrl->namespaces, &ns_list, synchronize_rcu); + list_splice_init_srcu(&ctrl->namespaces, &ns_list, &ctrl->srcu); mutex_unlock(&ctrl->namespaces_lock); - synchronize_srcu(&ctrl->srcu); list_for_each_entry_safe(ns, next, &ns_list, list) nvme_ns_remove(ns); From 6d7388d1097f6b2367026114ce8d9e7b8b9d3426 Mon Sep 17 00:00:00 2001 From: Shao Mingyin Date: Wed, 4 Nov 2026 03:07:25 +0800 Subject: [PATCH 49/52] nvmet: take subsys->lock when forcing reconnects for tbkas nvmet_subsys_attr_tbkas_store() walks subsys->ctrls to force a reconnect while holding only nvmet_config_sem. The list is protected by subsys->lock: nvmet_alloc_ctrl() adds entries and nvmet_ctrl_free() removes them under that lock, and the controller free path does not take nvmet_config_sem. Writing attr_tbkas concurrently with a controller going away, for example on a keep-alive timeout or a fatal error, can therefore dereference a controller that has already been removed and freed. Take subsys->lock around the list walk, as nvmet_subsys_attr_qid_max_store() already does for the same loop. delete_ctrl() only schedules the asynchronous teardown, so it does not recurse into subsys->lock. Fixes: e98e45e9465b ("nvmet: Add traffic based keep alive support to configfs") Cc: stable@vger.kernel.org Signed-off-by: Shao Mingyin Reviewed-by: Christoph Hellwig Signed-off-by: Keith Busch --- drivers/nvme/target/configfs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c index b3a5242d06f9..c17f2c8ab2df 100644 --- a/drivers/nvme/target/configfs.c +++ b/drivers/nvme/target/configfs.c @@ -1466,8 +1466,10 @@ static ssize_t nvmet_subsys_attr_tbkas_store(struct config_item *item, subsys->tbkas = tbkas; /* Force reconnect */ + mutex_lock(&subsys->lock); list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) ctrl->ops->delete_ctrl(ctrl); + mutex_unlock(&subsys->lock); up_write(&nvmet_config_sem); return count; From cf399d4abbeddc317f8160a79fefb4016c469862 Mon Sep 17 00:00:00 2001 From: Shao Mingyin Date: Wed, 4 Nov 2026 03:07:27 +0800 Subject: [PATCH 50/52] nvmet: bound the traddr and trsvcid configfs writes nvmet_addr_traddr_store() and nvmet_addr_trsvcid_store() reject a write only when count is larger than NVMF_TRADDR_SIZE (256) respectively NVMF_TRSVCID_SIZE (32). A write of exactly that many characters is accepted, and the following sscanf(page, "%s\n", port->disc_addr.traddr) has no field width. configfs terminates the buffer at page[count], so the scan writes 256 characters plus the trailing NUL, i.e. 257 bytes, into traddr[256]. The extra byte lands in the following tsas field of the discovery log entry, silently clearing the first TSAS byte (the RDMA queue type, or the TLS section type for TCP). trsvcid has the same off-by-one with a 32-byte write; there the extra byte lands in the reserved bytes that follow trsvcid. Limit the scans to one byte less than the destination arrays. The count checks can stay as they are so that a normal newline-terminated write is still accepted. Fixes: 9ba2a5cb8896 ("nvmet: filter newlines from user input") Cc: stable@vger.kernel.org Signed-off-by: Shao Mingyin Reviewed-by: Christoph Hellwig Signed-off-by: Keith Busch --- drivers/nvme/target/configfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c index c17f2c8ab2df..bde94656e4b7 100644 --- a/drivers/nvme/target/configfs.c +++ b/drivers/nvme/target/configfs.c @@ -150,7 +150,7 @@ static ssize_t nvmet_addr_traddr_store(struct config_item *item, if (nvmet_is_port_enabled(port, __func__)) return -EACCES; - if (sscanf(page, "%s\n", port->disc_addr.traddr) != 1) + if (sscanf(page, "%255s", port->disc_addr.traddr) != 1) return -EINVAL; return count; } @@ -242,7 +242,7 @@ static ssize_t nvmet_addr_trsvcid_store(struct config_item *item, if (nvmet_is_port_enabled(port, __func__)) return -EACCES; - if (sscanf(page, "%s\n", port->disc_addr.trsvcid) != 1) + if (sscanf(page, "%31s", port->disc_addr.trsvcid) != 1) return -EINVAL; return count; } From c92055eb22a8e135011c14c5eb40f5da0a0c8153 Mon Sep 17 00:00:00 2001 From: Shao Mingyin Date: Wed, 4 Nov 2026 21:14:46 +0800 Subject: [PATCH 51/52] nvmet: drop the redundant auth check in nvmet_parse_io_cmd() nvmet_parse_io_cmd() calls nvmet_check_auth_status() and then nvmet_check_ctrl_status(), which performs the same check again. The first call cannot fail either: this path only handles commands from I/O queues, and nvmet_check_auth_status() returns true unconditionally for qid > 0. Drop the duplicate. No functional change. Signed-off-by: Shao Mingyin Reviewed-by: Christoph Hellwig Signed-off-by: Keith Busch --- drivers/nvme/target/core.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c index eadab017c70b..2becc838cb63 100644 --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c @@ -1122,9 +1122,6 @@ static u16 nvmet_parse_io_cmd(struct nvmet_req *req) if (nvme_is_fabrics(cmd)) return nvmet_parse_fabrics_io_cmd(req); - if (unlikely(!nvmet_check_auth_status(req))) - return NVME_SC_AUTH_REQUIRED | NVME_STATUS_DNR; - ret = nvmet_check_ctrl_status(req); if (unlikely(ret)) return ret; From f33c8bc785401669b29229bcf3d0086ba9f5b87c Mon Sep 17 00:00:00 2001 From: Nilay Shroff Date: Thu, 5 Nov 2026 17:54:55 +0530 Subject: [PATCH 52/52] nvmet: cache passthru reference in __nvmet_req_complete() __nvmet_req_complete() releases the passthru reference held while processing a passthru request. However, it currently does so after calling ops->queue_response(). Once ops->queue_response() is called, the transport may complete and recycle the request on another CPU. If the request is reused, its req->p.ref_held field may be reset to false before __nvmet_req_complete() checks it in nvmet_put_passthru_ref(). Consequently, the passthru reference may not be released, leaving wait_for_completion(&passthru->disable_done) in __nvmet_passthru_ctrl_disable() blocked indefinitely. Fix this by caching the passthru pointer at the beginning of __nvmet_req_complete(), while the request is still valid, and use the cached pointer to release the reference after queuing the response. This also changes nvmet_put_passthru_ref() to accept the passthru pointer directly instead of accessing it through the request. Reported-by: Shin'ichiro Kawasaki Closes: https://lore.kernel.org/all/auhpmq499RVE9YpC@shinmob/ Fixes: 5e12d81874a1 ("nvmet: fix use-after-free in passthru I/O hotpath") Tested-by: Shin'ichiro Kawasaki Signed-off-by: Nilay Shroff Signed-off-by: Keith Busch --- drivers/nvme/target/core.c | 4 +++- drivers/nvme/target/nvmet.h | 24 +++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c index 2becc838cb63..cc1955bc8c84 100644 --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c @@ -806,6 +806,7 @@ static void __nvmet_req_complete(struct nvmet_req *req, u16 status) { struct nvmet_ns *ns = req->ns; struct nvmet_pr_per_ctrl_ref *pc_ref = req->pc_ref; + struct nvmet_passthru *passthru = nvmet_passthru_ref_held(req); if (!req->sq->sqhd_disabled) nvmet_update_sq_head(req); @@ -824,7 +825,8 @@ static void __nvmet_req_complete(struct nvmet_req *req, u16 status) if (ns) nvmet_put_namespace(ns); - nvmet_put_passthru_ref(req); + if (passthru) + nvmet_put_passthru_ref(passthru); } void nvmet_req_complete(struct nvmet_req *req, u16 status) diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index 3cd58e813aa7..2c2460ef5e2b 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -832,6 +832,15 @@ static inline struct nvmet_passthru *nvmet_subsys_passthru( return subsys->passthru; } +static inline struct nvmet_passthru *nvmet_passthru_ref_held( + struct nvmet_req *req) +{ + if (req->p.ref_held) + return nvmet_req_subsys(req)->passthru; + + return NULL; +} + static inline bool nvmet_get_passthru_ref(struct nvmet_req *req) { if (!percpu_ref_tryget_live(&nvmet_req_subsys(req)->passthru->ref)) @@ -841,13 +850,9 @@ static inline bool nvmet_get_passthru_ref(struct nvmet_req *req) return true; } -static inline void nvmet_put_passthru_ref(struct nvmet_req *req) +static inline void nvmet_put_passthru_ref(struct nvmet_passthru *passthru) { - if (!req->p.ref_held) - return; - - req->p.ref_held = false; - percpu_ref_put(&nvmet_req_subsys(req)->passthru->ref); + percpu_ref_put(&passthru->ref); } #else /* CONFIG_NVME_TARGET_PASSTHRU */ static inline void nvmet_passthru_subsys_free(struct nvmet_subsys *subsys) @@ -873,11 +878,16 @@ static inline struct nvmet_passthru *nvmet_subsys_passthru( { return NULL; } +static inline struct nvmet_passthru *nvmet_passthru_ref_held( + struct nvmet_req *req) +{ + return NULL; +} static inline bool nvmet_get_passthru_ref(struct nvmet_req *req) { return false; } -static inline void nvmet_put_passthru_ref(struct nvmet_req *req) +static inline void nvmet_put_passthru_ref(struct nvmet_passthru *passthru) { } #endif /* CONFIG_NVME_TARGET_PASSTHRU */