From nobody Mon Feb 2 07:30:15 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=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1769421365; cv=none; d=zohomail.com; s=zohoarc; b=Pwza493vtzGu2eJfpILrIJK+TpBCX1pTQ6f8Z0+YW97DqyoAPSws1otfgw4Dq5FCT8RMAbDDJqC3Uf8lQIFMfiwHmFgiHjObcFDzuwOi7eQpQqqJenVr6V3OBwmOF83pY7hDi9qgdWpwt92h/KE3NNb8mDL9RLzYOuVPCD2Ie9c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769421365; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=8GiHcDb7HwGpHc1kwL78gc8mpoEKJsTD+slGEEU3RgQ=; b=OJcBDABKgMIOSE3kFDh4HMzYgBoZs2qOzcL53gjgo72Pc+8lXfCdvEFhEM43gNhP0rDBv2bz0zfpMM4/021vgkRDIAAiu44WYTfFNZD6Mx7q/y69iS+/HTiSVVox0AANyMQ3ooS3Ol5njqW3jCGZQPpfGF7K/gQxQG26WSI5mLw= ARC-Authentication-Results: i=1; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1769421365037678.3612188367553; Mon, 26 Jan 2026 01:56:05 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 8644741A6F; Mon, 26 Jan 2026 04:56:04 -0500 (EST) Received: from [172.19.199.3] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 39DC343F14; Mon, 26 Jan 2026 04:50:44 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id A061B41C26; Mon, 26 Jan 2026 04:50:37 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 823234191F for ; Mon, 26 Jan 2026 04:50:32 -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-502-ORDdiiQ3MWSoqM5bmuXU2g-1; Mon, 26 Jan 2026 04:50:29 -0500 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 0674819775A8 for ; Mon, 26 Jan 2026 09:50:29 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 61A971956095 for ; Mon, 26 Jan 2026 09:50:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769421032; 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=8GiHcDb7HwGpHc1kwL78gc8mpoEKJsTD+slGEEU3RgQ=; b=US0JGYvB4OTKrNxt4JZG8M5tHEp4QtyAK15qj0eY71t8Ecu0LOKJjw/U4NQ0fQcTcD1+b9 qEmadMmx8xC2vJL9uj4RNVzxQhpI3cs0aGSZN/ZvLrfSv1Br7wTPik8p+VoPgciv1qXU5q TrQMt4axl2DlztjUSQM5p1YkWyd6NTI= X-MC-Unique: ORDdiiQ3MWSoqM5bmuXU2g-1 X-Mimecast-MFC-AGG-ID: ORDdiiQ3MWSoqM5bmuXU2g_1769421029 To: devel@lists.libvirt.org Subject: [PATCH v2 5/7] conf: Introduce granule attribute for virtio-iommu Date: Mon, 26 Jan 2026 10:50:19 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: QOxOD088k85ctc-x64X_gJ9Um2U-x5R0T8AV-zRjI0U_1769421029 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 5IM2DOC4Q6NUWBXY7G3H3LOC2N56QSSJ X-Message-ID-Hash: 5IM2DOC4Q6NUWBXY7G3H3LOC2N56QSSJ X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1769421367448154100 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik In PCI assignment scenario the virtio-iommu needs to know the guest page size also known as granule. Expose it as an attribute to the element of a virtio-iommu. This is possibly interesting only for aarch64 since it supports virtio-iommu and also supports running guests with different page size than the host. Signed-off-by: Michal Privoznik --- docs/formatdomain.rst | 38 ++++++++- src/conf/domain_conf.c | 77 ++++++++++++++++++- src/conf/domain_conf.h | 1 + src/conf/domain_validate.c | 9 ++- src/conf/schemas/domaincommon.rng | 22 ++++++ src/qemu/qemu_validate.c | 11 +++ .../virtio-iommu-aarch64.aarch64-latest.xml | 4 +- .../qemuxmlconfdata/virtio-iommu-aarch64.xml | 4 +- .../virtio-iommu-x86_64.x86_64-latest.xml | 3 + tests/qemuxmlconfdata/virtio-iommu-x86_64.xml | 6 +- 10 files changed, 166 insertions(+), 9 deletions(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 4b34a8a963..50563741a0 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -9194,7 +9194,7 @@ IOMMU devices =20 The ``iommu`` element can be used to add an IOMMU device. :since:`Since 2.= 1.0` =20 -Example: +Examples: =20 :: =20 @@ -9206,6 +9206,17 @@ Example: ... =20 + + ... + + + + + + + + ... + ``model`` Supported values are ``intel`` (for Q35 guests) ``smmuv3`` (:since:`since 5.5.0`, for ARM virt guests), ``virtio`` @@ -9264,6 +9275,31 @@ Example: The ``pciBus`` attribute notes the index of the controller that an IOMMU device is attached to. (QEMU/KVM and ``smmuv3`` model only) =20 +In case of ``virtio`` IOMMU device, the ``driver`` element can optionally +contain ``granule`` subelement that allows to choose which granule will be +used by default. It is useful when running guests with different page size +than the host. :since:`Since 12.1.0` (QEMU/KVM and ``virtio`` model only). +There are two possible options: + +:: + + + + + + + + + + + + + +The ``mode=3D'host'`` case matches the host page size, the other sets desi= red +granule size. Please note that hypervisor might support only some selected +values. For instance, QEMU supports only 4KiB, 8KiB, 16KiB and 64KiB large +granules. + 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 1b2a439ca4..4503fc0095 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1592,6 +1592,21 @@ VIR_ENUM_IMPL(virDomainChrSourceMode, ); =20 =20 +/*virDomainIOMMUGranuleModeTypeToString: + * @val: value to format + * + * Reuturns: an allocated string. Caller must free it. + */ +static char * +virDomainIOMMUGranuleModeTypeToString(int val) +{ + if (val =3D=3D -1) + return g_strdup("host"); + + return g_strdup_printf("%dKiB", val); +} + + static virClass *virDomainObjClass; static virClass *virDomainXMLOptionClass; static void virDomainObjDispose(void *obj); @@ -14487,6 +14502,8 @@ virDomainIOMMUDefParseXML(virDomainXMLOption *xmlop= t, return NULL; =20 if ((driver =3D virXPathNode("./driver", ctxt))) { + xmlNodePtr granule; + if (virXMLPropTristateSwitch(driver, "intremap", VIR_XML_PROP_NONE, &iommu->intremap) < 0) return NULL; @@ -14522,6 +14539,41 @@ virDomainIOMMUDefParseXML(virDomainXMLOption *xmlo= pt, if (virXMLPropInt(driver, "pciBus", 10, VIR_XML_PROP_NONE, &iommu->pci_bus, -1) < 0) return NULL; + + if ((granule =3D virXPathNode("./driver/granule", ctxt))) { + g_autofree char *mode =3D virXMLPropString(granule, "mode"); + unsigned long long size; + int rc; + + rc =3D virDomainParseMemory("./driver/granule/@size", + "./driver/granule/@unit", + ctxt, &size, false, false); + if (rc < 0) { + return NULL; + } else if (rc > 0) { + if (mode) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("'mode' and 'size' can't be specified= at the same time for 'granule'")); + return NULL; + } + + if (size !=3D (int) size) { + virReportError(VIR_ERR_OVERFLOW, "%s", _("size value t= oo large")); + return NULL; + } + + iommu->granule =3D (int)size; + } else { + if (STREQ_NULLABLE(mode, "host")) { + iommu->granule =3D -1; + } else if (mode) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%1$s' i= n element '%2$s': '%3$s'."), + "mode", "granule", mode); + return NULL; + } + } + } } =20 if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, @@ -16585,7 +16637,8 @@ virDomainIOMMUDefEquals(const virDomainIOMMUDef *a, a->eim !=3D b->eim || a->iotlb !=3D b->iotlb || a->aw_bits !=3D b->aw_bits || - a->dma_translation !=3D b->dma_translation) + a->dma_translation !=3D b->dma_translation || + a->granule !=3D b->granule) return false; =20 if (a->info.type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE && @@ -22340,6 +22393,16 @@ virDomainIOMMUDefCheckABIStability(virDomainIOMMUD= ef *src, virTristateSwitchTypeToString(src->xtsup)); return false; } + if (src->granule !=3D dst->granule) { + g_autofree char *src_granule =3D virDomainIOMMUGranuleModeTypeToSt= ring(src->granule); + g_autofree char *dst_granule =3D virDomainIOMMUGranuleModeTypeToSt= ring(dst->granule); + + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target domain IOMMU device granule '%1$s' does n= ot match source '%2$s'"), + dst_granule, + src_granule); + return false; + } =20 return virDomainDeviceInfoCheckABIStability(&src->info, &dst->info); } @@ -28628,6 +28691,7 @@ virDomainIOMMUDefFormat(virBuffer *buf, g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; g_auto(virBuffer) driverAttrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) driverChildBuf =3D VIR_BUFFER_INIT_CHILD(&childBuf); =20 if (iommu->intremap !=3D VIR_TRISTATE_SWITCH_ABSENT) { virBufferAsprintf(&driverAttrBuf, " intremap=3D'%s'", @@ -28665,8 +28729,17 @@ virDomainIOMMUDefFormat(virBuffer *buf, virBufferAsprintf(&driverAttrBuf, " pciBus=3D'%d'", iommu->pci_bus); } + if (iommu->granule !=3D 0) { + if (iommu->granule =3D=3D -1) { + virBufferAddLit(&driverChildBuf, "\n"); + } else { + virBufferAsprintf(&driverChildBuf, + "\n", + iommu->granule); + } + } =20 - virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, NULL); + virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, &driverChildB= uf); =20 virDomainDeviceInfoFormat(&childBuf, &iommu->info, 0); =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 83d49969d3..72badb32a6 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3062,6 +3062,7 @@ struct _virDomainIOMMUDef { virTristateSwitch dma_translation; virTristateSwitch xtsup; virTristateSwitch pt; + int granule; /* -1 means 'host', 0 unset, page size in KiB otherwise */ }; =20 typedef enum { diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index c83fff132b..1ad614935f 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -3194,7 +3194,8 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *io= mmu) iommu->aw_bits !=3D 0 || iommu->dma_translation !=3D VIR_TRISTATE_SWITCH_ABSENT || iommu->xtsup !=3D VIR_TRISTATE_SWITCH_ABSENT || - iommu->pt !=3D VIR_TRISTATE_SWITCH_ABSENT) { + iommu->pt !=3D VIR_TRISTATE_SWITCH_ABSENT || + iommu->granule !=3D 0) { virReportError(VIR_ERR_XML_ERROR, _("iommu model '%1$s' doesn't support some addi= tional attributes"), virDomainIOMMUModelTypeToString(iommu->model)); @@ -3229,7 +3230,8 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *io= mmu) iommu->eim !=3D VIR_TRISTATE_SWITCH_ABSENT || iommu->aw_bits !=3D 0 || iommu->dma_translation !=3D VIR_TRISTATE_SWITCH_ABSENT || - iommu->pci_bus >=3D 0) { + iommu->pci_bus >=3D 0 || + iommu->granule !=3D 0) { virReportError(VIR_ERR_XML_ERROR, _("iommu model '%1$s' doesn't support some addi= tional attributes"), virDomainIOMMUModelTypeToString(iommu->model)); @@ -3240,7 +3242,8 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *io= mmu) case VIR_DOMAIN_IOMMU_MODEL_INTEL: if (iommu->pt !=3D VIR_TRISTATE_SWITCH_ABSENT || iommu->xtsup !=3D VIR_TRISTATE_SWITCH_ABSENT || - iommu->pci_bus >=3D 0) { + iommu->pci_bus >=3D 0 || + iommu->granule !=3D 0) { virReportError(VIR_ERR_XML_ERROR, _("iommu model '%1$s' doesn't support some addi= tional attributes"), virDomainIOMMUModelTypeToString(iommu->model)); diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincom= mon.rng index 114dd3f96f..3d5eb7d4f3 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -6329,6 +6329,28 @@ + + + + + + host + + + + + + + + + + + + + + + + diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index ab8a1938c1..8f85334cf9 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -5685,6 +5685,17 @@ qemuValidateDomainDeviceDefIOMMU(const virDomainIOMM= UDef *iommu, return -1; } =20 + /* QEMU supports only 4KiB, 8KiB, 16KiB and 64KiB granule size */ + if (iommu->granule > 0 && + !(iommu->granule =3D=3D 4 || + iommu->granule =3D=3D 8 || + iommu->granule =3D=3D 16 || + iommu->granule =3D=3D 64)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("iommu: unsupported granule size. Supported value= s are 4, 8, 16 and 64 KiB")); + return -1; + } + return 0; } =20 diff --git a/tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.xml = b/tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.xml index 4ae628ab5a..ad2fedaab7 100644 --- a/tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.xml +++ b/tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.xml @@ -29,7 +29,9 @@