KFD creates sysfs entries for a kfd_process in
function kfd_create_process when creating it.

This commit extracts the code creating sysfs
entries to a separate function because it
would be invoked in other code path like
creating secondary kfd contexts (kfd_process).

Signed-off-by: Zhu Lingshan <lingshan....@amd.com>
Reviewed-by: Felix Kuehling <felix.kuehl...@amd.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  1 +
 drivers/gpu/drm/amd/amdkfd/kfd_process.c | 66 +++++++++++++++---------
 2 files changed, 42 insertions(+), 25 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h 
b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
index 2b95f37c1af8..0818705820c6 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
@@ -1043,6 +1043,7 @@ int kfd_process_create_wq(void);
 void kfd_process_destroy_wq(void);
 void kfd_cleanup_processes(void);
 struct kfd_process *kfd_create_process(struct task_struct *thread);
+int kfd_create_process_sysfs(struct kfd_process *process);
 struct kfd_process *kfd_get_process(const struct task_struct *task);
 struct kfd_process *kfd_lookup_process_by_pasid(u32 pasid,
                                                 struct kfd_process_device 
**pdd);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index 88421e57a072..bce7e35a15c9 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -825,6 +825,44 @@ static void kfd_process_device_destroy_ib_mem(struct 
kfd_process_device *pdd)
        kfd_process_free_gpuvm(qpd->ib_mem, pdd, &qpd->ib_kaddr);
 }
 
+int kfd_create_process_sysfs(struct kfd_process *process)
+{
+       int ret;
+
+       if (process->kobj) {
+               pr_warn("kobject already exsists for the kfd_process\n");
+               return -EINVAL;
+       }
+
+       process->kobj = kfd_alloc_struct(process->kobj);
+       if (!process->kobj) {
+               pr_warn("Creating procfs kobject failed");
+               return -ENOMEM;
+       }
+       ret = kobject_init_and_add(process->kobj, &procfs_type,
+                                  procfs.kobj, "%d",
+                                  (int)process->lead_thread->pid);
+       if (ret) {
+               pr_warn("Creating procfs pid directory failed");
+               kobject_put(process->kobj);
+               return ret;
+       }
+
+       kfd_sysfs_create_file(process->kobj, &process->attr_pasid,
+                             "pasid");
+
+       process->kobj_queues = kobject_create_and_add("queues",
+                                               process->kobj);
+       if (!process->kobj_queues)
+               pr_warn("Creating KFD proc/queues folder failed");
+
+       kfd_procfs_add_sysfs_stats(process);
+       kfd_procfs_add_sysfs_files(process);
+       kfd_procfs_add_sysfs_counters(process);
+
+       return 0;
+}
+
 struct kfd_process *kfd_create_process(struct task_struct *thread)
 {
        struct kfd_process *process;
@@ -874,31 +912,9 @@ struct kfd_process *kfd_create_process(struct task_struct 
*thread)
                if (!procfs.kobj)
                        goto out;
 
-               process->kobj = kfd_alloc_struct(process->kobj);
-               if (!process->kobj) {
-                       pr_warn("Creating procfs kobject failed");
-                       goto out;
-               }
-               ret = kobject_init_and_add(process->kobj, &procfs_type,
-                                          procfs.kobj, "%d",
-                                          (int)process->lead_thread->pid);
-               if (ret) {
-                       pr_warn("Creating procfs pid directory failed");
-                       kobject_put(process->kobj);
-                       goto out;
-               }
-
-               kfd_sysfs_create_file(process->kobj, &process->attr_pasid,
-                                     "pasid");
-
-               process->kobj_queues = kobject_create_and_add("queues",
-                                                       process->kobj);
-               if (!process->kobj_queues)
-                       pr_warn("Creating KFD proc/queues folder failed");
-
-               kfd_procfs_add_sysfs_stats(process);
-               kfd_procfs_add_sysfs_files(process);
-               kfd_procfs_add_sysfs_counters(process);
+               ret = kfd_create_process_sysfs(process);
+               if (ret)
+                       pr_warn("Failed to create sysfs entry for the 
kfd_process");
 
                kfd_debugfs_add_process(process);
 
-- 
2.47.1

Reply via email to