Skip to content

Commit ddbfac1

Browse files
ardbiesheuvelalexdeucher
authored andcommitted
drm/amd/display: Fix unsafe uses of kernel mode FPU
The point of isolating code that uses kernel mode FPU in separate compilation units is to ensure that even implicit uses of, e.g., SIMD registers for spilling occur only in a context where this is permitted, i.e., from inside a kernel_fpu_begin/end block. This is important on arm64, which uses -mgeneral-regs-only to build all kernel code, with the exception of such compilation units where FP or SIMD registers are expected to be used. Given that the compiler may invent uses of FP/SIMD anywhere in such a unit, none of its code may be accessible from outside a kernel_fpu_begin/end block. This means that all callers into such compilation units must use the DC_FP start/end macros, which must not occur there themselves. For robustness, all functions with external linkage that reside there should call dc_assert_fp_enabled() to assert that the FPU context was set up correctly. Fix this for the DCN35, DCN351 and DCN36 implementations. Cc: Austin Zheng <[email protected]> Cc: Jun Lei <[email protected]> Cc: Harry Wentland <[email protected]> Cc: Leo Li <[email protected]> Cc: Rodrigo Siqueira <[email protected]> Cc: Alex Deucher <[email protected]> Cc: "Christian König" <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Alex Deucher <[email protected]> Cc: [email protected] Signed-off-by: Alex Deucher <[email protected]>
1 parent bd8acfc commit ddbfac1

File tree

6 files changed

+56
-7
lines changed

6 files changed

+56
-7
lines changed

drivers/gpu/drm/amd/display/dc/dml/dcn31/dcn31_fpu.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,13 +808,17 @@ void dcn316_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bw_param
808808

809809
int dcn_get_max_non_odm_pix_rate_100hz(struct _vcs_dpi_soc_bounding_box_st *soc)
810810
{
811+
dc_assert_fp_enabled();
812+
811813
return soc->clock_limits[0].dispclk_mhz * 10000.0 / (1.0 + soc->dcn_downspread_percent / 100.0);
812814
}
813815

