From nobody Sun Feb 8 23:32:04 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1764087509; cv=none; d=zohomail.com; s=zohoarc; b=jmU5wSM/gFgnj7BUfAoQ8P92fBDLBDF2IkRy48PGuqkVHcdmIRbF6Z9ClcgAk9XxyhQSdZYqU28QWlKFz1jzfN4NzYdtCQLsNCUQxvhjAoHRAlpkLvzOYz4Ar66Hd6eQ/QMYLUOR6tFVktTpFeGTY5vljgzCl2toy71/Y5/lUXQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764087509; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fbGI+MEiiC6jErCUJoENINEqv/p0bcCbG1DZdiOJh7M=; b=YE0Bqtonh7jFsc5OuTfK6BbE+Ho490ceZkFWgYVeYH42lxJeCYrUv7+Lz5/XISBi+A+pVZh3Kp4ZSfiwLzX9HU8WbQ4QoQUNVtteXaUvgdU2E7wc0hWKSjnMZtVT8Fu/E1u5MOg+ZSGK22Yezz3fvSAnfylX03Fo0p+FpcwjC/c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1764087509571728.2534584357583; Tue, 25 Nov 2025 08:18:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vNvk4-000755-8k; Tue, 25 Nov 2025 11:18:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vNvj2-0006ia-B0 for qemu-devel@nongnu.org; Tue, 25 Nov 2025 11:17:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vNvj0-000566-SN for qemu-devel@nongnu.org; Tue, 25 Nov 2025 11:17:08 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-100-JCOyUmzlNd-dT72nQmOXzA-1; Tue, 25 Nov 2025 11:17:02 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6F48F1954B11; Tue, 25 Nov 2025 16:17:01 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.45.226.49]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 140671800298; Tue, 25 Nov 2025 16:16:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764087426; 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=fbGI+MEiiC6jErCUJoENINEqv/p0bcCbG1DZdiOJh7M=; b=UuKSHBQ4xc0EdMGXrI6BmL/WBysiKcZyQw0r8Np804o8OOxgBsw2ZEJm+zaNpDQsS9xJKY QMepjCNU1WEbWv0zu+bHbZrbw6MVfjtUIhgcfoeVn+uVcyleTWMmpijjcspwIzQWNhaQS5 3wqNWs8kJaFkavJUe/eRrleQl4oNthU= X-MC-Unique: JCOyUmzlNd-dT72nQmOXzA-1 X-Mimecast-MFC-AGG-ID: JCOyUmzlNd-dT72nQmOXzA_1764087421 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 1/4] block-backend: Fix race when resuming queued requests Date: Tue, 25 Nov 2025 17:16:45 +0100 Message-ID: <20251125161648.259321-2-kwolf@redhat.com> In-Reply-To: <20251125161648.259321-1-kwolf@redhat.com> References: <20251125161648.259321-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@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.152, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1764087511072019100 Content-Type: text/plain; charset="utf-8" When new requests arrive at a BlockBackend that is currently drained, these requests are queued until the drain section ends. There is a race window between blk_root_drained_end() waking up a queued request in an iothread from the main thread and blk_wait_while_drained() actually being woken up in the iothread and calling blk_inc_in_flight(). If the BlockBackend is drained again during this window, drain won't wait for this request and it will sneak in when the BlockBackend is already supposed to be quiesced. This causes assertion failures in bdrv_drain_all_begin() and can have other unintended consequences. Fix this by increasing the in_flight counter immediately when scheduling the request to be resumed so that the next drain will wait for it to complete. Cc: qemu-stable@nongnu.org Reported-by: Andrey Drobyshev Signed-off-by: Kevin Wolf Message-ID: <20251119172720.135424-1-kwolf@redhat.com> Reviewed-by: Hanna Czenczek Tested-by: Andrey Drobyshev Reviewed-by: Fiona Ebner Signed-off-by: Kevin Wolf --- block/block-backend.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index f8d6ba65c1..d6df369188 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1318,9 +1318,9 @@ static void coroutine_fn blk_wait_while_drained(Block= Backend *blk) * section. */ qemu_mutex_lock(&blk->queued_requests_lock); + /* blk_root_drained_end() has the corresponding blk_inc_in_flight(= ) */ blk_dec_in_flight(blk); qemu_co_queue_wait(&blk->queued_requests, &blk->queued_requests_lo= ck); - blk_inc_in_flight(blk); qemu_mutex_unlock(&blk->queued_requests_lock); } } @@ -2767,9 +2767,11 @@ static void blk_root_drained_end(BdrvChild *child) blk->dev_ops->drained_end(blk->dev_opaque); } qemu_mutex_lock(&blk->queued_requests_lock); - while (qemu_co_enter_next(&blk->queued_requests, - &blk->queued_requests_lock)) { + while (!qemu_co_queue_empty(&blk->queued_requests)) { /* Resume all queued requests */ + blk_inc_in_flight(blk); + qemu_co_enter_next(&blk->queued_requests, + &blk->queued_requests_lock); } qemu_mutex_unlock(&blk->queued_requests_lock); } --=20 2.51.1 From nobody Sun Feb 8 23:32:04 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1764087553; cv=none; d=zohomail.com; s=zohoarc; b=RatFeKVqeOIdcV8h+mEMrtBqqLNdxjQPuNMsVabc8hx2e5sd+H2Y/b/MWS/2AaDiZ+KhxoWLe23LBGp+5stB9jFBFtifPWPsalZdxYYKn4TtNATIfqXOxdKuq1+l2hKbTxdnOlfcGiuY7E88SYfmQS0Pb6c3Ii5jqefpNoavO18= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764087553; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=P+vw1qAFjBBxlHJT7pgmA4NHosOs7cQ65PoTw3CPa2g=; b=iESvTvJNE5HMw+I1SCAL+uVNSK+u4of7/qnj7c9+uN2PIFhKtqGaR06Fd4YJMiwbkzX0kFR3uZDHqnx4/Y2fEqJdlAJWBATnui/Nq+6EzaozvqB+R5GTl3xDTXUMdJfjc4cYSO+oFnZv2bCr+eMXlSKCYPhJknt+q5/fENzYMdU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1764087553562800.3415738266875; Tue, 25 Nov 2025 08:19:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vNvkn-0007oE-Pe; Tue, 25 Nov 2025 11:19:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vNvj5-0006j1-6z for qemu-devel@nongnu.org; Tue, 25 Nov 2025 11:17:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vNvj2-00056a-Iv for qemu-devel@nongnu.org; Tue, 25 Nov 2025 11:17:10 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-10-33Oz31LRPvOiQmmx8XAmug-1; Tue, 25 Nov 2025 11:17:04 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5958E180122F; Tue, 25 Nov 2025 16:17:03 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.45.226.49]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D79B71800451; Tue, 25 Nov 2025 16:17:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764087428; 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=P+vw1qAFjBBxlHJT7pgmA4NHosOs7cQ65PoTw3CPa2g=; b=fv04Gf60e/Ai2WyXaQ2w1fRyglLfMZC0LC7pX7aQ5vg+jeQSpH2d6jhHQsSiNBEjbRIVzC v+RI0lly4iKD4ylpG91wfy1uyTTF2nZlRr5PgcAX8d5Q2NIN7Wu5hLAdI0VsNiAbNyoE8U sHhA6mlHOraMz6SuCXx/3mKWN9P/yGo= X-MC-Unique: 33Oz31LRPvOiQmmx8XAmug-1 X-Mimecast-MFC-AGG-ID: 33Oz31LRPvOiQmmx8XAmug_1764087423 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 2/4] file-posix: populate pwrite_zeroes_alignment Date: Tue, 25 Nov 2025 17:16:46 +0100 Message-ID: <20251125161648.259321-3-kwolf@redhat.com> In-Reply-To: <20251125161648.259321-1-kwolf@redhat.com> References: <20251125161648.259321-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@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.152, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1764087555434019100 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi Linux block devices require write zeroes alignment whereas files do not. It may come as a surprise that block devices opened in buffered I/O mode require the alignment for write zeroes requests although normal read/write requests do not. Therefore it is necessary to populate the pwrite_zeroes_alignment field. Cc: qemu-stable@nongnu.org Signed-off-by: Stefan Hajnoczi Message-ID: <20251007141700.71891-2-stefanha@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy Tested-by: Fiona Ebner Reviewed-by: Fiona Ebner Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/file-posix.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index 12d12970fa..c9e367a222 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1611,6 +1611,22 @@ static void raw_refresh_limits(BlockDriverState *bs,= Error **errp) =20 bs->bl.pdiscard_alignment =3D dalign; } + +#ifdef __linux__ + /* + * Linux requires logical block size alignment for write zeroes ev= en + * when normal reads/writes do not require alignment. + */ + if (!s->needs_alignment) { + ret =3D probe_logical_blocksize(s->fd, + &bs->bl.pwrite_zeroes_alignment); + if (ret < 0) { + error_setg_errno(errp, -ret, + "Failed to probe logical block size"); + return; + } + } +#endif /* __linux__ */ } =20 raw_refresh_zoned_limits(bs, &st, errp); --=20 2.51.1 From nobody Sun Feb 8 23:32:04 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1764087502; cv=none; d=zohomail.com; s=zohoarc; b=YcGXNHU5e4sPcS6Nmzg/pjwhlf2idIAui8F0WsM4FSn7nRU08naZ9NCzxuzZSXY1akIVuPHOFBuPB7LRS5XSJtJgHfTZm335CcXiHL54HqVLcpVMmFe2K6NHLilIGrFb/HujWhGTV/A3PNJDccZNuQvizeB0p8BqRGHNDnibc/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764087502; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=08v7AzWh8ahJ/6I5lOs9Lhby5WymPW1UOUKrJIxyHcE=; b=MdHT/BGh7c7/GMxUb19gyEOTFkYZz+NR0m9Z/7gJVBzv8G3DOVBhZC7xPjahshlxpRjOOXhoGkgE5B5g5/gYkefp20RI/asAoetxYCm58S2/vEox29ezI35By5FcXJ23u+M4kG7gS5ItBDz5I4llZJONuN8w3XmY9us1RoTNAZU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1764087500779650.996815591533; Tue, 25 Nov 2025 08:18:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vNvjB-0006ui-Fc; Tue, 25 Nov 2025 11:17:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vNvj5-0006iz-6L for qemu-devel@nongnu.org; Tue, 25 Nov 2025 11:17:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vNvj2-00056h-Lm for qemu-devel@nongnu.org; Tue, 25 Nov 2025 11:17:10 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-278-scK4zRyvPnC38L3M5eDcXw-1; Tue, 25 Nov 2025 11:17:06 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 28FF5180045C; Tue, 25 Nov 2025 16:17:05 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.45.226.49]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C352F18004A3; Tue, 25 Nov 2025 16:17:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764087428; 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=08v7AzWh8ahJ/6I5lOs9Lhby5WymPW1UOUKrJIxyHcE=; b=SlTx+GNxrgNIomDlRW7ZFbtyi5xXVb1aMpmyHufUGiJbcELDuPUNuJh3qCmsZlx9CUf58P 2likeN3As/7S3igFsa+xpZBMavrrVvkc7mBWjr4bhTWS10cLhSGhF9O6/QxuWbZNXNM+R2 l1KJnWYoqvelh8uq4GrtI25DNz0S0L0= X-MC-Unique: scK4zRyvPnC38L3M5eDcXw-1 X-Mimecast-MFC-AGG-ID: scK4zRyvPnC38L3M5eDcXw_1764087425 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 3/4] block: use pwrite_zeroes_alignment when writing first sector Date: Tue, 25 Nov 2025 17:16:47 +0100 Message-ID: <20251125161648.259321-4-kwolf@redhat.com> In-Reply-To: <20251125161648.259321-1-kwolf@redhat.com> References: <20251125161648.259321-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@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.152, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1764087507112019100 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi Since commit 5634622bcb33 ("file-posix: allow BLKZEROOUT with -t writeback"), qemu-img create errors out on a Linux loop block device with a 4 KB sector size: # dd if=3D/dev/zero of=3Dblockfile bs=3D1M count=3D1024 # losetup --sector-size 4096 /dev/loop0 blockfile # qemu-img create -f raw /dev/loop0 1G Formatting '/dev/loop0', fmt=3Draw size=3D1073741824 qemu-img: /dev/loop0: Failed to clear the new image's first sector: Inval= id argument Use the pwrite_zeroes_alignment block limit to avoid misaligned fallocate(2) or ioctl(BLKZEROOUT) in the block/file-posix.c block driver. Cc: qemu-stable@nongnu.org Fixes: 5634622bcb33 ("file-posix: allow BLKZEROOUT with -t writeback") Reported-by: Jean-Louis Dupond Buglink: https://gitlab.com/qemu-project/qemu/-/issues/3127 Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Stefan Hajnoczi Message-ID: <20251007141700.71891-3-stefanha@redhat.com> Tested-by: Fiona Ebner Reviewed-by: Fiona Ebner Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/system/block-backend-io.h | 1 + block.c | 3 ++- block/block-backend.c | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/system/block-backend-io.h b/include/system/block-backe= nd-io.h index ba8dfcc7d0..6d5ac476fc 100644 --- a/include/system/block-backend-io.h +++ b/include/system/block-backend-io.h @@ -116,6 +116,7 @@ BlockAIOCB *blk_abort_aio_request(BlockBackend *blk, void *opaque, int ret); =20 uint32_t blk_get_request_alignment(BlockBackend *blk); +uint32_t blk_get_pwrite_zeroes_alignment(BlockBackend *blk); uint32_t blk_get_max_transfer(BlockBackend *blk); uint64_t blk_get_max_hw_transfer(BlockBackend *blk); =20 diff --git a/block.c b/block.c index 4f1581cedf..48a17f393c 100644 --- a/block.c +++ b/block.c @@ -606,12 +606,13 @@ create_file_fallback_zero_first_sector(BlockBackend *= blk, int64_t current_size, Error **errp) { + uint32_t alignment =3D blk_get_pwrite_zeroes_alignment(blk); int64_t bytes_to_clear; int ret; =20 GLOBAL_STATE_CODE(); =20 - bytes_to_clear =3D MIN(current_size, BDRV_SECTOR_SIZE); + bytes_to_clear =3D MIN(current_size, MAX(BDRV_SECTOR_SIZE, alignment)); if (bytes_to_clear) { ret =3D blk_co_pwrite_zeroes(blk, 0, bytes_to_clear, BDRV_REQ_MAY_= UNMAP); if (ret < 0) { diff --git a/block/block-backend.c b/block/block-backend.c index d6df369188..98315d4470 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2305,6 +2305,17 @@ uint32_t blk_get_request_alignment(BlockBackend *blk) return bs ? bs->bl.request_alignment : BDRV_SECTOR_SIZE; } =20 +/* Returns the optimal write zeroes alignment, in bytes; guaranteed nonzer= o */ +uint32_t blk_get_pwrite_zeroes_alignment(BlockBackend *blk) +{ + BlockDriverState *bs =3D blk_bs(blk); + IO_CODE(); + if (!bs) { + return BDRV_SECTOR_SIZE; + } + return bs->bl.pwrite_zeroes_alignment ?: bs->bl.request_alignment; +} + /* Returns the maximum hardware transfer length, in bytes; guaranteed nonz= ero */ uint64_t blk_get_max_hw_transfer(BlockBackend *blk) { --=20 2.51.1 From nobody Sun Feb 8 23:32:04 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1764087527; cv=none; d=zohomail.com; s=zohoarc; b=R8kL7CWqR2unZPVN9bu2PIoDksJ/O5Qrw1pZilrwdCzGTBOO2JCz4KGeRf9jYp1YtIw0p3ZIQ+4HvZl4pFKZnG1GlEd/aG1BvT5lJ6sba5+dsCoqrhosuWQuztLIq8hUVOh0wCB/qOHKbMNRK7his1ixcT9Ug9wHeKDP16VnkOA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764087527; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5mTXbugE+NHdNMCReF9WvlvDH492zviirZpTg38MZws=; b=fyo59QBZDbPrZsvHbwj3yNQhjZ7wUePzGNeI5QekJsuP3+1OpbVSz0Tq8eBnWI8RQYu0JQcKuoKa/VYO4IyOFgE8TLJANwFiXnhr6HlkEIeH0el5c2l1VEvGf+zt1tO9s6jFl6VAg73QaOZbag/S9r7uuUiNiJ5cUv9zrIsWAPk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1764087527584276.45761721460156; Tue, 25 Nov 2025 08:18:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vNvkU-0007UZ-LF; Tue, 25 Nov 2025 11:18:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vNvj8-0006qE-Lj for qemu-devel@nongnu.org; Tue, 25 Nov 2025 11:17:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vNvj6-00057Z-DD for qemu-devel@nongnu.org; Tue, 25 Nov 2025 11:17:13 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-480-KvQKVri-NuKMlvZCPn1uYQ-1; Tue, 25 Nov 2025 11:17:07 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ED3371956048; Tue, 25 Nov 2025 16:17:06 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.45.226.49]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 939B618004A3; Tue, 25 Nov 2025 16:17:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764087431; 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=5mTXbugE+NHdNMCReF9WvlvDH492zviirZpTg38MZws=; b=Hjk0q0rDymogWXZlFSqPM6huLl94eWZxiRcubC8zN2HRhD2w86czHllt3uyz1dC8o/8vtw ZbdOyq5gHEt8gBcjZZvcjNMiiRCjGCM6juAwk8qrO3xHXZvepEF+KOQwbgnEm+boLy+WB5 pv1zeZ8OJ7j2wJCI5qQCvvEWyh1+djQ= X-MC-Unique: KvQKVri-NuKMlvZCPn1uYQ-1 X-Mimecast-MFC-AGG-ID: KvQKVri-NuKMlvZCPn1uYQ_1764087427 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 4/4] iotests: add Linux loop device image creation test Date: Tue, 25 Nov 2025 17:16:48 +0100 Message-ID: <20251125161648.259321-5-kwolf@redhat.com> In-Reply-To: <20251125161648.259321-1-kwolf@redhat.com> References: <20251125161648.259321-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@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.152, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1764087529206019100 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi This qemu-iotests test case is based on the reproducer that Jean-Louis Dupond shared in https://gitlab.com/qemu-project/qemu/-/issues/3127. Signed-off-by: Stefan Hajnoczi Message-ID: <20251007141700.71891-4-stefanha@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy Tested-by: Vladimir Sementsov-Ogievskiy Tested-by: Fiona Ebner Reviewed-by: Fiona Ebner Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- tests/qemu-iotests/tests/loop-create-file | 59 +++++++++++++++++++ tests/qemu-iotests/tests/loop-create-file.out | 8 +++ 2 files changed, 67 insertions(+) create mode 100755 tests/qemu-iotests/tests/loop-create-file create mode 100644 tests/qemu-iotests/tests/loop-create-file.out diff --git a/tests/qemu-iotests/tests/loop-create-file b/tests/qemu-iotests= /tests/loop-create-file new file mode 100755 index 0000000000..5ec75b046b --- /dev/null +++ b/tests/qemu-iotests/tests/loop-create-file @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +# group: quick +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright Red Hat, Inc. +# +# Test Linux loop device image creation +# +# This test verifies #3127 "qemu-img create fails on loop device with sect= or size 4096" +# https://gitlab.com/qemu-project/qemu/-/issues/3127 + +seq=3D"$(basename $0)" +echo "QA output created by $seq" + +status=3D1 # failure is the default! + +_cleanup() { + if [ -n "$loopdev" ]; then + sudo losetup --detach "$loopdev" + fi + + _cleanup_test_img +} + +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +cd .. +. ./common.rc +. ./common.filter + +_supported_fmt raw +_supported_proto file +_supported_os Linux + +if ! sudo -n losetup &>/dev/null; then + _notrun "sudo losetup not available" +fi + +echo +echo "=3D=3D=3D Create image on a 4 KB sector size loop device =3D=3D=3D" +echo + +_make_test_img -f $IMGFMT 1M + +loopdev=3D$(sudo losetup --sector-size 4096 --find --show "$TEST_IMG") +if [ -z "$loopdev" ]; then + _fail +fi + +sudo $QEMU_IMG_PROG create -f raw "$loopdev" 1M | \ + sed -e "s#/dev/loop[0-9]\\+#LOOPDEV#g" + +# success, all done +echo +echo '*** done' +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/tests/loop-create-file.out b/tests/qemu-iot= ests/tests/loop-create-file.out new file mode 100644 index 0000000000..32d4155695 --- /dev/null +++ b/tests/qemu-iotests/tests/loop-create-file.out @@ -0,0 +1,8 @@ +QA output created by loop-create-file + +=3D=3D=3D Create image on a 4 KB sector size loop device =3D=3D=3D + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +Formatting 'LOOPDEV', fmt=3Draw size=3D1048576 + +*** done --=20 2.51.1