From patchwork Mon Mar 17 13:57:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sidong Yang X-Patchwork-Id: 14019566 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (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 83CFB241683 for ; Mon, 17 Mar 2025 13:57:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742219879; cv=none; b=mb6OpZ63hmbOfr+4d9mC0TgB0kQDJKCwZGjL1A9c8/S88Obnp6MmuPv4GSOexooIABvbchPs29Jv1z1BspoCWoICZbJgB2V4NPQ7p21mVMLVqwDJYQN4sQS6LsvXlSrSyF1FoeZYERjs1SmnYoD2PZfUO4vBFq5DnKF9Ee1fl5Y= 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.45 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-f45.google.com with SMTP id 98e67ed59e1d1-2ff6cf448b8so4197314a91.3 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=Neefv9JVIagdDSCNOs0DeibYLLJCNjoJRY3OP1DRAKVR2YxWne/WbBfClDecL2q/vS wTjlXUEF2GwUzSfL4xwWjZGyyr+unKtgw9C37hFOXTAOfzWBFaI0OUVogZN5EeA8W3Qm y3AwP7NTmi0MPmWEWXaKwKeRx3rqsR1mBVShRfWOQcZwlcSxBpNLnBKnupXwuL1+uIKT HTlEXxr9PYmGbiK2NM8cgzgsLA5Pt0e8jRnPkvrmWw1Wuj2XgWGOdJ2B+IlQ1ZEO05cP SzlV/1U6IwtznQFL3JMxw+CuBHj5ZVRLKaCKEkCMcjKtXQyGkESSB4kR72ox33EhUurr cVTw== X-Gm-Message-State: AOJu0Yydl6jciFA4SJxHy/nvmsNHHZdg4fK/q/YEQOgeCN8rrRHwRL2g geJF/HqP4ZW9Dq8CL4gDMV1vUtjgH99NLoCUdPvQpkYcQWcuVmc1GyYZw3Rb1Ws= X-Gm-Gg: ASbGncvtVbZcV11EYvZPbP9BieN7vHZF5eq7o5vo4r3AMLKTBhkNLsRgHPhSN3CXT2U GgxGIvK5yu0WkZ0vPMzYqSecEDzl/zsYo1upLVCjukhnjprOCQFrWf3p6Uxwo7RffXYHZXmN0O8 Or9y1mXLPpaq/i3pYqoT2KtnoBxK+iqi3uCAIpUi0RG5i60a2Ny3Ao2Im0MIoZzQ3h+Z5W/94Nw Wh9FSrlmAn2ZMBqynv8fAYJQEB3msvFwuhMZfDxl8arm8LXUZB8c2GW7if5zC/wC+OripT7GqGu fqTaipl2ZCrMb0UVvLPoPqnw9TREpnxiTrhgiU5zFjYygJcuAKX5S+rairNCTt9uuyV1hYmdGty UkTxMnZTiVg/O0ek= 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-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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(struct io_uring_params *p) sizeof(struct io_async_rw), offsetof(struct io_async_rw, clear)); ret |= 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 |= 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[] = { .plug = 1, .iopoll = 1, .iopoll_queue = 1, - .async_size = sizeof(struct io_uring_cmd_data), + .async_size = sizeof(struct io_async_cmd), .prep = io_uring_cmd_prep, .issue = 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 = io_kiocb_to_cmd(req, struct io_uring_cmd); - struct io_uring_cmd_data *cache = req->async_data; + struct io_async_cmd *ac = req->async_data; + struct io_uring_cmd_data *cache = &ac->data; if (cache->op_data) { kfree(cache->op_data); @@ -169,12 +170,18 @@ static int io_uring_cmd_prep_setup(struct io_kiocb *req, const struct io_uring_sqe *sqe) { struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd); - struct io_uring_cmd_data *cache; + struct io_async_cmd *ac; - cache = 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) != 0); + + ac = io_uring_alloc_async_data(&req->ctx->uring_cache, req); + if (!ac) return -ENOMEM; - cache->op_data = NULL; + ac->data.op_data = NULL; /* * 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 = cache->sqes; + memcpy(ac->data.sqes, sqe, uring_sqe_size(req->ctx)); + ioucmd->sqe = ac->data.sqes; return 0; } 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 +#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); From patchwork Mon Mar 17 13:57:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sidong Yang X-Patchwork-Id: 14019567 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 335D8242903 for ; Mon, 17 Mar 2025 13:57:59 +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=1742219881; cv=none; b=oZiN7/Cw67RFbHzW8AaRzYh62XLJbhLLJlbyOnKxzc/f9vx3Jrb6dQrJvCN/e1Znz4Cqmuv2L7ptjN11S9LE8d3wrG7NmG1Xh/Jy4AFpW9TcWqwtXfL8yNJKUp6DMoEi8GlD1f4ldB2nBpgxtqEtetN0/IQmOZH/bXDFs4gHFEc= 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.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="dKUQoHMD" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-3018e2d042bso1015873a91.2 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=j8XwfcgRM09W8MwS7dlaKAcHsvkZmtCL5Xwj0eOiQXoJZQ25j58PEkWCG9zthkpogY VGxOjMwE/21F3SbMmVvwGQzcUIoOSgtaZXRs/Lkv51P36X0Q86c3e81j7PwvvJD3wrdL wSYW5Z6a5kt9YVVrzsdMsE3JdC/O1/V8d/l7iPBC9TWUfexPIPt4q4J8w6YpBMrLDjWb 0Jf5hMgIUOqRnc9valfsW0b9ZFSqoZosMKeCeZhRImDUBY1HIP7of5Zl8IiWsfhQXCpT 0ym5oV7E4TGPbwMMHyR8DLY2zLtn1vyJMzpB6TGyOBKGPFYFLMIJY4+07D9RLR5HQr75 S64g== X-Gm-Message-State: AOJu0Yy15pqfC0ZmjBBzoh7rOG/YEY+gDZuDxLZlzPanYS+L1kmoedp2 CHmEj6H2CF5XgHsMkyD39HgVCvfIFIVeLBJJ3R/eqLvwaCO0e9OkSja6ja8g5rqF6NaYOk4DdLo b X-Gm-Gg: ASbGncuzZafazO9gO2B4pUkqQgIMHS+GNghb0ABFeA3/45MmBpwT1vTA2x7l1J0YIEv z6txOHUd0b08PJDK/ZRrL7DFYnGZTkN0R3oD89vxBH0riGE4YzAiaAU2dpf2LmDtyaJWhZZ/gyY zxuJ6vwtKWtfU0G9Zg5yCD9rJBk/W5psKv3dYkWFWdk98H2C9v7frho7obN8t018s5kvBb1vywC pWJXjVpNQUVQSPpYbkfPQjwxpOswobZj8o1C34U2wXiDMxIb4BLB8bUT0C7cliuEf/16F5+v3E4 GRvVv6r5Njl4ybZUU0QVNkUTeuF7yV6tM9IJDQxJB6kC9ArWaR5rNcKYZNo8vqsW/5tA5Ovc4lA Tb8nIUFA1n7fZTTg= 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-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 *ctx) 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[] = { }, [IORING_OP_URING_CMD] = { .name = "URING_CMD", + .cleanup = io_uring_cmd_cleanup, }, [IORING_OP_SEND_ZC] = { .name = "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, unsigned int issue_flags) if (issue_flags & IO_URING_F_UNLOCKED) return; + + req->flags &= ~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 = NULL; req->async_data = NULL; @@ -36,6 +43,11 @@ static void io_req_uring_cleanup(struct io_kiocb *req, unsigned int issue_flags) } } +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, unsigned int issue_flags) } EXPORT_SYMBOL_GPL(io_uring_cmd_sock); #endif + +void io_cmd_cache_free(const void *entry) +{ + struct io_async_cmd *ac = (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 #include struct io_async_cmd { struct io_uring_cmd_data data; + struct iou_vec iou_vec; }; 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); 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); From patchwork Mon Mar 17 13:57:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sidong Yang X-Patchwork-Id: 14019568 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (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 BF94F241664 for ; Mon, 17 Mar 2025 13:58:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742219884; cv=none; b=J1ScBMo4VoDpPUp3oEZZ3Y2z08aQayrAG3RLzwzTV07u1DwEQGF/eFRY4rByiCPCi5XpH+MMb+97CKHFZIi8q9oSnAZDJc/IEszFXXCnSv7R/OQo9yRUHI8nDiDBxs6Q1ftz6q4addeHKrWAyJIBzLHj4H0j0BzoJwnvpm0qYLw= 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.41 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-f41.google.com with SMTP id 98e67ed59e1d1-3014678689aso2393774a91.0 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=ZfUWbZAjXx87Jit2afsBgMOc5z7SQZsIqmPzG521lQdQ9zsso5AeIJbFwOZqHqJEHR dfrk7cslb+YrOitP0sAp6fRePS4JgabJRYp80ySBHWhQfq6ItEpHdfIsy7NOdTF8Wj0I QCo7MDHJaXEdfrFoJ18GZdDi3qnoh6ayDMltHxyYBs64yq5q/Ihi/CHLkUQMvRJNPcz4 AUuH6Zqpl1jG0KF1FGIshP9S8qshZojsgidfogT+6EUDpef0hnXzdeqQwmsavEWBbX+g tPQaLwLutE15ZAuxPubwkkzWfomdFo+S1Qo28daT1WgY02yMxBGh9EzW7a/2cZyPPPhR 27UQ== X-Gm-Message-State: AOJu0YwPJOshLgiWT00bncWXvaHZS3PY4U4INLNqxGRfBUxjhxGvf5Yg bSSHX57RL+nQ7uh8IGIZ3LE+z4Y8g+HqMrqK9DtYtwDHXBLAvzs5UHZj13x3HFw= X-Gm-Gg: ASbGncs09UKDm3JAahOXvU0VmH010xacWu7aQdAQE/0jsGF4Mds+AQYVeGLS68V9PG4 Ftx2khQ/6+6N78Dvl+lhEIqT6fNghRAe/YeShjxfWnB5Q3fwJi8MmSkBKlcYspMrzBNuvs7dMv6 00fOaIXzHkv8INNDtW9eqZzCzTXBySoieGK96YftCAgO/CXYrC20+JrcB8lLfAtPn/1nUWjjJJk Aci6wPNunk+G+7Yv4tlW/2EpaolgnSmcSQ9wjw4XqEwOj8kyJsjHLY0ObkgEZu57Q0rWm6cIUGc zOH1meYlDF83sk/zRssgrbLsqo8xyDitW0RTAMFfhB0e327fTRByb1rKq5HuWy/lzbCHpE6y8cv apxts 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-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 len, int rw, 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, + 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 @ioucmd * and the corresponding io_uring request. @@ -76,6 +82,14 @@ io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int 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); +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 = cmd_to_io_kiocb(ioucmd); + struct io_async_cmd *ac = req->async_data; + int ret; + + ret = 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 = cmd_to_io_kiocb(ioucmd); From patchwork Mon Mar 17 13:57:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sidong Yang X-Patchwork-Id: 14019569 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 6CAE9241664 for ; Mon, 17 Mar 2025 13:58:05 +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=1742219886; cv=none; b=WAtWmI8np4a3pTur0D4lRsUOLIqTcXgA7x+lYu5kvzEqvePr4vUWA8SkXCoodtKZdWlWGHY5WskRMb+LyU3BmbdonW1/NPWjPcWIjpECs9q7V8Unq0DPHA6iWrnSiPYNzBcTeKIVC6ZnZlkTpEbgfV8uw1uiOf3v0eXTwAKd0QE= 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.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="KdwR8lkn" Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-2fecba90cc3so4598250a91.2 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=WrFEUdiZkQX7MisPYEqGORYMUJFHkIxQuGXF7KBCSGfR5gvQNJj72pvQSfzxsojLQ6 MFsQBCu6HbmsriF6C0ei8kNc//8nwYRahkFwKanjVVaDaV5gFxlXfvh//ZEYbQfBoaW+ v5RgzLoamu5ukYhsVWXmAJHpzyOkeqTNxJV6Ncq/Etr4G4iivr+k3pF4DI3mhS6nCsND mFr2lRraEHDaFDbkYJwMbcKepJPXtKcCfEcRAGDGN1ZcWTpLuAYtZ1ouVcoNP9rcW4RJ /x7VzzOBuDX2V/4D5IQbws/B0fO4zdpou4jKCf7XpM1+9aiABdhPu0PZ94c8Urb+iQCY stPQ== X-Gm-Message-State: AOJu0YyN0TePqqrLQMjkkGcSJ0PWx3RGQZzFKFhoXIg3lPW43NbG5nuV unNfFws+4IoJTAcFFFigfvz2nMXoeQ/DCkK1tEl6qpOQUvx7ZQmdbOA9jqZobOA= X-Gm-Gg: ASbGnct0cNf/Kyan5FoiFoRIlH8JOqEVEHVwum3AaFDv9GFIoQaMOU3T+srMMn9tVXY 1ezxLun59ZhK01lSDEorjKZDyhQUg6SJNUZ7YN4Q5wPS7Owkw4r2nJxwZ19DCyNWOOYGxSDiWG2 9JqkkWtG2YaWnBASrlaMnkuM8XVP6IHu/CiTHm7EGlrE1NPCp+xQN3W2W/Wb81xDwuZC4aT6qmm 1vDYDRcwAEvdV597UBeVOlO/amNlGNMcEUoFOupSd2+ldeKCf2+/v1emExadyV2h9AEmEiHxBER ppwVowUdS8GlA0VohyNScHCmaPsIvwkTiHNkOy964jzaR5xcjWFpOboMHE2fVrlrKVvcKebF80z F6VE8szvhwjt1w7I= 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-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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; }; +static int btrfs_uring_import_iovec(struct io_uring_cmd *cmd, + unsigned int issue_flags, int rw) +{ + struct btrfs_uring_encoded_data *data = + io_uring_cmd_get_async_data(cmd)->op_data; + int ret; + + if (cmd && (cmd->flags & IORING_URING_CMD_FIXED)) { + data->iov = NULL; + ret = io_uring_cmd_import_fixed_vec(cmd, data->args.iov, + data->args.iovcnt, + ITER_DEST, issue_flags, + &data->iter); + } else { + data->iov = data->iovstack; + ret = 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 = 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; } - data->iov = data->iovstack; - ret = import_iovec(ITER_DEST, data->args.iov, data->args.iovcnt, - ARRAY_SIZE(data->iovstack), &data->iov, - &data->iter); + ret = btrfs_uring_import_iovec(cmd, issue_flags, ITER_DEST); if (ret < 0) goto out_acct; @@ -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_offset) goto out_acct; - data->iov = data->iovstack; - ret = import_iovec(ITER_SOURCE, data->args.iov, data->args.iovcnt, - ARRAY_SIZE(data->iovstack), &data->iov, - &data->iter); + ret = btrfs_uring_import_iovec(cmd, issue_flags, ITER_SOURCE); if (ret < 0) goto out_acct; From patchwork Mon Mar 17 13:57:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sidong Yang X-Patchwork-Id: 14019570 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 51EDD2459D9 for ; Mon, 17 Mar 2025 13:58:08 +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=1742219889; cv=none; b=n48SH7iokI9RruHH+eOTm0GHCj950XzrQcH+9c7hEOPYYRpJlcQag58t7PV6ttFUnnoWVLISAm13PuZR/sGNnCXXZMrdgLDI7erMaFJRd+2XWqAMfqQ1OFcIs1ZGx+xZIn099z8gOw4jFUAj69sCbsNxb9zmBEl9nCSnVG1AWd4= 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.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="CpzDdST4" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-3012a0c8496so2322269a91.2 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=gE3D6T0EsOzTBK1fKGRZw01Pcb+d6mZcqVd/SYdxQR+In9PwFl8Md4axglTZi6UGsl v56vywZx7qBKlndNpzC9d2knezWN7GZMqtqjGa1QvldsymQ2SaWfg86CESYigqJ8hD0W sleG5JODNJdxCnpaHsHv1dMG0iPAPgox5lEDt3wYV9TjG9HvkToH/eeYYPw+34v+7HB8 YlE2qwV/iwqOyCOetHjn15+wcdYYJbaReUeK1d2OrM4tYOt+4gipvNrNA3g7tqdAmPL6 k+j6Zw/+eVuPhFqY5QVJSP+wBSL0mKnBCNKcHxx0d5CeUGYTYptNTqFz9YhAfp/AF5Nk s/8w== X-Gm-Message-State: AOJu0YyILMzco8bK5OsyGZcgu+IdeW1OyzC4nzAtnoyukAjPpOOns4IY Xq9/3JixaB7wmpjXv90pprqDgUN0fh3z35EiO8aOnY8Iq1yTWUVWUXFycMwstX17nDJCv2Stml3 H X-Gm-Gg: ASbGncuTnawlN3GOlVhIZYHjqtakkxUT/zsleg+cGqYQFKVBSJBmjQR9XNzLIh7yIM3 V1A6m+tyRfdSCRfFGqpSlDNwaDMSdQzHTAwejdEMdL9l5pFSFqxR8naP1/nL5HtNW+sjB5hlxCv fc+ImOktkuIy/WXAFTAWo9HKVI0ZL4q17Q3dXF6hznGEP77rBxwiLTClaIRTdfPDKWEdUFJ2S92 Jn6lsyydKPSxwqliamGliK0AK4PAu4DZAFsClAe2cHVhNcL3w2KIegXsj1KDTu144SLWgWEobGa OBgoA+o/41Txfj6xmz8jlBhA2FBqLahUZa/ETghQ+b13SB/YtH05I1nBbsNGMu6/IdbSFPxv/Ko 6biIi 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-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This patch fixes a bug on encoded_read. In btrfs_uring_encoded_read(), btrfs_encoded_read could return -EAGAIN when receiving requests concurrently. 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_cmd *cmd, unsigned int issue ret = btrfs_encoded_read(&kiocb, &data->iter, &data->args, &cached_state, &disk_bytenr, &disk_io_size); + + if (ret == -EAGAIN) + goto out_acct; if (ret < 0 && ret != -EIOCBQUEUED) goto out_free;