diff mbox

[v2,5/6] drm/atomic: Handle encoder assignment conflicts in a separate check.

Message ID 1456303053-28806-6-git-send-email-maarten.lankhorst@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Maarten Lankhorst Feb. 24, 2016, 8:37 a.m. UTC
The current check doesn't handle the case where we don't steal an
encoder, but keep it on the current connector. If we repurpose
disable_conflicting_encoders to do the checking, we just have
to reject the ones that conflict.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Testcase: kms_setmode.invalid-clone-single-crtc-stealing
---
 drivers/gpu/drm/drm_atomic_helper.c | 58 +++++++++++++++----------------------
 1 file changed, 24 insertions(+), 34 deletions(-)

Comments

Ville Syrjälä March 1, 2016, 5:21 p.m. UTC | #1
On Wed, Feb 24, 2016 at 09:37:32AM +0100, Maarten Lankhorst wrote:
> The current check doesn't handle the case where we don't steal an
> encoder, but keep it on the current connector. If we repurpose
> disable_conflicting_encoders to do the checking, we just have
> to reject the ones that conflict.
> 
> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Testcase: kms_setmode.invalid-clone-single-crtc-stealing
> ---
>  drivers/gpu/drm/drm_atomic_helper.c | 58 +++++++++++++++----------------------
>  1 file changed, 24 insertions(+), 34 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
> index 3543c7fcd072..32bd5bebef0b 100644
> --- a/drivers/gpu/drm/drm_atomic_helper.c
> +++ b/drivers/gpu/drm/drm_atomic_helper.c
> @@ -86,7 +86,8 @@ drm_atomic_helper_plane_changed(struct drm_atomic_state *state,
>  	}
>  }
>  
> -static int disable_conflicting_connectors(struct drm_atomic_state *state)
> +static int handle_conflicting_encoders(struct drm_atomic_state *state,
> +				       bool disable_conflicting_encoders)
>  {
>  	struct drm_connector_state *conn_state;
>  	struct drm_connector *connector;
> @@ -106,8 +107,17 @@ static int disable_conflicting_connectors(struct drm_atomic_state *state)
>  		else
>  			new_encoder = funcs->best_encoder(connector);
>  
> -		if (new_encoder)
> +		if (new_encoder) {
> +			if (encoder_mask & (1 << drm_encoder_index(new_encoder))) {
> +				DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] on [CONNECTOR:%d:%s] already assigned\n",
> +					new_encoder->base.id, new_encoder->name,
> +					connector->base.id, connector->name);
> +
> +				return -EINVAL;
> +			}
> +
>  			encoder_mask |= 1 << drm_encoder_index(new_encoder);
> +		}
>  	}
>  
>  	drm_for_each_connector(connector, state->dev) {
> @@ -120,6 +130,15 @@ static int disable_conflicting_connectors(struct drm_atomic_state *state)
>  		if (!encoder || !(encoder_mask & (1 << drm_encoder_index(encoder))))
>  			continue;
>  
> +		if (!disable_conflicting_encoders) {
> +			DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] in use on [CRTC:%d:%s] by [CONNECTOR:%d:%s]\n",
> +					 encoder->base.id, encoder->name,
> +					 connector->state->crtc->base.id,
> +					 connector->state->crtc->name,
> +					 connector->base.id, connector->name);
> +			return -EINVAL;
> +		}
> +

Hmm. This can't possibly work can it? If I'm reding things correctly
this would already fail if we have crtc0->enc0->conn0 and then try to
change it to crtc1->enc0->conn0. But perhaps I'm missing some subtle
thing (there are a lot of those in our atomic framework due to thing
automagically getting added to the state).

The idea I had for checking things was something like:
for legacy setcrtc:
 for_new_connstate()
 	if (!state->crtc)
		continue;
	enc = ->best_encoder();
	if (encoder_mask & 1 << enc.index)
		fail;
 	encoder_mask |= 1 << enc.index;
 for_all_connectors
 	if (new_state)
		continue;
	if (!old_state->crtc)
		continue;
	enc = conn->best_encoder;
	if (encoder_mask & 1 << enc.index)
		disable_connector;

for atomic: 
 for_all_connectors
 	if (new_state)
		state = new_state;
	else
		state = old_state;
	if (!state->crtc)
		continue;
	if (new_state)
		enc = ->best_encoder()
	else
		enc = conn->best_encoder;
	if (encoder_mask & 1 << enc.index)
		fail;
	encoder_mask |= 1 << enc.index;

