Re: [RFC PATCH v2 20/32] iommu: Add APIs to get preserved state of a device

From: Baolu Lu

Date: Thu Dec 04 2025 - 01:24:28 EST


On 12/3/25 07:02, Samiullah Khawaja wrote:
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;

This might cause "NULL pointer dereference" issue if the device is not
iommu probed.

if (!dev->iommu)
return NULL;
ser = dev->iommu->device_ser;

+ if (ser && !ser->obj.incoming)
+ return ser;
+
+ return NULL;
+}

Thanks,
baolu