On Mon, Nov 16, 2026 at 5:34 AM Maxime Ripard <[email protected]> wrote:
>
> drm_mode_config_reset() has a dual role: it creates the initial KMS
> state at probe time, and resets hardware and software state during
> suspend/resume cycles.
>
> Since the two roles need different behaviors (notably for objects like
> drm_private_obj that must persist across suspend/resume),
> drm_mode_config_create_initial_state() was introduced to handle only
> the initial state creation at probe time.
>
> Switch to drm_mode_config_create_initial_state().
>
> Signed-off-by: Maxime Ripard <[email protected]>
> ---
> Cc: Broadcom internal kernel review list 
> <[email protected]>
> Cc: Zack Rusin <[email protected]>
> ---
>  drivers/gpu/drm/vmwgfx/vmwgfx_kms.c  | 14 +++++++++++++-
>  drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c  |  3 ---
>  drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c |  3 ---
>  drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c |  3 ---
>  4 files changed, 13 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c 
> b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> index 90ab9380d883..4924649033bb 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> @@ -1173,15 +1173,27 @@ int vmw_kms_init(struct vmw_private *dev_priv)
>         if (ret) {
>                 ret = vmw_kms_sou_init_display(dev_priv);
>                 if (ret) /* Fallback */
>                         ret = vmw_kms_ldu_init_display(dev_priv);
>         }
> +       if (ret)
> +               return ret;
> +
>         BUILD_BUG_ON(ARRAY_SIZE(display_unit_names) != (vmw_du_max + 1));
>         drm_info(&dev_priv->drm, "%s display unit initialized\n",
>                  display_unit_names[dev_priv->active_display_unit]);
>
> -       return ret;
> +       /*
> +        * Create the initial state once, after the display unit that will
> +        * be used has been settled on: a failure in one of the display
> +        * unit initialization functions is used as a fallback condition to
> +        * try the next one, and creating the state on a partially
> +        * initialized device would both leave the KMS objects of the two
> +        * backends on the same drm_device and trip WARN_ON() on the objects
> +        * that don't have a state.
> +        */
> +       return drm_mode_config_create_initial_state(dev);
>  }
>
>  int vmw_kms_close(struct vmw_private *dev_priv)
>  {
>         int ret = 0;
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c 
> b/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
> index 0dea09cc29a7..dd5ca4dc75e8 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
> @@ -537,11 +537,10 @@ static int vmw_ldu_init(struct vmw_private *dev_priv, 
> unsigned unit)
>         return ret;
>  }
>
>  int vmw_kms_ldu_init_display(struct vmw_private *dev_priv)
>  {
> -       struct drm_device *dev = &dev_priv->drm;
>         int i, ret;
>         int num_display_units = (dev_priv->capabilities & SVGA_CAP_MULTIMON) ?
>                                         VMWGFX_NUM_DISPLAY_UNITS : 1;
>
>         if (unlikely(dev_priv->ldu_priv)) {
> @@ -565,12 +564,10 @@ int vmw_kms_ldu_init_display(struct vmw_private 
> *dev_priv)
>                         goto err_free;
>         }
>
>         dev_priv->active_display_unit = vmw_du_legacy;
>
> -       drm_mode_config_reset(dev);
> -
>         return 0;
>
>  err_free:
>         kfree(dev_priv->ldu_priv);
>         dev_priv->ldu_priv = NULL;
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c 
> b/drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c
> index 39d58fc392bf..291e24456d06 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c
> @@ -921,11 +921,10 @@ static int vmw_sou_init(struct vmw_private *dev_priv, 
> unsigned unit)
>         return ret;
>  }
>
>  int vmw_kms_sou_init_display(struct vmw_private *dev_priv)
>  {
> -       struct drm_device *dev = &dev_priv->drm;
>         int i;
>
>         /* Screen objects won't work if GMR's aren't available */
>         if (!dev_priv->has_gmr)
>                 return -ENOSYS;
> @@ -937,12 +936,10 @@ int vmw_kms_sou_init_display(struct vmw_private 
> *dev_priv)
>         for (i = 0; i < VMWGFX_NUM_DISPLAY_UNITS; ++i)
>                 vmw_sou_init(dev_priv, i);
>
>         dev_priv->active_display_unit = vmw_du_screen_object;
>
> -       drm_mode_config_reset(dev);
> -
>         return 0;
>  }
>
>  static int do_bo_define_gmrfb(struct vmw_private *dev_priv,
>                                   struct vmw_framebuffer *framebuffer)
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c 
> b/drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c
> index b505f8ba3e83..7a3e6ee10932 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c
> @@ -1683,11 +1683,10 @@ static void vmw_stdu_destroy(struct 
> vmw_screen_target_display_unit *stdu)
>   * RETURNS:
>   * 0 on success, error code otherwise
>   */
>  int vmw_kms_stdu_init_display(struct vmw_private *dev_priv)
>  {
> -       struct drm_device *dev = &dev_priv->drm;
>         int i, ret;
>
>
>         /* Do nothing if there's no support for MOBs */
>         if (!dev_priv->has_mob)
> @@ -1706,9 +1705,7 @@ int vmw_kms_stdu_init_display(struct vmw_private 
> *dev_priv)
>                                 "Failed to initialize STDU %d", i);
>                         return ret;
>                 }
>         }
>
> -       drm_mode_config_reset(dev);
> -
>         return 0;
>  }
>
> --
> 2.56.1
>

That's a lot nicer than the v1, thanks. Sashiko is right that it leaks
in case of failure and something like:
- return drm_mode_config_create_initial_state(dev);
+ ret = drm_mode_config_create_initial_state(dev);
+ if (ret)
+ vmw_kms_close(dev_priv);
+
+ return ret;
would fix it but given that the leak happens when the screen failed to
initialize and the user has to deal with blank screen and the
allocation is small I would likely call it a low priority and probably
would be ok submitting as is.
Reviewed-by: Zack Rusin <[email protected]>

z

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to