From nobody Thu Nov 21 17:25:07 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 1730905304761158.91767375274105; Wed, 6 Nov 2024 07:01:44 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id B7B451586; Wed, 6 Nov 2024 10:01:43 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 9125F1631; Wed, 6 Nov 2024 10:00:42 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 0B56213B9; Wed, 6 Nov 2024 10:00:37 -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 50C941399 for ; Wed, 6 Nov 2024 10:00:36 -0500 (EST) Received: from mx-prod-mc-05.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-352-70srx0pKMoak4XehFl7l7Q-1; Wed, 06 Nov 2024 10:00:34 -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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9B0311955F29 for ; Wed, 6 Nov 2024 15:00:33 +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 E94281956054 for ; Wed, 6 Nov 2024 15:00:32 +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_H3,RCVD_IN_MSPIKE_WL,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=1730905236; 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=PCnbU/RUJ6lMTD25e8zB7O8MOw7ZRLdVJ2Yrew7zY4I=; b=QG4eCgv64ankECR7zEQ72WtoMUxzLH83aAbCSfb4MUO5hGj+/EXBQ0yqzQkG2ItXAbli8l q5dWkoOLFjbxkTTbehlVepgxz3hv+Bv9ys74cwhzuc48GY1STZnfDM6CJmLmh1pzkr8k1k Ow8q0fAt1QugxbCv088+/2jaNZOL1Ek= X-MC-Unique: 70srx0pKMoak4XehFl7l7Q-1 X-Mimecast-MFC-AGG-ID: 70srx0pKMoak4XehFl7l7Q From: Michal Privoznik To: devel@lists.libvirt.org Subject: [PATCH 2/3] qemu: Turn EIM IOMMU on automagically Date: Wed, 6 Nov 2024 16:00:27 +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: 8qsTU6SkKI1pHAThbBhUZsOjv-fQgI54vb4zKxd7O-4_1730905233 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: UJJ4GSV5J3GXP7EVJ2BIFFLYUBMSESCC X-Message-ID-Hash: UJJ4GSV5J3GXP7EVJ2BIFFLYUBMSESCC 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: 1730905305858116600 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 turn the EIM on for IOMMU device. Signed-off-by: Michal Privoznik --- src/qemu/qemu_domain.c | 37 ++++++++++++++++++- src/qemu/qemu_validate.c | 1 - src/qemu/qemu_validate.h | 2 + ...-eim-autoadd.x86_64-latest.abi-update.args | 34 +++++++++++++++++ ...u-eim-autoadd.x86_64-latest.abi-update.xml | 37 +++++++++++++++++++ .../intel-iommu-eim-autoadd.xml | 35 ++++++++++++++++++ tests/qemuxmlconftest.c | 1 + 7 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 tests/qemuxmlconfdata/intel-iommu-eim-autoadd.x86_64-la= test.abi-update.args create mode 100644 tests/qemuxmlconfdata/intel-iommu-eim-autoadd.x86_64-la= test.abi-update.xml create mode 100644 tests/qemuxmlconfdata/intel-iommu-eim-autoadd.xml diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 7b702cfc6b..39f3e38351 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -6453,6 +6453,37 @@ qemuDomainPstoreDefPostParse(virDomainPstoreDef *pst= ore, } =20 =20 +static int +qemuDomainIOMMUDefPostParse(virDomainIOMMUDef *iommu, + const virDomainDef *def, + virQEMUCaps *qemuCaps, + unsigned int parseFlags) +{ + /* In case domain has huge number of vCPUS and Extended Interrupt Mode + * (EIM) is not explicitly turned off, let's enable it. If we didn't t= hen + * guest will have troubles with interrupts. */ + if (parseFlags & VIR_DOMAIN_DEF_PARSE_ABI_UPDATE && + ARCH_IS_X86(def->os.arch) && + virDomainDefGetVcpusMax(def) > QEMU_MAX_VCPUS_WITHOUT_EIM && + qemuDomainIsQ35(def) && + iommu && iommu->model =3D=3D VIR_DOMAIN_IOMMU_MODEL_INTEL) { + + /* eim requires intremap. */ + if (iommu->intremap =3D=3D VIR_TRISTATE_SWITCH_ABSENT && + virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_INTREMAP)) { + iommu->intremap =3D VIR_TRISTATE_SWITCH_ON; + } + + if (iommu->eim =3D=3D VIR_TRISTATE_SWITCH_ABSENT && + virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_EIM)) { + iommu->eim =3D VIR_TRISTATE_SWITCH_ON; + } + } + + return 0; +} + + static int qemuDomainDeviceDefPostParse(virDomainDeviceDef *dev, const virDomainDef *def, @@ -6518,6 +6549,11 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDef *dev, ret =3D qemuDomainPstoreDefPostParse(dev->data.pstore, def, driver= ); break; =20 + case VIR_DOMAIN_DEVICE_IOMMU: + ret =3D qemuDomainIOMMUDefPostParse(dev->data.iommu, def, + qemuCaps, parseFlags); + break; + case VIR_DOMAIN_DEVICE_LEASE: case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_INPUT: @@ -6530,7 +6566,6 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDef *dev, case VIR_DOMAIN_DEVICE_MEMBALLOON: case VIR_DOMAIN_DEVICE_NVRAM: case VIR_DOMAIN_DEVICE_RNG: - case VIR_DOMAIN_DEVICE_IOMMU: case VIR_DOMAIN_DEVICE_AUDIO: case VIR_DOMAIN_DEVICE_CRYPTO: ret =3D 0; diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index fa23c5f973..aaa056379e 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -31,7 +31,6 @@ #include "virutil.h" =20 #define VIR_FROM_THIS VIR_FROM_QEMU -#define QEMU_MAX_VCPUS_WITHOUT_EIM 255 =20 VIR_LOG_INIT("qemu.qemu_validate"); =20 diff --git a/src/qemu/qemu_validate.h b/src/qemu/qemu_validate.h index e06a43b8e3..9315be73f5 100644 --- a/src/qemu/qemu_validate.h +++ b/src/qemu/qemu_validate.h @@ -22,6 +22,8 @@ =20 #include "qemu_capabilities.h" =20 +#define QEMU_MAX_VCPUS_WITHOUT_EIM 255 + int qemuValidateDomainDef(const virDomainDef *def, void *opaque, diff --git a/tests/qemuxmlconfdata/intel-iommu-eim-autoadd.x86_64-latest.ab= i-update.args b/tests/qemuxmlconfdata/intel-iommu-eim-autoadd.x86_64-latest= .abi-update.args new file mode 100644 index 0000000000..07fa1191b7 --- /dev/null +++ b/tests/qemuxmlconfdata/intel-iommu-eim-autoadd.x86_64-latest.abi-updat= e.args @@ -0,0 +1,34 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ +/usr/bin/qemu-system-x86_64 \ +-name guest=3DQEMUGuest1,debug-threads=3Don \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/va= r/lib/libvirt/qemu/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine q35,usb=3Doff,kernel_irqchip=3Dsplit,dump-guest-core=3Doff,memory= -backend=3Dpc.ram,acpi=3Doff \ +-accel kvm \ +-cpu qemu64 \ +-m size=3D219136k \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}'= \ +-overcommit mem-lock=3Doff \ +-smp 288,sockets=3D288,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":"intel-iommu","id":"iommu0","intremap":"on","eim":"on"}= ' \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-global ICH9-LPC.noreboot=3Doff \ +-watchdog-action reset \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,resource= control=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxmlconfdata/intel-iommu-eim-autoadd.x86_64-latest.ab= i-update.xml b/tests/qemuxmlconfdata/intel-iommu-eim-autoadd.x86_64-latest.= abi-update.xml new file mode 100644 index 0000000000..1caa0ceb60 --- /dev/null +++ b/tests/qemuxmlconfdata/intel-iommu-eim-autoadd.x86_64-latest.abi-updat= e.xml @@ -0,0 +1,37 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 288 + + hvm + + + + + + + qemu64 + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + + + +
+ + + +