linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] fb_defio: Remove custom address_space_operations
@ 2021-03-10 18:55 Matthew Wilcox (Oracle)
  2021-03-11  0:46 ` William Kucharski
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Matthew Wilcox (Oracle) @ 2021-03-10 18:55 UTC (permalink / raw)
  To: dri-devel, linux-fbdev
  Cc: Matthew Wilcox (Oracle),
	linux-kernel, Daniel Vetter, Ian Campbell, Jaya Kumar,
	Jani Nikula, linux-mm, linux-fsdevel, Christoph Hellwig,
	William Kucharski

There's no need to give the page an address_space.  Leaving the
page->mapping as NULL will cause the VM to handle set_page_dirty()
the same way that it's handled now, and that was the only reason to
set the address_space in the first place.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
---
v2: Delete local variable definitions
 drivers/video/fbdev/core/fb_defio.c | 35 -----------------------------
 drivers/video/fbdev/core/fbmem.c    |  4 ----
 include/linux/fb.h                  |  3 ---
 3 files changed, 42 deletions(-)

diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
index a591d291b231..b292887a2481 100644
--- a/drivers/video/fbdev/core/fb_defio.c
+++ b/drivers/video/fbdev/core/fb_defio.c
@@ -52,13 +52,6 @@ static vm_fault_t fb_deferred_io_fault(struct vm_fault *vmf)
 		return VM_FAULT_SIGBUS;
 
 	get_page(page);
-
-	if (vmf->vma->vm_file)
-		page->mapping = vmf->vma->vm_file->f_mapping;
-	else
-		printk(KERN_ERR "no mapping available\n");
-
-	BUG_ON(!page->mapping);
 	page->index = vmf->pgoff;
 
 	vmf->page = page;
@@ -151,17 +144,6 @@ static const struct vm_operations_struct fb_deferred_io_vm_ops = {
 	.page_mkwrite	= fb_deferred_io_mkwrite,
 };
 
-static int fb_deferred_io_set_page_dirty(struct page *page)
-{
-	if (!PageDirty(page))
-		SetPageDirty(page);
-	return 0;
-}
-
-static const struct address_space_operations fb_deferred_io_aops = {
-	.set_page_dirty = fb_deferred_io_set_page_dirty,
-};
-
 int fb_deferred_io_mmap(struct fb_info *info, struct vm_area_struct *vma)
 {
 	vma->vm_ops = &fb_deferred_io_vm_ops;
@@ -212,29 +194,12 @@ void fb_deferred_io_init(struct fb_info *info)
 }
 EXPORT_SYMBOL_GPL(fb_deferred_io_init);
 
-void fb_deferred_io_open(struct fb_info *info,
-			 struct inode *inode,
-			 struct file *file)
-{
-	file->f_mapping->a_ops = &fb_deferred_io_aops;
-}
-EXPORT_SYMBOL_GPL(fb_deferred_io_open);
-
 void fb_deferred_io_cleanup(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 */
-	for (i = 0 ; i < info->fix.smem_len; i += PAGE_SIZE) {
-		page = fb_deferred_io_page(info, i);
-		page->mapping = 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 06f5805de2de..372b52a2befa 100644
--- a/drivers/video/fbdev/core/fbmem.c
+++ b/drivers/video/fbdev/core/fbmem.c
@@ -1415,10 +1415,6 @@ __releases(&info->lock)
 		if (res)
 			module_put(info->fbops->owner);
 	}
-#ifdef CONFIG_FB_DEFERRED_IO
-	if (info->fbdefio)
-		fb_deferred_io_open(info, inode, file);
-#endif
 out:
 	unlock_fb_info(info);
 	if (res)
diff --git a/include/linux/fb.h b/include/linux/fb.h
index ecfbcc0553a5..a8dccd23c249 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -659,9 +659,6 @@ 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 void fb_deferred_io_open(struct fb_info *info,
-				struct inode *inode,
-				struct file *file);
 extern void fb_deferred_io_cleanup(struct fb_info *info);
 extern int fb_deferred_io_fsync(struct file *file, loff_t start,
 				loff_t end, int datasync);
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] fb_defio: Remove custom address_space_operations
  2021-03-10 18:55 [PATCH v2] fb_defio: Remove custom address_space_operations Matthew Wilcox (Oracle)
@ 2021-03-11  0:46 ` William Kucharski
  2021-03-12 14:12 ` Daniel Vetter
       [not found] ` <YLPjwUUmHDRjyPpR@Ryzen-9-3900X.localdomain>
  2 siblings, 0 replies; 8+ messages in thread
