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

From: Samiullah Khawaja

Date: Thu Dec 04 2025 - 12:48:35 EST


On Wed, Dec 3, 2025 at 10:24 PM Baolu Lu <baolu.lu@xxxxxxxxxxxxxxx> wrote:
>
> 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;
>

Thanks for this.

I will fix it in the next iteration.
> > + if (ser && !ser->obj.incoming)
> > + return ser;
> > +
> > + return NULL;
> > +}
>
> Thanks,
> baolu
>