Skip to content

Commit

Permalink
fbdev: Fix incorrect page mapping clearance at fb_deferred_io_release()
Browse files Browse the repository at this point in the history
The recent fix for the deferred I/O by the commit
  3efc61d ("fbdev: Fix invalid page access after closing deferred I/O devices")
caused a regression when the same fb device is opened/closed while
it's being used.  It resulted in a frozen screen even if something
is redrawn there after the close.  The breakage is because the patch
was made under a wrong assumption of a single open; in the current
code, fb_deferred_io_release() cleans up the page mapping of the
pageref list and it calls cancel_delayed_work_sync() unconditionally,
where both are no correct behavior for multiple opens.

This patch adds a refcount for the opens of the device, and applies
the cleanup only when all files get closed.

Fixes: 3efc61d ("fbdev: Fix invalid page access after closing deferred I/O devices")
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
tiwai authored and intel-lab-lkp committed Mar 8, 2023
1 parent 63355b9 commit fe94468
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
16 changes: 13 additions & 3 deletions drivers/video/fbdev/core/fb_defio.c
Expand Up @@ -305,17 +305,19 @@ void fb_deferred_io_open(struct fb_info *info,
struct inode *inode,
struct file *file)
{
struct fb_deferred_io *fbdefio = info->fbdefio;

file->f_mapping->a_ops = &fb_deferred_io_aops;
fbdefio->opens++;
}
EXPORT_SYMBOL_GPL(fb_deferred_io_open);

void fb_deferred_io_release(struct fb_info *info)
static void fb_deferred_io_release_internal(struct fb_info *info)
{
struct fb_deferred_io *fbdefio = info->fbdefio;
struct page *page;
int i;

BUG_ON(!fbdefio);
cancel_delayed_work_sync(&info->deferred_work);

/* clear out the mapping that we setup */
Expand All @@ -324,13 +326,21 @@ void fb_deferred_io_release(struct fb_info *info)
page->mapping = NULL;
}
}

void fb_deferred_io_release(struct fb_info *info)
{
struct fb_deferred_io *fbdefio = info->fbdefio;

if (!--fbdefio->opens)
fb_deferred_io_release_internal(info);
}
EXPORT_SYMBOL_GPL(fb_deferred_io_release);

void fb_deferred_io_cleanup(struct fb_info *info)
{
struct fb_deferred_io *fbdefio = info->fbdefio;

fb_deferred_io_release(info);
fb_deferred_io_release_internal(info);

kvfree(info->pagerefs);
mutex_destroy(&fbdefio->lock);
Expand Down
1 change: 1 addition & 0 deletions include/linux/fb.h
Expand Up @@ -212,6 +212,7 @@ struct fb_deferred_io {
/* delay between mkwrite and deferred handler */
unsigned long delay;
bool sort_pagereflist; /* sort pagelist by offset */
int opens; /* number of opened files */
struct mutex lock; /* mutex that protects the pageref list */
struct list_head pagereflist; /* list of pagerefs for touched pages */
/* callback */
Expand Down

0 comments on commit fe94468

Please sign in to comment.