Though I'm not entirely sure the legacy variant would work correctly due
to something maybe adding the connector to the state even though it's
not part of the set that the user requested. I might need to think more
on this.


>  		conn_state = drm_atomic_get_connector_state(state, connector);
>  		if (IS_ERR(conn_state))
>  			return PTR_ERR(conn_state);
> @@ -148,26 +167,6 @@ static int disable_conflicting_connectors(struct drm_atomic_state *state)
>  	return 0;
>  }
>  
> -static bool
> -check_pending_encoder_assignment(struct drm_atomic_state *state,
> -				 struct drm_encoder *new_encoder)
> -{
> -	struct drm_connector *connector;
> -	struct drm_connector_state *conn_state;
> -	int i;
> -
> -	for_each_connector_in_state(state, connector, conn_state, i) {
> -		if (conn_state->best_encoder != new_encoder)
> -			continue;
> -
> -		/* encoder already assigned and we're trying to re-steal it! */
> -		if (connector->state->best_encoder != conn_state->best_encoder)
> -			return false;
> -	}
> -
> -	return true;
> -}
> -
>  static void
>  set_best_encoder(struct drm_atomic_state *state,
>  		 struct drm_connector_state *conn_state,
> @@ -326,13 +325,6 @@ update_connector_routing(struct drm_atomic_state *state,
>  		return 0;
>  	}
>  
> -	if (!check_pending_encoder_assignment(state, new_encoder)) {
> -		DRM_DEBUG_ATOMIC("Encoder for [CONNECTOR:%d:%s] already assigned\n",
> -				 connector->base.id,
> -				 connector->name);
> -		return -EINVAL;
> -	}
> -
>  	ret = steal_encoder(state, new_encoder);
>  	if (ret) {
>  		DRM_DEBUG_ATOMIC("Encoder stealing failed for [CONNECTOR:%d:%s]\n",
> @@ -511,11 +503,9 @@ drm_atomic_helper_check_modeset(struct drm_device *dev,
>  		}
>  	}
>  
> -	if (state->legacy_set_config) {
> -		ret = disable_conflicting_connectors(state);
> -		if (ret)
> -			return ret;
> -	}
> +	ret = handle_conflicting_encoders(state, state->legacy_set_config);
> +	if (ret)
> +		return ret;
>  
>  	for_each_connector_in_state(state, connector, connector_state, i) {
>  		/*
> -- 
> 2.1.0
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Maarten Lankhorst March 1, 2016, 5:45 p.m. UTC | #2
Op 01-03-16 om 18:21 schreef Ville Syrjälä:
> On Wed, Feb 24, 2016 at 09:37:32AM +0100, Maarten Lankhorst wrote:
>> The current check doesn't handle the case where we don't steal an
>> encoder, but keep it on the current connector. If we repurpose
>> disable_conflicting_encoders to do the checking, we just have
>> to reject the ones that conflict.
>>
>> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
>> Testcase: kms_setmode.invalid-clone-single-crtc-stealing
>> ---
>>  drivers/gpu/drm/drm_atomic_helper.c | 58 +++++++++++++++----------------------
>>  1 file changed, 24 insertions(+), 34 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
>> index 3543c7fcd072..32bd5bebef0b 100644
>> --- a/drivers/gpu/drm/drm_atomic_helper.c
>> +++ b/drivers/gpu/drm/drm_atomic_helper.c
>> @@ -86,7 +86,8 @@ drm_atomic_helper_plane_changed(struct drm_atomic_state *state,
>>  	}
>>  }
>>  
>> -static int disable_conflicting_connectors(struct drm_atomic_state *state)
>> +static int handle_conflicting_encoders(struct drm_atomic_state *state,
>> +				       bool disable_conflicting_encoders)
>>  {
>>  	struct drm_connector_state *conn_state;
>>  	struct drm_connector *connector;
>> @@ -106,8 +107,17 @@ static int disable_conflicting_connectors(struct drm_atomic_state *state)
>>  		else
>>  			new_encoder = funcs->best_encoder(connector);
>>  
>> -		if (new_encoder)
>> +		if (new_encoder) {
>> +			if (encoder_mask & (1 << drm_encoder_index(new_encoder))) {
>> +				DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] on [CONNECTOR:%d:%s] already assigned\n",
>> +					new_encoder->base.id, new_encoder->name,
>> +					connector->base.id, connector->name);
>> +
>> +				return -EINVAL;
>> +			}
>> +
>>  			encoder_mask |= 1 << drm_encoder_index(new_encoder);
>> +		}
>>  	}
>>  
>>  	drm_for_each_connector(connector, state->dev) {
>> @@ -120,6 +130,15 @@ static int disable_conflicting_connectors(struct drm_atomic_state *state)
>>  		if (!encoder || !(encoder_mask & (1 << drm_encoder_index(encoder))))
>>  			continue;
>>  
>> +		if (!disable_conflicting_encoders) {
>> +			DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] in use on [CRTC:%d:%s] by [CONNECTOR:%d:%s]\n",
>> +					 encoder->base.id, encoder->name,
>> +					 connector->state->crtc->base.id,
>> +					 connector->state->crtc->name,
>> +					 connector->base.id, connector->name);
>> +			return -EINVAL;
>> +		}
>> +
> Hmm. This can't possibly work can it? If I'm reding things correctly
> this would already fail if we have crtc0->enc0->conn0 and then try to
> change it to crtc1->enc0->conn0. But perhaps I'm missing some subtle
> thing (there are a lot of those in our atomic framework due to thing
> automagically getting added to the state).
>
No, in that case the connector is part of the state.

This boils down to:

if (stealing encoder from existing connector not part of state)
if (atomic) return -EINVAL;
else
// disable connector and possibly crtc

~Maarten
Ville Syrjälä March 1, 2016, 5:58 p.m. UTC | #3
On Tue, Mar 01, 2016 at 06:45:53PM +0100, Maarten Lankhorst wrote:
> Op 01-03-16 om 18:21 schreef Ville Syrjälä:
> > On Wed, Feb 24, 2016 at 09:37:32AM +0100, Maarten Lankhorst wrote:
> >> The current check doesn't handle the case where we don't steal an
> >> encoder, but keep it on the current connector. If we repurpose
> >> disable_conflicting_encoders to do the checking, we just have
> >> to reject the ones that conflict.
> >>
> >> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> >> Testcase: kms_setmode.invalid-clone-single-crtc-stealing
> >> ---
> >>  drivers/gpu/drm/drm_atomic_helper.c | 58 +++++++++++++++----------------------
> >>  1 file changed, 24 insertions(+), 34 deletions(-)
> >>
> >> diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
> >> index 3543c7fcd072..32bd5bebef0b 100644
> >> --- a/drivers/gpu/drm/drm_atomic_helper.c
> >> +++ b/drivers/gpu/drm/drm_atomic_helper.c
> >> @@ -86,7 +86,8 @@ drm_atomic_helper_plane_changed(struct drm_atomic_state *state,
> >>  	}
> >>  }
> >>  
> >> -static int disable_conflicting_connectors(struct drm_atomic_state *state)
> >> +static int handle_conflicting_encoders(struct drm_atomic_state *state,
> >> +				       bool disable_conflicting_encoders)
> >>  {
> >>  	struct drm_connector_state *conn_state;
> >>  	struct drm_connector *connector;
> >> @@ -106,8 +107,17 @@ static int disable_conflicting_connectors(struct drm_atomic_state *state)
> >>  		else
> >>  			new_encoder = funcs->best_encoder(connector);
> >>  
> >> -		if (new_encoder)
> >> +		if (new_encoder) {
> >> +			if (encoder_mask & (1 << drm_encoder_index(new_encoder))) {
> >> +				DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] on [CONNECTOR:%d:%s] already assigned\n",
> >> +					new_encoder->base.id, new_encoder->name,
> >> +					connector->base.id, connector->name);
> >> +
> >> +				return -EINVAL;
> >> +			}
> >> +
> >>  			encoder_mask |= 1 << drm_encoder_index(new_encoder);
> >> +		}
> >>  	}
> >>  
> >>  	drm_for_each_connector(connector, state->dev) {
> >> @@ -120,6 +130,15 @@ static int disable_conflicting_connectors(struct drm_atomic_state *state)
> >>  		if (!encoder || !(encoder_mask & (1 << drm_encoder_index(encoder))))
> >>  			continue;
> >>  
> >> +		if (!disable_conflicting_encoders) {
> >> +			DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] in use on [CRTC:%d:%s] by [CONNECTOR:%d:%s]\n",
> >> +					 encoder->base.id, encoder->name,
> >> +					 connector->state->crtc->base.id,
> >> +					 connector->state->crtc->name,
> >> +					 connector->base.id, connector->name);
> >> +			return -EINVAL;
> >> +		}
> >> +
> > Hmm. This can't possibly work can it? If I'm reding things correctly
> > this would already fail if we have crtc0->enc0->conn0 and then try to
> > change it to crtc1->enc0->conn0. But perhaps I'm missing some subtle
> > thing (there are a lot of those in our atomic framework due to thing
> > automagically getting added to the state).
> >
> No, in that case the connector is part of the state.

Doh, I misread the condition for the existing state check.

OK, so I guess this is more or less what I had in mind as well, except
it uses the two loops version for both cases. The one difference between
my idea and this is that you don't include the old encoders in
encoder_mask for the atomic case, but that should be perfectly fine
since we can assume the old state itself had no conflicting encoder
assignments.

I think it could use a few high levelish comments around the loops to
explain what they are supposed to do, somewhat like you had in
update_output_state().

> 
> This boils down to:
> 
> if (stealing encoder from existing connector not part of state)
> if (atomic) return -EINVAL;
> else
> // disable connector and possibly crtc
> 
> ~Maarten
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
index 3543c7fcd072..32bd5bebef0b 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -86,7 +86,8 @@  drm_atomic_helper_plane_changed(struct drm_atomic_state *state,
 	}
 }
 
-static int disable_conflicting_connectors(struct drm_atomic_state *state)
+static int handle_conflicting_encoders(struct drm_atomic_state *state,
+				       bool disable_conflicting_encoders)
 {
 	struct drm_connector_state *conn_state;
 	struct drm_connector *connector;
@@ -106,8 +107,17 @@  static int disable_conflicting_connectors(struct drm_atomic_state *state)
 		else
 			new_encoder = funcs->best_encoder(connector);
 
-		if (new_encoder)
+		if (new_encoder) {
+			if (encoder_mask & (1 << drm_encoder_index(new_encoder))) {
+				DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] on [CONNECTOR:%d:%s] already assigned\n",
+					new_encoder->base.id, new_encoder->name,
+					connector->base.id, connector->name);
+
+				return -EINVAL;
+			}
+
 			encoder_mask |= 1 << drm_encoder_index(new_encoder);
+		}
 	}
 
 	drm_for_each_connector(connector, state->dev) {
@@ -120,6 +130,15 @@  static int disable_conflicting_connectors(struct drm_atomic_state *state)
 		if (!encoder || !(encoder_mask & (1 << drm_encoder_index(encoder))))
 			continue;
 
+		if (!disable_conflicting_encoders) {
+			DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] in use on [CRTC:%d:%s] by [CONNECTOR:%d:%s]\n",
+					 encoder->base.id, encoder->name,
+					 connector->state->crtc->base.id,
+					 connector->state->crtc->name,
+					 connector->base.id, connector->name);
+			return -EINVAL;
+		}
+
 		conn_state = drm_atomic_get_connector_state(state, connector);
 		if (IS_ERR(conn_state))
 			return PTR_ERR(conn_state);
@@ -148,26 +167,6 @@  static int disable_conflicting_connectors(struct drm_atomic_state *state)
 	return 0;
 }
 
-static bool
-check_pending_encoder_assignment(struct drm_atomic_state *state,
-				 struct drm_encoder *new_encoder)
-{
-	struct drm_connector *connector;
-	struct drm_connector_state *conn_state;
-	int i;
-
-	for_each_connector_in_state(state, connector, conn_state, i) {
-		if (conn_state->best_encoder != new_encoder)
-			continue;
-
-		/* encoder already assigned and we're trying to re-steal it! */
-		if (connector->state->best_encoder != conn_state->best_encoder)
-			return false;
-	}
-
-	return true;
-}
-
 static void
 set_best_encoder(struct drm_atomic_state *state,
 		 struct drm_connector_state *conn_state,
@@ -326,13 +325,6 @@  update_connector_routing(struct drm_atomic_state *state,
 		return 0;
 	}
 
-	if (!check_pending_encoder_assignment(state, new_encoder)) {
-		DRM_DEBUG_ATOMIC("Encoder for [CONNECTOR:%d:%s] already assigned\n",
-				 connector->base.id,
-				 connector->name);
-		return -EINVAL;
-	}
-
 	ret = steal_encoder(state, new_encoder);
 	if (ret) {
 		DRM_DEBUG_ATOMIC("Encoder stealing failed for [CONNECTOR:%d:%s]\n",
@@ -511,11 +503,9 @@  drm_atomic_helper_check_modeset(struct drm_device *dev,
 		}
 	}
 
-	if (state->legacy_set_config) {
-		ret = disable_conflicting_connectors(state);
-		if (ret)
-			return ret;
-	}
+	ret = handle_conflicting_encoders(state, state->legacy_set_config);
+	if (ret)
+		return ret;
 
 	for_each_connector_in_state(state, connector, connector_state, i) {
 		/*