Skip to contentSkip to conversation

drm/ttm: Fix COW check

PATCH In review Felix Kuehling 5 participants 15 messages Jul 12, 2021 – Jul 23, 2021

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 drm/ttm: Fix COW check

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")
---
 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(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index b3404c43a911..1aa750a6a5d2 100644
@@ -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)
drivers/gpu/drm/nouveau/nouveau_gem.c +2 -1
index 5b27845075a1..164ea564bb7a 100644
@@ -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
drivers/gpu/drm/radeon/radeon_gem.c +2 -1
index 458f92a70887..c19ad07eb7b5 100644
@@ -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)
drivers/gpu/drm/ttm/ttm_bo_vm.c +13 -1
index f56be5bc0861..fb325bad5db6 100644
@@ -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);
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +1 -0
index e6b1f98ec99f..e4bf7dc99320 100644
@@ -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
include/drm/ttm/ttm_bo_api.h +4 -0
index f681bbdbc698..40eb95875355 100644
@@ -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);
Signature · 6 lines
2.32.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Reviewed-by on v3 1/1
#1 lore raw

Am 13.07.21 um 00:06 schrieb Felix Kuehling:

Quoted 11 lines

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")
Quoted 113 lines
---
  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(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index b3404c43a911..1aa750a6a5d2 100644
@@ -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)
drivers/gpu/drm/nouveau/nouveau_gem.c +2 -1
index 5b27845075a1..164ea564bb7a 100644
@@ -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
drivers/gpu/drm/radeon/radeon_gem.c +2 -1
index 458f92a70887..c19ad07eb7b5 100644
@@ -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)
drivers/gpu/drm/ttm/ttm_bo_vm.c +13 -1
index f56be5bc0861..fb325bad5db6 100644
@@ -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);
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +1 -0
index e6b1f98ec99f..e4bf7dc99320 100644
@@ -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
include/drm/ttm/ttm_bo_api.h +4 -0
index f681bbdbc698..40eb95875355 100644
@@ -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);
#2 lore raw
Quoted 9 lines · Christian König

Am 13.07.21 um 00:06 schrieb Felix Kuehling:

Quoted 5 lines

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.

Quoted 8 lines
Quoted 6 lines

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")

Are you planning to push this to drm-misc?

Alex

Quoted 115 lines
Quoted 114 lines
---
  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(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index b3404c43a911..1aa750a6a5d2 100644
@@ -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)
drivers/gpu/drm/nouveau/nouveau_gem.c +2 -1
index 5b27845075a1..164ea564bb7a 100644
@@ -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
drivers/gpu/drm/radeon/radeon_gem.c +2 -1
index 458f92a70887..c19ad07eb7b5 100644
@@ -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)
drivers/gpu/drm/ttm/ttm_bo_vm.c +13 -1
index f56be5bc0861..fb325bad5db6 100644
@@ -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);
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +1 -0
index e6b1f98ec99f..e4bf7dc99320 100644
@@ -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
include/drm/ttm/ttm_bo_api.h +4 -0
index f681bbdbc698..40eb95875355 100644
@@ -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);
maintainer
#3 lore raw

Am 13.07.21 um 17:28 schrieb Alex Deucher:

Quoted 10 lines
Quoted 8 lines · Christian König

Am 13.07.21 um 00:06 schrieb Felix Kuehling:

Quoted 5 lines

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.

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines

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")

Are you planning to push this to drm-misc?

Yes, just didn't found time yesterday.

Christian.

Quoted 115 lines

Alex

Quoted 112 lines
Quoted 112 lines
---
   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(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index b3404c43a911..1aa750a6a5d2 100644
@@ -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)
drivers/gpu/drm/nouveau/nouveau_gem.c +2 -1
index 5b27845075a1..164ea564bb7a 100644
@@ -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
drivers/gpu/drm/radeon/radeon_gem.c +2 -1
index 458f92a70887..c19ad07eb7b5 100644
@@ -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)
drivers/gpu/drm/ttm/ttm_bo_vm.c +13 -1
index f56be5bc0861..fb325bad5db6 100644
@@ -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);
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +1 -0
index e6b1f98ec99f..e4bf7dc99320 100644
@@ -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
include/drm/ttm/ttm_bo_api.h +4 -0
index f681bbdbc698..40eb95875355 100644
@@ -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);
 
