All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Shenming Lu <lushenming@huawei.com>
Cc: Cornelia Huck <cohuck@redhat.com>, <kvm@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <wanghaibin.wang@huawei.com>,
	<yuzenghui@huawei.com>
Subject: Re: [PATCH v1] vfio/type1: Remove the almost unused check in vfio_iommu_type1_unpin_pages
Date: Tue, 6 Apr 2021 13:37:56 -0600	[thread overview]
Message-ID: <20210406133756.4520772c@omen> (raw)
In-Reply-To: <20210406135009.1707-1-lushenming@huawei.com>

On Tue, 6 Apr 2021 21:50:09 +0800
Shenming Lu <lushenming@huawei.com> wrote:

> The check i > npage at the end of vfio_iommu_type1_unpin_pages is unused
> unless npage < 0, but if npage < 0, this function will return npage, which
> should return -EINVAL instead. So let's just check the parameter npage at
> the start of the function. By the way, replace unpin_exit with break.
> 
> Signed-off-by: Shenming Lu <lushenming@huawei.com>
> ---
>  drivers/vfio/vfio_iommu_type1.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
> index 45cbfd4879a5..fd4213c41743 100644
> --- a/drivers/vfio/vfio_iommu_type1.c
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -960,7 +960,7 @@ static int vfio_iommu_type1_unpin_pages(void *iommu_data,
>  	bool do_accounting;
>  	int i;
>  
> -	if (!iommu || !user_pfn)
> +	if (!iommu || !user_pfn || npage <= 0)
>  		return -EINVAL;
>  
>  	/* Supported for v2 version only */
> @@ -977,13 +977,13 @@ static int vfio_iommu_type1_unpin_pages(void *iommu_data,
>  		iova = user_pfn[i] << PAGE_SHIFT;
>  		dma = vfio_find_dma(iommu, iova, PAGE_SIZE);
>  		if (!dma)
> -			goto unpin_exit;
> +			break;
> +
>  		vfio_unpin_page_external(dma, iova, do_accounting);
>  	}
>  
> -unpin_exit:
>  	mutex_unlock(&iommu->lock);
> -	return i > npage ? npage : (i > 0 ? i : -EINVAL);
> +	return i > 0 ? i : -EINVAL;
>  }
>  
>  static long vfio_sync_unpin(struct vfio_dma *dma, struct vfio_domain *domain,

Very odd behavior previously.  Applied to vfio next branch for v5.13.
Thanks,

Alex


      reply	other threads:[~2021-04-06 19:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-06 13:50 [PATCH v1] vfio/type1: Remove the almost unused check in vfio_iommu_type1_unpin_pages Shenming Lu
2021-04-06 19:37 ` Alex Williamson [this message]

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=20210406133756.4520772c@omen \
    --to=alex.williamson@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lushenming@huawei.com \
    --cc=wanghaibin.wang@huawei.com \
    --cc=yuzenghui@huawei.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.