From nobody Sun Feb 8 14:53:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009154; cv=none; d=zohomail.com; s=zohoarc; b=NIhX05rk1yl3bZwdU6vkYG8Wx2Qo3Qga20+/aHWE3q/Jn2FJFM9/BEol81vQJXsOAd+c5YbqxGHZRR2jv54CiNKVS7yi30gTdPNOMWPcGs7XPDVcgRSMCL7QRMqhvpRTEHKW3ZbHNPfi7nA5/qHe1gBeKW+q5B3zQiWKQ8OiiTw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009154; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wlmAsbYOSMGS7S/xQLFAQVmqiawUbNmgnHkR4NC/UUc=; b=QkLLxA5tKIZk3an9Adi8C2XSGSl3UhVmlB8+srPbYqMGcTbkFzk03CYHyY5wJ+/Tq3GD9z8ISjhS3UZBV/6iWt/Uvc9h909aXHtDyaGZBayoRX77V/6Px35e2J/fiohm1AB09Wn7hxPOFfxtz/3IVrg8qMFT0j2ClQgrckfqz3g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1590009154982895.8999776839999; Wed, 20 May 2020 14:12:34 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-28-EcTcmLu2PIucE4N6t-h2LA-1; Wed, 20 May 2020 17:12:30 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id B30DF1005512; Wed, 20 May 2020 21:12:23 +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 912D860CC0; Wed, 20 May 2020 21:12:23 +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 CDFE61809563; Wed, 20 May 2020 21:12:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCHd0002049 for ; Wed, 20 May 2020 17:12:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5CE1B5AB7A; Wed, 20 May 2020 21:12:17 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4031E5AB85 for ; Wed, 20 May 2020 21:12:17 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0FFD08ECB1A for ; Wed, 20 May 2020 21:12:17 +0000 (UTC) Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-59-x2f4S4_OPn-JR0rih1bZ7Q-1; Wed, 20 May 2020 17:12:14 -0400 Received: by mail-qk1-f196.google.com with SMTP id s1so5133166qkf.9 for ; Wed, 20 May 2020 14:12:14 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009153; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=wlmAsbYOSMGS7S/xQLFAQVmqiawUbNmgnHkR4NC/UUc=; b=Vw9ehoQFD8rg+Zw2jEf/SMx32bL4+qWpR4ofMfg2jKEj07Y2NZ6ga723MpifwtVtj5o9m0 orN+mVDKrpCeWuJSvGhdmbZ3YcTo7T2JeE4B0PsFy6PFpOpJW1ivpQPwAywZCfmg0svCCU oZcpY0miV1AzN+6KV4ymE/PtTDDfmKE= X-MC-Unique: EcTcmLu2PIucE4N6t-h2LA-1 X-MC-Unique: x2f4S4_OPn-JR0rih1bZ7Q-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wlmAsbYOSMGS7S/xQLFAQVmqiawUbNmgnHkR4NC/UUc=; b=Oj60GA6KUnuEdNntudJJuisrT5z9NEr+tgg95rjUUZ6SGhBLdxV2DzxioqtLeJeyyg /QpCfzXS9xQkTuso6kt0wQHrbadopR8S5jpMbJUpiKModdTzoUxePYSwDEomEyoYws2E uuX3j416SDBd61XGYe+pK10xchZfLcn3vpDHUteFEhvaIyWFz5WpLIA/W+MWstlpJF4n UOzCmJ/kzIK+vyh+H5GJm08FB+ydmoDJwywi+cs2CspZy4b1EmDa9twHb+pu2IBVJlVi QioWHhgGoNCJ+d74WK+Qlleh260dfN4PwTCbnIg9fgzbJz8YtLC/pwev9RvbkNyW0vaV sUXw== X-Gm-Message-State: AOAM532HMCmJPWMM2sqzr/ojhLSNgmFixjFcVgNvXjJbPK+RtXXmFJg+ pK+znXYAhVALblUYDWeDGw5ISoO+ X-Google-Smtp-Source: ABdhPJy2WpxFQ8k0aRR614tXP9y8jpLDtNdEFSlKBwLj7rq+avlvhfO+2pbLHR9ORdVSaTu7qV2V8Q== X-Received: by 2002:a37:7904:: with SMTP id u4mr6785666qkc.297.1590009133951; Wed, 20 May 2020 14:12:13 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 05/21] conf: qemu: validate multifunction hostdevice domain configs Date: Wed, 20 May 2020 18:11:27 -0300 Message-Id: <20200520211143.2980117-6-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shivaprasad G Bhat It is invalid to have secondary functions without the primary functions part of the domain. Prevents new domain define, but existing ones would not vanish. Signed-off-by: Shivaprasad G Bhat Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_domain_address.c | 1 - src/qemu/qemu_domain_address.h | 4 ++ src/qemu/qemu_validate.c | 56 +++++++++++++++++++ .../hostdev-pci-no-primary-function.xml | 23 ++++++++ .../hostdev-pci-validate.args | 30 ++++++++++ .../qemuxml2argvdata/hostdev-pci-validate.xml | 29 ++++++++++ tests/qemuxml2argvtest.c | 8 +++ 7 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 tests/qemuxml2argvdata/hostdev-pci-no-primary-function.= xml create mode 100644 tests/qemuxml2argvdata/hostdev-pci-validate.args create mode 100644 tests/qemuxml2argvdata/hostdev-pci-validate.xml diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index f431f4bb15..05ef4de100 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -1434,7 +1434,6 @@ qemuDomainSetupIsolationGroups(virDomainDefPtr def) * with the return value for that callback. * Zero on success. */ -static int qemuDomainPCIHostDevicesIter(qemuDomainPCIHostdevDataPtr data, virDomainPCIHostdevCallback cb) { diff --git a/src/qemu/qemu_domain_address.h b/src/qemu/qemu_domain_address.h index 198f813595..8d51456f5b 100644 --- a/src/qemu/qemu_domain_address.h +++ b/src/qemu/qemu_domain_address.h @@ -25,6 +25,7 @@ #include "domain_conf.h" #include "qemu_conf.h" #include "qemu_capabilities.h" +#include "qemu_domain.h" =20 int qemuDomainGetSCSIControllerModel(const virDomainDef *def, const virDomainControllerDef *cont, @@ -57,6 +58,9 @@ void qemuDomainSetDeviceSlotAggregateIdx(virDomainDefPtr def, virDomainDeviceDefPtr dev); =20 +int qemuDomainPCIHostDevicesIter(qemuDomainPCIHostdevDataPtr data, + virDomainPCIHostdevCallback cb); + int qemuDomainDefDeviceFindSlotAggregateIdx(virDomainDefPtr def, virDomainDeviceDefPtr dev); diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 584d1375b8..956e3daf7d 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -762,6 +762,59 @@ qemuValidateDefGetVcpuHotplugGranularity(const virDoma= inDef *def) } =20 =20 +static int +qemuValidatePCIHostdevIsPrimaryFunction(qemuDomainPCIHostdevDataPtr data, + virDomainHostdevDefPtr hostdev) +{ + if (!data->device || !hostdev) + return 0; + + if ((hostdev->source.subsys.u.pci.addr.function =3D=3D 0) && + (virHostdevPCIDevicesBelongToSameSlot(data->device, hostdev))) + return 1; + + return 0; +} + + +static int qemuValidateDomainDefPCIMultifunctionHostdev(qemuDomainPCIHostd= evDataPtr data, + virDomainHostdevDe= fPtr hostdev) +{ + qemuDomainPCIHostdevdata hostdevIterData =3D {data->def, NULL, hostdev= }; + + if (!virHostdevIsPCIMultifunctionDevice(hostdev) || + hostdev->source.subsys.u.pci.addr.function =3D=3D 0) + return 0; + + /* If the device is non-zero function but its Primary function is not + * part of the domain, error out. + */ + if (!qemuDomainPCIHostDevicesIter(&hostdevIterData, + qemuValidatePCIHostdevIsPrimaryFunct= ion)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Secondary functions of a PCI multifunction card " + "cannot be assigned to a domain without the " + "Primary function.")); + return -1; + } + + return 0; +} + + +static int qemuValidateDomainDefPCIHostdevs(const virDomainDef *def) +{ + qemuDomainPCIHostdevdata hostdevdata =3D {def, NULL, NULL}; + + if (qemuDomainPCIHostDevicesIter(&hostdevdata, + qemuValidateDomainDefPCIMultifunction= Hostdev)) { + return -1; + } + + return 0; +} + + int qemuValidateDomainDef(const virDomainDef *def, void *opaque) @@ -966,6 +1019,9 @@ qemuValidateDomainDef(const virDomainDef *def, if (qemuValidateDomainDefConsole(def, qemuCaps) < 0) return -1; =20 + if (qemuValidateDomainDefPCIHostdevs(def) < 0) + return -1; + if (cfg->vncTLS && cfg->vncTLSx509secretUUID && !virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_TLS_CREDS_X509)) { for (i =3D 0; i < def->ngraphics; i++) { diff --git a/tests/qemuxml2argvdata/hostdev-pci-no-primary-function.xml b/t= ests/qemuxml2argvdata/hostdev-pci-no-primary-function.xml new file mode 100644 index 0000000000..9cd844bbe7 --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-pci-no-primary-function.xml @@ -0,0 +1,23 @@ + + delete + 583a8e8e-f0ce-4f53-89ab-092862148b25 + 262144 + 4 + + hvm + + + /usr/bin/qemu-system-x86_64 + + + + + + + + +
+ + + + diff --git a/tests/qemuxml2argvdata/hostdev-pci-validate.args b/tests/qemux= ml2argvdata/hostdev-pci-validate.args new file mode 100644 index 0000000000..2a8508991e --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-pci-validate.args @@ -0,0 +1,30 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/tmp/lib/domain--1-delete \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/tmp/lib/domain--1-delete/.local/share \ +XDG_CACHE_HOME=3D/tmp/lib/domain--1-delete/.cache \ +XDG_CONFIG_HOME=3D/tmp/lib/domain--1-delete/.config \ +QEMU_AUDIO_DRV=3Dnone \ +/usr/bin/qemu-system-x86_64 \ +-name delete \ +-S \ +-machine pc,accel=3Dkvm,usb=3Doff,dump-guest-core=3Doff \ +-m 256 \ +-realtime mlock=3Doff \ +-smp 4,sockets=3D4,cores=3D1,threads=3D1 \ +-uuid 583a8e8e-f0ce-4f53-89ab-092862148b25 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,path=3D/tmp/lib/domain--1-delete/monitor.= sock,\ +server,nowait \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-no-acpi \ +-usb \ +-device vfio-pci,host=3D0000:06:12.1,id=3Dhostdev0,bus=3Dpci.0,addr=3D0x3 \ +-device vfio-pci,host=3D0000:06:12.2,id=3Dhostdev1,bus=3Dpci.0,addr=3D0x4 \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x5 diff --git a/tests/qemuxml2argvdata/hostdev-pci-validate.xml b/tests/qemuxm= l2argvdata/hostdev-pci-validate.xml new file mode 100644 index 0000000000..54797c2dda --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-pci-validate.xml @@ -0,0 +1,29 @@ + + delete + 583a8e8e-f0ce-4f53-89ab-092862148b25 + 262144 + 4 + + hvm + + + /usr/bin/qemu-system-x86_64 + + + + + + + + +
+ + + + + +
+ + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index df11669cd5..84e8157e17 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1714,6 +1714,14 @@ mymain(void) QEMU_CAPS_DEVICE_VFIO_PCI); DO_TEST("hostdev-vfio-multidomain", QEMU_CAPS_DEVICE_VFIO_PCI); + DO_TEST("hostdev-pci-validate", + QEMU_CAPS_KVM, + X_QEMU_CAPS_NODEFCONFIG, X_QEMU_CAPS_HOST_PCI_MULTIDOMAIN, + QEMU_CAPS_DEVICE_VFIO_PCI); + DO_TEST_PARSE_ERROR("hostdev-pci-no-primary-function", + QEMU_CAPS_KVM, + X_QEMU_CAPS_NODEFCONFIG, X_QEMU_CAPS_HOST_PCI_MULTIDOMAIN, + QEMU_CAPS_DEVICE_VFIO_PCI); DO_TEST("hostdev-mdev-precreated", QEMU_CAPS_DEVICE_VFIO_PCI); DO_TEST_PARSE_ERROR("hostdev-mdev-src-address-invalid", --=20 2.26.2