Quoted 1 line
Quoted 1 line

include/drm/ttm/ttm_bo_api.h void ttm_bo_vm_close(struct vm_area_struct *vma); · line 614

Quoted 1 line
include/drm/ttm/ttm_bo_api.h +0 -0
   vm_fault_t ttm_bo_vm_dummy_page(struct vm_fault *vmf, pgprot_t prot);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#4 lore raw
Quoted 17 lines · Christian König

Am 13.07.21 um 17:28 schrieb Alex Deucher:

Quoted 13 lines
Quoted 11 lines · Christian König

Am 13.07.21 um 00:06 schrieb Felix Kuehling:

Quoted 8 lines

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

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
Fixes f91142c62161 ("drm/ttm: nuke VM_MIXEDMAP on BO mappings v3")

Are you planning to push this to drm-misc?

Yes, just didn't found time yesterday.

This is pushed to the wrong tree drm-misc-next-fixes, should have been in drm-misc-fixes. Please be careful with that because every time that goes wrong the script gets confused about which the current tree is, and pushes the wrong tree to linux-next branches.

I'm going to hard-reset drm-misc-next-fixes now and hope that's good enough to fix things up (since Thomas is not around all the time for this merge window).
-Daniel

Quoted 120 lines

Christian.

Quoted 116 lines

Alex

Quoted 113 lines
Quoted 113 lines
---
   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(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index b3404c43a911..1aa750a6a5d2 100644
@@ -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)
drivers/gpu/drm/nouveau/nouveau_gem.c +2 -1
index 5b27845075a1..164ea564bb7a 100644
@@ -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
drivers/gpu/drm/radeon/radeon_gem.c +2 -1
index 458f92a70887..c19ad07eb7b5 100644
@@ -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)
drivers/gpu/drm/ttm/ttm_bo_vm.c +13 -1
index f56be5bc0861..fb325bad5db6 100644
@@ -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);
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +1 -0
index e6b1f98ec99f..e4bf7dc99320 100644
@@ -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
include/drm/ttm/ttm_bo_api.h +4 -0
index f681bbdbc698..40eb95875355 100644
@@ -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);
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#5 lore raw

Am 23.07.21 um 10:21 schrieb Daniel Vetter:

Quoted 23 lines
Quoted 15 lines · Christian König

Am 13.07.21 um 17:28 schrieb Alex Deucher:

Quoted 12 lines
Quoted 10 lines · Christian König

Am 13.07.21 um 00:06 schrieb Felix Kuehling:

Quoted 8 lines

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

Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
Fixes f91142c62161 ("drm/ttm: nuke VM_MIXEDMAP on BO mappings v3")

Are you planning to push this to drm-misc?

Yes, just didn't found time yesterday.

Quoted 8 lines

This is pushed to the wrong tree drm-misc-next-fixes, should have been in drm-misc-fixes. Please be careful with that because every time that goes wrong the script gets confused about which the current tree is, and pushes the wrong tree to linux-next branches.

I'm going to hard-reset drm-misc-next-fixes now and hope that's good enough to fix things up (since Thomas is not around all the time for this merge window).

STOP! I'm about to push a revert for this patch.

And yes that was pushed to the wrong branch, but it turned out that this was fortunate since the patch doesn't work correctly.

Christian.

Quoted 119 lines

-Daniel

Quoted 116 lines

Christian.

Quoted 114 lines

Alex

