Skip to contentSkip to conversation

gpu: drm: v3d: use new return type vm_fault_t

PATCH Superseded Souptick Joarder 2 participants 3 messages Jul 3, 2018 – Jul 4, 2018

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpu: drm: v3d: use new return type vm_fault_t

Use new return type vm_fault_t for fault handler. For now, this is just documenting that the function returns a VM_FAULT value rather than an errno. Once all instances are converted, vm_fault_t will become a distinct type.

see commit 1c8f422059ae ("mm: change return type to vm_fault_t") for reference.

Previously vm_insert_mixed returns err which driver mapped into VM_FAULT_* type. The new function vmf_insert_mixed will replace this inefficiency by returning VM_FAULT_* type.

---
 drivers/gpu/drm/v3d/v3d_bo.c  | 23 +++--------------------
 drivers/gpu/drm/v3d/v3d_drv.h |  3 ++-
 2 files changed, 5 insertions(+), 21 deletions(-)
drivers/gpu/drm/v3d/v3d_bo.c +3 -20
index 7b1e2a5..f4e8de4 100644
@@ -227,37 +227,20 @@ struct reservation_object *v3d_prime_res_obj(struct drm_gem_object *obj)
 	vma->vm_page_prot = pgprot_writecombine(vm_get_page_prot(vma->vm_flags));
 }
 
-int v3d_gem_fault(struct vm_fault *vmf)
+vm_fault_t v3d_gem_fault(struct vm_fault *vmf)
 {
 	struct vm_area_struct *vma = vmf->vma;
 	struct drm_gem_object *obj = vma->vm_private_data;
 	struct v3d_bo *bo = to_v3d_bo(obj);
 	unsigned long pfn;
 	pgoff_t pgoff;
-	int ret;
 
 	/* We don't use vmf->pgoff since that has the fake offset: */
 	pgoff = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
 	pfn = page_to_pfn(bo->pages[pgoff]);
 
-	ret = vm_insert_mixed(vma, vmf->address, __pfn_to_pfn_t(pfn, PFN_DEV));
-
-	switch (ret) {
-	case -EAGAIN:
-	case 0:
-	case -ERESTARTSYS:
-	case -EINTR:
-	case -EBUSY:
-		/*
-		 * EBUSY is ok: this just means that another thread
-		 * already did the job.
-		 */
-		return VM_FAULT_NOPAGE;
-	case -ENOMEM:
-		return VM_FAULT_OOM;
-	default:
-		return VM_FAULT_SIGBUS;
-	}
+	return vmf_insert_mixed(vma, vmf->address,
+		__pfn_to_pfn_t(pfn, PFN_DEV));
 }
 
 int v3d_mmap(struct file *filp, struct vm_area_struct *vma)
drivers/gpu/drm/v3d/v3d_drv.h +2 -1
index a043ac3..09aa634 100644
@@ -2,6 +2,7 @@
 /* Copyright (C) 2015-2018 Broadcom */
 
 #include <linux/reservation.h>
+#include <linux/mm_types.h>
 #include <drm/drmP.h>
 #include <drm/drm_encoder.h>
 #include <drm/drm_gem.h>
@@ -248,7 +249,7 @@ int v3d_mmap_bo_ioctl(struct drm_device *dev, void *data,
 		      struct drm_file *file_priv);
 int v3d_get_bo_offset_ioctl(struct drm_device *dev, void *data,
 			    struct drm_file *file_priv);
-int v3d_gem_fault(struct vm_fault *vmf);
+vm_fault_t v3d_gem_fault(struct vm_fault *vmf);
 int v3d_mmap(struct file *filp, struct vm_area_struct *vma);
 struct reservation_object *v3d_prime_res_obj(struct drm_gem_object *obj);
 int v3d_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
Signature · 1 line
1.9.1
#1 lore raw
Quoted 5 lines · Souptick Joarder

Use new return type vm_fault_t for fault handler. For now, this is just documenting that the function returns a VM_FAULT value rather than an errno. Once all instances are converted, vm_fault_t will become a distinct type.

Quoted 7 lines

see commit 1c8f422059ae ("mm: change return type to vm_fault_t") for reference.

Previously vm_insert_mixed returns err which driver mapped into VM_FAULT_* type. The new function vmf_insert_mixed will replace this inefficiency by returning VM_FAULT_* type.

I really think this changelog could do with more work. Specifically for this patch, I'd just say:

Convert v3d_gem_fault to return vm_fault_t

Instead of converting an errno into a vm_fault_t ourselves, use vmf_insert_mixed() which returns a vm_fault_t directly.

