Skip to content

Commit

Permalink
ubifs: Set page uptodate in the correct place
Browse files Browse the repository at this point in the history
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: 1e51764 ("UBIFS: add new flash file system")
Cc: stable@vger.kernel.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
  • Loading branch information
Matthew Wilcox (Oracle) authored and richardweinberger committed Feb 25, 2024
1 parent b401b62 commit 723012c
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions fs/ubifs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,6 @@ static int write_begin_slow(struct address_space *mapping,
return err;
}
}

SetPageUptodate(page);
ClearPageError(page);
}

if (PagePrivate(page))
Expand Down Expand Up @@ -463,9 +460,6 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping,
return err;
}
}

SetPageUptodate(page);
ClearPageError(page);
}

err = allocate_budget(c, page, ui, appending);
Expand All @@ -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
* write all of it, then it is not up to date.
*/
if (skipped_read) {
if (skipped_read)
ClearPageChecked(page);
ClearPageUptodate(page);
}
/*
* Budgeting failed which means it would have to force
* write-back but didn't, because we set the @fast flag in the
Expand Down Expand Up @@ -569,6 +561,9 @@ static int ubifs_write_end(struct file *file, struct address_space *mapping,
goto out;
}

if (len == PAGE_SIZE)
SetPageUptodate(page);

if (!PagePrivate(page)) {
attach_page_private(page, (void *)1);
atomic_long_inc(&c->dirty_pg_cnt);
Expand Down

0 comments on commit 723012c

Please sign in to comment.