diff options
author | Eric Anholt <eric@anholt.net> | 2016-10-20 19:48:12 -0400 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2016-11-03 21:48:07 -0400 |
commit | 457e67a728696c4f8e6423c64e93def50530db9a (patch) | |
tree | 920dd427cce4eb6fd9584051745e8a57ae98c3cc /drivers/gpu/drm/vc4/vc4_validate_shaders.c | |
parent | b2cdeb19f16ad984eb5bb9193f793d05a8101511 (diff) |
drm/vc4: Fix termination of the initial scan for branch targets.
The loop is scanning until the original max_ip (size of the BO), but
we want to not examine any code after the PROG_END's delay slots.
There was a block trying to do that, except that we had some early
continue statements if the signal wasn't a PROG_END or a BRANCH.
The failure mode would be that a valid shader is rejected because some
undefined memory after the PROG_END slots is parsed as a branch and
the rest of its setup is illegal. I haven't seen this in the wild,
but valgrind was complaining when about this up in the userland
simulator mode.
Signed-off-by: Eric Anholt <eric@anholt.net>
Diffstat (limited to 'drivers/gpu/drm/vc4/vc4_validate_shaders.c')
-rw-r--r-- | drivers/gpu/drm/vc4/vc4_validate_shaders.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/drivers/gpu/drm/vc4/vc4_validate_shaders.c b/drivers/gpu/drm/vc4/vc4_validate_shaders.c index 2543cf5b8b51..917321ce832f 100644 --- a/drivers/gpu/drm/vc4/vc4_validate_shaders.c +++ b/drivers/gpu/drm/vc4/vc4_validate_shaders.c | |||
@@ -608,9 +608,7 @@ static bool | |||
608 | vc4_validate_branches(struct vc4_shader_validation_state *validation_state) | 608 | vc4_validate_branches(struct vc4_shader_validation_state *validation_state) |
609 | { | 609 | { |
610 | uint32_t max_branch_target = 0; | 610 | uint32_t max_branch_target = 0; |
611 | bool found_shader_end = false; | ||
612 | int ip; | 611 | int ip; |
613 | int shader_end_ip = 0; | ||
614 | int last_branch = -2; | 612 | int last_branch = -2; |
615 | 613 | ||
616 | for (ip = 0; ip < validation_state->max_ip; ip++) { | 614 | for (ip = 0; ip < validation_state->max_ip; ip++) { |
@@ -621,8 +619,13 @@ vc4_validate_branches(struct vc4_shader_validation_state *validation_state) | |||
621 | uint32_t branch_target_ip; | 619 | uint32_t branch_target_ip; |
622 | 620 | ||
623 | if (sig == QPU_SIG_PROG_END) { | 621 | if (sig == QPU_SIG_PROG_END) { |
624 | shader_end_ip = ip; | 622 | /* There are two delay slots after program end is |
625 | found_shader_end = true; | 623 | * signaled that are still executed, then we're |
624 | * finished. validation_state->max_ip is the | ||
625 | * instruction after the last valid instruction in the | ||
626 | * program. | ||
627 | */ | ||
628 | validation_state->max_ip = ip + 3; | ||
626 | continue; | 629 | continue; |
627 | } | 630 | } |
628 | 631 | ||
@@ -676,15 +679,9 @@ vc4_validate_branches(struct vc4_shader_validation_state *validation_state) | |||
676 | } | 679 | } |
677 | set_bit(after_delay_ip, validation_state->branch_targets); | 680 | set_bit(after_delay_ip, validation_state->branch_targets); |
678 | max_branch_target = max(max_branch_target, after_delay_ip); | 681 | max_branch_target = max(max_branch_target, after_delay_ip); |
679 | |||
680 | /* There are two delay slots after program end is signaled | ||
681 | * that are still executed, then we're finished. | ||
682 | */ | ||
683 | if (found_shader_end && ip == shader_end_ip + 2) | ||
684 | break; | ||
685 | } | 682 | } |
686 | 683 | ||
687 | if (max_branch_target > shader_end_ip) { | 684 | if (max_branch_target > validation_state->max_ip - 3) { |
688 | DRM_ERROR("Branch landed after QPU_SIG_PROG_END"); | 685 | DRM_ERROR("Branch landed after QPU_SIG_PROG_END"); |
689 | return false; | 686 | return false; |
690 | } | 687 | } |