dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] Fix memory limits for STDU
@ 2024-04-11 21:26 Ian Forbes
  2024-04-11 21:26 ` [PATCH 1/4] drm/vmwgfx: Filter modes which exceed graphics memory Ian Forbes
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Ian Forbes @ 2024-04-11 21:26 UTC (permalink / raw)
  To: dri-devel
  Cc: bcm-kernel-feedback-list, zack.rusin, martin.krastev,
	maaz.mombasawala, Ian Forbes

Fixes a bug where modes that are too large for the device are exposed
and set causing a black screen on boot.

Resending as Patchwork did not like my last submission.

Ian Forbes (4):
  drm/vmwgfx: Filter modes which exceed graphics memory
  drm/vmwgfx: 3D disabled should not effect STDU memory limits
  drm/vmwgfx: Remove STDU logic from generic mode_valid function
  drm/vmwgfx: Standardize use of kibibytes when logging

 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c           | 19 ++++-------
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h           |  3 --
 drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c |  4 +--
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c           | 26 ++++++---------
 drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c          | 32 ++++++++++++++++++-
 5 files changed, 48 insertions(+), 36 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4] drm/vmwgfx: Filter modes which exceed graphics memory
  2024-04-11 21:26 [PATCH 0/4] Fix memory limits for STDU Ian Forbes
@ 2024-04-11 21:26 ` Ian Forbes
  2024-04-11 21:26 ` [PATCH 2/4] drm/vmwgfx: 3D disabled should not effect STDU memory limits Ian Forbes
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Ian Forbes @ 2024-04-11 21:26 UTC (permalink / raw)
  To: dri-devel
  Cc: bcm-kernel-feedback-list, zack.rusin, martin.krastev,
	maaz.mombasawala, Ian Forbes

SVGA requires individual surfaces to fit within graphics memory
(max_mob_pages) which means that modes with a final buffer size that would
exceed graphics memory must be pruned otherwise creation will fail.

This fixes an issue where VMs with low graphics memory (< 64MiB) configured
with high resolution mode boot to a black screen because surface creation
fails.

Fixes: d947d1b71deb ("drm/vmwgfx: Add and connect connector helper function")
Signed-off-by: Ian Forbes <ian.forbes@broadcom.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c | 32 +++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c b/drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c
index 2041c4d48daa..70b2ae974df3 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c
@@ -829,7 +829,37 @@ static void vmw_stdu_connector_destroy(struct drm_connector *connector)
 	vmw_stdu_destroy(vmw_connector_to_stdu(connector));
 }
 
+static enum drm_mode_status
+vmw_stdu_connector_mode_valid(struct drm_connector *connector,
+			      struct drm_display_mode *mode)
+{
+	enum drm_mode_status ret;
+	struct drm_device *dev = connector->dev;
+	struct vmw_private *dev_priv = vmw_priv(dev);
+	u64 assumed_cpp = dev_priv->assume_16bpp ? 2 : 4;
+	u64 required_mem = mode->hdisplay * assumed_cpp * mode->vdisplay;
+
+	ret = drm_mode_validate_size(mode, dev_priv->stdu_max_width,
+				     dev_priv->stdu_max_height);
+	if (ret != MODE_OK)
+		return ret;
+
+	ret = drm_mode_validate_size(mode, dev_priv->texture_max_width,
+				     dev_priv->texture_max_height);
+	if (ret != MODE_OK)
+		return ret;
 
+	if (required_mem > dev_priv->max_primary_mem)
+		return MODE_MEM;
+
+	if (required_mem > dev_priv->max_mob_pages * PAGE_SIZE)
+		return MODE_MEM;
+
+	if (required_mem > dev_priv->max_mob_size)
+		return MODE_MEM;
+
+	return MODE_OK;
+}
 
 static const struct drm_connector_funcs vmw_stdu_connector_funcs = {
 	.dpms = vmw_du_connector_dpms,
@@ -845,7 +875,7 @@ static const struct drm_connector_funcs vmw_stdu_connector_funcs = {
 static const struct
 drm_connector_helper_funcs vmw_stdu_connector_helper_funcs = {
 	.get_modes = vmw_connector_get_modes,
-	.mode_valid = vmw_connector_mode_valid
+	.mode_valid = vmw_stdu_connector_mode_valid
 };
 
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/4] drm/vmwgfx: 3D disabled should not effect STDU memory limits
  2024-04-11 21:26 [PATCH 0/4] Fix memory limits for STDU Ian Forbes
  2024-04-11 21:26 ` [PATCH 1/4] drm/vmwgfx: Filter modes which exceed graphics memory Ian Forbes
