All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Das, Nirmoy" <nirmoy.das@amd.com>
To: Changfeng <Changfeng.Zhu@amd.com>,
	Ray.Huang@amd.com, amd-gfx@freedesktop.org,
	Christian.Koenig@amd.com
Subject: Re: [PATCH] drm/amdgpu: take back kvmalloc_array for entries alloc because of kzalloc memory limit
Date: Wed, 2 Jun 2021 10:54:14 +0200	[thread overview]
Message-ID: <c9c3817a-ddd5-d73e-5a5b-fb3ad25d8ddc@amd.com> (raw)
In-Reply-To: <20210602083017.2335-1-Changfeng.Zhu@amd.com>


On 6/2/2021 10:30 AM, Changfeng wrote:
> From: changzhu <Changfeng.Zhu@amd.com>
>
> From: Changfeng <Changfeng.Zhu@amd.com>
>
> It will cause error when alloc memory larger than 128KB in
> amdgpu_bo_create->kzalloc.


I wonder why I didn't see the error on my machine. Is there any config I 
might be missing ?


Thanks,

Nirmoy

> Call Trace:
>     alloc_pages_current+0x6a/0xe0
>     kmalloc_order+0x32/0xb0
>     kmalloc_order_trace+0x1e/0x80
>     __kmalloc+0x249/0x2d0
>     amdgpu_bo_create+0x102/0x500 [amdgpu]
>     ? xas_create+0x264/0x3e0
>     amdgpu_bo_create_vm+0x32/0x60 [amdgpu]
>     amdgpu_vm_pt_create+0xf5/0x260 [amdgpu]
>     amdgpu_vm_init+0x1fd/0x4d0 [amdgpu]
>
> Change-Id: I29e479db45ead37c39449e856599fd4f6a0e34ce
> Signed-off-by: Changfeng <Changfeng.Zhu@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 27 +++++++++++++++-----------
>   1 file changed, 16 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 1923f035713a..714d613d020b 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -894,6 +894,10 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev,
>   		num_entries = 0;
>   
>   	bp.bo_ptr_size = struct_size((*vmbo), entries, num_entries);
> +	if (bp.bo_ptr_size > 32*AMDGPU_GPU_PAGE_SIZE) {
> +		DRM_INFO("Can't alloc memory larger than 128KB by using kzalloc in amdgpu_bo_create\n");
> +		bp.bo_ptr_size = sizeof(struct amdgpu_bo_vm);
> +	}
>   
>   	if (vm->use_cpu_for_update)
>   		bp.flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
> @@ -965,15 +969,19 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
>   	struct amdgpu_bo_vm *pt;
>   	int r;
>   
> -	if (entry->base.bo) {
> -		if (cursor->level < AMDGPU_VM_PTB)
> -			entry->entries =
> -				to_amdgpu_bo_vm(entry->base.bo)->entries;
> -		else
> -			entry->entries = NULL;
> -		return 0;
> +	if (cursor->level < AMDGPU_VM_PTB && !entry->entries) {
> +		unsigned num_entries;
> +		num_entries = amdgpu_vm_num_entries(adev, cursor->level);
> +		entry->entries = kvmalloc_array(num_entries,
> +						sizeof(*entry->entries),
> +						GFP_KERNEL | __GFP_ZERO);
> +		if (!entry->entries)
> +			return -ENOMEM;
>   	}
>   
> +	if (entry->base.bo)
> +		return 0;
> +
>   	r = amdgpu_vm_pt_create(adev, vm, cursor->level, immediate, &pt);
>   	if (r)
>   		return r;
> @@ -984,10 +992,6 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
>   	pt_bo = &pt->bo;
>   	pt_bo->parent = amdgpu_bo_ref(cursor->parent->base.bo);
>   	amdgpu_vm_bo_base_init(&entry->base, vm, pt_bo);
> -	if (cursor->level < AMDGPU_VM_PTB)
> -		entry->entries = pt->entries;
> -	else
> -		entry->entries = NULL;
>   
>   	r = amdgpu_vm_clear_bo(adev, vm, pt, immediate);
>   	if (r)
> @@ -1017,6 +1021,7 @@ static void amdgpu_vm_free_table(struct amdgpu_vm_pt *entry)
>   		amdgpu_bo_unref(&shadow);
>   		amdgpu_bo_unref(&entry->base.bo);
>   	}
> +	kvfree(entry->entries);
>   	entry->entries = NULL;
>   }
>   
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2021-06-02  8:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-02  8:30 [PATCH] drm/amdgpu: take back kvmalloc_array for entries alloc because of kzalloc memory limit Changfeng
2021-06-02  8:33 ` Christian König
2021-06-02  8:54 ` Das, Nirmoy [this message]
2021-06-02  8:57   ` Christian König
2021-06-02  9:00     ` Das, Nirmoy
2021-06-02  9:10     ` Zhu, Changfeng
2021-06-02  9:31       ` Das, Nirmoy
2021-06-02  9:40       ` Christian König
2021-06-02 10:02         ` Zhu, Changfeng

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=c9c3817a-ddd5-d73e-5a5b-fb3ad25d8ddc@amd.com \
    --to=nirmoy.das@amd.com \
    --cc=Changfeng.Zhu@amd.com \
    --cc=Christian.Koenig@amd.com \
    --cc=Ray.Huang@amd.com \
    --cc=amd-gfx@freedesktop.org \
    /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 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.