From: Mario Limonciello mario.limonciello@amd.com
[ Upstream commit b174084b3fe15ad1acc69530e673c1535d2e4f85 ]
[Why] If amdgpu_dm failed to initalize before amdgpu_dm_initialize_drm_device() completed then freeing atomic_obj will lead to list corruption.
[How] Check if atomic_obj state is initialized before trying to free.
Reviewed-by: Harry Wentland harry.wentland@amd.com Signed-off-by: Mario Limonciello mario.limonciello@amd.com Signed-off-by: Ivan Lipski ivan.lipski@amd.com Tested-by: Daniel Wheeler daniel.wheeler@amd.com Signed-off-by: Alex Deucher alexander.deucher@amd.com Signed-off-by: Sasha Levin sashal@kernel.org ---
LLM Generated explanations, may be completely bogus:
Now I have a clear understanding of the issue. Let me provide my analysis:
**Backport Status: YES**
This commit should be backported to stable kernel trees for the following reasons:
## Bug Fix Analysis
1. **Clear Bug Fix**: The commit fixes a critical bug that can cause list corruption during cleanup. The issue occurs when `amdgpu_dm_destroy_drm_device()` is called after initialization failure, but before `drm_atomic_private_obj_init()` has been executed.
2. **Crash Prevention**: Looking at the `drm_atomic_private_obj_fini()` implementation in drivers/gpu/drm/drm_atomic.c: ```c list_del(&obj->head); obj->funcs->atomic_destroy_state(obj, obj->state); ``` If `atomic_obj` was never initialized, calling `list_del()` on uninitialized list_head will cause list corruption, and dereferencing `obj->state` and `obj->funcs` will likely cause a kernel panic.
3. **Small and Contained Fix**: The fix is minimal - just adding a simple NULL check: ```c if (dm->atomic_obj.state) drm_atomic_private_obj_fini(&dm->atomic_obj); ```
4. **Clear Failure Path**: The initialization sequence shows: - `amdgpu_dm_initialize_drm_device()` calls `amdgpu_dm_mode_config_init()` - `amdgpu_dm_mode_config_init()` calls `drm_atomic_private_obj_init()` to initialize `atomic_obj` - If `amdgpu_dm_initialize_drm_device()` fails before reaching `amdgpu_dm_mode_config_init()`, the `atomic_obj` remains uninitialized - The error path calls `amdgpu_dm_fini()` which calls `amdgpu_dm_destroy_drm_device()` - Without this fix, `drm_atomic_private_obj_fini()` operates on uninitialized memory
5. **No Side Effects**: The fix only adds a defensive check and doesn't change any existing functionality. It only prevents cleanup of an uninitialized object.
6. **Follows Stable Rules**: This fix: - Fixes a real bug (list corruption/crash) - Is minimal (2 lines of code) - Has low risk of regression - Doesn't introduce new features - Is confined to the AMD display driver subsystem
7. **Initialization Order Issue**: The atomic_obj initialization happens relatively late in the initialization sequence, making this race condition possible in various failure scenarios during driver probe.
This is a textbook example of a commit that should be backported to stable - it fixes a real crash bug with a minimal, safe change that prevents operating on uninitialized data structures.
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c index f58fa5da7fe5..2d92dff6a77a 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -5368,7 +5368,8 @@ static int amdgpu_dm_initialize_drm_device(struct amdgpu_device *adev)
static void amdgpu_dm_destroy_drm_device(struct amdgpu_display_manager *dm) { - drm_atomic_private_obj_fini(&dm->atomic_obj); + if (dm->atomic_obj.state) + drm_atomic_private_obj_fini(&dm->atomic_obj); }
/******************************************************************************