From nobody Sun May 5 15:53:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 154202503400442.111405906566574; Mon, 12 Nov 2018 04:17:14 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C3B8F2D80F; Mon, 12 Nov 2018 12:17:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 473315D961; Mon, 12 Nov 2018 12:17:10 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DE3874BB74; Mon, 12 Nov 2018 12:17:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wACCFf4v005602 for ; Mon, 12 Nov 2018 07:15:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id 82AC85D982; Mon, 12 Nov 2018 12:15:41 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE3045D973; Mon, 12 Nov 2018 12:15:22 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Mon, 12 Nov 2018 13:14:55 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH 1/2] qemu: Extract MDEV VFIO PCI validation code into a separate helper X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 12 Nov 2018 12:17:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Since we'll need to validate other models apart from VFIO PCI too, having a helper for each model should keep the code base cleaner. Signed-off-by: Erik Skultety Reviewed-by: Boris Fiuczynski --- src/qemu/qemu_domain.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e25afdad6b..17d207513d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4564,11 +4564,11 @@ qemuDomainDeviceDefValidateNetwork(const virDomainN= etDef *net) =20 =20 static int -qemuDomainMdevDefValidate(const virDomainHostdevSubsysMediatedDev *mdevsrc, - const virDomainDef *def, - virQEMUCapsPtr qemuCaps) +qemuDomainMdevDefVFIOPCIValidate(const virDomainHostdevSubsysMediatedDev *= dev, + const virDomainDef *def, + virQEMUCapsPtr qemuCaps) { - if (mdevsrc->display =3D=3D VIR_TRISTATE_SWITCH_ABSENT) + if (dev->display =3D=3D VIR_TRISTATE_SWITCH_ABSENT) return 0; =20 if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VFIO_PCI_DISPLAY)) { @@ -4578,7 +4578,7 @@ qemuDomainMdevDefValidate(const virDomainHostdevSubsy= sMediatedDev *mdevsrc, return -1; } =20 - if (mdevsrc->model !=3D VIR_MDEV_MODEL_TYPE_VFIO_PCI) { + if (dev->model !=3D VIR_MDEV_MODEL_TYPE_VFIO_PCI) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _(" attribute 'display' is only supported" " with model=3D'vfio-pci'")); @@ -4586,7 +4586,7 @@ qemuDomainMdevDefValidate(const virDomainHostdevSubsy= sMediatedDev *mdevsrc, return -1; } =20 - if (mdevsrc->display =3D=3D VIR_TRISTATE_SWITCH_ON) { + if (dev->display =3D=3D VIR_TRISTATE_SWITCH_ON) { if (def->ngraphics =3D=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("graphics device is needed for attribute valu= e " @@ -4599,6 +4599,29 @@ qemuDomainMdevDefValidate(const virDomainHostdevSubs= ysMediatedDev *mdevsrc, } =20 =20 +static int +qemuDomainMdevDefValidate(const virDomainHostdevSubsysMediatedDev *mdevsrc, + const virDomainDef *def, + virQEMUCapsPtr qemuCaps) +{ + + switch ((virMediatedDeviceModelType) mdevsrc->model) { + case VIR_MDEV_MODEL_TYPE_VFIO_PCI: + return qemuDomainMdevDefVFIOPCIValidate(mdevsrc, def, qemuCaps); + case VIR_MDEV_MODEL_TYPE_VFIO_AP: + break; + case VIR_MDEV_MODEL_TYPE_VFIO_CCW: + break; + case VIR_MDEV_MODEL_TYPE_LAST: + virReportEnumRangeError(virMediatedDeviceModelType, + mdevsrc->model); + return -1; + } + + return 0; +} + + static int qemuDomainDeviceDefValidateHostdev(const virDomainHostdevDef *hostdev, const virDomainDef *def, --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 15:53:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 154202592840798.73733722745499; Mon, 12 Nov 2018 04:32:08 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 32C0A7AEA8; Mon, 12 Nov 2018 12:32:06 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9CB31600D7; Mon, 12 Nov 2018 12:32:05 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 20F91181A132; Mon, 12 Nov 2018 12:32:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wACCFgXX005610 for ; Mon, 12 Nov 2018 07:15:42 -0500 Received: by smtp.corp.redhat.com (Postfix) id E1A925D961; Mon, 12 Nov 2018 12:15:42 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id D05FA4ED8A; Mon, 12 Nov 2018 12:15:41 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Mon, 12 Nov 2018 13:14:56 +0100 Message-Id: <3e4e2ad5d3caff06fbf9ca93404eb76b53e7aa9c.1542024418.git.eskultet@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH 2/2] conf: Move VFIO AP validation from post parse to QEMU validation code X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 12 Nov 2018 12:32:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Even though commit 11708641 claims that a domain is allowed have a single VFIO AP hostdev only, this is a limitation posed by the platform vendor on purely virtual devices. Generally, post parse should only be used to populate some default values if missing or at least fail gracefully with VIR_DOMAIN_DEF_PARSE_ALLOW_POST_PARSE_FAIL). This patch more of an attempt to follow the guidelines for adding new features rather than a precaution measure, since even if vfio-ap supported multiple devices, one would have to downgrade libvirt for a machine to vanish from the list or in terms of future device migration to slightly older libvirt, there would be most probably a driver mismatch that would render the migration impossible anyway. Signed-off-by: Erik Skultety Reviewed-by: Boris Fiuczynski --- src/conf/domain_conf.c | 28 ---------------------------- src/qemu/qemu_domain.c | 28 +++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 237540bccc..e8e0adc819 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -4275,31 +4275,6 @@ virDomainDefPostParseGraphics(virDomainDef *def) } =20 =20 -static int -virDomainDefPostParseHostdev(virDomainDefPtr def) -{ - size_t i; - bool vfioap_found =3D false; - - /* verify settings of hostdevs vfio-ap */ - for (i =3D 0; i < def->nhostdevs; i++) { - virDomainHostdevDefPtr hostdev =3D def->hostdevs[i]; - - if (virHostdevIsMdevDevice(hostdev) && - hostdev->source.subsys.u.mdev.model =3D=3D VIR_MDEV_MODEL_TYPE= _VFIO_AP) { - if (vfioap_found) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Only one hostdev of model vfio-ap is " - "supported")); - return -1; - } - vfioap_found =3D true; - } - } - return 0; -} - - /** * virDomainDriveAddressIsUsedByDisk: * @def: domain definition containing the disks to check @@ -5210,9 +5185,6 @@ virDomainDefPostParseCommon(virDomainDefPtr def, =20 virDomainDefPostParseGraphics(def); =20 - if (virDomainDefPostParseHostdev(def) < 0) - return -1; - if (virDomainDefPostParseCPU(def) < 0) return -1; =20 diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 17d207513d..90253ae867 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4599,6 +4599,32 @@ qemuDomainMdevDefVFIOPCIValidate(const virDomainHost= devSubsysMediatedDev *dev, } =20 =20 +static int +qemuDomainMdevDefVFIOAPValidate(const virDomainDef *def) +{ + size_t i; + bool vfioap_found =3D false; + + /* currently, VFIO-AP is restricted to a single device only */ + for (i =3D 0; i < def->nhostdevs; i++) { + virDomainHostdevDefPtr hostdev =3D def->hostdevs[i]; + + if (virHostdevIsMdevDevice(hostdev) && + hostdev->source.subsys.u.mdev.model =3D=3D VIR_MDEV_MODEL_TYPE= _VFIO_AP) { + if (vfioap_found) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Only one hostdev of model vfio-ap is " + "supported")); + return -1; + } + vfioap_found =3D true; + } + } + + return 0; +} + + static int qemuDomainMdevDefValidate(const virDomainHostdevSubsysMediatedDev *mdevsrc, const virDomainDef *def, @@ -4609,7 +4635,7 @@ qemuDomainMdevDefValidate(const virDomainHostdevSubsy= sMediatedDev *mdevsrc, case VIR_MDEV_MODEL_TYPE_VFIO_PCI: return qemuDomainMdevDefVFIOPCIValidate(mdevsrc, def, qemuCaps); case VIR_MDEV_MODEL_TYPE_VFIO_AP: - break; + return qemuDomainMdevDefVFIOAPValidate(def); case VIR_MDEV_MODEL_TYPE_VFIO_CCW: break; case VIR_MDEV_MODEL_TYPE_LAST: --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list