Re: [PATCH v2] gpu: drm: etnaviv: Change return type to vm_fault_t

From: Lucas Stach
Date: Mon Jun 04 2018 - 05:31:48 EST


Am Dienstag, den 29.05.2018, 19:17 +0530 schrieb 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.
>
> Ref- commit 1c8f422059ae ("mm: change return type to vm_fault_t")
>
> Previously vm_insert_page() returns err which driver
> mapped into VM_FAULT_* type. The new function
> vmf_insert_page() 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@xxxxxxxxx>
> Reviewed-by: Matthew Wilcox <mawilcox@xxxxxxxxxxxxx>

Thanks, applied.

This won't be part of 4.18, as it's obviously too late for this
release, but will work it's way upstream with the next batch of etnaviv
updates.

Regards,
Lucas

> ---
> Âdrivers/gpu/drm/etnaviv/etnaviv_drv.h |ÂÂ3 ++-
> Âdrivers/gpu/drm/etnaviv/etnaviv_gem.c | 37 +++++++++--------------
> ------------
> Â2 files changed, 11 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h
> b/drivers/gpu/drm/etnaviv/etnaviv_drv.h
> index a54f0b7..f6777f0 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.h
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.h
> @@ -28,6 +28,7 @@
> Â#include <linux/list.h>
> Â#include <linux/types.h>
> Â#include <linux/sizes.h>
> +#include <linux/mm_types.h>
> Â
> Â#include <drm/drmP.h>
> Â#include <drm/drm_crtc_helper.h>
> @@ -62,7 +63,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device
> *dev, void *data,
> Â struct drm_file *file);
> Â
> Âint etnaviv_gem_mmap(struct file *filp, struct vm_area_struct *vma);
> -int etnaviv_gem_fault(struct vm_fault *vmf);
> +vm_fault_t etnaviv_gem_fault(struct vm_fault *vmf);
> Âint etnaviv_gem_mmap_offset(struct drm_gem_object *obj, u64
> *offset);
> Âstruct sg_table *etnaviv_gem_prime_get_sg_table(struct
> drm_gem_object *obj);
> Âvoid *etnaviv_gem_prime_vmap(struct drm_gem_object *obj);
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c
> b/drivers/gpu/drm/etnaviv/etnaviv_gem.c
> index fcc969f..b36e1ef 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c
> @@ -180,31 +180,30 @@ int etnaviv_gem_mmap(struct file *filp, struct
> vm_area_struct *vma)
> Â return obj->ops->mmap(obj, vma);
> Â}
> Â
> -int etnaviv_gem_fault(struct vm_fault *vmf)
> +vm_fault_t etnaviv_gem_fault(struct vm_fault *vmf)
> Â{
> Â struct vm_area_struct *vma = vmf->vma;
> Â struct drm_gem_object *obj = vma->vm_private_data;
> Â struct etnaviv_gem_object *etnaviv_obj = to_etnaviv_bo(obj);
> Â struct page **pages, *page;
> Â pgoff_t pgoff;
> - int ret;
> + int err;
> Â
> Â /*
> Â Â* Make sure we don't parallel update on a fault, nor move
> or remove
> - Â* something from beneath our feet.ÂÂNote that
> vm_insert_page() is
> + Â* something from beneath our feet.ÂÂNote that
> vmf_insert_page() is
> Â Â* specifically coded to take care of this, so we don't have
> to.
> Â Â*/
> - ret = mutex_lock_interruptible(&etnaviv_obj->lock);
> - if (ret)
> - goto out;
> -
> + err = mutex_lock_interruptible(&etnaviv_obj->lock);
> + if (err)
> + return VM_FAULT_NOPAGE;
> Â /* make sure we have pages attached now */
> Â pages = etnaviv_gem_get_pages(etnaviv_obj);
> Â mutex_unlock(&etnaviv_obj->lock);
> Â
> Â if (IS_ERR(pages)) {
> - ret = PTR_ERR(pages);
> - goto out;
> + err = PTR_ERR(pages);
> + return vmf_error(err);
> Â }
> Â
> Â /* We don't use vmf->pgoff since that has the fake offset:
> */
> @@ -215,25 +214,7 @@ int etnaviv_gem_fault(struct vm_fault *vmf)
> Â VERB("Inserting %p pfn %lx, pa %lx", (void *)vmf->address,
> Â ÂÂÂÂÂpage_to_pfn(page), page_to_pfn(page) << PAGE_SHIFT);
> Â
> - ret = vm_insert_page(vma, vmf->address, page);
> -
> -out:
> - 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_page(vma, vmf->address, page);
> Â}
> Â
> Âint etnaviv_gem_mmap_offset(struct drm_gem_object *obj, u64 *offset)