Skip to contentSkip to conversation

qxl: fix null-pointer crash during suspend

PATCH In review Peter Wu 4 participants 7 messages Sep 4, 2018 – Oct 2, 2018

Subsystems (4)
lore
Share & tools
lore

Peter Wu

author
#0 lore raw

PATCH 1/1 qxl: fix null-pointer crash during suspend

"crtc->helper_private" is not initialized by the QXL driver and thus the "crtc_funcs->disable" call would crash (resulting in suspend failure). Fix this by converting the suspend/resume functions to use the drm_mode_config_helper_* helpers.

Tested system sleep with QEMU 3.0 using "echo mem > /sys/power/state". During suspend the following message is visible from QEMU:

spice/server/display-channel.c:2425:display_channel_validate_surface: canvas address is 0x7fd05da68308 for 0 (and is NULL) spice/server/display-channel.c:2426:display_channel_validate_surface: failed on 0

This seems to be triggered by QXL_IO_NOTIFY_CMD after QXL_IO_DESTROY_PRIMARY_ASYNC, but aside from the warning things still seem to work (tested with both the GTK and -spice options).

---
Hi,

I found this issue while trying to suspend a VM that uses QXL. In order to see the stack trace over serial, boot with no_console_suspend. Searching for "qxl_drm_freeze" showed one recent report from Alan:
https://lkml.kernel.org/r/[email protected]

Kind regards,
Peter

---
 drivers/gpu/drm/qxl/qxl_drv.c | 26 +++++---------------------
 1 file changed, 5 insertions(+), 21 deletions(-)
drivers/gpu/drm/qxl/qxl_drv.c +5 -21
index 2445e75cf7ea..d00f45eed03c 100644
@@ -136,20 +136,11 @@ static int qxl_drm_freeze(struct drm_device *dev)
 {
 	struct pci_dev *pdev = dev->pdev;
 	struct qxl_device *qdev = dev->dev_private;
-	struct drm_crtc *crtc;
-
-	drm_kms_helper_poll_disable(dev);
-
-	console_lock();
-	qxl_fbdev_set_suspend(qdev, 1);
-	console_unlock();
+	int ret;
 
-	/* unpin the front buffers */
-	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
-		const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
-		if (crtc->enabled)
-			(*crtc_funcs->disable)(crtc);
-	}
+	ret = drm_mode_config_helper_suspend(dev);
+	if (ret)
+		return ret;
 
 	qxl_destroy_monitors_object(qdev);
 	qxl_surf_evict(qdev);
@@ -175,14 +166,7 @@ static int qxl_drm_resume(struct drm_device *dev, bool thaw)
 	}
 
 	qxl_create_monitors_object(qdev);
-	drm_helper_resume_force_mode(dev);
-
-	console_lock();
-	qxl_fbdev_set_suspend(qdev, 0);
-	console_unlock();
-
-	drm_kms_helper_poll_enable(dev);
-	return 0;
+	return drm_mode_config_helper_resume(dev);
 }
 
 static int qxl_pm_suspend(struct device *dev)
Signature · 6 lines
2.18.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 9 lines · Peter Wu

"crtc->helper_private" is not initialized by the QXL driver and thus the "crtc_funcs->disable" call would crash (resulting in suspend failure). Fix this by converting the suspend/resume functions to use the drm_mode_config_helper_* helpers.

Tested system sleep with QEMU 3.0 using "echo mem > /sys/power/state". During suspend the following message is visible from QEMU:

Quoted 8 lines

spice/server/display-channel.c:2425:display_channel_validate_surface: canvas address is 0x7fd05da68308 for 0 (and is NULL) spice/server/display-channel.c:2426:display_channel_validate_surface: failed on 0

This seems to be triggered by QXL_IO_NOTIFY_CMD after QXL_IO_DESTROY_PRIMARY_ASYNC, but aside from the warning things still seem to work (tested with both the GTK and -spice options).

Is this a new issue or something that was introduced a long time ago? In the latter case, please consider adding a "Cc:
<[email protected]>" tag to this patch.

Thanks,

Fubo.

author
#2 lore raw
Quoted 17 lines · Fubo Chen
Quoted 16 lines · Peter Wu

"crtc->helper_private" is not initialized by the QXL driver and thus the "crtc_funcs->disable" call would crash (resulting in suspend failure). Fix this by converting the suspend/resume functions to use the drm_mode_config_helper_* helpers.

