]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
amdkfd: fence handler evict and restore a kfd process by its context id
authorZhu Lingshan <lingshan.zhu@amd.com>
Tue, 5 Aug 2025 03:31:32 +0000 (11:31 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 8 Dec 2025 19:13:25 +0000 (14:13 -0500)
In fence enable signaling handler, kfd evicts
and restores the corresponding kfd_process,
this commit helps find the kfd_process by
both its mm and context id.

Signed-off-by: Zhu Lingshan <lingshan.zhu@amd.com>
Reviewed-by: Felix Kuehling <felix.kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c
drivers/gpu/drm/amd/amdkfd/kfd_device.c

index ec4a70b82ac52ea0d984d18dd0e77b5db6cca672..da4575676335fad21d617d9d28f37f6128aaa750 100644 (file)
@@ -411,7 +411,7 @@ int kgd2kfd_init_zone_device(struct amdgpu_device *adev)
 int kgd2kfd_quiesce_mm(struct mm_struct *mm, uint32_t trigger);
 int kgd2kfd_resume_mm(struct mm_struct *mm);
 int kgd2kfd_schedule_evict_and_restore_process(struct mm_struct *mm,
-                                               struct dma_fence *fence);
+                                              u16 context_id, struct dma_fence *fence);
 #if IS_ENABLED(CONFIG_HSA_AMD)
 int kgd2kfd_init(void);
 void kgd2kfd_exit(void);
index 4119d0a9235eaa3adeeb270585a5c8bed17af863..193ed8becab8d273119472ebaabd1d9c9bcebf8f 100644 (file)
@@ -128,8 +128,12 @@ static bool amdkfd_fence_enable_signaling(struct dma_fence *f)
        if (dma_fence_is_signaled(f))
                return true;
 
+       /* if fence->svm_bo is NULL, means this fence is created through
+        * init_kfd_vm() or amdgpu_amdkfd_gpuvm_restore_process_bos().
+        * Therefore, this fence is amdgpu_amdkfd_fence->eviction_fence.
+        */
        if (!fence->svm_bo) {
-               if (!kgd2kfd_schedule_evict_and_restore_process(fence->mm, f))
+               if (!kgd2kfd_schedule_evict_and_restore_process(fence->mm, fence->context_id, f))
                        return true;
        } else {
                if (!svm_range_schedule_evict_svm_bo(fence))
index c507a958196bf987fa07f286c2e6a2f1b4bc355e..cf640c9d19bf6c49f90fcaa49ab74070f13f2d44 100644 (file)
@@ -1205,12 +1205,13 @@ int kgd2kfd_resume_mm(struct mm_struct *mm)
  *   prepare for safe eviction of KFD BOs that belong to the specified
  *   process.
  *
- * @mm: mm_struct that identifies the specified KFD process
+ * @mm: mm_struct that identifies a group of KFD processes
+ * @context_id: an id that identifies a specific KFD context in the above kfd process group
  * @fence: eviction fence attached to KFD process BOs
  *
  */
 int kgd2kfd_schedule_evict_and_restore_process(struct mm_struct *mm,
-                                              struct dma_fence *fence)
+                                              u16 context_id, struct dma_fence *fence)
 {
        struct kfd_process *p;
        unsigned long active_time;
@@ -1222,7 +1223,7 @@ int kgd2kfd_schedule_evict_and_restore_process(struct mm_struct *mm,
        if (dma_fence_is_signaled(fence))
                return 0;
 
-       p = kfd_lookup_process_by_mm(mm);
+       p = kfd_lookup_process_by_id(mm, context_id);
        if (!p)
                return -ENODEV;