AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Felix Kuehling <felix.kuehling@amd.com>
To: xinhui pan <xinhui.pan@amd.com>, amd-gfx@lists.freedesktop.org
Cc: "Alex Deucher" <alexander.deucher@amd.com>,
	"Christian König" <christian.koenig@amd.com>
Subject: Re: [PATCH v4 2/2] drm/amdgpu: unref pt bo after job submit
Date: Fri, 13 Mar 2020 13:36:23 -0400	[thread overview]
Message-ID: <2b38aa48-40c1-2830-0005-2ddca7672535@amd.com> (raw)
In-Reply-To: <20200313160933.10394-3-xinhui.pan@amd.com>

This seems weird. This means that we update a page table, and then free 
it in the same amdgpu_vm_update_ptes call? That means the update is 
redundant. Can we eliminate the redundant PTE update if the page table 
is about to be freed anyway?

Regards,
   Felix

On 2020-03-13 12:09, xinhui pan wrote:
> Free page table bo before job submit is insane.
> We might touch invalid memory while job is runnig.
>
> we now have individualized bo resv during bo releasing.
> So any fences added to root PT bo is actually untested when
> a normal PT bo is releasing.
>
> We might hit gmc page fault or memory just got overwrited.
>
> Cc: Christian König <christian.koenig@amd.com>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: Felix Kuehling <Felix.Kuehling@amd.com>
> Signed-off-by: xinhui pan <xinhui.pan@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 24 +++++++++++++++++++++---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h |  3 +++
>   2 files changed, 24 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 73398831196f..346e2f753474 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -937,6 +937,21 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
>   	return r;
>   }
>   
> +static void amdgpu_vm_free_zombie_bo(struct amdgpu_device *adev,
> +		struct amdgpu_vm *vm)
> +{
> +	struct amdgpu_vm_pt *entry;
> +
> +	while (!list_empty(&vm->zombies)) {
> +		entry = list_first_entry(&vm->zombies, struct amdgpu_vm_pt,
> +				base.vm_status);
> +		list_del(&entry->base.vm_status);
> +
> +		amdgpu_bo_unref(&entry->base.bo->shadow);
> +		amdgpu_bo_unref(&entry->base.bo);
> +	}
> +}
> +
>   /**
>    * amdgpu_vm_free_table - fre one PD/PT
>    *
> @@ -945,10 +960,9 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
>   static void amdgpu_vm_free_table(struct amdgpu_vm_pt *entry)
>   {
>   	if (entry->base.bo) {
> +		list_move(&entry->base.vm_status,
> +				&entry->base.bo->vm_bo->vm->zombies);
>   		entry->base.bo->vm_bo = NULL;
> -		list_del(&entry->base.vm_status);
> -		amdgpu_bo_unref(&entry->base.bo->shadow);
> -		amdgpu_bo_unref(&entry->base.bo);
>   	}
>   	kvfree(entry->entries);
>   	entry->entries = NULL;
> @@ -1624,6 +1638,7 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,
>   	r = vm->update_funcs->commit(&params, fence);
>   
>   error_unlock:
> +	amdgpu_vm_free_zombie_bo(adev, vm);
>   	amdgpu_vm_eviction_unlock(vm);
>   	return r;
>   }
> @@ -2807,6 +2822,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
>   	INIT_LIST_HEAD(&vm->invalidated);
>   	spin_lock_init(&vm->invalidated_lock);
>   	INIT_LIST_HEAD(&vm->freed);
> +	INIT_LIST_HEAD(&vm->zombies);
>   
>   
>   	/* create scheduler entities for page table updates */
> @@ -3119,6 +3135,8 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
>   	}
>   
>   	amdgpu_vm_free_pts(adev, vm, NULL);
> +	amdgpu_vm_free_zombie_bo(adev, vm);
> +
>   	amdgpu_bo_unreserve(root);
>   	amdgpu_bo_unref(&root);
>   	WARN_ON(vm->root.base.bo);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
> index b5705fcfc935..9baf44fa16f0 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
> @@ -269,6 +269,9 @@ struct amdgpu_vm {
>   	/* BO mappings freed, but not yet updated in the PT */
>   	struct list_head	freed;
>   
> +	/* BO will be freed soon */
> +	struct list_head	zombies;
> +
>   	/* contains the page directory */
>   	struct amdgpu_vm_pt     root;
>   	struct dma_fence	*last_update;
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  reply	other threads:[~2020-03-13 17:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-13 16:09 [PATCH v4 0/2] fix gmc page fault on navi1X xinhui pan
2020-03-13 16:09 ` [PATCH v4 1/2] drm_amdgpu: Add job fence to resv conditionally xinhui pan
2020-03-13 16:09 ` [PATCH v4 2/2] drm/amdgpu: unref pt bo after job submit xinhui pan
2020-03-13 17:36   ` Felix Kuehling [this message]
2020-03-13 18:05     ` Christian König
2020-03-14 13:06       ` Pan, Xinhui
2020-03-16  8:15         ` Tao, Yintian
2020-03-16  9:51           ` Pan, Xinhui
2020-03-16  9:54             ` Tao, Yintian
2020-03-16 12:15           ` Christian König

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=2b38aa48-40c1-2830-0005-2ddca7672535@amd.com \
    --to=felix.kuehling@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=xinhui.pan@amd.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox