From nobody Tue Mar 24 00:57:20 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=1773938733; cv=none; d=zohomail.com; s=zohoarc; b=fYHHD4heBjtZ4lj276uOvPyTY8DKFsNJd0HNh+SrT4XvixmkVSb3Sp0AEUSJXvH9yFcyqPM92g7eDX9KTA6813rzU/DSDqtilCqUq+uY5pbmDBgd+dBNUDmka1krmd0LOfiTUGVZIfB/E3MwAhAH+RPC2QDpotZFeo7yL45hCI0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773938733; 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=8C7173bCtf18HdlMba8lYuF2unkMag6cDE8/V7lHf08=; b=kwQI4HfKT2Zle/2F8tWIHL52LGrCvQg6kMW15skm3Zn2RQLo4Qps7vrDKMw2tpnUeKqSYXqpxUYHVk1H9omTfRa9X9sL5Wbzqr3WlFTTRdnBedq+JjbPtGKH9f0DbNpbeDMznvNi8EBgD7R0tI/PitE1aDMvqpAc5c8iNGF3m3Y= 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 1773938733955646.9888982339428; Thu, 19 Mar 2026 09:45:33 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 7D67341AA9; Thu, 19 Mar 2026 12:45:33 -0400 (EDT) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 1C17841D46; Thu, 19 Mar 2026 12:40:36 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 547BD418B7; Thu, 19 Mar 2026 12:40:29 -0400 (EDT) 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 0446C41852 for ; Thu, 19 Mar 2026 12:37:12 -0400 (EDT) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-402-ISrGMYbcPpWSy-i8L84VBA-1; Thu, 19 Mar 2026 12:37:10 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7242A180044D for ; Thu, 19 Mar 2026 16:37:09 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.44.33.53]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BF01C30002DF for ; Thu, 19 Mar 2026 16:37:08 +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=-2.6 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,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=1773938232; 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=8C7173bCtf18HdlMba8lYuF2unkMag6cDE8/V7lHf08=; b=KWwsB8E80f7NnFvDOqsFb4F9ZVsZnwlgypN0l4Z4XmgBYNnBruYfLCa4GwviXwF1wvsNoe N6yUOSoiZpQdj1Owca+USJJEPAFUN6iZ6YtB02YLGnTsXqlL8mmdylnD1NaKyecJnSQbCl lLTlh9ezPHqybk6J5IEnCA04LkqM0GI= X-MC-Unique: ISrGMYbcPpWSy-i8L84VBA-1 X-Mimecast-MFC-AGG-ID: ISrGMYbcPpWSy-i8L84VBA_1773938229 To: devel@lists.libvirt.org Subject: [libvirt PATCH 09/11] conf: Add iommufd fdgroup support Date: Thu, 19 Mar 2026 17:36:55 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 3dAANHxqrq62pYVEX5MoufiYqv5shWwUVyUpFrRja5g_1773938229 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 74QESKESLA43LRWA65SGY2RELXQMRJ4Z X-Message-ID-Hash: 74QESKESLA43LRWA65SGY2RELXQMRJ4Z X-MailFrom: phrdina@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: Pavel Hrdina via Devel Reply-To: Pavel Hrdina X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1773938735874154100 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Pavel Hrdina This will allow management applications running libvirt without necessary permissions to pass FD for /dev/iommu with per-process locked memory accounting enabled. Kernel uses per-user locked memory accounting by default which may cause error while starting multiple VMs with host devices using IOMMUFD. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- docs/formatdomain.rst | 8 +++++++- src/conf/domain_conf.c | 7 +++++++ src/conf/domain_conf.h | 1 + src/conf/domain_validate.c | 16 ++++++++++++++++ src/conf/schemas/domaincommon.rng | 3 +++ tests/genericxml2xmlindata/iommufd.xml | 2 +- 6 files changed, 35 insertions(+), 2 deletions(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index f6096b2b9b..412b2b4ddd 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -1389,7 +1389,7 @@ Host Device IOMMUFD =20 ... - + ... =20 @@ -1403,6 +1403,12 @@ Host Device IOMMUFD This controls IOMMUFD usage for all host devices, each device can chang= e this global default by setting ``iommufd`` attribute for ``driver`` element. =20 + Optional ``fdgroup`` attribute can be used together with + ``virDomainFDAssociate()`` to pass /dev/iommu FD instead of letting + libvirt to open it. Caller is responsible for setting per-process locked + memory accounting otherwise starting multiple VMs with host devices usi= ng + IOMMUFD may fail. + Resource partitioning --------------------- =20 diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 950c755ad9..71488a0840 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -4242,6 +4242,8 @@ void virDomainDefFree(virDomainDef *def) g_free(def->kvm_features); g_free(def->tcg_features); =20 + g_free(def->iommufd_fdgroup); + virBlkioDeviceArrayClear(def->blkio.devices, def->blkio.ndevices); g_free(def->blkio.devices); @@ -19905,6 +19907,8 @@ virDomainDefIommufdParse(virDomainDef *def, if (virXMLPropTristateBool(nodes[0], "enabled", VIR_XML_PROP_REQUIRED,= &def->iommufd) < 0) return -1; =20 + def->iommufd_fdgroup =3D virXMLPropString(nodes[0], "fdgroup"); + return 0; } =20 @@ -28212,6 +28216,9 @@ virDomainDefIommufdFormat(virBuffer *buf, virBufferAsprintf(&attrBuf, " enabled=3D'%s'", virTristateBoolTypeToString(def->iommufd)); =20 + if (def->iommufd_fdgroup) + virBufferAsprintf(&attrBuf, " fdgroup=3D'%s'", def->iommufd_fdgrou= p); + virXMLFormatElement(buf, "iommufd", &attrBuf, NULL); } =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index f7e2eb6f5e..75acfc46bf 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3245,6 +3245,7 @@ struct _virDomainDef { virDomainFeatureTCG *tcg_features; =20 virTristateBool iommufd; + char *iommufd_fdgroup; =20 bool tseg_specified; unsigned long long tseg_size; diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 7e3da84767..a49156061f 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -2003,6 +2003,19 @@ virDomainDefValidateThrottleGroups(const virDomainDe= f *def) } =20 =20 +static int +virDomainDefValidateIommufd(const virDomainDef *def) +{ + if (def->iommufd =3D=3D VIR_TRISTATE_BOOL_NO && def->iommufd_fdgroup) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Setting 'fdgroup' when 'iommufd' is disabled is = not supported.")); + return -1; + } + + return 0; +} + + static int virDomainDefValidateInternal(const virDomainDef *def, virDomainXMLOption *xmlopt) @@ -2064,6 +2077,9 @@ virDomainDefValidateInternal(const virDomainDef *def, if (virDomainDefValidateThrottleGroups(def) < 0) return -1; =20 + if (virDomainDefValidateIommufd(def) < 0) + return -1; + return 0; } =20 diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincom= mon.rng index 0436ec8edc..db1dcd3bb7 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -1377,6 +1377,9 @@ + + + =20 diff --git a/tests/genericxml2xmlindata/iommufd.xml b/tests/genericxml2xmli= ndata/iommufd.xml index 63ea839383..10d59ca548 100644 --- a/tests/genericxml2xmlindata/iommufd.xml +++ b/tests/genericxml2xmlindata/iommufd.xml @@ -4,7 +4,7 @@ 219136 219136 1 - + hvm --=20 2.53.0