Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/amd/display: brightness race in
  amdgpu_dm_atomic_commit_tail()
- [Low] drm/amd/display: duplicate drmm_mode_config_init() in backlight
  KUnit tests
--

commit 846a4ea0302b706193f324593664f491fbb89bfe
Author: Mario Limonciello <[email protected]>

drm/amd: add luminance property support

This commit exposes the DRM LUMINANCE connector property for internal
panels when CONFIG_DRM_LUMINANCE is enabled and updates the backlight
KUnit fixtures.

> 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 56fca4e22df8d..8b5dde608266a 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
[ ... ]
> @@ -5188,6 +5189,13 @@ static void amdgpu_dm_atomic_commit_tail(struct 
> drm_atomic_commit *state)
>               amdgpu_dm_commit_streams(state, dc_state);
>       }
>  
> +     /*
> +      * Apply connector luminance now that the streams are committed. Display
> +      * Core resets the panel brightness when it enables a stream, and the
> +      * helper reprograms LUMINANCE panels after a modeset.
> +      */
> +     drm_atomic_helper_commit_luminance_enables(state);
> +
>       amdgpu_dm_update_hdcp(state);
>  
>       /* Handle connector state changes */
> @@ -5415,8 +5423,8 @@ static void amdgpu_dm_atomic_commit_tail(struct 
> drm_atomic_commit *state)
>  
>       /* restore the backlight level */
>       for (i = 0; i < dm->num_of_edps; i++) {
> -             if (dm->backlight_dev[i] &&
> -                 (dm->actual_brightness[i] != dm->brightness[i]))
> +             if ((dm->backlight_dev[i] || dm->luminance[i]) &&
> +                 dm->actual_brightness[i] != dm->brightness[i])
>                       amdgpu_dm_backlight_set_level(dm, i, dm->brightness[i]);
>       }
>  

[Severity: Medium]
Can the unlocked retry loop at the end of amdgpu_dm_atomic_commit_tail()
race with a concurrent luminance commit and overwrite a newer brightness
level with a stale one?

Fast atomic updates on disjoint CRTCs run amdgpu_dm_atomic_commit_tail()
concurrently without taking the global dm.atomic_obj lock.  Inside
amdgpu_dm_backlight_set_level(), dm->brightness[bl_idx] is updated before
acquiring dm->dc_lock, while dm->actual_brightness[bl_idx] is updated only
after releasing dm->dc_lock:

CPU0 (eDP panel commit)           CPU1 (other CRTC commit)
amdgpu_dm_atomic_commit_tail()
  ...
  amdgpu_dm_backlight_set_level(..., B1)
    dm->brightness[0] = B1;
    mutex_lock(&dm->dc_lock);
                                  amdgpu_dm_atomic_commit_tail()
                                    /* actual_brightness[0] != B1 */
                                    val = dm->brightness[0]; /* B1 */
    ...
    mutex_unlock(&dm->dc_lock);
    dm->actual_brightness[0] = B1;

/* next luminance commit B2 on CPU0 */
amdgpu_dm_atomic_commit_tail()
  ...
  amdgpu_dm_backlight_set_level(..., B2)
    dm->brightness[0] = B2;
    ...
    dm->actual_brightness[0] = B2;
                                    amdgpu_dm_backlight_set_level(..., B1)
                                      dm->brightness[0] = B1;
                                        <-- overwrites B2 with stale B1

This leaves the panel hardware brightness and dm->brightness[0] out of
sync with connector->state->luminance.  In addition, when CPU1 runs
amdgpu_dm_backlight_set_level() after CPU0 has already finished
amdgpu_dm_commit_planes(), it re-asserts psr_event_hw_programming and
replay_event_hw_programming with no subsequent plane flip to clear them,
keeping PSR and Replay disabled until a later flip.

> diff --git 
> a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_backlight_test.c 
> b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_backlight_test.c
> index 8fc1c2f997688..c33c121a19b25 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_backlight_test.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_backlight_test.c
> @@ -37,16 +37,39 @@ static const struct drm_connector_funcs 
> dm_backlight_test_connector_funcs = {
[ ... ]
>  static void setup_test_connector(struct kunit *test,
>                                struct dm_backlight_connector_fixture *fixture,
>                                int bl_idx, enum signal_type signal)
>  {
> -     fixture->adev = kunit_kzalloc(test, sizeof(*fixture->adev), GFP_KERNEL);
> -     fixture->aconnector = kunit_kzalloc(test, sizeof(*fixture->aconnector), 
> GFP_KERNEL);
> +     int ret;
> +
> +     fixture->adev = dm_kunit_alloc_adev(test);
> +     ret = drmm_mode_config_init(&fixture->adev->ddev);
> +     KUNIT_ASSERT_EQ(test, ret, 0);
[ ... ]
> @@ -483,12 +506,17 @@ static void 
> dm_test_register_backlight_device_success(struct kunit *test)
>       struct dc_link *link = dm_kunit_alloc_link(test);
>       struct drm_minor *primary;
>       unsigned int max;
> +     int ret;
> +
> +     ret = drmm_mode_config_init(&adev->ddev);
> +     KUNIT_ASSERT_EQ(test, ret, 0);

[Severity: Low]
Does calling drmm_mode_config_init() in setup_test_connector() and
dm_test_register_backlight_device_success() reinitialize mode_config a
second time and leak the standard DRM properties?

dm_kunit_alloc_adev() allocates the DRM device through
__drm_kunit_helper_alloc_drm_device() ->
__drm_kunit_helper_alloc_drm_device_with_driver(), which already calls
drmm_mode_config_init() when DRIVER_MODESET is set.  Calling
drmm_mode_config_init() again overwrites mode_config.property_list and
mode_config.object_idr in place, leaking the standard properties allocated
by the first call and registering a second drm_mode_config_init_release
cleanup action.

-- 
Sashiko AI review · 
https://sashiko.dev/#/patchset/[email protected]?part=4

Reply via email to