Re: [PATCH v2 12/26] iommu/amd: Add per-VM private IPA alloc/map helpers
From: Weinan Liu
Date: Sat May 30 2026 - 16:44:19 EST
On Wed, May 27, 2026 at 10:19 PM Suravee Suthikulpanit <suravee.suthikulpanit@xxxxxxx> wrote:
>
> +static void __maybe_unused free_private_vm_region(struct amd_iommu *iommu, u64 **entry,
> + u64 base, size_t size, u16 gid)
> +{
> + size_t unmapped;
> + u64 addr = base + (gid * size);
> +
> + pr_debug("%s: entry=%#llx(%#llx), base=%#llx, addr=%#llx, size=%#lx\n",
> + __func__, (unsigned long long)*entry,
> + iommu_virt_to_phys(*entry), base, addr, size);
> +
> + if (!iommu || !iommu->viommu_pdom)
> + return;
Should check if the page pointer *entry is non-NULL before operating on it.
*entry will be NULL if the caller encounters an error during alloc_private_vm_region(),
it may attempt to unmap and free a NULL pointer below:
> +
> + unmapped = iommu_unmap(&iommu->viommu_pdom->domain, addr, size);
> + if (unmapped != size)
> + pr_warn("%s: unmapped %#zx of %#lx at %#llx\n", __func__, unmapped, size, addr);
> +
> + set_memory_wb((unsigned long)*entry, size >> PAGE_SHIFT);
> + iommu_free_pages(*entry);
> + *entry = NULL;
> +}