From: "Christian König" <ckoenig.leichtzumerken@gmail.com> To: Felix Kuehling <Felix.Kuehling@amd.com>, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: Alex Deucher <alexander.deucher@amd.com>, christian.koenig@amd.com Subject: Re: [PATCH v3 1/1] drm/ttm: Fix COW check Date: Tue, 13 Jul 2021 08:57:00 +0200 [thread overview] Message-ID: <d617d831-7168-51a4-042e-e36a5af7761d@gmail.com> (raw) In-Reply-To: <20210712220636.475675-1-Felix.Kuehling@amd.com> Am 13.07.21 um 00:06 schrieb Felix Kuehling: > 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. > > v2: protect against mprotect making a mapping writable after the fact > v3: update driver-specific vm_operations_structs > > 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> Reviewed-by: Christian König <christian.koenig@amd.com> > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 3 ++- > drivers/gpu/drm/nouveau/nouveau_gem.c | 3 ++- > drivers/gpu/drm/radeon/radeon_gem.c | 3 ++- > drivers/gpu/drm/ttm/ttm_bo_vm.c | 14 +++++++++++++- > drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 1 + > include/drm/ttm/ttm_bo_api.h | 4 ++++ > 6 files changed, 24 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c > index b3404c43a911..1aa750a6a5d2 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c > @@ -79,7 +79,8 @@ static const struct vm_operations_struct amdgpu_gem_vm_ops = { > .fault = amdgpu_gem_fault, > .open = ttm_bo_vm_open, > .close = ttm_bo_vm_close, > - .access = ttm_bo_vm_access > + .access = ttm_bo_vm_access, > + .mprotect = ttm_bo_vm_mprotect > }; > > static void amdgpu_gem_object_free(struct drm_gem_object *gobj) > diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c > index 5b27845075a1..164ea564bb7a 100644 > --- a/drivers/gpu/drm/nouveau/nouveau_gem.c > +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c > @@ -70,7 +70,8 @@ static const struct vm_operations_struct nouveau_ttm_vm_ops = { > .fault = nouveau_ttm_fault, > .open = ttm_bo_vm_open, > .close = ttm_bo_vm_close, > - .access = ttm_bo_vm_access > + .access = ttm_bo_vm_access, > + .mprotect = ttm_bo_vm_mprotect > }; > > void > diff --git a/drivers/gpu/drm/radeon/radeon_gem.c b/drivers/gpu/drm/radeon/radeon_gem.c > index 458f92a70887..c19ad07eb7b5 100644 > --- a/drivers/gpu/drm/radeon/radeon_gem.c > +++ b/drivers/gpu/drm/radeon/radeon_gem.c > @@ -77,7 +77,8 @@ static const struct vm_operations_struct radeon_gem_vm_ops = { > .fault = radeon_gem_fault, > .open = ttm_bo_vm_open, > .close = ttm_bo_vm_close, > - .access = ttm_bo_vm_access > + .access = ttm_bo_vm_access, > + .mprotect = ttm_bo_vm_mprotect > }; > > static void radeon_gem_object_free(struct drm_gem_object *gobj) > diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c > index f56be5bc0861..fb325bad5db6 100644 > --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c > +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c > @@ -542,17 +542,29 @@ int ttm_bo_vm_access(struct vm_area_struct *vma, unsigned long addr, > } > EXPORT_SYMBOL(ttm_bo_vm_access); > > +int ttm_bo_vm_mprotect(struct vm_area_struct *vma, unsigned long start, > + unsigned long end, unsigned long newflags) > +{ > + /* Enforce no COW since would have really strange behavior with it. */ > + if (is_cow_mapping(newflags) && (newflags & VM_WRITE)) > + return -EINVAL; > + > + return 0; > +} > +EXPORT_SYMBOL(ttm_bo_vm_mprotect); > + > static const struct vm_operations_struct ttm_bo_vm_ops = { > .fault = ttm_bo_vm_fault, > .open = ttm_bo_vm_open, > .close = ttm_bo_vm_close, > .access = ttm_bo_vm_access, > + .mprotect = ttm_bo_vm_mprotect, > }; > > 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)) > return -EINVAL; > > ttm_bo_get(bo); > diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c > index e6b1f98ec99f..e4bf7dc99320 100644 > --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c > +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c > @@ -61,6 +61,7 @@ int vmw_mmap(struct file *filp, struct vm_area_struct *vma) > .fault = vmw_bo_vm_fault, > .open = ttm_bo_vm_open, > .close = ttm_bo_vm_close, > + .mprotect = ttm_bo_vm_mprotect, > #ifdef CONFIG_TRANSPARENT_HUGEPAGE > .huge_fault = vmw_bo_vm_huge_fault, > #endif > diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h > index f681bbdbc698..40eb95875355 100644 > --- a/include/drm/ttm/ttm_bo_api.h > +++ b/include/drm/ttm/ttm_bo_api.h > @@ -605,6 +605,10 @@ void ttm_bo_vm_close(struct vm_area_struct *vma); > > int ttm_bo_vm_access(struct vm_area_struct *vma, unsigned long addr, > void *buf, int len, int write); > + > +int ttm_bo_vm_mprotect(struct vm_area_struct *vma, unsigned long start, > + unsigned long end, unsigned long newflags); > + > bool ttm_bo_delayed_delete(struct ttm_device *bdev, bool remove_all); > > vm_fault_t ttm_bo_vm_dummy_page(struct vm_fault *vmf, pgprot_t prot);
WARNING: multiple messages have this Message-ID (diff)
From: "Christian König" <ckoenig.leichtzumerken@gmail.com> To: Felix Kuehling <Felix.Kuehling@amd.com>, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: Alex Deucher <alexander.deucher@amd.com>, christian.koenig@amd.com Subject: Re: [PATCH v3 1/1] drm/ttm: Fix COW check Date: Tue, 13 Jul 2021 08:57:00 +0200 [thread overview] Message-ID: <d617d831-7168-51a4-042e-e36a5af7761d@gmail.com> (raw) In-Reply-To: <20210712220636.475675-1-Felix.Kuehling@amd.com> Am 13.07.21 um 00:06 schrieb Felix Kuehling: > 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. > > v2: protect against mprotect making a mapping writable after the fact > v3: update driver-specific vm_operations_structs > > 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> Reviewed-by: Christian König <christian.koenig@amd.com> > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 3 ++- > drivers/gpu/drm/nouveau/nouveau_gem.c | 3 ++- > drivers/gpu/drm/radeon/radeon_gem.c | 3 ++- > drivers/gpu/drm/ttm/ttm_bo_vm.c | 14 +++++++++++++- > drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 1 + > include/drm/ttm/ttm_bo_api.h | 4 ++++ > 6 files changed, 24 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c > index b3404c43a911..1aa750a6a5d2 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c > @@ -79,7 +79,8 @@ static const struct vm_operations_struct amdgpu_gem_vm_ops = { > .fault = amdgpu_gem_fault, > .open = ttm_bo_vm_open, > .close = ttm_bo_vm_close, > - .access = ttm_bo_vm_access > + .access = ttm_bo_vm_access, > + .mprotect = ttm_bo_vm_mprotect > }; > > static void amdgpu_gem_object_free(struct drm_gem_object *gobj) > diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c > index 5b27845075a1..164ea564bb7a 100644 > --- a/drivers/gpu/drm/nouveau/nouveau_gem.c > +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c > @@ -70,7 +70,8 @@ static const struct vm_operations_struct nouveau_ttm_vm_ops = { > .fault = nouveau_ttm_fault, > .open = ttm_bo_vm_open, > .close = ttm_bo_vm_close, > - .access = ttm_bo_vm_access > + .access = ttm_bo_vm_access, > + .mprotect = ttm_bo_vm_mprotect > }; > > void > diff --git a/drivers/gpu/drm/radeon/radeon_gem.c b/drivers/gpu/drm/radeon/radeon_gem.c > index 458f92a70887..c19ad07eb7b5 100644 > --- a/drivers/gpu/drm/radeon/radeon_gem.c > +++ b/drivers/gpu/drm/radeon/radeon_gem.c > @@ -77,7 +77,8 @@ static const struct vm_operations_struct radeon_gem_vm_ops = { > .fault = radeon_gem_fault, > .open = ttm_bo_vm_open, > .close = ttm_bo_vm_close, > - .access = ttm_bo_vm_access > + .access = ttm_bo_vm_access, > + .mprotect = ttm_bo_vm_mprotect > }; > > static void radeon_gem_object_free(struct drm_gem_object *gobj) > diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c > index f56be5bc0861..fb325bad5db6 100644 > --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c > +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c > @@ -542,17 +542,29 @@ int ttm_bo_vm_access(struct vm_area_struct *vma, unsigned long addr, > } > EXPORT_SYMBOL(ttm_bo_vm_access); > > +int ttm_bo_vm_mprotect(struct vm_area_struct *vma, unsigned long start, > + unsigned long end, unsigned long newflags) > +{ > + /* Enforce no COW since would have really strange behavior with it. */ > + if (is_cow_mapping(newflags) && (newflags & VM_WRITE)) > + return -EINVAL; > + > + return 0; > +} > +EXPORT_SYMBOL(ttm_bo_vm_mprotect); > + > static const struct vm_operations_struct ttm_bo_vm_ops = { > .fault = ttm_bo_vm_fault, > .open = ttm_bo_vm_open, > .close = ttm_bo_vm_close, > .access = ttm_bo_vm_access, > + .mprotect = ttm_bo_vm_mprotect, > }; > > 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)) > return -EINVAL; > > ttm_bo_get(bo); > diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c > index e6b1f98ec99f..e4bf7dc99320 100644 > --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c > +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c > @@ -61,6 +61,7 @@ int vmw_mmap(struct file *filp, struct vm_area_struct *vma) > .fault = vmw_bo_vm_fault, > .open = ttm_bo_vm_open, > .close = ttm_bo_vm_close, > + .mprotect = ttm_bo_vm_mprotect, > #ifdef CONFIG_TRANSPARENT_HUGEPAGE > .huge_fault = vmw_bo_vm_huge_fault, > #endif > diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h > index f681bbdbc698..40eb95875355 100644 > --- a/include/drm/ttm/ttm_bo_api.h > +++ b/include/drm/ttm/ttm_bo_api.h > @@ -605,6 +605,10 @@ void ttm_bo_vm_close(struct vm_area_struct *vma); > > int ttm_bo_vm_access(struct vm_area_struct *vma, unsigned long addr, > void *buf, int len, int write); > + > +int ttm_bo_vm_mprotect(struct vm_area_struct *vma, unsigned long start, > + unsigned long end, unsigned long newflags); > + > bool ttm_bo_delayed_delete(struct ttm_device *bdev, bool remove_all); > > vm_fault_t ttm_bo_vm_dummy_page(struct vm_fault *vmf, pgprot_t prot); _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx
next prev parent reply other threads:[~2021-07-13 6:57 UTC|newest] Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-12 22:06 [PATCH v3 1/1] drm/ttm: Fix COW check Felix Kuehling 2021-07-12 22:06 ` Felix Kuehling 2021-07-13 6:57 ` Christian König [this message] 2021-07-13 6:57 ` Christian König 2021-07-13 15:28 ` Alex Deucher 2021-07-13 15:28 ` Alex Deucher 2021-07-14 8:51 ` Christian König 2021-07-14 8:51 ` Christian König 2021-07-23 8:21 ` Daniel Vetter 2021-07-23 8:21 ` Daniel Vetter 2021-07-23 8:33 ` Christian König 2021-07-23 8:33 ` Christian König 2021-07-23 9:00 ` Daniel Vetter 2021-07-23 9:00 ` Daniel Vetter 2021-07-23 9:09 ` Christian König 2021-07-23 9:09 ` Christian König 2021-07-13 15:29 ` Felix Kuehling 2021-07-13 15:29 ` Felix Kuehling 2021-07-14 10:44 ` Daniel Vetter 2021-07-14 10:44 ` Daniel Vetter 2021-07-14 10:46 ` Daniel Vetter 2021-07-14 10:46 ` Daniel Vetter 2021-07-14 10:51 ` Christian König 2021-07-14 10:51 ` Christian König 2021-07-14 11:15 ` Daniel Vetter 2021-07-14 11:15 ` Daniel Vetter 2021-07-14 13:09 ` Christian König 2021-07-14 13:09 ` Christian König 2021-07-14 16:11 ` Felix Kuehling 2021-07-14 16:11 ` Felix Kuehling
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=d617d831-7168-51a4-042e-e36a5af7761d@gmail.com \ --to=ckoenig.leichtzumerken@gmail.com \ --cc=Felix.Kuehling@amd.com \ --cc=alexander.deucher@amd.com \ --cc=amd-gfx@lists.freedesktop.org \ --cc=christian.koenig@amd.com \ --cc=dri-devel@lists.freedesktop.org \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.