All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH libdrm v2 1/3] amdgpu: Take lock before removing devices from fd_tab hash table.
@ 2018-05-18 17:00 Jan Vesely
       [not found] ` <20180518170007.2847-1-jan.vesely-kgbqMDwikbSVc3sceRu5cw@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Vesely @ 2018-05-18 17:00 UTC (permalink / raw)
  To: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Close the file descriptors under lock as well.
v2: close fds after removing from hash table

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
---
 amdgpu/amdgpu_device.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c
index 983b19ab..e23dd3b3 100644
--- a/amdgpu/amdgpu_device.c
+++ b/amdgpu/amdgpu_device.c
@@ -126,6 +126,13 @@ static int amdgpu_get_auth(int fd, int *auth)
 
 static void amdgpu_device_free_internal(amdgpu_device_handle dev)
 {
+	pthread_mutex_lock(&fd_mutex);
+	util_hash_table_remove(fd_tab, UINT_TO_PTR(dev->fd));
+	close(dev->fd);
+	if ((dev->flink_fd >= 0) && (dev->fd != dev->flink_fd))
+		close(dev->flink_fd);
+	pthread_mutex_unlock(&fd_mutex);
+
 	amdgpu_vamgr_deinit(&dev->vamgr_32);
 	amdgpu_vamgr_deinit(&dev->vamgr);
 	amdgpu_vamgr_deinit(&dev->vamgr_high_32);
@@ -133,10 +140,6 @@ static void amdgpu_device_free_internal(amdgpu_device_handle dev)
 	util_hash_table_destroy(dev->bo_flink_names);
 	util_hash_table_destroy(dev->bo_handles);
 	pthread_mutex_destroy(&dev->bo_table_mutex);
-	util_hash_table_remove(fd_tab, UINT_TO_PTR(dev->fd));
-	close(dev->fd);
-	if ((dev->flink_fd >= 0) && (dev->fd != dev->flink_fd))
-		close(dev->flink_fd);
 	free(dev->marketing_name);
 	free(dev);
 }
-- 
2.17.0

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

* [PATCH libdrm 2/3] amdgpu/util_hash_table: Add helper function to count the number of entries in hash table
       [not found] ` <20180518170007.2847-1-jan.vesely-kgbqMDwikbSVc3sceRu5cw@public.gmane.org>
@ 2018-05-18 17:00   ` Jan Vesely
  2018-05-18 17:00   ` [PATCH libdrm 3/3] amdgpu: Destroy fd_hash table when the last device is removed Jan Vesely
  1 sibling, 0 replies; 4+ messages in thread
From: Jan Vesely @ 2018-05-18 17:00 UTC (permalink / raw)
  To: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Analogous to the mesa commit of the same name.
Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
---
 amdgpu/util_hash_table.c | 12 ++++++++++++
 amdgpu/util_hash_table.h |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/amdgpu/util_hash_table.c b/amdgpu/util_hash_table.c
index 89a8bf9b..e06d4415 100644
--- a/amdgpu/util_hash_table.c
+++ b/amdgpu/util_hash_table.c
@@ -237,6 +237,18 @@ drm_private void util_hash_table_foreach(struct util_hash_table *ht,
 	}
 }
 
