All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: Fix reference leak in psp_xgmi_reflect_topology_info()
@ 2021-12-09  6:36 ` Jianglei Nie
  0 siblings, 0 replies; 4+ messages in thread
From: Jianglei Nie @ 2021-12-09  6:36 UTC (permalink / raw)
  To: alexander.deucher, christian.koenig, Xinhui.Pan, airlied, daniel,
	Hawking.Zhang, john.clements, candice.li, lijo.lazar, Jinzhou.Su,
	jonathan.kim
  Cc: amd-gfx, dri-devel, linux-kernel, Jianglei Nie

In line 1138 (#1), amdgpu_get_xgmi_hive() increases the kobject reference
counter of the hive it returned. The hive returned by
amdgpu_get_xgmi_hive()should be released with the help of
amdgpu_put_xgmi_hive() to balance its kobject reference counter properly.
Forgetting the amdgpu_put_xgmi_hive() operation will result in reference
leak.

We can fix it by calling amdgpu_put_xgmi_hive() before the end of the
function (#2).

1128 static void psp_xgmi_reflect_topology_info(struct psp_context *psp,
1129 			struct psp_xgmi_node_info node_info)
1130 {

1138 	hive = amdgpu_get_xgmi_hive(psp->adev);
	// #1: kzalloc space reference increment
1139 	list_for_each_entry(mirror_adev, &hive->device_list, gmc.xgmi.head) {
1140		struct psp_xgmi_topology_info *mirror_top_info;
1141		int j;

1143		if (mirror_adev->gmc.xgmi.node_id != dst_node_id)
1144			continue;

1146		mirror_top_info = &mirror_adev->psp.xgmi_context.top_info;
1147		for (j = 0; j < mirror_top_info->num_nodes; j++) {
1148			if (mirror_top_info->nodes[j].node_id != src_node_id)
1149				continue;

1151			mirror_top_info->nodes[j].num_hops = dst_num_hops;

1157			if (dst_num_links)
1158				mirror_top_info->nodes[j].num_links = dst_num_links;

1160			break;
1161		}

1163		break;
1164	}
	// #2: missing reference decrement
1165 }

Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index c641f84649d6..f6362047ed71 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -1162,6 +1162,7 @@ static void psp_xgmi_reflect_topology_info(struct psp_context *psp,
 
 		break;
 	}
+	amdgpu_put_xgmi_hive(hive);
 }
 
 int psp_xgmi_get_topology_info(struct psp_context *psp,
-- 
2.25.1


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

* [PATCH] drm/amdgpu: Fix reference leak in psp_xgmi_reflect_topology_info()
@ 2021-12-09  6:36 ` Jianglei Nie
  0 siblings, 0 replies; 4+ messages in thread
From: Jianglei Nie @ 2021-12-09  6:36 UTC (permalink / raw)
  To: alexander.deucher, christian.koenig, Xinhui.Pan, airlied, daniel,
	Hawking.Zhang, john.clements, candice.li, lijo.lazar, Jinzhou.Su,
	jonathan.kim
  Cc: Jianglei Nie, dri-devel, amd-gfx, linux-kernel

