Skip to contentSkip to conversation

drm/amd/amdgpu: fix bug fail to remove debugfs when rmmod

PATCH In review Wang Hongcheng 3 participants 7 messages Aug 10, 2017 – Aug 15, 2017 6 messages not in the archive

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

PATCH 1/1 drm/amd/amdgpu: fix bug fail to remove debugfs when rmmod

Some debug files are forgotten to remove at fini. Remove them all in pci_remove.

BUG: SWDEV-129297
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 19 +++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    |  2 ++
 3 files changed, 23 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
index c28069e4..b542191 100644
@@ -1250,6 +1250,8 @@ struct amdgpu_debugfs {
 int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
 			     const struct drm_info_list *files,
 			     unsigned nfiles);
+int amdgpu_debugfs_cleanup(struct amdgpu_device *adev);
+
 int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
 
 #if defined(CONFIG_DEBUG_FS)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +19 -0
index 7e40071..7594abb 100644
@@ -3215,6 +3215,25 @@ int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
 	return 0;
 }
 
+int amdgpu_debugfs_cleanup(struct amdgpu_device *adev)
+{
+	struct drm_info_node *node, *tmp;
+
+	if (!&adev->ddev->primary->debugfs_root)
+		return 0;
+
+	mutex_lock(&adev->ddev->primary->debugfs_lock);
+	list_for_each_entry_safe(node, tmp,
+		&adev->ddev->primary->debugfs_list, list) {
+		debugfs_remove(node->dent);
+		list_del(&node->list);
+		kfree(node);
+	}
+	mutex_unlock(&adev->ddev->primary->debugfs_lock);
+
+	return 0;
+}
+
 #if defined(CONFIG_DEBUG_FS)
 
 static ssize_t amdgpu_debugfs_regs_read(struct file *f, char __user *buf,
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
index 13c91a6..4f5af93 100644
@@ -594,7 +594,9 @@ static void
 amdgpu_pci_remove(struct pci_dev *pdev)
 {
 	struct drm_device *dev = pci_get_drvdata(pdev);
+	struct amdgpu_device *adev = dev->dev_private;
 
+	amdgpu_debugfs_cleanup(adev);
 	drm_dev_unregister(dev);
 	drm_dev_unref(dev);
 }
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1502356338-12687-1-git-send-email-Annie.Wang-5C7GfCeVMHo@public.gmane.org

#2 lore raw
Quoted 4 lines · Wang Hongcheng

Some debug files are forgotten to remove at fini. Remove them all in pci_remove.

BUG: SWDEV-129297

What files are failing to get removed? I'd prefer to remove them in the relevant places in the code (to mirror where they are added) rather than generically cleaning everything up. Either that or unify all the debugfs init/fini stuff in one place.

Alex

Quoted 68 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 19 +++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    |  2 ++
 3 files changed, 23 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
index c28069e4..b542191 100644
@@ -1250,6 +1250,8 @@ struct amdgpu_debugfs {
 int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
                             const struct drm_info_list *files,
                             unsigned nfiles);
+int amdgpu_debugfs_cleanup(struct amdgpu_device *adev);
+
 int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
 
 #if defined(CONFIG_DEBUG_FS)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +19 -0
index 7e40071..7594abb 100644
@@ -3215,6 +3215,25 @@ int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
        return 0;
 }
 
