From: Zhu Lingshan <lingshan.zhu@amd.com>
To: <felix.kuehling@amd.com>, <alexander.deucher@amd.com>
Cc: <ray.huang@amd.com>, <amd-gfx@lists.freedesktop.org>,
Zhu Lingshan <lingshan.zhu@amd.com>
Subject: [PATCH V6 16/18] amdkfd: fence handler evict and restore a kfd process by its context id
Date: Wed, 22 Oct 2025 15:30:41 +0800 [thread overview]
Message-ID: <20251022073043.13009-17-lingshan.zhu@amd.com> (raw)
In-Reply-To: <20251022073043.13009-1-lingshan.zhu@amd.com>
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>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 2 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c | 6 +++++-
drivers/gpu/drm/amd/amdkfd/kfd_device.c | 7 ++++---
3 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index 087e8fe2c077..321cbf9a1528 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
@@ -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);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c
index 4119d0a9235e..193ed8becab8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c
@@ -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))
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
index e9cfb80bd436..0b9a3c198c14 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
@@ -1202,12 +1202,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;
@@ -1219,7 +1220,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;
--
2.51.0
next prev parent reply other threads:[~2025-10-22 7:31 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-22 7:30 [PATCH V6 00/18] amdkfd: Implement kfd multiple contexts Zhu Lingshan
2025-10-22 7:30 ` [PATCH V6 01/18] amdkfd: enlarge the hashtable of kfd_process Zhu Lingshan
2025-10-22 7:30 ` [PATCH V6 02/18] amdkfd: mark the first kfd_process as the primary one Zhu Lingshan
2025-10-22 7:30 ` [PATCH V6 03/18] amdkfd: find_process_by_mm always return the primary context Zhu Lingshan
2025-10-22 7:30 ` [PATCH V6 04/18] amdkfd: Introduce kfd_create_process_sysfs as a separate function Zhu Lingshan
2025-10-22 7:30 ` [PATCH V6 05/18] amdkfd: destroy kfd secondary contexts through fd close Zhu Lingshan
2025-10-22 7:30 ` [PATCH V6 06/18] amdkfd: process svm ioctl only on the primary kfd process Zhu Lingshan
2025-10-22 7:30 ` [PATCH V6 07/18] amdkfd: process USERPTR allocation " Zhu Lingshan
2025-10-22 7:30 ` [PATCH V6 08/18] amdkfd: identify a secondary kfd process by its id Zhu Lingshan
2025-10-30 21:17 ` Felix Kuehling
2025-10-22 7:30 ` [PATCH V6 09/18] amdkfd: find kfd_process by filep->private_data in kfd_mmap Zhu Lingshan
2025-10-22 7:30 ` [PATCH V6 10/18] amdkfd: remove DIQ support Zhu Lingshan
2025-10-22 7:30 ` [PATCH V6 11/18] amdkfd: process pointer of a HIQ should be NULL Zhu Lingshan
2025-10-22 7:30 ` [PATCH V6 12/18] amdkfd: remove test_kq Zhu Lingshan
2025-10-22 7:30 ` [PATCH V6 13/18] amdkfd: introduce new helper kfd_lookup_process_by_id Zhu Lingshan
2025-10-22 7:30 ` [PATCH V6 14/18] amdkfd: record kfd context id into kfd process_info Zhu Lingshan
2025-10-22 7:30 ` [PATCH V6 15/18] amdkfd: record kfd context id in amdkfd_fence Zhu Lingshan
2025-10-22 7:30 ` Zhu Lingshan [this message]
2025-10-22 7:30 ` [PATCH V6 17/18] amdkfd: process debug trap ioctl only on a primary context Zhu Lingshan
2025-10-30 21:18 ` Felix Kuehling
2025-10-22 7:30 ` [PATCH V6 18/18] amdkfd: introduce new ioctl AMDKFD_IOC_CREATE_PROCESS Zhu Lingshan
2025-10-30 21:28 ` Felix Kuehling
2025-10-30 21:15 ` [PATCH V6 00/18] amdkfd: Implement kfd multiple contexts Felix Kuehling
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251022073043.13009-17-lingshan.zhu@amd.com \
--to=lingshan.zhu@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=felix.kuehling@amd.com \
--cc=ray.huang@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox