drm: Branch 'master' - 3 commits

[email protected] (Jan Vesely) Fri, 25 May 2018 16:26:24 +0000 (UTC)
Newsgroups gmane.comp.video.dri.patches
Message-ID <[email protected]>
 amdgpu/amdgpu_device.c   |   15 +++++++++++----
 amdgpu/util_hash_table.c |   12 ++++++++++++
 amdgpu/util_hash_table.h |    2 ++
 3 files changed, 25 insertions(+), 4 deletions(-)

New commits:
commit c1f2d9b900e30119bcf6f88c0d11a0dd620fd060
Author: Jan Vesely <[email protected]>
Date:   Fri May 18 11:39:15 2018 -0400

    amdgpu: Destroy fd_hash table when the last device is removed.
    
    Fixes memory leak on module unload.
    Analogous to mesa commit of the same name.
    Signed-off-by: Jan Vesely <[email protected]>
    Reviewed-by: Michel Dänzer <[email protected]>
    Reviewed-by: Alex Deucher <[email protected]>

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);
commit 52ef6fbaf1962dac2a8b75078c20d65da90cfe8d
Author: Jan Vesely <[email protected]>
Date:   Fri May 18 11:36:20 2018 -0400

    amdgpu/util_hash_table: Add helper function to count the number of entries in hash table
    
    Analogous to the mesa commit of the same name.
    Signed-off-by: Jan Vesely <[email protected]>
    Reviewed-by: Michel Dänzer <[email protected]>
    Reviewed-by: Alex Deucher <[email protected]>

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_ */
commit 712fa0f3f420a7b9b42ae6d6fcb513aca97d541d
Author: Jan Vesely <[email protected]>
Date:   Thu May 10 19:22:17 2018 -0400

    amdgpu: Take a lock before removing devices from fd_tab hash table.
    
    Close the file descriptors under lock as well.
    v2: close fds after removing from hash table
    
    Signed-off-by: Jan Vesely <[email protected]>
    Reviewed-by: Michel Dänzer <[email protected]>
    Reviewed-by: Alex Deucher <[email protected]>

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);
 }

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
--
_______________________________________________
Dri-patches mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dri-patches