In line 1138 (#1), amdgpu_get_xgmi_hive() increases the kobject reference
counter of the hive it returned. The hive returned by
amdgpu_get_xgmi_hive()should be released with the help of
amdgpu_put_xgmi_hive() to balance its kobject reference counter properly.
Forgetting the amdgpu_put_xgmi_hive() operation will result in reference
leak.

We can fix it by calling amdgpu_put_xgmi_hive() before the end of the
function (#2).

1128 static void psp_xgmi_reflect_topology_info(struct psp_context *psp,
1129 			struct psp_xgmi_node_info node_info)
1130 {

1138 	hive = amdgpu_get_xgmi_hive(psp->adev);
	// #1: kzalloc space reference increment
1139 	list_for_each_entry(mirror_adev, &hive->device_list, gmc.xgmi.head) {
1140		struct psp_xgmi_topology_info *mirror_top_info;
1141		int j;

1143		if (mirror_adev->gmc.xgmi.node_id != dst_node_id)
1144			continue;

1146		mirror_top_info = &mirror_adev->psp.xgmi_context.top_info;
1147		for (j = 0; j < mirror_top_info->num_nodes; j++) {
1148			if (mirror_top_info->nodes[j].node_id != src_node_id)
1149				continue;

1151			mirror_top_info->nodes[j].num_hops = dst_num_hops;

1157			if (dst_num_links)
1158				mirror_top_info->nodes[j].num_links = dst_num_links;

1160			break;
1161		}

1163		break;
1164	}
	// #2: missing reference decrement
1165 }

Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index c641f84649d6..f6362047ed71 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -1162,6 +1162,7 @@ static void psp_xgmi_reflect_topology_info(struct psp_context *psp,
 
 		break;
 	}
+	amdgpu_put_xgmi_hive(hive);
 }
 
 int psp_xgmi_get_topology_info(struct psp_context *psp,
-- 
2.25.1


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

* [PATCH] drm/amdgpu: Fix reference leak in psp_xgmi_reflect_topology_info()
@ 2022-06-07  7:12 ` Jianglei Nie
  0 siblings, 0 replies; 4+ messages in thread
From: Jianglei Nie @ 2022-06-07  7:12 UTC (permalink / raw)
  To: alexander.deucher, christian.koenig, Xinhui.Pan, airlied, daniel,
	Hawking.Zhang, john.clements, candice.li, Likun.Gao
  Cc: amd-gfx, dri-devel, linux-kernel, Jianglei Nie

amdgpu_get_xgmi_hive() increases the kobject reference counter of the
hive it returned. The hive returned by amdgpu_get_xgmi_hive() should be
released with the help of amdgpu_put_xgmi_hive() to balance its kobject
reference counter properly. Forgetting the amdgpu_put_xgmi_hive()
operation will result in reference leak.

We can fix it by calling amdgpu_put_xgmi_hive() before the end of the
function.

Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index e9411c28d88b..7b3a78da1684 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -1292,6 +1292,7 @@ static void psp_xgmi_reflect_topology_info(struct psp_context *psp,
 
 		break;
 	}
+	amdgpu_put_xgmi_hive(hive);
 }
 
 int psp_xgmi_get_topology_info(struct psp_context *psp,
-- 
2.25.1


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

* [PATCH] drm/amdgpu: Fix reference leak in psp_xgmi_reflect_topology_info()
@ 2022-06-07  7:12 ` Jianglei Nie
  0 siblings, 0 replies; 4+ messages in thread
From: Jianglei Nie @ 2022-06-07  7:12 UTC (permalink / raw)
  To: alexander.deucher, christian.koenig, Xinhui.Pan, airlied, daniel,
	Hawking.Zhang, john.clements, candice.li, Likun.Gao
  Cc: Jianglei Nie, dri-devel, amd-gfx, linux-kernel

amdgpu_get_xgmi_hive() increases the kobject reference counter of the
hive it returned. The hive returned by amdgpu_get_xgmi_hive() should be
released with the help of amdgpu_put_xgmi_hive() to balance its kobject
reference counter properly. Forgetting the amdgpu_put_xgmi_hive()
operation will result in reference leak.

We can fix it by calling amdgpu_put_xgmi_hive() before the end of the
function.

Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index e9411c28d88b..7b3a78da1684 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -1292,6 +1292,7 @@ static void psp_xgmi_reflect_topology_info(struct psp_context *psp,
 
 		break;
 	}
+	amdgpu_put_xgmi_hive(hive);
 }
 
 int psp_xgmi_get_topology_info(struct psp_context *psp,
-- 
2.25.1


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

end of thread, other threads:[~2022-06-07  7:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-09  6:36 [PATCH] drm/amdgpu: Fix reference leak in psp_xgmi_reflect_topology_info() Jianglei Nie
2021-12-09  6:36 ` Jianglei Nie
2022-06-07  7:12 Jianglei Nie
2022-06-07  7:12 ` Jianglei Nie

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.