From: William Kucharski @ 2021-03-11  0:46 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle)
  Cc: dri-devel, linux-fbdev, linux-kernel, Daniel Vetter,
	Ian Campbell, Jaya Kumar, Jani Nikula, linux-mm, linux-fsdevel,
	Christoph Hellwig

Looks good; my apologies for missing the leftover declaration of struct page in the same routine which you also found and removed this time around.

> On Mar 10, 2021, at 11:55 AM, Matthew Wilcox (Oracle) <willy@infradead.org> wrote:
> 
> There's no need to give the page an address_space.  Leaving the
> page->mapping as NULL will cause the VM to handle set_page_dirty()
> the same way that it's handled now, and that was the only reason to
> set the address_space in the first place.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Reviewed-by: William Kucharski <william.kucharski@oracle.com>
> ---
> v2: Delete local variable definitions
> drivers/video/fbdev/core/fb_defio.c | 35 -----------------------------
> drivers/video/fbdev/core/fbmem.c    |  4 ----
> include/linux/fb.h                  |  3 ---
> 3 files changed, 42 deletions(-)
> 
> diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
> index a591d291b231..b292887a2481 100644
> --- a/drivers/video/fbdev/core/fb_defio.c
> +++ b/drivers/video/fbdev/core/fb_defio.c
> @@ -52,13 +52,6 @@ static vm_fault_t fb_deferred_io_fault(struct vm_fault *vmf)
> 		return VM_FAULT_SIGBUS;
> 
> 	get_page(page);
> -
> -	if (vmf->vma->vm_file)
> -		page->mapping = vmf->vma->vm_file->f_mapping;
> -	else
> -		printk(KERN_ERR "no mapping available\n");
> -
> -	BUG_ON(!page->mapping);
> 	page->index = vmf->pgoff;
> 
> 	vmf->page = page;
> @@ -151,17 +144,6 @@ static const struct vm_operations_struct fb_deferred_io_vm_ops = {
> 	.page_mkwrite	= fb_deferred_io_mkwrite,
> };
> 
> -static int fb_deferred_io_set_page_dirty(struct page *page)
> -{
> -	if (!PageDirty(page))
> -		SetPageDirty(page);
> -	return 0;
> -}
> -
> -static const struct address_space_operations fb_deferred_io_aops = {
> -	.set_page_dirty = fb_deferred_io_set_page_dirty,
> -};
> -
> int fb_deferred_io_mmap(struct fb_info *info, struct vm_area_struct *vma)
> {
> 	vma->vm_ops = &fb_deferred_io_vm_ops;
> @@ -212,29 +194,12 @@ void fb_deferred_io_init(struct fb_info *info)
> }
> EXPORT_SYMBOL_GPL(fb_deferred_io_init);
> 
> -void fb_deferred_io_open(struct fb_info *info,
> -			 struct inode *inode,
> -			 struct file *file)
> -{
> -	file->f_mapping->a_ops = &fb_deferred_io_aops;
> -}
> -EXPORT_SYMBOL_GPL(fb_deferred_io_open);
> -
> void fb_deferred_io_cleanup(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 */
> -	for (i = 0 ; i < info->fix.smem_len; i += PAGE_SIZE) {
> -		page = fb_deferred_io_page(info, i);
> -		page->mapping = 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 06f5805de2de..372b52a2befa 100644
> --- a/drivers/video/fbdev/core/fbmem.c
> +++ b/drivers/video/fbdev/core/fbmem.c
> @@ -1415,10 +1415,6 @@ __releases(&info->lock)
> 		if (res)
> 			module_put(info->fbops->owner);
> 	}
> -#ifdef CONFIG_FB_DEFERRED_IO
> -	if (info->fbdefio)
> -		fb_deferred_io_open(info, inode, file);
> -#endif
> out:
> 	unlock_fb_info(info);
> 	if (res)
> diff --git a/include/linux/fb.h b/include/linux/fb.h
> index ecfbcc0553a5..a8dccd23c249 100644
> --- a/include/linux/fb.h
> +++ b/include/linux/fb.h
> @@ -659,9 +659,6 @@ 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 void fb_deferred_io_open(struct fb_info *info,
> -				struct inode *inode,
> -				struct file *file);
> extern void fb_deferred_io_cleanup(struct fb_info *info);
> extern int fb_deferred_io_fsync(struct file *file, loff_t start,
> 				loff_t end, int datasync);
> -- 
> 2.30.0
> 
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] fb_defio: Remove custom address_space_operations
  2021-03-10 18:55 [PATCH v2] fb_defio: Remove custom address_space_operations Matthew Wilcox (Oracle)
  2021-03-11  0:46 ` William Kucharski
@ 2021-03-12 14:12 ` Daniel Vetter
       [not found] ` <YLPjwUUmHDRjyPpR@Ryzen-9-3900X.localdomain>
  2 siblings, 0 replies; 8+ messages in thread
From: Daniel Vetter @ 2021-03-12 14:12 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle)
  Cc: dri-devel, linux-fbdev, William Kucharski, Jani Nikula,
	Daniel Vetter, linux-kernel, linux-mm, Ian Campbell,
	linux-fsdevel, Jaya Kumar, Christoph Hellwig

On Wed, Mar 10, 2021 at 06:55:30PM +0000, Matthew Wilcox (Oracle) wrote:
> There's no need to give the page an address_space.  Leaving the
> page->mapping as NULL will cause the VM to handle set_page_dirty()
> the same way that it's handled now, and that was the only reason to
> set the address_space in the first place.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Reviewed-by: William Kucharski <william.kucharski@oracle.com>

Thanks for your patch, merged to drm-misc-next for 5.13.

While I have an expert here, does this mean that for a VM_PFNMAP we could
pull of the same trick without any struct page backing, assuming we pulle
the per-page dirty state into some tracking of our own?

I'm asking since for DRM drivers we currently have a fairly awkward
situation with a bounce buffer in system memory going on that we copy out
of, because we can't directly use the gpu buffers. If we can track
directly in the gpu buffers, maybe even as some kind of overlay over the
vma, we could avoid that copy.

Otoh no one cares about fbcon performance, so *shrug*.

Cheers, Daniel

> ---
> v2: Delete local variable definitions
>  drivers/video/fbdev/core/fb_defio.c | 35 -----------------------------
>  drivers/video/fbdev/core/fbmem.c    |  4 ----
>  include/linux/fb.h                  |  3 ---
>  3 files changed, 42 deletions(-)
> 
> diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
> index a591d291b231..b292887a2481 100644
> --- a/drivers/video/fbdev/core/fb_defio.c
> +++ b/drivers/video/fbdev/core/fb_defio.c
> @@ -52,13 +52,6 @@ static vm_fault_t fb_deferred_io_fault(struct vm_fault *vmf)
>  		return VM_FAULT_SIGBUS;
>  
>  	get_page(page);
> -
> -	if (vmf->vma->vm_file)
> -		page->mapping = vmf->vma->vm_file->f_mapping;
> -	else
> -		printk(KERN_ERR "no mapping available\n");
> -
> -	BUG_ON(!page->mapping);
>  	page->index = vmf->pgoff;
>  
>  	vmf->page = page;
> @@ -151,17 +144,6 @@ static const struct vm_operations_struct fb_deferred_io_vm_ops = {
>  	.page_mkwrite	= fb_deferred_io_mkwrite,
>  };
>  
> -static int fb_deferred_io_set_page_dirty(struct page *page)
> -{
> -	if (!PageDirty(page))
> -		SetPageDirty(page);
> -	return 0;
> -}
> -
> -static const struct address_space_operations fb_deferred_io_aops = {
> -	.set_page_dirty = fb_deferred_io_set_page_dirty,
> -};
> -
>  int fb_deferred_io_mmap(struct fb_info *info, struct vm_area_struct *vma)
>  {
>  	vma->vm_ops = &fb_deferred_io_vm_ops;
> @@ -212,29 +194,12 @@ void fb_deferred_io_init(struct fb_info *info)
>  }
>  EXPORT_SYMBOL_GPL(fb_deferred_io_init);
>  
> -void fb_deferred_io_open(struct fb_info *info,
> -			 struct inode *inode,
> -			 struct file *file)
> -{
> -	file->f_mapping->a_ops = &fb_deferred_io_aops;
> -}
> -EXPORT_SYMBOL_GPL(fb_deferred_io_open);
> -
>  void fb_deferred_io_cleanup(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 */
> -	for (i = 0 ; i < info->fix.smem_len; i += PAGE_SIZE) {
> -		page = fb_deferred_io_page(info, i);
> -		page->mapping = 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 06f5805de2de..372b52a2befa 100644
> --- a/drivers/video/fbdev/core/fbmem.c
> +++ b/drivers/video/fbdev/core/fbmem.c
> @@ -1415,10 +1415,6 @@ __releases(&info->lock)
>  		if (res)
>  			module_put(info->fbops->owner);
>  	}
> -#ifdef CONFIG_FB_DEFERRED_IO
> -	if (info->fbdefio)
> -		fb_deferred_io_open(info, inode, file);
> -#endif
>  out:
>  	unlock_fb_info(info);
>  	if (res)
> diff --git a/include/linux/fb.h b/include/linux/fb.h
> index ecfbcc0553a5..a8dccd23c249 100644
> --- a/include/linux/fb.h
> +++ b/include/linux/fb.h
> @@ -659,9 +659,6 @@ 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 void fb_deferred_io_open(struct fb_info *info,
> -				struct inode *inode,
> -				struct file *file);
>  extern void fb_deferred_io_cleanup(struct fb_info *info);
>  extern int fb_deferred_io_fsync(struct file *file, loff_t start,
>  				loff_t end, int datasync);
> -- 
> 2.30.0
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] fb_defio: Remove custom address_space_operations
       [not found] ` <YLPjwUUmHDRjyPpR@Ryzen-9-3900X.localdomain>
