From nobody Thu Dec 18 08:07:35 2025 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=1744902438; cv=none; d=zohomail.com; s=zohoarc; b=ZSTigOsFH/wXA/tDYlRb7/mLLf+BbTCCqaTQ3R8rqHy6jF26x20XRi7evbJVpU5CJvbFHv496SndJG/wytW41fD/ALYQCFWT5uFjFa7fnTn/8fFsr7TyJv9ykZ7SHU9ru1H6rLEOYoYagbsY/XcE1wAHoKK/Mm2IYQas/eYujJs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1744902438; 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=bk0H+Roar0tnodB2dERrgUOH2kRI0WFF19le/uODht0=; b=NgguIXQRaz5gSRqNsN+PoiAmXineNXjjCSA71bSe7lRL2CIU8YmJmeb0SLVxQYDqTCQeffjDrEDDWYB+/SY+tTIosUzn7tGcks1Oalen27+YhsExDIhHB6/SG01L7IAqq31NUjKjSZgK2teH24K4NywhVChWOkgpKgU08ILbDMY= 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 174490242694178.33731546391277; Thu, 17 Apr 2025 08:07:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u5QoE-0005Ta-3N; Thu, 17 Apr 2025 11:05:46 -0400 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 1u5QoC-0005TG-4k for qemu-devel@nongnu.org; Thu, 17 Apr 2025 11:05:44 -0400 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 1u5Qo9-0000RM-Uq for qemu-devel@nongnu.org; Thu, 17 Apr 2025 11:05:43 -0400 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-546-IOVnyVYgNq-f2ddImsVAXQ-1; Thu, 17 Apr 2025 11:05:37 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 D9CA01956078; Thu, 17 Apr 2025 15:05:36 +0000 (UTC) Received: from localhost (unknown [10.2.16.64]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DB0CA30002C2; Thu, 17 Apr 2025 15:05:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744902341; 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=bk0H+Roar0tnodB2dERrgUOH2kRI0WFF19le/uODht0=; b=OsuWcD5U+pCE1EqJBGuQbhbECqJwWmdawr8KTpddPUcjL2Gt5Z6nl3Ao8nOPCqiij2xJwi kzej6GyeOvG++TVrECtfUJ6fIklbrc9ohXn4Kck6/EeeAlnMRvqEWF9da7P6N2BYHIDrx0 4VkJvzuby0xCwQyrSPFaFEjGqLXRpvE= X-MC-Unique: IOVnyVYgNq-f2ddImsVAXQ-1 X-Mimecast-MFC-AGG-ID: IOVnyVYgNq-f2ddImsVAXQ_1744902337 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Stefan Hajnoczi , Fam Zheng , Hanna Reitz , Kevin Wolf Subject: [PATCH v4 2/2] block/io: skip head/tail requests on EINVAL Date: Thu, 17 Apr 2025 11:05:28 -0400 Message-ID: <20250417150528.76470-3-stefanha@redhat.com> In-Reply-To: <20250417150528.76470-1-stefanha@redhat.com> References: <20250417150528.76470-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=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: 1744902440558019000 Content-Type: text/plain; charset="utf-8" When guests send misaligned discard requests, the block layer breaks them up into a misaligned head, an aligned main body, and a misaligned tail. The file-posix block driver on Linux returns -EINVAL on misaligned discard requests. This causes bdrv_co_pdiscard() to fail and guests configured with werror=3Dstop will pause. Add a special case for misaligned head/tail requests. Simply continue when EINVAL is encountered so that the aligned main body of the request can be completed and the guest is not paused. This is the best we can do when guest discard limits do not match the host discard limits. Fixes: https://issues.redhat.com/browse/RHEL-86032 Signed-off-by: Stefan Hajnoczi Reviewed-by: Hanna Czenczek --- block/io.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/block/io.c b/block/io.c index 1ba8d1aeea..ccec11386b 100644 --- a/block/io.c +++ b/block/io.c @@ -3109,11 +3109,12 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child,= int64_t offset, /* Invalidate the cached block-status data range if this discard overl= aps */ bdrv_bsc_invalidate_range(bs, offset, bytes); =20 - /* Discard is advisory, but some devices track and coalesce + /* + * Discard is advisory, but some devices track and coalesce * unaligned requests, so we must pass everything down rather than - * round here. Still, most devices will just silently ignore - * unaligned requests (by returning -ENOTSUP), so we must fragment - * the request accordingly. */ + * round here. Still, most devices reject unaligned requests with + * -EINVAL or -ENOTSUP, so we must fragment the request accordingly. + */ align =3D MAX(bs->bl.pdiscard_alignment, bs->bl.request_alignment); assert(align % bs->bl.request_alignment =3D=3D 0); head =3D offset % align; @@ -3180,7 +3181,11 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, = int64_t offset, } } if (ret && ret !=3D -ENOTSUP) { - goto out; + if (ret =3D=3D -EINVAL && (offset % align !=3D 0 || num % alig= n !=3D 0)) { + /* Silently skip rejected unaligned head/tail requests */ + } else { + goto out; /* bail out */ + } } =20 offset +=3D num; --=20 2.49.0