Re: [RFC PATCH v2 11/32] iommu/pages: Add APIs to preserve/unpreserve/restore iommu pages

From: Samiullah Khawaja

Date: Thu Dec 04 2025 - 12:39:58 EST


On Wed, Dec 3, 2025 at 6:30 PM Baolu Lu <baolu.lu@xxxxxxxxxxxxxxx> wrote:
>
> On 12/3/25 07:02, Samiullah Khawaja wrote:
> > +int iommu_preserve_pages(struct iommu_pages_list *list)
> > +{
> > + struct ioptdesc *iopt;
> > + int count = 0;
> > + int ret;
> > +
> > + list_for_each_entry(iopt, &list->pages, iopt_freelist_elm) {
> > + ret = kho_preserve_folio(ioptdesc_folio(iopt));
> > + if (ret) {
> > + iommu_unpreserve_pages(list, count);
> > + return ret;
> > + }
> > +
> > + ++count;
> > + }
> > +
> > + return 0;
> > +}
> > +EXPORT_SYMBOL_GPL(iommu_preserve_pages);
>
> What is the purpose of "count"?

Thanks for reviewing.

The count is there to unpreserve only the preserved pages if an error
occurs during preservation. For example if 4 pages (from the start of
the list) were preserved out of 10 pages in the list, the unpreserve
function will unpreserve the first 4 pages from the start of the list.
Please take a look at the implementation of iommu_unpreserve_pages for
details.
>
> Thanks,
> baolu

Sami