From: Chao Yu <yuchao0@huawei.com>
To: <jaegeuk@kernel.org>
Cc: <linux-f2fs-devel@lists.sourceforge.net>,
<linux-kernel@vger.kernel.org>, <chao@kernel.org>,
Chao Yu <yuchao0@huawei.com>
Subject: [PATCH] f2fs: fix to keep isolation of atomic write
Date: Fri, 25 Dec 2020 16:53:04 +0800 [thread overview]
Message-ID: <20201225085304.114448-1-yuchao0@huawei.com> (raw)
ThreadA ThreadB
- f2fs_ioc_start_atomic_write
- write
- f2fs_ioc_commit_atomic_write
- f2fs_commit_inmem_pages
- f2fs_drop_inmem_pages
- f2fs_drop_inmem_pages
- __revoke_inmem_pages
- f2fs_vm_page_mkwrite
- set_page_dirty
- tag ATOMIC_WRITTEN_PAGE and add page
to inmem_pages list
- clear_inode_flag(FI_ATOMIC_FILE)
- f2fs_vm_page_mkwrite
- set_page_dirty
- f2fs_update_dirty_page
- f2fs_trace_pid
- tag inmem page private to pid
- truncate
- f2fs_invalidate_page
- set page->mapping to NULL
then it will cause panic once we
access page->mapping
The root cause is we missed to keep isolation of atomic write in the case
of commit_atomic_write vs mkwrite, let commit_atomic_write helds i_mmap_sem
lock to avoid this issue.
Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
fs/f2fs/file.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 22a0101538c0..1ff5fc10e1fa 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -2094,10 +2094,12 @@ static int f2fs_ioc_commit_atomic_write(struct file *filp)
goto err_out;
}
+ down_write(&F2FS_I(inode)->i_mmap_sem);
+
if (f2fs_is_atomic_file(inode)) {
ret = f2fs_commit_inmem_pages(inode);
if (ret)
- goto err_out;
+ goto up_write;
ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 0, true);
if (!ret)
@@ -2105,6 +2107,8 @@ static int f2fs_ioc_commit_atomic_write(struct file *filp)
} else {
ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 1, false);
}
+up_write:
+ up_write(&F2FS_I(inode)->i_mmap_sem);
err_out:
if (is_inode_flag_set(inode, FI_ATOMIC_REVOKE_REQUEST)) {
clear_inode_flag(inode, FI_ATOMIC_REVOKE_REQUEST);
--
2.29.2
reply other threads:[~2020-12-25 8:54 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20201225085304.114448-1-yuchao0@huawei.com \
--to=yuchao0@huawei.com \
--cc=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.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).