Skip to contentSkip to conversation

drm/amdgpu: use DEFINE_DEBUGFS_ATTRIBUTE with debugfs_create_file_unsafe()

PATCH In review Deepak R Varma 7 participants 15 messages Oct 30, 2020 – Oct 31, 2020

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

PATCH 1/1 drm/amdgpu: use DEFINE_DEBUGFS_ATTRIBUTE with debugfs_create_file_unsafe()

Using DEFINE_DEBUGFS_ATTRIBUTE macro with debugfs_create_file_unsafe() function in place of the debugfs_create_file() function will make the file operation struct "reset" aware of the file's lifetime. Additional details here: https://lists.archive.carbon60.com/linux/kernel/2369498

Issue reported by Coccinelle script:
scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci

---
Please Note: This is a Outreachy project task patch.

 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +10 -10
index 2d125b8b15ee..f076b1ba7319 100644
@@ -1551,29 +1551,29 @@ static int amdgpu_debugfs_sclk_set(void *data, u64 val)
 	return 0;
 }
 
-DEFINE_SIMPLE_ATTRIBUTE(fops_ib_preempt, NULL,
-			amdgpu_debugfs_ib_preempt, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_ib_preempt, NULL,
+			 amdgpu_debugfs_ib_preempt, "%llu\n");
 
-DEFINE_SIMPLE_ATTRIBUTE(fops_sclk_set, NULL,
-			amdgpu_debugfs_sclk_set, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_sclk_set, NULL,
+			 amdgpu_debugfs_sclk_set, "%llu\n");
 
 int amdgpu_debugfs_init(struct amdgpu_device *adev)
 {
 	int r, i;
 
 	adev->debugfs_preempt =
-		debugfs_create_file("amdgpu_preempt_ib", 0600,
-				    adev_to_drm(adev)->primary->debugfs_root, adev,
-				    &fops_ib_preempt);
+		debugfs_create_file_unsafe("amdgpu_preempt_ib", 0600,
+					   adev_to_drm(adev)->primary->debugfs_root, adev,
+					   &fops_ib_preempt);
 	if (!(adev->debugfs_preempt)) {
 		DRM_ERROR("unable to create amdgpu_preempt_ib debugsfs file\n");
 		return -EIO;
 	}
 
 	adev->smu.debugfs_sclk =
-		debugfs_create_file("amdgpu_force_sclk", 0200,
-				    adev_to_drm(adev)->primary->debugfs_root, adev,
-				    &fops_sclk_set);
+		debugfs_create_file_unsafe("amdgpu_force_sclk", 0200,
+					   adev_to_drm(adev)->primary->debugfs_root, adev,
+					   &fops_sclk_set);
 	if (!(adev->smu.debugfs_sclk)) {
 		DRM_ERROR("unable to create amdgpu_set_sclk debugsfs file\n");
 		return -EIO;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 20 lines · Deepak R Varma

Using DEFINE_DEBUGFS_ATTRIBUTE macro with debugfs_create_file_unsafe() function in place of the debugfs_create_file() function will make the file operation struct "reset" aware of the file's lifetime. Additional details here: https://lists.archive.carbon60.com/linux/kernel/2369498

Issue reported by Coccinelle script:
scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci

---
Please Note: This is a Outreachy project task patch.

 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +0 -0
index 2d125b8b15ee..f076b1ba7319 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val) · line 1555

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +2 -2
@@ -1551,29 +1551,29 @@ static int amdgpu_debugfs_sclk_set(void *data, u64 val)
 	return 0;
 }
 
-DEFINE_SIMPLE_ATTRIBUTE(fops_ib_preempt, NULL,
-			amdgpu_debugfs_ib_preempt, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_ib_preempt, NULL,
+			 amdgpu_debugfs_ib_preempt, "%llu\n");

Are you sure this is ok? Do these devices need this additional "protection"? Do they have the problem that these macros were written for?

Same for the other patches you just submitted here, I think you need to somehow "prove" that these changes are necessary, checkpatch isn't able to determine this all the time.

thanks,

greg k-h

#2 lore raw
Quoted 33 lines · Greg KH
Quoted 20 lines · Deepak R Varma

Using DEFINE_DEBUGFS_ATTRIBUTE macro with debugfs_create_file_unsafe() function in place of the debugfs_create_file() function will make the file operation struct "reset" aware of the file's lifetime. Additional details here: https://lists.archive.carbon60.com/linux/kernel/2369498

Issue reported by Coccinelle script:
scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci

---
Please Note: This is a Outreachy project task patch.

 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +0 -0
