All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] drm/vmwgfx: Add debugfs entries for ttm placements
@ 2022-04-01 20:56 Zack Rusin
  2022-04-01 20:56 ` [PATCH 2/3] drm/vmwgfx: Write the driver id registers Zack Rusin
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Zack Rusin @ 2022-04-01 20:56 UTC (permalink / raw)
  To: dri-devel; +Cc: krastevm, mombasawalam

From: Zack Rusin <zackr@vmware.com>

Add a few debugfs entries for every used TTM placement that vmwgfx is
using. This allows basic tracking of memory usage inside vmwgfx, e.g.
'cat /sys/kernel/debug/dri/0/mob_ttm' will display mob memory usage.

Signed-off-by: Zack Rusin <zackr@vmware.com>
Reviewed-by: Martin Krastev <krastevm@vmware.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c        |  1 +
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h        |  1 +
 drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 97 +++++++++++++++++++++-
 3 files changed, 98 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 791f9a5f3868..6d675855f065 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -1632,6 +1632,7 @@ static int vmw_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 		goto out_unload;
 
 	vmw_debugfs_gem_init(vmw);
+	vmw_ttm_debugfs_init(vmw);
 
 	return 0;
 out_unload:
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index be19aa6e1f13..eabe3e8e9cf9 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -1085,6 +1085,7 @@ vmw_bo_sg_table(struct ttm_buffer_object *bo);
 extern int vmw_bo_create_and_populate(struct vmw_private *dev_priv,
 				      unsigned long bo_size,
 				      struct ttm_buffer_object **bo_p);
+void vmw_ttm_debugfs_init(struct vmw_private *vdev);
 
 extern void vmw_piter_start(struct vmw_piter *viter,
 			    const struct vmw_sg_table *vsgt,
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
index b84ecc6d6611..355414595e52 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0 OR MIT
 /**************************************************************************
  *
- * Copyright 2009-2015 VMware, Inc., Palo Alto, CA., USA
+ * Copyright 2009-2022 VMware, Inc., Palo Alto, CA., USA
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the
@@ -677,3 +677,98 @@ int vmw_bo_create_and_populate(struct vmw_private *dev_priv,
 		*bo_p = bo;
 	return ret;
 }
+
+#if defined(CONFIG_DEBUG_FS)
+
+static int vmw_ttm_vram_table_show(struct seq_file *m, void *unused)
+{
+	struct vmw_private *vdev = (struct vmw_private *)m->private;
+	struct ttm_resource_manager *man = ttm_manager_type(&vdev->bdev,
+							    TTM_PL_VRAM);
+	struct drm_printer p = drm_seq_file_printer(m);
+
+	ttm_resource_manager_debug(man, &p);
+	return 0;
+}
+
+static int vmw_ttm_page_pool_show(struct seq_file *m, void *unused)
+{
+	struct vmw_private *vdev = (struct vmw_private *)m->private;
+
+	return ttm_pool_debugfs(&vdev->bdev.pool, m);
+}
+
+static int vmw_ttm_mob_table_show(struct seq_file *m, void *unused)
+{
+	struct vmw_private *vdev = (struct vmw_private *)m->private;
+	struct ttm_resource_manager *man = ttm_manager_type(&vdev->bdev,
+							    VMW_PL_MOB);
+	struct drm_printer p = drm_seq_file_printer(m);
+
+	ttm_resource_manager_debug(man, &p);
+	return 0;
+}
+
+static int vmw_ttm_gmr_table_show(struct seq_file *m, void *unused)
+{
+	struct vmw_private *vdev = (struct vmw_private *)m->private;
+	struct ttm_resource_manager *man = ttm_manager_type(&vdev->bdev,
+							    VMW_PL_GMR);
+	struct drm_printer p = drm_seq_file_printer(m);
+
+	ttm_resource_manager_debug(man, &p);
+	return 0;
+}
+
+static int vmw_ttm_system_table_show(struct seq_file *m, void *unused)
+{
+	struct vmw_private *vdev = (struct vmw_private *)m->private;
+	struct ttm_resource_manager *man = ttm_manager_type(&vdev->bdev,
+							    TTM_PL_SYSTEM);
+	struct drm_printer p = drm_seq_file_printer(m);
+
+	ttm_resource_manager_debug(man, &p);
+	return 0;
+}
+
+static int vmw_ttm_system_mob_table_show(struct seq_file *m, void *unused)
+{
+	struct vmw_private *vdev = (struct vmw_private *)m->private;
+	struct ttm_resource_manager *man = ttm_manager_type(&vdev->bdev,
+							    VMW_PL_SYSTEM);
+	struct drm_printer p = drm_seq_file_printer(m);
+
+	ttm_resource_manager_debug(man, &p);
+	return 0;
+}
+
+DEFINE_SHOW_ATTRIBUTE(vmw_ttm_vram_table);
+DEFINE_SHOW_ATTRIBUTE(vmw_ttm_mob_table);
+DEFINE_SHOW_ATTRIBUTE(vmw_ttm_gmr_table);
+DEFINE_SHOW_ATTRIBUTE(vmw_ttm_system_table);
+DEFINE_SHOW_ATTRIBUTE(vmw_ttm_system_mob_table);
+DEFINE_SHOW_ATTRIBUTE(vmw_ttm_page_pool);
+
+#endif
+
+void vmw_ttm_debugfs_init(struct vmw_private *vdev)
+{
+#if defined(CONFIG_DEBUG_FS)
+	struct drm_device *drm = &vdev->drm;
+	struct drm_minor *minor = drm->primary;
+	struct dentry *root = minor->debugfs_root;
+
+	debugfs_create_file("vram_ttm", 0444, root, vdev,
+			    &vmw_ttm_vram_table_fops);
+	debugfs_create_file("mob_ttm", 0444, root, vdev,
+			    &vmw_ttm_mob_table_fops);
+	debugfs_create_file("gmr_ttm", 0444, root, vdev,
+			    &vmw_ttm_gmr_table_fops);
+	debugfs_create_file("system_ttm", 0444, root, vdev,
+			    &vmw_ttm_system_table_fops);
+	debugfs_create_file("system_mob_ttm", 0444, root, vdev,
+			    &vmw_ttm_system_mob_table_fops);
+	debugfs_create_file("ttm_page_pool", 0444, root, vdev,
+			    &vmw_ttm_page_pool_fops);
+#endif
+}
-- 
2.32.0


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

* [PATCH 2/3] drm/vmwgfx: Write the driver id registers
  2022-04-01 20:56 [PATCH 1/3] drm/vmwgfx: Add debugfs entries for ttm placements Zack Rusin
@ 2022-04-01 20:56 ` Zack Rusin
  2022-04-01 20:56   ` Zack Rusin
  2022-04-04 15:38 ` [PATCH 1/3] drm/vmwgfx: Add debugfs entries for ttm placements Daniel Vetter
  2 siblings, 0 replies; 7+ messages in thread
