From: Serhii Popovych Date: Mon, 08 Oct 2018 07:29:48 +0000 Subject: Re: [RFC PATCH kernel] vfio/spapr_tce: Get rid of possible infinite loop Message-Id: <74ee5fc5-839b-27d6-5731-1b2731f9f95b@redhat.com> MIME-Version: 1 Content-Type: multipart/mixed; boundary="mlNQ9P0PV7bTzILEy0bFLL1jJXITV6LBX" List-Id: References: <20181002032231.7494-1-aik@ozlabs.ru> In-Reply-To: <20181002032231.7494-1-aik@ozlabs.ru> To: Alexey Kardashevskiy , linuxppc-dev@lists.ozlabs.org Cc: Alex Williamson , kvm-ppc@vger.kernel.org, David Gibson This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --mlNQ9P0PV7bTzILEy0bFLL1jJXITV6LBX Content-Type: multipart/mixed; boundary="m286uEMlX1QUTLnXN10RttdcTSXZj5F3F"; protected-headers="v1" From: Serhii Popovych To: Alexey Kardashevskiy , linuxppc-dev@lists.ozlabs.org Cc: David Gibson , kvm-ppc@vger.kernel.org, Alex Williamson Message-ID: <74ee5fc5-839b-27d6-5731-1b2731f9f95b@redhat.com> Subject: Re: [RFC PATCH kernel] vfio/spapr_tce: Get rid of possible infinite loop References: <20181002032231.7494-1-aik@ozlabs.ru> In-Reply-To: <20181002032231.7494-1-aik@ozlabs.ru> --m286uEMlX1QUTLnXN10RttdcTSXZj5F3F Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Alexey Kardashevskiy wrote: > As a part of cleanup, the SPAPR TCE IOMMU subdriver releases preregiste= red > 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 mak= e > the code more bug prone. >=20 > Signed-off-by: Alexey Kardashevskiy > --- > 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_io= mmu_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)); I'm not sure that tce_iommu_prereg_free() call under WARN_ON() is good idea because WARN_ON() is a preprocessor macro: if CONFIG_WARN=3Dn is added by the analogy with CONFIG_BUG=3Dn defining= WARN_ON() as empty we will loose call to tce_iommu_prereg_free() leaking resources. There is no problem at the moment: WARN_ON() defined for PPC in arch/powerpc/include/asm/bug.h unconditionally. So your first version with intermediate variable looks better to me. > =20 > tce_iommu_disable(container); > if (container->mm) >=20 --=20 Thanks, Serhii --m286uEMlX1QUTLnXN10RttdcTSXZj5F3F-- --mlNQ9P0PV7bTzILEy0bFLL1jJXITV6LBX Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQEcBAEBAgAGBQJbuwdxAAoJEBTawMmQ61bB/R0H/jQUzYa7A+l2JHPgyJ4hGrgI MoI+4Ar2QyMvRbwoYX5mT1TmpSLcNU5ygwlYr2owCzV/NjfOm0SNGIx0X525+5kX LK2ThUOikkgpoensvVMcAHKcmxd74t/MqbU+lWhkxcO82/YGOdmgQoF2TDUvkiHp 1IXq1w1pSjUPidkyQG9ynwZdR/stw5mPRF0Y6HP+BmwSz7HhxTSv+TS+gLdRvb7+ KZg66JYOlo4qIYXFhc5caxKZH0vysRyUkSKnsPGwGbB5VdVZ2xQKRZ2aWjHEezKp fTQ9T6Ph9UvDNQzVUWLCo80FYONbWNMFgWoQ4cGZ0KRurws5Cp+QqGBJsbMb0P8= =wktK -----END PGP SIGNATURE----- --mlNQ9P0PV7bTzILEy0bFLL1jJXITV6LBX--