Quoted 19 lines
drivers/gpu/drm/v3d/v3d_bo.c +0 -12
 	unsigned long pfn;
 	pgoff_t pgoff;
-	int ret;
 
 	/* We don't use vmf->pgoff since that has the fake offset: */
 	pgoff = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
 	pfn = page_to_pfn(bo->pages[pgoff]);
 
-	ret = vm_insert_mixed(vma, vmf->address, __pfn_to_pfn_t(pfn, PFN_DEV));
-
-	switch (ret) {
-	case -EAGAIN:
-	case 0:
-	case -ERESTARTSYS:
-	case -EINTR:
-	case -EBUSY:
-		/*
-		 * EBUSY is ok: this just means that another thread
-		 * already did the job.

drivers/gpu/drm/v3d/v3d_bo.c struct reservation_object *v3d_prime_res_obj(struct drm_gem_object *obj) · line 244

Quoted 10 lines
drivers/gpu/drm/v3d/v3d_bo.c +2 -7
-		 */
-		return VM_FAULT_NOPAGE;
-	case -ENOMEM:
-		return VM_FAULT_OOM;
-	default:
-		return VM_FAULT_SIGBUS;
-	}
+	return vmf_insert_mixed(vma, vmf->address,
+		__pfn_to_pfn_t(pfn, PFN_DEV));
 }

The line-split here is kind of ugly. I'd do a little more extensive surgery:

- unsigned long pfn;
+ pfn_t pfn;

- pfn = page_to_pfn(bo->pages[pgoff]);
+ pfn = __pfn_to_pfn_t(page_to_pfn(bo->pages[pgoff]), PFN_DEV);

+ return vmf_insert_mixed(vma, vmf->address, pfn);

#2 lore raw
Quoted 15 lines · Matthew Wilcox
Quoted 5 lines · Souptick Joarder

Use new return type vm_fault_t for fault handler. For now, this is just documenting that the function returns a VM_FAULT value rather than an errno. Once all instances are converted, vm_fault_t will become a distinct type.

Quoted 7 lines

see commit 1c8f422059ae ("mm: change return type to vm_fault_t") for reference.

Previously vm_insert_mixed returns err which driver mapped into VM_FAULT_* type. The new function vmf_insert_mixed will replace this inefficiency by returning VM_FAULT_* type.

Quoted 17 lines

I really think this changelog could do with more work. Specifically for this patch, I'd just say:

Convert v3d_gem_fault to return vm_fault_t

Instead of converting an errno into a vm_fault_t ourselves, use vmf_insert_mixed() which returns a vm_fault_t directly.

Quoted 9 lines
      unsigned long pfn;
      pgoff_t pgoff;
drivers/gpu/drm/v3d/v3d_bo.c +0 -2
-     int ret;
 
      /* We don't use vmf->pgoff since that has the fake offset: */
      pgoff = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
      pfn = page_to_pfn(bo->pages[pgoff]);
 
-     ret = vm_insert_mixed(vma, vmf->address, __pfn_to_pfn_t(pfn,

PFN_DEV));

Quoted 21 lines
Quoted 10 lines
drivers/gpu/drm/v3d/v3d_bo.c +0 -10
-
-     switch (ret) {
-     case -EAGAIN:
-     case 0:
-     case -ERESTARTSYS:
-     case -EINTR:
-     case -EBUSY:
-             /*
-              * EBUSY is ok: this just means that another thread
-              * already did the job.

drivers/gpu/drm/v3d/v3d_bo.c struct reservation_object *v3d_prime_res_obj(struct drm_gem_object *obj) · line 244

Quoted 10 lines
drivers/gpu/drm/v3d/v3d_bo.c +2 -7
-              */
-             return VM_FAULT_NOPAGE;
-     case -ENOMEM:
-             return VM_FAULT_OOM;
-     default:
-             return VM_FAULT_SIGBUS;
-     }
+     return vmf_insert_mixed(vma, vmf->address,
+             __pfn_to_pfn_t(pfn, PFN_DEV));
 }
Quoted 1 line

The line-split here is kind of ugly. I'd do a little more extensive

surgery:

Review

Quoted 8 lines
(quoted diff) +3 -2
-       unsigned long pfn;
+       pfn_t pfn;
 
-       pfn = page_to_pfn(bo->pages[pgoff]);
+       pfn = __pfn_to_pfn_t(page_to_pfn(bo->pages[pgoff]), PFN_DEV);
 
+       return vmf_insert_mixed(vma, vmf->address, pfn);

Ok, I will add the same and send v2.

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