All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vfio/type1: Fix vfio_find_dma_valid return
@ 2021-08-19 23:53 Anthony Yznaga
  2021-08-20 16:24 ` Alex Williamson
  0 siblings, 1 reply; 4+ messages in thread
From: Anthony Yznaga @ 2021-08-19 23:53 UTC (permalink / raw)
  To: kvm; +Cc: alex.williamson, steven.sistare

Fix vfio_find_dma_valid to return WAITED on success if it was necessary
to wait which mean iommu lock was dropped and reacquired.  This allows
vfio_iommu_type1_pin_pages to recheck vaddr_invalid_count and possibly
avoid the checking the validity of every vaddr in its list.

Signed-off-by: Anthony Yznaga <anthony.yznaga@oracle.com>
---
 drivers/vfio/vfio_iommu_type1.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index a3e925a41b0d..7ca8c4e95da4 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -612,6 +612,7 @@ static int vfio_find_dma_valid(struct vfio_iommu *iommu, dma_addr_t start,
 			       size_t size, struct vfio_dma **dma_p)
 {
 	int ret;
+	int waited = 0;
 
 	do {
 		*dma_p = vfio_find_dma(iommu, start, size);
@@ -620,10 +621,10 @@ static int vfio_find_dma_valid(struct vfio_iommu *iommu, dma_addr_t start,
 		else if (!(*dma_p)->vaddr_invalid)
 			ret = 0;
 		else
-			ret = vfio_wait(iommu);
+			ret = waited = vfio_wait(iommu);
 	} while (ret > 0);
 
-	return ret;
+	return ret ? ret : waited;
 }
 
 /*
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] vfio/type1: Fix vfio_find_dma_valid return
  2021-08-19 23:53 [PATCH] vfio/type1: Fix vfio_find_dma_valid return Anthony Yznaga
@ 2021-08-20 16:24 ` Alex Williamson
  2021-08-20 18:44   ` Anthony Yznaga
  0 siblings, 1 reply; 4+ messages in thread
From: Alex Williamson @ 2021-08-20 16:24 UTC (permalink / raw)
  To: Anthony Yznaga; +Cc: kvm, steven.sistare

On Thu, 19 Aug 2021 16:53:57 -0700
Anthony Yznaga <anthony.yznaga@oracle.com> wrote:

> Fix vfio_find_dma_valid to return WAITED on success if it was necessary
> to wait which mean iommu lock was dropped and reacquired.  This allows
> vfio_iommu_type1_pin_pages to recheck vaddr_invalid_count and possibly
> avoid the checking the validity of every vaddr in its list.
> 
> Signed-off-by: Anthony Yznaga <anthony.yznaga@oracle.com>
> ---
>  drivers/vfio/vfio_iommu_type1.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
> index a3e925a41b0d..7ca8c4e95da4 100644
> --- a/drivers/vfio/vfio_iommu_type1.c
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -612,6 +612,7 @@ static int vfio_find_dma_valid(struct vfio_iommu *iommu, dma_addr_t start,
>  			       size_t size, struct vfio_dma **dma_p)
>  {
>  	int ret;
> +	int waited = 0;
>  
>  	do {
>  		*dma_p = vfio_find_dma(iommu, start, size);
> @@ -620,10 +621,10 @@ static int vfio_find_dma_valid(struct vfio_iommu *iommu, dma_addr_t start,
>  		else if (!(*dma_p)->vaddr_invalid)
>  			ret = 0;
>  		else
> -			ret = vfio_wait(iommu);
> +			ret = waited = vfio_wait(iommu);
>  	} while (ret > 0);
>  
> -	return ret;
> +	return ret ? ret : waited;
>  }
>  
>  /*

How about...

diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 0b4f7c174c7a..0e9217687f5c 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -612,17 +612,17 @@ static int vfio_wait(struct vfio_iommu *iommu)
 static int vfio_find_dma_valid(struct vfio_iommu *iommu, dma_addr_t start,
 			       size_t size, struct vfio_dma **dma_p)
 {
-	int ret;
+	int ret = 0;
 
 	do {
 		*dma_p = vfio_find_dma(iommu, start, size);
 		if (!*dma_p)
-			ret = -EINVAL;
+			return -EINVAL;
 		else if (!(*dma_p)->vaddr_invalid)
-			ret = 0;
+			return ret;
 		else
 			ret = vfio_wait(iommu);
-	} while (ret > 0);
+	} while (ret == WAITED);
 
 	return ret;
 }


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] vfio/type1: Fix vfio_find_dma_valid return
  2021-08-20 16:24 ` Alex Williamson
