2021-01-07 04:46:50

by Keqian Zhu

[permalink] [raw]
Subject: [PATCH 3/6] vfio/iommu_type1: Initially set the pinned_page_dirty_scope

For now there are 3 ways to promote the pinned_page_dirty_scope
status of vfio_iommu:

1. Through vfio pin interface.
2. Detach a group without pinned_dirty_scope.
3. Attach a group with pinned_dirty_scope.

For point 3, the only chance to promote the pinned_page_dirty_scope
status is when vfio_iommu is newly created. As we can safely set
empty vfio_iommu to be at pinned status, then the point 3 can be
removed to reduce operations.

Signed-off-by: Keqian Zhu <[email protected]>
---
drivers/vfio/vfio_iommu_type1.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 110ada24ee91..b596c482487b 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -2045,11 +2045,8 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
* Non-iommu backed group cannot dirty memory directly,
* it can only use interfaces that provide dirty
* tracking.
- * The iommu scope can only be promoted with the
- * addition of a dirty tracking group.
*/
group->pinned_page_dirty_scope = true;
- promote_pinned_page_dirty_scope(iommu);
mutex_unlock(&iommu->lock);

return 0;
@@ -2436,6 +2433,7 @@ static void *vfio_iommu_type1_open(unsigned long arg)
INIT_LIST_HEAD(&iommu->iova_list);
iommu->dma_list = RB_ROOT;
iommu->dma_avail = dma_entry_limit;
+ iommu->pinned_page_dirty_scope = true;
mutex_init(&iommu->lock);
BLOCKING_INIT_NOTIFIER_HEAD(&iommu->notifier);

--
2.19.1


2021-01-15 23:33:29

by Alex Williamson

[permalink] [raw]
Subject: Re: [PATCH 3/6] vfio/iommu_type1: Initially set the pinned_page_dirty_scope

On Thu, 7 Jan 2021 12:43:58 +0800
Keqian Zhu <[email protected]> wrote:

> For now there are 3 ways to promote the pinned_page_dirty_scope
> status of vfio_iommu:
>
> 1. Through vfio pin interface.
> 2. Detach a group without pinned_dirty_scope.
> 3. Attach a group with pinned_dirty_scope.
>
> For point 3, the only chance to promote the pinned_page_dirty_scope
> status is when vfio_iommu is newly created. As we can safely set
> empty vfio_iommu to be at pinned status, then the point 3 can be
> removed to reduce operations.
>
> Signed-off-by: Keqian Zhu <[email protected]>
> ---
> drivers/vfio/vfio_iommu_type1.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
> index 110ada24ee91..b596c482487b 100644
> --- a/drivers/vfio/vfio_iommu_type1.c
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -2045,11 +2045,8 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
> * Non-iommu backed group cannot dirty memory directly,
> * it can only use interfaces that provide dirty
> * tracking.
> - * The iommu scope can only be promoted with the
> - * addition of a dirty tracking group.
> */
> group->pinned_page_dirty_scope = true;
> - promote_pinned_page_dirty_scope(iommu);
> mutex_unlock(&iommu->lock);
>
> return 0;
> @@ -2436,6 +2433,7 @@ static void *vfio_iommu_type1_open(unsigned long arg)
> INIT_LIST_HEAD(&iommu->iova_list);
> iommu->dma_list = RB_ROOT;
> iommu->dma_avail = dma_entry_limit;
> + iommu->pinned_page_dirty_scope = true;
> mutex_init(&iommu->lock);
> BLOCKING_INIT_NOTIFIER_HEAD(&iommu->notifier);
>

This would be resolved automatically if we used the counter approach I
mentioned on the previous patch, adding a pinned-page scope group simply
wouldn't increment the iommu counter, which would initially be zero
indicating no "all-dma" groups. Thanks,

Alex

2021-01-19 04:25:38

by Keqian Zhu

[permalink] [raw]
Subject: Re: [PATCH 3/6] vfio/iommu_type1: Initially set the pinned_page_dirty_scope



On 2021/1/16 7:30, Alex Williamson wrote:
> On Thu, 7 Jan 2021 12:43:58 +0800
> Keqian Zhu <[email protected]> wrote:
>
>> For now there are 3 ways to promote the pinned_page_dirty_scope
>> status of vfio_iommu:
>>
>> 1. Through vfio pin interface.
>> 2. Detach a group without pinned_dirty_scope.
>> 3. Attach a group with pinned_dirty_scope.
>>
>> For point 3, the only chance to promote the pinned_page_dirty_scope
>> status is when vfio_iommu is newly created. As we can safely set
>> empty vfio_iommu to be at pinned status, then the point 3 can be
>> removed to reduce operations.
>>
>> Signed-off-by: Keqian Zhu <[email protected]>
>> ---
>> drivers/vfio/vfio_iommu_type1.c | 4 +---
>> 1 file changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
>> index 110ada24ee91..b596c482487b 100644
>> --- a/drivers/vfio/vfio_iommu_type1.c
>> +++ b/drivers/vfio/vfio_iommu_type1.c
>> @@ -2045,11 +2045,8 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
>> * Non-iommu backed group cannot dirty memory directly,
>> * it can only use interfaces that provide dirty
>> * tracking.
>> - * The iommu scope can only be promoted with the
>> - * addition of a dirty tracking group.
>> */
>> group->pinned_page_dirty_scope = true;
>> - promote_pinned_page_dirty_scope(iommu);
>> mutex_unlock(&iommu->lock);
>>
>> return 0;
>> @@ -2436,6 +2433,7 @@ static void *vfio_iommu_type1_open(unsigned long arg)
>> INIT_LIST_HEAD(&iommu->iova_list);
>> iommu->dma_list = RB_ROOT;
>> iommu->dma_avail = dma_entry_limit;
>> + iommu->pinned_page_dirty_scope = true;
>> mutex_init(&iommu->lock);
>> BLOCKING_INIT_NOTIFIER_HEAD(&iommu->notifier);
>>
>
> This would be resolved automatically if we used the counter approach I
> mentioned on the previous patch, adding a pinned-page scope group simply
> wouldn't increment the iommu counter, which would initially be zero
> indicating no "all-dma" groups. Thanks,
>
Sure, I will do that, thanks.

Keqian.

> Alex
>
> .
>