All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] gpu: drm: gma500: Change return type to vm_fault_t
@ 2018-07-13 15:45 Souptick Joarder
  0 siblings, 0 replies; 5+ messages in thread
From: Souptick Joarder @ 2018-07-13 15:45 UTC (permalink / raw)
  To: akpm; +Cc: patrik.r.jakobsson, airlied, dri-devel, linux-kernel, willy

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.

Ref-> commit 1c8f422059ae ("mm: change return type to vm_fault_t")

Previously vm_insert_{pfn,mixed} returns err which driver
mapped into VM_FAULT_* type. The new function
vmf_insert_{pfn,mixed} will replace this inefficiency by
returning VM_FAULT_* type.

vmf_error() is the newly introduce inline function
in 4.17-rc6.

Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
Reviewed-by: Matthew Wilcox <mawilcox@microsoft.com>
---
v2: updated the change log

v3: Fixed kbuild error

 drivers/gpu/drm/gma500/framebuffer.c | 14 +++++---------
 drivers/gpu/drm/gma500/gem.c         | 27 ++++++++++-----------------
 drivers/gpu/drm/gma500/psb_drv.h     |  3 ++-
 3 files changed, 17 insertions(+), 27 deletions(-)

diff --git a/drivers/gpu/drm/gma500/framebuffer.c b/drivers/gpu/drm/gma500/framebuffer.c
index cb0a2ae..632aadb 100644
--- a/drivers/gpu/drm/gma500/framebuffer.c
+++ b/drivers/gpu/drm/gma500/framebuffer.c
@@ -111,7 +111,7 @@ static int psbfb_pan(struct fb_var_screeninfo *var, struct fb_info *info)
         return 0;
 }
 
