All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: Sam Ravnborg <sam@ravnborg.org>
Cc: linux-fbdev@vger.kernel.org, airlied@linux.ie, deller@gmx.de,
	javierm@redhat.com, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 3/3] fbdev: Refactor implementation of page_mkwrite
Date: Tue, 26 Apr 2022 10:41:12 +0200	[thread overview]
Message-ID: <13cce5b6-0353-dad1-33d5-b089bdfd4b8c@suse.de> (raw)
In-Reply-To: <YmbncpwerOQLB1cS@ravnborg.org>


[-- Attachment #1.1: Type: text/plain, Size: 5100 bytes --]

Hi

Am 25.04.22 um 20:24 schrieb Sam Ravnborg:
> Hi Thomas.
> 
> On Mon, Apr 25, 2022 at 01:27:51PM +0200, Thomas Zimmermann wrote:
>> Refactor the page-write handler for deferred I/O. Drivers use the
>> function to let fbdev track written pages of mmap'ed framebuffer
>> memory.
> 
> I like how the comments got a brush up and a little more info was added.
> But I do not see the point of the refactoring - the code is equally
> readable before and after - maybe even easier before (modulus the
> improved comments).

FYI I'm going to move the locking into the track-page helper, which 
makes the code more readable.

Best regards
Thomas

> 
> But if you consider it better keep it. Again just my thoughts when
> reading the code.
> 
> 	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>
>> ---
>>   drivers/video/fbdev/core/fb_defio.c | 68 ++++++++++++++++++++---------
>>   1 file changed, 48 insertions(+), 20 deletions(-)
>>
>> diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
>> index a03b9c64fc61..214581ce5840 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,47 @@ 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.
>> + */
>> +static 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;
>> +}
>> +
>> +/* 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,
>> -- 
>> 2.36.0

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: Thomas Zimmermann <tzimmermann@suse.de>
To: Sam Ravnborg <sam@ravnborg.org>
Cc: javierm@redhat.com, daniel@ffwll.ch, deller@gmx.de,
	airlied@linux.ie, maarten.lankhorst@linux.intel.com,
	linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 3/3] fbdev: Refactor implementation of page_mkwrite
Date: Tue, 26 Apr 2022 10:41:12 +0200	[thread overview]
Message-ID: <13cce5b6-0353-dad1-33d5-b089bdfd4b8c@suse.de> (raw)
In-Reply-To: <YmbncpwerOQLB1cS@ravnborg.org>


[-- Attachment #1.1: Type: text/plain, Size: 5100 bytes --]

Hi

Am 25.04.22 um 20:24 schrieb Sam Ravnborg:
> Hi Thomas.
> 
> On Mon, Apr 25, 2022 at 01:27:51PM +0200, Thomas Zimmermann wrote:
>> Refactor the page-write handler for deferred I/O. Drivers use the
>> function to let fbdev track written pages of mmap'ed framebuffer
>> memory.
> 
> I like how the comments got a brush up and a little more info was added.
> But I do not see the point of the refactoring - the code is equally
> readable before and after - maybe even easier before (modulus the
> improved comments).

FYI I'm going to move the locking into the track-page helper, which 
makes the code more readable.

Best regards
Thomas

> 
> But if you consider it better keep it. Again just my thoughts when
> reading the code.
> 
> 	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>
>> ---
>>   drivers/video/fbdev/core/fb_defio.c | 68 ++++++++++++++++++++---------
>>   1 file changed, 48 insertions(+), 20 deletions(-)
>>
>> diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
>> index a03b9c64fc61..214581ce5840 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,47 @@ 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.
>> + */
>> +static 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;
>> +}
>> +
>> +/* 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,
>> -- 
>> 2.36.0

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

  parent reply	other threads:[~2022-04-26  8:41 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-25 11:27 [PATCH v2 0/3] fbdev: Decouple deferred I/O from struct page Thomas Zimmermann
2022-04-25 11:27 ` Thomas Zimmermann
2022-04-25 11:27 ` [PATCH v2 1/3] fbdev: Put mmap for deferred I/O into drivers Thomas Zimmermann
2022-04-25 11:27   ` Thomas Zimmermann
2022-04-25 15:53   ` kernel test robot
2022-04-25 15:53     ` kernel test robot
2022-04-25 17:26   ` Sam Ravnborg
2022-04-25 17:26     ` Sam Ravnborg
2022-04-25 17:46     ` Sam Ravnborg
2022-04-25 17:46       ` Sam Ravnborg
2022-04-26  7:39       ` Thomas Zimmermann
2022-04-25 11:27 ` [PATCH v2 2/3] fbdev: Track deferred-I/O pages in pageref struct Thomas Zimmermann
2022-04-25 11:27   ` Thomas Zimmermann
2022-04-25 18:17   ` Sam Ravnborg
2022-04-25 18:17     ` Sam Ravnborg
2022-04-26  8:01     ` Thomas Zimmermann
2022-04-26  8:01       ` Thomas Zimmermann
2022-04-26  9:24       ` Sam Ravnborg
2022-04-26  9:24         ` Sam Ravnborg
2022-04-25 11:27 ` [PATCH v2 3/3] fbdev: Refactor implementation of page_mkwrite Thomas Zimmermann
2022-04-25 11:27   ` Thomas Zimmermann
2022-04-25 18:24   ` Sam Ravnborg
2022-04-25 18:24     ` Sam Ravnborg
2022-04-26  8:10     ` Thomas Zimmermann
2022-04-26  8:10       ` Thomas Zimmermann
2022-04-26  8:41     ` Thomas Zimmermann [this message]
2022-04-26  8:41       ` 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=13cce5b6-0353-dad1-33d5-b089bdfd4b8c@suse.de \
    --to=tzimmermann@suse.de \
    --cc=airlied@linux.ie \
    --cc=deller@gmx.de \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=javierm@redhat.com \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=sam@ravnborg.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.