@ 2021-05-30 21:14   ` Matthew Wilcox
  2021-05-30 22:40     ` Nathan Chancellor
  2021-06-01 14:10     ` Daniel Vetter
  0 siblings, 2 replies; 8+ messages in thread
From: Matthew Wilcox @ 2021-05-30 21:14 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: dri-devel, linux-fbdev, William Kucharski, Jani Nikula,
	Daniel Vetter, linux-kernel, linux-mm, Ian Campbell,
	linux-fsdevel, Jaya Kumar, Christoph Hellwig

On Sun, May 30, 2021 at 12:13:05PM -0700, Nathan Chancellor wrote:
> Hi Matthew,
> 
> On Wed, Mar 10, 2021 at 06:55:30PM +0000, Matthew Wilcox (Oracle) wrote:
> > There's no need to give the page an address_space.  Leaving the
> > page->mapping as NULL will cause the VM to handle set_page_dirty()
> > the same way that it's handled now, and that was the only reason to
> > set the address_space in the first place.
> > 
> > Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> > Reviewed-by: Christoph Hellwig <hch@lst.de>
> > Reviewed-by: William Kucharski <william.kucharski@oracle.com>
> 
> This patch in mainline as commit ccf953d8f3d6 ("fb_defio: Remove custom
> address_space_operations") causes my Hyper-V based VM to no longer make
> it to a graphical environment.

Hi Nathan,

Thanks for the report.  I sent Daniel a revert patch with a full
explanation last week, which I assume he'll queue up for a pull soon.
You can just git revert ccf953d8f3d6 for yourself until that shows up.
Sorry for the inconvenience.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] fb_defio: Remove custom address_space_operations
  2021-05-30 21:14   ` Matthew Wilcox