@ 2024-04-11 21:26 ` Ian Forbes
  2024-04-11 21:26 ` [PATCH 3/4] drm/vmwgfx: Remove STDU logic from generic mode_valid function Ian Forbes
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Ian Forbes @ 2024-04-11 21:26 UTC (permalink / raw)
  To: dri-devel
  Cc: bcm-kernel-feedback-list, zack.rusin, martin.krastev,
	maaz.mombasawala, Ian Forbes

This limit became a hard cap starting with the change referenced below.
Surface creation on the device will fail if the requested size is larger
than this limit so altering the value arbitrarily will expose modes that
are too large for the device's hard limits.

Fixes: 7ebb47c9f9ab ("drm/vmwgfx: Read new register for GB memory when available")
Signed-off-by: Ian Forbes <ian.forbes@broadcom.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 41ad13e45554..570d5fb65a2d 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -958,13 +958,6 @@ static int vmw_driver_load(struct vmw_private *dev_priv, u32 pci_id)
 				vmw_read(dev_priv,
 					 SVGA_REG_SUGGESTED_GBOBJECT_MEM_SIZE_KB);
 
-		/*
-		 * Workaround for low memory 2D VMs to compensate for the
-		 * allocation taken by fbdev
-		 */
-		if (!(dev_priv->capabilities & SVGA_CAP_3D))
-			mem_size *= 3;
-
 		dev_priv->max_mob_pages = mem_size * 1024 / PAGE_SIZE;
 		dev_priv->max_primary_mem =
 			vmw_read(dev_priv, SVGA_REG_MAX_PRIMARY_MEM);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/4] drm/vmwgfx: Remove STDU logic from generic mode_valid function
  2024-04-11 21:26 [PATCH 0/4] Fix memory limits for STDU Ian Forbes
  2024-04-11 21:26 ` [PATCH 1/4] drm/vmwgfx: Filter modes which exceed graphics memory Ian Forbes
  2024-04-11 21:26 ` [PATCH 2/4] drm/vmwgfx: 3D disabled should not effect STDU memory limits Ian Forbes