Quoted 112 lines
Quoted 112 lines
---
    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(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index b3404c43a911..1aa750a6a5d2 100644
@@ -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)
drivers/gpu/drm/nouveau/nouveau_gem.c +2 -1
index 5b27845075a1..164ea564bb7a 100644
@@ -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
drivers/gpu/drm/radeon/radeon_gem.c +2 -1
index 458f92a70887..c19ad07eb7b5 100644
@@ -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)
drivers/gpu/drm/ttm/ttm_bo_vm.c +13 -1
index f56be5bc0861..fb325bad5db6 100644
@@ -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);
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +1 -0
index e6b1f98ec99f..e4bf7dc99320 100644
@@ -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
include/drm/ttm/ttm_bo_api.h +4 -0
index f681bbdbc698..40eb95875355 100644
@@ -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);
 
Quoted 2 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/drm/ttm/ttm_bo_api.h void ttm_bo_vm_close(struct vm_area_struct *vma); · line 614

Quoted 1 line
include/drm/ttm/ttm_bo_api.h +0 -0
    vm_fault_t ttm_bo_vm_dummy_page(struct vm_fault *vmf, pgprot_t prot);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#6 lore raw
Quoted 31 lines · Christian König

Am 23.07.21 um 10:21 schrieb Daniel Vetter:

Quoted 28 lines
Quoted 15 lines · Christian König

Am 13.07.21 um 17:28 schrieb Alex Deucher:

Quoted 12 lines
Quoted 10 lines · Christian König

Am 13.07.21 um 00:06 schrieb Felix Kuehling:

Quoted 8 lines

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

Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
Fixes f91142c62161 ("drm/ttm: nuke VM_MIXEDMAP on BO mappings v3")

Are you planning to push this to drm-misc?

Yes, just didn't found time yesterday.

This is pushed to the wrong tree drm-misc-next-fixes, should have been in drm-misc-fixes. Please be careful with that because every time that goes wrong the script gets confused about which the current tree is, and pushes the wrong tree to linux-next branches.

Quoted 8 lines
Quoted 3 lines

I'm going to hard-reset drm-misc-next-fixes now and hope that's good enough to fix things up (since Thomas is not around all the time for this merge window).

STOP! I'm about to push a revert for this patch.

And yes that was pushed to the wrong branch, but it turned out that this was fortunate since the patch doesn't work correctly.

Well I just hard-reset, so you can push the right patch to the right branch now. The trouble is that outside of the merge window no one is allowed to push to drm-misc-next-fixes. If you do, then dim pushes drm-misc-next-fixes to for-linux-next instead of drm-misc-next, and we have bad surprises.

Which unfortunately happens like every merge window a few times and always takes a few days/weeks to get caught.
-Danie

Quoted 125 lines

Christian.

Quoted 121 lines

-Daniel

Quoted 117 lines

Christian.

Quoted 115 lines

Alex

Quoted 113 lines
Quoted 113 lines
---
    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(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index b3404c43a911..1aa750a6a5d2 100644
@@ -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)
drivers/gpu/drm/nouveau/nouveau_gem.c +2 -1
index 5b27845075a1..164ea564bb7a 100644
@@ -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
drivers/gpu/drm/radeon/radeon_gem.c +2 -1
index 458f92a70887..c19ad07eb7b5 100644
@@ -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)
drivers/gpu/drm/ttm/ttm_bo_vm.c +13 -1
index f56be5bc0861..fb325bad5db6 100644
@@ -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);
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +1 -0
index e6b1f98ec99f..e4bf7dc99320 100644
@@ -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
include/drm/ttm/ttm_bo_api.h +4 -0
index f681bbdbc698..40eb95875355 100644
@@ -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);
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#7 lore raw

Am 23.07.21 um 11:00 schrieb Daniel Vetter:

Quoted 34 lines · Christian König
Quoted 33 lines

Am 23.07.21 um 10:21 schrieb Daniel Vetter:

Quoted 21 lines
Quoted 13 lines · Christian König

Am 13.07.21 um 17:28 schrieb Alex Deucher:

Quoted 11 lines
Quoted 9 lines · Christian König

Am 13.07.21 um 00:06 schrieb Felix Kuehling:

Quoted 8 lines

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

Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
Fixes f91142c62161 ("drm/ttm: nuke VM_MIXEDMAP on BO mappings v3")

Are you planning to push this to drm-misc?

Yes, just didn't found time yesterday.