@ 2021-05-30 22:40     ` Nathan Chancellor
  2021-06-01 14:10     ` Daniel Vetter
  1 sibling, 0 replies; 8+ messages in thread
From: Nathan Chancellor @ 2021-05-30 22:40 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: dri-devel, linux-fbdev, William Kucharski, Jani Nikula,
	Daniel Vetter, linux-kernel, linux-mm, Ian Campbell,
	linux-fsdevel, Jaya Kumar, Christoph Hellwig

On 5/30/2021 2:14 PM, Matthew Wilcox wrote:
> On Sun, May 30, 2021 at 12:13:05PM -0700, Nathan Chancellor wrote:
>> Hi Matthew,
>>
>> On Wed, Mar 10, 2021 at 06:55:30PM +0000, Matthew Wilcox (Oracle) wrote:
>>> There's no need to give the page an address_space.  Leaving the
>>> page->mapping as NULL will cause the VM to handle set_page_dirty()
>>> the same way that it's handled now, and that was the only reason to
>>> set the address_space in the first place.
>>>
>>> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
>>> Reviewed-by: Christoph Hellwig <hch@lst.de>
>>> Reviewed-by: William Kucharski <william.kucharski@oracle.com>
>>
>> This patch in mainline as commit ccf953d8f3d6 ("fb_defio: Remove custom
>> address_space_operations") causes my Hyper-V based VM to no longer make
>> it to a graphical environment.
> 
> Hi Nathan,
> 
> Thanks for the report.  I sent Daniel a revert patch with a full
> explanation last week, which I assume he'll queue up for a pull soon.
> You can just git revert ccf953d8f3d6 for yourself until that shows up.
> Sorry for the inconvenience.
> 

Thank you for the quick response! I will keep an eye out for the patch 
while reverting it locally in the meantime.

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] fb_defio: Remove custom address_space_operations
  2021-05-30 21:14   ` Matthew Wilcox
  2021-05-30 22:40     ` Nathan Chancellor