@ 2024-04-11 21:26 ` Ian Forbes
  2024-04-11 21:26 ` [PATCH 4/4] drm/vmwgfx: Standardize use of kibibytes when logging Ian Forbes
  2024-04-12  3:22 ` [PATCH 0/4] Fix memory limits for STDU Zack Rusin
  4 siblings, 0 replies; 7+ messages in thread
From: Ian Forbes @ 2024-04-11 21:26 UTC (permalink / raw)
  To: dri-devel
  Cc: bcm-kernel-feedback-list, zack.rusin, martin.krastev,
	maaz.mombasawala, Ian Forbes

STDU has its own mode_valid function now so this logic can be removed from
the generic version.

Fixes: 935f795045a6 ("drm/vmwgfx: Refactor drm connector probing for display modes")
Signed-off-by: Ian Forbes <ian.forbes@broadcom.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h |  3 ---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 26 +++++++++-----------------
 2 files changed, 9 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index 4ecaea0026fc..a1ce41e1c468 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -1043,9 +1043,6 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf,
 int vmw_kms_write_svga(struct vmw_private *vmw_priv,
 		       unsigned width, unsigned height, unsigned pitch,
 		       unsigned bpp, unsigned depth);
-bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
-				uint32_t pitch,
-				uint32_t height);
 int vmw_kms_present(struct vmw_private *dev_priv,
 		    struct drm_file *file_priv,
 		    struct vmw_framebuffer *vfb,
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index 13b2820cae51..9532258a0848 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -2171,13 +2171,12 @@ int vmw_kms_write_svga(struct vmw_private *vmw_priv,
 	return 0;
 }
 
+static
 bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
-				uint32_t pitch,
-				uint32_t height)
+				u64 pitch,
+				u64 height)
 {
-	return ((u64) pitch * (u64) height) < (u64)
-		((dev_priv->active_display_unit == vmw_du_screen_target) ?
-		 dev_priv->max_primary_mem : dev_priv->vram_size);
+	return (pitch * height) < (u64)dev_priv->vram_size;
 }
 
 /**
@@ -2873,25 +2872,18 @@ int vmw_du_helper_plane_update(struct vmw_du_update_plane *update)
 enum drm_mode_status vmw_connector_mode_valid(struct drm_connector *connector,
 					      struct drm_display_mode *mode)
 {
+	enum drm_mode_status ret;
 	struct drm_device *dev = connector->dev;
 	struct vmw_private *dev_priv = vmw_priv(dev);
-	u32 max_width = dev_priv->texture_max_width;
-	u32 max_height = dev_priv->texture_max_height;
 	u32 assumed_cpp = 4;
 
 	if (dev_priv->assume_16bpp)
 		assumed_cpp = 2;
 
-	if (dev_priv->active_display_unit == vmw_du_screen_target) {
-		max_width  = min(dev_priv->stdu_max_width,  max_width);
-		max_height = min(dev_priv->stdu_max_height, max_height);
-	}
-
-	if (max_width < mode->hdisplay)
-		return MODE_BAD_HVALUE;
-
-	if (max_height < mode->vdisplay)
-		return MODE_BAD_VVALUE;
+	ret = drm_mode_validate_size(mode, dev_priv->texture_max_width,
+				     dev_priv->texture_max_height);
+	if (ret != MODE_OK)
+		return ret;
 
 	if (!vmw_kms_validate_mode_vram(dev_priv,
 					mode->hdisplay * assumed_cpp,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/4] drm/vmwgfx: Standardize use of kibibytes when logging
  2024-04-11 21:26 [PATCH 0/4] Fix memory limits for STDU Ian Forbes
                   ` (2 preceding siblings ...)
  2024-04-11 21:26 ` [PATCH 3/4] drm/vmwgfx: Remove STDU logic from generic mode_valid function Ian Forbes
@ 2024-04-11 21:26 ` Ian Forbes
  2024-04-12  3:22 ` [PATCH 0/4] Fix memory limits for STDU Zack Rusin
  4 siblings, 0 replies; 7+ messages in thread
From: Ian Forbes @ 2024-04-11 21:26 UTC (permalink / raw)
  To: dri-devel
  Cc: bcm-kernel-feedback-list, zack.rusin, martin.krastev,
	maaz.mombasawala, Ian Forbes

Use the same standard abbreviation KiB instead of incorrect variants.

Signed-off-by: Ian Forbes <ian.forbes@broadcom.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c           | 12 ++++++------
 drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c |  4 ++--
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 570d5fb65a2d..27973eed84cc 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -744,7 +744,7 @@ static int vmw_setup_pci_resources(struct vmw_private *dev,
 		dev->vram_size = pci_resource_len(pdev, 2);
 
 		drm_info(&dev->drm,
-			"Register MMIO at 0x%pa size is %llu kiB\n",
+			"Register MMIO at 0x%pa size is %llu KiB\n",
 			 &rmmio_start, (uint64_t)rmmio_size / 1024);
 		dev->rmmio = devm_ioremap(dev->drm.dev,
 					  rmmio_start,
@@ -763,7 +763,7 @@ static int vmw_setup_pci_resources(struct vmw_private *dev,
 		fifo_size = pci_resource_len(pdev, 2);
 
 		drm_info(&dev->drm,
-			 "FIFO at %pa size is %llu kiB\n",
+			 "FIFO at %pa size is %llu KiB\n",
 			 &fifo_start, (uint64_t)fifo_size / 1024);
 		dev->fifo_mem = devm_memremap(dev->drm.dev,
 					      fifo_start,
@@ -788,7 +788,7 @@ static int vmw_setup_pci_resources(struct vmw_private *dev,
 	 * SVGA_REG_VRAM_SIZE.
 	 */
 	drm_info(&dev->drm,
-		 "VRAM at %pa size is %llu kiB\n",
+		 "VRAM at %pa size is %llu KiB\n",
 		 &dev->vram_start, (uint64_t)dev->vram_size / 1024);
 
 	return 0;
@@ -982,13 +982,13 @@ static int vmw_driver_load(struct vmw_private *dev_priv, u32 pci_id)
 		dev_priv->max_primary_mem = dev_priv->vram_size;
 	}
 	drm_info(&dev_priv->drm,
-		 "Legacy memory limits: VRAM = %llu kB, FIFO = %llu kB, surface = %u kB\n",
+		 "Legacy memory limits: VRAM = %llu KiB, FIFO = %llu KiB, surface = %u KiB\n",
 		 (u64)dev_priv->vram_size / 1024,
 		 (u64)dev_priv->fifo_mem_size / 1024,
 		 dev_priv->memory_size / 1024);
 
 	drm_info(&dev_priv->drm,
-		 "MOB limits: max mob size = %u kB, max mob pages = %u\n",
+		 "MOB limits: max mob size = %u KiB, max mob pages = %u\n",
 		 dev_priv->max_mob_size / 1024, dev_priv->max_mob_pages);
 
 	ret = vmw_dma_masks(dev_priv);
@@ -1006,7 +1006,7 @@ static int vmw_driver_load(struct vmw_private *dev_priv, u32 pci_id)
 			 (unsigned)dev_priv->max_gmr_pages);
 	}
 	drm_info(&dev_priv->drm,
-		 "Maximum display memory size is %llu kiB\n",
+		 "Maximum display memory size is %llu KiB\n",
 		 (uint64_t)dev_priv->max_primary_mem / 1024);
 
 	/* Need mmio memory to check for fifo pitchlock cap. */
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
index a0b47c9b33f5..5bd967fbcf55 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
@@ -94,14 +94,14 @@ static int vmw_gmrid_man_get_node(struct ttm_resource_manager *man,
 			} else
 				new_max_pages = gman->max_gmr_pages * 2;
 			if (new_max_pages > gman->max_gmr_pages && new_max_pages >= gman->used_gmr_pages) {
-				DRM_WARN("vmwgfx: increasing guest mob limits to %u kB.\n",
+				DRM_WARN("vmwgfx: increasing guest mob limits to %u KiB.\n",
 					 ((new_max_pages) << (PAGE_SHIFT - 10)));
 
 				gman->max_gmr_pages = new_max_pages;
 			} else {
 				char buf[256];
 				snprintf(buf, sizeof(buf),
-					 "vmwgfx, error: guest graphics is out of memory (mob limit at: %ukB).\n",
+					 "vmwgfx, error: guest graphics is out of memory (mob limit at: %u KiB).\n",
 					 ((gman->max_gmr_pages) << (PAGE_SHIFT - 10)));
 				vmw_host_printf(buf);
 				DRM_WARN("%s", buf);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/4] Fix memory limits for STDU
  2024-04-11 21:26 [PATCH 0/4] Fix memory limits for STDU Ian Forbes
                   ` (3 preceding siblings ...)
  2024-04-11 21:26 ` [PATCH 4/4] drm/vmwgfx: Standardize use of kibibytes when logging Ian Forbes
@ 2024-04-12  3:22 ` Zack Rusin
  2024-04-15 22:08   ` Ian Forbes
  4 siblings, 1 reply; 7+ messages in thread
From: Zack Rusin @ 2024-04-12  3:22 UTC (permalink / raw)
  To: Ian Forbes
  Cc: dri-devel, bcm-kernel-feedback-list, martin.krastev, maaz.mombasawala

On Thu, Apr 11, 2024 at 5:27 PM Ian Forbes <ian.forbes@broadcom.com> wrote:
>
> Fixes a bug where modes that are too large for the device are exposed
> and set causing a black screen on boot.
>
> Resending as Patchwork did not like my last submission.
>
> Ian Forbes (4):
>   drm/vmwgfx: Filter modes which exceed graphics memory
>   drm/vmwgfx: 3D disabled should not effect STDU memory limits
>   drm/vmwgfx: Remove STDU logic from generic mode_valid function
>   drm/vmwgfx: Standardize use of kibibytes when logging
>
>  drivers/gpu/drm/vmwgfx/vmwgfx_drv.c           | 19 ++++-------
>  drivers/gpu/drm/vmwgfx/vmwgfx_drv.h           |  3 --
>  drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c |  4 +--
>  drivers/gpu/drm/vmwgfx/vmwgfx_kms.c           | 26 ++++++---------
>  drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c          | 32 ++++++++++++++++++-
>  5 files changed, 48 insertions(+), 36 deletions(-)
>

In general that looks great! Two questions:
- with stdu what happens when the mode selected is close to our
limits, the guest is using a hardware cursor and we allocate cursor
mobs?
- with legacy du, is general mode selection with modes close to vram
size working?

And one comment: in series like those, be careful with fixes tags if
the patches depend on each other, i.e. the third one depends on the
first but they have different fixes tags so they're disconnected. It's
a good idea to keep distro kernel maintainers in mind with those and
try to organize the patches in a way that makes it a bit more clearer
that #3 depends on #1. It should be fine in this case though.

z

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/4] Fix memory limits for STDU
  2024-04-12  3:22 ` [PATCH 0/4] Fix memory limits for STDU Zack Rusin
