fbdev: Refactor implementation of page_mkwrite

Refactor the page-write handler for deferred I/O. Drivers use the
function to let fbdev track written pages of mmap'ed framebuffer
memory.

v3:
	* keep locking within track-pages function for readability (Sam)
v2:
	* don't export the helper until we have an external caller

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220429100834.18898-4-tzimmermann@suse.de
This commit is contained in:
Thomas Zimmermann 2022-04-29 12:08:32 +02:00
Родитель 56c134f7f1
Коммит 3ed3811283
1 изменённых файлов: 38 добавлений и 15 удалений

Просмотреть файл

@ -143,26 +143,17 @@ int fb_deferred_io_fsync(struct file *file, loff_t start, loff_t end, int datasy
} }
EXPORT_SYMBOL_GPL(fb_deferred_io_fsync); EXPORT_SYMBOL_GPL(fb_deferred_io_fsync);
/* vm_ops->page_mkwrite handler */ /*
static vm_fault_t fb_deferred_io_mkwrite(struct vm_fault *vmf) * Adds a page to the dirty list. Call this from struct
* vm_operations_struct.page_mkwrite.
*/
static vm_fault_t fb_deferred_io_track_page(struct fb_info *info, unsigned long offset,
struct page *page)
{ {
struct page *page = vmf->page;
struct fb_info *info = vmf->vma->vm_private_data;
struct fb_deferred_io *fbdefio = info->fbdefio; struct fb_deferred_io *fbdefio = info->fbdefio;
struct fb_deferred_io_pageref *pageref; struct fb_deferred_io_pageref *pageref;
unsigned long offset;
vm_fault_t ret; vm_fault_t ret;
offset = (vmf->address - vmf->vma->vm_start);
/* this is a callback we get when userspace first tries to
write to the page. we schedule a workqueue. that workqueue
will eventually mkclean the touched pages and execute the
deferred framebuffer IO. then if userspace touches a page
again, we repeat the same scheme */
file_update_time(vmf->vma->vm_file);
/* protect against the workqueue changing the page list */ /* protect against the workqueue changing the page list */
mutex_lock(&fbdefio->lock); mutex_lock(&fbdefio->lock);
@ -197,6 +188,38 @@ err_mutex_unlock:
return ret; return ret;
} }
/*
* fb_deferred_io_page_mkwrite - Mark a page as written for deferred I/O
* @fb_info: The fbdev info structure
* @vmf: The VM fault
*
* This is a callback we get when userspace first tries to
* write to the page. We schedule a workqueue. That workqueue
* will eventually mkclean the touched pages and execute the
* deferred framebuffer IO. Then if userspace touches a page
* again, we repeat the same scheme.
*
* Returns:
* VM_FAULT_LOCKED on success, or a VM_FAULT error otherwise.
*/
static vm_fault_t fb_deferred_io_page_mkwrite(struct fb_info *info, struct vm_fault *vmf)
{
unsigned long offset = vmf->address - vmf->vma->vm_start;
struct page *page = vmf->page;
file_update_time(vmf->vma->vm_file);
return fb_deferred_io_track_page(info, offset, page);
}
/* vm_ops->page_mkwrite handler */
static vm_fault_t fb_deferred_io_mkwrite(struct vm_fault *vmf)
{
struct fb_info *info = vmf->vma->vm_private_data;
return fb_deferred_io_page_mkwrite(info, vmf);
}
static const struct vm_operations_struct fb_deferred_io_vm_ops = { static const struct vm_operations_struct fb_deferred_io_vm_ops = {
.fault = fb_deferred_io_fault, .fault = fb_deferred_io_fault,
.page_mkwrite = fb_deferred_io_mkwrite, .page_mkwrite = fb_deferred_io_mkwrite,