drm/nouveau: Fix runtime suspend on R570
Subsystems (4)
Lyude Paul
maintainercover drm/nouveau: Fix runtime suspend on R570
Turns out our last attempt at fixing suspend/resume was not entirely correct, only partially correct. This reverts the partial fix, while leaving the piping of suspend/runtime suspend/etc. that we did in preparation for this originally, since I have a strong feeling it will come in use again in the future.
Lyude Paul (2):
Revert "nouveau/gsp: fix suspend/resume regression on r570 firmware" drm/nouveau/gsp/r570: Never enter Gcoff state
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/fbsr.c | 2 +- drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c | 2 +- drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/fbsr.c | 8 ++++---- drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/rm.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-)
Signature · 1 line
2.54.0
Lyude Paul
maintainerPATCH 1/2 Revert "nouveau/gsp: fix suspend/resume regression on r570 firmware"
This reverts commit 8302d0afeaec0bc57d951dd085e0cffe997d4d18.
It turns out this looked like the right fix on some systems, but it's not - as this causes runtime PM to actually fail on many a laptop.
--- drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/fbsr.c | 2 +- drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c | 2 +- drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/fbsr.c | 8 ++++---- drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/rm.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-)
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/fbsr.c +1 -1
@@ -208,7 +208,7 @@ r535_fbsr_resume(struct nvkm_gsp *gsp) }static int -r535_fbsr_suspend (struct nvkm_gsp *gsp,bool runtime) +r535_fbsr_suspend (struct nvkm_gsp *gsp) {struct nvkm_subdev *subdev = &gsp->subdev;struct nvkm_device *device = subdev->device;
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c +1 -1
@@ -1749,7 +1749,7 @@ r535_gsp_fini(struct nvkm_gsp *gsp, enum nvkm_suspend_state suspend) sr->sysmemAddrOfSuspendResumeData = gsp->sr.radix3.lvl0.addr; sr->sizeOfSuspendResumeData = len; - ret = rm->api->fbsr->suspend (gsp, suspend ==NVKM_RUNTIME_SUSPEND ); + ret = rm->api->fbsr->suspend (gsp);if (ret) {nvkm_gsp_mem_dtor (&gsp->sr.meta);nvkm_gsp_radix3_dtor (gsp, &gsp->sr.radix3);
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/fbsr.c +4 -4
@@ -62,7 +62,7 @@ r570_fbsr_resume(struct nvkm_gsp *gsp) }static int -r570_fbsr_init (struct nvkm_gsp *gsp,struct sg_table *sgt,u64 size,bool runtime) +r570_fbsr_init (struct nvkm_gsp *gsp,struct sg_table *sgt,u64 size) {NV2080_CTRL_INTERNAL_FBSR_INIT_PARAMS *ctrl;struct nvkm_gsp_object memlist;
@@ -81,7 +81,7 @@ r570_fbsr_init(struct nvkm_gsp *gsp, struct sg_table *sgt, u64 size, bool runtim ctrl->hClient = gsp->internal.client.object.handle; ctrl->hSysMem = memlist.handle; ctrl->sysmemAddrOfSuspendResumeData = gsp->sr.meta.addr; - ctrl->bEnteringGcoffState = runtime ?1 :0 ; + ctrl->bEnteringGcoffState =1 ; ret =nvkm_gsp_rm_ctrl_wr (&gsp->internal.device.subdevice, ctrl);if (ret)
@@ -92,7 +92,7 @@ r570_fbsr_init(struct nvkm_gsp *gsp, struct sg_table *sgt, u64 size, bool runtim }static int -r570_fbsr_suspend (struct nvkm_gsp *gsp,bool runtime) +r570_fbsr_suspend (struct nvkm_gsp *gsp) {struct nvkm_subdev *subdev = &gsp->subdev;struct nvkm_device *device = subdev->device;
@@ -133,7 +133,7 @@ r570_fbsr_suspend(struct nvkm_gsp *gsp, bool runtime)return ret;/* Initialise FBSR on RM. */ - ret =r570_fbsr_init (gsp, &gsp->sr.fbsr, size, runtime); + ret =r570_fbsr_init (gsp, &gsp->sr.fbsr, size);if (ret) {nvkm_gsp_sg_free (device, &gsp->sr.fbsr);return ret;
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/rm.h +1 -1
@@ -78,7 +78,7 @@ struct nvkm_rm_api { } *device;const struct nvkm_rm_api_fbsr { -int (*suspend)(struct nvkm_gsp *,bool runtime); +int (*suspend)(struct nvkm_gsp *);void (*resume)(struct nvkm_gsp *); } *fbsr;
Signature · 1 line
2.54.0
Lyude Paul
maintainerPATCH 2/2 drm/nouveau/gsp/r570: Never enter Gcoff state
In reply to Lyude PaulIt turns out that the only reason our previous fixes looked like they worked for this was because we would occasionally set the Gcoff state to 0 in the normal S3 path, which fixed suspend/resume on desktops - but not on machines using runtime suspend.
The proper fix is to just never set this flag. Our current guess for the reasoning behind this is that Gcoff likely coincides with GC6, and not literally power off.
--- drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/fbsr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/fbsr.c +1 -1
@@ -81,7 +81,7 @@ r570_fbsr_init(struct nvkm_gsp *gsp, struct sg_table *sgt, u64 size) ctrl->hClient = gsp->internal.client.object.handle; ctrl->hSysMem = memlist.handle; ctrl->sysmemAddrOfSuspendResumeData = gsp->sr.meta.addr; - ctrl->bEnteringGcoffState =1 ; + ctrl->bEnteringGcoffState =0 ; ret =nvkm_gsp_rm_ctrl_wr (&gsp->internal.device.subdevice, ctrl);if (ret)
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 2/2] drm/nouveau/gsp/r570: Never enter Gcoff state
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing rollback of hardware state in suspend paths when operations fail, leaving the device hung. --
commit ed5c98b04aafc61a13ebb42fe49a1f15121c1b4d
Author: Lyude Paul <[email protected]>
drm/nouveau/gsp/r570: Never enter Gcoff state
It turns out that the only reason our previous fixes looked like they worked for this was because we would occasionally set the Gcoff state to 0 in the normal S3 path, which fixed suspend/resume on desktops - but not on machines using runtime suspend.
The proper fix is to just never set this flag. Our current guess for the reasoning behind this is that Gcoff likely coincides with GC6, and not literally power off.
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/fbsr.c r570_fbsr_init(struct nvkm_gsp *gsp, struct sg_table *sgt, u64 size) · line 87
Quoted 13 lines
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/fbsr.c +1
-1@@ -81,7 +81,7 @@ r570_fbsr_init(struct nvkm_gsp *gsp, struct sg_table *sgt, u64 size) ctrl->hClient = gsp->internal.client.object.handle; ctrl->hSysMem = memlist.handle; ctrl->sysmemAddrOfSuspendResumeData = gsp->sr.meta.addr; - ctrl->bEnteringGcoffState =1 ; + ctrl->bEnteringGcoffState =0 ; ret =nvkm_gsp_rm_ctrl_wr (&gsp->internal.device.subdevice, ctrl);if (ret)
[Severity: High]
This is a pre-existing issue, but I have a question about the suspend path's error handling.
If nvkm_gsp_rm_ctrl_wr() fails here, r570_fbsr_init() returns an error back to r570_fbsr_suspend():
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/fbsr.c:r570_fbsr_suspend() {
...
r570_fbsr_suspend_channels(gsp, true);
...
device->bar->bar2 = false;
...
ret = r570_fbsr_init(gsp, &gsp->sr.fbsr, size);
if (ret) {
nvkm_gsp_sg_free(device, &gsp->sr.fbsr);
return ret;
}
}The same error path exists earlier in r570_fbsr_suspend() if nvkm_instobj_save() or nvkm_gsp_sg() fail.
Since the PM core doesn't call the resume callback for devices that fail to suspend, does this leave the GPU hung with suspended channels and BAR2 disabled?
Would it make sense to restore the channel and BAR state on error paths in r570_fbsr_suspend() before returning?
Quoted 5 lines
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/fbsr.c +0
-0return ret;nvkm_gsp_rm_free (&memlist);return 0 ; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH 1/2] Revert "nouveau/gsp: fix suspend/resume regression on r570 firmware"
In reply to Lyude PaulThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Hardware channels and BAR2 are left permanently disabled when r570_fbsr_suspend fails midway. --
commit ba836a35e2d15cfdb3c33dd77c467b89aed9e52a
Author: Lyude Paul <[email protected]>
Revert "nouveau/gsp: fix suspend/resume regression on r570 firmware"
This reverts commit 8302d0afeaec0bc57d951dd085e0cffe997d4d18, which was intended to fix a suspend/resume regression on r570 firmware but instead caused runtime PM to fail on many laptops.
Quoted 3 lines
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/fbsr.c +0
-0
[ ... ]
Quoted 9 lines
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/fbsr.c +1
-1@@ -92,7 +92,7 @@ r570_fbsr_init(struct nvkm_gsp *gsp, struct sg_table *sgt, u64 size, bool runtim }static int -r570_fbsr_suspend (struct nvkm_gsp *gsp,bool runtime) +r570_fbsr_suspend (struct nvkm_gsp *gsp) {struct nvkm_subdev *subdev = &gsp->subdev;struct nvkm_device *device = subdev->device;
[ ... ]
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/fbsr.c r570_fbsr_suspend(struct nvkm_gsp *gsp, bool runtime) · line 139
Quoted 9 lines
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/fbsr.c +1
-1@@ -133,7 +133,7 @@ r570_fbsr_suspend(struct nvkm_gsp *gsp, bool runtime)return ret;/* Initialise FBSR on RM. */ - ret =r570_fbsr_init (gsp, &gsp->sr.fbsr, size, runtime); + ret =r570_fbsr_init (gsp, &gsp->sr.fbsr, size);if (ret) {nvkm_gsp_sg_free (device, &gsp->sr.fbsr);return ret;
[Severity: High]
This is a pre-existing issue, but does this error path leave the GPU unusable if it fails?
During the suspend sequence, r570_fbsr_suspend() disables channel scheduling and BAR2 early on. If a subsequent operation like r570_fbsr_init() (or nvkm_gsp_sg() earlier) fails, it returns an error here without restoring the hardware state.
Since the PM core will abort the suspend on error and skip the resume callback for this device, does this mean channels and BAR2 are never re-enabled, leaving the device in an unrecoverable state until reboot?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH 1/2] Revert "nouveau/gsp: fix suspend/resume regression on r570 firmware"
In reply to Lyude PaulQuoted 8 lines · Lyude Paul
This reverts commit
8302d0afeaec0bc57d951dd085e0cffe997d4d18.It turns out this looked like the right fix on some systems, but it's not - as this causes runtime PM to actually fail on many a laptop.
Signed-off-by Lyude Paul <[email protected]>Fixes 8302d0afeaec ("nouveau/gsp: fix suspend/resume regression on r570 firmware")
Quoted 10 lines
Cc <[email protected]>Cc Lyude Paul <[email protected]>Cc Dave Airlie <[email protected]>Cc Kees Cook <[email protected]>Cc Danilo Krummrich <[email protected]>Cc Timur Tabi <[email protected]>Cc Ben Skeggs <[email protected]>Cc Andy Shevchenko <[email protected]>Cc Mel Henning <[email protected]>Cc <[email protected]> # v6.19+
Two times Cc to stable.
I also recommend to move the rest of the Cc list below cutter '---' line.
Will be something like this:
---
Cc: ...
Cc: ...
---
This will reduce the unneeded noise in the commit messages.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 2/2] drm/nouveau/gsp/r570: Never enter Gcoff state
In reply to Lyude PaulQuoted 21 lines · Lyude Paul
It turns out that the only reason our previous fixes looked like they worked for this was because we would occasionally set the Gcoff state to 0 in the normal S3 path, which fixed suspend/resume on desktops - but not on machines using runtime suspend.
The proper fix is to just never set this flag. Our current guess for the reasoning behind this is that Gcoff likely coincides with GC6, and not literally power off.
Signed-off-by Lyude Paul <[email protected]>Fixes 8302d0afeaec ("nouveau/gsp: fix suspend/resume regression on r570 firmware")Cc <[email protected]>Cc Lyude Paul <[email protected]>Cc Dave Airlie <[email protected]>Cc Kees Cook <[email protected]>Cc Danilo Krummrich <[email protected]>Cc Timur Tabi <[email protected]>Cc Ben Skeggs <[email protected]>Cc Andy Shevchenko <[email protected]>Cc Mel Henning <[email protected]>Cc <[email protected]> # v6.19+
Quoted 3 lines
--- drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/fbsr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Same comment here.
Signature · 2 lines
With Best Regards, Andy Shevchenko