From nobody Sun Oct 5 01:49:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1758826472; cv=none; d=zohomail.com; s=zohoarc; b=CRZKPG3puiQPdMyhpIP7p7Amyaprz2l3NfZNOBd5gejRsLKeYtwemIJSwFVDipbWqa79pp5so6sOF/GSbTfzwMSX621XP7qtvelW2gy1rj49Wdupu/njUiRdw0qMdqNduTaFH4FQwiRNXoD/dYz6EwRSYOK2o+lU6F+vMifSSQI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758826472; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=YROj/IGmmP6ngA1dkx1bGJcusO+CgVQdCY7TcSgPkNU=; b=OYCI4v5Lp3kZj7/KcMtuYMsLTHcWEOP2+o0dhg75ve7xFmWHsgBrvijZ5VmAelsx9NaYFIDXwZbusdbqqRcMFsHNfEFggCEcVw1PLE7M1ItoMVFLJ9Q7ruzP0no0YOxFG0Saj9q7z9wxhZS6ctcMjfLXA8UAA9+r97A9jTyp9Tk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1758826472058821.8595121623767; Thu, 25 Sep 2025 11:54:32 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 0E6B5440DC; Thu, 25 Sep 2025 14:54:31 -0400 (EDT) Received: from [172.19.199.14] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 3D6A644738; Thu, 25 Sep 2025 14:20:13 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 42F9C440D1; Thu, 25 Sep 2025 14:14:12 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 077D6440D2 for ; Thu, 25 Sep 2025 14:07:56 -0400 (EDT) Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-301-iluLtW93NX-P3qfznqJDcA-1; Thu, 25 Sep 2025 14:07:55 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9E3E71956086 for ; Thu, 25 Sep 2025 18:07:54 +0000 (UTC) Received: from harajuku.usersys.redhat.com.homenet.telecomitalia.it (unknown [10.45.225.196]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ADC4B300021A for ; Thu, 25 Sep 2025 18:07:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758823676; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YROj/IGmmP6ngA1dkx1bGJcusO+CgVQdCY7TcSgPkNU=; b=VNi/qr/gktJG0pMP10pYKOI25IQLMxldHXCPstU7AdKGOI1zxe5c80ZQqZNG/FiqrG03ow mDUJqDZkDlkItL4jwKvlmBTLVOxPO7SB4rMp7+gOtn7gVTl8Gw2EW0HNcIVvO/yWznZB4k HEO4rvgaCyxLxnuDvgUEj9Ky0An7Bqs= X-MC-Unique: iluLtW93NX-P3qfznqJDcA-1 X-Mimecast-MFC-AGG-ID: iluLtW93NX-P3qfznqJDcA_1758823674 To: devel@lists.libvirt.org Subject: [PATCH v2 19/38] qemu: Add sanity checks for auto-added PCI and USB controllers Date: Thu, 25 Sep 2025 20:07:05 +0200 Message-ID: <20250925180724.500758-20-abologna@redhat.com> In-Reply-To: <20250925180724.500758-1-abologna@redhat.com> References: <20250925180724.500758-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 0vwIEq-XiBNxg-mE-5GQf8ulZSJreE64KcqiDj1gxA8_1758823674 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ST4TYLFXM73DPHNMP3DKTL4NB6TAMUZX X-Message-ID-Hash: ST4TYLFXM73DPHNMP3DKTL4NB6TAMUZX X-MailFrom: abologna@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Andrea Bolognani via Devel Reply-To: Andrea Bolognani X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758826472655116600 Content-Type: text/plain; charset="utf-8"; x-default="true" These checks enforce some expectations that were, until now, documented solely through comments or not spelled out at all. Signed-off-by: Andrea Bolognani Reviewed-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/qemu/qemu_postparse.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_postparse.c b/src/qemu/qemu_postparse.c index d5708fbff9..cf08e6e07c 100644 --- a/src/qemu/qemu_postparse.c +++ b/src/qemu/qemu_postparse.c @@ -1384,6 +1384,29 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *driver, break; } =20 + /* Sanity check. If the machine type does not support PCI, asking + * for PCI(e) root to be added is an obvious mistake */ + if ((addPCIRoot || + addPCIeRoot) && + !qemuDomainSupportsPCI(def)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Machine type '%1$s' wants PCI but PCI is not sup= ported"), + def->os.machine); + return -1; + } + + /* Sanity check. If the machine type supports PCI, we need to reflect + * that fact in the XML or other parts of the machine handling code + * might misbehave */ + if (qemuDomainSupportsPCI(def) && + !addPCIRoot && + !addPCIeRoot) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Machine type '%1$s' supports PCI but no PCI cont= roller added"), + def->os.machine); + return -1; + } + if (addDefaultUSB && virDomainControllerFind(def, VIR_DOMAIN_CONTROLLE= R_TYPE_USB, 0) < 0) virDomainDefAddUSBController(def, 0, usbModel); =20 @@ -1392,9 +1415,6 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *driver, =20 pciRoot =3D virDomainControllerFind(def, VIR_DOMAIN_CONTROLLER_TYPE_PC= I, 0); =20 - /* NB: any machine that sets addPCIRoot to true must also return - * true from the function qemuDomainSupportsPCI(). - */ if (addPCIRoot) { if (pciRoot >=3D 0) { if (def->controllers[pciRoot]->model !=3D VIR_DOMAIN_CONTROLLE= R_MODEL_PCI_ROOT) { --=20 2.51.0