FAILED: patch "[PATCH] erofs: cap LZMA stream pool size" failed to apply to 6.1-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x c9b47e6b23114e939b17f818471c7a46e59006e7
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026080538-tartly-varying-5d75@gregkh' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From c9b47e6b23114e939b17f818471c7a46e59006e7 Mon Sep 17 00:00:00 2001
From: Michael Bommarito <[email protected]>
Date: Tue, 14 Jul 2026 07:47:29 -0400
Subject: [PATCH] erofs: cap LZMA stream pool size
fs/erofs/decompressor_lzma.c sizes the module-global MicroLZMA stream pool from num_possible_cpus() when the lzma_streams module parameter is unset, then z_erofs_load_lzma_config() preallocates one image-supplied dictionary per stream, accepting dictionaries up to 8 MiB. On high-CPU systems, a small EROFS image can pin hundreds of MiB of vmalloc-backed decoder state until the erofs module is unloaded.
Impact: An EROFS image mounted by the system can pin up to 8 MiB of vmalloc memory per LZMA stream, either as intended or unexpectedly.
Bound the default stream count by a new CONFIG_EROFS_FS_ZIP_LZMA_DEFAULT_MAX_STREAMS option, default 16, so the worst-case default preallocation is 128 MiB if the number of CPUs is no less than 16 while preserving the existing per-image dictionary limit. An explicit lzma_streams module parameter is still honoured as-is, so administrators who deliberately size the pool are not affected.
fs/erofs/Kconfig +14 -0
@@ -131,6 +131,20 @@ config EROFS_FS_ZIP_LZMA Say N if you want to disable LZMA compression support. +config EROFS_FS_ZIP_LZMA_DEFAULT_MAX_STREAMS + int "EROFS LZMA default maximum decompression streams" + depends on EROFS_FS_ZIP_LZMA + range 1 NR_CPUS + default 16 + help + By default EROFS allocates one LZMA decompression stream per CPU. + Each stream can hold a dictionary of up to 8 MiB taken from the + mounted image, so on systems with many CPUs this can reserve a lot + of memory. This caps the default; the lzma_streams module parameter + still overrides it. + + If unsure, keep the default of 16. + config EROFS_FS_ZIP_DEFLATE bool "EROFS DEFLATE compressed data support" depends on EROFS_FS_ZIP
fs/erofs/decompressor_lzma.c +2 -1
@@ -51,7 +51,8 @@ static int __init z_erofs_lzma_init(void)/* by default, use # of possible CPUs instead */ if (!z_erofs_lzma_nstrms) - z_erofs_lzma_nstrms =num_possible_cpus (); + z_erofs_lzma_nstrms = min_t(unsigned int, num_possible_cpus(), +CONFIG_EROFS_FS_ZIP_LZMA_DEFAULT_MAX_STREAMS );for (i =0 ; i < z_erofs_lzma_nstrms; ++i) {struct z_erofs_lzma *strm =kzalloc_obj (*strm);
Sasha Levin
maintainerPATCH 1/3 erofs: tidy up internal.h
From: Gao Xiang <[email protected]>
[ Upstream commit 557afdd94cf853885ac3b5c218bdf49c021f7323 ]
Reorder internal.h code so that removing unneeded macros and more. No logic changes.
Stable-dep-of: c9b47e6b2311 ("erofs: cap LZMA stream pool size")
--- fs/erofs/internal.h | 83 +++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 55 deletions(-)
fs/erofs/internal.h +28 -55
@@ -364,12 +364,6 @@ struct page *erofs_grab_cache_page_nowait(struct address_space *mapping, readahead_gfp_mask(mapping) & ~__GFP_RECLAIM); } -extern const struct super_operations erofs_sops; -extern struct file_system_type erofs_fs_type; - -extern const struct address_space_operations erofs_raw_access_aops; -extern const struct address_space_operations z_erofs_aops; -enum { BH_Encoded = BH_PrivateStart, BH_FullMapped,
@@ -401,7 +395,6 @@ struct erofs_map_blocks {unsigned int m_flags; }; -/* Flags used by erofs_map_blocks_flatmode() */ #define EROFS_GET_BLOCKS_RAW 0x0001/* * Used to get the exact decompressed length, e.g. fiemap (consider lookback
@@ -419,24 +412,6 @@ enum {Z_EROFS_COMPRESSION_RUNTIME_MAX }; -/* zmap.c */ -extern const struct iomap_ops z_erofs_iomap_report_ops; - -#ifdef CONFIG_EROFS_FS_ZIP -int z_erofs_fill_inode (struct inode *inode); -int z_erofs_map_blocks_iter (struct inode *inode, -struct erofs_map_blocks *map, -int flags); -#else -static inline int z_erofs_fill_inode (struct inode *inode) {return -EOPNOTSUPP ; } -static inline int z_erofs_map_blocks_iter (struct inode *inode, -struct erofs_map_blocks *map, -int flags) -{ -return -EOPNOTSUPP ; -} -#endif /* !CONFIG_EROFS_FS_ZIP */ -struct erofs_map_dev {struct erofs_fscache *m_fscache;struct block_device *m_bdev;
@@ -447,8 +422,27 @@ struct erofs_map_dev {unsigned int m_deviceid; }; -/* data.c */ +extern struct file_system_type erofs_fs_type; +extern const struct super_operations erofs_sops; + +extern const struct address_space_operations erofs_raw_access_aops; +extern const struct address_space_operations z_erofs_aops; +extern const struct address_space_operations erofs_fscache_access_aops; + +extern const struct inode_operations erofs_generic_iops; +extern const struct inode_operations erofs_symlink_iops; +extern const struct inode_operations erofs_fast_symlink_iops; +extern const struct inode_operations erofs_dir_iops; +extern const struct file_operations erofs_file_fops; +extern const struct file_operations erofs_dir_fops; + +extern const struct iomap_ops z_erofs_iomap_report_ops; + +/* flags for erofs_fscache_register_cookie() */ +#define EROFS_REG_COOKIE_NEED_INODE 1 +#define EROFS_REG_COOKIE_NEED_NOEXIST 2 +void *erofs_read_metadata (struct super_block *sb,struct erofs_buf *buf,erofs_off_t *offset,int *lengthp);void erofs_unmap_metabuf (struct erofs_buf *buf);
@@ -463,7 +457,6 @@ int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,int erofs_map_blocks (struct inode *inode,struct erofs_map_blocks *map,int flags); -/* inode.c */ static inline unsigned long erofs_inode_hash (erofs_nid_t nid) {#if BITS_PER_LONG ==32
@@ -473,24 +466,13 @@ static inline unsigned long erofs_inode_hash(erofs_nid_t nid)#endif } -extern const struct inode_operations erofs_generic_iops; -extern const struct inode_operations erofs_symlink_iops; -extern const struct inode_operations erofs_fast_symlink_iops; -struct inode *erofs_iget (struct super_block *sb,erofs_nid_t nid);int erofs_getattr (struct user_namespace *mnt_userns,const struct path *path,struct kstat *stat,u32 request_mask,unsigned int query_flags); - -/* namei.c */ -extern const struct inode_operations erofs_dir_iops; -int erofs_namei (struct inode *dir,const struct qstr *name,erofs_nid_t *nid,unsigned int *d_type); -/* dir.c */ -extern const struct file_operations erofs_dir_fops; -static inline void *erofs_vm_map_ram (struct page **pages,unsigned int count) {int retried =0 ;
@@ -506,23 +488,19 @@ static inline void *erofs_vm_map_ram(struct page **pages, unsigned int count)return NULL ; } -/* pcpubuf.c */ void *erofs_get_pcpubuf (unsigned int requiredpages);void erofs_put_pcpubuf (void *ptr);int erofs_pcpubuf_growsize (unsigned int nrpages);void erofs_pcpubuf_init (void );void erofs_pcpubuf_exit (void ); -/* sysfs.c */ int erofs_register_sysfs (struct super_block *sb);void erofs_unregister_sysfs (struct super_block *sb);int __init erofs_init_sysfs (void );void erofs_exit_sysfs (void ); -/* utils.c / zdata.c */ struct page *erofs_allocpage (struct page **pagepool,gfp_t gfp); -static inline void erofs_pagepool_add (struct page **pagepool, -struct page *page) +static inline void erofs_pagepool_add (struct page **pagepool,struct page *page) {set_page_private (page, (unsigned long )*pagepool); *pagepool = page;
@@ -546,6 +524,9 @@ int erofs_try_to_free_all_cached_pages(struct erofs_sb_info *sbi, struct erofs_workgroup *egrp);int erofs_try_to_free_cached_page (struct page *page);int z_erofs_parse_cfgs (struct super_block *sb,struct erofs_super_block *dsb); +int z_erofs_fill_inode (struct inode *inode); +int z_erofs_map_blocks_iter (struct inode *inode,struct erofs_map_blocks *map, +int flags);#else static inline void erofs_shrinker_register (struct super_block *sb) {}static inline void erofs_shrinker_unregister (struct super_block *sb) {}
@@ -553,6 +534,7 @@ static inline int erofs_init_shrinker(void) { return 0; }static inline void erofs_exit_shrinker (void ) {}static inline int z_erofs_init_zip_subsystem (void ) {return 0 ; }static inline void z_erofs_exit_zip_subsystem (void ) {} +static inline int z_erofs_fill_inode (struct inode *inode) {return -EOPNOTSUPP ; }#endif /* !CONFIG_EROFS_FS_ZIP */ #ifdef CONFIG_EROFS_FS_ZIP_LZMA
@@ -561,23 +543,15 @@ void z_erofs_lzma_exit(void);#else static inline int z_erofs_lzma_init (void ) {return 0 ; }static inline int z_erofs_lzma_exit (void ) {return 0 ; } -#endif /* !CONFIG_EROFS_FS_ZIP */ +#endif /* !CONFIG_EROFS_FS_ZIP_LZMA */ -/* flags for erofs_fscache_register_cookie() */ -#define EROFS_REG_COOKIE_NEED_INODE 1 -#define EROFS_REG_COOKIE_NEED_NOEXIST 2 - -/* fscache.c */ #ifdef CONFIG_EROFS_FS_ONDEMAND int erofs_fscache_register_fs (struct super_block *sb);void erofs_fscache_unregister_fs (struct super_block *sb);struct erofs_fscache *erofs_fscache_register_cookie (struct super_block *sb, -char *name, -unsigned int flags); +char *name,unsigned int flags);void erofs_fscache_unregister_cookie (struct erofs_fscache *fscache); - -extern const struct address_space_operations erofs_fscache_access_aops;#else static inline int erofs_fscache_register_fs (struct super_block *sb) {
@@ -587,8 +561,7 @@ static inline void erofs_fscache_unregister_fs(struct super_block *sb) {}static inline struct erofs_fscache *erofs_fscache_register_cookie (struct super_block *sb, -char *name, -unsigned int flags) +char *name,unsigned int flags) {return ERR_PTR (-EOPNOTSUPP ); }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/3 erofs: maintain cookies of share domain in self-contained list
From: Jingbo Xu <[email protected]>
[ Upstream commit 2dfb8c3b122fad4504a92c34ba68f2fe4444b3f6 ]
We'd better not touch sb->s_inodes list and inode->i_count directly. Let's maintain cookies of share domain in a self-contained list in erofs.
Besides, relinquish cookie with the mutex held. Otherwise if a cookie is registered when the old cookie with the same name in the same domain has been removed from the list but not relinquished yet, fscache may complain "Duplicate cookie detected".
Stable-dep-of: c9b47e6b2311 ("erofs: cap LZMA stream pool size")
--- fs/erofs/fscache.c | 44 ++++++++++++++++++++------------------------ fs/erofs/internal.h | 4 ++++ 2 files changed, 24 insertions(+), 24 deletions(-)
fs/erofs/fscache.c +20 -24
@@ -9,6 +9,7 @@static DEFINE_MUTEX (erofs_domain_list_lock);static DEFINE_MUTEX (erofs_domain_cookies_lock);static LIST_HEAD (erofs_domain_list); +static LIST_HEAD (erofs_domain_cookies_list);static struct vfsmount *erofs_pseudo_mnt; static struct netfs_io_request *erofs_fscache_alloc_request(struct address_space *mapping,
@@ -389,8 +390,6 @@ const struct address_space_operations erofs_fscache_access_aops = {static void erofs_fscache_domain_put (struct erofs_domain *domain) { -if (!domain) -return ;mutex_lock (&erofs_domain_list_lock);if (refcount_dec_and_test (&domain->ref)) {list_del (&domain->list);
@@ -505,6 +504,8 @@ struct erofs_fscache *erofs_fscache_acquire_cookie(struct super_block *sb, ctx =kzalloc (sizeof (*ctx),GFP_KERNEL );if (!ctx)return ERR_PTR (-ENOMEM ); +INIT_LIST_HEAD (&ctx->node); +refcount_set (&ctx->ref,1 ); cookie =fscache_acquire_cookie (volume,FSCACHE_ADV_WANT_CACHE_SIZE , name,strlen (name),NULL ,0 ,0 );
@@ -550,6 +551,7 @@ static void erofs_fscache_relinquish_cookie(struct erofs_fscache *ctx)fscache_unuse_cookie (ctx->cookie,NULL ,NULL );fscache_relinquish_cookie (ctx->cookie, false);iput (ctx->inode); +iput (ctx->anon_inode);kfree (ctx->name);kfree (ctx); }
@@ -582,6 +584,7 @@ struct erofs_fscache *erofs_fscache_domain_init_cookie(struct super_block *sb, ctx->domain = domain; ctx->anon_inode = inode; +list_add (&ctx->node, &erofs_domain_cookies_list); inode->i_private = ctx;refcount_inc (&domain->ref);return ctx;
@@ -595,29 +598,23 @@ struct erofs_fscache *erofs_domain_register_cookie(struct super_block *sb, char *name, unsigned int flags) { -struct inode *inode;struct erofs_fscache *ctx;struct erofs_domain *domain =EROFS_SB (sb)->domain; -struct super_block *psb = erofs_pseudo_mnt->mnt_sb;mutex_lock (&erofs_domain_cookies_lock); -spin_lock (&psb->s_inode_list_lock); -list_for_each_entry (inode, &psb->s_inodes, i_sb_list) { - ctx = inode->i_private; -if (!ctx || ctx->domain != domain ||strcmp (ctx->name, name)) +list_for_each_entry (ctx, &erofs_domain_cookies_list, node) { +if (ctx->domain != domain ||strcmp (ctx->name, name))continue ;if (!(flags &EROFS_REG_COOKIE_NEED_NOEXIST )) { -igrab (inode); +refcount_inc (&ctx->ref); }else {erofs_err (sb,"%s already exists in domain %s" , name, domain->domain_id); ctx =ERR_PTR (-EEXIST ); } -spin_unlock (&psb->s_inode_list_lock);mutex_unlock (&erofs_domain_cookies_lock);return ctx; } -spin_unlock (&psb->s_inode_list_lock); ctx =erofs_fscache_domain_init_cookie (sb, name, flags);mutex_unlock (&erofs_domain_cookies_lock);return ctx;
@@ -634,23 +631,22 @@ struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb,void erofs_fscache_unregister_cookie (struct erofs_fscache *ctx) { -bool drop; -struct erofs_domain *domain; +struct erofs_domain *domain =NULL ;if (!ctx)return ; - domain = ctx->domain; -if (domain) { -mutex_lock (&erofs_domain_cookies_lock); - drop =atomic_read (&ctx->anon_inode->i_count) ==1 ; -iput (ctx->anon_inode); -mutex_unlock (&erofs_domain_cookies_lock); -if (!drop) -return ; - } +if (!ctx->domain) +return erofs_fscache_relinquish_cookie (ctx); -erofs_fscache_relinquish_cookie (ctx); -erofs_fscache_domain_put (domain); +mutex_lock (&erofs_domain_cookies_lock); +if (refcount_dec_and_test (&ctx->ref)) { + domain = ctx->domain; +list_del (&ctx->node); +erofs_fscache_relinquish_cookie (ctx); + } +mutex_unlock (&erofs_domain_cookies_lock); +if (domain) +erofs_fscache_domain_put (domain); }int erofs_fscache_register_fs (struct super_block *sb)
fs/erofs/internal.h +4 -0
@@ -108,7 +108,11 @@ struct erofs_fscache {struct fscache_cookie *cookie;struct inode *inode;struct inode *anon_inode; + +/* used for share domain mode */ struct erofs_domain *domain; +struct list_head node; +refcount_t ref;char *name; };
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/3 erofs: cap LZMA stream pool size
In reply to Sasha LevinFrom: Michael Bommarito <[email protected]>
[ Upstream commit c9b47e6b23114e939b17f818471c7a46e59006e7 ]
fs/erofs/decompressor_lzma.c sizes the module-global MicroLZMA stream pool from num_possible_cpus() when the lzma_streams module parameter is unset, then z_erofs_load_lzma_config() preallocates one image-supplied dictionary per stream, accepting dictionaries up to 8 MiB. On high-CPU systems, a small EROFS image can pin hundreds of MiB of vmalloc-backed decoder state until the erofs module is unloaded.
Impact: An EROFS image mounted by the system can pin up to 8 MiB of vmalloc memory per LZMA stream, either as intended or unexpectedly.
Bound the default stream count by a new CONFIG_EROFS_FS_ZIP_LZMA_DEFAULT_MAX_STREAMS option, default 16, so the worst-case default preallocation is 128 MiB if the number of CPUs is no less than 16 while preserving the existing per-image dictionary limit. An explicit lzma_streams module parameter is still honoured as-is, so administrators who deliberately size the pool are not affected.
--- fs/erofs/Kconfig | 14 ++++++++++++++ fs/erofs/decompressor_lzma.c | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-)
fs/erofs/Kconfig +14 -0
@@ -99,6 +99,20 @@ config EROFS_FS_ZIP_LZMA If unsure, say N. +config EROFS_FS_ZIP_LZMA_DEFAULT_MAX_STREAMS + int "EROFS LZMA default maximum decompression streams" + depends on EROFS_FS_ZIP_LZMA + range 1 NR_CPUS + default 16 + help + By default EROFS allocates one LZMA decompression stream per CPU. + Each stream can hold a dictionary of up to 8 MiB taken from the + mounted image, so on systems with many CPUs this can reserve a lot + of memory. This caps the default; the lzma_streams module parameter + still overrides it. + + If unsure, keep the default of 16. + config EROFS_FS_ONDEMAND bool "EROFS fscache-based on-demand read support" depends on CACHEFILES_ONDEMAND && (EROFS_FS=m && FSCACHE || EROFS_FS=y && FSCACHE=y)
fs/erofs/decompressor_lzma.c +2 -1
@@ -53,7 +53,8 @@ int z_erofs_lzma_init(void)/* by default, use # of possible CPUs instead */ if (!z_erofs_lzma_nstrms) - z_erofs_lzma_nstrms =num_possible_cpus (); + z_erofs_lzma_nstrms = min_t(unsigned int, num_possible_cpus(), +CONFIG_EROFS_FS_ZIP_LZMA_DEFAULT_MAX_STREAMS );for (i =0 ; i < z_erofs_lzma_nstrms; ++i) {struct z_erofs_lzma *strm =kzalloc (sizeof (*strm),GFP_KERNEL );
Signature · 1 line
2.53.0