@ 2021-06-01 14:10     ` Daniel Vetter
  2021-06-01 14:30       ` Matthew Wilcox
  1 sibling, 1 reply; 8+ messages in thread
From: Daniel Vetter @ 2021-06-01 14:10 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Nathan Chancellor, linux-fbdev, linux-mm, Jani Nikula,
	Daniel Vetter, linux-kernel, dri-devel, William Kucharski,
	Ian Campbell, linux-fsdevel, Jaya Kumar, Christoph Hellwig

On Sun, May 30, 2021 at 10:14:22PM +0100, Matthew Wilcox wrote:
> On Sun, May 30, 2021 at 12:13:05PM -0700, Nathan Chancellor wrote:
> > Hi Matthew,
> > 
> > On Wed, Mar 10, 2021 at 06:55:30PM +0000, Matthew Wilcox (Oracle) wrote:
> > > There's no need to give the page an address_space.  Leaving the
> > > page->mapping as NULL will cause the VM to handle set_page_dirty()
> > > the same way that it's handled now, and that was the only reason to
> > > set the address_space in the first place.
> > > 
> > > Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> > > Reviewed-by: Christoph Hellwig <hch@lst.de>
> > > Reviewed-by: William Kucharski <william.kucharski@oracle.com>
> > 
> > This patch in mainline as commit ccf953d8f3d6 ("fb_defio: Remove custom
> > address_space_operations") causes my Hyper-V based VM to no longer make
> > it to a graphical environment.
> 
> Hi Nathan,
> 
> Thanks for the report.  I sent Daniel a revert patch with a full
> explanation last week, which I assume he'll queue up for a pull soon.
> You can just git revert ccf953d8f3d6 for yourself until that shows up.
> Sorry for the inconvenience.

Uh that patch didn't get cc'ed to any list so I've ignored it. I've found
it now, but lack of lore link is awkward. Can you pls resubmit with
dri-devel on cc? fbdev list is dead, I don't look there.

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] fb_defio: Remove custom address_space_operations
  2021-06-01 14:10     ` Daniel Vetter
@ 2021-06-01 14:30       ` Matthew Wilcox
  2021-06-01 15:39         ` Daniel Vetter
  0 siblings, 1 reply; 8+ messages in thread
From: Matthew Wilcox @ 2021-06-01 14:30 UTC (permalink / raw)
  To: Nathan Chancellor, linux-fbdev, linux-mm, Jani Nikula,
	linux-kernel, dri-devel, William Kucharski, Ian Campbell,
	linux-fsdevel, Jaya Kumar, Christoph Hellwig

[-- Attachment #1: Type: text/plain, Size: 1495 bytes --]

On Tue, Jun 01, 2021 at 04:10:32PM +0200, Daniel Vetter wrote:
> On Sun, May 30, 2021 at 10:14:22PM +0100, Matthew Wilcox wrote:
> > On Sun, May 30, 2021 at 12:13:05PM -0700, Nathan Chancellor wrote:
> > > Hi Matthew,
> > > 
> > > On Wed, Mar 10, 2021 at 06:55:30PM +0000, Matthew Wilcox (Oracle) wrote:
> > > > There's no need to give the page an address_space.  Leaving the
> > > > page->mapping as NULL will cause the VM to handle set_page_dirty()
> > > > the same way that it's handled now, and that was the only reason to
> > > > set the address_space in the first place.
> > > > 
> > > > Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> > > > Reviewed-by: Christoph Hellwig <hch@lst.de>
> > > > Reviewed-by: William Kucharski <william.kucharski@oracle.com>
> > > 
> > > This patch in mainline as commit ccf953d8f3d6 ("fb_defio: Remove custom
> > > address_space_operations") causes my Hyper-V based VM to no longer make
> > > it to a graphical environment.
> > 
> > Hi Nathan,
> > 
> > Thanks for the report.  I sent Daniel a revert patch with a full
> > explanation last week, which I assume he'll queue up for a pull soon.
> > You can just git revert ccf953d8f3d6 for yourself until that shows up.
> > Sorry for the inconvenience.
> 
> Uh that patch didn't get cc'ed to any list so I've ignored it. I've found
> it now, but lack of lore link is awkward. Can you pls resubmit with
> dri-devel on cc? fbdev list is dead, I don't look there.

How about I just attach it here?

[-- Attachment #2: 0001-Revert-fb_defio-Remove-custom-address_space_operatio.patch --]
[-- Type: text/plain, Size: 3792 bytes --]

From e88921d0775d87323a8688af37dfd7cdebdde5a9 Mon Sep 17 00:00:00 2001
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Date: Tue, 25 May 2021 08:37:33 -0400
Subject: [PATCH] Revert "fb_defio: Remove custom address_space_operations"

Commit ccf953d8f3d6 makes framebuffers which use deferred I/O stop
displaying updates after the first one.  This is because the pages
handled by fb_defio no longer have a page_mapping().  That prevents
page_mkclean() from marking the PTEs as clean, and so writes are only
noticed the first time.

Reported-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 drivers/video/fbdev/core/fb_defio.c | 35 +++++++++++++++++++++++++++++
 drivers/video/fbdev/core/fbmem.c    |  4 ++++
 include/linux/fb.h                  |  3 +++
 3 files changed, 42 insertions(+)

diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
index b292887a2481..a591d291b231 100644
--- a/drivers/video/fbdev/core/fb_defio.c
+++ b/drivers/video/fbdev/core/fb_defio.c
@@ -52,6 +52,13 @@ static vm_fault_t fb_deferred_io_fault(struct vm_fault *vmf)
 		return VM_FAULT_SIGBUS;
 
 	get_page(page);
+
+	if (vmf->vma->vm_file)
+		page->mapping = vmf->vma->vm_file->f_mapping;
+	else
+		printk(KERN_ERR "no mapping available\n");
+
+	BUG_ON(!page->mapping);
 	page->index = vmf->pgoff;
 
 	vmf->page = page;
@@ -144,6 +151,17 @@ static const struct vm_operations_struct fb_deferred_io_vm_ops = {
 	.page_mkwrite	= fb_deferred_io_mkwrite,
 };
 
+static int fb_deferred_io_set_page_dirty(struct page *page)
+{
+	if (!PageDirty(page))
+		SetPageDirty(page);
+	return 0;
+}
+
+static const struct address_space_operations fb_deferred_io_aops = {
+	.set_page_dirty = fb_deferred_io_set_page_dirty,
+};
+
 int fb_deferred_io_mmap(struct fb_info *info, struct vm_area_struct *vma)
 {
 	vma->vm_ops = &fb_deferred_io_vm_ops;
@@ -194,12 +212,29 @@ void fb_deferred_io_init(struct fb_info *info)
 }
 EXPORT_SYMBOL_GPL(fb_deferred_io_init);
 
+void fb_deferred_io_open(struct fb_info *info,
+			 struct inode *inode,
+			 struct file *file)
+{
+	file->f_mapping->a_ops = &fb_deferred_io_aops;
+}
+EXPORT_SYMBOL_GPL(fb_deferred_io_open);
+
 void fb_deferred_io_cleanup(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 */
+	for (i = 0 ; i < info->fix.smem_len; i += PAGE_SIZE) {
+		page = fb_deferred_io_page(info, i);
+		page->mapping = 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 072780b0e570..98f193078c05 100644
--- a/drivers/video/fbdev/core/fbmem.c
+++ b/drivers/video/fbdev/core/fbmem.c
@@ -1415,6 +1415,10 @@ __releases(&info->lock)
 		if (res)
 			module_put(info->fbops->owner);
 	}
+#ifdef CONFIG_FB_DEFERRED_IO
+	if (info->fbdefio)
+		fb_deferred_io_open(info, inode, file);
+#endif
 out:
 	unlock_fb_info(info);
 	if (res)
diff --git a/include/linux/fb.h b/include/linux/fb.h
index a8dccd23c249..ecfbcc0553a5 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -659,6 +659,9 @@ 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 void fb_deferred_io_open(struct fb_info *info,
+				struct inode *inode,
+				struct file *file);
 extern void fb_deferred_io_cleanup(struct fb_info *info);
 extern int fb_deferred_io_fsync(struct file *file, loff_t start,
 				loff_t end, int datasync);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] fb_defio: Remove custom address_space_operations
  2021-06-01 14:30       ` Matthew Wilcox
