Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'erofs-for-6.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs

Pull erofs updates from Gao Xiang:
"Nothing exciting lands for this cycle, since we're still busying in
developing support for sub-page blocks and large-folios of compressed
data for new scenarios on Android.

In this cycle, MicroLZMA format is marked as stable, and there are
minor cleanups around documentation and codebase. In addition, it also
fixes incorrect lockref usage in erofs_insert_workgroup().

Summary:

- Fix inode metadata space layout documentation

- Avoid warning for MicroLZMA format anymore

- Fix erofs_insert_workgroup() lockref usage

- Some cleanups"

* tag 'erofs-for-6.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs:
erofs: fix erofs_insert_workgroup() lockref usage
erofs: tidy up redundant includes
erofs: get rid of ROOT_NID()
erofs: simplify compression configuration parser
erofs: don't warn MicroLZMA format anymore
erofs: fix inode metadata space layout description in documentation

+89 -136
+1 -1
Documentation/filesystems/erofs.rst
··· 199 199 | | 200 200 |__________________| 64 bytes 201 201 202 - Xattrs, extents, data inline are followed by the corresponding inode with 202 + Xattrs, extents, data inline are placed after the corresponding inode with 203 203 proper alignment, and they could be optional for different data mappings. 204 204 _currently_ total 5 data layouts are supported: 205 205
+2 -5
fs/erofs/Kconfig
··· 91 91 select XZ_DEC_MICROLZMA 92 92 help 93 93 Saying Y here includes support for reading EROFS file systems 94 - containing LZMA compressed data, specifically called microLZMA. it 95 - gives better compression ratios than the LZ4 algorithm, at the 94 + containing LZMA compressed data, specifically called microLZMA. It 95 + gives better compression ratios than the default LZ4 format, at the 96 96 expense of more CPU overhead. 97 - 98 - LZMA support is an experimental feature for now and so most file 99 - systems will be readable without selecting this option. 100 97 101 98 If unsure, say N. 102 99
+6
fs/erofs/compress.h
··· 21 21 }; 22 22 23 23 struct z_erofs_decompressor { 24 + int (*config)(struct super_block *sb, struct erofs_super_block *dsb, 25 + void *data, int size); 24 26 int (*decompress)(struct z_erofs_decompress_req *rq, 25 27 struct page **pagepool); 26 28 char *name; ··· 94 92 extern const struct z_erofs_decompressor erofs_decompressors[]; 95 93 96 94 /* prototypes for specific algorithms */ 95 + int z_erofs_load_lzma_config(struct super_block *sb, 96 + struct erofs_super_block *dsb, void *data, int size); 97 + int z_erofs_load_deflate_config(struct super_block *sb, 98 + struct erofs_super_block *dsb, void *data, int size); 97 99 int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq, 98 100 struct page **pagepool); 99 101 int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,
-2
fs/erofs/data.c
··· 5 5 * Copyright (C) 2021, Alibaba Cloud 6 6 */ 7 7 #include "internal.h" 8 - #include <linux/prefetch.h> 9 8 #include <linux/sched/mm.h> 10 - #include <linux/dax.h> 11 9 #include <trace/events/erofs.h> 12 10 13 11 void erofs_unmap_metabuf(struct erofs_buf *buf)
+59 -4
fs/erofs/decompressor.c
··· 4 4 * https://www.huawei.com/ 5 5 */ 6 6 #include "compress.h" 7 - #include <linux/module.h> 8 7 #include <linux/lz4.h> 9 8 10 9 #ifndef LZ4_DISTANCE_MAX /* history window size */ ··· 23 24 unsigned int oend; 24 25 }; 25 26 26 - int z_erofs_load_lz4_config(struct super_block *sb, 27 - struct erofs_super_block *dsb, 28 - struct z_erofs_lz4_cfgs *lz4, int size) 27 + static int z_erofs_load_lz4_config(struct super_block *sb, 28 + struct erofs_super_block *dsb, void *data, int size) 29 29 { 30 30 struct erofs_sb_info *sbi = EROFS_SB(sb); 31 + struct z_erofs_lz4_cfgs *lz4 = data; 31 32 u16 distance; 32 33 33 34 if (lz4) { ··· 369 370 .name = "interlaced" 370 371 }, 371 372 [Z_EROFS_COMPRESSION_LZ4] = { 373 + .config = z_erofs_load_lz4_config, 372 374 .decompress = z_erofs_lz4_decompress, 373 375 .name = "lz4" 374 376 }, 375 377 #ifdef CONFIG_EROFS_FS_ZIP_LZMA 376 378 [Z_EROFS_COMPRESSION_LZMA] = { 379 + .config = z_erofs_load_lzma_config, 377 380 .decompress = z_erofs_lzma_decompress, 378 381 .name = "lzma" 379 382 }, 380 383 #endif 381 384 #ifdef CONFIG_EROFS_FS_ZIP_DEFLATE 382 385 [Z_EROFS_COMPRESSION_DEFLATE] = { 386 + .config = z_erofs_load_deflate_config, 383 387 .decompress = z_erofs_deflate_decompress, 384 388 .name = "deflate" 385 389 }, 386 390 #endif 387 391 }; 392 + 393 + int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb) 394 + { 395 + struct erofs_sb_info *sbi = EROFS_SB(sb); 396 + struct erofs_buf buf = __EROFS_BUF_INITIALIZER; 397 + unsigned int algs, alg; 398 + erofs_off_t offset; 399 + int size, ret = 0; 400 + 401 + if (!erofs_sb_has_compr_cfgs(sbi)) { 402 + sbi->available_compr_algs = Z_EROFS_COMPRESSION_LZ4; 403 + return z_erofs_load_lz4_config(sb, dsb, NULL, 0); 404 + } 405 + 406 + sbi->available_compr_algs = le16_to_cpu(dsb->u1.available_compr_algs); 407 + if (sbi->available_compr_algs & ~Z_EROFS_ALL_COMPR_ALGS) { 408 + erofs_err(sb, "unidentified algorithms %x, please upgrade kernel", 409 + sbi->available_compr_algs & ~Z_EROFS_ALL_COMPR_ALGS); 410 + return -EOPNOTSUPP; 411 + } 412 + 413 + erofs_init_metabuf(&buf, sb); 414 + offset = EROFS_SUPER_OFFSET + sbi->sb_size; 415 + alg = 0; 416 + for (algs = sbi->available_compr_algs; algs; algs >>= 1, ++alg) { 417 + void *data; 418 + 419 + if (!(algs & 1)) 420 + continue; 421 + 422 + data = erofs_read_metadata(sb, &buf, &offset, &size); 423 + if (IS_ERR(data)) { 424 + ret = PTR_ERR(data); 425 + break; 426 + } 427 + 428 + if (alg >= ARRAY_SIZE(erofs_decompressors) || 429 + !erofs_decompressors[alg].config) { 430 + erofs_err(sb, "algorithm %d isn't enabled on this kernel", 431 + alg); 432 + ret = -EOPNOTSUPP; 433 + } else { 434 + ret = erofs_decompressors[alg].config(sb, 435 + dsb, data, size); 436 + } 437 + 438 + kfree(data); 439 + if (ret) 440 + break; 441 + } 442 + erofs_put_metabuf(&buf); 443 + return ret; 444 + }
+3 -3
fs/erofs/decompressor_deflate.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-or-later 2 - #include <linux/module.h> 3 2 #include <linux/zlib.h> 4 3 #include "compress.h" 5 4 ··· 76 77 } 77 78 78 79 int z_erofs_load_deflate_config(struct super_block *sb, 79 - struct erofs_super_block *dsb, 80 - struct z_erofs_deflate_cfgs *dfl, int size) 80 + struct erofs_super_block *dsb, void *data, int size) 81 81 { 82 + struct z_erofs_deflate_cfgs *dfl = data; 83 + 82 84 if (!dfl || size < sizeof(struct z_erofs_deflate_cfgs)) { 83 85 erofs_err(sb, "invalid deflate cfgs, size=%u", size); 84 86 return -EINVAL;
+2 -5
fs/erofs/decompressor_lzma.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-or-later 2 2 #include <linux/xz.h> 3 - #include <linux/module.h> 4 3 #include "compress.h" 5 4 6 5 struct z_erofs_lzma { ··· 71 72 } 72 73 73 74 int z_erofs_load_lzma_config(struct super_block *sb, 74 - struct erofs_super_block *dsb, 75 - struct z_erofs_lzma_cfgs *lzma, int size) 75 + struct erofs_super_block *dsb, void *data, int size) 76 76 { 77 77 static DEFINE_MUTEX(lzma_resize_mutex); 78 + struct z_erofs_lzma_cfgs *lzma = data; 78 79 unsigned int dict_size, i; 79 80 struct z_erofs_lzma *strm, *head = NULL; 80 81 int err; ··· 94 95 dict_size); 95 96 return -EINVAL; 96 97 } 97 - 98 - erofs_info(sb, "EXPERIMENTAL MicroLZMA in use. Use at your own risk!"); 99 98 100 99 /* in case 2 z_erofs_load_lzma_config() race to avoid deadlock */ 101 100 mutex_lock(&lzma_resize_mutex);
+3 -39
fs/erofs/internal.h
··· 8 8 #define __EROFS_INTERNAL_H 9 9 10 10 #include <linux/fs.h> 11 + #include <linux/dax.h> 11 12 #include <linux/dcache.h> 12 13 #include <linux/mm.h> 14 + #include <linux/module.h> 13 15 #include <linux/pagemap.h> 14 16 #include <linux/bio.h> 15 17 #include <linux/magic.h> ··· 229 227 enum erofs_kmap_type kmap_type; 230 228 }; 231 229 #define __EROFS_BUF_INITIALIZER ((struct erofs_buf){ .page = NULL }) 232 - 233 - #define ROOT_NID(sb) ((sb)->root_nid) 234 230 235 231 #define erofs_blknr(sb, addr) ((addr) >> (sb)->s_blocksize_bits) 236 232 #define erofs_blkoff(sb, addr) ((addr) & ((sb)->s_blocksize - 1)) ··· 469 469 void z_erofs_exit_zip_subsystem(void); 470 470 int erofs_try_to_free_all_cached_pages(struct erofs_sb_info *sbi, 471 471 struct erofs_workgroup *egrp); 472 - int z_erofs_load_lz4_config(struct super_block *sb, 473 - struct erofs_super_block *dsb, 474 - struct z_erofs_lz4_cfgs *lz4, int len); 475 472 int z_erofs_map_blocks_iter(struct inode *inode, struct erofs_map_blocks *map, 476 473 int flags); 477 474 void *erofs_get_pcpubuf(unsigned int requiredpages); ··· 477 480 void __init erofs_pcpubuf_init(void); 478 481 void erofs_pcpubuf_exit(void); 479 482 int erofs_init_managed_cache(struct super_block *sb); 483 + int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb); 480 484 #else 481 485 static inline void erofs_shrinker_register(struct super_block *sb) {} 482 486 static inline void erofs_shrinker_unregister(struct super_block *sb) {} ··· 485 487 static inline void erofs_exit_shrinker(void) {} 486 488 static inline int z_erofs_init_zip_subsystem(void) { return 0; } 487 489 static inline void z_erofs_exit_zip_subsystem(void) {} 488 - static inline int z_erofs_load_lz4_config(struct super_block *sb, 489 - struct erofs_super_block *dsb, 490 - struct z_erofs_lz4_cfgs *lz4, int len) 491 - { 492 - if (lz4 || dsb->u1.lz4_max_distance) { 493 - erofs_err(sb, "lz4 algorithm isn't enabled"); 494 - return -EINVAL; 495 - } 496 - return 0; 497 - } 498 490 static inline void erofs_pcpubuf_init(void) {} 499 491 static inline void erofs_pcpubuf_exit(void) {} 500 492 static inline int erofs_init_managed_cache(struct super_block *sb) { return 0; } ··· 493 505 #ifdef CONFIG_EROFS_FS_ZIP_LZMA 494 506 int __init z_erofs_lzma_init(void); 495 507 void z_erofs_lzma_exit(void); 496 - int z_erofs_load_lzma_config(struct super_block *sb, 497 - struct erofs_super_block *dsb, 498 - struct z_erofs_lzma_cfgs *lzma, int size); 499 508 #else 500 509 static inline int z_erofs_lzma_init(void) { return 0; } 501 510 static inline int z_erofs_lzma_exit(void) { return 0; } 502 - static inline int z_erofs_load_lzma_config(struct super_block *sb, 503 - struct erofs_super_block *dsb, 504 - struct z_erofs_lzma_cfgs *lzma, int size) { 505 - if (lzma) { 506 - erofs_err(sb, "lzma algorithm isn't enabled"); 507 - return -EINVAL; 508 - } 509 - return 0; 510 - } 511 511 #endif /* !CONFIG_EROFS_FS_ZIP_LZMA */ 512 512 513 513 #ifdef CONFIG_EROFS_FS_ZIP_DEFLATE 514 514 int __init z_erofs_deflate_init(void); 515 515 void z_erofs_deflate_exit(void); 516 - int z_erofs_load_deflate_config(struct super_block *sb, 517 - struct erofs_super_block *dsb, 518 - struct z_erofs_deflate_cfgs *dfl, int size); 519 516 #else 520 517 static inline int z_erofs_deflate_init(void) { return 0; } 521 518 static inline int z_erofs_deflate_exit(void) { return 0; } 522 - static inline int z_erofs_load_deflate_config(struct super_block *sb, 523 - struct erofs_super_block *dsb, 524 - struct z_erofs_deflate_cfgs *dfl, int size) { 525 - if (dfl) { 526 - erofs_err(sb, "deflate algorithm isn't enabled"); 527 - return -EINVAL; 528 - } 529 - return 0; 530 - } 531 519 #endif /* !CONFIG_EROFS_FS_ZIP_DEFLATE */ 532 520 533 521 #ifdef CONFIG_EROFS_FS_ONDEMAND
+11 -70
fs/erofs/super.c
··· 4 4 * https://www.huawei.com/ 5 5 * Copyright (C) 2021, Alibaba Cloud 6 6 */ 7 - #include <linux/module.h> 8 7 #include <linux/statfs.h> 9 - #include <linux/parser.h> 10 8 #include <linux/seq_file.h> 11 9 #include <linux/crc32c.h> 12 10 #include <linux/fs_context.h> 13 11 #include <linux/fs_parser.h> 14 - #include <linux/dax.h> 15 12 #include <linux/exportfs.h> 16 13 #include "xattr.h" 17 14 ··· 153 156 return buffer; 154 157 } 155 158 156 - #ifdef CONFIG_EROFS_FS_ZIP 157 - static int erofs_load_compr_cfgs(struct super_block *sb, 158 - struct erofs_super_block *dsb) 159 + #ifndef CONFIG_EROFS_FS_ZIP 160 + static int z_erofs_parse_cfgs(struct super_block *sb, 161 + struct erofs_super_block *dsb) 159 162 { 160 - struct erofs_sb_info *sbi = EROFS_SB(sb); 161 - struct erofs_buf buf = __EROFS_BUF_INITIALIZER; 162 - unsigned int algs, alg; 163 - erofs_off_t offset; 164 - int size, ret = 0; 163 + if (!dsb->u1.available_compr_algs) 164 + return 0; 165 165 166 - sbi->available_compr_algs = le16_to_cpu(dsb->u1.available_compr_algs); 167 - if (sbi->available_compr_algs & ~Z_EROFS_ALL_COMPR_ALGS) { 168 - erofs_err(sb, "try to load compressed fs with unsupported algorithms %x", 169 - sbi->available_compr_algs & ~Z_EROFS_ALL_COMPR_ALGS); 170 - return -EINVAL; 171 - } 172 - 173 - erofs_init_metabuf(&buf, sb); 174 - offset = EROFS_SUPER_OFFSET + sbi->sb_size; 175 - alg = 0; 176 - for (algs = sbi->available_compr_algs; algs; algs >>= 1, ++alg) { 177 - void *data; 178 - 179 - if (!(algs & 1)) 180 - continue; 181 - 182 - data = erofs_read_metadata(sb, &buf, &offset, &size); 183 - if (IS_ERR(data)) { 184 - ret = PTR_ERR(data); 185 - break; 186 - } 187 - 188 - switch (alg) { 189 - case Z_EROFS_COMPRESSION_LZ4: 190 - ret = z_erofs_load_lz4_config(sb, dsb, data, size); 191 - break; 192 - case Z_EROFS_COMPRESSION_LZMA: 193 - ret = z_erofs_load_lzma_config(sb, dsb, data, size); 194 - break; 195 - case Z_EROFS_COMPRESSION_DEFLATE: 196 - ret = z_erofs_load_deflate_config(sb, dsb, data, size); 197 - break; 198 - default: 199 - DBG_BUGON(1); 200 - ret = -EFAULT; 201 - } 202 - kfree(data); 203 - if (ret) 204 - break; 205 - } 206 - erofs_put_metabuf(&buf); 207 - return ret; 208 - } 209 - #else 210 - static int erofs_load_compr_cfgs(struct super_block *sb, 211 - struct erofs_super_block *dsb) 212 - { 213 - if (dsb->u1.available_compr_algs) { 214 - erofs_err(sb, "try to load compressed fs when compression is disabled"); 215 - return -EINVAL; 216 - } 217 - return 0; 166 + erofs_err(sb, "compression disabled, unable to mount compressed EROFS"); 167 + return -EOPNOTSUPP; 218 168 } 219 169 #endif 220 170 ··· 350 406 } 351 407 352 408 /* parse on-disk compression configurations */ 353 - if (erofs_sb_has_compr_cfgs(sbi)) 354 - ret = erofs_load_compr_cfgs(sb, dsb); 355 - else 356 - ret = z_erofs_load_lz4_config(sb, dsb, NULL, 0); 409 + ret = z_erofs_parse_cfgs(sb, dsb); 357 410 if (ret < 0) 358 411 goto out; 359 412 ··· 665 724 xa_init(&sbi->managed_pslots); 666 725 #endif 667 726 668 - inode = erofs_iget(sb, ROOT_NID(sbi)); 727 + inode = erofs_iget(sb, sbi->root_nid); 669 728 if (IS_ERR(inode)) 670 729 return PTR_ERR(inode); 671 730 672 731 if (!S_ISDIR(inode->i_mode)) { 673 732 erofs_err(sb, "rootino(nid %llu) is not a directory(i_mode %o)", 674 - ROOT_NID(sbi), inode->i_mode); 733 + sbi->root_nid, inode->i_mode); 675 734 iput(inode); 676 735 return -EINVAL; 677 736 } ··· 701 760 if (err) 702 761 return err; 703 762 704 - erofs_info(sb, "mounted with root inode @ nid %llu.", ROOT_NID(sbi)); 763 + erofs_info(sb, "mounted with root inode @ nid %llu.", sbi->root_nid); 705 764 return 0; 706 765 } 707 766
+1 -7
fs/erofs/utils.c
··· 77 77 struct erofs_sb_info *const sbi = EROFS_SB(sb); 78 78 struct erofs_workgroup *pre; 79 79 80 - /* 81 - * Bump up before making this visible to others for the XArray in order 82 - * to avoid potential UAF without serialized by xa_lock. 83 - */ 84 - lockref_get(&grp->lockref); 85 - 80 + DBG_BUGON(grp->lockref.count < 1); 86 81 repeat: 87 82 xa_lock(&sbi->managed_pslots); 88 83 pre = __xa_cmpxchg(&sbi->managed_pslots, grp->index, ··· 91 96 cond_resched(); 92 97 goto repeat; 93 98 } 94 - lockref_put_return(&grp->lockref); 95 99 grp = pre; 96 100 } 97 101 xa_unlock(&sbi->managed_pslots);
+1
fs/erofs/zdata.c
··· 796 796 return PTR_ERR(pcl); 797 797 798 798 spin_lock_init(&pcl->obj.lockref.lock); 799 + pcl->obj.lockref.count = 1; /* one ref for this request */ 799 800 pcl->algorithmformat = map->m_algorithmformat; 800 801 pcl->length = 0; 801 802 pcl->partial = true;