linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Sumitra Sharma <sumitraartsy@gmail.com>,
	Matthew Wilcox <willy@infradead.org>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Ira Weiny <ira.weiny@intel.com>, Fabio <fmdefrancesco@gmail.com>,
	Deepak R Varma <drv@mailo.com>
Subject: Re: [PATCH] fs/vboxsf: Replace kmap() with kmap_local_{page, folio}()
Date: Thu, 29 Jun 2023 12:01:53 +0200	[thread overview]
Message-ID: <3105fb11-b599-73c9-5a7b-895ef384a2e3@redhat.com> (raw)
In-Reply-To: <20230629092844.GA456505@sumitra.com>

Hi,

On 6/29/23 11:28, Sumitra Sharma wrote:
> On Wed, Jun 28, 2023 at 06:15:04PM +0100, Matthew Wilcox wrote:
>> Here's a more comprehensive read_folio patch.  It's not at all
>> efficient, but then if we wanted an efficient vboxsf, we'd implement
>> vboxsf_readahead() and actually do an async call with deferred setting
>> of the uptodate flag.  I can consult with anyone who wants to do all
>> this work.
>>
>> I haven't even compiled this, just trying to show the direction this
>> should take.
>>
>> diff --git a/fs/vboxsf/file.c b/fs/vboxsf/file.c
>> index 2307f8037efc..f1af9a7bd3d8 100644
>> --- a/fs/vboxsf/file.c
>> +++ b/fs/vboxsf/file.c
>> @@ -227,26 +227,31 @@ const struct inode_operations vboxsf_reg_iops = {
>>  
>>  static int vboxsf_read_folio(struct file *file, struct folio *folio)
>>  {
>> -	struct page *page = &folio->page;
>>  	struct vboxsf_handle *sf_handle = file->private_data;
>> -	loff_t off = page_offset(page);
>> -	u32 nread = PAGE_SIZE;
>> -	u8 *buf;
>> +	loff_t pos = folio_pos(folio);
>> +	size_t offset = 0;
>>  	int err;
>>  
>> -	buf = kmap(page);
>> +	do {
>> +		u8 *buf = kmap_local_folio(folio, offset);
>> +		u32 nread = PAGE_SIZE;
>>  
>> -	err = vboxsf_read(sf_handle->root, sf_handle->handle, off, &nread, buf);
>> -	if (err == 0) {
>> -		memset(&buf[nread], 0, PAGE_SIZE - nread);
>> -		flush_dcache_page(page);
>> -		SetPageUptodate(page);
>> -	} else {
>> -		SetPageError(page);
>> -	}
>> +		err = vboxsf_read(sf_handle->root, sf_handle->handle, pos,
>> +				&nread, buf);
>> +		if (nread < PAGE_SIZE)
>> +			memset(&buf[nread], 0, PAGE_SIZE - nread);
>> +		kunmap_local(buf);
>> +		if (err)
>> +			break;
>> +		offset += PAGE_SIZE;
>> +		pos += PAGE_SIZE;
>> +	} while (offset < folio_size(folio);
>>  
>> -	kunmap(page);
>> -	unlock_page(page);
>> +	if (!err) {
>> +		flush_dcache_folio(folio);
>> +		folio_mark_uptodate(folio);
>> +	}
>> +	folio_unlock(folio);
>>  	return err;
>>  }
>>
> 
> Hi 
> 
> So, after reading the comments, I understood that the problem presented 
> by Hans and Matthew is as follows:
> 
> 1) In the current code, the buffers used by vboxsf_write()/vboxsf_read() are 
> translated to PAGELIST-s before passing to the hypervisor, 
> but inefficiently— it first maps a page in vboxsf_read_folio() and then 
> calls page_to_phys(virt_to_page()) in the function hgcm_call_init_linaddr(). 
> 
> The inefficiency in the current implementation arises due to the unnecessary 
> mapping of a page in vboxsf_read_folio() because the mapping output, i.e. the 
> linear address, is used deep down in file 'drivers/virt/vboxguest/vboxguest_utils.c'. 
> Hence, the mapping must be done in this file; to do so, the folio must be passed 
> until this point. It can be done by adding a new member, 'struct folio *folio', 
> in the 'struct vmmdev_hgcm_function_parameter64'. 

struct vmmdev_hgcm_function_parameter64 is defined in

include/uapi/linux/vbox_vmmdev_types.h

This is part of the userspace API of vboxguest which allows userspace
to make (some) VirtualBox hypervisor request through a chardev.

You can not just go and change this struct.

Note there already is a VMMDEV_HGCM_PARM_TYPE_PAGELIST type. So you
could do the conversion from folio to pagelist (see the vboxguest code
for how to do this) in the vboxsf_read() code (making it take a folio
pointer as arg) and then directly pass the pagelist to the vbg_hgcm_call().

> The unused member 'phys_addr' in this struct can also be removed.

Again no you can NOT just go and make changes to an uapi header.

Regards,

Hans


  reply	other threads:[~2023-06-29 10:06 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-27 13:51 [PATCH] fs/vboxsf: Replace kmap() with kmap_local_{page, folio}() Sumitra Sharma
2023-06-27 14:34 ` Hans de Goede
2023-06-27 17:46   ` Matthew Wilcox
2023-06-27 18:10     ` Hans de Goede
2023-06-27 18:19       ` Hans de Goede
2023-06-27 17:48 ` Matthew Wilcox
2023-06-27 18:04   ` Hans de Goede
2023-06-29  4:30   ` Sumitra Sharma
2023-06-29  5:35     ` Hans de Goede
2023-06-28 17:15 ` Matthew Wilcox
2023-06-28 22:23   ` Fabio M. De Francesco
2023-06-28 22:40     ` Fabio M. De Francesco
2023-06-29  2:13       ` Ira Weiny
2023-06-29  3:16     ` Matthew Wilcox
2023-06-29 15:04       ` Fabio M. De Francesco
2023-06-29  2:23   ` Ira Weiny
2023-06-29  3:08     ` Matthew Wilcox
2023-06-29  9:28   ` Sumitra Sharma
2023-06-29 10:01     ` Hans de Goede [this message]
2023-06-29 14:42     ` Matthew Wilcox
2023-06-29 15:01       ` Hans de Goede

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=3105fb11-b599-73c9-5a7b-895ef384a2e3@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=drv@mailo.com \
    --cc=fmdefrancesco@gmail.com \
    --cc=ira.weiny@intel.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sumitraartsy@gmail.com \
    --cc=willy@infradead.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).