From nobody Mon May 6 07:06:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1572970465; cv=none; d=zoho.com; s=zohoarc; b=Ze01T6U+Qzb7zy9wuGLvsmUYsrVRwgDQ2bazqdOju9WnZk4ACvC1MpspkQhyLudnngiiV2jyVzRvZh1zGMJvR6a1HFJvSoff2Hjz+zP5cYE2sYz6sNdgsa3man4qnTvondkOPhfj94rxLV4fPUL5EyGPS07Sbl7BE4hbWrUcuLw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572970465; 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=nwEMrnwaknfNDltCl6J18vsSxPQwiF52kX4a7gZqzp8=; b=dzdTJIFKDo+6pHpf06CSuVbh27zEf8TCbCPKBVMXPqzQwbigcHP/EZaRQlnqvMv8srUbR0m0gi8ILsTJayJ9J+KchmFEjXGUOBbo5gS38EXTlOl6enZTfBPNikbhEjqONzbMicpFh3B+NjrDVi9WcK4wzSLFWhXOUL/q8BA8MGE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; 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 1572970465597858.6606848114619; Tue, 5 Nov 2019 08:14:25 -0800 (PST) Received: from localhost ([::1]:45846 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iS1TJ-00076P-2Z for importer@patchew.org; Tue, 05 Nov 2019 11:14:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52787) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iS1QJ-0005Y7-NF for qemu-devel@nongnu.org; Tue, 05 Nov 2019 11:11:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iS1QI-0002uz-DU for qemu-devel@nongnu.org; Tue, 05 Nov 2019 11:11:15 -0500 Received: from relay.sw.ru ([185.231.240.75]:43440) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iS1QI-0002os-5z; Tue, 05 Nov 2019 11:11:14 -0500 Received: from [10.94.4.71] (helo=dptest2.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iS1Q9-0000Xh-PU; Tue, 05 Nov 2019 19:11:05 +0300 From: Denis Plotnikov To: qemu-devel@nongnu.org Subject: [PATCH v1 1/4] virtio: protect non-modern devices from too big virtqueue size setting Date: Tue, 5 Nov 2019 19:11:02 +0300 Message-Id: <20191105161105.19016-2-dplotnikov@virtuozzo.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20191105161105.19016-1-dplotnikov@virtuozzo.com> References: <20191105161105.19016-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, kwolf@redhat.com, ehabkost@redhat.com, qemu-block@nongnu.org, mst@redhat.com, stefanha@redhat.com, mreitz@redhat.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" The patch protects from creating illegal virtio device configuration via direct virtqueue size property setting. Signed-off-by: Denis Plotnikov --- hw/virtio/virtio-blk-pci.c | 9 +++++++++ hw/virtio/virtio-scsi-pci.c | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/hw/virtio/virtio-blk-pci.c b/hw/virtio/virtio-blk-pci.c index 60c9185c39..6177ff1df8 100644 --- a/hw/virtio/virtio-blk-pci.c +++ b/hw/virtio/virtio-blk-pci.c @@ -48,6 +48,15 @@ static void virtio_blk_pci_realize(VirtIOPCIProxy *vpci_= dev, Error **errp) { VirtIOBlkPCI *dev =3D VIRTIO_BLK_PCI(vpci_dev); DeviceState *vdev =3D DEVICE(&dev->vdev); + bool modern =3D virtio_pci_modern(vpci_dev); + uint32_t queue_size =3D dev->vdev.conf.queue_size; + + if (!modern && queue_size > 128) { + error_setg(errp, + "too big queue size (%u, max: 128) " + "for non-modern virtio device", queue_size); + return; + } =20 if (vpci_dev->nvectors =3D=3D DEV_NVECTORS_UNSPECIFIED) { vpci_dev->nvectors =3D dev->vdev.conf.num_queues + 1; diff --git a/hw/virtio/virtio-scsi-pci.c b/hw/virtio/virtio-scsi-pci.c index 2830849729..6e6790fda5 100644 --- a/hw/virtio/virtio-scsi-pci.c +++ b/hw/virtio/virtio-scsi-pci.c @@ -17,6 +17,7 @@ =20 #include "hw/virtio/virtio-scsi.h" #include "virtio-pci.h" +#include "qapi/error.h" =20 typedef struct VirtIOSCSIPCI VirtIOSCSIPCI; =20 @@ -47,6 +48,15 @@ static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpci= _dev, Error **errp) VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(vdev); DeviceState *proxy =3D DEVICE(vpci_dev); char *bus_name; + bool modern =3D virtio_pci_modern(vpci_dev); + uint32_t virtqueue_size =3D vs->conf.virtqueue_size; + + if (!modern && virtqueue_size > 128) { + error_setg(errp, + "too big virtqueue size (%u, max: 128) " + "for non-modern virtio device", virtqueue_size); + return; + } =20 if (vpci_dev->nvectors =3D=3D DEV_NVECTORS_UNSPECIFIED) { vpci_dev->nvectors =3D vs->conf.num_queues + 3; --=20 2.17.0 From nobody Mon May 6 07:06:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1572970615; cv=none; d=zoho.com; s=zohoarc; b=AXRqBlQ3wOhJIVR7ydLOqwyD0tbCnl94powIvgwFR1fR6CvPPr+Lh7scEK0D8LhxIhYOWezUCBy7sXVhoqmMk+ZiFtxCyNgo0cgveK7gsO3j1erUAakOGvYxePThuc1a5b+DufgvJlwOa26P0g9wtElmBFgKHDs4zCqLO1sE/38= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572970615; 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=MZaTF65SZXC+GLCy9YUsOqmaPZ4n7AG4O/BnBUTe0BI=; b=k2FGdlxtgoZMjnc1+9Q8OoUehD45V6RXT0e2yfC61NaQppRBXid8aJuL44/zTcoEhkz2ySRkSLQGfuOZ0+RsQrWQIKFCqz09LO1RL03tk16nsQFaVasmRx5sIOOOOx9/V6bZS8yh5hnaQPeNeK4XOR+7Qo4AWXLa1e9r2gi8qOA= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; 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 1572970615153903.6415276641591; Tue, 5 Nov 2019 08:16:55 -0800 (PST) Received: from localhost ([::1]:45884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iS1Vm-0001Jg-58 for importer@patchew.org; Tue, 05 Nov 2019 11:16:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52786) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iS1QJ-0005Y6-Nq for qemu-devel@nongnu.org; Tue, 05 Nov 2019 11:11:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iS1QI-0002un-CB for qemu-devel@nongnu.org; Tue, 05 Nov 2019 11:11:15 -0500 Received: from relay.sw.ru ([185.231.240.75]:43434) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iS1QI-0002or-4V; Tue, 05 Nov 2019 11:11:14 -0500 Received: from [10.94.4.71] (helo=dptest2.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iS1Q9-0000Xh-W2; Tue, 05 Nov 2019 19:11:06 +0300 From: Denis Plotnikov To: qemu-devel@nongnu.org Subject: [PATCH v1 2/4] virtio: make seg_max virtqueue size dependent Date: Tue, 5 Nov 2019 19:11:03 +0300 Message-Id: <20191105161105.19016-3-dplotnikov@virtuozzo.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20191105161105.19016-1-dplotnikov@virtuozzo.com> References: <20191105161105.19016-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, kwolf@redhat.com, ehabkost@redhat.com, qemu-block@nongnu.org, mst@redhat.com, stefanha@redhat.com, mreitz@redhat.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" seg_max has a restriction to be less or equal to virtqueue size according to Virtio 1.0 specification Although seg_max can't be set directly, it's worth to express this dependancy directly in the code for sanity purpose. Signed-off-by: Denis Plotnikov --- hw/block/virtio-blk.c | 2 +- hw/scsi/virtio-scsi.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 06e57a4d39..21530304cf 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -903,7 +903,7 @@ 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.queue_size - 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); diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 839f120256..f7e5533cd5 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -650,7 +650,7 @@ 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.virtqueue_size - 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)= ); --=20 2.17.0 From nobody Mon May 6 07:06:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1572970466; cv=none; d=zoho.com; s=zohoarc; b=lnzE4UgJoSrq2FsF5vyNkFUyGIZtTbtP4nXvVBULFX9InlwShK436YGorBu32FSUlB+h9ROlWJsqGqXk7OsQIZDX1nyV62hqobtcXWB2GyyHTyFhPOzv/kP8vqHatcRJjRCdbQVgAvFfn/XHEcbKjBFLQ1RCnUMojLAw9SHUfNQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572970466; 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=Vmvb88jyXopiUlRXOklRBG9MiAfB4Ixqyr6urNaSHjU=; b=lji/CcESSOg1w3QyenVIyuPMxb8WbT+KwTHcnCDFAPMnFWkQ1bJgPyXU7kngnew16fqIDm9O4+WOToPWz/xYjmScJ1HCupEomNFVJoPrewbiYwpLa/tYLzbXrRqBfnq8J9K5SyUWM8/lfWPCreSCMdNsFP7nr7pLVhtpptgjXRU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; 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 1572970466695398.0142699825574; Tue, 5 Nov 2019 08:14:26 -0800 (PST) Received: from localhost ([::1]:45850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iS1TL-0007Dp-NC for importer@patchew.org; Tue, 05 Nov 2019 11:14:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52831) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iS1QN-0005YR-CS for qemu-devel@nongnu.org; Tue, 05 Nov 2019 11:11:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iS1QJ-0002vS-Ab for qemu-devel@nongnu.org; Tue, 05 Nov 2019 11:11:19 -0500 Received: from relay.sw.ru ([185.231.240.75]:43452) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iS1QI-0002ov-9F; Tue, 05 Nov 2019 11:11:14 -0500 Received: from [10.94.4.71] (helo=dptest2.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iS1QA-0000Xh-2V; Tue, 05 Nov 2019 19:11:06 +0300 From: Denis Plotnikov To: qemu-devel@nongnu.org Subject: [PATCH v1 3/4] virtio: increase virtuqueue sizes in new machine types Date: Tue, 5 Nov 2019 19:11:04 +0300 Message-Id: <20191105161105.19016-4-dplotnikov@virtuozzo.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20191105161105.19016-1-dplotnikov@virtuozzo.com> References: <20191105161105.19016-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, kwolf@redhat.com, ehabkost@redhat.com, qemu-block@nongnu.org, mst@redhat.com, stefanha@redhat.com, mreitz@redhat.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" Linux guests submit IO requests no longer than PAGE_SIZE * max_seg field reported by SCSI controler. Thus typical sequential read with 1 MB size results in the following pattern of the IO from the guest: 8,16 1 15754 2.766095122 2071 D R 2095104 + 1008 [dd] 8,16 1 15755 2.766108785 2071 D R 2096112 + 1008 [dd] 8,16 1 15756 2.766113486 2071 D R 2097120 + 32 [dd] 8,16 1 15757 2.767668961 0 C R 2095104 + 1008 [0] 8,16 1 15758 2.768534315 0 C R 2096112 + 1008 [0] 8,16 1 15759 2.768539782 0 C R 2097120 + 32 [0] The IO was generated by dd if=3D/dev/sda of=3D/dev/null bs=3D1024 iflag=3Ddirect This effectively means that on rotational disks we will observe 3 IOPS for each 2 MBs processed. This definitely negatively affects both guest and host IO performance. The cure is relatively simple - we should report lengthy scatter-gather ability of the SCSI controller. Fortunately the situation here is very good. VirtIO transport layer can accomodate 1024 items in one request while we are using only 128. This situation is present since almost very beginning. 2 items are dedicated for request metadata thus we should publish VIRTQUEUE_MAX_SIZE - 2 as max_seg. The following pattern is observed after the patch: 8,16 1 9921 2.662721340 2063 D R 2095104 + 1024 [dd] 8,16 1 9922 2.662737585 2063 D R 2096128 + 1024 [dd] 8,16 1 9923 2.665188167 0 C R 2095104 + 1024 [0] 8,16 1 9924 2.665198777 0 C R 2096128 + 1024 [0] which is much better. To fix this particular case, the patch adds new machine types with extended virtqueue sizes to 256 which also increases max_seg to 254 implicitly. Suggested-by: Denis V. Lunev Signed-off-by: Denis Plotnikov --- hw/core/machine.c | 14 ++++++++++++++ hw/i386/pc_piix.c | 16 +++++++++++++--- hw/i386/pc_q35.c | 14 ++++++++++++-- include/hw/boards.h | 6 ++++++ 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 55b08f1466..28013a0e3f 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -24,6 +24,13 @@ #include "hw/pci/pci.h" #include "hw/mem/nvdimm.h" =20 +GlobalProperty hw_compat_4_0_1[] =3D { + { "virtio-blk-device", "queue-size", "128" }, + { "virtio-scsi-device", "virtqueue_size", "128" }, + { "vhost-scsi-device", "virtqueue_size", "128" }, +}; +const size_t hw_compat_4_0_1_len =3D G_N_ELEMENTS(hw_compat_4_0_1); + GlobalProperty hw_compat_4_0[] =3D { { "virtio-balloon-device", "qemu-4-0-config-size", "true" }, }; @@ -157,6 +164,13 @@ GlobalProperty hw_compat_2_1[] =3D { }; const size_t hw_compat_2_1_len =3D G_N_ELEMENTS(hw_compat_2_1); =20 +GlobalProperty hw_compat[] =3D { + { "virtio-blk-device", "queue-size", "256" }, + { "virtio-scsi-device", "virtqueue_size", "256" }, + { "vhost-scsi-device", "virtqueue_size", "256" }, +}; +const size_t hw_compat_len =3D G_N_ELEMENTS(hw_compat); + static char *machine_get_accel(Object *obj, Error **errp) { MachineState *ms =3D MACHINE(obj); diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 8ad8e885c6..2260a61b1b 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -426,15 +426,27 @@ static void pc_i440fx_machine_options(MachineClass *m) m->default_machine_opts =3D "firmware=3Dbios-256k.bin"; m->default_display =3D "std"; machine_class_allow_dynamic_sysbus_dev(m, TYPE_RAMFB_DEVICE); + compat_props_add(m->compat_props, hw_compat, hw_compat_len); } =20 -static void pc_i440fx_4_0_machine_options(MachineClass *m) +static void pc_i440fx_4_0_2_machine_options(MachineClass *m) { pc_i440fx_machine_options(m); m->alias =3D "pc"; m->is_default =3D 1; } =20 +DEFINE_I440FX_MACHINE(v4_0_2, "pc-i440fx-4.0.2", NULL, + pc_i440fx_4_0_2_machine_options); + +static void pc_i440fx_4_0_machine_options(MachineClass *m) +{ + pc_i440fx_4_0_2_machine_options(m); + m->alias =3D NULL; + m->is_default =3D 0; + compat_props_add(m->compat_props, hw_compat_4_0_1, hw_compat_4_0_1_len= ); +} + DEFINE_I440FX_MACHINE(v4_0, "pc-i440fx-4.0", NULL, pc_i440fx_4_0_machine_options); =20 @@ -443,9 +455,7 @@ static void pc_i440fx_3_1_machine_options(MachineClass = *m) PCMachineClass *pcmc =3D PC_MACHINE_CLASS(m); =20 pc_i440fx_4_0_machine_options(m); - m->is_default =3D 0; m->smbus_no_migration_support =3D true; - m->alias =3D NULL; pcmc->pvh_enabled =3D false; compat_props_add(m->compat_props, hw_compat_3_1, hw_compat_3_1_len); compat_props_add(m->compat_props, pc_compat_3_1, pc_compat_3_1_len); diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 45cc29d1ad..50ccd9ebcf 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -363,14 +363,25 @@ static void pc_q35_machine_options(MachineClass *m) machine_class_allow_dynamic_sysbus_dev(m, TYPE_INTEL_IOMMU_DEVICE); machine_class_allow_dynamic_sysbus_dev(m, TYPE_RAMFB_DEVICE); m->max_cpus =3D 288; + compat_props_add(m->compat_props, hw_compat, hw_compat_len); } =20 -static void pc_q35_4_0_1_machine_options(MachineClass *m) +static void pc_q35_4_0_2_machine_options(MachineClass *m) { pc_q35_machine_options(m); m->alias =3D "q35"; } =20 +DEFINE_Q35_MACHINE(v4_0_2, "pc-q35-4.0.2", NULL, + pc_q35_4_0_2_machine_options); + +static void pc_q35_4_0_1_machine_options(MachineClass *m) +{ + pc_q35_4_0_2_machine_options(m); + m->alias =3D NULL; + compat_props_add(m->compat_props, hw_compat_4_0_1, hw_compat_4_0_1_len= ); +} + DEFINE_Q35_MACHINE(v4_0_1, "pc-q35-4.0.1", NULL, pc_q35_4_0_1_machine_options); =20 @@ -378,7 +389,6 @@ static void pc_q35_4_0_machine_options(MachineClass *m) { pc_q35_4_0_1_machine_options(m); m->default_kernel_irqchip_split =3D true; - m->alias =3D NULL; compat_props_add(m->compat_props, hw_compat_4_0, hw_compat_4_0_len); compat_props_add(m->compat_props, pc_compat_4_0, pc_compat_4_0_len); } diff --git a/include/hw/boards.h b/include/hw/boards.h index fe1885cbff..cf10632dac 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -293,6 +293,9 @@ struct MachineState { } \ type_init(machine_initfn##_register_types) =20 +extern GlobalProperty hw_compat_4_0_1[]; +extern const size_t hw_compat_4_0_1_len; + extern GlobalProperty hw_compat_4_0[]; extern const size_t hw_compat_4_0_len; =20 @@ -338,4 +341,7 @@ extern const size_t hw_compat_2_2_len; extern GlobalProperty hw_compat_2_1[]; extern const size_t hw_compat_2_1_len; =20 +extern GlobalProperty hw_compat[]; +extern const size_t hw_compat_len; + #endif --=20 2.17.0 From nobody Mon May 6 07:06:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1572970691; cv=none; d=zoho.com; s=zohoarc; b=LlEzXHIxi7QrmNhS7B4gR2MIN5ojNSVlbuC7cO9i5Op7URIKw3NUr1tTvWty3VBXInF3ZHP7aaxtFBDGT3DlJC5kiH/LJvJbqDiQkl55MQ3fUL4uoGlEvslhF3mIIwtLe0c2B9waJCuy2r6zDJyyb7GwNLu4SWkveRp24uwoPmE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572970691; 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=O73eNLCurjE2ehqjtTRvaBY2kuCioMReCLBlrOP2WVc=; b=lDgrQM5IlXK0pB4PI41Cmw08cCf7Yte/LUxYXd7iBSfkVJUL6KeU8ZCA7iQw/zItYkuMY3o9oWELtbHHKFHaSIWc3Mbq9tSgIe2Lii6DTgnko6UFDcn3M99s3vr01m690WkH6nXJKDI1NuTyB9gORFHWSXB7C1r88fF4H6yZzTw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; 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 1572970691297858.819211604729; Tue, 5 Nov 2019 08:18:11 -0800 (PST) Received: from localhost ([::1]:45894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iS1X0-0002La-Af for importer@patchew.org; Tue, 05 Nov 2019 11:18:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52828) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iS1QN-0005YP-34 for qemu-devel@nongnu.org; Tue, 05 Nov 2019 11:11:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iS1QJ-0002vY-Av for qemu-devel@nongnu.org; Tue, 05 Nov 2019 11:11:19 -0500 Received: from relay.sw.ru ([185.231.240.75]:43446) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iS1QI-0002ot-9u; Tue, 05 Nov 2019 11:11:14 -0500 Received: from [10.94.4.71] (helo=dptest2.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iS1QA-0000Xh-61; Tue, 05 Nov 2019 19:11:06 +0300 From: Denis Plotnikov To: qemu-devel@nongnu.org Subject: [PATCH v1 4/4] iotests: add test for virtio-scsi and virtio-blk machine type settings Date: Tue, 5 Nov 2019 19:11:05 +0300 Message-Id: <20191105161105.19016-5-dplotnikov@virtuozzo.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20191105161105.19016-1-dplotnikov@virtuozzo.com> References: <20191105161105.19016-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, kwolf@redhat.com, ehabkost@redhat.com, qemu-block@nongnu.org, mst@redhat.com, stefanha@redhat.com, mreitz@redhat.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 queue size settings for all available machine types. Signed-off-by: Denis Plotnikov Reviewed-by: Stefan Hajnoczi --- tests/qemu-iotests/267 | 154 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/267.out | 1 + tests/qemu-iotests/group | 1 + 3 files changed, 156 insertions(+) create mode 100755 tests/qemu-iotests/267 create mode 100644 tests/qemu-iotests/267.out diff --git a/tests/qemu-iotests/267 b/tests/qemu-iotests/267 new file mode 100755 index 0000000000..6d3cc574b3 --- /dev/null +++ b/tests/qemu-iotests/267 @@ -0,0 +1,154 @@ +#!/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 +import iotests + +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'scrip= ts')) +import qemu + +# list of device types and virtqueue properties to test +# this is a generalized approach +# for now we just check queue length +# more properties can be added in each list +virtio_scsi_props =3D {'vq_size': 'virtqueue_size'} +virtio_blk_props =3D {'vq_size': 'queue-size'} + +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']} + +def make_pattern(props): + pattern_items =3D ['{0} =3D \d+'.format(prop) for prop in props] + return '|'.join(pattern_items) + + +def query_virtqueue_props(vm, dev_type_name): + output =3D vm.qmp('human-monitor-command', command_line=3D'info qtree') + output =3D output['return'] + + props_list =3D dev_types[dev_type_name].values(); + + pattern =3D make_pattern(props_list) + + res =3D re.findall(pattern, output) + + if len(res) !=3D len(props_list): + not_found =3D props_list.difference(set(res)) + + ret =3D (0, '({0}): The following properties not found: {1}' + .format(dev_type_name, ', '.join(not_found))) + else: + props =3D dict() + for prop in res: + p =3D prop.split(' =3D ') + props[p[0]] =3D int(p[1]) + ret =3D (1, props) + + return ret + + +def check_mt(mt, dev_type_name): + vm_params =3D ['-machine', mt['name']] + vm_dev_params[dev_type_name] + + vm =3D qemu.QEMUMachine(iotests.qemu_prog, vm_params) + vm.launch() + ret =3D query_virtqueue_props(vm, dev_type_name) + vm.shutdown() + + if ret[0] =3D=3D 0: + print('Error ({0}): {1}'.format(mt['name'], ret[1])) + return 1 + + errors =3D 0 + props =3D ret[1] + + for prop_name, prop_val in props.items(): + if mt[prop_name] !=3D prop_val: + print('Error [{0}, {1}]: {2}=3D{3} (expected {4})'. + format(mt['name'], dev_type_name, prop_name, prop_val, + mt[prop_name])) + errors +=3D 1 + + return errors + +def is_256_virtqueue_size_mt(mt): + mt =3D mt.split("-") + + # machine types like pc-x.x + if len(mt) =3D=3D 2: + return False + + # machine types like pc--x.x[.x] + ver =3D mt[2] + + ver =3D ver.split("."); + + # all versions greater than 4.0.1 goes with 256 queue size + if int(ver[0]) >=3D 4: + major =3D int(ver[1]) + minor =3D 0 + if len(ver) > 2: + minor =3D int(ver[2]) + + if major > 0 or minor > 1: + return True + + return False + + +# collect all machine types except 'none' +vm =3D iotests.VM() +vm.launch() +machines =3D [m['name'] for m in vm.qmp('query-machines')['return']] +vm.shutdown() +machines.remove('none') +machines.remove('isapc') + +failed =3D 0 + +for dev_type in dev_types: + # create a list of machine types and their parameters + # machine types vz8.X.X must have virtqueue_length=3D256 + # others must have virtqueue_length=3D128 + mtypes =3D list() + for m in machines: + if is_256_virtqueue_size_mt(m): + vq_size =3D 256 + else: + vq_size =3D 128 + + mtypes.append({'name': m, dev_types[dev_type]['vq_size']: vq_size}) + + # test each machine type + for mt in mtypes: + failed +=3D check_mt(mt, dev_type) + +if failed > 0: + print('Failed') +else: + print('Success') diff --git a/tests/qemu-iotests/267.out b/tests/qemu-iotests/267.out new file mode 100644 index 0000000000..35821117c8 --- /dev/null +++ b/tests/qemu-iotests/267.out @@ -0,0 +1 @@ +Success diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 3605796bb2..ab8523ad60 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -252,3 +252,4 @@ 255 rw auto quick 256 rw auto quick 266 rw quick +267 auto quick --=20 2.17.0