From: Mukul Joshi <[email protected]>

remote->active_accel_bits aliased info->vpod.active_accel_bits, which
psp_ual_query_info() refreshes on every commit. Teardown
(peer_remote_fini / gart unmap) then iterated the new set instead of the
one sw_init mapped, orphaning drm_mm nodes in the shared GTT manager.
Make active_accel_bits an owned snapshot copied at sw_init time. Drop the
now-redundant not-initialised guard in metadata_npa_unmapping(), since the
earlier remote->ring_bo NULL-check already covers that case.

Signed-off-by: Mukul Joshi <[email protected]>
Reviewed-by: Philip Yang <[email protected]>
Signed-off-by: Alex Deucher <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
index 73aa9e98202b5..2d9317db32027 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
@@ -3887,8 +3887,14 @@ struct amdgpu_ualink_remote {
        /* address alias mode alloc npa address for shared wb */
        struct drm_mm_node              rptr_mm_node;
 
-       /* active accelator id bitmap of the pod */
-       unsigned long                   *active_accel_bits;
+       /*
+        * Owned snapshot of the vPod's active accelerator bitmap, taken at
+        * sw_init time. Must NOT alias info->vpod.active_accel_bits, which
+        * psp_ual_query_info() refreshes on every commit: aliasing it would let
+        * teardown unmap a different set than setup mapped, leaking drm_mm 
nodes
+        * in the shared GTT manager.
+        */
+       DECLARE_BITMAP(active_accel_bits, AMDGPU_UALINK_ACCEL_MAX);
        u32                             num_accel;
 
        /* remote GPUs ring buffer, read, write pointer local copy and gart 
mapping */
@@ -4266,8 +4272,6 @@ static void amdgpu_ualink_metadata_npa_unmapping(struct 
amdgpu_device *adev)
 
        if (!remote->ring_bo)
                return;
-       if (!remote->active_accel_bits)
-               return;
 
        rb_size = AMDGPU_UALINK_RB_SIZE;
        rb_size_in_pages = rb_size >> AMDGPU_GPU_PAGE_SHIFT;
@@ -4686,7 +4690,9 @@ static int amdgpu_ualink_metadata_init(struct 
amdgpu_device *adev)
        u32 status, accel_id;
        int r;
 
-       remote->active_accel_bits = adev->ualink.info->vpod.active_accel_bits;
+       bitmap_copy(remote->active_accel_bits,
+                   adev->ualink.info->vpod.active_accel_bits,
+                   AMDGPU_UALINK_ACCEL_MAX);
        dev_dbg(adev->dev, "%d active accelerators config in vpod\n",
                bitmap_weight(remote->active_accel_bits, 
AMDGPU_UALINK_ACCEL_MAX));
 
-- 
2.55.0

Reply via email to