From nobody Sun Dec 22 06:17:18 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706128403621318.9098584050223; Wed, 24 Jan 2024 12:33:23 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 7B5AA1B29; Wed, 24 Jan 2024 15:33:22 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 295951913; Wed, 24 Jan 2024 14:42:04 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 2586019A3; Wed, 24 Jan 2024 14:38:57 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 6A9931913 for ; Wed, 24 Jan 2024 14:38:14 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-391-LlEd-KgSNeKzlO1IpQqgvw-1; Wed, 24 Jan 2024 14:38:12 -0500 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 40EC53C02B7C for ; Wed, 24 Jan 2024 19:38:12 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.45.226.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C1D35492BC9 for ; Wed, 24 Jan 2024 19:38:11 +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=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: LlEd-KgSNeKzlO1IpQqgvw-1 From: Andrea Bolognani To: devel@lists.libvirt.org Subject: [PATCH 21/33] qemu: Clean up qemuDomainDefaultUSBControllerModel() Date: Wed, 24 Jan 2024 20:37:41 +0100 Message-ID: <20240124193753.1265454-22-abologna@redhat.com> In-Reply-To: <20240124193753.1265454-1-abologna@redhat.com> References: <20240124193753.1265454-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: O6MXQWQKD45ZVKGT24RVP7FGQOOUID3J X-Message-ID-Hash: O6MXQWQKD45ZVKGT24RVP7FGQOOUID3J 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: Content-Type: text/plain; charset="utf-8"; x-default="true" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706128405340100001 Mostly reduce the number of 'else if' and improve comments. Signed-off-by: Andrea Bolognani Reviewed-by: Peter Krempa --- src/qemu/qemu_domain.c | 62 ++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d992b51877..dcf73c0e08 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4183,11 +4183,9 @@ qemuDomainDefaultUSBControllerModel(const virDomainD= ef *def, virQEMUCaps *qemuCaps, unsigned int parseFlags) { - /* Pick a suitable default model for the USB controller if none - * has been selected by the user and we have the qemuCaps for - * figuring out which controllers are supported. - * - * We rely on device availability instead of setting the model + bool abiUpdate =3D !!(parseFlags & VIR_DOMAIN_DEF_PARSE_ABI_UPDATE); + + /* We rely on device availability instead of setting the model * unconditionally because, for some machine types, there's a * chance we will get away with using the legacy USB controller * when the relevant device is not available. @@ -4200,50 +4198,62 @@ qemuDomainDefaultUSBControllerModel(const virDomain= Def *def, * address is found */ return VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE; } - } else if (ARCH_IS_PPC64(def->os.arch)) { - /* To not break migration we need to set default USB controller - * for ppc64 to pci-ohci if we cannot change ABI of the VM. - * The nec-usb-xhci or qemu-xhci controller is used as default - * only for newly defined domains or devices. */ - if ((parseFlags & VIR_DOMAIN_DEF_PARSE_ABI_UPDATE) && - virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_QEMU_XHCI)) { + } + + if (ARCH_IS_PPC64(def->os.arch)) { + /* In order not to break migration compatibility, we need to + * set default USB controller to pci-ohci (USB2) for existing + * guests. New guests can use USB3 instead */ + if (abiUpdate && virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_QEMU_XH= CI)) return VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_XHCI; - } else if ((parseFlags & VIR_DOMAIN_DEF_PARSE_ABI_UPDATE) && - virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI)) { + if (abiUpdate && virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI)) return VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI; - } else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_PCI_OHCI)) { + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_PCI_OHCI)) return VIR_DOMAIN_CONTROLLER_MODEL_USB_PCI_OHCI; - } else { - /* Explicitly fallback to legacy USB controller for PPC64. */ - return -1; - } - } else if (def->os.arch =3D=3D VIR_ARCH_AARCH64) { + + /* For ppc64 specifically, returning -1 here will result in + * an attempt to use the legacy USB controller rather than an + * outright failure */ + return -1; + } + + if (def->os.arch =3D=3D VIR_ARCH_AARCH64) { + /* Prefer USB3 */ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_QEMU_XHCI)) return VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_XHCI; - else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI)) + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI)) return VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI; + + /* We should probably return -1 here and avoid the + * possibility of falling back to piix3-uhci (USB1), but + * historically we haven't done that and starting now might + * cause backwards compatibility issues */ } =20 if (ARCH_IS_X86(def->os.arch)) { if (qemuDomainIsQ35(def) && autoAdded) { - /* Prefer adding a USB3 controller if supported, fall back - * to USB2 if there is no USB3 available, and if that's - * unavailable don't add anything. - */ + /* Prefer USB3 */ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_QEMU_XHCI)) return VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_XHCI; if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI)) return VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI; + + /* Fall back to USB2 */ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_ICH9_USB_EHCI1)) return VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_EHCI1; + + /* If no suitable device is available, simply avoid + * adding the controller */ return -2; } } =20 - /* Default USB controller is piix3-uhci if available. */ + /* piix3-uhci (USB1) is the last ditch effort before giving up */ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_PIIX3_USB_UHCI)) return VIR_DOMAIN_CONTROLLER_MODEL_USB_PIIX3_UHCI; =20 + /* No suitable model could be found. This will return in either + * an error or the use of the legacy USB controller */ return -1; } =20 --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org