Skip to contentSkip to conversation

drm/vmwgfx: Add drm_panic support

PATCH Superseded Ian Forbes 5 participants 12 messages Oct 23, 2025 – Oct 2

Subsystems (3)
lore
Share & tools
lore

Ian Forbes

author
#0 lore raw

PATCH 1/1 drm/vmwgfx: Add drm_panic support

Sets up VRAM as the scanout buffer then switches to legacy mode.

---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c  | 33 ++++++++++++++++++++++++++++
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.h  |  5 +++++
 drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c |  2 ++
 3 files changed, 40 insertions(+)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +33 -0
index 54ea1b513950..4ff4ae041236 100644
@@ -20,6 +20,7 @@
 #include <drm/drm_rect.h>
 #include <drm/drm_sysfs.h>
 #include <drm/drm_edid.h>
+#include <drm/drm_panic.h>
 
 void vmw_du_init(struct vmw_display_unit *du)
 {
@@ -2022,3 +2023,35 @@ bool vmw_user_object_is_null(struct vmw_user_object *uo)
 {
 	return !uo->buffer && !uo->surface;
 }
+
+int
+vmw_get_scanout_buffer(struct drm_plane *plane, struct drm_scanout_buffer *sb)
+{
+	void  *vram;
+	struct vmw_private *vmw_priv = container_of(plane->dev, struct vmw_private, drm);
+
+	// Only call on the primary display
+	if (container_of(plane, struct vmw_display_unit, primary)->unit != 0)
+		return -EINVAL;
+
+	vram = memremap(vmw_priv->vram_start, vmw_priv->vram_size,
+			MEMREMAP_WB | MEMREMAP_DEC);
+	if (!vram)
+		return -ENOMEM;
+
+	sb->map[0].vaddr = vram;
+	sb->format = drm_format_info(DRM_FORMAT_RGB565);
+	sb->width  = vmw_priv->initial_width;
+	sb->height = vmw_priv->initial_height;
+	sb->pitch[0] = sb->width * 2;
+	return 0;
+}
+
+void vmw_panic_flush(struct drm_plane *plane)
+{
+	struct vmw_private *vmw_priv = container_of(plane->dev, struct vmw_private, drm);
+
+	vmw_kms_write_svga(vmw_priv,
+			   vmw_priv->initial_width, vmw_priv->initial_height,
+			   vmw_priv->initial_width * 2, 16, 16);
+}
drivers/gpu/drm/vmwgfx/vmwgfx_kms.h +5 -0
index 445471fe9be6..8e37561cd527 100644
@@ -500,6 +500,11 @@ int vmw_kms_stdu_readback(struct vmw_private *dev_priv,
 
 int vmw_du_helper_plane_update(struct vmw_du_update_plane *update);
 
+struct drm_scanout_buffer;
+
+int vmw_get_scanout_buffer(struct drm_plane *pl, struct drm_scanout_buffer *sb);
+void vmw_panic_flush(struct drm_plane *plane);
+
 /**
  * vmw_du_translate_to_crtc - Translate a rect from framebuffer to crtc
  * @state: Plane state.
drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c +2 -0
index 20aab725e53a..37cb742ba1d9 100644
@@ -1506,6 +1506,8 @@ drm_plane_helper_funcs vmw_stdu_primary_plane_helper_funcs = {
 	.atomic_update = vmw_stdu_primary_plane_atomic_update,
 	.prepare_fb = vmw_stdu_primary_plane_prepare_fb,
 	.cleanup_fb = vmw_stdu_primary_plane_cleanup_fb,
+	.get_scanout_buffer = vmw_get_scanout_buffer,
+	.panic_flush = vmw_panic_flush,
 };
 
 static const struct drm_crtc_helper_funcs vmw_stdu_crtc_helper_funcs = {
Signature · 1 line
2.51.0
Acked-by on v1 1/1
#1 lore raw
Quoted 1 line · Ian Forbes

Sets up VRAM as the scanout buffer then switches to legacy mode.

Thank you and Ryosuke for working on drm_panic support on vmwgfx. For the use of the drm_panic API, it looks good to me.

Quoted 86 lines
---
  drivers/gpu/drm/vmwgfx/vmwgfx_kms.c  | 33 ++++++++++++++++++++++++++++
  drivers/gpu/drm/vmwgfx/vmwgfx_kms.h  |  5 +++++
  drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c |  2 ++
  3 files changed, 40 insertions(+)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +33 -0
index 54ea1b513950..4ff4ae041236 100644
@@ -20,6 +20,7 @@
  #include <drm/drm_rect.h>
  #include <drm/drm_sysfs.h>
  #include <drm/drm_edid.h>
+#include <drm/drm_panic.h>
 
  void vmw_du_init(struct vmw_display_unit *du)
  {
@@ -2022,3 +2023,35 @@ bool vmw_user_object_is_null(struct vmw_user_object *uo)
  {
  	return !uo->buffer && !uo->surface;
  }
+
+int
+vmw_get_scanout_buffer(struct drm_plane *plane, struct drm_scanout_buffer *sb)
+{
+	void  *vram;
+	struct vmw_private *vmw_priv = container_of(plane->dev, struct vmw_private, drm);
+
+	// Only call on the primary display
+	if (container_of(plane, struct vmw_display_unit, primary)->unit != 0)
+		return -EINVAL;
+
+	vram = memremap(vmw_priv->vram_start, vmw_priv->vram_size,
+			MEMREMAP_WB | MEMREMAP_DEC);
+	if (!vram)
+		return -ENOMEM;
+
+	sb->map[0].vaddr = vram;
+	sb->format = drm_format_info(DRM_FORMAT_RGB565);
+	sb->width  = vmw_priv->initial_width;
+	sb->height = vmw_priv->initial_height;
+	sb->pitch[0] = sb->width * 2;
+	return 0;
+}
+
+void vmw_panic_flush(struct drm_plane *plane)
+{
+	struct vmw_private *vmw_priv = container_of(plane->dev, struct vmw_private, drm);
+
+	vmw_kms_write_svga(vmw_priv,
+			   vmw_priv->initial_width, vmw_priv->initial_height,
+			   vmw_priv->initial_width * 2, 16, 16);
+}
drivers/gpu/drm/vmwgfx/vmwgfx_kms.h +5 -0
index 445471fe9be6..8e37561cd527 100644
@@ -500,6 +500,11 @@ int vmw_kms_stdu_readback(struct vmw_private *dev_priv,
 
  int vmw_du_helper_plane_update(struct vmw_du_update_plane *update);
 
+struct drm_scanout_buffer;
+
+int vmw_get_scanout_buffer(struct drm_plane *pl, struct drm_scanout_buffer *sb);
+void vmw_panic_flush(struct drm_plane *plane);
+
  /**
   * vmw_du_translate_to_crtc - Translate a rect from framebuffer to crtc
   * @state: Plane state.
drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c +2 -0
index 20aab725e53a..37cb742ba1d9 100644
@@ -1506,6 +1506,8 @@ drm_plane_helper_funcs vmw_stdu_primary_plane_helper_funcs = {
  	.atomic_update = vmw_stdu_primary_plane_atomic_update,
  	.prepare_fb = vmw_stdu_primary_plane_prepare_fb,
  	.cleanup_fb = vmw_stdu_primary_plane_cleanup_fb,
+	.get_scanout_buffer = vmw_get_scanout_buffer,
+	.panic_flush = vmw_panic_flush,
  };
 
  static const struct drm_crtc_helper_funcs vmw_stdu_crtc_helper_funcs = {
#2 lore raw
Quoted 41 lines · Jocelyn Falempe
Quoted 1 line · Ian Forbes

Sets up VRAM as the scanout buffer then switches to legacy mode.

Thank you and Ryosuke for working on drm_panic support on vmwgfx. For the use of the drm_panic API, it looks good to me.

Quoted 34 lines
---
  drivers/gpu/drm/vmwgfx/vmwgfx_kms.c  | 33 ++++++++++++++++++++++++++++
  drivers/gpu/drm/vmwgfx/vmwgfx_kms.h  |  5 +++++
  drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c |  2 ++
  3 files changed, 40 insertions(+)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +11 -0
index 54ea1b513950..4ff4ae041236 100644
@@ -20,6 +20,7 @@
  #include <drm/drm_rect.h>
  #include <drm/drm_sysfs.h>
  #include <drm/drm_edid.h>
+#include <drm/drm_panic.h>
  void vmw_du_init(struct vmw_display_unit *du)
  {
@@ -2022,3 +2023,35 @@ bool vmw_user_object_is_null(struct vmw_user_object *uo)
  {
  	return !uo->buffer && !uo->surface;
  }
+
+int
+vmw_get_scanout_buffer(struct drm_plane *plane, struct drm_scanout_buffer *sb)
+{
+	void  *vram;
+	struct vmw_private *vmw_priv = container_of(plane->dev, struct vmw_private, drm);
+
+	// Only call on the primary display
+	if (container_of(plane, struct vmw_display_unit, primary)->unit != 0)
+		return -EINVAL;
Quoted 8 lines

drivers/gpu/drm/vmwgfx/vmwgfx_kms.c bool vmw_user_object_is_null(struct vmw_user_object *uo) · line 2043

Quoted 8 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +8 -0
+
+	vram = memremap(vmw_priv->vram_start, vmw_priv->vram_size,
+			MEMREMAP_WB | MEMREMAP_DEC);
+	if (!vram)
+		return -ENOMEM;
+
+	sb->map[0].vaddr = vram;
+	sb->format = drm_format_info(DRM_FORMAT_RGB565);

Let me confirm whether debugfs feature works correctly. As I mentioned in my original patch [1], modifying this format will allow to display the panic screen by debugfs only one time. In your environment, can you trigger panic screen by debugfs multiple times?

Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +5 -0
+	sb->width  = vmw_priv->initial_width;
+	sb->height = vmw_priv->initial_height;
+	sb->pitch[0] = sb->width * 2;
+	return 0;
+}
Quoted 8 lines

drivers/gpu/drm/vmwgfx/vmwgfx_kms.c bool vmw_user_object_is_null(struct vmw_user_object *uo) · line 2056

Quoted 8 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +8 -0
+
+void vmw_panic_flush(struct drm_plane *plane)
+{
+	struct vmw_private *vmw_priv = container_of(plane->dev, struct vmw_private, drm);
+
+	vmw_kms_write_svga(vmw_priv,
+			   vmw_priv->initial_width, vmw_priv->initial_height,
+			   vmw_priv->initial_width * 2, 16, 16);

vmw_kms_write_svga() calls vmw_write() which locks spin lock. Since these functions are called in panic handler, we should avoid them. You can find some idea in my original patch [1]!

[1] https://lore.kernel.org/all/[email protected]/

Thank you
Ryosuke

Quoted 29 lines
Quoted 27 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +1 -0
+}
drivers/gpu/drm/vmwgfx/vmwgfx_kms.h +5 -0
index 445471fe9be6..8e37561cd527 100644
@@ -500,6 +500,11 @@ int vmw_kms_stdu_readback(struct vmw_private *dev_priv,
  int vmw_du_helper_plane_update(struct vmw_du_update_plane *update);
+struct drm_scanout_buffer;
+
+int vmw_get_scanout_buffer(struct drm_plane *pl, struct drm_scanout_buffer *sb);
+void vmw_panic_flush(struct drm_plane *plane);
+
  /**
   * vmw_du_translate_to_crtc - Translate a rect from framebuffer to crtc
   * @state: Plane state.
drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c +2 -0
index 20aab725e53a..37cb742ba1d9 100644
@@ -1506,6 +1506,8 @@ drm_plane_helper_funcs vmw_stdu_primary_plane_helper_funcs = {
  	.atomic_update = vmw_stdu_primary_plane_atomic_update,
  	.prepare_fb = vmw_stdu_primary_plane_prepare_fb,
  	.cleanup_fb = vmw_stdu_primary_plane_cleanup_fb,
+	.get_scanout_buffer = vmw_get_scanout_buffer,
+	.panic_flush = vmw_panic_flush,
  };
  static const struct drm_crtc_helper_funcs vmw_stdu_crtc_helper_funcs = {
#3 lore raw
Quoted 47 lines · Ryosuke Yasuoka
Quoted 46 lines · Jocelyn Falempe
Quoted 1 line · Ian Forbes

Sets up VRAM as the scanout buffer then switches to legacy mode.

Thank you and Ryosuke for working on drm_panic support on vmwgfx. For the use of the drm_panic API, it looks good to me.

Quoted 39 lines
---
   drivers/gpu/drm/vmwgfx/vmwgfx_kms.c  | 33 ++++++++++++++++++++++++++++
   drivers/gpu/drm/vmwgfx/vmwgfx_kms.h  |  5 +++++
   drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c |  2 ++
   3 files changed, 40 insertions(+)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +16 -0
index 54ea1b513950..4ff4ae041236 100644
@@ -20,6 +20,7 @@
   #include <drm/drm_rect.h>
   #include <drm/drm_sysfs.h>
   #include <drm/drm_edid.h>
+#include <drm/drm_panic.h>
   void vmw_du_init(struct vmw_display_unit *du)
   {
@@ -2022,3 +2023,35 @@ bool vmw_user_object_is_null(struct vmw_user_object *uo)
   {
   	return !uo->buffer && !uo->surface;
   }
+
+int
+vmw_get_scanout_buffer(struct drm_plane *plane, struct drm_scanout_buffer *sb)
+{
+	void  *vram;
+	struct vmw_private *vmw_priv = container_of(plane->dev, struct vmw_private, drm);
+
+	// Only call on the primary display
+	if (container_of(plane, struct vmw_display_unit, primary)->unit != 0)
+		return -EINVAL;
+
+	vram = memremap(vmw_priv->vram_start, vmw_priv->vram_size,
+			MEMREMAP_WB | MEMREMAP_DEC);
+	if (!vram)
+		return -ENOMEM;
Quoted 8 lines
Quoted 3 lines

drivers/gpu/drm/vmwgfx/vmwgfx_kms.c bool vmw_user_object_is_null(struct vmw_user_object *uo) · line 2043

Quoted 3 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +3 -0
+
+	sb->map[0].vaddr = vram;
+	sb->format = drm_format_info(DRM_FORMAT_RGB565);

Let me confirm whether debugfs feature works correctly. As I mentioned in my original patch [1], modifying this format will allow to display the panic screen by debugfs only one time. In your environment, can you trigger panic screen by debugfs multiple times?

The debugfs interface is broken by design, it's just here to help adding new device support to drm_panic, so not a problem if there are garbage after you trigger it. (it's the case on most driver anyway).

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +9 -0
+	sb->width  = vmw_priv->initial_width;
+	sb->height = vmw_priv->initial_height;
+	sb->pitch[0] = sb->width * 2;
+	return 0;
+}
+
+void vmw_panic_flush(struct drm_plane *plane)
+{
+	struct vmw_private *vmw_priv = container_of(plane->dev, struct vmw_private, drm);
Quoted 8 lines
Quoted 4 lines

drivers/gpu/drm/vmwgfx/vmwgfx_kms.c bool vmw_user_object_is_null(struct vmw_user_object *uo) · line 2056

Quoted 4 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +4 -0
+
+	vmw_kms_write_svga(vmw_priv,
+			   vmw_priv->initial_width, vmw_priv->initial_height,
+			   vmw_priv->initial_width * 2, 16, 16);

vmw_kms_write_svga() calls vmw_write() which locks spin lock. Since these functions are called in panic handler, we should avoid them. You can find some idea in my original patch [1]!

Maybe another solution is to restrict the panic handler to VMWGFX_PCI_ID_SVGA3, that doesn't need locks in vmw_write().

I don't know if there are still a lot of hosts with VMWGFX_PCI_ID_SVGA2 in the open, and if we want to add drm_panic support for them.

Best regards,

Signature · 1 line
Jocelyn
Quoted 36 lines

[1] https://lore.kernel.org/all/[email protected]/

Thank you
Ryosuke

Quoted 29 lines
Quoted 27 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +1 -0
+}
drivers/gpu/drm/vmwgfx/vmwgfx_kms.h +5 -0
index 445471fe9be6..8e37561cd527 100644
@@ -500,6 +500,11 @@ int vmw_kms_stdu_readback(struct vmw_private *dev_priv,
   int vmw_du_helper_plane_update(struct vmw_du_update_plane *update);
+struct drm_scanout_buffer;
+
+int vmw_get_scanout_buffer(struct drm_plane *pl, struct drm_scanout_buffer *sb);
+void vmw_panic_flush(struct drm_plane *plane);
+
   /**
    * vmw_du_translate_to_crtc - Translate a rect from framebuffer to crtc
    * @state: Plane state.
drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c +2 -0
index 20aab725e53a..37cb742ba1d9 100644
@@ -1506,6 +1506,8 @@ drm_plane_helper_funcs vmw_stdu_primary_plane_helper_funcs = {
   	.atomic_update = vmw_stdu_primary_plane_atomic_update,
   	.prepare_fb = vmw_stdu_primary_plane_prepare_fb,
   	.cleanup_fb = vmw_stdu_primary_plane_cleanup_fb,
+	.get_scanout_buffer = vmw_get_scanout_buffer,
+	.panic_flush = vmw_panic_flush,
   };
   static const struct drm_crtc_helper_funcs vmw_stdu_crtc_helper_funcs = {
author
#4 lore raw

PATCH v2 1/1 drm/vmwgfx: Add drm_panic support

In reply to Ian Forbes

Sets up VRAM as the scanout buffer then switches to legacy mode.

---

v2:
- Set SVGA_REG_CONFIG_DONE=false so that SVGA3 works correctly

 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c  | 35 ++++++++++++++++++++++++++++
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.h  |  5 ++++
 drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c |  2 ++
 3 files changed, 42 insertions(+)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +35 -0
index efdbb67a4966..87448e86d3b3 100644
@@ -20,6 +20,7 @@
 #include <drm/drm_rect.h>
 #include <drm/drm_sysfs.h>
 #include <drm/drm_edid.h>
+#include <drm/drm_panic.h>
 
 void vmw_du_init(struct vmw_display_unit *du)
 {
@@ -2025,3 +2026,37 @@ bool vmw_user_object_is_null(struct vmw_user_object *uo)
 {
 	return !uo->buffer && !uo->surface;
 }
+
+int
+vmw_get_scanout_buffer(struct drm_plane *plane, struct drm_scanout_buffer *sb)
+{
+	void  *vram;
+	struct vmw_private *vmw_priv = container_of(plane->dev, struct vmw_private, drm);
+
+	// Only call on the primary display
+	if (container_of(plane, struct vmw_display_unit, primary)->unit != 0)
+		return -EINVAL;
+
+	vmw_write(vmw_priv, SVGA_REG_CONFIG_DONE, false);
+
+	vram = memremap(vmw_priv->vram_start, vmw_priv->vram_size,
+			MEMREMAP_WB | MEMREMAP_DEC);
+	if (!vram)
+		return -ENOMEM;
+
+	sb->map[0].vaddr = vram;
+	sb->format = drm_format_info(DRM_FORMAT_RGB565);
+	sb->width  = vmw_priv->initial_width;
+	sb->height = vmw_priv->initial_height;
+	sb->pitch[0] = sb->width * 2;
+	return 0;
+}
+
+void vmw_panic_flush(struct drm_plane *plane)
+{
+	struct vmw_private *vmw_priv = container_of(plane->dev, struct vmw_private, drm);
+
+	vmw_kms_write_svga(vmw_priv,
+			   vmw_priv->initial_width, vmw_priv->initial_height,
+			   vmw_priv->initial_width * 2, 16, 16);
+}
drivers/gpu/drm/vmwgfx/vmwgfx_kms.h +5 -0
index 445471fe9be6..8e37561cd527 100644
@@ -500,6 +500,11 @@ int vmw_kms_stdu_readback(struct vmw_private *dev_priv,
 
 int vmw_du_helper_plane_update(struct vmw_du_update_plane *update);
 
+struct drm_scanout_buffer;
+
+int vmw_get_scanout_buffer(struct drm_plane *pl, struct drm_scanout_buffer *sb);
+void vmw_panic_flush(struct drm_plane *plane);
+
 /**
  * vmw_du_translate_to_crtc - Translate a rect from framebuffer to crtc
  * @state: Plane state.
drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c +2 -0
index add13294fb7c..faacfef7baa5 100644
@@ -1506,6 +1506,8 @@ drm_plane_helper_funcs vmw_stdu_primary_plane_helper_funcs = {
 	.atomic_update = vmw_stdu_primary_plane_atomic_update,
 	.prepare_fb = vmw_stdu_primary_plane_prepare_fb,
 	.cleanup_fb = vmw_stdu_primary_plane_cleanup_fb,
+	.get_scanout_buffer = vmw_get_scanout_buffer,
+	.panic_flush = vmw_panic_flush,
 };
 
 static const struct drm_crtc_helper_funcs vmw_stdu_crtc_helper_funcs = {
Signature · 1 line
2.51.1
#5 lore raw

Hi

Am 07.11.25 um 21:46 schrieb Ian Forbes:

Quoted 35 lines

Sets up VRAM as the scanout buffer then switches to legacy mode.

---

v2:
- Set SVGA_REG_CONFIG_DONE=false so that SVGA3 works correctly

  drivers/gpu/drm/vmwgfx/vmwgfx_kms.c  | 35 ++++++++++++++++++++++++++++
  drivers/gpu/drm/vmwgfx/vmwgfx_kms.h  |  5 ++++
  drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c |  2 ++
  3 files changed, 42 insertions(+)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +6 -0
index efdbb67a4966..87448e86d3b3 100644
@@ -20,6 +20,7 @@
  #include <drm/drm_rect.h>
  #include <drm/drm_sysfs.h>
  #include <drm/drm_edid.h>
+#include <drm/drm_panic.h>
 
  void vmw_du_init(struct vmw_display_unit *du)
  {
@@ -2025,3 +2026,37 @@ bool vmw_user_object_is_null(struct vmw_user_object *uo)
  {
  	return !uo->buffer && !uo->surface;
  }
+
+int
+vmw_get_scanout_buffer(struct drm_plane *plane, struct drm_scanout_buffer *sb)
+{
+	void  *vram;

drivers/gpu/drm/vmwgfx/vmwgfx_kms.c bool vmw_user_object_is_null(struct vmw_user_object *uo) · line 2043

Quoted 10 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +10 -0
+	struct vmw_private *vmw_priv = container_of(plane->dev, struct vmw_private, drm);
+
+	// Only call on the primary display
+	if (container_of(plane, struct vmw_display_unit, primary)->unit != 0)
+		return -EINVAL;
+
+	vmw_write(vmw_priv, SVGA_REG_CONFIG_DONE, false);
+
+	vram = memremap(vmw_priv->vram_start, vmw_priv->vram_size,
+			MEMREMAP_WB | MEMREMAP_DEC);

Does that really work? We just had a kernel panic, so remapping might be difficult.

Quoted 9 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +9 -0
+	if (!vram)
+		return -ENOMEM;
+
+	sb->map[0].vaddr = vram;
+	sb->format = drm_format_info(DRM_FORMAT_RGB565);
+	sb->width  = vmw_priv->initial_width;
+	sb->height = vmw_priv->initial_height;
+	sb->pitch[0] = sb->width * 2;
+	return 0;

drivers/gpu/drm/vmwgfx/vmwgfx_kms.c bool vmw_user_object_is_null(struct vmw_user_object *uo) · line 2062

Quoted 10 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +10 -0
+}
+
+void vmw_panic_flush(struct drm_plane *plane)
+{
+	struct vmw_private *vmw_priv = container_of(plane->dev, struct vmw_private, drm);
+
+	vmw_kms_write_svga(vmw_priv,
+			   vmw_priv->initial_width, vmw_priv->initial_height,
+			   vmw_priv->initial_width * 2, 16, 16);
+}

I think we should consider adding a callback table for these operations. There's flush here and the vmap above is another possible candidate.

Best regards
Thomas

Quoted 29 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.h +5 -0
index 445471fe9be6..8e37561cd527 100644
@@ -500,6 +500,11 @@ int vmw_kms_stdu_readback(struct vmw_private *dev_priv,
 
  int vmw_du_helper_plane_update(struct vmw_du_update_plane *update);
 
+struct drm_scanout_buffer;
+
+int vmw_get_scanout_buffer(struct drm_plane *pl, struct drm_scanout_buffer *sb);
+void vmw_panic_flush(struct drm_plane *plane);
+
  /**
   * vmw_du_translate_to_crtc - Translate a rect from framebuffer to crtc
   * @state: Plane state.
drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c +2 -0
index add13294fb7c..faacfef7baa5 100644
@@ -1506,6 +1506,8 @@ drm_plane_helper_funcs vmw_stdu_primary_plane_helper_funcs = {
  	.atomic_update = vmw_stdu_primary_plane_atomic_update,
  	.prepare_fb = vmw_stdu_primary_plane_prepare_fb,
  	.cleanup_fb = vmw_stdu_primary_plane_cleanup_fb,
+	.get_scanout_buffer = vmw_get_scanout_buffer,
+	.panic_flush = vmw_panic_flush,
  };
 
  static const struct drm_crtc_helper_funcs vmw_stdu_crtc_helper_funcs = {
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
#6 lore raw
In reply to Ian Forbes

Hi

Am 07.11.25 um 21:46 schrieb Ian Forbes:

Quoted 1 line

Sets up VRAM as the scanout buffer then switches to legacy mode.

Please use make this a bit more elaborate.

Please also note that you don't set up VRAM, but return the scanout information for the given plane. That could be a difference if there are multiple planes.

Quoted 39 lines

---

v2:
- Set SVGA_REG_CONFIG_DONE=false so that SVGA3 works correctly

  drivers/gpu/drm/vmwgfx/vmwgfx_kms.c  | 35 ++++++++++++++++++++++++++++
  drivers/gpu/drm/vmwgfx/vmwgfx_kms.h  |  5 ++++
  drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c |  2 ++
  3 files changed, 42 insertions(+)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +11 -0
index efdbb67a4966..87448e86d3b3 100644
@@ -20,6 +20,7 @@
  #include <drm/drm_rect.h>
  #include <drm/drm_sysfs.h>
  #include <drm/drm_edid.h>
+#include <drm/drm_panic.h>
 
  void vmw_du_init(struct vmw_display_unit *du)
  {
@@ -2025,3 +2026,37 @@ bool vmw_user_object_is_null(struct vmw_user_object *uo)
  {
  	return !uo->buffer && !uo->surface;
  }
+
+int
+vmw_get_scanout_buffer(struct drm_plane *plane, struct drm_scanout_buffer *sb)
+{
+	void  *vram;
+	struct vmw_private *vmw_priv = container_of(plane->dev, struct vmw_private, drm);
+
+	// Only call on the primary display
+	if (container_of(plane, struct vmw_display_unit, primary)->unit != 0)
+		return -EINVAL;

drivers/gpu/drm/vmwgfx/vmwgfx_kms.c bool vmw_user_object_is_null(struct vmw_user_object *uo) · line 2047

Quoted 10 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +9 -0
+
+	vmw_write(vmw_priv, SVGA_REG_CONFIG_DONE, false);
+
+	vram = memremap(vmw_priv->vram_start, vmw_priv->vram_size,
+			MEMREMAP_WB | MEMREMAP_DEC);
+	if (!vram)
+		return -ENOMEM;
+
 
+	sb->map[0].vaddr = vram;

Please use iosys_map_set_vaddr() to initialize this field.

drivers/gpu/drm/vmwgfx/vmwgfx_kms.c bool vmw_user_object_is_null(struct vmw_user_object *uo) · line 2050

Quoted 3 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +3 -0
+	sb->format = drm_format_info(DRM_FORMAT_RGB565);
+	sb->width  = vmw_priv->initial_width;
+	sb->height = vmw_priv->initial_height;

Usually, you want to look at the plane's current framebuffer for this information.

drivers/gpu/drm/vmwgfx/vmwgfx_kms.c bool vmw_user_object_is_null(struct vmw_user_object *uo) · line 2051

Quoted 1 line
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +1 -0
+	sb->pitch[0] = sb->width * 2;

Please use drm_format_info_min_pitch() to compute this value or set whatever has been programmed to the hardware already.

Best regards
Thomas

Quoted 40 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +11 -0
+	return 0;
+}
+
+void vmw_panic_flush(struct drm_plane *plane)
+{
+	struct vmw_private *vmw_priv = container_of(plane->dev, struct vmw_private, drm);
+
+	vmw_kms_write_svga(vmw_priv,
+			   vmw_priv->initial_width, vmw_priv->initial_height,
+			   vmw_priv->initial_width * 2, 16, 16);
+}
drivers/gpu/drm/vmwgfx/vmwgfx_kms.h +5 -0
index 445471fe9be6..8e37561cd527 100644
@@ -500,6 +500,11 @@ int vmw_kms_stdu_readback(struct vmw_private *dev_priv,
 
  int vmw_du_helper_plane_update(struct vmw_du_update_plane *update);
 
+struct drm_scanout_buffer;
+
+int vmw_get_scanout_buffer(struct drm_plane *pl, struct drm_scanout_buffer *sb);
+void vmw_panic_flush(struct drm_plane *plane);
+
  /**
   * vmw_du_translate_to_crtc - Translate a rect from framebuffer to crtc
   * @state: Plane state.
drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c +2 -0
index add13294fb7c..faacfef7baa5 100644
@@ -1506,6 +1506,8 @@ drm_plane_helper_funcs vmw_stdu_primary_plane_helper_funcs = {
  	.atomic_update = vmw_stdu_primary_plane_atomic_update,
  	.prepare_fb = vmw_stdu_primary_plane_prepare_fb,
  	.cleanup_fb = vmw_stdu_primary_plane_cleanup_fb,
+	.get_scanout_buffer = vmw_get_scanout_buffer,
+	.panic_flush = vmw_panic_flush,
  };
 
  static const struct drm_crtc_helper_funcs vmw_stdu_crtc_helper_funcs = {
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
author
#7 lore raw
Quoted 12 lines · Thomas Zimmermann

Hi

Am 07.11.25 um 21:46 schrieb Ian Forbes:

Quoted 1 line

Sets up VRAM as the scanout buffer then switches to legacy mode.

Please use make this a bit more elaborate.

Please also note that you don't set up VRAM, but return the scanout information for the given plane. That could be a difference if there are multiple planes.

"VRAM" is a per device. It's not tied to a plane which is why we check the display
unit ID to call this only once. It requires setup by mapping the mmio region and poking
a register (CONFIG_DONE = false). I'm not sure how else to describe it other than
"setup".

Quoted 4 lines

Usually, you want to look at the plane's current framebuffer for this information.

The Screen Target (default) mode allows resolutions larger than legacy/register mode can handle.
These sizes are guaranteed to be safe for legacy mode.

#8 lore raw

Hi

Am 13.11.25 um 16:49 schrieb Ian Forbes:

Quoted 11 lines · Thomas Zimmermann
Quoted 10 lines

Hi

Am 07.11.25 um 21:46 schrieb Ian Forbes:

Quoted 1 line

Sets up VRAM as the scanout buffer then switches to legacy mode.

Please use make this a bit more elaborate.

Please also note that you don't set up VRAM, but return the scanout information for the given plane. That could be a difference if there are multiple planes.

Quoted 7 lines

"VRAM" is a per device. It's not tied to a plane which is why we check the display
unit ID to call this only once. It requires setup by mapping the mmio region and poking
a register (CONFIG_DONE = false). I'm not sure how else to describe it other than
"setup".

Yeah, sure. The question was: does it still work if you run this code for multiple planes? The DRM core will try to find multiple scanout buffers, if necessary.

Quoted 7 lines
Quoted 4 lines

Usually, you want to look at the plane's current framebuffer for this information.

The Screen Target (default) mode allows resolutions larger than legacy/register mode can handle.
These sizes are guaranteed to be safe for legacy mode.

Ok.

Best regards
Thomas

Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
author
#9 lore raw

PATCH v3 1/1 drm/vmwgfx: Add drm_panic support

In reply to Ian Forbes

Uses VRAM as the scanout buffer then switches the device to legacy mode. Restrict support to 64 Bit so we don't waste valuable VA space on the mostly unused VRAM mapping.

---

v2:
- Set SVGA_REG_CONFIG_DONE=false so that SVGA3 works correctly
v3:
- Rebase
- Pre-map VRAM
- Restrict to 64 Bit only

 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c  |  6 +++++
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h  |  1 +
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c  | 34 ++++++++++++++++++++++++++++
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.h  |  5 ++++
 drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c |  4 ++++
 5 files changed, 50 insertions(+)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +6 -0
index 0f101aedb49a..e6e38b7a2d5b 100644
@@ -761,6 +761,12 @@ static int vmw_setup_pci_resources(struct vmw_private *dev,
 		return -EINVAL;
 	}
 
+#if defined(CONFIG_64BIT)
+	dev->vram_mem = devm_memremap(dev->drm.dev,
+				      dev->vram_start,
+				      dev->vram_size,
+				      MEMREMAP_WB | MEMREMAP_DEC);
+#endif
 	/*
 	 * This is approximate size of the vram, the exact size will only
 	 * be known after we read SVGA_REG_VRAM_SIZE. The PCI resource
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +1 -0
index 38bea8abab84..463b5a5dfc43 100644
@@ -472,6 +472,7 @@ struct vmw_private {
 	resource_size_t max_primary_mem;
 	u32 __iomem *rmmio;
 	u32 *fifo_mem;
+	u32 *vram_mem;
 	resource_size_t fifo_mem_size;
 	uint32_t fb_max_width;
 	uint32_t fb_max_height;
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +34 -0
index 31d3ee0825ca..2d5e51ed5568 100644
@@ -21,6 +21,7 @@
 #include <drm/drm_sysfs.h>
 #include <drm/drm_edid.h>
 #include <drm/drm_blend.h>
+#include <drm/drm_panic.h>
 
 void vmw_du_init(struct vmw_display_unit *du)
 {
@@ -2034,3 +2035,36 @@ bool vmw_user_object_is_null(struct vmw_user_object *uo)
 {
 	return !uo->buffer && !uo->surface;
 }
+
+int
+vmw_get_scanout_buffer(struct drm_plane *plane, struct drm_scanout_buffer *sb)
+{
+	void  *vram;
+	struct vmw_private *vmw_priv = container_of(plane->dev, struct vmw_private, drm);
+
+	// Only call on the primary display
+	if (container_of(plane, struct vmw_display_unit, primary)->unit != 0)
+		return -EINVAL;
+
+	vram = vmw_priv->vram_mem;
+	if (!vram)
+		return -ENOMEM;
+
+	vmw_write(vmw_priv, SVGA_REG_CONFIG_DONE, false);
+
+	iosys_map_set_vaddr(&sb->map[0], vram);
+	sb->format = drm_format_info(DRM_FORMAT_RGB565);
+	sb->width  = vmw_priv->initial_width;
+	sb->height = vmw_priv->initial_height;
+	sb->pitch[0] = drm_format_info_min_pitch(sb->format, 0, sb->width);
+	return 0;
+}
+
+void vmw_panic_flush(struct drm_plane *plane)
+{
+	struct vmw_private *vmw_priv = container_of(plane->dev, struct vmw_private, drm);
+
+	vmw_kms_write_svga(vmw_priv,
+			   vmw_priv->initial_width, vmw_priv->initial_height,
+			   vmw_priv->initial_width * 2, 16, 16);
+}
drivers/gpu/drm/vmwgfx/vmwgfx_kms.h +5 -0
index 2224d7d91d1b..139c194ec54b 100644
@@ -498,6 +498,11 @@ int vmw_kms_stdu_readback(struct vmw_private *dev_priv,
 
 int vmw_du_helper_plane_update(struct vmw_du_update_plane *update);
 
+struct drm_scanout_buffer;
+
+int vmw_get_scanout_buffer(struct drm_plane *pl, struct drm_scanout_buffer *sb);
+void vmw_panic_flush(struct drm_plane *plane);
+
 /**
  * vmw_du_translate_to_crtc - Translate a rect from framebuffer to crtc
  * @state: Plane state.
drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c +4 -0
index 4139837f4caf..bf4b22cd9e5d 100644
@@ -1506,6 +1506,10 @@ drm_plane_helper_funcs vmw_stdu_primary_plane_helper_funcs = {
 	.atomic_update = vmw_stdu_primary_plane_atomic_update,
 	.prepare_fb = vmw_stdu_primary_plane_prepare_fb,
 	.cleanup_fb = vmw_stdu_primary_plane_cleanup_fb,
+#if defined(CONFIG_64BIT)
+	.get_scanout_buffer = vmw_get_scanout_buffer,
+	.panic_flush = vmw_panic_flush,
+#endif
 };
 
 static const struct drm_crtc_helper_funcs vmw_stdu_crtc_helper_funcs = {
Signature · 1 line
2.55.0
#10 lore raw
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] drm/vmwgfx: invalid pointer dereference of ERR_PTR from devm_memremap - [High] drm/vmwgfx…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] drm/vmwgfx: invalid pointer dereference of ERR_PTR from devm_memremap
- [High] drm/vmwgfx: deadlock in panic handler due to spinlock acquisition on SVGA2
- [Medium] drm/vmwgfx: buffer overflow in drm_panic due to missing vram_size bounds check --

commit a3fc842fd80e0209060a17de6e1213becdd10164
Author: Ian Forbes <[email protected]>

drm/vmwgfx: Add drm_panic support

Uses VRAM as the scanout buffer then switches the device to legacy mode. Restrict support to 64 Bit so we don't waste valuable VA space on the mostly unused VRAM mapping.

drivers/gpu/drm/vmwgfx/vmwgfx_drv.c static int vmw_setup_pci_resources(struct vmw_private *dev, · line 768

Quoted 13 lines
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +5 -0
index 0f101aedb49a0..e6e38b7a2d5b8 100644
@@ -761,6 +761,12 @@ static int vmw_setup_pci_resources(struct vmw_private *dev,
 		return -EINVAL;
 	}
 
+#if defined(CONFIG_64BIT)
+	dev->vram_mem = devm_memremap(dev->drm.dev,
+				      dev->vram_start,
+				      dev->vram_size,
+				      MEMREMAP_WB | MEMREMAP_DEC);

[Severity: High]
Does this code handle failures from devm_memremap() correctly?

If devm_memremap() fails during device initialization, it returns an ERR_PTR value, but this value is assigned to dev->vram_mem without validation using IS_ERR().

Quoted 3 lines
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +1 -0
+#endif
 	/*
 	 * This is approximate size of the vram, the exact size will only

[ ... ]

Quoted 12 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +4 -0
index a6c3304e1a67d..942176e2b3c69 100644
@@ -2023,3 +2024,36 @@ bool vmw_user_object_is_null(struct vmw_user_object *uo)
 {
 	return !uo->buffer && !uo->surface;
 }
+
+int
+vmw_get_scanout_buffer(struct drm_plane *plane, struct drm_scanout_buffer *sb)
+{

drivers/gpu/drm/vmwgfx/vmwgfx_kms.c bool vmw_user_object_is_null(struct vmw_user_object *uo) · line 2040

Quoted 10 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +10 -0
+	void  *vram;
+	struct vmw_private *vmw_priv = container_of(plane->dev, struct vmw_private, drm);
+
+	// Only call on the primary display
+	if (container_of(plane, struct vmw_display_unit, primary)->unit != 0)
+		return -EINVAL;
+
+	vram = vmw_priv->vram_mem;
+	if (!vram)
+		return -ENOMEM;

[Severity: High]
Can this code incorrectly forward an error pointer to iosys_map_set_vaddr()?

Because the previous devm_memremap() assignment was not checked for IS_ERR(), this !vram check will not catch an ERR_PTR value.

The invalid pointer will then be passed along, causing a page fault and recursive panic when the panic screen tries to render.

drivers/gpu/drm/vmwgfx/vmwgfx_kms.c bool vmw_user_object_is_null(struct vmw_user_object *uo) · line 2042

Quoted 2 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +2 -0
+
+	vmw_write(vmw_priv, SVGA_REG_CONFIG_DONE, false);

[Severity: High]
Is it safe to invoke vmw_write() here during a panic?

The panic handler runs in atomic context with interrupts disabled. On SVGA2 hardware, vmw_write() acquires a spinlock:

vmw_write()
spin_lock(&dev_priv->hw_lock);
outl(offset, dev_priv->io_start + SVGA_INDEX_PORT);
...

If another CPU holds the lock, or if the panicking CPU was already holding it, this will deadlock and permanently freeze the system instead of displaying the panic screen.

drivers/gpu/drm/vmwgfx/vmwgfx_kms.c bool vmw_user_object_is_null(struct vmw_user_object *uo) · line 2059

Quoted 6 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +6 -0
+
+	iosys_map_set_vaddr(&sb->map[0], vram);
+	sb->format = drm_format_info(DRM_FORMAT_RGB565);
+	sb->width  = vmw_priv->initial_width;
+	sb->height = vmw_priv->initial_height;
+	sb->pitch[0] = drm_format_info_min_pitch(sb->format, 0, sb->width);

[Severity: Medium]
Could this result in a buffer overflow during panic rendering?

The vmw_priv->initial_width and initial_height dimensions are supplied by the host hypervisor and are copied directly to the drm_scanout_buffer without verifying that the resulting buffer size fits within the mapped dev->vram_size.

If the hypervisor provides excessively large dimensions, the generic drm_panic code will write out-of-bounds of the mapped PCI BAR region.

drivers/gpu/drm/vmwgfx/vmwgfx_kms.c bool vmw_user_object_is_null(struct vmw_user_object *uo) · line 2069

Quoted 10 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +10 -0
+	return 0;
+}
+
+void vmw_panic_flush(struct drm_plane *plane)
+{
+	struct vmw_private *vmw_priv = container_of(plane->dev, struct vmw_private, drm);
+
+	vmw_kms_write_svga(vmw_priv,
+			   vmw_priv->initial_width, vmw_priv->initial_height,
+			   vmw_priv->initial_width * 2, 16, 16);

[Severity: High]
Can this also cause a deadlock in the panic handler?

Similar to the vmw_write() call above, vmw_kms_write_svga() performs multiple register reads and writes that invoke vmw_write() and acquire hw_lock on SVGA2 hardware.

Since this runs in atomic panic context, acquiring a spinlock can deadlock the system.

Quoted 1 line
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +1 -0
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v3 1/1
#11 lore raw
In reply to Ian Forbes
Quoted 3 lines · Ian Forbes

Uses VRAM as the scanout buffer then switches the device to legacy mode. Restrict support to 64 Bit so we don't waste valuable VA space on the mostly unused VRAM mapping.

Thanks a lot for to resending this patch.

Quoted 128 lines

---

v2:
- Set SVGA_REG_CONFIG_DONE=false so that SVGA3 works correctly
v3:
- Rebase
- Pre-map VRAM
- Restrict to 64 Bit only

  drivers/gpu/drm/vmwgfx/vmwgfx_drv.c  |  6 +++++
  drivers/gpu/drm/vmwgfx/vmwgfx_drv.h  |  1 +
  drivers/gpu/drm/vmwgfx/vmwgfx_kms.c  | 34 ++++++++++++++++++++++++++++
  drivers/gpu/drm/vmwgfx/vmwgfx_kms.h  |  5 ++++
  drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c |  4 ++++
  5 files changed, 50 insertions(+)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +6 -0
index 0f101aedb49a..e6e38b7a2d5b 100644
@@ -761,6 +761,12 @@ static int vmw_setup_pci_resources(struct vmw_private *dev,
  		return -EINVAL;
  	}
 
+#if defined(CONFIG_64BIT)
+	dev->vram_mem = devm_memremap(dev->drm.dev,
+				      dev->vram_start,
+				      dev->vram_size,
+				      MEMREMAP_WB | MEMREMAP_DEC);
+#endif
  	/*
  	 * This is approximate size of the vram, the exact size will only
  	 * be known after we read SVGA_REG_VRAM_SIZE. The PCI resource
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +1 -0
index 38bea8abab84..463b5a5dfc43 100644
@@ -472,6 +472,7 @@ struct vmw_private {
  	resource_size_t max_primary_mem;
  	u32 __iomem *rmmio;
  	u32 *fifo_mem;
+	u32 *vram_mem;
  	resource_size_t fifo_mem_size;
  	uint32_t fb_max_width;
  	uint32_t fb_max_height;
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +34 -0
index 31d3ee0825ca..2d5e51ed5568 100644
@@ -21,6 +21,7 @@
  #include <drm/drm_sysfs.h>
  #include <drm/drm_edid.h>
  #include <drm/drm_blend.h>
+#include <drm/drm_panic.h>
 
  void vmw_du_init(struct vmw_display_unit *du)
  {
@@ -2034,3 +2035,36 @@ bool vmw_user_object_is_null(struct vmw_user_object *uo)
  {
  	return !uo->buffer && !uo->surface;
  }
+
+int
+vmw_get_scanout_buffer(struct drm_plane *plane, struct drm_scanout_buffer *sb)
+{
+	void  *vram;
+	struct vmw_private *vmw_priv = container_of(plane->dev, struct vmw_private, drm);
+
+	// Only call on the primary display
+	if (container_of(plane, struct vmw_display_unit, primary)->unit != 0)
+		return -EINVAL;
+
+	vram = vmw_priv->vram_mem;
+	if (!vram)
+		return -ENOMEM;
+
+	vmw_write(vmw_priv, SVGA_REG_CONFIG_DONE, false);
+
+	iosys_map_set_vaddr(&sb->map[0], vram);
+	sb->format = drm_format_info(DRM_FORMAT_RGB565);
+	sb->width  = vmw_priv->initial_width;
+	sb->height = vmw_priv->initial_height;
+	sb->pitch[0] = drm_format_info_min_pitch(sb->format, 0, sb->width);
+	return 0;
+}
+
+void vmw_panic_flush(struct drm_plane *plane)
+{
+	struct vmw_private *vmw_priv = container_of(plane->dev, struct vmw_private, drm);
+
+	vmw_kms_write_svga(vmw_priv,
+			   vmw_priv->initial_width, vmw_priv->initial_height,
+			   vmw_priv->initial_width * 2, 16, 16);
+}
drivers/gpu/drm/vmwgfx/vmwgfx_kms.h +5 -0
index 2224d7d91d1b..139c194ec54b 100644
@@ -498,6 +498,11 @@ int vmw_kms_stdu_readback(struct vmw_private *dev_priv,
 
  int vmw_du_helper_plane_update(struct vmw_du_update_plane *update);
 
+struct drm_scanout_buffer;
+
+int vmw_get_scanout_buffer(struct drm_plane *pl, struct drm_scanout_buffer *sb);
+void vmw_panic_flush(struct drm_plane *plane);
+
  /**
   * vmw_du_translate_to_crtc - Translate a rect from framebuffer to crtc
   * @state: Plane state.
drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c +4 -0
index 4139837f4caf..bf4b22cd9e5d 100644
@@ -1506,6 +1506,10 @@ drm_plane_helper_funcs vmw_stdu_primary_plane_helper_funcs = {
  	.atomic_update = vmw_stdu_primary_plane_atomic_update,
  	.prepare_fb = vmw_stdu_primary_plane_prepare_fb,
  	.cleanup_fb = vmw_stdu_primary_plane_cleanup_fb,
+#if defined(CONFIG_64BIT)
+	.get_scanout_buffer = vmw_get_scanout_buffer,
+	.panic_flush = vmw_panic_flush,
+#endif
  };
 
  static const struct drm_crtc_helper_funcs vmw_stdu_crtc_helper_funcs = {