From patchwork Mon Sep 26 23:20:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12989588 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 C1B55C07E9D for ; Mon, 26 Sep 2022 23:23:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231281AbiIZXXz (ORCPT ); Mon, 26 Sep 2022 19:23:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230464AbiIZXXa (ORCPT ); Mon, 26 Sep 2022 19:23:30 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B40974CFD for ; Mon, 26 Sep 2022 16:21:41 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id l8so5498885wmi.2 for ; Mon, 26 Sep 2022 16:21:41 -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=2lSUpe592kbPQPhQMkeGWB6/Vun9yDD9GrzMvVsq/YE=; b=JFbAjsOf6gkvU2GaAnBFENd3hLGFO8h2NWD77dSXj1bf6R8YMQhAOAKRgS1GguZODi mMWUwIcBxp8oMowWSmqmooyQE8Ui8DGey2yyqCMn0PrnQSphOLdHYV9sqaCkWi3J8Z71 ujS58zLsqNRstIljwi/BiKQSRGan2yCrK8ToOD/6tmLmiax2KRqKrHyL2VbtC+GWYlTI Wd+juE6H8Bzv9SvrgJc8ORLrGUT/rGNhFJHze6jMTRjxuJWd9JOru/P2NJO+5wzIejui SJsgic1C/OHKFpigsmAoQkC3IfHmwzIbTReZv5jq4WjZ65QuyxlSlgwVlycLigCNgSvq CPUQ== 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=2lSUpe592kbPQPhQMkeGWB6/Vun9yDD9GrzMvVsq/YE=; b=22JgSs5zwI8My6VvGi2trea14e0BJnp6fRWbj67Jz3dnRu0kdM7wztB0B3TEKSQ+fL PPLfTkVMNKSuSK+RsNwnr/+3XdPy5TvXGQnNrHpgA8G+gwfqIgF8q1DOpgCCPA/9JnXO joOu3loQxurFg/KP2cJDFtgy6PIujPf4Domt2i12fe69NP2qHeHueIdYGNiKE8qmqtUd G2aZECA4khvid8AsDN44UDN0hO/xH6nF6HlbbbVMSuebcPqQVBsDuHDTrLJvIUmryIRt ISpc2Mw9S/N8lfvsXDQdd59+l73sQvVkm0Vc0MNZy2pawbZnxOxQT26DgVH72XpdTU/U TEXg== X-Gm-Message-State: ACrzQf1NWHMbRA1dgaUuzdp10stA6CEKwJf1KpMbZZn/b2Ugb3oRZR7Z gvbRbjq/WJf+5VmTIqTQnRfiXAZLspM= X-Google-Smtp-Source: AMsMyM5BoDLsOTFAfDL386+fPjg+8rwxIFtbUFGximKW1UCOcJU5xowKivua312gQyRza1tybn0Ukw== X-Received: by 2002:a7b:c450:0:b0:3b4:fb1a:325d with SMTP id l16-20020a7bc450000000b003b4fb1a325dmr654012wmi.138.1664234499131; Mon, 26 Sep 2022 16:21:39 -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 p16-20020adfe610000000b00225239d9265sm90616wrm.74.2022.09.26.16.21.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 16:21:38 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, Beld Zhang Subject: [PATCH for-next 1/2] io_uring/rw: fix unexpected link breakage Date: Tue, 27 Sep 2022 00:20:28 +0100 Message-Id: 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-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 76ebcfebc9a6..c562203d7a67 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -823,6 +823,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:20:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12989589 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 4339DC07E9D for ; Mon, 26 Sep 2022 23:24:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231305AbiIZXX6 (ORCPT ); Mon, 26 Sep 2022 19:23:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231332AbiIZXXa (ORCPT ); Mon, 26 Sep 2022 19:23:30 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B92375CF0 for ; Mon, 26 Sep 2022 16:21:42 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id o5so5511338wms.1 for ; Mon, 26 Sep 2022 16:21:42 -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=gnOOAPoZ7GOp9P0945PJk9CfgwZn+k9Do3cZbeKmceo=; b=GWValW1wRzUMUQsyQh/M4yXejPvhND9Hb2WzuBzgq5FboFJq7IH5Ge5wv2z7LB+zjk 1DV3Le3n207begFJjyI31zcejkuWUt9rLZ8arB/QSF5rOWMu84ziAzLSvLH26boM5ySe d1W9EBWTjjU0DPznK+vHb6wSebuaWLSZ2XxHymfrfIAegPEANKTkOHWvilb6YOm9HLBs HrtBnPOrVMXlAcRRKrpLbzN5DPJaQiekN0b5dQeiQv/V3t9BnDo6YeXja9+UKo/yZlxn MVZ2pFgHV2/BIJ2PS2z2uGRQZf7G/3Ti34IFwNVqmprpkbPBhh8c0GGuhzJUqdxmzGaD DQTA== 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=gnOOAPoZ7GOp9P0945PJk9CfgwZn+k9Do3cZbeKmceo=; b=d86VUOCZOzhVJ60CzGcCltGBbaagGKVtP5uI3Tnk9dfGlEfWe6ammIIRVQcL78Wk7j dxP+uwVsLecKgnPjcjxKwcTbFmRiYkQg6ylFEwqjOWRpN1EePLcsVvM/YCwI+nRBwcwt FzcmjRZ88xqZJzbPnT22hKpinHPWEfChc2v1oraPdbnBL5xbRJUAL5pNSwrPD9r4WnI6 lieyGCPsK2ZnLMD1mkhEBPk1gH2Y1682sCe1Paud59XLt80sFbZS8hM+AukUjnhpYFbM DxzrrBi5WwfnWTkZsjQX9VBOqndBoOW3+cWmQW9bFpVYD70oOGsDn3rQZtw205mtFcEb wOUg== X-Gm-Message-State: ACrzQf3lgdVz480sTf8qXPL3IxRFG+9rjcdgVupiUFo07FIfSVV+xWtt 2+DNApH66UqYR6xSlOKnzQwm/4VFvw0= X-Google-Smtp-Source: AMsMyM4yO7rOesFLaIIpW9w5BJGNoHexQzzwZnFSkLOi72BYA7dkEeQsXiE6tScrylcM9d2K7v1F8A== X-Received: by 2002:a05:600c:3d17:b0:3b4:adc7:976c with SMTP id bh23-20020a05600c3d1700b003b4adc7976cmr620480wmb.108.1664234500254; Mon, 26 Sep 2022 16:21:40 -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 p16-20020adfe610000000b00225239d9265sm90616wrm.74.2022.09.26.16.21.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 16:21:39 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH for-next 2/2] io_uring/rw: don't lose short results on io_setup_async_rw() Date: Tue, 27 Sep 2022 00:20:29 +0100 Message-Id: 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 c562203d7a67..722c06026701 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -794,10 +794,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; /*