819-Revert-dmaengine-dmatest-move-callback-wait-queue-to.patch 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. From 8772422ee95b17d87b5cb6cb4318b7ec73f4cfcf Mon Sep 17 00:00:00 2001
  2. From: Yangbo Lu <[email protected]>
  3. Date: Mon, 29 Jan 2018 18:04:07 +0800
  4. Subject: [PATCH] Revert "dmaengine: dmatest: move callback wait queue to
  5. thread context"
  6. This reverts commit 679dbeac0b6bb551e1f3b95673695b22b2ac953d.
  7. ---
  8. drivers/dma/dmatest.c | 55 ++++++++++++++++++++++-----------------------------
  9. 1 file changed, 24 insertions(+), 31 deletions(-)
  10. --- a/drivers/dma/dmatest.c
  11. +++ b/drivers/dma/dmatest.c
  12. @@ -158,12 +158,6 @@ MODULE_PARM_DESC(run, "Run the test (def
  13. #define PATTERN_OVERWRITE 0x20
  14. #define PATTERN_COUNT_MASK 0x1f
  15. -/* poor man's completion - we want to use wait_event_freezable() on it */
  16. -struct dmatest_done {
  17. - bool done;
  18. - wait_queue_head_t *wait;
  19. -};
  20. -
  21. struct dmatest_thread {
  22. struct list_head node;
  23. struct dmatest_info *info;
  24. @@ -172,8 +166,6 @@ struct dmatest_thread {
  25. u8 **srcs;
  26. u8 **dsts;
  27. enum dma_transaction_type type;
  28. - wait_queue_head_t done_wait;
  29. - struct dmatest_done test_done;
  30. bool done;
  31. };
  32. @@ -334,25 +326,18 @@ static unsigned int dmatest_verify(u8 **
  33. return error_count;
  34. }
  35. +/* poor man's completion - we want to use wait_event_freezable() on it */
  36. +struct dmatest_done {
  37. + bool done;
  38. + wait_queue_head_t *wait;
  39. +};
  40. static void dmatest_callback(void *arg)
  41. {
  42. struct dmatest_done *done = arg;
  43. - struct dmatest_thread *thread =
  44. - container_of(arg, struct dmatest_thread, done_wait);
  45. - if (!thread->done) {
  46. - done->done = true;
  47. - wake_up_all(done->wait);
  48. - } else {
  49. - /*
  50. - * If thread->done, it means that this callback occurred
  51. - * after the parent thread has cleaned up. This can
  52. - * happen in the case that driver doesn't implement
  53. - * the terminate_all() functionality and a dma operation
  54. - * did not occur within the timeout period
  55. - */
  56. - WARN(1, "dmatest: Kernel memory may be corrupted!!\n");
  57. - }
  58. +
  59. + done->done = true;
  60. + wake_up_all(done->wait);
  61. }
  62. static unsigned int min_odd(unsigned int x, unsigned int y)
  63. @@ -423,8 +408,9 @@ static unsigned long long dmatest_KBs(s6
  64. */
  65. static int dmatest_func(void *data)
  66. {
  67. + DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_wait);
  68. struct dmatest_thread *thread = data;
  69. - struct dmatest_done *done = &thread->test_done;
  70. + struct dmatest_done done = { .wait = &done_wait };
  71. struct dmatest_info *info;
  72. struct dmatest_params *params;
  73. struct dma_chan *chan;
  74. @@ -651,9 +637,9 @@ static int dmatest_func(void *data)
  75. continue;
  76. }
  77. - done->done = false;
  78. + done.done = false;
  79. tx->callback = dmatest_callback;
  80. - tx->callback_param = done;
  81. + tx->callback_param = &done;
  82. cookie = tx->tx_submit(tx);
  83. if (dma_submit_error(cookie)) {
  84. @@ -666,12 +652,21 @@ static int dmatest_func(void *data)
  85. }
  86. dma_async_issue_pending(chan);
  87. - wait_event_freezable_timeout(thread->done_wait, done->done,
  88. + wait_event_freezable_timeout(done_wait, done.done,
  89. msecs_to_jiffies(params->timeout));
  90. status = dma_async_is_tx_complete(chan, cookie, NULL, NULL);
  91. - if (!done->done) {
  92. + if (!done.done) {
  93. + /*
  94. + * We're leaving the timed out dma operation with
  95. + * dangling pointer to done_wait. To make this
  96. + * correct, we'll need to allocate wait_done for
  97. + * each test iteration and perform "who's gonna
  98. + * free it this time?" dancing. For now, just
  99. + * leave it dangling.
  100. + */
  101. + WARN(1, "dmatest: Kernel stack may be corrupted!!\n");
  102. dmaengine_unmap_put(um);
  103. result("test timed out", total_tests, src_off, dst_off,
  104. len, 0);
  105. @@ -752,7 +747,7 @@ err_thread_type:
  106. dmatest_KBs(runtime, total_len), ret);
  107. /* terminate all transfers on specified channels */
  108. - if (ret || failed_tests)
  109. + if (ret)
  110. dmaengine_terminate_all(chan);
  111. thread->done = true;
  112. @@ -812,8 +807,6 @@ static int dmatest_add_threads(struct dm
  113. thread->info = info;
  114. thread->chan = dtc->chan;
  115. thread->type = type;
  116. - thread->test_done.wait = &thread->done_wait;
  117. - init_waitqueue_head(&thread->done_wait);
  118. smp_wmb();
  119. thread->task = kthread_create(dmatest_func, thread, "%s-%s%u",
  120. dma_chan_name(chan), op, i);