Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp2640869ybf; Mon, 2 Mar 2020 12:46:40 -0800 (PST) X-Google-Smtp-Source: ADFU+vugB6v4nsbW5OEmof8Q0qiYZs3LMfJ+awOpW+QKyu5LSqSSz673IX4A3j/BreYdcmRE4rPt X-Received: by 2002:a05:6830:104d:: with SMTP id b13mr598512otp.42.1583182000787; Mon, 02 Mar 2020 12:46:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583182000; cv=none; d=google.com; s=arc-20160816; b=pQRZpbiHBPsPpnImD8eDkLBrrTZo5R8ugCpgFHSTnfEA/nuzgwWZfgeQxidR531Tnc xg7Z67cnJNydw2F9wymrr9d3/kASqVyTaWCGLpl9R9IAGLPmN0uoHKYEkdlrDnp2dLNp H6XKyX6w0cN4tPeYQL1TKSK0p3tQNy7BVJdvdaq6VFo66KlNn8AY3IE1dHR6MDs0SoET rI/QQqXZ7hKxajKHvs+JUVND+WPWjYTDGLYbLdb2vOu6pEYg4DapRusfesoZHVCowsrR TVBdL6lnJdp3RPK35eFeuNlRSrmt1nNFGjj3HnbrXT/RUZCiYGwMm/81l9jyG5sCjufN fPow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=LiVaYMYbUqVkP59cyO56jsLqHdgbJcbPk8cCf+c5iQk=; b=Hc9SUPfqIiQHKc9RVapX1mpDHlVPBkLzh1HwORZW95STs46fv/MmSN1R+6G/ZR9h2R wkbjm9PjBMyGwb5I/83RRpzqEgv9yDTHtGqYVhfllAhuDEtNbDXS1mR0OOWvzVfly1Ng ZH2UeyF2SGq6ZXCGER+vx3BsXOVGl+9dcO4NPXRaa0nANIapa8ouacyAaBVmWNv23tl0 sjYS+A1fwbcfgrBoIgOHIo4/1MX0iZ57NCCBvC8KOBNDKH9Sf3Pj7N5qTRLu9d91SRI0 sxWKB7zIpc1krHC6QFLuodP1IIlvHL7oub2s2mQ0nRXUvBnAwpSrr06rLqLpu03wnEzS 1cTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VDYhoM+G; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g10si4073784otk.137.2020.03.02.12.46.28; Mon, 02 Mar 2020 12:46:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VDYhoM+G; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726891AbgCBUqW (ORCPT + 99 others); Mon, 2 Mar 2020 15:46:22 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:54329 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726859AbgCBUqV (ORCPT ); Mon, 2 Mar 2020 15:46:21 -0500 Received: by mail-wm1-f68.google.com with SMTP id z12so563551wmi.4; Mon, 02 Mar 2020 12:46:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=LiVaYMYbUqVkP59cyO56jsLqHdgbJcbPk8cCf+c5iQk=; b=VDYhoM+GRA8h10UXlzddLLQx4vSaobwAFLVAmwUqtfy5lppuxGh2ziDeKcdo49s4N6 NbHoQY9pl1EssocnWic/a89dF4TJwlIbpEvjrxHmM+1KARspHph8QsbkPq4n+kTGJRDL /AgSRQix+BxehDipE/jKNXUv7F3nBRNiyRc6I41vr2g2uhLUN6xOZxxLox4tCsw1lrKk qSADnZip8++Ho0SI//qmyfjL+fNpDKxyOrozhH55R7fkVJ3HT8hwOdaKy1dTVNkNzrFG ZdstYla+kdmhX/xFGoMFaavY0LX5p7hCg1KwOTkBIoHzYkckAgnxJN5YP81oVp1jxeCX uoWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LiVaYMYbUqVkP59cyO56jsLqHdgbJcbPk8cCf+c5iQk=; b=eHGhRitmH0cj3+bIuTU9RXSCohbnFaStTr5egMsm6VMYDK7fe9JTYd6nVJOMFC6KQR wHqRkr7oZ8NVBxiYJjU8wULQPXbptLoDN9/W1NnqAF5pcyfGdIOcWCk7341e87SSVx5O FsCG+s1oUYrXawYf7/uk5JscnlOArVWtRojU2gg8l/mrlRzaiuH2nbr0FZHLL6wPH+6b bH2MkN4sY7jiFh9vSIrohYVNi3MGoQ76/pFZcQ0FjJKdmzz9SMVBk+j56aAxyaQ9Gypv a6eP9mrrYE5XPOHzuGZW2JaOY5hj2gQ5QtvSaesoX2Fak3dniPzZnFlsRmXWE00KNBuy QhDg== X-Gm-Message-State: ANhLgQ2LKRlOQulgSM9dsfw4/P3JLQabNs0YVIa/VhKm/GHGH+HnX85M RdT1mDqqhGFK5DjeDKFmzCFsy3xp X-Received: by 2002:a7b:c3d1:: with SMTP id t17mr232855wmj.27.1583181979094; Mon, 02 Mar 2020 12:46:19 -0800 (PST) Received: from localhost.localdomain ([109.126.130.242]) by smtp.gmail.com with ESMTPSA id b14sm20186549wrn.75.2020.03.02.12.46.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2020 12:46:18 -0800 (PST) From: Pavel Begunkov To: Jens Axboe , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/4] io_uring: make submission ref putting consistent Date: Mon, 2 Mar 2020 23:45:17 +0300 Message-Id: X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The rule is simple, any async handler gets a submission ref and should put it at the end. Make them all follow it, and so more consistent. This is a preparation patch, and as io_wq_assign_next() currently won't ever work, this doesn't care to use io_put_req_find_next() instead of io_put_req(). Signed-off-by: Pavel Begunkov --- fs/io_uring.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index ff6cc05b86c7..ad8046a9bc0f 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -2550,7 +2550,7 @@ static bool io_req_cancelled(struct io_kiocb *req) if (req->work.flags & IO_WQ_WORK_CANCEL) { req_set_fail_links(req); io_cqring_add_event(req, -ECANCELED); - io_put_req(req); + io_double_put_req(req); return true; } @@ -2600,6 +2600,7 @@ static void io_fsync_finish(struct io_wq_work **workptr) if (io_req_cancelled(req)) return; __io_fsync(req, &nxt); + io_put_req(req); /* drop submission reference */ if (nxt) io_wq_assign_next(workptr, nxt); } @@ -2609,7 +2610,6 @@ static int io_fsync(struct io_kiocb *req, struct io_kiocb **nxt, { /* fsync always requires a blocking context */ if (force_nonblock) { - io_put_req(req); req->work.func = io_fsync_finish; return -EAGAIN; } @@ -2621,9 +2621,6 @@ static void __io_fallocate(struct io_kiocb *req, struct io_kiocb **nxt) { int ret; - if (io_req_cancelled(req)) - return; - ret = vfs_fallocate(req->file, req->sync.mode, req->sync.off, req->sync.len); if (ret < 0) @@ -2637,7 +2634,10 @@ static void io_fallocate_finish(struct io_wq_work **workptr) struct io_kiocb *req = container_of(*workptr, struct io_kiocb, work); struct io_kiocb *nxt = NULL; + if (io_req_cancelled(req)) + return; __io_fallocate(req, &nxt); + io_put_req(req); /* drop submission reference */ if (nxt) io_wq_assign_next(workptr, nxt); } @@ -2659,7 +2659,6 @@ static int io_fallocate(struct io_kiocb *req, struct io_kiocb **nxt, { /* fallocate always requiring blocking context */ if (force_nonblock) { - io_put_req(req); req->work.func = io_fallocate_finish; return -EAGAIN; } @@ -3015,6 +3014,7 @@ static void io_close_finish(struct io_wq_work **workptr) /* not cancellable, don't do io_req_cancelled() */ __io_close_finish(req, &nxt); + io_put_req(req); /* drop submission reference */ if (nxt) io_wq_assign_next(workptr, nxt); } @@ -3038,6 +3038,8 @@ static int io_close(struct io_kiocb *req, struct io_kiocb **nxt, * the file again and cause a double CQE entry for this request */ io_queue_async_work(req); + /* submission ref will be dropped, take it for async */ + refcount_inc_not_zero(&req->refs); return 0; } @@ -3088,6 +3090,7 @@ static void io_sync_file_range_finish(struct io_wq_work **workptr) if (io_req_cancelled(req)) return; __io_sync_file_range(req, &nxt); + io_put_req(req); /* put submission ref */ if (nxt) io_wq_assign_next(workptr, nxt); } @@ -3097,7 +3100,6 @@ static int io_sync_file_range(struct io_kiocb *req, struct io_kiocb **nxt, { /* sync_file_range always requires a blocking context */ if (force_nonblock) { - io_put_req(req); req->work.func = io_sync_file_range_finish; return -EAGAIN; } @@ -3464,11 +3466,10 @@ static void io_accept_finish(struct io_wq_work **workptr) struct io_kiocb *req = container_of(*workptr, struct io_kiocb, work); struct io_kiocb *nxt = NULL; - io_put_req(req); - if (io_req_cancelled(req)) return; __io_accept(req, &nxt, false); + io_put_req(req); /* drop submission reference */ if (nxt) io_wq_assign_next(workptr, nxt); } @@ -4733,17 +4734,14 @@ static void io_wq_submit_work(struct io_wq_work **workptr) } while (1); } - /* drop submission reference */ - io_put_req(req); - if (ret) { req_set_fail_links(req); io_cqring_add_event(req, ret); io_put_req(req); } - /* if a dependent link is ready, pass it back */ - if (!ret && nxt) + io_put_req(req); /* drop submission reference */ + if (nxt) io_wq_assign_next(workptr, nxt); } -- 2.24.0