All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4: fix a bug in ext4_wait_for_tail_page_commit
@ 2019-09-17  8:48 yangerkun
  2019-09-17 15:31 ` Theodore Y. Ts'o
  2019-09-18 10:45 ` Jan Kara
  0 siblings, 2 replies; 8+ messages in thread
From: yangerkun @ 2019-09-17  8:48 UTC (permalink / raw)
  To: tytso, jack; +Cc: linux-ext4, yi.zhang, houtao1, yangerkun

No need to wait when offset equals to 0. And it will trigger a bug since
the latter __ext4_journalled_invalidatepage can free the buffers but leave
page still dirty.

[   26.057508] ------------[ cut here ]------------
[   26.058531] kernel BUG at fs/ext4/inode.c:2134!
...
[   26.088130] Call trace:
[   26.088695]  ext4_writepage+0x914/0xb28
[   26.089541]  writeout.isra.4+0x1b4/0x2b8
[   26.090409]  move_to_new_page+0x3b0/0x568
[   26.091338]  __unmap_and_move+0x648/0x988
[   26.092241]  unmap_and_move+0x48c/0xbb8
[   26.093096]  migrate_pages+0x220/0xb28
[   26.093945]  kernel_mbind+0x828/0xa18
[   26.094791]  __arm64_sys_mbind+0xc8/0x138
[   26.095716]  el0_svc_common+0x190/0x490
[   26.096571]  el0_svc_handler+0x60/0xd0
[   26.097423]  el0_svc+0x8/0xc

Run below parallel can reproduce it easily(ext3):
void main()
{
        int fd, fd1, fd2, fd3, ret;
        void *addr;
        size_t length = 4096;
        int flags;
        off_t offset = 0;
        char *str = "12345";

        fd = open("a", O_RDWR | O_CREAT);
        assert(fd >= 0);

        ret = ftruncate(fd, length);
        assert(ret == 0);

        fd1 = open("a", O_RDWR | O_CREAT, -1);
        assert(fd1 >= 0);

        flags = 0xc00f;/*Journal data mode*/
        ret = ioctl(fd1, _IOW('f', 2, long), &flags);
        assert(ret == 0);

        fd2 = open("a", O_RDWR | O_CREAT);
        assert(fd2 >= 0);

        fd3 = open("a", O_TRUNC | O_NOATIME);
        assert(fd3 >= 0);

        addr = mmap(NULL, length, 0xe, 0x28013, fd2, offset);
        assert(addr != (void *)-1);
        memcpy(addr, str, 5);
        mbind(addr, length, 0, 0, 0, 2);

        close(fd);
        munmap(addr, length);
}

Signed-off-by: yangerkun <yangerkun@huawei.com>
---
 fs/ext4/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 006b7a2070bf..a9943ae4f74d 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -5479,7 +5479,7 @@ static void ext4_wait_for_tail_page_commit(struct inode *inode)
 	 * do. We do the check mainly to optimize the common PAGE_SIZE ==
 	 * blocksize case
 	 */
-	if (offset > PAGE_SIZE - i_blocksize(inode))
+	if (!offset || offset > PAGE_SIZE - i_blocksize(inode))
 		return;
 	while (1) {
 		page = find_lock_page(inode->i_mapping,
-- 
2.17.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-09-19  1:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-17  8:48 [PATCH] ext4: fix a bug in ext4_wait_for_tail_page_commit yangerkun
2019-09-17 15:31 ` Theodore Y. Ts'o
2019-09-18  1:47   ` yangerkun
2019-09-18 10:06   ` Jan Kara
2019-09-18 10:45 ` Jan Kara
2019-09-18 13:09   ` yangerkun
2019-09-18 13:27     ` Jan Kara
2019-09-19  1:29       ` yangerkun

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.