From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id F26A182D78 for ; Wed, 1 Dec 2021 14:10:33 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E5CD5CBB2 for ; Wed, 1 Dec 2021 14:10:33 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 15F82CBA6 for ; Wed, 1 Dec 2021 14:10:32 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id C53BD4446D for ; Wed, 1 Dec 2021 14:10:31 +0100 (CET) From: Fabian Ebner To: pve-devel@lists.proxmox.com Date: Wed, 1 Dec 2021 14:10:27 +0100 Message-Id: <20211201131027.296583-1-f.ebner@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.168 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH qemu] fix #3738: cherry-pick "block: introduce max_hw_iov for use in scsi-generic" X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Dec 2021 13:10:34 -0000 which fixes the bad commit 18473467d55a20d643b6c9b3a52de42f705b4d35 that was tracked down via bisecting, and has a Cc for qemu-stable as well. Issue was easy enough to reproduce with a single virtio-block disk using a few runs of dd if=/dev/urandom of=file bs=1M count=1000 Commit cc071629539dc1f303175a7e2d4ab854c0a8b20f upstream. Signed-off-by: Fabian Ebner --- ...e-max_hw_iov-for-use-in-scsi-generic.patch | 124 ++++++++++++++++++ debian/patches/series | 1 + 2 files changed, 125 insertions(+) create mode 100644 debian/patches/extra/0008-block-introduce-max_hw_iov-for-use-in-scsi-generic.patch diff --git a/debian/patches/extra/0008-block-introduce-max_hw_iov-for-use-in-scsi-generic.patch b/debian/patches/extra/0008-block-introduce-max_hw_iov-for-use-in-scsi-generic.patch new file mode 100644 index 0000000..06bc693 --- /dev/null +++ b/debian/patches/extra/0008-block-introduce-max_hw_iov-for-use-in-scsi-generic.patch @@ -0,0 +1,124 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Paolo Bonzini +Date: Thu, 23 Sep 2021 09:04:36 -0400 +Subject: [PATCH] block: introduce max_hw_iov for use in scsi-generic + +Linux limits the size of iovecs to 1024 (UIO_MAXIOV in the kernel +sources, IOV_MAX in POSIX). Because of this, on some host adapters +requests with many iovecs are rejected with -EINVAL by the +io_submit() or readv()/writev() system calls. + +In fact, the same limit applies to SG_IO as well. To fix both the +EINVAL and the possible performance issues from using fewer iovecs +than allowed by Linux (some HBAs have max_segments as low as 128), +introduce a separate entry in BlockLimits to hold the max_segments +value from sysfs. This new limit is used only for SG_IO and clamped +to bs->bl.max_iov anyway, just like max_hw_transfer is clamped to +bs->bl.max_transfer. + +Reported-by: Halil Pasic +Cc: Hanna Reitz +Cc: Kevin Wolf +Cc: qemu-block@nongnu.org +Cc: qemu-stable@nongnu.org +Fixes: 18473467d5 ("file-posix: try BLKSECTGET on block devices too, do not round to power of 2", 2021-06-25) +Signed-off-by: Paolo Bonzini +Message-Id: <20210923130436.1187591-1-pbonzini@redhat.com> +Signed-off-by: Kevin Wolf +--- + block/block-backend.c | 6 ++++++ + block/file-posix.c | 2 +- + block/io.c | 1 + + hw/scsi/scsi-generic.c | 2 +- + include/block/block_int.h | 7 +++++++ + include/sysemu/block-backend.h | 1 + + 6 files changed, 17 insertions(+), 2 deletions(-) + +diff --git a/block/block-backend.c b/block/block-backend.c +index 6140d133e2..ba2b5ebb10 100644 +--- a/block/block-backend.c ++++ b/block/block-backend.c +@@ -1986,6 +1986,12 @@ uint32_t blk_get_max_transfer(BlockBackend *blk) + return ROUND_DOWN(max, blk_get_request_alignment(blk)); + } + ++int blk_get_max_hw_iov(BlockBackend *blk) ++{ ++ return MIN_NON_ZERO(blk->root->bs->bl.max_hw_iov, ++ blk->root->bs->bl.max_iov); ++} ++ + int blk_get_max_iov(BlockBackend *blk) + { + return blk->root->bs->bl.max_iov; +diff --git a/block/file-posix.c b/block/file-posix.c +index c62e42743d..53be0bdc1b 100644 +--- a/block/file-posix.c ++++ b/block/file-posix.c +@@ -1273,7 +1273,7 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) + + ret = hdev_get_max_segments(s->fd, &st); + if (ret > 0) { +- bs->bl.max_iov = ret; ++ bs->bl.max_hw_iov = ret; + } + } + } +diff --git a/block/io.c b/block/io.c +index 18d345a87a..bb0a254def 100644 +--- a/block/io.c ++++ b/block/io.c +@@ -136,6 +136,7 @@ static void bdrv_merge_limits(BlockLimits *dst, const BlockLimits *src) + dst->min_mem_alignment = MAX(dst->min_mem_alignment, + src->min_mem_alignment); + dst->max_iov = MIN_NON_ZERO(dst->max_iov, src->max_iov); ++ dst->max_hw_iov = MIN_NON_ZERO(dst->max_hw_iov, src->max_hw_iov); + } + + typedef struct BdrvRefreshLimitsState { +diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c +index 665baf900e..0306ccc7b1 100644 +--- a/hw/scsi/scsi-generic.c ++++ b/hw/scsi/scsi-generic.c +@@ -180,7 +180,7 @@ static int scsi_handle_inquiry_reply(SCSIGenericReq *r, SCSIDevice *s, int len) + page = r->req.cmd.buf[2]; + if (page == 0xb0) { + uint64_t max_transfer = blk_get_max_hw_transfer(s->conf.blk); +- uint32_t max_iov = blk_get_max_iov(s->conf.blk); ++ uint32_t max_iov = blk_get_max_hw_iov(s->conf.blk); + + assert(max_transfer); + max_transfer = MIN_NON_ZERO(max_transfer, max_iov * qemu_real_host_page_size) +diff --git a/include/block/block_int.h b/include/block/block_int.h +index ffe86068d4..f4c75e8ba9 100644 +--- a/include/block/block_int.h ++++ b/include/block/block_int.h +@@ -718,6 +718,13 @@ typedef struct BlockLimits { + */ + uint64_t max_hw_transfer; + ++ /* Maximal number of scatter/gather elements allowed by the hardware. ++ * Applies whenever transfers to the device bypass the kernel I/O ++ * scheduler, for example with SG_IO. If larger than max_iov ++ * or if zero, blk_get_max_hw_iov will fall back to max_iov. ++ */ ++ int max_hw_iov; ++ + /* memory alignment, in bytes so that no bounce buffer is needed */ + size_t min_mem_alignment; + +diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h +index 29d4fdbf63..82bae55161 100644 +--- a/include/sysemu/block-backend.h ++++ b/include/sysemu/block-backend.h +@@ -211,6 +211,7 @@ uint32_t blk_get_request_alignment(BlockBackend *blk); + uint32_t blk_get_max_transfer(BlockBackend *blk); + uint64_t blk_get_max_hw_transfer(BlockBackend *blk); + int blk_get_max_iov(BlockBackend *blk); ++int blk_get_max_hw_iov(BlockBackend *blk); + void blk_set_guest_block_size(BlockBackend *blk, int align); + void *blk_try_blockalign(BlockBackend *blk, size_t size); + void *blk_blockalign(BlockBackend *blk, size_t size); +-- +2.30.2 + diff --git a/debian/patches/series b/debian/patches/series index 92bcf10..d953c4f 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -5,6 +5,7 @@ extra/0004-monitor-refactor-set-expire_password-and-allow-VNC-d.patch extra/0005-monitor-hmp-correctly-invert-password-argument-detec.patch extra/0006-qxl-fix-pre-save-logic.patch extra/0007-block-mirror-fix-NULL-pointer-dereference-in-mirror_.patch +extra/0008-block-introduce-max_hw_iov-for-use-in-scsi-generic.patch bitmap-mirror/0001-drive-mirror-add-support-for-sync-bitmap-mode-never.patch bitmap-mirror/0002-drive-mirror-add-support-for-conditional-and-always-.patch bitmap-mirror/0003-mirror-add-check-for-bitmap-mode-without-bitmap.patch -- 2.30.2