From nobody Sun Oct 5 21:14:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1542248015001824.5214702693423; Wed, 14 Nov 2018 18:13:35 -0800 (PST) Received: from localhost ([::1]:35654 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN79x-0001qd-RM for importer@patchew.org; Wed, 14 Nov 2018 21:13:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN70u-0002QD-OZ for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:04:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gN70r-0005kt-JF for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:04:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33882) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gN70m-0005fZ-2F; Wed, 14 Nov 2018 21:04:04 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7B234C050E0E; Thu, 15 Nov 2018 02:04:00 +0000 (UTC) Received: from red.redhat.com (ovpn-123-32.rdu2.redhat.com [10.10.123.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1FE860BF6; Thu, 15 Nov 2018 02:03:59 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 14 Nov 2018 20:03:30 -0600 Message-Id: <20181115020334.1189829-10-eblake@redhat.com> In-Reply-To: <20181115020334.1189829-1-eblake@redhat.com> References: <20181115020334.1189829-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 15 Nov 2018 02:04:00 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 09/13] RFC: crypto: Rely on block layer for fragmentation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" No need to reimplement fragmentation to BLOCK_CRYPTO_MAX_IO_SIZE ourselves when we can ask the block layer to do it for us. Signed-off-by: Eric Blake --- Question - is this patch for 'crypto' acceptable, or should we stick with just the previous one that marks things as 64-bit clean? --- block/crypto.c | 80 +++++++++++++++++++------------------------------- 1 file changed, 30 insertions(+), 50 deletions(-) diff --git a/block/crypto.c b/block/crypto.c index 259ef2649e1..b004cef22c2 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -328,8 +328,6 @@ block_crypto_co_preadv(BlockDriverState *bs, uint64_t o= ffset, uint64_t bytes, QEMUIOVector *qiov, int flags) { BlockCrypto *crypto =3D bs->opaque; - uint64_t cur_bytes; /* number of bytes in current iteration */ - uint64_t bytes_done =3D 0; uint8_t *cipher_data =3D NULL; QEMUIOVector hd_qiov; int ret =3D 0; @@ -346,38 +344,30 @@ block_crypto_co_preadv(BlockDriverState *bs, uint64_t= offset, uint64_t bytes, /* Bounce buffer because we don't wish to expose cipher text * in qiov which points to guest memory. */ - cipher_data =3D - qemu_try_blockalign(bs->file->bs, MIN(BLOCK_CRYPTO_MAX_IO_SIZE, - qiov->size)); + assert(qiov->size <=3D BLOCK_CRYPTO_MAX_IO_SIZE); + cipher_data =3D qemu_try_blockalign(bs->file->bs, qiov->size); if (cipher_data =3D=3D NULL) { ret =3D -ENOMEM; goto cleanup; } - while (bytes) { - cur_bytes =3D MIN(bytes, BLOCK_CRYPTO_MAX_IO_SIZE); + qemu_iovec_reset(&hd_qiov); + qemu_iovec_add(&hd_qiov, cipher_data, bytes); - qemu_iovec_reset(&hd_qiov); - qemu_iovec_add(&hd_qiov, cipher_data, cur_bytes); - - ret =3D bdrv_co_preadv(bs->file, payload_offset + offset + bytes_d= one, - cur_bytes, &hd_qiov, 0); - if (ret < 0) { - goto cleanup; - } - - if (qcrypto_block_decrypt(crypto->block, offset + bytes_done, - cipher_data, cur_bytes, NULL) < 0) { - ret =3D -EIO; - goto cleanup; - } - - qemu_iovec_from_buf(qiov, bytes_done, cipher_data, cur_bytes); + ret =3D bdrv_co_preadv(bs->file, payload_offset + offset, bytes, + &hd_qiov, 0); + if (ret < 0) { + goto cleanup; + } - bytes -=3D cur_bytes; - bytes_done +=3D cur_bytes; + if (qcrypto_block_decrypt(crypto->block, offset, + cipher_data, bytes, NULL) < 0) { + ret =3D -EIO; + goto cleanup; } + qemu_iovec_from_buf(qiov, 0, cipher_data, bytes); + cleanup: qemu_iovec_destroy(&hd_qiov); qemu_vfree(cipher_data); @@ -391,8 +381,6 @@ block_crypto_co_pwritev(BlockDriverState *bs, uint64_t = offset, uint64_t bytes, QEMUIOVector *qiov, int flags) { BlockCrypto *crypto =3D bs->opaque; - uint64_t cur_bytes; /* number of bytes in current iteration */ - uint64_t bytes_done =3D 0; uint8_t *cipher_data =3D NULL; QEMUIOVector hd_qiov; int ret =3D 0; @@ -409,36 +397,28 @@ block_crypto_co_pwritev(BlockDriverState *bs, uint64_= t offset, uint64_t bytes, /* Bounce buffer because we're not permitted to touch * contents of qiov - it points to guest memory. */ - cipher_data =3D - qemu_try_blockalign(bs->file->bs, MIN(BLOCK_CRYPTO_MAX_IO_SIZE, - qiov->size)); + assert(qiov->size <=3D BLOCK_CRYPTO_MAX_IO_SIZE); + cipher_data =3D qemu_try_blockalign(bs->file->bs, qiov->size); if (cipher_data =3D=3D NULL) { ret =3D -ENOMEM; goto cleanup; } - while (bytes) { - cur_bytes =3D MIN(bytes, BLOCK_CRYPTO_MAX_IO_SIZE); + qemu_iovec_to_buf(qiov, 0, cipher_data, bytes); - qemu_iovec_to_buf(qiov, bytes_done, cipher_data, cur_bytes); + if (qcrypto_block_encrypt(crypto->block, offset, + cipher_data, bytes, NULL) < 0) { + ret =3D -EIO; + goto cleanup; + } - if (qcrypto_block_encrypt(crypto->block, offset + bytes_done, - cipher_data, cur_bytes, NULL) < 0) { - ret =3D -EIO; - goto cleanup; - } + qemu_iovec_reset(&hd_qiov); + qemu_iovec_add(&hd_qiov, cipher_data, bytes); - qemu_iovec_reset(&hd_qiov); - qemu_iovec_add(&hd_qiov, cipher_data, cur_bytes); - - ret =3D bdrv_co_pwritev(bs->file, payload_offset + offset + bytes_= done, - cur_bytes, &hd_qiov, flags); - if (ret < 0) { - goto cleanup; - } - - bytes -=3D cur_bytes; - bytes_done +=3D cur_bytes; + ret =3D bdrv_co_pwritev(bs->file, payload_offset + offset, + bytes, &hd_qiov, flags); + if (ret < 0) { + goto cleanup; } cleanup: @@ -453,7 +433,7 @@ static void block_crypto_refresh_limits(BlockDriverStat= e *bs, Error **errp) BlockCrypto *crypto =3D bs->opaque; uint64_t sector_size =3D qcrypto_block_get_sector_size(crypto->block); bs->bl.request_alignment =3D sector_size; /* No sub-sector I/O */ - bs->bl.max_transfer =3D INT64_MAX; + bs->bl.max_transfer =3D BLOCK_CRYPTO_MAX_IO_SIZE; } --=20 2.17.2