Skip to contentSkip to conversation

Patch "drm/amd/display: release spinlock before committing updates to stream" has been added to the 4.17-stable tree

DISCUSSION Andrey Grodzovsky 4 participants 6 messages Jul 5, 2018 – Jul 6, 2018 1 message not in the archive Stable branch

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive

This patch is wrong as noted by MIchel a while ago - quote from his review of the patch.

"Actually, pflip_status should really only be set to AMDGPU_FLIP_SUBMITTED after the flip has been programmed to the hardware, at least as far as the lock holder is concerned. That's why the code was previously holding the lock until after the dc_commit_updates_for_stream call. Otherwise, it's at least theoretically possible that either:

* dm_pflip_high_irq is called before dc_commit_updates_for_stream, but sees flip_status == AMDGPU_FLIP_SUBMITTED and sends the event to userspace prematurely

* dm_pflip_high_irq is called after dc_commit_updates_for_stream, but sees flip_status != AMDGPU_FLIP_SUBMITTED, so it incorrectly doesn't send the event to userspace "

It shouldn't go in.

Andrey

Quoted 82 lines · On 07/05/2018 11:59 AM, [email protected] wrote:

This is a note to let you know that I've just added the patch titled

drm/amd/display: release spinlock before committing updates to stream

to the 4.17-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
drm-amd-display-release-spinlock-before-committing-updates-to-stream.patch
and it can be found in the queue-4.17 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

From 4de9f38bb2cce3a4821ffb8a83d6b08f6e37d905 Mon Sep 17 00:00:00 2001
From: Shirish S <[email protected]>
Date: Tue, 26 Jun 2018 09:32:39 +0530
Subject: drm/amd/display: release spinlock before committing updates to stream
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

From: Shirish S <[email protected]>

commit 4de9f38bb2cce3a4821ffb8a83d6b08f6e37d905 upstream.

Currently, amdgpu_do_flip() spinlocks crtc->dev->event_lock and releases it only after committing updates to the stream.

dc_commit_updates_for_stream() should be moved out of spinlock for the below reasons:

1. event_lock is supposed to protect access to acrct->pflip_status _only_
2. dc_commit_updates_for_stream() has potential sleep's
and also its not appropriate to be in an atomic state for such long sequences of code.

---
  drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |    6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2 -4
