From patchwork Thu Jul 7 08:12:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 1653398 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=SSJusMyG; dkim-atps=neutral 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 4LdqD60pJKz9s09 for ; Thu, 7 Jul 2022 18:23:02 +1000 (AEST) Received: from localhost ([::1]:33218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9Mmp-00085l-RP for incoming@patchwork.ozlabs.org; Thu, 07 Jul 2022 04:22:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o9Md8-00070r-5W for qemu-devel@nongnu.org; Thu, 07 Jul 2022 04:12:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:38958) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o9Md6-0007mW-G6 for qemu-devel@nongnu.org; Thu, 07 Jul 2022 04:12:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657181574; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a93GsxKY0muqBL+LWACkxxKWKt6MOUdxYh8WkWccbl0=; b=SSJusMyGe3fEyntP7IXAHs96Fb8m/pTXNJUjEP8h8AcsQsFhvps0eA10IFLfr/WL30PHbQ UXGwGHCJtmNoukVn6GeequV/DiTJY0HYtAVyme/WFWPVZJZxSzcpGzl7yuWlXOCMzUCMkt rb82+eYPYp7Py4WS9E7WdbQhNg0l9mQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-664-t9TKhChxPEWPLJRC6KU_5A-1; Thu, 07 Jul 2022 04:12:51 -0400 X-MC-Unique: t9TKhChxPEWPLJRC6KU_5A-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1ACCF8339A4; Thu, 7 Jul 2022 08:12:51 +0000 (UTC) Received: from localhost (unknown [10.39.194.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1453C27D9A; Thu, 7 Jul 2022 08:12:50 +0000 (UTC) From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Julia Suvorova , qemu-block@nongnu.org, Stefano Garzarella , Hanna Reitz , Kevin Wolf , Aarushi Mehta , Stefan Hajnoczi , Richard Henderson , Dominique Martinet Subject: [PULL 1/2] io_uring: fix short read slow path Date: Thu, 7 Jul 2022 09:12:46 +0100 Message-Id: <20220707081247.1416955-2-stefanha@redhat.com> In-Reply-To: <20220707081247.1416955-1-stefanha@redhat.com> References: <20220707081247.1416955-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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" From: Dominique Martinet 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 Message-Id: <20220630010137.2518851-1-dominique.martinet@atmark-techno.com> Reviewed-by: Hanna Reitz Reviewed-by: Stefano Garzarella Signed-off-by: Stefan Hajnoczi --- 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 d48e472e74..b238661740 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; From patchwork Thu Jul 7 08:12:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 1653407 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=YNnDxYQm; dkim-atps=neutral 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 4LdqjT2lmGz9s09 for ; Thu, 7 Jul 2022 18:45:01 +1000 (AEST) Received: from localhost ([::1]:39494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9N87-0007rP-43 for incoming@patchwork.ozlabs.org; Thu, 07 Jul 2022 04:44:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o9Md9-00073x-Gu for qemu-devel@nongnu.org; Thu, 07 Jul 2022 04:12:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:30139) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o9Md7-0007mh-6Q for qemu-devel@nongnu.org; Thu, 07 Jul 2022 04:12:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657181576; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CeBTMnW6x9bRaOSbJPDaYLuExUX3ZycHGAAA/UaTC6g=; b=YNnDxYQmcqGWdZenX6MA4V6r2FXPbrzMy2L7UcNGopoKiicepa9NKhXXxcKv6we2Gj+RLw tU0C5A/Wen5E7kFqSeBNDWq1qp4T+0hUSR4nQYQKwMxklSOpLPE6Y5EDjwa+QPqm3hLNhK eu2gSkxrnTBHlspLkDbfbVfSna9gv+Y= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-619-kq8dt6QqMUKZXNj_4JQgJQ-1; Thu, 07 Jul 2022 04:12:53 -0400 X-MC-Unique: kq8dt6QqMUKZXNj_4JQgJQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D25D43826A41; Thu, 7 Jul 2022 08:12:52 +0000 (UTC) Received: from localhost (unknown [10.39.194.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F755401E6B; Thu, 7 Jul 2022 08:12:52 +0000 (UTC) From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Julia Suvorova , qemu-block@nongnu.org, Stefano Garzarella , Hanna Reitz , Kevin Wolf , Aarushi Mehta , Stefan Hajnoczi , Richard Henderson , Dominique Martinet Subject: [PULL 2/2] block/io_uring: clarify that short reads can happen Date: Thu, 7 Jul 2022 09:12:47 +0100 Message-Id: <20220707081247.1416955-3-stefanha@redhat.com> In-Reply-To: <20220707081247.1416955-1-stefanha@redhat.com> References: <20220707081247.1416955-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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" Jens Axboe has confirmed that short reads are rare but can happen: https://lore.kernel.org/io-uring/YsU%2FCGkl9ZXUI+Tj@stefanha-x1.localdomain/T/#m729963dc577d709b709c191922e98ec79d7eef54 The luring_resubmit_short_read() comment claimed they were only due to a specific io_uring bug that was fixed in Linux commit 9d93a3f5a0c ("io_uring: punt short reads to async context"), which is wrong. Dominique Martinet found that a btrfs bug also causes short reads. There may be more kernel code paths that result in short reads. Let's consider short reads fair game. Cc: Dominique Martinet Based-on: <20220630010137.2518851-1-dominique.martinet@atmark-techno.com> Signed-off-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella Message-id: 20220706080341.1206476-1-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- block/io_uring.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/block/io_uring.c b/block/io_uring.c index b238661740..f8a19fd97f 100644 --- a/block/io_uring.c +++ b/block/io_uring.c @@ -73,12 +73,8 @@ static void luring_resubmit(LuringState *s, LuringAIOCB *luringcb) /** * luring_resubmit_short_read: * - * Before Linux commit 9d93a3f5a0c ("io_uring: punt short reads to async - * context") a buffered I/O request with the start of the file range in the - * page cache could result in a short read. Applications need to resubmit the - * remaining read request. - * - * This is a slow path but recent kernels never take it. + * Short reads are rare but may occur. The remaining read request needs to be + * resubmitted. */ static void luring_resubmit_short_read(LuringState *s, LuringAIOCB *luringcb, int nread)