@ 2021-08-20 18:44   ` Anthony Yznaga
  2021-08-20 19:46     ` Alex Williamson
  0 siblings, 1 reply; 4+ messages in thread
From: Anthony Yznaga @ 2021-08-20 18:44 UTC (permalink / raw)
  To: Alex Williamson; +Cc: kvm, steven.sistare

On 8/20/21 9:24 AM, Alex Williamson wrote:
> On Thu, 19 Aug 2021 16:53:57 -0700
> Anthony Yznaga <anthony.yznaga@oracle.com> wrote:
>
>> Fix vfio_find_dma_valid to return WAITED on success if it was necessary
>> to wait which mean iommu lock was dropped and reacquired.  This allows
>> vfio_iommu_type1_pin_pages to recheck vaddr_invalid_count and possibly
>> avoid the checking the validity of every vaddr in its list.
>>
>> Signed-off-by: Anthony Yznaga <anthony.yznaga@oracle.com>
>> ---
>>  drivers/vfio/vfio_iommu_type1.c | 5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
>> index a3e925a41b0d..7ca8c4e95da4 100644
>> --- a/drivers/vfio/vfio_iommu_type1.c
>> +++ b/drivers/vfio/vfio_iommu_type1.c
>> @@ -612,6 +612,7 @@ static int vfio_find_dma_valid(struct vfio_iommu *iommu, dma_addr_t start,
>>  			       size_t size, struct vfio_dma **dma_p)
>>  {
>>  	int ret;
>> +	int waited = 0;
>>  
>>  	do {
>>  		*dma_p = vfio_find_dma(iommu, start, size);
>> @@ -620,10 +621,10 @@ static int vfio_find_dma_valid(struct vfio_iommu *iommu, dma_addr_t start,
>>  		else if (!(*dma_p)->vaddr_invalid)
>>  			ret = 0;
>>  		else
>> -			ret = vfio_wait(iommu);
>> +			ret = waited = vfio_wait(iommu);
>>  	} while (ret > 0);
>>  
>> -	return ret;
>> +	return ret ? ret : waited;
>>  }
>>  
>>  /*
> How about...
>
> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
> index 0b4f7c174c7a..0e9217687f5c 100644
> --- a/drivers/vfio/vfio_iommu_type1.c
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -612,17 +612,17 @@ static int vfio_wait(struct vfio_iommu *iommu)
>  static int vfio_find_dma_valid(struct vfio_iommu *iommu, dma_addr_t start,
>  			       size_t size, struct vfio_dma **dma_p)
>  {
> -	int ret;
> +	int ret = 0;
>  
>  	do {
>  		*dma_p = vfio_find_dma(iommu, start, size);
>  		if (!*dma_p)
> -			ret = -EINVAL;
> +			return -EINVAL;
>  		else if (!(*dma_p)->vaddr_invalid)
> -			ret = 0;
> +			return ret;
>  		else
>  			ret = vfio_wait(iommu);
> -	} while (ret > 0);
> +	} while (ret == WAITED);
>  
>  	return ret;
>  }
>

Even better.  Should I send a new patch?

Thanks,
Anthony


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] vfio/type1: Fix vfio_find_dma_valid return
  2021-08-20 18:44   ` Anthony Yznaga
@ 2021-08-20 19:46     ` Alex Williamson
  0 siblings, 0 replies; 4+ messages in thread
From: Alex Williamson @ 2021-08-20 19:46 UTC (permalink / raw)
  To: Anthony Yznaga; +Cc: kvm, steven.sistare

On Fri, 20 Aug 2021 11:44:01 -0700
Anthony Yznaga <anthony.yznaga@oracle.com> wrote:

> On 8/20/21 9:24 AM, Alex Williamson wrote:
> > On Thu, 19 Aug 2021 16:53:57 -0700
> > Anthony Yznaga <anthony.yznaga@oracle.com> wrote:
> >  
> >> Fix vfio_find_dma_valid to return WAITED on success if it was necessary
> >> to wait which mean iommu lock was dropped and reacquired.  This allows
> >> vfio_iommu_type1_pin_pages to recheck vaddr_invalid_count and possibly
> >> avoid the checking the validity of every vaddr in its list.
> >>
> >> Signed-off-by: Anthony Yznaga <anthony.yznaga@oracle.com>
> >> ---
> >>  drivers/vfio/vfio_iommu_type1.c | 5 +++--
> >>  1 file changed, 3 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
> >> index a3e925a41b0d..7ca8c4e95da4 100644
> >> --- a/drivers/vfio/vfio_iommu_type1.c
> >> +++ b/drivers/vfio/vfio_iommu_type1.c
> >> @@ -612,6 +612,7 @@ static int vfio_find_dma_valid(struct vfio_iommu *iommu, dma_addr_t start,
> >>  			       size_t size, struct vfio_dma **dma_p)
> >>  {
> >>  	int ret;
> >> +	int waited = 0;
> >>  
> >>  	do {
> >>  		*dma_p = vfio_find_dma(iommu, start, size);
> >> @@ -620,10 +621,10 @@ static int vfio_find_dma_valid(struct vfio_iommu *iommu, dma_addr_t start,
> >>  		else if (!(*dma_p)->vaddr_invalid)
> >>  			ret = 0;
> >>  		else
> >> -			ret = vfio_wait(iommu);
> >> +			ret = waited = vfio_wait(iommu);
> >>  	} while (ret > 0);
> >>  
> >> -	return ret;
> >> +	return ret ? ret : waited;
> >>  }
> >>  
> >>  /*  
> > How about...
> >
> > diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
> > index 0b4f7c174c7a..0e9217687f5c 100644
> > --- a/drivers/vfio/vfio_iommu_type1.c
> > +++ b/drivers/vfio/vfio_iommu_type1.c
> > @@ -612,17 +612,17 @@ static int vfio_wait(struct vfio_iommu *iommu)
> >  static int vfio_find_dma_valid(struct vfio_iommu *iommu, dma_addr_t start,
> >  			       size_t size, struct vfio_dma **dma_p)
> >  {
> > -	int ret;
> > +	int ret = 0;
> >  
> >  	do {
> >  		*dma_p = vfio_find_dma(iommu, start, size);
> >  		if (!*dma_p)
> > -			ret = -EINVAL;
> > +			return -EINVAL;
> >  		else if (!(*dma_p)->vaddr_invalid)
> > -			ret = 0;
> > +			return ret;
> >  		else
> >  			ret = vfio_wait(iommu);
> > -	} while (ret > 0);
> > +	} while (ret == WAITED);
> >  
> >  	return ret;
> >  }
> >  
> 
> Even better.  Should I send a new patch?

That would be preferable, otherwise at least a sign-off or reviewed-by
for the newer version.  Thanks,

Alex


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-08-20 19:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-19 23:53 [PATCH] vfio/type1: Fix vfio_find_dma_valid return Anthony Yznaga
2021-08-20 16:24 ` Alex Williamson
2021-08-20 18:44   ` Anthony Yznaga
2021-08-20 19:46     ` Alex Williamson

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.