From: Matthew Wilcox <willy@infradead.org>
To: Richard Weinberger <richard@nod.at>
Cc: linux-mtd <linux-mtd@lists.infradead.org>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH 4/4] ubifs: Convert do_writepage() to take a folio
Date: Tue, 6 Jun 2023 04:22:51 +0100 [thread overview]
Message-ID: <ZH6mixCMHce1S+vK@casper.infradead.org> (raw)
In-Reply-To: <2059298337.3685966.1686001020185.JavaMail.zimbra@nod.at>
On Mon, Jun 05, 2023 at 11:37:00PM +0200, Richard Weinberger wrote:
> > - addr = kmap(page);
> > - block = page->index << UBIFS_BLOCKS_PER_PAGE_SHIFT;
> > + addr = kmap_local_folio(folio, offset);
> > + block = folio->index << UBIFS_BLOCKS_PER_PAGE_SHIFT;
> > i = 0;
> > - while (len) {
> > - blen = min_t(int, len, UBIFS_BLOCK_SIZE);
> > + for (;;) {
>
> This change will cause a file system corruption.
> If len is zero (it can be) then a zero length data node will be written.
> The while(len) made sure that upon zero length nothing is written.
I don't see how 'len' can be 0. len is modified each time around the
loop, and if it's decremented to 0, we break. So you must be referring
to a case where the caller of do_writepage passes 0.
There are three callers of do_writepage, two in ubifs_writepage():
int err, len = folio_size(folio);
...
if (folio_pos(folio) + len < i_size) {
...
return do_writepage(folio, len);
len is folio_size(), which is not 0.
len = offset_in_folio(folio, i_size);
Here, we know that len is not 0. We already tested earlier:
if (folio_pos(folio) >= i_size) {
so we know that i_size > folio_pos() and i_size < folio_pos() +
folio_size(). Actually, I should make this more explicit:
len = i_size - folio_pos(folio);
Now it should be clear that len cannot be zero.
The third caller is do_truncation():
loff_t old_size = inode->i_size, new_size = attr->ia_size;
int offset = new_size & (UBIFS_BLOCK_SIZE - 1), budgeted = 1;
if (offset) {
pgoff_t index = new_size >> PAGE_SHIFT;
offset = offset_in_folio(folio,
new_size);
err = do_writepage(folio, offset);
It's not large-folio-safe, but it's definitely not 0.
Did I miss something?
next prev parent reply other threads:[~2023-06-06 3:22 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-05 16:50 [PATCH 0/4] ubifs: Convert writeback to use folios Matthew Wilcox (Oracle)
2023-06-05 16:50 ` [PATCH 1/4] ubifs: Convert from writepage to writepages Matthew Wilcox (Oracle)
2023-06-06 14:37 ` Zhihao Cheng
2023-06-07 14:11 ` Zhihao Cheng
2023-06-05 16:50 ` [PATCH 2/4] ubifs: Convert ubifs_writepage to use a folio Matthew Wilcox (Oracle)
2023-06-07 14:48 ` Zhihao Cheng
2023-06-05 16:50 ` [PATCH 3/4] ubifs: Use a folio in do_truncation() Matthew Wilcox (Oracle)
2023-06-05 17:05 ` Matthew Wilcox
2023-06-08 14:31 ` Zhihao Cheng
2023-06-05 16:50 ` [PATCH 4/4] ubifs: Convert do_writepage() to take a folio Matthew Wilcox (Oracle)
2023-06-05 19:28 ` kernel test robot
2023-06-05 21:37 ` Richard Weinberger
2023-06-06 3:22 ` Matthew Wilcox [this message]
2023-06-06 6:13 ` Richard Weinberger
2023-06-06 12:32 ` Matthew Wilcox
2023-06-06 13:41 ` Richard Weinberger
2023-06-05 23:29 ` kernel test robot
2023-06-08 15:09 ` Zhihao Cheng
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=ZH6mixCMHce1S+vK@casper.infradead.org \
--to=willy@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=richard@nod.at \
/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).