From: Maarten Lankhorst <[email protected]> [ Upstream commit a58d487fb1a52579d3c37544ea371da78ed70c45 ]
Fix a compile error in the kunit tests when CONFIG_PREEMPT_RT is enabled, and the normal mutex is converted into a rtmutex. Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Reviewed-by: Jouni Högander <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Maarten Lankhorst <[email protected]> Signed-off-by: Sasha Levin <[email protected]> --- LLM Generated explanations, may be completely bogus: ## Analysis **What the commit does:** Fixes a build failure in `ttm_bo_reserve_interrupted()` kunit test when `CONFIG_PREEMPT_RT` is enabled. On PREEMPT_RT, `struct mutex` becomes `struct rt_mutex`, so direct `mutex_lock(&bo->base.resv->lock.base)` calls fail to compile. The fix replaces the raw mutex calls with the proper `dma_resv_lock()`/`dma_resv_unlock()` API, which correctly abstracts the underlying lock type. **Type of fix:** Build fix — prevents compilation failure under a valid kernel configuration (PREEMPT_RT). **Scope:** Extremely small — 2 lines changed in a test file. Changes `mutex_lock` → `dma_resv_lock` and `mutex_unlock` → `dma_resv_unlock`. The `dma_resv_*` API has been available for many kernel versions and is the proper way to lock reservation objects. **Affected versions:** The test file was introduced in v6.9-rc1 (commit 995279d280d1e). A similar fix for a *different function* (`ttm_bo_reserve_deadlock`) was done in v6.11-rc1 (commit f85376c890ef4), but it missed this second instance in `ttm_bo_reserve_interrupted`. The buggy code exists in v6.12 and v6.13 stable trees. The file doesn't exist in v6.1 or v6.6 (pre-v6.9). **Risk assessment:** Extremely low risk. This is a 2-line change in test code only, using well-established APIs. It cannot cause runtime regressions in production code. The `dma_resv_lock(obj, NULL)` call is semantically equivalent to locking the underlying ww_mutex without a context, which is what the original `mutex_lock` was doing. **Stable criteria assessment:** - Obviously correct and tested: Yes — uses standard API, reviewed by Jouni Högander, reported by kernel test robot - Fixes a real bug: Yes — build failure with PREEMPT_RT - Important issue: Build fixes are explicitly listed as stable-worthy in the rules - Small and contained: Yes — 2 lines in one test file - No new features: Correct **Verification:** - `git log --diff-filter=A` confirmed the test file was introduced in commit 995279d280d1e (v6.9-rc1) - `git show v6.12:...ttm_bo_test.c` confirmed the buggy `mutex_lock(&bo->base.resv->lock.base)` exists at line 225 in v6.12 - `git show v6.13:...ttm_bo_test.c` confirmed the same buggy code exists in v6.13 - `git show v6.6/v6.1:...ttm_bo_test.c` confirmed the file does NOT exist in these older stable trees - `git show v6.12:include/linux/dma-resv.h` confirmed `dma_resv_lock`/`dma_resv_unlock` API exists in v6.12 - Previous related fix f85376c890ef4 confirmed this is the same class of PREEMPT_RT build issue but in a different function (`ttm_bo_reserve_deadlock` vs `ttm_bo_reserve_interrupted`) - The commit has `Reported-by: kernel test robot` and `Reviewed-by: Jouni Högander`, confirming it was properly tested and reviewed This is a straightforward build fix — small, correct, zero runtime risk, and applies to existing stable trees (v6.12, v6.13). Build fixes are explicitly allowed in stable. **YES** drivers/gpu/drm/ttm/tests/ttm_bo_test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/ttm/tests/ttm_bo_test.c b/drivers/gpu/drm/ttm/tests/ttm_bo_test.c index d468f83220720..f3103307b5df9 100644 --- a/drivers/gpu/drm/ttm/tests/ttm_bo_test.c +++ b/drivers/gpu/drm/ttm/tests/ttm_bo_test.c @@ -222,13 +222,13 @@ static void ttm_bo_reserve_interrupted(struct kunit *test) KUNIT_FAIL(test, "Couldn't create ttm bo reserve task\n"); /* Take a lock so the threaded reserve has to wait */ - mutex_lock(&bo->base.resv->lock.base); + dma_resv_lock(bo->base.resv, NULL); wake_up_process(task); msleep(20); err = kthread_stop(task); - mutex_unlock(&bo->base.resv->lock.base); + dma_resv_unlock(bo->base.resv); KUNIT_ASSERT_EQ(test, err, -ERESTARTSYS); } -- 2.51.0
