AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: Felix Kuehling <felix.kuehling@amd.com>,
	Alex Deucher <alexander.deucher@amd.com>,
	amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 2/2] drm/ttm: Fix COW check
Date: Fri, 9 Jul 2021 21:37:26 +0200	[thread overview]
Message-ID: <19fbefce-b9c8-8f22-2789-0eee8f58c61a@gmail.com> (raw)
In-Reply-To: <2fd0006e-f005-b11c-3918-a9d690a1831a@amd.com>

Am 09.07.21 um 21:31 schrieb Felix Kuehling:
> On 2021-07-09 2:38 a.m., Christian König wrote:
>>
>>
>> Am 08.07.21 um 21:36 schrieb Alex Deucher:
>>> From: Felix Kuehling <Felix.Kuehling@amd.com>
>>>
>>> KFD Thunk maps invisible VRAM BOs with PROT_NONE, MAP_PRIVATE.
>>> is_cow_mapping returns true for these mappings. Add a check for
>>> vm_flags & VM_WRITE to avoid mmap failures on private read-only or
>>> PROT_NONE mappings.
>>
>> I'm pretty sure that this is not working as expected.
>
> Not sure what you mean. Debugger access to the memory through the 
> PROT_NONE VMAs is definitely working, with both ptrace and 
> /proc/<pid>/mem.
>
>
>>
>>>
>>> Fixes: f91142c62161 ("drm/ttm: nuke VM_MIXEDMAP on BO mappings v3")
>>> Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
>>> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
>>> ---
>>> drivers/gpu/drm/ttm/ttm_bo_vm.c | 2 +-
>>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c 
>>> b/drivers/gpu/drm/ttm/ttm_bo_vm.c
>>> index f56be5bc0861..a75e90c7d4aa 100644
>>> --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
>>> +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
>>> @@ -552,7 +552,7 @@ static const struct vm_operations_struct 
>>> ttm_bo_vm_ops = {
>>>   int ttm_bo_mmap_obj(struct vm_area_struct *vma, struct 
>>> ttm_buffer_object *bo)
>>>   {
>>>       /* Enforce no COW since would have really strange behavior 
>>> with it. */
>>> -    if (is_cow_mapping(vma->vm_flags))
>>> +    if (is_cow_mapping(vma->vm_flags) && (vma->vm_flags & VM_WRITE))
>>
>> is_cow_mapping() already checks for VM_MAYWRITE, so this here 
>> shouldn't be necessary.
>
> AFAICT, VM_MAYWRITE is not based on the PROT_... bits used to create 
> the VMA, but based on the permissions of the file. So as long as the 
> render node is writable, VM_MAYWRITE is set for all VMAs that map it.
>
> I would agree that it's probably a bad idea for the Thunk to map these 
> VMAs with MAP_PRIVATE. We can try changing the Thunk to use MAP_SHARED 
> for these PROT_NONE mappings. But that doesn't change the fact that 
> this kernel patch broke existing usermode.

Yeah, but see the discussion around MAP_PRIVATE and COW regarding this. 
What Thunk did here was a really bad idea.

I think we have only two options here:
1. Accept the breakage of thunk.
2. Add a workaround in amdgpu/amdkfd to force MAP_PRIVATE into 
MAP_SHARED in the kernel.

Regards,
Christian.

>
> Regards,
>   Felix
>
>
>>
>> Christian.
>>
>>>           return -EINVAL;
>>>         ttm_bo_get(bo);
>>

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  reply	other threads:[~2021-07-09 19:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-08 19:36 [PATCH 1/2] drm/amdkfd: Allow CPU access for all VRAM BOs Alex Deucher
2021-07-08 19:36 ` [PATCH 2/2] drm/ttm: Fix COW check Alex Deucher
2021-07-09  6:38   ` Christian König
2021-07-09  7:52     ` Daniel Vetter
2021-07-09 19:31     ` Felix Kuehling
2021-07-09 19:37       ` Christian König [this message]
2021-07-10  0:29         ` Felix Kuehling
2021-07-12  9:27           ` Christian König

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=19fbefce-b9c8-8f22-2789-0eee8f58c61a@gmail.com \
    --to=ckoenig.leichtzumerken@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=felix.kuehling@amd.com \
    /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