From nobody Fri May 3 03:23:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1576851616; cv=none; d=zohomail.com; s=zohoarc; b=FNvqFHj0U6uoZuhGVHQJydk45iQCFouj+CIkpWaVJcyASByzTuwy2cHXz3aaDwSs2CcYdBi/BbKCwd3z8T8DDZs1ZkatlcIHx3+aUt20HLmjSLTHWJPCPg0oxkNRqfaYmavMT3b2Gz0fQ/zrOUihOCT2ZK8Dv4xpINcgBWnx73Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576851616; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=vvoiA6BiLE5p4wqKJNQu/CknS0qEnknCMyVVCPCLJ1M=; b=DtWkhPr3u6LnT/Vn4Q2Qi242VrXSQXGd+z2sU3ySsXiH/U00aMIpbWFKmD2JvsnflDL6pLa8eHozbIw8jkxyduXzewd1dUyA3O8V4Rd7rpj8qJBZbBxQ1TWgWrmYd+TLjclgih3wuuhreEtIiHRIvnHTvcQT/ee5WquYkXg/zW0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576851616365279.17421908527876; Fri, 20 Dec 2019 06:20:16 -0800 (PST) Received: from localhost ([::1]:56806 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiJ8Y-00036i-OA for importer@patchew.org; Fri, 20 Dec 2019 09:20:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43458) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiIuE-0006Oh-K2 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 09:05:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiIuC-000242-LX for qemu-devel@nongnu.org; Fri, 20 Dec 2019 09:05:26 -0500 Received: from relay.sw.ru ([185.231.240.75]:58170) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iiIuC-0001qr-3F for qemu-devel@nongnu.org; Fri, 20 Dec 2019 09:05:24 -0500 Received: from dptest2.qa.sw.ru ([10.94.4.71]) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iiIte-0007S2-F4; Fri, 20 Dec 2019 17:04:50 +0300 From: Denis Plotnikov To: qemu-devel@nongnu.org Subject: [PATCH v5 1/2] virtio: make seg_max virtqueue size dependent Date: Fri, 20 Dec 2019 17:04:42 +0300 Message-Id: <20191220140443.1399-2-dplotnikov@virtuozzo.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20191220140443.1399-1-dplotnikov@virtuozzo.com> References: <20191220140443.1399-1-dplotnikov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, ehabkost@redhat.com, kwolf@radhat.com, mreitz@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, mst@radhat.com, den@virtuozzo.com 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" Before the patch, seg_max parameter was immutable and hardcoded to 126 (128 - 2) without respect to queue size. This has two negative effec= ts: 1. when queue size is < 128, we have Virtio 1.1 specfication violation: (2.6.5.3.1 Driver Requirements) seq_max must be <=3D queue_size. This violation affects the old Linux guests (ver < 4.14). These guests crash on these queue_size setups. 2. when queue_size > 128, as was pointed out by Denis Lunev , seg_max restrics guest's block request length which affects guests' performance making them issues more block request than needed. https://lists.gnu.org/archive/html/qemu-devel/2017-12/msg03721.html To mitigate this two effects, the patch adds the property adjusting seg_max to queue size automaticaly. Since seg_max is a guest visible parameter, the property is machine type managable and allows to choose between old (seg_max =3D 126 always) and new (seg_max =3D queue_size - 2) behaviors. Not to change the behavior of the older VMs, prevent setting the default seg_max_adjust value for older machine types. Reviewed-by: Stefan Hajnoczi Signed-off-by: Denis Plotnikov --- hw/block/virtio-blk.c | 9 ++++++++- hw/core/machine.c | 3 +++ hw/scsi/vhost-scsi.c | 2 ++ hw/scsi/virtio-scsi.c | 10 +++++++++- include/hw/virtio/virtio-blk.h | 1 + include/hw/virtio/virtio-scsi.h | 1 + 6 files changed, 24 insertions(+), 2 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index d62e6377c2..0f6f8113b7 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -908,7 +908,8 @@ static void virtio_blk_update_config(VirtIODevice *vdev= , uint8_t *config) blk_get_geometry(s->blk, &capacity); memset(&blkcfg, 0, sizeof(blkcfg)); virtio_stq_p(vdev, &blkcfg.capacity, capacity); - virtio_stl_p(vdev, &blkcfg.seg_max, 128 - 2); + virtio_stl_p(vdev, &blkcfg.seg_max, + s->conf.seg_max_adjust ? s->conf.queue_size - 2 : 128 - 2= ); virtio_stw_p(vdev, &blkcfg.geometry.cylinders, conf->cyls); virtio_stl_p(vdev, &blkcfg.blk_size, blk_size); virtio_stw_p(vdev, &blkcfg.min_io_size, conf->min_io_size / blk_size); @@ -1133,6 +1134,11 @@ static void virtio_blk_device_realize(DeviceState *d= ev, Error **errp) error_setg(errp, "num-queues property must be larger than 0"); return; } + if (conf->queue_size <=3D 2) { + error_setg(errp, "invalid queue-size property (%" PRIu16 "), " + "must be > 2", conf->queue_size); + return; + } if (!is_power_of_2(conf->queue_size) || conf->queue_size > VIRTQUEUE_MAX_SIZE) { error_setg(errp, "invalid queue-size property (%" PRIu16 "), " @@ -1262,6 +1268,7 @@ static Property virtio_blk_properties[] =3D { true), DEFINE_PROP_UINT16("num-queues", VirtIOBlock, conf.num_queues, 1), DEFINE_PROP_UINT16("queue-size", VirtIOBlock, conf.queue_size, 128), + DEFINE_PROP_BOOL("seg-max-adjust", VirtIOBlock, conf.seg_max_adjust, t= rue), DEFINE_PROP_LINK("iothread", VirtIOBlock, conf.iothread, TYPE_IOTHREAD, IOThread *), DEFINE_PROP_BIT64("discard", VirtIOBlock, host_features, diff --git a/hw/core/machine.c b/hw/core/machine.c index 023548b4f3..bfa320387e 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -29,6 +29,9 @@ =20 GlobalProperty hw_compat_4_2[] =3D { { "virtio-blk-device", "x-enable-wce-if-config-wce", "off" }, + { "virtio-blk-device", "seg-max-adjust", "off"}, + { "virtio-scsi-device", "seg_max_adjust", "off"}, + { "vhost-blk-device", "seg_max_adjust", "off"}, }; const size_t hw_compat_4_2_len =3D G_N_ELEMENTS(hw_compat_4_2); =20 diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c index c693fc748a..26f710d3ec 100644 --- a/hw/scsi/vhost-scsi.c +++ b/hw/scsi/vhost-scsi.c @@ -275,6 +275,8 @@ static Property vhost_scsi_properties[] =3D { DEFINE_PROP_UINT32("num_queues", VirtIOSCSICommon, conf.num_queues, 1), DEFINE_PROP_UINT32("virtqueue_size", VirtIOSCSICommon, conf.virtqueue_= size, 128), + DEFINE_PROP_BOOL("seg_max_adjust", VirtIOSCSICommon, conf.seg_max_adju= st, + true), DEFINE_PROP_UINT32("max_sectors", VirtIOSCSICommon, conf.max_sectors, 0xFFFF), DEFINE_PROP_UINT32("cmd_per_lun", VirtIOSCSICommon, conf.cmd_per_lun, = 128), diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index e8b2b64d09..405cb6c953 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -654,7 +654,8 @@ static void virtio_scsi_get_config(VirtIODevice *vdev, VirtIOSCSICommon *s =3D VIRTIO_SCSI_COMMON(vdev); =20 virtio_stl_p(vdev, &scsiconf->num_queues, s->conf.num_queues); - virtio_stl_p(vdev, &scsiconf->seg_max, 128 - 2); + virtio_stl_p(vdev, &scsiconf->seg_max, + s->conf.seg_max_adjust ? s->conf.virtqueue_size - 2 : 128= - 2); virtio_stl_p(vdev, &scsiconf->max_sectors, s->conf.max_sectors); virtio_stl_p(vdev, &scsiconf->cmd_per_lun, s->conf.cmd_per_lun); virtio_stl_p(vdev, &scsiconf->event_info_size, sizeof(VirtIOSCSIEvent)= ); @@ -893,6 +894,11 @@ void virtio_scsi_common_realize(DeviceState *dev, virtio_cleanup(vdev); return; } + if (s->conf.virtqueue_size <=3D 2) { + error_setg(errp, "invalid virtqueue_size property (=3D %" PRIu16 "= ), " + "must be > 2", s->conf.virtqueue_size); + return; + } s->cmd_vqs =3D g_new0(VirtQueue *, s->conf.num_queues); s->sense_size =3D VIRTIO_SCSI_SENSE_DEFAULT_SIZE; s->cdb_size =3D VIRTIO_SCSI_CDB_DEFAULT_SIZE; @@ -949,6 +955,8 @@ static Property virtio_scsi_properties[] =3D { DEFINE_PROP_UINT32("num_queues", VirtIOSCSI, parent_obj.conf.num_queue= s, 1), DEFINE_PROP_UINT32("virtqueue_size", VirtIOSCSI, parent_obj.conf.virtqueue_size, 1= 28), + DEFINE_PROP_BOOL("seg_max_adjust", VirtIOSCSI, + parent_obj.conf.seg_max_adjust, true), DEFINE_PROP_UINT32("max_sectors", VirtIOSCSI, parent_obj.conf.max_sect= ors, 0xFFFF), DEFINE_PROP_UINT32("cmd_per_lun", VirtIOSCSI, parent_obj.conf.cmd_per_= lun, diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index 9c19f5b634..1e62f869b2 100644 --- a/include/hw/virtio/virtio-blk.h +++ b/include/hw/virtio/virtio-blk.h @@ -38,6 +38,7 @@ struct VirtIOBlkConf uint32_t request_merging; uint16_t num_queues; uint16_t queue_size; + bool seg_max_adjust; uint32_t max_discard_sectors; uint32_t max_write_zeroes_sectors; bool x_enable_wce_if_config_wce; diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scs= i.h index 122f7c4b6f..24e768909d 100644 --- a/include/hw/virtio/virtio-scsi.h +++ b/include/hw/virtio/virtio-scsi.h @@ -48,6 +48,7 @@ typedef struct virtio_scsi_config VirtIOSCSIConfig; struct VirtIOSCSIConf { uint32_t num_queues; uint32_t virtqueue_size; + bool seg_max_adjust; uint32_t max_sectors; uint32_t cmd_per_lun; #ifdef CONFIG_VHOST_SCSI --=20 2.17.0 From nobody Fri May 3 03:23:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1576852076; cv=none; d=zohomail.com; s=zohoarc; b=FNKujQnnYFxYJHQ3+sjHA9UApjuSPt6WErIoy9lY1GJWJMo2A70ps9VB3zHPuAyGdkLhs+sXMmNTg1hz6kgCtTMU4hojsH5NaqlPtKgyn6gGOxiQTD7Lkc7Mb9KvKOajeUHrdSCClCosM+jgeC+fklbg0IkXEgge3TXNeuFZ+gM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576852076; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=bjRLJwTsJjd/qtdtAB2TQNmWidB8Z2yWQdAQkg7gpd0=; b=Tvqj6IbLNwjbkxBv2oWcPSe6EHhzgp+uhkgONjrOlLEc4mwGqT2yT4SjU90FtQ9mGaEi0hVKIUrYCYpFuu5/FlSm02od7zKw1xKQ16ivpHbLRtx36UPYmZ9XoGWzUYqtpxC6Xn0g+bH+99gl+RCqbSWDbUNukEx6yp4QLAhEsIw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576852076525954.4634209119088; Fri, 20 Dec 2019 06:27:56 -0800 (PST) Received: from localhost ([::1]:57098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiJFx-0005bD-4j for importer@patchew.org; Fri, 20 Dec 2019 09:27:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43469) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiIuE-0006Om-MO for qemu-devel@nongnu.org; Fri, 20 Dec 2019 09:05:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiIuC-00023e-J2 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 09:05:26 -0500 Received: from relay.sw.ru ([185.231.240.75]:58172) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iiIuC-0001qs-39 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 09:05:24 -0500 Received: from dptest2.qa.sw.ru ([10.94.4.71]) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iiIte-0007S2-Mh; Fri, 20 Dec 2019 17:04:50 +0300 From: Denis Plotnikov To: qemu-devel@nongnu.org Subject: [PATCH v5 2/2] tests: add virtio-scsi and virtio-blk seg_max_adjust test Date: Fri, 20 Dec 2019 17:04:43 +0300 Message-Id: <20191220140443.1399-3-dplotnikov@virtuozzo.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20191220140443.1399-1-dplotnikov@virtuozzo.com> References: <20191220140443.1399-1-dplotnikov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, ehabkost@redhat.com, kwolf@radhat.com, mreitz@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, mst@radhat.com, den@virtuozzo.com 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" It tests proper seg_max_adjust settings for all machine types except 'none', 'isapc', 'microvm' Signed-off-by: Denis Plotnikov --- tests/acceptance/virtio_seg_max_adjust.py | 134 ++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100755 tests/acceptance/virtio_seg_max_adjust.py diff --git a/tests/acceptance/virtio_seg_max_adjust.py b/tests/acceptance/v= irtio_seg_max_adjust.py new file mode 100755 index 0000000000..5458573138 --- /dev/null +++ b/tests/acceptance/virtio_seg_max_adjust.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python +# +# Test virtio-scsi and virtio-blk queue settings for all machine types +# +# Copyright (c) 2019 Virtuozzo International GmbH +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import sys +import os +import re + +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'pytho= n')) +from qemu.machine import QEMUMachine +from avocado_qemu import Test + +#list of machine types and virtqueue properties to test +VIRTIO_SCSI_PROPS =3D {'seg_max_adjust': 'seg_max_adjust'} +VIRTIO_BLK_PROPS =3D {'seg_max_adjust': 'seg-max-adjust'} + +DEV_TYPES =3D {'virtio-scsi-pci': VIRTIO_SCSI_PROPS, + 'virtio-blk-pci': VIRTIO_BLK_PROPS} + +VM_DEV_PARAMS =3D {'virtio-scsi-pci': ['-device', 'virtio-scsi-pci,id=3Dsc= si0'], + 'virtio-blk-pci': ['-device', + 'virtio-blk-pci,id=3Dscsi0,drive=3Ddri= ve0', + '-drive', + 'driver=3Dnull-co,id=3Ddrive0,if=3Dnon= e']} + + +class VirtioMaxSegSettingsCheck(Test): + @staticmethod + def make_pattern(props): + pattern_items =3D ['{0} =3D \w+'.format(prop) for prop in props] + return '|'.join(pattern_items) + + def query_virtqueue(self, vm, dev_type_name): + query_ok =3D False + error =3D None + props =3D None + + output =3D vm.command('human-monitor-command', + command_line =3D 'info qtree') + props_list =3D DEV_TYPES[dev_type_name].values(); + pattern =3D self.make_pattern(props_list) + res =3D re.findall(pattern, output) + + if len(res) !=3D len(props_list): + props_list =3D set(props_list) + res =3D set(res) + not_found =3D props_list.difference(res) + not_found =3D ', '.join(not_found) + error =3D '({0}): The following properties not found: {1}'\ + .format(dev_type_name, not_found) + else: + query_ok =3D True + props =3D dict() + for prop in res: + p =3D prop.split(' =3D ') + props[p[0]] =3D p[1] + return query_ok, props, error + + def check_mt(self, mt, dev_type_name): + with QEMUMachine(self.qemu_bin) as vm: + vm.set_machine(mt["name"]) + for s in VM_DEV_PARAMS[dev_type_name]: + vm.add_args(s) + vm.launch() + query_ok, props, error =3D self.query_virtqueue(vm, dev_type_n= ame) + + if not query_ok: + self.fail('machine type {0}: {1}'.format(mt['name'], error)) + + for prop_name, prop_val in props.items(): + expected_val =3D mt[prop_name] + self.assertEqual(expected_val, prop_val) + + @staticmethod + def seg_max_adjust_enabled(mt): + # machine types >=3D 5.0 should have seg_max_adjust =3D true + # others seg_max_adjust =3D false + mt =3D mt.split("-") + + # machine types with one line name and name like pc-x.x + if len(mt) <=3D 2: + return False + + # machine types like pc--x.x[.x] + ver =3D mt[2] + ver =3D ver.split("."); + + # versions >=3D 5.0 goes with seg_max_adjust enabled + major =3D int(ver[0]) + + if major >=3D 5: + return True + return False + + def test_machine_types(self): + # collect all machine types except 'none', 'isapc', 'microvm' + with QEMUMachine(self.qemu_bin) as vm: + vm.launch() + machines =3D [m['name'] for m in vm.command('query-machines')] + vm.shutdown() + machines.remove('none') + machines.remove('isapc') + machines.remove('microvm') + + for dev_type in DEV_TYPES: + # create the list of machine types and their parameters. + mtypes =3D list() + for m in machines: + if self.seg_max_adjust_enabled(m): + enabled =3D 'true' + else: + enabled =3D 'false' + mtypes.append({'name': m, + DEV_TYPES[dev_type]['seg_max_adjust']: enab= led}) + + # test each machine type for a device type + for mt in mtypes: + self.check_mt(mt, dev_type) --=20 2.17.0