From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Gibson Date: Tue, 02 Oct 2018 04:44:33 +0000 Subject: Re: [RFC PATCH kernel] vfio/spapr_tce: Get rid of possible infinite loop Message-Id: <20181002044433.GC1886@umbus.fritz.box> MIME-Version: 1 Content-Type: multipart/mixed; boundary="JWEK1jqKZ6MHAcjA" List-Id: References: <20181002032231.7494-1-aik@ozlabs.ru> In-Reply-To: <20181002032231.7494-1-aik@ozlabs.ru> To: Alexey Kardashevskiy Cc: Alex Williamson , linuxppc-dev@lists.ozlabs.org, kvm-ppc@vger.kernel.org --JWEK1jqKZ6MHAcjA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Oct 02, 2018 at 01:22:31PM +1000, Alexey Kardashevskiy wrote: > 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. >=20 > This makes the loop finite and prints a warning on every failure to make > the code more bug prone. >=20 > Signed-off-by: Alexey Kardashevskiy Reviewed-by: David Gibson It does improve the current behaviour. I do suspect, however, that leaving the failed regions in the list will probably cause another failure later on. > --- > drivers/vfio/vfio_iommu_spapr_tce.c | 10 +++------- > 1 file changed, 3 insertions(+), 7 deletions(-) >=20 > diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iomm= u_spapr_tce.c > index b1a8ab3..ece0651 100644 > --- a/drivers/vfio/vfio_iommu_spapr_tce.c > +++ b/drivers/vfio/vfio_iommu_spapr_tce.c > @@ -371,6 +371,7 @@ static void tce_iommu_release(void *iommu_data) > { > struct tce_container *container =3D iommu_data; > struct tce_iommu_group *tcegrp; > + struct tce_iommu_prereg *tcemem, *tmtmp; > long i; > =20 > while (tce_groups_attached(container)) { > @@ -393,13 +394,8 @@ static void tce_iommu_release(void *iommu_data) > tce_iommu_free_table(container, tbl); > } > =20 > - while (!list_empty(&container->prereg_list)) { > - struct tce_iommu_prereg *tcemem; > - > - tcemem =3D list_first_entry(&container->prereg_list, > - struct tce_iommu_prereg, next); > - WARN_ON_ONCE(tce_iommu_prereg_free(container, tcemem)); > - } > + list_for_each_entry_safe(tcemem, tmtmp, &container->prereg_list, next) > + WARN_ON(tce_iommu_prereg_free(container, tcemem)); > =20 > tce_iommu_disable(container); > if (container->mm) --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --JWEK1jqKZ6MHAcjA Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEdfRlhq5hpmzETofcbDjKyiDZs5IFAluy964ACgkQbDjKyiDZ s5J8QQ//Rwfy2Fg+5jLjAPv1qaaCVo35lQcUb63ii8uQgQSoK4s40b9BXtnXhWOY Zm8j2ZS7SFG6T1sWNBooBAkrfaipyyDcYtSlveCeLV8p4YVMtjoF6gP5jWK3M7Wz IC8qApl3iUIOBoHbECMTC1NDRYPNw+alCI9JoiewlIqbVRdyZI735aiS6bjerN4D Qq4GKSDn8xztwJODFUK2EFnWqAN5ZTUrJJeQnrFFb7al4Hc+jR7OFi4Igl7j47y2 OyeS/ZmvjeGSoI+FOgEXPAgT6QFZvguBKOICXOMHOqclSMLWOrS6wPU0W5J7MVpe LTqisnOLksvn99fc+gZaOcbTMnYHHwSsMStuuZw9bPXGTIL4oXXypa73vlaIvR8w d4wkHx9Gnnzh50b/rsAgJX4zUkL0wpnPc75m96jCvsUV8BjwRhJGfXbkqlZkOUaE 3/TFLELRdWt2fYAVY4Uhc+uR8Bdt8PqNZydGifkYfl5cn+gpclp7v9CEnjhsXDUB Lr7sLAsKH2hnI6pIKAkAVBfuYCES2TeOokWN/5g4G+fqbte1spA11sWF4a5Hq2h+ 8a/ST9xiaaSw4/m3xuCjWO9ySBHz6ke6bGiWd/sJhEgE1+cNBNpA0Xeivtena+me mllpIYxqct5cCFHdXdTC0WXGk+PXoJWFYtb80RUtqwdzeuuyioo= =2nya -----END PGP SIGNATURE----- --JWEK1jqKZ6MHAcjA--