From nobody Sat Dec 21 16:46:22 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 1706128291969171.2521999290849; Wed, 24 Jan 2024 12:31:31 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id C2C5C1B58; Wed, 24 Jan 2024 15:31:30 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E1BB41AB7; Wed, 24 Jan 2024 14:41:53 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 9E0A11903; Wed, 24 Jan 2024 14:38:53 -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 050AC1908 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-357-iLoZfJ8OOXOiHTBDewZr8w-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 799B938116E7 for ; Wed, 24 Jan 2024 19:38:11 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.45.226.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 06D0D492BC6 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_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: iLoZfJ8OOXOiHTBDewZr8w-1 From: Andrea Bolognani To: devel@lists.libvirt.org Subject: [PATCH 20/33] qemu: Enhance qemuDomainDefaultUSBControllerModel() Date: Wed, 24 Jan 2024 20:37:40 +0100 Message-ID: <20240124193753.1265454-21-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: QILIZA7WLSCDFGXGZ5CPAOZVEHXNQJY3 X-Message-ID-Hash: QILIZA7WLSCDFGXGZ5CPAOZVEHXNQJY3 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: 1706128293132100001 In addition to the code in qemuDomainControllerDefPostParse(), which we have just factored into its own function, we also have some code in qemuDomainDefAddDefaultDevices() that deals with choosing the model for a USB controller, specifically for q35 guests. Integrate it into the newly-created function. Since we want slightly different behaviors depending on whether the USB controller that we're working on is the one that we try to automatically add for certain new guests (addDefaultUSB), introduce a new parameter to the function and a new possible return value. Signed-off-by: Andrea Bolognani Reviewed-by: Peter Krempa --- src/qemu/qemu_domain.c | 74 ++++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 18 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 09f572b0b5..d992b51877 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4151,9 +4151,35 @@ qemuDomainDefaultSCSIControllerModel(const virDomain= Def *def, } =20 =20 +/** + * qemuDomainDefaultUSBControllerModel: + * @def: domain definition + * @cont: controller definition, or NULL + * @autoAdded: whether this controller is being automatically added + * @qemuCaps: QEMU capabilities, or NULL + * @parseFlags: parse flags + * + * Choose a reasonable model to use for a USB controller where a + * specific one hasn't been provided by the user. + * + * The choice is based on a number of factors, including the guest's + * architecture and machine type. @qemuCaps, if provided, might be + * taken into consideration too. + * + * @autoAdded should be true is this is a controller that libvirt is + * trying to automatically add on domain creation for the user's + * convenience: in that case, the function might decide to simply not + * add the controller instead of reporting a failure. + * + * Returns: >=3D0 (a virDomainControllerModelUSB value) on success, + * -1 on error, and + * -2 if no suitable model could be found but it's okay to + * just skip the controller altogether. + */ static int qemuDomainDefaultUSBControllerModel(const virDomainDef *def, const virDomainControllerDef *cont, + bool autoAdded, virQEMUCaps *qemuCaps, unsigned int parseFlags) { @@ -4169,7 +4195,7 @@ qemuDomainDefaultUSBControllerModel(const virDomainDe= f *def, * See qemuBuildControllersCommandLine() */ =20 if (ARCH_IS_S390(def->os.arch)) { - if (cont->info.type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) { + if (cont && 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; @@ -4198,6 +4224,22 @@ qemuDomainDefaultUSBControllerModel(const virDomainD= ef *def, return VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI; } =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. + */ + 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; + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_ICH9_USB_EHCI1)) + return VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_EHCI1; + return -2; + } + } + /* Default USB controller is piix3-uhci if available. */ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_PIIX3_USB_UHCI)) return VIR_DOMAIN_CONTROLLER_MODEL_USB_PIIX3_UHCI; @@ -4209,7 +4251,8 @@ qemuDomainDefaultUSBControllerModel(const virDomainDe= f *def, static int qemuDomainDefAddDefaultDevices(virQEMUDriver *driver, virDomainDef *def, - virQEMUCaps *qemuCaps) + virQEMUCaps *qemuCaps, + unsigned int parseFlags) { bool addDefaultUSB =3D false; int usbModel =3D -1; /* "default for machinetype" */ @@ -4243,20 +4286,6 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *driver, addPCIeRoot =3D true; addImplicitSATA =3D true; addITCOWatchdog =3D true; - - /* 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. - */ - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_QEMU_XHCI)) - usbModel =3D VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_XHCI; - else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI)) - usbModel =3D VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI; - else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_ICH9_USB_EHCI1)) - usbModel =3D VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_EHCI1; - else - addDefaultUSB =3D false; - break; } if (qemuDomainIsI440FX(def)) addPCIRoot =3D true; @@ -4348,6 +4377,15 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *driver, break; } =20 + if (addDefaultUSB) { + usbModel =3D qemuDomainDefaultUSBControllerModel(def, NULL, true, = qemuCaps, parseFlags); + /* A return value of -2 indicates that no reasonable default + * could be figured out, and that we should handle that by + * not adding the USB controller */ + if (usbModel =3D=3D -2) + addDefaultUSB =3D false; + } + if (addDefaultUSB && virDomainControllerFind(def, VIR_DOMAIN_CONTROLLER_TYPE_USB, 0) < = 0 && virDomainDefAddUSBController(def, 0, usbModel) < 0) @@ -5091,7 +5129,7 @@ qemuDomainDefPostParse(virDomainDef *def, if (qemuDomainDefBootPostParse(def, driver, parseFlags) < 0) return -1; =20 - if (qemuDomainDefAddDefaultDevices(driver, def, qemuCaps) < 0) + if (qemuDomainDefAddDefaultDevices(driver, def, qemuCaps, parseFlags) = < 0) return -1; =20 if (qemuDomainDefSetDefaultCPU(def, driver->hostarch, qemuCaps) < 0) @@ -5695,7 +5733,7 @@ qemuDomainControllerDefPostParse(virDomainControllerD= ef *cont, =20 case VIR_DOMAIN_CONTROLLER_TYPE_USB: if (cont->model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_USB_DEFAULT && = qemuCaps) { - cont->model =3D qemuDomainDefaultUSBControllerModel(def, cont,= qemuCaps, parseFlags); + cont->model =3D qemuDomainDefaultUSBControllerModel(def, cont,= false, 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