Tested system sleep with QEMU 3.0 using "echo mem > /sys/power/state". During suspend the following message is visible from QEMU:

spice/server/display-channel.c:2425:display_channel_validate_surface: canvas address is 0x7fd05da68308 for 0 (and is NULL) spice/server/display-channel.c:2426:display_channel_validate_surface: failed on 0

This seems to be triggered by QXL_IO_NOTIFY_CMD after QXL_IO_DESTROY_PRIMARY_ASYNC, but aside from the warning things still seem to work (tested with both the GTK and -spice options).

Quoted 5 lines
Quoted 1 line

Is this a new issue or something that was introduced a long time ago? In the latter case, please consider adding a "Cc:
<[email protected]>" tag to this patch.

I am not sure exactly when the issue was introduced, but the original code was added in v3.10-rc7-800-gd84300bf7934 while the new drm_mode_config_helper_suspend API was added in 4.16.

The intended call chain to initialize the private object seems to be:
drm_crtc_helper_add
<- qdev_crtc_init
<- qxl_modeset_init
<- qxl_pci_probe

If any error occurs along the callchain, then the helper_private pointer will remain NULL. Or if the crtc is obtained in a different way (not sure how).

Not sure if it is worth backporting, suspend/resume does not seem an important use case for VMs using QXL and the fix was not validated for older kernels.

Signature · 3 lines
Kind regards,
Peter Wu
https://lekensteyn.nl
Reviewed-by on v1 1/1
#3 lore raw
In reply to Peter Wu
Quoted 1 line · Peter Wu

"crtc->helper_private" is not initialized by the QXL driver and thus the

This is still initialized, it's the ->disable that goes boom. At least the call to drm_crtc_helper_add is still there. The ->disable was removed in:

commit 64581714b58bc3e16ede8dc37a025c3aa0e0eef1

Author: Laurent Pinchart <[email protected]>
Date:   Fri Jun 30 12:36:45 2017 +0300

drm: Convert atomic drivers from CRTC .disable() to .atomic_disable()

Fixes 64581714b58b ("drm: Convert atomic drivers from CRTC .disable() to .atomic_disable()")
Cc <[email protected]> # v4.14+

I'll let Gerd pick this one up, after some testing. Also adding Laurent. -Daniel

Quoted 81 lines

"crtc_funcs->disable" call would crash (resulting in suspend failure). Fix this by converting the suspend/resume functions to use the drm_mode_config_helper_* helpers.

Tested system sleep with QEMU 3.0 using "echo mem > /sys/power/state". During suspend the following message is visible from QEMU:

spice/server/display-channel.c:2425:display_channel_validate_surface: canvas address is 0x7fd05da68308 for 0 (and is NULL) spice/server/display-channel.c:2426:display_channel_validate_surface: failed on 0

This seems to be triggered by QXL_IO_NOTIFY_CMD after QXL_IO_DESTROY_PRIMARY_ASYNC, but aside from the warning things still seem to work (tested with both the GTK and -spice options).

---
Hi,

I found this issue while trying to suspend a VM that uses QXL. In order to see the stack trace over serial, boot with no_console_suspend. Searching for "qxl_drm_freeze" showed one recent report from Alan:
https://lkml.kernel.org/r/[email protected]

Kind regards,
Peter

---
 drivers/gpu/drm/qxl/qxl_drv.c | 26 +++++---------------------
 1 file changed, 5 insertions(+), 21 deletions(-)
drivers/gpu/drm/qxl/qxl_drv.c +5 -21
index 2445e75cf7ea..d00f45eed03c 100644
@@ -136,20 +136,11 @@ static int qxl_drm_freeze(struct drm_device *dev)
 {
 	struct pci_dev *pdev = dev->pdev;
 	struct qxl_device *qdev = dev->dev_private;
-	struct drm_crtc *crtc;
-
-	drm_kms_helper_poll_disable(dev);
-
-	console_lock();
-	qxl_fbdev_set_suspend(qdev, 1);
-	console_unlock();
+	int ret;
 
-	/* unpin the front buffers */
-	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
-		const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
-		if (crtc->enabled)
-			(*crtc_funcs->disable)(crtc);
-	}
+	ret = drm_mode_config_helper_suspend(dev);
+	if (ret)
+		return ret;
 
 	qxl_destroy_monitors_object(qdev);
 	qxl_surf_evict(qdev);
