Skip to content

Commit bb9025f

Browse files
pchelkin91Christoph Hellwig
authored and
Christoph Hellwig
committed
dma-mapping: benchmark: fix up kthread-related error handling
kthread creation failure is invalidly handled inside do_map_benchmark(). The put_task_struct() calls on the error path are supposed to balance the get_task_struct() calls which only happen after all the kthreads are successfully created. Rollback using kthread_stop() for already created kthreads in case of such failure. In normal situation call kthread_stop_put() to gracefully stop kthreads and put their task refcounts. This should be done for all started kthreads. Found by Linux Verification Center (linuxtesting.org). Fixes: 65789da ("dma-mapping: add benchmark support for streaming DMA APIs") Suggested-by: Robin Murphy <[email protected]> Signed-off-by: Fedor Pchelkin <[email protected]> Reviewed-by: Robin Murphy <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent c760b37 commit bb9025f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

kernel/dma/map_benchmark.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ static int do_map_benchmark(struct map_benchmark_data *map)
118118
if (IS_ERR(tsk[i])) {
119119
pr_err("create dma_map thread failed\n");
120120
ret = PTR_ERR(tsk[i]);
121+
while (--i >= 0)
122+
kthread_stop(tsk[i]);
121123
goto out;
122124
}
123125

@@ -139,13 +141,17 @@ static int do_map_benchmark(struct map_benchmark_data *map)
139141

140142
msleep_interruptible(map->bparam.seconds * 1000);
141143

142-
/* wait for the completion of benchmark threads */
144+
/* wait for the completion of all started benchmark threads */
143145
for (i = 0; i < threads; i++) {
144-
ret = kthread_stop(tsk[i]);
145-
if (ret)
146-
goto out;
146+
int kthread_ret = kthread_stop_put(tsk[i]);
147+
148+
if (kthread_ret)
149+
ret = kthread_ret;
147150
}
148151

152+
if (ret)
153+
goto out;
154+
149155
loops = atomic64_read(&map->loops);
150156
if (likely(loops > 0)) {
151157
u64 map_variance, unmap_variance;
@@ -170,8 +176,6 @@ static int do_map_benchmark(struct map_benchmark_data *map)
170176
}
171177

172178
out:
173-
for (i = 0; i < threads; i++)
174-
put_task_struct(tsk[i]);
175179
put_device(map->dev);
176180
kfree(tsk);
177181
return ret;

0 commit comments

Comments
 (0)