From nobody Sun Apr 28 19:33:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1571041093; cv=none; d=zoho.com; s=zohoarc; b=mq1xTLLmCub79HyC+/BFdJphy3/a8nBQWexACFNk4sVBKsMThQFIKhiM5zFUbrv8MxLyTxkUFmkyWQi6Dwk6pRaHVPN/QzdGLlWKCL17AjLPHU52npBTBL3rzeTOtiIhuEzRRNOeavuLsjvTB/Jb9c4djzcybJRv1FIEaVEWkKM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571041093; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=R6RtrLZxxY2s1eviN2GmfYidifpvl3pH/rBLZpH6kg4=; b=NlI3Z9wiPHd51kHw657jjXVJ8HBax/+8UzbnEpfcI9KBA05k+4qV/bKVnfVIOcelcrJQY1E9NPq0ZQVp3TxtAr/XFlfioWtCo6HlrC48RWmeh+QwMG0gbrdEWeIHZLP5Qk8H53zeArcN6crkpAw5406iUqzZ8bZ1uM539i8ggmY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571041092105975.8234319818865; Mon, 14 Oct 2019 01:18:12 -0700 (PDT) Received: from localhost ([::1]:45564 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJvYP-0007AF-97 for importer@patchew.org; Mon, 14 Oct 2019 04:18:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52097) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJvX9-0006aK-3b for qemu-devel@nongnu.org; Mon, 14 Oct 2019 04:16:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJvX7-0001ii-8y for qemu-devel@nongnu.org; Mon, 14 Oct 2019 04:16:50 -0400 Received: from 6.130.60.178.static.reverse-mundo-r.com ([178.60.130.6]:41212 helo=fanzine.igalia.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iJvX5-0001fd-KX; Mon, 14 Oct 2019 04:16:49 -0400 Received: from 87-100-137-117.bb.dnainternet.fi ([87.100.137.117] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iJvX0-0003Tk-6d; Mon, 14 Oct 2019 10:16:42 +0200 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iJvW7-0007ji-1v; Mon, 14 Oct 2019 11:15:47 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From; bh=R6RtrLZxxY2s1eviN2GmfYidifpvl3pH/rBLZpH6kg4=; b=KygllYyT0DkUCYHcuHJ2pbakIgrHb0f688aGd/wZC38i7ijbNGjSzb0adfEgZoWHd5Iv1sBkWgO+sRTWubUeh4nvJulgZSr6xG85v9XWQzjavBeid589KJkAcrHb2qUbCMwEX91J3gFcgcuRz6FULxMuv4mbxdKITr2DcDg9JmvPqDsS4UhxA6abCdq9oRdotRqQGe/B8MhFMJa8JIhHMfcHlCt2tor8fLFcPCVaAb7wqte2FHNQvjBgCLHtYg3nzKbdqlT0LkJUixcQGg2o1JHsZKS3VNgipDlANiREY57F8XZxTaGTQixQp4l4XS14IYdRq+/MN3f3vuxXyAxeJA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v2] block: Reject misaligned write requests with BDRV_REQ_NO_FALLBACK Date: Mon, 14 Oct 2019 11:15:45 +0300 Message-Id: <20191014081545.29694-1-berto@igalia.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Nir Soffer Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The BDRV_REQ_NO_FALLBACK flag means that an operation should only be performed if it can be offloaded or otherwise performed efficiently. However a misaligned write request requires a RMW so we should return an error and let the caller decide how to proceed. This hits an assertion since commit c8bb23cbdb if the required alignment is larger than the cluster size: qemu-img create -f qcow2 -o cluster_size=3D2k img.qcow2 4G qemu-io -c "open -o driver=3Dqcow2,file.align=3D4k blkdebug::img.qcow2" \ -c 'write 0 512' qemu-io: block/io.c:1127: bdrv_driver_pwritev: Assertion `!(flags & BDRV_RE= Q_NO_FALLBACK)' failed. Aborted The reason is that when writing to an unallocated cluster we try to skip the copy-on-write part and zeroize it using BDRV_REQ_NO_FALLBACK instead, resulting in a write request that is too small (2KB cluster size vs 4KB required alignment). Signed-off-by: Alberto Garcia --- v2: - Use QEMU_IS_ALIGNED and (offset | bytes) [Nir] - Fix typo in comment in iotest - Expand commit message v1: - Initial version block/io.c | 6 +++++ tests/qemu-iotests/268 | 55 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/268.out | 7 +++++ tests/qemu-iotests/group | 1 + 4 files changed, 69 insertions(+) create mode 100755 tests/qemu-iotests/268 create mode 100644 tests/qemu-iotests/268.out diff --git a/block/io.c b/block/io.c index 4f9ee97c2b..18d842382a 100644 --- a/block/io.c +++ b/block/io.c @@ -2071,6 +2071,12 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *chi= ld, return ret; } =20 + /* If the request is misaligned then we can't make it efficient */ + if (!QEMU_IS_ALIGNED(offset | bytes, align) && + (flags & BDRV_REQ_NO_FALLBACK)) { + return -ENOTSUP; + } + bdrv_inc_in_flight(bs); /* * Align write if necessary by performing a read-modify-write cycle. diff --git a/tests/qemu-iotests/268 b/tests/qemu-iotests/268 new file mode 100755 index 0000000000..78c3f4db3a --- /dev/null +++ b/tests/qemu-iotests/268 @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +# +# Test write request with required alignment larger than the cluster size +# +# Copyright (C) 2019 Igalia, S.L. +# Author: Alberto Garcia +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=3Dberto@igalia.com + +seq=3D`basename $0` +echo "QA output created by $seq" + +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto file + +echo +echo "=3D=3D Required alignment larger than cluster size =3D=3D" + +CLUSTER_SIZE=3D2k _make_test_img 1M +# Since commit c8bb23cbdb writing to an unallocated cluster fills the +# empty COW areas with bdrv_write_zeroes(flags=3DBDRV_REQ_NO_FALLBACK) +$QEMU_IO -c "open -o driver=3D$IMGFMT,file.align=3D4k blkdebug::$TEST_IMG"= \ + -c "write 0 512" | _filter_qemu_io + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/268.out b/tests/qemu-iotests/268.out new file mode 100644 index 0000000000..2ed6c68529 --- /dev/null +++ b/tests/qemu-iotests/268.out @@ -0,0 +1,7 @@ +QA output created by 268 + +=3D=3D Required alignment larger than cluster size =3D=3D +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +wrote 512/512 bytes at offset 0 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 5805a79d9e..4c861f7eed 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -278,3 +278,4 @@ 265 rw auto quick 266 rw quick 267 rw auto quick snapshot +268 rw auto quick --=20 2.20.1