From nobody Fri Jan 3 00:28:06 2025 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 1706127724490640.294118025421; Wed, 24 Jan 2024 12:22:04 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4C6C21BB3; Wed, 24 Jan 2024 15:22:03 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 01C931A56; Wed, 24 Jan 2024 14:41:29 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 562A1199E; Wed, 24 Jan 2024 14:38:20 -0500 (EST) 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 6BEF618DB for ; Wed, 24 Jan 2024 14:38:13 -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-530--_ggI84JP2eN2ONrzgVEIw-1; Wed, 24 Jan 2024 14:38:11 -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 B2ED71C068D0 for ; Wed, 24 Jan 2024 19:38:10 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.45.226.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3FC0A492BC6 for ; Wed, 24 Jan 2024 19:38:10 +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_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: -_ggI84JP2eN2ONrzgVEIw-1 From: Andrea Bolognani To: devel@lists.libvirt.org Subject: [PATCH 19/33] qemu: Add qemuDomainDefaultUSBControllerModel() Date: Wed, 24 Jan 2024 20:37:39 +0100 Message-ID: <20240124193753.1265454-20-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: WVRPPBOQ3V52LKWRJ3L576VRACFWMZRO X-Message-ID-Hash: WVRPPBOQ3V52LKWRJ3L576VRACFWMZRO 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: 1706127725157100001 Extract the logic from qemuDomainControllerDefPostParse(). The code is mostly unchanged, but there's a subtle difference: the piix3-uhci has been moved from the top of the chunk to the bottom. This is because the original code set cont->model directly, which made it okay to start with a suboptimal default and subsequently overwrite it with a better one; now that we return the selected value instead, we need to make sure that we only ever consider piix3-uhci if everything else has failed. Signed-off-by: Andrea Bolognani Reviewed-by: Peter Krempa --- src/qemu/qemu_domain.c | 100 +++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 44 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 7475fb4f39..09f572b0b5 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4151,6 +4151,61 @@ qemuDomainDefaultSCSIControllerModel(const virDomain= Def *def, } =20 =20 +static int +qemuDomainDefaultUSBControllerModel(const virDomainDef *def, + const virDomainControllerDef *cont, + 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 + * 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. + * + * See qemuBuildControllersCommandLine() */ + + if (ARCH_IS_S390(def->os.arch)) { + if (cont->info.type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) { + /* set the default USB model to none for s390 unless an + * 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)) { + return VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_XHCI; + } else if ((parseFlags & VIR_DOMAIN_DEF_PARSE_ABI_UPDATE) && + virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI)) { + return VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI; + } else 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) { + 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)) + return VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI; + } + + /* Default USB controller is piix3-uhci if available. */ + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_PIIX3_USB_UHCI)) + return VIR_DOMAIN_CONTROLLER_MODEL_USB_PIIX3_UHCI; + + return -1; +} + + static int qemuDomainDefAddDefaultDevices(virQEMUDriver *driver, virDomainDef *def, @@ -5640,50 +5695,7 @@ qemuDomainControllerDefPostParse(virDomainController= Def *cont, =20 case VIR_DOMAIN_CONTROLLER_TYPE_USB: if (cont->model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_USB_DEFAULT && = qemuCaps) { - /* 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 - * 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. - * - * See qemuBuildControllersCommandLine() */ - - /* Default USB controller is piix3-uhci if available. */ - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_PIIX3_USB_UHCI)) - cont->model =3D VIR_DOMAIN_CONTROLLER_MODEL_USB_PIIX3_UHCI; - - if (ARCH_IS_S390(def->os.arch)) { - if (cont->info.type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_= NONE) { - /* set the default USB model to none for s390 unless an - * address is found */ - cont->model =3D VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE; - } - } else if (ARCH_IS_PPC64(def->os.arch)) { - /* To not break migration we need to set default USB contr= oller - * for ppc64 to pci-ohci if we cannot change ABI of the VM. - * The nec-usb-xhci or qemu-xhci controller is used as def= ault - * only for newly defined domains or devices. */ - if ((parseFlags & VIR_DOMAIN_DEF_PARSE_ABI_UPDATE) && - virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_QEMU_XHCI)) { - cont->model =3D VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_X= HCI; - } else if ((parseFlags & VIR_DOMAIN_DEF_PARSE_ABI_UPDATE) = && - virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI)) { - cont->model =3D VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XH= CI; - } else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_PCI_OHCI)) { - cont->model =3D VIR_DOMAIN_CONTROLLER_MODEL_USB_PCI_OH= CI; - } else { - /* Explicitly fallback to legacy USB controller for PP= C64. */ - cont->model =3D -1; - } - } else if (def->os.arch =3D=3D VIR_ARCH_AARCH64) { - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_QEMU_XHCI)) - cont->model =3D VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_X= HCI; - else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI)) - cont->model =3D VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XH= CI; - } + cont->model =3D qemuDomainDefaultUSBControllerModel(def, cont,= qemuCaps, parseFlags); } /* forbid usb model 'qusb1' and 'qusb2' in this kind of hyperviosr= */ if (cont->model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB1 || --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org