From nobody Mon Sep 8 17:06:10 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=1755621996; cv=none; d=zohomail.com; s=zohoarc; b=WE+ldJ2kDhkc1x4n5QI7rzwgJYbiIDdQGPFjihqvK2Q3i6ueWFlOmZs4H7PdhcGfVbr2m743khKJnisKFgDWuLDNYtmDFc7Yo9L0L8IvmwN0gHguaooEBDZbSCapJjh5LUBF/ObcevBhKSOp73R5aWQldMnAP7c8OONDYAXnAmc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755621996; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post: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=AGJbcK2sCYVLgKMoKDVsLe81J/z6n18tC1BLyMNbORY=; b=bc0ihV9l/vSBRhWN2mkdY1uUj4jpSol2uTXcBo96jcU6t2t6lQQacemkHfB7I6zKjbnQAdtjVej02ELw0qK5imTTsf+EpiHAkxT/wGzEA6kQNo26l04+bVSzFIqJIg4Dlyjn07drsv/hN1YgWtaPRwsk9vF7ytQaE/mNPVdShjo= 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 1755621996020175.01857771816663; Tue, 19 Aug 2025 09:46:36 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id EC324BA4; Tue, 19 Aug 2025 12:46:34 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 8F093D48; Tue, 19 Aug 2025 12:24:14 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 5B6EDB0D; Tue, 19 Aug 2025 12:24:01 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 85E8EB26 for ; Tue, 19 Aug 2025 12:23:07 -0400 (EDT) Received: from mx-prod-mc-03.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-690-XtLleVRHNsCfAjdKqKTt3Q-1; Tue, 19 Aug 2025 12:23:05 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 94F931956079 for ; Tue, 19 Aug 2025 16:23:04 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.45.224.253]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BEC59180044F for ; Tue, 19 Aug 2025 16:23:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755620587; 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=/65bsaC3yM+B1qYEOKzii0N4ybt0YxtiRviLuzRB0cU=; b=d7mRhhmzzhrQZ4gHSuUD0TX3wuInnAW54Y0YyNdyvui/BvQy44IJ04nsNFnhj81XWldtAU 00nZeIxMHT7wuScWIC3onRPl9bBnqSLvwmGkXb0pcZARkyVfWpzf8dmovxvoH3w0LiXjfn wR2TgN7pR0S5CBY0Ga9na4QSQk2gr+c= X-MC-Unique: XtLleVRHNsCfAjdKqKTt3Q-1 X-Mimecast-MFC-AGG-ID: XtLleVRHNsCfAjdKqKTt3Q_1755620584 To: devel@lists.libvirt.org Subject: [PATCH 18/31] qemu: Add sanity checks for auto-added PCI and USB controllers Date: Tue, 19 Aug 2025 18:22:22 +0200 Message-ID: <20250819162235.468215-19-abologna@redhat.com> In-Reply-To: <20250819162235.468215-1-abologna@redhat.com> References: <20250819162235.468215-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: vCIN4l_078RO3cGWE2IVuGOVBJlZ-728JLk4m7-eTcs_1755620584 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: FERGZ24BMYNYEO6E6EDFGEGBVAJ7FJRW X-Message-ID-Hash: FERGZ24BMYNYEO6E6EDFGEGBVAJ7FJRW X-MailFrom: abologna@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: 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: 1755621996685116600 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 --- src/qemu/qemu_postparse.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_postparse.c b/src/qemu/qemu_postparse.c index ab39dfe138..e2004993f3 100644 --- a/src/qemu/qemu_postparse.c +++ b/src/qemu/qemu_postparse.c @@ -1383,6 +1383,41 @@ 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; + } + + /* Sanity check. USB controllers are PCI devices, so asking for a + * USB controller to be added but not for a PCI(e) root to be + * added at the same time is likely an oversight */ + if (addDefaultUSB && + !addPCIRoot && + !addPCIeRoot) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Machine type '%1$s' wants USB but no PCI control= ler added"), + def->os.machine); + return -1; + } + if (addDefaultUSB && virDomainControllerFind(def, VIR_DOMAIN_CONTROLLE= R_TYPE_USB, 0) < 0) virDomainDefAddUSBController(def, 0, usbModel); =20 @@ -1391,9 +1426,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.50.1