Re: [PATCH v8 02/18] iommu: Implement IOMMU Live update FLB callbacks

From: Samiullah Khawaja

Date: Wed Dec 02 2026 - 16:34:26 EST


On Mon, Nov 30, 2026 at 06:47:43PM +0000, Pranjal Shrivastava wrote:
On Mon, Nov 30, 2026 at 06:40:01PM +0000, Pranjal Shrivastava wrote:
On Mon, Nov 23, 2026 at 04:49:33AM +0000, Samiullah Khawaja wrote:
> Add liveupdate FLB for IOMMU state preservation. Use KHO preserve memory
> alloc/free helper functions to allocate memory for the IOMMU Live update
> FLB object and the serialization structs for device, domain and iommu.
>
> During retrieve, walk through the preserved obj array headers and
> restore each folio. Also recreate the FLB obj.
>
> +/*
> + * Restore a set of serialized objects from the previous kernel. The objects
> + * are read using the size recorded by the previous kernel in their header.
> + *
> + * Failure to restore preserved IOMMU state is considered fatal. This is
> + * because the IOMMU translations for preserved IOMMUs were kept enabled in the
> + * previous kernel and the preserved devices have their IOMMU domains still
> + * present. Not being able to restore means that the memory mapped into
> + * preserved domains might be already corrupted by the preserved devices.
> + */
> +static void iommu_ser_set_restore(struct iommu_ser_set *set, u64 head_pa)
> +{
> + size_t entry_size = sizeof(struct iommu_hdr_ser);
> +
> + if (head_pa) {
> + struct kho_block_header_ser *block = phys_to_virt(head_pa);
> + struct iommu_hdr_ser *hdr = (void *)(block + 1);
> +
> + entry_size = hdr->size;
> + }
> +
> + if (entry_size < sizeof(struct iommu_hdr_ser) ||
> + entry_size > KHO_BLOCK_SIZE - sizeof(struct kho_block_header_ser))
> + goto err_fatal;
> +

With the callers passing sizeof(struct iommu_domain_ser) etc. Or, if
every layout change is supposed to bump IOMMU_LUO_FLB_VERSION (see the
comment on the ABI doc below), simply require that entry_size matches
sizeof() of the struct.


Oops, I lost a part of the comment while trimming, what I meant was:
The lower bound here only guarantees that the common header is
readable, but the users of these sets dereference each entry as the
full iommu_{domain,device,hw}_ser. If the previous kernel recorded a
smaller size, we'd read past the end of each object into the next

During restore we setup the block entry size according to the size
specified by the previous kernel in the common header. If the previous
kernel recorded a smaller size, the users of the _ser structs will only
read that much.

Note that the size can increase without breaking the compatibility, so a
newer kernel with larger _ser structs will be able to read the
older/smaller preserved state by using size/feature bits to decide which
part of the structs are valid.

I will update the documentation with all this.

But I think a buggy previous kernel can still set the size to be smaller
than the minimum _ser struct, so I will add checks for that.
entry. Should the lower bound be the size of the struct the set holds,
e.g.:

static void iommu_ser_set_restore(struct iommu_ser_set *set, u64 head_pa,
size_t min_size)
[...]
if (entry_size < min_size ||
entry_size > KHO_BLOCK_SIZE - sizeof(struct kho_block_header_ser))
goto err_fatal;

With the callers passing sizeof(struct iommu_domain_ser) etc.? Or, if
every layout change is supposed to bump IOMMU_LUO_FLB_VERSION, simply
require that entry_size matches sizeof() of the struct.

Thanks,
Praan

Thanks,
Sami