Le 08/10/2024 à 10:24, Christian König a écrit :
Am 03.10.24 um 14:43 schrieb Pierre-Eric Pelloux-Prayer:
If a drm_file name is set append it to the process name.
This information is useful with the virtio/native-context driver: this
allows the guest applications identifier to visible in amdgpu's output.
The output in amdgpu_vm_info/amdgpu_gem_info looks like this:
pid:12255 Process:glxgears/test-set-fd-name ----------
Signed-off-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@xxxxxxx>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 1 +
.../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 34 ++++++++++++++-----
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 +-
drivers/gpu/drm/amd/amdkfd/kfd_process.c | 3 ++
6 files changed, 34 insertions(+), 11 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index f9d119448442..ad909173e419 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
@@ -299,6 +299,7 @@ int amdgpu_amdkfd_gpuvm_set_vm_pasid(struct amdgpu_device *adev,
struct amdgpu_vm *avm, u32 pasid);
int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct amdgpu_device *adev,
struct amdgpu_vm *avm,
+ struct drm_file *filp,
void **process_info,
struct dma_fence **ef);
void amdgpu_amdkfd_gpuvm_release_process_vm(struct amdgpu_device *adev,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/
amdgpu_amdkfd_gpuvm.c
index 6d5fd371d5ce..172882af6705 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1558,6 +1558,7 @@ int amdgpu_amdkfd_gpuvm_set_vm_pasid(struct amdgpu_device *adev,
int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct amdgpu_device *adev,
struct amdgpu_vm *avm,
+ struct drm_file *filp,
void **process_info,
struct dma_fence **ef)
{
@@ -1577,7 +1578,7 @@ int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct amdgpu_device *adev,
if (ret)
return ret;
- amdgpu_vm_set_task_info(avm);
+ amdgpu_vm_set_task_info(avm, filp);
return 0;
}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 891128ecee6d..5d43e24906d2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -1178,7 +1178,7 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)
}
/* Use this opportunity to fill in task info for the vm */
- amdgpu_vm_set_task_info(vm);
+ amdgpu_vm_set_task_info(vm, p->filp);
if (adev->debug_vm) {
/* Invalidate all BOs to test for userspace bugs */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 561ff832930e..920660c23e0f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -2355,24 +2355,41 @@ amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid)
amdgpu_vm_get_vm_from_pasid(adev, pasid));
}
-static int amdgpu_vm_create_task_info(struct amdgpu_vm *vm)
+static int amdgpu_vm_create_task_info(struct amdgpu_vm *vm, struct drm_file *filp)
It would be nice to pass in only the const char *client_name here and lock/unlock the mutex outside
of the VM code.
Only nice to have, but I would rather like to keep the drm_file internals outside of the VM code.
Fixed in the attached patch.
Pierre-Eric
Regards,
Christian.
{
char process_name[TASK_COMM_LEN];
- size_t pname_len;
+ size_t pname_len, pdesc_len;
get_task_comm(process_name, current->group_leader);
- pname_len = strlen(process_name);
+ pdesc_len = pname_len = strlen(process_name);
+
+ mutex_lock(&filp->client_name_lock);
+ if (filp->client_name)
+ pdesc_len += strlen(filp->client_name) + 1;
+
+ /* Add 1 for the NUL char. */
+ pdesc_len += 1;
vm->task_info = kzalloc(
- struct_size(vm->task_info, process_desc, pname_len + 1),
+ struct_size(vm->task_info, process_desc, pdesc_len),
GFP_KERNEL);
- if (!vm->task_info)
+ if (!vm->task_info) {
+ mutex_unlock(&filp->client_name_lock);
return -ENOMEM;
+ }
/* Set process attributes now. */
vm->task_info->tgid = current->group_leader->pid;
- strscpy(vm->task_info->process_desc, process_name, pname_len + 1);
+ strscpy(vm->task_info->process_desc, process_name, pdesc_len);
+
+ if (filp->client_name) {
+ /* Append the drm-client-name. */
+ vm->task_info->process_desc[pname_len] = '/';
+ strscpy(&vm->task_info->process_desc[pname_len + 1],
+ filp->client_name, pdesc_len - (pname_len + 1));
+ }
+ mutex_unlock(&filp->client_name_lock);
kref_init(&vm->task_info->refcount);
return 0;
@@ -2382,11 +2399,12 @@ static int amdgpu_vm_create_task_info(struct amdgpu_vm *vm)
* amdgpu_vm_set_task_info - Sets VMs task info.
*
* @vm: vm for which to set the info
+ * @filp: drm_file instance
*/
-void amdgpu_vm_set_task_info(struct amdgpu_vm *vm)
+void amdgpu_vm_set_task_info(struct amdgpu_vm *vm, struct drm_file *filp)
{
if (!vm->task_info) {
- if (amdgpu_vm_create_task_info(vm))
+ if (amdgpu_vm_create_task_info(vm, filp))
return;
} else if (vm->task_info->pid == current->pid) {
return;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
index 44da250217be..8df3dece54c2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
@@ -561,7 +561,7 @@ bool amdgpu_vm_handle_fault(struct amdgpu_device *adev, u32 pasid,
u32 vmid, u32 node_id, uint64_t addr, uint64_t ts,
bool write_fault);
-void amdgpu_vm_set_task_info(struct amdgpu_vm *vm);
+void amdgpu_vm_set_task_info(struct amdgpu_vm *vm, struct drm_file *filp);
void amdgpu_vm_move_to_lru_tail(struct amdgpu_device *adev,
struct amdgpu_vm *vm);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index a902950cc060..e473fe433d3f 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -1654,6 +1654,7 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd,
struct file *drm_file)
{
struct amdgpu_fpriv *drv_priv;
+ struct drm_file *filp;
struct amdgpu_vm *avm;
struct kfd_process *p;
struct dma_fence *ef;
@@ -1673,8 +1674,10 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd,
p = pdd->process;
dev = pdd->dev;
+ filp = drm_file->private_data;
ret = amdgpu_amdkfd_gpuvm_acquire_process_vm(dev->adev, avm,
+ filp,
&p->kgd_process_info,
&ef);
if (ret) {
From 38d40d25d24f94d2e5bb8b295789fb14671993e0 Mon Sep 17 00:00:00 2001
From: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@xxxxxxx>
Date: Fri, 20 Sep 2024 11:06:48 +0200
Subject: [PATCH 6/6] drm/amdgpu: use drm_file::name in task_info::process_desc
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
If a drm_file name is set append it to the process name.
This information is useful with the virtio/native-context driver: this
allows the guest applications identifier to visible in amdgpu's output.
The output in amdgpu_vm_info/amdgpu_gem_info looks like this:
pid:12255 Process:glxgears/test-set-fd-name ----------
Reviewed-by: Christian König <christian.koenig@xxxxxxx>
Signed-off-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@xxxxxxx>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 1 +
.../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 5 +++-
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 4 ++-
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 29 ++++++++++++++-----
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 +-
drivers/gpu/drm/amd/amdkfd/kfd_process.c | 3 ++
6 files changed, 34 insertions(+), 10 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index f9d119448442..ad909173e419 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
@@ -299,6 +299,7 @@ int amdgpu_amdkfd_gpuvm_set_vm_pasid(struct amdgpu_device *adev,
struct amdgpu_vm *avm, u32 pasid);
int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct amdgpu_device *adev,
struct amdgpu_vm *avm,
+ struct drm_file *filp,
void **process_info,
struct dma_fence **ef);
void amdgpu_amdkfd_gpuvm_release_process_vm(struct amdgpu_device *adev,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index ce5ca304dba9..a241e2e96c6c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1552,6 +1552,7 @@ int amdgpu_amdkfd_gpuvm_set_vm_pasid(struct amdgpu_device *adev,
int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct amdgpu_device *adev,
struct amdgpu_vm *avm,
+ struct drm_file *filp,
void **process_info,
struct dma_fence **ef)
{
@@ -1571,7 +1572,9 @@ int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct amdgpu_device *adev,
if (ret)
return ret;
- amdgpu_vm_set_task_info(avm);
+ mutex_lock(&filp->client_name_lock);
+ amdgpu_vm_set_task_info(avm, filp->client_name);
+ mutex_unlock(&filp->client_name_lock);
return 0;
}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 891128ecee6d..04f25a5a63f3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -1178,7 +1178,9 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)
}
/* Use this opportunity to fill in task info for the vm */
- amdgpu_vm_set_task_info(vm);
+ mutex_lock(&p->filp->client_name_lock);
+ amdgpu_vm_set_task_info(vm, p->filp->client_name);
+ mutex_unlock(&p->filp->client_name_lock);
if (adev->debug_vm) {
/* Invalidate all BOs to test for userspace bugs */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index be149978447d..6363ad76d26f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -2371,16 +2371,23 @@ amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid)
amdgpu_vm_get_vm_from_pasid(adev, pasid));
}
-static int amdgpu_vm_create_task_info(struct amdgpu_vm *vm)
+static int amdgpu_vm_create_task_info(struct amdgpu_vm *vm,
+ const char *client_name)
{
char process_name[TASK_COMM_LEN];
- size_t pname_len;
+ size_t pname_len, pdesc_len;
get_task_comm(process_name, current->group_leader);
- pname_len = strlen(process_name);
+ pdesc_len = pname_len = strlen(process_name);
+
+ if (client_name)
+ pdesc_len += strlen(client_name) + 1;
+
+ /* Add 1 for the NUL char. */
+ pdesc_len += 1;
vm->task_info = kzalloc(
- struct_size(vm->task_info, process_desc, pname_len + 1),
+ struct_size(vm->task_info, process_desc, pdesc_len),
GFP_KERNEL);
if (!vm->task_info)
@@ -2388,7 +2395,14 @@ static int amdgpu_vm_create_task_info(struct amdgpu_vm *vm)
/* Set process attributes now. */
vm->task_info->tgid = current->group_leader->pid;
- strscpy(vm->task_info->process_desc, process_name, pname_len + 1);
+ strscpy(vm->task_info->process_desc, process_name, pdesc_len);
+
+ if (client_name) {
+ /* Append the drm-client-name. */
+ vm->task_info->process_desc[pname_len] = '/';
+ strscpy(&vm->task_info->process_desc[pname_len + 1],
+ client_name, pdesc_len - (pname_len + 1));
+ }
kref_init(&vm->task_info->refcount);
return 0;
@@ -2398,11 +2412,12 @@ static int amdgpu_vm_create_task_info(struct amdgpu_vm *vm)
* amdgpu_vm_set_task_info - Sets VMs task info.
*
* @vm: vm for which to set the info
+ * @client_name: optional debug name attached
*/
-void amdgpu_vm_set_task_info(struct amdgpu_vm *vm)
+void amdgpu_vm_set_task_info(struct amdgpu_vm *vm, const char *client_name)
{
if (!vm->task_info) {
- if (amdgpu_vm_create_task_info(vm))
+ if (amdgpu_vm_create_task_info(vm, client_name))
return;
} else if (vm->task_info->pid == current->pid) {
return;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
index 8220469c05b3..10e1315bcdc6 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
@@ -562,7 +562,7 @@ bool amdgpu_vm_handle_fault(struct amdgpu_device *adev, u32 pasid,
u32 vmid, u32 node_id, uint64_t addr, uint64_t ts,
bool write_fault);
-void amdgpu_vm_set_task_info(struct amdgpu_vm *vm);
+void amdgpu_vm_set_task_info(struct amdgpu_vm *vm, const char *client_name);
void amdgpu_vm_move_to_lru_tail(struct amdgpu_device *adev,
struct amdgpu_vm *vm);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index d07acf1b2f93..fc87966adb6a 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -1680,6 +1680,7 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd,
struct file *drm_file)
{
struct amdgpu_fpriv *drv_priv;
+ struct drm_file *filp;
struct amdgpu_vm *avm;
struct kfd_process *p;
struct dma_fence *ef;
@@ -1699,8 +1700,10 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd,
p = pdd->process;
dev = pdd->dev;
+ filp = drm_file->private_data;
ret = amdgpu_amdkfd_gpuvm_acquire_process_vm(dev->adev, avm,
+ filp,
&p->kgd_process_info,
&ef);
if (ret) {
--
2.40.1