All of lore.kernel.org
 help / color / mirror / Atom feed
* [RESEND PATCH] drm/amdgpu: Unwind UALink peer GART mappings on sw_init failure
@ 2026-11-30 14:50 Lin Huiyi
  2026-11-30 14:58 ` sashiko-bot
  2026-11-30 15:11 ` Philip Yang
  0 siblings, 2 replies; 5+ messages in thread
From: Lin Huiyi @ 2026-11-30 14:50 UTC (permalink / raw)
  To: alexander.deucher, christian.koenig
  Cc: airlied, simona, Philip.Yang, amd-gfx, dri-devel, Lin Huiyi

amdgpu_ualink_peer_remote_init() maps a set of GART ranges for every
remote peer. If one of the amdgpu_ualink_gart_map() calls fails, it
breaks out of the loop and returns an error, but the mappings created
for the peers processed so far are left behind.

amdgpu_ualink_sw_init() then takes the out_sdma_entities_fini path, which
only tears down the SDMA entities and frees the remote structure without
calling amdgpu_ualink_peer_remote_fini(). The already-allocated
drm_mm_nodes stay registered in the shared GTT manager after the memory
that tracked them is gone, corrupting the drm_mm state and leaking GART
space on every failed activation.

Fix this by calling amdgpu_ualink_peer_remote_fini() on the error path.
Move the peer mutex initialization ahead of the fallible mappings so that
fini can safely destroy the locks even when only some peers were mapped;
gart_unmap() already ignores unallocated nodes.

Fixes: 6e3834ceaf2f ("drm/amdgpu: Add UALink cross-GPU TLB shootdown and remote interrupt")
Signed-off-by: Lin Huiyi <xinghui79@qq.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
index b4fac5ecab..74c9e72727 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
@@ -6186,6 +6186,12 @@ static int amdgpu_ualink_peer_remote_init(struct amdgpu_device *adev)
 	dev_dbg(adev->dev, "src_accel_id %u gart mapping flags 0x%llx\n",
 		src_accel_id, flags);
 
