From patchwork Thu Jun 30 01:01:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique MARTINET X-Patchwork-Id: 1650427 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LYKp34X9zz9s0r for ; Thu, 30 Jun 2022 11:03:22 +1000 (AEST) Received: from localhost ([::1]:48058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6iaU-0006eW-Vf for incoming@patchwork.ozlabs.org; Wed, 29 Jun 2022 21:03:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6iZD-0006cJ-Kh for qemu-devel@nongnu.org; Wed, 29 Jun 2022 21:01:59 -0400 Received: from gw2.atmark-techno.com ([35.74.137.57]:40260) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6iZ8-0006VU-Kp for qemu-devel@nongnu.org; Wed, 29 Jun 2022 21:01:58 -0400 Received: from gw2.atmark-techno.com (localhost [127.0.0.1]) by gw2.atmark-techno.com (Postfix) with ESMTP id D086320D73 for ; Thu, 30 Jun 2022 10:01:51 +0900 (JST) Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by gw2.atmark-techno.com (Postfix) with ESMTPS id 5FFBC20D57 for ; Thu, 30 Jun 2022 10:01:51 +0900 (JST) Received: by mail-pl1-f199.google.com with SMTP id c16-20020a170902b69000b0016a71a49c0cso8485494pls.23 for ; Wed, 29 Jun 2022 18:01:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IcaC2idNlr9EpLNjyFT+wDQbQ+dGuNWy1F/Un6xiP6U=; b=ETf2E6zNBsazfAqd0VatzoB0Ssgf/edkwrE3YigoIEzLMzW8RWGwxCMh7Zfu60CD5w UzckFRK8+q+LErHRXVnd/1Bn8f/xdEPvKjKue6vLsinJOfGVcItpWOPk5yaCgz76EJWZ qNlQ6TspIm2K+9DM0aU7Hxe1SBsuSysphI2rSTOpZMPmjw58G+H962zNXphtx5INf7DI g/iHlcRbJFpN96SislLdDMnQU9j4sH6biRn+u/SynEA0T8grslQnurOwmEcR+mc4MwZ1 aVrWT2m/lAzs7iwYyQcUXnWG1CbEDLWtrvYtifdmLUXSuNqAQXxA4DVZGPfs8c7qbRmI va4A== X-Gm-Message-State: AJIora8iwic3GR9m+N9/hZUl7CZmniHlGvL+YF5JAgG/Jv6AIafcJOS+ /Z243JH4RPBCIGgsTNE51trTqoXhFBlyK9Sb/RJGs09tcWMtT3bCo5KGe1iUNhqAUH4cIEpnICt vS5f8DTcSQf4o1EVt X-Received: by 2002:a63:4710:0:b0:410:ac39:831b with SMTP id u16-20020a634710000000b00410ac39831bmr5295659pga.395.1656550910216; Wed, 29 Jun 2022 18:01:50 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v1xEhkjWJ8jrGwi9FFuefFu3kQovNoOmdpGeBFUovZH45iDF4Kb35Plq1v6pc+aUVq4AC12w== X-Received: by 2002:a63:4710:0:b0:410:ac39:831b with SMTP id u16-20020a634710000000b00410ac39831bmr5295641pga.395.1656550909947; Wed, 29 Jun 2022 18:01:49 -0700 (PDT) Received: from pc-zest.atmarktech (162.198.187.35.bc.googleusercontent.com. [35.187.198.162]) by smtp.gmail.com with ESMTPSA id c10-20020a170903234a00b0016b9b6d67a2sm2631462plh.155.2022.06.29.18.01.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Jun 2022 18:01:49 -0700 (PDT) Received: from martinet by pc-zest.atmarktech with local (Exim 4.95) (envelope-from ) id 1o6iZ2-00AZHu-50; Thu, 30 Jun 2022 10:01:48 +0900 From: Dominique Martinet To: Aarushi Mehta , Julia Suvorova , Stefan Hajnoczi , Stefano Garzarella Cc: Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org, qemu-devel@nongnu.org, Filipe Manana , Dominique Martinet Subject: [PATCH v2] io_uring: fix short read slow path Date: Thu, 30 Jun 2022 10:01:37 +0900 Message-Id: <20220630010137.2518851-1-dominique.martinet@atmark-techno.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220629044957.1998430-1-dominique.martinet@atmark-techno.com> References: <20220629044957.1998430-1-dominique.martinet@atmark-techno.com> MIME-Version: 1.0 Received-SPF: pass client-ip=35.74.137.57; envelope-from=dominique.martinet@atmark-techno.com; helo=gw2.atmark-techno.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" sqeq.off here is the offset to read within the disk image, so obviously not 'nread' (the amount we just read), but as the author meant to write its current value incremented by the amount we just read. Normally recent versions of linux will not issue short reads, but it can happen so we should fix this. This lead to weird image corruptions when short read happened Fixes: 6663a0a33764 ("block/io_uring: implements interfaces for io_uring") Link: https://lkml.kernel.org/r/YrrFGO4A1jS0GI0G@atmark-techno.com Signed-off-by: Dominique Martinet Reviewed-by: Hanna Reitz Reviewed-by: Stefano Garzarella --- v1 -> v2: also updated total_read to use += as suggested by Kevin, thank you! I've tested this quickly by making short reads "recursives", e.g. added the following to luring_resubmit_short_read() after setting 'remaining': if (remaining > 4096) remaining -= 4096; so when we ask for more we issue an extra short reads, making sure we go through the two short reads path. (Unfortunately I wasn't quite sure what to fiddle with to issue short reads in the first place, I tried cutting one of the iovs short in luring_do_submit() but I must not have been doing it properly as I ended up with 0 return values which are handled by filling in with 0 (reads after eof) and that didn't work well) Anyway, this looks OK to me now. Thanks, Dominique block/io_uring.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/io_uring.c b/block/io_uring.c index d48e472e74cb..b238661740f5 100644 --- a/block/io_uring.c +++ b/block/io_uring.c @@ -89,7 +89,7 @@ static void luring_resubmit_short_read(LuringState *s, LuringAIOCB *luringcb, trace_luring_resubmit_short_read(s, luringcb, nread); /* Update read position */ - luringcb->total_read = nread; + luringcb->total_read += nread; remaining = luringcb->qiov->size - luringcb->total_read; /* Shorten qiov */ @@ -103,7 +103,7 @@ static void luring_resubmit_short_read(LuringState *s, LuringAIOCB *luringcb, remaining); /* Update sqe */ - luringcb->sqeq.off = nread; + luringcb->sqeq.off += nread; luringcb->sqeq.addr = (__u64)(uintptr_t)luringcb->resubmit_qiov.iov; luringcb->sqeq.len = luringcb->resubmit_qiov.niov;