From 2435b93cb8c9572bf404bb6e903349604c5af0be Mon Sep 17 00:00:00 2001 From: ajeshkv Date: Tue, 1 Dec 2020 16:34:21 +0530 Subject: [PATCH] gpu: nvgpu: fix for worker thread unit test Fix a possible issue which could arise due to invoking the function nvgpu_worker_init twice on same worker thread. A worker poll task thread could be already using the mutex/condition variable when the second init invocation is done, leading to an undefined behaviour. Second invocation is done for branch coverage, which can be done using a different worker with thread running status set. Bug 3180383 Change-Id: Ife2917e349aa039a4e0baa399c696a7c9ab3015e Signed-off-by: ajeshkv Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2453218 Reviewed-by: automaticguardword Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: svc-mobile-coverity Reviewed-by: Alex Waterman Reviewed-by: Sagar Kamble Reviewed-by: Philip Elcan Reviewed-by: Vaibhav Kachore Reviewed-by: mobile promotions GVS: Gerrit_Virtual_Submit Tested-by: mobile promotions --- userspace/units/interface/worker/worker.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/userspace/units/interface/worker/worker.c b/userspace/units/interface/worker/worker.c index 81d79f09a..961418a13 100644 --- a/userspace/units/interface/worker/worker.c +++ b/userspace/units/interface/worker/worker.c @@ -95,6 +95,7 @@ static u32 wakeup_timeout(struct nvgpu_worker *worker) } _Thread_local struct nvgpu_worker worker; +_Thread_local struct nvgpu_worker worker_branch; _Thread_local struct nvgpu_worker_ops worker_ops = { /* pre_process is NULL for branch testing for NULL when thread starts. */ .pre_process = NULL, @@ -136,7 +137,9 @@ int test_init(struct unit_module *m, struct gk20a *g, void *args) while (!nvgpu_thread_is_running(&worker.poll_task)) { nvgpu_udelay(5); } - err = nvgpu_worker_init(g, &worker, &worker_ops); + + nvgpu_atomic_set(&worker_branch.poll_task.running, 1); + err = nvgpu_worker_init(g, &worker_branch, &worker_ops); unit_assert(err == 0, return UNIT_FAIL); return UNIT_SUCCESS;