From nobody Wed Dec 17 13:55:42 2025 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (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 848A7241684 for ; Mon, 17 Mar 2025 13:57:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742219879; cv=none; b=icNmm2eYL8NO9UhEV0scNEnAZTySWRZbh7CT5TwJNd6ANP8oe8uDHHTxm/fCCL5ua02ZmspPF7tJOvVqJoO1YqSl90bjSoMgmALFBHJ0lJEAppajdtzQKDp7GbB8kFgCAmTelivzRmJTW3lNFTKkle3WWGQ29X4rG82F3+C3Q58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742219879; c=relaxed/simple; bh=A9g/LrEtdhtW/MmP/tsNzLw+P7Qu4pr41B1T0nC/w3s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X1IOhlp33EyPN1GYLRS7FoRs+uSA4RnbPfDqZuDYba9keePAWu7/9qI7Kc3vf6xneCr/V2gQUS2Q50luo2/dDXViNwD9xQdGBc6N9bbC3Crtegtznc767OeT04bkGEuipqHJbm+7z5HvrnhKvDbdHAbb1xzQ9o1xbX6i9/0PMEE= 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=kW9T+5q0; arc=none smtp.client-ip=209.85.216.48 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="kW9T+5q0" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-2ff80290e44so3785853a91.0 for ; Mon, 17 Mar 2025 06:57:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=furiosa.ai; s=google; t=1742219877; x=1742824677; 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=Xpw7J2fiIuJ4upLXrHzc6RkW8KJ4iba1XK12Qdwis60=; b=kW9T+5q01cjNBZEQFQCCuboFl05UUxo87H3V6shasojD2qt0zQaSL5tF4lS1YryZdA wy3Mv12DMmLuXFgK+ZX5zBbcSWeXAVtCiI/iTbkFQL9ORjobkBYJVR2ZgkgFbSXvLCV3 zTlNHzDTvBlBihYXGumIswzjH7aGJprN8HeCs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742219877; x=1742824677; 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=Xpw7J2fiIuJ4upLXrHzc6RkW8KJ4iba1XK12Qdwis60=; b=IkdxLsTVNrqdAFS4Ik0XIYcwamYXy+/EMULIIN38QsVPKLzWA7KaJTidDQApGzboKY CVQSn635Sx4NYaYdD6ijDiZ01tC+kiA72Ly0cIJwJBGxSsbEF6gPFDZLA0+e9N/E4Abz rmotrpJb3Sw1+szZuUSqXN1O4+No7cM9F4s0tRaRSE6J15p6qrX7zHX32FYCKJd6BSEo S4HKmVfUAaNtnWviSQEYlMGksUSVHFUjRepQnAgfGPGx9/iYI0xMMPqYrc5B3lyiiJY0 HOENpThVNFvCb/KgjcZnX7yC4I/AoVLKgnR4V29HE0k0cfv1MM1lgitalfnnZjQfdej6 jjnQ== X-Forwarded-Encrypted: i=1; AJvYcCXyEniVyhzfEuPTXkF8sGN6sj6TLC0uc8KA9Ft0OgYGmH5empp8RItoKLFN+FSqBfVte3sMEwXFMPJdQqI=@vger.kernel.org X-Gm-Message-State: AOJu0YzWnp4GC1Y+5ORsCZiOrvzScBnWIukgM23y9rJvcJawweR4Euhg RuNCnkInyIJtMyZagoxFCD/tqW7N4U8ByKrJsE4HlZ1NdGnkQvZK8mlaCToyhLY= X-Gm-Gg: ASbGnctnxwD0RB0cpcK3u6oO5wpWqrCfMd5Tig1QxSLX2vg+pv1vqQA5KBYhDMVUPOk 86KWyZM4uELcXAEUnPn/nOvuS+am37iGvc8lEuwRO48wDLmc0icPNYF+E3F7rghdPjGPBdYv775 os7mv+8L04cpuyfzvanD3ZR2bpr7E1kLTP2DlD7OZVRgi89twnhDdyd5dtrwLTtRTlOWZqlTpYk 0aLBDTBQj4UkA1F2fPeaxyEFfTN0NJX/JGq3HBFRmduGthPp3wFzcxd3YBSie8GBcL6cdH3fYiF y5sDHmdUv6RP37k2E4ehJyg0wTOb4W8i4JEBdLLGkPMKMy2y6CuBs7DS1H90xoFj4om1pSoOBRO LzvfMDWQ1XScyHko= X-Google-Smtp-Source: AGHT+IFP2188UAaoN4VlSu0tKYL92dtV5f8yHioDJyjQGx6rjRnXF/au3otxmx+1j694si5SwniPrQ== X-Received: by 2002:a17:90b:2cd0:b0:2fe:b8b9:5aa6 with SMTP id 98e67ed59e1d1-30151d8182dmr14008918a91.31.1742219876874; Mon, 17 Mar 2025 06:57:56 -0700 (PDT) Received: from sidong.sidong.yang.office.furiosa.vpn ([61.83.209.48]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-30153b99508sm5993742a91.39.2025.03.17.06.57.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Mar 2025 06:57:56 -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 v4 1/5] io_uring/cmd: introduce io_async_cmd for hide io_uring_cmd_data Date: Mon, 17 Mar 2025 13:57:38 +0000 Message-ID: <20250317135742.4331-2-sidong.yang@furiosa.ai> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250317135742.4331-1-sidong.yang@furiosa.ai> References: <20250317135742.4331-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" io_uring_cmd_data should not be exposed for drivers to avoid to be abused its private fields. io_async_cmd is new struct that has io_uring_cmd_data for offset 0. So driver could be use async_data as io_uring_cmd_data as used before. And private fields would be added in io_async_cmd. Signed-off-by: Sidong Yang --- io_uring/io_uring.c | 2 +- io_uring/opdef.c | 2 +- io_uring/uring_cmd.c | 21 ++++++++++++++------- io_uring/uring_cmd.h | 6 ++++++ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 5ff30a7092ed..513f036bccbb 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->uring_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 de39b602aa82..e4cd6fe9fd47 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,18 @@ 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->uring_cache, req); - if (!cache) + /* + * 'data' must be at offset 0 to allow casting io_async_cmd to + * io_uring_cmd_data in 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->uring_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 +190,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..f3593012658c 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 13:55:42 2025 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (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 05DD324168D for ; Mon, 17 Mar 2025 13:57:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742219881; cv=none; b=BDqxoFwLki2ClWpcApL615OCBHO606CcKYEmQRZ3KdmD9DX1ucEZnrE/4Gv4+TBNO4Ttykf9MNPfzb3EvWZV0lPzdqaLx2OARyAZiPeq6eCLjbtbGPL2vvu3xbAB8qzd99k8pzxkaM/3QS+44sOC/aYf1dFgas62Jx0njVlijBg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742219881; c=relaxed/simple; bh=MUln8dzk96jrS8N7WaQSszZ2y7lpJFghuGsy5mJDX7w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bi8YXoFE3Dhc8San2SN28UmrSSVfkTXBXZ/TBpsAnBzrfCTkm4UYBSaw+CV/0uz3gCWPj5hTHIax9dvYFCCnFMQlkGN6pXZIETFU52X/8r54vIbnybc7nxqR8355Ljup0Oir26/hrT4NvAtJLRQ/D4Ew4GmTEqKm/I4GII/eVNI= 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=dKUQoHMD; arc=none smtp.client-ip=209.85.216.47 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="dKUQoHMD" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2ff797f8f1bso2870650a91.3 for ; Mon, 17 Mar 2025 06:57:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=furiosa.ai; s=google; t=1742219879; x=1742824679; 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=YQa2yXoRrARN2BUDV+ngN+TPs4QoczcMbvd+w0pXTw8=; b=dKUQoHMD1mdhkIi4cVWcT90C8UdRh3hl4zoLdBuAW3lkrBY+EdQuAr4rKTFTpzWply Bwi0v+u2F+MQwPBHe/KkDp9XKb/AAO4CIh4tctu1O9hG0Ssz4ds3/1hnX+VaJo7Y8Fdq B4amqLcAVfk/fOx/4ItI6C8MAuEKkbxCIrcPQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742219879; x=1742824679; 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=YQa2yXoRrARN2BUDV+ngN+TPs4QoczcMbvd+w0pXTw8=; b=u5RsST32iHt28qFW9rvNjzBO3x3e+wvnV/XHcKs2Y8hINJpxd9+ItiqJDX7CU7suZr I7S/+Pc/7SzD55NfKNWvKOzWq7UL4wQGMf1TK1nQgI5XWu4KEldQiEm0A1YgZ4XlUhoT cy7VNmJNNUdWM89KoTyjiKfbaEGOHmqFfVem8ET99CMh08TJTkSSXM73ecN/QMiHS64k f2d/uJHzUjNz/i8ugWrtbwrwa/0n/4qqyGxcS8DeYpY5FhMlY9Kvs/Oxb6n07x3HonH9 fYwnYSscgXcobz82PMSPlDinAgob4Zfo5tm8v00lsGQv+p1Pdogqyw5rxyyOKZmv+Hli u6LQ== X-Forwarded-Encrypted: i=1; AJvYcCUdRRXinsDKW2i68Dt/Vke38AgExLQ0dkM/3O8xKyxeq0ai0V0m6XBRBJLQp/FWTkW4OKTvLeD+gR+5P0I=@vger.kernel.org X-Gm-Message-State: AOJu0YwDTvDKbNfyXqpiweHgQtNuG+qh+K3607juVfbbUmj8SYixLvyP 3R/r2NvCBsM4dWrouiChIdp+Rh+5IqDHqEC8tpFFDyoTevxGMWXsFuo6syv9vyM= X-Gm-Gg: ASbGncsDdnyygycrZNXeD1VRCGcS1eKjhDZvmb9GW93DVZjlkQe42jT1nVyL7Yl1sHE Anmwzxbuctn89EqMGPkadJXOKHPhqFGb+4G+dKI+8RjmU2uDrQBVW4au+Gvj7iHG6FfKUClwP10 hzfB6lo6ndhNvDTQQpUeesr5E5TZxQx0509X295INYwVbuMsV5KM2dz42LgG4ttMTJkCviXFBU/ xnNpzHqN0qzROmqdkwU+hiIP/ts6kSEH/PmhTA93F1juMpTKQHpAnbMtHPkSwibwYyhGPPw6dk6 Gx+Ef9NLYLMDr7PV2VN0GQeqPcw6A3kVVE04cdZI42HCDOKDDlaLoywwbdemrvrmbojIOojZTLK 3Yfma5PZ6K8tOzrU= X-Google-Smtp-Source: AGHT+IE1Y7pp7Us6sxXqWDZ6744BRQUSCXKFnFGSNVTBGDp4dsbg+5u3su0ELJH3VSZUrZsckswABQ== X-Received: by 2002:a17:90b:3145:b0:2fe:a336:fe65 with SMTP id 98e67ed59e1d1-30151cd2dc5mr16694880a91.10.1742219879425; Mon, 17 Mar 2025 06:57:59 -0700 (PDT) Received: from sidong.sidong.yang.office.furiosa.vpn ([61.83.209.48]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-30153b99508sm5993742a91.39.2025.03.17.06.57.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Mar 2025 06:57:59 -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 v4 2/5] io-uring/cmd: add iou_vec field for io_uring_cmd Date: Mon, 17 Mar 2025 13:57:39 +0000 Message-ID: <20250317135742.4331-3-sidong.yang@furiosa.ai> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250317135742.4331-1-sidong.yang@furiosa.ai> References: <20250317135742.4331-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 adds iou_vec field for io_uring_cmd. Also it needs to be cleanup for cache. It could be used in uring cmd api that imports multiple fixed buffers. Signed-off-by: Sidong Yang --- io_uring/io_uring.c | 2 +- io_uring/opdef.c | 1 + io_uring/uring_cmd.c | 20 ++++++++++++++++++++ io_uring/uring_cmd.h | 4 ++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 513f036bccbb..08506d1224c5 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->uring_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 e4cd6fe9fd47..bf4002e93ec5 100644 --- a/io_uring/uring_cmd.c +++ b/io_uring/uring_cmd.c @@ -29,6 +29,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->iou_vec); + if (ac->iou_vec.nr > IO_VEC_CACHE_SOFT_CAP) + io_vec_free(&ac->iou_vec); + if (io_alloc_cache_put(&req->ctx->uring_cache, cache)) { ioucmd->sqe =3D NULL; req->async_data =3D NULL; @@ -36,6 +43,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) { @@ -346,3 +358,11 @@ int io_uring_cmd_sock(struct io_uring_cmd *cmd, unsign= ed int issue_flags) } EXPORT_SYMBOL_GPL(io_uring_cmd_sock); #endif + +void io_cmd_cache_free(const void *entry) +{ + struct io_async_cmd *ac =3D (struct io_async_cmd *)entry; + + io_vec_free(&ac->iou_vec); + kfree(ac); +} diff --git a/io_uring/uring_cmd.h b/io_uring/uring_cmd.h index f3593012658c..8986224e0c57 100644 --- a/io_uring/uring_cmd.h +++ b/io_uring/uring_cmd.h @@ -1,13 +1,17 @@ // SPDX-License-Identifier: GPL-2.0 +#include =20 #include =20 struct io_async_cmd { struct io_uring_cmd_data data; + struct iou_vec iou_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 13:55:42 2025 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 C01C6242924 for ; Mon, 17 Mar 2025 13:58:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742219884; cv=none; b=JElXMlsefhA8FejvUvYYabNBJSzKsdUrkM2JhN4wqAWoNTThg4kB06sB8wQrHTlzlQBE7fN2euS+eNLckxopI6591ehZTX4Qa9ZrmqyWzoR3c+DULrbaUiD/nXjUYBep1Qx9ebP01UxD3CI6TLZSBfnqtZUiIHEYWzsnJwecr0k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742219884; c=relaxed/simple; bh=r1Vjqf1oCP/p83aYpJWj+A3gopug7Rxe//nacHp5G/0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I8GfVVRQJdjefVsoF1sr5VxCF5PTQNdjYLm2zZG0BqX3vffOMmX8eWKgJ3P1ZoYhff9YRAZL00NpA8Bf3eLqIiGW7caUGNSGU6IcW8tESqrp/Eo5XdGQsRlcJD3mZZ5n82OlWbycudyrypo60t1dqZcfyW29djMLGs8N9OVBz68= 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=DzF7VrMR; arc=none smtp.client-ip=209.85.216.51 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="DzF7VrMR" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-3012a0c8496so2321994a91.2 for ; Mon, 17 Mar 2025 06:58:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=furiosa.ai; s=google; t=1742219882; x=1742824682; 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=e7fOqEAGiDFRx1EvcNylApPOY9CX77o6NfjwJaTL4ZI=; b=DzF7VrMRZRL8DfFJrTsfEAVU7WbBBNneR2QRK0SEqzTJfYSC/W7eJgqsj7y59YH9a7 0DWz4hUEuZ6iy3SASnFtgukSlwhIWBFBGAyALBw/pOVVlQGdnHF9lZfKVlHI5xZiS/Zz +eV8Dh3GS8HX9NYzeGu60LPJM+cqVPZCZJVVk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742219882; x=1742824682; 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=e7fOqEAGiDFRx1EvcNylApPOY9CX77o6NfjwJaTL4ZI=; b=Ih8CuYMLAw1bzef4jTZDfMYVZds7cpRQ78FL8SupSbvHtNPs6FkLaiYuNywMk6ZzRa lPan9xxiGbvBAiOPnMFUSkGWu+Ip+aobR+GQFmGOmbX1McLRdd1laHh/VegJ7P8OMsXy 8pGLTEtevApZXZAvLkmFotsYi6tmAgOqbOC4E9GfszYRNBBLHrDEhR16bG3wXIOyLg1p h91hbcNOCt7+RqYFuc/j1NsxeQpvg2mHtCmW5FEh9EcsLqk8/Bts5/o95EIh8SloxbRA vndX6POtezFT9OM6TgMBQr8i2ruGx8cVO33g/7/nKehjWmhQbscR0tSBP3xf/DV641fl +jKg== X-Forwarded-Encrypted: i=1; AJvYcCUcsQWgFaIYpkFd9UW5Dq18E3/2QXkfEZc/SMzbfOG5LM6f1334+1189w4uZCl3zxLTAjPcHDgnXuZ0r8U=@vger.kernel.org X-Gm-Message-State: AOJu0YwBm6n4GnjnsQC1JY6/fJAp+nG8y2SSHMq0AltTMid9ch1RGVIo 0/nuuJYJx2RzBpkHrZYCFLJgM//da9Em7pOCwJp12vxr97hRQSqaMc2Wrmh8r0I= X-Gm-Gg: ASbGncsxfQtmPtsFi1Bz63qTPZ/MPwgcXfnsTdovlQNbou5KdV6n0g8zTb7xj5OY+TU omVJzW1bt+xhMl6Ymjgwqj923JRI9Jic5gQRhcqRrymUEDUcRE3INsUEAoT6/nLjd/SuLO/lDM3 NwZelhR8ZH64kDGZoIeMRy/6nxJDIBfE2n/vnCpXYXTAfSNuEjIh0OmynbFSn3i3Azu+1VgDpME +yzGJkGn8lK47YY/pTG6QNHlBbb3GoP7F8dHKt1sXSDx71iz8AI85oBG6rPvkQVQajwXvCgrNT6 FkzC5T8yqse2XaGUW/tn2P+Q3R5Avg+p96lRJ6FQBzMLRhVzcI/R1qrIs8vL9pgFzlIH8n/rkJk 3kiOu X-Google-Smtp-Source: AGHT+IEwHFUXeuCpBUyeil9Wg5Oba6oRQ9mFosTXz52ACT97GF4NSEeGLEXjUVwa2P9T2GloeiXqeQ== X-Received: by 2002:a17:90b:520e:b0:2fe:baa3:b8b9 with SMTP id 98e67ed59e1d1-30151cb4009mr15615142a91.4.1742219882048; Mon, 17 Mar 2025 06:58:02 -0700 (PDT) Received: from sidong.sidong.yang.office.furiosa.vpn ([61.83.209.48]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-30153b99508sm5993742a91.39.2025.03.17.06.57.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Mar 2025 06:58:01 -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 v4 3/5] io-uring/cmd: introduce io_uring_cmd_import_fixed_vec Date: Mon, 17 Mar 2025 13:57:40 +0000 Message-ID: <20250317135742.4331-4-sidong.yang@furiosa.ai> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250317135742.4331-1-sidong.yang@furiosa.ai> References: <20250317135742.4331-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" io_uring_cmd_import_fixed_vec() could be used for using multiple fixed buffer in uring_cmd callback. Signed-off-by: Sidong Yang --- include/linux/io_uring/cmd.h | 14 ++++++++++++++ io_uring/uring_cmd.c | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/linux/io_uring/cmd.h b/include/linux/io_uring/cmd.h index 598cacda4aa3..ab7ecef60787 100644 --- a/include/linux/io_uring/cmd.h +++ b/include/linux/io_uring/cmd.h @@ -44,6 +44,12 @@ int io_uring_cmd_import_fixed(u64 ubuf, unsigned long le= n, int rw, struct io_uring_cmd *ioucmd, unsigned int issue_flags); =20 +int io_uring_cmd_import_fixed_vec(struct io_uring_cmd *ioucmd, + const struct iovec __user *uvec, + unsigned long uvec_segs, int ddir, + unsigned int issue_flags, + struct iov_iter *iter); + /* * Completes the request, i.e. posts an io_uring CQE and deallocates @iouc= md * and the corresponding io_uring request. @@ -76,6 +82,14 @@ io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, i= nt rw, { return -EOPNOTSUPP; } +int io_uring_cmd_import_fixed_vec(struct io_uring_cmd *ioucmd, + const struct iovec __user *uvec, + unsigned long uvec_segs, int ddir, + unsigned int issue_flags, + struct iov_iter *iter) +{ + 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 bf4002e93ec5..effcd01b8a35 100644 --- a/io_uring/uring_cmd.c +++ b/io_uring/uring_cmd.c @@ -274,6 +274,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, + unsigned long uvec_segs, int ddir, + unsigned int issue_flags, + struct iov_iter *iter) +{ + 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->iou_vec, uvec, uvec_segs); + if (ret) + return ret; + + return io_import_reg_vec(ddir, iter, req, &ac->iou_vec, ac->iou_vec.nr, + 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); --=20 2.43.0 From nobody Wed Dec 17 13:55:42 2025 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 6CB67245022 for ; Mon, 17 Mar 2025 13:58:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742219886; cv=none; b=SYjN2eofuWKMGx27BU47BysiDE9OrK+riAYPiRz4AQUyfFsv4mWCqwjARBYvNungvS8+BP8qYtSMiU2MiP4V5SGcdENbF7w23es+74KVQ4Enzc2j7hGRvAgV4seKrd7sdFdOdkd1P4lFSqiIQEh220V3UGjPAqE4getuh6QLHKo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742219886; c=relaxed/simple; bh=jjy/ipAsVAjM570PsPj8EFg1BR0qzO1tolMoinZ9Ul8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gyKK5i9pcHU8Ow3SzA2pqtM0TnVhBsxGaruYp+fRNqNTNA71BBg7/UHycVrRXG6Y2dmGUnM/7UGxmrf9YFRIhGOglLfgJuhEUVk5S9pbOoqy5MuofGrpiTt+0r9AlCke4xOuBu5n7Gqntbt6+Jp6S+ycqHhM/nW50Jj0A4uTBTY= 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=KdwR8lkn; arc=none smtp.client-ip=209.85.214.173 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="KdwR8lkn" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-223a7065ff8so38804625ad.0 for ; Mon, 17 Mar 2025 06:58:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=furiosa.ai; s=google; t=1742219884; x=1742824684; 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=gA/GFNSLx9g8BrxtQW6nnUtMwtq8vRTEsCNTXthdg1I=; b=KdwR8lknBkk0y3/Ue2UtywXBWCCkbDYoO67uQcXxecd3q21/h9QkEYEg9KfeDXWOtq ciw+CRCLmFDHrCIbze5ahmRiF3m2Y4r4LPmOzGFcLSAu39To5DnwxLI2erwKqL2ve8sG IJqxdQC7mKZ3NJf4q/+Hbv+3v+TjybPDrB2+8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742219884; x=1742824684; 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=gA/GFNSLx9g8BrxtQW6nnUtMwtq8vRTEsCNTXthdg1I=; b=H3XfeW129eLMwMVSt1Ltr41hzl+6sGf1Pzp7/hWqUC0bK8sNz8oEZjY+yhddeQGwz0 TVLI2OLuQjZpFiAJlXRx0OeQgv1YTJu5fp3fOANvteyXKM5cg9pcMG3+PVXcdIEhojkX D8t3Hz3YLIJJiDP8UoU980Zo3Q9pxbRuTt+IJGxTTF0w9Pm6/bI40l5xixPiuQDnaJlf OvrPubGLpm2lRuuWLeVTe4JD8AKP7UVRwOgB8xtjdW1z5fUucHOh/m4Sgv7X9qriB7vZ 9QC0YmD34bmuM2dHlE1jG54wz+/2gBPapcK9J9zWNu0f/UHnOTVsVtMAZXhZnt8o6SEs Fjhg== X-Forwarded-Encrypted: i=1; AJvYcCVLHubLjuC5/I6N2J/cFS3Y2/24wtaq/IsNGACfVSfOyfcLfjVagg4mcq7265mabva9zJUqaj+CT2PHTGk=@vger.kernel.org X-Gm-Message-State: AOJu0YyInwesaLXO5eH7xcWmEpss61Bzcv+aoGznl+jTsLU7XMMZ+REo RCs+MM9cbNOKItqsSBQsOYNQJ49oEfbzs1vqbJ5i86EfHXSPIXJ6wQCtkeAWN5U= X-Gm-Gg: ASbGnctLGpdUSnTYokhVs0xLg1G63PqI+2OnPisstGpcCjIdRJh/dcvvojB/bYQKxcA k//AxDqmcI6ln489Fqur+rwfPOa2TlKw72YgvM8k3XvEbSqbs+cWljU63QL95FDVi5Fu6e35k8R i+0x7P+4EjyWKwYEXqbOW9QB9V6CoOYsvG+/x/VjzzHOpEOi3yJWA2fkuWNGc+rn07OEUrr5EfT 23ea5r5CdnAVTBNGicPGpxWjswEm0ozpT1Ay/Gym5dr3DTHPVypjOA2S5Oq2TyCn93bLlikxTLr Pf9kEZlA/I2MBLq8PB2kP8Jnh7Ghl3tbY46WB4wP/tcNJDTCAudK43ZXP2tLn6h2TPWX1A383d0 7Z2caOa6ErYD5L9s= X-Google-Smtp-Source: AGHT+IFR7AcxAe0GTSDHpA3O1seZLZqT6TdAlslNuPZsXOgxqL8PZ6/n5ArYVp7pqIiRkt7+bkJSOQ== X-Received: by 2002:a17:90b:4d04:b0:2fe:baa3:b8bc with SMTP id 98e67ed59e1d1-30151d3fbb4mr12872664a91.23.1742219884680; Mon, 17 Mar 2025 06:58:04 -0700 (PDT) Received: from sidong.sidong.yang.office.furiosa.vpn ([61.83.209.48]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-30153b99508sm5993742a91.39.2025.03.17.06.58.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Mar 2025 06:58:04 -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 v4 4/5] btrfs: ioctl: introduce btrfs_uring_import_iovec() Date: Mon, 17 Mar 2025 13:57:41 +0000 Message-ID: <20250317135742.4331-5-sidong.yang@furiosa.ai> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250317135742.4331-1-sidong.yang@furiosa.ai> References: <20250317135742.4331-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 --- fs/btrfs/ioctl.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 6c18bad53cd3..a7b52fd99059 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -4802,6 +4802,28 @@ struct btrfs_uring_encoded_data { struct iov_iter iter; }; =20 +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 && (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, + ITER_DEST, issue_flags, + &data->iter); + } 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); @@ -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 From nobody Wed Dec 17 13:55:42 2025 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (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 30C032459D7 for ; Mon, 17 Mar 2025 13:58:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742219889; cv=none; b=DPiXVpX4CguqT6aRalY+2fvP8KNZTNzbHJVBkT2VM7VG3l/ZOLcyrfRSgd/yoNoLt9lO9VN0OaWof2Hqok5EZQa/XRXWLkEDT5mPW0Mf/pAFrp2GamBoq/P0xX5wLoNmj3IsFyTqL9PBqgOYEyWpjxdFnEsrb8jecqiJ+NbtJJ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742219889; c=relaxed/simple; bh=jX0ueY9211gETMFC7G0MuImPr6rWSlX9oFF0HSj0qeQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nu8rnplZfV5yIQdh2F7nfbV75czI9+UAkJPgGT3ZO43Q7/2cqK+njrLSuNvhx1r+jxB3FYnIWW0e5Biybgn6CBw3TmSHg7OtNFr/IVCEhKbuBRmd3giAc3o1LTGJA5S2Sc3tHVP0HEp6DFjgYF477iDyE87fJLgZKnQ0AdUlec4= 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=CpzDdST4; arc=none smtp.client-ip=209.85.216.47 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="CpzDdST4" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-3014678689aso2394020a91.0 for ; Mon, 17 Mar 2025 06:58:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=furiosa.ai; s=google; t=1742219887; x=1742824687; 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=KCFknnsao+MA3rkiA5nb/VuBAcmMICvzxTPutU19C0o=; b=CpzDdST4SUHXX63D528pN/pT8+g3o8kiuU3UkTTWcwsbL19Pid2fyrglxdER4bkTwU 3HJ9pwi5C+5+vF44ZCrnyyXwtjNagIZFva25cI+tWpf/W59w6G6jzJLvS2+79yTTWP0M 2em89jC/qYQZRpfpGGyl9pvWnfvV+xrTuCiVg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742219887; x=1742824687; 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=KCFknnsao+MA3rkiA5nb/VuBAcmMICvzxTPutU19C0o=; b=sMF2ezBwNZv63t9Z/CH2PYQJLKcctn8BgXlm9XX0zQmwIV27sw4N+cBch6SxMf3f9a IkBsMC1IAz8DWko5JZ/ffeu7gkeKz4eLash5GbEfU0KAJtYVcriOY+KUvDYk7v8uI/5W i0+IABm/T3pWGGJNTYoY6Jjm/Wa8qe6wuTdfLs6cf4n06kVZ8dVEn0mBNBgjRw836Vx4 /OreIhFyGgiK19JmKwtANjAH13wAtKAHrIzHNswEdiKk7v/FI9JpDCo676I+kblcy6oD J0un7KybKlFIQfbyADhKJjg0eTt/Ht9zvm3wsYOfcsjeoFJn11e1Q0Cbwd+PaeqBbglD lYxg== X-Forwarded-Encrypted: i=1; AJvYcCWXrqYktB/tr5gmIfiA2IMZp0qsM3iF72W82UgnKqUslx8558lOTpetUGUPHJuPqYw0DI4HW3AKyLQr2eA=@vger.kernel.org X-Gm-Message-State: AOJu0Yyxu2fbmJq+xBEDcXXsFX+/dsbRYCxUdPh2x3bLRernB4tS04ge x9NOhbnCN7mbsG4TlHZTmiY4sslNQVzPiZJ2pBqYlDHtd3DezsWiQDJjxZ0laDA= X-Gm-Gg: ASbGnct2OUoA5nbFK0KGbwEZsjsaanICl7sTuQNwCFci8k7cvw4EAxaHYLg/Rrio9Lk p4dBkeCwCN1Er2V6+JPLtXjn2j85Q2eiCeAhhEf8uVRwpcyVgjfccMzYDHMjIqoB3TId7BZL9Xy fnVrTgfwAfZHg7KlFqkGnovppEtIl7/CXJouKHNInTv8KQr1pFalNdl0snPOg3YNiWeY65rVHHf 3XA+v6K8Avq6DlXyCoV+6r2O/brs7p6Z3hBfnyucSej/UE1rqEQ8jUu2Rh6UROEi+5zTUJLy5qe 1IkwPOeEBShnSiSVeuYZxIqwg3b8IlJdM5ZceQRrwLCs6WW2ZfrrQxVtWbbFLaVl3X2C5wjbD3A LS7aK X-Google-Smtp-Source: AGHT+IELSRI9QIZeeFAktb+zISbFeOiwkhBMlafTPTduJwqWCwWpj5FYPH9pfrHw+RSrrQDy4i+60Q== X-Received: by 2002:a17:90a:fc4f:b0:2fa:15ab:4de7 with SMTP id 98e67ed59e1d1-30151ce15a6mr18431695a91.12.1742219887603; Mon, 17 Mar 2025 06:58:07 -0700 (PDT) Received: from sidong.sidong.yang.office.furiosa.vpn ([61.83.209.48]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-30153b99508sm5993742a91.39.2025.03.17.06.58.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Mar 2025 06:58:07 -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 v4 5/5] btrfs: ioctl: don't free iov when -EAGAIN in uring encoded read Date: Mon, 17 Mar 2025 13:57:42 +0000 Message-ID: <20250317135742.4331-6-sidong.yang@furiosa.ai> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250317135742.4331-1-sidong.yang@furiosa.ai> References: <20250317135742.4331-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 fixes a bug on encoded_read. In btrfs_uring_encoded_read(), btrfs_encoded_read could return -EAGAIN when receiving requests concurrentl= y. And data->iov goes to out_free and it freed and return -EAGAIN. io-uring subsystem would call it again and it doesn't reset data. And data->iov freed and iov_iter reference it. iov_iter would be used in btrfs_uring_read_finished() and could be raise memory bug. Signed-off-by: Sidong Yang --- fs/btrfs/ioctl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index a7b52fd99059..02fa8dd1a3ce 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -4922,6 +4922,9 @@ static int btrfs_uring_encoded_read(struct io_uring_c= md *cmd, unsigned int issue =20 ret =3D btrfs_encoded_read(&kiocb, &data->iter, &data->args, &cached_stat= e, &disk_bytenr, &disk_io_size); + + if (ret =3D=3D -EAGAIN) + goto out_acct; if (ret < 0 && ret !=3D -EIOCBQUEUED) goto out_free; =20 --=20 2.43.0