linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kirill Tkhai <ktkhai@virtuozzo.com>
To: miklos@szeredi.hu, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] fuse: Fix race in fuse_writepage_in_flight()
Date: Thu, 10 Jan 2019 13:48:42 +0300	[thread overview]
Message-ID: <00b1782a-5c5c-5bc8-7ea9-4f8450679fa1@virtuozzo.com> (raw)
In-Reply-To: <154322517208.18737.3297786654135648324.stgit@localhost.localdomain>

Hi, Miklos,

any comments about this?

On 26.11.2018 12:46, Kirill Tkhai wrote:
> Checking for FR_PENDING in fuse_writepage_in_flight() is racy.
> It does not guarantee the first request in misc.write.next list
> is not in userspace, since there we take fc->lock, while
> fuse_dev_do_read() takes fiq->waitq.lock:
> 
> fuse_dev_read()                           fuse_writepage_in_flight()
>                                             test_bit(FR_PENDING)
>   clear_bit(FR_PENDING)
> handle old_req->pages[0] in userspace
>                                             copy_highpage(old_req->pages[0], page)
>                                             ^^^^^
>                                             userspace never sees this pages
> 
> The only reliable way to determ, whether we are able to replace
> old_req's page, is to completely skip the first request in the list.
> This patch makes the function to do that.
> 
> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
> ---
>  fs/fuse/file.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/fuse/file.c b/fs/fuse/file.c
> index b52f9baaa3e7..c6650c68b31a 100644
> --- a/fs/fuse/file.c
> +++ b/fs/fuse/file.c
> @@ -1740,6 +1740,7 @@ static bool fuse_writepage_in_flight(struct fuse_req *new_req,
>  {
>  	struct fuse_conn *fc = get_fuse_conn(new_req->inode);
>  	struct fuse_inode *fi = get_fuse_inode(new_req->inode);
> +	struct fuse_req *first_req;
>  	struct fuse_req *tmp;
>  	struct fuse_req *old_req;
>  	bool found = false;
> @@ -1764,6 +1765,7 @@ static bool fuse_writepage_in_flight(struct fuse_req *new_req,
>  	}
>  
>  	new_req->num_pages = 1;
> +	first_req = old_req;
>  	for (tmp = old_req; tmp != NULL; tmp = tmp->misc.write.next) {
>  		BUG_ON(tmp->inode != new_req->inode);
>  		curr_index = tmp->misc.write.in.offset >> PAGE_SHIFT;
> @@ -1773,7 +1775,7 @@ static bool fuse_writepage_in_flight(struct fuse_req *new_req,
>  		}
>  	}
>  
> -	if (old_req->num_pages == 1 && test_bit(FR_PENDING, &old_req->flags)) {
> +	if (old_req->num_pages == 1 && old_req != first_req) {
>  		struct backing_dev_info *bdi = inode_to_bdi(page->mapping->host);
>  
>  		copy_highpage(old_req->pages[0], page);
> 

  parent reply	other threads:[~2019-01-10 10:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-26  9:46 [PATCH 1/2] fuse: Fix race in fuse_writepage_in_flight() Kirill Tkhai
2018-11-26  9:46 ` [PATCH 2/2] fuse: Replace page without copying " Kirill Tkhai
2019-01-15 15:39   ` Miklos Szeredi
2019-01-15 16:14     ` Kirill Tkhai
2019-01-15 16:36       ` Miklos Szeredi
2019-01-15 16:38         ` Kirill Tkhai
2019-01-10 10:48 ` Kirill Tkhai [this message]
2019-01-10 11:00   ` [PATCH 1/2] fuse: Fix race " Miklos Szeredi
2019-01-10 11:03     ` Kirill Tkhai
2019-01-15 15:37       ` Miklos Szeredi
2019-01-15 15:55         ` Kirill Tkhai
2019-01-15 16:03           ` Miklos Szeredi
2019-01-15 16:05             ` Kirill Tkhai

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=00b1782a-5c5c-5bc8-7ea9-4f8450679fa1@virtuozzo.com \
    --to=ktkhai@virtuozzo.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    /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).