From nobody Wed Dec 17 08:56:18 2025 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 EE32B24EF6A for ; Wed, 19 Mar 2025 06:13:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742364807; cv=none; b=EL7vPUDZy0ocIrbMWLJQNAdrB+GPXYDSO78RlVq2YCVzjdXu4Sgfz6HJ6+lwwV4YmCEhoZ5WssbbA2Qn5VEg4EzHHmzKR0MO7RQStcsaxoT0FqRKQd7z2shcf6TuLBGWDddHZ76RdxjtLC8gde6cqtRw7DwTmuE0g/NrIDInvew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742364807; c=relaxed/simple; bh=JVp+R6surQiovwaIKFttfDz3Q9gl45zG0j+0tsq2SxA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HQDgJOpteO3W7pbBknLFQgie5qLOf6097f9LuwS1Vzpzo8eMhWbXCEc1EG2MC/uFsJVDdm92lNWHDneCRzLWrtCBRyQ/dhH+0TFVVAN/GkKzMZA93/+/PRa2p3EuwJUhRnNut+nRhXMhJmwU+7uCmmWqa45EsHOYMVcDxPwSPh4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=furiosa.ai; spf=none smtp.mailfrom=furiosa.ai; dkim=pass (1024-bit key) header.d=furiosa.ai header.i=@furiosa.ai header.b=fEboSbYv; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=furiosa.ai Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=furiosa.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=furiosa.ai header.i=@furiosa.ai header.b="fEboSbYv" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2264aefc45dso8115575ad.0 for ; Tue, 18 Mar 2025 23:13:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=furiosa.ai; s=google; t=1742364805; x=1742969605; 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; bh=DyIfb3cMQmkLjGyXRr92VgXsWIyWeZB1/LvhfHHV0+U=; b=fEboSbYvK3DqpXzh6LNl3Lxfd6ZPFxFSe17ToWPrgX8+nNgqy4FRILf7NCFrWjRuaF nvbdJH4r5f9Xf2ezMeBZaJBkMhRiVYMx9zqJLn4pBcub9vPTQYsI7OCSOiSDgG9N6Ots IXX50nN41iOGJoZF0Z9VAMTqN9TFs1wCjqA9E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742364805; x=1742969605; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DyIfb3cMQmkLjGyXRr92VgXsWIyWeZB1/LvhfHHV0+U=; b=A7eY4D4u9n80Tu7KISCTjRdNlcsbXnSViE0t9OUGB9/vqsmO19a6VSAw7Q7ORP/IuE +dUlJpNKHWpB9dZl3aFEqO3y5eat+euPSKE+m8ABVDChh5L7p2hY8qGJjvn5hi8Gkcwi HdbblVtmQyv+tbMRUVLQe6K3oLiQR+EHKucusRdnaTgUI+9Q+TggelHv4A/+y/KL/yv0 ib45XMUp3byZiNM7eREDXpsmBg8b/vvAAumw2Spf1iQaZZAckW+/i7YxsSgAGhhCaCnw 0NUr/hWP0v3pLuI4/aWHOyqEGYxw96c97ZQ5OqJidxyA7rVOjlfRiVs71ytX3d+4CV0I FzYw== X-Forwarded-Encrypted: i=1; AJvYcCWAySJYEooVobwsA5Fnp/33CLEyVenZjao0fJBLloQsff2kpVNZJGpoK2eHj9Y/CR5hn0zeV+yNM4gYOv0=@vger.kernel.org X-Gm-Message-State: AOJu0YwpjNSAm61u9uYMWcPVKsds1CW51d9mF4ID8se7jn20nD/UsorS /Va0lJ8S5Xv2pro8d/+PgPvj0lowAVIzY0QpfJ2ypjlKG/O0WrJi5z94QhlWXCA= X-Gm-Gg: ASbGncu7Mqqd51X8C92kEt1vwKxYgsERre9rtYrkewYsBgssvXeUi79q3V96nQ8cWsA yfG5UMFZ1WYdEjA/ciFSKsMXoCJa1DnnLE7sQM+ed5N1tTXg9Lzx5qR/GAmBm4TPxtCuaGpTKdf 6aEiKjcCMsMhWPMw8aj1fU7SCWml8z3IeyZAArJVj0mJR1E9v6oeG4NOYZNEaCkXu4ECHHzXy0Q IaV3CGV9Z1wN46npu3GmFj1QaABxIkzmI15rZhifGYcHK4NGwImEFwKCwPg0yzxU7jL2MuzOJk+ GM3tSfOeFQLyz/rGqNrYXjAKGdyWL4PW355cR1qxm+ngjRev2+X5ZUnU15+rAg4oxbeFaCavtBo sorof X-Google-Smtp-Source: AGHT+IEma3OybcJ79OOz94lGu709GfcmPOvj0c+kXippDXOfifH1HLUbalNH0Kn2IST8s5E/XF5rbQ== X-Received: by 2002:a17:902:f60d:b0:220:f449:7419 with SMTP id d9443c01a7336-2264982b1cemr26338635ad.7.1742364805268; Tue, 18 Mar 2025 23:13:25 -0700 (PDT) Received: from sidong.sidong.yang.office.furiosa.vpn ([61.83.209.48]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-301bf589b07sm645103a91.11.2025.03.18.23.13.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 23:13:24 -0700 (PDT) From: Sidong Yang To: Josef Bacik , David Sterba , Jens Axboe , Pavel Begunkov Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org Subject: [RFC PATCH v5 1/5] io_uring: rename the data cmd cache Date: Wed, 19 Mar 2025 06:12:47 +0000 Message-ID: <20250319061251.21452-2-sidong.yang@furiosa.ai> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250319061251.21452-1-sidong.yang@furiosa.ai> References: <20250319061251.21452-1-sidong.yang@furiosa.ai> 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" From: Pavel Begunkov Pick a more descriptive name for the cmd async data cache. Signed-off-by: Pavel Begunkov --- include/linux/io_uring_types.h | 2 +- io_uring/io_uring.c | 4 ++-- io_uring/uring_cmd.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h index 0e87e292bfb5..c17d2eedf478 100644 --- a/include/linux/io_uring_types.h +++ b/include/linux/io_uring_types.h @@ -318,7 +318,7 @@ struct io_ring_ctx { struct io_alloc_cache apoll_cache; struct io_alloc_cache netmsg_cache; struct io_alloc_cache rw_cache; - struct io_alloc_cache uring_cache; + struct io_alloc_cache cmd_cache; =20 /* * Any cancelable uring_cmd is added to this list in diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 5ff30a7092ed..7f26ad334e30 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -289,7 +289,7 @@ static void io_free_alloc_caches(struct io_ring_ctx *ct= x) io_alloc_cache_free(&ctx->apoll_cache, kfree); io_alloc_cache_free(&ctx->netmsg_cache, io_netmsg_cache_free); io_alloc_cache_free(&ctx->rw_cache, io_rw_cache_free); - io_alloc_cache_free(&ctx->uring_cache, kfree); + io_alloc_cache_free(&ctx->cmd_cache, kfree); io_alloc_cache_free(&ctx->msg_cache, kfree); io_futex_cache_free(ctx); io_rsrc_cache_free(ctx); @@ -334,7 +334,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(str= uct io_uring_params *p) ret |=3D io_alloc_cache_init(&ctx->rw_cache, IO_ALLOC_CACHE_MAX, sizeof(struct io_async_rw), offsetof(struct io_async_rw, clear)); - ret |=3D io_alloc_cache_init(&ctx->uring_cache, IO_ALLOC_CACHE_MAX, + ret |=3D io_alloc_cache_init(&ctx->cmd_cache, IO_ALLOC_CACHE_MAX, sizeof(struct io_uring_cmd_data), 0); spin_lock_init(&ctx->msg_lock); ret |=3D io_alloc_cache_init(&ctx->msg_cache, IO_ALLOC_CACHE_MAX, diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c index de39b602aa82..792bd54851b1 100644 --- a/io_uring/uring_cmd.c +++ b/io_uring/uring_cmd.c @@ -28,7 +28,7 @@ static void io_req_uring_cleanup(struct io_kiocb *req, un= signed int issue_flags) =20 if (issue_flags & IO_URING_F_UNLOCKED) return; - if (io_alloc_cache_put(&req->ctx->uring_cache, cache)) { + if (io_alloc_cache_put(&req->ctx->cmd_cache, cache)) { ioucmd->sqe =3D NULL; req->async_data =3D NULL; req->flags &=3D ~REQ_F_ASYNC_DATA; @@ -171,7 +171,7 @@ static int io_uring_cmd_prep_setup(struct io_kiocb *req, struct io_uring_cmd *ioucmd =3D io_kiocb_to_cmd(req, struct io_uring_cmd); struct io_uring_cmd_data *cache; =20 - cache =3D io_uring_alloc_async_data(&req->ctx->uring_cache, req); + cache =3D io_uring_alloc_async_data(&req->ctx->cmd_cache, req); if (!cache) return -ENOMEM; cache->op_data =3D NULL; --=20 2.43.0 From nobody Wed Dec 17 08:56:18 2025 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (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 99C9024FBE7 for ; Wed, 19 Mar 2025 06:13:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742364810; cv=none; b=OOHYUuTXmHVNJPNNn9lSTK21CbUoAIiwTLDXOfVuIvHMNf3dht6Te4Kg9M0VgEw1WQr2kaBjaB2Y3rAEyJSAR/OaboFNyuDWyRbqtWAjNRaIWwDSwQVsP0h5Ps6UFx0kYdXW6rGgxRi/5TO+cwDz+2tE2b2Nb8pSu7wqRX6I86Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742364810; c=relaxed/simple; bh=0IdlGsxiHlOpfB3LWKjSS9hQhoWmXtFYaCxPr3UzbE4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VVLkD0WOfAh1GhxQmR6r15GOOVolQClnV86LDVJZUkjRdIcH9IcfquxsO+fDMhVd3X1xL8Ok89UfANKzl1qIyoCzZXEXLc/B8i/+QV8joFJzqFkieFmoPt2NmOFG0ZpF+nzLfH+52OZhxaOMbBXEscLYTSjG6D2dg4puN//2ilk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=furiosa.ai; spf=none smtp.mailfrom=furiosa.ai; dkim=pass (1024-bit key) header.d=furiosa.ai header.i=@furiosa.ai header.b=J9ry71SE; arc=none smtp.client-ip=209.85.216.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=furiosa.ai Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=furiosa.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=furiosa.ai header.i=@furiosa.ai header.b="J9ry71SE" Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-2ff6ae7667dso8259955a91.0 for ; Tue, 18 Mar 2025 23:13:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=furiosa.ai; s=google; t=1742364808; x=1742969608; 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; bh=6AbNriybkAMg6arWdOZVqfylWfhbFH3phG3S4HFDKww=; b=J9ry71SEuiDmw14IQk1Pmk3yFRI/2xqN08SBlv2P7vavGHbPvfsCoQ3mppUNWoEU98 uJcVAvo6tWr7O3f5pvtIX0tprFetwrArPBbROR/OosdWgNpgS1Yv4bXvhHM4KJ5+UWl7 dDV5SF4cK/u3Mumby9/dlmrz96fN+5c7t6hqE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742364808; x=1742969608; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6AbNriybkAMg6arWdOZVqfylWfhbFH3phG3S4HFDKww=; b=rr1e91vjzd2hu9Vf9wmUxwuomVYVeqN7cVg/tjZwhLK6JvJZZYzhq+8SfrM49tZ75p Uk/tDalmUy+Qg2eTgr/EFuTxIC5KLd73wf8L460XAcaxyNw2qOPcQkyS8UB1y2BQRkzD w3bQM3ubq29tM6CwqJonSlvbACI1+hzYkAi0MLXhzgIq+hUCDayhVOcSWddK5cpozcQn 1pjVAL5tNcZloSAvnhzwu261yPMri42lP33hnF6TU1SvC0abXpCJGOa5pjWlDfbiErSv lbBVe3lJfTtQJ1KDzK2X5gu+XFG96rtESDUjGuTeAHDLIMq5flV3iWyeK7+Qyd+3c8Qt m7vQ== X-Forwarded-Encrypted: i=1; AJvYcCVzsHu2auNj17XoJ15AIxH9OoUBje0UiPsrJPIsmsDFaCqWrcyKbmTdkFP3aSgbUHJcdw32PZ5LEPbxlko=@vger.kernel.org X-Gm-Message-State: AOJu0Yy6PXcXAPwqJezQqajzGhQJ7nhnSUlhxRXtziMVkDo2r0HMlnfz M/6l9obPxk8HCrPYfeCSbndn6gbS/SKJOZaCS9fmT29xJAgsABbxjYQMH5qTkHE= X-Gm-Gg: ASbGnctOI2HkmHgqsFyKaEFSCtgovnNF/ztPRG/Bo0rIAL3aJQqJX3lrskvFC/oSb5G Zj3fps8QUVil3olNc17IESFSLo94ean7Sx1jkH+SdLV6PkW1n8oqPZEvvjvXVnW1mUGInbW8Nox SujN0h23OADsG9C04ug8xflxo9dTG/pPHuO2ppDBw9xHtKa8B8j897YJM4lYUlFEEdG0DLVMrMi VEVzK1A9MLDYLaXpTKaK02IkR8beOeO7ztLK8o3hxiZxhwgLMBkEeOdtWY/qmrTIPE7ImRKZKsz LeowLI6VTmpjF0f3Q/1aWfuDqm9YpWIrNo8b+GzHjNe09j+NzLt0gfDllbuepQpUfqRr2n5/rBb LaKDN X-Google-Smtp-Source: AGHT+IGXSqzU8y1cmSTygGM2aLfIYSj2l7hrJ3dPPrIwTZ/TmZGV+LoRrdcJncNf2fekVNIFT5waog== X-Received: by 2002:a17:90b:390e:b0:2fe:b8ba:62de with SMTP id 98e67ed59e1d1-301be1f8ecdmr2258008a91.25.1742364807891; Tue, 18 Mar 2025 23:13:27 -0700 (PDT) Received: from sidong.sidong.yang.office.furiosa.vpn ([61.83.209.48]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-301bf589b07sm645103a91.11.2025.03.18.23.13.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 23:13:27 -0700 (PDT) From: Sidong Yang To: Josef Bacik , David Sterba , Jens Axboe , Pavel Begunkov Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org Subject: [RFC PATCH v5 2/5] io_uring/cmd: don't expose entire cmd async data Date: Wed, 19 Mar 2025 06:12:48 +0000 Message-ID: <20250319061251.21452-3-sidong.yang@furiosa.ai> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250319061251.21452-1-sidong.yang@furiosa.ai> References: <20250319061251.21452-1-sidong.yang@furiosa.ai> 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" From: Pavel Begunkov io_uring needs private bits in cmd's ->async_data, and they should never be exposed to drivers as it'd certainly be abused. Leave struct io_uring_cmd_data for the drivers but wrap it into a structure. It's a prep patch and doesn't do anything useful yet. Signed-off-by: Pavel Begunkov --- io_uring/io_uring.c | 2 +- io_uring/opdef.c | 2 +- io_uring/uring_cmd.c | 18 +++++++++++------- io_uring/uring_cmd.h | 6 ++++++ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 7f26ad334e30..5eb9be063a7c 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -335,7 +335,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(str= uct io_uring_params *p) sizeof(struct io_async_rw), offsetof(struct io_async_rw, clear)); ret |=3D io_alloc_cache_init(&ctx->cmd_cache, IO_ALLOC_CACHE_MAX, - sizeof(struct io_uring_cmd_data), 0); + sizeof(struct io_async_cmd), 0); spin_lock_init(&ctx->msg_lock); ret |=3D io_alloc_cache_init(&ctx->msg_cache, IO_ALLOC_CACHE_MAX, sizeof(struct io_kiocb), 0); diff --git a/io_uring/opdef.c b/io_uring/opdef.c index 7fd173197b1e..e4aa61a414fb 100644 --- a/io_uring/opdef.c +++ b/io_uring/opdef.c @@ -416,7 +416,7 @@ const struct io_issue_def io_issue_defs[] =3D { .plug =3D 1, .iopoll =3D 1, .iopoll_queue =3D 1, - .async_size =3D sizeof(struct io_uring_cmd_data), + .async_size =3D sizeof(struct io_async_cmd), .prep =3D io_uring_cmd_prep, .issue =3D io_uring_cmd, }, diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c index 792bd54851b1..7c126ee497ea 100644 --- a/io_uring/uring_cmd.c +++ b/io_uring/uring_cmd.c @@ -19,7 +19,8 @@ static void io_req_uring_cleanup(struct io_kiocb *req, unsigned int issue_= flags) { struct io_uring_cmd *ioucmd =3D io_kiocb_to_cmd(req, struct io_uring_cmd); - struct io_uring_cmd_data *cache =3D req->async_data; + struct io_async_cmd *ac =3D req->async_data; + struct io_uring_cmd_data *cache =3D &ac->data; =20 if (cache->op_data) { kfree(cache->op_data); @@ -169,12 +170,15 @@ static int io_uring_cmd_prep_setup(struct io_kiocb *r= eq, const struct io_uring_sqe *sqe) { struct io_uring_cmd *ioucmd =3D io_kiocb_to_cmd(req, struct io_uring_cmd); - struct io_uring_cmd_data *cache; + struct io_async_cmd *ac; =20 - cache =3D io_uring_alloc_async_data(&req->ctx->cmd_cache, req); - if (!cache) + /* see io_uring_cmd_get_async_data() */ + BUILD_BUG_ON(offsetof(struct io_async_cmd, data) !=3D 0); + + ac =3D io_uring_alloc_async_data(&req->ctx->cmd_cache, req); + if (!ac) return -ENOMEM; - cache->op_data =3D NULL; + ac->data.op_data =3D NULL; =20 /* * Unconditionally cache the SQE for now - this is only needed for @@ -183,8 +187,8 @@ static int io_uring_cmd_prep_setup(struct io_kiocb *req, * that it doesn't read in per-op data, play it safe and ensure that * any SQE data is stable beyond prep. This can later get relaxed. */ - memcpy(cache->sqes, sqe, uring_sqe_size(req->ctx)); - ioucmd->sqe =3D cache->sqes; + memcpy(ac->data.sqes, sqe, uring_sqe_size(req->ctx)); + ioucmd->sqe =3D ac->data.sqes; return 0; } =20 diff --git a/io_uring/uring_cmd.h b/io_uring/uring_cmd.h index f6837ee0955b..2ec3a8785534 100644 --- a/io_uring/uring_cmd.h +++ b/io_uring/uring_cmd.h @@ -1,5 +1,11 @@ // SPDX-License-Identifier: GPL-2.0 =20 +#include + +struct io_async_cmd { + struct io_uring_cmd_data data; +}; + int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags); int io_uring_cmd_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe= ); =20 --=20 2.43.0 From nobody Wed Dec 17 08:56:18 2025 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 0BBCD2505B6 for ; Wed, 19 Mar 2025 06:13:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742364812; cv=none; b=Yus1mtlm94E8tGVasCVOl7rQdYTKcMX0go6oFD+brG38MWqaNXc4i0xjMxUU7Uf9vR2CVuU0hLfmX1GmQJzsQBn4Yxn2tLaHV6wbCbi5CQAmCtBXJ+4w7vDhhhRiy5dzfgd3buLjnI9FIVUqvrumBULxfrmMaDboKpNb2TI4Rc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742364812; c=relaxed/simple; bh=mbXqG+VTiVNDPa0Fi621P5lQqETDJPz9dw0maRf2RLE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hm6acSxa6PNTXwBk+HoFJbnBHgAsbbnRLL7ixMHF8piqIDI2wQ8pY8UJijjxJ6YO/tQ1GyCH3f8A8YYCkScRDHCICraHfHdIsdev3Ma+mYFBTR59u44IcNBQZsFAR+X1Gnz/SGPpoSYVjapfsSYc9w7GosXTce+T6LAQ0/3lia4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=furiosa.ai; spf=none smtp.mailfrom=furiosa.ai; dkim=pass (1024-bit key) header.d=furiosa.ai header.i=@furiosa.ai header.b=MAH5+K1d; arc=none smtp.client-ip=209.85.216.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=furiosa.ai Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=furiosa.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=furiosa.ai header.i=@furiosa.ai header.b="MAH5+K1d" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-301a4d5156aso2439921a91.1 for ; Tue, 18 Mar 2025 23:13:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=furiosa.ai; s=google; t=1742364810; x=1742969610; 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; bh=Mh8BnNc+9/8hJHF7wOcyjiM5crihBkkiiF/ddYF+Pzo=; b=MAH5+K1dsnpvMY4su3MtbJYISmB8e8AuY8ZMJbIQU8Yw72LWhos4pSVCGeYYg6axY/ 0peBIFlZ4c8ZUBbiyT4yx18FIE7e0wFgxwxNpZ4mfO7B2L8XThxARABjK+niTY08R+eR 3zMbvbUSTT1DWklscrAduvLF+ilx0brFUKa20= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742364810; x=1742969610; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Mh8BnNc+9/8hJHF7wOcyjiM5crihBkkiiF/ddYF+Pzo=; b=TYhGAtYNS2g+HvxK5qJK4Bk5KdnF0t81KwN1v3HLgFbPHdguLPsg/JbixopkPweFby jbEguqjjQWgy0b5RZvD2+oD/T9RHEcAZ3iCv33xmezsyGN7sTGe/hJJ3K7rjPtxP5P+r WemUn8rQDVlt524F8iZ7aVSSN7YAaeToWi06SclqMQ4icpTnQrZ1PChdbRebLKf1+yMf mrPTlh62RrN/xgEg3ivb/f7IfYK6sOZ6rY2zRcCRbqf9sSRhF2nDCVWdqQemwwVncnli UT7ZNw1oowmsdaKYQ9+GvzQXKHVr6u465ZlYMwVcKelet2hqWm0hmcT9Q1ttgR/Pl1ym jS6A== X-Forwarded-Encrypted: i=1; AJvYcCV0RtsZAPP+e00f6gbWZtHui72bhuXBaYyDzonTGLirZtmziCTLQfa5lSO3RXi+LpvZEv/DYNyjzk2U4WA=@vger.kernel.org X-Gm-Message-State: AOJu0YxKnYzBDNVqhEpqa2NG3wul6K60kma071DqujauDApkeAbVDNHl wTa9LRFsHJDWXco/p8EOTOLrP8nP4fV6aDx/+hHbnRpmfX78wI1DCrZYCBUps4h0+DFL3zAYWBu 1 X-Gm-Gg: ASbGncuXVqQBm108lRyiS/vO68fiNtSjIz0lQ6IiWHtJkgpsQfdkFdSJCmBkVI2aWqp zDKwH5isfBSz7z2WDmMJ9DbnXY7rd08gvtSNxLsH6Dj8426G66Ki8UgcBMWNdKL6w8n03ugJgo/ hzaO4eUPLr65rusTbr0fGeomGkIR384y6y7y1k1Wjmw2WNzGWIvPEWRVq2mCa3/8epNDgcMC2qO F5FYsfEY8MDB6w7geWp3A1bVNHQxUqSU34eJAyXAbu1ezsRfAqaRpkRCcB5Udmn53hnY9qilqpb kjIeeNHcSORwAFj4JtajwdMwwA1v5YAGcS9W34hPzu8NMk2QMGZzmsrBdW6GT6GGJ/5X21YJra1 fJqDt X-Google-Smtp-Source: AGHT+IHdbGO2urDOPCZIrJkjwT3bv9l2w3k2XVp7akC+vU69YG4/FJ7qndudn2Bzmp/K9qg91BFgbw== X-Received: by 2002:a17:90b:224c:b0:2fe:b907:562f with SMTP id 98e67ed59e1d1-301bdf84fb6mr2588150a91.14.1742364810240; Tue, 18 Mar 2025 23:13:30 -0700 (PDT) Received: from sidong.sidong.yang.office.furiosa.vpn ([61.83.209.48]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-301bf589b07sm645103a91.11.2025.03.18.23.13.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 23:13:29 -0700 (PDT) From: Sidong Yang To: Josef Bacik , David Sterba , Jens Axboe , Pavel Begunkov Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org Subject: [RFC PATCH v5 3/5] io_uring/cmd: add iovec cache for commands Date: Wed, 19 Mar 2025 06:12:49 +0000 Message-ID: <20250319061251.21452-4-sidong.yang@furiosa.ai> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250319061251.21452-1-sidong.yang@furiosa.ai> References: <20250319061251.21452-1-sidong.yang@furiosa.ai> 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" From: Pavel Begunkov Add iou_vec to commands and wire caching for it, but don't expose it to users just yet. Signed-off-by: Pavel Begunkov --- io_uring/io_uring.c | 2 +- io_uring/opdef.c | 1 + io_uring/uring_cmd.c | 20 ++++++++++++++++++++ io_uring/uring_cmd.h | 5 +++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 5eb9be063a7c..8ef93ce4a539 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -289,7 +289,7 @@ static void io_free_alloc_caches(struct io_ring_ctx *ct= x) io_alloc_cache_free(&ctx->apoll_cache, kfree); io_alloc_cache_free(&ctx->netmsg_cache, io_netmsg_cache_free); io_alloc_cache_free(&ctx->rw_cache, io_rw_cache_free); - io_alloc_cache_free(&ctx->cmd_cache, kfree); + io_alloc_cache_free(&ctx->cmd_cache, io_cmd_cache_free); io_alloc_cache_free(&ctx->msg_cache, kfree); io_futex_cache_free(ctx); io_rsrc_cache_free(ctx); diff --git a/io_uring/opdef.c b/io_uring/opdef.c index e4aa61a414fb..489384c0438b 100644 --- a/io_uring/opdef.c +++ b/io_uring/opdef.c @@ -755,6 +755,7 @@ const struct io_cold_def io_cold_defs[] =3D { }, [IORING_OP_URING_CMD] =3D { .name =3D "URING_CMD", + .cleanup =3D io_uring_cmd_cleanup, }, [IORING_OP_SEND_ZC] =3D { .name =3D "SEND_ZC", diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c index 7c126ee497ea..abcc1ad236ef 100644 --- a/io_uring/uring_cmd.c +++ b/io_uring/uring_cmd.c @@ -16,6 +16,14 @@ #include "rsrc.h" #include "uring_cmd.h" =20 +void io_cmd_cache_free(const void *entry) +{ + struct io_async_cmd *ac =3D (struct io_async_cmd *)entry; + + io_vec_free(&ac->vec); + kfree(ac); +} + static void io_req_uring_cleanup(struct io_kiocb *req, unsigned int issue_= flags) { struct io_uring_cmd *ioucmd =3D io_kiocb_to_cmd(req, struct io_uring_cmd); @@ -29,6 +37,13 @@ static void io_req_uring_cleanup(struct io_kiocb *req, u= nsigned int issue_flags) =20 if (issue_flags & IO_URING_F_UNLOCKED) return; + + req->flags &=3D ~REQ_F_NEED_CLEANUP; + + io_alloc_cache_vec_kasan(&ac->vec); + if (ac->vec.nr > IO_VEC_CACHE_SOFT_CAP) + io_vec_free(&ac->vec); + if (io_alloc_cache_put(&req->ctx->cmd_cache, cache)) { ioucmd->sqe =3D NULL; req->async_data =3D NULL; @@ -36,6 +51,11 @@ static void io_req_uring_cleanup(struct io_kiocb *req, u= nsigned int issue_flags) } } =20 +void io_uring_cmd_cleanup(struct io_kiocb *req) +{ + io_req_uring_cleanup(req, 0); +} + bool io_uring_try_cancel_uring_cmd(struct io_ring_ctx *ctx, struct io_uring_task *tctx, bool cancel_all) { diff --git a/io_uring/uring_cmd.h b/io_uring/uring_cmd.h index 2ec3a8785534..b45ec7cffcd1 100644 --- a/io_uring/uring_cmd.h +++ b/io_uring/uring_cmd.h @@ -1,13 +1,18 @@ // SPDX-License-Identifier: GPL-2.0 =20 #include +#include =20 struct io_async_cmd { struct io_uring_cmd_data data; + struct iou_vec vec; }; =20 int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags); int io_uring_cmd_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe= ); +void io_uring_cmd_cleanup(struct io_kiocb *req); =20 bool io_uring_try_cancel_uring_cmd(struct io_ring_ctx *ctx, struct io_uring_task *tctx, bool cancel_all); + +void io_cmd_cache_free(const void *entry); --=20 2.43.0 From nobody Wed Dec 17 08:56:18 2025 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (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 7ECB9250BE8 for ; Wed, 19 Mar 2025 06:13:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742364816; cv=none; b=HFZUCh05O+zW2bGZfekG+vrgWW0cE9J0Li8ldSkBBbOy5Wk6XJFtiFXfFfOPX1RH0qZDeAuO9XSaJQhEEB4UPTsaiuNPz5ad/waPyuq5BCw0pLdKxU3QzNE7/YJEbH2g/ABMi7PfyV2ZYVmkQ1FVJkWgAX2MeItlmT3QmL9+WN8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742364816; c=relaxed/simple; bh=oYciIjC4rs6s5STw/xs6kdWP2TAKeNAc+tUFNO4Yp0w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KCiCVGWf9c/yQxdxamft6XtFfbFFiXEXDg8jmBQCHEaeW1TAxpu2BU8AMzMC2eaBJw/ZCyJsoXnZmNTPr2y9PFi4Gop+eAVSb1i5GsHCCrzWb8EKciJK3YWOk2zXQwFEmgjVQSvip2hxmqX+5BP++xKzVonyUwvL4UW5ZHcNCwk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=furiosa.ai; spf=none smtp.mailfrom=furiosa.ai; dkim=pass (1024-bit key) header.d=furiosa.ai header.i=@furiosa.ai header.b=ZOqsCtpu; arc=none smtp.client-ip=209.85.216.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=furiosa.ai Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=furiosa.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=furiosa.ai header.i=@furiosa.ai header.b="ZOqsCtpu" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-2ff6e91cff5so6383944a91.2 for ; Tue, 18 Mar 2025 23:13:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=furiosa.ai; s=google; t=1742364813; x=1742969613; 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; bh=autIi02mQOQDOvMtdJVsC4xB36voEA7M/gHvacF/Km8=; b=ZOqsCtpuDhkCuT/HVOSTKeII4BQgwD+IEaHELWGBGVFV5CaW4p4AxqQx5sCjq00iBT aOF9iY7sJgPGztT9MCusn3ES/hI/8ZK4ycbQ/Y9CVma7YFtL6MXb0FQSALzPgtVOyx+D BupwtJFCJxxCgNiA8tLjpgYHDqiQYk+fNWopU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742364813; x=1742969613; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=autIi02mQOQDOvMtdJVsC4xB36voEA7M/gHvacF/Km8=; b=qpbZ5VhbTRMXoIkxsFWU0qQz8GWdRq4zS+6WI5hlku/ZRy5cEdKY+sAh6dKK8+Bqxv OXc2GZqpFIjcnH83uIqzss1W+bHS/bxZjRTxQ0W0I4YORMkUGr7X0Il0N3n4s6QwyWxi mT+6qzkQgyD3NUJyFozKWTRMUgXFelVcADzLwY6bjc5FE5CaEyJe5Cg6NV1EtOfBYS+P aT3pVRaHngdZyZuzaecYg1z6eXwtLubslUCzBXU/ch9ibE2iN4159f/WgCVvuQN8Gwi/ ve9ruE4VdqV4t+WAPzL3FoE9STZiHWXNS52uybLIde7gdmelGSZfl0wtnXBT4VGKZmTJ Wg4Q== X-Forwarded-Encrypted: i=1; AJvYcCUm7UkIG1T6JpBQ553ivoAsf4I6xpMQYcm+w8jd0pFy4TrZfTzHC2+X8vF3zwgS6fOkU5bZ+Ti0yWR2O0E=@vger.kernel.org X-Gm-Message-State: AOJu0YwlcnwnYtGGX9Oy7whe0oKhRnIvh9SDOE4LUebWebCiQVOhzPgP Cy/jxu6WNqsBo69x/+/Cvhdn9xFwX3NSLjc3DjEADk0/9YpGJRyII8DcjLBO0z8= X-Gm-Gg: ASbGnctnrc89rHGCHUHYeq00eYhi/CrjMJAoCea4upqaYBw7ECoglatp1GzZdUH03/2 fNSdcd2TXOQnc1HakXIz9IB4uT6DZ8FG3Tinepb3GP1qnEQwqW3AEmAdDEz2LENWB9iVHOgJlku JWi429iiCbYEFhRVM1sEn61sGGP+Tyfgodx120IPCx2yZYDOsdpJh5DCcz1eX88E0TS47KxNna3 atmyb5nfFfz1jxgr0w3nmZEwf+MovlcpUzmHGDzQcDjeVUQDSFh829hnCzujtZI+kMsPzOsV/rA dtQdfROCmQ3/iso58hndf9XRHwS8lZcrkFVGjHDGoajFIpYly8ftJTSnjTlX801q9P7MH2OHov9 aHATQ X-Google-Smtp-Source: AGHT+IEai+OcJT8yk913mhD/xW86Gxo7BwT+qp3PGV+FzY19u9roByHP0Sc4MTXXudcClCLxtzma/g== X-Received: by 2002:a17:90b:3ec1:b0:2ef:67c2:4030 with SMTP id 98e67ed59e1d1-301be1d94d1mr2484193a91.27.1742364812826; Tue, 18 Mar 2025 23:13:32 -0700 (PDT) Received: from sidong.sidong.yang.office.furiosa.vpn ([61.83.209.48]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-301bf589b07sm645103a91.11.2025.03.18.23.13.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 23:13:32 -0700 (PDT) From: Sidong Yang To: Josef Bacik , David Sterba , Jens Axboe , Pavel Begunkov Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org Subject: [RFC PATCH v5 4/5] io_uring/cmd: introduce io_uring_cmd_import_fixed_vec Date: Wed, 19 Mar 2025 06:12:50 +0000 Message-ID: <20250319061251.21452-5-sidong.yang@furiosa.ai> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250319061251.21452-1-sidong.yang@furiosa.ai> References: <20250319061251.21452-1-sidong.yang@furiosa.ai> 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" From: Pavel Begunkov io_uring_cmd_import_fixed_vec() is a cmd helper around vectored registered buffer import functions, which caches the memory under the hood. The lifetime of the vectore and hence the iterator is bound to the request. Furthermore, the user is not allowed to call it multiple times for a single request. Signed-off-by: Pavel Begunkov --- include/linux/io_uring/cmd.h | 13 +++++++++++++ io_uring/uring_cmd.c | 19 +++++++++++++++++++ io_uring/uring_cmd.h | 6 ++++++ 3 files changed, 38 insertions(+) diff --git a/include/linux/io_uring/cmd.h b/include/linux/io_uring/cmd.h index 598cacda4aa3..e6723fa95160 100644 --- a/include/linux/io_uring/cmd.h +++ b/include/linux/io_uring/cmd.h @@ -43,6 +43,11 @@ int io_uring_cmd_import_fixed(u64 ubuf, unsigned long le= n, int rw, struct iov_iter *iter, struct io_uring_cmd *ioucmd, unsigned int issue_flags); +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 /* * Completes the request, i.e. posts an io_uring CQE and deallocates @iouc= md @@ -76,6 +81,14 @@ io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, i= nt rw, { return -EOPNOTSUPP; } +static inline int io_uring_cmd_import_fixed_vec(struct io_uring_cmd *ioucm= d, + const struct iovec __user *uvec, + size_t uvec_segs, + int ddir, struct iov_iter *iter, + unsigned issue_flags) +{ + return -EOPNOTSUPP; +} static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, u64 ret2, unsigned issue_flags) { diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c index abcc1ad236ef..c3eb2c263520 100644 --- a/io_uring/uring_cmd.c +++ b/io_uring/uring_cmd.c @@ -279,6 +279,25 @@ int io_uring_cmd_import_fixed(u64 ubuf, unsigned long = len, int rw, } EXPORT_SYMBOL_GPL(io_uring_cmd_import_fixed); =20 +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) +{ + struct io_kiocb *req =3D cmd_to_io_kiocb(ioucmd); + struct io_async_cmd *ac =3D req->async_data; + int ret; + + ret =3D io_prep_reg_iovec(req, &ac->vec, uvec, uvec_segs); + if (ret) + return ret; + + return io_import_reg_vec(ddir, iter, req, &ac->vec, uvec_segs, + issue_flags); +} +EXPORT_SYMBOL_GPL(io_uring_cmd_import_fixed_vec); + void io_uring_cmd_issue_blocking(struct io_uring_cmd *ioucmd) { struct io_kiocb *req =3D cmd_to_io_kiocb(ioucmd); diff --git a/io_uring/uring_cmd.h b/io_uring/uring_cmd.h index b45ec7cffcd1..14e525255854 100644 --- a/io_uring/uring_cmd.h +++ b/io_uring/uring_cmd.h @@ -16,3 +16,9 @@ bool io_uring_try_cancel_uring_cmd(struct io_ring_ctx *ct= x, struct io_uring_task *tctx, bool cancel_all); =20 void io_cmd_cache_free(const void *entry); + +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 2.43.0 From nobody Wed Dec 17 08:56:18 2025 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 2D77A250BE5 for ; Wed, 19 Mar 2025 06:13:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742364817; cv=none; b=ox6FTUGlB/304P/1rln4yAIGcC8+9GneakaCqlfR0eBJXfmlurr7NOuM9b/Vb4W72fswIZpzg53vqOt8KyqTMMuUWKZObjmUhX6OhJeH3P4XL+OCQP0bVqkCCRS6A+dbij6Z1XgV4lX3PYPPX0/MqHuz67os/AoRyU4we+p0o2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742364817; c=relaxed/simple; bh=eyjj1uHvjzoEdaKMraFRmuVcUzgVgA4sRhGNzePsgog=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TY0/ZaBYXxYeU9blqHcFI90oMG4A6YvPsYpxBV4aBRaBK1lccgBwSVbbbVFiXiwIWhPEhYgT7S89VFVqMR3B1Fby/k0zi0iO0z8xxWOllbbdCNsPFSXyAxQhFGVqAQ5sllrFe6txsJlsaMdHbFdIJHwAw6SDLNlNroeXM40X+yU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=furiosa.ai; spf=none smtp.mailfrom=furiosa.ai; dkim=pass (1024-bit key) header.d=furiosa.ai header.i=@furiosa.ai header.b=cm+X6FzY; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=furiosa.ai Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=furiosa.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=furiosa.ai header.i=@furiosa.ai header.b="cm+X6FzY" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-225fbdfc17dso61135555ad.3 for ; Tue, 18 Mar 2025 23:13:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=furiosa.ai; s=google; t=1742364815; x=1742969615; 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; bh=Ae4PagFT38IepvXpzRbslA5V5XToKvo9V6NCx8IDEps=; b=cm+X6FzYD6gd65QlfG6VCTMkgJ4vWA1Z3zUvNtRUcOru8BnVt4wYYoxI9X/10J4NW7 IbwwOXJpt5Bob+1aWQFnfPImETJTDUJFwxOEKisDdCxBuz151KnSwXJAJxru1FGDkop5 Ik2l98iMPOzB2VPZmaDzqeoEQK7FSHI2ENKHA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742364815; x=1742969615; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ae4PagFT38IepvXpzRbslA5V5XToKvo9V6NCx8IDEps=; b=RPjq5I3p0ciOGKPuF3S2PlT2MmT1prcVvflhZwr19q/AQnALUMaHj3JJGwgIlD4/q6 KCldl2fHryfKO/91nYQz9h4N+qtB5WJ0tqM5WSNP1/3gCd9ic8Yt/k1Sg6fxAEid2Zcw nPkdPHt9Ke0TIkfHce5HhRG5Nsi4/B/64WFk5/qanbP0KPlVaFsUXqFAElTi42JUIE26 d4SwtC40SreKWwDeG/T8eqMA2C+v15dcnxTXf4ddx7JPXWvLUtn6QdGFVTjq1lPvkKwT YZpdjhE4j8WY3XrfpLtavbmxboCkW0V4tnQyo5IcEzMdUtcrJ2bjHdqSZuWiTyVIXKjd 8QbA== X-Forwarded-Encrypted: i=1; AJvYcCUncWCCxr2WVa2IDG6c1qSmrD+McYX78aamoSqxqVsq3WzfYqr+YAOclQzWa6PUALLQVz9TLhppK3LbJOo=@vger.kernel.org X-Gm-Message-State: AOJu0YzGa3yRsL7mkeLLSSy338Gk/K3ulvY0RkYYpD0sfucEItA5K5lR ljiWnMPLO5eeAE3i/KqucbkY8jsqQ6JUP36LwvdyqoRQQJ8CUPKXjDsV70mUSeA= X-Gm-Gg: ASbGncsli6HhcpQhStYOgyV+IyiR6rDMGRfbLHCRk+6bXqX8drjOVD+C62D07KWou/h ahlmnpsx0MmbTwThlT9WXncWRzDkcLqbGjeRCA4ab5oEoRaLARVXFuS4qR/Rjrin99FKmZlbcdz IAq/mInKLIVGc8FfuULi9HgTwoFyhKJK4OagtNVtVrstQ0NQpPhiUY8MitvGEMTmRvjy08aqKUW cs73UDtG8ULdHyEsmkz3ixn1b44AQdsifFOhAXgtYS7W4JMXovz4FxBiRicO0rnZQHtUxUCViEJ 7CZB5HG4pY5p/MqDjUibuDm08TsWDLYTExeJtHSIUl3cdAOWzqSWd7EexoiZ5rCQvcu/KXfzQ/o DwMg7 X-Google-Smtp-Source: AGHT+IHce4wHjB8TrjarMeRb5jF9Qk1EWj8yU9d+p762t9eiTgkZ3MdU6c4esyFK68gM71Y2X9wSlA== X-Received: by 2002:a17:902:e5c6:b0:223:5e6a:57ab with SMTP id d9443c01a7336-22649a7c112mr19578105ad.39.1742364815445; Tue, 18 Mar 2025 23:13:35 -0700 (PDT) Received: from sidong.sidong.yang.office.furiosa.vpn ([61.83.209.48]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-301bf589b07sm645103a91.11.2025.03.18.23.13.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 23:13:35 -0700 (PDT) From: Sidong Yang To: Josef Bacik , David Sterba , Jens Axboe , Pavel Begunkov Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, Sidong Yang Subject: [RFC PATCH v5 5/5] btrfs: ioctl: introduce btrfs_uring_import_iovec() Date: Wed, 19 Mar 2025 06:12:51 +0000 Message-ID: <20250319061251.21452-6-sidong.yang@furiosa.ai> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250319061251.21452-1-sidong.yang@furiosa.ai> References: <20250319061251.21452-1-sidong.yang@furiosa.ai> 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" This patch introduces btrfs_uring_import_iovec(). In encoded read/write with uring cmd, it uses import_iovec without supporting fixed buffer. btrfs_using_import_iovec() could use fixed buffer if cmd flags has IORING_URING_CMD_FIXED. Signed-off-by: Sidong Yang Reviewed-by: Pavel Begunkov --- fs/btrfs/ioctl.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 6c18bad53cd3..e5b4af41ca6b 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -4802,7 +4802,29 @@ struct btrfs_uring_encoded_data { struct iov_iter iter; }; =20 -static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int= issue_flags) +static int btrfs_uring_import_iovec(struct io_uring_cmd *cmd, + unsigned int issue_flags, int rw) +{ + struct btrfs_uring_encoded_data *data =3D + io_uring_cmd_get_async_data(cmd)->op_data; + int ret; + + if (cmd->flags & IORING_URING_CMD_FIXED) { + data->iov =3D NULL; + ret =3D io_uring_cmd_import_fixed_vec(cmd, data->args.iov, + data->args.iovcnt, rw, + &data->iter, issue_flags); + } else { + data->iov =3D data->iovstack; + ret =3D import_iovec(rw, data->args.iov, data->args.iovcnt, + ARRAY_SIZE(data->iovstack), &data->iov, + &data->iter); + } + return ret; +} + +static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, + unsigned int issue_flags) { size_t copy_end_kernel =3D offsetofend(struct btrfs_ioctl_encoded_io_args= , flags); size_t copy_end; @@ -4874,10 +4896,7 @@ static int btrfs_uring_encoded_read(struct io_uring_= cmd *cmd, unsigned int issue goto out_acct; } =20 - data->iov =3D data->iovstack; - ret =3D import_iovec(ITER_DEST, data->args.iov, data->args.iovcnt, - ARRAY_SIZE(data->iovstack), &data->iov, - &data->iter); + ret =3D btrfs_uring_import_iovec(cmd, issue_flags, ITER_DEST); if (ret < 0) goto out_acct; =20 @@ -5022,10 +5041,7 @@ static int btrfs_uring_encoded_write(struct io_uring= _cmd *cmd, unsigned int issu if (data->args.len > data->args.unencoded_len - data->args.unencoded_off= set) goto out_acct; =20 - data->iov =3D data->iovstack; - ret =3D import_iovec(ITER_SOURCE, data->args.iov, data->args.iovcnt, - ARRAY_SIZE(data->iovstack), &data->iov, - &data->iter); + ret =3D btrfs_uring_import_iovec(cmd, issue_flags, ITER_SOURCE); if (ret < 0) goto out_acct; =20 --=20 2.43.0