@@ -3967,10 +3967,11 @@ static void amdgpu_dm_do_flip(struct drm
  	if (acrtc->base.state->event)
  		prepare_flip_isr(acrtc);
 
+	spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
+
  	surface_updates->surface = dc_stream_get_status(acrtc_state->stream)->plane_states[0];
  	surface_updates->flip_addr = &addr;
 
-
  	dc_commit_updates_for_stream(adev->dm.dc,
  					     surface_updates,
  					     1,
@@ -3983,9 +3984,6 @@ static void amdgpu_dm_do_flip(struct drm
  			 __func__,
  			 addr.address.grph.addr.high_part,
  			 addr.address.grph.addr.low_part);
-
-
-	spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
  }
 
  static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,

Patches currently in stable-queue which might be from [email protected] are

queue-4.17/drm-amdgpu-add-apu-support-in-vi_set_vce_clocks.patch queue-4.17/drm-amdgpu-add-apu-support-in-vi_set_uvd_clocks.patch queue-4.17/drm-amd-display-release-spinlock-before-committing-updates-to-stream.patch

maintainer
#2 lore raw
Quoted 13 lines · Andrey Grodzovsky

This patch is wrong as noted by MIchel a while ago - quote from his review of the patch.

"Actually, pflip_status should really only be set to AMDGPU_FLIP_SUBMITTED after the flip has been programmed to the hardware, at least as far as the lock holder is concerned. That's why the code was previously holding the lock until after the dc_commit_updates_for_stream call. Otherwise, it's at least theoretically possible that either:

* dm_pflip_high_irq is called before dc_commit_updates_for_stream, but sees flip_status == AMDGPU_FLIP_SUBMITTED and sends the event to userspace prematurely

Quoted 5 lines

* dm_pflip_high_irq is called after dc_commit_updates_for_stream, but sees flip_status != AMDGPU_FLIP_SUBMITTED, so it incorrectly doesn't send the event to userspace "

It shouldn't go in.

Is there a fix for this in Linus's tree for these problems? If not, why not? If so, what is that git commit id?

thanks,

greg k-h

#3 lore raw
Quoted 14 lines · Greg KH
Quoted 13 lines · Andrey Grodzovsky

This patch is wrong as noted by MIchel a while ago - quote from his review of the patch.

"Actually, pflip_status should really only be set to AMDGPU_FLIP_SUBMITTED after the flip has been programmed to the hardware, at least as far as the lock holder is concerned. That's why the code was previously holding the lock until after the dc_commit_updates_for_stream call. Otherwise, it's at least theoretically possible that either:

* dm_pflip_high_irq is called before dc_commit_updates_for_stream, but sees flip_status == AMDGPU_FLIP_SUBMITTED and sends the event to userspace prematurely

Quoted 7 lines
Quoted 5 lines

* dm_pflip_high_irq is called after dc_commit_updates_for_stream, but sees flip_status != AMDGPU_FLIP_SUBMITTED, so it incorrectly doesn't send the event to userspace "

It shouldn't go in.

Is there a fix for this in Linus's tree for these problems? If not, why not? If so, what is that git commit id?

AFAIK there is still no fix for the original issue which this patch was intended to fix.

Harry, can you please comment on this ?

Andrey

Quoted 4 lines

thanks,

greg k-h

#4 lore raw
Quoted 19 lines · Andrey Grodzovsky
Quoted 18 lines · Greg KH
Quoted 17 lines · Andrey Grodzovsky

This patch is wrong as noted by MIchel a while ago - quote from his review of the patch.

"Actually, pflip_status should really only be set to AMDGPU_FLIP_SUBMITTED after the flip has been programmed to the hardware, at least as far as the lock holder is concerned. That's why the code was previously holding the lock until after the dc_commit_updates_for_stream call. Otherwise, it's at least theoretically possible that either:

* dm_pflip_high_irq is called before dc_commit_updates_for_stream, but sees flip_status == AMDGPU_FLIP_SUBMITTED and sends the event to userspace prematurely

* dm_pflip_high_irq is called after dc_commit_updates_for_stream, but sees flip_status != AMDGPU_FLIP_SUBMITTED, so it incorrectly doesn't send the event to userspace "

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

It shouldn't go in.

Is there a fix for this in Linus's tree for these problems? If not, why not?  If so, what is that git commit id?

AFAIK there is still no fix for the original issue which this patch was intended to fix.

Harry, can you please comment on this ?

That can be better answered by Shirish.

In my opinion the issue described by Michel is a lesser evil than attempting to allocate memory inside a spinlocked area.

Shirish, we need to understand why dc_commit_updates_for_stream() is trying to do a UPDATE_TYPE_FULL in your scenario. This should never really happen through the amdgpu_dm_do_flip code path and we need to understand why. If we never do UPDATE_TYPE_FULL here we should not need to allocate memory and should be find with leaving the spinlock around dc_commit_updates_for_stream().

Harry

Quoted 7 lines

Andrey

Quoted 4 lines

thanks,

greg k-h

#5 lore raw
Quoted 16 lines · Harry Wentland
Quoted 15 lines · Andrey Grodzovsky
Quoted 14 lines · Greg KH
Quoted 13 lines · Andrey Grodzovsky

This patch is wrong as noted by MIchel a while ago - quote from his review of the patch.

"Actually, pflip_status should really only be set to AMDGPU_FLIP_SUBMITTED after the flip has been programmed to the hardware, at least as far as the lock holder is concerned. That's why the code was previously holding the lock until after the dc_commit_updates_for_stream call. Otherwise, it's at least theoretically possible that either:

* dm_pflip_high_irq is called before dc_commit_updates_for_stream, but sees flip_status == AMDGPU_FLIP_SUBMITTED and sends the event to userspace prematurely

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

* dm_pflip_high_irq is called after dc_commit_updates_for_stream, but sees flip_status != AMDGPU_FLIP_SUBMITTED, so it incorrectly doesn't send the event to userspace "

It shouldn't go in.

Is there a fix for this in Linus's tree for these problems? If not, why not?  If so, what is that git commit id?

AFAIK there is still no fix for the original issue which this patch was intended to fix.

Andrey,
Ideally  sleep's should not be coded within spinlock block, in this case its coded in dc_commit_updates_for_stream() at the below occurrences:
1. In drivers/gpu/drm/amd/amdgpu/atom.c => amdgpu_atom_execute_table_locked() => kzalloc
2. mutex callbacks in drivers/gpu/drm/amd/powerplay/amd_powerplay.c & drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c.
3. In drivers/gpu/drm/amd/display/dc/core/dc.c => dc_create_state() => kzalloc

In my case,  when rendering on multiple planes,  it led to system instabilities and with this patch applied we no more see them. (analysis further below in this mail).

Also when posted on amd-gfx with the corresponding RB's there was no objection to this patch not sure if nobody saw this patch getting merged.

Quoted 5 lines
Quoted 2 lines

Harry, can you please comment on this ?

That can be better answered by Shirish.

In my opinion the issue described by Michel is a lesser evil than attempting to allocate memory inside a spinlocked area.

Yes Harry. I agree, hence i pushed this patch as we have a code that attempts to allocate memory and furthermore calls mutex's.

Quoted 1 line

Shirish, we need to understand why dc_commit_updates_for_stream() is trying to do a UPDATE_TYPE_FULL in your scenario. This should never really happen through the amdgpu_dm_do_flip code path and we need to understand why.

This happens in amdgpu_dm_do_flip() because of the hard-coded number of surfaces it call dc_commit_updates_for_stream() with, dc_commit_updates_for_stream(adev->dm.dc,
                                             surface_updates,
                                             1, <<<<<<<<<
                                             acrtc_state->stream,
                                             NULL,
&surface_updates->surface,
                                             state);

which is 1, where as in case of rendering on multiple planes the stream has 2 surfaces attached and hence the below  condition fails in very first check of check_update_surfaces_for_stream() "if ( ... || stream_status->plane_count != surface_count)"

Quoted 1 line

If we never do UPDATE_TYPE_FULL here we should not need to allocate memory and should be find with leaving the spinlock around dc_commit_updates_for_stream().

As i understand we may end-up trying to do a UPDATE_TYPE_FULL due to failure in any of the several checks in dc_check_update_surfaces_for_stream().
We cannot rule out the possibility of a code path being executed as long as it exists, ideally we should code another callback in amdgpu_dm_flip() that presumes the update type is always UPDATE_TYPE_FAST.

Till we fix this hard-coding i recommend that we should have this patch, am open to avoiding it if it breaks existing working systems or offends any builds.

Thanks.
Regards,
Shirish S

Quoted 7 lines

Harry

Quoted 5 lines

Andrey

Quoted 3 lines

thanks,

greg k-h

Signature · 2 lines
Regards,
Shirish S
#6 lore raw
Quoted 57 lines · Shirish
Quoted 16 lines · Harry Wentland
Quoted 15 lines · Andrey Grodzovsky
Quoted 14 lines · Greg KH
Quoted 13 lines · Andrey Grodzovsky

This patch is wrong as noted by MIchel a while ago - quote from his review of the patch.

"Actually, pflip_status should really only be set to AMDGPU_FLIP_SUBMITTED after the flip has been programmed to the hardware, at least as far as the lock holder is concerned. That's why the code was previously holding the lock until after the dc_commit_updates_for_stream call. Otherwise, it's at least theoretically possible that either:

* dm_pflip_high_irq is called before dc_commit_updates_for_stream, but sees flip_status == AMDGPU_FLIP_SUBMITTED and sends the event to userspace prematurely

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

* dm_pflip_high_irq is called after dc_commit_updates_for_stream, but sees flip_status != AMDGPU_FLIP_SUBMITTED, so it incorrectly doesn't send the event to userspace "

It shouldn't go in.

Is there a fix for this in Linus's tree for these problems? If not, why not?  If so, what is that git commit id?

AFAIK there is still no fix for the original issue which this patch was intended to fix.

Andrey,
Ideally  sleep's should not be coded within spinlock block, in this case its coded in dc_commit_updates_for_stream() at the below occurrences:
1. In drivers/gpu/drm/amd/amdgpu/atom.c => amdgpu_atom_execute_table_locked() => kzalloc
2. mutex callbacks in drivers/gpu/drm/amd/powerplay/amd_powerplay.c & drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c.
3. In drivers/gpu/drm/amd/display/dc/core/dc.c => dc_create_state() => kzalloc

In my case,  when rendering on multiple planes,  it led to system instabilities and with this patch applied we no more see them. (analysis further below in this mail).

Also when posted on amd-gfx with the corresponding RB's there was no objection to this patch not sure if nobody saw this patch getting merged.

Quoted 5 lines
Quoted 2 lines

Harry, can you please comment on this ?

That can be better answered by Shirish.

In my opinion the issue described by Michel is a lesser evil than attempting to allocate memory inside a spinlocked area.

Yes Harry. I agree, hence i pushed this patch as we have a code that attempts to allocate memory and furthermore calls mutex's.

Quoted 1 line

Shirish, we need to understand why dc_commit_updates_for_stream() is trying to do a UPDATE_TYPE_FULL in your scenario. This should never really happen through the amdgpu_dm_do_flip code path and we need to understand why.

This happens in amdgpu_dm_do_flip() because of the hard-coded number of surfaces it call dc_commit_updates_for_stream() with, dc_commit_updates_for_stream(adev->dm.dc,
                                             surface_updates,
                                             1, <<<<<<<<<
acrtc_state->stream,
                                             NULL,
&surface_updates->surface,
                                             state);

which is 1, where as in case of rendering on multiple planes the stream has 2 surfaces attached and hence the below  condition fails in very first check of check_update_surfaces_for_stream() "if ( ... || stream_status->plane_count != surface_count)"

Quoted 1 line

  If we never do UPDATE_TYPE_FULL here we should not need to allocate memory and should be find with leaving the spinlock around dc_commit_updates_for_stream().

Quoted 8 lines

As i understand we may end-up trying to do a UPDATE_TYPE_FULL due to failure in any of the several checks in dc_check_update_surfaces_for_stream().
We cannot rule out the possibility of a code path being executed as long as it exists, ideally we should code another callback in amdgpu_dm_flip() that presumes the update type is always UPDATE_TYPE_FAST.

Till we fix this hard-coding i recommend that we should have this patch, am open to avoiding it if it breaks existing working systems or offends any builds.

Thanks.
Regards,
Shirish S

I believe that at least then we should put a BIG comment in the code explaining this change both to avoid future people looking into it trying to revert it believing it's just a plain bug and for possible proper revert when the underlying issue with sleeping in atomic context is resolved.

Andrey

Quoted 8 lines
Quoted 7 lines

Harry

Quoted 5 lines

Andrey

Quoted 3 lines

thanks,

greg k-h