drm/test: drm_exec: use kzalloc() to allocate GEM objects
Subsystems (2)
PATCH 1/1 drm/test: drm_exec: use kzalloc() to allocate GEM objects
Since commit e7fa80e2932c ("drm_gem: add mutex to drm_gem_object.gpuva") it is possible for test_prepare_array() to exceed a stack frame size of 2048 bytes depending on the exact configuration of the kernel.
drivers/gpu/drm/tests/drm_exec_test.c: In function ‘test_prepare_array’:
drivers/gpu/drm/tests/drm_exec_test.c:171:1: error: the frame size of 2128 bytes is larger than 2048 bytes [-Werror=frame-larger-than=]
171 | }
| ^ cc1: all warnings being treated as errors
make[6]: *** [scripts/Makefile.build:287: drivers/gpu/drm/tests/drm_exec_test.o] Error 1 make[6]: *** Waiting for unfinished jobs....
In order to fix this, allocate the GEM objects in test_prepare_array() with kzalloc(), rather than placing them on the stack.
--- drivers/gpu/drm/tests/drm_exec_test.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/gpu/drm/tests/drm_exec_test.c +19 -7
@@ -150,14 +150,22 @@ static void test_prepare(struct kunit *test)static void test_prepare_array (struct kunit *test) {struct drm_exec_priv *priv = test->priv; -struct drm_gem_object gobj1 = { }; -struct drm_gem_object gobj2 = { }; -struct drm_gem_object *array[] = { &gobj1, &gobj2 }; +struct drm_gem_object *gobj1; +struct drm_gem_object *gobj2; +struct drm_gem_object *array[] = { + (gobj1 =kzalloc (sizeof (*gobj1),GFP_KERNEL )), + (gobj2 =kzalloc (sizeof (*gobj2),GFP_KERNEL )), + };struct drm_exec exec;int ret; -drm_gem_private_object_init (priv->drm, &gobj1,PAGE_SIZE ); -drm_gem_private_object_init (priv->drm, &gobj2,PAGE_SIZE ); +if (!gobj1 || !gobj2) { +KUNIT_FAIL (test,"Failed to allocate GEM objects.\n" ); + goto out; + } + +drm_gem_private_object_init (priv->drm, gobj1,PAGE_SIZE ); +drm_gem_private_object_init (priv->drm, gobj2,PAGE_SIZE );drm_exec_init (&exec,DRM_EXEC_INTERRUPTIBLE_WAIT ,0 );drm_exec_until_all_locked (&exec)
@@ -166,8 +174,12 @@ static void test_prepare_array(struct kunit *test)KUNIT_EXPECT_EQ (test, ret,0 );drm_exec_fini (&exec); -drm_gem_private_object_fini (&gobj1); -drm_gem_private_object_fini (&gobj2); +drm_gem_private_object_fini (gobj1); +drm_gem_private_object_fini (gobj2); + +out: +kfree (gobj1); +kfree (gobj2); }static void test_multiple_loops (struct kunit *test)
base-commit: 0b6da6d3a8d5391ff9da2358ac5afd8b7badd943
Signature · 1 line
2.51.0
Quoted 12 lines · Danilo Krummrich
Since commit
e7fa80e2932c("drm_gem: add mutex to drm_gem_object.gpuva") it is possible fortest_prepare_array()to exceed a stack frame size of 2048 bytes depending on the exact configuration of the kernel.
drivers/gpu/drm/tests/drm_exec_test.c: In function ‘test_prepare_array’:
drivers/gpu/drm/tests/drm_exec_test.c:171:1: error: the frame size of 2128 bytes is larger than 2048 bytes [-Werror=frame-larger-than=]171 | } | ^cc1: all warnings being treated as errors
make[6]: *** [scripts/Makefile.build:287:drivers/gpu/drm/tests/drm_exec_test.o] Error 1 make[6]: *** Waiting for unfinished jobs....
Quoted 7 lines
In order to fix this, allocate the GEM objects in
test_prepare_array()withkzalloc(), rather than placing them on the stack.Cc Alice Ryhl <[email protected]>Cc Christian König <[email protected]>Fixes e7fa80e2932c ("drm_gem: add mutex to drm_gem_object.gpuva")Signed-off-by Danilo Krummrich <[email protected]>
Quoted 53 lines
--- drivers/gpu/drm/tests/drm_exec_test.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)drivers/gpu/drm/tests/drm_exec_test.c +19
-7@@ -150,14 +150,22 @@ static void test_prepare(struct kunit *test)static void test_prepare_array (struct kunit *test) {struct drm_exec_priv *priv = test->priv; -struct drm_gem_object gobj1 = { }; -struct drm_gem_object gobj2 = { }; -struct drm_gem_object *array[] = { &gobj1, &gobj2 }; +struct drm_gem_object *gobj1; +struct drm_gem_object *gobj2; +struct drm_gem_object *array[] = { + (gobj1 =kzalloc (sizeof (*gobj1),GFP_KERNEL )), + (gobj2 =kzalloc (sizeof (*gobj2),GFP_KERNEL )), + };struct drm_exec exec;int ret; -drm_gem_private_object_init (priv->drm, &gobj1,PAGE_SIZE ); -drm_gem_private_object_init (priv->drm, &gobj2,PAGE_SIZE ); +if (!gobj1 || !gobj2) { +KUNIT_FAIL (test,"Failed to allocate GEM objects.\n" ); + goto out; + } + +drm_gem_private_object_init (priv->drm, gobj1,PAGE_SIZE ); +drm_gem_private_object_init (priv->drm, gobj2,PAGE_SIZE );drm_exec_init (&exec,DRM_EXEC_INTERRUPTIBLE_WAIT ,0 );drm_exec_until_all_locked (&exec)@@ -166,8 +174,12 @@ static void test_prepare_array(struct kunit *test)KUNIT_EXPECT_EQ (test, ret,0 );drm_exec_fini (&exec); -drm_gem_private_object_fini (&gobj1); -drm_gem_private_object_fini (&gobj2); +drm_gem_private_object_fini (gobj1); +drm_gem_private_object_fini (gobj2); + +out: +kfree (gobj1); +kfree (gobj2); }static void test_multiple_loops (struct kunit *test)base-commit:
0b6da6d3a8d5391ff9da2358ac5afd8b7badd943
Quoted 12 lines · Danilo Krummrich
Since commit
e7fa80e2932c("drm_gem: add mutex to drm_gem_object.gpuva") it is possible fortest_prepare_array()to exceed a stack frame size of 2048 bytes depending on the exact configuration of the kernel.
drivers/gpu/drm/tests/drm_exec_test.c: In function ‘test_prepare_array’:
drivers/gpu/drm/tests/drm_exec_test.c:171:1: error: the frame size of 2128 bytes is larger than 2048 bytes [-Werror=frame-larger-than=]171 | } | ^cc1: all warnings being treated as errors
make[6]: *** [scripts/Makefile.build:287:drivers/gpu/drm/tests/drm_exec_test.o] Error 1 make[6]: *** Waiting for unfinished jobs....
Quoted 7 lines
In order to fix this, allocate the GEM objects in
test_prepare_array()withkzalloc(), rather than placing them on the stack.Cc Alice Ryhl <[email protected]>Cc Christian König <[email protected]>Fixes e7fa80e2932c ("drm_gem: add mutex to drm_gem_object.gpuva")Signed-off-by Danilo Krummrich <[email protected]>
Quoted 12 lines · Danilo Krummrich
Since commit
e7fa80e2932c("drm_gem: add mutex to drm_gem_object.gpuva") it is possible fortest_prepare_array()to exceed a stack frame size of 2048 bytes depending on the exact configuration of the kernel.
drivers/gpu/drm/tests/drm_exec_test.c: In function ‘test_prepare_array’:
drivers/gpu/drm/tests/drm_exec_test.c:171:1: error: the frame size of 2128 bytes is larger than 2048 bytes [-Werror=frame-larger-than=]171 | } | ^cc1: all warnings being treated as errors
make[6]: *** [scripts/Makefile.build:287:drivers/gpu/drm/tests/drm_exec_test.o] Error 1 make[6]: *** Waiting for unfinished jobs....
Quoted 7 lines
In order to fix this, allocate the GEM objects in
test_prepare_array()withkzalloc(), rather than placing them on the stack.Cc Alice Ryhl <[email protected]>Cc Christian König <[email protected]>Fixes e7fa80e2932c ("drm_gem: add mutex to drm_gem_object.gpuva")Signed-off-by Danilo Krummrich <[email protected]>
Quoted 53 lines
--- drivers/gpu/drm/tests/drm_exec_test.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)drivers/gpu/drm/tests/drm_exec_test.c +19
-7@@ -150,14 +150,22 @@ static void test_prepare(struct kunit *test)static void test_prepare_array (struct kunit *test) {struct drm_exec_priv *priv = test->priv; -struct drm_gem_object gobj1 = { }; -struct drm_gem_object gobj2 = { }; -struct drm_gem_object *array[] = { &gobj1, &gobj2 }; +struct drm_gem_object *gobj1; +struct drm_gem_object *gobj2; +struct drm_gem_object *array[] = { + (gobj1 =kzalloc (sizeof (*gobj1),GFP_KERNEL )), + (gobj2 =kzalloc (sizeof (*gobj2),GFP_KERNEL )), + };struct drm_exec exec;int ret; -drm_gem_private_object_init (priv->drm, &gobj1,PAGE_SIZE ); -drm_gem_private_object_init (priv->drm, &gobj2,PAGE_SIZE ); +if (!gobj1 || !gobj2) { +KUNIT_FAIL (test,"Failed to allocate GEM objects.\n" ); + goto out; + } + +drm_gem_private_object_init (priv->drm, gobj1,PAGE_SIZE ); +drm_gem_private_object_init (priv->drm, gobj2,PAGE_SIZE );drm_exec_init (&exec,DRM_EXEC_INTERRUPTIBLE_WAIT ,0 );drm_exec_until_all_locked (&exec)@@ -166,8 +174,12 @@ static void test_prepare_array(struct kunit *test)KUNIT_EXPECT_EQ (test, ret,0 );drm_exec_fini (&exec); -drm_gem_private_object_fini (&gobj1); -drm_gem_private_object_fini (&gobj2); +drm_gem_private_object_fini (gobj1); +drm_gem_private_object_fini (gobj2); + +out: +kfree (gobj1); +kfree (gobj2); }static void test_multiple_loops (struct kunit *test)base-commit:
0b6da6d3a8d5391ff9da2358ac5afd8b7badd943
Quoted 7 lines · Danilo Krummrich
drivers/gpu/drm/tests/drm_exec_test.c +0
-0@@ -150,14 +150,22 @@ static void test_prepare(struct kunit *test)static void test_prepare_array (struct kunit *test) {
drivers/gpu/drm/tests/drm_exec_test.c static void test_prepare(struct kunit *test) · line 158
Quoted 10 lines
drivers/gpu/drm/tests/drm_exec_test.c +6
-3struct drm_exec_priv *priv = test->priv; -struct drm_gem_object gobj1 = { }; -struct drm_gem_object gobj2 = { }; -struct drm_gem_object *array[] = { &gobj1, &gobj2 }; +struct drm_gem_object *gobj1; +struct drm_gem_object *gobj2; +struct drm_gem_object *array[] = { + (gobj1 =kzalloc (sizeof (*gobj1),GFP_KERNEL )), + (gobj2 =kzalloc (sizeof (*gobj2),GFP_KERNEL )), + };
Actually, I think this should use kunit_kzmalloc() instead. Unless anyone disagrees, I'd apply the following hunk when applying the patch.
drivers/gpu/drm/tests/drm_exec_test.c +3 -7
@@ -153,15 +153,15 @@ static void test_prepare_array(struct kunit *test)struct drm_gem_object *gobj1;struct drm_gem_object *gobj2;struct drm_gem_object *array[] = { - (gobj1 =kzalloc (sizeof (*gobj1),GFP_KERNEL )), - (gobj2 =kzalloc (sizeof (*gobj2),GFP_KERNEL )), + (gobj1 =kunit_kzalloc (test,sizeof (*gobj1),GFP_KERNEL )), + (gobj2 =kunit_kzalloc (test,sizeof (*gobj2),GFP_KERNEL )), };struct drm_exec exec;int ret;if (!gobj1 || !gobj2) {KUNIT_FAIL (test,"Failed to allocate GEM objects.\n" ); - goto out; +return ; }drm_gem_private_object_init (priv->drm, gobj1,PAGE_SIZE );
@@ -176,10 +176,6 @@ static void test_prepare_array(struct kunit *test)drm_gem_private_object_fini (gobj1);drm_gem_private_object_fini (gobj2); - -out: -kfree (gobj1); -kfree (gobj2); }static void test_multiple_loops (struct kunit *test)
Danilo Krummrich
AppliedQuoted 12 lines · Danilo Krummrich
Since commit
e7fa80e2932c("drm_gem: add mutex to drm_gem_object.gpuva") it is possible fortest_prepare_array()to exceed a stack frame size of 2048 bytes depending on the exact configuration of the kernel.
drivers/gpu/drm/tests/drm_exec_test.c: In function ‘test_prepare_array’:
drivers/gpu/drm/tests/drm_exec_test.c:171:1: error: the frame size of 2128 bytes is larger than 2048 bytes [-Werror=frame-larger-than=]171 | } | ^cc1: all warnings being treated as errors
make[6]: *** [scripts/Makefile.build:287:drivers/gpu/drm/tests/drm_exec_test.o] Error 1 make[6]: *** Waiting for unfinished jobs....
Quoted 7 lines
In order to fix this, allocate the GEM objects in
test_prepare_array()withkzalloc(), rather than placing them on the stack.Cc Alice Ryhl <[email protected]>Cc Christian König <[email protected]>Fixes e7fa80e2932c ("drm_gem: add mutex to drm_gem_object.gpuva")Signed-off-by Danilo Krummrich <[email protected]>
Applied to drm-misc-next, thanks!
[ Use kunit_kzalloc() instead of kzalloc(). - Danilo ]