From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: "Pierre-Eric Pelloux-Prayer" <pierre-eric@damsy.net>,
"Christian König" <christian.koenig@amd.com>,
"Pierre-Eric Pelloux-Prayer" <pierre-eric.pelloux-prayer@amd.com>,
alexander.deucher@amd.com, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH 1/2] amdgpu: add the amdgpu_vm ptr in the vm_bo_map/unmap events
Date: Mon, 3 Jun 2024 16:12:29 +0200 [thread overview]
Message-ID: <4e1ae4fb-472a-40a6-a26d-7f9aff709057@gmail.com> (raw)
In-Reply-To: <011928f3-ae86-4506-a9a5-1ced96032f34@damsy.net>
Am 03.06.24 um 13:52 schrieb Pierre-Eric Pelloux-Prayer:
> Hi Christia,
>
> Le 03/06/2024 à 11:58, Christian König a écrit :
>> Am 03.06.24 um 10:46 schrieb Pierre-Eric Pelloux-Prayer:
>>> These 2 traces events are tied to a specific VM so in order for them
>>> to be useful for a tool we need to trace the amdgpu_vm as well.
>>
>> The bo_va already contains the VM pointer the map/unmap operation
>> belongs to.
>>
>
> Indeed, I've missed that. I'll fix that in v2.
>
>>>
>>> Signed-off-by: Pierre-Eric Pelloux-Prayer
>>> <pierre-eric.pelloux-prayer@amd.com>
>>> ---
>>> drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h | 20 ++++++++++++--------
>>> drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 ++++----
>>> 2 files changed, 16 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h
>>> index f539b1d00234..c84050d318d6 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h
>>> @@ -243,10 +243,11 @@ TRACE_EVENT(amdgpu_vm_grab_id,
>>> );
>>> TRACE_EVENT(amdgpu_vm_bo_map,
>>> - TP_PROTO(struct amdgpu_bo_va *bo_va,
>>> + TP_PROTO(struct amdgpu_vm *vm, struct amdgpu_bo_va *bo_va,
>>> struct amdgpu_bo_va_mapping *mapping),
>>> - TP_ARGS(bo_va, mapping),
>>> + TP_ARGS(vm, bo_va, mapping),
>>> TP_STRUCT__entry(
>>> + __field(struct amdgpu_vm *, vm)
>>> __field(struct amdgpu_bo *, bo)
>>> __field(long, start)
>>> __field(long, last)
>>> @@ -255,22 +256,24 @@ TRACE_EVENT(amdgpu_vm_bo_map,
>>> ),
>>> TP_fast_assign(
>>> + __entry->vm = vm;
>>> __entry->bo = bo_va ? bo_va->base.bo : NULL;
>>> __entry->start = mapping->start;
>>> __entry->last = mapping->last;
>>> __entry->offset = mapping->offset;
>>> __entry->flags = mapping->flags;
>>> ),
>>> - TP_printk("bo=%p, start=%lx, last=%lx, offset=%010llx,
>>> flags=%llx",
>>> - __entry->bo, __entry->start, __entry->last,
>>> + TP_printk("vm=%p bo=%p, start=%lx, last=%lx,
>>> offset=%010llx, flags=%llx",
>>> + __entry->vm, __entry->bo, __entry->start, __entry->last,
>>> __entry->offset, __entry->flags)
>>> );
>>> TRACE_EVENT(amdgpu_vm_bo_unmap,
>>> - TP_PROTO(struct amdgpu_bo_va *bo_va,
>>> + TP_PROTO(struct amdgpu_vm *vm, struct amdgpu_bo_va *bo_va,
>>> struct amdgpu_bo_va_mapping *mapping),
>>> - TP_ARGS(bo_va, mapping),
>>> + TP_ARGS(vm, bo_va, mapping),
>>> TP_STRUCT__entry(
>>> + __field(struct amdgpu_vm *, vm)
>>> __field(struct amdgpu_bo *, bo)
>>> __field(long, start)
>>> __field(long, last)
>>> @@ -279,14 +282,15 @@ TRACE_EVENT(amdgpu_vm_bo_unmap,
>>> ),
>>> TP_fast_assign(
>>> + __entry->vm = vm;
>>> __entry->bo = bo_va ? bo_va->base.bo : NULL;
>>> __entry->start = mapping->start;
>>> __entry->last = mapping->last;
>>> __entry->offset = mapping->offset;
>>> __entry->flags = mapping->flags;
>>> ),
>>> - TP_printk("bo=%p, start=%lx, last=%lx, offset=%010llx,
>>> flags=%llx",
>>> - __entry->bo, __entry->start, __entry->last,
>>> + TP_printk("vm=%p bo=%p, start=%lx, last=%lx,
>>> offset=%010llx, flags=%llx",
>>> + __entry->vm, __entry->bo, __entry->start, __entry->last,
>>> __entry->offset, __entry->flags)
>>> );
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>> index 3abfa66d72a2..e04928d2e26a 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>> @@ -1642,7 +1642,7 @@ static void amdgpu_vm_bo_insert_map(struct
>>> amdgpu_device *adev,
>>> if (amdgpu_vm_is_bo_always_valid(vm, bo) && !bo_va->base.moved)
>>> amdgpu_vm_bo_moved(&bo_va->base);
>>> - trace_amdgpu_vm_bo_map(bo_va, mapping);
>>> + trace_amdgpu_vm_bo_map(vm, bo_va, mapping);
>>> }
>>> /* Validate operation parameters to prevent potential abuse */
>>> @@ -1834,7 +1834,7 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device
>>> *adev,
>>> list_del(&mapping->list);
>>> amdgpu_vm_it_remove(mapping, &vm->va);
>>> mapping->bo_va = NULL;
>>> - trace_amdgpu_vm_bo_unmap(bo_va, mapping);
>>> + trace_amdgpu_vm_bo_unmap(vm, bo_va, mapping);
>>> if (valid)
>>> list_add(&mapping->list, &vm->freed);
>>> @@ -1929,7 +1929,7 @@ int amdgpu_vm_bo_clear_mappings(struct
>>> amdgpu_device *adev,
>>> tmp->bo_va = NULL;
>>> list_add(&tmp->list, &vm->freed);
>>> - trace_amdgpu_vm_bo_unmap(NULL, tmp);
>>> + trace_amdgpu_vm_bo_unmap(vm, NULL, tmp);
>>
>> That bo_va is NULL here is probably a bug and should be fixed.
>
> Would something like this work?
>
> trace_amdgpu_vm_bo_unmap(tmp->bo_va, tmp);
> tmp->bo_va = NULL;
> list_add(&tmp->list, &vm->freed);
It's not 100% accurate because only parts of the mapping is unmapped,
but yes I think that should work.
Regards,
Christian.
>
> Thanks,
> Pierre-Eric
>
>
>>
>> Regards,
>> Christian.
>>
>>> }
>>> /* Insert partial mapping before the range */
>>> @@ -2056,7 +2056,7 @@ void amdgpu_vm_bo_del(struct amdgpu_device *adev,
>>> list_del(&mapping->list);
>>> amdgpu_vm_it_remove(mapping, &vm->va);
>>> mapping->bo_va = NULL;
>>> - trace_amdgpu_vm_bo_unmap(bo_va, mapping);
>>> + trace_amdgpu_vm_bo_unmap(vm, bo_va, mapping);
>>> list_add(&mapping->list, &vm->freed);
>>> }
>>> list_for_each_entry_safe(mapping, next, &bo_va->invalids, list) {
next prev parent reply other threads:[~2024-06-03 14:12 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-03 8:46 [PATCH 1/2] amdgpu: add the amdgpu_vm ptr in the vm_bo_map/unmap events Pierre-Eric Pelloux-Prayer
2024-06-03 8:46 ` [PATCH 2/2] amdgpu: don't dereference a NULL resource in sysfs code Pierre-Eric Pelloux-Prayer
2024-06-06 7:14 ` Christian König
2024-06-03 9:58 ` [PATCH 1/2] amdgpu: add the amdgpu_vm ptr in the vm_bo_map/unmap events Christian König
2024-06-03 11:52 ` Pierre-Eric Pelloux-Prayer
2024-06-03 14:12 ` Christian König [this message]
2024-06-06 6:52 ` Pelloux-Prayer, Pierre-Eric
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=4e1ae4fb-472a-40a6-a26d-7f9aff709057@gmail.com \
--to=ckoenig.leichtzumerken@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=pierre-eric.pelloux-prayer@amd.com \
--cc=pierre-eric@damsy.net \
/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