From nobody Wed Nov 27 03:28:27 2024 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=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 1730905325213185.51740076918543; Wed, 6 Nov 2024 07:02:05 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 1CA8D12A6; Wed, 6 Nov 2024 10:02:04 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 4CA3915D7; Wed, 6 Nov 2024 10:00:48 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id B00C514BF; Wed, 6 Nov 2024 10:00:44 -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 9A3341448 for ; Wed, 6 Nov 2024 10:00:38 -0500 (EST) Received: from mx-prod-mc-02.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-413-8nBtWNeXOKe8NPxYgiwR5A-1; Wed, 06 Nov 2024 10:00:35 -0500 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B6A0C1955D47 for ; Wed, 6 Nov 2024 15:00:34 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.3.236]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0DDAD19560AA for ; Wed, 6 Nov 2024 15:00:33 +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.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE 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=1730905238; 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=HKL7Jnf9MMgpIlpfn1azm2t6VNNkS2SxrCHbRj3U0OU=; b=UXWnJ0KptP3b5w2W48Bz/AkeVkKpg+2OVXqyVaHKY9KVCxZ217kztFpGhFvohGpTn0o7Ci NxMcO8P4PHa40Roc4a9xgToAI3gcIRNIIkwxEweN6p5cIy3f8S9UOXb78qnhBUWINWxctU PvkKFTi95ahazVRIq+nHXkSBmsF+Ljg= X-MC-Unique: 8nBtWNeXOKe8NPxYgiwR5A-1 X-Mimecast-MFC-AGG-ID: 8nBtWNeXOKe8NPxYgiwR5A From: Michal Privoznik To: devel@lists.libvirt.org Subject: [PATCH 3/3] qemu_domain: Automagically add IOMMU if needed Date: Wed, 6 Nov 2024 16:00:28 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ah88Do7CMc73ClliuGZzjuItafHD3fmVZT82wZjAs8Q_1730905234 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: MRRZNIULM2X27VAEBKNLP7XZZFMLILRD X-Message-ID-Hash: MRRZNIULM2X27VAEBKNLP7XZZFMLILRD X-MailFrom: mprivozn@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: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1730905325948116600 Content-Type: text/plain; charset="utf-8"; x-default="true" If a Q35 domain has huge number of vCPUS (over 255, currently), then it needs IOMMU with Extended Interrupt Mode enabled (see check in qemuValidateDomainVCpuTopology()). Well, we already add some devices and to other tricks when parsing new domain XML. Might as well add IOMMU device if above condition is met. Resolves: https://issues.redhat.com/browse/RHEL-65844 Signed-off-by: Michal Privoznik --- src/qemu/qemu_domain.c | 19 +++++++++++++++++++ .../intel-iommu-eim-autoadd.xml | 1 - 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 39f3e38351..f07f0505b1 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4262,6 +4262,7 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *driver, bool addDefaultUSBMouse =3D false; bool addPanicDevice =3D false; bool addITCOWatchdog =3D false; + bool addIOMMU =3D false; =20 /* add implicit input devices */ if (qemuDomainDefAddImplicitInputDevice(def, qemuCaps) < 0) @@ -4284,6 +4285,10 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *driver, addImplicitSATA =3D true; addITCOWatchdog =3D true; =20 + if (virDomainDefGetVcpusMax(def) > QEMU_MAX_VCPUS_WITHOUT_EIM)= { + addIOMMU =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. @@ -4530,6 +4535,20 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *driver, } } =20 + if (addIOMMU && !def->iommu && + virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_INTEL_IOMMU) && + virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_EIM)) { + g_autoptr(virDomainIOMMUDef) iommu =3D NULL; + + iommu =3D virDomainIOMMUDefNew(); + iommu->model =3D VIR_DOMAIN_IOMMU_MODEL_INTEL; + /* eim requires intremap. */ + iommu->intremap =3D VIR_TRISTATE_SWITCH_ON; + iommu->eim =3D VIR_TRISTATE_SWITCH_ON; + + def->iommu =3D g_steal_pointer(&iommu); + } + if (qemuDomainDefAddDefaultAudioBackend(driver, def) < 0) return -1; =20 diff --git a/tests/qemuxmlconfdata/intel-iommu-eim-autoadd.xml b/tests/qemu= xmlconfdata/intel-iommu-eim-autoadd.xml index 7c294fe2f9..fa3aaf0d44 100644 --- a/tests/qemuxmlconfdata/intel-iommu-eim-autoadd.xml +++ b/tests/qemuxmlconfdata/intel-iommu-eim-autoadd.xml @@ -30,6 +30,5 @@