@@ -175,14 +166,7 @@ static int qxl_drm_resume(struct drm_device *dev, bool thaw)
 	}
 
 	qxl_create_monitors_object(qdev);
-	drm_helper_resume_force_mode(dev);
-
-	console_lock();
-	qxl_fbdev_set_suspend(qdev, 0);
-	console_unlock();
-
-	drm_kms_helper_poll_enable(dev);
-	return 0;
+	return drm_mode_config_helper_resume(dev);
 }
 
 static int qxl_pm_suspend(struct device *dev)
Signature · 6 lines
2.18.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#4 lore raw

Hello,

Quoted 10 lines · On Tuesday, 2 October 2018 11:14:22 EEST Daniel Vetter wrote:
Quoted 1 line · Peter Wu

"crtc->helper_private" is not initialized by the QXL driver and thus the

This is still initialized, it's the ->disable that goes boom. At least the call to drm_crtc_helper_add is still there. The ->disable was removed in:

commit 64581714b58bc3e16ede8dc37a025c3aa0e0eef1

Author: Laurent Pinchart <[email protected]>
Date:   Fri Jun 30 12:36:45 2017 +0300
Quoted 7 lines

drm: Convert atomic drivers from CRTC .disable() to .atomic_disable()

Fixes 64581714b58b ("drm: Convert atomic drivers from CRTC .disable() to

.atomic_disable()") Cc: <[email protected]> # v4.14+

I'll let Gerd pick this one up, after some testing. Also adding Laurent.

Sorry for breaking it :-( Please let me know if there's something I can do to help.

Quoted 84 lines
Quoted 44 lines

"crtc_funcs->disable" call would crash (resulting in suspend failure). Fix this by converting the suspend/resume functions to use the drm_mode_config_helper_* helpers.

Tested system sleep with QEMU 3.0 using "echo mem > /sys/power/state".

During suspend the following message is visible from QEMU:
spice/server/display-channel.c:2425:display_channel_validate_surface:
canvas address is 0x7fd05da68308 for 0 (and is NULL) spice/server/display-channel.c:2426:display_channel_validate_surface:
failed on 0>
This seems to be triggered by QXL_IO_NOTIFY_CMD after QXL_IO_DESTROY_PRIMARY_ASYNC, but aside from the warning things still seem to work (tested with both the GTK and -spice options).

---
Hi,

I found this issue while trying to suspend a VM that uses QXL. In order to see the stack trace over serial, boot with no_console_suspend. Searching for "qxl_drm_freeze" showed one recent report from Alan:
https://lkml.kernel.org/r/[email protected]

Kind regards,
Peter
---

 drivers/gpu/drm/qxl/qxl_drv.c | 26 +++++---------------------
 1 file changed, 5 insertions(+), 21 deletions(-)
drivers/gpu/drm/qxl/qxl_drv.c +0 -2
index 2445e75cf7ea..d00f45eed03c 100644
@@ -136,20 +136,11 @@ static int qxl_drm_freeze(struct drm_device *dev)
 
 {
 
 	struct pci_dev *pdev = dev->pdev;
 	struct qxl_device *qdev = dev->dev_private;
 
-	struct drm_crtc *crtc;
-

drivers/gpu/drm/qxl/qxl_drv.c static int qxl_drm_freeze(struct drm_device *dev) · line 152

Quoted 10 lines
drivers/gpu/drm/qxl/qxl_drv.c +1 -8
-	drm_kms_helper_poll_disable(dev);
-
-	console_lock();
-	qxl_fbdev_set_suspend(qdev, 1);
-	console_unlock();
+	int ret;
 
-	/* unpin the front buffers */
-	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
-		const struct drm_crtc_helper_funcs *crtc_funcs = crtc-

helper_private;

Quoted 29 lines
drivers/gpu/drm/qxl/qxl_drv.c +3 -3
-		if (crtc->enabled)
-			(*crtc_funcs->disable)(crtc);
-	}
+	ret = drm_mode_config_helper_suspend(dev);
+	if (ret)
+		return ret;
drivers/gpu/drm/qxl/qxl_drv.c +0 -0
 	qxl_destroy_monitors_object(qdev);
 	qxl_surf_evict(qdev);
@@ -175,14 +166,7 @@ static int qxl_drm_resume(struct drm_device *dev,

bool thaw)>

drivers/gpu/drm/qxl/qxl_drv.c +1 -8
 	}
 
 	qxl_create_monitors_object(qdev);
 
-	drm_helper_resume_force_mode(dev);
-
-	console_lock();
-	qxl_fbdev_set_suspend(qdev, 0);
-	console_unlock();
-
-	drm_kms_helper_poll_enable(dev);
-	return 0;
+	return drm_mode_config_helper_resume(dev);
 
 }
 
 static int qxl_pm_suspend(struct device *dev)
