[RFC PATCH 11/15] iommufd: Add basic skeleton based on liveupdate_file_handle

Samiullah Khawaja
2025-09-28T19:07:58Z

From: YiFei Zhu <zhuyifei@google.com>

No functionality is implemented in this commit. Just registering and
unregistering of the struct liveupdate_file_handle for iommufd.

All operations are stubs returning either error or no-op.

Signed-off-by: YiFei Zhu <zhuyifei@google.com>
Signed-off-by: Samiullah Khawaja <skhawaja@google.com>
---
drivers/iommu/iommufd/Makefile | 1 +
drivers/iommu/iommufd/iommufd_private.h | 15 ++++++
drivers/iommu/iommufd/liveupdate.c | 68 +++++++++++++++++++++++++
drivers/iommu/iommufd/main.c | 14 ++++-
4 files changed, 97 insertions(+), 1 deletion(-)
create mode 100644 drivers/iommu/iommufd/liveupdate.c

diff --git a/drivers/iommu/iommufd/Makefile b/drivers/iommu/iommufd/Makefile
index 71d692c9a8f4..f37830ff7229 100644
--- a/drivers/iommu/iommufd/Makefile
+++ b/drivers/iommu/iommufd/Makefile
@@ -17,3 +17,4 @@ obj-$(CONFIG_IOMMUFD_DRIVER) += iova_bitmap.o

iommufd_driver-y := driver.o
obj-$(CONFIG_IOMMUFD_DRIVER_CORE) += iommufd_driver.o
+obj-$(CONFIG_LIVEUPDATE) += liveupdate.o
diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h
index 0da2a81eedfa..faf48ca9e555 100644
--- a/drivers/iommu/iommufd/iommufd_private.h
+++ b/drivers/iommu/iommufd/iommufd_private.h
@@ -702,6 +702,21 @@ iommufd_get_vdevice(struct iommufd_ctx *ictx, u32 id)
struct iommufd_vdevice, obj);
}

+#ifdef CONFIG_LIVEUPDATE
+int iommufd_liveupdate_register_lufs(void);
+int iommufd_liveupdate_unregister_lufs(void);
+#else
+static inline int iommufd_liveupdate_register_lufs(void)
+{
+ return 0;
+}
+
+static inline int iommufd_liveupdate_unregister_lufs(void)
+{
+ return 0;
+}
+#endif
+
#ifdef CONFIG_IOMMUFD_TEST
int iommufd_test(struct iommufd_ucmd *ucmd);
void iommufd_selftest_destroy(struct iommufd_object *obj);
diff --git a/drivers/iommu/iommufd/liveupdate.c b/drivers/iommu/iommufd/liveupdate.c
new file mode 100644
index 000000000000..6d2a64966335
--- /dev/null
+++ b/drivers/iommu/iommufd/liveupdate.c
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#define pr_fmt(fmt) "iommufd: " fmt
+
+#include <linux/file.h>
+#include <linux/iommufd.h>
+#include <linux/liveupdate.h>
+
+#include "iommufd_private.h"
+
+static int iommufd_liveupdate_prepare(struct liveupdate_file_handler *handler,
+ struct file *file, u64 *data)
+{
+ return -EOPNOTSUPP;
+}
+
+static int iommufd_liveupdate_freeze(struct liveupdate_file_handler *handler,
+ struct file *file, u64 *data)
+{
+ /* No-Op; everything should be made read-only */
+ return 0;
+}
+
+static void iommufd_liveupdate_cancel(struct liveupdate_file_handler *handler,
+ struct file *file, u64 data)
+{
+}
+
+static void iommufd_liveupdate_finish(struct liveupdate_file_handler *handler,
+ struct file *file, u64 data, bool reclaimed)
+{
+}
+
+static int iommufd_liveupdate_retrieve(struct liveupdate_file_handler *handler,
+ u64 data, struct file **file_p)
+{
+ return -EOPNOTSUPP;
+}
+
+static bool iommufd_liveupdate_can_preserve(struct liveupdate_file_handler *handler,
+ struct file *file)
+{
+ return false;
+}
+
+static struct liveupdate_file_ops iommufd_lu_file_ops = {
+ .prepare = iommufd_liveupdate_prepare,
+ .freeze = iommufd_liveupdate_freeze,
+ .cancel = iommufd_liveupdate_cancel,
+ .finish = iommufd_liveupdate_finish,
+ .retrieve = iommufd_liveupdate_retrieve,
+ .can_preserve = iommufd_liveupdate_can_preserve,
+};
+
+static struct liveupdate_file_handler iommufd_lu_handler = {
+ .compatible = "iommufd-v1",
+ .ops = &iommufd_lu_file_ops,
+};
+
+int iommufd_liveupdate_register_lufs(void)
+{
+ return liveupdate_register_file_handler(&iommufd_lu_handler);
+}
+
+int iommufd_liveupdate_unregister_lufs(void)
+{
+ return liveupdate_unregister_file_handler(&iommufd_lu_handler);
+}
diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c
index 15af7ced0501..b3bf65bc8da4 100644
--- a/drivers/iommu/iommufd/main.c
+++ b/drivers/iommu/iommufd/main.c
@@ -723,11 +723,21 @@ static int __init iommufd_init(void)
if (ret)
goto err_misc;
}
+
+ if (IS_ENABLED(CONFIG_LIVEUPDATE)) {
+ ret = iommufd_liveupdate_register_lufs();
+ if (ret)
+ goto err_vfio_misc;
+ }
+
ret = iommufd_test_init();
if (ret)
- goto err_vfio_misc;
+ goto err_lufs;
return 0;

+err_lufs:
+ if (IS_ENABLED(CONFIG_LIVEUPDATE))
+ iommufd_liveupdate_unregister_lufs();
err_vfio_misc:
if (IS_ENABLED(CONFIG_IOMMUFD_VFIO_CONTAINER))
misc_deregister(&vfio_misc_dev);
@@ -739,6 +749,8 @@ static int __init iommufd_init(void)
static void __exit iommufd_exit(void)
{
iommufd_test_exit();
+ if (IS_ENABLED(CONFIG_LIVEUPDATE))
+ iommufd_liveupdate_unregister_lufs();
if (IS_ENABLED(CONFIG_IOMMUFD_VFIO_CONTAINER))
misc_deregister(&vfio_misc_dev);
misc_deregister(&iommu_misc_dev);
--
2.51.0.536.g15c5d4f767-goog