On 1/19/2026 5:41 AM, Pavel Hrdina wrote:
On Fri, Jan 16, 2026 at 05:39:33PM -0800, Nathan Chen via Devel wrote:
From: Nathan Chen<[email protected]>

Implement the IOMMU_OPTION_RLIMIT_MODE
ioctl to set per-process memory accounting for
iommufd. This prevents ENOMEM errors from the
default per-user memory accounting when multiple
VMs under the libvirt-qemu user have their pinned
memory summed and checked against a per-process
RLIMIT_MEMLOCK limit.

Signed-off-by: Nathan Chen<[email protected]>
---
  meson.build              |   1 +
  po/POTFILES              |   1 +
  src/libvirt_private.syms |   3 ++
  src/util/meson.build     |   1 +
  src/util/viriommufd.c    | 111 +++++++++++++++++++++++++++++++++++++++
  src/util/viriommufd.h    |  25 +++++++++
  6 files changed, 142 insertions(+)
  create mode 100644 src/util/viriommufd.c
  create mode 100644 src/util/viriommufd.h

diff --git a/meson.build b/meson.build
index 964d1fa4e1..a6db70f13e 100644
--- a/meson.build
+++ b/meson.build
@@ -732,6 +732,7 @@ headers = [
    'ifaddrs.h',
    'libtasn1.h',
    'linux/kvm.h',
+  'linux/iommufd.h',
    'mntent.h',
    'net/ethernet.h',
    'net/if.h',
diff --git a/po/POTFILES b/po/POTFILES
index f0aad35c8c..c78d2b8000 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -303,6 +303,7 @@ src/util/virhostuptime.c
  src/util/viridentity.c
  src/util/virinhibitor.c
  src/util/virinitctl.c
+src/util/viriommufd.c
  src/util/viriscsi.c
  src/util/virjson.c
  src/util/virlease.c
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6bffd2eb6d..7fa76a1ec3 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2646,6 +2646,9 @@ virInhibitorRelease;
  virInitctlFifos;
  virInitctlSetRunLevel;
+# util/viriommufd.h
+virIOMMUFDSetRLimitMode;
+
  # util/viriscsi.h
  virISCSIConnectionLogin;
  virISCSIConnectionLogout;
diff --git a/src/util/meson.build b/src/util/meson.build
index 4950a795cc..9fb0aa0fe7 100644
--- a/src/util/meson.build
+++ b/src/util/meson.build
@@ -46,6 +46,7 @@ util_sources = [
    'viridentity.c',
    'virinhibitor.c',
    'virinitctl.c',
+  'viriommufd.c',
    'viriscsi.c',
    'virjson.c',
    'virkeycode.c',
diff --git a/src/util/viriommufd.c b/src/util/viriommufd.c
new file mode 100644
index 0000000000..225c76f4b2
--- /dev/null
+++ b/src/util/viriommufd.c
@@ -0,0 +1,111 @@
+#include <config.h>
+
+#include "viriommufd.h"
+#include "virlog.h"
+#include "virerror.h"
+#include "virfile.h"
+
+#ifdef __linux__
+
+# include <sys/ioctl.h>
+# include <linux/types.h>
+
+# ifdef HAVE_LINUX_IOMMUFD_H
+#  include <linux/iommufd.h>
+# endif
+
+# define VIR_FROM_THIS VIR_FROM_NONE
+
+VIR_LOG_INIT("util.iommufd");
Move these two before #ifdef __linux__ as they don't depend on linux and
not having VIR_FROM_THIS defines breaks compilation on non-linux systems
because the else branch calls virReportError().

Ok that makes sense, I will move these out in the next revision.

Nathan

Reply via email to