From nobody Sun Feb 8 11:20:02 2026 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 1727424537288420.0106114483284; Fri, 27 Sep 2024 01:08:57 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 3B95811D9; Fri, 27 Sep 2024 04:08:50 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 7EA5613BA; Fri, 27 Sep 2024 04:04:01 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 4E79914DE; Fri, 27 Sep 2024 04:03:56 -0400 (EDT) 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 0D5641436 for ; Fri, 27 Sep 2024 04:03:40 -0400 (EDT) Received: from mx-prod-mc-01.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-561-WPz9fdw5OriG4zvoN-VO8Q-1; Fri, 27 Sep 2024 04:03:38 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (unknown [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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6ADD9196E081 for ; Fri, 27 Sep 2024 08:03:37 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.116.143]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7F9FB1956054; Fri, 27 Sep 2024 08:03:34 +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_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=1727424219; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1NkbkIpwO4s7jIeWbHxHka0SPzjxnrTkcKkOE1vTftI=; b=Jov1m1D2idzPESwwVxECOeLmt8pfIwA4bJMcPoRM7uMGM476p59+cpcR8OLb5Xpv8z++DT 7SZ+NaoFzOTJ1WQ916fi7lB/pjdAzmi3qb2iRQAtkbLIerORWSrXXeoBdpEVVAQWENrXTR uW6iPgNcBcxucq3gaKKBv50blm9FSMs= X-MC-Unique: WPz9fdw5OriG4zvoN-VO8Q-1 From: Han Han To: devel@lists.libvirt.org Subject: [RFC PATCH 5/5] qemu: Add suppport for amd-iommu device and xtsup attrib Date: Fri, 27 Sep 2024 15:45:46 +0800 Message-ID: <20240927080309.886224-6-hhan@redhat.com> In-Reply-To: <20240927080309.886224-1-hhan@redhat.com> References: <20240927080309.886224-1-hhan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: QUEIXIG7ELOWNLD5FLDFC336NCFP6CE6 X-Message-ID-Hash: QUEIXIG7ELOWNLD5FLDFC336NCFP6CE6 X-MailFrom: hhan@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 CC: Han Han 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: 1727424539265116600 Content-Type: text/plain; charset="utf-8"; x-default="true" Fixes: https://issues.redhat.com/browse/RHEL-50560 Signed-off-by: Han Han --- docs/formatdomain.rst | 20 +++++++++- src/conf/domain_conf.c | 16 ++++++++ src/conf/domain_conf.h | 2 + src/conf/domain_validate.c | 39 ++++++++++++++++++- src/conf/schemas/domaincommon.rng | 6 +++ src/qemu/qemu_command.c | 15 +++++++ src/qemu/qemu_domain_address.c | 2 + src/qemu/qemu_validate.c | 1 + tests/qemuxmlconfdata/amd-iommu-aw-bits.err | 1 + tests/qemuxmlconfdata/amd-iommu-aw-bits.xml | 32 +++++++++++++++ .../amd-iommu-caching-mode.err | 1 + .../amd-iommu-caching-mode.xml | 32 +++++++++++++++ .../amd-iommu-device-iotlb.x86_64-latest.args | 34 ++++++++++++++++ .../amd-iommu-device-iotlb.xml | 37 ++++++++++++++++++ .../amd-iommu-dma-translation.err | 1 + .../amd-iommu-dma-translation.xml | 32 +++++++++++++++ tests/qemuxmlconfdata/amd-iommu-eim.err | 1 + tests/qemuxmlconfdata/amd-iommu-eim.xml | 32 +++++++++++++++ .../amd-iommu-xtsup.x86_64-latest.args | 34 ++++++++++++++++ tests/qemuxmlconfdata/amd-iommu-xtsup.xml | 32 +++++++++++++++ .../amd-iommu.x86_64-latest.args | 34 ++++++++++++++++ tests/qemuxmlconfdata/amd-iommu.xml | 32 +++++++++++++++ tests/qemuxmlconfdata/intel-iommu-xtsup.err | 1 + tests/qemuxmlconfdata/intel-iommu-xtsup.xml | 38 ++++++++++++++++++ tests/qemuxmlconftest.c | 8 ++++ 25 files changed, 480 insertions(+), 3 deletions(-) create mode 100644 tests/qemuxmlconfdata/amd-iommu-aw-bits.err create mode 100644 tests/qemuxmlconfdata/amd-iommu-aw-bits.xml create mode 100644 tests/qemuxmlconfdata/amd-iommu-caching-mode.err create mode 100644 tests/qemuxmlconfdata/amd-iommu-caching-mode.xml create mode 100644 tests/qemuxmlconfdata/amd-iommu-device-iotlb.x86_64-lat= est.args create mode 100644 tests/qemuxmlconfdata/amd-iommu-device-iotlb.xml create mode 100644 tests/qemuxmlconfdata/amd-iommu-dma-translation.err create mode 100644 tests/qemuxmlconfdata/amd-iommu-dma-translation.xml create mode 100644 tests/qemuxmlconfdata/amd-iommu-eim.err create mode 100644 tests/qemuxmlconfdata/amd-iommu-eim.xml create mode 100644 tests/qemuxmlconfdata/amd-iommu-xtsup.x86_64-latest.args create mode 100644 tests/qemuxmlconfdata/amd-iommu-xtsup.xml create mode 100644 tests/qemuxmlconfdata/amd-iommu.x86_64-latest.args create mode 100644 tests/qemuxmlconfdata/amd-iommu.xml create mode 100644 tests/qemuxmlconfdata/intel-iommu-xtsup.err create mode 100644 tests/qemuxmlconfdata/intel-iommu-xtsup.xml diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 4336cff3ac..866dbf4bd4 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -8587,10 +8587,20 @@ Example: ... =20 +:: + + ... + + + + + + ``model`` Supported values are ``intel`` (for Q35 guests) ``smmuv3`` - (:since:`since 5.5.0`, for ARM virt guests), and ``virtio`` - (:since:`since 8.3.0`, for Q35 and ARM virt guests). + (:since:`since 5.5.0`, for ARM virt guests), ``virtio`` + (:since:`since 8.3.0`, for Q35 and ARM virt guests), and ``amd`` (:sinc= e:`since 10.9.0`, + for Q35 guests ). =20 ``driver`` The ``driver`` subelement can be used to configure additional options, = some @@ -8631,6 +8641,12 @@ Example: example to efficiently enable more than 255 vCPUs. :since:`Since 10.7.0` (QEMU/KVM only) =20 + ``xtsup`` + The ``xtsup`` attribute with possible values ``on`` and ``off`` can b= e used to + enable XTsup mode. A q35 domain with x2apic cpu feature ( as the ``fea= ture`` paragraph + in `CPU model and topology`_), and both x2apic feature and XTsup turne= d on for IOMMU, + will be able to use more than 255 vCPUs. :since:`Since 10.9.0` (QEMU/K= VM only) + The ``virtio`` IOMMU devices can further have ``address`` element as descr= ibed in `Device addresses`_ (address has to by type of ``pci``). =20 diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6d7dee7956..6e7d92b264 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1335,6 +1335,7 @@ VIR_ENUM_IMPL(virDomainIOMMUModel, "intel", "smmuv3", "virtio", + "amd", ); =20 VIR_ENUM_IMPL(virDomainVsockModel, @@ -13933,6 +13934,10 @@ virDomainIOMMUDefParseXML(virDomainXMLOption *xmlo= pt, if (virXMLPropTristateSwitch(driver, "dma_translation", VIR_XML_PR= OP_NONE, &iommu->dma_translation) < 0) return NULL; + + if (virXMLPropTristateSwitch(driver, "xtsup", VIR_XML_PROP_NONE, + &iommu->xtsup) < 0) + return NULL; } =20 if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, @@ -21492,6 +21497,13 @@ virDomainIOMMUDefCheckABIStability(virDomainIOMMUD= ef *src, virTristateSwitchTypeToString(src->dma_translation)= ); return false; } + if (src->xtsup !=3D dst->xtsup) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target domain IOMMU device xtsup value '%1$s' do= es not match source '%2$s'"), + virTristateSwitchTypeToString(dst->xtsup), + virTristateSwitchTypeToString(src->xtsup)); + return false; + } =20 return virDomainDeviceInfoCheckABIStability(&src->info, &dst->info); } @@ -27480,6 +27492,10 @@ virDomainIOMMUDefFormat(virBuffer *buf, virBufferAsprintf(&driverAttrBuf, " dma_translation=3D'%s'", virTristateSwitchTypeToString(iommu->dma_transla= tion)); } + if (iommu->xtsup !=3D VIR_TRISTATE_SWITCH_ABSENT) { + virBufferAsprintf(&driverAttrBuf, " xtsup=3D'%s'", + virTristateSwitchTypeToString(iommu->xtsup)); + } =20 virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, NULL); =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index a15af4fae3..d527975eb3 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2919,6 +2919,7 @@ typedef enum { VIR_DOMAIN_IOMMU_MODEL_INTEL, VIR_DOMAIN_IOMMU_MODEL_SMMUV3, VIR_DOMAIN_IOMMU_MODEL_VIRTIO, + VIR_DOMAIN_IOMMU_MODEL_AMD, =20 VIR_DOMAIN_IOMMU_MODEL_LAST } virDomainIOMMUModel; @@ -2932,6 +2933,7 @@ struct _virDomainIOMMUDef { unsigned int aw_bits; virDomainDeviceInfo info; virTristateSwitch dma_translation; + virTristateSwitch xtsup; }; =20 typedef enum { diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index eddb4a5e74..344df0c559 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -2980,7 +2980,8 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *io= mmu) iommu->caching_mode !=3D VIR_TRISTATE_SWITCH_ABSENT || iommu->eim !=3D VIR_TRISTATE_SWITCH_ABSENT || iommu->iotlb !=3D VIR_TRISTATE_SWITCH_ABSENT || - iommu->aw_bits !=3D 0) { + iommu->aw_bits !=3D 0 || + iommu->xtsup !=3D VIR_TRISTATE_SWITCH_ABSENT) { virReportError(VIR_ERR_XML_ERROR, _("iommu model '%1$s' doesn't support additiona= l attributes"), virDomainIOMMUModelTypeToString(iommu->model)); @@ -2989,6 +2990,41 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *i= ommu) break; =20 case VIR_DOMAIN_IOMMU_MODEL_INTEL: + if (iommu->xtsup !=3D VIR_TRISTATE_SWITCH_ABSENT) { + virReportError(VIR_ERR_XML_ERROR, + _("iommu model '%1$s' doesn't support the xtsup= attribute"), + virDomainIOMMUModelTypeToString(iommu->model)); + return -1; + } + break; + + case VIR_DOMAIN_IOMMU_MODEL_AMD: + if (iommu->caching_mode !=3D VIR_TRISTATE_SWITCH_ABSENT) { + virReportError(VIR_ERR_XML_ERROR, + _("iommu model '%1$s' doesn't support the cachi= ng_mode attribute"), + virDomainIOMMUModelTypeToString(iommu->model)); + return -1; + } + if (iommu->eim !=3D VIR_TRISTATE_SWITCH_ABSENT) { + virReportError(VIR_ERR_XML_ERROR, + _("iommu model '%1$s' doesn't support the eim a= ttribute"), + virDomainIOMMUModelTypeToString(iommu->model)); + return -1; + } + if (iommu->aw_bits !=3D 0) { + virReportError(VIR_ERR_XML_ERROR, + _("iommu model '%1$s' doesn't support the aw_bi= ts attribute"), + virDomainIOMMUModelTypeToString(iommu->model)); + return -1; + } + if (iommu->dma_translation !=3D VIR_TRISTATE_SWITCH_ABSENT) { + virReportError(VIR_ERR_XML_ERROR, + _("iommu model '%1$s' doesn't support the dma_t= ranslation attribute"), + virDomainIOMMUModelTypeToString(iommu->model)); + return -1; + } + break; + case VIR_DOMAIN_IOMMU_MODEL_LAST: break; } @@ -2996,6 +3032,7 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *io= mmu) switch (iommu->model) { case VIR_DOMAIN_IOMMU_MODEL_SMMUV3: case VIR_DOMAIN_IOMMU_MODEL_INTEL: + case VIR_DOMAIN_IOMMU_MODEL_AMD: if (iommu->info.type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) { virReportError(VIR_ERR_XML_ERROR, _("iommu model '%1$s' can't have address"), diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincom= mon.rng index efb5f00d77..d4336c5996 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -6070,6 +6070,7 @@ intel smmuv3 virtio + amd @@ -6105,6 +6106,11 @@ + + + + + diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index a0c9e5f8b3..c3d74544db 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6040,6 +6040,20 @@ qemuBuildIOMMUCommandLine(virCommand *cmd, /* There is no -device for SMMUv3, so nothing to be done here */ return 0; =20 + case VIR_DOMAIN_IOMMU_MODEL_AMD: + if (virJSONValueObjectAdd(&props, + "s:driver", "amd-iommu", + "s:id", iommu->info.alias, + "S:intremap", qemuOnOffAuto(iommu->intre= map), + "T:device-iotlb", iommu->iotlb, + "T:xtsup", iommu->xtsup, + NULL) < 0) + return -1; + + if (qemuBuildDeviceCommandlineFromJSON(cmd, props, def, qemuCaps) = < 0) + return -1; + + return 0; case VIR_DOMAIN_IOMMU_MODEL_LAST: default: virReportEnumRangeError(virDomainIOMMUModel, iommu->model); @@ -6853,6 +6867,7 @@ qemuBuildMachineCommandLine(virCommand *cmd, =20 case VIR_DOMAIN_IOMMU_MODEL_INTEL: case VIR_DOMAIN_IOMMU_MODEL_VIRTIO: + case VIR_DOMAIN_IOMMU_MODEL_AMD: /* These IOMMUs are formatted in qemuBuildIOMMUCommandLine */ break; =20 diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 970ae3949d..37c7a59aec 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -943,6 +943,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDevic= eDef *dev, =20 case VIR_DOMAIN_IOMMU_MODEL_INTEL: case VIR_DOMAIN_IOMMU_MODEL_SMMUV3: + case VIR_DOMAIN_IOMMU_MODEL_AMD: case VIR_DOMAIN_IOMMU_MODEL_LAST: /* These are not PCI devices */ return 0; @@ -2367,6 +2368,7 @@ qemuDomainAssignDevicePCISlots(virDomainDef *def, =20 case VIR_DOMAIN_IOMMU_MODEL_INTEL: case VIR_DOMAIN_IOMMU_MODEL_SMMUV3: + case VIR_DOMAIN_IOMMU_MODEL_AMD: case VIR_DOMAIN_IOMMU_MODEL_LAST: /* These are not PCI devices */ break; diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index fa23c5f973..326b0a9460 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -5046,6 +5046,7 @@ qemuValidateDomainDeviceDefIOMMU(const virDomainIOMMU= Def *iommu, { switch (iommu->model) { case VIR_DOMAIN_IOMMU_MODEL_INTEL: + case VIR_DOMAIN_IOMMU_MODEL_AMD: if (!qemuDomainIsQ35(def)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("IOMMU device: '%1$s' is only supported with = Q35 machines"), diff --git a/tests/qemuxmlconfdata/amd-iommu-aw-bits.err b/tests/qemuxmlcon= fdata/amd-iommu-aw-bits.err new file mode 100644 index 0000000000..3958049227 --- /dev/null +++ b/tests/qemuxmlconfdata/amd-iommu-aw-bits.err @@ -0,0 +1 @@ +XML error: iommu model 'amd' doesn't support the aw_bits attribute diff --git a/tests/qemuxmlconfdata/amd-iommu-aw-bits.xml b/tests/qemuxmlcon= fdata/amd-iommu-aw-bits.xml new file mode 100644 index 0000000000..9433890f77 --- /dev/null +++ b/tests/qemuxmlconfdata/amd-iommu-aw-bits.xml @@ -0,0 +1,32 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + qemu64 + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + + + +
+ + + +