Skip to contentSkip to conversation

amdkfd: implement per process/device pasid in sysfs

PATCH In review Zhu Lingshan 5 participants 10 messages Oct 30, 2025 – Oct 31, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 amdkfd: implement per process/device pasid in sysfs

The pasid is a per-process-per-device attribute,
therefore this commit implements per
struct kfd_process_device->pasid in sysfs

---
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  9 ++-------
 drivers/gpu/drm/amd/amdkfd/kfd_process.c | 18 +++++++++++-------
 2 files changed, 13 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -7
index 70ef051511bb..6a3cfeccacd8 100644
@@ -864,6 +864,8 @@ struct kfd_process_device {
 	bool has_reset_queue;
 
 	u32 pasid;
+	char pasid_filename[MAX_SYSFS_FILENAME_LEN];
+	struct attribute attr_pasid;
 };
 
 #define qpd_to_pdd(x) container_of(x, struct kfd_process_device, qpd)
@@ -983,7 +985,6 @@ struct kfd_process {
 	/* Kobj for our procfs */
 	struct kobject *kobj;
 	struct kobject *kobj_queues;
-	struct attribute attr_pasid;
 
 	/* Keep track cwsr init */
 	bool has_cwsr;
@@ -1100,12 +1101,6 @@ void kfd_process_device_remove_obj_handle(struct kfd_process_device *pdd,
 					int handle);
 struct kfd_process *kfd_lookup_process_by_pid(struct pid *pid);
 
-/* PASIDs */
-int kfd_pasid_init(void);
-void kfd_pasid_exit(void);
-u32 kfd_pasid_alloc(void);
-void kfd_pasid_free(u32 pasid);
-
 /* Doorbells */
 size_t kfd_doorbell_process_slice(struct kfd_dev *kfd);
 int kfd_doorbell_init(struct kfd_dev *kfd);
drivers/gpu/drm/amd/amdkfd/kfd_process.c +11 -7
index ddfe30c13e9d..24cf3b250b37 100644
@@ -328,9 +328,11 @@ static int kfd_get_cu_occupancy(struct attribute *attr, char *buffer)
 static ssize_t kfd_procfs_show(struct kobject *kobj, struct attribute *attr,
 			       char *buffer)
 {
-	if (strcmp(attr->name, "pasid") == 0)
-		return snprintf(buffer, PAGE_SIZE, "%d\n", 0);
-	else if (strncmp(attr->name, "vram_", 5) == 0) {
+	if (strncmp(attr->name, "pasid_", 6) == 0) {
+		struct kfd_process_device *pdd = container_of(attr, struct kfd_process_device,
+							      attr_pasid);
+		return snprintf(buffer, PAGE_SIZE, "%u\n", pdd->pasid);
+	} else if (strncmp(attr->name, "vram_", 5) == 0) {
 		struct kfd_process_device *pdd = container_of(attr, struct kfd_process_device,
 							      attr_vram);
 		return snprintf(buffer, PAGE_SIZE, "%llu\n", atomic64_read(&pdd->vram_usage));
@@ -662,6 +664,7 @@ static void kfd_procfs_add_sysfs_files(struct kfd_process *p)
 	 * Create sysfs files for each GPU:
 	 * - proc/<pid>/vram_<gpuid>
 	 * - proc/<pid>/sdma_<gpuid>
+	 * - proc/<pid>/pasid_<gpuid>
 	 */
 	for (i = 0; i < p->n_pdds; i++) {
 		struct kfd_process_device *pdd = p->pdds[i];
@@ -675,6 +678,10 @@ static void kfd_procfs_add_sysfs_files(struct kfd_process *p)
 			 pdd->dev->id);
 		kfd_sysfs_create_file(p->kobj, &pdd->attr_sdma,
 					    pdd->sdma_filename);
+
+		snprintf(pdd->pasid_filename, MAX_SYSFS_FILENAME_LEN, "pasid_%u",
+			 pdd->dev->id);
+		kfd_sysfs_create_file(p->kobj, &pdd->attr_pasid, pdd->pasid_filename);
 	}
 }
 
@@ -888,9 +895,6 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)
 			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)
@@ -1104,7 +1108,6 @@ static void kfd_process_remove_sysfs(struct kfd_process *p)
 	if (!p->kobj)
 		return;
 
-	sysfs_remove_file(p->kobj, &p->attr_pasid);
 	kobject_del(p->kobj_queues);
 	kobject_put(p->kobj_queues);
 	p->kobj_queues = NULL;
@@ -1114,6 +1117,7 @@ static void kfd_process_remove_sysfs(struct kfd_process *p)
 
 		sysfs_remove_file(p->kobj, &pdd->attr_vram);
 		sysfs_remove_file(p->kobj, &pdd->attr_sdma);
+		sysfs_remove_file(p->kobj, &pdd->attr_pasid);
 
 		sysfs_remove_file(pdd->kobj_stats, &pdd->attr_evict);
 		if (pdd->dev->kfd2kgd->get_cu_occupancy)
Signature · 1 line
2.51.0
maintainer
#1 lore raw
Quoted 3 lines · Zhu Lingshan

The pasid is a per-process-per-device attribute,
therefore this commit implements per
struct kfd_process_device->pasid in sysfs

Does anyone in user mode actually need this PASID? When we changed the PASID allocation to be per-process-device, we changed a bunch of our dmesg logging (and I think debugfs files, too) to report PIDs instead of PASIDs. So there should be no good reason to know PASIDs in user mode.

Regards,
  Felix

Quoted 105 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  9 ++-------
  drivers/gpu/drm/amd/amdkfd/kfd_process.c | 18 +++++++++++-------
  2 files changed, 13 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -7
index 70ef051511bb..6a3cfeccacd8 100644
@@ -864,6 +864,8 @@ struct kfd_process_device {
  	bool has_reset_queue;
 
  	u32 pasid;
+	char pasid_filename[MAX_SYSFS_FILENAME_LEN];
+	struct attribute attr_pasid;
  };
 
  #define qpd_to_pdd(x) container_of(x, struct kfd_process_device, qpd)