+	/* Initialize all locks before any fallible mapping so fini can unwind. */
+	for_each_set_bit(dst_accel_id, remote->active_accel_bits, AMDGPU_UALINK_ACCEL_MAX) {
+		if (dst_accel_id != src_accel_id)
+			mutex_init(&remote->peer[dst_accel_id].lock);
+	}
+
 	for_each_set_bit(dst_accel_id, remote->active_accel_bits, AMDGPU_UALINK_ACCEL_MAX) {
 		if (dst_accel_id == src_accel_id)
 			continue;
@@ -6193,7 +6199,6 @@ static int amdgpu_ualink_peer_remote_init(struct amdgpu_device *adev)
 		dev_dbg(adev->dev, "peer_remote to dst_accel_id %u\n", dst_accel_id);
 
 		peer = &remote->peer[dst_accel_id];
-		mutex_init(&peer->lock);
 
 		interrupt = &peer->interrupt;
 		shootdown = &peer->shootdown;
@@ -6353,11 +6358,13 @@ int amdgpu_ualink_sw_init(struct amdgpu_device *adev)
 
 	r = amdgpu_ualink_peer_remote_init(adev);
 	if (r)
-		goto out_sdma_entities_fini;
+		goto out_peer_remote_fini;
 
 	dev_dbg(adev->dev, "ualink sw init succeed\n");
 	return 0;
 
+out_peer_remote_fini:
+	amdgpu_ualink_peer_remote_fini(adev);
 out_sdma_entities_fini:
 	amdgpu_ualink_sdma_entities_fini(adev);
 out_npa_unmap:
-- 
2.56.1


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

* Re: [RESEND PATCH] drm/amdgpu: Unwind UALink peer GART mappings on sw_init failure
  2026-11-30 14:50 [RESEND PATCH] drm/amdgpu: Unwind UALink peer GART mappings on sw_init failure Lin Huiyi
@ 2026-11-30 14:58 ` sashiko-bot
  2026-11-30 15:11 ` Philip Yang
  1 sibling, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-30 14:58 UTC (permalink / raw)
  To: Lin Huiyi; +Cc: amd-gfx, dri-devel

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/amdgpu: unused label out_sdma_entities_fini in
  amdgpu_ualink_sw_init()
--

commit b9e3288ae5fab2693604cd2fa96cf9a0518f82d8
Author: Lin Huiyi <xinghui79@qq.com>

drm/amdgpu: Unwind UALink peer GART mappings on sw_init failure

This commit initializes all peer mutexes before mapping GART ranges and
calls amdgpu_ualink_peer_remote_fini() on the amdgpu_ualink_sw_init()
failure path so partially created peer GART mappings are unwound.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> index fa4c3d27d2720..cf794c0feb3df 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c

[ ... ]

> @@ -6345,11 +6350,13 @@ int amdgpu_ualink_sw_init(struct amdgpu_device *adev)
>  
>  	r = amdgpu_ualink_peer_remote_init(adev);
>  	if (r)
> -		goto out_sdma_entities_fini;
> +		goto out_peer_remote_fini;
>  
>  	dev_dbg(adev->dev, "ualink sw init succeed\n");
>  	return 0;
>  
> +out_peer_remote_fini:
> +	amdgpu_ualink_peer_remote_fini(adev);
>  out_sdma_entities_fini:
>  	amdgpu_ualink_sdma_entities_fini(adev);
>  out_npa_unmap:

[Severity: Medium]
Does replacing the only jump to out_sdma_entities_fini leave that label
unused, triggering a -Wunused-label warning (and a build failure with
WERROR enabled)?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_676B6B489057421A3AB8F3CC598DA5743607@qq.com?part=1

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

* Re: [RESEND PATCH] drm/amdgpu: Unwind UALink peer GART mappings on sw_init failure
  2026-11-30 14:50 [RESEND PATCH] drm/amdgpu: Unwind UALink peer GART mappings on sw_init failure Lin Huiyi
  2026-11-30 14:58 ` sashiko-bot
@ 2026-11-30 15:11 ` Philip Yang
  2026-11-30 15:15   ` [PATCH v3] " Lin Huiyi
  1 sibling, 1 reply; 5+ messages in thread
From: Philip Yang @ 2026-11-30 15:11 UTC (permalink / raw)
  To: Lin Huiyi, alexander.deucher, christian.koenig
  Cc: airlied, simona, Philip.Yang, amd-gfx, dri-devel

[-- Attachment #1: Type: text/plain, Size: 3488 bytes --]



On 2026-11-30 09:50, Lin Huiyi wrote:
> [Some people who received this message don't often get email fromxinghui79@qq.com. Learn why this is important athttps://aka.ms/LearnAboutSenderIdentification ]
>
> amdgpu_ualink_peer_remote_init() maps a set of GART ranges for every
> remote peer. If one of the amdgpu_ualink_gart_map() calls fails, it
> breaks out of the loop and returns an error, but the mappings created
> for the peers processed so far are left behind.
>
> amdgpu_ualink_sw_init() then takes the out_sdma_entities_fini path, which
> only tears down the SDMA entities and frees the remote structure without
> calling amdgpu_ualink_peer_remote_fini(). The already-allocated
> drm_mm_nodes stay registered in the shared GTT manager after the memory
> that tracked them is gone, corrupting the drm_mm state and leaking GART
> space on every failed activation.
>
> Fix this by calling amdgpu_ualink_peer_remote_fini() on the error path.
> Move the peer mutex initialization ahead of the fallible mappings so that
> fini can safely destroy the locks even when only some peers were mapped;
> gart_unmap() already ignores unallocated nodes.
>
> Fixes: 6e3834ceaf2f ("drm/amdgpu: Add UALink cross-GPU TLB shootdown and remote interrupt")
> Signed-off-by: Lin Huiyi<xinghui79@qq.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 11 +++++++++--
>   1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> index b4fac5ecab..74c9e72727 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> @@ -6186,6 +6186,12 @@ static int amdgpu_ualink_peer_remote_init(struct amdgpu_device *adev)
>          dev_dbg(adev->dev, "src_accel_id %u gart mapping flags 0x%llx\n",
>                  src_accel_id, flags);
>
> +       /* Initialize all locks before any fallible mapping so fini can unwind. */
> +       for_each_set_bit(dst_accel_id, remote->active_accel_bits, AMDGPU_UALINK_ACCEL_MAX) {
> +               if (dst_accel_id != src_accel_id)
> +                       mutex_init(&remote->peer[dst_accel_id].lock);
> +       }
> +
Calling mutex_destroy() on an all-zero struct mutex is safe in every 
config, so this for loop isn't needed. Please remove it.
>          for_each_set_bit(dst_accel_id, remote->active_accel_bits, AMDGPU_UALINK_ACCEL_MAX) {
>                  if (dst_accel_id == src_accel_id)
>                          continue;
> @@ -6193,7 +6199,6 @@ static int amdgpu_ualink_peer_remote_init(struct amdgpu_device *adev)
>                  dev_dbg(adev->dev, "peer_remote to dst_accel_id %u\n", dst_accel_id);
>
>                  peer = &remote->peer[dst_accel_id];
> -               mutex_init(&peer->lock);
>
>                  interrupt = &peer->interrupt;
>                  shootdown = &peer->shootdown;
> @@ -6353,11 +6358,13 @@ int amdgpu_ualink_sw_init(struct amdgpu_device *adev)
>
>          r = amdgpu_ualink_peer_remote_init(adev);
>          if (r)
> -               goto out_sdma_entities_fini;
> +               goto out_peer_remote_fini;
>
>          dev_dbg(adev->dev, "ualink sw init succeed\n");
>          return 0;
>
> +out_peer_remote_fini:
> +       amdgpu_ualink_peer_remote_fini(adev);
>   out_sdma_entities_fini:
The label out_sdma_entities_fini is no longer used, please remove 
itRegards, Philip
>          amdgpu_ualink_sdma_entities_fini(adev);
>   out_npa_unmap:
> --
> 2.56.1
>

[-- Attachment #2: Type: text/html, Size: 4442 bytes --]

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

* [PATCH v3] drm/amdgpu: Unwind UALink peer GART mappings on sw_init failure
  2026-11-30 15:11 ` Philip Yang
@ 2026-11-30 15:15   ` Lin Huiyi
  2026-12-01 17:22     ` Philip Yang
  0 siblings, 1 reply; 5+ messages in thread
From: Lin Huiyi @ 2026-11-30 15:15 UTC (permalink / raw)
  To: alexander.deucher, christian.koenig
  Cc: airlied, simona, Philip.Yang, amd-gfx, dri-devel, Lin Huiyi

amdgpu_ualink_peer_remote_init() maps a set of GART ranges for every
remote peer. If one of the amdgpu_ualink_gart_map() calls fails, it
breaks out of the loop and returns an error, but the mappings created
for the peers processed so far are left behind.

amdgpu_ualink_sw_init() then takes the out_sdma_entities_fini path, which
only tears down the SDMA entities and frees the remote structure without
calling amdgpu_ualink_peer_remote_fini(). The already-allocated
drm_mm_nodes stay registered in the shared GTT manager after the memory
that tracked them is gone, corrupting the drm_mm state and leaking GART
space on every failed activation.

Fix this by calling amdgpu_ualink_peer_remote_fini() on the error path.
This is safe even for peers whose mappings were not created yet, since
gart_unmap() ignores unallocated nodes and mutex_destroy() copes with a
zero-initialized mutex.

Fixes: 6e3834ceaf2f ("drm/amdgpu: Add UALink cross-GPU TLB shootdown and remote interrupt")
Signed-off-by: Lin Huiyi <xinghui79@qq.com>
---
v3: drop the mutex_init loop and keep the per-peer mutex_init as
    before, since mutex_destroy() is safe on a zero-initialized mutex,
    so the loop was unnecessary. Pointed out by Philip Yang.
v2: rename the existing out_sdma_entities_fini label to
    out_peer_remote_fini instead of adding a second label, to avoid
    -Wunused-label (Sashiko).
 drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
index b4fac5ecab..df716e2370 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
@@ -6353,12 +6353,13 @@ int amdgpu_ualink_sw_init(struct amdgpu_device *adev)
 
 	r = amdgpu_ualink_peer_remote_init(adev);
 	if (r)
-		goto out_sdma_entities_fini;
+		goto out_peer_remote_fini;
 
 	dev_dbg(adev->dev, "ualink sw init succeed\n");
 	return 0;
 
-out_sdma_entities_fini:
+out_peer_remote_fini:
+	amdgpu_ualink_peer_remote_fini(adev);
 	amdgpu_ualink_sdma_entities_fini(adev);
 out_npa_unmap:
 	amdgpu_ualink_metadata_npa_unmapping(adev);
-- 
2.56.1


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

* Re: [PATCH v3] drm/amdgpu: Unwind UALink peer GART mappings on sw_init failure
  2026-11-30 15:15   ` [PATCH v3] " Lin Huiyi
@ 2026-12-01 17:22     ` Philip Yang
  0 siblings, 0 replies; 5+ messages in thread
From: Philip Yang @ 2026-12-01 17:22 UTC (permalink / raw)
  To: Lin Huiyi, alexander.deucher, christian.koenig
  Cc: airlied, simona, Philip.Yang, amd-gfx, dri-devel

[-- Attachment #1: Type: text/plain, Size: 2678 bytes --]



On 2026-11-30 10:15, Lin Huiyi wrote:
> [Some people who received this message don't often get email fromxinghui79@qq.com. Learn why this is important athttps://aka.ms/LearnAboutSenderIdentification ]
>
> amdgpu_ualink_peer_remote_init() maps a set of GART ranges for every
> remote peer. If one of the amdgpu_ualink_gart_map() calls fails, it
> breaks out of the loop and returns an error, but the mappings created
> for the peers processed so far are left behind.
>
> amdgpu_ualink_sw_init() then takes the out_sdma_entities_fini path, which
> only tears down the SDMA entities and frees the remote structure without
> calling amdgpu_ualink_peer_remote_fini(). The already-allocated
> drm_mm_nodes stay registered in the shared GTT manager after the memory
> that tracked them is gone, corrupting the drm_mm state and leaking GART
> space on every failed activation.
>
> Fix this by calling amdgpu_ualink_peer_remote_fini() on the error path.
> This is safe even for peers whose mappings were not created yet, since
> gart_unmap() ignores unallocated nodes and mutex_destroy() copes with a
> zero-initialized mutex.
>
> Fixes: 6e3834ceaf2f ("drm/amdgpu: Add UALink cross-GPU TLB shootdown and remote interrupt")
> Signed-off-by: Lin Huiyi<xinghui79@qq.com>
Reviewed-by: Philip Yang <philip.yang@amd.com>

I will apply this patch to amd-staging-drm-next branch.

Thanks,
Philip
> ---
> v3: drop the mutex_init loop and keep the per-peer mutex_init as
>      before, since mutex_destroy() is safe on a zero-initialized mutex,
>      so the loop was unnecessary. Pointed out by Philip Yang.
> v2: rename the existing out_sdma_entities_fini label to
>      out_peer_remote_fini instead of adding a second label, to avoid
>      -Wunused-label (Sashiko).
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> index b4fac5ecab..df716e2370 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> @@ -6353,12 +6353,13 @@ int amdgpu_ualink_sw_init(struct amdgpu_device *adev)
>
>          r = amdgpu_ualink_peer_remote_init(adev);
>          if (r)
> -               goto out_sdma_entities_fini;
> +               goto out_peer_remote_fini;
>
>          dev_dbg(adev->dev, "ualink sw init succeed\n");
>          return 0;
>
> -out_sdma_entities_fini:
> +out_peer_remote_fini:
> +       amdgpu_ualink_peer_remote_fini(adev);
>          amdgpu_ualink_sdma_entities_fini(adev);
>   out_npa_unmap:
>          amdgpu_ualink_metadata_npa_unmapping(adev);
> --
> 2.56.1
>

[-- Attachment #2: Type: text/html, Size: 3503 bytes --]

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

end of thread, other threads:[~2026-12-01 17:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 14:50 [RESEND PATCH] drm/amdgpu: Unwind UALink peer GART mappings on sw_init failure Lin Huiyi
2026-11-30 14:58 ` sashiko-bot
2026-11-30 15:11 ` Philip Yang
2026-11-30 15:15   ` [PATCH v3] " Lin Huiyi
2026-12-01 17:22     ` Philip Yang

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.