[RFC PATCH v2 20/32] iommu: Add APIs to get preserved state of a device
From: Samiullah Khawaja
Date: Tue Dec 02 2025 - 18:06:57 EST
The preserved state of the device needs to be fetched at various places
during liveupdate. The added API can also be used to check if a device
is preserved or not. The API is only used during shutdown and after
liveupdate so no locking needed.
Signed-off-by: Samiullah Khawaja <skhawaja@xxxxxxxxxx>
---
include/linux/iommu-lu.h | 67 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/include/linux/iommu-lu.h b/include/linux/iommu-lu.h
index 95375530b7be..08a659de8553 100644
--- a/include/linux/iommu-lu.h
+++ b/include/linux/iommu-lu.h
@@ -8,9 +8,76 @@
#ifndef _LINUX_IOMMU_LU_H
#define _LINUX_IOMMU_LU_H
+#include <linux/device.h>
+#include <linux/iommu.h>
#include <linux/liveupdate.h>
#include <linux/kho/abi/iommu.h>
+#ifdef CONFIG_LIVEUPDATE
+static inline void *dev_iommu_preserved_state(struct device *dev)
+{
+ struct device_ser *ser;
+
+ ser = dev->iommu->device_ser;
+ if (ser && !ser->obj.incoming)
+ return ser;
+
+ return NULL;
+}
+
+static inline void *dev_iommu_restored_state(struct device *dev)
+{
+ struct device_ser *ser;
+
+ ser = dev->iommu->device_ser;
+ if (ser && ser->obj.incoming)
+ return ser;
+
+ return NULL;
+}
+
+static inline void *iommu_domain_restored_state(struct iommu_domain *domain)
+{
+ struct iommu_domain_ser *ser;
+
+ ser = domain->preserved_state;
+ if (ser && ser->obj.incoming)
+ return ser;
+
+ return NULL;
+}
+
+static inline int dev_iommu_restore_did(struct device *dev, struct iommu_domain *domain)
+{
+ struct device_ser *ser = dev_iommu_restored_state(dev);
+
+ if (ser && iommu_domain_restored_state(domain))
+ return ser->domain_iommu_ser.did;
+
+ return -1;
+}
+#else
+static inline void *dev_iommu_preserved_state(struct device *dev)
+{
+ return NULL;
+}
+
+static inline void *dev_iommu_restored_state(struct device *dev)
+{
+ return NULL;
+}
+
+static inline int dev_iommu_restore_did(struct device *dev, struct iommu_domain *domain)
+{
+ return -1;
+}
+
+static inline void *iommu_domain_restored_state(struct iommu_domain *domain)
+{
+ return NULL;
+}
+#endif
+
int iommu_domain_preserve(struct iommu_domain *domain, struct iommu_domain_ser **ser);
int iommu_domain_unpreserve(struct iommu_domain *domain);
int iommu_preserve_device(struct iommu_domain *domain, struct device *dev);
--
2.52.0.158.g65b55ccf14-goog