From nobody Tue Apr 30 01:57:59 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1504618597120685.0097569070144; Tue, 5 Sep 2017 06:36:37 -0700 (PDT) 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 71A973F74C; Tue, 5 Sep 2017 13:36:35 +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 45AD980C6C; Tue, 5 Sep 2017 13:36:35 +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 D2A543FACF; Tue, 5 Sep 2017 13:36:34 +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 v85DPhim031381 for ; Tue, 5 Sep 2017 09:25:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1C14380C75; Tue, 5 Sep 2017 13:25:43 +0000 (UTC) Received: from inaba.usersys.redhat.com (unknown [10.43.2.219]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 991B380C73 for ; Tue, 5 Sep 2017 13:25:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 71A973F74C Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Andrea Bolognani To: libvir-list@redhat.com Date: Tue, 5 Sep 2017 15:25:32 +0200 Message-Id: <20170905132533.20148-2-abologna@redhat.com> In-Reply-To: <20170905132533.20148-1-abologna@redhat.com> References: <20170905132533.20148-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/2] qemu: Clean up qemuBuildControllerDevCommandLine() 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: , MIME-Version: 1.0 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]); Tue, 05 Sep 2017 13:36:36 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a cleanup: label, which will be used later, and improve the readability of one of the checks by making it conform to our formatting standard and moving a comment. Signed-off-by: Andrea Bolognani Reviewed-by: Laine Stump --- src/qemu/qemu_command.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 9a27987d4..83430b33f 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3122,6 +3122,7 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd, VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL, VIR_DOMAIN_CONTROLLER_TYPE_CCID, }; + int ret =3D -1; =20 for (j =3D 0; j < ARRAY_CARDINALITY(contOrder); j++) { for (i =3D 0; i < def->ncontrollers; i++) { @@ -3183,7 +3184,7 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Multiple legacy USB controllers are " "not supported")); - return -1; + goto cleanup; } usblegacy =3D true; continue; @@ -3191,7 +3192,7 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd, =20 if (qemuBuildControllerDevStr(def, cont, qemuCaps, &devstr, &usbcontroller) < 0) - return -1; + goto cleanup; =20 if (devstr) { virCommandAddArg(cmd, "-device"); @@ -3201,16 +3202,20 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd, } } =20 - /* We haven't added any USB controller yet, but we haven't been asked - * not to add one either. Add a legacy USB controller, unless we're - * creating a kind of guest we want to keep legacy-free */ if (usbcontroller =3D=3D 0 && !qemuDomainIsQ35(def) && !qemuDomainIsVirt(def) && - !ARCH_IS_S390(def->os.arch)) + !ARCH_IS_S390(def->os.arch)) { + /* We haven't added any USB controller yet, but we haven't been as= ked + * not to add one either. Add a legacy USB controller, unless we're + * creating a kind of guest we want to keep legacy-free */ virCommandAddArg(cmd, "-usb"); + } =20 - return 0; + ret =3D 0; + + cleanup: + return ret; } =20 =20 --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue Apr 30 01:57:59 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1504618603162679.8534686694983; Tue, 5 Sep 2017 06:36:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5B22A8F2FE; Tue, 5 Sep 2017 13:36:41 +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 38ADE6BF6C; Tue, 5 Sep 2017 13:36:41 +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 ED8E51806105; Tue, 5 Sep 2017 13:36:40 +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 v85DPiWU031391 for ; Tue, 5 Sep 2017 09:25:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5FB3F80C74; Tue, 5 Sep 2017 13:25:44 +0000 (UTC) Received: from inaba.usersys.redhat.com (unknown [10.43.2.219]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B34E480C78 for ; Tue, 5 Sep 2017 13:25:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5B22A8F2FE Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Andrea Bolognani To: libvir-list@redhat.com Date: Tue, 5 Sep 2017 15:25:33 +0200 Message-Id: <20170905132533.20148-3-abologna@redhat.com> In-Reply-To: <20170905132533.20148-1-abologna@redhat.com> References: <20170905132533.20148-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/2] qemu: Order PCI controllers on the command line 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: , MIME-Version: 1.0 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 05 Sep 2017 13:36:41 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Unlike other controllers, PCI controller can plug into each other, which might turn into a problem if they are not listed in the expected order on the QEMU command line, because the guest will then not be able to start with an error such as qemu-kvm: -device pci-bridge,chassis_nr=3D3,id=3Dpci.3,bus=3Dpci.2.0,addr= =3D0x7: Bus 'pci.2.0' not found Add some logic to make sure PCI controller appear in the correct order on the QEMU command line, regardless of the order they were added to the guest configuration. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1479674 Signed-off-by: Andrea Bolognani --- src/qemu/qemu_command.c | 72 ++++++++++++++++--= ---- .../qemuxml2argv-pci-autoadd-idx.args | 2 +- .../qemuxml2argv-pseries-many-buses-2.args | 4 +- 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 83430b33f..c0e60a184 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3096,6 +3096,8 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd, virQEMUCapsPtr qemuCaps) { size_t i, j; + size_t *pciContIndex; + size_t npciContIndex; int usbcontroller =3D 0; bool usblegacy =3D false; int contOrder[] =3D { @@ -3107,14 +3109,10 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd, * machines. For newer Q35 machines it is added out of the * controllers loop, after the floppy drives. * - * We don't add PCI/PCIe root controller either, because it's - * implicit, but we do add PCI bridges and other PCI - * controllers, so we leave that in to check each - * one. Likewise, we don't do anything for the primary IDE + * Likewise, we don't do anything for the primary IDE * controller on an i440fx machine or primary SATA on q35, but * we do add those beyond these two exceptions. */ - VIR_DOMAIN_CONTROLLER_TYPE_PCI, VIR_DOMAIN_CONTROLLER_TYPE_USB, VIR_DOMAIN_CONTROLLER_TYPE_SCSI, VIR_DOMAIN_CONTROLLER_TYPE_IDE, @@ -3124,6 +3122,54 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd, }; int ret =3D -1; =20 + /* PCI controllers require special handling because they plug into + * each other, which makes getting the ordering right on the QEMU + * command line crucial: if we don't, and eg. list a pci-bridge + * before the pci-root it plugs into, the guest will not start */ + + npciContIndex =3D 0; + if (VIR_ALLOC_N(pciContIndex, def->ncontrollers) < 0) + goto cleanup; + + for (i =3D 0; i < def->ncontrollers; i++) { + virDomainControllerDefPtr cont =3D def->controllers[i]; + + if (cont->type !=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI) + continue; + + pciContIndex[cont->idx] =3D i; + npciContIndex =3D MAX(npciContIndex, cont->idx + 1); + } + + for (i =3D 0; i < npciContIndex; i++) { + virDomainControllerDefPtr cont =3D def->controllers[pciContIndex[i= ]]; + char *devstr; + + if (cont->type !=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI) + continue; + + /* skip pcie-root */ + if (cont->model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT) + continue; + + /* Skip pci-root, except for pSeries guests (which actually + * support more than one PCI Host Bridge per guest) */ + if (!qemuDomainIsPSeries(def) && + cont->model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT) { + continue; + } + + if (qemuBuildControllerDevStr(def, cont, qemuCaps, + &devstr, &usbcontroller) < 0) + goto cleanup; + + if (devstr) { + virCommandAddArg(cmd, "-device"); + virCommandAddArg(cmd, devstr); + VIR_FREE(devstr); + } + } + for (j =3D 0; j < ARRAY_CARDINALITY(contOrder); j++) { for (i =3D 0; i < def->ncontrollers; i++) { virDomainControllerDefPtr cont =3D def->controllers[i]; @@ -3139,20 +3185,6 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd, continue; } =20 - /* skip pcie-root */ - if (cont->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI && - cont->model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT) { - continue; - } - - /* Skip pci-root, except for pSeries guests (which actually - * support more than one PCI Host Bridge per guest) */ - if (!qemuDomainIsPSeries(def) && - cont->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI && - cont->model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT) { - continue; - } - /* first SATA controller on Q35 machines is implicit */ if (cont->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_SATA && cont->idx =3D=3D 0 && qemuDomainIsQ35(def)) @@ -3215,6 +3247,8 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd, ret =3D 0; =20 cleanup: + VIR_FREE(pciContIndex); + return ret; } =20 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pci-autoadd-idx.args b/tes= ts/qemuxml2argvdata/qemuxml2argv-pci-autoadd-idx.args index 6b2f21bba..c03f72d96 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-pci-autoadd-idx.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-pci-autoadd-idx.args @@ -17,7 +17,6 @@ QEMU_AUDIO_DRV=3Dnone \ server,nowait \ -mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dreadline \ -boot c \ --device pci-bridge,chassis_nr=3D8,id=3Dpci.8,bus=3Dpci.0,addr=3D0x3 \ -device pci-bridge,chassis_nr=3D1,id=3Dpci.1,bus=3Dpci.0,addr=3D0x4 \ -device pci-bridge,chassis_nr=3D2,id=3Dpci.2,bus=3Dpci.0,addr=3D0x5 \ -device pci-bridge,chassis_nr=3D3,id=3Dpci.3,bus=3Dpci.0,addr=3D0x6 \ @@ -25,6 +24,7 @@ server,nowait \ -device pci-bridge,chassis_nr=3D5,id=3Dpci.5,bus=3Dpci.0,addr=3D0x8 \ -device pci-bridge,chassis_nr=3D6,id=3Dpci.6,bus=3Dpci.0,addr=3D0x9 \ -device pci-bridge,chassis_nr=3D7,id=3Dpci.7,bus=3Dpci.0,addr=3D0xa \ +-device pci-bridge,chassis_nr=3D8,id=3Dpci.8,bus=3Dpci.0,addr=3D0x3 \ -usb \ -drive file=3D/var/iso/f18kde.iso,format=3Draw,if=3Dnone,media=3Dcdrom,\ id=3Ddrive-ide0-1-0,readonly=3Don \ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-many-buses-2.args = b/tests/qemuxml2argvdata/qemuxml2argv-pseries-many-buses-2.args index 13fed02f8..7b2171f59 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-pseries-many-buses-2.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-many-buses-2.args @@ -18,5 +18,5 @@ QEMU_AUDIO_DRV=3Dnone \ server,nowait \ -mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dreadline \ -boot c \ --device spapr-pci-host-bridge,index=3D1,id=3Dpci.2 \ --device spapr-pci-host-bridge,index=3D2,id=3Dpci.1 +-device spapr-pci-host-bridge,index=3D2,id=3Dpci.1 \ +-device spapr-pci-host-bridge,index=3D1,id=3Dpci.2 --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list