Skip to contentSkip to conversation

Use kvmalloc_array for radeon and amdgpu CS chunks

PATCH Applied Chen Li 3 participants 6 messages Mar 3, 2021

Subsystems (2)
lore
Share & tools
lore

Chen Li

author
#0 lore raw

v3 cover Use kvmalloc_array for radeon and amdgpu CS chunks

When testing kernel with trinity, the kernel turned to tainted in that radeon CS require large memory and order is over MAX_ORDER.

kvmalloc/kvmalloc_array should be used here in that it will fallback to vmalloc if necessary.

Chen Li (3):
drm/radeon: Use kvmalloc for CS chunks drm/amdgpu: Use kvmalloc for CS chunks drm/amdgpu: correct DRM_ERROR for kvmalloc_array

Changelog:
v1->v2:
* also use kvmalloc in amdgpu
* fix a DRM_ERROR message for kvmalloc_array.
v2->v3:
* add missing kvfree for amdgpu CS

 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 14 +++++++-------
 drivers/gpu/drm/radeon/radeon_cs.c     |  8 ++++----
 2 files changed, 11 insertions(+), 11 deletions(-)

--
2.30.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#1 lore raw

PATCH v3 1/3 drm/radeon: Use kvmalloc for CS chunks

The number of chunks/chunks_array may be passed in by userspace and can be large.

---
 drivers/gpu/drm/radeon/radeon_cs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/radeon/radeon_cs.c +4 -4
index 35e937d39b51..fb736ef9f9aa 100644
@@ -288,7 +288,7 @@ int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data)
 	p->chunk_relocs = NULL;
 	p->chunk_flags = NULL;
 	p->chunk_const_ib = NULL;
-	p->chunks_array = kcalloc(cs->num_chunks, sizeof(uint64_t), GFP_KERNEL);
+	p->chunks_array = kvmalloc_array(cs->num_chunks, sizeof(uint64_t), GFP_KERNEL);
 	if (p->chunks_array == NULL) {
 		return -ENOMEM;
 	}
@@ -299,7 +299,7 @@ int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data)
 	}
 	p->cs_flags = 0;
 	p->nchunks = cs->num_chunks;
-	p->chunks = kcalloc(p->nchunks, sizeof(struct radeon_cs_chunk), GFP_KERNEL);
+	p->chunks = kvmalloc_array(p->nchunks, sizeof(struct radeon_cs_chunk), GFP_KERNEL);
 	if (p->chunks == NULL) {
 		return -ENOMEM;
 	}
@@ -452,8 +452,8 @@ static void radeon_cs_parser_fini(struct radeon_cs_parser *parser, int error, bo
 	kvfree(parser->vm_bos);
 	for (i = 0; i < parser->nchunks; i++)
 		kvfree(parser->chunks[i].kdata);
-	kfree(parser->chunks);
-	kfree(parser->chunks_array);
+	kvfree(parser->chunks);
+	kvfree(parser->chunks_array);
 	radeon_ib_free(parser->rdev, &parser->ib);
 	radeon_ib_free(parser->rdev, &parser->const_ib);
 }
Signature · 8 lines
2.30.0



_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#2 lore raw

PATCH v3 2/3 drm/amdgpu: Use kvmalloc for CS chunks

In reply to Chen Li

The number of chunks/chunks_array may be passed in by userspace and can be large.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +6 -6
index 3e240b952e79..d9ae2cb86bc7 100644
@@ -117,7 +117,7 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, union drm_amdgpu_cs
 	if (cs->in.num_chunks == 0)
 		return 0;
 
-	chunk_array = kmalloc_array(cs->in.num_chunks, sizeof(uint64_t), GFP_KERNEL);
+	chunk_array = kvmalloc_array(cs->in.num_chunks, sizeof(uint64_t), GFP_KERNEL);
 	if (!chunk_array)
 		return -ENOMEM;
 
@@ -144,7 +144,7 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, union drm_amdgpu_cs
 	}
 
 	p->nchunks = cs->in.num_chunks;