index 2d125b8b15ee..f076b1ba7319 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val) · line 1555

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +2 -2
@@ -1551,29 +1551,29 @@ static int amdgpu_debugfs_sclk_set(void *data, u64 val)
 	return 0;
 }
 
-DEFINE_SIMPLE_ATTRIBUTE(fops_ib_preempt, NULL,
-			amdgpu_debugfs_ib_preempt, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_ib_preempt, NULL,
+			 amdgpu_debugfs_ib_preempt, "%llu\n");

Are you sure this is ok? Do these devices need this additional "protection"? Do they have the problem that these macros were written for?

Quoted 3 lines

Same for the other patches you just submitted here, I think you need to somehow "prove" that these changes are necessary, checkpatch isn't able to determine this all the time.

Hi Greg,
Based on my understanding, the current function debugfs_create_file() adds an overhead of lifetime managing proxy for such fop structs. This should be applicable to these set of drivers as well. Hence I think this change will be useful.

I will wait for comments from other experts for driver specific consideration / behavior.

Thanks,
drv

Quoted 4 lines

thanks,

greg k-h

maintainer
#3 lore raw

Am 30.10.20 um 08:57 schrieb Deepak R Varma:

Quoted 33 lines · Greg KH
Quoted 32 lines · Deepak R Varma
Quoted 20 lines

Using DEFINE_DEBUGFS_ATTRIBUTE macro with debugfs_create_file_unsafe()
function in place of the debugfs_create_file() function will make the
file operation struct "reset" aware of the file's lifetime. Additional
details here: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.archive.carbon60.com%2Flinux%2Fkernel%2F2369498&data=04%7C01%7Cchristian.koenig%40amd.com%7Cddd7a6ac8164415a639708d87ca97004%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637396414464384011%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=o6GOHvMxNMuOPlC4nhDyURCHBLqfQZhYQq%2BiIMt3D3s%3D&reserved=0

Issue reported by Coccinelle script:
scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci

---
Please Note: This is a Outreachy project task patch.

  drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 20 ++++++++++----------
  1 file changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +0 -0
index 2d125b8b15ee..f076b1ba7319 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val) · line 1555

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +2 -2
@@ -1551,29 +1551,29 @@ static int amdgpu_debugfs_sclk_set(void *data, u64 val)
  	return 0;
  }
 
-DEFINE_SIMPLE_ATTRIBUTE(fops_ib_preempt, NULL,
-			amdgpu_debugfs_ib_preempt, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_ib_preempt, NULL,
+			 amdgpu_debugfs_ib_preempt, "%llu\n");

Are you sure this is ok? Do these devices need this additional "protection"? Do they have the problem that these macros were written for?

Quoted 8 lines
Quoted 3 lines

Same for the other patches you just submitted here, I think you need to somehow "prove" that these changes are necessary, checkpatch isn't able to determine this all the time.

Hi Greg,
Based on my understanding, the current function debugfs_create_file() adds an overhead of lifetime managing proxy for such fop structs. This should be applicable to these set of drivers as well. Hence I think this change will be useful.

Well since this is only created once per device instance I don't really care about this little overhead.

But what exactly is debugfs doing or not doing here?

Regards,
Christian.

Quoted 11 lines

I will wait for comments from other experts for driver specific consideration / behavior.

Thanks,
drv

Quoted 3 lines

thanks,

greg k-h

#4 lore raw
Quoted 42 lines · Christian K�nig

Am 30.10.20 um 08:57 schrieb Deepak R Varma:

Quoted 32 lines · Greg KH
Quoted 31 lines · Deepak R Varma
Quoted 20 lines

Using DEFINE_DEBUGFS_ATTRIBUTE macro with debugfs_create_file_unsafe()
function in place of the debugfs_create_file() function will make the
file operation struct "reset" aware of the file's lifetime. Additional
details here: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.archive.carbon60.com%2Flinux%2Fkernel%2F2369498&data=04%7C01%7Cchristian.koenig%40amd.com%7Cddd7a6ac8164415a639708d87ca97004%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637396414464384011%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=o6GOHvMxNMuOPlC4nhDyURCHBLqfQZhYQq%2BiIMt3D3s%3D&reserved=0

Issue reported by Coccinelle script:
scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci

---
Please Note: This is a Outreachy project task patch.

  drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 20 ++++++++++----------
  1 file changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +0 -0
index 2d125b8b15ee..f076b1ba7319 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val) · line 1554

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +2 -2
@@ -1551,29 +1551,29 @@ static int amdgpu_debugfs_sclk_set(void *data, u64 val)
  	return 0;
  }
