diff mbox series

[RFT,v2,09/12] drm/exynos: Call drm_atomic_helper_shutdown() at shutdown/unbind time

Message ID 20230921122641.RFT.v2.9.Iea33274908b6b258955f45a8aaf6f5bba24ad6cd@changeid (mailing list archive)
State New, archived
Headers show
Series drm: call drm_atomic_helper_shutdown() at the right times | expand

Commit Message

Doug Anderson Sept. 21, 2023, 7:26 p.m. UTC
Based on grepping through the source code this driver appears to be
missing a call to drm_atomic_helper_shutdown() at system shutdown time
and at driver unbind time. Among other things, this means that if a
panel is in use that it won't be cleanly powered off at system
shutdown time.

The fact that we should call drm_atomic_helper_shutdown() in the case
of OS shutdown/restart and at driver remove (or unbind) time comes
straight out of the kernel doc "driver instance overview" in
drm_drv.c.

A few notes about this fix:
- When adding drm_atomic_helper_shutdown() to the unbind path, I added
  it after drm_kms_helper_poll_fini() since that's when other drivers
  seemed to have it.
- Technically with a previous patch, ("drm/atomic-helper:
  drm_atomic_helper_shutdown(NULL) should be a noop"), we don't
  actually need to check to see if our "drm" pointer is NULL before
  calling drm_atomic_helper_shutdown(). We'll leave the "if" test in,
  though, so that this patch can land without any dependencies. It
  could potentially be removed later.
- This patch also makes sure to set the drvdata to NULL in the case of
  bind errors to make sure that shutdown can't access freed data.

Suggested-by: Maxime Ripard <mripard@kernel.org>
Reviewed-by: Maxime Ripard <mripard@kernel.org>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---
This commit is only compile-time tested.

(no changes since v1)

 drivers/gpu/drm/exynos/exynos_drm_drv.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Marek Szyprowski Sept. 22, 2023, 5:55 a.m. UTC | #1
On 21.09.2023 21:26, Douglas Anderson wrote:
> Based on grepping through the source code this driver appears to be
> missing a call to drm_atomic_helper_shutdown() at system shutdown time
> and at driver unbind time. Among other things, this means that if a
> panel is in use that it won't be cleanly powered off at system
> shutdown time.
>
> The fact that we should call drm_atomic_helper_shutdown() in the case
> of OS shutdown/restart and at driver remove (or unbind) time comes
> straight out of the kernel doc "driver instance overview" in
> drm_drv.c.
>
> A few notes about this fix:
> - When adding drm_atomic_helper_shutdown() to the unbind path, I added
>    it after drm_kms_helper_poll_fini() since that's when other drivers
>    seemed to have it.
> - Technically with a previous patch, ("drm/atomic-helper:
>    drm_atomic_helper_shutdown(NULL) should be a noop"), we don't
>    actually need to check to see if our "drm" pointer is NULL before
>    calling drm_atomic_helper_shutdown(). We'll leave the "if" test in,
>    though, so that this patch can land without any dependencies. It
>    could potentially be removed later.
> - This patch also makes sure to set the drvdata to NULL in the case of
>    bind errors to make sure that shutdown can't access freed data.
>
> Suggested-by: Maxime Ripard <mripard@kernel.org>
> Reviewed-by: Maxime Ripard <mripard@kernel.org>
> Signed-off-by: Douglas Anderson <dianders@chromium.org>

Seems to be working fine on all my test Exynos-based boards with display.

Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>

Reviewed-by: Marek Szyprowski <m.szyprowski@samsung.com>

> ---
> This commit is only compile-time tested.
>
> (no changes since v1)
>
>   drivers/gpu/drm/exynos/exynos_drm_drv.c | 11 +++++++++++
>   1 file changed, 11 insertions(+)
>
> diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c
> index 8399256cb5c9..5380fb6c55ae 100644
> --- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
> +++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
> @@ -300,6 +300,7 @@ static int exynos_drm_bind(struct device *dev)
>   	drm_mode_config_cleanup(drm);
>   	exynos_drm_cleanup_dma(drm);
>   	kfree(private);
> +	dev_set_drvdata(dev, NULL);
>   err_free_drm:
>   	drm_dev_put(drm);
>   
> @@ -313,6 +314,7 @@ static void exynos_drm_unbind(struct device *dev)
>   	drm_dev_unregister(drm);
>   
>   	drm_kms_helper_poll_fini(drm);
> +	drm_atomic_helper_shutdown(drm);
>   
>   	component_unbind_all(drm->dev, drm);
>   	drm_mode_config_cleanup(drm);
> @@ -350,9 +352,18 @@ static int exynos_drm_platform_remove(struct platform_device *pdev)
>   	return 0;
>   }
>   
> +static void exynos_drm_platform_shutdown(struct platform_device *pdev)
> +{
> +	struct drm_device *drm = platform_get_drvdata(pdev);
> +
> +	if (drm)
> +		drm_atomic_helper_shutdown(drm);
> +}
> +
>   static struct platform_driver exynos_drm_platform_driver = {
>   	.probe	= exynos_drm_platform_probe,
>   	.remove	= exynos_drm_platform_remove,
> +	.shutdown = exynos_drm_platform_shutdown,
>   	.driver	= {
>   		.name	= "exynos-drm",
>   		.pm	= &exynos_drm_pm_ops,

Best regards
Inki Dae Oct. 6, 2023, 2:19 a.m. UTC | #2
Thanks for testing. :)

Acked-by : Inki Dae <inki.dae@samsung.com>

2023년 9월 22일 (금) 오후 3:00, Marek Szyprowski <m.szyprowski@samsung.com>님이 작성:
>
>
> On 21.09.2023 21:26, Douglas Anderson wrote:
> > Based on grepping through the source code this driver appears to be
> > missing a call to drm_atomic_helper_shutdown() at system shutdown time
> > and at driver unbind time. Among other things, this means that if a
> > panel is in use that it won't be cleanly powered off at system
> > shutdown time.
> >
> > The fact that we should call drm_atomic_helper_shutdown() in the case
> > of OS shutdown/restart and at driver remove (or unbind) time comes
> > straight out of the kernel doc "driver instance overview" in
> > drm_drv.c.
> >
> > A few notes about this fix:
> > - When adding drm_atomic_helper_shutdown() to the unbind path, I added
> >    it after drm_kms_helper_poll_fini() since that's when other drivers
> >    seemed to have it.
> > - Technically with a previous patch, ("drm/atomic-helper:
> >    drm_atomic_helper_shutdown(NULL) should be a noop"), we don't
> >    actually need to check to see if our "drm" pointer is NULL before
> >    calling drm_atomic_helper_shutdown(). We'll leave the "if" test in,
> >    though, so that this patch can land without any dependencies. It
> >    could potentially be removed later.
> > - This patch also makes sure to set the drvdata to NULL in the case of
> >    bind errors to make sure that shutdown can't access freed data.
> >
> > Suggested-by: Maxime Ripard <mripard@kernel.org>
> > Reviewed-by: Maxime Ripard <mripard@kernel.org>
> > Signed-off-by: Douglas Anderson <dianders@chromium.org>
>
> Seems to be working fine on all my test Exynos-based boards with display.
>
> Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
>
> Reviewed-by: Marek Szyprowski <m.szyprowski@samsung.com>
>
> > ---
> > This commit is only compile-time tested.
> >
> > (no changes since v1)
> >
> >   drivers/gpu/drm/exynos/exynos_drm_drv.c | 11 +++++++++++
> >   1 file changed, 11 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c
> > index 8399256cb5c9..5380fb6c55ae 100644
> > --- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
> > +++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
> > @@ -300,6 +300,7 @@ static int exynos_drm_bind(struct device *dev)
> >       drm_mode_config_cleanup(drm);
> >       exynos_drm_cleanup_dma(drm);
> >       kfree(private);
> > +     dev_set_drvdata(dev, NULL);
> >   err_free_drm:
> >       drm_dev_put(drm);
> >
> > @@ -313,6 +314,7 @@ static void exynos_drm_unbind(struct device *dev)
> >       drm_dev_unregister(drm);
> >
> >       drm_kms_helper_poll_fini(drm);
> > +     drm_atomic_helper_shutdown(drm);
> >
> >       component_unbind_all(drm->dev, drm);
> >       drm_mode_config_cleanup(drm);
> > @@ -350,9 +352,18 @@ static int exynos_drm_platform_remove(struct platform_device *pdev)
> >       return 0;
> >   }
> >
> > +static void exynos_drm_platform_shutdown(struct platform_device *pdev)
> > +{
> > +     struct drm_device *drm = platform_get_drvdata(pdev);
> > +
> > +     if (drm)
> > +             drm_atomic_helper_shutdown(drm);
> > +}
> > +
> >   static struct platform_driver exynos_drm_platform_driver = {
> >       .probe  = exynos_drm_platform_probe,
> >       .remove = exynos_drm_platform_remove,
> > +     .shutdown = exynos_drm_platform_shutdown,
> >       .driver = {
> >               .name   = "exynos-drm",
> >               .pm     = &exynos_drm_pm_ops,
>
> Best regards
> --
> Marek Szyprowski, PhD
> Samsung R&D Institute Poland
>
Doug Anderson Oct. 6, 2023, 1:50 p.m. UTC | #3
Hi,

On Thu, Oct 5, 2023 at 7:20 PM Inki Dae <daeinki@gmail.com> wrote:
>
> Thanks for testing. :)
>
> Acked-by : Inki Dae <inki.dae@samsung.com>

Inki: does that mean you'd like this to go through drm-misc? I'm happy
to do that, but there are no dependencies here so this could easily go
through your tree.


> 2023년 9월 22일 (금) 오후 3:00, Marek Szyprowski <m.szyprowski@samsung.com>님이 작성:
> >
> >
> > On 21.09.2023 21:26, Douglas Anderson wrote:
> > > Based on grepping through the source code this driver appears to be
> > > missing a call to drm_atomic_helper_shutdown() at system shutdown time
> > > and at driver unbind time. Among other things, this means that if a
> > > panel is in use that it won't be cleanly powered off at system
> > > shutdown time.
> > >
> > > The fact that we should call drm_atomic_helper_shutdown() in the case
> > > of OS shutdown/restart and at driver remove (or unbind) time comes
> > > straight out of the kernel doc "driver instance overview" in
> > > drm_drv.c.
> > >
> > > A few notes about this fix:
> > > - When adding drm_atomic_helper_shutdown() to the unbind path, I added
> > >    it after drm_kms_helper_poll_fini() since that's when other drivers
> > >    seemed to have it.
> > > - Technically with a previous patch, ("drm/atomic-helper:
> > >    drm_atomic_helper_shutdown(NULL) should be a noop"), we don't
> > >    actually need to check to see if our "drm" pointer is NULL before
> > >    calling drm_atomic_helper_shutdown(). We'll leave the "if" test in,
> > >    though, so that this patch can land without any dependencies. It
> > >    could potentially be removed later.
> > > - This patch also makes sure to set the drvdata to NULL in the case of
> > >    bind errors to make sure that shutdown can't access freed data.
> > >
> > > Suggested-by: Maxime Ripard <mripard@kernel.org>
> > > Reviewed-by: Maxime Ripard <mripard@kernel.org>
> > > Signed-off-by: Douglas Anderson <dianders@chromium.org>
> >
> > Seems to be working fine on all my test Exynos-based boards with display.
> >
> > Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
> >
> > Reviewed-by: Marek Szyprowski <m.szyprowski@samsung.com>
> >
> > > ---
> > > This commit is only compile-time tested.
> > >
> > > (no changes since v1)
> > >
> > >   drivers/gpu/drm/exynos/exynos_drm_drv.c | 11 +++++++++++
> > >   1 file changed, 11 insertions(+)
> > >
> > > diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c
> > > index 8399256cb5c9..5380fb6c55ae 100644
> > > --- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
> > > +++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
> > > @@ -300,6 +300,7 @@ static int exynos_drm_bind(struct device *dev)
> > >       drm_mode_config_cleanup(drm);
> > >       exynos_drm_cleanup_dma(drm);
> > >       kfree(private);
> > > +     dev_set_drvdata(dev, NULL);
> > >   err_free_drm:
> > >       drm_dev_put(drm);
> > >
> > > @@ -313,6 +314,7 @@ static void exynos_drm_unbind(struct device *dev)
> > >       drm_dev_unregister(drm);
> > >
> > >       drm_kms_helper_poll_fini(drm);
> > > +     drm_atomic_helper_shutdown(drm);
> > >
> > >       component_unbind_all(drm->dev, drm);
> > >       drm_mode_config_cleanup(drm);
> > > @@ -350,9 +352,18 @@ static int exynos_drm_platform_remove(struct platform_device *pdev)
> > >       return 0;
> > >   }
> > >
> > > +static void exynos_drm_platform_shutdown(struct platform_device *pdev)
> > > +{
> > > +     struct drm_device *drm = platform_get_drvdata(pdev);
> > > +
> > > +     if (drm)
> > > +             drm_atomic_helper_shutdown(drm);
> > > +}
> > > +
> > >   static struct platform_driver exynos_drm_platform_driver = {
> > >       .probe  = exynos_drm_platform_probe,
> > >       .remove = exynos_drm_platform_remove,
> > > +     .shutdown = exynos_drm_platform_shutdown,
> > >       .driver = {
> > >               .name   = "exynos-drm",
> > >               .pm     = &exynos_drm_pm_ops,
> >
> > Best regards
> > --
> > Marek Szyprowski, PhD
> > Samsung R&D Institute Poland
> >
Inki Dae Oct. 10, 2023, 3:46 p.m. UTC | #4
Hi,

2023년 10월 6일 (금) 오후 10:51, Doug Anderson <dianders@chromium.org>님이 작성:
>
> Hi,
>
> On Thu, Oct 5, 2023 at 7:20 PM Inki Dae <daeinki@gmail.com> wrote:
> >
> > Thanks for testing. :)
> >
> > Acked-by : Inki Dae <inki.dae@samsung.com>
>
> Inki: does that mean you'd like this to go through drm-misc? I'm happy
> to do that, but there are no dependencies here so this could easily go
> through your tree.

Ah, you are right. No dependency here. I will pick it up.

Thanks,
Inki Dae

>
>
> > 2023년 9월 22일 (금) 오후 3:00, Marek Szyprowski <m.szyprowski@samsung.com>님이 작성:
> > >
> > >
> > > On 21.09.2023 21:26, Douglas Anderson wrote:
> > > > Based on grepping through the source code this driver appears to be
> > > > missing a call to drm_atomic_helper_shutdown() at system shutdown time
> > > > and at driver unbind time. Among other things, this means that if a
> > > > panel is in use that it won't be cleanly powered off at system
> > > > shutdown time.
> > > >
> > > > The fact that we should call drm_atomic_helper_shutdown() in the case
> > > > of OS shutdown/restart and at driver remove (or unbind) time comes
> > > > straight out of the kernel doc "driver instance overview" in
> > > > drm_drv.c.
> > > >
> > > > A few notes about this fix:
> > > > - When adding drm_atomic_helper_shutdown() to the unbind path, I added
> > > >    it after drm_kms_helper_poll_fini() since that's when other drivers
> > > >    seemed to have it.
> > > > - Technically with a previous patch, ("drm/atomic-helper:
> > > >    drm_atomic_helper_shutdown(NULL) should be a noop"), we don't
> > > >    actually need to check to see if our "drm" pointer is NULL before
> > > >    calling drm_atomic_helper_shutdown(). We'll leave the "if" test in,
> > > >    though, so that this patch can land without any dependencies. It
> > > >    could potentially be removed later.
> > > > - This patch also makes sure to set the drvdata to NULL in the case of
> > > >    bind errors to make sure that shutdown can't access freed data.
> > > >
> > > > Suggested-by: Maxime Ripard <mripard@kernel.org>
> > > > Reviewed-by: Maxime Ripard <mripard@kernel.org>
> > > > Signed-off-by: Douglas Anderson <dianders@chromium.org>
> > >
> > > Seems to be working fine on all my test Exynos-based boards with display.
> > >
> > > Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
> > >
> > > Reviewed-by: Marek Szyprowski <m.szyprowski@samsung.com>
> > >
> > > > ---
> > > > This commit is only compile-time tested.
> > > >
> > > > (no changes since v1)
> > > >
> > > >   drivers/gpu/drm/exynos/exynos_drm_drv.c | 11 +++++++++++
> > > >   1 file changed, 11 insertions(+)
> > > >
> > > > diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c
> > > > index 8399256cb5c9..5380fb6c55ae 100644
> > > > --- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
> > > > +++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
> > > > @@ -300,6 +300,7 @@ static int exynos_drm_bind(struct device *dev)
> > > >       drm_mode_config_cleanup(drm);
> > > >       exynos_drm_cleanup_dma(drm);
> > > >       kfree(private);
> > > > +     dev_set_drvdata(dev, NULL);
> > > >   err_free_drm:
> > > >       drm_dev_put(drm);
> > > >
> > > > @@ -313,6 +314,7 @@ static void exynos_drm_unbind(struct device *dev)
> > > >       drm_dev_unregister(drm);
> > > >
> > > >       drm_kms_helper_poll_fini(drm);
> > > > +     drm_atomic_helper_shutdown(drm);
> > > >
> > > >       component_unbind_all(drm->dev, drm);
> > > >       drm_mode_config_cleanup(drm);
> > > > @@ -350,9 +352,18 @@ static int exynos_drm_platform_remove(struct platform_device *pdev)
> > > >       return 0;
> > > >   }
> > > >
> > > > +static void exynos_drm_platform_shutdown(struct platform_device *pdev)
> > > > +{
> > > > +     struct drm_device *drm = platform_get_drvdata(pdev);
> > > > +
> > > > +     if (drm)
> > > > +             drm_atomic_helper_shutdown(drm);
> > > > +}
> > > > +
> > > >   static struct platform_driver exynos_drm_platform_driver = {
> > > >       .probe  = exynos_drm_platform_probe,
> > > >       .remove = exynos_drm_platform_remove,
> > > > +     .shutdown = exynos_drm_platform_shutdown,
> > > >       .driver = {
> > > >               .name   = "exynos-drm",
> > > >               .pm     = &exynos_drm_pm_ops,
> > >
> > > Best regards
> > > --
> > > Marek Szyprowski, PhD
> > > Samsung R&D Institute Poland
> > >
diff mbox series

Patch

diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c
index 8399256cb5c9..5380fb6c55ae 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
@@ -300,6 +300,7 @@  static int exynos_drm_bind(struct device *dev)
 	drm_mode_config_cleanup(drm);
 	exynos_drm_cleanup_dma(drm);
 	kfree(private);
+	dev_set_drvdata(dev, NULL);
 err_free_drm:
 	drm_dev_put(drm);
 
@@ -313,6 +314,7 @@  static void exynos_drm_unbind(struct device *dev)
 	drm_dev_unregister(drm);
 
 	drm_kms_helper_poll_fini(drm);
+	drm_atomic_helper_shutdown(drm);
 
 	component_unbind_all(drm->dev, drm);
 	drm_mode_config_cleanup(drm);
@@ -350,9 +352,18 @@  static int exynos_drm_platform_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static void exynos_drm_platform_shutdown(struct platform_device *pdev)
+{
+	struct drm_device *drm = platform_get_drvdata(pdev);
+
+	if (drm)
+		drm_atomic_helper_shutdown(drm);
+}
+
 static struct platform_driver exynos_drm_platform_driver = {
 	.probe	= exynos_drm_platform_probe,
 	.remove	= exynos_drm_platform_remove,
+	.shutdown = exynos_drm_platform_shutdown,
 	.driver	= {
 		.name	= "exynos-drm",
 		.pm	= &exynos_drm_pm_ops,