[PATCH 5/9] drm/amdgpu: rework moved handling in the VM

zhoucm1 david1.zhou at amd.com
Mon Aug 28 06:51:24 UTC 2017


How do you keep the access of bo_base->moved is safely? I guess moving 
it to status_lock is better.


Regards,

David Zhou


On 2017年08月25日 17:38, Christian König wrote:
> From: Christian König <christian.koenig at amd.com>
>
> Instead of using the vm_state use a separate flag to note
> that the BO was moved.
>
> Signed-off-by: Christian König <christian.koenig at amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 13 +++++++------
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h |  3 +++
>   2 files changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 16148ef..85189f1 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -1787,13 +1787,13 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,
>   	else
>   		flags = 0x0;
>   
> -	/* We access vm_status without the status lock here, but that is ok
> -	 * because when we don't clear the BO is locked and so the status can't
> -	 * change
> -	 */
> -	if ((!clear && !list_empty(&bo_va->base.vm_status)) ||
> -	    bo_va->cleared != clear)
> +	if (!clear && bo_va->base.moved) {
> +		bo_va->base.moved = false;
> +		list_splice_init(&bo_va->valids, &bo_va->invalids);
> +
> +	} else if (bo_va->cleared != clear) {
>   		list_splice_init(&bo_va->valids, &bo_va->invalids);
> +	}
>   
>   	list_for_each_entry(mapping, &bo_va->invalids, list) {
>   		r = amdgpu_vm_bo_split_mapping(adev, exclusive, pages_addr, vm,
> @@ -2418,6 +2418,7 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
>   	struct amdgpu_vm_bo_base *bo_base;
>   
>   	list_for_each_entry(bo_base, &bo->va, bo_list) {
> +		bo_base->moved = true;
>   		spin_lock(&bo_base->vm->status_lock);
>   		list_move(&bo_base->vm_status, &bo_base->vm->moved);
>   		spin_unlock(&bo_base->vm->status_lock);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
> index e705f0f..ff093d4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
> @@ -105,6 +105,9 @@ struct amdgpu_vm_bo_base {
>   
>   	/* protected by spinlock */
>   	struct list_head		vm_status;
> +
> +	/* protected by the BO being reserved */
> +	bool				moved;
>   };
>   
>   struct amdgpu_vm_pt {



More information about the amd-gfx mailing list