From: Thomas Zimmermann <tzimmermann@suse.de>
To: daniel@ffwll.ch, airlied@linux.ie, mripard@kernel.org,
maarten.lankhorst@linux.intel.com, deller@gmx.de,
javierm@redhat.com
Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org,
Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH 4/9] fbdev: Export helper for implementing page_mkwrite
Date: Thu, 3 Mar 2022 21:58:34 +0100 [thread overview]
Message-ID: <20220303205839.28484-5-tzimmermann@suse.de> (raw)
In-Reply-To: <20220303205839.28484-1-tzimmermann@suse.de>
Refactor the page-write handler and export it as helper function
fb_deferred_io_page_mkwrite(). Drivers that implement struct
vm_operations_struct.page_mkwrite for deferred I/O should use the
function to let fbdev track written pages of mmap'ed framebuffer
memory.
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
drivers/video/fbdev/core/fb_defio.c | 69 ++++++++++++++++++++---------
include/linux/fb.h | 1 +
2 files changed, 50 insertions(+), 20 deletions(-)
diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
index 20c6eb94a685..8cd40b1714d4 100644
--- a/drivers/video/fbdev/core/fb_defio.c
+++ b/drivers/video/fbdev/core/fb_defio.c
@@ -143,29 +143,18 @@ int fb_deferred_io_fsync(struct file *file, loff_t start, loff_t end, int datasy
}
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. Requires caller to hold
+ * struct fb_deferred_io.lock. 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_pageref *pageref;
- unsigned long offset;
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 */
- mutex_lock(&fbdefio->lock);
-
/* first write in this cycle, notify the driver */
if (fbdefio->first_io && list_empty(&fbdefio->pagelist))
fbdefio->first_io(info);
@@ -186,8 +175,6 @@ static vm_fault_t fb_deferred_io_mkwrite(struct vm_fault *vmf)
*/
lock_page(pageref->page);
- mutex_unlock(&fbdefio->lock);
-
/* come back after delay to process the deferred IO */
schedule_delayed_work(&info->deferred_work, fbdefio->delay);
return VM_FAULT_LOCKED;
@@ -197,6 +184,48 @@ static vm_fault_t fb_deferred_io_mkwrite(struct vm_fault *vmf)
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.
+ */
+vm_fault_t fb_deferred_io_page_mkwrite(struct fb_info *info, struct vm_fault *vmf)
+{
+ struct page *page = vmf->page;
+ struct fb_deferred_io *fbdefio = info->fbdefio;
+ unsigned long offset;
+ vm_fault_t ret;
+
+ offset = (vmf->address - vmf->vma->vm_start);
+
+ file_update_time(vmf->vma->vm_file);
+
+ /* protect against the workqueue changing the page list */
+ mutex_lock(&fbdefio->lock);
+ ret = __fb_deferred_io_track_page(info, offset, page);
+ mutex_unlock(&fbdefio->lock);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(fb_deferred_io_page_mkwrite);
+
+/* 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 = {
.fault = fb_deferred_io_fault,
.page_mkwrite = fb_deferred_io_mkwrite,
diff --git a/include/linux/fb.h b/include/linux/fb.h
index 768de6534a82..631a1d0cb193 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -670,6 +670,7 @@ static inline void __fb_pad_aligned_buffer(u8 *dst, u32 d_pitch,
}
/* drivers/video/fb_defio.c */
+vm_fault_t fb_deferred_io_page_mkwrite(struct fb_info *info, struct vm_fault *vmf);
int fb_deferred_io_mmap(struct fb_info *info, struct vm_area_struct *vma);
extern int fb_deferred_io_init(struct fb_info *info);
extern void fb_deferred_io_open(struct fb_info *info,
--
2.35.1
next prev parent reply other threads:[~2022-03-03 20:58 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-03 20:58 [PATCH 0/9] drm: Support GEM SHMEM fbdev without shadow FB Thomas Zimmermann
2022-03-03 20:58 ` [PATCH 1/9] drm/simpledrm: Use fbdev defaults for shadow buffering Thomas Zimmermann
2022-03-08 9:31 ` Javier Martinez Canillas
2022-03-08 9:56 ` Thomas Zimmermann
2022-03-08 9:58 ` Javier Martinez Canillas
2022-03-03 20:58 ` [PATCH 2/9] fbdev: Put mmap for deferred I/O into drivers Thomas Zimmermann
2022-03-08 14:03 ` Javier Martinez Canillas
2022-03-03 20:58 ` [PATCH 3/9] fbdev: Track deferred-I/O pages in pageref struct Thomas Zimmermann
2022-03-08 14:42 ` Javier Martinez Canillas
2022-03-09 8:36 ` Thomas Zimmermann
2022-03-09 11:21 ` Javier Martinez Canillas
2022-03-03 20:58 ` Thomas Zimmermann [this message]
2022-03-08 17:21 ` [PATCH 4/9] fbdev: Export helper for implementing page_mkwrite Javier Martinez Canillas
2022-03-03 20:58 ` [PATCH 5/9] drm/fb-helper: Separate deferred I/O from shadow buffers Thomas Zimmermann
2022-03-08 17:24 ` Javier Martinez Canillas
2022-03-03 20:58 ` [PATCH 6/9] drm/fb-helper: Provide callback to create fbdev dumb buffers Thomas Zimmermann
2022-03-08 17:51 ` Javier Martinez Canillas
2022-03-09 8:42 ` Thomas Zimmermann
2022-03-15 19:11 ` Thomas Zimmermann
2022-03-03 20:58 ` [PATCH 7/9] drm/fb-helper: Provide fbdev deferred-I/O helpers Thomas Zimmermann
2022-03-08 18:56 ` Javier Martinez Canillas
2022-03-03 20:58 ` [PATCH 8/9] drm/gem-shmem: Implement fbdev dumb buffer and mmap helpers Thomas Zimmermann
2022-03-08 19:29 ` Javier Martinez Canillas
2022-03-09 8:47 ` Thomas Zimmermann
2022-03-09 11:25 ` Javier Martinez Canillas
2022-03-03 20:58 ` [PATCH 9/9] drm/virtio: Implement dumb_create_fbdev with GEM SHMEM helpers Thomas Zimmermann
2022-03-08 19:37 ` Javier Martinez Canillas
2022-03-09 8:52 ` Thomas Zimmermann
2022-03-09 11:29 ` Javier Martinez Canillas
2022-03-08 9:13 ` [PATCH 0/9] drm: Support GEM SHMEM fbdev without shadow FB Javier Martinez Canillas
2022-03-08 9:44 ` Thomas Zimmermann
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=20220303205839.28484-5-tzimmermann@suse.de \
--to=tzimmermann@suse.de \
--cc=airlied@linux.ie \
--cc=daniel@ffwll.ch \
--cc=deller@gmx.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=javierm@redhat.com \
--cc=linux-fbdev@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
/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).