Quoted 8 lines

This is pushed to the wrong tree drm-misc-next-fixes, should have been in drm-misc-fixes. Please be careful with that because every time that goes wrong the script gets confused about which the current tree is, and pushes the wrong tree to linux-next branches.

I'm going to hard-reset drm-misc-next-fixes now and hope that's good enough to fix things up (since Thomas is not around all the time for this merge window).

STOP! I'm about to push a revert for this patch.

Quoted 7 lines
Quoted 2 lines

And yes that was pushed to the wrong branch, but it turned out that this was fortunate since the patch doesn't work correctly.

Well I just hard-reset, so you can push the right patch to the right branch now. The trouble is that outside of the merge window no one is allowed to push to drm-misc-next-fixes. If you do, then dim pushes drm-misc-next-fixes to for-linux-next instead of drm-misc-next, and we have bad surprises.

Could we then make the branch read-only for that time?

Quoted 2 lines

Which unfortunately happens like every merge window a few times and always takes a few days/weeks to get caught.

Yeah, at least to me it's absolutely not obvious when the merge windows for a certain version start/end.

Christian.

Quoted 123 lines

-Danie

Quoted 121 lines

Christian.

Quoted 119 lines

-Daniel

Quoted 116 lines

Christian.

Quoted 114 lines

Alex

Quoted 112 lines
Quoted 112 lines
---
     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(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index b3404c43a911..1aa750a6a5d2 100644
@@ -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)
drivers/gpu/drm/nouveau/nouveau_gem.c +2 -1
index 5b27845075a1..164ea564bb7a 100644
@@ -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
drivers/gpu/drm/radeon/radeon_gem.c +2 -1
index 458f92a70887..c19ad07eb7b5 100644
@@ -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)
drivers/gpu/drm/ttm/ttm_bo_vm.c +13 -1
index f56be5bc0861..fb325bad5db6 100644
@@ -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);
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +1 -0
index e6b1f98ec99f..e4bf7dc99320 100644
@@ -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
include/drm/ttm/ttm_bo_api.h +4 -0
index f681bbdbc698..40eb95875355 100644
@@ -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);
 
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/drm/ttm/ttm_bo_api.h void ttm_bo_vm_close(struct vm_area_struct *vma); · line 614

Quoted 1 line
include/drm/ttm/ttm_bo_api.h +0 -0
     vm_fault_t ttm_bo_vm_dummy_page(struct vm_fault *vmf, pgprot_t prot);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#8 lore raw
In reply to Christian König

Am 2021-07-13 um 2:57 a.m. schrieb Christian König:

Quoted 8 lines

Am 13.07.21 um 00:06 schrieb Felix Kuehling:

Quoted 5 lines

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.

Quoted 8 lines
Quoted 6 lines

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")

Thank you!

Alex, this patch is against your updated amd-staging-drm-next branch. Please replace my previous version of the patch with this one.

Thanks,
  Felix

Quoted 113 lines
Quoted 113 lines

---
  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(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index b3404c43a911..1aa750a6a5d2 100644
@@ -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)
drivers/gpu/drm/nouveau/nouveau_gem.c +2 -1
index 5b27845075a1..164ea564bb7a 100644
@@ -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

drivers/gpu/drm/radeon/radeon_gem.c +2 -1
index 458f92a70887..c19ad07eb7b5 100644
@@ -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)
drivers/gpu/drm/ttm/ttm_bo_vm.c +0 -0
index f56be5bc0861..fb325bad5db6 100644
@@ -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;

drivers/gpu/drm/ttm/ttm_bo_vm.c +5 -0
+
+    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);

drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +1 -0
index e6b1f98ec99f..e4bf7dc99320 100644
@@ -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

include/drm/ttm/ttm_bo_api.h +0 -0
index f681bbdbc698..40eb95875355 100644
@@ -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,
Quoted 9 lines
Quoted 8 lines
include/drm/ttm/ttm_bo_api.h +4 -0
                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
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#9 lore raw
In reply to Felix Kuehling
Quoted 11 lines · 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")