From: Zack Rusin @ 2022-04-01 20:56 UTC (permalink / raw)
  To: dri-devel; +Cc: krastevm, mombasawalam

From: Zack Rusin <zackr@vmware.com>

Driver id registers are a new mechanism in the svga device to hint to the
device which driver is running. This should not change device behavior
in any way, but might be convenient to work-around specific bugs
in guest drivers.

Signed-off-by: Zack Rusin <zackr@vmware.com>
Reviewed-by: Martin Krastev <krastevm@vmware.com>
Reviewed-by: Maaz Mombasawala <mombasawalam@vmware.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 43 +++++++++++++++++++++++------
 1 file changed, 34 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 6d675855f065..72a17618ba0a 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -25,10 +25,13 @@
  *
  **************************************************************************/
 
-#include <linux/dma-mapping.h>
-#include <linux/module.h>
-#include <linux/pci.h>
-#include <linux/cc_platform.h>
+
+#include "vmwgfx_drv.h"
+
+#include "vmwgfx_devcaps.h"
+#include "vmwgfx_mksstat.h"
+#include "vmwgfx_binding.h"
+#include "ttm_object.h"
 
 #include <drm/drm_aperture.h>
 #include <drm/drm_drv.h>
@@ -41,11 +44,11 @@
 #include <drm/ttm/ttm_placement.h>
 #include <generated/utsrelease.h>
 
-#include "ttm_object.h"
-#include "vmwgfx_binding.h"
-#include "vmwgfx_devcaps.h"
-#include "vmwgfx_drv.h"
-#include "vmwgfx_mksstat.h"
+#include <linux/cc_platform.h>
+#include <linux/dma-mapping.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/version.h>
 
 #define VMWGFX_DRIVER_DESC "Linux drm driver for VMware graphics devices"
 
@@ -806,6 +809,27 @@ static int vmw_detect_version(struct vmw_private *dev)
 	return 0;
 }
 
