ceph-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Matthew Wilcox <willy@infradead.org>,
	David Howells <dhowells@redhat.com>
Cc: Andrew W Elble <aweits@rit.edu>,
	ceph-devel@vger.kernel.org, pfmeec@rit.edu,
	linux-cachefs@redhat.com
Subject: Re: [PATCH 5/5] ceph: fold ceph_update_writeable_page into ceph_write_begin
Date: Fri, 11 Jun 2021 11:38:39 -0400	[thread overview]
Message-ID: <d9fec91d22d985737ceefbc2b8f02c42dfed7df8.camel@kernel.org> (raw)
In-Reply-To: <YMN/PfW2t8e5M58m@casper.infradead.org>

On Fri, 2021-06-11 at 16:20 +0100, Matthew Wilcox wrote:
> On Fri, Jun 11, 2021 at 04:11:49PM +0100, David Howells wrote:
> > Jeff Layton <jlayton@kernel.org> wrote:
> > 
> > > On Fri, 2021-06-11 at 10:14 -0400, Andrew W Elble wrote:
> > > > We're seeing file corruption while running 5.10, bisected to 1cc1699070bd:
> > > > 
> > > > > > +static int ceph_write_begin(struct file *file, struct address_space *mapping,
> > > > > > +			    loff_t pos, unsigned len, unsigned flags,
> > > > > > +			    struct page **pagep, void **fsdata)
> > > > 
> > > > <snip>
> > > > 
> > > > > > +		/*
> > > > > > +		 * In some cases we don't need to read at all:
> > > > > > +		 * - full page write
> > > > > > +		 * - write that lies completely beyond EOF
> > > > > > +		 * - write that covers the the page from start to EOF or beyond it
> > > > > > +		 */
> > > > > > +		if ((pos_in_page == 0 && len == PAGE_SIZE) ||
> > > > > > +		    (pos >= i_size_read(inode)) ||
> > > > 
> > > > Shouldn't this be '((pos & PAGE_MASK) >= i_size_read(inode)) ||' ?
> > > > 
> > > > Seems like fs/netfs/read_helper.c currently has the same issue?
> 
> How does (pos & PAGE_MASK) >= i_size_read() make sense?  That could only
> be true if the file is less than a page in size, whereas it should
> always be true if the write starts outside the current i_size.
> 

Yeah, I guess what we really need is to round the i_size up to the start
of the next page and then compare whether pos is beyond that.

> > That's not quite right either.  page may be larger than PAGE_MASK if
> > grab_cache_page_write_begin() returns a THP (if that's possible).
> > 
> > Maybe:
> > 
> > 	(pos & thp_size(page) - 1) >= i_size_read(inode)
> > 
> > Really, we want something like thp_pos().  Maybe Willy has something like that
> > up his sleeve.
> > 
> > In fact, in netfs_write_begin(), index and pos_in_page should be calculated
> > after grab_cache_page_write_begin() has been called, just in case the new page
> > extends before the page containing the requested position.
> 
> Yes.  I do that kind of thing in iomap.  What you're doing there looks
> a bit like offset_in_folio(), but I don't understand the problem with
> just checking pos against i_size directly.
> 

Suppose the i_size is 3 and you do a 1 byte write at offset 5. You're
beyond the EOF, so the condition would return true, but you still need
to read in the start of the page in that case.

I think we probably need a testcase that does this in xfstests:

open file
write 3 bytes at start
close
unmount or drop pagecache in some way
then write 1 byte at offset 5
see whether the resulting contents match the expect ones

>
https://git.infradead.org/users/willy/pagecache.git/shortlog/refs/heads/folio
> contains a number of commits that start 'iomap:' which may be of interest.

-- 
Jeff Layton <jlayton@kernel.org>


  reply	other threads:[~2021-06-11 15:38 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-16 17:38 [PATCH 0/5] ceph: addr.c cleanups Jeff Layton
2020-09-16 17:38 ` [PATCH 1/5] ceph: break out writeback of incompatible snap context to separate function Jeff Layton
2020-09-16 17:38 ` [PATCH 2/5] ceph: don't call ceph_update_writeable_page from page_mkwrite Jeff Layton
2020-09-16 17:38 ` [PATCH 3/5] ceph: fold ceph_sync_readpages into ceph_readpage Jeff Layton
2020-09-16 17:38 ` [PATCH 4/5] ceph: fold ceph_sync_writepages into writepage_nounlock Jeff Layton
2020-09-16 17:38 ` [PATCH 5/5] ceph: fold ceph_update_writeable_page into ceph_write_begin Jeff Layton
2020-09-16 19:16   ` Jeff Layton
2021-06-11 14:14     ` Andrew W Elble
2021-06-11 14:52       ` Jeff Layton
2021-06-11 15:11       ` David Howells
2021-06-11 15:20         ` Matthew Wilcox
2021-06-11 15:38           ` Jeff Layton [this message]
2021-06-11 15:35         ` David Howells
2021-06-11 15:59           ` Andrew W Elble
2021-06-11 17:56           ` Matthew Wilcox
2021-06-11 21:47           ` David Howells

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=d9fec91d22d985737ceefbc2b8f02c42dfed7df8.camel@kernel.org \
    --to=jlayton@kernel.org \
    --cc=aweits@rit.edu \
    --cc=ceph-devel@vger.kernel.org \
    --cc=dhowells@redhat.com \
    --cc=linux-cachefs@redhat.com \
    --cc=pfmeec@rit.edu \
    --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).