[PATCH 01/15] ubifs: Set page uptodate in the correct place

Zhihao Cheng chengzhihao1 at huawei.com
Sun Jan 21 23:22:45 PST 2024


在 2024/1/21 7:08, Matthew Wilcox (Oracle) 写道:
> 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: 1e51764a3c2a ("UBIFS: add new flash file system")
> Cc: stable at vger.kernel.org
> Signed-off-by: Matthew Wilcox (Oracle) <willy at infradead.org>
> ---
>   fs/ubifs/file.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
> index 5029eb3390a5..40a9b03ef821 100644
> --- a/fs/ubifs/file.c
> +++ b/fs/ubifs/file.c
> @@ -463,9 +463,6 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping,
>   				return err;
>   			}
>   		}
> -
> -		SetPageUptodate(page);
> -		ClearPageError(page);
>   	}

This solution looks good to me, and I think 'SetPageUptodate' should be 
removed from write_begin_slow(slow path) too.

>   
>   	err = allocate_budget(c, page, ui, appending);
> @@ -569,6 +566,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);
> 




More information about the linux-mtd mailing list