+static void util_hash_table_inc(void *k, void *v, void *d)
+{
+	++*(size_t *)d;
+}
+
+drm_private size_t util_hash_table_count(struct util_hash_table *ht)
+{
+	size_t count = 0;
+	util_hash_table_foreach(ht, util_hash_table_inc, &count);
+	return count;
+}
+
 drm_private void util_hash_table_destroy(struct util_hash_table *ht)
 {
 	struct util_hash_iter iter;
diff --git a/amdgpu/util_hash_table.h b/amdgpu/util_hash_table.h
index 5e295a81..3ab81a12 100644
--- a/amdgpu/util_hash_table.h
+++ b/amdgpu/util_hash_table.h
@@ -64,6 +64,8 @@ drm_private void util_hash_table_foreach(struct util_hash_table *ht,
 			void (*callback)(void *key, void *value, void *data),
 			void *data);
 
+drm_private size_t util_hash_table_count(struct util_hash_table *ht);
+
 drm_private void util_hash_table_destroy(struct util_hash_table *ht);
 
 #endif /* U_HASH_TABLE_H_ */
-- 
2.17.0

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

* [PATCH libdrm 3/3] amdgpu: Destroy fd_hash table when the last device is removed.
       [not found] ` <20180518170007.2847-1-jan.vesely-kgbqMDwikbSVc3sceRu5cw@public.gmane.org>
  2018-05-18 17:00   ` [PATCH libdrm 2/3] amdgpu/util_hash_table: Add helper function to count the number of entries in " Jan Vesely
@ 2018-05-18 17:00   ` Jan Vesely
       [not found]     ` <20180518170007.2847-3-jan.vesely-kgbqMDwikbSVc3sceRu5cw@public.gmane.org>
  1 sibling, 1 reply; 4+ messages in thread
From: Jan Vesely @ 2018-05-18 17:00 UTC (permalink / raw)
  To: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Fixes memory leak on module unload.
Analogous to mesa commit of the same name.
Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
---
 amdgpu/amdgpu_device.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c
index e23dd3b3..34ac95b8 100644
--- a/amdgpu/amdgpu_device.c
+++ b/amdgpu/amdgpu_device.c
@@ -128,6 +128,10 @@ static void amdgpu_device_free_internal(amdgpu_device_handle dev)
 {
 	pthread_mutex_lock(&fd_mutex);
 	util_hash_table_remove(fd_tab, UINT_TO_PTR(dev->fd));
+	if (util_hash_table_count(fd_tab) == 0) {
+		util_hash_table_destroy(fd_tab);
+		fd_tab = NULL;
+	}
 	close(dev->fd);
 	if ((dev->flink_fd >= 0) && (dev->fd != dev->flink_fd))
 		close(dev->flink_fd);
-- 
2.17.0

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

* Re: [PATCH libdrm 3/3] amdgpu: Destroy fd_hash table when the last device is removed.
       [not found]     ` <20180518170007.2847-3-jan.vesely-kgbqMDwikbSVc3sceRu5cw@public.gmane.org>
@ 2018-05-24 17:04       ` Jan Vesely
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Vesely @ 2018-05-24 17:04 UTC (permalink / raw)
  To: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW


[-- Attachment #1.1: Type: text/plain, Size: 903 bytes --]

On Fri, 2018-05-18 at 13:00 -0400, Jan Vesely wrote:
> Fixes memory leak on module unload.
> Analogous to mesa commit of the same name.
> Signed-off-by: Jan Vesely <jan.vesely-kgbqMDwikbSVc3sceRu5cw@public.gmane.org>
> ---
>  amdgpu/amdgpu_device.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c
> index e23dd3b3..34ac95b8 100644
> --- a/amdgpu/amdgpu_device.c
> +++ b/amdgpu/amdgpu_device.c
> @@ -128,6 +128,10 @@ static void amdgpu_device_free_internal(amdgpu_device_handle dev)
>  {
>  	pthread_mutex_lock(&fd_mutex);
>  	util_hash_table_remove(fd_tab, UINT_TO_PTR(dev->fd));
> +	if (util_hash_table_count(fd_tab) == 0) {
> +		util_hash_table_destroy(fd_tab);
> +		fd_tab = NULL;
> +	}
>  	close(dev->fd);
>  	if ((dev->flink_fd >= 0) && (dev->fd != dev->flink_fd))
>  		close(dev->flink_fd);

gentle ping.

Jan

[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 154 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

end of thread, other threads:[~2018-05-24 17:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-18 17:00 [PATCH libdrm v2 1/3] amdgpu: Take lock before removing devices from fd_tab hash table Jan Vesely
     [not found] ` <20180518170007.2847-1-jan.vesely-kgbqMDwikbSVc3sceRu5cw@public.gmane.org>
2018-05-18 17:00   ` [PATCH libdrm 2/3] amdgpu/util_hash_table: Add helper function to count the number of entries in " Jan Vesely
2018-05-18 17:00   ` [PATCH libdrm 3/3] amdgpu: Destroy fd_hash table when the last device is removed Jan Vesely
     [not found]     ` <20180518170007.2847-3-jan.vesely-kgbqMDwikbSVc3sceRu5cw@public.gmane.org>
2018-05-24 17:04       ` Jan Vesely

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.