@ 2024-04-15 22:08   ` Ian Forbes
  0 siblings, 0 replies; 7+ messages in thread
From: Ian Forbes @ 2024-04-15 22:08 UTC (permalink / raw)
  To: Zack Rusin
  Cc: dri-devel, bcm-kernel-feedback-list, martin.krastev, maaz.mombasawala

On Thu, Apr 11, 2024 at 10:22 PM Zack Rusin <zack.rusin@broadcom.com> wrote:
>
> - with stdu what happens when the mode selected is close to our
> limits, the guest is using a hardware cursor and we allocate cursor
> mobs?

With overcommit (cfdc3458db8a1620b1e307e3cb07480a161146ab) it won't be
an issue. Before overcommit there may be issues. That's what the
original code in patch 3 was trying to solve by increasing the guest
memory limit but that variable is also the hard host limit which would
invalidate fixes made by patch 1. Regardless it will be broken in one
way or another. We'd have to backport overcommit or multiply by that
constant factor from patch 3 when calling vmw_gmrid_man_init in
vmwgfx_gmird_manager.c in a separate patch. The only distros that may
be problematic would be debian 11 and ubuntu 22.04 without the HWE
kernel. Graphical installs of Ubuntu 22.04 LTS will have HWE by
default so only Ubuntu server users who installed a GUI and configured
the graphics memory to be tiny will be affected but chances are it was
already broken.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-04-15 22:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-11 21:26 [PATCH 0/4] Fix memory limits for STDU Ian Forbes
2024-04-11 21:26 ` [PATCH 1/4] drm/vmwgfx: Filter modes which exceed graphics memory Ian Forbes
2024-04-11 21:26 ` [PATCH 2/4] drm/vmwgfx: 3D disabled should not effect STDU memory limits Ian Forbes
2024-04-11 21:26 ` [PATCH 3/4] drm/vmwgfx: Remove STDU logic from generic mode_valid function Ian Forbes
2024-04-11 21:26 ` [PATCH 4/4] drm/vmwgfx: Standardize use of kibibytes when logging Ian Forbes
2024-04-12  3:22 ` [PATCH 0/4] Fix memory limits for STDU Zack Rusin
2024-04-15 22:08   ` Ian Forbes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).