Skip to contentSkip to conversation

drm/amd/display: use kvzalloc to allocate struct dc

PATCH Superseded Honglei Huang 2 participants 2 messages Jun 23

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd/display: use kvzalloc to allocate struct dc

struct dc has grown large over time (most of it the two inlined dc_scratch_space copies) and now sits close to the page allocator's 4 MiB contiguous allocation limit. Its actual size is not fixed by the source alone, it also depends on the compiler and the .configk, so it can easily cross 4 MiB, e.g. with a newer GCC or a config change, and once it does dc_create() fails.

dc_create() allocates it with kzalloc(). Once struct dc exceeds 4 MiB the request is rounded up to order 11 (8 MiB), which is above MAX_PAGE_ORDER, so the page allocator warns and returns NULL. dc_create() then fails, DM init fails and amdgpu probe aborts with -EINVAL:

  WARNING: mm/page_alloc.c:5197 at __alloc_frozen_pages_noprof+0x2f9/0x380
  RSI: ...000b   RBP: ...000b      <- order = 11 (8 MiB)
   __kmalloc_large_noprof+0x1e/0xc0
   dc_create+0x38/0x660 [amdgpu]
   amdgpu_dm_init+0x2d9/0x510 [amdgpu]
   dm_hw_init+0x1b/0x90 [amdgpu]
  amdgpu 0000:03:00.0: hw_init of IP block <dm> failed -22
  amdgpu 0000:03:00.0: probe with driver amdgpu failed with error -22

struct dc is software only state, never DMAed and only kept as an opaque pointer, so it needs no physically contiguous memory. Use kvzalloc()/ kvfree() so it falls back to vmalloc(), removing the dependency on MAX_PAGE_ORDER. The underlying bloat of struct dc should be addressed separately.

---
 drivers/gpu/drm/amd/display/dc/core/dc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc.c +3 -3
index b3530fbf32f..65bd927435e 100644
@@ -1507,7 +1507,7 @@ static void disable_vbios_mode_if_required(
 
 struct dc *dc_create(const struct dc_init_data *init_params)
 {
-	struct dc *dc = kzalloc_obj(*dc);
+	struct dc *dc = kvzalloc_obj(*dc);
 	unsigned int full_pipe_count;
 
 	if (!dc)
@@ -1555,7 +1555,7 @@ struct dc *dc_create(const struct dc_init_data *init_params)
 
 destruct_dc:
 	dc_destruct(dc);
-	kfree(dc);
+	kvfree(dc);
 	return NULL;
 }
 
@@ -1604,7 +1604,7 @@ void dc_deinit_callbacks(struct dc *dc)
 void dc_destroy(struct dc **dc)
 {
 	dc_destruct(*dc);
-	kfree(*dc);
+	kvfree(*dc);
 	*dc = NULL;
 }
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 21 lines · Honglei Huang

struct dc has grown large over time (most of it the two inlined dc_scratch_space copies) and now sits close to the page allocator's 4 MiB contiguous allocation limit. Its actual size is not fixed by the source alone, it also depends on the compiler and the .configk, so it can easily cross 4 MiB, e.g. with a newer GCC or a config change, and once it does dc_create() fails.

dc_create() allocates it with kzalloc(). Once struct dc exceeds 4 MiB the request is rounded up to order 11 (8 MiB), which is above MAX_PAGE_ORDER, so the page allocator warns and returns NULL. dc_create() then fails, DM init fails and amdgpu probe aborts with -EINVAL:

   WARNING: mm/page_alloc.c:5197 at __alloc_frozen_pages_noprof+0x2f9/0x380
   RSI: ...000b   RBP: ...000b      <- order = 11 (8 MiB)
    __kmalloc_large_noprof+0x1e/0xc0
    dc_create+0x38/0x660 [amdgpu]
    amdgpu_dm_init+0x2d9/0x510 [amdgpu]
    dm_hw_init+0x1b/0x90 [amdgpu]
   amdgpu 0000:03:00.0: hw_init of IP block <dm> failed -22
   amdgpu 0000:03:00.0: probe with driver amdgpu failed with error -22
Quoted 6 lines

struct dc is software only state, never DMAed and only kept as an opaque pointer, so it needs no physically contiguous memory. Use kvzalloc()/ kvfree() so it falls back to vmalloc(), removing the dependency on MAX_PAGE_ORDER. The underlying bloat of struct dc should be addressed separately.

Quoted 36 lines
---
  drivers/gpu/drm/amd/display/dc/core/dc.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc.c +3 -3
index b3530fbf32f..65bd927435e 100644
@@ -1507,7 +1507,7 @@ static void disable_vbios_mode_if_required(
 
  struct dc *dc_create(const struct dc_init_data *init_params)
  {
-	struct dc *dc = kzalloc_obj(*dc);
+	struct dc *dc = kvzalloc_obj(*dc);
  	unsigned int full_pipe_count;
 
  	if (!dc)
@@ -1555,7 +1555,7 @@ struct dc *dc_create(const struct dc_init_data *init_params)
 
  destruct_dc:
  	dc_destruct(dc);
-	kfree(dc);
+	kvfree(dc);
  	return NULL;
  }
 
@@ -1604,7 +1604,7 @@ void dc_deinit_callbacks(struct dc *dc)
  void dc_destroy(struct dc **dc)
  {
  	dc_destruct(*dc);
-	kfree(*dc);
+	kvfree(*dc);
  	*dc = NULL;
  }