Skip to contentSkip to conversation

drm/atomic-helper: Don't allocated plane state in CRTC check

PATCH Superseded Thomas Zimmermann 2 participants 8 messages Sep 29, 2022 – Sep 30, 2022

Subsystems (2)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

PATCH 1/1 drm/atomic-helper: Don't allocated plane state in CRTC check

In drm_atomic_helper_check_crtc_state(), do not add a new plane state to the global state if it does not exist already. Adding a new plane state will results in overhead for the plane during the atomic-commit step.

For the test in drm_atomic_helper_check_crtc_state() to succeed, it is important that the CRTC has an enabled primary plane after the commit. This can be a newly enabled plane or an already enabled plane. So if a plane is not part of the commit, use the plane's existing state. The new helper drm_atomic_get_next_plane_state() returns the correct instance.

Fixes d6b9af1097fe ("drm/atomic-helper: Add helper drm_atomic_helper_check_crtc_state()")
Cc Thomas Zimmermann <[email protected]>
Cc Jocelyn Falempe <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_atomic_helper.c |  4 +---
 include/drm/drm_atomic.h            | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +1 -3
index 98cc3137c062..463d4f3fa443 100644
@@ -960,9 +960,7 @@ int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state,
 
 			if (plane->type != DRM_PLANE_TYPE_PRIMARY)
 				continue;