So looking at vmf_insert_pfn_prot() and the comment there we can't have VM_PFNMAP and is_cow_mapping ever be true, or things break. On platforms without pte_special at least.

So I'm not sure this is a great idea, and definitely not for all drivers
...

Can we clear VM_MAYWRITE instead to force this to be a non-cow mapping instead?
-Daniel

Quoted 116 lines
---
 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(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index b3404c43a911..1aa750a6a5d2 100644
@@ -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)
drivers/gpu/drm/nouveau/nouveau_gem.c +2 -1
index 5b27845075a1..164ea564bb7a 100644
@@ -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
drivers/gpu/drm/radeon/radeon_gem.c +2 -1
index 458f92a70887..c19ad07eb7b5 100644
@@ -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)
drivers/gpu/drm/ttm/ttm_bo_vm.c +13 -1
index f56be5bc0861..fb325bad5db6 100644
@@ -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);
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +1 -0
index e6b1f98ec99f..e4bf7dc99320 100644
@@ -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
include/drm/ttm/ttm_bo_api.h +4 -0
index f681bbdbc698..40eb95875355 100644
@@ -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);
Signature · 1 line
2.32.0
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#10 lore raw
Quoted 17 lines · Daniel Vetter
Quoted 11 lines · 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")

So looking at vmf_insert_pfn_prot() and the comment there we can't have VM_PFNMAP and is_cow_mapping ever be true, or things break. On platforms without pte_special at least.

Quoted 5 lines

So I'm not sure this is a great idea, and definitely not for all drivers
...

Can we clear VM_MAYWRITE instead to force this to be a non-cow mapping instead?

Quick git grep says there's plenty of drivers which clear MAYWRITE, and often with comments to block mprotect upfront. That feels like the cleaner approach, and maybe limited to an overwrite in just amdgpu with a comment explaining why it's needed? As in amdgpu mmap function which just clears VM_MAYWRITE if it's a cow mapping and then calls into ttm mmap implementation.
-Daniel

Quoted 121 lines
Quoted 116 lines
---
 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(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index b3404c43a911..1aa750a6a5d2 100644
@@ -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)
drivers/gpu/drm/nouveau/nouveau_gem.c +2 -1
index 5b27845075a1..164ea564bb7a 100644
@@ -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
drivers/gpu/drm/radeon/radeon_gem.c +2 -1
index 458f92a70887..c19ad07eb7b5 100644
@@ -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)
drivers/gpu/drm/ttm/ttm_bo_vm.c +13 -1
index f56be5bc0861..fb325bad5db6 100644
@@ -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);
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +1 -0
index e6b1f98ec99f..e4bf7dc99320 100644
@@ -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
include/drm/ttm/ttm_bo_api.h +4 -0
index f681bbdbc698..40eb95875355 100644
@@ -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);
Signature · 1 line
2.32.0
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
maintainer
#11 lore raw
In reply to Daniel Vetter

Am 14.07.21 um 12:44 schrieb Daniel Vetter:

Quoted 9 lines · Felix Kuehling
Quoted 8 lines

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

Quoted 6 lines
Quoted 3 lines
Fixes f91142c62161 ("drm/ttm: nuke VM_MIXEDMAP on BO mappings v3")

So looking at vmf_insert_pfn_prot() and the comment there we can't have VM_PFNMAP and is_cow_mapping ever be true, or things break. On platforms without pte_special at least.

Key idea is that we never end up in vmf_insert_pfn_prot() because the vma is mapped with PROT_NONE.

Quoted 2 lines

So I'm not sure this is a great idea, and definitely not for all drivers

Yeah, I'm absolutely not happy with this either but it seemed to be the least painful thing to do.

Quoted 4 lines

...

Can we clear VM_MAYWRITE instead to force this to be a non-cow mapping instead?

Well we have considered forcefully setting VM_SHARED, which won't work easily for a couple of reasons.

But clearing VM_MAYWRITE in amdgpu/amdkfd may actually work as well.

Felix can you test this?

Thanks,
Christian.

Quoted 118 lines

-Daniel