814816
int dcn_get_approx_det_segs_required_for_pstate(
815817
struct _vcs_dpi_soc_bounding_box_st *soc,
816818
int pix_clk_100hz, int bpp, int seg_size_kb)
817819
{
820+
dc_assert_fp_enabled();
821+
818822
/* Roughly calculate required crb to hide latency. In practice there is slightly
819823
* more buffer available for latency hiding
820824
*/

drivers/gpu/drm/amd/display/dc/dml/dcn35/dcn35_fpu.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ int dcn35_populate_dml_pipes_from_context_fpu(struct dc *dc,
445445
bool upscaled = false;
446446
const unsigned int max_allowed_vblank_nom = 1023;
447447

448+
dc_assert_fp_enabled();
449+
448450
dcn31_populate_dml_pipes_from_context(dc, context, pipes,
449451
validate_mode);
450452

@@ -498,9 +500,7 @@ int dcn35_populate_dml_pipes_from_context_fpu(struct dc *dc,
498500

499501
pipes[pipe_cnt].pipe.src.unbounded_req_mode = false;
500502

501-
DC_FP_START();
502503
dcn31_zero_pipe_dcc_fraction(pipes, pipe_cnt);
503-
DC_FP_END();
504504

505505
pipes[pipe_cnt].pipe.dest.vfront_porch = timing->v_front_porch;
506506
pipes[pipe_cnt].pipe.src.dcc_rate = 3;
@@ -581,6 +581,8 @@ void dcn35_decide_zstate_support(struct dc *dc, struct dc_state *context)
581581
unsigned int i, plane_count = 0;
582582
DC_LOGGER_INIT(dc->ctx->logger);
583583

584+
dc_assert_fp_enabled();
585+
584586
for (i = 0; i < dc->res_pool->pipe_count; i++) {
585587
if (context->res_ctx.pipe_ctx[i].plane_state)
586588
plane_count++;

drivers/gpu/drm/amd/display/dc/dml/dcn351/dcn351_fpu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,8 @@ int dcn351_populate_dml_pipes_from_context_fpu(struct dc *dc,
478478
bool upscaled = false;
479479
const unsigned int max_allowed_vblank_nom = 1023;
480480

481+
dc_assert_fp_enabled();
482+
481483
dcn31_populate_dml_pipes_from_context(dc, context, pipes,
482484
validate_mode);
483485

@@ -531,9 +533,7 @@ int dcn351_populate_dml_pipes_from_context_fpu(struct dc *dc,
531533

532534
pipes[pipe_cnt].pipe.src.unbounded_req_mode = false;
533535

534-
DC_FP_START();
535536
dcn31_zero_pipe_dcc_fraction(pipes, pipe_cnt);
536-
DC_FP_END();
537537

538538
pipes[pipe_cnt].pipe.dest.vfront_porch = timing->v_front_porch;
539539
pipes[pipe_cnt].pipe.src.dcc_rate = 3;

drivers/gpu/drm/amd/display/dc/resource/dcn35/dcn35_resource.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,20 @@ enum dc_status dcn35_patch_unknown_plane_state(struct dc_plane_state *plane_stat
17601760
}
17611761

17621762

1763+
static int populate_dml_pipes_from_context_fpu(struct dc *dc,
1764+
struct dc_state *context,
1765+
display_e2e_pipe_params_st *pipes,
1766+
enum dc_validate_mode validate_mode)
1767+
{
1768+
int ret;
1769+
1770+
DC_FP_START();
1771+
ret = dcn35_populate_dml_pipes_from_context_fpu(dc, context, pipes, validate_mode);
1772+
DC_FP_END();
1773+
1774+
return ret;
1775+
}
1776+
17631777
static struct resource_funcs dcn35_res_pool_funcs = {
17641778
.destroy = dcn35_destroy_resource_pool,
17651779
.link_enc_create = dcn35_link_encoder_create,
@@ -1770,7 +1784,7 @@ static struct resource_funcs dcn35_res_pool_funcs = {
17701784
.validate_bandwidth = dcn35_validate_bandwidth,
17711785
.calculate_wm_and_dlg = NULL,
17721786
.update_soc_for_wm_a = dcn31_update_soc_for_wm_a,
1773-
.populate_dml_pipes = dcn35_populate_dml_pipes_from_context_fpu,
1787+
.populate_dml_pipes = populate_dml_pipes_from_context_fpu,
17741788
.acquire_free_pipe_as_secondary_dpp_pipe = dcn20_acquire_free_pipe_for_layer,
17751789
.release_pipe = dcn20_release_pipe,
17761790
.add_stream_to_ctx = dcn30_add_stream_to_ctx,

drivers/gpu/drm/amd/display/dc/resource/dcn351/dcn351_resource.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1732,6 +1732,21 @@ static enum dc_status dcn351_validate_bandwidth(struct dc *dc,
17321732
return out ? DC_OK : DC_FAIL_BANDWIDTH_VALIDATE;
17331733
}
17341734

1735+
static int populate_dml_pipes_from_context_fpu(struct dc *dc,
1736+
struct dc_state *context,
1737+
display_e2e_pipe_params_st *pipes,
1738+
enum dc_validate_mode validate_mode)
1739+
{
1740+
int ret;
1741+
1742+
DC_FP_START();
1743+
ret = dcn351_populate_dml_pipes_from_context_fpu(dc, context, pipes, validate_mode);
1744+
DC_FP_END();
1745+
1746+
return ret;
1747+
1748+
}
1749+
17351750
static struct resource_funcs dcn351_res_pool_funcs = {
17361751
.destroy = dcn351_destroy_resource_pool,
17371752
.link_enc_create = dcn35_link_encoder_create,
@@ -1742,7 +1757,7 @@ static struct resource_funcs dcn351_res_pool_funcs = {
17421757
.validate_bandwidth = dcn351_validate_bandwidth,
17431758
.calculate_wm_and_dlg = NULL,
17441759
.update_soc_for_wm_a = dcn31_update_soc_for_wm_a,
1745-
.populate_dml_pipes = dcn351_populate_dml_pipes_from_context_fpu,
1760+
.populate_dml_pipes = populate_dml_pipes_from_context_fpu,
17461761
.acquire_free_pipe_as_secondary_dpp_pipe = dcn20_acquire_free_pipe_for_layer,
17471762
.release_pipe = dcn20_release_pipe,
17481763
.add_stream_to_ctx = dcn30_add_stream_to_ctx,

drivers/gpu/drm/amd/display/dc/resource/dcn36/dcn36_resource.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1734,6 +1734,20 @@ static enum dc_status dcn35_validate_bandwidth(struct dc *dc,
17341734
}
17351735

17361736

1737+
static int populate_dml_pipes_from_context_fpu(struct dc *dc,
1738+
struct dc_state *context,
1739+
display_e2e_pipe_params_st *pipes,
1740+
enum dc_validate_mode validate_mode)
1741+
{
1742+
int ret;
1743+
1744+
DC_FP_START();
1745+
ret = dcn35_populate_dml_pipes_from_context_fpu(dc, context, pipes, validate_mode);
1746+
DC_FP_END();
1747+
1748+
return ret;
1749+
}
1750+
17371751
static struct resource_funcs dcn36_res_pool_funcs = {
17381752
.destroy = dcn36_destroy_resource_pool,
17391753
.link_enc_create = dcn35_link_encoder_create,
@@ -1744,7 +1758,7 @@ static struct resource_funcs dcn36_res_pool_funcs = {
17441758
.validate_bandwidth = dcn35_validate_bandwidth,
17451759
.calculate_wm_and_dlg = NULL,
17461760
.update_soc_for_wm_a = dcn31_update_soc_for_wm_a,
1747-
.populate_dml_pipes = dcn35_populate_dml_pipes_from_context_fpu,
1761+
.populate_dml_pipes = populate_dml_pipes_from_context_fpu,
17481762
.acquire_free_pipe_as_secondary_dpp_pipe = dcn20_acquire_free_pipe_for_layer,
17491763
.release_pipe = dcn20_release_pipe,
17501764
.add_stream_to_ctx = dcn30_add_stream_to_ctx,

0 commit comments

Comments
 (0)