From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C96EC43603 for ; Sat, 14 Dec 2019 14:53:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EE11C24656 for ; Sat, 14 Dec 2019 14:53:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OA1qGASg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725895AbfLNOxm (ORCPT ); Sat, 14 Dec 2019 09:53:42 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:36878 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725872AbfLNOxm (ORCPT ); Sat, 14 Dec 2019 09:53:42 -0500 Received: by mail-lf1-f68.google.com with SMTP id b15so1313792lfc.4; Sat, 14 Dec 2019 06:53:40 -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=LtP8axFgRqFzauZbZkt21kxhVbu1x/apgV9RLv9E/DQ=; b=OA1qGASgsSIpKlr/o/6TKcWH/VY+zcBPwUz5lPJxoCObhk9koCvbAraNki+N8M323y V1npiOLFbqo0JgJiDKWCqJTCu/wJQXq3OiNyC6QrQk9+gAcvAtd3W44q8NmE5pxry/Yh vlPwQeu0Qq4EAXXf64Z7AbzQPztqYv6ycl+SpXGnzzLz8wNYcbeZ9Ffnm6Ztabe7cBs0 06c1k29iRaTbRCSEDMGwnbXzozVv19/8f6TMdOV3PtxnfHBlsmkeYlqV3AlIr4Vmo4od GffNLL/YoSMkHQa75DoHDe8NQGhoX8BFQAi9ehHWiecQ1jP4NQJMNe25l2jPEW0F2kuS i6vw== 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=LtP8axFgRqFzauZbZkt21kxhVbu1x/apgV9RLv9E/DQ=; b=LVkn/4iEX3Lw7HU8HMMylhFSQKyXvEsw6Gg2RIe+mKjDSGkoSwj8v8tuHHjVDF2XkQ MqmPUt50RmmeY7QWgRVzJB/zOjANLUOC/7s8igPuDnrQ6KaLOMErnDV/2v3+Zcq++NGA S0ispmeZnv4Zncv0DyDLauelEYaETWwomdmqQDO2HsNZvEqYKD3XJza38v0UwAwM6AEA F/opQDMn8SG+dyAVwlL5nt1CPT/yyJXPGZmbBN9V3rtwtsledyAC8pYJyv+DPy2W2J5b EVGCne1IZzW+3nDOv8Ob6CGyJsbWY9tbUdaaqAbDKC3sowMfGTS8apqaRczWBGlQSBgx bSZg== X-Gm-Message-State: APjAAAW3Q6IAkE52PwKX3jNPa5/UIlnF3TV4/JtEfBTazcRwDqdEaWs7 Brj4PpfuExYIipbwrysZw/E= X-Google-Smtp-Source: APXvYqwHOwTLEmzguOMBkv/bixIiSVVQLsRatRso9F0PQ4xDdWTJ7Zf/4xTHWceJQgmy71rf2GAGrA== X-Received: by 2002:ac2:4945:: with SMTP id o5mr11368865lfi.93.1576335219887; Sat, 14 Dec 2019 06:53:39 -0800 (PST) Received: from localhost.localdomain ([212.122.72.247]) by smtp.gmail.com with ESMTPSA id h19sm6771480ljl.57.2019.12.14.06.53.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Dec 2019 06:53:39 -0800 (PST) From: Pavel Begunkov To: Jens Axboe , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] io_uring: don't wait when under-submitting Date: Sat, 14 Dec 2019 17:53:14 +0300 Message-Id: X-Mailer: git-send-email 2.24.0 In-Reply-To: <6256169d519f72fe592e70be47a04aa0e9c3b9a1.1576333754.git.asml.silence@gmail.com> References: <6256169d519f72fe592e70be47a04aa0e9c3b9a1.1576333754.git.asml.silence@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: io-uring-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org There is no reliable way to submit and wait in a single syscall, as io_submit_sqes() may under-consume sqes (in case of an early error). Then it will wait for not-yet-submitted requests, deadlocking the user in most cases. In such cases adjust min_complete, so it won't wait for more than what have been submitted in the current call to io_uring_enter(). It may be less than totally in-flight including previous submissions, but this shouldn't do harm and up to a user. Signed-off-by: Pavel Begunkov --- v2: cap min_complete if submitted partially (Jens Axboe) v3: update commit message (Jens Axboe) fs/io_uring.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 81219a631a6d..5dfc805ec31c 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -3763,11 +3763,8 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr, unsigned int sqe_flags; req = io_get_req(ctx, statep); - if (unlikely(!req)) { - if (!submitted) - submitted = -EAGAIN; + if (unlikely(!req)) break; - } if (!io_get_sqring(ctx, req)) { __io_free_req(req); break; @@ -5272,6 +5269,14 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit, submitted = io_submit_sqes(ctx, to_submit, f.file, fd, &cur_mm, false); mutex_unlock(&ctx->uring_lock); + + if (submitted != to_submit) { + if (!submitted) { + submitted = -EAGAIN; + goto done; + } + min_complete = min(min_complete, (u32)submitted); + } } if (flags & IORING_ENTER_GETEVENTS) { unsigned nr_events = 0; @@ -5284,7 +5289,7 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit, ret = io_cqring_wait(ctx, min_complete, sig, sigsz); } } - +done: percpu_ref_put(&ctx->refs); out_fput: fdput(f); -- 2.24.0