0537-drm-vc4-Fix-termination-of-the-initial-scan-for-bran.patch 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. From 1f42fbc79dea3529dd919249ee6e58f157704aaf Mon Sep 17 00:00:00 2001
  2. From: Eric Anholt <eric@anholt.net>
  3. Date: Thu, 20 Oct 2016 16:48:12 -0700
  4. Subject: [PATCH] drm/vc4: Fix termination of the initial scan for branch
  5. targets.
  6. The loop is scanning until the original max_ip (size of the BO), but
  7. we want to not examine any code after the PROG_END's delay slots.
  8. There was a block trying to do that, except that we had some early
  9. continue statements if the signal wasn't a PROG_END or a BRANCH.
  10. The failure mode would be that a valid shader is rejected because some
  11. undefined memory after the PROG_END slots is parsed as a branch and
  12. the rest of its setup is illegal. I haven't seen this in the wild,
  13. but valgrind was complaining when about this up in the userland
  14. simulator mode.
  15. Signed-off-by: Eric Anholt <eric@anholt.net>
  16. (cherry picked from commit 457e67a728696c4f8e6423c64e93def50530db9a)
  17. ---
  18. drivers/gpu/drm/vc4/vc4_validate_shaders.c | 19 ++++++++-----------
  19. 1 file changed, 8 insertions(+), 11 deletions(-)
  20. --- a/drivers/gpu/drm/vc4/vc4_validate_shaders.c
  21. +++ b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
  22. @@ -608,9 +608,7 @@ static bool
  23. vc4_validate_branches(struct vc4_shader_validation_state *validation_state)
  24. {
  25. uint32_t max_branch_target = 0;
  26. - bool found_shader_end = false;
  27. int ip;
  28. - int shader_end_ip = 0;
  29. int last_branch = -2;
  30. for (ip = 0; ip < validation_state->max_ip; ip++) {
  31. @@ -621,8 +619,13 @@ vc4_validate_branches(struct vc4_shader_
  32. uint32_t branch_target_ip;
  33. if (sig == QPU_SIG_PROG_END) {
  34. - shader_end_ip = ip;
  35. - found_shader_end = true;
  36. + /* There are two delay slots after program end is
  37. + * signaled that are still executed, then we're
  38. + * finished. validation_state->max_ip is the
  39. + * instruction after the last valid instruction in the
  40. + * program.
  41. + */
  42. + validation_state->max_ip = ip + 3;
  43. continue;
  44. }
  45. @@ -676,15 +679,9 @@ vc4_validate_branches(struct vc4_shader_
  46. }
  47. set_bit(after_delay_ip, validation_state->branch_targets);
  48. max_branch_target = max(max_branch_target, after_delay_ip);
  49. -
  50. - /* There are two delay slots after program end is signaled
  51. - * that are still executed, then we're finished.
  52. - */
  53. - if (found_shader_end && ip == shader_end_ip + 2)
  54. - break;
  55. }
  56. - if (max_branch_target > shader_end_ip) {
  57. + if (max_branch_target > validation_state->max_ip - 3) {
  58. DRM_ERROR("Branch landed after QPU_SIG_PROG_END");
  59. return false;
  60. }