+static void vmw_write_driver_id(struct vmw_private *dev)
+{
+	if ((dev->capabilities2 & SVGA_CAP2_DX2) != 0) {
+		vmw_write(dev,  SVGA_REG_GUEST_DRIVER_ID,
+			  SVGA_REG_GUEST_DRIVER_ID_LINUX);
+
+		vmw_write(dev, SVGA_REG_GUEST_DRIVER_VERSION1,
+			  LINUX_VERSION_MAJOR << 24 |
+			  LINUX_VERSION_PATCHLEVEL << 16 |
+			  LINUX_VERSION_SUBLEVEL);
+		vmw_write(dev, SVGA_REG_GUEST_DRIVER_VERSION2,
+			  VMWGFX_DRIVER_MAJOR << 24 |
+			  VMWGFX_DRIVER_MINOR << 16 |
+			  VMWGFX_DRIVER_PATCHLEVEL);
+		vmw_write(dev, SVGA_REG_GUEST_DRIVER_VERSION3, 0);
+
+		vmw_write(dev, SVGA_REG_GUEST_DRIVER_ID,
+			  SVGA_REG_GUEST_DRIVER_ID_SUBMIT);
+	}
+}
+
 static int vmw_driver_load(struct vmw_private *dev_priv, u32 pci_id)
 {
 	int ret;
@@ -1094,6 +1118,7 @@ static int vmw_driver_load(struct vmw_private *dev_priv, u32 pci_id)
 	vmw_host_printf("vmwgfx: Module Version: %d.%d.%d (kernel: %s)",
 			VMWGFX_DRIVER_MAJOR, VMWGFX_DRIVER_MINOR,
 			VMWGFX_DRIVER_PATCHLEVEL, UTS_RELEASE);
+	vmw_write_driver_id(dev_priv);
 
 	if (dev_priv->enable_fb) {
 		vmw_fifo_resource_inc(dev_priv);
-- 
2.32.0


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

* [PATCH 3/3] drm/vmwgfx: Fix gem refcounting on prime exported surfaces
  2022-04-01 20:56 [PATCH 1/3] drm/vmwgfx: Add debugfs entries for ttm placements Zack Rusin
@ 2022-04-01 20:56   ` Zack Rusin
  2022-04-01 20:56   ` Zack Rusin
  2022-04-04 15:38 ` [PATCH 1/3] drm/vmwgfx: Add debugfs entries for ttm placements Daniel Vetter
  2 siblings, 0 replies; 7+ messages in thread
From: Zack Rusin @ 2022-04-01 20:56 UTC (permalink / raw)
  To: dri-devel; +Cc: krastevm, mombasawalam, Zack Rusin, stable

From: Zack Rusin <zackr@vmware.com>

vmwgfx exports two different kinds of gpu buffers to the userspace:
surfaces and mob's. Surfaces are backed by mob's. Currently only
surfaces are allowed with prime. Surfaces exported as prime weren't
increasing the reference count on the backing mob's (gem objects), which
meant that if the userspace destroyed the mob's, the exported surface
was becoming invalid and its usage lead to crashes (due to usage after
free).

Surfaces need to increase the reference count on the backing mob's for
the duration of the exported file descriptor for purposes of prime. Same
has to happen when an already existing mob is passed to the surface, its
reference count has to be increased.

This fixes crashes with XA state tracker which is used for xrender
acceleration on xf86-video-vmware.

Signed-off-by: Zack Rusin <zackr@vmware.com>
Cc: <stable@vger.kernel.org> # v5.17+
Reviewed-by: Martin Krastev <krastevm@vmware.com>
Reviewed-by: Maaz Mombasawala <mombasawalam@vmware.com>
---
 drivers/gpu/drm/vmwgfx/ttm_object.c      |  7 ++++++-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h      |  2 ++
 drivers/gpu/drm/vmwgfx/vmwgfx_gem.c      |  6 ++----
 drivers/gpu/drm/vmwgfx/vmwgfx_prime.c    | 14 ++++++++++++--
 drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 12 ++++++++++++
 drivers/gpu/drm/vmwgfx/vmwgfx_surface.c  |  1 +
 6 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/ttm_object.c b/drivers/gpu/drm/vmwgfx/ttm_object.c
index 26a55fef1ab5..53e9f81f7e1b 100644
--- a/drivers/gpu/drm/vmwgfx/ttm_object.c
+++ b/drivers/gpu/drm/vmwgfx/ttm_object.c
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
 /**************************************************************************
  *
- * Copyright (c) 2009-2013 VMware, Inc., Palo Alto, CA., USA
+ * Copyright (c) 2009-2022 VMware, Inc., Palo Alto, CA., USA
  * All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -51,6 +51,7 @@
 #include <linux/module.h>
 #include "ttm_object.h"
 #include "vmwgfx_drv.h"
+#include "vmwgfx_resource_priv.h"
 
 MODULE_IMPORT_NS(DMA_BUF);
 
@@ -617,6 +618,7 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,
 	struct ttm_base_object *base;
 	struct dma_buf *dma_buf;
 	struct ttm_prime_object *prime;
+	struct vmw_resource *res;
 	int ret;
 
 	base = ttm_base_object_lookup(tfile, handle);
@@ -667,6 +669,9 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,
 
 	ret = dma_buf_fd(dma_buf, flags);
 	if (ret >= 0) {
+		res = user_surface_converter->base_obj_to_res(&prime->base);
+		if (res)
+			vmw_resource_prime_ref(res);
 		*prime_fd = ret;
 		ret = 0;
 	} else
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index eabe3e8e9cf9..bb11f0d0b9b1 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -853,6 +853,8 @@ void vmw_resource_dirty_update(struct vmw_resource *res, pgoff_t start,
 			       pgoff_t end);
 int vmw_resources_clean(struct vmw_buffer_object *vbo, pgoff_t start,
 			pgoff_t end, pgoff_t *num_prefault);
+void vmw_resource_prime_ref(struct vmw_resource *res);
+void vmw_resource_prime_unref(struct vmw_resource *res);
 
 /**
  * vmw_resource_mob_attached - Whether a resource currently has a mob attached
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
index ce609e7d758f..f41dc638df23 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
 /*
- * Copyright 2021 VMware, Inc.
+ * Copyright 2021-2022 VMware, Inc.
  *
  * Permission is hereby granted, free of charge, to any person
  * obtaining a copy of this software and associated documentation
@@ -46,9 +46,8 @@ vmw_buffer_object(struct ttm_buffer_object *bo)
 static void vmw_gem_object_free(struct drm_gem_object *gobj)
 {
 	struct ttm_buffer_object *bo = drm_gem_ttm_of_gem(gobj);
-	if (bo) {
+	if (bo)
 		ttm_bo_put(bo);
-	}
 }
 
 static int vmw_gem_object_open(struct drm_gem_object *obj,
@@ -158,7 +157,6 @@ int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv,
 	return ret;
 }
 
-
 int vmw_gem_object_create_ioctl(struct drm_device *dev, void *data,
 				struct drm_file *filp)
 {
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_prime.c b/drivers/gpu/drm/vmwgfx/vmwgfx_prime.c
index 2d72a5ee7c0c..2896d212db54 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_prime.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_prime.c
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0 OR MIT
 /**************************************************************************
  *
- * Copyright 2013 VMware, Inc., Palo Alto, CA., USA
+ * Copyright 2013-2022 VMware, Inc., Palo Alto, CA., USA
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the
@@ -31,6 +31,7 @@
  */
 
 #include "vmwgfx_drv.h"
+#include "vmwgfx_resource_priv.h"
 #include "ttm_object.h"
 #include <linux/dma-buf.h>
 
@@ -62,12 +63,21 @@ static void vmw_prime_unmap_dma_buf(struct dma_buf_attachment *attach,
 {
 }
 
+static void vmw_prime_release(struct dma_buf *dma_buf)
+{
+	struct ttm_prime_object *prime = dma_buf->priv;
+	struct vmw_resource *res =
+			user_surface_converter->base_obj_to_res(&prime->base);
+	if (res)
+		vmw_resource_prime_unref(res);
+}
+
 const struct dma_buf_ops vmw_prime_dmabuf_ops =  {
 	.attach = vmw_prime_map_attach,
 	.detach = vmw_prime_map_detach,
 	.map_dma_buf = vmw_prime_map_dma_buf,
 	.unmap_dma_buf = vmw_prime_unmap_dma_buf,
-	.release = NULL,
+	.release = vmw_prime_release,
 };
 
 int vmw_prime_fd_to_handle(struct drm_device *dev,
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
index 6542f1498651..11de5d697351 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
@@ -1169,3 +1169,15 @@ int vmw_resources_clean(struct vmw_buffer_object *vbo, pgoff_t start,
 
 	return 0;
 }
+
+void vmw_resource_prime_ref(struct vmw_resource *res)
+{
+	if (res->backup)
+		drm_gem_object_get(&res->backup->base.base);
+}
+
+void vmw_resource_prime_unref(struct vmw_resource *res)
+{
+	if (res->backup)
+		drm_gem_object_put(&res->backup->base.base);
+}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
index 00e8e27e4884..04fdf613df83 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
@@ -1502,6 +1502,7 @@ vmw_gb_surface_define_internal(struct drm_device *dev,
 				goto out_unlock;
 			} else {
 				backup_handle = req->base.buffer_handle;
+				drm_gem_object_get(&res->backup->base.base);
 			}
 		}
 	} else if (req->base.drm_surface_flags &
-- 
2.32.0


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

* [PATCH 3/3] drm/vmwgfx: Fix gem refcounting on prime exported surfaces
@ 2022-04-01 20:56   ` Zack Rusin
  0 siblings, 0 replies; 7+ messages in thread
From: Zack Rusin @ 2022-04-01 20:56 UTC (permalink / raw)
  To: dri-devel; +Cc: krastevm, stable, mombasawalam

From: Zack Rusin <zackr@vmware.com>

vmwgfx exports two different kinds of gpu buffers to the userspace:
surfaces and mob's. Surfaces are backed by mob's. Currently only
surfaces are allowed with prime. Surfaces exported as prime weren't
increasing the reference count on the backing mob's (gem objects), which
meant that if the userspace destroyed the mob's, the exported surface
was becoming invalid and its usage lead to crashes (due to usage after
free).

Surfaces need to increase the reference count on the backing mob's for
the duration of the exported file descriptor for purposes of prime. Same
has to happen when an already existing mob is passed to the surface, its
reference count has to be increased.

This fixes crashes with XA state tracker which is used for xrender
acceleration on xf86-video-vmware.

Signed-off-by: Zack Rusin <zackr@vmware.com>
Cc: <stable@vger.kernel.org> # v5.17+
Reviewed-by: Martin Krastev <krastevm@vmware.com>
Reviewed-by: Maaz Mombasawala <mombasawalam@vmware.com>
---
 drivers/gpu/drm/vmwgfx/ttm_object.c      |  7 ++++++-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h      |  2 ++
 drivers/gpu/drm/vmwgfx/vmwgfx_gem.c      |  6 ++----
 drivers/gpu/drm/vmwgfx/vmwgfx_prime.c    | 14 ++++++++++++--
 drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 12 ++++++++++++
 drivers/gpu/drm/vmwgfx/vmwgfx_surface.c  |  1 +
 6 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/ttm_object.c b/drivers/gpu/drm/vmwgfx/ttm_object.c
index 26a55fef1ab5..53e9f81f7e1b 100644
--- a/drivers/gpu/drm/vmwgfx/ttm_object.c
+++ b/drivers/gpu/drm/vmwgfx/ttm_object.c
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
 /**************************************************************************
  *
- * Copyright (c) 2009-2013 VMware, Inc., Palo Alto, CA., USA
+ * Copyright (c) 2009-2022 VMware, Inc., Palo Alto, CA., USA
  * All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -51,6 +51,7 @@
 #include <linux/module.h>
 #include "ttm_object.h"
 #include "vmwgfx_drv.h"
+#include "vmwgfx_resource_priv.h"
 
 MODULE_IMPORT_NS(DMA_BUF);
 
@@ -617,6 +618,7 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,
 	struct ttm_base_object *base;
 	struct dma_buf *dma_buf;
 	struct ttm_prime_object *prime;
+	struct vmw_resource *res;
 	int ret;
 
 	base = ttm_base_object_lookup(tfile, handle);
@@ -667,6 +669,9 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,
 
 	ret = dma_buf_fd(dma_buf, flags);
 	if (ret >= 0) {
+		res = user_surface_converter->base_obj_to_res(&prime->base);
+		if (res)
+			vmw_resource_prime_ref(res);
 		*prime_fd = ret;
 		ret = 0;
 	} else
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index eabe3e8e9cf9..bb11f0d0b9b1 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -853,6 +853,8 @@ void vmw_resource_dirty_update(struct vmw_resource *res, pgoff_t start,
 			       pgoff_t end);
 int vmw_resources_clean(struct vmw_buffer_object *vbo, pgoff_t start,
 			pgoff_t end, pgoff_t *num_prefault);
+void vmw_resource_prime_ref(struct vmw_resource *res);
+void vmw_resource_prime_unref(struct vmw_resource *res);
 
 /**
  * vmw_resource_mob_attached - Whether a resource currently has a mob attached
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
index ce609e7d758f..f41dc638df23 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
 /*
- * Copyright 2021 VMware, Inc.
+ * Copyright 2021-2022 VMware, Inc.
  *
  * Permission is hereby granted, free of charge, to any person
  * obtaining a copy of this software and associated documentation
@@ -46,9 +46,8 @@ vmw_buffer_object(struct ttm_buffer_object *bo)
 static void vmw_gem_object_free(struct drm_gem_object *gobj)
 {
 	struct ttm_buffer_object *bo = drm_gem_ttm_of_gem(gobj);
-	if (bo) {
+	if (bo)
 		ttm_bo_put(bo);
-	}
 }
 
 static int vmw_gem_object_open(struct drm_gem_object *obj,
@@ -158,7 +157,6 @@ int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv,
 	return ret;
 }
 
-
 int vmw_gem_object_create_ioctl(struct drm_device *dev, void *data,
 				struct drm_file *filp)
 {
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_prime.c b/drivers/gpu/drm/vmwgfx/vmwgfx_prime.c
index 2d72a5ee7c0c..2896d212db54 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_prime.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_prime.c
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0 OR MIT
 /**************************************************************************
  *
- * Copyright 2013 VMware, Inc., Palo Alto, CA., USA
+ * Copyright 2013-2022 VMware, Inc., Palo Alto, CA., USA
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the
@@ -31,6 +31,7 @@
  */
 
 #include "vmwgfx_drv.h"
+#include "vmwgfx_resource_priv.h"
 #include "ttm_object.h"
 #include <linux/dma-buf.h>
 
@@ -62,12 +63,21 @@ static void vmw_prime_unmap_dma_buf(struct dma_buf_attachment *attach,
 {
 }
 
+static void vmw_prime_release(struct dma_buf *dma_buf)
+{
+	struct ttm_prime_object *prime = dma_buf->priv;
+	struct vmw_resource *res =
+			user_surface_converter->base_obj_to_res(&prime->base);
+	if (res)
+		vmw_resource_prime_unref(res);
+}
+
 const struct dma_buf_ops vmw_prime_dmabuf_ops =  {
 	.attach = vmw_prime_map_attach,
 	.detach = vmw_prime_map_detach,
 	.map_dma_buf = vmw_prime_map_dma_buf,
 	.unmap_dma_buf = vmw_prime_unmap_dma_buf,
-	.release = NULL,
+	.release = vmw_prime_release,
 };
 
 int vmw_prime_fd_to_handle(struct drm_device *dev,
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
index 6542f1498651..11de5d697351 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
@@ -1169,3 +1169,15 @@ int vmw_resources_clean(struct vmw_buffer_object *vbo, pgoff_t start,
 
 	return 0;
 }
+
+void vmw_resource_prime_ref(struct vmw_resource *res)
+{
+	if (res->backup)
+		drm_gem_object_get(&res->backup->base.base);
+}
+
+void vmw_resource_prime_unref(struct vmw_resource *res)
+{
+	if (res->backup)
+		drm_gem_object_put(&res->backup->base.base);
+}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
index 00e8e27e4884..04fdf613df83 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
@@ -1502,6 +1502,7 @@ vmw_gb_surface_define_internal(struct drm_device *dev,
 				goto out_unlock;
 			} else {
 				backup_handle = req->base.buffer_handle;
+				drm_gem_object_get(&res->backup->base.base);
 			}
 		}
 	} else if (req->base.drm_surface_flags &
-- 
2.32.0


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

* Re: [PATCH 1/3] drm/vmwgfx: Add debugfs entries for ttm placements
  2022-04-01 20:56 [PATCH 1/3] drm/vmwgfx: Add debugfs entries for ttm placements Zack Rusin
  2022-04-01 20:56 ` [PATCH 2/3] drm/vmwgfx: Write the driver id registers Zack Rusin
  2022-04-01 20:56   ` Zack Rusin
@ 2022-04-04 15:38 ` Daniel Vetter
  2022-04-05 14:00   ` Zack Rusin
  2 siblings, 1 reply; 7+ messages in thread
From: Daniel Vetter @ 2022-04-04 15:38 UTC (permalink / raw)
  To: Zack Rusin; +Cc: krastevm, mombasawalam, dri-devel

On Fri, Apr 01, 2022 at 04:56:00PM -0400, Zack Rusin wrote:
> From: Zack Rusin <zackr@vmware.com>
> 
> Add a few debugfs entries for every used TTM placement that vmwgfx is
> using. This allows basic tracking of memory usage inside vmwgfx, e.g.
> 'cat /sys/kernel/debug/dri/0/mob_ttm' will display mob memory usage.
> 
> Signed-off-by: Zack Rusin <zackr@vmware.com>
> Reviewed-by: Martin Krastev <krastevm@vmware.com>
> ---
>  drivers/gpu/drm/vmwgfx/vmwgfx_drv.c        |  1 +
>  drivers/gpu/drm/vmwgfx/vmwgfx_drv.h        |  1 +
>  drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 97 +++++++++++++++++++++-
>  3 files changed, 98 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> index 791f9a5f3868..6d675855f065 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> @@ -1632,6 +1632,7 @@ static int vmw_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>  		goto out_unload;
>  
>  	vmw_debugfs_gem_init(vmw);
> +	vmw_ttm_debugfs_init(vmw);
>  
>  	return 0;
>  out_unload:
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
> index be19aa6e1f13..eabe3e8e9cf9 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
> @@ -1085,6 +1085,7 @@ vmw_bo_sg_table(struct ttm_buffer_object *bo);
>  extern int vmw_bo_create_and_populate(struct vmw_private *dev_priv,
>  				      unsigned long bo_size,
>  				      struct ttm_buffer_object **bo_p);
> +void vmw_ttm_debugfs_init(struct vmw_private *vdev);
>  
>  extern void vmw_piter_start(struct vmw_piter *viter,
>  			    const struct vmw_sg_table *vsgt,
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> index b84ecc6d6611..355414595e52 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> @@ -1,7 +1,7 @@
>  // SPDX-License-Identifier: GPL-2.0 OR MIT
>  /**************************************************************************
>   *
> - * Copyright 2009-2015 VMware, Inc., Palo Alto, CA., USA
> + * Copyright 2009-2022 VMware, Inc., Palo Alto, CA., USA
>   *
>   * Permission is hereby granted, free of charge, to any person obtaining a
>   * copy of this software and associated documentation files (the
> @@ -677,3 +677,98 @@ int vmw_bo_create_and_populate(struct vmw_private *dev_priv,
>  		*bo_p = bo;
>  	return ret;
>  }
> +
> +#if defined(CONFIG_DEBUG_FS)
> +
> +static int vmw_ttm_vram_table_show(struct seq_file *m, void *unused)
> +{
> +	struct vmw_private *vdev = (struct vmw_private *)m->private;
> +	struct ttm_resource_manager *man = ttm_manager_type(&vdev->bdev,
> +							    TTM_PL_VRAM);
> +	struct drm_printer p = drm_seq_file_printer(m);
> +
> +	ttm_resource_manager_debug(man, &p);
> +	return 0;
> +}
> +
> +static int vmw_ttm_page_pool_show(struct seq_file *m, void *unused)
> +{
> +	struct vmw_private *vdev = (struct vmw_private *)m->private;
> +
> +	return ttm_pool_debugfs(&vdev->bdev.pool, m);
> +}
> +
> +static int vmw_ttm_mob_table_show(struct seq_file *m, void *unused)
> +{
> +	struct vmw_private *vdev = (struct vmw_private *)m->private;
> +	struct ttm_resource_manager *man = ttm_manager_type(&vdev->bdev,
> +							    VMW_PL_MOB);
> +	struct drm_printer p = drm_seq_file_printer(m);
> +
> +	ttm_resource_manager_debug(man, &p);
> +	return 0;
> +}
> +
> +static int vmw_ttm_gmr_table_show(struct seq_file *m, void *unused)
> +{
> +	struct vmw_private *vdev = (struct vmw_private *)m->private;
> +	struct ttm_resource_manager *man = ttm_manager_type(&vdev->bdev,
> +							    VMW_PL_GMR);
> +	struct drm_printer p = drm_seq_file_printer(m);
> +
> +	ttm_resource_manager_debug(man, &p);
> +	return 0;
> +}
> +
> +static int vmw_ttm_system_table_show(struct seq_file *m, void *unused)
> +{
> +	struct vmw_private *vdev = (struct vmw_private *)m->private;
> +	struct ttm_resource_manager *man = ttm_manager_type(&vdev->bdev,
> +							    TTM_PL_SYSTEM);
> +	struct drm_printer p = drm_seq_file_printer(m);
> +
> +	ttm_resource_manager_debug(man, &p);
> +	return 0;
> +}
> +
> +static int vmw_ttm_system_mob_table_show(struct seq_file *m, void *unused)
> +{
> +	struct vmw_private *vdev = (struct vmw_private *)m->private;
> +	struct ttm_resource_manager *man = ttm_manager_type(&vdev->bdev,
> +							    VMW_PL_SYSTEM);
> +	struct drm_printer p = drm_seq_file_printer(m);
> +
> +	ttm_resource_manager_debug(man, &p);
> +	return 0;
> +}
> +
> +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_vram_table);
> +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_mob_table);
> +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_gmr_table);
> +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_system_table);
> +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_system_mob_table);
> +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_page_pool);
> +
> +#endif
> +
> +void vmw_ttm_debugfs_init(struct vmw_private *vdev)
> +{
> +#if defined(CONFIG_DEBUG_FS)
> +	struct drm_device *drm = &vdev->drm;
> +	struct drm_minor *minor = drm->primary;
> +	struct dentry *root = minor->debugfs_root;
> +
> +	debugfs_create_file("vram_ttm", 0444, root, vdev,
> +			    &vmw_ttm_vram_table_fops);
> +	debugfs_create_file("mob_ttm", 0444, root, vdev,
> +			    &vmw_ttm_mob_table_fops);
> +	debugfs_create_file("gmr_ttm", 0444, root, vdev,
> +			    &vmw_ttm_gmr_table_fops);
> +	debugfs_create_file("system_ttm", 0444, root, vdev,
> +			    &vmw_ttm_system_table_fops);
> +	debugfs_create_file("system_mob_ttm", 0444, root, vdev,
> +			    &vmw_ttm_system_mob_table_fops);
> +	debugfs_create_file("ttm_page_pool", 0444, root, vdev,
> +			    &vmw_ttm_page_pool_fops);
> +#endif

Bit orthogonal, but can't ttm create the debugfs files for all the regions
on its own when we set everything up? Or at least a "create me all the
regions debugfs files" helpers would be useful. It's just rather silly
amounts of boilerplate we're having here, and that in each driver.
-Daniel

> +}
> -- 
> 2.32.0
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

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

* Re: [PATCH 1/3] drm/vmwgfx: Add debugfs entries for ttm placements
  2022-04-04 15:38 ` [PATCH 1/3] drm/vmwgfx: Add debugfs entries for ttm placements Daniel Vetter
@ 2022-04-05 14:00   ` Zack Rusin
  2022-04-05 20:05     ` Daniel Vetter
  0 siblings, 1 reply; 7+ messages in thread
From: Zack Rusin @ 2022-04-05 14:00 UTC (permalink / raw)
  To: daniel; +Cc: Martin Krastev, Maaz Mombasawala, dri-devel

On Mon, 2022-04-04 at 17:38 +0200, Daniel Vetter wrote:
> On Fri, Apr 01, 2022 at 04:56:00PM -0400, Zack Rusin wrote:
> > From: Zack Rusin <zackr@vmware.com>
> > 
> > Add a few debugfs entries for every used TTM placement that vmwgfx
> > is
> > using. This allows basic tracking of memory usage inside vmwgfx,
> > e.g.
> > 'cat /sys/kernel/debug/dri/0/mob_ttm' will display mob memory
> > usage.
> > 
> > Signed-off-by: Zack Rusin <zackr@vmware.com>
> > Reviewed-by: Martin Krastev <krastevm@vmware.com>
> > ---
> >  drivers/gpu/drm/vmwgfx/vmwgfx_drv.c        |  1 +
> >  drivers/gpu/drm/vmwgfx/vmwgfx_drv.h        |  1 +
> >  drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 97
> > +++++++++++++++++++++-
> >  3 files changed, 98 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> > b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> > index 791f9a5f3868..6d675855f065 100644
> > --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> > +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> > @@ -1632,6 +1632,7 @@ static int vmw_probe(struct pci_dev *pdev,
> > const struct pci_device_id *ent)
> >               goto out_unload;
> > 
> >       vmw_debugfs_gem_init(vmw);
> > +     vmw_ttm_debugfs_init(vmw);
> > 
> >       return 0;
> >  out_unload:
> > diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
> > b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
> > index be19aa6e1f13..eabe3e8e9cf9 100644
> > --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
> > +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
> > @@ -1085,6 +1085,7 @@ vmw_bo_sg_table(struct ttm_buffer_object
> > *bo);
> >  extern int vmw_bo_create_and_populate(struct vmw_private
> > *dev_priv,
> >                                     unsigned long bo_size,
> >                                     struct ttm_buffer_object
> > **bo_p);
> > +void vmw_ttm_debugfs_init(struct vmw_private *vdev);
> > 
> >  extern void vmw_piter_start(struct vmw_piter *viter,
> >                           const struct vmw_sg_table *vsgt,
> > diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> > b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> > index b84ecc6d6611..355414595e52 100644
> > --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> > +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> > @@ -1,7 +1,7 @@
> >  // SPDX-License-Identifier: GPL-2.0 OR MIT
> >  /*****************************************************************
> > *********
> >   *
> > - * Copyright 2009-2015 VMware, Inc., Palo Alto, CA., USA
> > + * Copyright 2009-2022 VMware, Inc., Palo Alto, CA., USA
> >   *
> >   * Permission is hereby granted, free of charge, to any person
> > obtaining a
> >   * copy of this software and associated documentation files (the
> > @@ -677,3 +677,98 @@ int vmw_bo_create_and_populate(struct
> > vmw_private *dev_priv,
> >               *bo_p = bo;
> >       return ret;
> >  }
> > +
> > +#if defined(CONFIG_DEBUG_FS)
> > +
> > +static int vmw_ttm_vram_table_show(struct seq_file *m, void
> > *unused)
> > +{
> > +     struct vmw_private *vdev = (struct vmw_private *)m->private;
> > +     struct ttm_resource_manager *man = ttm_manager_type(&vdev-
> > >bdev,
> > +                                                        
> > TTM_PL_VRAM);
> > +     struct drm_printer p = drm_seq_file_printer(m);
> > +
> > +     ttm_resource_manager_debug(man, &p);
> > +     return 0;
> > +}
> > +
> > +static int vmw_ttm_page_pool_show(struct seq_file *m, void
> > *unused)
> > +{
> > +     struct vmw_private *vdev = (struct vmw_private *)m->private;
> > +
> > +     return ttm_pool_debugfs(&vdev->bdev.pool, m);
> > +}
> > +
> > +static int vmw_ttm_mob_table_show(struct seq_file *m, void
> > *unused)
> > +{
> > +     struct vmw_private *vdev = (struct vmw_private *)m->private;
> > +     struct ttm_resource_manager *man = ttm_manager_type(&vdev-
> > >bdev,
> > +                                                        
> > VMW_PL_MOB);
> > +     struct drm_printer p = drm_seq_file_printer(m);
> > +
> > +     ttm_resource_manager_debug(man, &p);
> > +     return 0;
> > +}
> > +
> > +static int vmw_ttm_gmr_table_show(struct seq_file *m, void
> > *unused)
> > +{
> > +     struct vmw_private *vdev = (struct vmw_private *)m->private;
> > +     struct ttm_resource_manager *man = ttm_manager_type(&vdev-
> > >bdev,
> > +                                                        
> > VMW_PL_GMR);
> > +     struct drm_printer p = drm_seq_file_printer(m);
> > +
> > +     ttm_resource_manager_debug(man, &p);
> > +     return 0;
> > +}
> > +
> > +static int vmw_ttm_system_table_show(struct seq_file *m, void
> > *unused)
> > +{
> > +     struct vmw_private *vdev = (struct vmw_private *)m->private;
> > +     struct ttm_resource_manager *man = ttm_manager_type(&vdev-
> > >bdev,
> > +                                                        
> > TTM_PL_SYSTEM);
> > +     struct drm_printer p = drm_seq_file_printer(m);
> > +
> > +     ttm_resource_manager_debug(man, &p);
> > +     return 0;
> > +}
> > +
> > +static int vmw_ttm_system_mob_table_show(struct seq_file *m, void
> > *unused)
> > +{
> > +     struct vmw_private *vdev = (struct vmw_private *)m->private;
> > +     struct ttm_resource_manager *man = ttm_manager_type(&vdev-
> > >bdev,
> > +                                                        
> > VMW_PL_SYSTEM);
> > +     struct drm_printer p = drm_seq_file_printer(m);
> > +
> > +     ttm_resource_manager_debug(man, &p);
> > +     return 0;
> > +}
> > +
> > +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_vram_table);
> > +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_mob_table);
> > +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_gmr_table);
> > +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_system_table);
> > +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_system_mob_table);
> > +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_page_pool);
> > +
> > +#endif
> > +
> > +void vmw_ttm_debugfs_init(struct vmw_private *vdev)
> > +{
> > +#if defined(CONFIG_DEBUG_FS)
> > +     struct drm_device *drm = &vdev->drm;
> > +     struct drm_minor *minor = drm->primary;
> > +     struct dentry *root = minor->debugfs_root;
> > +
> > +     debugfs_create_file("vram_ttm", 0444, root, vdev,
> > +                         &vmw_ttm_vram_table_fops);
> > +     debugfs_create_file("mob_ttm", 0444, root, vdev,
> > +                         &vmw_ttm_mob_table_fops);
> > +     debugfs_create_file("gmr_ttm", 0444, root, vdev,
> > +                         &vmw_ttm_gmr_table_fops);
> > +     debugfs_create_file("system_ttm", 0444, root, vdev,
> > +                         &vmw_ttm_system_table_fops);
> > +     debugfs_create_file("system_mob_ttm", 0444, root, vdev,
> > +                         &vmw_ttm_system_mob_table_fops);
> > +     debugfs_create_file("ttm_page_pool", 0444, root, vdev,
> > +                         &vmw_ttm_page_pool_fops);
> > +#endif
> 
> Bit orthogonal, but can't ttm create the debugfs files for all the
> regions
> on its own when we set everything up? Or at least a "create me all
> the
> regions debugfs files" helpers would be useful. It's just rather
> silly
> amounts of boilerplate we're having here, and that in each driver.

Yea, agreed. With some kind of mapping between ttm data placement
defines and file names, this would be very much doable. Would you like
to see that done instead of this patch or after this patch lands?

z


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

* Re: [PATCH 1/3] drm/vmwgfx: Add debugfs entries for ttm placements
  2022-04-05 14:00   ` Zack Rusin
@ 2022-04-05 20:05     ` Daniel Vetter
  0 siblings, 0 replies; 7+ messages in thread
From: Daniel Vetter @ 2022-04-05 20:05 UTC (permalink / raw)
  To: Zack Rusin; +Cc: Martin Krastev, Maaz Mombasawala, dri-devel

On Tue, 5 Apr 2022 at 16:01, Zack Rusin <zackr@vmware.com> wrote:
>
> On Mon, 2022-04-04 at 17:38 +0200, Daniel Vetter wrote:
> > On Fri, Apr 01, 2022 at 04:56:00PM -0400, Zack Rusin wrote:
> > > From: Zack Rusin <zackr@vmware.com>
> > >
> > > Add a few debugfs entries for every used TTM placement that vmwgfx
> > > is
> > > using. This allows basic tracking of memory usage inside vmwgfx,
> > > e.g.
> > > 'cat /sys/kernel/debug/dri/0/mob_ttm' will display mob memory
> > > usage.
> > >
> > > Signed-off-by: Zack Rusin <zackr@vmware.com>
> > > Reviewed-by: Martin Krastev <krastevm@vmware.com>
> > > ---
> > >  drivers/gpu/drm/vmwgfx/vmwgfx_drv.c        |  1 +
> > >  drivers/gpu/drm/vmwgfx/vmwgfx_drv.h        |  1 +
> > >  drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 97
> > > +++++++++++++++++++++-
> > >  3 files changed, 98 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> > > b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> > > index 791f9a5f3868..6d675855f065 100644
> > > --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> > > +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> > > @@ -1632,6 +1632,7 @@ static int vmw_probe(struct pci_dev *pdev,
> > > const struct pci_device_id *ent)
> > >               goto out_unload;
> > >
> > >       vmw_debugfs_gem_init(vmw);
> > > +     vmw_ttm_debugfs_init(vmw);
> > >
> > >       return 0;
> > >  out_unload:
> > > diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
> > > b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
> > > index be19aa6e1f13..eabe3e8e9cf9 100644
> > > --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
> > > +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
> > > @@ -1085,6 +1085,7 @@ vmw_bo_sg_table(struct ttm_buffer_object
> > > *bo);
> > >  extern int vmw_bo_create_and_populate(struct vmw_private
> > > *dev_priv,
> > >                                     unsigned long bo_size,
> > >                                     struct ttm_buffer_object
> > > **bo_p);
> > > +void vmw_ttm_debugfs_init(struct vmw_private *vdev);
> > >
> > >  extern void vmw_piter_start(struct vmw_piter *viter,
> > >                           const struct vmw_sg_table *vsgt,
> > > diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> > > b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> > > index b84ecc6d6611..355414595e52 100644
> > > --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> > > +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> > > @@ -1,7 +1,7 @@
> > >  // SPDX-License-Identifier: GPL-2.0 OR MIT
> > >  /*****************************************************************
> > > *********
> > >   *
> > > - * Copyright 2009-2015 VMware, Inc., Palo Alto, CA., USA
> > > + * Copyright 2009-2022 VMware, Inc., Palo Alto, CA., USA
> > >   *
> > >   * Permission is hereby granted, free of charge, to any person
> > > obtaining a
> > >   * copy of this software and associated documentation files (the
> > > @@ -677,3 +677,98 @@ int vmw_bo_create_and_populate(struct
> > > vmw_private *dev_priv,
> > >               *bo_p = bo;
> > >       return ret;
> > >  }
> > > +
> > > +#if defined(CONFIG_DEBUG_FS)
> > > +
> > > +static int vmw_ttm_vram_table_show(struct seq_file *m, void
> > > *unused)
> > > +{
> > > +     struct vmw_private *vdev = (struct vmw_private *)m->private;
> > > +     struct ttm_resource_manager *man = ttm_manager_type(&vdev-
> > > >bdev,
> > > +
> > > TTM_PL_VRAM);
> > > +     struct drm_printer p = drm_seq_file_printer(m);
> > > +
> > > +     ttm_resource_manager_debug(man, &p);
> > > +     return 0;
> > > +}
> > > +
> > > +static int vmw_ttm_page_pool_show(struct seq_file *m, void
> > > *unused)
> > > +{
> > > +     struct vmw_private *vdev = (struct vmw_private *)m->private;
> > > +
> > > +     return ttm_pool_debugfs(&vdev->bdev.pool, m);
> > > +}
> > > +
> > > +static int vmw_ttm_mob_table_show(struct seq_file *m, void
> > > *unused)
> > > +{
> > > +     struct vmw_private *vdev = (struct vmw_private *)m->private;
> > > +     struct ttm_resource_manager *man = ttm_manager_type(&vdev-
> > > >bdev,
> > > +
> > > VMW_PL_MOB);
> > > +     struct drm_printer p = drm_seq_file_printer(m);
> > > +
> > > +     ttm_resource_manager_debug(man, &p);
> > > +     return 0;
> > > +}
> > > +
> > > +static int vmw_ttm_gmr_table_show(struct seq_file *m, void
> > > *unused)
> > > +{
> > > +     struct vmw_private *vdev = (struct vmw_private *)m->private;
> > > +     struct ttm_resource_manager *man = ttm_manager_type(&vdev-
> > > >bdev,
> > > +
> > > VMW_PL_GMR);
> > > +     struct drm_printer p = drm_seq_file_printer(m);
> > > +
> > > +     ttm_resource_manager_debug(man, &p);
> > > +     return 0;
> > > +}
> > > +
> > > +static int vmw_ttm_system_table_show(struct seq_file *m, void
> > > *unused)
> > > +{
> > > +     struct vmw_private *vdev = (struct vmw_private *)m->private;
> > > +     struct ttm_resource_manager *man = ttm_manager_type(&vdev-
> > > >bdev,
> > > +
> > > TTM_PL_SYSTEM);
> > > +     struct drm_printer p = drm_seq_file_printer(m);
> > > +
> > > +     ttm_resource_manager_debug(man, &p);
> > > +     return 0;
> > > +}
> > > +
> > > +static int vmw_ttm_system_mob_table_show(struct seq_file *m, void
> > > *unused)
> > > +{
> > > +     struct vmw_private *vdev = (struct vmw_private *)m->private;
> > > +     struct ttm_resource_manager *man = ttm_manager_type(&vdev-
> > > >bdev,
> > > +
> > > VMW_PL_SYSTEM);
> > > +     struct drm_printer p = drm_seq_file_printer(m);
> > > +
> > > +     ttm_resource_manager_debug(man, &p);
> > > +     return 0;
> > > +}
> > > +
> > > +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_vram_table);
> > > +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_mob_table);
> > > +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_gmr_table);
> > > +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_system_table);
> > > +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_system_mob_table);
> > > +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_page_pool);
> > > +
> > > +#endif
> > > +
> > > +void vmw_ttm_debugfs_init(struct vmw_private *vdev)
> > > +{
> > > +#if defined(CONFIG_DEBUG_FS)
> > > +     struct drm_device *drm = &vdev->drm;
> > > +     struct drm_minor *minor = drm->primary;
> > > +     struct dentry *root = minor->debugfs_root;
> > > +
> > > +     debugfs_create_file("vram_ttm", 0444, root, vdev,
> > > +                         &vmw_ttm_vram_table_fops);
> > > +     debugfs_create_file("mob_ttm", 0444, root, vdev,
> > > +                         &vmw_ttm_mob_table_fops);
> > > +     debugfs_create_file("gmr_ttm", 0444, root, vdev,
> > > +                         &vmw_ttm_gmr_table_fops);
> > > +     debugfs_create_file("system_ttm", 0444, root, vdev,
> > > +                         &vmw_ttm_system_table_fops);
> > > +     debugfs_create_file("system_mob_ttm", 0444, root, vdev,
> > > +                         &vmw_ttm_system_mob_table_fops);
> > > +     debugfs_create_file("ttm_page_pool", 0444, root, vdev,
> > > +                         &vmw_ttm_page_pool_fops);
> > > +#endif
> >
> > Bit orthogonal, but can't ttm create the debugfs files for all the
> > regions
> > on its own when we set everything up? Or at least a "create me all
> > the
> > regions debugfs files" helpers would be useful. It's just rather
> > silly
> > amounts of boilerplate we're having here, and that in each driver.
>
> Yea, agreed. With some kind of mapping between ttm data placement
> defines and file names, this would be very much doable. Would you like
> to see that done instead of this patch or after this patch lands?

If you're volunteering either way is fine imo :-)
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

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

end of thread, other threads:[~2022-04-05 20:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-01 20:56 [PATCH 1/3] drm/vmwgfx: Add debugfs entries for ttm placements Zack Rusin
2022-04-01 20:56 ` [PATCH 2/3] drm/vmwgfx: Write the driver id registers Zack Rusin
2022-04-01 20:56 ` [PATCH 3/3] drm/vmwgfx: Fix gem refcounting on prime exported surfaces Zack Rusin
2022-04-01 20:56   ` Zack Rusin
2022-04-04 15:38 ` [PATCH 1/3] drm/vmwgfx: Add debugfs entries for ttm placements Daniel Vetter
2022-04-05 14:00   ` Zack Rusin
2022-04-05 20:05     ` Daniel Vetter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.