[PATCH v5 6/6] drm/amdgpu: use drm_file::name in task_info::process_desc

Pierre-Eric Pelloux-Prayer pierre-eric at damsy.net
Wed Oct 9 07:52:03 UTC 2024



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 at amd.com>
>> ---
>>   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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0006-drm-amdgpu-use-drm_file-name-in-task_info-process_de.patch
Type: text/x-patch
Size: 6925 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/dri-devel/attachments/20241009/4717f84d/attachment.bin>


More information about the dri-devel mailing list