-	p->chunks = kmalloc_array(p->nchunks, sizeof(struct amdgpu_cs_chunk),
+	p->chunks = kvmalloc_array(p->nchunks, sizeof(struct amdgpu_cs_chunk),
 			    GFP_KERNEL);
 	if (!p->chunks) {
 		ret = -ENOMEM;
@@ -238,7 +238,7 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, union drm_amdgpu_cs
 
 	if (p->uf_entry.tv.bo)
 		p->job->uf_addr = uf_offset;
-	kfree(chunk_array);
+	kvfree(chunk_array);
 
 	/* Use this opportunity to fill in task info for the vm */
 	amdgpu_vm_set_task_info(vm);
@@ -250,11 +250,11 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, union drm_amdgpu_cs
 free_partial_kdata:
 	for (; i >= 0; i--)
 		kvfree(p->chunks[i].kdata);
-	kfree(p->chunks);
+	kvfree(p->chunks);
 	p->chunks = NULL;
 	p->nchunks = 0;
 free_chunk:
-	kfree(chunk_array);
+	kvfree(chunk_array);
 
 	return ret;
 }
@@ -706,7 +706,7 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,
 
 	for (i = 0; i < parser->nchunks; i++)
 		kvfree(parser->chunks[i].kdata);
-	kfree(parser->chunks);
+	kvfree(parser->chunks);
 	if (parser->job)
 		amdgpu_job_free(parser->job);
 	if (parser->uf_entry.tv.bo) {
Signature · 8 lines
2.30.0



_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#3 lore raw

PATCH v3 3/3 drm/amdgpu: correct DRM_ERROR for kvmalloc_array

In reply to Chen Li

This may avoid debug confusion.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -1
index d9ae2cb86bc7..b5c766998045 100644
@@ -559,7 +559,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 					sizeof(struct page *),
 					GFP_KERNEL | __GFP_ZERO);
 		if (!e->user_pages) {
-			DRM_ERROR("calloc failure\n");
+			DRM_ERROR("kvmalloc_array failure\n");
 			return -ENOMEM;
 		}
 
Signature · 8 lines
2.30.0



_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
maintainer Reviewed-by on the v3 series
#4 lore raw
In reply to Chen Li

Am 03.03.21 um 04:49 schrieb Chen Li:

Quoted 16 lines

When testing kernel with trinity, the kernel turned to tainted in that radeon CS require large memory and order is over MAX_ORDER.

kvmalloc/kvmalloc_array should be used here in that it will fallback to vmalloc if necessary.

Chen Li (3):
drm/radeon: Use kvmalloc for CS chunks drm/amdgpu: Use kvmalloc for CS chunks drm/amdgpu: correct DRM_ERROR for kvmalloc_array

Changelog:
v1->v2:
* also use kvmalloc in amdgpu
* fix a DRM_ERROR message for kvmalloc_array.
v2->v3:
* add missing kvfree for amdgpu CS

Quoted 8 lines
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 14 +++++++-------
  drivers/gpu/drm/radeon/radeon_cs.c     |  8 ++++----
  2 files changed, 11 insertions(+), 11 deletions(-)

--
2.30.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Applied
#5 lore raw

Applied. Thanks!

Alex

Quoted 30 lines · Christian König

series.

Am 03.03.21 um 04:49 schrieb Chen Li:

Quoted 16 lines

When testing kernel with trinity, the kernel turned to tainted in that radeon CS require large memory and order is over MAX_ORDER.

kvmalloc/kvmalloc_array should be used here in that it will fallback to vmalloc if necessary.

Chen Li (3):
drm/radeon: Use kvmalloc for CS chunks drm/amdgpu: Use kvmalloc for CS chunks drm/amdgpu: correct DRM_ERROR for kvmalloc_array

Changelog:
v1->v2:
* also use kvmalloc in amdgpu
* fix a DRM_ERROR message for kvmalloc_array.
v2->v3:
* add missing kvfree for amdgpu CS

Quoted 8 lines
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 14 +++++++-------
  drivers/gpu/drm/radeon/radeon_cs.c     |  8 ++++----
  2 files changed, 11 insertions(+), 11 deletions(-)

--
2.30.0

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx