From nobody Mon Feb 2 09:26:42 2026 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; 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=1768229639; cv=none; d=zohomail.com; s=zohoarc; b=S5ijpH9YeWhwd3IO+OrjZT3wHX4GdG//J7neAr0eNuIjAh/Jc7jAzTWIN43Homtkb0Ap3N+PqpIpKxjc3rpu8sIlsNhFs7T9mhXZOMw4VABv6akwk/pXY7rPMjMMCZ/CJy2nWv8gYMZV/dMnxG88cwqLuXBkCcKHIov9y8hXiwM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768229639; 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=vAsEO3b4ltFoRNQm3//RIIqu6PR/Jt2a3DNwlSMezhQ=; b=GaRHiTeneB/ckzgTIK2WtPc5xMC1wRUY0mBC6/WMrq+ERS9qwN0HcsnP+xpoe+7SeIltKnVyEb3GKKic5xQkeozq5bIBAT368zsN+2mAvoYlQ8L2AozP4HFWc1RLBierrpwscLxbyFvS/EAggV7/HN2CZP81nxAcnQ4d31a2oIc= 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 1768229639009204.70503315158953; Mon, 12 Jan 2026 06:53:59 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 359DD417ED; Mon, 12 Jan 2026 09:53:58 -0500 (EST) Received: from [172.19.199.83] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 9DA5941BB2; Mon, 12 Jan 2026 09:49:50 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 0E551417E9; Mon, 12 Jan 2026 09:49:29 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 3F3C03F86A for ; Mon, 12 Jan 2026 09:49:28 -0500 (EST) 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-574-OfhNFfjZODmfQ_eCOgw4jQ-1; Mon, 12 Jan 2026 09:49:26 -0500 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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5337C195605B for ; Mon, 12 Jan 2026 14:49:25 +0000 (UTC) Received: from harajuku.usersys.redhat.com.homenet.telecomitalia.it (unknown [10.45.224.90]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 90DA430001A2 for ; Mon, 12 Jan 2026 14:49:24 +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.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW, 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=1768229367; 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=vAsEO3b4ltFoRNQm3//RIIqu6PR/Jt2a3DNwlSMezhQ=; b=BcixUXi3jwDQ3dNj7aVDbJPKklfIq4k29bUQUHsnBRfXzafB3A9kX3ixrEpBxsTqCSQ1mo 9sN+a6DBVAiGdTn6tOHzMFvxJNfnISeSRGCqkHdQv3/jOJTikpsDrCW+J5EFMjY6+tlHRa 7Wam8df/EgJ4zDtLK6nydlc32uoohUo= X-MC-Unique: OfhNFfjZODmfQ_eCOgw4jQ-1 X-Mimecast-MFC-AGG-ID: OfhNFfjZODmfQ_eCOgw4jQ_1768229365 To: devel@lists.libvirt.org Subject: [PATCH 4/4] qemu: Automatically add USB controller if USB devices are present Date: Mon, 12 Jan 2026 15:49:16 +0100 Message-ID: <20260112144916.127295-5-abologna@redhat.com> In-Reply-To: <20260112144916.127295-1-abologna@redhat.com> References: <20260112144916.127295-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: CeFri7l9u3GdlXh8Kkuzk3y7C-fhq6HGPr91X3qnSk8_1768229365 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 57STJEGWGD4HNLZEICG23YWMXLC2HRJD X-Message-ID-Hash: 57STJEGWGD4HNLZEICG23YWMXLC2HRJD 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: 1768229640279158500 Content-Type: text/plain; charset="utf-8"; x-default="true" The current behavior is to error out, but that's not very helpful. Automatically add the necessary USB controller instead. Resolves: https://issues.redhat.com/browse/RHEL-2455 Signed-off-by: Andrea Bolognani --- src/qemu/qemu_postparse.c | 11 ++++++ ...h-devices-virt-aarch64.aarch64-latest.args | 36 +++++++++++++++++++ ...th-devices-virt-aarch64.aarch64-latest.err | 1 - ...th-devices-virt-aarch64.aarch64-latest.xml | 13 +++++++ tests/qemuxmlconftest.c | 2 +- 5 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 tests/qemuxmlconfdata/usb-controller-automatic-with-dev= ices-virt-aarch64.aarch64-latest.args delete mode 100644 tests/qemuxmlconfdata/usb-controller-automatic-with-dev= ices-virt-aarch64.aarch64-latest.err diff --git a/src/qemu/qemu_postparse.c b/src/qemu/qemu_postparse.c index 8940cb09b3..d3548b24d8 100644 --- a/src/qemu/qemu_postparse.c +++ b/src/qemu/qemu_postparse.c @@ -1329,6 +1329,17 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *driver, return -1; } =20 + /* If the default UBS controller would normally not be added for the + * machine but USB devices are present in the configuration, it's more + * user-friendly to automatically add the USB controller instead of + * requiring the user to take care of that manually. Of course this is + * still subject to the logic below, i.e. we will only add the + * controller if a suitable model can be figured out and an explicit + * one was not already present */ + if (!addDefaultUSB && virDomainDefHasUSBDevices(def)) { + addDefaultUSB =3D true; + } + if (addDefaultUSB && usbModel =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_USB_D= EFAULT) { usbModel =3D qemuDomainDefaultUSBControllerModelAutoAdded(def, qem= uCaps); =20 diff --git a/tests/qemuxmlconfdata/usb-controller-automatic-with-devices-vi= rt-aarch64.aarch64-latest.args b/tests/qemuxmlconfdata/usb-controller-autom= atic-with-devices-virt-aarch64.aarch64-latest.args new file mode 100644 index 0000000000..850eaa7ec0 --- /dev/null +++ b/tests/qemuxmlconfdata/usb-controller-automatic-with-devices-virt-aarc= h64.aarch64-latest.args @@ -0,0 +1,36 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/var/lib/libvirt/qemu/domain--1-test \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/var/lib/libvirt/qemu/domain--1-test/.local/share \ +XDG_CACHE_HOME=3D/var/lib/libvirt/qemu/domain--1-test/.cache \ +XDG_CONFIG_HOME=3D/var/lib/libvirt/qemu/domain--1-test/.config \ +/usr/bin/qemu-system-aarch64 \ +-name guest=3Dtest,debug-threads=3Don \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/va= r/lib/libvirt/qemu/domain--1-test/master-key.aes"}' \ +-machine virt,usb=3Doff,gic-version=3D2,dump-guest-core=3Doff,memory-backe= nd=3Dmach-virt.ram,acpi=3Doff \ +-accel tcg \ +-cpu cortex-a15 \ +-m size=3D219136k \ +-object '{"qom-type":"memory-backend-ram","id":"mach-virt.ram","size":2243= 95264}' \ +-overcommit mem-lock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,fd=3D1729,server=3Don,wait=3Doff \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-boot strict=3Don \ +-device '{"driver":"pcie-root-port","port":8,"chassis":1,"id":"pci.1","bus= ":"pcie.0","multifunction":true,"addr":"0x1"}' \ +-device '{"driver":"pcie-root-port","port":9,"chassis":2,"id":"pci.2","bus= ":"pcie.0","addr":"0x1.0x1"}' \ +-device '{"driver":"qemu-xhci","id":"usb","bus":"pci.1","addr":"0x0"}' \ +-device '{"driver":"usb-tablet","id":"input0","bus":"usb.0","port":"1"}' \ +-device '{"driver":"usb-kbd","id":"input1","bus":"usb.0","port":"2"}' \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,resource= control=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxmlconfdata/usb-controller-automatic-with-devices-vi= rt-aarch64.aarch64-latest.err b/tests/qemuxmlconfdata/usb-controller-automa= tic-with-devices-virt-aarch64.aarch64-latest.err deleted file mode 100644 index 90050be94b..0000000000 --- a/tests/qemuxmlconfdata/usb-controller-automatic-with-devices-virt-aarc= h64.aarch64-latest.err +++ /dev/null @@ -1 +0,0 @@ -unsupported configuration: USB is disabled for this domain, but USB device= s are present in the domain XML diff --git a/tests/qemuxmlconfdata/usb-controller-automatic-with-devices-vi= rt-aarch64.aarch64-latest.xml b/tests/qemuxmlconfdata/usb-controller-automa= tic-with-devices-virt-aarch64.aarch64-latest.xml index 431ff6703b..7923087433 100644 --- a/tests/qemuxmlconfdata/usb-controller-automatic-with-devices-virt-aarc= h64.aarch64-latest.xml +++ b/tests/qemuxmlconfdata/usb-controller-automatic-with-devices-virt-aarc= h64.aarch64-latest.xml @@ -20,7 +20,20 @@ destroy /usr/bin/qemu-system-aarch64 + +
+ + + + +
+ + + + +
+