-DEFINE_SIMPLE_ATTRIBUTE(fops_ib_preempt, NULL,
-			amdgpu_debugfs_ib_preempt, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_ib_preempt, NULL,
+			 amdgpu_debugfs_ib_preempt, "%llu\n");

Are you sure this is ok? Do these devices need this additional "protection"? Do they have the problem that these macros were written for?

Quoted 8 lines
Quoted 3 lines

Same for the other patches you just submitted here, I think you need to somehow "prove" that these changes are necessary, checkpatch isn't able to determine this all the time.

Hi Greg,
Based on my understanding, the current function debugfs_create_file() adds an overhead of lifetime managing proxy for such fop structs. This should be applicable to these set of drivers as well. Hence I think this change will be useful.

Quoted 4 lines

Well since this is only created once per device instance I don't really care about this little overhead.

But what exactly is debugfs doing or not doing here?

It is trying to save drivers from having debugfs files open that point to memory that can go away at any time. For graphics devices, I doubt that is the case.

thanks,

greg k-h

#5 lore raw
Quoted 43 lines · Greg KH
Quoted 42 lines · Christian K�nig

Am 30.10.20 um 08:57 schrieb Deepak R Varma:

Quoted 40 lines · Greg KH
Quoted 31 lines · Deepak R Varma
Quoted 20 lines

Using DEFINE_DEBUGFS_ATTRIBUTE macro with debugfs_create_file_unsafe()
function in place of the debugfs_create_file() function will make the
file operation struct "reset" aware of the file's lifetime. Additional
details here: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.archive.carbon60.com%2Flinux%2Fkernel%2F2369498&data=04%7C01%7Cchristian.koenig%40amd.com%7Cddd7a6ac8164415a639708d87ca97004%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637396414464384011%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=o6GOHvMxNMuOPlC4nhDyURCHBLqfQZhYQq%2BiIMt3D3s%3D&reserved=0

Issue reported by Coccinelle script:
scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci

---
Please Note: This is a Outreachy project task patch.

  drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 20 ++++++++++----------
  1 file changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +0 -0
index 2d125b8b15ee..f076b1ba7319 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val) · line 1554

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +2 -2
@@ -1551,29 +1551,29 @@ static int amdgpu_debugfs_sclk_set(void *data, u64 val)
  	return 0;
  }
-DEFINE_SIMPLE_ATTRIBUTE(fops_ib_preempt, NULL,
-			amdgpu_debugfs_ib_preempt, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_ib_preempt, NULL,
+			 amdgpu_debugfs_ib_preempt, "%llu\n");

Are you sure this is ok? Do these devices need this additional "protection"? Do they have the problem that these macros were written for?

Quoted 3 lines

Same for the other patches you just submitted here, I think you need to somehow "prove" that these changes are necessary, checkpatch isn't able to determine this all the time.

Hi Greg,
Based on my understanding, the current function debugfs_create_file() adds an overhead of lifetime managing proxy for such fop structs. This should be applicable to these set of drivers as well. Hence I think this change will be useful.

Quoted 8 lines
Quoted 4 lines

Well since this is only created once per device instance I don't really care about this little overhead.

But what exactly is debugfs doing or not doing here?

It is trying to save drivers from having debugfs files open that point to memory that can go away at any time. For graphics devices, I doubt that is the case.

So for anything we add/remove we have two-stage cleanup

1. drm_dev_unregister (or drm_connector_unregisters, those are the only two hotunpluggable things we have) unregister all the uapi interfaces. This deletes all the sysfs and debugfs files.

2. Once all the references to the underlying object disappear from the kernel, we free up the data structure.

Now for chardev and similar uapi, we hold full references for open files. But for sysfs and debugfs we assume that those uapi layers will make sure that after we deleted the files in step 1 all access through these functions are guaranteed to have finished. If that's not the case, then we need to rework our refcounting and also refcount the underlying drm structure (drm_device or drm_connector) from sysfs/debugfs files.

Now I tried to look at the patch Deepak references, and I'm not really clear what changes. Or whether we made a wrong assumption previously about what debugfs/sysfs guarantee when we delete the files.
-Daniel

Quoted 4 lines

thanks,

greg k-h

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#6 lore raw
Quoted 69 lines · Daniel Vetter
Quoted 43 lines · Greg KH
Quoted 42 lines · Christian K�nig

Am 30.10.20 um 08:57 schrieb Deepak R Varma:

Quoted 40 lines · Greg KH
Quoted 31 lines · Deepak R Varma
Quoted 20 lines

Using DEFINE_DEBUGFS_ATTRIBUTE macro with debugfs_create_file_unsafe()
function in place of the debugfs_create_file() function will make the
file operation struct "reset" aware of the file's lifetime. Additional
details here: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.archive.carbon60.com%2Flinux%2Fkernel%2F2369498&data=04%7C01%7Cchristian.koenig%40amd.com%7Cddd7a6ac8164415a639708d87ca97004%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637396414464384011%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=o6GOHvMxNMuOPlC4nhDyURCHBLqfQZhYQq%2BiIMt3D3s%3D&reserved=0

Issue reported by Coccinelle script:
scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci

---
Please Note: This is a Outreachy project task patch.

  drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 20 ++++++++++----------
  1 file changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +0 -0
index 2d125b8b15ee..f076b1ba7319 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val) · line 1554

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +2 -2
@@ -1551,29 +1551,29 @@ static int amdgpu_debugfs_sclk_set(void *data, u64 val)
  	return 0;
  }
-DEFINE_SIMPLE_ATTRIBUTE(fops_ib_preempt, NULL,
-			amdgpu_debugfs_ib_preempt, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_ib_preempt, NULL,
+			 amdgpu_debugfs_ib_preempt, "%llu\n");

Are you sure this is ok? Do these devices need this additional "protection"? Do they have the problem that these macros were written for?

Quoted 3 lines

Same for the other patches you just submitted here, I think you need to somehow "prove" that these changes are necessary, checkpatch isn't able to determine this all the time.

Hi Greg,
Based on my understanding, the current function debugfs_create_file() adds an overhead of lifetime managing proxy for such fop structs. This should be applicable to these set of drivers as well. Hence I think this change will be useful.

Quoted 8 lines
Quoted 4 lines

Well since this is only created once per device instance I don't really care about this little overhead.

But what exactly is debugfs doing or not doing here?

It is trying to save drivers from having debugfs files open that point to memory that can go away at any time. For graphics devices, I doubt that is the case.

So for anything we add/remove we have two-stage cleanup

1. drm_dev_unregister (or drm_connector_unregisters, those are the only two hotunpluggable things we have) unregister all the uapi interfaces. This deletes all the sysfs and debugfs files.

2. Once all the references to the underlying object disappear from the kernel, we free up the data structure.

Now for chardev and similar uapi, we hold full references for open files. But for sysfs and debugfs we assume that those uapi layers will make sure that after we deleted the files in step 1 all access through these functions are guaranteed to have finished. If that's not the case, then we need to rework our refcounting and also refcount the underlying drm structure (drm_device or drm_connector) from sysfs/debugfs files.

Quoted 3 lines

Now I tried to look at the patch Deepak references, and I'm not really clear what changes. Or whether we made a wrong assumption previously about what debugfs/sysfs guarantee when we delete the files.

I read some more code and kerneldoc, and I still have no idea what this new _unsafe variant is used for. Only ones I've found seem to use debugfs_file_get/put like the normal variant, to protect against concurrently removed files due to hotunplug. Which is kinda what we've been expecting debugfs to do for us.

What's a use-case for _unsafe _without_ debugfs_file_get/put?

Decently confused me over here doesn't get this.
-Daniel

Quoted 11 lines

-Daniel

Quoted 4 lines

thanks,

greg k-h

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#7 lore raw
Quoted 80 lines · Daniel Vetter
Quoted 69 lines · Daniel Vetter
Quoted 43 lines · Greg KH
Quoted 42 lines · Christian K�nig

Am 30.10.20 um 08:57 schrieb Deepak R Varma:

Quoted 40 lines · Greg KH
Quoted 31 lines · Deepak R Varma
Quoted 20 lines

Using DEFINE_DEBUGFS_ATTRIBUTE macro with debugfs_create_file_unsafe()
function in place of the debugfs_create_file() function will make the
file operation struct "reset" aware of the file's lifetime. Additional
details here: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.archive.carbon60.com%2Flinux%2Fkernel%2F2369498&data=04%7C01%7Cchristian.koenig%40amd.com%7Cddd7a6ac8164415a639708d87ca97004%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637396414464384011%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=o6GOHvMxNMuOPlC4nhDyURCHBLqfQZhYQq%2BiIMt3D3s%3D&reserved=0

Issue reported by Coccinelle script:
scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci

---
Please Note: This is a Outreachy project task patch.

  drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 20 ++++++++++----------
  1 file changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +0 -0
index 2d125b8b15ee..f076b1ba7319 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val) · line 1554

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +2 -2
@@ -1551,29 +1551,29 @@ static int amdgpu_debugfs_sclk_set(void *data, u64 val)
  	return 0;
  }
-DEFINE_SIMPLE_ATTRIBUTE(fops_ib_preempt, NULL,
-			amdgpu_debugfs_ib_preempt, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_ib_preempt, NULL,
+			 amdgpu_debugfs_ib_preempt, "%llu\n");

Are you sure this is ok? Do these devices need this additional "protection"? Do they have the problem that these macros were written for?

Quoted 3 lines

Same for the other patches you just submitted here, I think you need to somehow "prove" that these changes are necessary, checkpatch isn't able to determine this all the time.

Hi Greg,
Based on my understanding, the current function debugfs_create_file() adds an overhead of lifetime managing proxy for such fop structs. This should be applicable to these set of drivers as well. Hence I think this change will be useful.

Quoted 8 lines
Quoted 4 lines

Well since this is only created once per device instance I don't really care about this little overhead.

But what exactly is debugfs doing or not doing here?

It is trying to save drivers from having debugfs files open that point to memory that can go away at any time. For graphics devices, I doubt that is the case.

So for anything we add/remove we have two-stage cleanup

1. drm_dev_unregister (or drm_connector_unregisters, those are the only two hotunpluggable things we have) unregister all the uapi interfaces. This deletes all the sysfs and debugfs files.

2. Once all the references to the underlying object disappear from the kernel, we free up the data structure.

Now for chardev and similar uapi, we hold full references for open files. But for sysfs and debugfs we assume that those uapi layers will make sure that after we deleted the files in step 1 all access through these functions are guaranteed to have finished. If that's not the case, then we need to rework our refcounting and also refcount the underlying drm structure (drm_device or drm_connector) from sysfs/debugfs files.

Quoted 3 lines

Now I tried to look at the patch Deepak references, and I'm not really clear what changes. Or whether we made a wrong assumption previously about what debugfs/sysfs guarantee when we delete the files.

I read some more code and kerneldoc, and I still have no idea what this new _unsafe variant is used for. Only ones I've found seem to use debugfs_file_get/put like the normal variant, to protect against concurrently removed files due to hotunplug. Which is kinda what we've been expecting debugfs to do for us.

Quoted 4 lines

What's a use-case for _unsafe _without_ debugfs_file_get/put?

Decently confused me over here doesn't get this.
-Daniel

Hi All,
Thank you for your comments. I was not anticipating this to be such a offbeat patch. Pardon my growing understanding.

Please suggest if I can evaluate the change proposed to confirm if this is a meaningful change.

Thank you again!
./drv

Quoted 17 lines
Quoted 12 lines

-Daniel

Quoted 4 lines

thanks,

greg k-h

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
maintainer
#8 lore raw
In reply to Greg KH

Am 30.10.20 um 09:25 schrieb Greg KH:

Quoted 42 lines · Christian König
Quoted 41 lines

Am 30.10.20 um 08:57 schrieb Deepak R Varma:

Quoted 40 lines · Greg KH
Quoted 31 lines · Deepak R Varma
Quoted 20 lines

Using DEFINE_DEBUGFS_ATTRIBUTE macro with debugfs_create_file_unsafe()
function in place of the debugfs_create_file() function will make the
file operation struct "reset" aware of the file's lifetime. Additional
details here: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.archive.carbon60.com%2Flinux%2Fkernel%2F2369498&data=04%7C01%7Cchristian.koenig%40amd.com%7Ce3fb2f2236f44f8779bc08d87cad3a2d%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637396430734542672%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=CuDnWSIacKfdcv6%2B00Q9mZ%2BAcXse5mlFpuSsBybZ%2Fww%3D&reserved=0

Issue reported by Coccinelle script:
scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci

---
Please Note: This is a Outreachy project task patch.

   drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 20 ++++++++++----------
   1 file changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +0 -0
index 2d125b8b15ee..f076b1ba7319 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val) · line 1554

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +2 -2
@@ -1551,29 +1551,29 @@ static int amdgpu_debugfs_sclk_set(void *data, u64 val)
   	return 0;
   }
-DEFINE_SIMPLE_ATTRIBUTE(fops_ib_preempt, NULL,
-			amdgpu_debugfs_ib_preempt, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_ib_preempt, NULL,
+			 amdgpu_debugfs_ib_preempt, "%llu\n");

Are you sure this is ok? Do these devices need this additional "protection"? Do they have the problem that these macros were written for?

Quoted 3 lines

Same for the other patches you just submitted here, I think you need to somehow "prove" that these changes are necessary, checkpatch isn't able to determine this all the time.

Hi Greg,
Based on my understanding, the current function debugfs_create_file() adds an overhead of lifetime managing proxy for such fop structs. This should be applicable to these set of drivers as well. Hence I think this change will be useful.

Quoted 7 lines
Quoted 4 lines

Well since this is only created once per device instance I don't really care about this little overhead.

But what exactly is debugfs doing or not doing here?

It is trying to save drivers from having debugfs files open that point to memory that can go away at any time. For graphics devices, I doubt that is the case.

Well we have somebody working on hot plug removal for dGPUs, but that is really not an issue here.

Even if our device are removed most of the debugfs files shouldn't be affected by that.

Thanks,
Christian.

Quoted 4 lines

thanks,

greg k-h

#9 lore raw
In reply to Deepak R Varma
Quoted 38 lines · Deepak R Varma
Quoted 33 lines · Greg KH
Quoted 20 lines · Deepak R Varma

Using DEFINE_DEBUGFS_ATTRIBUTE macro with debugfs_create_file_unsafe() function in place of the debugfs_create_file() function will make the file operation struct "reset" aware of the file's lifetime. Additional details here: https://lists.archive.carbon60.com/linux/kernel/2369498

Issue reported by Coccinelle script:
scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci

---
Please Note: This is a Outreachy project task patch.

 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +0 -0
index 2d125b8b15ee..f076b1ba7319 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val) · line 1555

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +2 -2
@@ -1551,29 +1551,29 @@ static int amdgpu_debugfs_sclk_set(void *data, u64 val)
 	return 0;
 }
 
-DEFINE_SIMPLE_ATTRIBUTE(fops_ib_preempt, NULL,
-			amdgpu_debugfs_ib_preempt, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_ib_preempt, NULL,
+			 amdgpu_debugfs_ib_preempt, "%llu\n");

Are you sure this is ok? Do these devices need this additional "protection"? Do they have the problem that these macros were written for?

Quoted 3 lines

Same for the other patches you just submitted here, I think you need to somehow "prove" that these changes are necessary, checkpatch isn't able to determine this all the time.

Quoted 5 lines

Hi Greg,
Based on my understanding, the current function debugfs_create_file() adds an overhead of lifetime managing proxy for such fop structs. This should be applicable to these set of drivers as well. Hence I think this change will be useful.

Why do these drivers need these changes? Are these files dynamically removed from the system at random times?

There is a reason we didn't just do a global search/replace for this in the kernel when the new functions were added, so I don't know why checkpatch is now saying it must be done.

thanks,

greg k-h

#10 lore raw
Quoted 51 lines · Greg KH,
Quoted 3 lines · Deepak R Varma
Quoted 2 lines · Greg KH
Quoted 1 line · Deepak R Varma

Using DEFINE_DEBUGFS_ATTRIBUTE macro with

debugfs_create_file_unsafe()

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

function in place of the debugfs_create_file() function will make the file operation struct "reset" aware of the file's lifetime.

Additional

Quoted 1 line
Quoted 1 line
Quoted 1 line

details here:

https://lists.archive.carbon60.com/linux/kernel/2369498

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Issue reported by Coccinelle script:
scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci

---
Please Note: This is a Outreachy project task patch.

 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 20

++++++++++----------

Quoted 3 lines
Quoted 3 lines

Review

Quoted 3 lines
 1 file changed, 10 insertions(+), 10 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c

Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void

Quoted 4 lines

index 2d125b8b15ee..f076b1ba7319 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +0 -0
@@ -1551,29 +1551,29 @@ static int amdgpu_debugfs_sclk_set(void

*data, u64 val)

Quoted 16 lines
Quoted 12 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val) · line 1555

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +2 -2
  return 0;
 }
 
-DEFINE_SIMPLE_ATTRIBUTE(fops_ib_preempt, NULL,
-                 amdgpu_debugfs_ib_preempt, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_ib_preempt, NULL,
+                  amdgpu_debugfs_ib_preempt, "%llu\n");

Are you sure this is ok? Do these devices need this additional "protection"? Do they have the problem that these macros were written for?

Quoted 3 lines

Same for the other patches you just submitted here, I think you need to somehow "prove" that these changes are necessary, checkpatch isn't able to determine this all the time.

Quoted 5 lines

Hi Greg,
Based on my understanding, the current function debugfs_create_file() adds an overhead of lifetime managing proxy for such fop structs. This should be applicable to these set of drivers as well. Hence I think this change will be useful.

Quoted 7 lines

Why do these drivers need these changes? Are these files dynamically removed from the system at random times?

There is a reason we didn't just do a global search/replace for this in the kernel when the new functions were added, so I don't know why checkpatch is now saying it must be done.

Hi,

Sorry to jump in on the thread this way, but what exactly does a 'lifetime managing proxy' for file operations mean? I am trying to understand how DEFINE_DEBUGFS_ATTRIBUTE changes things wrt debug_ fs file operations but can't find many resources. :(

Please let me know if I should be asking this in a different mailing list/irc instead.

The change seems to be suggested by a coccinelle script.

Regards,
Sumera

thanks,

Quoted 12 lines

greg k-h

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/outreachy-kernel/20201030080316.GA1612206%40kroah.com
.

#11 lore raw
Quoted 61 lines · Sumera Priyadarsini
Quoted 51 lines · Greg KH,
Quoted 3 lines · Deepak R Varma
Quoted 2 lines · Greg KH
Quoted 1 line · Deepak R Varma

Using DEFINE_DEBUGFS_ATTRIBUTE macro with

debugfs_create_file_unsafe()

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

function in place of the debugfs_create_file() function will make the file operation struct "reset" aware of the file's lifetime.

Additional

Quoted 1 line
Quoted 1 line
Quoted 1 line

details here:

https://lists.archive.carbon60.com/linux/kernel/2369498

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Issue reported by Coccinelle script:
scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci

---
Please Note: This is a Outreachy project task patch.

 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 20

++++++++++----------

Quoted 3 lines
Quoted 3 lines

Review

Quoted 3 lines
 1 file changed, 10 insertions(+), 10 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c

Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void

Quoted 4 lines

index 2d125b8b15ee..f076b1ba7319 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +0 -0
@@ -1551,29 +1551,29 @@ static int amdgpu_debugfs_sclk_set(void

*data, u64 val)

Quoted 16 lines
Quoted 12 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val) · line 1555

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +2 -2
  return 0;
 }
 
-DEFINE_SIMPLE_ATTRIBUTE(fops_ib_preempt, NULL,
-                 amdgpu_debugfs_ib_preempt, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_ib_preempt, NULL,
+                  amdgpu_debugfs_ib_preempt, "%llu\n");

Are you sure this is ok? Do these devices need this additional "protection"? Do they have the problem that these macros were written for?

Quoted 3 lines

Same for the other patches you just submitted here, I think you need to somehow "prove" that these changes are necessary, checkpatch isn't able to determine this all the time.

Quoted 5 lines

Hi Greg,
Based on my understanding, the current function debugfs_create_file() adds an overhead of lifetime managing proxy for such fop structs. This should be applicable to these set of drivers as well. Hence I think this change will be useful.

Quoted 7 lines

Why do these drivers need these changes? Are these files dynamically removed from the system at random times?

There is a reason we didn't just do a global search/replace for this in the kernel when the new functions were added, so I don't know why checkpatch is now saying it must be done.

Quoted 6 lines

Hi,

Sorry to jump in on the thread this way, but what exactly does a 'lifetime managing proxy' for file operations mean? I am trying to understand how DEFINE_DEBUGFS_ATTRIBUTE changes things wrt debug_ fs file operations but can't find many resources. :(

It means that the debugfs core can handle debugfs files being removed from the system while they are still open when they were created by a driver/module that is now unloaded from memory.

This is only an issue for drivers that manage devices that have unknown lifespans (i.e. they can be yanked out of the system at any time, and the memory for those debugfs files can be freed).

For the entire DRM/GPU subsystem, I strongly doubt this is the case.

Quoted 4 lines

Please let me know if I should be asking this in a different mailing list/irc instead.

The change seems to be suggested by a coccinelle script.

I know, and I don't think that script knows the nuances behind this, as, again, we would have just done a global search/replace for this when the debugfs fixes went into the kernel.

thanks,

greg k-h

#12 lore raw
Quoted 79 lines · Greg KH
Quoted 61 lines · Sumera Priyadarsini
Quoted 51 lines · Greg KH,
Quoted 3 lines · Deepak R Varma
Quoted 2 lines · Greg KH
Quoted 1 line · Deepak R Varma

Using DEFINE_DEBUGFS_ATTRIBUTE macro with

debugfs_create_file_unsafe()

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

function in place of the debugfs_create_file() function will make the file operation struct "reset" aware of the file's lifetime.

Additional

Quoted 1 line
Quoted 1 line
Quoted 1 line

details here:

https://lists.archive.carbon60.com/linux/kernel/2369498

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Issue reported by Coccinelle script:
scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci

---
Please Note: This is a Outreachy project task patch.

 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 20

++++++++++----------

Quoted 3 lines
Quoted 3 lines

Review

Quoted 3 lines
 1 file changed, 10 insertions(+), 10 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c

Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void

Quoted 4 lines

index 2d125b8b15ee..f076b1ba7319 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +0 -0
@@ -1551,29 +1551,29 @@ static int amdgpu_debugfs_sclk_set(void

*data, u64 val)

Quoted 16 lines
Quoted 12 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val) · line 1555

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +2 -2
  return 0;
 }
 
-DEFINE_SIMPLE_ATTRIBUTE(fops_ib_preempt, NULL,
-                 amdgpu_debugfs_ib_preempt, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_ib_preempt, NULL,
+                  amdgpu_debugfs_ib_preempt, "%llu\n");

Are you sure this is ok? Do these devices need this additional "protection"? Do they have the problem that these macros were written for?

Quoted 3 lines

Same for the other patches you just submitted here, I think you need to somehow "prove" that these changes are necessary, checkpatch isn't able to determine this all the time.

Quoted 5 lines

Hi Greg,
Based on my understanding, the current function debugfs_create_file() adds an overhead of lifetime managing proxy for such fop structs. This should be applicable to these set of drivers as well. Hence I think this change will be useful.

Quoted 7 lines

Why do these drivers need these changes? Are these files dynamically removed from the system at random times?

There is a reason we didn't just do a global search/replace for this in the kernel when the new functions were added, so I don't know why checkpatch is now saying it must be done.

Quoted 6 lines

Hi,

Sorry to jump in on the thread this way, but what exactly does a 'lifetime managing proxy' for file operations mean? I am trying to understand how DEFINE_DEBUGFS_ATTRIBUTE changes things wrt debug_ fs file operations but can't find many resources. :(

It means that the debugfs core can handle debugfs files being removed from the system while they are still open when they were created by a driver/module that is now unloaded from memory.

This is only an issue for drivers that manage devices that have unknown lifespans (i.e. they can be yanked out of the system at any time, and the memory for those debugfs files can be freed).

For the entire DRM/GPU subsystem, I strongly doubt this is the case.

Quoted 8 lines
Quoted 4 lines

Please let me know if I should be asking this in a different mailing list/irc instead.

The change seems to be suggested by a coccinelle script.

I know, and I don't think that script knows the nuances behind this, as, again, we would have just done a global search/replace for this when the debugfs fixes went into the kernel.

The script comes from Nicolai Stange <[email protected]>.

If there are some precise considerations that make the change likely to be useful, then the script can be changed.

If the script is not helpful, then it can be removed.

julia

Quoted 10 lines

thanks,

greg k-h

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20201030082425.GA1619669%40kroah.com.

#13 lore raw
In reply to Greg KH
Quoted 10 lines · Greg KH
Quoted 9 lines · Deepak R Varma
Quoted 8 lines · Greg KH
Quoted 7 lines · Deepak R Varma

Using DEFINE_DEBUGFS_ATTRIBUTE macro with debugfs_create_file_unsafe() function in place of the debugfs_create_file() function will make the file operation struct "reset" aware of the file's lifetime. Additional details here: https://lists.archive.carbon60.com/linux/kernel/2369498

Issue reported by Coccinelle script:
scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci

[]

Quoted 3 lines

There is a reason we didn't just do a global search/replace for this in the kernel when the new functions were added, so I don't know why checkpatch is now saying it must be done.

I think it's not a checkpatch warning here.

#14 lore raw
Quoted 9 lines · Joe Perches
Quoted 8 lines · Greg KH
Quoted 7 lines · Deepak R Varma
Quoted 6 lines · Greg KH
Quoted 5 lines · Deepak R Varma

Using DEFINE_DEBUGFS_ATTRIBUTE macro with debugfs_create_file_unsafe() function in place of the debugfs_create_file() function will make the file operation struct "reset" aware of the file's lifetime. Additional details here: https://lists.archive.carbon60.com/linux/kernel/2369498

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Issue reported by Coccinelle script:
scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci

[]

Quoted 3 lines

There is a reason we didn't just do a global search/replace for this in the kernel when the new functions were added, so I don't know why checkpatch is now saying it must be done.

I think it's not a checkpatch warning here.

That is correct, it's a coccinelle script.

julia

Quoted 6 lines

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/0b818156537f354904938f437cbb9dd02e765653.camel%40perches.com.