Signature · 10 lines
Regards,

Laurent Pinchart



_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw
In reply to Daniel Vetter

Hello,

Quoted 10 lines · On Tuesday, 2 October 2018 11:14:22 EEST Daniel Vetter wrote:
Quoted 1 line · Peter Wu

"crtc->helper_private" is not initialized by the QXL driver and thus the

This is still initialized, it's the ->disable that goes boom. At least the call to drm_crtc_helper_add is still there. The ->disable was removed in:

commit 64581714b58bc3e16ede8dc37a025c3aa0e0eef1

Author: Laurent Pinchart <[email protected]>
Date:   Fri Jun 30 12:36:45 2017 +0300
Quoted 7 lines

drm: Convert atomic drivers from CRTC .disable() to .atomic_disable()

Fixes 64581714b58b ("drm: Convert atomic drivers from CRTC .disable() to

.atomic_disable()") Cc: <[email protected]> # v4.14+

I'll let Gerd pick this one up, after some testing. Also adding Laurent.

Sorry for breaking it :-( Please let me know if there's something I can do to help.

Quoted 84 lines
Quoted 44 lines

"crtc_funcs->disable" call would crash (resulting in suspend failure). Fix this by converting the suspend/resume functions to use the drm_mode_config_helper_* helpers.

Tested system sleep with QEMU 3.0 using "echo mem > /sys/power/state".

During suspend the following message is visible from QEMU:
spice/server/display-channel.c:2425:display_channel_validate_surface:
canvas address is 0x7fd05da68308 for 0 (and is NULL) spice/server/display-channel.c:2426:display_channel_validate_surface:
failed on 0>
This seems to be triggered by QXL_IO_NOTIFY_CMD after QXL_IO_DESTROY_PRIMARY_ASYNC, but aside from the warning things still seem to work (tested with both the GTK and -spice options).

---
Hi,

I found this issue while trying to suspend a VM that uses QXL. In order to see the stack trace over serial, boot with no_console_suspend. Searching for "qxl_drm_freeze" showed one recent report from Alan:
https://lkml.kernel.org/r/[email protected]

Kind regards,
Peter
---

 drivers/gpu/drm/qxl/qxl_drv.c | 26 +++++---------------------
 1 file changed, 5 insertions(+), 21 deletions(-)
drivers/gpu/drm/qxl/qxl_drv.c +0 -2
index 2445e75cf7ea..d00f45eed03c 100644
@@ -136,20 +136,11 @@ static int qxl_drm_freeze(struct drm_device *dev)
 
 {
 
 	struct pci_dev *pdev = dev->pdev;
 	struct qxl_device *qdev = dev->dev_private;
 
-	struct drm_crtc *crtc;
-

drivers/gpu/drm/qxl/qxl_drv.c static int qxl_drm_freeze(struct drm_device *dev) · line 152

Quoted 10 lines
drivers/gpu/drm/qxl/qxl_drv.c +1 -8
-	drm_kms_helper_poll_disable(dev);
-
-	console_lock();
-	qxl_fbdev_set_suspend(qdev, 1);
-	console_unlock();
+	int ret;
 
-	/* unpin the front buffers */
-	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
-		const struct drm_crtc_helper_funcs *crtc_funcs = crtc-

helper_private;

Quoted 29 lines
drivers/gpu/drm/qxl/qxl_drv.c +3 -3
-		if (crtc->enabled)
-			(*crtc_funcs->disable)(crtc);
-	}
+	ret = drm_mode_config_helper_suspend(dev);
+	if (ret)
+		return ret;
drivers/gpu/drm/qxl/qxl_drv.c +0 -0
 	qxl_destroy_monitors_object(qdev);
 	qxl_surf_evict(qdev);
@@ -175,14 +166,7 @@ static int qxl_drm_resume(struct drm_device *dev,

bool thaw)>

drivers/gpu/drm/qxl/qxl_drv.c +1 -8
 	}
 
 	qxl_create_monitors_object(qdev);
 
-	drm_helper_resume_force_mode(dev);
-
-	console_lock();
-	qxl_fbdev_set_suspend(qdev, 0);
-	console_unlock();
-
-	drm_kms_helper_poll_enable(dev);
-	return 0;
+	return drm_mode_config_helper_resume(dev);
 
 }
 
 static int qxl_pm_suspend(struct device *dev)
Signature · 3 lines
Regards,

Laurent Pinchart
Reviewed-by on v1 1/1
#6 lore raw
In reply to Peter Wu
Quoted 1 line · Peter Wu

"crtc->helper_private" is not initialized by the QXL driver and thus the

This is still initialized, it's the ->disable that goes boom. At least the call to drm_crtc_helper_add is still there. The ->disable was removed in:

commit 64581714b58bc3e16ede8dc37a025c3aa0e0eef1

Author: Laurent Pinchart <[email protected]>
Date:   Fri Jun 30 12:36:45 2017 +0300

drm: Convert atomic drivers from CRTC .disable() to .atomic_disable()

Fixes 64581714b58b ("drm: Convert atomic drivers from CRTC .disable() to .atomic_disable()")
Cc <[email protected]> # v4.14+

I'll let Gerd pick this one up, after some testing. Also adding Laurent. -Daniel

Quoted 81 lines

"crtc_funcs->disable" call would crash (resulting in suspend failure). Fix this by converting the suspend/resume functions to use the drm_mode_config_helper_* helpers.

Tested system sleep with QEMU 3.0 using "echo mem > /sys/power/state". During suspend the following message is visible from QEMU:

spice/server/display-channel.c:2425:display_channel_validate_surface: canvas address is 0x7fd05da68308 for 0 (and is NULL) spice/server/display-channel.c:2426:display_channel_validate_surface: failed on 0

This seems to be triggered by QXL_IO_NOTIFY_CMD after QXL_IO_DESTROY_PRIMARY_ASYNC, but aside from the warning things still seem to work (tested with both the GTK and -spice options).

---
Hi,

I found this issue while trying to suspend a VM that uses QXL. In order to see the stack trace over serial, boot with no_console_suspend. Searching for "qxl_drm_freeze" showed one recent report from Alan:
https://lkml.kernel.org/r/[email protected]

Kind regards,
Peter

---
 drivers/gpu/drm/qxl/qxl_drv.c | 26 +++++---------------------
 1 file changed, 5 insertions(+), 21 deletions(-)
drivers/gpu/drm/qxl/qxl_drv.c +5 -21
index 2445e75cf7ea..d00f45eed03c 100644
@@ -136,20 +136,11 @@ static int qxl_drm_freeze(struct drm_device *dev)
 {
 	struct pci_dev *pdev = dev->pdev;
 	struct qxl_device *qdev = dev->dev_private;
-	struct drm_crtc *crtc;
-
-	drm_kms_helper_poll_disable(dev);
-
-	console_lock();
-	qxl_fbdev_set_suspend(qdev, 1);
-	console_unlock();
+	int ret;
 
-	/* unpin the front buffers */
-	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
-		const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
-		if (crtc->enabled)
-			(*crtc_funcs->disable)(crtc);
-	}
+	ret = drm_mode_config_helper_suspend(dev);
+	if (ret)
+		return ret;
 
 	qxl_destroy_monitors_object(qdev);
 	qxl_surf_evict(qdev);
@@ -175,14 +166,7 @@ static int qxl_drm_resume(struct drm_device *dev, bool thaw)
 	}
 
 	qxl_create_monitors_object(qdev);
-	drm_helper_resume_force_mode(dev);
-
-	console_lock();
-	qxl_fbdev_set_suspend(qdev, 0);
-	console_unlock();
-
-	drm_kms_helper_poll_enable(dev);
-	return 0;
+	return drm_mode_config_helper_resume(dev);
 }
 
 static int qxl_pm_suspend(struct device *dev)
Signature · 6 lines
2.18.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch