From patchwork Sat Jun 11 12:22:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 12878502 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6C6BC43334 for ; Sat, 11 Jun 2022 12:22:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230098AbiFKMWm (ORCPT ); Sat, 11 Jun 2022 08:22:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231831AbiFKMWl (ORCPT ); Sat, 11 Jun 2022 08:22:41 -0400 Received: from out1.migadu.com (out1.migadu.com [IPv6:2001:41d0:2:863f::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CBFF183AA for ; Sat, 11 Jun 2022 05:22:39 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1654950157; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=cF5VLqZazzAXFMPFgW6edUuYNdGOTMIng7AFwFbNHPE=; b=jBI9wyes8Rvh1aTOl4RpBf4yzcz7MxZCtp7v/MfCjWmJ7kSDPGhUndQS+J/BBHCwNdGJCT FDRnYccyeq+JapEHmXpPeZHGAAOhgH8U/+izFUjE1SySVJdPzInK/ro2YqLOqUjRWnNSJN nhx7X+BD+VaLKsvjtY8pa7cg1QdlsGE= From: Hao Xu To: io-uring@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov Subject: [PATCH for-5.20 1/6] io_uring: poll: remove unnecessary req->ref set Date: Sat, 11 Jun 2022 20:22:19 +0800 Message-Id: <20220611122224.941800-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Hao Xu We now don't need to set req->refcount for poll requests since the reworked poll code ensures no request release race. Signed-off-by: Hao Xu --- io_uring/poll.c | 1 - 1 file changed, 1 deletion(-) diff --git a/io_uring/poll.c b/io_uring/poll.c index 0df5eca93b16..73584c4e3e9b 100644 --- a/io_uring/poll.c +++ b/io_uring/poll.c @@ -683,7 +683,6 @@ int io_poll_add_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) if ((flags & IORING_POLL_ADD_MULTI) && (req->flags & REQ_F_CQE_SKIP)) return -EINVAL; - io_req_set_refcount(req); req->apoll_events = poll->events = io_poll_parse_events(sqe, flags); return 0; } From patchwork Sat Jun 11 12:22:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 12878503 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B43DCCA47A for ; Sat, 11 Jun 2022 12:22:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231844AbiFKMWo (ORCPT ); Sat, 11 Jun 2022 08:22:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231831AbiFKMWo (ORCPT ); Sat, 11 Jun 2022 08:22:44 -0400 Received: from out1.migadu.com (out1.migadu.com [IPv6:2001:41d0:2:863f::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64E5E167F3 for ; Sat, 11 Jun 2022 05:22:43 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1654950162; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CvrJD9gksnnXOee+F5KF9tGQ2m10atYyWkwTq+1fegY=; b=XZ6P2GZIsWU117siu1q0vmtmAe2XR6Ku+hXSs/71Eg8pHIJvNiU9GEQEqBLZrGW50dkeHS P+sD8OSfbnHQ302g794/6UGzsBVcHxcjrWhFrIkOczIPyjGheOw11fMChwEh1BrsMs5YDh PtKghzz7owQb2w/5G9HRXRdq5n20AKw= From: Hao Xu To: io-uring@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov Subject: [PATCH 5.19 2/6] io_uring: openclose: fix bug of closing wrong fixed file Date: Sat, 11 Jun 2022 20:22:20 +0800 Message-Id: <20220611122224.941800-2-hao.xu@linux.dev> In-Reply-To: <20220611122224.941800-1-hao.xu@linux.dev> References: <20220611122224.941800-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Hao Xu Don't update ret until fixed file is closed, otherwise the file slot becomes the error code. Fixes: a7c41b4687f5 ("io_uring: let IORING_OP_FILES_UPDATE support choosing fixed file slots") Signed-off-by: Hao Xu --- io_uring/rsrc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c index d78e7f2ea91f..cf8c85d1fb59 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -705,8 +705,8 @@ static int io_files_update_with_index_alloc(struct io_kiocb *req, if (ret < 0) break; if (copy_to_user(&fds[done], &ret, sizeof(ret))) { - ret = -EFAULT; __io_close_fixed(req, issue_flags, ret); + ret = -EFAULT; break; } } From patchwork Sat Jun 11 12:22:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 12878504 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E76AEC433EF for ; Sat, 11 Jun 2022 12:22:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231831AbiFKMWr (ORCPT ); Sat, 11 Jun 2022 08:22:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231897AbiFKMWq (ORCPT ); Sat, 11 Jun 2022 08:22:46 -0400 Received: from out1.migadu.com (out1.migadu.com [91.121.223.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 363DC23149 for ; Sat, 11 Jun 2022 05:22:46 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1654950164; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L1wIvv3zLWMR31Nd8s1DbvuiWn532QeRZmT5/FrvJdE=; b=HLzR7dAf2nMidWb+ESDtsv1+ReSj2HWXZNl773sIvuBScjH6ajiCBIGoPjHkIfGzu0jpW3 VMipxDXTwEZTndxZOo5CQgN5I3OZzUYRaGzzIkhtbMfkUFSr85aBUqItobyfD/hcDoIlw7 9eFAMIE5cQfqNpS7hQTc05yWx4ICHjE= From: Hao Xu To: io-uring@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov Subject: [PATCH 5.19 3/6] io_uring: openclose: fix bug of unexpected return value in IORING_CLOSE_FD_AND_FILE_SLOT mode Date: Sat, 11 Jun 2022 20:22:21 +0800 Message-Id: <20220611122224.941800-3-hao.xu@linux.dev> In-Reply-To: <20220611122224.941800-1-hao.xu@linux.dev> References: <20220611122224.941800-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Hao Xu In IORING_CLOSE_FD_AND_FILE_SLOT mode, if we successfully close fixed file but fails in close->fd >= fdt->max_fds check, cqe-res = 0 is returned, which should be -EBADF. Fixes: a7c41b4687f5 ("io_uring: let IORING_OP_FILES_UPDATE support choosing fixed file slots") Signed-off-by: Hao Xu --- io_uring/openclose.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/io_uring/openclose.c b/io_uring/openclose.c index b35bf5f66dd9..4eb1f23e028a 100644 --- a/io_uring/openclose.c +++ b/io_uring/openclose.c @@ -248,7 +248,7 @@ int io_close(struct io_kiocb *req, unsigned int issue_flags) struct io_close *close = io_kiocb_to_cmd(req); struct fdtable *fdt; struct file *file; - int ret = -EBADF; + int ret; if (close->file_slot) { ret = io_close_fixed(req, issue_flags); @@ -256,6 +256,7 @@ int io_close(struct io_kiocb *req, unsigned int issue_flags) goto err; } + ret = -EBADF; spin_lock(&files->file_lock); fdt = files_fdtable(files); if (close->fd >= fdt->max_fds) { From patchwork Sat Jun 11 12:22:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 12878505 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05AA9C43334 for ; Sat, 11 Jun 2022 12:22:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231941AbiFKMWt (ORCPT ); Sat, 11 Jun 2022 08:22:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231897AbiFKMWs (ORCPT ); Sat, 11 Jun 2022 08:22:48 -0400 Received: from out1.migadu.com (out1.migadu.com [IPv6:2001:41d0:2:863f::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B85E167F3 for ; Sat, 11 Jun 2022 05:22:48 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1654950166; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GoEGEMXuglk9x7fsQg2tGkCbYjjy8eCyCqhMokdQTi8=; b=G7icOufwvsb6oa19wZ8RDivlH5w7JKq3IVVpM26wkEzV925nlY33j8edSznCznW+jCIR6v x0FN/8BEkOvG1esTOR4yKXh2ydn0DmYhymec/mXv95hmAGBNzPPmZ9WczLt42ajErV51Mq xjWcI2RVRB2foVG9LBbIMvjassUKjhY= From: Hao Xu To: io-uring@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov Subject: [PATCH for-5.20 4/6] io_uring: openclose: support separate return value for IORING_CLOSE_FD_AND_FILE_SLOT Date: Sat, 11 Jun 2022 20:22:22 +0800 Message-Id: <20220611122224.941800-4-hao.xu@linux.dev> In-Reply-To: <20220611122224.941800-1-hao.xu@linux.dev> References: <20220611122224.941800-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Hao Xu In IORING_CLOSE_FD_AND_FILE_SLOT mode, we just stop and return error code if either of fixed or normal file close fails. But we can actually continue to do the close even one of them fails. What we need to do is put the two result in two place: for normal file close, put the result in cqe->res like the previous behaviour, while for fixed file close, put it in cqe->flags. Users should check both member to get the status of fixed and normal file close. Signed-off-by: Hao Xu --- io_uring/openclose.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/io_uring/openclose.c b/io_uring/openclose.c index 4eb1f23e028a..da930081c03c 100644 --- a/io_uring/openclose.c +++ b/io_uring/openclose.c @@ -248,12 +248,15 @@ int io_close(struct io_kiocb *req, unsigned int issue_flags) struct io_close *close = io_kiocb_to_cmd(req); struct fdtable *fdt; struct file *file; - int ret; + int ret, ret2; if (close->file_slot) { ret = io_close_fixed(req, issue_flags); - if (ret || !(close->flags & IORING_CLOSE_FD_AND_FILE_SLOT)) + if (!(close->flags & IORING_CLOSE_FD_AND_FILE_SLOT)) goto err; + else + ret2 = ret; + } ret = -EBADF; @@ -286,6 +289,6 @@ int io_close(struct io_kiocb *req, unsigned int issue_flags) err: if (ret < 0) req_set_fail(req); - io_req_set_res(req, ret, 0); + io_req_set_res(req, ret, ret2); return IOU_OK; } From patchwork Sat Jun 11 12:22:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 12878506 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6E7DC433EF for ; Sat, 11 Jun 2022 12:22:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232372AbiFKMW7 (ORCPT ); Sat, 11 Jun 2022 08:22:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231897AbiFKMW6 (ORCPT ); Sat, 11 Jun 2022 08:22:58 -0400 Received: from out1.migadu.com (out1.migadu.com [IPv6:2001:41d0:2:863f::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 644722ED77 for ; Sat, 11 Jun 2022 05:22:55 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1654950174; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Mpp2p0ochQc/iLJwABzIvZ+1jToYJPYHhFnUDQIAQBE=; b=S4Hjk2QNa1Zx5fCzxLnFHMxAhNVf39grpWaG0pmSt1Jd1LWAJQ+0oOPpYAW1xR7WrDMgfe 8Mxk079YabIuciVUSrGuuBQXcCCN36Q8s9nDoZqLj43l4DMpB34Oe+xn4Ewb+//oiB7um/ 4b8V35UUeYbufSg55gogDo62dKUfoUg= From: Hao Xu To: io-uring@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov Subject: [PATCH for-5.20 5/6] io_uring: remove duplicate kbuf release Date: Sat, 11 Jun 2022 20:22:23 +0800 Message-Id: <20220611122224.941800-5-hao.xu@linux.dev> In-Reply-To: <20220611122224.941800-1-hao.xu@linux.dev> References: <20220611122224.941800-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Hao Xu __io_req_complete_put() is called by __io_req_complete_post, and before that we already put kbuf, no need to do that in __io_req_complete_put() again. Signed-off-by: Hao Xu --- io_uring/io_uring.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 1572ebe3cff1..a94ddd0ba507 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -1245,12 +1245,6 @@ static void __io_req_complete_put(struct io_kiocb *req) } } io_req_put_rsrc(req); - /* - * Selected buffer deallocation in io_clean_op() assumes that - * we don't hold ->completion_lock. Clean them here to avoid - * deadlocks. - */ - io_put_kbuf_comp(req); io_dismantle_req(req); io_put_task(req->task, 1); wq_list_add_head(&req->comp_list, &ctx->locked_free_list); From patchwork Sat Jun 11 12:29:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 12878515 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10F1BC43334 for ; Sat, 11 Jun 2022 12:30:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229666AbiFKMaI (ORCPT ); Sat, 11 Jun 2022 08:30:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229723AbiFKMaH (ORCPT ); Sat, 11 Jun 2022 08:30:07 -0400 Received: from out2.migadu.com (out2.migadu.com [IPv6:2001:41d0:2:aacc::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4267C60FB for ; Sat, 11 Jun 2022 05:30:06 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1654950604; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=faVsmm7SshsrJAyY/i6h9TMbvPwTJcP4C9gciMxrHYQ=; b=EgW/8CukXBr17W2HUep3qaXQyBUiYIrfZDF+zbrjQFKt46e0fySXo7YvnT/I9UIja3J9vH +9JEbsJin4fkI59T6TX1oQzftYnHt2sdYYRPifJo0UBfiayzuH1kiKuF70wzpmF7zVWffi SE++mZBIljG8RTpzlueV57ArDADVfWw= From: Hao Xu To: io-uring@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov Subject: [PATCH 5.19 6/6] io_uring: kbuf: fix bug of not consuming ring buffer in partial io case Date: Sat, 11 Jun 2022 20:29:52 +0800 Message-Id: <20220611122952.942096-1-hao.xu@linux.dev> In-Reply-To: <20220611122224.941800-1-hao.xu@linux.dev> References: <20220611122224.941800-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Hao Xu When we use ring-mapped provided buffer, we should consume it before arm poll if partial io has been done. Otherwise the buffer may be used by other requests and thus we lost the data. Fixes: c7fb19428d67 ("io_uring: add support for ring mapped supplied buffers") Signed-off-by: Hao Xu --- io_uring/kbuf.c | 9 +++++++-- io_uring/kbuf.h | 10 ++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c index d2b2b4728381..0680b63af1d2 100644 --- a/io_uring/kbuf.c +++ b/io_uring/kbuf.c @@ -49,8 +49,13 @@ void __io_kbuf_recycle(struct io_kiocb *req, unsigned issue_flags) */ if (req->flags & REQ_F_BUFFER_RING) { if (req->buf_list) { - req->buf_index = req->buf_list->bgid; - req->flags &= ~REQ_F_BUFFER_RING; + if (req->flags & REQ_F_PARTIAL_IO) { + req->buf_list->head++; + req->buf_list = NULL; + } else { + req->buf_index = req->buf_list->bgid; + req->flags &= ~REQ_F_BUFFER_RING; + } } return; } diff --git a/io_uring/kbuf.h b/io_uring/kbuf.h index b58d9d20c97e..9ecb175e60a9 100644 --- a/io_uring/kbuf.h +++ b/io_uring/kbuf.h @@ -58,8 +58,14 @@ static inline void io_kbuf_recycle(struct io_kiocb *req, unsigned issue_flags) { if (!(req->flags & (REQ_F_BUFFER_SELECTED|REQ_F_BUFFER_RING))) return; - /* don't recycle if we already did IO to this buffer */ - if (req->flags & REQ_F_PARTIAL_IO) + /* + * For legacy provided buffer mode, don't recycle if we already did + * IO to this buffer. For ring-mapped provided buffer mode, we should + * increment ring->head to explicitly monopolize the buffer to avoid + * multiple use. + */ + if ((req->flags & REQ_F_BUFFER_SELECTED) && + (req->flags & REQ_F_PARTIAL_IO)) return; __io_kbuf_recycle(req, issue_flags); }