+int amdgpu_debugfs_cleanup(struct amdgpu_device *adev)
+{
+       struct drm_info_node *node, *tmp;
+
+       if (!&adev->ddev->primary->debugfs_root)
+               return 0;
+
+       mutex_lock(&adev->ddev->primary->debugfs_lock);
+       list_for_each_entry_safe(node, tmp,
+               &adev->ddev->primary->debugfs_list, list) {
+               debugfs_remove(node->dent);
+               list_del(&node->list);
+               kfree(node);
+       }
+       mutex_unlock(&adev->ddev->primary->debugfs_lock);
+
+       return 0;
+}
+
 #if defined(CONFIG_DEBUG_FS)
 
 static ssize_t amdgpu_debugfs_regs_read(struct file *f, char __user *buf,
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -1
index 13c91a6..4f5af93 100644
@@ -594,7 +594,9 @@ static void
 amdgpu_pci_remove(struct pci_dev *pdev)
 {
        struct drm_device *dev = pci_get_drvdata(pdev);
+       struct amdgpu_device *adev = dev->dev_private;
 
+       amdgpu_debugfs_cleanup(adev);
        drm_dev_unregister(dev);
        drm_dev_unref(dev);
 }
--

2.7.4

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): CADnq5_O7L1H_TTYX9DSGPRfoB+7=MFfWA0Vx7Q8TqHSi2sD5Mg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#4 lore raw

Hi Alex,

The following files are all left.

amdgpu_fence_info
amdgpu_firmware_info
amdgpu_gem_info
amdgpu_gpu_reset
amdgpu_gtt_mm
amdgpu_pm_info
amdgpu_sa_info
amdgpu_test_ib
amdgpu_vram_mm
ttm_dma_page_pool
ttm_page_pool

Instead of fini them separately, how about implement the callback function --- debugfs_fini.
.debugfs_fini = amdgpu_debugfs_cleanup,

And in the future I will send another patch to collect all the init function
.debugfs_init = amdgpu_debugfs_init,

Quoted 92 lines

-----Original Message-----
From: Alex Deucher [mailto:[email protected]]
Sent: Friday, August 11, 2017 1:01 AM
To: Wang, Annie <[email protected]>
Cc: amd-gfx list <[email protected]>
Subject: Re: [PATCH] drm/amd/amdgpu: fix bug fail to remove debugfs when rmmod

Quoted 4 lines · Wang Hongcheng

Some debug files are forgotten to remove at fini. Remove them all in pci_remove.

BUG: SWDEV-129297

What files are failing to get removed? I'd prefer to remove them in the relevant places in the code (to mirror where they are added) rather than generically cleaning everything up. Either that or unify all the debugfs init/fini stuff in one place.

Alex

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_debugfs_add_files(struct

Quoted 28 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 19 +++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    |  2 ++
 3 files changed, 23 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
index c28069e4..b542191 100644
@@ -1250,6 +1250,8 @@ struct amdgpu_debugfs {  int
 amdgpu_debugfs_add_files(struct amdgpu_device *adev,
                             const struct drm_info_list *files,
                             unsigned nfiles);
+int amdgpu_debugfs_cleanup(struct amdgpu_device *adev);
+
 int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
 
 #if defined(CONFIG_DEBUG_FS)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 7e40071..7594abb 100644
@@ -3215,6 +3215,25 @@ int amdgpu_debugfs_add_files(struct

amdgpu_device *adev,

Quoted 41 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +18 -0
        return 0;
 }
 
+int amdgpu_debugfs_cleanup(struct amdgpu_device *adev) {
+       struct drm_info_node *node, *tmp;
+
+       if (!&adev->ddev->primary->debugfs_root)
+               return 0;
+
+       mutex_lock(&adev->ddev->primary->debugfs_lock);
+       list_for_each_entry_safe(node, tmp,
+               &adev->ddev->primary->debugfs_list, list) {
+               debugfs_remove(node->dent);
+               list_del(&node->list);
+               kfree(node);
+       }
+       mutex_unlock(&adev->ddev->primary->debugfs_lock);
+
+       return 0;
+}
+
 #if defined(CONFIG_DEBUG_FS)
 
 static ssize_t amdgpu_debugfs_regs_read(struct file *f, char __user

*buf, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 13c91a6..4f5af93 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -1
@@ -594,7 +594,9 @@ static void
 amdgpu_pci_remove(struct pci_dev *pdev)  {
        struct drm_device *dev = pci_get_drvdata(pdev);
+       struct amdgpu_device *adev = dev->dev_private;
 
+       amdgpu_debugfs_cleanup(adev);
        drm_dev_unregister(dev);
        drm_dev_unref(dev);
 }
--

2.7.4

Quoted 4 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): MWHPR12MB19208BDF83D8C2AFB478D10381890-Gy0DoCVfaSXeXoETSPOSegdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#6 lore raw

Hi Annie,

well something is clearly not working as expected here.

All those files are registered with drm_debugfs_create_files() and should automatically be removed when drm_debugfs_cleanup() is called.

Can you figure out what is going wrong here?

Thanks,
Christian.

Am 11.08.2017 um 04:25 schrieb Wang, Annie:

Quoted 113 lines

Hi Alex,

The following files are all left.

amdgpu_fence_info
amdgpu_firmware_info
amdgpu_gem_info
amdgpu_gpu_reset
amdgpu_gtt_mm
amdgpu_pm_info
amdgpu_sa_info
amdgpu_test_ib
amdgpu_vram_mm
ttm_dma_page_pool
ttm_page_pool

Instead of fini them separately, how about implement the callback function --- debugfs_fini.
.debugfs_fini = amdgpu_debugfs_cleanup,

And in the future I will send another patch to collect all the init function
.debugfs_init = amdgpu_debugfs_init,

Quoted 90 lines

-----Original Message-----
From: Alex Deucher [mailto:[email protected]]
Sent: Friday, August 11, 2017 1:01 AM
To: Wang, Annie <[email protected]>
Cc: amd-gfx list <[email protected]>
Subject: Re: [PATCH] drm/amd/amdgpu: fix bug fail to remove debugfs when rmmod

Quoted 4 lines · Wang Hongcheng

Some debug files are forgotten to remove at fini. Remove them all in pci_remove.

BUG: SWDEV-129297

What files are failing to get removed? I'd prefer to remove them in the relevant places in the code (to mirror where they are added) rather than generically cleaning everything up. Either that or unify all the debugfs init/fini stuff in one place.

Alex

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_debugfs_add_files(struct

Quoted 27 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  2 ++
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 19 +++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    |  2 ++
  3 files changed, 23 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
index c28069e4..b542191 100644
@@ -1250,6 +1250,8 @@ struct amdgpu_debugfs {  int
 amdgpu_debugfs_add_files(struct amdgpu_device *adev,
                              const struct drm_info_list *files,
                              unsigned nfiles);
+int amdgpu_debugfs_cleanup(struct amdgpu_device *adev);
+
  int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
 
  #if defined(CONFIG_DEBUG_FS)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 7e40071..7594abb 100644
@@ -3215,6 +3215,25 @@ int amdgpu_debugfs_add_files(struct

amdgpu_device *adev,

Quoted 41 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +18 -0
         return 0;
  }
 
+int amdgpu_debugfs_cleanup(struct amdgpu_device *adev) {
+       struct drm_info_node *node, *tmp;
+
+       if (!&adev->ddev->primary->debugfs_root)
+               return 0;
+
+       mutex_lock(&adev->ddev->primary->debugfs_lock);
+       list_for_each_entry_safe(node, tmp,
+               &adev->ddev->primary->debugfs_list, list) {
+               debugfs_remove(node->dent);
+               list_del(&node->list);
+               kfree(node);
+       }
+       mutex_unlock(&adev->ddev->primary->debugfs_lock);
+
+       return 0;
+}
+
  #if defined(CONFIG_DEBUG_FS)
 
  static ssize_t amdgpu_debugfs_regs_read(struct file *f, char __user

*buf, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 13c91a6..4f5af93 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -1
@@ -594,7 +594,9 @@ static void
  amdgpu_pci_remove(struct pci_dev *pdev)  {
         struct drm_device *dev = pci_get_drvdata(pdev);
+       struct amdgpu_device *adev = dev->dev_private;
 
+       amdgpu_debugfs_cleanup(adev);
         drm_dev_unregister(dev);
         drm_dev_unref(dev);
  }
--

2.7.4

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 6d494b94-00a0-951a-7b32-6e80acd61b83-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#8 lore raw

Hi Christian,

Yes. drm_debugfs_cleanup() should delete all the files, after the following commit.

commit 086f2e5cde747dcae800b2d8b0ac7741a8c6fcbe

Author: Noralf Trønnes <[email protected]>
Date:   Thu Jan 26 23:56:03 2017 +0100

drm: debugfs: Remove all files automatically on cleanup

Instead of having the drivers call drm_debugfs_remove_files() in their drm_driver->debugfs_cleanup hook, do it automatically by traversing minor->debugfs_list.
Also use debugfs_remove_recursive() so drivers who add their own debugfs files don't have to keep track of them for removal.

Kernel before 4.11 don't clean debugfs files automatically.

Quoted 65 lines

-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Friday, August 11, 2017 4:15 PM
To: Wang, Annie <[email protected]>; Alex Deucher <[email protected]>
Cc: amd-gfx list <[email protected]>
Subject: Re: [PATCH] drm/amd/amdgpu: fix bug fail to remove debugfs when rmmod

Hi Annie,

well something is clearly not working as expected here.

All those files are registered with drm_debugfs_create_files() and should automatically be removed when drm_debugfs_cleanup() is called.

Can you figure out what is going wrong here?

Thanks,
Christian.

Am 11.08.2017 um 04:25 schrieb Wang, Annie:

Quoted 16 lines

Hi Alex,

The following files are all left.

amdgpu_fence_info
amdgpu_firmware_info
amdgpu_gem_info
amdgpu_gpu_reset
amdgpu_gtt_mm
amdgpu_pm_info
amdgpu_sa_info
amdgpu_test_ib
amdgpu_vram_mm
ttm_dma_page_pool
ttm_page_pool

Quoted 1 line

Instead of fini them separately, how about implement the callback function ---

debugfs_fini.

Quoted 25 lines

.debugfs_fini = amdgpu_debugfs_cleanup,

And in the future I will send another patch to collect all the init function
.debugfs_init = amdgpu_debugfs_init,

Quoted 19 lines

-----Original Message-----
From: Alex Deucher [mailto:[email protected]]
Sent: Friday, August 11, 2017 1:01 AM
To: Wang, Annie <[email protected]>
Cc: amd-gfx list <[email protected]>
Subject: Re: [PATCH] drm/amd/amdgpu: fix bug fail to remove debugfs when rmmod

Quoted 4 lines · Wang Hongcheng

Some debug files are forgotten to remove at fini. Remove them all in pci_remove.

BUG: SWDEV-129297

What files are failing to get removed? I'd prefer to remove them in the relevant places in the code (to mirror where they are added) rather than generically cleaning everything up. Either that or unify all the debugfs init/fini stuff in one place.

Quoted 81 lines
Quoted 6 lines
Quoted 6 lines

Alex

Quoted 4 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  2 ++
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 19

+++++++++++++++++++

Quoted 73 lines
Quoted 65 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_debugfs_add_files(struct

Quoted 23 lines
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    |  2 ++
  3 files changed, 23 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
index c28069e4..b542191 100644
@@ -1250,6 +1250,8 @@ struct amdgpu_debugfs {  int
 amdgpu_debugfs_add_files(struct amdgpu_device *adev,
                              const struct drm_info_list *files,
                              unsigned nfiles);
+int amdgpu_debugfs_cleanup(struct amdgpu_device *adev);
+
  int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
 
  #if defined(CONFIG_DEBUG_FS)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 7e40071..7594abb 100644
@@ -3215,6 +3215,25 @@ int amdgpu_debugfs_add_files(struct

amdgpu_device *adev,

Quoted 41 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +18 -0
         return 0;
  }
 
+int amdgpu_debugfs_cleanup(struct amdgpu_device *adev) {
+       struct drm_info_node *node, *tmp;
+
+       if (!&adev->ddev->primary->debugfs_root)
+               return 0;
+
+       mutex_lock(&adev->ddev->primary->debugfs_lock);
+       list_for_each_entry_safe(node, tmp,
+               &adev->ddev->primary->debugfs_list, list) {
+               debugfs_remove(node->dent);
+               list_del(&node->list);
+               kfree(node);
+       }
+       mutex_unlock(&adev->ddev->primary->debugfs_lock);
+
+       return 0;
+}
+
  #if defined(CONFIG_DEBUG_FS)
 
  static ssize_t amdgpu_debugfs_regs_read(struct file *f, char

__user *buf, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 13c91a6..4f5af93 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -1
@@ -594,7 +594,9 @@ static void
  amdgpu_pci_remove(struct pci_dev *pdev)  {
         struct drm_device *dev = pci_get_drvdata(pdev);
+       struct amdgpu_device *adev = dev->dev_private;
 
+       amdgpu_debugfs_cleanup(adev);
         drm_dev_unregister(dev);
         drm_dev_unref(dev);
  }
--

2.7.4

Quoted 4 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): MWHPR12MB1920D995AC95885ACA03CD66818D0-Gy0DoCVfaSXeXoETSPOSegdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#10 lore raw

Ok in this case I don't think we should do anything here.

That we can't rmmod the driver on pre 4.11 is a bit annoying, but doesn't affect the upstream driver.

Christian.

Am 15.08.2017 um 05:00 schrieb Wang, Annie:

Quoted 16 lines

Hi Christian,

Yes. drm_debugfs_cleanup() should delete all the files, after the following commit.

commit 086f2e5cde747dcae800b2d8b0ac7741a8c6fcbe

Author: Noralf Trønnes <[email protected]>
Date:   Thu Jan 26 23:56:03 2017 +0100

drm: debugfs: Remove all files automatically on cleanup

Instead of having the drivers call drm_debugfs_remove_files() in their drm_driver->debugfs_cleanup hook, do it automatically by traversing minor->debugfs_list.
Also use debugfs_remove_recursive() so drivers who add their own debugfs files don't have to keep track of them for removal.

Quoted 152 lines

Kernel before 4.11 don't clean debugfs files automatically.

Quoted 145 lines

-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Friday, August 11, 2017 4:15 PM
To: Wang, Annie <[email protected]>; Alex Deucher <[email protected]>
Cc: amd-gfx list <[email protected]>
Subject: Re: [PATCH] drm/amd/amdgpu: fix bug fail to remove debugfs when rmmod

Hi Annie,

well something is clearly not working as expected here.

All those files are registered with drm_debugfs_create_files() and should automatically be removed when drm_debugfs_cleanup() is called.

Can you figure out what is going wrong here?

Thanks,
Christian.

Am 11.08.2017 um 04:25 schrieb Wang, Annie:

Quoted 16 lines

Hi Alex,

The following files are all left.

amdgpu_fence_info
amdgpu_firmware_info
amdgpu_gem_info
amdgpu_gpu_reset
amdgpu_gtt_mm
amdgpu_pm_info
amdgpu_sa_info
amdgpu_test_ib
amdgpu_vram_mm
ttm_dma_page_pool
ttm_page_pool

Quoted 1 line

Instead of fini them separately, how about implement the callback function ---

debugfs_fini.

Quoted 31 lines

.debugfs_fini = amdgpu_debugfs_cleanup,

And in the future I will send another patch to collect all the init function
.debugfs_init = amdgpu_debugfs_init,

Quoted 25 lines

-----Original Message-----
From: Alex Deucher [mailto:[email protected]]
Sent: Friday, August 11, 2017 1:01 AM
To: Wang, Annie <[email protected]>
Cc: amd-gfx list <[email protected]>
Subject: Re: [PATCH] drm/amd/amdgpu: fix bug fail to remove debugfs when rmmod

Quoted 4 lines · Wang Hongcheng

Some debug files are forgotten to remove at fini. Remove them all in pci_remove.

BUG: SWDEV-129297

What files are failing to get removed? I'd prefer to remove them in the relevant places in the code (to mirror where they are added) rather than generically cleaning everything up. Either that or unify all the debugfs init/fini stuff in one place.

Alex

Quoted 4 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  2 ++
   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 19

+++++++++++++++++++

Quoted 73 lines
Quoted 65 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_debugfs_add_files(struct

Quoted 23 lines
   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    |  2 ++
   3 files changed, 23 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
index c28069e4..b542191 100644
@@ -1250,6 +1250,8 @@ struct amdgpu_debugfs {  int
 amdgpu_debugfs_add_files(struct amdgpu_device *adev,
                               const struct drm_info_list *files,
                               unsigned nfiles);
+int amdgpu_debugfs_cleanup(struct amdgpu_device *adev);
+
   int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
 
   #if defined(CONFIG_DEBUG_FS)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 7e40071..7594abb 100644
@@ -3215,6 +3215,25 @@ int amdgpu_debugfs_add_files(struct

amdgpu_device *adev,

Quoted 41 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +18 -0
          return 0;
   }
 
+int amdgpu_debugfs_cleanup(struct amdgpu_device *adev) {
+       struct drm_info_node *node, *tmp;
+
+       if (!&adev->ddev->primary->debugfs_root)
+               return 0;
+
+       mutex_lock(&adev->ddev->primary->debugfs_lock);
+       list_for_each_entry_safe(node, tmp,
+               &adev->ddev->primary->debugfs_list, list) {
+               debugfs_remove(node->dent);
+               list_del(&node->list);
+               kfree(node);
+       }
+       mutex_unlock(&adev->ddev->primary->debugfs_lock);
+
+       return 0;
+}
+
   #if defined(CONFIG_DEBUG_FS)
 
   static ssize_t amdgpu_debugfs_regs_read(struct file *f, char

__user *buf, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 13c91a6..4f5af93 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -1
@@ -594,7 +594,9 @@ static void
   amdgpu_pci_remove(struct pci_dev *pdev)  {
          struct drm_device *dev = pci_get_drvdata(pdev);
+       struct amdgpu_device *adev = dev->dev_private;
 
+       amdgpu_debugfs_cleanup(adev);
          drm_dev_unregister(dev);
          drm_dev_unref(dev);
   }
--

2.7.4

Quoted 4 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): bd183141-0bd2-81a6-f9f9-ae7bb6418287-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#12 lore raw
Quoted 4 lines · Christian König

Ok in this case I don't think we should do anything here.

That we can't rmmod the driver on pre 4.11 is a bit annoying, but doesn't affect the upstream driver.

This patch can be applied to the KCL for dkms.

Alex

Quoted 191 lines

Christian.

Am 15.08.2017 um 05:00 schrieb Wang, Annie:

Quoted 183 lines

Hi Christian,

Yes. drm_debugfs_cleanup() should delete all the files, after the following commit.

commit 086f2e5cde747dcae800b2d8b0ac7741a8c6fcbe

Author: Noralf Trønnes <[email protected]>
Date:   Thu Jan 26 23:56:03 2017 +0100

drm: debugfs: Remove all files automatically on cleanup

Instead of having the drivers call drm_debugfs_remove_files() in their drm_driver->debugfs_cleanup hook, do it automatically by traversing minor->debugfs_list.
Also use debugfs_remove_recursive() so drivers who add their own debugfs files don't have to keep track of them for removal.

Link:
http://patchwork.freedesktop.org/patch/msgid/[email protected]

Kernel before 4.11 don't clean debugfs files automatically.

Quoted 157 lines

-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Friday, August 11, 2017 4:15 PM
To: Wang, Annie <[email protected]>; Alex Deucher <[email protected]>
Cc: amd-gfx list <[email protected]>
Subject: Re: [PATCH] drm/amd/amdgpu: fix bug fail to remove debugfs when rmmod

Hi Annie,

well something is clearly not working as expected here.

All those files are registered with drm_debugfs_create_files() and should automatically be removed when drm_debugfs_cleanup() is called.

Can you figure out what is going wrong here?

Thanks,
Christian.

Am 11.08.2017 um 04:25 schrieb Wang, Annie:

Quoted 17 lines

Hi Alex,

The following files are all left.

amdgpu_fence_info
amdgpu_firmware_info
amdgpu_gem_info
amdgpu_gpu_reset
amdgpu_gtt_mm
amdgpu_pm_info
amdgpu_sa_info
amdgpu_test_ib
amdgpu_vram_mm
ttm_dma_page_pool
ttm_page_pool

Quoted 2 lines

Instead of fini them separately, how about implement the callback function ---

debugfs_fini.

Quoted 35 lines

.debugfs_fini = amdgpu_debugfs_cleanup,

And in the future I will send another patch to collect all the init function
.debugfs_init = amdgpu_debugfs_init,

Quoted 27 lines

-----Original Message-----
From: Alex Deucher [mailto:[email protected]]
Sent: Friday, August 11, 2017 1:01 AM
To: Wang, Annie <[email protected]>
Cc: amd-gfx list <[email protected]>
Subject: Re: [PATCH] drm/amd/amdgpu: fix bug fail to remove debugfs when rmmod

Quoted 5 lines · Wang Hongcheng

Some debug files are forgotten to remove at fini. Remove them all in pci_remove.

BUG: SWDEV-129297

What files are failing to get removed? I'd prefer to remove them in the relevant places in the code (to mirror where they are added) rather than generically cleaning everything up. Either that or unify all the debugfs init/fini stuff in one place.

Alex

Quoted 4 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  2 ++
   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 19

+++++++++++++++++++

Quoted 77 lines
Quoted 68 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_debugfs_add_files(struct

Quoted 24 lines
   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    |  2 ++
   3 files changed, 23 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
index c28069e4..b542191 100644
@@ -1250,6 +1250,8 @@ struct amdgpu_debugfs {  int
 amdgpu_debugfs_add_files(struct amdgpu_device *adev,
                               const struct drm_info_list *files,
                               unsigned nfiles);
+int amdgpu_debugfs_cleanup(struct amdgpu_device *adev);
+
   int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
 
   #if defined(CONFIG_DEBUG_FS)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 7e40071..7594abb 100644
@@ -3215,6 +3215,25 @@ int amdgpu_debugfs_add_files(struct

amdgpu_device *adev,

Quoted 42 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +18 -0
          return 0;
   }
 
+int amdgpu_debugfs_cleanup(struct amdgpu_device *adev) {
+       struct drm_info_node *node, *tmp;
+
+       if (!&adev->ddev->primary->debugfs_root)
+               return 0;
+
+       mutex_lock(&adev->ddev->primary->debugfs_lock);
+       list_for_each_entry_safe(node, tmp,
+               &adev->ddev->primary->debugfs_list, list) {
+               debugfs_remove(node->dent);
+               list_del(&node->list);
+               kfree(node);
+       }
+       mutex_unlock(&adev->ddev->primary->debugfs_lock);
+
+       return 0;
+}
+
   #if defined(CONFIG_DEBUG_FS)
 
   static ssize_t amdgpu_debugfs_regs_read(struct file *f, char

__user *buf, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 13c91a6..4f5af93 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -1
@@ -594,7 +594,9 @@ static void
   amdgpu_pci_remove(struct pci_dev *pdev)  {
          struct drm_device *dev = pci_get_drvdata(pdev);
+       struct amdgpu_device *adev = dev->dev_private;
 
+       amdgpu_debugfs_cleanup(adev);
          drm_dev_unregister(dev);
          drm_dev_unref(dev);
   }
--

2.7.4

Quoted 4 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx