From nobody Sun Sep 27 00:39:22 2026 Received: from mail-pf1-f226.google.com (mail-pf1-f226.google.com [209.85.210.226]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4B4241D223 for ; Thu, 27 Aug 2026 18:57:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.226 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787857064; cv=none; b=FSXJA0PpGmo0EVjUjWkGbgsEUjOueJ3jQEZ4YWkQC+S2YLHzF5TrKKC8plGAGBMjhdsOaZxeMsBM1HMvL7sOs+MwfDOJmRlAG9nYFlTfNWfnuJw+TsPd55GVutZDJFK4gpD3o61+O4ePPsXGOJwao9A4Q1KNBmqKXzDbBYDnmKs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787857064; c=relaxed/simple; bh=0hKzxnL8XE6fGVBWT7EQKItv4FkZAY/aHcHONEZp87M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SgzOWGSV6biKnnFhD41mIFC96C+Rl1h/ltaawXNBTAdhqOzGOqoRxUCbPKW99El+1m4DuemLvlu+jX+rTlaTpVtXVhnm+1w3eGjyCd4yZSPvKiQNBQItV2ppUz29dfNH3HFA/KPnQr4/+o5xYfwk1l139jcJKVPvUWUjtgdYmQU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=pass smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=NEKtZEhB; arc=none smtp.client-ip=209.85.210.226 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="NEKtZEhB" Received: by mail-pf1-f226.google.com with SMTP id d2e1a72fcca58-8552619b869so27421b3a.1 for ; Thu, 27 Aug 2026 11:57:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1787857051; x=1788461851; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=AXyg/Z49jw4aKGSw6uMDay7JycMrkh3Jwq5rCDvbinw=; b=NEKtZEhBQknQEm/9AVjwGxUazhEzoXXSKQl7AV2lbamALFoqxCOUjVToYoBW0zKZ92 FuYPFy/fOeUbAiDt/rnJ2lNycfTIiuMzKP65ZSPp//eJdoyUFQXBCZGsZbe8KnK0Klty KD9fJOF9qucvTjeBM63St53cCIBI57eBDNVWCd7hacrXBtCHehVA1VoNNFHedmMZR4GW MHH18kQdtr/V/C7ibaRHJwDu4XmzOUy/4CMhZg5865GDk+RgdqxoKHOMu2kZ+i6pPTEP 1wjXxJUkEoebvTQAhqZjTQ3WP8s3Gj/J5Tb/yUs55kTQ9+qtAdtyNObmLksz6oZpPRgH SA5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787857051; x=1788461851; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=AXyg/Z49jw4aKGSw6uMDay7JycMrkh3Jwq5rCDvbinw=; b=cWoqb+N6r0w/V9O7RAvHn0ojlWBbL4X5vHCJjSD1xfqgXKBTDax8wcLsMcAgTUdKnJ ogIVknf/yYaDBiY6NEV1jgBScDl8jxqbDFfSGrd1arpGaB0SsIqDIV4r3ul4SfSu4Jcq X08I0uO9Ffra6BE6SnU6xb4PMRo5kgERAfBGg4o3uIKL/zuyBw4xJErc7jdknMw0c2+j 6U3Ukjx9YVzetTe4on7PEdXOQL3jbFOP/JpbL/sHETNngNpJrWcn3781cjiW5PjCzfpd HrFReMO6oBl/mSnZVczdQRIYChfY+oDZB/X5iExIu7d/LSVC/zYKoIeXD+M73ucUYKS1 qfYw== X-Forwarded-Encrypted: i=1; AHgh+RpzeP/o5en1y6tLTV6bY/X63p1YGdMKlseGL1frVkMPz8e7yWZbDozuILBV0YWMMQGCz6miDo07yPa6Bec=@vger.kernel.org X-Gm-Message-State: AFuF++n2dcLKLEg4KzS8Fv1hUV9ZUByyRgv+yPVdrU9oFs3BTWXAwsWO d1ouo6wCvtmivW69awZkuDJuxeGcAixs7+5WEBwAIr3U3BeWVJdrqbqJGBV6IYT9bj7m+vhvh3O akJdbYE+AvSWG6CX1mJwoOoWYOz5Ds8BioFpE X-Gm-Gg: AR+sD11xFYzb1fVfYcoEKApIHe5aDOL/MLTLAU97Hwj3ZTMhChl0Nxq0Z3tg8/k9qlG 2BMU/loHTDZFTgYfOMmDjN0h4vJ8GcvOquymXNfPsO4EfCy1lfRTO4wSKTVRlwXqywTCbUFlxNr bZRxmHE55lSYhTqdQh9pGwq6Tp2l3jNWl786DmG5Cfwk4OPMesRIUPhFE6DYCau6sd0GVx/TMgE KxJlyYVeRX/2POE9A0VxwhGQwXdWn2edO9zL9uJmQnsr41ik2v+GuxEmaBY/c3UTw2GkPmYfLlk BWBodOZ78/V9XVb/PGrhg0RhjFaFQ0YN1wcNVhySkF2M2yn9ZNd1b3ZHSrlsKFEqAo7n8TTIMnq RAVOa96WtlY6OMIQBH2X1FTSbM+6ZqF6I X-Received: by 2002:a17:90a:38a5:b0:396:d28e:b52 with SMTP id 98e67ed59e1d1-396d28e0d9cmr549029a91.3.1787857051190; Thu, 27 Aug 2026 11:57:31 -0700 (PDT) Received: from c7-smtp-2026.dev.purestorage.com ([208.88.159.129]) by smtp-relay.gmail.com with ESMTPS id 98e67ed59e1d1-396b0d2fecbsm1264708a91.2.2026.08.27.11.57.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Aug 2026 11:57:31 -0700 (PDT) X-Relaying-Domain: purestorage.com Received: from dev-csander.dev.purestorage.com (bond0.slc5-n17m28-k8s.dev.purestorage.com [IPv6:2620:125:9025:20::a31:41f]) by c7-smtp-2026.dev.purestorage.com (Postfix) with ESMTP id 826E140308; Thu, 27 Aug 2026 12:57:30 -0600 (MDT) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 7EF97E404C2; Thu, 27 Aug 2026 12:57:30 -0600 (MDT) From: Caleb Sander Mateos To: Jens Axboe , Ming Lei , Keith Busch , Christoph Hellwig , Sagi Grimberg , "James E.J. Bottomley" , "Martin K. Petersen" , Chris Mason , David Sterba , Bernd Schubert , Joanne Koong , Miklos Szeredi Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org, linux-btrfs@vger.kernel.org, fuse-devel@lists.linux.dev, io-uring@vger.kernel.org, linux-kernel@vger.kernel.org, Caleb Sander Mateos Subject: [PATCH 1/2] io_uring/cmd: split io_uring_cmd_set_res() from io_uring_cmd_done() Date: Thu, 27 Aug 2026 12:57:20 -0600 Message-ID: <20260827185722.3234622-2-csander@purestorage.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260827185722.3234622-1-csander@purestorage.com> References: <20260827185722.3234622-1-csander@purestorage.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In preparation for setting the io_uring NVMe passthru CQE results from the blk-mq request completion rather than the task work callback, split out functions io_uring_cmd_set_res{,32}() from io_uring_cmd_done{,32}(). This allows io_uring_cmd_done{,32}() and __io_uring_cmd_done() to be consolidated into a single CQE-size-agnostic function with 3 fewer arguments than __io_uring_cmd_done(). Signed-off-by: Caleb Sander Mateos --- block/ioctl.c | 7 ++++--- drivers/block/ublk_drv.c | 24 ++++++++++++++++-------- drivers/nvme/host/ioctl.c | 7 ++++--- drivers/scsi/scsi_bsg.c | 4 ++-- fs/btrfs/ioctl.c | 3 ++- fs/fuse/dev_uring.c | 15 ++++++++++----- include/linux/io_uring/cmd.h | 30 ++++++++++++++---------------- io_uring/uring_cmd.c | 35 +++++++++++++++++++---------------- 8 files changed, 71 insertions(+), 54 deletions(-) diff --git a/block/ioctl.c b/block/ioctl.c index 64b4e6c0f696..946cab74f253 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -869,13 +869,14 @@ static void blk_cmd_complete(struct io_tw_req tw_req,= io_tw_token_t tw) struct io_uring_cmd *cmd =3D io_uring_cmd_from_tw(tw_req); struct blk_iou_cmd *bic =3D io_uring_cmd_to_pdu(cmd, struct blk_iou_cmd); =20 if (bic->res =3D=3D -EAGAIN && bic->nowait) io_uring_cmd_issue_blocking(cmd); - else - io_uring_cmd_done(cmd, bic->res, - IO_URING_CMD_TASK_WORK_ISSUE_FLAGS); + else { + io_uring_cmd_set_res(cmd, bic->res); + io_uring_cmd_done(cmd, IO_URING_CMD_TASK_WORK_ISSUE_FLAGS); + } } =20 static void bio_cmd_bio_end_io(struct bio *bio) { struct io_uring_cmd *cmd =3D bio->bi_private; diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 4d17ed264da1..51f15e5b3c01 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -837,11 +837,12 @@ static void ublk_batch_deinit_fetch_buf(struct ublk_q= ueue *ubq, list_del_init(&fcmd->node); WARN_ON_ONCE(fcmd !=3D ubq->active_fcmd); __ublk_release_fcmd(ubq); spin_unlock(&ubq->evts_lock); =20 - io_uring_cmd_done(fcmd->cmd, res, data->issue_flags); + io_uring_cmd_set_res(fcmd->cmd, res); + io_uring_cmd_done(fcmd->cmd, data->issue_flags); ublk_batch_free_fcmd(fcmd); } =20 static int ublk_batch_fetch_post_cqe(struct ublk_batch_fetch_cmd *fcmd, struct io_br_sel *sel, @@ -1640,11 +1641,12 @@ static void ublk_complete_io_cmd(struct ublk_io *io= , struct request *req, int res, unsigned issue_flags) { struct io_uring_cmd *cmd =3D __ublk_prep_compl_io_cmd(io, req); =20 /* tell ublksrv one io request is coming */ - io_uring_cmd_done(cmd, res, issue_flags); + io_uring_cmd_set_res(cmd, res); + io_uring_cmd_done(cmd, issue_flags); } =20 #define UBLK_REQUEUE_DELAY_MS 3 =20 static inline void __ublk_abort_rq(struct ublk_queue *ubq, @@ -1726,11 +1728,12 @@ static void ublk_auto_buf_dispatch(const struct ubl= k_queue *ubq, enum auto_buf_reg_res res =3D ublk_auto_buf_register(ubq, req, io, cmd, issue_flags); =20 if (res !=3D AUTO_BUF_REG_FAIL) { ublk_auto_buf_io_setup(ubq, req, io, cmd, res); - io_uring_cmd_done(cmd, UBLK_IO_RES_OK, issue_flags); + io_uring_cmd_set_res(cmd, UBLK_IO_RES_OK); + io_uring_cmd_done(cmd, issue_flags); } } =20 static bool ublk_start_io(const struct ublk_queue *ubq, struct request *re= q, struct ublk_io *io) @@ -2787,12 +2790,14 @@ static void ublk_cancel_cmd(struct ublk_queue *ubq,= u16 tag, cmd =3D io->cmd; io->cmd =3D NULL; } spin_unlock(&ubq->cancel_lock); =20 - if (!done && cmd) - io_uring_cmd_done(cmd, UBLK_IO_RES_ABORT, issue_flags); + if (!done && cmd) { + io_uring_cmd_set_res(cmd, UBLK_IO_RES_ABORT); + io_uring_cmd_done(cmd, issue_flags); + } } =20 /* * Cancel a batch fetch command if it hasn't been claimed by another path. * @@ -2814,11 +2819,12 @@ static void ublk_batch_cancel_cmd(struct ublk_queue= *ubq, if (done) list_del_init(&fcmd->node); spin_unlock(&ubq->evts_lock); =20 if (done) { - io_uring_cmd_done(fcmd->cmd, UBLK_IO_RES_ABORT, issue_flags); + io_uring_cmd_set_res(fcmd->cmd, UBLK_IO_RES_ABORT); + io_uring_cmd_done(fcmd->cmd, issue_flags); ublk_batch_free_fcmd(fcmd); } } =20 static void ublk_batch_cancel_queue(struct ublk_queue *ubq) @@ -3524,12 +3530,14 @@ static void ublk_ch_uring_cmd_cb(struct io_tw_req t= w_req, io_tw_token_t tw) struct io_uring_cmd *cmd =3D io_uring_cmd_from_tw(tw_req); int ret =3D -ECANCELED; =20 if (!tw.cancel) ret =3D ublk_ch_uring_cmd_local(cmd, issue_flags); - if (ret !=3D -EIOCBQUEUED) - io_uring_cmd_done(cmd, ret, issue_flags); + if (ret !=3D -EIOCBQUEUED) { + io_uring_cmd_set_res(cmd, ret); + io_uring_cmd_done(cmd, issue_flags); + } } =20 static int ublk_ch_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_= flags) { if (unlikely(issue_flags & IO_URING_F_CANCEL)) { diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c index 6539d4750098..131959c00287 100644 --- a/drivers/nvme/host/ioctl.c +++ b/drivers/nvme/host/ioctl.c @@ -438,12 +438,12 @@ static void nvme_uring_task_cb(struct io_tw_req tw_re= q, io_tw_token_t tw) struct io_uring_cmd *ioucmd =3D io_uring_cmd_from_tw(tw_req); struct nvme_uring_cmd_pdu *pdu =3D nvme_uring_cmd_pdu(ioucmd); =20 if (pdu->bio) blk_rq_unmap_user(pdu->bio); - io_uring_cmd_done32(ioucmd, pdu->status, pdu->result, - IO_URING_CMD_TASK_WORK_ISSUE_FLAGS); + io_uring_cmd_set_res32(ioucmd, pdu->status, pdu->result); + io_uring_cmd_done(ioucmd, IO_URING_CMD_TASK_WORK_ISSUE_FLAGS); } =20 static enum rq_end_io_ret nvme_uring_cmd_end_io(struct request *req, blk_status_t err, const struct io_comp_batch *iob) @@ -469,11 +469,12 @@ static enum rq_end_io_ret nvme_uring_cmd_end_io(struc= t request *req, */ if (blk_rq_is_poll(req) && iob && iob->poll_ctx =3D=3D io_uring_cmd_ctx_handle(ioucmd)) { if (pdu->bio) blk_rq_unmap_user(pdu->bio); - io_uring_cmd_done32(ioucmd, pdu->status, pdu->result, 0); + io_uring_cmd_set_res32(ioucmd, pdu->status, pdu->result); + io_uring_cmd_done(ioucmd, 0); } else { io_uring_cmd_do_in_task_lazy(ioucmd, nvme_uring_task_cb); } return RQ_END_IO_FREE; } diff --git a/drivers/scsi/scsi_bsg.c b/drivers/scsi/scsi_bsg.c index e80dec53174e..8b32d8e8f29f 100644 --- a/drivers/scsi/scsi_bsg.c +++ b/drivers/scsi/scsi_bsg.c @@ -58,12 +58,12 @@ static void scsi_bsg_uring_task_cb(struct io_tw_req tw_= req, io_tw_token_t tw) res2 =3D bsg_scsi_res2_build(status_byte(scmd->result), driver_status, host_byte(scmd->result), sense_len_wr, scmd->resid_len); =20 blk_mq_free_request(rq); - io_uring_cmd_done32(ioucmd, ret, res2, - IO_URING_CMD_TASK_WORK_ISSUE_FLAGS); + io_uring_cmd_set_res32(ioucmd, ret, res2); + io_uring_cmd_done(ioucmd, IO_URING_CMD_TASK_WORK_ISSUE_FLAGS); } =20 static enum rq_end_io_ret scsi_bsg_uring_cmd_done(struct request *req, blk_status_t status, const struct io_comp_batch *iocb) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 72bc9d4f7708..07057a708452 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -4619,11 +4619,12 @@ static void btrfs_uring_read_finished(struct io_tw_= req tw_req, io_tw_token_t tw) =20 out: btrfs_unlock_extent(io_tree, priv->start, priv->lockend, &priv->cached_st= ate); btrfs_inode_unlock(inode, BTRFS_ILOCK_SHARED); =20 - io_uring_cmd_done(cmd, ret, IO_URING_CMD_TASK_WORK_ISSUE_FLAGS); + io_uring_cmd_set_res(cmd, ret); + io_uring_cmd_done(cmd, IO_URING_CMD_TASK_WORK_ISSUE_FLAGS); add_rchar(current, ret); =20 for (index =3D 0; index < priv->nr_pages; index++) __free_page(priv->pages[index]); =20 diff --git a/fs/fuse/dev_uring.c b/fs/fuse/dev_uring.c index 77c8cec43d9c..c5bb50183e1c 100644 --- a/fs/fuse/dev_uring.c +++ b/fs/fuse/dev_uring.c @@ -364,12 +364,14 @@ static void fuse_uring_entry_teardown(struct fuse_rin= g_ent *ent) */ list_move(&ent->list, &queue->ent_released); ent->state =3D FRRS_RELEASED; spin_unlock(&queue->lock); =20 - if (cmd) - io_uring_cmd_done(cmd, -ENOTCONN, IO_URING_F_UNLOCKED); + if (cmd) { + io_uring_cmd_set_res(cmd, -ENOTCONN); + io_uring_cmd_done(cmd, IO_URING_F_UNLOCKED); + } =20 if (req) fuse_uring_stop_fuse_req_end(req); } =20 @@ -529,11 +531,12 @@ static void fuse_uring_cancel(struct io_uring_cmd *cm= d, } spin_unlock(&queue->lock); =20 if (need_cmd_done) { /* no queue lock to avoid lock order issues */ - io_uring_cmd_done(cmd, -ENOTCONN, issue_flags); + io_uring_cmd_set_res(cmd, -ENOTCONN); + io_uring_cmd_done(cmd, issue_flags); kfree(ent); if (atomic_dec_and_test(&queue->ring->queue_refs)) wake_up_all(&queue->ring->stop_waitq); } } @@ -940,11 +943,12 @@ static void fuse_uring_send(struct fuse_ring_ent *ent= , struct io_uring_cmd *cmd, list_move_tail(&ent->list, &queue->ent_in_userspace); ent->cmd =3D NULL; fuse_uring_add_to_pq(ent); spin_unlock(&queue->lock); =20 - io_uring_cmd_done(cmd, ret, issue_flags); + io_uring_cmd_set_res(cmd, ret); + io_uring_cmd_done(cmd, issue_flags); } =20 /* FUSE_URING_CMD_COMMIT_AND_FETCH handler */ static int fuse_uring_commit_fetch(struct io_uring_cmd *cmd, int issue_fla= gs, struct fuse_chan *fch) @@ -1307,11 +1311,12 @@ static void fuse_uring_send_in_task(struct io_tw_re= q tw_req, io_tw_token_t tw) =20 spin_lock(&queue->lock); list_del_init(&ent->list); spin_unlock(&queue->lock); =20 - io_uring_cmd_done(cmd, err, issue_flags); + io_uring_cmd_set_res(cmd, err); + io_uring_cmd_done(cmd, issue_flags); =20 fuse_uring_req_end(ent, ent->fuse_req, err); kfree(ent); if (atomic_dec_and_test(&queue->ring->queue_refs)) wake_up_all(&queue->ring->stop_waitq); diff --git a/include/linux/io_uring/cmd.h b/include/linux/io_uring/cmd.h index 331dcbefe72f..96fcc06097c4 100644 --- a/include/linux/io_uring/cmd.h +++ b/include/linux/io_uring/cmd.h @@ -50,19 +50,22 @@ int io_uring_cmd_import_fixed_vec(struct io_uring_cmd *= ioucmd, const struct iovec __user *uvec, size_t uvec_segs, int ddir, struct iov_iter *iter, unsigned issue_flags); =20 +/* One of these must be called prior to io_uring_cmd_done() */ +void io_uring_cmd_set_res(struct io_uring_cmd *, s32 ret); +void io_uring_cmd_set_res32(struct io_uring_cmd *, s32 ret, u64 res2); + /* * Completes the request, i.e. posts an io_uring CQE and deallocates @iouc= md * and the corresponding io_uring request. * * Note: the caller should never hard code @issue_flags and is only allowed * to pass the mask provided by the core io_uring code. */ -void __io_uring_cmd_done(struct io_uring_cmd *cmd, s32 ret, u64 res2, - unsigned issue_flags, bool is_cqe32); +void io_uring_cmd_done(struct io_uring_cmd *, unsigned issue_flags); =20 void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd, io_req_tw_func_t task_work_cb, unsigned flags); =20 @@ -105,12 +108,19 @@ static inline int io_uring_cmd_import_fixed_vec(struc= t io_uring_cmd *ioucmd, int ddir, struct iov_iter *iter, unsigned issue_flags) { return -EOPNOTSUPP; } -static inline void __io_uring_cmd_done(struct io_uring_cmd *cmd, s32 ret, - u64 ret2, unsigned issue_flags, bool is_cqe32) +static inline void io_uring_cmd_set_res(struct io_uring_cmd *cmd, s32 ret) +{ +} +static inline void io_uring_cmd_set_res32(struct io_uring_cmd *cmd, s32 re= t, + u64 res2) +{ +} +static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, + unsigned issue_flags) { } static inline void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd, io_req_tw_func_t task_work_cb, unsigned flags) { @@ -168,22 +178,10 @@ static inline struct task_struct *io_uring_cmd_get_ta= sk(struct io_uring_cmd *cmd static inline void *io_uring_cmd_ctx_handle(struct io_uring_cmd *cmd) { return cmd_to_io_kiocb(cmd)->ctx; } =20 -static inline void io_uring_cmd_done(struct io_uring_cmd *ioucmd, s32 ret, - unsigned issue_flags) -{ - return __io_uring_cmd_done(ioucmd, ret, 0, issue_flags, false); -} - -static inline void io_uring_cmd_done32(struct io_uring_cmd *ioucmd, s32 re= t, - u64 res2, unsigned issue_flags) -{ - return __io_uring_cmd_done(ioucmd, ret, res2, issue_flags, true); -} - int io_buffer_register_bvec(struct io_uring_cmd *cmd, struct request *rq, void (*release)(void *), unsigned int index, unsigned int issue_flags); int io_buffer_unregister_bvec(struct io_uring_cmd *cmd, unsigned int index, unsigned int issue_flags); diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c index 726a659f38c3..ef3e7e352c6a 100644 --- a/io_uring/uring_cmd.c +++ b/io_uring/uring_cmd.c @@ -136,40 +136,43 @@ void __io_uring_cmd_do_in_task(struct io_uring_cmd *i= oucmd, req->io_task_work.func =3D task_work_cb; __io_req_task_work_add(req, flags); } EXPORT_SYMBOL_GPL(__io_uring_cmd_do_in_task); =20 -static inline void io_req_set_cqe32_extra(struct io_kiocb *req, - u64 extra1, u64 extra2) +void io_uring_cmd_set_res(struct io_uring_cmd *cmd, s32 ret) { - req->big_cqe.extra1 =3D extra1; - req->big_cqe.extra2 =3D extra2; + struct io_kiocb *req =3D cmd_to_io_kiocb(cmd); + + if (ret < 0) + req_set_fail(req); + io_req_set_res(req, ret, 0); } +EXPORT_SYMBOL_GPL(io_uring_cmd_set_res); + +void io_uring_cmd_set_res32(struct io_uring_cmd *cmd, s32 ret, u64 res2) +{ + struct io_kiocb *req =3D cmd_to_io_kiocb(cmd); + + if (ret < 0) + req_set_fail(req); + io_req_set_res32(req, ret, 0, res2, 0); +} +EXPORT_SYMBOL_GPL(io_uring_cmd_set_res32); =20 /* * Called by consumers of io_uring_cmd, if they originally returned * -EIOCBQUEUED upon receiving the command. */ -void __io_uring_cmd_done(struct io_uring_cmd *ioucmd, s32 ret, u64 res2, - unsigned issue_flags, bool is_cqe32) +void io_uring_cmd_done(struct io_uring_cmd *ioucmd, unsigned issue_flags) { struct io_kiocb *req =3D cmd_to_io_kiocb(ioucmd); =20 if (WARN_ON_ONCE(req->flags & REQ_F_APOLL_MULTISHOT)) return; =20 io_uring_cmd_del_cancelable(ioucmd, issue_flags); =20 - if (ret < 0) - req_set_fail(req); - - io_req_set_res(req, ret, 0); - if (is_cqe32) { - if (req->ctx->flags & IORING_SETUP_CQE_MIXED) - req->cqe.flags |=3D IORING_CQE_F_32; - io_req_set_cqe32_extra(req, res2, 0); - } io_req_uring_cleanup(req, issue_flags); if (req->flags & REQ_F_IOPOLL) { /* order with io_do_iopoll() checking ->iopoll_completed */ smp_store_release(&req->iopoll_completed, 1); } else if (issue_flags & IO_URING_F_COMPLETE_DEFER) { @@ -179,11 +182,11 @@ void __io_uring_cmd_done(struct io_uring_cmd *ioucmd,= s32 ret, u64 res2, } else { req->io_task_work.func =3D io_req_task_complete; io_req_task_work_add(req); } } -EXPORT_SYMBOL_GPL(__io_uring_cmd_done); +EXPORT_SYMBOL_GPL(io_uring_cmd_done); =20 int io_uring_cmd_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) { struct io_uring_cmd *ioucmd =3D io_kiocb_to_cmd(req, struct io_uring_cmd); struct io_async_cmd *ac; --=20 2.55.0 From nobody Sun Sep 27 00:39:22 2026 Received: from mail-pf1-f228.google.com (mail-pf1-f228.google.com [209.85.210.228]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A593D490BFC for ; Thu, 27 Aug 2026 18:57:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.228 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787857063; cv=none; b=sTFeljfJXtybNhTkqEIxqSyVGZXvrB7NJ4NOAH8RgroICtk19obC3eqyHkLtWyGwoPCaYEgQ+w4zXT3KCjz6/53Nt3PnOe1o82KnXRRRF5sNJcc5XsXxIhGX5QXuanpbKbB6QN+gHYcN9T+PfBt9tExJE6Z1jgDVMXgL/47stgQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787857063; c=relaxed/simple; bh=bId58P1f3rx83kEyCFQCmbOQueTyIg0Jg1Ag1a5jGfQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EYhifEtB4y14GpYWk2d/tXvkUX6TcKFVHB32GmBfW1Oq1du1xzaRhubxyeyr36l+j6sLnp7JcsaX1nEPrkymIY2I4Cki4mbUqz37bFAj6gXjCvcmDR8nUOvSWj9wT4lm8kZeguVlSlRCN/3mXushKFq/WCyx0xCuvFVq5gzFVvc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=pass smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=Q9rrg5rA; arc=none smtp.client-ip=209.85.210.228 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="Q9rrg5rA" Received: by mail-pf1-f228.google.com with SMTP id d2e1a72fcca58-85457d780adso28302b3a.2 for ; Thu, 27 Aug 2026 11:57:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1787857052; x=1788461852; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Ex+RB5aItdA3h/bx30wNaWsAq7n74S1CMmypqWLJ+1k=; b=Q9rrg5rARoepcGhMNERctdSNthFuFWKbtn0YACk+MDoFqExmU3YFRTvG4ddSXeXGLJ ZjOTr7Ezz8nshhwzVsbdrmg3gYansSJK9e/QTsJP2bESpb3QEJz2jtmfpTJjuRSdYNMu aaZCMl7Yy+5xfIj+vZI+Q+ta2uBdSzlmlpwwa8izr7BTDocl3P69ejOOb/bEMlKBoAhl kdD+4ZbDp3ve0Ph6K/GhwDG/SyTHQV8BU9IM2YaIsO+j4edvVUURTqXDbaHUdBm5eHHb oPdddvES6u1xiuAyc+VDqmxWLO0Y0d3vwmTbrqOJQSq4FcKAeKXYfQR3aRWr3NY2/pxG PPeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787857052; x=1788461852; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Ex+RB5aItdA3h/bx30wNaWsAq7n74S1CMmypqWLJ+1k=; b=aJVSbaXFfgMZacb/jMZM7/E1JAbqejAWbnDMBdLEtyeGsfMzc4YJZd2hpHkleH+cVV gB4zJLNTaUxu46XdxRVI+ruitZG5hj0id5IeCjnjR0QC8Eeqw0NZ2TyQpJwJHxvSsrMo Sqe3DYYV9iei3XQ+IMF2Wcpgekn34C4ycVIl5riLyyQCI/d0kJgWvjKOmT1YhqcLREPx 3c51S8QI5SEIm3Zc+NzbWV/qotrVGtfYjwtiaOMeDZAZVV9zNJm1Ip04nG+u6GKvK51x Q68Pm9BLaqzZJMSUcOan1iKAz2PdnuIC+D89UXsY4cd8bftzIADdYD8TqB1PNTvQ303q clig== X-Forwarded-Encrypted: i=1; AHgh+RpAgFQpXV8+7Td83sIGUGHT8NzHAVDGSD3KOlereqFEnaXi5hgGq9sCriy/z55QjfFKyEJDfY08uFJVZvU=@vger.kernel.org X-Gm-Message-State: AFuF++nd5ZITERqH95HfW72dh5/02ki0X3GXXAEzf2wuhbhTBqP4sf2y 2wif9O/WJPfQGQT6jyLxvpIUB/fbH5Rzw0MtlKBrQzdbveG97u31gQDOQ6tR5sd+W86ehB4ZlTk 4HccgoeMOqWvSDYGIaKCHZ9DYHtHOBCXEvtpMrreuVTZY7Cak30af X-Gm-Gg: AR+sD12h83sOeu2b0sYhIcdHmfv/JYEoTP3XR0q8W0sUN4CPCKzCxlPCw2JJgaWzSAz jVz66Uzw0s1rXecqQ6aZP3TLFlFmO9B68hpVJeHy1Hgs73pkj2+2kZ//vxe0JORnjpKLy/yoNmC +pbPYWkQCEzUSeAOe1ABslKHm48H0dol7CYEjjYdPjdb9GZxP79KLO4j+Aw88BqzxnRH9C27wY3 gcWKguEhK+bH2dz0HcqTUZnxujT/yKJuNeiVUscib8PtNNKNOD2Zk+O4wH/RP4c91PNxrm7Fq6V aS5DxOqtaP8MfRVYcEnxjWpvtn1lxTytOZuKJrwbsD7LDSXQtExVAd4Rmnx4sSQcTPdrmhTx/lK ecYIzbV4s8y3gCfGLLw== X-Received: by 2002:a05:6a00:4449:b0:851:c2bd:43d1 with SMTP id d2e1a72fcca58-85628a85b9amr829996b3a.1.1787857051450; Thu, 27 Aug 2026 11:57:31 -0700 (PDT) Received: from c7-smtp-2026.dev.purestorage.com ([2620:125:9017:12:36:3:6:0]) by smtp-relay.gmail.com with ESMTPS id d2e1a72fcca58-8538d0c4935sm2212871b3a.7.2026.08.27.11.57.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Aug 2026 11:57:31 -0700 (PDT) X-Relaying-Domain: purestorage.com Received: from dev-csander.dev.purestorage.com (dev-csander.dev.purestorage.com [10.112.12.104]) by c7-smtp-2026.dev.purestorage.com (Postfix) with ESMTP id A24254030A; Thu, 27 Aug 2026 12:57:30 -0600 (MDT) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 9F60AE404C2; Thu, 27 Aug 2026 12:57:30 -0600 (MDT) From: Caleb Sander Mateos To: Jens Axboe , Ming Lei , Keith Busch , Christoph Hellwig , Sagi Grimberg , "James E.J. Bottomley" , "Martin K. Petersen" , Chris Mason , David Sterba , Bernd Schubert , Joanne Koong , Miklos Szeredi Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org, linux-btrfs@vger.kernel.org, fuse-devel@lists.linux.dev, io-uring@vger.kernel.org, linux-kernel@vger.kernel.org, Caleb Sander Mateos Subject: [PATCH 2/2] nvme/ioctl: call io_uring_cmd_set_res32() in ->end_io() Date: Thu, 27 Aug 2026 12:57:21 -0600 Message-ID: <20260827185722.3234622-3-csander@purestorage.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260827185722.3234622-1-csander@purestorage.com> References: <20260827185722.3234622-1-csander@purestorage.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" io_uring_cmd_set_res32() only performs loads and stores to the io_uring request state, so it's safe to call in interrupt context. Move the call from the nvme_uring_task_cb() task work to nvme_uring_cmd_end_io(). This unifies the 2 io_uring_cmd_set_res32() callers and removes the need to pass result and status through struct nvme_uring_cmd_pdu, saving 16 bytes and a couple memory accesses. Signed-off-by: Caleb Sander Mateos --- drivers/nvme/host/ioctl.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c index 131959c00287..b50bba207818 100644 --- a/drivers/nvme/host/ioctl.c +++ b/drivers/nvme/host/ioctl.c @@ -421,12 +421,10 @@ struct nvme_uring_data { * Expect build errors if this grows larger than that. */ struct nvme_uring_cmd_pdu { struct request *req; struct bio *bio; - u64 result; - int status; }; =20 static inline struct nvme_uring_cmd_pdu *nvme_uring_cmd_pdu( struct io_uring_cmd *ioucmd) { @@ -438,29 +436,30 @@ static void nvme_uring_task_cb(struct io_tw_req tw_re= q, io_tw_token_t tw) struct io_uring_cmd *ioucmd =3D io_uring_cmd_from_tw(tw_req); struct nvme_uring_cmd_pdu *pdu =3D nvme_uring_cmd_pdu(ioucmd); =20 if (pdu->bio) blk_rq_unmap_user(pdu->bio); - io_uring_cmd_set_res32(ioucmd, pdu->status, pdu->result); io_uring_cmd_done(ioucmd, IO_URING_CMD_TASK_WORK_ISSUE_FLAGS); } =20 static enum rq_end_io_ret nvme_uring_cmd_end_io(struct request *req, blk_status_t err, const struct io_comp_batch *iob) { struct io_uring_cmd *ioucmd =3D req->end_io_data; struct nvme_uring_cmd_pdu *pdu =3D nvme_uring_cmd_pdu(ioucmd); + u64 result =3D le64_to_cpu(nvme_req(req)->result.u64); + int status; =20 if (nvme_req(req)->flags & NVME_REQ_CANCELLED) { - pdu->status =3D -EINTR; + status =3D -EINTR; } else { - pdu->status =3D nvme_req(req)->status; - if (!pdu->status) - pdu->status =3D blk_status_to_errno(err); + status =3D nvme_req(req)->status; + if (!status) + status =3D blk_status_to_errno(err); } - pdu->result =3D le64_to_cpu(nvme_req(req)->result.u64); + io_uring_cmd_set_res32(ioucmd, status, result); =20 /* * For IOPOLL, check if this completion is happening in the context * of the same io_ring that owns the request (local context). If so, * we can complete inline without task_work overhead. Otherwise, we @@ -469,11 +468,10 @@ static enum rq_end_io_ret nvme_uring_cmd_end_io(struc= t request *req, */ if (blk_rq_is_poll(req) && iob && iob->poll_ctx =3D=3D io_uring_cmd_ctx_handle(ioucmd)) { if (pdu->bio) blk_rq_unmap_user(pdu->bio); - io_uring_cmd_set_res32(ioucmd, pdu->status, pdu->result); io_uring_cmd_done(ioucmd, 0); } else { io_uring_cmd_do_in_task_lazy(ioucmd, nvme_uring_task_cb); } return RQ_END_IO_FREE; --=20 2.55.0