From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AD9FDCCD1AB for ; Fri, 24 Oct 2025 04:22:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To: Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=HcyH9reGqGAeYbGxR5vDfBAZeC8+dhdfp3nQT7CViH8=; b=a1PvReUA+usKjxMW2Na/sg8E6L Q9tZxfjoIZ+oKj3pL4pD5EmbFzAIW+UYnwWjCDTcfJerHqoG9M7097BKZ/aFYC7IFjjPxqZ0M19X4 uErEjsxuMQzJ45dwc7eO+eiFg3yY0cPOL3pSjK/vxeq110lvA6GKlh+rw9cY3lLlRwIYGBXTdn64m YEXjXNKccRiT8lZ5i7ah2b6bv+l7QzvevJPYwi+N7EMR8Z96CAbiC+XSnf4aXVeC2Kl8AUY43oigP y3UhIuhK4RadH5hq5mIJmrS9VWRluHXsAVg/pMy9vEz/DQ4g1VNAe5q2W0pxrwYOzRf57GcbYbVVh /PoAUTiw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vC9Ja-00000008Did-1yCA; Fri, 24 Oct 2025 04:22:10 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vC9JV-00000008Dhv-4BUK for linux-nvme@lists.infradead.org; Fri, 24 Oct 2025 04:22:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761279724; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HcyH9reGqGAeYbGxR5vDfBAZeC8+dhdfp3nQT7CViH8=; b=ZWllSkIHztHHJeZkz8Ig9Ia5tqQPmQSB3Kwbx34VpiLjj2GcY0Ud1yCvG14gws+FK4DYhp 6t4jVFBxhhYt5r0GhkzHbD22tiXBbIhcPl47H3kQfElcKtM+vjQ6a0EDWp6KKvbdV600MS IOallOZUeZh4M5NJGYMO6uuH/J8n9+M= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-307-WDD9V3B9O1agD7-K0GP8SA-1; Fri, 24 Oct 2025 00:21:59 -0400 X-MC-Unique: WDD9V3B9O1agD7-K0GP8SA-1 X-Mimecast-MFC-AGG-ID: WDD9V3B9O1agD7-K0GP8SA_1761279717 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A3CA318002DD; Fri, 24 Oct 2025 04:21:57 +0000 (UTC) Received: from fedora (unknown [10.72.120.13]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 50F0A180057D; Fri, 24 Oct 2025 04:21:48 +0000 (UTC) Date: Fri, 24 Oct 2025 12:21:43 +0800 From: Ming Lei To: Caleb Sander Mateos Cc: Jens Axboe , Miklos Szeredi , Keith Busch , Christoph Hellwig , Sagi Grimberg , Chris Mason , David Sterba , io-uring@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 3/3] io_uring/uring_cmd: avoid double indirect call in task work dispatch Message-ID: References: <20251023201830.3109805-1-csander@purestorage.com> <20251023201830.3109805-4-csander@purestorage.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251023_212206_111064_482D2E8D X-CRM114-Status: GOOD ( 36.39 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org On Thu, Oct 23, 2025 at 08:49:40PM -0700, Caleb Sander Mateos wrote: > On Thu, Oct 23, 2025 at 8:42 PM Ming Lei wrote: > > > > On Thu, Oct 23, 2025 at 02:18:30PM -0600, Caleb Sander Mateos wrote: > > > io_uring task work dispatch makes an indirect call to struct io_kiocb's > > > io_task_work.func field to allow running arbitrary task work functions. > > > In the uring_cmd case, this calls io_uring_cmd_work(), which immediately > > > makes another indirect call to struct io_uring_cmd's task_work_cb field. > > > Define the uring_cmd task work callbacks as functions whose signatures > > > match io_req_tw_func_t. Define a IO_URING_CMD_TASK_WORK_ISSUE_FLAGS > > > constant in io_uring/cmd.h to avoid manufacturing issue_flags in the > > > uring_cmd task work callbacks. Now uring_cmd task work dispatch makes a > > > single indirect call to the uring_cmd implementation's callback. This > > > also allows removing the task_work_cb field from struct io_uring_cmd, > > > freeing up some additional storage space. > > > > The idea looks good. > > > > > > > > Signed-off-by: Caleb Sander Mateos > > > --- > > > block/ioctl.c | 4 +++- > > > drivers/block/ublk_drv.c | 15 +++++++++------ > > > drivers/nvme/host/ioctl.c | 5 +++-- > > > fs/btrfs/ioctl.c | 4 +++- > > > fs/fuse/dev_uring.c | 5 +++-- > > > include/linux/io_uring/cmd.h | 16 +++++++--------- > > > io_uring/uring_cmd.c | 13 ++----------- > > > 7 files changed, 30 insertions(+), 32 deletions(-) > > > > > > diff --git a/block/ioctl.c b/block/ioctl.c > > > index d7489a56b33c..5c10d48fab27 100644 > > > --- a/block/ioctl.c > > > +++ b/block/ioctl.c > > > @@ -767,13 +767,15 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) > > > struct blk_iou_cmd { > > > int res; > > > bool nowait; > > > }; > > > > > > -static void blk_cmd_complete(struct io_uring_cmd *cmd, unsigned int issue_flags) > > > +static void blk_cmd_complete(struct io_kiocb *req, io_tw_token_t tw) > > > { > > > + struct io_uring_cmd *cmd = io_kiocb_to_cmd(req, struct io_uring_cmd); > > > struct blk_iou_cmd *bic = io_uring_cmd_to_pdu(cmd, struct blk_iou_cmd); > > > + unsigned int issue_flags = IO_URING_CMD_TASK_WORK_ISSUE_FLAGS; > > > > Now `io_kiocb` is exposed to driver, it could be perfect if 'io_uring_cmd' > > is kept in kernel API interface, IMO. > > You mean change the io_req_tw_func_t signature to pass struct > io_uring_cmd * instead of struct io_kiocb *? I don't think that would > make sense because task work is a more general concept, not just for > uring_cmd. I agree it's a bit ugly exposing struct io_kiocb * outside > of the io_uring core, but I don't see a way to encapsulate it without > other downsides (the additional indirect call or the gross macro from > v1). Treating it as an opaque pointer type seems like the least bad > option... If switching to `struct io_kiocb *` can't be accepted, `opaque pointer type` might not be too bad: - share the callback storage for both `io_uring_cmd_tw_t` and `io_req_tw_func_t` via union - add one request flag for deciding to dispatch which one & prepare `io_kiocb *` or `io_uring_cmd *`. > > > > > ... > > > > > diff --git a/include/linux/io_uring/cmd.h b/include/linux/io_uring/cmd.h > > > index b84b97c21b43..3efad93404f9 100644 > > > --- a/include/linux/io_uring/cmd.h > > > +++ b/include/linux/io_uring/cmd.h > > > @@ -9,18 +9,13 @@ > > > /* only top 8 bits of sqe->uring_cmd_flags for kernel internal use */ > > > #define IORING_URING_CMD_CANCELABLE (1U << 30) > > > /* io_uring_cmd is being issued again */ > > > #define IORING_URING_CMD_REISSUE (1U << 31) > > > > > > -typedef void (*io_uring_cmd_tw_t)(struct io_uring_cmd *cmd, > > > - unsigned issue_flags); > > > - > > > struct io_uring_cmd { > > > struct file *file; > > > const struct io_uring_sqe *sqe; > > > - /* callback to defer completions to task context */ > > > - io_uring_cmd_tw_t task_work_cb; > > > u32 cmd_op; > > > u32 flags; > > > u8 pdu[32]; /* available inline for free use */ > > > > pdu[40] > > I considered that, but wondered if we might want to reuse the 8 bytes > for something internal to uring_cmd rather than providing it to the > driver's uring_cmd implementation. If we increase pdu and a driver > starts using more than 32 bytes, it will be difficult to claw back. It > seems reasonable to reserve half the space for the io_uring/uring_cmd > layer and half for the driver. Fair enough, but I think the 8bytes need to define as reserved, at least with document benefit. Thanks, Ming