All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] drm/amdgpu: Don't clear memory when PTB BO is released
@ 2022-07-07 16:45 Philip Yang
  2022-07-07 18:11 ` Felix Kuehling
  2022-07-07 19:03 ` Christian König
  0 siblings, 2 replies; 3+ messages in thread
From: Philip Yang @ 2022-07-07 16:45 UTC (permalink / raw)
  To: amd-gfx; +Cc: Philip Yang, felix.kuehling

MMU notifier callback unmap the svm range update page table may free the
PTB BO, then amdgpu_fill_buffer zero BO memory could cause deadlock as
kmalloc may trigger MMU notifier.

amdgpu_vm_pt_clear setup PTB BO memory with initial value, and no
sensitive data in page table that must be wiped out before releasing the
memory. So don't clear the memory when PTB BO is released.

Signed-off-by: Philip Yang <Philip.Yang@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index 8a7b0f6162da..65b4ff6979ee 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -576,7 +576,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
 	if (!amdgpu_bo_support_uswc(bo->flags))
 		bo->flags &= ~AMDGPU_GEM_CREATE_CPU_GTT_USWC;
 
-	if (adev->ras_enabled)
+	if (adev->ras_enabled && bp->type != ttm_bo_type_kernel)
 		bo->flags |= AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE;
 
 	bo->tbo.bdev = &adev->mman.bdev;
-- 
2.35.1


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

* Re: [PATCH 1/1] drm/amdgpu: Don't clear memory when PTB BO is released
  2022-07-07 16:45 [PATCH 1/1] drm/amdgpu: Don't clear memory when PTB BO is released Philip Yang
@ 2022-07-07 18:11 ` Felix Kuehling
  2022-07-07 19:03 ` Christian König
  1 sibling, 0 replies; 3+ messages in thread
From: Felix Kuehling @ 2022-07-07 18:11 UTC (permalink / raw)
  To: Philip Yang, amd-gfx

On 2022-07-07 12:45, Philip Yang wrote:
> MMU notifier callback unmap the svm range update page table may free the
> PTB BO, then amdgpu_fill_buffer zero BO memory could cause deadlock as
> kmalloc may trigger MMU notifier.
>
> amdgpu_vm_pt_clear setup PTB BO memory with initial value, and no
> sensitive data in page table that must be wiped out before releasing the
> memory. So don't clear the memory when PTB BO is released.

The problem happens if the memory is used for a non-pagetable BO after 
it has been freed. In that case it doesn't get initialized. That can 
leak data from the page table to a user mode application. And it can 
leak RAS poison to a new user mode allocation.

Therefore this memory must be wiped on free. If this causes issues in 
the context of the MMU notifier, then the wiping of memory should be 
deferred to a worker thread. The code for delayed freeing already exists 
for cases where memory has an unsignaled fence when it is freed. So it 
should be possible to create a fence, attach it to the BO before freeing 
it (maybe after it is individualized in amdgpu_bo_release_notify), and 
only signal it after freeing the BO. Or maybe there is a more 
straight-forward way to force delayed freeing of PT BOs in the MMU notifier.

Another alternative is to ensure that kmalloc in amdgpu_fill_buffer can 
never cause a recursive MMU notifiers by using GFP_ATOMIC or 
memalloc_noreclaim_save/restore. BTW, I don't see where the kmalloc is 
happening. I guess it's somewhere lower in the call stack.

Regard,
   Felix


>
> Signed-off-by: Philip Yang <Philip.Yang@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index 8a7b0f6162da..65b4ff6979ee 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -576,7 +576,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
>   	if (!amdgpu_bo_support_uswc(bo->flags))
>   		bo->flags &= ~AMDGPU_GEM_CREATE_CPU_GTT_USWC;
>   
> -	if (adev->ras_enabled)
> +	if (adev->ras_enabled && bp->type != ttm_bo_type_kernel)
>   		bo->flags |= AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE;
>   
>   	bo->tbo.bdev = &adev->mman.bdev;

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

* Re: [PATCH 1/1] drm/amdgpu: Don't clear memory when PTB BO is released
  2022-07-07 16:45 [PATCH 1/1] drm/amdgpu: Don't clear memory when PTB BO is released Philip Yang
  2022-07-07 18:11 ` Felix Kuehling
@ 2022-07-07 19:03 ` Christian König
  1 sibling, 0 replies; 3+ messages in thread
From: Christian König @ 2022-07-07 19:03 UTC (permalink / raw)
  To: Philip Yang, amd-gfx; +Cc: felix.kuehling

Am 07.07.22 um 18:45 schrieb Philip Yang:
> MMU notifier callback unmap the svm range update page table may free the
> PTB BO, then amdgpu_fill_buffer zero BO memory could cause deadlock as
> kmalloc may trigger MMU notifier.

Uff that means the whole free BO code path can't allocate anything.

I don't think we can do that.

>
> amdgpu_vm_pt_clear setup PTB BO memory with initial value, and no
> sensitive data in page table that must be wiped out before releasing the
> memory. So don't clear the memory when PTB BO is released.
>
> Signed-off-by: Philip Yang <Philip.Yang@amd.com>

Reviewed-by: Christian König <christian.koenig@amd.com> for this change 
here, but in general we need to talk about that once more.

Regards,
Christian.

> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index 8a7b0f6162da..65b4ff6979ee 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -576,7 +576,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
>   	if (!amdgpu_bo_support_uswc(bo->flags))
>   		bo->flags &= ~AMDGPU_GEM_CREATE_CPU_GTT_USWC;
>   
> -	if (adev->ras_enabled)
> +	if (adev->ras_enabled && bp->type != ttm_bo_type_kernel)
>   		bo->flags |= AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE;
>   
>   	bo->tbo.bdev = &adev->mman.bdev;


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

end of thread, other threads:[~2022-07-07 19:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-07 16:45 [PATCH 1/1] drm/amdgpu: Don't clear memory when PTB BO is released Philip Yang
2022-07-07 18:11 ` Felix Kuehling
2022-07-07 19:03 ` Christian König

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.