From patchwork Mon Sep 26 23:44:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12989607 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 00A0FC07E9D for ; Mon, 26 Sep 2022 23:46:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229760AbiIZXqC (ORCPT ); Mon, 26 Sep 2022 19:46:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229542AbiIZXqB (ORCPT ); Mon, 26 Sep 2022 19:46:01 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2F6A8A1DB for ; Mon, 26 Sep 2022 16:46:00 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id s14so12596470wro.0 for ; Mon, 26 Sep 2022 16:46:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=MWf2JMcAHHBE1hwpwhCIJnSpqlaA9N7ZdDzYoRDa2V8=; b=F0ojKyqsFjDiYqrP2HC8I6XDEI6O4kh4PpbmjtbZa9KwjbE6kewS7y7G0rsPvzE4nq pkq+YY/lGtWRkMJQjXq3Rsw9rIZamdw+eQu7K4kBjUJND+4J5eqvoALTYWsunLPv948/ ZUKjphMpnItUv8cPyEMzN1J0OxswX6z/TsBUJzRfBwkGqaIu4tdOkohBz6E1rjzZoG2N tQfGRnWokpz4KXBagm8XBWVMxlR+kUtyhvIWhq/p+tNj9aDCC8MPdzJZYm/cM0kAqKH/ oeV1XFieNv6ByP0OOcr9BV0h5feNJgMykZ2p8vZfoJ/ppZl+TxIR8JVwfljCWR3T8OWO 7R9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=MWf2JMcAHHBE1hwpwhCIJnSpqlaA9N7ZdDzYoRDa2V8=; b=kjl8TcDfMQ26khH6uIGiUjwoJU3FMDNTPp7WNacjH8I5SJlMMNZ8NjPaqyPYzHewFn KtBlHLt7FeJditQ2+EVbtiYiV+h6+HRFSC4Pm4lJ2PSpFThoTkDzPvzHwCCBpqhrzBJo uybQA7CO6ejLy0U4d/p96I6rt4MpJQPMDoSuddfjj/m9+hHxB3wQLkKpZaA8nRm42D99 ttXq2OPEXWWll5S6ypmP0iHFE0lX1qKoBHpRbWnBSk+k/tLLUOc/+lBIyqNNFbumpPfk 2pYWLUhgNbxx9om7qiKFSwGzYg9mgjnpfQ9IBEEuwZT0WBXwn9O4IKTK9jQzlDko53/S jThw== X-Gm-Message-State: ACrzQf0xWLmEq1LXWxrJKBCoFeO6b9t81Kbfuzj7Tyt9nlrCW0VacHAY lyEEw08b5SoSxI9x6vVcdwzlZrC2beg= X-Google-Smtp-Source: AMsMyM4E0Cy/giQZuPVUBC7W49rnOBujZhuKzudh7DDCbd0Unz+QLjCSlLtHFbj3DtJQbSKsQn6hRw== X-Received: by 2002:a5d:64c2:0:b0:228:cb3e:1ce with SMTP id f2-20020a5d64c2000000b00228cb3e01cemr14900352wri.392.1664235958942; Mon, 26 Sep 2022 16:45:58 -0700 (PDT) Received: from 127.0.0.1localhost (94.196.228.157.threembb.co.uk. [94.196.228.157]) by smtp.gmail.com with ESMTPSA id l16-20020a05600012d000b0022abd7d57b1sm89318wrx.115.2022.09.26.16.45.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 16:45:58 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, Beld Zhang Subject: [PATCH for-next v2 1/2] io_uring/rw: fix unexpected link breakage Date: Tue, 27 Sep 2022 00:44:39 +0100 Message-Id: <3a1088440c7be98e5800267af922a67da0ef9f13.1664235732.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org req->cqe.res is set in io_read() to the amount of bytes left to be done, which is used to figure out whether to fail a read or not. However, io_read() may do another without returning, and we stash the previous value into ->bytes_done but forget to update cqe.res. Then we ask a read to do strictly less than cqe.res but expect the return to be exactly cqe.res. Fix the bug by updating cqe.res for retries. Cc: stable@vger.kernel.org Reported-and-Tested-by: Beld Zhang Signed-off-by: Pavel Begunkov --- io_uring/rw.c | 1 + 1 file changed, 1 insertion(+) diff --git a/io_uring/rw.c b/io_uring/rw.c index 59c92a4616b8..ed14322aadb9 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -793,6 +793,7 @@ int io_read(struct io_kiocb *req, unsigned int issue_flags) return -EAGAIN; } + req->cqe.res = iov_iter_count(&s->iter); /* * Now retry read with the IOCB_WAITQ parts set in the iocb. If * we get -EIOCBQUEUED, then we'll get a notification when the From patchwork Mon Sep 26 23:44:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12989608 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 908A0C32771 for ; Mon, 26 Sep 2022 23:46:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229542AbiIZXqE (ORCPT ); Mon, 26 Sep 2022 19:46:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229913AbiIZXqD (ORCPT ); Mon, 26 Sep 2022 19:46:03 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C00D18A1FB for ; Mon, 26 Sep 2022 16:46:01 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id c11so12466152wrp.11 for ; Mon, 26 Sep 2022 16:46:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=yeTVKqHS44D0sYF8vHhQLsW0veSVF9jujNYiKozf49E=; b=nKxEZ2zVV9wpyGPciSAddIOdShVzxIeV1w0WQ9HVHY2yefVmSJcwl1gx1/8yD+JihW 6ZI9x6YLaxfZRSyauC7JXB4P594f3NQ1NnKaxz4w0jOCjP7U9o7OSOOtm5Kdl7z63w/f mm/SjNc4qOe4QHPDJ36ANX3zs8EVIKRunEpUumqZtB1Y/8mTWy6HXMlGJb5cneBWi8Ny qeRmhKg5JOR7Oj0qQ6i71dYZnlr1U3dEHsJIOi/13RbRbtXb+UxjcVJMy2jqQAJqPIxv WWxrVZhqj0+NnviSZZviiC61qSvgd88TEsD7jfL5Ej9SjPBLeGEu4y3TR0zdDaqT0T5j UnsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=yeTVKqHS44D0sYF8vHhQLsW0veSVF9jujNYiKozf49E=; b=EmnMe26U7eRY78QucYHNLFVMqJvKFdRuJCnp9kXj7El7/mfHJUUoeqWYbdkpazGpHU X5GAd/Re8DyqGO6jNPOJORTK/hdkdJmAi5ITfiZqOXZUslMc+gYOk97Z98fo3D/RdI0g OVhlv7MjdkYjOUHblUO2Tm2I3ydQ2Xaj8aJcpDGVodRVvmgX6D4tnyDC3Qbi0z7CpFQr iqUnMfKWEA2QWLEuLmvgQ+2xi9KFXMjNr98UHJGdm+XD/c7874M+A6/6jnLiSfINqmFD V2zRG/azB3D50lVVrKceCjS41zEPsHY8Ow0005hyVPQ5//vt+HPSTXEd88iReUlwkVpX ZDyw== X-Gm-Message-State: ACrzQf0PzBsqxrmKTBNHRpCbgGP5IsMKcCeg82+YIaz1oDcnoYCyZOcC 4hMGliyTHnge4imr2xc+XRd+UMCd82I= X-Google-Smtp-Source: AMsMyM7+p5WimJbflwdGsKdLNGJQXk2SD8CkQkDmlX0eTAhPgmcqIvOG+kklHgikpA5chHwuJFPv7Q== X-Received: by 2002:adf:b646:0:b0:221:76eb:b3ba with SMTP id i6-20020adfb646000000b0022176ebb3bamr14665544wre.237.1664235960065; Mon, 26 Sep 2022 16:46:00 -0700 (PDT) Received: from 127.0.0.1localhost (94.196.228.157.threembb.co.uk. [94.196.228.157]) by smtp.gmail.com with ESMTPSA id l16-20020a05600012d000b0022abd7d57b1sm89318wrx.115.2022.09.26.16.45.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 16:45:59 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH for-next v2 2/2] io_uring/rw: don't lose short results on io_setup_async_rw() Date: Tue, 27 Sep 2022 00:44:40 +0100 Message-Id: <0e8d20cebe5fc9c96ed268463c394237daabc384.1664235732.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org If a retry io_setup_async_rw() fails we lose result from the first io_iter_do_read(), which is a problem mostly for streams/sockets. Cc: stable@vger.kernel.org Signed-off-by: Pavel Begunkov --- io_uring/rw.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/io_uring/rw.c b/io_uring/rw.c index ed14322aadb9..1ae1e52ab4cb 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -764,10 +764,12 @@ int io_read(struct io_kiocb *req, unsigned int issue_flags) iov_iter_restore(&s->iter, &s->iter_state); ret2 = io_setup_async_rw(req, iovec, s, true); - if (ret2) - return ret2; - iovec = NULL; + if (ret2) { + ret = ret > 0 ? ret : ret2; + goto done; + } + io = req->async_data; s = &io->s; /*