Skip to content

Commit 4b810bf

Browse files
committed
Merge tag 'erofs-for-6.5-rc2-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs
Pull erofs fixes from Gao Xiang: "Three patches address regressions related to post-EOF unexpected behaviors and fsdax unavailability of chunk-based regular files. The other two patches mainly get rid of kmap_atomic() and simplify z_erofs_transform_plain(). - Fix two unexpected loop cases when reading beyond EOF - Fix fsdax unavailability for chunk-based regular files - Get rid of the remaining kmap_atomic() - Minor cleanups" * tag 'erofs-for-6.5-rc2-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs: erofs: fix fsdax unavailability for chunk-based regular files erofs: avoid infinite loop in z_erofs_do_read_page() when reading beyond EOF erofs: avoid useless loops in z_erofs_pcluster_readmore() when reading beyond EOF erofs: simplify z_erofs_transform_plain() erofs: get rid of the remaining kmap_atomic()
2 parents b1983d4 + 18bddc5 commit 4b810bf

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

fs/erofs/decompressor.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static void *z_erofs_lz4_handle_overlap(struct z_erofs_lz4_decompress_ctx *ctx,
148148
*maptype = 0;
149149
return inpage;
150150
}
151-
kunmap_atomic(inpage);
151+
kunmap_local(inpage);
152152
might_sleep();
153153
src = erofs_vm_map_ram(rq->in, ctx->inpages);
154154
if (!src)
@@ -162,7 +162,7 @@ static void *z_erofs_lz4_handle_overlap(struct z_erofs_lz4_decompress_ctx *ctx,
162162
src = erofs_get_pcpubuf(ctx->inpages);
163163
if (!src) {
164164
DBG_BUGON(1);
165-
kunmap_atomic(inpage);
165+
kunmap_local(inpage);
166166
return ERR_PTR(-EFAULT);
167167
}
168168

@@ -173,9 +173,9 @@ static void *z_erofs_lz4_handle_overlap(struct z_erofs_lz4_decompress_ctx *ctx,
173173
min_t(unsigned int, total, PAGE_SIZE - *inputmargin);
174174

175175
if (!inpage)
176-
inpage = kmap_atomic(*in);
176+
inpage = kmap_local_page(*in);
177177
memcpy(tmp, inpage + *inputmargin, page_copycnt);
178-
kunmap_atomic(inpage);
178+
kunmap_local(inpage);
179179
inpage = NULL;
180180
tmp += page_copycnt;
181181
total -= page_copycnt;
@@ -214,7 +214,7 @@ static int z_erofs_lz4_decompress_mem(struct z_erofs_lz4_decompress_ctx *ctx,
214214
int ret, maptype;
215215

216216
DBG_BUGON(*rq->in == NULL);
217-
headpage = kmap_atomic(*rq->in);
217+
headpage = kmap_local_page(*rq->in);
218218

219219
/* LZ4 decompression inplace is only safe if zero_padding is enabled */
220220
if (erofs_sb_has_zero_padding(EROFS_SB(rq->sb))) {
@@ -223,7 +223,7 @@ static int z_erofs_lz4_decompress_mem(struct z_erofs_lz4_decompress_ctx *ctx,
223223
min_t(unsigned int, rq->inputsize,
224224
rq->sb->s_blocksize - rq->pageofs_in));
225225
if (ret) {
226-
kunmap_atomic(headpage);
226+
kunmap_local(headpage);
227227
return ret;
228228
}
229229
may_inplace = !((rq->pageofs_in + rq->inputsize) &
@@ -261,7 +261,7 @@ static int z_erofs_lz4_decompress_mem(struct z_erofs_lz4_decompress_ctx *ctx,
261261
}
262262

263263
if (maptype == 0) {
264-
kunmap_atomic(headpage);
264+
kunmap_local(headpage);
265265
} else if (maptype == 1) {
266266
vm_unmap_ram(src, ctx->inpages);
267267
} else if (maptype == 2) {
@@ -289,7 +289,7 @@ static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq,
289289
/* one optimized fast path only for non bigpcluster cases yet */
290290
if (ctx.inpages == 1 && ctx.outpages == 1 && !rq->inplace_io) {
291291
DBG_BUGON(!*rq->out);
292-
dst = kmap_atomic(*rq->out);
292+
dst = kmap_local_page(*rq->out);
293293
dst_maptype = 0;
294294
goto dstmap_out;
295295
}
@@ -311,7 +311,7 @@ static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq,
311311
dstmap_out:
312312
ret = z_erofs_lz4_decompress_mem(&ctx, dst + rq->pageofs_out);
313313
if (!dst_maptype)
314-
kunmap_atomic(dst);
314+
kunmap_local(dst);
315315
else if (dst_maptype == 2)
316316
vm_unmap_ram(dst, ctx.outpages);
317317
return ret;
@@ -328,7 +328,7 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
328328
const unsigned int lefthalf = rq->outputsize - righthalf;
329329
const unsigned int interlaced_offset =
330330
rq->alg == Z_EROFS_COMPRESSION_SHIFTED ? 0 : rq->pageofs_out;
331-
unsigned char *src, *dst;
331+
u8 *src;
332332

333333
if (outpages > 2 && rq->alg == Z_EROFS_COMPRESSION_SHIFTED) {
334334
DBG_BUGON(1);
@@ -341,22 +341,19 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
341341
}
342342

343343
src = kmap_local_page(rq->in[inpages - 1]) + rq->pageofs_in;
344-
if (rq->out[0]) {
345-
dst = kmap_local_page(rq->out[0]);
346-
memcpy(dst + rq->pageofs_out, src + interlaced_offset,
347-
righthalf);
348-
kunmap_local(dst);
349-
}
344+
if (rq->out[0])
345+
memcpy_to_page(rq->out[0], rq->pageofs_out,
346+
src + interlaced_offset, righthalf);
350347

351348
if (outpages > inpages) {
352349
DBG_BUGON(!rq->out[outpages - 1]);
353350
if (rq->out[outpages - 1] != rq->in[inpages - 1]) {
354-
dst = kmap_local_page(rq->out[outpages - 1]);
355-
memcpy(dst, interlaced_offset ? src :
356-
(src + righthalf), lefthalf);
357-
kunmap_local(dst);
351+
memcpy_to_page(rq->out[outpages - 1], 0, src +
352+
(interlaced_offset ? 0 : righthalf),
353+
lefthalf);
358354
} else if (!interlaced_offset) {
359355
memmove(src, src + righthalf, lefthalf);
356+
flush_dcache_page(rq->in[inpages - 1]);
360357
}
361358
}
362359
kunmap_local(src);

fs/erofs/inode.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ static void *erofs_read_inode(struct erofs_buf *buf,
183183

184184
inode->i_flags &= ~S_DAX;
185185
if (test_opt(&sbi->opt, DAX_ALWAYS) && S_ISREG(inode->i_mode) &&
186-
vi->datalayout == EROFS_INODE_FLAT_PLAIN)
186+
(vi->datalayout == EROFS_INODE_FLAT_PLAIN ||
187+
vi->datalayout == EROFS_INODE_CHUNK_BASED))
187188
inode->i_flags |= S_DAX;
188189

189190
if (!nblks)

fs/erofs/zdata.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe,
10351035
*/
10361036
tight &= (fe->mode > Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE);
10371037

1038-
cur = end - min_t(unsigned int, offset + end - map->m_la, end);
1038+
cur = end - min_t(erofs_off_t, offset + end - map->m_la, end);
10391039
if (!(map->m_flags & EROFS_MAP_MAPPED)) {
10401040
zero_user_segment(page, cur, end);
10411041
goto next_part;
@@ -1841,7 +1841,7 @@ static void z_erofs_pcluster_readmore(struct z_erofs_decompress_frontend *f,
18411841
}
18421842

18431843
cur = map->m_la + map->m_llen - 1;
1844-
while (cur >= end) {
1844+
while ((cur >= end) && (cur < i_size_read(inode))) {
18451845
pgoff_t index = cur >> PAGE_SHIFT;
18461846
struct page *page;
18471847

0 commit comments

Comments
 (0)