Quoted 116 lines
---
  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(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index b3404c43a911..1aa750a6a5d2 100644
@@ -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)
drivers/gpu/drm/nouveau/nouveau_gem.c +2 -1
index 5b27845075a1..164ea564bb7a 100644
@@ -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
drivers/gpu/drm/radeon/radeon_gem.c +2 -1
index 458f92a70887..c19ad07eb7b5 100644
@@ -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)
drivers/gpu/drm/ttm/ttm_bo_vm.c +13 -1
index f56be5bc0861..fb325bad5db6 100644
@@ -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);
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +1 -0
index e6b1f98ec99f..e4bf7dc99320 100644
@@ -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
include/drm/ttm/ttm_bo_api.h +4 -0
index f681bbdbc698..40eb95875355 100644
@@ -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);
Signature · 1 line
2.32.0
#12 lore raw
Quoted 13 lines · Christian König

Am 14.07.21 um 12:44 schrieb Daniel Vetter:

Quoted 12 lines · Felix Kuehling
Quoted 11 lines

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")
Quoted 6 lines
Quoted 3 lines

So looking at vmf_insert_pfn_prot() and the comment there we can't have VM_PFNMAP and is_cow_mapping ever be true, or things break. On platforms without pte_special at least.

Key idea is that we never end up in vmf_insert_pfn_prot() because the vma is mapped with PROT_NONE.

Ah right if it's PROT_NONE then it's ok. But the code here only checks for VM_WRITE, not VM_READ, so PROT_READ can get through and go boom? Or something else I'm missing?

Maybe time for a few amdgpu mmap tests that go through the combos and make sure it works/fails all correctly.
-Daniel

Quoted 131 lines
Quoted 1 line

So I'm not sure this is a great idea, and definitely not for all drivers

Yeah, I'm absolutely not happy with this either but it seemed to be the least painful thing to do.

Quoted 4 lines

...

Can we clear VM_MAYWRITE instead to force this to be a non-cow mapping instead?

Well we have considered forcefully setting VM_SHARED, which won't work easily for a couple of reasons.

But clearing VM_MAYWRITE in amdgpu/amdkfd may actually work as well.

Felix can you test this?

Thanks,
Christian.

Quoted 110 lines

-Daniel

Quoted 108 lines
---
  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(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index b3404c43a911..1aa750a6a5d2 100644
@@ -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)
drivers/gpu/drm/nouveau/nouveau_gem.c +2 -1
index 5b27845075a1..164ea564bb7a 100644
@@ -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
drivers/gpu/drm/radeon/radeon_gem.c +2 -1
index 458f92a70887..c19ad07eb7b5 100644
@@ -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)
drivers/gpu/drm/ttm/ttm_bo_vm.c +13 -1
index f56be5bc0861..fb325bad5db6 100644
@@ -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);
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +1 -0
index e6b1f98ec99f..e4bf7dc99320 100644
@@ -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
include/drm/ttm/ttm_bo_api.h +4 -0
index f681bbdbc698..40eb95875355 100644
@@ -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);
Signature · 1 line
2.32.0
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
maintainer
#13 lore raw

Am 14.07.21 um 13:15 schrieb Daniel Vetter:

Quoted 14 lines · Christian König
Quoted 13 lines

Am 14.07.21 um 12:44 schrieb Daniel Vetter:

Quoted 12 lines · Felix Kuehling
Quoted 11 lines

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")
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

So looking at vmf_insert_pfn_prot() and the comment there we can't have VM_PFNMAP and is_cow_mapping ever be true, or things break. On platforms without pte_special at least.

Key idea is that we never end up in vmf_insert_pfn_prot() because the vma is mapped with PROT_NONE.

Ah right if it's PROT_NONE then it's ok. But the code here only checks for VM_WRITE, not VM_READ, so PROT_READ can get through and go boom? Or something else I'm missing?

Ah, good point. Yeah that is indeed not handled correctly and can cause a BUG_ON().

Looks like we need to revert that patch and go back to the drawing board then.

Christian.

Quoted 133 lines

