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 02/18] amdkfd: mark the first kfd_process as the primary one
Date: Wed, 22 Oct 2025 15:30:27 +0800 [thread overview]
Message-ID: <20251022073043.13009-3-lingshan.zhu@amd.com> (raw)
In-Reply-To: <20251022073043.13009-1-lingshan.zhu@amd.com>
The first kfd_process is created through open(),
this commit marks it as the primary kfd_process
by assigning a primary id for its context_id.
Only the primary process should register the mmu_notifier.
Signed-off-by: Zhu Lingshan <lingshan.zhu@amd.com>
Reviewed-by: Felix Kuehling <felix.kuehling@amd.com>
---
drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 5 +++++
drivers/gpu/drm/amd/amdkfd/kfd_process.c | 20 ++++++++++++--------
2 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
index d943ecf62a3b..729330f8a384 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
@@ -1018,9 +1018,14 @@ struct kfd_process {
/* if gpu page fault sent to KFD */
bool gpu_page_fault;
+
+ /*kfd context id */
+ u16 context_id;
};
#define KFD_PROCESS_TABLE_SIZE 8 /* bits: 256 entries */
+#define KFD_CONTEXT_ID_PRIMARY 0xFFFF
+
extern DECLARE_HASHTABLE(kfd_processes_table, KFD_PROCESS_TABLE_SIZE);
extern struct srcu_struct kfd_processes_srcu;
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index ddfe30c13e9d..2a22c718ee94 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -68,7 +68,7 @@ static struct workqueue_struct *kfd_restore_wq;
static struct kfd_process *find_process(const struct task_struct *thread,
bool ref);
static void kfd_process_ref_release(struct kref *ref);
-static struct kfd_process *create_process(const struct task_struct *thread);
+static struct kfd_process *create_process(const struct task_struct *thread, bool primary);
static void evict_process_worker(struct work_struct *work);
static void restore_process_worker(struct work_struct *work);
@@ -867,7 +867,7 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)
if (process) {
pr_debug("Process already found\n");
} else {
- process = create_process(thread);
+ process = create_process(thread, true);
if (IS_ERR(process))
goto out;
@@ -1512,7 +1512,7 @@ void kfd_process_set_trap_debug_flag(struct qcm_process_device *qpd,
* On return the kfd_process is fully operational and will be freed when the
* mm is released
*/
-static struct kfd_process *create_process(const struct task_struct *thread)
+static struct kfd_process *create_process(const struct task_struct *thread, bool primary)
{
struct kfd_process *process;
struct mmu_notifier *mn;
@@ -1528,6 +1528,7 @@ static struct kfd_process *create_process(const struct task_struct *thread)
process->lead_thread = thread->group_leader;
process->n_pdds = 0;
process->queues_paused = false;
+
INIT_DELAYED_WORK(&process->eviction_work, evict_process_worker);
INIT_DELAYED_WORK(&process->restore_work, restore_process_worker);
process->last_restore_timestamp = get_jiffies_64();
@@ -1571,12 +1572,15 @@ static struct kfd_process *create_process(const struct task_struct *thread)
* After this point, mmu_notifier_put will trigger the cleanup by
* dropping the last process reference in the free_notifier.
*/
- mn = mmu_notifier_get(&kfd_process_mmu_notifier_ops, process->mm);
- if (IS_ERR(mn)) {
- err = PTR_ERR(mn);
- goto err_register_notifier;
+ if (primary) {
+ process->context_id = KFD_CONTEXT_ID_PRIMARY;
+ mn = mmu_notifier_get(&kfd_process_mmu_notifier_ops, process->mm);
+ if (IS_ERR(mn)) {
+ err = PTR_ERR(mn);
+ goto err_register_notifier;
+ }
+ BUG_ON(mn != &process->mmu_notifier);
}
- BUG_ON(mn != &process->mmu_notifier);
kfd_unref_process(process);
get_task_struct(process->lead_thread);
--
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 ` Zhu Lingshan [this message]
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 ` [PATCH V6 16/18] amdkfd: fence handler evict and restore a kfd process by its context id Zhu Lingshan
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-3-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