linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Theodore Ts'o <tytso@mit.edu>
Cc: "Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
	linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	Ojaswin Mujoo <ojaswin@linux.ibm.com>,
	Disha Goel <disgoel@linux.ibm.com>
Subject: Re: [RFCv2 2/5] ext4: Remove PAGE_SIZE assumption of folio from mpage_submit_folio
Date: Sun, 11 Jun 2023 15:15:54 +0100	[thread overview]
Message-ID: <ZIXXGhvfJEaKDIXC@casper.infradead.org> (raw)
In-Reply-To: <20230611055831.GF1436857@mit.edu>

On Sun, Jun 11, 2023 at 01:58:31AM -0400, Theodore Ts'o wrote:
> On Mon, May 15, 2023 at 04:10:41PM +0530, Ritesh Harjani (IBM) wrote:
> > mpage_submit_folio() was converted to take folio. Even though
> > folio_size() in ext4 as of now is PAGE_SIZE, but it's better to
> > remove that assumption which I am assuming is a missed left over from
> > patch[1].
> > 
> > [1]: https://lore.kernel.org/linux-ext4/20230324180129.1220691-7-willy@infradead.org/
> > 
> > Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
> 
> I didn't notice this right away, because the failure is not 100%
> reliable, but this commit will sometimes cause "kvm-xfstests -c
> ext4/encrypt generic/068" to crash.  Reverting the patch fixes the
> problem, so I plan to drop this patch from my tree.

Hrm.  Well, let's think about how this can go wrong:

@@ -1885,7 +1885,7 @@ static int mpage_submit_folio(struct mpage_da_data *mpd,
+struct folio *folio)
        len = folio_size(folio);
        if (folio_pos(folio) + len > size &&
            !ext4_verity_in_progress(mpd->inode))
-               len = size & ~PAGE_MASK;
+        	len = size - folio_pos(folio);
        err = ext4_bio_write_folio(&mpd->io_submit, folio, len);
        if (!err)
                mpd->wbc->nr_to_write--;

Just off-camera is:

        size = i_size_read(mpd->inode);

Now, nothing is preventing i_size to be truncated to far below this
folio, right?  So if that happened before this patch, we'd write some
randomly sized fragment of the page.  Now we'll get a negative result
... which is assigned to size_t, so is exabytes in size.

So do we care if we write a random fragment of a page after a truncate?
If so, we should add:

	if (folio_pos(folio) >= size)
		return 0; /* Do we need to account nr_to_write? */

If we simply don't care that we're doing a spurious write, then we can
do something like:

-		len = size & ~PAGE_MASK;
+		len = size & (len - 1);


  reply	other threads:[~2023-06-11 14:16 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-15 10:40 [RFCv2 0/5] ext4: misc left over folio changes Ritesh Harjani (IBM)
2023-05-15 10:40 ` [RFCv2 1/5] ext4: kill unused function ext4_journalled_write_inline_data Ritesh Harjani (IBM)
2023-05-15 10:40 ` [RFCv2 2/5] ext4: Remove PAGE_SIZE assumption of folio from mpage_submit_folio Ritesh Harjani (IBM)
2023-05-16 19:14   ` Matthew Wilcox
2023-06-11  5:58   ` Theodore Ts'o
2023-06-11 14:15     ` Matthew Wilcox [this message]
2023-06-11 14:25     ` Ritesh Harjani
2023-06-12 17:25       ` Ritesh Harjani
2023-06-12 17:43         ` Matthew Wilcox
2023-06-12 18:25           ` Ritesh Harjani
2023-06-12 19:16             ` Matthew Wilcox
2023-06-13  3:57               ` Ritesh Harjani
2023-06-13  9:59                 ` Jan Kara
2023-06-13 19:39                   ` Ritesh Harjani
2023-06-13 19:45                     ` Matthew Wilcox
2023-06-13 20:43                       ` Ritesh Harjani
2023-05-15 10:40 ` [RFCv2 3/5] ext4: Change remaining tracepoints to use folio Ritesh Harjani (IBM)
2023-05-15 10:40 ` [RFCv2 4/5] ext4: Make mpage_journal_page_buffers " Ritesh Harjani (IBM)
2023-05-16 19:16   ` Matthew Wilcox
2023-05-15 10:40 ` [RFCv2 5/5] ext4: Make ext4_write_inline_data_end() " Ritesh Harjani (IBM)
2023-05-16 19:27 ` [PATCH 6/5] ext4: Call fsverity_verify_folio() Matthew Wilcox (Oracle)
2023-05-17  6:45   ` Ritesh Harjani
2023-05-20  1:06   ` Eric Biggers
2023-06-09  3:14 ` [RFCv2 0/5] ext4: misc left over folio changes Theodore Ts'o

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=ZIXXGhvfJEaKDIXC@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=disgoel@linux.ibm.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=ojaswin@linux.ibm.com \
    --cc=ritesh.list@gmail.com \
    --cc=tytso@mit.edu \
    /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).