Maybe time for a few amdgpu mmap tests that go through the combos and make sure it works/fails all correctly.
-Daniel

Quoted 128 lines
Quoted 1 line

So I'm not sure this is a great idea, and definitely not for all drivers

Yeah, I'm absolutely not happy with this either but it seemed to be the least painful thing to do.

Quoted 4 lines

...

Can we clear VM_MAYWRITE instead to force this to be a non-cow mapping instead?

Well we have considered forcefully setting VM_SHARED, which won't work easily for a couple of reasons.

But clearing VM_MAYWRITE in amdgpu/amdkfd may actually work as well.

Felix can you test this?

Thanks,
Christian.

Quoted 110 lines

-Daniel

Quoted 108 lines
---
   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(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index b3404c43a911..1aa750a6a5d2 100644
@@ -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)
drivers/gpu/drm/nouveau/nouveau_gem.c +2 -1
index 5b27845075a1..164ea564bb7a 100644
@@ -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
drivers/gpu/drm/radeon/radeon_gem.c +2 -1
index 458f92a70887..c19ad07eb7b5 100644
@@ -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)
drivers/gpu/drm/ttm/ttm_bo_vm.c +13 -1
index f56be5bc0861..fb325bad5db6 100644
@@ -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);
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +1 -0
index e6b1f98ec99f..e4bf7dc99320 100644
@@ -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
include/drm/ttm/ttm_bo_api.h +4 -0
index f681bbdbc698..40eb95875355 100644
@@ -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);
Signature · 1 line
2.32.0
#14 lore raw
In reply to Christian König

Am 2021-07-14 um 6:51 a.m. schrieb Christian König:

Quoted 13 lines

Am 14.07.21 um 12:44 schrieb Daniel Vetter:

Quoted 12 lines · Felix Kuehling
Quoted 11 lines

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")
Quoted 6 lines
Quoted 3 lines

So looking at vmf_insert_pfn_prot() and the comment there we can't have VM_PFNMAP and is_cow_mapping ever be true, or things break. On platforms without pte_special at least.

Key idea is that we never end up in vmf_insert_pfn_prot() because the vma is mapped with PROT_NONE.

Ah, thanks for that pointer. I wasn't aware of that BUG_ON. I thought it was more of an abstract "copy-on-write faults may be bad on these mappings."

Quoted 12 lines
Quoted 3 lines

So I'm not sure this is a great idea, and definitely not for all drivers

Yeah, I'm absolutely not happy with this either but it seemed to be the least painful thing to do.

Quoted 4 lines

...

Can we clear VM_MAYWRITE instead to force this to be a non-cow mapping instead?

Quoted 6 lines

Well we have considered forcefully setting VM_SHARED, which won't work easily for a couple of reasons.

But clearing VM_MAYWRITE in amdgpu/amdkfd may actually work as well.

Felix can you test this?

Sounds like it should work and be straight forward (I thought that about setting VM_SHARED, too ...). I'll give it a try.

Thanks,
  Felix

Quoted 133 lines

Thanks,
Christian.

Quoted 128 lines

-Daniel

Quoted 126 lines

---
  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(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index b3404c43a911..1aa750a6a5d2 100644
@@ -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)
drivers/gpu/drm/nouveau/nouveau_gem.c +2 -1
index 5b27845075a1..164ea564bb7a 100644
@@ -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

drivers/gpu/drm/radeon/radeon_gem.c +2 -1
index 458f92a70887..c19ad07eb7b5 100644
@@ -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)
drivers/gpu/drm/ttm/ttm_bo_vm.c +0 -0
index f56be5bc0861..fb325bad5db6 100644
@@ -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;

drivers/gpu/drm/ttm/ttm_bo_vm.c +5 -0
+
+    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);

drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +1 -0
index e6b1f98ec99f..e4bf7dc99320 100644
@@ -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

include/drm/ttm/ttm_bo_api.h +0 -0
index f681bbdbc698..40eb95875355 100644
@@ -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);

include/drm/ttm/ttm_bo_api.h +2 -0
+
+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);
--
2.32.0