@@ -983,7 +985,6 @@ struct kfd_process {
  	/* Kobj for our procfs */
  	struct kobject *kobj;
  	struct kobject *kobj_queues;
-	struct attribute attr_pasid;
 
  	/* Keep track cwsr init */
  	bool has_cwsr;
@@ -1100,12 +1101,6 @@ void kfd_process_device_remove_obj_handle(struct kfd_process_device *pdd,
  					int handle);
  struct kfd_process *kfd_lookup_process_by_pid(struct pid *pid);
 
-/* PASIDs */
-int kfd_pasid_init(void);
-void kfd_pasid_exit(void);
-u32 kfd_pasid_alloc(void);
-void kfd_pasid_free(u32 pasid);
-
  /* Doorbells */
  size_t kfd_doorbell_process_slice(struct kfd_dev *kfd);
  int kfd_doorbell_init(struct kfd_dev *kfd);
drivers/gpu/drm/amd/amdkfd/kfd_process.c +11 -7
index ddfe30c13e9d..24cf3b250b37 100644
@@ -328,9 +328,11 @@ static int kfd_get_cu_occupancy(struct attribute *attr, char *buffer)
  static ssize_t kfd_procfs_show(struct kobject *kobj, struct attribute *attr,
  			       char *buffer)
  {
-	if (strcmp(attr->name, "pasid") == 0)
-		return snprintf(buffer, PAGE_SIZE, "%d\n", 0);
-	else if (strncmp(attr->name, "vram_", 5) == 0) {
+	if (strncmp(attr->name, "pasid_", 6) == 0) {
+		struct kfd_process_device *pdd = container_of(attr, struct kfd_process_device,
+							      attr_pasid);
+		return snprintf(buffer, PAGE_SIZE, "%u\n", pdd->pasid);
+	} else if (strncmp(attr->name, "vram_", 5) == 0) {
  		struct kfd_process_device *pdd = container_of(attr, struct kfd_process_device,
  							      attr_vram);
  		return snprintf(buffer, PAGE_SIZE, "%llu\n", atomic64_read(&pdd->vram_usage));
@@ -662,6 +664,7 @@ static void kfd_procfs_add_sysfs_files(struct kfd_process *p)
  	 * Create sysfs files for each GPU:
  	 * - proc/<pid>/vram_<gpuid>
  	 * - proc/<pid>/sdma_<gpuid>
+	 * - proc/<pid>/pasid_<gpuid>
  	 */
  	for (i = 0; i < p->n_pdds; i++) {
  		struct kfd_process_device *pdd = p->pdds[i];
@@ -675,6 +678,10 @@ static void kfd_procfs_add_sysfs_files(struct kfd_process *p)
  			 pdd->dev->id);
  		kfd_sysfs_create_file(p->kobj, &pdd->attr_sdma,
  					    pdd->sdma_filename);
+
+		snprintf(pdd->pasid_filename, MAX_SYSFS_FILENAME_LEN, "pasid_%u",
+			 pdd->dev->id);
+		kfd_sysfs_create_file(p->kobj, &pdd->attr_pasid, pdd->pasid_filename);
  	}
  }
 
@@ -888,9 +895,6 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)
  			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)
@@ -1104,7 +1108,6 @@ static void kfd_process_remove_sysfs(struct kfd_process *p)
  	if (!p->kobj)
  		return;
 
-	sysfs_remove_file(p->kobj, &p->attr_pasid);
  	kobject_del(p->kobj_queues);
  	kobject_put(p->kobj_queues);
  	p->kobj_queues = NULL;
@@ -1114,6 +1117,7 @@ static void kfd_process_remove_sysfs(struct kfd_process *p)
 
  		sysfs_remove_file(p->kobj, &pdd->attr_vram);
  		sysfs_remove_file(p->kobj, &pdd->attr_sdma);
+		sysfs_remove_file(p->kobj, &pdd->attr_pasid);
 
  		sysfs_remove_file(pdd->kobj_stats, &pdd->attr_evict);
  		if (pdd->dev->kfd2kgd->get_cu_occupancy)
#2 lore raw
Quoted 9 lines · Felix
Quoted 3 lines · Zhu Lingshan

The pasid is a per-process-per-device attribute,
therefore this commit implements per
struct kfd_process_device->pasid in sysfs

Does anyone in user mode actually need this PASID? When we changed the PASID allocation to be per-process-device, we changed a bunch of our dmesg logging (and I think debugfs files, too) to report PIDs instead of PASIDs. So there should be no good reason to know PASIDs in user mode.

Hello Felix,

This patch is to fix current buggy pasid in sysfs which is hard-coded 0, if we don't need to expose pasid to user space, I think we should remove it from sysfs.

Thanks
Lingshan

Quoted 117 lines

Regards,
  Felix

Quoted 112 lines

---
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  9 ++------- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 18 +++++++++++-------

  2 files changed, 13 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -1
index 70ef051511bb..6a3cfeccacd8 100644
@@ -864,6 +864,8 @@ struct kfd_process_device {
       bool has_reset_queue;
         u32 pasid;
+    char pasid_filename[MAX_SYSFS_FILENAME_LEN];
+    struct attribute attr_pasid;
   };
     #define qpd_to_pdd(x) container_of(x, struct kfd_process_device,
 qpd)
@@ -983,7 +985,6 @@ struct kfd_process {
       /* Kobj for our procfs */
       struct kobject *kobj;
       struct kobject *kobj_queues;
-    struct attribute attr_pasid;
         /* Keep track cwsr init */
       bool has_cwsr;
@@ -1100,12 +1101,6 @@ void
 kfd_process_device_remove_obj_handle(struct kfd_process_device *pdd,
                       int handle);
   struct kfd_process *kfd_lookup_process_by_pid(struct pid *pid);

  -/* PASIDs */

drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -5
-int kfd_pasid_init(void);
-void kfd_pasid_exit(void);
-u32 kfd_pasid_alloc(void);
-void kfd_pasid_free(u32 pasid);
-

  /* Doorbells */
  size_t kfd_doorbell_process_slice(struct kfd_dev *kfd); int kfd_doorbell_init(struct kfd_dev *kfd);

drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
index ddfe30c13e9d..24cf3b250b37 100644
@@ -328,9 +328,11 @@ static int kfd_get_cu_occupancy(struct attribute
 *attr, char *buffer)

  static ssize_t kfd_procfs_show(struct kobject *kobj, struct attribute *attr,
                     char *buffer)
  {
-    if (strcmp(attr->name, "pasid") == 0)
-        return snprintf(buffer, PAGE_SIZE, "%d\n", 0);
-    else if (strncmp(attr->name, "vram_", 5) == 0) {
+    if (strncmp(attr->name, "pasid_", 6) == 0) {
+        struct kfd_process_device *pdd = container_of(attr, struct kfd_process_device,
+                                  attr_pasid);
+        return snprintf(buffer, PAGE_SIZE, "%u\n", pdd->pasid); +    } else if (strncmp(attr->name, "vram_", 5) == 0) { struct kfd_process_device *pdd = container_of(attr, struct kfd_process_device,
                                    attr_vram);
          return snprintf(buffer, PAGE_SIZE, "%llu\n", atomic64_read(&pdd->vram_usage));

drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -0
@@ -662,6 +664,7 @@ static void kfd_procfs_add_sysfs_files(struct
 kfd_process *p)
        * Create sysfs files for each GPU:
        * - proc/<pid>/vram_<gpuid>
        * - proc/<pid>/sdma_<gpuid>
+     * - proc/<pid>/pasid_<gpuid>
        */
       for (i = 0; i < p->n_pdds; i++) {

          struct kfd_process_device *pdd = p->pdds[i];

drivers/gpu/drm/amd/amdkfd/kfd_process.c +4 -0
@@ -675,6 +678,10 @@ static void kfd_procfs_add_sysfs_files(struct
 kfd_process *p)
                pdd->dev->id);
           kfd_sysfs_create_file(p->kobj, &pdd->attr_sdma,
                           pdd->sdma_filename);
+
+        snprintf(pdd->pasid_filename, MAX_SYSFS_FILENAME_LEN,
 "pasid_%u",
+             pdd->dev->id);
+        kfd_sysfs_create_file(p->kobj, &pdd->attr_pasid,
 pdd->pasid_filename);

      }
  }
  @@ -888,9 +895,6 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)
              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)

drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
@@ -1104,7 +1108,6 @@ static void kfd_process_remove_sysfs(struct
 kfd_process *p)
       if (!p->kobj)
           return;
   -    sysfs_remove_file(p->kobj, &p->attr_pasid);
       kobject_del(p->kobj_queues);
       kobject_put(p->kobj_queues);

      p->kobj_queues = NULL;

drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -0
@@ -1114,6 +1117,7 @@ static void kfd_process_remove_sysfs(struct
 kfd_process *p)
             sysfs_remove_file(p->kobj, &pdd->attr_vram);
           sysfs_remove_file(p->kobj, &pdd->attr_sdma);
+        sysfs_remove_file(p->kobj, &pdd->attr_pasid);
             sysfs_remove_file(pdd->kobj_stats, &pdd->attr_evict);
           if (pdd->dev->kfd2kgd->get_cu_occupancy)
maintainer
#3 lore raw
Quoted 11 lines · Lingshan
Quoted 6 lines · Felix
Quoted 3 lines · Zhu Lingshan

The pasid is a per-process-per-device attribute,
therefore this commit implements per
struct kfd_process_device->pasid in sysfs

Does anyone in user mode actually need this PASID? When we changed the PASID allocation to be per-process-device, we changed a bunch of our dmesg logging (and I think debugfs files, too) to report PIDs instead of PASIDs. So there should be no good reason to know PASIDs in user mode.

Hello Felix,

This patch is to fix current buggy pasid in sysfs which is hard-coded 0, if we don't need to expose pasid to user space, I think we should remove it from sysfs.

It's not buggy, it's there to avoid breaking old user mode tools that expected to find a PASID per process. Take a look at this commit for the history: commit 8544374c0f82edb285779f21b149826fe2c2977c

Author: Xiaogang Chen <[email protected]>
Date:   Mon Jan 13 17:35:59 2025 -0600

    drm/amdkfd: Have kfd driver use same PASID values from graphic driver

We used to have a PASID per process and reported it to user mode. We had to change that to fix some issues related to multiple GPU partitions. That broke reporting of PASIDs to user mode. We kept reporting a 0 PASID to avoid breaking existing user mode tools that expect to read a PASID. But because that PASID was never that useful to begin with, reporting 0 doesn't do any harm here.

Adding another interface to report per-process/device PASIDs to user mode is pointless if there is no user mode client that needs that information. And we don't want user mode to use PASIDs to refer to processes or VM address spaces.

Regards,
  Felix

Quoted 113 lines

Thanks
Lingshan

Quoted 110 lines

Regards,
  Felix

Quoted 105 lines

---
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  9 ++------- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 18 +++++++++++-------

  2 files changed, 13 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -1
index 70ef051511bb..6a3cfeccacd8 100644
@@ -864,6 +864,8 @@ struct kfd_process_device {
       bool has_reset_queue;
         u32 pasid;
+    char pasid_filename[MAX_SYSFS_FILENAME_LEN];
+    struct attribute attr_pasid;
   };
     #define qpd_to_pdd(x) container_of(x, struct kfd_process_device, qpd)
