Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp835365pxb; Thu, 9 Sep 2021 13:13:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUYRqbKu/he055CBVSWfBAMGM0a6ja/0osbq+nEchM8UWF1qSVnk8txvymBNQ6b5reC4ZC X-Received: by 2002:a6b:8f4e:: with SMTP id r75mr4222707iod.172.1631218435068; Thu, 09 Sep 2021 13:13:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631218435; cv=none; d=google.com; s=arc-20160816; b=gboD7j5TVB5c9FECGN9A940cc/D2EZxoS2YjzSskEmqwErnph0Td2KYQTXuFgF8ksv 9yxRIZa61NlE6DpRMEd3fhKnSMJelUziznUgMAjQ/gdu6x0kG2qnFGYlGTKLV90pQ2c5 ReSWVW93lav4Ju7XLWvoNxC649lUCyZv2pbs0UoXktQXCveQTaiwhBuDmlu4T7lGdOC1 VJL2JYs0vWPYwoxPOe7G9Seag1svhevOVYMh/fDKpG0lU0yTZ0GsQZaKaU0KPB9BFGV+ VfUcEcX2K7bfVPf/FWSeyYXwe0C7o5E8qSSoBsBXZ3JX41feJideKNrmlelIL8x5oiOF go2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=VCQSRehR2ZOFo/zjKqjv0LY16gqxQWCKetw3T+VgWXE=; b=XLfgo2TZXcPduqCkwypo9zIF3we0v3z9jgYdxPGilfp5klBsgxIWFCfyOe1s/jrBRC f49B7T/8Gx61mQ2K2tB88CFwdHSaNWJ1NabbL6cuLj3UzbNVLQX00QwKLqdgFPo/ovUD 9qIY6sOf5R576BO6ambFsIUtx5N0w1rKkIdVcyg3tf3Uluh0tzUfEB8zwWcRJ6JYreap qEWPFFQZvP339jaMs7qOwQFl6dt++XS2gM3RNXYV7MxnQ/Vr78rhcJHgfWQwdBeCIEay cTZnYln8RvE45nqrqJjTBI13u8c/rQDsEzi/G/ubbKb4HSaE8yVRsC+lJJQTgUcYHfWz llRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=AliT6R74; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a12si3152271ilt.135.2021.09.09.13.13.42; Thu, 09 Sep 2021 13:13:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=AliT6R74; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245624AbhIITjX (ORCPT + 99 others); Thu, 9 Sep 2021 15:39:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245263AbhIITjX (ORCPT ); Thu, 9 Sep 2021 15:39:23 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3725BC061575 for ; Thu, 9 Sep 2021 12:38:13 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id p15so4773763ljn.3 for ; Thu, 09 Sep 2021 12:38:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VCQSRehR2ZOFo/zjKqjv0LY16gqxQWCKetw3T+VgWXE=; b=AliT6R74tIzwlYSKpVb0jpl+QAkq5TlMBBdZh/VSrASCQJ5jZSDBd+2VKAtFoAun9o INXNuZN30cPsf7inYtabYnvsYnM+4N+LDuUwHBxHM3jEk1kzU0ACPdcHWBnoQ8KgEx2y DAJ3UQGzsVpIbYzABfU4I7iyeRkKdC3yHuQzw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VCQSRehR2ZOFo/zjKqjv0LY16gqxQWCKetw3T+VgWXE=; b=qX08kk+Zsb+CcUtoe78GaDW9YboI0sDfYkIDN+o4K6fM0T/mBjlabh3h/SXQLpPUcq QJtJxNv3KkfmpH2MEbQM86JGM+Xn5u/DUTy7xCxloYBN5CD2smnuu0kEfBpenjrre8RL TUptQsYjpVRzg918vF8+3gNYYA3B0j0mXToEQ/1X6ka/YOmfPtvasP3AAvU3tC5Jwy8a q+HbNxdEonaF6UjhfQPBvyW+68f2U5dx8nThUtBrFhUAHas2Rg62Z2/ikaVuDbBaSNXX XKKthlbdJycRCQxA2DhlvJXyuerzVkGR423lvczwFME231oIScLIQNGMDursOOHQxWDE gPrA== X-Gm-Message-State: AOAM530dTRLpJ5BQnElMoGrDpOvXGMAvbdLxaPsGxlbOG2FpWpkiEsAK TneB+wMZn6M3U6nxpoUhPYXbuC1GTKgqrO/RJb0= X-Received: by 2002:a2e:351a:: with SMTP id z26mr1145078ljz.59.1631216290993; Thu, 09 Sep 2021 12:38:10 -0700 (PDT) Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com. [209.85.167.50]) by smtp.gmail.com with ESMTPSA id c17sm289321lfb.257.2021.09.09.12.38.10 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Sep 2021 12:38:10 -0700 (PDT) Received: by mail-lf1-f50.google.com with SMTP id a4so5843310lfg.8 for ; Thu, 09 Sep 2021 12:38:10 -0700 (PDT) X-Received: by 2002:a05:6512:34c3:: with SMTP id w3mr1059425lfr.173.1631216289838; Thu, 09 Sep 2021 12:38:09 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Linus Torvalds Date: Thu, 9 Sep 2021 12:37:53 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [git pull] iov_iter fixes To: Al Viro , Jens Axboe , Pavel Begunkov Cc: Linux Kernel Mailing List , linux-fsdevel Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 8, 2021 at 9:24 PM Al Viro wrote: > > Fixes for io-uring handling of iov_iter reexpands Ugh. I have pulled this, because I understand what it does and I agree it fixes a bug, but it really feels very very hacky and wrong to me. It really smells like io-uring is doing a "iov_iter_revert()" using a number that it pulls incorrectly out of its arse. So when io-uring does that iov_iter_revert(iter, io_size - iov_iter_count(iter)); what it *really* wants to do is just basically "iov_iter_reset(iter)". And that's basically what that addition of that "iov_iter_reexpand()" tries to effectively do. Wouldn't it be better to have a function that does exactly that? Alternatively (and I'm cc'ing Jens) is is not possible for the io-uring code to know how many bytes it *actually* used, rather than saying that "ok, the iter originally had X bytes, now it has Y bytes, so it must have used X-Y bytes" which was actively wrong for the case where something ended up truncating the IO for some reason. Because I note that io-uring does that /* may have left rw->iter inconsistent on -EIOCBQUEUED */ iov_iter_revert(&rw->iter, req->result - iov_iter_count(&rw->iter)); in io_resubmit_prep() too, and that you guys missed that it's the exact same issue, and needs that exact same iov_iter_reexpand(). That "req->result" is once again the *original* length, and the above code once again mis-handles the case of "oh, the iov got truncated because of some IO limit". So I've pulled this, but I think it is (a) ugly nasty (b) incomplete and misses a case and needs more thought. At the VERY least it needs that iov_iter_reexpand() in io_resubmit_prep() too, I think. I'd like the comments expanded too. In particular that /* some cases will consume bytes even on error returns */ really should expand on the "some cases" thing, and why such an error isn't fatal buye should be retried asynchronously blindly like this? Because I think _that_ is part of the fundamental issue here - the io_uring code tries to just blindly re-submit the whole thing, and it does it very badly and actually incorrectly. Or am I missing something? Linus