From: Ryan Roberts <ryan.roberts@arm.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Arnd Bergmann <arnd@arndb.de>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>,
Alex Williamson <alex@shazbot.org>,
Jason Gunthorpe <jgg@nvidia.com>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Jean-Philippe Brucker <jpb@kernel.org>,
Oded Gabbay <ogabbay@kernel.org>,
Jonathan Corbet <corbet@lwn.net>
Cc: Ryan Roberts <ryan.roberts@arm.com>,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
kvm@vger.kernel.org, devicetree@vger.kernel.org,
dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org
Subject: [RFC PATCH v2 12/15] vfio: Support VFIO devices that access the CPU MMU
Date: Thu, 15 Oct 2026 15:25:46 +0100 [thread overview]
Message-ID: <20261015142552.4128028-13-ryan.roberts@arm.com> (raw)
In-Reply-To: <20261015142552.4128028-1-ryan.roberts@arm.com>
From: Jean-Philippe Brucker <jpb@kernel.org>
Support devices that are attached to a CPU and perform DMA through a
MMU. They do not have an IOMMU and do not use a VFIO container.
The VMM needs device-specific knowledge in order to create a virtual
device (device tree, ACPI tables), so it also knows not to allocate a
container.
Signed-off-by: Jean-Philippe Brucker <jpb@kernel.org>
---
drivers/vfio/group.c | 37 +++++++++++++++++++++++++++++--------
drivers/vfio/vfio.h | 5 +++++
drivers/vfio/vfio_main.c | 16 +++++++++++++++-
include/linux/vfio.h | 1 +
4 files changed, 50 insertions(+), 9 deletions(-)
diff --git a/drivers/vfio/group.c b/drivers/vfio/group.c
index b2299e5bc6df..99d85880a41c 100644
--- a/drivers/vfio/group.c
+++ b/drivers/vfio/group.c
@@ -120,7 +120,7 @@ static int vfio_group_ioctl_set_container(struct vfio_group *group,
return -EBADF;
mutex_lock(&group->group_lock);
- if (vfio_group_has_iommu(group)) {
+ if (vfio_group_has_iommu(group) || group->type == VFIO_CPU_MMU) {
ret = -EINVAL;
goto out_unlock;
}
@@ -173,7 +173,8 @@ static int vfio_df_group_open(struct vfio_device_file *df)
int ret;
mutex_lock(&device->group->group_lock);
- if (!vfio_group_has_iommu(device->group)) {
+ if (!vfio_group_has_iommu(device->group) &&
+ device->group->type != VFIO_CPU_MMU) {
ret = -EINVAL;
goto out_unlock;
}
@@ -635,7 +636,8 @@ static bool vfio_group_has_device(struct vfio_group *group, struct device *dev)
return false;
}
-static struct vfio_group *vfio_group_find_or_alloc(struct device *dev)
+static struct vfio_group *vfio_group_find_or_alloc(struct device *dev,
+ enum vfio_group_type type)
{
struct iommu_group *iommu_group;
struct vfio_group *group;
@@ -662,12 +664,13 @@ static struct vfio_group *vfio_group_find_or_alloc(struct device *dev)
mutex_lock(&vfio.group_lock);
group = vfio_group_find_from_iommu(iommu_group);
if (group) {
- if (WARN_ON(vfio_group_has_device(group, dev)))
+ if (WARN_ON(vfio_group_has_device(group, dev)) ||
+ WARN_ON(group->type != type))
group = ERR_PTR(-EINVAL);
else
refcount_inc(&group->drivers);
} else {
- group = vfio_create_group(iommu_group, VFIO_IOMMU);
+ group = vfio_create_group(iommu_group, type);
}
mutex_unlock(&vfio.group_lock);
@@ -681,10 +684,18 @@ int vfio_device_set_group(struct vfio_device *device,
{
struct vfio_group *group;
- if (type == VFIO_IOMMU)
- group = vfio_group_find_or_alloc(device->dev);
- else
+ switch (type) {
+ case VFIO_IOMMU:
+ case VFIO_CPU_MMU:
+ group = vfio_group_find_or_alloc(device->dev, type);
+ break;
+ case VFIO_EMULATED_IOMMU:
+ case VFIO_NO_IOMMU:
group = vfio_noiommu_group_alloc(device->dev, type);
+ break;
+ default:
+ group = ERR_PTR(-EINVAL);
+ }
if (IS_ERR(group))
return PTR_ERR(group);
@@ -761,6 +772,11 @@ int vfio_device_group_use_iommu(struct vfio_device *device)
lockdep_assert_held(&group->group_lock);
+ if (group->type == VFIO_CPU_MMU) {
+ get_file(group->opened_file);
+ return 0;
+ }
+
if (WARN_ON(!group->container))
return -EINVAL;
@@ -777,6 +793,11 @@ void vfio_device_group_unuse_iommu(struct vfio_device *device)
lockdep_assert_held(&group->group_lock);
+ if (group->type == VFIO_CPU_MMU) {
+ fput(group->opened_file);
+ return;
+ }
+
if (WARN_ON(!group->container))
return;
diff --git a/drivers/vfio/vfio.h b/drivers/vfio/vfio.h
index 7728bc99b63d..07c5223612d3 100644
--- a/drivers/vfio/vfio.h
+++ b/drivers/vfio/vfio.h
@@ -64,6 +64,11 @@ enum vfio_group_type {
* taint the kernel.
*/
VFIO_NO_IOMMU,
+
+ /*
+ * Physical devices using the CPU MMU
+ */
+ VFIO_CPU_MMU,
};
#if IS_ENABLED(CONFIG_VFIO_GROUP)
diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
index 423ead48aafe..41fee81a14cb 100644
--- a/drivers/vfio/vfio_main.c
+++ b/drivers/vfio/vfio_main.c
@@ -344,7 +344,8 @@ static int __vfio_register_dev(struct vfio_device *device,
{
int ret;
- if (WARN_ON(IS_ENABLED(CONFIG_IOMMUFD) &&
+ if (type != VFIO_CPU_MMU &&
+ WARN_ON(IS_ENABLED(CONFIG_IOMMUFD) &&
(!device->ops->bind_iommufd ||
!device->ops->unbind_iommufd ||
!device->ops->attach_ioas ||
@@ -415,6 +416,19 @@ int vfio_register_emulated_iommu_dev(struct vfio_device *device)
}
EXPORT_SYMBOL_GPL(vfio_register_emulated_iommu_dev);
+/*
+ * Register a devices that accesses memory through the CPU MMU. Although it
+ * doesn't use an IOMMU, the device must have an IOMMU group.
+ */
+int vfio_register_cpu_mmu_dev(struct vfio_device *device)
+{
+ if (!IS_ENABLED(CONFIG_VFIO_GROUP))
+ return -EOPNOTSUPP;
+
+ return __vfio_register_dev(device, VFIO_CPU_MMU);
+}
+EXPORT_SYMBOL_GPL(vfio_register_cpu_mmu_dev);
+
/*
* Decrement the device reference count and wait for the device to be
* removed. Open file descriptors for the device... */
diff --git a/include/linux/vfio.h b/include/linux/vfio.h
index 45f08986359e..7d3a5ff1ad00 100644
--- a/include/linux/vfio.h
+++ b/include/linux/vfio.h
@@ -337,6 +337,7 @@ static inline void vfio_put_device(struct vfio_device *device)
put_device(&device->device);
}
+int vfio_register_cpu_mmu_dev(struct vfio_device *device);
int vfio_register_group_dev(struct vfio_device *device);
int vfio_register_emulated_iommu_dev(struct vfio_device *device);
void vfio_unregister_group_dev(struct vfio_device *device);
--
2.43.0
next prev parent reply other threads:[~2026-10-15 14:26 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 14:25 [RFC PATCH v2 00/15] Arm Core Local Accelerator Driver Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 01/15] misc/arm-cla: Add driver skeleton and documentation Ryan Roberts
2026-10-15 14:35 ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 02/15] misc/arm-cla: Add launch operation helpers Ryan Roberts
2026-10-15 14:42 ` sashiko-bot
2026-10-15 16:17 ` Greg Kroah-Hartman
2026-10-15 14:25 ` [RFC PATCH v2 03/15] dt-bindings: misc: Add Arm Core Local Accelerator Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 04/15] misc/arm-cla: Probe firmware-described devices Ryan Roberts
2026-10-15 14:37 ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 05/15] misc/arm-cla: Initialize devices on CPU bringup Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 06/15] misc/arm-cla: Accelerator context save and restore Ryan Roberts
2026-10-15 14:41 ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 07/15] misc/arm-cla: Set up memory translation context Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 08/15] misc/arm-cla: Manage domain contexts Ryan Roberts
2026-10-15 14:38 ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 09/15] misc/arm-cla: Add userspace interface Ryan Roberts
2026-10-15 14:47 ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 10/15] KVM: arm64: Introduce support to pin VMIDs Ryan Roberts
2026-10-15 14:38 ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 11/15] KVM: arm64: Export stage-2 MMU config Ryan Roberts
2026-10-15 14:43 ` sashiko-bot
2026-10-15 14:25 ` Ryan Roberts [this message]
2026-10-15 14:44 ` [RFC PATCH v2 12/15] vfio: Support VFIO devices that access the CPU MMU sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 13/15] misc/arm-cla: Add stage-2 MTC and VM context switch Ryan Roberts
2026-10-15 14:40 ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 14/15] misc/arm-cla: Support exclusive context assignment Ryan Roberts
2026-10-15 14:41 ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 15/15] misc/arm-cla: Add vfio-mdev user interface Ryan Roberts
2026-10-15 14:49 ` sashiko-bot
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=20261015142552.4128028-13-ryan.roberts@arm.com \
--to=ryan.roberts@arm.com \
--cc=alex@shazbot.org \
--cc=arnd@arndb.de \
--cc=catalin.marinas@arm.com \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gregkh@linuxfoundation.org \
--cc=jgg@nvidia.com \
--cc=jpb@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=ogabbay@kernel.org \
--cc=oupton@kernel.org \
--cc=robh@kernel.org \
--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