Patch "fbdev: Fix incorrect page mapping clearance at fb_deferred_io_release()" has been added to the 5.15-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    fbdev: Fix incorrect page mapping clearance at fb_deferred_io_release()

to the 5.15-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     fbdev-fix-incorrect-page-mapping-clearance-at-fb_def.patch
and it can be found in the queue-5.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit a67b59a0fe2dacc469e88dc08601e15ae362002a
Author: Takashi Iwai <tiwai@xxxxxxx>
Date:   Wed Mar 8 11:50:12 2023 +0100

    fbdev: Fix incorrect page mapping clearance at fb_deferred_io_release()
    
    [ Upstream commit fe9ae05cfbe587dda724fcf537c00bc2f287da62 ]
    
    The recent fix for the deferred I/O by the commit
      3efc61d95259 ("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.
    
    As both fb_deferred_io_open() and _close() are called always in the
    fb_info lock (mutex), it's safe to use the normal int for the
    refcounting.
    
    Also, a useless BUG_ON() is dropped.
    
    Fixes: 3efc61d95259 ("fbdev: Fix invalid page access after closing deferred I/O devices")
    Cc: <stable@xxxxxxxxxxxxxxx>
    Signed-off-by: Takashi Iwai <tiwai@xxxxxxx>
    Reviewed-by: Patrik Jakobsson <patrik.r.jakobsson@xxxxxxxxx>
    Signed-off-by: Thomas Zimmermann <tzimmermann@xxxxxxx>
    Link: https://patchwork.freedesktop.org/patch/msgid/20230308105012.1845-1-tiwai@xxxxxxx
    Stable-dep-of: 33cd6ea9c067 ("fbdev: flush deferred IO before closing")
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
index b3f41f432ec2..7e76e53b83d5 100644
--- a/drivers/video/fbdev/core/fb_defio.c
+++ b/drivers/video/fbdev/core/fb_defio.c
@@ -288,17 +288,18 @@ 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->open_count++;
 }
 EXPORT_SYMBOL_GPL(fb_deferred_io_open);
 
-void fb_deferred_io_release(struct fb_info *info)
+static void fb_deferred_io_lastclose(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 */
@@ -307,13 +308,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->open_count)
+		fb_deferred_io_lastclose(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_lastclose(info);
 
 	kvfree(info->pagerefs);
 	mutex_destroy(&fbdefio->lock);
diff --git a/include/linux/fb.h b/include/linux/fb.h
index 433cddf8442b..b79a833524ef 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -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 open_count; /* number of opened files; protected by fb_info lock */
 	struct mutex lock; /* mutex that protects the pageref list */
 	struct list_head pagereflist; /* list of pagerefs for touched pages */
 	/* callback */




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux