Patch "dma-mapping: benchmark: fix up kthread-related error handling" has been added to the 6.8-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    dma-mapping: benchmark: fix up kthread-related error handling

to the 6.8-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     dma-mapping-benchmark-fix-up-kthread-related-error-h.patch
and it can be found in the queue-6.8 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 43254f21bc6b9616746e41b9460cdc9707d80867
Author: Fedor Pchelkin <pchelkin@xxxxxxxxx>
Date:   Sat May 4 14:47:01 2024 +0300

    dma-mapping: benchmark: fix up kthread-related error handling
    
    [ Upstream commit bb9025f4432f8c158322cf2c04c2b492f23eb511 ]
    
    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: 65789daa8087 ("dma-mapping: add benchmark support for streaming DMA APIs")
    Suggested-by: Robin Murphy <robin.murphy@xxxxxxx>
    Signed-off-by: Fedor Pchelkin <pchelkin@xxxxxxxxx>
    Reviewed-by: Robin Murphy <robin.murphy@xxxxxxx>
    Signed-off-by: Christoph Hellwig <hch@xxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/kernel/dma/map_benchmark.c b/kernel/dma/map_benchmark.c
index 02205ab53b7e9..2478957cf9f83 100644
--- a/kernel/dma/map_benchmark.c
+++ b/kernel/dma/map_benchmark.c
@@ -118,6 +118,8 @@ static int do_map_benchmark(struct map_benchmark_data *map)
 		if (IS_ERR(tsk[i])) {
 			pr_err("create dma_map thread failed\n");
 			ret = PTR_ERR(tsk[i]);
+			while (--i >= 0)
+				kthread_stop(tsk[i]);
 			goto out;
 		}
 
@@ -139,13 +141,17 @@ static int do_map_benchmark(struct map_benchmark_data *map)
 
 	msleep_interruptible(map->bparam.seconds * 1000);
 
-	/* wait for the completion of benchmark threads */
+	/* wait for the completion of all started benchmark threads */
 	for (i = 0; i < threads; i++) {
-		ret = kthread_stop(tsk[i]);
-		if (ret)
-			goto out;
+		int kthread_ret = kthread_stop_put(tsk[i]);
+
+		if (kthread_ret)
+			ret = kthread_ret;
 	}
 
+	if (ret)
+		goto out;
+
 	loops = atomic64_read(&map->loops);
 	if (likely(loops > 0)) {
 		u64 map_variance, unmap_variance;
@@ -170,8 +176,6 @@ static int do_map_benchmark(struct map_benchmark_data *map)
 	}
 
 out:
-	for (i = 0; i < threads; i++)
-		put_task_struct(tsk[i]);
 	put_device(map->dev);
 	kfree(tsk);
 	return ret;




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux