drm/amd/display: use pre-allocated temp structure for bounding box
Subsystems (3)
Alex Deucher
maintainerPATCH 1/2 drm/amd/display: use pre-allocated temp structure for bounding box
This mirrors what the driver does for older DCN generations.
Should fix:
BUG: sleeping function called from invalid context at include/linux/sched/mm.h:306
in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 449, name: kworker/u64:8preempt_count: 2, expected: 0
RCU nest depth: 0, expected: 0
Preemption disabled at:ffffffffc0ce1580>] dc_fpu_begin+0x30/0xd0 [amdgpu]
CPU: 5 PID: 449 Comm: kworker/u64:8 Tainted: G W 6.8.0+ #35 Hardware name: System manufacturer System Product Name/ROG STRIX X570-E GAMING WIFI II, BIOS 4204 02/24/2022 Workqueue: events_unbound async_run_entry_fn
--- drivers/gpu/drm/amd/display/dc/dc.h | 1 + .../drm/amd/display/dc/resource/dcn32/dcn32_resource.c | 8 +++----- .../drm/amd/display/dc/resource/dcn321/dcn321_resource.c | 8 +++----- 3 files changed, 7 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/display/dc/dc.h +1 -0
@@ -1444,6 +1444,7 @@ struct dc { } scratch;struct dml2_configuration_options dml2_options; +struct dml2_configuration_options dml2_tmp;enum dc_acpi_cm_power_state power_state; };
drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c +3 -5
@@ -2007,11 +2007,9 @@ void dcn32_calculate_wm_and_dlg(struct dc *dc, struct dc_state *context,static void dcn32_update_bw_bounding_box (struct dc *dc,struct clk_bw_params *bw_params) { -struct dml2_configuration_options *dml2_opt; +struct dml2_configuration_options *dml2_opt = &dc->dml2_tmp; - dml2_opt =kmemdup (&dc->dml2_options,sizeof (dc->dml2_options),GFP_KERNEL ); -if (!dml2_opt) -return ; +memcpy (dml2_opt, &dc->dml2_options,sizeof (dc->dml2_options));DC_FP_START ();
@@ -2027,7 +2025,7 @@ static void dcn32_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bwDC_FP_END (); -kfree (dml2_opt); +memcpy (&dc->dml2_options, dml2_opt,sizeof (dc->dml2_options)); }static struct resource_funcs dcn32_res_pool_funcs = {
drivers/gpu/drm/amd/display/dc/resource/dcn321/dcn321_resource.c +3 -5
@@ -1581,11 +1581,9 @@ static struct dc_cap_funcs cap_funcs = {static void dcn321_update_bw_bounding_box (struct dc *dc,struct clk_bw_params *bw_params) { -struct dml2_configuration_options *dml2_opt; +struct dml2_configuration_options *dml2_opt = &dc->dml2_tmp; - dml2_opt =kmemdup (&dc->dml2_options,sizeof (dc->dml2_options),GFP_KERNEL ); -if (!dml2_opt) -return ; +memcpy (dml2_opt, &dc->dml2_options,sizeof (dc->dml2_options));DC_FP_START ();
@@ -1601,7 +1599,7 @@ static void dcn321_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bDC_FP_END (); -kfree (dml2_opt); +memcpy (&dc->dml2_options, dml2_opt,sizeof (dc->dml2_options)); }static struct resource_funcs dcn321_res_pool_funcs = {
Signature · 1 line
2.45.1
Alex Deucher
maintainerPATCH 2/2 drm/amd/display/dcn401: use pre-allocated temp structure for bounding box
This mirrors what the driver does for older DCN generations.
Should fix:
[ 26.924055] BUG: sleeping function called from invalid context at include/linux/sched/mm.h:306 [ 26.924060] in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 1022, name: modprobe [ 26.924063] preempt_count: 2, expected: 0 [ 26.924064] RCU nest depth: 0, expected: 0 [ 26.924066] Preemption disabled at: [ 26.924067] [<ffffffffc089e5e0>] dc_fpu_begin+0x30/0xd0 [amdgpu] [ 26.924322] CPU: 9 PID: 1022 Comm: modprobe Not tainted 6.8.0+ #20 [ 26.924325] Hardware name: System manufacturer System Product Name/CROSSHAIR VI HERO, BIOS 6302 10/23/2018 [ 26.924326] Call Trace: [ 26.924327] <TASK> [ 26.924329] dump_stack_lvl+0x37/0x50 [ 26.924333] ? dc_fpu_begin+0x30/0xd0 [amdgpu] [ 26.924589] dump_stack+0x10/0x20 [ 26.924592] __might_resched+0x16a/0x1c0 [ 26.924596] __might_sleep+0x42/0x70 [ 26.924598] __kmalloc_node_track_caller+0x2ad/0x4b0 [ 26.924601] ? dm_helpers_allocate_gpu_mem+0x12/0x20 [amdgpu] [ 26.924855] ? dcn401_update_bw_bounding_box+0x2a/0xf0 [amdgpu] [ 26.925122] kmemdup+0x20/0x50 [ 26.925124] ? kernel_fpu_begin_mask+0x6b/0xe0 [ 26.925127] ? kmemdup+0x20/0x50 [ 26.925129] dcn401_update_bw_bounding_box+0x2a/0xf0 [amdgpu] [ 26.925393] dc_create+0x311/0x670 [amdgpu] [ 26.925649] amdgpu_dm_init+0x2aa/0x1fa0 [amdgpu] [ 26.925903] ? irq_work_queue+0x38/0x50 [ 26.925907] ? vprintk_emit+0x1e7/0x270 [ 26.925910] ? dev_printk_emit+0x83/0xb0 [ 26.925914] ? amdgpu_device_rreg+0x17/0x20 [amdgpu] [ 26.926133] dm_hw_init+0x14/0x30 [amdgpu]
--- drivers/gpu/drm/amd/display/dc/core/dc_state.c | 13 ++++++------- .../display/dc/resource/dcn401/dcn401_resource.c | 8 +++----- 2 files changed, 9 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc_state.c +6 -7
@@ -192,15 +192,14 @@ static void init_state(struct dc *dc, struct dc_state *state)/* Public dc_state functions */ struct dc_state *dc_state_create (struct dc *dc,struct dc_state_create_params *params) { +struct dc_state *state;#ifdef CONFIG_DRM_AMD_DC_FP -struct dml2_configuration_options *dml2_opt; +struct dml2_configuration_options *dml2_opt = &dc->dml2_tmp; - dml2_opt =kmemdup (&dc->dml2_options,sizeof (*dml2_opt),GFP_KERNEL ); -if (!dml2_opt) -return NULL ; +memcpy (dml2_opt, &dc->dml2_options,sizeof (dc->dml2_options));#endif -struct dc_state *state =kvzalloc (sizeof (struct dc_state ), -GFP_KERNEL ); + + state =kvzalloc (sizeof (struct dc_state ),GFP_KERNEL );if (!state)return NULL ;
@@ -218,7 +217,7 @@ struct dc_state *dc_state_create(struct dc *dc, struct dc_state_create_params *p dml2_create(dc, dml2_opt, &state->bw_ctx.dml2_dc_power_source); } -kfree (dml2_opt); +memcpy (&dc->dml2_options, dml2_opt,sizeof (dc->dml2_options));#endif kref_init (&state->refcount);
drivers/gpu/drm/amd/display/dc/resource/dcn401/dcn401_resource.c +3 -5
@@ -1581,11 +1581,9 @@ static struct dc_cap_funcs cap_funcs = {static void dcn401_update_bw_bounding_box (struct dc *dc,struct clk_bw_params *bw_params) { -struct dml2_configuration_options *dml2_opt; +struct dml2_configuration_options *dml2_opt = &dc->dml2_tmp; - dml2_opt =kmemdup (&dc->dml2_options,sizeof (*dml2_opt),GFP_KERNEL ); -if (!dml2_opt) -return ; +memcpy (dml2_opt, &dc->dml2_options,sizeof (dc->dml2_options));DC_FP_START ();
@@ -1601,7 +1599,7 @@ static void dcn401_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bDC_FP_END (); -kfree (dml2_opt); +memcpy (&dc->dml2_options, dml2_opt,sizeof (dc->dml2_options)); }enum dc_status dcn401_patch_unknown_plane_state (struct dc_plane_state *plane_state)
Signature · 1 line
2.45.1
Quoted 20 lines · Alex Deucher
This mirrors what the driver does for older DCN generations.
Should fix:
BUG: sleeping function called from invalid context at
include/linux/sched/mm.h:306in_atomic(): 1,irqs_disabled(): 0,non_block: 0, pid: 449, name:
kworker/u64:8preempt_count: 2, expected: 0
RCU nest depth: 0, expected: 0
Preemption disabled at:ffffffffc0ce1580>]dc_fpu_begin+0x30/0xd0[amdgpu]CPU: 5 PID: 449 Comm: kworker/u64:8 Tainted: G W 6.8.0+ #35 Hardware name: System manufacturer System Product Name/ROG STRIX X570-E GAMING WIFI II, BIOS 4204 02/24/2022 Workqueue: events_unbound async_run_entry_fnFixes 88c61827cedc ("drm/amd/display: dynamically allocate
dml2_configuration_optionsstructures")
Quoted 8 lines
Tested-by George Zhang <[email protected]>Suggested-by Hamza Mahfooz <[email protected]>Signed-off-by Alex Deucher <[email protected]>Cc George Zhang <[email protected]>Cc Arnd Bergmann <[email protected]>
That looks nicer than all the other suggestions, thanks!
One part sticks out though:
drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c static void dcn32_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bw · line 2029
Quoted 8 lines
(quoted diff) +0
-0@@ -2027,7 +2025,7 @@ static void dcn32_update_bw_bounding_box(structdc *dc, struct
clk_bw_params*bwdrivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c +1
-1DC_FP_END (); -kfree (dml2_opt); +memcpy (&dc->dml2_options, dml2_opt,sizeof (dc->dml2_options)); }
The driver did not copy the data back before, so this is a change in behavior. Is that intentional or a mistake?
If the intention is to have the data copied back into dc->dml2_options in the end, wouldn't it be easier to just pass a pointer as in the old version before commit e779f4587f61 ("drm/amd/display: Add handling for DC power mode")?
Arnd
Deucher, Alexander
maintainer[Public]
Quoted 53 lines
-----Original Message-----
From: Arnd Bergmann <[email protected]>
Sent: Tuesday, June 4, 2024 3:43 PM
To: Deucher, Alexander <[email protected]>; amd- [email protected]
Cc: Zhang, George <[email protected]>; Mahfooz, Hamza <[email protected]>; Wentland, Harry <[email protected]>; Li, Sun peng (Leo) <[email protected]>; Siqueira, Rodrigo <[email protected]>; Aberback, Joshua <[email protected]>
Subject: Re: [PATCH 1/2] drm/amd/display: use pre-allocated temp structure for bounding boxQuoted 20 lines · Alex Deucher
This mirrors what the driver does for older DCN generations.
Should fix:
BUG: sleeping function called from invalid context at
include/linux/sched/mm.h:306in_atomic(): 1,irqs_disabled(): 0,non_block: 0, pid: 449, name:
kworker/u64:8preempt_count: 2, expected: 0
RCU nest depth: 0, expected: 0
Preemption disabled at:ffffffffc0ce1580>]dc_fpu_begin+0x30/0xd0[amdgpu]CPU: 5 PID: 449 Comm: kworker/u64:8 Tainted: G W 6.8.0+ #35 Hardware name: System manufacturer System Product Name/ROG STRIX X570-E GAMING WIFI II, BIOS 4204 02/24/2022 Workqueue: events_unbound async_run_entry_fnFixes 88c61827cedc ("drm/amd/display: dynamically allocate
dml2_configuration_optionsstructures")Quoted 8 lines
Tested-by George Zhang <[email protected]>Suggested-by Hamza Mahfooz <[email protected]>Signed-off-by Alex Deucher <[email protected]>Cc George Zhang <[email protected]>Cc Arnd Bergmann <[email protected]>That looks nicer than all the other suggestions, thanks!
Acked-by Arnd Bergmann <[email protected]>One part sticks out though:
Review static void
Quoted 1 line
(quoted diff) +0
-0@@ -2027,7 +2025,7 @@ static voiddcn32_update_bw_bounding_box(struct
Quoted 2 lines
dc *dc, struct
clk_bw_params*bw
Quoted 8 lines
drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c static void dcn32_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bw · line 2029
Quoted 5 lines
DC_FP_END();drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c +1
-1-kfree (dml2_opt); +memcpy (&dc->dml2_options, dml2_opt,sizeof (dc->dml2_options)); }The driver did not copy the data back before, so this is a change in behavior. Is that intentional or a mistake?
Yes, sorry, was on autopilot based on the patch Hamza had pointed me to. Will drop in v2.
Thanks,
Alex
Quoted 7 lines
If the intention is to have the data copied back into
dc->dml2_optionsin the end, wouldn't it be easier to just pass a pointer as in the old version before commite779f4587f61("drm/amd/display: Add handling for DC power mode")?Arnd