@ 2021-06-01 15:39         ` Daniel Vetter
  0 siblings, 0 replies; 8+ messages in thread
From: Daniel Vetter @ 2021-06-01 15:39 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Nathan Chancellor, linux-fbdev, linux-mm, Jani Nikula,
	linux-kernel, dri-devel, William Kucharski, Ian Campbell,
	linux-fsdevel, Jaya Kumar, Christoph Hellwig

On Tue, Jun 01, 2021 at 03:30:30PM +0100, Matthew Wilcox wrote:
> On Tue, Jun 01, 2021 at 04:10:32PM +0200, Daniel Vetter wrote:
> > On Sun, May 30, 2021 at 10:14:22PM +0100, Matthew Wilcox wrote:
> > > On Sun, May 30, 2021 at 12:13:05PM -0700, Nathan Chancellor wrote:
> > > > Hi Matthew,
> > > > 
> > > > On Wed, Mar 10, 2021 at 06:55:30PM +0000, Matthew Wilcox (Oracle) wrote:
> > > > > There's no need to give the page an address_space.  Leaving the
> > > > > page->mapping as NULL will cause the VM to handle set_page_dirty()
> > > > > the same way that it's handled now, and that was the only reason to
> > > > > set the address_space in the first place.
> > > > > 
> > > > > Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> > > > > Reviewed-by: Christoph Hellwig <hch@lst.de>
> > > > > Reviewed-by: William Kucharski <william.kucharski@oracle.com>
> > > > 
> > > > This patch in mainline as commit ccf953d8f3d6 ("fb_defio: Remove custom
> > > > address_space_operations") causes my Hyper-V based VM to no longer make
> > > > it to a graphical environment.
> > > 
> > > Hi Nathan,
> > > 
> > > Thanks for the report.  I sent Daniel a revert patch with a full
> > > explanation last week, which I assume he'll queue up for a pull soon.
> > > You can just git revert ccf953d8f3d6 for yourself until that shows up.
> > > Sorry for the inconvenience.
> > 
> > Uh that patch didn't get cc'ed to any list so I've ignored it. I've found
> > it now, but lack of lore link is awkward. Can you pls resubmit with
> > dri-devel on cc? fbdev list is dead, I don't look there.
> 
> How about I just attach it here?

Thanks, that worked with Link: and everything and no choking of my script
:-)

Cheers, Daniel

> From e88921d0775d87323a8688af37dfd7cdebdde5a9 Mon Sep 17 00:00:00 2001
> From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
> Date: Tue, 25 May 2021 08:37:33 -0400
> Subject: [PATCH] Revert "fb_defio: Remove custom address_space_operations"
> 
> Commit ccf953d8f3d6 makes framebuffers which use deferred I/O stop
> displaying updates after the first one.  This is because the pages
> handled by fb_defio no longer have a page_mapping().  That prevents
> page_mkclean() from marking the PTEs as clean, and so writes are only
> noticed the first time.
> 
> Reported-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
>  drivers/video/fbdev/core/fb_defio.c | 35 +++++++++++++++++++++++++++++
>  drivers/video/fbdev/core/fbmem.c    |  4 ++++
>  include/linux/fb.h                  |  3 +++
>  3 files changed, 42 insertions(+)
> 
> diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
> index b292887a2481..a591d291b231 100644
> --- a/drivers/video/fbdev/core/fb_defio.c
> +++ b/drivers/video/fbdev/core/fb_defio.c
> @@ -52,6 +52,13 @@ static vm_fault_t fb_deferred_io_fault(struct vm_fault *vmf)
>  		return VM_FAULT_SIGBUS;
>  
>  	get_page(page);
> +
> +	if (vmf->vma->vm_file)
> +		page->mapping = vmf->vma->vm_file->f_mapping;
> +	else
> +		printk(KERN_ERR "no mapping available\n");
> +
> +	BUG_ON(!page->mapping);
>  	page->index = vmf->pgoff;
>  
>  	vmf->page = page;
> @@ -144,6 +151,17 @@ static const struct vm_operations_struct fb_deferred_io_vm_ops = {
>  	.page_mkwrite	= fb_deferred_io_mkwrite,
>  };
>  
> +static int fb_deferred_io_set_page_dirty(struct page *page)
> +{
> +	if (!PageDirty(page))
> +		SetPageDirty(page);
> +	return 0;
> +}
> +
> +static const struct address_space_operations fb_deferred_io_aops = {
> +	.set_page_dirty = fb_deferred_io_set_page_dirty,
> +};
> +
>  int fb_deferred_io_mmap(struct fb_info *info, struct vm_area_struct *vma)
>  {
>  	vma->vm_ops = &fb_deferred_io_vm_ops;
> @@ -194,12 +212,29 @@ void fb_deferred_io_init(struct fb_info *info)
>  }
>  EXPORT_SYMBOL_GPL(fb_deferred_io_init);
>  
> +void fb_deferred_io_open(struct fb_info *info,
> +			 struct inode *inode,
> +			 struct file *file)
> +{
> +	file->f_mapping->a_ops = &fb_deferred_io_aops;
> +}
> +EXPORT_SYMBOL_GPL(fb_deferred_io_open);
> +
>  void fb_deferred_io_cleanup(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 */
> +	for (i = 0 ; i < info->fix.smem_len; i += PAGE_SIZE) {
> +		page = fb_deferred_io_page(info, i);
> +		page->mapping = 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 072780b0e570..98f193078c05 100644
> --- a/drivers/video/fbdev/core/fbmem.c
> +++ b/drivers/video/fbdev/core/fbmem.c
> @@ -1415,6 +1415,10 @@ __releases(&info->lock)
>  		if (res)
>  			module_put(info->fbops->owner);
>  	}
> +#ifdef CONFIG_FB_DEFERRED_IO
> +	if (info->fbdefio)
> +		fb_deferred_io_open(info, inode, file);
> +#endif
>  out:
>  	unlock_fb_info(info);
>  	if (res)
> diff --git a/include/linux/fb.h b/include/linux/fb.h
> index a8dccd23c249..ecfbcc0553a5 100644
> --- a/include/linux/fb.h
> +++ b/include/linux/fb.h
> @@ -659,6 +659,9 @@ 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 void fb_deferred_io_open(struct fb_info *info,
> +				struct inode *inode,
> +				struct file *file);
>  extern void fb_deferred_io_cleanup(struct fb_info *info);
>  extern int fb_deferred_io_fsync(struct file *file, loff_t start,
>  				loff_t end, int datasync);
> -- 
> 2.30.2
> 


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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-06-01 15:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-10 18:55 [PATCH v2] fb_defio: Remove custom address_space_operations Matthew Wilcox (Oracle)
2021-03-11  0:46 ` William Kucharski
2021-03-12 14:12 ` Daniel Vetter
     [not found] ` <YLPjwUUmHDRjyPpR@Ryzen-9-3900X.localdomain>
2021-05-30 21:14   ` Matthew Wilcox
2021-05-30 22:40     ` Nathan Chancellor
2021-06-01 14:10     ` Daniel Vetter
2021-06-01 14:30       ` Matthew Wilcox
2021-06-01 15:39         ` Daniel Vetter

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).