linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Serhii Popovych <spopovyc@redhat.com>
To: Alexey Kardashevskiy <aik@ozlabs.ru>, linuxppc-dev@lists.ozlabs.org
Cc: Alex Williamson <alex.williamson@redhat.com>,
	kvm-ppc@vger.kernel.org,
	David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [RFC PATCH kernel] vfio/spapr_tce: Get rid of possible infinite loop
Date: Mon, 8 Oct 2018 10:29:48 +0300	[thread overview]
Message-ID: <74ee5fc5-839b-27d6-5731-1b2731f9f95b@redhat.com> (raw)
In-Reply-To: <20181002032231.7494-1-aik@ozlabs.ru>


[-- Attachment #1.1: Type: text/plain, Size: 2107 bytes --]

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.
> 
> This makes the loop finite and prints a warning on every failure to make
> the code more bug prone.
> 
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> ---
>  drivers/vfio/vfio_iommu_spapr_tce.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_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 = iommu_data;
>  	struct tce_iommu_group *tcegrp;
> +	struct tce_iommu_prereg *tcemem, *tmtmp;
>  	long i;
>  
>  	while (tce_groups_attached(container)) {
> @@ -393,13 +394,8 @@ static void tce_iommu_release(void *iommu_data)
>  		tce_iommu_free_table(container, tbl);
>  	}
>  
> -	while (!list_empty(&container->prereg_list)) {
> -		struct tce_iommu_prereg *tcemem;
> -
> -		tcemem = 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=n is added by the analogy with CONFIG_BUG=n 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.

>  
>  	tce_iommu_disable(container);
>  	if (container->mm)
> 


-- 
Thanks,
Serhii


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]

  parent reply	other threads:[~2018-10-08  7:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-02  3:22 [RFC PATCH kernel] vfio/spapr_tce: Get rid of possible infinite loop Alexey Kardashevskiy
2018-10-02  4:44 ` David Gibson
2018-10-03 18:17 ` Alex Williamson
2018-10-08  7:29 ` Serhii Popovych [this message]
2018-10-08 10:18   ` Michael Ellerman
2018-12-19  4:44     ` Alexey Kardashevskiy
2018-12-23 13:28 ` [RFC,kernel] " Michael Ellerman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=74ee5fc5-839b-27d6-5731-1b2731f9f95b@redhat.com \
    --to=spopovyc@redhat.com \
    --cc=aik@ozlabs.ru \
    --cc=alex.williamson@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).