From nobody Sun Feb 8 10:50:21 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 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 1580402739392849.1403487772377; Thu, 30 Jan 2020 08:45:39 -0800 (PST) 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-186-sp-_GdLTPqaQCBxuHPf6_A-1; Thu, 30 Jan 2020 11:45:34 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4FB581005F63; Thu, 30 Jan 2020 16:45:27 +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 2AB83CFDA; Thu, 30 Jan 2020 16:45:27 +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 A310018089D6; Thu, 30 Jan 2020 16:45:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00UGj3rq031925 for ; Thu, 30 Jan 2020 11:45:03 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2CC9B10551AE; Thu, 30 Jan 2020 16:45:03 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 279A110551AC for ; Thu, 30 Jan 2020 16:45:01 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (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 0DB32803B5C for ; Thu, 30 Jan 2020 16:45:01 +0000 (UTC) Received: from mail-qk1-f194.google.com (mail-qk1-f194.google.com [209.85.222.194]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-331-in_dyxo1NL-vYcGfisUPjw-1; Thu, 30 Jan 2020 11:44:58 -0500 Received: by mail-qk1-f194.google.com with SMTP id k6so3549804qki.5 for ; Thu, 30 Jan 2020 08:44:58 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:c177:887c:ce1b:6a44:15ec]) by smtp.gmail.com with ESMTPSA id 135sm3007157qkj.55.2020.01.30.08.44.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2020 08:44:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580402738; 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=tAXdERVI3QpIk9otbCa3YhCOVXiLGuWGkq77Vqjqp1c=; b=BsdXwQo5CpKXoi8Tnc82XYYp1yfxHSuTK9wXfMNKlABTvmH7bRw+QS5bXnTaYFPVkLwmFD UZfS975ZSiv1eDCwJtsGTR9E70WrVUT1KzFgjhE0QUN/NiX1qTfodZlFGCRGhzDD0COBhj 6r+QLyN/1fy5Tn/a50DBVZuO4A1lUBE= 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=yvjxrmemBhyyihq95bV9wQRN1QZyfJMGV1Rn/S04ZDU=; b=Plw6mcbSTvc89YOqaqE7TJJANELX3TPoNJns3AHgXYpvv2aQ/KrAXUqfSemNmJGhWC 6apetbmBrHnj633DGm6/VHfvvuk3TlrhZXVN62L2zh4wHvcIooM1TaMPmWpSouT0SZy0 Y2/tWYLpXjVMrMa/4rsTRLSw+ECcyZJ7zoMdyecwJbQzE5E2O8ND6oLBpKzK9QrF1QP7 zWJ7T1EUEyqNm5hfAYUL8mTUZXW6ZYknQb05/bm+YpIbURTCxrBdpXbMCeVNsY3E66Yi gTXZzr0g3WDV+K0qopVPtD+hrrPk15UplHCX9rMBahJy7f8yRODRVQm0nmUzUg0VPjjj m9JQ== X-Gm-Message-State: APjAAAVCBqIvM+bgt1hr+319QkLDmMwShg8bW29NpLxlCXKBFL7vMW/S Qjnws0tj4q7pKuDuML/gRahnyviLx28= X-Google-Smtp-Source: APXvYqwifOpW+fzbHOoGfIkPGUsg096F4takzG28NDbY5UNoX0V3nnDVfsALHFuRLvKSSZ+6nb+iQQ== X-Received: by 2002:a05:620a:342:: with SMTP id t2mr5903371qkm.383.1580402697408; Thu, 30 Jan 2020 08:44:57 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 05/21] conf: qemu: validate multifunction hostdevice domain configs Date: Thu, 30 Jan 2020 13:44:17 -0300 Message-Id: <20200130164433.2694119-6-danielhb413@gmail.com> In-Reply-To: <20200130164433.2694119-1-danielhb413@gmail.com> References: <20200130164433.2694119-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: in_dyxo1NL-vYcGfisUPjw-1 X-MC-Unique: sp-_GdLTPqaQCBxuHPf6_A-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 00UGj3rq031925 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.84 on 10.5.11.23 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.c | 3 ++ src/qemu/qemu_domain_address.c | 54 +++++++++++++++++++ src/qemu/qemu_domain_address.h | 2 + .../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, 149 insertions(+) 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.c b/src/qemu/qemu_domain.c index 05a8d3de38..2de7343882 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -5888,6 +5888,9 @@ qemuDomainDefValidate(const virDomainDef *def, if (qemuDomainDefValidateFeatures(def, qemuCaps) < 0) goto cleanup; =20 + if (qemuDomainDefValidatePCIHostdevs(def) < 0) + goto cleanup; + if (qemuDomainDefValidateMemory(def, qemuCaps) < 0) goto cleanup; =20 diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 3fed22d720..d9e36867bd 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -2266,6 +2266,60 @@ qemuDomainValidateDevicePCISlotsChipsets(virDomainDe= fPtr def, } =20 =20 +static int +qemuDomainDefPCIHostdevIsPrimaryFunction(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 qemuDomainDefValidatePCIMultifunctionHostdev(qemuDomainPCIHostd= evDataPtr data, + virDomainHostdevDe= fPtr hostdev) +{ + int ret =3D 0; + qemuDomainPCIHostdevdata hostdevIterData =3D {data->def, NULL, hostdev= }; + + if (!virHostdevIsPCIMultifunctionDevice(hostdev) || + hostdev->source.subsys.u.pci.addr.function =3D=3D 0) + goto skip; + + /* If the device is non-zero function but its Primary function is not + * part of the domain, then error out. + */ + if (!qemuDomainPCIHostDevicesIter(&hostdevIterData, + qemuDomainDefPCIHostdevIsPrimaryFunc= tion)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Secondary functions of a PCI multifunction card " + "cannot be assigned to a domain without the " + "Primary function.")); + ret =3D -1; + } + + skip: + return ret; +} + +int qemuDomainDefValidatePCIHostdevs(const virDomainDef *def) +{ + qemuDomainPCIHostdevdata hostdevdata =3D {def, NULL, NULL}; + + if (qemuDomainPCIHostDevicesIter(&hostdevdata, + qemuDomainDefValidatePCIMultifunction= Hostdev)) { + return -1; + } + + return 0; +} + + /* * This assigns static PCI slots to all configured devices. * The ordering here is chosen to match the ordering used diff --git a/src/qemu/qemu_domain_address.h b/src/qemu/qemu_domain_address.h index d7f06dd430..a17245dbde 100644 --- a/src/qemu/qemu_domain_address.h +++ b/src/qemu/qemu_domain_address.h @@ -57,6 +57,8 @@ void qemuDomainSetDeviceSlotAggregateIdx(virDomainDefPtr def, virDomainDeviceDefPtr dev); =20 +int qemuDomainDefValidatePCIHostdevs(const virDomainDef *def); + int qemuDomainDefDeviceFindSlotAggregateIdx(virDomainDefPtr def, virDomainDeviceDefPtr dev); 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 dad03f1dec..02375b2611 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1606,6 +1606,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.24.1