From patchwork Thu Nov 15 02:03:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 10683431 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1A5F114E2 for ; Thu, 15 Nov 2018 02:05:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF4C02C154 for ; Thu, 15 Nov 2018 02:05:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E32B52C158; Thu, 15 Nov 2018 02:05:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6F7B72C154 for ; Thu, 15 Nov 2018 02:05:29 +0000 (UTC) Received: from localhost ([::1]:35610 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN728-0003Sv-Pd for patchwork-qemu-devel@patchwork.kernel.org; Wed, 14 Nov 2018 21:05:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53474) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN70c-0002AV-6V for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:03:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gN70Y-0005bt-Vv for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:03:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51758) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gN70S-0005ZC-Ab; Wed, 14 Nov 2018 21:03:44 -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 27EA7308428D; Thu, 15 Nov 2018 02:03:42 +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 5F96860BF6; Thu, 15 Nov 2018 02:03:41 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 14 Nov 2018 20:03:22 -0600 Message-Id: <20181115020334.1189829-2-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.40]); Thu, 15 Nov 2018 02:03:42 +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 01/13] qcow2: Prefer byte-based calls into bs->file 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We had only a few sector-based stragglers left; convert them to use our preferred byte-based accesses. Signed-off-by: Eric Blake Reviewed-by: Alberto Garcia --- v2: rebased to threaded decompression handling [moved from a different series] v5: commit message tweak v2: indentation fix --- block/qcow2-refcount.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 1c63ac244ac..3ef53c0b2c6 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -2374,8 +2374,8 @@ write_refblocks: on_disk_refblock = (void *)((char *) *refcount_table + refblock_index * s->cluster_size); - ret = bdrv_write(bs->file, refblock_offset / BDRV_SECTOR_SIZE, - on_disk_refblock, s->cluster_sectors); + ret = bdrv_pwrite(bs->file, refblock_offset, on_disk_refblock, + s->cluster_size); if (ret < 0) { fprintf(stderr, "ERROR writing refblock: %s\n", strerror(-ret)); goto fail; @@ -2597,7 +2597,7 @@ fail: * - 0 if writing to this offset will not affect the mentioned metadata * - a positive QCow2MetadataOverlap value indicating one overlapping section * - a negative value (-errno) indicating an error while performing a check, - * e.g. when bdrv_read failed on QCOW2_OL_INACTIVE_L2 + * e.g. when bdrv_pread failed on QCOW2_OL_INACTIVE_L2 */ int qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset, int64_t size) From patchwork Thu Nov 15 02:03:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 10683433 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C6B2B1747 for ; Thu, 15 Nov 2018 02:05:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B22682C154 for ; Thu, 15 Nov 2018 02:05:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A612D2C156; Thu, 15 Nov 2018 02:05:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 531952C154 for ; Thu, 15 Nov 2018 02:05:35 +0000 (UTC) Received: from localhost ([::1]:35611 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN72E-0003Uw-I4 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 14 Nov 2018 21:05:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53505) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN70e-0002CR-AV for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:03:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gN70c-0005d5-7J for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:03:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55708) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gN70S-0005Zv-Ff; Wed, 14 Nov 2018 21:03:46 -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 9D11A80462; Thu, 15 Nov 2018 02:03:43 +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 6418260BF6; Thu, 15 Nov 2018 02:03:42 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 14 Nov 2018 20:03:23 -0600 Message-Id: <20181115020334.1189829-3-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.28]); Thu, 15 Nov 2018 02:03:43 +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 02/13] vdi: Switch to byte-based calls 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, Stefan Weil , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We are gradually moving away from sector-based interfaces, towards byte-based. Make the change for the last few sector-based calls into the block layer from the vdi driver. Ideally, the vdi driver should switch to doing everything byte-based, but that's a more invasive change that requires a bit more auditing. Signed-off-by: Eric Blake Reviewed-by: Alberto Garcia --- block/vdi.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/block/vdi.c b/block/vdi.c index 2380daa583e..b5d699f62c2 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -377,7 +377,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, logout("\n"); - ret = bdrv_read(bs->file, 0, (uint8_t *)&header, 1); + ret = bdrv_pread(bs->file, 0, &header, sizeof(header)); if (ret < 0) { goto fail; } @@ -467,15 +467,14 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, s->header = header; bmap_size = header.blocks_in_image * sizeof(uint32_t); - bmap_size = DIV_ROUND_UP(bmap_size, SECTOR_SIZE); - s->bmap = qemu_try_blockalign(bs->file->bs, bmap_size * SECTOR_SIZE); + s->bmap = qemu_try_blockalign(bs->file->bs, bmap_size); if (s->bmap == NULL) { ret = -ENOMEM; goto fail; } - ret = bdrv_read(bs->file, s->bmap_sector, (uint8_t *)s->bmap, - bmap_size); + ret = bdrv_pread(bs->file, s->bmap_sector * SECTOR_SIZE, s->bmap, + bmap_size); if (ret < 0) { goto fail_free_bmap; } @@ -694,7 +693,7 @@ nonallocating_write: assert(VDI_IS_ALLOCATED(bmap_first)); *header = s->header; vdi_header_to_le(header); - ret = bdrv_write(bs->file, 0, block, 1); + ret = bdrv_pwrite(bs->file, 0, block, SECTOR_SIZE); g_free(block); block = NULL; @@ -712,7 +711,8 @@ nonallocating_write: base = ((uint8_t *)&s->bmap[0]) + bmap_first * SECTOR_SIZE; logout("will write %u block map sectors starting from entry %u\n", n_sectors, bmap_first); - ret = bdrv_write(bs->file, offset, base, n_sectors); + ret = bdrv_pwrite(bs->file, offset * SECTOR_SIZE, base, + n_sectors * SECTOR_SIZE); } return ret; From patchwork Thu Nov 15 02:03:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 10683441 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A9C10109C for ; Thu, 15 Nov 2018 02:08:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 940BC2C140 for ; Thu, 15 Nov 2018 02:08:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87D712C15F; Thu, 15 Nov 2018 02:08:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 15DFD2C16C for ; Thu, 15 Nov 2018 02:08:27 +0000 (UTC) Received: from localhost ([::1]:35627 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN750-00067X-Bb for patchwork-qemu-devel@patchwork.kernel.org; Wed, 14 Nov 2018 21:08:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53522) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN70g-0002ED-6Y for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:03:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gN70e-0005dr-9h for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:03:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41612) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gN70U-0005aH-S6; Wed, 14 Nov 2018 21:03:50 -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 A08CD31256C4; Thu, 15 Nov 2018 02:03:44 +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 D8DF860C45; Thu, 15 Nov 2018 02:03:43 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 14 Nov 2018 20:03:24 -0600 Message-Id: <20181115020334.1189829-4-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.46]); Thu, 15 Nov 2018 02:03:44 +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 03/13] vvfat: Switch to byte-based calls 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We are gradually moving away from sector-based interfaces, towards byte-based. Make the change for the last few sector-based calls into the block layer from the vvfat driver. Ideally, the vvfat driver should switch to doing everything byte-based, but that's a more invasive change that requires a bit more auditing. Signed-off-by: Eric Blake Reviewed-by: Alberto Garcia --- block/vvfat.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index b7b61ea8b78..915a05ae4f2 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1494,8 +1494,8 @@ static int vvfat_read(BlockDriverState *bs, int64_t sector_num, DLOG(fprintf(stderr, "sectors %" PRId64 "+%" PRId64 " allocated\n", sector_num, n >> BDRV_SECTOR_BITS)); - if (bdrv_read(s->qcow, sector_num, buf + i * 0x200, - n >> BDRV_SECTOR_BITS)) { + if (bdrv_pread(s->qcow, sector_num * BDRV_SECTOR_BITS, + buf + i * 0x200, n) < 0) { return -1; } i += (n >> BDRV_SECTOR_BITS) - 1; @@ -1983,7 +1983,8 @@ static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s, if (res) { return -1; } - res = bdrv_write(s->qcow, offset, s->cluster_buffer, 1); + res = bdrv_pwrite(s->qcow, offset * BDRV_SECTOR_SIZE, + s->cluster_buffer, BDRV_SECTOR_SIZE); if (res) { return -2; } @@ -2146,7 +2147,7 @@ DLOG(checkpoint()); * - get modified FAT * - compare the two FATs (TODO) * - get buffer for marking used clusters - * - recurse direntries from root (using bs->bdrv_read to make + * - recurse direntries from root (using bs->bdrv_pread to make * sure to get the new data) * - check that the FAT agrees with the size * - count the number of clusters occupied by this directory and @@ -2911,9 +2912,9 @@ static int handle_deletes(BDRVVVFATState* s) /* * synchronize mapping with new state: * - * - copy FAT (with bdrv_read) + * - copy FAT (with bdrv_pread) * - mark all filenames corresponding to mappings as deleted - * - recurse direntries from root (using bs->bdrv_read) + * - recurse direntries from root (using bs->bdrv_pread) * - delete files corresponding to mappings marked as deleted */ static int do_commit(BDRVVVFATState* s) @@ -2933,10 +2934,10 @@ static int do_commit(BDRVVVFATState* s) return ret; } - /* copy FAT (with bdrv_read) */ + /* copy FAT (with bdrv_pread) */ memcpy(s->fat.pointer, s->fat2, 0x200 * s->sectors_per_fat); - /* recurse direntries from root (using bs->bdrv_read) */ + /* recurse direntries from root (using bs->bdrv_pread) */ ret = commit_direntries(s, 0, -1); if (ret) { fprintf(stderr, "Fatal: error while committing (%d)\n", ret); @@ -3050,7 +3051,8 @@ DLOG(checkpoint()); * Use qcow backend. Commit later. */ DLOG(fprintf(stderr, "Write to qcow backend: %d + %d\n", (int)sector_num, nb_sectors)); - ret = bdrv_write(s->qcow, sector_num, buf, nb_sectors); + ret = bdrv_pwrite(s->qcow, sector_num * BDRV_SECTOR_SIZE, buf, + nb_sectors * BDRV_SECTOR_SIZE); if (ret < 0) { fprintf(stderr, "Error writing to qcow backend\n"); return ret; From patchwork Thu Nov 15 02:03:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 10683447 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A36C313B5 for ; Thu, 15 Nov 2018 02:10:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86B982C199 for ; Thu, 15 Nov 2018 02:10:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7926D2C19A; Thu, 15 Nov 2018 02:10:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E871B2C197 for ; Thu, 15 Nov 2018 02:10:53 +0000 (UTC) Received: from localhost ([::1]:35644 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN77M-0007vL-Kc for patchwork-qemu-devel@patchwork.kernel.org; Wed, 14 Nov 2018 21:10:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN70g-0002EC-67 for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:03:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gN70e-0005dq-9X for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:03:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56458) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gN70Z-0005bo-9x; Wed, 14 Nov 2018 21:03:51 -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 9E44E30832CF; Thu, 15 Nov 2018 02:03:50 +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 DE14360BF6; Thu, 15 Nov 2018 02:03:44 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 14 Nov 2018 20:03:25 -0600 Message-Id: <20181115020334.1189829-5-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.44]); Thu, 15 Nov 2018 02:03:50 +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 04/13] block: Removed unused sector-based blocking I/O 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, Fam Zheng , Stefan Hajnoczi , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We are gradually moving away from sector-based interfaces, towards byte-based. Now that all callers of blocking I/O have been converted to use our preferred byte-based bdrv_p{read,write}(), we can delete the unused bdrv_{read,write}(). Note that the old byte-based code checked that callers passed values for transactions that did not exceed 2G limits (to prevent scaling the caller's input by the sector size from exceeding a signed 32-bit length). We can double-check that the block layer does the same thing for byte-based code, by noting that even though the newer signatures allow a 64-bit length parameter, the block layer is actually fragmenting things to honor both bl.max_transfer (0 if the driver has no inherent limit, or has not been audited for 64-bit cleanness; non-zero if the driver wants to enforce a particular cap) as well as some sanity sizing, as follows: - bdrv_merge_limits(): Uses the smaller cap of either driver (or leaves things uncapped if both drivers enforce no cap) - bdrv_co_do_copy_on_readv(): Caps things to 2G if driver did not request cap - bdrv_aligned_preadv(): Caps things to 2G if driver did not request cap - bdrv_co_do_pwrite_zeroes(): Caps things to MAX_BOUNCE_BUFFER if driver did not request cap - bdrv_aligned_pwritev(): Caps things to 2G if driver did not request cap Signed-off-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- v2: Enhance commit message with audit results --- include/block/block.h | 4 ---- block/io.c | 48 ++++++++----------------------------------- 2 files changed, 8 insertions(+), 44 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 7f5453b45b6..52b18373807 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -307,10 +307,6 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, Error **errp); void bdrv_reopen_commit(BDRVReopenState *reopen_state); void bdrv_reopen_abort(BDRVReopenState *reopen_state); -int bdrv_read(BdrvChild *child, int64_t sector_num, - uint8_t *buf, int nb_sectors); -int bdrv_write(BdrvChild *child, int64_t sector_num, - const uint8_t *buf, int nb_sectors); int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, int bytes, BdrvRequestFlags flags); int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags); diff --git a/block/io.c b/block/io.c index bd9d688f8ba..39d4e7a3ae1 100644 --- a/block/io.c +++ b/block/io.c @@ -836,45 +836,6 @@ static int bdrv_prwv_co(BdrvChild *child, int64_t offset, return rwco.ret; } -/* - * Process a synchronous request using coroutines - */ -static int bdrv_rw_co(BdrvChild *child, int64_t sector_num, uint8_t *buf, - int nb_sectors, bool is_write, BdrvRequestFlags flags) -{ - QEMUIOVector qiov; - struct iovec iov = { - .iov_base = (void *)buf, - .iov_len = nb_sectors * BDRV_SECTOR_SIZE, - }; - - if (nb_sectors < 0 || nb_sectors > BDRV_REQUEST_MAX_SECTORS) { - return -EINVAL; - } - - qemu_iovec_init_external(&qiov, &iov, 1); - return bdrv_prwv_co(child, sector_num << BDRV_SECTOR_BITS, - &qiov, is_write, flags); -} - -/* return < 0 if error. See bdrv_write() for the return codes */ -int bdrv_read(BdrvChild *child, int64_t sector_num, - uint8_t *buf, int nb_sectors) -{ - return bdrv_rw_co(child, sector_num, buf, nb_sectors, false, 0); -} - -/* Return < 0 if error. Important errors are: - -EIO generic I/O error (may happen for all errors) - -ENOMEDIUM No media inserted. - -EINVAL Invalid sector number or nb_sectors - -EACCES Trying to write a read-only device -*/ -int bdrv_write(BdrvChild *child, int64_t sector_num, - const uint8_t *buf, int nb_sectors) -{ - return bdrv_rw_co(child, sector_num, (uint8_t *)buf, nb_sectors, true, 0); -} int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, int bytes, BdrvRequestFlags flags) @@ -897,7 +858,7 @@ int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, * flags are passed through to bdrv_pwrite_zeroes (e.g. BDRV_REQ_MAY_UNMAP, * BDRV_REQ_FUA). * - * Returns < 0 on error, 0 on success. For error codes see bdrv_write(). + * Returns < 0 on error, 0 on success. For error codes see bdrv_pwrite(). */ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) { @@ -935,6 +896,7 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) } } +/* return < 0 if error. See bdrv_pwrite() for the return codes */ int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) { int ret; @@ -975,6 +937,12 @@ int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) return qiov->size; } +/* Return < 0 if error. Important errors are: + -EIO generic I/O error (may happen for all errors) + -ENOMEDIUM No media inserted. + -EINVAL Invalid sector number or nb_sectors + -EACCES Trying to write a read-only device +*/ int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, int bytes) { QEMUIOVector qiov; From patchwork Thu Nov 15 02:03:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 10683455 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1773D14DB for ; Thu, 15 Nov 2018 02:13:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01F7A2C1B9 for ; Thu, 15 Nov 2018 02:13:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA61C2C1BB; Thu, 15 Nov 2018 02:13:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 968A72C1B9 for ; Thu, 15 Nov 2018 02:13:16 +0000 (UTC) Received: from localhost ([::1]:35655 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN79f-0001rz-Uk for patchwork-qemu-devel@patchwork.kernel.org; Wed, 14 Nov 2018 21:13:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53616) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN70m-0002LG-S1 for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:04:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gN70l-0005h0-JF for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:04:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55002) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gN70e-0005dG-9f; Wed, 14 Nov 2018 21:03:58 -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 7FA4489ADB; Thu, 15 Nov 2018 02:03:54 +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 F1EE960BF6; Thu, 15 Nov 2018 02:03:50 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 14 Nov 2018 20:03:26 -0600 Message-Id: <20181115020334.1189829-6-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.26]); Thu, 15 Nov 2018 02:03:54 +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 05/13] block: Switch to 64-bit bl.max_transfer 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, Fam Zheng , Stefan Hajnoczi , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This change has no semantic impact: all drivers either leave the value at 0 (no inherent 32-bit limit is still translated into fragmentation below 2G; see the previous patch for that audit), or set it to a value less than 2G. However, switching to a larger type and enforcing the 2G cap at the block layer makes it easier to audit specific drivers for their robustness to larger sizing, by letting them specify a value larger than INT_MAX if they have been audited to be 64-bit clean. Signed-off-by: Eric Blake --- include/block/block_int.h | 8 +++++--- block/io.c | 7 +++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index f605622216d..b19d94dac5f 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -549,9 +549,11 @@ typedef struct BlockLimits { /* Maximal transfer length in bytes. Need not be power of 2, but * must be multiple of opt_transfer and bl.request_alignment, or 0 - * for no 32-bit limit. For now, anything larger than INT_MAX is - * clamped down. */ - uint32_t max_transfer; + * for no 32-bit limit. The block layer fragments all actions + * below 2G, so setting this value to anything larger than INT_MAX + * implies that the driver has been audited for 64-bit + * cleanness. */ + uint64_t max_transfer; /* memory alignment, in bytes so that no bounce buffer is needed */ size_t min_mem_alignment; diff --git a/block/io.c b/block/io.c index 39d4e7a3ae1..4911a1123eb 100644 --- a/block/io.c +++ b/block/io.c @@ -159,6 +159,13 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error **errp) if (drv->bdrv_refresh_limits) { drv->bdrv_refresh_limits(bs, errp); } + + /* Clamp max_transfer to 2G */ + if (bs->bl.max_transfer > UINT32_MAX) { + bs->bl.max_transfer = QEMU_ALIGN_DOWN(BDRV_REQUEST_MAX_BYTES, + MAX(bs->bl.opt_transfer, + bs->bl.request_alignment)); + } } /** From patchwork Thu Nov 15 02:03:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 10683445 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A1A1414E2 for ; Thu, 15 Nov 2018 02:08:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B3902C0BE for ; Thu, 15 Nov 2018 02:08:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E9F82C0EB; Thu, 15 Nov 2018 02:08:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1ABD82C0BE for ; Thu, 15 Nov 2018 02:08:54 +0000 (UTC) Received: from localhost ([::1]:35630 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN75R-0006SD-9Z for patchwork-qemu-devel@patchwork.kernel.org; Wed, 14 Nov 2018 21:08:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN70p-0002N2-Lg for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:04:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gN70n-0005it-Nv for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:04:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58532) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gN70i-0005e3-17; Wed, 14 Nov 2018 21:04:00 -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 5E08036807; Thu, 15 Nov 2018 02:03:56 +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 D752A60BF6; Thu, 15 Nov 2018 02:03:54 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 14 Nov 2018 20:03:27 -0600 Message-Id: <20181115020334.1189829-7-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.30]); Thu, 15 Nov 2018 02:03:56 +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 06/13] blkdebug: Audit for read/write 64-bit cleanness 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, Markus Armbruster , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Since the block layer is never supposed to hand us an offset + bytes that would exceed off_t, we can assert this in rule_check(). With that in place, there is nothing else in the pread, pwrite, or pwrite_zeroes code paths that can't handle inputs larger than 2G (even if the block layer currently never hands us something that large); update the refresh_limits callback to document this fact, when the user doesn't specify an override. For a user override, we have to change the QAPI type to 'uint64' instead of 'int'. At the same time, we can also change 'align' to 'int32' to match the existing checks in blkdebug_open() that alignment is always smaller than 2G. Signed-off-by: Eric Blake --- qapi/block-core.json | 2 +- block/blkdebug.c | 17 +++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index d4fe710836e..32f0edd189f 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3122,7 +3122,7 @@ { 'struct': 'BlockdevOptionsBlkdebug', 'data': { 'image': 'BlockdevRef', '*config': 'str', - '*align': 'int', '*max-transfer': 'int32', + '*align': 'int32', '*max-transfer': 'uint64', '*opt-write-zero': 'int32', '*max-write-zero': 'int32', '*opt-discard': 'int32', '*max-discard': 'int32', '*inject-error': ['BlkdebugInjectErrorOptions'], diff --git a/block/blkdebug.c b/block/blkdebug.c index 0759452925b..be4d65f86a0 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -415,9 +415,7 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags, align = MAX(s->align, bs->file->bs->bl.request_alignment); s->max_transfer = qemu_opt_get_size(opts, "max-transfer", 0); - if (s->max_transfer && - (s->max_transfer >= INT_MAX || - !QEMU_IS_ALIGNED(s->max_transfer, align))) { + if (s->max_transfer && !QEMU_IS_ALIGNED(s->max_transfer, align)) { error_setg(errp, "Cannot meet constraints with max-transfer %" PRIu64, s->max_transfer); goto out; @@ -477,6 +475,7 @@ static int rule_check(BlockDriverState *bs, uint64_t offset, uint64_t bytes) int error; bool immediately; + assert(offset <= INT64_MAX - bytes); QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) { uint64_t inject_offset = rule->options.inject.offset; @@ -517,9 +516,7 @@ blkdebug_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes, /* Sanity check block layer guarantees */ assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment)); assert(QEMU_IS_ALIGNED(bytes, bs->bl.request_alignment)); - if (bs->bl.max_transfer) { - assert(bytes <= bs->bl.max_transfer); - } + assert(bytes <= bs->bl.max_transfer); err = rule_check(bs, offset, bytes); if (err) { @@ -538,9 +535,7 @@ blkdebug_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes, /* Sanity check block layer guarantees */ assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment)); assert(QEMU_IS_ALIGNED(bytes, bs->bl.request_alignment)); - if (bs->bl.max_transfer) { - assert(bytes <= bs->bl.max_transfer); - } + assert(bytes <= bs->bl.max_transfer); err = rule_check(bs, offset, bytes); if (err) { @@ -865,9 +860,7 @@ static void blkdebug_refresh_limits(BlockDriverState *bs, Error **errp) if (s->align) { bs->bl.request_alignment = s->align; } - if (s->max_transfer) { - bs->bl.max_transfer = s->max_transfer; - } + bs->bl.max_transfer = s->max_transfer ?: INT64_MAX; if (s->opt_write_zero) { bs->bl.pwrite_zeroes_alignment = s->opt_write_zero; } From patchwork Thu Nov 15 02:03:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 10683439 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F1D2B14E2 for ; Thu, 15 Nov 2018 02:06:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCBCC2C15B for ; Thu, 15 Nov 2018 02:06:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0A452C15D; Thu, 15 Nov 2018 02:06:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 826F82C15B for ; Thu, 15 Nov 2018 02:06:05 +0000 (UTC) Received: from localhost ([::1]:35613 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN72i-0003xf-Px for patchwork-qemu-devel@patchwork.kernel.org; Wed, 14 Nov 2018 21:06:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53684) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN70p-0002N0-Lc for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:04:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gN70m-0005iD-W0 for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:04:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60964) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gN70i-0005ew-0w; Wed, 14 Nov 2018 21:04:00 -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 6493D80E7B; Thu, 15 Nov 2018 02:03:58 +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 BD66860BF7; Thu, 15 Nov 2018 02:03:56 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 14 Nov 2018 20:03:28 -0600 Message-Id: <20181115020334.1189829-8-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.25]); Thu, 15 Nov 2018 02:03:58 +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 07/13] blklogwrites: Audit for read/write 64-bit cleanness 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, Ari Sundholm , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Nothing in blk_log_writes_co_do_log() is inherently limited by a 32-bit type; document this by updating the refresh_limits callback to document that this driver is 64-bit clean. Signed-off-by: Eric Blake --- block/blklogwrites.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/blklogwrites.c b/block/blklogwrites.c index ff98cd55333..c945d3d77d7 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -328,6 +328,7 @@ static void blk_log_writes_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVBlkLogWritesState *s = bs->opaque; bs->bl.request_alignment = s->sectorsize; + bs->bl.max_transfer = INT64_MAX; } static int coroutine_fn From patchwork Thu Nov 15 02:03:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 10683443 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A9B9914E2 for ; Thu, 15 Nov 2018 02:08:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91CA128B47 for ; Thu, 15 Nov 2018 02:08:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 841FF28A04; Thu, 15 Nov 2018 02:08:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 334BA28A7A for ; Thu, 15 Nov 2018 02:08:32 +0000 (UTC) Received: from localhost ([::1]:35621 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN755-0004pq-FM for patchwork-qemu-devel@patchwork.kernel.org; Wed, 14 Nov 2018 21:08:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53685) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN70p-0002N1-Lf for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:04:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gN70n-0005iy-Pf for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:04:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55760) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gN70i-0005fA-Mn; Wed, 14 Nov 2018 21:04:02 -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 79B0588307; Thu, 15 Nov 2018 02:03:59 +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 B08BD60BF6; Thu, 15 Nov 2018 02:03:58 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 14 Nov 2018 20:03:29 -0600 Message-Id: <20181115020334.1189829-9-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.28]); Thu, 15 Nov 2018 02:03:59 +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 08/13] crypto: Audit for read/write 64-bit cleanness 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The crypto read/write functions do their own fragmentation (because everything has to go through a bounce buffer); while we could advertise BLOCK_CRYPTO_MAX_IO_SIZE as our max_transfer (and let the block layer do our fragmentation for us), I'm instead choosing to document that this driver is 64-bit clean. Signed-off-by: Eric Blake --- block/crypto.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/crypto.c b/block/crypto.c index 33ee01bebd9..259ef2649e1 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -453,6 +453,7 @@ static void block_crypto_refresh_limits(BlockDriverState *bs, Error **errp) BlockCrypto *crypto = bs->opaque; uint64_t sector_size = qcrypto_block_get_sector_size(crypto->block); bs->bl.request_alignment = sector_size; /* No sub-sector I/O */ + bs->bl.max_transfer = INT64_MAX; } From patchwork Thu Nov 15 02:03:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 10683453 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5EFCE14DB for ; Thu, 15 Nov 2018 02:13:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 407742C1B9 for ; Thu, 15 Nov 2018 02:13:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32AC42C1BB; Thu, 15 Nov 2018 02:13:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AC7352C1B9 for ; Thu, 15 Nov 2018 02:13:14 +0000 (UTC) Received: from localhost ([::1]:35654 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN79d-0001qd-RK for patchwork-qemu-devel@patchwork.kernel.org; Wed, 14 Nov 2018 21:13:13 -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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 offset, uint64_t bytes, QEMUIOVector *qiov, int flags) { BlockCrypto *crypto = bs->opaque; - uint64_t cur_bytes; /* number of bytes in current iteration */ - uint64_t bytes_done = 0; uint8_t *cipher_data = NULL; QEMUIOVector hd_qiov; int ret = 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 = - qemu_try_blockalign(bs->file->bs, MIN(BLOCK_CRYPTO_MAX_IO_SIZE, - qiov->size)); + assert(qiov->size <= BLOCK_CRYPTO_MAX_IO_SIZE); + cipher_data = qemu_try_blockalign(bs->file->bs, qiov->size); if (cipher_data == NULL) { ret = -ENOMEM; goto cleanup; } - while (bytes) { - cur_bytes = 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 = bdrv_co_preadv(bs->file, payload_offset + offset + bytes_done, - 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 = -EIO; - goto cleanup; - } - - qemu_iovec_from_buf(qiov, bytes_done, cipher_data, cur_bytes); + ret = bdrv_co_preadv(bs->file, payload_offset + offset, bytes, + &hd_qiov, 0); + if (ret < 0) { + goto cleanup; + } - bytes -= cur_bytes; - bytes_done += cur_bytes; + if (qcrypto_block_decrypt(crypto->block, offset, + cipher_data, bytes, NULL) < 0) { + ret = -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 = bs->opaque; - uint64_t cur_bytes; /* number of bytes in current iteration */ - uint64_t bytes_done = 0; uint8_t *cipher_data = NULL; QEMUIOVector hd_qiov; int ret = 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 = - qemu_try_blockalign(bs->file->bs, MIN(BLOCK_CRYPTO_MAX_IO_SIZE, - qiov->size)); + assert(qiov->size <= BLOCK_CRYPTO_MAX_IO_SIZE); + cipher_data = qemu_try_blockalign(bs->file->bs, qiov->size); if (cipher_data == NULL) { ret = -ENOMEM; goto cleanup; } - while (bytes) { - cur_bytes = 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 = -EIO; + goto cleanup; + } - if (qcrypto_block_encrypt(crypto->block, offset + bytes_done, - cipher_data, cur_bytes, NULL) < 0) { - ret = -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 = bdrv_co_pwritev(bs->file, payload_offset + offset + bytes_done, - cur_bytes, &hd_qiov, flags); - if (ret < 0) { - goto cleanup; - } - - bytes -= cur_bytes; - bytes_done += cur_bytes; + ret = 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(BlockDriverState *bs, Error **errp) BlockCrypto *crypto = bs->opaque; uint64_t sector_size = qcrypto_block_get_sector_size(crypto->block); bs->bl.request_alignment = sector_size; /* No sub-sector I/O */ - bs->bl.max_transfer = INT64_MAX; + bs->bl.max_transfer = BLOCK_CRYPTO_MAX_IO_SIZE; } From patchwork Thu Nov 15 02:03:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 10683459 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9BB9813B5 for ; Thu, 15 Nov 2018 02:15:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86DAF2C1BA for ; Thu, 15 Nov 2018 02:15:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A5012C1BE; Thu, 15 Nov 2018 02:15:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 27D592C1BA for ; Thu, 15 Nov 2018 02:15:08 +0000 (UTC) Received: from localhost ([::1]:35664 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN7BT-00032A-Ey for patchwork-qemu-devel@patchwork.kernel.org; Wed, 14 Nov 2018 21:15:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN70u-0002QC-OG 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-0005ky-Kl for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:04:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32910) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gN70m-0005ft-Pg; 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 820CE80F90; Thu, 15 Nov 2018 02:04:01 +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 B5F0E60BF6; Thu, 15 Nov 2018 02:04:00 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 14 Nov 2018 20:03:31 -0600 Message-Id: <20181115020334.1189829-11-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.27]); Thu, 15 Nov 2018 02:04:01 +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 10/13] file-posix: Audit for read/write 64-bit cleanness 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Any use of aio is inherently limited by size_t aio_nbytes in struct aiocb. read() is similarly limited to size_t bytes, although in practice, the ssize_t return means any read attempt on a 32-bit platform for more than 2G will likely return a short read (if that much memory was even available to begin with). And while preadv() can technically read more than size_t bytes by use of more than one iov, the fact that you can only pass a finite number of iov each of which is limited to size_t bytes is a limiting factor. While we already attempt other methods at populating a more reasonable max_transfer limit in the cases where the kernel makes that information available, it is important that we at least let the block layer know about our hard limitation of size_t bytes (mainly applicable to 32-bit compilation). At the same time, on 64-bit platforms, that means we are now advertising that we don't have any other unintended size-botching problems, if the block layer were to start handing us requests larger than 2G. Signed-off-by: Eric Blake --- block/file-posix.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index 48ad3bb372a..4b43ff8cb5c 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1073,6 +1073,9 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) raw_probe_alignment(bs, s->fd, errp); bs->bl.min_mem_alignment = s->buf_align; bs->bl.opt_mem_alignment = MAX(s->buf_align, getpagesize()); + if (!bs->bl.max_transfer) { + bs->bl.max_transfer = SIZE_MAX; + } } static int check_for_dasd(int fd) From patchwork Thu Nov 15 02:03:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 10683449 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8023C13B5 for ; Thu, 15 Nov 2018 02:11:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66C942C19B for ; Thu, 15 Nov 2018 02:11:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B1932C19D; Thu, 15 Nov 2018 02:11:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0D9152C19B for ; Thu, 15 Nov 2018 02:11:00 +0000 (UTC) Received: from localhost ([::1]:35645 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN77T-00080D-7u for patchwork-qemu-devel@patchwork.kernel.org; Wed, 14 Nov 2018 21:10:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53760) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN70u-0002QA-Ni 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-0005kj-HL for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:04:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60456) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gN70m-0005gT-1p; 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 888E213A5C; Thu, 15 Nov 2018 02:04:02 +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 BB18E60BF6; Thu, 15 Nov 2018 02:04:01 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 14 Nov 2018 20:03:32 -0600 Message-Id: <20181115020334.1189829-12-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.29]); Thu, 15 Nov 2018 02:04:02 +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 11/13] qcow2: Audit for read/write 64-bit cleanness 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The qcow2 read/write functions do their own fragmentation (because of cluster remapping); while we could advertise s->cluster_size and let the block layer do fragmentation for us, that would NOT solve the issue of the block layer handing us a length less than a cluster but at an offset which overlaps a cluster boundary. Thus, we still have to fragment ourselves, at which point it is easiest to just document that this driver is 64-bit clean. Signed-off-by: Eric Blake --- block/qcow2.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/qcow2.c b/block/qcow2.c index 0b5ad130060..1dd3491f77f 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1687,6 +1687,7 @@ static void qcow2_refresh_limits(BlockDriverState *bs, Error **errp) } bs->bl.pwrite_zeroes_alignment = s->cluster_size; bs->bl.pdiscard_alignment = s->cluster_size; + bs->bl.max_transfer = INT64_MAX; } static int qcow2_reopen_prepare(BDRVReopenState *state, From patchwork Thu Nov 15 02:03:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 10683457 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EC51B13BB for ; Thu, 15 Nov 2018 02:15:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDEE42C1BA for ; Thu, 15 Nov 2018 02:15:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C18092C1BE; Thu, 15 Nov 2018 02:15:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5585A2C1BA for ; Thu, 15 Nov 2018 02:15:06 +0000 (UTC) Received: from localhost ([::1]:35662 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN7BR-00030j-Lg for patchwork-qemu-devel@patchwork.kernel.org; Wed, 14 Nov 2018 21:15:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53800) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN70x-0002SI-C8 for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:04:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gN70v-0005mg-U3 for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:04:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:6462) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gN70s-0005lA-MY; Wed, 14 Nov 2018 21:04:10 -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 D4B6EC049D7A; Thu, 15 Nov 2018 02:04:09 +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 CB09760BF7; Thu, 15 Nov 2018 02:04:02 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 14 Nov 2018 20:03:33 -0600 Message-Id: <20181115020334.1189829-13-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.31]); Thu, 15 Nov 2018 02:04:09 +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 12/13] block: Document need for audit of read/write 64-bit cleanness 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, Josh Durgin , qemu-block@nongnu.org, Stefan Weil , Jeff Cody , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP At this time, any block driver that has not been audited for 64-bit cleanness, but which uses byte-based callbacks, should explicitly document that the driver wants the block layer to cap things at 2G. This patch has no semantic change. And it shows that the things I'm not interested in auditing are: bochs, cloop, dmg, file-win32, qcow, rbd, vvfat, vxhs Signed-off-by: Eric Blake --- block/bochs.c | 1 + block/cloop.c | 1 + block/dmg.c | 1 + block/file-win32.c | 2 ++ block/qcow.c | 1 + block/rbd.c | 1 + block/vvfat.c | 1 + block/vxhs.c | 1 + 8 files changed, 9 insertions(+) diff --git a/block/bochs.c b/block/bochs.c index 22e7d442113..cfa449ffb6f 100644 --- a/block/bochs.c +++ b/block/bochs.c @@ -202,6 +202,7 @@ fail: static void bochs_refresh_limits(BlockDriverState *bs, Error **errp) { bs->bl.request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O */ + bs->bl.max_transfer = BDRV_REQUEST_MAX_BYTES; } static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num) diff --git a/block/cloop.c b/block/cloop.c index df2b85f7234..1ac0ed234d8 100644 --- a/block/cloop.c +++ b/block/cloop.c @@ -211,6 +211,7 @@ fail: static void cloop_refresh_limits(BlockDriverState *bs, Error **errp) { bs->bl.request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O */ + bs->bl.max_transfer = BDRV_REQUEST_MAX_BYTES; } static inline int cloop_read_block(BlockDriverState *bs, int block_num) diff --git a/block/dmg.c b/block/dmg.c index 50e91aef6d9..ea5553b6bf2 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -555,6 +555,7 @@ fail: static void dmg_refresh_limits(BlockDriverState *bs, Error **errp) { bs->bl.request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O */ + bs->bl.max_transfer = BDRV_REQUEST_MAX_BYTES; } static inline int is_sector_in_chunk(BDRVDMGState* s, diff --git a/block/file-win32.c b/block/file-win32.c index f1e2187f3bd..91b2dd9ed88 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -256,6 +256,7 @@ static void raw_probe_alignment(BlockDriverState *bs, Error **errp) /* XXX Does Windows support AIO on less than 512-byte alignment? */ bs->bl.request_alignment = 512; + bs->bl.max_transfer = BDRV_REQUEST_MAX_BYTES; } static void raw_parse_flags(int flags, bool use_aio, int *access_flags, @@ -716,6 +717,7 @@ static void hdev_refresh_limits(BlockDriverState *bs, Error **errp) { /* XXX Does Windows support AIO on less than 512-byte alignment? */ bs->bl.request_alignment = 512; + bs->bl.max_transfer = BDRV_REQUEST_MAX_BYTES; } static int hdev_open(BlockDriverState *bs, QDict *options, int flags, diff --git a/block/qcow.c b/block/qcow.c index 4518cb4c35e..ae6deacdb1f 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -618,6 +618,7 @@ static void qcow_refresh_limits(BlockDriverState *bs, Error **errp) * it's easier to let the block layer handle rounding than to * audit this code further. */ bs->bl.request_alignment = BDRV_SECTOR_SIZE; + bs->bl.max_transfer = BDRV_REQUEST_MAX_BYTES; } static coroutine_fn int qcow_co_preadv(BlockDriverState *bs, uint64_t offset, diff --git a/block/rbd.c b/block/rbd.c index 8a1a9f4b6e2..248e635b077 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -236,6 +236,7 @@ static void qemu_rbd_refresh_limits(BlockDriverState *bs, Error **errp) { /* XXX Does RBD support AIO on less than 512-byte alignment? */ bs->bl.request_alignment = 512; + bs->bl.max_transfer = BDRV_REQUEST_MAX_BYTES; } diff --git a/block/vvfat.c b/block/vvfat.c index 915a05ae4f2..35f35328baf 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1304,6 +1304,7 @@ fail: static void vvfat_refresh_limits(BlockDriverState *bs, Error **errp) { bs->bl.request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O */ + bs->bl.max_transfer = BDRV_REQUEST_MAX_BYTES; } static inline void vvfat_close_current_file(BDRVVVFATState *s) diff --git a/block/vxhs.c b/block/vxhs.c index 0cb0a007e90..5828f53432c 100644 --- a/block/vxhs.c +++ b/block/vxhs.c @@ -221,6 +221,7 @@ static void vxhs_refresh_limits(BlockDriverState *bs, Error **errp) { /* XXX Does VXHS support AIO on less than 512-byte alignment? */ bs->bl.request_alignment = 512; + bs->bl.max_transfer = BDRV_REQUEST_MAX_BYTES; } static int vxhs_init_and_ref(void) From patchwork Thu Nov 15 02:03:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 10683451 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 05CC013B5 for ; Thu, 15 Nov 2018 02:11:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E40212C1A3 for ; Thu, 15 Nov 2018 02:11:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D71BC2C1A4; Thu, 15 Nov 2018 02:11:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4B3D42C1A2 for ; Thu, 15 Nov 2018 02:11:21 +0000 (UTC) Received: from localhost ([::1]:35646 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN77o-0008FL-GN for patchwork-qemu-devel@patchwork.kernel.org; Wed, 14 Nov 2018 21:11:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53845) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN71D-0002hN-UE for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:04:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gN718-0005pS-OF for qemu-devel@nongnu.org; Wed, 14 Nov 2018 21:04:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60540) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gN70w-0005mk-Hv; Wed, 14 Nov 2018 21:04:14 -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 C05F0168F; Thu, 15 Nov 2018 02:04:13 +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 1C55760BF6; Thu, 15 Nov 2018 02:04:09 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 14 Nov 2018 20:03:34 -0600 Message-Id: <20181115020334.1189829-14-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.29]); Thu, 15 Nov 2018 02:04:13 +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 13/13] block: Enforce non-zero bl.max_transfer 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, Fam Zheng , Stefan Hajnoczi , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The raw format driver and the filter drivers default to picking up the same limits as what they wrap, and I've audited that they are otherwise simple enough in their passthrough to be 64-bit clean; it's not worth changing their .bdrv_refresh_limits to advertise anything different. Previous patches changed all remaining byte-based format and protocol drivers to supply an explicit max_transfer consistent with an audit (or lack thereof) of their code. And for drivers still using sector-based callbacks (gluster, iscsi, parallels, qed, replication, sheepdog, ssh, vhdx), we can easily supply a 2G default limit while waiting for a later per-driver conversion and auditing while moving to byte-based callbacks. With that, we can assert that max_transfer is now always set (either by sector-based default, by merge with a backing layer, or by explicit settings), and enforce that it be non-zero by the end of bdrv_refresh_limits(). This in turn lets us simplify portions of the block layer to use MIN() instead of MIN_NON_ZERO(), while still fragmenting things to no larger than 2G chunks. Also, we no longer need to rewrite the driver's bl.max_transfer to a value below 2G. There should be no semantic change from this patch, although it does open the door if a future patch wants to let the block layer choose a larger value than 2G while still honoring bl.max_transfer for fragmentation. Signed-off-by: Eric Blake --- [hmm - in sending this email, I realize that I didn't specifically check whether quorum always picks up a sane limit from its children, since it is byte-based but lacks a .bdrv_refresh_limits] include/block/block_int.h | 10 +++++----- block/io.c | 25 ++++++++++++------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index b19d94dac5f..410553bb0cc 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -548,11 +548,11 @@ typedef struct BlockLimits { uint32_t opt_transfer; /* Maximal transfer length in bytes. Need not be power of 2, but - * must be multiple of opt_transfer and bl.request_alignment, or 0 - * for no 32-bit limit. The block layer fragments all actions - * below 2G, so setting this value to anything larger than INT_MAX - * implies that the driver has been audited for 64-bit - * cleanness. */ + * must be larger than opt_transfer and request_alignment (the + * block layer rounds it down as needed). The block layer + * fragments all actions below 2G, so setting this value to + * anything larger than INT_MAX implies that the driver has been + * audited for 64-bit cleanness. */ uint64_t max_transfer; /* memory alignment, in bytes so that no bounce buffer is needed */ diff --git a/block/io.c b/block/io.c index 4911a1123eb..0024be0bf31 100644 --- a/block/io.c +++ b/block/io.c @@ -129,6 +129,9 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error **errp) /* Default alignment based on whether driver has byte interface */ bs->bl.request_alignment = (drv->bdrv_co_preadv || drv->bdrv_aio_preadv) ? 1 : 512; + /* Default cap at 2G for drivers without byte interface */ + if (bs->bl.request_alignment == 1) + bs->bl.max_transfer = BDRV_REQUEST_MAX_BYTES; /* Take some limits from the children as a default */ if (bs->file) { @@ -160,12 +163,11 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error **errp) drv->bdrv_refresh_limits(bs, errp); } - /* Clamp max_transfer to 2G */ - if (bs->bl.max_transfer > UINT32_MAX) { - bs->bl.max_transfer = QEMU_ALIGN_DOWN(BDRV_REQUEST_MAX_BYTES, - MAX(bs->bl.opt_transfer, - bs->bl.request_alignment)); - } + /* Check that we got a maximum cap, and round it down as needed */ + assert(bs->bl.max_transfer); + bs->bl.max_transfer = QEMU_ALIGN_DOWN(bs->bl.max_transfer, + MAX(bs->bl.opt_transfer, + bs->bl.request_alignment)); } /** @@ -1145,8 +1147,7 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child, int64_t cluster_bytes; size_t skip_bytes; int ret; - int max_transfer = MIN_NON_ZERO(bs->bl.max_transfer, - BDRV_REQUEST_MAX_BYTES); + int max_transfer = MIN(bs->bl.max_transfer, BDRV_REQUEST_MAX_BYTES); unsigned int progress = 0; if (!drv) { @@ -1286,8 +1287,7 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child, assert((bytes & (align - 1)) == 0); assert(!qiov || bytes == qiov->size); assert((bs->open_flags & BDRV_O_NO_IO) == 0); - max_transfer = QEMU_ALIGN_DOWN(MIN_NON_ZERO(bs->bl.max_transfer, INT_MAX), - align); + max_transfer = QEMU_ALIGN_DOWN(MIN(bs->bl.max_transfer, INT_MAX), align); /* TODO: We would need a per-BDS .supported_read_flags and * potential fallback support, if we ever implement any read flags @@ -1460,7 +1460,7 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, int max_write_zeroes = MIN_NON_ZERO(bs->bl.max_pwrite_zeroes, INT_MAX); int alignment = MAX(bs->bl.pwrite_zeroes_alignment, bs->bl.request_alignment); - int max_transfer = MIN_NON_ZERO(bs->bl.max_transfer, MAX_BOUNCE_BUFFER); + int max_transfer = MIN(bs->bl.max_transfer, MAX_BOUNCE_BUFFER); if (!drv) { return -ENOMEDIUM; @@ -1668,8 +1668,7 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChild *child, assert((offset & (align - 1)) == 0); assert((bytes & (align - 1)) == 0); assert(!qiov || bytes == qiov->size); - max_transfer = QEMU_ALIGN_DOWN(MIN_NON_ZERO(bs->bl.max_transfer, INT_MAX), - align); + max_transfer = QEMU_ALIGN_DOWN(MIN(bs->bl.max_transfer, INT_MAX), align); ret = bdrv_co_write_req_prepare(child, offset, bytes, req, flags);