linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Jani Nikula <jani.nikula@intel.com>
Cc: linux-fbdev@vger.kernel.org, intel-gfx@lists.freedesktop.org,
	dri-devel@lists.freedesktop.org, Jaya Kumar <jayalk@intworks.biz>
Subject: Re: [PATCH v2 01/14] video: fb_defio: preserve user fb_ops
Date: Fri, 29 Nov 2019 15:22:33 +0000	[thread overview]
Message-ID: <20191129152233.GF624164@phenom.ffwll.local> (raw)
In-Reply-To: <022c82429da15d6450ff9ac1a897322ec3124db4.1575022735.git.jani.nikula@intel.com>

On Fri, Nov 29, 2019 at 12:29:31PM +0200, Jani Nikula wrote:
> Modifying fb_ops directly to override fb_mmap with fb_deferred_io_mmap
> and then resetting it to NULL afterwards causes problems all over the
> place. First, it prevents making the fbops member of struct fb_info a
> const pointer, which means we can't make struct fb_ops const
> anywhere. Second, a few places have to go out of their way to restore
> the original fb_mmap pointer that gets reset to NULL.
> 
> Since the only user of the fbops->fb_mmap hook is fb_mmap() in fbmem.c,
> call fb_deferred_io_mmap() directly when deferred IO is enabled, and
> avoid modifying fb_ops altogether.
> 
> Simply use info->fbdefio to determine whether deferred IO should be used
> or not. This should be accurate enough for all use cases, although
> perhaps not pedantically correct.
> 
> v2: Simplify considerably by calling fb_deferred_io_mmap() directly
>     (Daniel, Ville)
> 
> Cc: Jaya Kumar <jayalk@intworks.biz>
> Cc: linux-fbdev@vger.kernel.org
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
> ---
>  drivers/video/fbdev/core/fb_defio.c |  3 ---
>  drivers/video/fbdev/core/fbmem.c    | 15 +++++++++++----
>  2 files changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
> index 82c20c6047b0..a591d291b231 100644
> --- a/drivers/video/fbdev/core/fb_defio.c
> +++ b/drivers/video/fbdev/core/fb_defio.c
> @@ -171,7 +171,6 @@ int fb_deferred_io_mmap(struct fb_info *info, struct vm_area_struct *vma)
>  	vma->vm_private_data = info;
>  	return 0;
>  }
> -EXPORT_SYMBOL(fb_deferred_io_mmap);
>  
>  /* workqueue callback */
>  static void fb_deferred_io_work(struct work_struct *work)
> @@ -206,7 +205,6 @@ void fb_deferred_io_init(struct fb_info *info)
>  
>  	BUG_ON(!fbdefio);
>  	mutex_init(&fbdefio->lock);
> -	info->fbops->fb_mmap = fb_deferred_io_mmap;
>  	INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
>  	INIT_LIST_HEAD(&fbdefio->pagelist);
>  	if (fbdefio->delay = 0) /* set a default of 1 s */
> @@ -237,7 +235,6 @@ void fb_deferred_io_cleanup(struct fb_info *info)
>  		page->mapping = NULL;
>  	}
>  
> -	info->fbops->fb_mmap = NULL;
>  	mutex_destroy(&fbdefio->lock);
>  }
>  EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
> diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
> index 86b06a599f96..990550930a8e 100644
> --- a/drivers/video/fbdev/core/fbmem.c
> +++ b/drivers/video/fbdev/core/fbmem.c
> @@ -1332,16 +1332,23 @@ static int
>  fb_mmap(struct file *file, struct vm_area_struct * vma)
>  {
>  	struct fb_info *info = file_fb_info(file);
> -	struct fb_ops *fb;
> +	int (*fb_mmap_fn)(struct fb_info *info, struct vm_area_struct *vma);

Oh I function pointer for tidier control flow, neato.

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>

>  	unsigned long mmio_pgoff;
>  	unsigned long start;
>  	u32 len;
>  
>  	if (!info)
>  		return -ENODEV;
> -	fb = info->fbops;
>  	mutex_lock(&info->mm_lock);
> -	if (fb->fb_mmap) {
> +
> +	fb_mmap_fn = info->fbops->fb_mmap;
> +
> +#if IS_ENABLED(CONFIG_FB_DEFERRED_IO)
> +	if (info->fbdefio)
> +		fb_mmap_fn = fb_deferred_io_mmap;
> +#endif
> +
> +	if (fb_mmap_fn) {
>  		int res;
>  
>  		/*
> @@ -1349,7 +1356,7 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)
>  		 * SME protection is removed ahead of the call
>  		 */
>  		vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
> -		res = fb->fb_mmap(info, vma);
> +		res = fb_mmap_fn(info, vma);
>  		mutex_unlock(&info->mm_lock);
>  		return res;
>  	}
> -- 
> 2.20.1
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

  parent reply	other threads:[~2019-11-29 15:22 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-29 10:29 [PATCH v2 00/14] video, drm, etc: constify fbops in struct fb_info Jani Nikula
2019-11-29 10:29 ` [PATCH v2 01/14] video: fb_defio: preserve user fb_ops Jani Nikula
2019-11-29 14:12   ` Noralf Trønnes
2019-11-29 15:22   ` Daniel Vetter [this message]
2019-11-29 10:29 ` [PATCH v2 02/14] drm/fb-helper: don't preserve fb_ops across deferred IO use Jani Nikula
2019-11-29 14:12   ` Noralf Trønnes
2019-11-29 10:29 ` [PATCH v2 03/14] video: smscufx: don't restore fb_mmap after deferred IO cleanup Jani Nikula
2019-11-29 10:29 ` [PATCH v2 04/14] video: udlfb: " Jani Nikula
2019-11-29 10:29 ` [PATCH v2 05/14] video: fbdev: vesafb: modify the static fb_ops directly Jani Nikula
2019-11-29 10:29 ` [PATCH v2 06/14] video: fbmem: use const pointer for fb_ops Jani Nikula
2019-11-29 15:25   ` [Intel-gfx] " Daniel Vetter
2019-11-29 10:29 ` [PATCH v2 07/14] video: omapfb: " Jani Nikula
2019-12-03  9:16   ` Jani Nikula
2019-11-29 10:29 ` [PATCH v2 08/14] video: fbdev: make fbops member of struct fb_info a const pointer Jani Nikula
2019-11-30  1:41   ` kbuild test robot
2019-11-29 10:29 ` [PATCH v2 09/14] drm: constify fb ops across all drivers Jani Nikula
2019-11-29 10:29 ` [PATCH v2 10/14] video: " Jani Nikula
2019-11-29 10:35   ` [Intel-gfx] " Jani Nikula
2019-11-29 10:29 ` [PATCH v2 11/14] HID: picoLCD: constify fb ops Jani Nikula
2019-12-02  8:40   ` Bruno Prémont
2019-12-05  9:38     ` Jani Nikula
2019-12-08  0:07       ` Jiri Kosina
2019-11-29 10:29 ` [PATCH v2 12/14] media: constify fb ops across all drivers Jani Nikula
2019-11-29 10:35   ` [Intel-gfx] " Jani Nikula
2019-11-29 10:29 ` [PATCH v2 13/14] samples: vfio-mdev: constify fb ops Jani Nikula
2019-11-29 10:29 ` [PATCH v2 14/14] auxdisplay: " Jani Nikula
2019-11-29 15:24   ` Daniel Vetter
2019-11-29 20:16     ` Miguel Ojeda
2019-11-29 20:30       ` Daniel Vetter
2019-11-29 20:59         ` Miguel Ojeda
2019-12-02  8:08           ` robin
2019-12-02  7:37   ` robin
2019-11-29 15:40 ` [PATCH v2 00/14] video, drm, etc: constify fbops in struct fb_info Daniel Vetter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191129152233.GF624164@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@intel.com \
    --cc=jayalk@intworks.biz \
    --cc=linux-fbdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).