Skip to contentSkip to conversation

drm/amdgpu: avoid dummy_read_page overlapping mappings

PATCH In review Prike Liang 1 participant 2 messages Oct 22, 2024 – Oct 23, 2024

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: avoid dummy_read_page overlapping mappings

In the A+A system, the dummy_read_page is mapped twice during the device graphics memory software initialization.

To avoid page remapping, export the ttm_glob_use_count to the driver for checking whether the same page has already been mapped.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c | 3 ++-
 drivers/gpu/drm/ttm/ttm_device.c         | 7 +++----
 include/drm/ttm/ttm_device.h             | 5 +++++
 3 files changed, 10 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +2 -1
index 256b95232de5..81e567f63967 100644
@@ -76,7 +76,8 @@ static int amdgpu_gart_dummy_page_init(struct amdgpu_device *adev)
 {
 	struct page *dummy_page = ttm_glob.dummy_read_page;
 
-	if (adev->dummy_page_addr)
+	if (adev->dummy_page_addr ||
+				ttm_glob.ttm_glob_use_count > 1)
 		return 0;
 	adev->dummy_page_addr = dma_map_page(&adev->pdev->dev, dummy_page, 0,
 					     PAGE_SIZE, DMA_BIDIRECTIONAL);
drivers/gpu/drm/ttm/ttm_device.c +3 -4
index 434cf0258000..d99ccfa94c67 100644
@@ -41,7 +41,6 @@
  * ttm_global_mutex - protecting the global state
  */
 static DEFINE_MUTEX(ttm_global_mutex);
-static unsigned ttm_glob_use_count;
 struct ttm_global ttm_glob;
 EXPORT_SYMBOL(ttm_glob);
 
@@ -52,7 +51,7 @@ static void ttm_global_release(void)
 	struct ttm_global *glob = &ttm_glob;
 
 	mutex_lock(&ttm_global_mutex);
-	if (--ttm_glob_use_count > 0)
+	if (--glob->ttm_glob_use_count > 0)
 		goto out;
 
 	ttm_pool_mgr_fini();
@@ -72,7 +71,7 @@ static int ttm_global_init(void)
 	int ret = 0;
 
 	mutex_lock(&ttm_global_mutex);
-	if (++ttm_glob_use_count > 1)
+	if (++glob->ttm_glob_use_count > 1)
 		goto out;
 
 	si_meminfo(&si);
@@ -118,7 +117,7 @@ static int ttm_global_init(void)
 	if (ret && ttm_debugfs_root)
 		debugfs_remove(ttm_debugfs_root);
 	if (ret)
-		--ttm_glob_use_count;
+		--glob->ttm_glob_use_count;
 	mutex_unlock(&ttm_global_mutex);
 	return ret;
 }
include/drm/ttm/ttm_device.h +5 -0
index c22f30535c84..8afb380989e1 100644
@@ -56,6 +56,11 @@ extern struct ttm_global {
 	 * @bo_count: Number of buffer objects allocated by devices.
 	 */
 	atomic_t bo_count;
+
+	/**
+	 * @ttm_glob_use_count: Number of ttm glob object referenced by devices.
+	 */
+	unsigned ttm_glob_use_count;
 } ttm_glob;
 
 struct ttm_device_funcs {
Signature · 1 line
2.34.1
#1 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Hold on to this patch for a while. I need to further investigate whether it requires allocating a separate page for the second VGA device.

Thanks,
Prike

Quoted 94 lines

-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Tuesday, October 22, 2024 3:19 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Liang, Prike <[email protected]>
Subject: [PATCH] drm/amdgpu: avoid dummy_read_page overlapping mappings

In the A+A system, the dummy_read_page is mapped twice during the device graphics memory software initialization.

To avoid page remapping, export the ttm_glob_use_count to the driver for checking whether the same page has already been mapped.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c | 3 ++-
 drivers/gpu/drm/ttm/ttm_device.c         | 7 +++----
 include/drm/ttm/ttm_device.h             | 5 +++++
 3 files changed, 10 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +2 -1
index 256b95232de5..81e567f63967 100644
@@ -76,7 +76,8 @@ static int amdgpu_gart_dummy_page_init(struct
 amdgpu_device *adev)  {
      struct page *dummy_page = ttm_glob.dummy_read_page;
 
-     if (adev->dummy_page_addr)
+     if (adev->dummy_page_addr ||
+                             ttm_glob.ttm_glob_use_count > 1)
              return 0;
      adev->dummy_page_addr = dma_map_page(&adev->pdev->dev,
 dummy_page, 0,

PAGE_SIZE, DMA_BIDIRECTIONAL); diff -
-git a/drivers/gpu/drm/ttm/ttm_device.c b/drivers/gpu/drm/ttm/ttm_device.c index 434cf0258000..d99ccfa94c67 100644

drivers/gpu/drm/ttm/ttm_device.c +3 -4
@@ -41,7 +41,6 @@
  * ttm_global_mutex - protecting the global state
  */
 static DEFINE_MUTEX(ttm_global_mutex);
-static unsigned ttm_glob_use_count;
 struct ttm_global ttm_glob;
 EXPORT_SYMBOL(ttm_glob);
 
@@ -52,7 +51,7 @@ static void ttm_global_release(void)
      struct ttm_global *glob = &ttm_glob;
 
      mutex_lock(&ttm_global_mutex);
-     if (--ttm_glob_use_count > 0)
+     if (--glob->ttm_glob_use_count > 0)
              goto out;
 
      ttm_pool_mgr_fini();
@@ -72,7 +71,7 @@ static int ttm_global_init(void)
      int ret = 0;
 
      mutex_lock(&ttm_global_mutex);
-     if (++ttm_glob_use_count > 1)
+     if (++glob->ttm_glob_use_count > 1)
              goto out;
 
      si_meminfo(&si);
@@ -118,7 +117,7 @@ static int ttm_global_init(void)
      if (ret && ttm_debugfs_root)
              debugfs_remove(ttm_debugfs_root);
      if (ret)
-             --ttm_glob_use_count;
+             --glob->ttm_glob_use_count;
      mutex_unlock(&ttm_global_mutex);
      return ret;
 }
include/drm/ttm/ttm_device.h index renamed from include/drm/ttm/ttm_device.h +0 -0

c22f30535c84..8afb380989e1 100644

include/drm/ttm/ttm_device.h +5 -1
@@ -56,6 +56,11 @@ extern struct ttm_global {
       * @bo_count: Number of buffer objects allocated by devices.
       */
      atomic_t bo_count;
+
+     /**
+      * @ttm_glob_use_count: Number of ttm glob object referenced by devices.
+      */
+     unsigned ttm_glob_use_count;
 } ttm_glob;
 
 struct ttm_device_funcs {
--

2.34.1