From: Daniel Vetter <daniel@ffwll.ch>
To: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
Cc: Jani Nikula <jani.nikula@intel.com>,
linux-fbdev@vger.kernel.org, intel-gfx@lists.freedesktop.org,
dri-devel@lists.freedesktop.org, Jaya Kumar <jayalk@intworks.biz>
Subject: Re: [Intel-gfx] [PATCH 01/13] video: fb_defio: preserve user fb_ops
Date: Wed, 27 Nov 2019 18:09:32 +0000 [thread overview]
Message-ID: <20191127180932.GE406127@phenom.ffwll.local> (raw)
In-Reply-To: <20191127170116.GK1208@intel.com>
On Wed, Nov 27, 2019 at 07:01:16PM +0200, Ville Syrjälä wrote:
> On Wed, Nov 27, 2019 at 06:31:57PM +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.
> >
> > Preserve the passed in fb_ops by making a copy of it and modifying that
> > instead. Add a deferred_io_private member to struct fb_info to store the
> > pointer to the old fb_ops, and restore that at cleanup.
>
> Quite the horror show. I wonder how hard it would be to just have each
> driver that can use defio provide a mmap hook that either dispatches
> to the defio one or the native one depending if defio is used or not...
>
> A few drivers at least seem to always use defio so those should be
> trivial. Some others seem to make the decision dynamically, which
> would require custom .mmap(). Though I suppose all of them could just
> be of the form
> foo_mmap_wrap{)
> {
> if (info->defio)
> defio_mmap()
> else
> foo_mmap();
> }
>
> Hmm. Actually is .fb_mmap() called from anywhere but fb_mmap()? If not
> we could just shove the defio check there? Or if it's called from
> several places we could try to wrap all calls in _fb_mmap() or somesuch.
While we're spinning this garn about fb_mmap improvements: My cunning
plan, documented in todo.rst even, is to have our own fb_mmap
implementation for the drm fbdev helper, which will handle all this
internally.
And then just quietly burn down the fbdev defio stuff to the ground,
because it's the stuff for nightmares.
https://dri.freedesktop.org/docs/drm/gpu/todo.html#generic-fbdev-defio-support
tldr; Imo no point investing too much in polishing the defio stuff.
-Daniel
>
> >
> > Cc: Jaya Kumar <jayalk@intworks.biz>
> > Cc: linux-fbdev@vger.kernel.org
> > Signed-off-by: Jani Nikula <jani.nikula@intel.com>
> >
> > ---
> >
> > Note: If the approach is acceptable, we'll also need to handle the error
> > returns on memory allocation failures at fb_deferred_io_init() call
> > sites. There are 13.
> > ---
> > drivers/video/fbdev/core/fb_defio.c | 25 ++++++++++++++++++++++---
> > include/linux/fb.h | 3 ++-
> > 2 files changed, 24 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
> > index 82c20c6047b0..36697844c1e0 100644
> > --- a/drivers/video/fbdev/core/fb_defio.c
> > +++ b/drivers/video/fbdev/core/fb_defio.c
> > @@ -200,13 +200,23 @@ static void fb_deferred_io_work(struct work_struct *work)
> > mutex_unlock(&fbdefio->lock);
> > }
> >
> > -void fb_deferred_io_init(struct fb_info *info)
> > +int fb_deferred_io_init(struct fb_info *info)
> > {
> > struct fb_deferred_io *fbdefio = info->fbdefio;
> > + struct fb_ops *fbops;
> >
> > BUG_ON(!fbdefio);
> > +
> > + fbops = kmemdup(info->fbops, sizeof(*fbops), GFP_KERNEL);
> > + if (!fbops)
> > + return -ENOMEM;
> > +
> > + fbops->fb_mmap = fb_deferred_io_mmap;
> > + info->deferred_io_private = info->fbops;
> > + info->fbops = fbops;
> > +
> > 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 */
> > @@ -229,6 +239,12 @@ void fb_deferred_io_cleanup(struct fb_info *info)
> > int i;
> >
> > BUG_ON(!fbdefio);
> > +
> > + /* sanity check against misuse */
> > + if (WARN_ON(!info->deferred_io_private ||
> > + info->fbops->fb_mmap != fb_deferred_io_mmap))
> > + return;
> > +
> > cancel_delayed_work_sync(&info->deferred_work);
> >
> > /* clear out the mapping that we setup */
> > @@ -237,7 +253,10 @@ void fb_deferred_io_cleanup(struct fb_info *info)
> > page->mapping = NULL;
> > }
> >
> > - info->fbops->fb_mmap = NULL;
> > + kfree(info->fbops);
> > + info->fbops = info->deferred_io_private;
> > + info->deferred_io_private = NULL;
> > +
> > mutex_destroy(&fbdefio->lock);
> > }
> > EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
> > diff --git a/include/linux/fb.h b/include/linux/fb.h
> > index a6ad528990de..65f2abd47745 100644
> > --- a/include/linux/fb.h
> > +++ b/include/linux/fb.h
> > @@ -470,6 +470,7 @@ struct fb_info {
> > #ifdef CONFIG_FB_DEFERRED_IO
> > struct delayed_work deferred_work;
> > struct fb_deferred_io *fbdefio;
> > + void *deferred_io_private;
> > #endif
> >
> > struct fb_ops *fbops;
> > @@ -658,7 +659,7 @@ static inline void __fb_pad_aligned_buffer(u8 *dst, u32 d_pitch,
> >
> > /* drivers/video/fb_defio.c */
> > int fb_deferred_io_mmap(struct fb_info *info, struct vm_area_struct *vma);
> > -extern void fb_deferred_io_init(struct fb_info *info);
> > +extern int fb_deferred_io_init(struct fb_info *info);
> > extern void fb_deferred_io_open(struct fb_info *info,
> > struct inode *inode,
> > struct file *file);
> > --
> > 2.20.1
>
> --
> Ville Syrjälä
> Intel
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
next prev parent reply other threads:[~2019-11-27 18:09 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-27 16:31 [PATCH 00/13] video, drm: constify fbops in struct fb_info Jani Nikula
2019-11-27 16:31 ` [PATCH 01/13] video: fb_defio: preserve user fb_ops Jani Nikula
2019-11-27 17:01 ` Ville Syrjälä
2019-11-27 18:09 ` Daniel Vetter [this message]
2019-11-27 18:17 ` [Intel-gfx] " Daniel Vetter
2019-11-27 18:21 ` Daniel Vetter
2019-11-28 9:09 ` Jani Nikula
2019-11-28 10:05 ` Daniel Vetter
2019-11-28 10:08 ` Daniel Vetter
2019-11-28 10:34 ` Jani Nikula
2019-11-27 16:31 ` [PATCH 02/13] drm/fb-helper: don't preserve fb_ops across deferred IO use Jani Nikula
2019-11-27 18:18 ` [Intel-gfx] " Daniel Vetter
2019-11-28 11:31 ` Noralf Trønnes
2019-11-28 12:05 ` [Intel-gfx] " Jani Nikula
2019-11-28 14:03 ` Noralf Trønnes
2019-11-27 16:31 ` [PATCH 03/13] video: smscufx: don't restore fb_mmap after deferred IO cleanup Jani Nikula
2019-11-27 18:20 ` [Intel-gfx] " Daniel Vetter
2019-11-27 16:32 ` [PATCH 04/13] video: udlfb: " Jani Nikula
2019-11-27 18:22 ` Daniel Vetter
2019-11-27 16:32 ` [PATCH 05/13] video: fbdev: vesafb: modify the static fb_ops directly Jani Nikula
2019-11-27 18:23 ` Daniel Vetter
2019-11-27 16:32 ` [PATCH 06/13] video: fbmem: use const pointer for fb_ops Jani Nikula
2019-11-27 16:32 ` [PATCH 07/13] video: omapfb: " Jani Nikula
2019-11-27 16:32 ` [PATCH 08/13] video: fbdev: make fbops member of struct fb_info a const pointer Jani Nikula
2019-11-28 9:36 ` kbuild test robot
2019-11-28 10:46 ` kbuild test robot
2019-11-27 16:32 ` [PATCH 09/13] drm: constify fb ops across all drivers Jani Nikula
2019-11-27 16:32 ` [PATCH 10/13] video: " Jani Nikula
2019-11-27 16:32 ` [PATCH 11/13] HID: picoLCD: constify fb ops Jani Nikula
2019-11-27 16:32 ` [PATCH 12/13] media: constify fb ops across all drivers Jani Nikula
2019-11-27 16:32 ` [PATCH 13/13] samples: vfio-mdev: constify fb ops Jani Nikula
2019-11-27 18:29 ` Daniel Vetter
2019-11-28 9:22 ` Jani Nikula
2019-11-28 10:11 ` Daniel Vetter
2019-11-28 8:31 ` Christophe de Dinechin
2019-11-28 10:35 ` Jani Nikula
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=20191127180932.GE406127@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 \
--cc=ville.syrjala@linux.intel.com \
/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).