Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1159127ybl; Fri, 13 Dec 2019 10:33:39 -0800 (PST) X-Google-Smtp-Source: APXvYqyVgR1/RM7TaiEeYuE0C93xVqpg8ZA7LbUbH0zsZKJtyO3gFEMkIwnBVSwXobm/sn4BjBDf X-Received: by 2002:a9d:7447:: with SMTP id p7mr15189203otk.189.1576262019560; Fri, 13 Dec 2019 10:33:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576262019; cv=none; d=google.com; s=arc-20160816; b=Zf4p8zJ55NHjv9Sz/LjeiMKfRfQVDb9OPEFYLRYnPgCFSRfr/Smlggm20KvxYq4Jy4 BmLNQXirUyp6vUj+94VehK6EwgDWwqS1jzC1cZ53M429qhLDUKLxkHq3rzVHNGDVNune BJKDlJZubKAwFVdSnguTDG4v/0uiaAietdYTDVO1Xbh7KOUJFMc4HJjou4uY7RrKJ6U3 Cptm1mM8DFJGw1wTcIgIWj/oy8XLf8+Ws/agZCraGDobRjRjAku/bOzvZg8JppcbdiNI 64IHcDx/WIjuwiuAgc0rQa56ayKCukoTAABzYczrPQHI55askFDL5uo0Ncg2UzWtySaP kmTQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:to:from:subject:dkim-signature; bh=5Ho3srihBAE8WuqzThl+Cpq/uBCrB5qBgKR3HmQKsxU=; b=NPM+qBtzqJHLBdue9NXVxoKVB+QqpxA781pKGzk9EvLwYsXdxwMuGs95hnZhcjDjfK 0ywD+ZpmefoaOD/U+NmRaUzIBC967hb0G6E0TgG4vET+wGhKyyBHbCq/sdssPQgbsp5O U3UOMUiChiLPXrgygcoiZICUUd4jpu5XHYRylyI4rF7naUrLvIgGP+Eh/Erx7KL+v90Y hkvhjKXJrAgtbEKVSW9k0nzqpj5z8/syWlpI/fTmU0t3tbBRwvIvXVK73J6BzlOL1HTU Ht3WUAMtS9DsEeiZyu7LiYAjU2bZ0GSIpzikI4E6bugx6ANh1LxcjhLM0aihWM8ZZ7fq L/Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=1rG8VDBf; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j9si5133035otq.317.2019.12.13.10.33.27; Fri, 13 Dec 2019 10:33:39 -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=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=1rG8VDBf; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728810AbfLMScm (ORCPT + 99 others); Fri, 13 Dec 2019 13:32:42 -0500 Received: from mail-il1-f195.google.com ([209.85.166.195]:42742 "EHLO mail-il1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728699AbfLMScl (ORCPT ); Fri, 13 Dec 2019 13:32:41 -0500 Received: by mail-il1-f195.google.com with SMTP id a6so213739ili.9 for ; Fri, 13 Dec 2019 10:32:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:from:to:references:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=5Ho3srihBAE8WuqzThl+Cpq/uBCrB5qBgKR3HmQKsxU=; b=1rG8VDBf1RzS6fLt6IZMvsGREvW/pB39avCyZC+RA7z8lS+72OOEAbK0AX/E4uEFi9 1pcAEAISjkBkzz+s+qx+f6cv0K9X7/PKhCumokvg8oGTO30cCYTkOrdcrjxq1X2C5lqy 40hX1py4b2WRqaGyi5TvYrHNZ19KSfHiXoTvwmneHfOx1mumq1q2mFU5JK/N2pplYOU5 fo3zlX0iSQ6zrkh9qTgOKKyf94r3l4pSZIeDIlslhIlpGLDzKAWtBaafMApfkfOp01Wx /qfgef5eZtzAUW50+Cbtkj1ePMHN/+TELH2qeHCu4um3Me98g9gkx6CNV0hWbFfvvxyh droQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=5Ho3srihBAE8WuqzThl+Cpq/uBCrB5qBgKR3HmQKsxU=; b=FA4g1Bve/VBTZqWomvaiirHx6ajXnIrAo6yZibwpwqnBPE1BgVENjpkx9TihmMaJ9D r7XAntkHQ8Pvo08rM+3y0K+6KXkyKDKVW2XQLY2E/bxf6QdMFjrDfqSvY+5tTWjZb5aU G42wd79pI3WBOuBA3cNYMIeJbd8+KjpxE99NqIwwowdBrmc3cr274bjN6Ta6DnMJzzD3 J2KZpC1qWiwKvMqqkEiR0n+B+pOzey3/lq2q+P0rtlFD34ql4Zh8ViiLFgmrvcw+ukN7 QiFhgVweLgrtAL3rxB9Fb9nnAUhWlyXWnanhVUPFfW8SFXrJbrYDSFkB7aiFt7KGQTVj FiOA== X-Gm-Message-State: APjAAAWqRQdYBC1aPvwee9hm9eYEU6WJ08DMlwi9GJRwmfRkCoy1tf5N Tof7+0R0FQJE56ZhURDw/BfgXLESKY8hBg== X-Received: by 2002:a92:d806:: with SMTP id y6mr687452ilm.234.1576261960431; Fri, 13 Dec 2019 10:32:40 -0800 (PST) Received: from [192.168.1.159] ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id r22sm2942913ilb.25.2019.12.13.10.32.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 13 Dec 2019 10:32:39 -0800 (PST) Subject: Re: [PATCH 1/1] io_uring: don't wait when under-submitting From: Jens Axboe To: Pavel Begunkov , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org References: <5caa38be87f069eb4cc921d58ee1a98ff5d53978.1576223348.git.asml.silence@gmail.com> <21ca72b0-c35d-96b7-399f-d4034d976c27@kernel.dk> Message-ID: <9fbb03f4-6444-04a6-4cfb-ee4b3aa0bcd1@kernel.dk> Date: Fri, 13 Dec 2019 11:32:38 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <21ca72b0-c35d-96b7-399f-d4034d976c27@kernel.dk> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/13/19 11:22 AM, Jens Axboe wrote: > On 12/13/19 12:51 AM, Pavel Begunkov wrote: >> 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. > > Why not just cap the wait_nr? If someone does to_submit = 8, wait_nr = 8, > and we only submit 4, just wait for 4? Ala: > > diff --git a/fs/io_uring.c b/fs/io_uring.c > index 81219a631a6d..4a76ccbb7856 100644 > --- a/fs/io_uring.c > +++ b/fs/io_uring.c > @@ -5272,6 +5272,10 @@ 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 <= 0) > + goto done; > + if (submitted != to_submit && min_complete > submitted) > + min_complete = submitted; > } > if (flags & IORING_ENTER_GETEVENTS) { > unsigned nr_events = 0; > @@ -5284,7 +5288,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); > This is probably a bit cleaner, since it only adjusts if we're going to wait. diff --git a/fs/io_uring.c b/fs/io_uring.c index 81219a631a6d..e262549a2601 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -5272,11 +5272,15 @@ 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 <= 0) + goto done; } if (flags & IORING_ENTER_GETEVENTS) { unsigned nr_events = 0; min_complete = min(min_complete, ctx->cq_entries); + if (submitted != to_submit && min_complete > submitted) + min_complete = submitted; if (ctx->flags & IORING_SETUP_IOPOLL) { ret = io_iopoll_check(ctx, &nr_events, min_complete); @@ -5284,7 +5288,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); -- Jens Axboe