-			plane_state = drm_atomic_get_plane_state(state, plane);
-			if (IS_ERR(plane_state))
-				return PTR_ERR(plane_state);
+			plane_state = drm_atomic_get_next_plane_state(state, plane);
 			if (plane_state->fb && plane_state->crtc) {
 				has_primary_plane = true;
 				break;
include/drm/drm_atomic.h +20 -0
index 10b1990bc1f6..4006f2d459e3 100644
@@ -623,6 +623,26 @@ drm_atomic_get_new_plane_state(struct drm_atomic_state *state,
 	return state->planes[drm_plane_index(plane)].new_state;
 }
 
+/**
+ * drm_atomic_get_next_plane_state - get plane state after atomic commit
+ * @state: global atomic state object
+ * @plane: plane to grab
+ *
+ * This function returns the plane state that the given plane will have
+ * after the atomic commit. This will be the new plane state if the plane
+ * is part of the global atomic state, or the current state otherwise.
+ */
+static inline struct drm_plane_state *
+drm_atomic_get_next_plane_state(struct drm_atomic_state *state,
+				struct drm_plane *plane)
+{
+	struct drm_plane_state *plane_state = drm_atomic_get_new_plane_state(state, plane);
+
+	if (plane_state)
+		return plane_state;
+	return plane->state;
+}
+
 /**
  * drm_atomic_get_existing_connector_state - get connector state, if it exists
  * @state: global atomic state object
Signature · 1 line
2.37.3
#1 lore raw
Quoted 30 lines · Thomas Zimmermann

In drm_atomic_helper_check_crtc_state(), do not add a new plane state to the global state if it does not exist already. Adding a new plane state will results in overhead for the plane during the atomic-commit step.

For the test in drm_atomic_helper_check_crtc_state() to succeed, it is important that the CRTC has an enabled primary plane after the commit. This can be a newly enabled plane or an already enabled plane. So if a plane is not part of the commit, use the plane's existing state. The new helper drm_atomic_get_next_plane_state() returns the correct instance.

Fixes d6b9af1097fe ("drm/atomic-helper: Add helper drm_atomic_helper_check_crtc_state()")
Cc Thomas Zimmermann <[email protected]>
Cc Jocelyn Falempe <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_atomic_helper.c |  4 +---
 include/drm/drm_atomic.h            | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +0 -0
index 98cc3137c062..463d4f3fa443 100644

drivers/gpu/drm/drm_atomic_helper.c int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state, · line 964

Quoted 8 lines
drivers/gpu/drm/drm_atomic_helper.c +1 -3
@@ -960,9 +960,7 @@ int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state,
 
 			if (plane->type != DRM_PLANE_TYPE_PRIMARY)
 				continue;
-			plane_state = drm_atomic_get_plane_state(state, plane);
-			if (IS_ERR(plane_state))
-				return PTR_ERR(plane_state);
+			plane_state = drm_atomic_get_next_plane_state(state, plane);
 			if (plane_state->fb && plane_state->crtc) {

Hmm. Why this is even looking at these. If the plane is in the crtc's plane_mask then surely plane_state->crtc must already point to this crtc? And I don't think ->fb and ->crtc are allowed to disagree, so if one is set then surely the other one must be as well or we'd return an error at some point somewhere?

Quoted 18 lines
drivers/gpu/drm/drm_atomic_helper.c +0 -0
 				has_primary_plane = true;
 				break;
include/drm/drm_atomic.h +8 -0
index 10b1990bc1f6..4006f2d459e3 100644
@@ -623,6 +623,26 @@ drm_atomic_get_new_plane_state(struct drm_atomic_state *state,
 	return state->planes[drm_plane_index(plane)].new_state;
 }
 
+/**
+ * drm_atomic_get_next_plane_state - get plane state after atomic commit
+ * @state: global atomic state object
+ * @plane: plane to grab
+ *
+ * This function returns the plane state that the given plane will have
+ * after the atomic commit. This will be the new plane state if the plane
+ * is part of the global atomic state, or the current state otherwise.

include/drm/drm_atomic.h drm_atomic_get_new_plane_state(struct drm_atomic_state *state, · line 643

Quoted 10 lines
include/drm/drm_atomic.h +10 -0
+ */
+static inline struct drm_plane_state *
+drm_atomic_get_next_plane_state(struct drm_atomic_state *state,
+				struct drm_plane *plane)
+{
+	struct drm_plane_state *plane_state = drm_atomic_get_new_plane_state(state, plane);
+
+	if (plane_state)
+		return plane_state;
+	return plane->state;

You're not holding the appropriate lock so that does not look safe. Even if you know somewhere, somehow this sort of thing to be safe I don't think it's a good idea to promote this with any kind of official function because someone will shoot themselves in the foot with it.

Quoted 7 lines
include/drm/drm_atomic.h +2 -0
+}
+
 /**
  * drm_atomic_get_existing_connector_state - get connector state, if it exists
  * @state: global atomic state object
Signature · 1 line
2.37.3
Signature · 2 lines
Ville Syrjälä
Intel
author maintainer
#2 lore raw

Hi,

thanks for reviewing.

Am 29.09.22 um 21:03 schrieb Ville Syrjälä:

Quoted 32 lines · Thomas Zimmermann
Quoted 31 lines

In drm_atomic_helper_check_crtc_state(), do not add a new plane state to the global state if it does not exist already. Adding a new plane state will results in overhead for the plane during the atomic-commit step.

For the test in drm_atomic_helper_check_crtc_state() to succeed, it is important that the CRTC has an enabled primary plane after the commit. This can be a newly enabled plane or an already enabled plane. So if a plane is not part of the commit, use the plane's existing state. The new helper drm_atomic_get_next_plane_state() returns the correct instance.

Fixes d6b9af1097fe ("drm/atomic-helper: Add helper drm_atomic_helper_check_crtc_state()")
Cc Thomas Zimmermann <[email protected]>
Cc Jocelyn Falempe <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
  drivers/gpu/drm/drm_atomic_helper.c |  4 +---
  include/drm/drm_atomic.h            | 20 ++++++++++++++++++++
  2 files changed, 21 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +0 -0
index 98cc3137c062..463d4f3fa443 100644
@@ -960,9 +960,7 @@ int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state,
 
Quoted 13 lines

drivers/gpu/drm/drm_atomic_helper.c int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state, · line 964

Quoted 7 lines
drivers/gpu/drm/drm_atomic_helper.c +1 -3
  			if (plane->type != DRM_PLANE_TYPE_PRIMARY)
  				continue;
-			plane_state = drm_atomic_get_plane_state(state, plane);
-			if (IS_ERR(plane_state))
-				return PTR_ERR(plane_state);
+			plane_state = drm_atomic_get_next_plane_state(state, plane);
  			if (plane_state->fb && plane_state->crtc) {

Hmm. Why this is even looking at these. If the plane is in the crtc's plane_mask then surely plane_state->crtc must already point to this crtc? And I don't think ->fb and ->crtc are allowed to disagree, so if one is set then surely the other one must be as well or we'd return an error at some point somewhere?

Yeah, the crtc test is done for keeping consistency. Other places also sometimes validate that these fields don't disagree. I'll remove the crtc test in the next version. The fb test is the important one.

Quoted 26 lines
Quoted 26 lines
drivers/gpu/drm/drm_atomic_helper.c +0 -0
  				has_primary_plane = true;
  				break;
include/drm/drm_atomic.h +15 -0
index 10b1990bc1f6..4006f2d459e3 100644
@@ -623,6 +623,26 @@ drm_atomic_get_new_plane_state(struct drm_atomic_state *state,
  	return state->planes[drm_plane_index(plane)].new_state;
  }
 
+/**
+ * drm_atomic_get_next_plane_state - get plane state after atomic commit
+ * @state: global atomic state object
+ * @plane: plane to grab
+ *
+ * This function returns the plane state that the given plane will have
+ * after the atomic commit. This will be the new plane state if the plane
+ * is part of the global atomic state, or the current state otherwise.
+ */
+static inline struct drm_plane_state *
+drm_atomic_get_next_plane_state(struct drm_atomic_state *state,
+				struct drm_plane *plane)
+{
+	struct drm_plane_state *plane_state = drm_atomic_get_new_plane_state(state, plane);
+
Quoted 8 lines

include/drm/drm_atomic.h drm_atomic_get_new_plane_state(struct drm_atomic_state *state, · line 643

Quoted 3 lines
include/drm/drm_atomic.h +3 -0
+	if (plane_state)
+		return plane_state;
+	return plane->state;

You're not holding the appropriate lock so that does not look safe. Even if you know somewhere, somehow this sort of thing to be safe I don't think it's a good idea to promote this with any kind of official function because someone will shoot themselves in the foot with it.

OK. It'll be inlined with locking added.

Best regards
Thomas

Quoted 9 lines
Quoted 8 lines
include/drm/drm_atomic.h +2 -0
+}
+
  /**
   * drm_atomic_get_existing_connector_state - get connector state, if it exists
   * @state: global atomic state object
Signature · 1 line
2.37.3
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
#3 lore raw
Quoted 51 lines · Thomas Zimmermann

Hi,

thanks for reviewing.

Am 29.09.22 um 21:03 schrieb Ville Syrjälä:

Quoted 32 lines · Thomas Zimmermann
Quoted 31 lines

In drm_atomic_helper_check_crtc_state(), do not add a new plane state to the global state if it does not exist already. Adding a new plane state will results in overhead for the plane during the atomic-commit step.

For the test in drm_atomic_helper_check_crtc_state() to succeed, it is important that the CRTC has an enabled primary plane after the commit. This can be a newly enabled plane or an already enabled plane. So if a plane is not part of the commit, use the plane's existing state. The new helper drm_atomic_get_next_plane_state() returns the correct instance.

Fixes d6b9af1097fe ("drm/atomic-helper: Add helper drm_atomic_helper_check_crtc_state()")
Cc Thomas Zimmermann <[email protected]>
Cc Jocelyn Falempe <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
  drivers/gpu/drm/drm_atomic_helper.c |  4 +---
  include/drm/drm_atomic.h            | 20 ++++++++++++++++++++
  2 files changed, 21 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +0 -0
index 98cc3137c062..463d4f3fa443 100644
@@ -960,9 +960,7 @@ int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state,
 
Quoted 13 lines

drivers/gpu/drm/drm_atomic_helper.c int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state, · line 964

Quoted 7 lines
drivers/gpu/drm/drm_atomic_helper.c +1 -3
  			if (plane->type != DRM_PLANE_TYPE_PRIMARY)
  				continue;
-			plane_state = drm_atomic_get_plane_state(state, plane);
-			if (IS_ERR(plane_state))
-				return PTR_ERR(plane_state);
+			plane_state = drm_atomic_get_next_plane_state(state, plane);
  			if (plane_state->fb && plane_state->crtc) {

Hmm. Why this is even looking at these. If the plane is in the crtc's plane_mask then surely plane_state->crtc must already point to this crtc? And I don't think ->fb and ->crtc are allowed to disagree, so if one is set then surely the other one must be as well or we'd return an error at some point somewhere?

Quoted 3 lines

Yeah, the crtc test is done for keeping consistency. Other places also sometimes validate that these fields don't disagree. I'll remove the crtc test in the next version. The fb test is the important one.

What I'm asking how can you have crtc!=NULL && fb==NULL at all here? Some other plane state check function (can't remember which one specifically) should have rejected that. So either you're checking for impossible things, or there is a bug somewhere else.

So to me it looks like it should be enough to just check the plane_mask and not even bother looking at the plane state at all.

Quoted 58 lines
Quoted 27 lines
Quoted 27 lines
drivers/gpu/drm/drm_atomic_helper.c +0 -0
  				has_primary_plane = true;
  				break;
include/drm/drm_atomic.h +15 -0
index 10b1990bc1f6..4006f2d459e3 100644
@@ -623,6 +623,26 @@ drm_atomic_get_new_plane_state(struct drm_atomic_state *state,
  	return state->planes[drm_plane_index(plane)].new_state;
  }
 
+/**
+ * drm_atomic_get_next_plane_state - get plane state after atomic commit
+ * @state: global atomic state object
+ * @plane: plane to grab
+ *
+ * This function returns the plane state that the given plane will have
+ * after the atomic commit. This will be the new plane state if the plane
+ * is part of the global atomic state, or the current state otherwise.
+ */
+static inline struct drm_plane_state *
+drm_atomic_get_next_plane_state(struct drm_atomic_state *state,
+				struct drm_plane *plane)
+{
+	struct drm_plane_state *plane_state = drm_atomic_get_new_plane_state(state, plane);
+
Quoted 8 lines

include/drm/drm_atomic.h drm_atomic_get_new_plane_state(struct drm_atomic_state *state, · line 643

Quoted 3 lines
include/drm/drm_atomic.h +3 -0
+	if (plane_state)
+		return plane_state;
+	return plane->state;

You're not holding the appropriate lock so that does not look safe. Even if you know somewhere, somehow this sort of thing to be safe I don't think it's a good idea to promote this with any kind of official function because someone will shoot themselves in the foot with it.

OK. It'll be inlined with locking added.

Best regards
Thomas

Quoted 9 lines
Quoted 8 lines
include/drm/drm_atomic.h +2 -0
+}
+
  /**
   * drm_atomic_get_existing_connector_state - get connector state, if it exists
   * @state: global atomic state object
Signature · 1 line
2.37.3
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
Signature · 2 lines
Ville Syrjälä
Intel
#4 lore raw
Quoted 52 lines · Ville Syrjälä
Quoted 51 lines · Thomas Zimmermann

Hi,

thanks for reviewing.

Am 29.09.22 um 21:03 schrieb Ville Syrjälä:

Quoted 45 lines · Thomas Zimmermann
Quoted 30 lines

In drm_atomic_helper_check_crtc_state(), do not add a new plane state to the global state if it does not exist already. Adding a new plane state will results in overhead for the plane during the atomic-commit step.

For the test in drm_atomic_helper_check_crtc_state() to succeed, it is important that the CRTC has an enabled primary plane after the commit. This can be a newly enabled plane or an already enabled plane. So if a plane is not part of the commit, use the plane's existing state. The new helper drm_atomic_get_next_plane_state() returns the correct instance.

Fixes d6b9af1097fe ("drm/atomic-helper: Add helper drm_atomic_helper_check_crtc_state()")
Cc Thomas Zimmermann <[email protected]>
Cc Jocelyn Falempe <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
  drivers/gpu/drm/drm_atomic_helper.c |  4 +---
  include/drm/drm_atomic.h            | 20 ++++++++++++++++++++
  2 files changed, 21 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +0 -0
index 98cc3137c062..463d4f3fa443 100644

drivers/gpu/drm/drm_atomic_helper.c int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state, · line 964

Quoted 8 lines
drivers/gpu/drm/drm_atomic_helper.c +1 -3
@@ -960,9 +960,7 @@ int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state,
 
  			if (plane->type != DRM_PLANE_TYPE_PRIMARY)
  				continue;
-			plane_state = drm_atomic_get_plane_state(state, plane);
-			if (IS_ERR(plane_state))
-				return PTR_ERR(plane_state);
+			plane_state = drm_atomic_get_next_plane_state(state, plane);
  			if (plane_state->fb && plane_state->crtc) {

Hmm. Why this is even looking at these. If the plane is in the crtc's plane_mask then surely plane_state->crtc must already point to this crtc? And I don't think ->fb and ->crtc are allowed to disagree, so if one is set then surely the other one must be as well or we'd return an error at some point somewhere?

Quoted 8 lines
Quoted 3 lines

Yeah, the crtc test is done for keeping consistency. Other places also sometimes validate that these fields don't disagree. I'll remove the crtc test in the next version. The fb test is the important one.

What I'm asking how can you have crtc!=NULL && fb==NULL at all here? Some other plane state check function (can't remember which one specifically) should have rejected that. So either you're checking for impossible things, or there is a bug somewhere else.

Oh and btw, fb != NULL doesn't guarantee the plane is actually visible (could have been fully clipped), if that is what you're trying to check here.

Signature · 2 lines
Ville Syrjälä
Intel
author maintainer
#5 lore raw

Hi

Am 30.09.22 um 12:26 schrieb Ville Syrjälä:

Quoted 57 lines · Ville Syrjälä
Quoted 56 lines · Thomas Zimmermann
Quoted 54 lines

Hi,

thanks for reviewing.

Am 29.09.22 um 21:03 schrieb Ville Syrjälä:

Quoted 32 lines · Thomas Zimmermann
Quoted 31 lines

In drm_atomic_helper_check_crtc_state(), do not add a new plane state to the global state if it does not exist already. Adding a new plane state will results in overhead for the plane during the atomic-commit step.

For the test in drm_atomic_helper_check_crtc_state() to succeed, it is important that the CRTC has an enabled primary plane after the commit. This can be a newly enabled plane or an already enabled plane. So if a plane is not part of the commit, use the plane's existing state. The new helper drm_atomic_get_next_plane_state() returns the correct instance.

Fixes d6b9af1097fe ("drm/atomic-helper: Add helper drm_atomic_helper_check_crtc_state()")
Cc Thomas Zimmermann <[email protected]>
Cc Jocelyn Falempe <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
   drivers/gpu/drm/drm_atomic_helper.c |  4 +---
   include/drm/drm_atomic.h            | 20 ++++++++++++++++++++
   2 files changed, 21 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +0 -0
index 98cc3137c062..463d4f3fa443 100644
@@ -960,9 +960,7 @@ int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state,
 
Quoted 13 lines

drivers/gpu/drm/drm_atomic_helper.c int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state, · line 964

Quoted 7 lines
drivers/gpu/drm/drm_atomic_helper.c +1 -3
   			if (plane->type != DRM_PLANE_TYPE_PRIMARY)
   				continue;
-			plane_state = drm_atomic_get_plane_state(state, plane);
-			if (IS_ERR(plane_state))
-				return PTR_ERR(plane_state);
+			plane_state = drm_atomic_get_next_plane_state(state, plane);
   			if (plane_state->fb && plane_state->crtc) {

Hmm. Why this is even looking at these. If the plane is in the crtc's plane_mask then surely plane_state->crtc must already point to this crtc? And I don't think ->fb and ->crtc are allowed to disagree, so if one is set then surely the other one must be as well or we'd return an error at some point somewhere?

Yeah, the crtc test is done for keeping consistency. Other places also sometimes validate that these fields don't disagree. I'll remove the crtc test in the next version. The fb test is the important one.

Quoted 9 lines
Quoted 4 lines

What I'm asking how can you have crtc!=NULL && fb==NULL at all here? Some other plane state check function (can't remember which one specifically) should have rejected that. So either you're checking for impossible things, or there is a bug somewhere else.

Oh and btw, fb != NULL doesn't guarantee the plane is actually visible (could have been fully clipped), if that is what you're trying to check here.

No, it's really just about having a primary plane enabled on the CRTC.

Best regards
Thomas

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
#6 lore raw
Quoted 65 lines · Thomas Zimmermann

Hi

Am 30.09.22 um 12:26 schrieb Ville Syrjälä:

Quoted 62 lines · Ville Syrjälä
Quoted 60 lines · Thomas Zimmermann
Quoted 51 lines

Hi,

thanks for reviewing.

Am 29.09.22 um 21:03 schrieb Ville Syrjälä:

Quoted 32 lines · Thomas Zimmermann
Quoted 31 lines

In drm_atomic_helper_check_crtc_state(), do not add a new plane state to the global state if it does not exist already. Adding a new plane state will results in overhead for the plane during the atomic-commit step.

For the test in drm_atomic_helper_check_crtc_state() to succeed, it is important that the CRTC has an enabled primary plane after the commit. This can be a newly enabled plane or an already enabled plane. So if a plane is not part of the commit, use the plane's existing state. The new helper drm_atomic_get_next_plane_state() returns the correct instance.

Fixes d6b9af1097fe ("drm/atomic-helper: Add helper drm_atomic_helper_check_crtc_state()")
Cc Thomas Zimmermann <[email protected]>
Cc Jocelyn Falempe <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
   drivers/gpu/drm/drm_atomic_helper.c |  4 +---
   include/drm/drm_atomic.h            | 20 ++++++++++++++++++++
   2 files changed, 21 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +0 -0
index 98cc3137c062..463d4f3fa443 100644
@@ -960,9 +960,7 @@ int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state,
 
Quoted 13 lines

drivers/gpu/drm/drm_atomic_helper.c int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state, · line 964

Quoted 7 lines
drivers/gpu/drm/drm_atomic_helper.c +1 -3
   			if (plane->type != DRM_PLANE_TYPE_PRIMARY)
   				continue;
-			plane_state = drm_atomic_get_plane_state(state, plane);
-			if (IS_ERR(plane_state))
-				return PTR_ERR(plane_state);
+			plane_state = drm_atomic_get_next_plane_state(state, plane);
   			if (plane_state->fb && plane_state->crtc) {

Hmm. Why this is even looking at these. If the plane is in the crtc's plane_mask then surely plane_state->crtc must already point to this crtc? And I don't think ->fb and ->crtc are allowed to disagree, so if one is set then surely the other one must be as well or we'd return an error at some point somewhere?

Quoted 3 lines

Yeah, the crtc test is done for keeping consistency. Other places also sometimes validate that these fields don't disagree. I'll remove the crtc test in the next version. The fb test is the important one.

What I'm asking how can you have crtc!=NULL && fb==NULL at all here? Some other plane state check function (can't remember which one specifically) should have rejected that. So either you're checking for impossible things, or there is a bug somewhere else.

Quoted 6 lines
Quoted 4 lines

Oh and btw, fb != NULL doesn't guarantee the plane is actually visible (could have been fully clipped), if that is what you're trying to check here.

No, it's really just about having a primary plane enabled on the CRTC.

Not sure what you mean by enabled. Usually a fully clipped plane will actually be disabled in hardware.

Signature · 2 lines
Ville Syrjälä
Intel
author maintainer
#7 lore raw
In reply to Ville Syrjälä

Hi

Am 30.09.22 um 11:12 schrieb Ville Syrjälä:

Quoted 56 lines · Thomas Zimmermann
Quoted 51 lines

Hi,

thanks for reviewing.

Am 29.09.22 um 21:03 schrieb Ville Syrjälä:

Quoted 32 lines · Thomas Zimmermann
Quoted 31 lines

In drm_atomic_helper_check_crtc_state(), do not add a new plane state to the global state if it does not exist already. Adding a new plane state will results in overhead for the plane during the atomic-commit step.

For the test in drm_atomic_helper_check_crtc_state() to succeed, it is important that the CRTC has an enabled primary plane after the commit. This can be a newly enabled plane or an already enabled plane. So if a plane is not part of the commit, use the plane's existing state. The new helper drm_atomic_get_next_plane_state() returns the correct instance.

Fixes d6b9af1097fe ("drm/atomic-helper: Add helper drm_atomic_helper_check_crtc_state()")
Cc Thomas Zimmermann <[email protected]>
Cc Jocelyn Falempe <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
   drivers/gpu/drm/drm_atomic_helper.c |  4 +---
   include/drm/drm_atomic.h            | 20 ++++++++++++++++++++
   2 files changed, 21 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +0 -0
index 98cc3137c062..463d4f3fa443 100644
@@ -960,9 +960,7 @@ int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state,
 
Quoted 13 lines

drivers/gpu/drm/drm_atomic_helper.c int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state, · line 964

Quoted 7 lines
drivers/gpu/drm/drm_atomic_helper.c +1 -3
   			if (plane->type != DRM_PLANE_TYPE_PRIMARY)
   				continue;
-			plane_state = drm_atomic_get_plane_state(state, plane);
-			if (IS_ERR(plane_state))
-				return PTR_ERR(plane_state);
+			plane_state = drm_atomic_get_next_plane_state(state, plane);
   			if (plane_state->fb && plane_state->crtc) {

Hmm. Why this is even looking at these. If the plane is in the crtc's plane_mask then surely plane_state->crtc must already point to this crtc? And I don't think ->fb and ->crtc are allowed to disagree, so if one is set then surely the other one must be as well or we'd return an error at some point somewhere?

Quoted 3 lines

Yeah, the crtc test is done for keeping consistency. Other places also sometimes validate that these fields don't disagree. I'll remove the crtc test in the next version. The fb test is the important one.

Quoted 7 lines

What I'm asking how can you have crtc!=NULL && fb==NULL at all here? Some other plane state check function (can't remember which one specifically) should have rejected that. So either you're checking for impossible things, or there is a bug somewhere else.

So to me it looks like it should be enough to just check the plane_mask and not even bother looking at the plane state at all.

Indeed. Somehow I confused plane_mask with 'mask of all planes possible'.

Best regards
Thomas

Quoted 64 lines
Quoted 60 lines
Quoted 29 lines
Quoted 29 lines
drivers/gpu/drm/drm_atomic_helper.c +0 -0
   				has_primary_plane = true;
   				break;
include/drm/drm_atomic.h +15 -0
index 10b1990bc1f6..4006f2d459e3 100644
@@ -623,6 +623,26 @@ drm_atomic_get_new_plane_state(struct drm_atomic_state *state,
   	return state->planes[drm_plane_index(plane)].new_state;
   }
 
+/**
+ * drm_atomic_get_next_plane_state - get plane state after atomic commit
+ * @state: global atomic state object
+ * @plane: plane to grab
+ *
+ * This function returns the plane state that the given plane will have
+ * after the atomic commit. This will be the new plane state if the plane
+ * is part of the global atomic state, or the current state otherwise.
+ */
+static inline struct drm_plane_state *
+drm_atomic_get_next_plane_state(struct drm_atomic_state *state,
+				struct drm_plane *plane)
+{
+	struct drm_plane_state *plane_state = drm_atomic_get_new_plane_state(state, plane);
+
Quoted 8 lines

include/drm/drm_atomic.h drm_atomic_get_new_plane_state(struct drm_atomic_state *state, · line 643

Quoted 3 lines
include/drm/drm_atomic.h +3 -0
+	if (plane_state)
+		return plane_state;
+	return plane->state;

You're not holding the appropriate lock so that does not look safe. Even if you know somewhere, somehow this sort of thing to be safe I don't think it's a good idea to promote this with any kind of official function because someone will shoot themselves in the foot with it.

OK. It'll be inlined with locking added.

Best regards
Thomas

Quoted 9 lines
Quoted 8 lines
include/drm/drm_atomic.h +2 -0
+}
+
   /**
    * drm_atomic_get_existing_connector_state - get connector state, if it exists
    * @state: global atomic state object
Signature · 1 line
2.37.3
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev