Commit 723012ca authored by Matthew Wilcox (Oracle)'s avatar Matthew Wilcox (Oracle) Committed by Richard Weinberger

ubifs: Set page uptodate in the correct place

Page cache reads are lockless, so setting the freshly allocated page
uptodate before we've overwritten it with the data it's supposed to have
in it will allow a simultaneous reader to see old data.  Move the call
to SetPageUptodate into ubifs_write_end(), which is after we copied the
new data into the page.

Fixes: 1e51764a ("UBIFS: add new flash file system")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
parent b401b621
...@@ -261,9 +261,6 @@ static int write_begin_slow(struct address_space *mapping, ...@@ -261,9 +261,6 @@ static int write_begin_slow(struct address_space *mapping,
return err; return err;
} }
} }
SetPageUptodate(page);
ClearPageError(page);
} }
if (PagePrivate(page)) if (PagePrivate(page))
...@@ -463,9 +460,6 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping, ...@@ -463,9 +460,6 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping,
return err; return err;
} }
} }
SetPageUptodate(page);
ClearPageError(page);
} }
err = allocate_budget(c, page, ui, appending); err = allocate_budget(c, page, ui, appending);
...@@ -475,10 +469,8 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping, ...@@ -475,10 +469,8 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping,
* If we skipped reading the page because we were going to * If we skipped reading the page because we were going to
* write all of it, then it is not up to date. * write all of it, then it is not up to date.
*/ */
if (skipped_read) { if (skipped_read)
ClearPageChecked(page); ClearPageChecked(page);
ClearPageUptodate(page);
}
/* /*
* Budgeting failed which means it would have to force * Budgeting failed which means it would have to force
* write-back but didn't, because we set the @fast flag in the * write-back but didn't, because we set the @fast flag in the
...@@ -569,6 +561,9 @@ static int ubifs_write_end(struct file *file, struct address_space *mapping, ...@@ -569,6 +561,9 @@ static int ubifs_write_end(struct file *file, struct address_space *mapping,
goto out; goto out;
} }
if (len == PAGE_SIZE)
SetPageUptodate(page);
if (!PagePrivate(page)) { if (!PagePrivate(page)) {
attach_page_private(page, (void *)1); attach_page_private(page, (void *)1);
atomic_long_inc(&c->dirty_pg_cnt); atomic_long_inc(&c->dirty_pg_cnt);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment