2023-06-21 22:59:01

by Jonas Karlman

[permalink] [raw]
Subject: [PATCH v2 0/5] drm/rockchip: Fix crtc duplicate state and crtc reset funcs

This series fixes a reset of state in duplicate state crtc funcs for VOP
driver, a possible crash and ensure crtc reset helper is called in VOP2
driver.

Patch 1 use kmemdup instead of kzalloc to duplicate the crtc state.
Patch 2 change to use crtc and plane cleanup helpers directly.
Patch 3 adds a null guard for allocation failure.
Patch 4 adds a crash guard for empty crtc state.
Patch 5 adds a missing call to crtc reset helper.

This is the next part of an ongoing effort to upstream HDMI 2.0 support
used in LibreELEC for the past 3+ years.

Changes in v2:
- Handle possible allocation failure in crtc reset funcs
- Collect r-b tags

This series is also available at [1].

[1] https://github.com/Kwiboo/linux-rockchip/commits/next-20230621-duplicate-state

Jonas Karlman (5):
drm/rockchip: vop: Fix reset of state in duplicate state crtc funcs
drm/rockchip: vop: Use cleanup helper directly as destroy funcs
drm/rockchip: vop: Fix call to crtc reset helper
drm/rockchip: vop2: Don't crash for invalid duplicate_state
drm/rockchip: vop2: Add missing call to crtc reset helper

drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 24 +++++-------
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 39 ++++++++++----------
2 files changed, 28 insertions(+), 35 deletions(-)

--
2.41.0



2023-06-21 22:59:50

by Jonas Karlman

[permalink] [raw]
Subject: [PATCH v2 5/5] drm/rockchip: vop2: Add missing call to crtc reset helper

Add missing call to crtc reset helper to properly vblank reset.

Also move vop2_crtc_reset and call vop2_crtc_destroy_state to simplify
and remove duplicated code.

Fixes: 604be85547ce ("drm/rockchip: Add VOP2 driver")
Signed-off-by: Jonas Karlman <[email protected]>
---
v2:
- Add check for allocation failure (Sascha)

drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 31 +++++++++-----------
1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
index f725487d02ef..5ba83121a1b9 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
@@ -2080,23 +2080,6 @@ static const struct drm_crtc_helper_funcs vop2_crtc_helper_funcs = {
.atomic_disable = vop2_crtc_atomic_disable,
};

-static void vop2_crtc_reset(struct drm_crtc *crtc)
-{
- struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
-
- if (crtc->state) {
- __drm_atomic_helper_crtc_destroy_state(crtc->state);
- kfree(vcstate);
- }
-
- vcstate = kzalloc(sizeof(*vcstate), GFP_KERNEL);
- if (!vcstate)
- return;
-
- crtc->state = &vcstate->base;
- crtc->state->crtc = crtc;
-}
-
static struct drm_crtc_state *vop2_crtc_duplicate_state(struct drm_crtc *crtc)
{
struct rockchip_crtc_state *vcstate;
@@ -2123,6 +2106,20 @@ static void vop2_crtc_destroy_state(struct drm_crtc *crtc,
kfree(vcstate);
}

+static void vop2_crtc_reset(struct drm_crtc *crtc)
+{
+ struct rockchip_crtc_state *vcstate =
+ kzalloc(sizeof(*vcstate), GFP_KERNEL);
+
+ if (crtc->state)
+ vop2_crtc_destroy_state(crtc, crtc->state);
+
+ if (vcstate)
+ __drm_atomic_helper_crtc_reset(crtc, &vcstate->base);
+ else
+ __drm_atomic_helper_crtc_reset(crtc, NULL);
+}
+
static const struct drm_crtc_funcs vop2_crtc_funcs = {
.set_config = drm_atomic_helper_set_config,
.page_flip = drm_atomic_helper_page_flip,
--
2.41.0


2023-06-21 23:01:27

by Jonas Karlman

[permalink] [raw]
Subject: [PATCH v2 2/5] drm/rockchip: vop: Use cleanup helper directly as destroy funcs

vop_plane_destroy and vop_crtc_destroy are plain wrappers around
drm_plane_cleanup and drm_crtc_cleanup. Use them directly as plane and
crtc funcs to closer match VOP2 driver.

Signed-off-by: Jonas Karlman <[email protected]>
Reviewed-by: Sascha Hauer <[email protected]>
---
v2:
- Collect r-b tag

drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 16 +++-------------
1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
index 60b23636a3fe..25c873d4ff53 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
@@ -766,11 +766,6 @@ static void vop_crtc_atomic_disable(struct drm_crtc *crtc,
}
}

-static void vop_plane_destroy(struct drm_plane *plane)
-{
- drm_plane_cleanup(plane);
-}
-
static inline bool rockchip_afbc(u64 modifier)
{
return modifier == ROCKCHIP_AFBC_MOD;
@@ -1131,7 +1126,7 @@ static const struct drm_plane_helper_funcs plane_helper_funcs = {
static const struct drm_plane_funcs vop_plane_funcs = {
.update_plane = drm_atomic_helper_update_plane,
.disable_plane = drm_atomic_helper_disable_plane,
- .destroy = vop_plane_destroy,
+ .destroy = drm_plane_cleanup,
.reset = drm_atomic_helper_plane_reset,
.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
@@ -1602,11 +1597,6 @@ static const struct drm_crtc_helper_funcs vop_crtc_helper_funcs = {
.atomic_disable = vop_crtc_atomic_disable,
};

-static void vop_crtc_destroy(struct drm_crtc *crtc)
-{
- drm_crtc_cleanup(crtc);
-}
-
static struct drm_crtc_state *vop_crtc_duplicate_state(struct drm_crtc *crtc)
{
struct rockchip_crtc_state *rockchip_state;
@@ -1711,7 +1701,7 @@ vop_crtc_verify_crc_source(struct drm_crtc *crtc, const char *source_name,
static const struct drm_crtc_funcs vop_crtc_funcs = {
.set_config = drm_atomic_helper_set_config,
.page_flip = drm_atomic_helper_page_flip,
- .destroy = vop_crtc_destroy,
+ .destroy = drm_crtc_cleanup,
.reset = vop_crtc_reset,
.atomic_duplicate_state = vop_crtc_duplicate_state,
.atomic_destroy_state = vop_crtc_destroy_state,
@@ -1962,7 +1952,7 @@ static void vop_destroy_crtc(struct vop *vop)
*/
list_for_each_entry_safe(plane, tmp, &drm_dev->mode_config.plane_list,
head)
- vop_plane_destroy(plane);
+ drm_plane_cleanup(plane);

/*
* Destroy CRTC after vop_plane_destroy() since vop_disable_plane()
--
2.41.0


2023-06-21 23:01:32

by Jonas Karlman

[permalink] [raw]
Subject: [PATCH v2 3/5] drm/rockchip: vop: Fix call to crtc reset helper

Allocation of crtc_state may fail in vop_crtc_reset, causing an invalid
pointer to be passed to __drm_atomic_helper_crtc_reset.

Fix this by adding a NULL check of crtc_state, similar to other drivers.

Fixes: 01e2eaf40c9d ("drm/rockchip: Convert to using __drm_atomic_helper_crtc_reset() for reset.")
Signed-off-by: Jonas Karlman <[email protected]>
---
v2:
- New patch

drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
index 25c873d4ff53..23bc79064e78 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
@@ -1630,7 +1630,10 @@ static void vop_crtc_reset(struct drm_crtc *crtc)
if (crtc->state)
vop_crtc_destroy_state(crtc, crtc->state);

- __drm_atomic_helper_crtc_reset(crtc, &crtc_state->base);
+ if (crtc_state)
+ __drm_atomic_helper_crtc_reset(crtc, &crtc_state->base);
+ else
+ __drm_atomic_helper_crtc_reset(crtc, NULL);
}

#ifdef CONFIG_DRM_ANALOGIX_DP
--
2.41.0


2023-06-22 11:41:19

by Sascha Hauer

[permalink] [raw]
Subject: Re: [PATCH v2 3/5] drm/rockchip: vop: Fix call to crtc reset helper

On Wed, Jun 21, 2023 at 10:33:20PM +0000, Jonas Karlman wrote:
> Allocation of crtc_state may fail in vop_crtc_reset, causing an invalid
> pointer to be passed to __drm_atomic_helper_crtc_reset.
>
> Fix this by adding a NULL check of crtc_state, similar to other drivers.
>
> Fixes: 01e2eaf40c9d ("drm/rockchip: Convert to using __drm_atomic_helper_crtc_reset() for reset.")
> Signed-off-by: Jonas Karlman <[email protected]>

Reviewed-by: Sascha Hauer <[email protected]>

Sascha

> ---
> v2:
> - New patch
>
> drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
> index 25c873d4ff53..23bc79064e78 100644
> --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
> +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
> @@ -1630,7 +1630,10 @@ static void vop_crtc_reset(struct drm_crtc *crtc)
> if (crtc->state)
> vop_crtc_destroy_state(crtc, crtc->state);
>
> - __drm_atomic_helper_crtc_reset(crtc, &crtc_state->base);
> + if (crtc_state)
> + __drm_atomic_helper_crtc_reset(crtc, &crtc_state->base);
> + else
> + __drm_atomic_helper_crtc_reset(crtc, NULL);
> }
>
> #ifdef CONFIG_DRM_ANALOGIX_DP
> --
> 2.41.0
>
>

--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |

2023-06-22 11:41:30

by Sascha Hauer

[permalink] [raw]
Subject: Re: [PATCH v2 5/5] drm/rockchip: vop2: Add missing call to crtc reset helper

On Wed, Jun 21, 2023 at 10:33:23PM +0000, Jonas Karlman wrote:
> Add missing call to crtc reset helper to properly vblank reset.
>
> Also move vop2_crtc_reset and call vop2_crtc_destroy_state to simplify
> and remove duplicated code.
>
> Fixes: 604be85547ce ("drm/rockchip: Add VOP2 driver")
> Signed-off-by: Jonas Karlman <[email protected]>
> ---
> v2:
> - Add check for allocation failure (Sascha)

Reviewed-by: Sascha Hauer <[email protected]>

Sascha

>
> drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 31 +++++++++-----------
> 1 file changed, 14 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
> index f725487d02ef..5ba83121a1b9 100644
> --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
> +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
> @@ -2080,23 +2080,6 @@ static const struct drm_crtc_helper_funcs vop2_crtc_helper_funcs = {
> .atomic_disable = vop2_crtc_atomic_disable,
> };
>
> -static void vop2_crtc_reset(struct drm_crtc *crtc)
> -{
> - struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
> -
> - if (crtc->state) {
> - __drm_atomic_helper_crtc_destroy_state(crtc->state);
> - kfree(vcstate);
> - }
> -
> - vcstate = kzalloc(sizeof(*vcstate), GFP_KERNEL);
> - if (!vcstate)
> - return;
> -
> - crtc->state = &vcstate->base;
> - crtc->state->crtc = crtc;
> -}
> -
> static struct drm_crtc_state *vop2_crtc_duplicate_state(struct drm_crtc *crtc)
> {
> struct rockchip_crtc_state *vcstate;
> @@ -2123,6 +2106,20 @@ static void vop2_crtc_destroy_state(struct drm_crtc *crtc,
> kfree(vcstate);
> }
>
> +static void vop2_crtc_reset(struct drm_crtc *crtc)
> +{
> + struct rockchip_crtc_state *vcstate =
> + kzalloc(sizeof(*vcstate), GFP_KERNEL);
> +
> + if (crtc->state)
> + vop2_crtc_destroy_state(crtc, crtc->state);
> +
> + if (vcstate)
> + __drm_atomic_helper_crtc_reset(crtc, &vcstate->base);
> + else
> + __drm_atomic_helper_crtc_reset(crtc, NULL);
> +}
> +
> static const struct drm_crtc_funcs vop2_crtc_funcs = {
> .set_config = drm_atomic_helper_set_config,
> .page_flip = drm_atomic_helper_page_flip,
> --
> 2.41.0
>
>

--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |

2023-08-12 15:13:53

by Jonas Karlman

[permalink] [raw]
Subject: Re: [PATCH v2 0/5] drm/rockchip: Fix crtc duplicate state and crtc reset funcs

Hi Heiko,

Please consider reviewing and merging this series [2], and also [3].

drm/rockchip: Fix crtc duplicate state and crtc reset funcs
[2] https://lore.kernel.org/all/[email protected]/

drm/rockchip: vop: Add NV15, NV20 and NV30 support
[3] https://lore.kernel.org/all/[email protected]/

Regards,
Jonas

On 2023-06-22 00:33, Jonas Karlman wrote:
> This series fixes a reset of state in duplicate state crtc funcs for VOP
> driver, a possible crash and ensure crtc reset helper is called in VOP2
> driver.
>
> Patch 1 use kmemdup instead of kzalloc to duplicate the crtc state.
> Patch 2 change to use crtc and plane cleanup helpers directly.
> Patch 3 adds a null guard for allocation failure.
> Patch 4 adds a crash guard for empty crtc state.
> Patch 5 adds a missing call to crtc reset helper.
>
> This is the next part of an ongoing effort to upstream HDMI 2.0 support
> used in LibreELEC for the past 3+ years.
>
> Changes in v2:
> - Handle possible allocation failure in crtc reset funcs
> - Collect r-b tags
>
> This series is also available at [1].
>
> [1] https://github.com/Kwiboo/linux-rockchip/commits/next-20230621-duplicate-state
>
> Jonas Karlman (5):
> drm/rockchip: vop: Fix reset of state in duplicate state crtc funcs
> drm/rockchip: vop: Use cleanup helper directly as destroy funcs
> drm/rockchip: vop: Fix call to crtc reset helper
> drm/rockchip: vop2: Don't crash for invalid duplicate_state
> drm/rockchip: vop2: Add missing call to crtc reset helper
>
> drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 24 +++++-------
> drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 39 ++++++++++----------
> 2 files changed, 28 insertions(+), 35 deletions(-)
>


2023-08-13 00:14:47

by Heiko Stübner

[permalink] [raw]
Subject: Re: [PATCH v2 0/5] drm/rockchip: Fix crtc duplicate state and crtc reset funcs

Hi Jonas,

Am Samstag, 12. August 2023, 16:18:05 CEST schrieb Jonas Karlman:
> Please consider reviewing and merging this series [2], and also [3].

during the last months my testfarm aquired some issues, I'm still
working on fixing, so my testing is way limited right now.

> drm/rockchip: Fix crtc duplicate state and crtc reset funcs
> [2] https://lore.kernel.org/all/[email protected]/

Though this one looked easy and when going through the code looked
quite right.


> drm/rockchip: vop: Add NV15, NV20 and NV30 support
> [3] https://lore.kernel.org/all/[email protected]/

I guess I need to track down someone on IRC to tell me if these new NVxx
types look correct, because I don't have too much clue about those drm-formats
yet. Hopefully I'll get to that on monday.


Heiko


> On 2023-06-22 00:33, Jonas Karlman wrote:
> > This series fixes a reset of state in duplicate state crtc funcs for VOP
> > driver, a possible crash and ensure crtc reset helper is called in VOP2
> > driver.
> >
> > Patch 1 use kmemdup instead of kzalloc to duplicate the crtc state.
> > Patch 2 change to use crtc and plane cleanup helpers directly.
> > Patch 3 adds a null guard for allocation failure.
> > Patch 4 adds a crash guard for empty crtc state.
> > Patch 5 adds a missing call to crtc reset helper.
> >
> > This is the next part of an ongoing effort to upstream HDMI 2.0 support
> > used in LibreELEC for the past 3+ years.
> >
> > Changes in v2:
> > - Handle possible allocation failure in crtc reset funcs
> > - Collect r-b tags
> >
> > This series is also available at [1].
> >
> > [1] https://github.com/Kwiboo/linux-rockchip/commits/next-20230621-duplicate-state
> >
> > Jonas Karlman (5):
> > drm/rockchip: vop: Fix reset of state in duplicate state crtc funcs
> > drm/rockchip: vop: Use cleanup helper directly as destroy funcs
> > drm/rockchip: vop: Fix call to crtc reset helper
> > drm/rockchip: vop2: Don't crash for invalid duplicate_state
> > drm/rockchip: vop2: Add missing call to crtc reset helper
> >
> > drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 24 +++++-------
> > drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 39 ++++++++++----------
> > 2 files changed, 28 insertions(+), 35 deletions(-)
> >
>
>





2023-08-13 01:14:54

by Heiko Stübner

[permalink] [raw]
Subject: Re: [PATCH v2 0/5] drm/rockchip: Fix crtc duplicate state and crtc reset funcs

On Wed, 21 Jun 2023 22:33:15 +0000 (UTC), Jonas Karlman wrote:
> This series fixes a reset of state in duplicate state crtc funcs for VOP
> driver, a possible crash and ensure crtc reset helper is called in VOP2
> driver.
>
> Patch 1 use kmemdup instead of kzalloc to duplicate the crtc state.
> Patch 2 change to use crtc and plane cleanup helpers directly.
> Patch 3 adds a null guard for allocation failure.
> Patch 4 adds a crash guard for empty crtc state.
> Patch 5 adds a missing call to crtc reset helper.
>
> [...]

Applied, thanks!

[1/5] drm/rockchip: vop: Fix reset of state in duplicate state crtc funcs
commit: 13fc28804bf10ca0b7bce3efbba95c534836d7ca
[2/5] drm/rockchip: vop: Use cleanup helper directly as destroy funcs
commit: 800f7c332df7cd9614c416fd005a6bb53f96f13c
[3/5] drm/rockchip: vop: Fix call to crtc reset helper
commit: 5aacd290837828c089a83ac9795c74c4c9e2c923
[4/5] drm/rockchip: vop2: Don't crash for invalid duplicate_state
commit: 342f7e4967d02b0ec263b15916304fc54841b608
[5/5] drm/rockchip: vop2: Add missing call to crtc reset helper
commit: 4d49d87b3606369c6e29b9d051892ee1a6fc4e75

Best regards,
--
Heiko Stuebner <[email protected]>