Commit 517ad4ae authored by Alexey Kardashevskiy's avatar Alexey Kardashevskiy Committed by Michael Ellerman

vfio/spapr_tce: Get rid of possible infinite loop

As a part of cleanup, the SPAPR TCE IOMMU subdriver releases preregistered
memory. If there is a bug in memory release, the loop in
tce_iommu_release() becomes infinite; this actually happened to me.

This makes the loop finite and prints a warning on every failure to make
the code more bug prone.
Signed-off-by: default avatarAlexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: default avatarDavid Gibson <david@gibson.dropbear.id.au>
Acked-by: default avatarAlex Williamson <alex.williamson@redhat.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent fa1ada78
...@@ -371,6 +371,7 @@ static void tce_iommu_release(void *iommu_data) ...@@ -371,6 +371,7 @@ static void tce_iommu_release(void *iommu_data)
{ {
struct tce_container *container = iommu_data; struct tce_container *container = iommu_data;
struct tce_iommu_group *tcegrp; struct tce_iommu_group *tcegrp;
struct tce_iommu_prereg *tcemem, *tmtmp;
long i; long i;
while (tce_groups_attached(container)) { while (tce_groups_attached(container)) {
...@@ -393,13 +394,8 @@ static void tce_iommu_release(void *iommu_data) ...@@ -393,13 +394,8 @@ static void tce_iommu_release(void *iommu_data)
tce_iommu_free_table(container, tbl); tce_iommu_free_table(container, tbl);
} }
while (!list_empty(&container->prereg_list)) { list_for_each_entry_safe(tcemem, tmtmp, &container->prereg_list, next)
struct tce_iommu_prereg *tcemem; WARN_ON(tce_iommu_prereg_free(container, tcemem));
tcemem = list_first_entry(&container->prereg_list,
struct tce_iommu_prereg, next);
WARN_ON_ONCE(tce_iommu_prereg_free(container, tcemem));
}
tce_iommu_disable(container); tce_iommu_disable(container);
if (container->mm) if (container->mm)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment