Skip to content

Commit

Permalink
squashfs: fix cache race with migration
Browse files Browse the repository at this point in the history
Migration replaces the page in the mapping before copying the contents and
the flags over from the old page, so check that the page in the page cache
is really up to date before using it.  Without this, stressing squashfs
reads with parallel compaction sometimes results in squashfs reporting
data corruption.

Link: https://lkml.kernel.org/r/[email protected]
Fixes: e994f5b ("squashfs: cache partial compressed blocks")
Signed-off-by: Vincent Whitchurch <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Phillip Lougher <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
vwax authored and akpm00 committed Jul 8, 2023
1 parent 191fcdb commit 08bab74
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions fs/squashfs/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,26 @@ static int squashfs_bio_read_cached(struct bio *fullbio,
return 0;
}

static struct page *squashfs_get_cache_page(struct address_space *mapping,
pgoff_t index)
{
struct page *page;

if (!mapping)
return NULL;

page = find_get_page(mapping, index);
if (!page)
return NULL;

if (!PageUptodate(page)) {
put_page(page);
return NULL;
}

return page;
}

static int squashfs_bio_read(struct super_block *sb, u64 index, int length,
struct bio **biop, int *block_offset)
{
Expand All @@ -190,11 +210,10 @@ static int squashfs_bio_read(struct super_block *sb, u64 index, int length,
for (i = 0; i < page_count; ++i) {
unsigned int len =
min_t(unsigned int, PAGE_SIZE - offset, total_len);
struct page *page = NULL;
pgoff_t index = (read_start >> PAGE_SHIFT) + i;
struct page *page;

if (cache_mapping)
page = find_get_page(cache_mapping,
(read_start >> PAGE_SHIFT) + i);
page = squashfs_get_cache_page(cache_mapping, index);
if (!page)
page = alloc_page(GFP_NOIO);

Expand Down

0 comments on commit 08bab74

Please sign in to comment.