-static int psbfb_vm_fault(struct vm_fault *vmf)
+static vm_fault_t psbfb_vm_fault(struct vm_fault *vmf)
 {
 	struct vm_area_struct *vma = vmf->vma;
 	struct psb_framebuffer *psbfb = vma->vm_private_data;
@@ -120,7 +120,7 @@ static int psbfb_vm_fault(struct vm_fault *vmf)
 	int page_num;
 	int i;
 	unsigned long address;
-	int ret;
+	vm_fault_t ret = VM_FAULT_SIGBUS;
 	unsigned long pfn;
 	unsigned long phys_addr = (unsigned long)dev_priv->stolen_base +
 				  psbfb->gtt->offset;
@@ -133,18 +133,14 @@ static int psbfb_vm_fault(struct vm_fault *vmf)
 	for (i = 0; i < page_num; i++) {
 		pfn = (phys_addr >> PAGE_SHIFT);
 
-		ret = vm_insert_mixed(vma, address,
+		ret = vmf_insert_mixed(vma, address,
 				__pfn_to_pfn_t(pfn, PFN_DEV));
-		if (unlikely((ret == -EBUSY) || (ret != 0 && i > 0)))
+		if (unlikely(ret & VM_FAULT_ERROR))
 			break;
-		else if (unlikely(ret != 0)) {
-			ret = (ret == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS;
-			return ret;
-		}
 		address += PAGE_SIZE;
 		phys_addr += PAGE_SIZE;
 	}
-	return VM_FAULT_NOPAGE;
+	return ret;
 }
 
 static void psbfb_vm_open(struct vm_area_struct *vma)
diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c
index 1312397..e7be5c9 100644
--- a/drivers/gpu/drm/gma500/gem.c
+++ b/drivers/gpu/drm/gma500/gem.c
@@ -134,12 +134,13 @@ int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
  *	vma->vm_private_data points to the GEM object that is backing this
  *	mapping.
  */
-int psb_gem_fault(struct vm_fault *vmf)
+vm_fault_t psb_gem_fault(struct vm_fault *vmf)
 {
 	struct vm_area_struct *vma = vmf->vma;
 	struct drm_gem_object *obj;
 	struct gtt_range *r;
-	int ret;
+	int err;
+	vm_fault_t ret;
 	unsigned long pfn;
 	pgoff_t page_offset;
 	struct drm_device *dev;
@@ -158,9 +159,10 @@ int psb_gem_fault(struct vm_fault *vmf)
 	/* For now the mmap pins the object and it stays pinned. As things
 	   stand that will do us no harm */
 	if (r->mmapping == 0) {
-		ret = psb_gtt_pin(r);
-		if (ret < 0) {
-			dev_err(dev->dev, "gma500: pin failed: %d\n", ret);
+		err = psb_gtt_pin(r);
+		if (err < 0) {
+			dev_err(dev->dev, "gma500: pin failed: %d\n", err);
+			ret = vmf_error(err);
 			goto fail;
 		}
 		r->mmapping = 1;
@@ -175,18 +177,9 @@ int psb_gem_fault(struct vm_fault *vmf)
 		pfn = (dev_priv->stolen_base + r->offset) >> PAGE_SHIFT;
 	else
 		pfn = page_to_pfn(r->pages[page_offset]);
-	ret = vm_insert_pfn(vma, vmf->address, pfn);
-
+	ret = vmf_insert_pfn(vma, vmf->address, pfn);
 fail:
 	mutex_unlock(&dev_priv->mmap_mutex);
-	switch (ret) {
-	case 0:
-	case -ERESTARTSYS:
-	case -EINTR:
-		return VM_FAULT_NOPAGE;
-	case -ENOMEM:
-		return VM_FAULT_OOM;
-	default:
-		return VM_FAULT_SIGBUS;
-	}
+
+	return ret;
 }
diff --git a/drivers/gpu/drm/gma500/psb_drv.h b/drivers/gpu/drm/gma500/psb_drv.h
index e8300f5..93d2f40 100644
--- a/drivers/gpu/drm/gma500/psb_drv.h
+++ b/drivers/gpu/drm/gma500/psb_drv.h
@@ -21,6 +21,7 @@
 #define _PSB_DRV_H_
 
 #include <linux/kref.h>
+#include <linux/mm_types.h>
 
 #include <drm/drmP.h>
 #include <drm/drm_global.h>
@@ -749,7 +750,7 @@ extern int psb_gem_get_aperture(struct drm_device *dev, void *data,
 			struct drm_file *file);
 extern int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
 			struct drm_mode_create_dumb *args);
-extern int psb_gem_fault(struct vm_fault *vmf);
+extern vm_fault_t psb_gem_fault(struct vm_fault *vmf);
 
 /* psb_device.c */
 extern const struct psb_ops psb_chip_ops;
-- 
1.9.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] gpu: drm: gma500: Change return type to vm_fault_t
  2018-06-14 19:12   ` Souptick Joarder
@ 2018-07-03  6:16     ` Souptick Joarder
  0 siblings, 0 replies; 5+ messages in thread
From: Souptick Joarder @ 2018-07-03  6:16 UTC (permalink / raw)
  To: Matthew Wilcox, Patrik Jakobsson, airlied; +Cc: dri-devel, linux-kernel

On Fri, Jun 15, 2018 at 12:42 AM, Souptick Joarder <jrdr.linux@gmail.com> wrote:
> On Mon, Jun 4, 2018 at 10:47 AM, Souptick Joarder <jrdr.linux@gmail.com> wrote:
>> On Sun, May 27, 2018 at 6:15 AM, Souptick Joarder <jrdr.linux@gmail.com> wrote:
>>> 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.
>>>
>>> Ref-> commit 1c8f422059ae ("mm: change return type to vm_fault_t")
>>>
>>> Previously vm_insert_{pfn,mixed} returns err which driver
>>> mapped into VM_FAULT_* type. The new function
>>> vmf_insert_{pfn,mixed} will replace this inefficiency by
>>> returning VM_FAULT_* type.
>>>
>>> vmf_error() is the newly introduce inline function
>>> in 4.17-rc6.
>>>
>>> Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
>>> Reviewed-by: Matthew Wilcox <mawilcox@microsoft.com>
>>> ---
>>> v2: updated the change log
>>>
>>> v3: Fixed kbuild error
>>>
>>>  drivers/gpu/drm/gma500/framebuffer.c | 14 +++++---------
>>>  drivers/gpu/drm/gma500/gem.c         | 27 ++++++++++-----------------
>>>  drivers/gpu/drm/gma500/psb_drv.h     |  3 ++-
>>>  3 files changed, 17 insertions(+), 27 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/gma500/framebuffer.c b/drivers/gpu/drm/gma500/framebuffer.c
>>> index cb0a2ae..632aadb 100644
>>> --- a/drivers/gpu/drm/gma500/framebuffer.c
>>> +++ b/drivers/gpu/drm/gma500/framebuffer.c
>>> @@ -111,7 +111,7 @@ static int psbfb_pan(struct fb_var_screeninfo *var, struct fb_info *info)
>>>          return 0;
>>>  }
>>>
>>> -static int psbfb_vm_fault(struct vm_fault *vmf)
>>> +static vm_fault_t psbfb_vm_fault(struct vm_fault *vmf)
>>>  {
>>>         struct vm_area_struct *vma = vmf->vma;
>>>         struct psb_framebuffer *psbfb = vma->vm_private_data;
>>> @@ -120,7 +120,7 @@ static int psbfb_vm_fault(struct vm_fault *vmf)
>>>         int page_num;
>>>         int i;
>>>         unsigned long address;
>>> -       int ret;
>>> +       vm_fault_t ret = VM_FAULT_SIGBUS;
>>>         unsigned long pfn;
>>>         unsigned long phys_addr = (unsigned long)dev_priv->stolen_base +
>>>                                   psbfb->gtt->offset;
>>> @@ -133,18 +133,14 @@ static int psbfb_vm_fault(struct vm_fault *vmf)
>>>         for (i = 0; i < page_num; i++) {
>>>                 pfn = (phys_addr >> PAGE_SHIFT);
>>>
>>> -               ret = vm_insert_mixed(vma, address,
>>> +               ret = vmf_insert_mixed(vma, address,
>>>                                 __pfn_to_pfn_t(pfn, PFN_DEV));
>>> -               if (unlikely((ret == -EBUSY) || (ret != 0 && i > 0)))
>>> +               if (unlikely(ret & VM_FAULT_ERROR))
>>>                         break;
>>> -               else if (unlikely(ret != 0)) {
>>> -                       ret = (ret == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS;
>>> -                       return ret;
>>> -               }
>>>                 address += PAGE_SIZE;
>>>                 phys_addr += PAGE_SIZE;
>>>         }
>>> -       return VM_FAULT_NOPAGE;
>>> +       return ret;
>>>  }
>>>
>>>  static void psbfb_vm_open(struct vm_area_struct *vma)
>>> diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c
>>> index 1312397..e7be5c9 100644
>>> --- a/drivers/gpu/drm/gma500/gem.c
>>> +++ b/drivers/gpu/drm/gma500/gem.c
>>> @@ -134,12 +134,13 @@ int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
>>>   *     vma->vm_private_data points to the GEM object that is backing this
>>>   *     mapping.
>>>   */
>>> -int psb_gem_fault(struct vm_fault *vmf)
>>> +vm_fault_t psb_gem_fault(struct vm_fault *vmf)
>>>  {
>>>         struct vm_area_struct *vma = vmf->vma;
>>>         struct drm_gem_object *obj;
>>>         struct gtt_range *r;
>>> -       int ret;
>>> +       int err;
>>> +       vm_fault_t ret;
>>>         unsigned long pfn;
>>>         pgoff_t page_offset;
>>>         struct drm_device *dev;
>>> @@ -158,9 +159,10 @@ int psb_gem_fault(struct vm_fault *vmf)
>>>         /* For now the mmap pins the object and it stays pinned. As things
>>>            stand that will do us no harm */
>>>         if (r->mmapping == 0) {
>>> -               ret = psb_gtt_pin(r);
>>> -               if (ret < 0) {
>>> -                       dev_err(dev->dev, "gma500: pin failed: %d\n", ret);
>>> +               err = psb_gtt_pin(r);
>>> +               if (err < 0) {
>>> +                       dev_err(dev->dev, "gma500: pin failed: %d\n", err);
>>> +                       ret = vmf_error(err);
>>>                         goto fail;
>>>                 }
>>>                 r->mmapping = 1;
>>> @@ -175,18 +177,9 @@ int psb_gem_fault(struct vm_fault *vmf)
>>>                 pfn = (dev_priv->stolen_base + r->offset) >> PAGE_SHIFT;
>>>         else
>>>                 pfn = page_to_pfn(r->pages[page_offset]);
>>> -       ret = vm_insert_pfn(vma, vmf->address, pfn);
>>> -
>>> +       ret = vmf_insert_pfn(vma, vmf->address, pfn);
>>>  fail:
>>>         mutex_unlock(&dev_priv->mmap_mutex);
>>> -       switch (ret) {
>>> -       case 0:
>>> -       case -ERESTARTSYS:
>>> -       case -EINTR:
>>> -               return VM_FAULT_NOPAGE;
>>> -       case -ENOMEM:
>>> -               return VM_FAULT_OOM;
>>> -       default:
>>> -               return VM_FAULT_SIGBUS;
>>> -       }
>>> +
>>> +       return ret;
>>>  }
>>> diff --git a/drivers/gpu/drm/gma500/psb_drv.h b/drivers/gpu/drm/gma500/psb_drv.h
>>> index e8300f5..93d2f40 100644
>>> --- a/drivers/gpu/drm/gma500/psb_drv.h
>>> +++ b/drivers/gpu/drm/gma500/psb_drv.h
>>> @@ -21,6 +21,7 @@
>>>  #define _PSB_DRV_H_
>>>
>>>  #include <linux/kref.h>
>>> +#include <linux/mm_types.h>
>>>
>>>  #include <drm/drmP.h>
>>>  #include <drm/drm_global.h>
>>> @@ -749,7 +750,7 @@ extern int psb_gem_get_aperture(struct drm_device *dev, void *data,
>>>                         struct drm_file *file);
>>>  extern int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
>>>                         struct drm_mode_create_dumb *args);
>>> -extern int psb_gem_fault(struct vm_fault *vmf);
>>> +extern vm_fault_t psb_gem_fault(struct vm_fault *vmf);
>>>
>>>  /* psb_device.c */
>>>  extern const struct psb_ops psb_chip_ops;
>>> --
>>> 1.9.1
>>>
>>
>> If no comment, we would like to get this patch
>> in 4.18.
>
> Patrik, Is it possible to get this patch in 4.18 ?

Can we get this patch in queue for 4.19 ?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] gpu: drm: gma500: Change return type to vm_fault_t
  2018-06-04  5:17 ` Souptick Joarder
@ 2018-06-14 19:12   ` Souptick Joarder
  2018-07-03  6:16     ` Souptick Joarder
  0 siblings, 1 reply; 5+ messages in thread
From: Souptick Joarder @ 2018-06-14 19:12 UTC (permalink / raw)
  To: Matthew Wilcox, Patrik Jakobsson, airlied; +Cc: dri-devel, linux-kernel

On Mon, Jun 4, 2018 at 10:47 AM, Souptick Joarder <jrdr.linux@gmail.com> wrote:
> On Sun, May 27, 2018 at 6:15 AM, Souptick Joarder <jrdr.linux@gmail.com> wrote:
>> 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.
>>
>> Ref-> commit 1c8f422059ae ("mm: change return type to vm_fault_t")
>>
>> Previously vm_insert_{pfn,mixed} returns err which driver
>> mapped into VM_FAULT_* type. The new function
>> vmf_insert_{pfn,mixed} will replace this inefficiency by
>> returning VM_FAULT_* type.
>>
>> vmf_error() is the newly introduce inline function
>> in 4.17-rc6.
>>
>> Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
>> Reviewed-by: Matthew Wilcox <mawilcox@microsoft.com>
>> ---
>> v2: updated the change log
>>
>> v3: Fixed kbuild error
>>
>>  drivers/gpu/drm/gma500/framebuffer.c | 14 +++++---------
>>  drivers/gpu/drm/gma500/gem.c         | 27 ++++++++++-----------------
>>  drivers/gpu/drm/gma500/psb_drv.h     |  3 ++-
>>  3 files changed, 17 insertions(+), 27 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/gma500/framebuffer.c b/drivers/gpu/drm/gma500/framebuffer.c
>> index cb0a2ae..632aadb 100644
>> --- a/drivers/gpu/drm/gma500/framebuffer.c
>> +++ b/drivers/gpu/drm/gma500/framebuffer.c
>> @@ -111,7 +111,7 @@ static int psbfb_pan(struct fb_var_screeninfo *var, struct fb_info *info)
>>          return 0;
>>  }
>>
>> -static int psbfb_vm_fault(struct vm_fault *vmf)
>> +static vm_fault_t psbfb_vm_fault(struct vm_fault *vmf)
>>  {
>>         struct vm_area_struct *vma = vmf->vma;
>>         struct psb_framebuffer *psbfb = vma->vm_private_data;
>> @@ -120,7 +120,7 @@ static int psbfb_vm_fault(struct vm_fault *vmf)
>>         int page_num;
>>         int i;
>>         unsigned long address;
>> -       int ret;
>> +       vm_fault_t ret = VM_FAULT_SIGBUS;
>>         unsigned long pfn;
>>         unsigned long phys_addr = (unsigned long)dev_priv->stolen_base +
>>                                   psbfb->gtt->offset;
>> @@ -133,18 +133,14 @@ static int psbfb_vm_fault(struct vm_fault *vmf)
>>         for (i = 0; i < page_num; i++) {
>>                 pfn = (phys_addr >> PAGE_SHIFT);
>>
>> -               ret = vm_insert_mixed(vma, address,
>> +               ret = vmf_insert_mixed(vma, address,
>>                                 __pfn_to_pfn_t(pfn, PFN_DEV));
>> -               if (unlikely((ret == -EBUSY) || (ret != 0 && i > 0)))
>> +               if (unlikely(ret & VM_FAULT_ERROR))
>>                         break;
>> -               else if (unlikely(ret != 0)) {
>> -                       ret = (ret == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS;
>> -                       return ret;
>> -               }
>>                 address += PAGE_SIZE;
>>                 phys_addr += PAGE_SIZE;
>>         }
>> -       return VM_FAULT_NOPAGE;
>> +       return ret;
>>  }
>>
>>  static void psbfb_vm_open(struct vm_area_struct *vma)
>> diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c
>> index 1312397..e7be5c9 100644
>> --- a/drivers/gpu/drm/gma500/gem.c
>> +++ b/drivers/gpu/drm/gma500/gem.c
>> @@ -134,12 +134,13 @@ int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
>>   *     vma->vm_private_data points to the GEM object that is backing this
>>   *     mapping.
>>   */
>> -int psb_gem_fault(struct vm_fault *vmf)
>> +vm_fault_t psb_gem_fault(struct vm_fault *vmf)
>>  {
>>         struct vm_area_struct *vma = vmf->vma;
>>         struct drm_gem_object *obj;
>>         struct gtt_range *r;
>> -       int ret;
>> +       int err;
>> +       vm_fault_t ret;
>>         unsigned long pfn;
>>         pgoff_t page_offset;
>>         struct drm_device *dev;
>> @@ -158,9 +159,10 @@ int psb_gem_fault(struct vm_fault *vmf)
>>         /* For now the mmap pins the object and it stays pinned. As things
>>            stand that will do us no harm */
>>         if (r->mmapping == 0) {
>> -               ret = psb_gtt_pin(r);
>> -               if (ret < 0) {
>> -                       dev_err(dev->dev, "gma500: pin failed: %d\n", ret);
>> +               err = psb_gtt_pin(r);
>> +               if (err < 0) {
>> +                       dev_err(dev->dev, "gma500: pin failed: %d\n", err);
>> +                       ret = vmf_error(err);
>>                         goto fail;
>>                 }
>>                 r->mmapping = 1;
>> @@ -175,18 +177,9 @@ int psb_gem_fault(struct vm_fault *vmf)
>>                 pfn = (dev_priv->stolen_base + r->offset) >> PAGE_SHIFT;
>>         else
>>                 pfn = page_to_pfn(r->pages[page_offset]);
>> -       ret = vm_insert_pfn(vma, vmf->address, pfn);
>> -
>> +       ret = vmf_insert_pfn(vma, vmf->address, pfn);
>>  fail:
>>         mutex_unlock(&dev_priv->mmap_mutex);
>> -       switch (ret) {
>> -       case 0:
>> -       case -ERESTARTSYS:
>> -       case -EINTR:
>> -               return VM_FAULT_NOPAGE;
>> -       case -ENOMEM:
>> -               return VM_FAULT_OOM;
>> -       default:
>> -               return VM_FAULT_SIGBUS;
>> -       }
>> +
>> +       return ret;
>>  }
>> diff --git a/drivers/gpu/drm/gma500/psb_drv.h b/drivers/gpu/drm/gma500/psb_drv.h
>> index e8300f5..93d2f40 100644
>> --- a/drivers/gpu/drm/gma500/psb_drv.h
>> +++ b/drivers/gpu/drm/gma500/psb_drv.h
>> @@ -21,6 +21,7 @@
>>  #define _PSB_DRV_H_
>>
>>  #include <linux/kref.h>
>> +#include <linux/mm_types.h>
>>
>>  #include <drm/drmP.h>
>>  #include <drm/drm_global.h>
>> @@ -749,7 +750,7 @@ extern int psb_gem_get_aperture(struct drm_device *dev, void *data,
>>                         struct drm_file *file);
>>  extern int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
>>                         struct drm_mode_create_dumb *args);
>> -extern int psb_gem_fault(struct vm_fault *vmf);
>> +extern vm_fault_t psb_gem_fault(struct vm_fault *vmf);
>>
>>  /* psb_device.c */
>>  extern const struct psb_ops psb_chip_ops;
>> --
>> 1.9.1
>>
>
> If no comment, we would like to get this patch
> in 4.18.

Patrik, Is it possible to get this patch in 4.18 ?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] gpu: drm: gma500: Change return type to vm_fault_t
  2018-05-27  0:45 Souptick Joarder
@ 2018-06-04  5:17 ` Souptick Joarder
  2018-06-14 19:12   ` Souptick Joarder
  0 siblings, 1 reply; 5+ messages in thread
From: Souptick Joarder @ 2018-06-04  5:17 UTC (permalink / raw)
  To: Matthew Wilcox, Patrik Jakobsson, airlied; +Cc: dri-devel, linux-kernel

On Sun, May 27, 2018 at 6:15 AM, Souptick Joarder <jrdr.linux@gmail.com> wrote:
> 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.
>
> Ref-> commit 1c8f422059ae ("mm: change return type to vm_fault_t")
>
> Previously vm_insert_{pfn,mixed} returns err which driver
> mapped into VM_FAULT_* type. The new function
> vmf_insert_{pfn,mixed} will replace this inefficiency by
> returning VM_FAULT_* type.
>
> vmf_error() is the newly introduce inline function
> in 4.17-rc6.
>
> Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
> Reviewed-by: Matthew Wilcox <mawilcox@microsoft.com>
> ---
> v2: updated the change log
>
> v3: Fixed kbuild error
>
>  drivers/gpu/drm/gma500/framebuffer.c | 14 +++++---------
>  drivers/gpu/drm/gma500/gem.c         | 27 ++++++++++-----------------
>  drivers/gpu/drm/gma500/psb_drv.h     |  3 ++-
>  3 files changed, 17 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/gpu/drm/gma500/framebuffer.c b/drivers/gpu/drm/gma500/framebuffer.c
> index cb0a2ae..632aadb 100644
> --- a/drivers/gpu/drm/gma500/framebuffer.c
> +++ b/drivers/gpu/drm/gma500/framebuffer.c
> @@ -111,7 +111,7 @@ static int psbfb_pan(struct fb_var_screeninfo *var, struct fb_info *info)
>          return 0;
>  }
>
> -static int psbfb_vm_fault(struct vm_fault *vmf)
> +static vm_fault_t psbfb_vm_fault(struct vm_fault *vmf)
>  {
>         struct vm_area_struct *vma = vmf->vma;
>         struct psb_framebuffer *psbfb = vma->vm_private_data;
> @@ -120,7 +120,7 @@ static int psbfb_vm_fault(struct vm_fault *vmf)
>         int page_num;
>         int i;
>         unsigned long address;
> -       int ret;
> +       vm_fault_t ret = VM_FAULT_SIGBUS;
>         unsigned long pfn;
>         unsigned long phys_addr = (unsigned long)dev_priv->stolen_base +
>                                   psbfb->gtt->offset;
> @@ -133,18 +133,14 @@ static int psbfb_vm_fault(struct vm_fault *vmf)
>         for (i = 0; i < page_num; i++) {
>                 pfn = (phys_addr >> PAGE_SHIFT);
>
> -               ret = vm_insert_mixed(vma, address,
> +               ret = vmf_insert_mixed(vma, address,
>                                 __pfn_to_pfn_t(pfn, PFN_DEV));
> -               if (unlikely((ret == -EBUSY) || (ret != 0 && i > 0)))
> +               if (unlikely(ret & VM_FAULT_ERROR))
>                         break;
> -               else if (unlikely(ret != 0)) {
> -                       ret = (ret == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS;
> -                       return ret;
> -               }
>                 address += PAGE_SIZE;
>                 phys_addr += PAGE_SIZE;
>         }
> -       return VM_FAULT_NOPAGE;
> +       return ret;
>  }
>
>  static void psbfb_vm_open(struct vm_area_struct *vma)
> diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c
> index 1312397..e7be5c9 100644
> --- a/drivers/gpu/drm/gma500/gem.c
> +++ b/drivers/gpu/drm/gma500/gem.c
> @@ -134,12 +134,13 @@ int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
>   *     vma->vm_private_data points to the GEM object that is backing this
>   *     mapping.
>   */
> -int psb_gem_fault(struct vm_fault *vmf)
> +vm_fault_t psb_gem_fault(struct vm_fault *vmf)
>  {
>         struct vm_area_struct *vma = vmf->vma;
>         struct drm_gem_object *obj;
>         struct gtt_range *r;
> -       int ret;
> +       int err;
> +       vm_fault_t ret;
>         unsigned long pfn;
>         pgoff_t page_offset;
>         struct drm_device *dev;
> @@ -158,9 +159,10 @@ int psb_gem_fault(struct vm_fault *vmf)
>         /* For now the mmap pins the object and it stays pinned. As things
>            stand that will do us no harm */
>         if (r->mmapping == 0) {
> -               ret = psb_gtt_pin(r);
> -               if (ret < 0) {
> -                       dev_err(dev->dev, "gma500: pin failed: %d\n", ret);
> +               err = psb_gtt_pin(r);
> +               if (err < 0) {
> +                       dev_err(dev->dev, "gma500: pin failed: %d\n", err);
> +                       ret = vmf_error(err);
>                         goto fail;
>                 }
>                 r->mmapping = 1;
> @@ -175,18 +177,9 @@ int psb_gem_fault(struct vm_fault *vmf)
>                 pfn = (dev_priv->stolen_base + r->offset) >> PAGE_SHIFT;
>         else
>                 pfn = page_to_pfn(r->pages[page_offset]);
> -       ret = vm_insert_pfn(vma, vmf->address, pfn);
> -
> +       ret = vmf_insert_pfn(vma, vmf->address, pfn);
>  fail:
>         mutex_unlock(&dev_priv->mmap_mutex);
> -       switch (ret) {
> -       case 0:
> -       case -ERESTARTSYS:
> -       case -EINTR:
> -               return VM_FAULT_NOPAGE;
> -       case -ENOMEM:
> -               return VM_FAULT_OOM;
> -       default:
> -               return VM_FAULT_SIGBUS;
> -       }
> +
> +       return ret;
>  }
> diff --git a/drivers/gpu/drm/gma500/psb_drv.h b/drivers/gpu/drm/gma500/psb_drv.h
> index e8300f5..93d2f40 100644
> --- a/drivers/gpu/drm/gma500/psb_drv.h
> +++ b/drivers/gpu/drm/gma500/psb_drv.h
> @@ -21,6 +21,7 @@
>  #define _PSB_DRV_H_
>
>  #include <linux/kref.h>
> +#include <linux/mm_types.h>
>
>  #include <drm/drmP.h>
>  #include <drm/drm_global.h>
> @@ -749,7 +750,7 @@ extern int psb_gem_get_aperture(struct drm_device *dev, void *data,
>                         struct drm_file *file);
>  extern int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
>                         struct drm_mode_create_dumb *args);
> -extern int psb_gem_fault(struct vm_fault *vmf);
> +extern vm_fault_t psb_gem_fault(struct vm_fault *vmf);
>
>  /* psb_device.c */
>  extern const struct psb_ops psb_chip_ops;
> --
> 1.9.1
>

If no comment, we would like to get this patch
in 4.18.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3] gpu: drm: gma500: Change return type to vm_fault_t
@ 2018-05-27  0:45 Souptick Joarder
  2018-06-04  5:17 ` Souptick Joarder
  0 siblings, 1 reply; 5+ messages in thread
From: Souptick Joarder @ 2018-05-27  0:45 UTC (permalink / raw)
  To: willy, patrik.r.jakobsson, airlied; +Cc: dri-devel, linux-kernel

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.

Ref-> commit 1c8f422059ae ("mm: change return type to vm_fault_t")

Previously vm_insert_{pfn,mixed} returns err which driver
mapped into VM_FAULT_* type. The new function
vmf_insert_{pfn,mixed} will replace this inefficiency by
returning VM_FAULT_* type.

vmf_error() is the newly introduce inline function
in 4.17-rc6.

Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
Reviewed-by: Matthew Wilcox <mawilcox@microsoft.com>
---
v2: updated the change log

v3: Fixed kbuild error

 drivers/gpu/drm/gma500/framebuffer.c | 14 +++++---------
 drivers/gpu/drm/gma500/gem.c         | 27 ++++++++++-----------------
 drivers/gpu/drm/gma500/psb_drv.h     |  3 ++-
 3 files changed, 17 insertions(+), 27 deletions(-)

diff --git a/drivers/gpu/drm/gma500/framebuffer.c b/drivers/gpu/drm/gma500/framebuffer.c
index cb0a2ae..632aadb 100644
--- a/drivers/gpu/drm/gma500/framebuffer.c
+++ b/drivers/gpu/drm/gma500/framebuffer.c
@@ -111,7 +111,7 @@ static int psbfb_pan(struct fb_var_screeninfo *var, struct fb_info *info)
         return 0;
 }
 
-static int psbfb_vm_fault(struct vm_fault *vmf)
+static vm_fault_t psbfb_vm_fault(struct vm_fault *vmf)
 {
 	struct vm_area_struct *vma = vmf->vma;
 	struct psb_framebuffer *psbfb = vma->vm_private_data;
@@ -120,7 +120,7 @@ static int psbfb_vm_fault(struct vm_fault *vmf)
 	int page_num;
 	int i;
 	unsigned long address;
-	int ret;
+	vm_fault_t ret = VM_FAULT_SIGBUS;
 	unsigned long pfn;
 	unsigned long phys_addr = (unsigned long)dev_priv->stolen_base +
 				  psbfb->gtt->offset;
@@ -133,18 +133,14 @@ static int psbfb_vm_fault(struct vm_fault *vmf)
 	for (i = 0; i < page_num; i++) {
 		pfn = (phys_addr >> PAGE_SHIFT);
 
-		ret = vm_insert_mixed(vma, address,
+		ret = vmf_insert_mixed(vma, address,
 				__pfn_to_pfn_t(pfn, PFN_DEV));
-		if (unlikely((ret == -EBUSY) || (ret != 0 && i > 0)))
+		if (unlikely(ret & VM_FAULT_ERROR))
 			break;
-		else if (unlikely(ret != 0)) {
-			ret = (ret == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS;
-			return ret;
-		}
 		address += PAGE_SIZE;
 		phys_addr += PAGE_SIZE;
 	}
-	return VM_FAULT_NOPAGE;
+	return ret;
 }
 
 static void psbfb_vm_open(struct vm_area_struct *vma)
diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c
index 1312397..e7be5c9 100644
--- a/drivers/gpu/drm/gma500/gem.c
+++ b/drivers/gpu/drm/gma500/gem.c
@@ -134,12 +134,13 @@ int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
  *	vma->vm_private_data points to the GEM object that is backing this
  *	mapping.
  */
-int psb_gem_fault(struct vm_fault *vmf)
+vm_fault_t psb_gem_fault(struct vm_fault *vmf)
 {
 	struct vm_area_struct *vma = vmf->vma;
 	struct drm_gem_object *obj;
 	struct gtt_range *r;
-	int ret;
+	int err;
+	vm_fault_t ret;
 	unsigned long pfn;
 	pgoff_t page_offset;
 	struct drm_device *dev;
@@ -158,9 +159,10 @@ int psb_gem_fault(struct vm_fault *vmf)
 	/* For now the mmap pins the object and it stays pinned. As things
 	   stand that will do us no harm */
 	if (r->mmapping == 0) {
-		ret = psb_gtt_pin(r);
-		if (ret < 0) {
-			dev_err(dev->dev, "gma500: pin failed: %d\n", ret);
+		err = psb_gtt_pin(r);
+		if (err < 0) {
+			dev_err(dev->dev, "gma500: pin failed: %d\n", err);
+			ret = vmf_error(err);
 			goto fail;
 		}
 		r->mmapping = 1;
@@ -175,18 +177,9 @@ int psb_gem_fault(struct vm_fault *vmf)
 		pfn = (dev_priv->stolen_base + r->offset) >> PAGE_SHIFT;
 	else
 		pfn = page_to_pfn(r->pages[page_offset]);
-	ret = vm_insert_pfn(vma, vmf->address, pfn);
-
+	ret = vmf_insert_pfn(vma, vmf->address, pfn);
 fail:
 	mutex_unlock(&dev_priv->mmap_mutex);
-	switch (ret) {
-	case 0:
-	case -ERESTARTSYS:
-	case -EINTR:
-		return VM_FAULT_NOPAGE;
-	case -ENOMEM:
-		return VM_FAULT_OOM;
-	default:
-		return VM_FAULT_SIGBUS;
-	}
+
+	return ret;
 }
diff --git a/drivers/gpu/drm/gma500/psb_drv.h b/drivers/gpu/drm/gma500/psb_drv.h
index e8300f5..93d2f40 100644
--- a/drivers/gpu/drm/gma500/psb_drv.h
+++ b/drivers/gpu/drm/gma500/psb_drv.h
@@ -21,6 +21,7 @@
 #define _PSB_DRV_H_
 
 #include <linux/kref.h>
+#include <linux/mm_types.h>
 
 #include <drm/drmP.h>
 #include <drm/drm_global.h>
@@ -749,7 +750,7 @@ extern int psb_gem_get_aperture(struct drm_device *dev, void *data,
 			struct drm_file *file);
 extern int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
 			struct drm_mode_create_dumb *args);
-extern int psb_gem_fault(struct vm_fault *vmf);
+extern vm_fault_t psb_gem_fault(struct vm_fault *vmf);
 
 /* psb_device.c */
 extern const struct psb_ops psb_chip_ops;
-- 
1.9.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-07-13 15:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-13 15:45 [PATCH v3] gpu: drm: gma500: Change return type to vm_fault_t Souptick Joarder
  -- strict thread matches above, loose matches on Subject: below --
2018-05-27  0:45 Souptick Joarder
2018-06-04  5:17 ` Souptick Joarder
2018-06-14 19:12   ` Souptick Joarder
2018-07-03  6:16     ` Souptick Joarder

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.