From: hev <r@hev.cc>
To: Matthew Wilcox <willy@infradead.org>
Cc: linux-mm@kvack.org, Guoqi <chenguoqic@163.com>,
Huacai Chen <chenhuacai@loongson.cn>, Rui Wang <kernel@hev.cc>
Subject: Re: [RFC PATCH] mm/shmem: Fix undo range for failed fallocate
Date: Thu, 3 Nov 2022 15:52:43 +0800 [thread overview]
Message-ID: <CAHirt9h2CrLhYML3XW=Vj4=BD5eVDoRAbULVGgNbEdYnAzwCzA@mail.gmail.com> (raw)
In-Reply-To: <Y2KBovUHODJJ8ZnV@casper.infradead.org>
Hi Matthew,
On Wed, Nov 2, 2022 at 10:41 PM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Tue, Nov 01, 2022 at 11:22:48AM +0800, Rui Wang wrote:
> > This patch fixes data loss caused by the fallocate system
> > call interrupted by a signal.
> >
> > Bug: https://lore.kernel.org/linux-mm/33b85d82.7764.1842e9ab207.Coremail.chenguoqic@163.com/
> > Fixes: b9a8a4195c7d ("truncate,shmem: Handle truncates that split large folios")
>
> How does that commit introduce this bug?
In the test case[1], we created a file that contains non-zero data
from offset 0 to A-1. and a process try to expand this file by
fallocate(fd, 0, 0, B), B > A.
Concurrently, another process try to interrupt this fallocate syscall
by a signal. I think the expected results are:
1. The file is not expanded and file size is A, and the data from
offset 0 to A-1 is not changed.
2. The file is expanded and the data from offset 0 to A-1 is not
changed, and from A to B-1 contains zeros.
Now, the unexpected result is that the file is not expanded and the
data that from offset 0 to A-1 is changed by
truncate_inode_partial_folio that called
from shmem_undo_range with unfalloc = true.
This issue is only reproduced when file on tmpfs, and begin from this
commit: b9a8a4195c7d ("truncate,shmem: Handle truncates that split
large folios")
>
> > Reported-by: Guoqi Chen <chenguoqic@163.com>
> > Cc: Huacai Chen <chenhuacai@loongson.cn>
> > Signed-off-by: Rui Wang <kernel@hev.cc>
> > ---
> > mm/shmem.c | 20 ++++++++++++--------
> > 1 file changed, 12 insertions(+), 8 deletions(-)
> >
> > diff --git a/mm/shmem.c b/mm/shmem.c
> > index bc9b84602eec..8c8dce34eafc 100644
> > --- a/mm/shmem.c
> > +++ b/mm/shmem.c
> > @@ -948,11 +948,13 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,
> > folio = shmem_get_partial_folio(inode, lstart >> PAGE_SHIFT);
> > if (folio) {
> > same_folio = lend < folio_pos(folio) + folio_size(folio);
> > - folio_mark_dirty(folio);
> > - if (!truncate_inode_partial_folio(folio, lstart, lend)) {
> > - start = folio->index + folio_nr_pages(folio);
> > - if (same_folio)
> > - end = folio->index;
> > + if (!unfalloc || !folio_test_uptodate(folio)) {
> > + folio_mark_dirty(folio);
> > + if (!truncate_inode_partial_folio(folio, lstart, lend)) {
> > + start = folio->index + folio_nr_pages(folio);
> > + if (same_folio)
> > + end = folio->index;
> > + }
>
> ... so what you're saying is that if we allocate a page, but zeroing
> it is interrupted by a signal, we cannot now remove that page from
> the cache? That seems wrong.
>
> Surely the right solution is to remove this page from the cache if we're
> interrupted by a signal.
So I think we should not truncate_inode_partial_folio for unfalloc =
true. Isn't that right?
[1] https://github.com/abner-chenc/abner/blob/master/fallocate.c
Regards,
Ray
next prev parent reply other threads:[~2022-11-03 7:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-01 3:22 Rui Wang
2022-11-02 14:41 ` Matthew Wilcox
2022-11-03 7:52 ` hev [this message]
2022-11-19 14:45 ` hev
2022-11-19 20:20 ` Matthew Wilcox
2022-11-23 4:02 ` Hugh Dickins
2022-12-05 0:45 ` Hugh Dickins
2022-12-05 0:51 ` [PATCH] tmpfs: fix data loss from " Hugh Dickins
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='CAHirt9h2CrLhYML3XW=Vj4=BD5eVDoRAbULVGgNbEdYnAzwCzA@mail.gmail.com' \
--to=r@hev.cc \
--cc=chenguoqic@163.com \
--cc=chenhuacai@loongson.cn \
--cc=kernel@hev.cc \
--cc=linux-mm@kvack.org \
--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