@@ -983,7 +985,6 @@ struct kfd_process {
       /* Kobj for our procfs */
       struct kobject *kobj;
       struct kobject *kobj_queues;
-    struct attribute attr_pasid;
         /* Keep track cwsr init */
       bool has_cwsr;
@@ -1100,12 +1101,6 @@ void 
 kfd_process_device_remove_obj_handle(struct kfd_process_device *pdd,
                       int handle);
   struct kfd_process *kfd_lookup_process_by_pid(struct pid *pid);

  -/* PASIDs */

drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -5
-int kfd_pasid_init(void);
-void kfd_pasid_exit(void);
-u32 kfd_pasid_alloc(void);
-void kfd_pasid_free(u32 pasid);
-

  /* Doorbells */
  size_t kfd_doorbell_process_slice(struct kfd_dev *kfd); int kfd_doorbell_init(struct kfd_dev *kfd);

drivers/gpu/drm/amd/amdkfd/kfd_process.c +5 -3
index ddfe30c13e9d..24cf3b250b37 100644
@@ -328,9 +328,11 @@ static int kfd_get_cu_occupancy(struct 
 attribute *attr, char *buffer)
   static ssize_t kfd_procfs_show(struct kobject *kobj, struct attribute *attr,
                      char *buffer)
   {
-    if (strcmp(attr->name, "pasid") == 0)
-        return snprintf(buffer, PAGE_SIZE, "%d\n", 0);
-    else if (strncmp(attr->name, "vram_", 5) == 0) {
+    if (strncmp(attr->name, "pasid_", 6) == 0) {
+        struct kfd_process_device *pdd = container_of(attr, struct 
 kfd_process_device,
+                                  attr_pasid);
+        return snprintf(buffer, PAGE_SIZE, "%u\n", pdd->pasid);
+    } else if (strncmp(attr->name, "vram_", 5) == 0) {
           struct kfd_process_device *pdd = container_of(attr, struct kfd_process_device,

                                    attr_vram);
          return snprintf(buffer, PAGE_SIZE, "%llu\n", atomic64_read(&pdd->vram_usage));

drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -0
@@ -662,6 +664,7 @@ static void kfd_procfs_add_sysfs_files(struct 
 kfd_process *p)
        * Create sysfs files for each GPU:
        * - proc/<pid>/vram_<gpuid>
        * - proc/<pid>/sdma_<gpuid>
+     * - proc/<pid>/pasid_<gpuid>
        */
       for (i = 0; i < p->n_pdds; i++) {

          struct kfd_process_device *pdd = p->pdds[i];

drivers/gpu/drm/amd/amdkfd/kfd_process.c +4 -0
@@ -675,6 +678,10 @@ static void kfd_procfs_add_sysfs_files(struct 
 kfd_process *p)
                pdd->dev->id);
           kfd_sysfs_create_file(p->kobj, &pdd->attr_sdma,
                           pdd->sdma_filename);
+
+        snprintf(pdd->pasid_filename, MAX_SYSFS_FILENAME_LEN, 
 "pasid_%u",
+             pdd->dev->id);
+        kfd_sysfs_create_file(p->kobj, &pdd->attr_pasid, 
 pdd->pasid_filename);

      }
  }
  @@ -888,9 +895,6 @@ struct kfd_process *kfd_create_process(struct task_struct *thread) 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)

drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
@@ -1104,7 +1108,6 @@ static void kfd_process_remove_sysfs(struct 
 kfd_process *p)
       if (!p->kobj)
           return;
   -    sysfs_remove_file(p->kobj, &p->attr_pasid);
       kobject_del(p->kobj_queues);
       kobject_put(p->kobj_queues);

      p->kobj_queues = NULL;

drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -0
@@ -1114,6 +1117,7 @@ static void kfd_process_remove_sysfs(struct 
 kfd_process *p)
             sysfs_remove_file(p->kobj, &pdd->attr_vram);
           sysfs_remove_file(p->kobj, &pdd->attr_sdma);
+        sysfs_remove_file(p->kobj, &pdd->attr_pasid);
             sysfs_remove_file(pdd->kobj_stats, &pdd->attr_evict);
           if (pdd->dev->kfd2kgd->get_cu_occupancy)
#4 lore raw
In reply to Zhu Lingshan
Quoted 3 lines · Zhu Lingshan

The pasid is a per-process-per-device attribute,
therefore this commit implements per
struct kfd_process_device->pasid in sysfs

This per device pasid is used internally in kfd, not used at user space. So no need to exposing it.

Quoted 21 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  9 ++-------
  drivers/gpu/drm/amd/amdkfd/kfd_process.c | 18 +++++++++++-------
  2 files changed, 13 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -0
index 70ef051511bb..6a3cfeccacd8 100644
@@ -864,6 +864,8 @@ struct kfd_process_device {
  	bool has_reset_queue;
 
  	u32 pasid;
+	char pasid_filename[MAX_SYSFS_FILENAME_LEN];
+	struct attribute attr_pasid;
  };
 
  #define qpd_to_pdd(x) container_of(x, struct kfd_process_device, qpd)

drivers/gpu/drm/amd/amdkfd/kfd_priv.h struct kfd_process { · line 986

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -1
@@ -983,7 +985,6 @@ struct kfd_process {
  	/* Kobj for our procfs */
  	struct kobject *kobj;
  	struct kobject *kobj_queues;
-	struct attribute attr_pasid;

We keep it to have use space tools(ex rocm-smi) work as the tools still read it before they change.

drivers/gpu/drm/amd/amdkfd/kfd_priv.h void kfd_process_device_remove_obj_handle(struct kfd_process_device *pdd, · line 1107

Quoted 12 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -5
  	/* Keep track cwsr init */
  	bool has_cwsr;
@@ -1100,12 +1101,6 @@ void kfd_process_device_remove_obj_handle(struct kfd_process_device *pdd,
  					int handle);
  struct kfd_process *kfd_lookup_process_by_pid(struct pid *pid);
 
-/* PASIDs */
-int kfd_pasid_init(void);
-void kfd_pasid_exit(void);
-u32 kfd_pasid_alloc(void);
-void kfd_pasid_free(u32 pasid);

This part is right, these declarations were forgotten to remove.

Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -1
-
  /* Doorbells */
  size_t kfd_doorbell_process_slice(struct kfd_dev *kfd);
  int kfd_doorbell_init(struct kfd_dev *kfd);
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
index ddfe30c13e9d..24cf3b250b37 100644

drivers/gpu/drm/amd/amdkfd/kfd_process.c static int kfd_get_cu_occupancy(struct attribute *attr, char *buffer) · line 332

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -2
@@ -328,9 +328,11 @@ static int kfd_get_cu_occupancy(struct attribute *attr, char *buffer)
  static ssize_t kfd_procfs_show(struct kobject *kobj, struct attribute *attr,
  			       char *buffer)
  {
-	if (strcmp(attr->name, "pasid") == 0)
-		return snprintf(buffer, PAGE_SIZE, "%d\n", 0);

Same as above we keep it to have compatibility with current tools.

 Regards

Xiaogang

Quoted 54 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +11 -5
-	else if (strncmp(attr->name, "vram_", 5) == 0) {
+	if (strncmp(attr->name, "pasid_", 6) == 0) {
+		struct kfd_process_device *pdd = container_of(attr, struct kfd_process_device,
+							      attr_pasid);
+		return snprintf(buffer, PAGE_SIZE, "%u\n", pdd->pasid);
+	} else if (strncmp(attr->name, "vram_", 5) == 0) {
  		struct kfd_process_device *pdd = container_of(attr, struct kfd_process_device,
  							      attr_vram);
  		return snprintf(buffer, PAGE_SIZE, "%llu\n", atomic64_read(&pdd->vram_usage));
@@ -662,6 +664,7 @@ static void kfd_procfs_add_sysfs_files(struct kfd_process *p)
  	 * Create sysfs files for each GPU:
  	 * - proc/<pid>/vram_<gpuid>
  	 * - proc/<pid>/sdma_<gpuid>
+	 * - proc/<pid>/pasid_<gpuid>
  	 */
  	for (i = 0; i < p->n_pdds; i++) {
  		struct kfd_process_device *pdd = p->pdds[i];
@@ -675,6 +678,10 @@ static void kfd_procfs_add_sysfs_files(struct kfd_process *p)
  			 pdd->dev->id);
  		kfd_sysfs_create_file(p->kobj, &pdd->attr_sdma,
  					    pdd->sdma_filename);
+
+		snprintf(pdd->pasid_filename, MAX_SYSFS_FILENAME_LEN, "pasid_%u",
+			 pdd->dev->id);
+		kfd_sysfs_create_file(p->kobj, &pdd->attr_pasid, pdd->pasid_filename);
  	}
  }
 
@@ -888,9 +895,6 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)
  			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)
@@ -1104,7 +1108,6 @@ static void kfd_process_remove_sysfs(struct kfd_process *p)
  	if (!p->kobj)
  		return;
 
-	sysfs_remove_file(p->kobj, &p->attr_pasid);
  	kobject_del(p->kobj_queues);
  	kobject_put(p->kobj_queues);
  	p->kobj_queues = NULL;
@@ -1114,6 +1117,7 @@ static void kfd_process_remove_sysfs(struct kfd_process *p)
 
  		sysfs_remove_file(p->kobj, &pdd->attr_vram);
  		sysfs_remove_file(p->kobj, &pdd->attr_sdma);
+		sysfs_remove_file(p->kobj, &pdd->attr_pasid);
 
  		sysfs_remove_file(pdd->kobj_stats, &pdd->attr_evict);
  		if (pdd->dev->kfd2kgd->get_cu_occupancy)
#5 lore raw
Quoted 6 lines · Xiaogang
Quoted 3 lines · Zhu Lingshan

The pasid is a per-process-per-device attribute,
therefore this commit implements per
struct kfd_process_device->pasid in sysfs

This per device pasid is used internally in kfd, not used at user space. So no need to exposing it.

Agree completely, the PASID is a technical attribute we use internally in the kernel and should not expose to userspace at all.

Maybe in debugfs to narrow down problems, but certainly not in sysfs. That would make the internal handling an uAPI and so not changeable any more.

Regards,
Christian.

Quoted 105 lines
Quoted 19 lines

---
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  9 ++------- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 18 +++++++++++-------

  2 files changed, 13 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -0
index 70ef051511bb..6a3cfeccacd8 100644
@@ -864,6 +864,8 @@ struct kfd_process_device {
       bool has_reset_queue;
         u32 pasid;
+    char pasid_filename[MAX_SYSFS_FILENAME_LEN];
+    struct attribute attr_pasid;
   };
     #define qpd_to_pdd(x) container_of(x, struct kfd_process_device, qpd)

drivers/gpu/drm/amd/amdkfd/kfd_priv.h struct kfd_process { · line 986

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -1
@@ -983,7 +985,6 @@ struct kfd_process {
       /* Kobj for our procfs */
       struct kobject *kobj;
       struct kobject *kobj_queues;
-    struct attribute attr_pasid;

We keep it to have use space tools(ex rocm-smi) work as the tools still read it before they change.

drivers/gpu/drm/amd/amdkfd/kfd_priv.h void kfd_process_device_remove_obj_handle(struct kfd_process_device *pdd, · line 1107

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -0
         /* Keep track cwsr init */
       bool has_cwsr;
@@ -1100,12 +1101,6 @@ void kfd_process_device_remove_obj_handle(struct kfd_process_device *pdd,
                       int handle);
   struct kfd_process *kfd_lookup_process_by_pid(struct pid *pid);

  -/* PASIDs */

drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -4
-int kfd_pasid_init(void);
-void kfd_pasid_exit(void);
-u32 kfd_pasid_alloc(void);
-void kfd_pasid_free(u32 pasid);

This part is right, these declarations were forgotten to remove.

Quoted 9 lines

-
  /* Doorbells */
  size_t kfd_doorbell_process_slice(struct kfd_dev *kfd); int kfd_doorbell_init(struct kfd_dev *kfd);

drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
index ddfe30c13e9d..24cf3b250b37 100644

drivers/gpu/drm/amd/amdkfd/kfd_process.c static int kfd_get_cu_occupancy(struct attribute *attr, char *buffer) · line 332

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -2
@@ -328,9 +328,11 @@ static int kfd_get_cu_occupancy(struct attribute *attr, char *buffer)
   static ssize_t kfd_procfs_show(struct kobject *kobj, struct attribute *attr,
                      char *buffer)
   {
-    if (strcmp(attr->name, "pasid") == 0)
-        return snprintf(buffer, PAGE_SIZE, "%d\n", 0);

Same as above we keep it to have compatibility with current tools.

 Regards

Xiaogang

Quoted 49 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +10 -1
-    else if (strncmp(attr->name, "vram_", 5) == 0) {
+    if (strncmp(attr->name, "pasid_", 6) == 0) {
+        struct kfd_process_device *pdd = container_of(attr, struct kfd_process_device,
+                                  attr_pasid);
+        return snprintf(buffer, PAGE_SIZE, "%u\n", pdd->pasid);
+    } else if (strncmp(attr->name, "vram_", 5) == 0) {
           struct kfd_process_device *pdd = container_of(attr, struct kfd_process_device,
                                     attr_vram);
           return snprintf(buffer, PAGE_SIZE, "%llu\n", atomic64_read(&pdd->vram_usage));
@@ -662,6 +664,7 @@ static void kfd_procfs_add_sysfs_files(struct kfd_process *p)
        * Create sysfs files for each GPU:
        * - proc/<pid>/vram_<gpuid>
        * - proc/<pid>/sdma_<gpuid>
+     * - proc/<pid>/pasid_<gpuid>
        */
       for (i = 0; i < p->n_pdds; i++) {
           struct kfd_process_device *pdd = p->pdds[i];
@@ -675,6 +678,10 @@ static void kfd_procfs_add_sysfs_files(struct kfd_process *p)
                pdd->dev->id);
           kfd_sysfs_create_file(p->kobj, &pdd->attr_sdma,
                           pdd->sdma_filename);
+
+        snprintf(pdd->pasid_filename, MAX_SYSFS_FILENAME_LEN, "pasid_%u",
+             pdd->dev->id);
+        kfd_sysfs_create_file(p->kobj, &pdd->attr_pasid, pdd->pasid_filename);
       }
   }
   @@ -888,9 +895,6 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)

              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)

drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -0
@@ -1104,7 +1108,6 @@ static void kfd_process_remove_sysfs(struct kfd_process *p)
       if (!p->kobj)
           return;
   -    sysfs_remove_file(p->kobj, &p->attr_pasid);
       kobject_del(p->kobj_queues);
       kobject_put(p->kobj_queues);
       p->kobj_queues = NULL;
@@ -1114,6 +1117,7 @@ static void kfd_process_remove_sysfs(struct kfd_process *p)
             sysfs_remove_file(p->kobj, &pdd->attr_vram);
           sysfs_remove_file(p->kobj, &pdd->attr_sdma);
+        sysfs_remove_file(p->kobj, &pdd->attr_pasid);
             sysfs_remove_file(pdd->kobj_stats, &pdd->attr_evict);
           if (pdd->dev->kfd2kgd->get_cu_occupancy)
#6 lore raw
Quoted 7 lines · Christian König
Quoted 5 lines · Xiaogang
Quoted 3 lines · Zhu Lingshan

The pasid is a per-process-per-device attribute,
therefore this commit implements per
struct kfd_process_device->pasid in sysfs

This per device pasid is used internally in kfd, not used at user space. So no need to exposing it.

Agree completely, the PASID is a technical attribute we use internally in the kernel and should not expose to userspace at all.

current kfd sysfs reports pasid to user space, but buggy hard-coded zero, this patch tries fixing this issue. Or we should remove sysfs/pasid if user space does not need it at all.

Thanks
Lingshan

Quoted 109 lines

Maybe in debugfs to narrow down problems, but certainly not in sysfs. That would make the internal handling an uAPI and so not changeable any more.

Regards,
Christian.

Quoted 103 lines
Quoted 18 lines

---
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  9 ++------- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 18 +++++++++++-------

  2 files changed, 13 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -0
index 70ef051511bb..6a3cfeccacd8 100644
@@ -864,6 +864,8 @@ struct kfd_process_device {
       bool has_reset_queue;
         u32 pasid;
+    char pasid_filename[MAX_SYSFS_FILENAME_LEN];
+    struct attribute attr_pasid;
   };
     #define qpd_to_pdd(x) container_of(x, struct kfd_process_device, qpd)

drivers/gpu/drm/amd/amdkfd/kfd_priv.h struct kfd_process { · line 986

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -1
@@ -983,7 +985,6 @@ struct kfd_process {
       /* Kobj for our procfs */
       struct kobject *kobj;
       struct kobject *kobj_queues;
-    struct attribute attr_pasid;

We keep it to have use space tools(ex rocm-smi) work as the tools still read it before they change.

drivers/gpu/drm/amd/amdkfd/kfd_priv.h void kfd_process_device_remove_obj_handle(struct kfd_process_device *pdd, · line 1107

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -0
         /* Keep track cwsr init */
       bool has_cwsr;
@@ -1100,12 +1101,6 @@ void kfd_process_device_remove_obj_handle(struct kfd_process_device *pdd,
                       int handle);
   struct kfd_process *kfd_lookup_process_by_pid(struct pid *pid);

  -/* PASIDs */

drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -4
-int kfd_pasid_init(void);
-void kfd_pasid_exit(void);
-u32 kfd_pasid_alloc(void);
-void kfd_pasid_free(u32 pasid);

This part is right, these declarations were forgotten to remove.

Quoted 9 lines

-
  /* Doorbells */
  size_t kfd_doorbell_process_slice(struct kfd_dev *kfd); int kfd_doorbell_init(struct kfd_dev *kfd);

drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
index ddfe30c13e9d..24cf3b250b37 100644

drivers/gpu/drm/amd/amdkfd/kfd_process.c static int kfd_get_cu_occupancy(struct attribute *attr, char *buffer) · line 332

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -2
@@ -328,9 +328,11 @@ static int kfd_get_cu_occupancy(struct attribute *attr, char *buffer)
   static ssize_t kfd_procfs_show(struct kobject *kobj, struct attribute *attr,
                      char *buffer)
   {
-    if (strcmp(attr->name, "pasid") == 0)
-        return snprintf(buffer, PAGE_SIZE, "%d\n", 0);

Same as above we keep it to have compatibility with current tools.

 Regards

Xiaogang

Quoted 49 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +10 -1
-    else if (strncmp(attr->name, "vram_", 5) == 0) {
+    if (strncmp(attr->name, "pasid_", 6) == 0) {
+        struct kfd_process_device *pdd = container_of(attr, struct kfd_process_device,
+                                  attr_pasid);
+        return snprintf(buffer, PAGE_SIZE, "%u\n", pdd->pasid);
+    } else if (strncmp(attr->name, "vram_", 5) == 0) {
           struct kfd_process_device *pdd = container_of(attr, struct kfd_process_device,
                                     attr_vram);
           return snprintf(buffer, PAGE_SIZE, "%llu\n", atomic64_read(&pdd->vram_usage));
@@ -662,6 +664,7 @@ static void kfd_procfs_add_sysfs_files(struct kfd_process *p)
        * Create sysfs files for each GPU:
        * - proc/<pid>/vram_<gpuid>
        * - proc/<pid>/sdma_<gpuid>
+     * - proc/<pid>/pasid_<gpuid>
        */
       for (i = 0; i < p->n_pdds; i++) {
           struct kfd_process_device *pdd = p->pdds[i];
@@ -675,6 +678,10 @@ static void kfd_procfs_add_sysfs_files(struct kfd_process *p)
                pdd->dev->id);
           kfd_sysfs_create_file(p->kobj, &pdd->attr_sdma,
                           pdd->sdma_filename);
+
+        snprintf(pdd->pasid_filename, MAX_SYSFS_FILENAME_LEN, "pasid_%u",
+             pdd->dev->id);
+        kfd_sysfs_create_file(p->kobj, &pdd->attr_pasid, pdd->pasid_filename);
       }
   }
   @@ -888,9 +895,6 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)

              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)

drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -0
@@ -1104,7 +1108,6 @@ static void kfd_process_remove_sysfs(struct kfd_process *p)
       if (!p->kobj)
           return;
   -    sysfs_remove_file(p->kobj, &p->attr_pasid);
       kobject_del(p->kobj_queues);
       kobject_put(p->kobj_queues);
       p->kobj_queues = NULL;
@@ -1114,6 +1117,7 @@ static void kfd_process_remove_sysfs(struct kfd_process *p)
             sysfs_remove_file(p->kobj, &pdd->attr_vram);
           sysfs_remove_file(p->kobj, &pdd->attr_sdma);
+        sysfs_remove_file(p->kobj, &pdd->attr_pasid);
             sysfs_remove_file(pdd->kobj_stats, &pdd->attr_evict);
           if (pdd->dev->kfd2kgd->get_cu_occupancy)
#7 lore raw
In reply to Chen, Xiaogang
Quoted 7 lines · Xiaogang
Quoted 3 lines · Zhu Lingshan

The pasid is a per-process-per-device attribute,
therefore this commit implements per
struct kfd_process_device->pasid in sysfs

This per device pasid is used internally in kfd, not used at user space. So no need to exposing it.

current sysfs implementation exposing PASID to user space, but buggy value 0, this commit intends to fix this issue.

Thanks
Lingshan

Quoted 122 lines
Quoted 21 lines

---
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  9 ++------- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 18 +++++++++++-------

  2 files changed, 13 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -0
index 70ef051511bb..6a3cfeccacd8 100644
@@ -864,6 +864,8 @@ struct kfd_process_device {
       bool has_reset_queue;
         u32 pasid;
+    char pasid_filename[MAX_SYSFS_FILENAME_LEN];
+    struct attribute attr_pasid;
   };
     #define qpd_to_pdd(x) container_of(x, struct kfd_process_device,
 qpd)

drivers/gpu/drm/amd/amdkfd/kfd_priv.h struct kfd_process { · line 986

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -1
@@ -983,7 +985,6 @@ struct kfd_process {
       /* Kobj for our procfs */
       struct kobject *kobj;
       struct kobject *kobj_queues;
-    struct attribute attr_pasid;

We keep it to have use space tools(ex rocm-smi) work as the tools still read it before they change.

drivers/gpu/drm/amd/amdkfd/kfd_priv.h void kfd_process_device_remove_obj_handle(struct kfd_process_device *pdd, · line 1107

Quoted 11 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -0
         /* Keep track cwsr init */
       bool has_cwsr;
@@ -1100,12 +1101,6 @@ void
 kfd_process_device_remove_obj_handle(struct kfd_process_device *pdd,
                       int handle);
   struct kfd_process *kfd_lookup_process_by_pid(struct pid *pid);

  -/* PASIDs */

drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -4
-int kfd_pasid_init(void);
-void kfd_pasid_exit(void);
-u32 kfd_pasid_alloc(void);
-void kfd_pasid_free(u32 pasid);

This part is right, these declarations were forgotten to remove.

Quoted 11 lines

-
  /* Doorbells */
  size_t kfd_doorbell_process_slice(struct kfd_dev *kfd); int kfd_doorbell_init(struct kfd_dev *kfd);

drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
index ddfe30c13e9d..24cf3b250b37 100644
@@ -328,9 +328,11 @@ static int kfd_get_cu_occupancy(struct attribute
 *attr, char *buffer)
Quoted 6 lines

  static ssize_t kfd_procfs_show(struct kobject *kobj, struct attribute *attr,
                     char *buffer)
  {
-    if (strcmp(attr->name, "pasid") == 0)
-        return snprintf(buffer, PAGE_SIZE, "%d\n", 0);

Same as above we keep it to have compatibility with current tools.

 Regards

Xiaogang

Quoted 59 lines

-    else if (strncmp(attr->name, "vram_", 5) == 0) {
+    if (strncmp(attr->name, "pasid_", 6) == 0) {
+        struct kfd_process_device *pdd = container_of(attr, struct kfd_process_device,
+                                  attr_pasid);
+        return snprintf(buffer, PAGE_SIZE, "%u\n", pdd->pasid); +    } else if (strncmp(attr->name, "vram_", 5) == 0) { struct kfd_process_device *pdd = container_of(attr, struct kfd_process_device,
                                    attr_vram);
          return snprintf(buffer, PAGE_SIZE, "%llu\n", atomic64_read(&pdd->vram_usage));

drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -0
@@ -662,6 +664,7 @@ static void kfd_procfs_add_sysfs_files(struct
 kfd_process *p)
        * Create sysfs files for each GPU:
        * - proc/<pid>/vram_<gpuid>
        * - proc/<pid>/sdma_<gpuid>
+     * - proc/<pid>/pasid_<gpuid>
        */
       for (i = 0; i < p->n_pdds; i++) {

          struct kfd_process_device *pdd = p->pdds[i];

drivers/gpu/drm/amd/amdkfd/kfd_process.c +4 -0
@@ -675,6 +678,10 @@ static void kfd_procfs_add_sysfs_files(struct
 kfd_process *p)
                pdd->dev->id);
           kfd_sysfs_create_file(p->kobj, &pdd->attr_sdma,
                           pdd->sdma_filename);
+
+        snprintf(pdd->pasid_filename, MAX_SYSFS_FILENAME_LEN,
 "pasid_%u",
+             pdd->dev->id);
+        kfd_sysfs_create_file(p->kobj, &pdd->attr_pasid,
 pdd->pasid_filename);

      }
  }
  @@ -888,9 +895,6 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)
              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)

drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
@@ -1104,7 +1108,6 @@ static void kfd_process_remove_sysfs(struct
 kfd_process *p)
       if (!p->kobj)
           return;
   -    sysfs_remove_file(p->kobj, &p->attr_pasid);
       kobject_del(p->kobj_queues);
       kobject_put(p->kobj_queues);

      p->kobj_queues = NULL;

drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -0
@@ -1114,6 +1117,7 @@ static void kfd_process_remove_sysfs(struct
 kfd_process *p)
             sysfs_remove_file(p->kobj, &pdd->attr_vram);
           sysfs_remove_file(p->kobj, &pdd->attr_sdma);
+        sysfs_remove_file(p->kobj, &pdd->attr_pasid);
             sysfs_remove_file(pdd->kobj_stats, &pdd->attr_evict);
           if (pdd->dev->kfd2kgd->get_cu_occupancy)
#8 lore raw
Quoted 9 lines · Lingshan
Quoted 6 lines · Xiaogang
Quoted 3 lines · Zhu Lingshan

The pasid is a per-process-per-device attribute,
therefore this commit implements per
struct kfd_process_device->pasid in sysfs

This per device pasid is used internally in kfd, not used at user space. So no need to exposing it.

current sysfs implementation exposing PASID to user space, but buggy value 0, this commit intends to fix this issue.

It is just for keeping current tools working. The PASID value has no meaning for use space that it would not get useful info about driver through it or uses PASID to change driver behavior.

Regards

Xiaogang

Quoted 117 lines

Thanks
Lingshan

Quoted 114 lines
Quoted 19 lines

---
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  9 ++------- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 18 +++++++++++-------

  2 files changed, 13 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -0
index 70ef051511bb..6a3cfeccacd8 100644
@@ -864,6 +864,8 @@ struct kfd_process_device {
       bool has_reset_queue;
         u32 pasid;
+    char pasid_filename[MAX_SYSFS_FILENAME_LEN];
+    struct attribute attr_pasid;
   };
     #define qpd_to_pdd(x) container_of(x, struct kfd_process_device, qpd)

drivers/gpu/drm/amd/amdkfd/kfd_priv.h struct kfd_process { · line 986

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -1
@@ -983,7 +985,6 @@ struct kfd_process {
       /* Kobj for our procfs */
       struct kobject *kobj;
       struct kobject *kobj_queues;
-    struct attribute attr_pasid;

We keep it to have use space tools(ex rocm-smi) work as the tools still read it before they change.

drivers/gpu/drm/amd/amdkfd/kfd_priv.h void kfd_process_device_remove_obj_handle(struct kfd_process_device *pdd, · line 1107

Quoted 11 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -0
         /* Keep track cwsr init */
       bool has_cwsr;
@@ -1100,12 +1101,6 @@ void 
 kfd_process_device_remove_obj_handle(struct kfd_process_device *pdd,
                       int handle);
   struct kfd_process *kfd_lookup_process_by_pid(struct pid *pid);

  -/* PASIDs */

drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -4
-int kfd_pasid_init(void);
-void kfd_pasid_exit(void);
-u32 kfd_pasid_alloc(void);
-void kfd_pasid_free(u32 pasid);

This part is right, these declarations were forgotten to remove.

Quoted 9 lines

-
  /* Doorbells */
  size_t kfd_doorbell_process_slice(struct kfd_dev *kfd); int kfd_doorbell_init(struct kfd_dev *kfd);

drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
index ddfe30c13e9d..24cf3b250b37 100644

drivers/gpu/drm/amd/amdkfd/kfd_process.c static int kfd_get_cu_occupancy(struct · line 333

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -2
@@ -328,9 +328,11 @@ static int kfd_get_cu_occupancy(struct 
 attribute *attr, char *buffer)
   static ssize_t kfd_procfs_show(struct kobject *kobj, struct attribute *attr,
                      char *buffer)
   {
-    if (strcmp(attr->name, "pasid") == 0)
-        return snprintf(buffer, PAGE_SIZE, "%d\n", 0);

Same as above we keep it to have compatibility with current tools.

 Regards

Xiaogang

Quoted 56 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +5 -1
-    else if (strncmp(attr->name, "vram_", 5) == 0) {
+    if (strncmp(attr->name, "pasid_", 6) == 0) {
+        struct kfd_process_device *pdd = container_of(attr, struct 
 kfd_process_device,
+                                  attr_pasid);
+        return snprintf(buffer, PAGE_SIZE, "%u\n", pdd->pasid);
+    } else if (strncmp(attr->name, "vram_", 5) == 0) {
           struct kfd_process_device *pdd = container_of(attr, struct kfd_process_device,

                                    attr_vram);
          return snprintf(buffer, PAGE_SIZE, "%llu\n", atomic64_read(&pdd->vram_usage));

drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -0
@@ -662,6 +664,7 @@ static void kfd_procfs_add_sysfs_files(struct 
 kfd_process *p)
        * Create sysfs files for each GPU:
        * - proc/<pid>/vram_<gpuid>
        * - proc/<pid>/sdma_<gpuid>
+     * - proc/<pid>/pasid_<gpuid>
        */
       for (i = 0; i < p->n_pdds; i++) {

          struct kfd_process_device *pdd = p->pdds[i];

drivers/gpu/drm/amd/amdkfd/kfd_process.c +4 -0
@@ -675,6 +678,10 @@ static void kfd_procfs_add_sysfs_files(struct 
 kfd_process *p)
                pdd->dev->id);
           kfd_sysfs_create_file(p->kobj, &pdd->attr_sdma,
                           pdd->sdma_filename);
+
+        snprintf(pdd->pasid_filename, MAX_SYSFS_FILENAME_LEN, 
 "pasid_%u",
+             pdd->dev->id);
+        kfd_sysfs_create_file(p->kobj, &pdd->attr_pasid, 
 pdd->pasid_filename);

      }
  }
  @@ -888,9 +895,6 @@ struct kfd_process *kfd_create_process(struct task_struct *thread) 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)

drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
@@ -1104,7 +1108,6 @@ static void kfd_process_remove_sysfs(struct 
 kfd_process *p)
       if (!p->kobj)
           return;
   -    sysfs_remove_file(p->kobj, &p->attr_pasid);
       kobject_del(p->kobj_queues);
       kobject_put(p->kobj_queues);

      p->kobj_queues = NULL;

drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -0
@@ -1114,6 +1117,7 @@ static void kfd_process_remove_sysfs(struct 
 kfd_process *p)
             sysfs_remove_file(p->kobj, &pdd->attr_vram);
           sysfs_remove_file(p->kobj, &pdd->attr_sdma);
+        sysfs_remove_file(p->kobj, &pdd->attr_pasid);
             sysfs_remove_file(pdd->kobj_stats, &pdd->attr_evict);
           if (pdd->dev->kfd2kgd->get_cu_occupancy)
#9 lore raw
In reply to Zhu Lingshan

We already have pasid in debugfs under /sys/kernel/debug/kfd/proc/<pid>/pasid_<gpuid> with my patch "drm/amdkfd: add pasid debugfs entries", so what is the point to add it in sysfs?

Regards,
Eric

Quoted 108 lines · Zhu Lingshan

The pasid is a per-process-per-device attribute,
therefore this commit implements per
struct kfd_process_device->pasid in sysfs

---
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  9 ++-------
  drivers/gpu/drm/amd/amdkfd/kfd_process.c | 18 +++++++++++-------
  2 files changed, 13 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -7
index 70ef051511bb..6a3cfeccacd8 100644
@@ -864,6 +864,8 @@ struct kfd_process_device {
  	bool has_reset_queue;
 
  	u32 pasid;
+	char pasid_filename[MAX_SYSFS_FILENAME_LEN];
+	struct attribute attr_pasid;
  };
 
  #define qpd_to_pdd(x) container_of(x, struct kfd_process_device, qpd)
@@ -983,7 +985,6 @@ struct kfd_process {
  	/* Kobj for our procfs */
  	struct kobject *kobj;
  	struct kobject *kobj_queues;
-	struct attribute attr_pasid;
 
  	/* Keep track cwsr init */
  	bool has_cwsr;
@@ -1100,12 +1101,6 @@ void kfd_process_device_remove_obj_handle(struct kfd_process_device *pdd,
  					int handle);
  struct kfd_process *kfd_lookup_process_by_pid(struct pid *pid);
 
-/* PASIDs */
-int kfd_pasid_init(void);
-void kfd_pasid_exit(void);
-u32 kfd_pasid_alloc(void);
-void kfd_pasid_free(u32 pasid);
-
  /* Doorbells */
  size_t kfd_doorbell_process_slice(struct kfd_dev *kfd);
  int kfd_doorbell_init(struct kfd_dev *kfd);
drivers/gpu/drm/amd/amdkfd/kfd_process.c +11 -7
index ddfe30c13e9d..24cf3b250b37 100644
@@ -328,9 +328,11 @@ static int kfd_get_cu_occupancy(struct attribute *attr, char *buffer)
  static ssize_t kfd_procfs_show(struct kobject *kobj, struct attribute *attr,
  			       char *buffer)
  {
-	if (strcmp(attr->name, "pasid") == 0)
-		return snprintf(buffer, PAGE_SIZE, "%d\n", 0);
-	else if (strncmp(attr->name, "vram_", 5) == 0) {
+	if (strncmp(attr->name, "pasid_", 6) == 0) {
+		struct kfd_process_device *pdd = container_of(attr, struct kfd_process_device,
+							      attr_pasid);
+		return snprintf(buffer, PAGE_SIZE, "%u\n", pdd->pasid);
+	} else if (strncmp(attr->name, "vram_", 5) == 0) {
  		struct kfd_process_device *pdd = container_of(attr, struct kfd_process_device,
  							      attr_vram);
  		return snprintf(buffer, PAGE_SIZE, "%llu\n", atomic64_read(&pdd->vram_usage));
@@ -662,6 +664,7 @@ static void kfd_procfs_add_sysfs_files(struct kfd_process *p)
  	 * Create sysfs files for each GPU:
  	 * - proc/<pid>/vram_<gpuid>
  	 * - proc/<pid>/sdma_<gpuid>
+	 * - proc/<pid>/pasid_<gpuid>
  	 */
  	for (i = 0; i < p->n_pdds; i++) {
  		struct kfd_process_device *pdd = p->pdds[i];
@@ -675,6 +678,10 @@ static void kfd_procfs_add_sysfs_files(struct kfd_process *p)
  			 pdd->dev->id);
  		kfd_sysfs_create_file(p->kobj, &pdd->attr_sdma,
  					    pdd->sdma_filename);
+
+		snprintf(pdd->pasid_filename, MAX_SYSFS_FILENAME_LEN, "pasid_%u",
+			 pdd->dev->id);
+		kfd_sysfs_create_file(p->kobj, &pdd->attr_pasid, pdd->pasid_filename);
  	}
  }
 
@@ -888,9 +895,6 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)
  			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)
@@ -1104,7 +1108,6 @@ static void kfd_process_remove_sysfs(struct kfd_process *p)
  	if (!p->kobj)
  		return;
 
-	sysfs_remove_file(p->kobj, &p->attr_pasid);
  	kobject_del(p->kobj_queues);
  	kobject_put(p->kobj_queues);
  	p->kobj_queues = NULL;
@@ -1114,6 +1117,7 @@ static void kfd_process_remove_sysfs(struct kfd_process *p)
 
  		sysfs_remove_file(p->kobj, &pdd->attr_vram);
  		sysfs_remove_file(p->kobj, &pdd->attr_sdma);
+		sysfs_remove_file(p->kobj, &pdd->attr_pasid);
 
  		sysfs_remove_file(pdd->kobj_stats, &pdd->attr_evict);
  		if (pdd->dev->kfd2kgd->get_cu_occupancy)