Skip to content

Commit 27917e8

Browse files
committed
erofs: address D-cache aliasing
Flush the D-cache before unlocking folios for compressed inodes, as they are dirtied during decompression. Avoid calling flush_dcache_folio() on every CPU write, since it's more like playing whack-a-mole without real benefit. It has no impact on x86 and arm64/risc-v: on x86, flush_dcache_folio() is a no-op, and on arm64/risc-v, PG_dcache_clean (PG_arch_1) is clear for new page cache folios. However, certain ARM boards are affected, as reported. Fixes: 3883a79 ("staging: erofs: introduce VLE decompression support") Closes: https://lore.kernel.org/r/[email protected] Closes: https://lore.kernel.org/r/[email protected] Tested-by: Jan Kiszka <[email protected]> Tested-by: Stefan Kerkmann <[email protected]> Signed-off-by: Gao Xiang <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f5443d0 commit 27917e8

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

fs/erofs/data.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,11 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)
214214

215215
/*
216216
* bit 30: I/O error occurred on this folio
217+
* bit 29: CPU has dirty data in D-cache (needs aliasing handling);
217218
* bit 0 - 29: remaining parts to complete this folio
218219
*/
219-
#define EROFS_ONLINEFOLIO_EIO (1 << 30)
220+
#define EROFS_ONLINEFOLIO_EIO 30
221+
#define EROFS_ONLINEFOLIO_DIRTY 29
220222

221223
void erofs_onlinefolio_init(struct folio *folio)
222224
{
@@ -233,19 +235,23 @@ void erofs_onlinefolio_split(struct folio *folio)
233235
atomic_inc((atomic_t *)&folio->private);
234236
}
235237

236-
void erofs_onlinefolio_end(struct folio *folio, int err)
238+
void erofs_onlinefolio_end(struct folio *folio, int err, bool dirty)
237239
{
238240
int orig, v;
239241

240242
do {
241243
orig = atomic_read((atomic_t *)&folio->private);
242-
v = (orig - 1) | (err ? EROFS_ONLINEFOLIO_EIO : 0);
244+
DBG_BUGON(orig <= 0);
245+
v = dirty << EROFS_ONLINEFOLIO_DIRTY;
246+
v |= (orig - 1) | (!!err << EROFS_ONLINEFOLIO_EIO);
243247
} while (atomic_cmpxchg((atomic_t *)&folio->private, orig, v) != orig);
244248

245-
if (v & ~EROFS_ONLINEFOLIO_EIO)
249+
if (v & (BIT(EROFS_ONLINEFOLIO_DIRTY) - 1))
246250
return;
247251
folio->private = 0;
248-
folio_end_read(folio, !(v & EROFS_ONLINEFOLIO_EIO));
252+
if (v & BIT(EROFS_ONLINEFOLIO_DIRTY))
253+
flush_dcache_folio(folio);
254+
folio_end_read(folio, !(v & BIT(EROFS_ONLINEFOLIO_EIO)));
249255
}
250256

251257
static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,

fs/erofs/decompressor.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,11 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
301301
cur = min(cur, rq->outputsize);
302302
if (cur && rq->out[0]) {
303303
kin = kmap_local_page(rq->in[nrpages_in - 1]);
304-
if (rq->out[0] == rq->in[nrpages_in - 1]) {
304+
if (rq->out[0] == rq->in[nrpages_in - 1])
305305
memmove(kin + rq->pageofs_out, kin + pi, cur);
306-
flush_dcache_page(rq->out[0]);
307-
} else {
306+
else
308307
memcpy_to_page(rq->out[0], rq->pageofs_out,
309308
kin + pi, cur);
310-
}
311309
kunmap_local(kin);
312310
}
313311
rq->outputsize -= cur;
@@ -325,14 +323,12 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
325323
po = (rq->pageofs_out + cur + pi) & ~PAGE_MASK;
326324
DBG_BUGON(no >= nrpages_out);
327325
cnt = min(insz - pi, PAGE_SIZE - po);
328-
if (rq->out[no] == rq->in[ni]) {
326+
if (rq->out[no] == rq->in[ni])
329327
memmove(kin + po,
330328
kin + rq->pageofs_in + pi, cnt);
331-
flush_dcache_page(rq->out[no]);
332-
} else if (rq->out[no]) {
329+
else if (rq->out[no])
333330
memcpy_to_page(rq->out[no], po,
334331
kin + rq->pageofs_in + pi, cnt);
335-
}
336332
pi += cnt;
337333
} while (pi < insz);
338334
kunmap_local(kin);

fs/erofs/fileio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static void erofs_fileio_ki_complete(struct kiocb *iocb, long ret)
3838
} else {
3939
bio_for_each_folio_all(fi, &rq->bio) {
4040
DBG_BUGON(folio_test_uptodate(fi.folio));
41-
erofs_onlinefolio_end(fi.folio, ret);
41+
erofs_onlinefolio_end(fi.folio, ret, false);
4242
}
4343
}
4444
bio_uninit(&rq->bio);
@@ -154,7 +154,7 @@ static int erofs_fileio_scan_folio(struct erofs_fileio *io, struct folio *folio)
154154
}
155155
cur += len;
156156
}
157-
erofs_onlinefolio_end(folio, err);
157+
erofs_onlinefolio_end(folio, err, false);
158158
return err;
159159
}
160160

fs/erofs/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
390390
int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map);
391391
void erofs_onlinefolio_init(struct folio *folio);
392392
void erofs_onlinefolio_split(struct folio *folio);
393-
void erofs_onlinefolio_end(struct folio *folio, int err);
393+
void erofs_onlinefolio_end(struct folio *folio, int err, bool dirty);
394394
struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid);
395395
int erofs_getattr(struct mnt_idmap *idmap, const struct path *path,
396396
struct kstat *stat, u32 request_mask,

fs/erofs/zdata.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ static int z_erofs_scan_folio(struct z_erofs_frontend *f,
10911091
tight = (bs == PAGE_SIZE);
10921092
}
10931093
} while ((end = cur) > 0);
1094-
erofs_onlinefolio_end(folio, err);
1094+
erofs_onlinefolio_end(folio, err, false);
10951095
return err;
10961096
}
10971097

@@ -1196,7 +1196,7 @@ static void z_erofs_fill_other_copies(struct z_erofs_backend *be, int err)
11961196
cur += len;
11971197
}
11981198
kunmap_local(dst);
1199-
erofs_onlinefolio_end(page_folio(bvi->bvec.page), err);
1199+
erofs_onlinefolio_end(page_folio(bvi->bvec.page), err, true);
12001200
list_del(p);
12011201
kfree(bvi);
12021202
}
@@ -1355,7 +1355,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs_backend *be, int err)
13551355

13561356
DBG_BUGON(z_erofs_page_is_invalidated(page));
13571357
if (!z_erofs_is_shortlived_page(page)) {
1358-
erofs_onlinefolio_end(page_folio(page), err);
1358+
erofs_onlinefolio_end(page_folio(page), err, true);
13591359
continue;
13601360
}
13611361
if (pcl->algorithmformat != Z_EROFS_COMPRESSION_LZ4) {

0 commit comments

Comments
 (0)