From: Pranjal Shrivastava <praan@google.com>
To: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
Jason Gunthorpe <jgg@ziepe.ca>, Kevin Tian <kevin.tian@intel.com>,
Alex Williamson <alex@shazbot.org>,
David Matlack <dmatlack@google.com>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>
Cc: Mostafa Saleh <smostafa@google.com>,
Daniel Mentz <danielmentz@google.com>,
Samiullah Khawaja <skhawaja@google.com>,
iommu@lists.linux.dev, kvm@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org,
Logan Odell <loganodell@google.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Pranjal Shrivastava <praan@google.com>
Subject: [RFC PATCH 4/7] vfio/type1: Expose IO page table usage via fdinfo
Date: Thu, 1 Oct 2026 22:45:28 +0000 [thread overview]
Message-ID: <20261001224531.765278-5-praan@google.com> (raw)
In-Reply-To: <20261001224531.765278-1-praan@google.com>
From: Logan Odell <loganodell@google.com>
Collect the IO page table usage statistics from each IOMMU domain
attached to a legacy VFIO container and expose that data to userspace via
the new iommu-nr-pages field in fdinfo.
Introduce and implement the get_nr_pages callback for vfio-iommu-type1,
that iterates over all attached domains and aggregates their nr_pages
counters.
Only domains whose page table is implemented by the generic_pt library
account their page table memory. If any domain attached to the container
does not, get_nr_pages() returns -EOPNOTSUPP and the field is omitted
instead of reporting a partial count.
Document the new field in Documentation/filesystems/proc.rst.
Signed-off-by: Logan Odell <loganodell@google.com>
Signed-off-by: Pranjal Shrivastava <praan@google.com>
---
Documentation/filesystems/proc.rst | 17 +++++++++++++++++
drivers/vfio/container.c | 21 +++++++++++++++++++++
drivers/vfio/vfio.h | 2 ++
drivers/vfio/vfio_iommu_type1.c | 21 +++++++++++++++++++++
4 files changed, 61 insertions(+)
diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst
index c102b62023cd..2d06c9930fcf 100644
--- a/Documentation/filesystems/proc.rst
+++ b/Documentation/filesystems/proc.rst
@@ -2200,6 +2200,23 @@ VFIO Device files
where 'vfio-device-syspath' is the sysfs path corresponding to the VFIO device
file.
+VFIO Container files
+~~~~~~~~~~~~~~~~~~~~
+
+::
+
+ pos: 0
+ flags: 02000002
+ mnt_id: 17
+ ino: 1103
+ iommu-nr-pages: 11
+
+where 'iommu-nr-pages' is the number of pages of memory used by the IO page
+tables of all IOMMU domains attached to the container. It is omitted when no
+IOMMU backend is set, or when any attached domain does not account its IO page
+table memory. Currently only domains using the generic_pt page table library
+account their IO page table memory.
+
3.9 /proc/<pid>/map_files - Information about memory mapped files
---------------------------------------------------------------------
This directory contains symbolic links which represent memory mapped files
diff --git a/drivers/vfio/container.c b/drivers/vfio/container.c
index 003281dbf8bc..2cb6c5373626 100644
--- a/drivers/vfio/container.c
+++ b/drivers/vfio/container.c
@@ -7,6 +7,7 @@
#include <linux/file.h>
#include <linux/slab.h>
#include <linux/fs.h>
+#include <linux/seq_file.h>
#include <linux/capability.h>
#include <linux/iommu.h>
#include <linux/miscdevice.h>
@@ -384,12 +385,32 @@ static int vfio_fops_release(struct inode *inode, struct file *filep)
return 0;
}
+#ifdef CONFIG_PROC_FS
+static void vfio_fops_show_fdinfo(struct seq_file *m, struct file *filep)
+{
+ struct vfio_container *container = filep->private_data;
+ long nr_pages = -EOPNOTSUPP;
+
+ down_read(&container->group_lock);
+ if (container->iommu_driver && container->iommu_driver->ops->get_nr_pages)
+ nr_pages = container->iommu_driver->ops->get_nr_pages(container->iommu_data);
+ up_read(&container->group_lock);
+
+ /* Only report a count that covers every domain in the container */
+ if (nr_pages >= 0)
+ seq_printf(m, "iommu-nr-pages:\t%ld\n", nr_pages);
+}
+#endif
+
static const struct file_operations vfio_fops = {
.owner = THIS_MODULE,
.open = vfio_fops_open,
.release = vfio_fops_release,
.unlocked_ioctl = vfio_fops_unl_ioctl,
.compat_ioctl = compat_ptr_ioctl,
+#ifdef CONFIG_PROC_FS
+ .show_fdinfo = vfio_fops_show_fdinfo,
+#endif
};
struct vfio_container *vfio_container_from_file(struct file *file)
diff --git a/drivers/vfio/vfio.h b/drivers/vfio/vfio.h
index 7728bc99b63d..37e8841ad0e9 100644
--- a/drivers/vfio/vfio.h
+++ b/drivers/vfio/vfio.h
@@ -226,6 +226,8 @@ struct vfio_iommu_driver_ops {
void *data, size_t count, bool write);
struct iommu_domain *(*group_iommu_domain)(void *iommu_data,
struct iommu_group *group);
+ /* Returns IO page table pages used, or -EOPNOTSUPP if not accounted */
+ long (*get_nr_pages)(void *iommu_data);
};
struct vfio_iommu_driver {
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index c8151ba54de3..fc7c1553d574 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -3249,6 +3249,26 @@ vfio_iommu_type1_group_iommu_domain(void *iommu_data,
return domain;
}
+static long vfio_iommu_type1_get_nr_pages(void *iommu_data)
+{
+ struct vfio_iommu *iommu = iommu_data;
+ struct vfio_domain *d;
+ long total = 0;
+
+ mutex_lock(&iommu->lock);
+ list_for_each_entry(d, &iommu->domain_list, next) {
+ /* Only generic_pt page tables account their pages */
+ if (!d->domain->is_iommupt) {
+ total = -EOPNOTSUPP;
+ break;
+ }
+ total += atomic_long_read(&d->domain->nr_pages);
+ }
+ mutex_unlock(&iommu->lock);
+
+ return total;
+}
+
static const struct vfio_iommu_driver_ops vfio_iommu_driver_ops_type1 = {
.name = "vfio-iommu-type1",
.owner = THIS_MODULE,
@@ -3263,6 +3283,7 @@ static const struct vfio_iommu_driver_ops vfio_iommu_driver_ops_type1 = {
.unregister_device = vfio_iommu_type1_unregister_device,
.dma_rw = vfio_iommu_type1_dma_rw,
.group_iommu_domain = vfio_iommu_type1_group_iommu_domain,
+ .get_nr_pages = vfio_iommu_type1_get_nr_pages,
};
static int __init vfio_iommu_type1_init(void)
--
2.56.0.rc1.315.gc6ed9934b7-goog
next prev parent reply other threads:[~2026-10-01 22:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261001224531.765278-1-praan@google.com>
2026-10-01 22:45 ` [RFC PATCH 1/7] iommu: Add infrastructure for per-domain IOPT accounting Pranjal Shrivastava
2026-10-01 22:45 ` [RFC PATCH 2/7] iommu: Implement domain-attributed page allocation Pranjal Shrivastava
2026-10-01 22:45 ` [RFC PATCH 3/7] iommupt: Enable per-domain IOPT attribution Pranjal Shrivastava
2026-10-01 22:45 ` Pranjal Shrivastava [this message]
2026-10-01 22:45 ` [RFC PATCH 5/7] iommufd: Expose IO page table usage via fdinfo Pranjal Shrivastava
2026-10-01 22:45 ` [RFC PATCH 6/7] iommufd/selftest: Add observability test for iommu-nr-pages Pranjal Shrivastava
2026-10-01 22:45 ` [RFC PATCH 7/7] vfio/selftests: Add observability test for IO page table usage Pranjal Shrivastava
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261001224531.765278-5-praan@google.com \
--to=praan@google.com \
--cc=alex@shazbot.org \
--cc=corbet@lwn.net \
--cc=danielmentz@google.com \
--cc=dmatlack@google.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=loganodell@google.com \
--cc=rdunlap@infradead.org \
--cc=robin.murphy@arm.com \
--cc=skhan@linuxfoundation.org \
--cc=skhawaja@google.com \
--cc=smostafa@google.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®