drm/amd/display: Fix error handling on waiting for completion
Subsystems (3)
PATCH 1/1 drm/amd/display: Fix error handling on waiting for completion
[Why]
In GNOME Settings->Display the switching from mirror mode to single display occasionally causes wait_for_completion_interruptible_timeout() to return -ERESTARTSYS and fails atomic check.
[How]
Replace the call with wait_for_completion_timeout() since the waiting for hw_done and flip_done completion doesn't need to worry about interruption from signal.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2 -2
@@ -9844,10 +9844,10 @@ static int do_aquire_global_lock(struct drm_device *dev,* Make sure all pending HW programming completed and * page flips done */ - ret =wait_for_completion_interruptible_timeout (&commit->hw_done,10 *HZ ); + ret =wait_for_completion_timeout (&commit->hw_done,10 *HZ );if (ret >0 ) - ret =wait_for_completion_interruptible_timeout ( + ret =wait_for_completion_timeout ( &commit->flip_done,10 *HZ );if (ret ==0 )
Signature · 1 line
2.33.0
Quoted 11 lines · Stylon Wang
[Why]
In GNOMESettings->Displaythe switching from mirror mode to single display occasionally causeswait_for_completion_interruptible_timeout()to return-ERESTARTSYSand fails atomic check.[How]
Replace the call withwait_for_completion_timeout()since the waiting forhw_doneandflip_donecompletion doesn't need to worry about interruption from signal.Signed-off-by Stylon Wang <[email protected]>
I think this is okay, but I'll write out how I think these work here in case anyone has corrections.
Both variants allow the thread to sleep, but the interruptible variant can waken due to signals. These signals are a secondary wakeup event and would require use to restart the wait and (probably) keep track of how long we were waiting before.
We want wakeup only on completion, so we should be using the wait_for_completion_timeout() variants instead in most (if not all?) cases in our display driver.
This probably has some nuances that matter more for different variants of UAPI, but with this understanding I think this is:
Now, if we could revive that patch series I had from the other year and outright drop do_aquire_global_lock()...
Regards,
Nicholas Kazlauskas
Quoted 22 lines
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2
-2@@ -9844,10 +9844,10 @@ static int do_aquire_global_lock(struct drm_device *dev,* Make sure all pending HW programming completed and * page flips done */ - ret =wait_for_completion_interruptible_timeout (&commit->hw_done,10 *HZ ); + ret =wait_for_completion_timeout (&commit->hw_done,10 *HZ );if (ret >0 ) - ret =wait_for_completion_interruptible_timeout ( + ret =wait_for_completion_timeout ( &commit->flip_done,10 *HZ );if (ret ==0 )
Quoted 23 lines · Stylon Wang
[Why]
In GNOMESettings->Displaythe switching from mirror mode to single display occasionally causeswait_for_completion_interruptible_timeout()to return-ERESTARTSYSand fails atomic check.[How]
Replace the call withwait_for_completion_timeout()since the waiting forhw_doneandflip_donecompletion doesn't need to worry about interruption from signal.Signed-off-by Stylon Wang <[email protected]>--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0
-0@@ -9844,10 +9844,10 @@ static int do_aquire_global_lock(struct drm_device *dev,* Make sure all pending HW programming completed and * page flips done
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int do_aquire_global_lock(struct drm_device *dev, · line 9853
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2
-2*/ - ret =wait_for_completion_interruptible_timeout (&commit->hw_done,10 *HZ ); + ret =wait_for_completion_timeout (&commit->hw_done,10 *HZ );if (ret >0 ) - ret =wait_for_completion_interruptible_timeout ( + ret =wait_for_completion_timeout ( &commit->flip_done,10 *HZ );if (ret ==0 )
The *_interruptible_* variant is needed so that the display manager process can be killed while it's waiting here, which could take up to 10 seconds (per the timeout).
What's the problem with -ERESTARTSYS? Either the ioctl should be restarted automatically, or if it bounces back to user space, that needs to be able to retry the ioctl while it returns -1 and errno == EINTR. drmIoctl handles this transparently.
Signature · 2 lines
Earthling Michel Dänzer | https://redhat.com Libre software enthusiast | Mesa and Xwayland developer
Quoted 32 lines · Michel Dänzer
Quoted 31 lines · Stylon Wang
[Why]
In GNOMESettings->Displaythe switching from mirror mode to single display occasionally causeswait_for_completion_interruptible_timeout()to return-ERESTARTSYSand fails atomic check.[How]
Replace the call withwait_for_completion_timeout()since the waiting forhw_doneandflip_donecompletion doesn't need to worry about interruption from signal.Signed-off-by Stylon Wang <[email protected]>--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2
-2@@ -9844,10 +9844,10 @@ static int do_aquire_global_lock(struct drm_device *dev,* Make sure all pending HW programming completed and * page flips done */ - ret =wait_for_completion_interruptible_timeout (&commit->hw_done,10 *HZ ); + ret =wait_for_completion_timeout (&commit->hw_done,10 *HZ );if (ret >0 ) - ret =wait_for_completion_interruptible_timeout ( + ret =wait_for_completion_timeout ( &commit->flip_done,10 *HZ );
Quoted 8 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int do_aquire_global_lock(struct drm_device *dev, · line 9853
Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0
-0if (ret ==0 )The *_interruptible_* variant is needed so that the display manager process can be killed while it's waiting here, which could take up to 10 seconds (per the timeout).
What's the problem with
-ERESTARTSYS? Either the ioctl should be restarted automatically, or if it bounces back to user space, that needs to be able to retry the ioctl while it returns -1 and errno == EINTR. drmIoctl handles this transparently.
Thanks for the insight Michel!
If it's just an error in the log without a functional issue then maybe we should downgrade it to a debug statement in the case where it returns -ERESTARTSYS.
If this is a functional issue (DRM not automatically retrying the commit?) then maybe we should take a deeper look into the IOCTL itself.
Regards,
Nicholas Kazlauskas
Quoted 6 lines · Nicholas
If it's just an error in the log without a functional issue then maybe we should downgrade it to a debug statement in the case where it returns
-ERESTARTSYS.If this is a functional issue (DRM not automatically retrying the commit?) then maybe we should take a deeper look into the IOCTL itself.
libdrm handles EINTR but not ERESTARTSYS. So, if the kernel returns ERESTARTSYS then Mutter will error out.
Should the kernel be fixed to return EINTR instead of ERESTARTSYS, or should libdrm be fixed to handle ERESTARTSYS?
Quoted 6 lines · Simon Ser
Quoted 4 lines · Nicholas
If it's just an error in the log without a functional issue then maybe we should downgrade it to a debug statement in the case where it returns
-ERESTARTSYS.
Quoted 8 lines
Quoted 2 lines
If this is a functional issue (DRM not automatically retrying the commit?) then maybe we should take a deeper look into the IOCTL itself.
libdrm handles EINTR but not ERESTARTSYS. So, if the kernel returns ERESTARTSYS then Mutter will error out.
Should the kernel be fixed to return EINTR instead of ERESTARTSYS, or should libdrm be fixed to handle ERESTARTSYS?
The kernel is supposed to convert ERESTARTSYS to EINTR when returning to user space (when the kernel can't restart the system call itself), so user space doesn't need to handle the former.
Signature · 2 lines
Earthling Michel Dänzer | https://redhat.com Libre software enthusiast | Mesa and Xwayland developer
Am 26.10.21 um 18:03 schrieb Kazlauskas, Nicholas:
Quoted 38 lines · Michel Dänzer
Quoted 37 lines · Stylon Wang
Quoted 23 lines
[Why]
In GNOMESettings->Displaythe switching from mirror mode to single display occasionally causeswait_for_completion_interruptible_timeout()to return-ERESTARTSYSand fails atomic check.[How]
Replace the call withwait_for_completion_timeout()since the waiting forhw_doneandflip_donecompletion doesn't need to worry about interruption from signal.Signed-off-by Stylon Wang <[email protected]>---
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0
-0@@ -9844,10 +9844,10 @@ static int do_aquire_global_lock(structdrm_device *dev, * Make sure all pending HW programming completed anddrivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int do_aquire_global_lock(struct · line 9853
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2
-2* page flips done */ - ret =wait_for_completion_interruptible_timeout (&commit->hw_done,10 *HZ ); + ret = wait_for_completion_timeout(&commit->hw_done, 10*HZ); if (ret > 0) - ret = wait_for_completion_interruptible_timeout( + ret = wait_for_completion_timeout( &commit->flip_done, 10*HZ); if (ret == 0)The *_interruptible_* variant is needed so that the display manager process can be killed while it's waiting here, which could take up to 10 seconds (per the timeout).
Quoted 7 lines
Quoted 3 lines
What's the problem with
-ERESTARTSYS? Either the ioctl should be restarted automatically, or if it bounces back to user space, that needs to be able to retry the ioctl while it returns -1 and errno == EINTR. drmIoctl handles this transparently.Thanks for the insight Michel!
If it's just an error in the log without a functional issue then maybe we should downgrade it to a debug statement in the case where it returns
-ERESTARTSYS.
Yeah, that is a very common problem. -ERESTARTSYS should never be logged, not even on debug level, since it is part of normal operation.
Regards,
Christian.
Quoted 6 lines
If this is a functional issue (DRM not automatically retrying the commit?) then maybe we should take a deeper look into the IOCTL itself.
Regards,
Nicholas Kazlauskas
[AMD Official Use Only]
Hi Michel,
The problem with -ERESTARTSYS is the same half-baked atomic state with modifications we made in the interrupted atomic check, is reused in the next retry and fails the atomic check. What we expect in the next retry is with the original atomic state. I am going to dig deeper and see if at DRM side we can go back to use to the original atomic state in the retry.
Regards
Stylon Wang
MTS Software Development Eng. | AMD
Display Solution Team
O +(886) 2-3789-3667 ext. 23667 C +(886) 921-897-142
----------------------------------------------------------------------------------------------------------------------------------
6F, 3, YuanCyu St (NanKang Software Park) Taipei, Taiwan
Facebook<https://www.facebook.com/AMD> | Twitter<https://twitter.com/AMD> | amd.com<http://www.amd.com/>
________________________________
From: Michel Dänzer <[email protected]>
Sent: October 26, 2021 11:51 PM
To: Wang, Chao-kai (Stylon) <[email protected]>; [email protected] <[email protected]>
Cc: Wentland, Harry <[email protected]>; Siqueira, Rodrigo <[email protected]>; [email protected] <[email protected]>; Kazlauskas, Nicholas <[email protected]>
Subject: Re: [PATCH] drm/amd/display: Fix error handling on waiting for completion
Quoted 23 lines · Stylon Wang
[Why]
In GNOMESettings->Displaythe switching from mirror mode to single display occasionally causeswait_for_completion_interruptible_timeout()to return-ERESTARTSYSand fails atomic check.[How]
Replace the call withwait_for_completion_timeout()since the waiting forhw_doneandflip_donecompletion doesn't need to worry about interruption from signal.Signed-off-by Stylon Wang <[email protected]>--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0
-0@@ -9844,10 +9844,10 @@ static int do_aquire_global_lock(struct drm_device *dev,* Make sure all pending HW programming completed and * page flips done
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int do_aquire_global_lock(struct drm_device *dev, · line 9853
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2
-2*/ - ret =wait_for_completion_interruptible_timeout (&commit->hw_done,10 *HZ ); + ret =wait_for_completion_timeout (&commit->hw_done,10 *HZ );if (ret >0 ) - ret =wait_for_completion_interruptible_timeout ( + ret =wait_for_completion_timeout ( &commit->flip_done,10 *HZ );if (ret ==0 )
The *_interruptible_* variant is needed so that the display manager process can be killed while it's waiting here, which could take up to 10 seconds (per the timeout).
What's the problem with -ERESTARTSYS? Either the ioctl should be restarted automatically, or if it bounces back to user space, that needs to be able to retry the ioctl while it returns -1 and errno == EINTR. drmIoctl handles this transparently.
--
Earthling Michel Dänzer | https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fredhat.com%2F&data=04%7C01%7Cstylon.wang%40amd.com%7C251ee7aba8574015713a08d998986a5f%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637708602663589383%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=LcSFyj%2FJ9VYbNfxJQRjpiRAcurbzTbD5yUVysxzpmXs%3D&reserved=0
Libre software enthusiast | Mesa and Xwayland developer
[ Adding dri-devel ]
Quoted 2 lines · Chao-kai (Stylon)
The problem with
-ERESTARTSYSis the same half-baked atomic state with modifications we made in the interrupted atomic check, is reused in the next retry and fails the atomic check. What we expect in the next retry is with the original atomic state. I am going to dig deeper and see if at DRM side we can go back to use to the original atomic state in the retry.
I suspect either DC/DM needs to be able to handle the modified state on retry, or it needs to restore the original state before it returns -ERESTARTSYS.
Signature · 2 lines
Earthling Michel Dänzer | https://redhat.com Libre software enthusiast | Mesa and Xwayland developer