* [PATCH -next v3 0/2] erofs: reliably distinguish block based and fscache mode @ 2024-04-19 12:36 Baokun Li via Linux-erofs 2024-04-19 12:36 ` [PATCH -next v3 1/2] erofs: get rid of erofs_fs_context Baokun Li via Linux-erofs 2024-04-19 12:36 ` [PATCH -next v3 2/2] erofs: reliably distinguish block based and fscache mode Baokun Li via Linux-erofs 0 siblings, 2 replies; 12+ messages in thread From: Baokun Li via Linux-erofs @ 2024-04-19 12:36 UTC (permalink / raw) To: linux-erofs; +Cc: brauner, yangerkun, linux-kernel, huyue2, viro Hi Christian, As your original patch had some "DOS line endings", I failed at am it, so manually changed the relevant content when making v2, which caused Author to be modified, I just noticed this and corrected it, apologies for that. Changes since v2: Get rid of erofs_fs_context. Changes since v1: Allocate and initialise fc->s_fs_info in erofs_fc_get_tree() instead of modifying fc->sb_flags. V1: https://lore.kernel.org/r/20240415121746.1207242-1-libaokun1@huawei.com/ V2: https://lore.kernel.org/r/20240417065513.3409744-1-libaokun1@huawei.com/ Baokun Li (1): erofs: get rid of erofs_fs_context Christian Brauner (1): erofs: reliably distinguish block based and fscache mode fs/erofs/internal.h | 7 --- fs/erofs/super.c | 124 ++++++++++++++++++++------------------------ 2 files changed, 55 insertions(+), 76 deletions(-) -- 2.31.1 ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH -next v3 1/2] erofs: get rid of erofs_fs_context 2024-04-19 12:36 [PATCH -next v3 0/2] erofs: reliably distinguish block based and fscache mode Baokun Li via Linux-erofs @ 2024-04-19 12:36 ` Baokun Li via Linux-erofs 2024-04-22 10:25 ` Jingbo Xu ` (3 more replies) 2024-04-19 12:36 ` [PATCH -next v3 2/2] erofs: reliably distinguish block based and fscache mode Baokun Li via Linux-erofs 1 sibling, 4 replies; 12+ messages in thread From: Baokun Li via Linux-erofs @ 2024-04-19 12:36 UTC (permalink / raw) To: linux-erofs; +Cc: brauner, yangerkun, linux-kernel, huyue2, viro Instead of allocating the erofs_sb_info in fill_super() allocate it during erofs_init_fs_context() and ensure that erofs can always have the info available during erofs_kill_sb(). After this erofs_fs_context is no longer needed, replace ctx with sbi, no functional changes. Suggested-by: Jingbo Xu <jefflexu@linux.alibaba.com> Signed-off-by: Baokun Li <libaokun1@huawei.com> --- fs/erofs/internal.h | 7 --- fs/erofs/super.c | 116 ++++++++++++++++++++------------------------ 2 files changed, 53 insertions(+), 70 deletions(-) diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 39c67119f43b..d28ccfc0352b 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -84,13 +84,6 @@ struct erofs_dev_context { bool flatdev; }; -struct erofs_fs_context { - struct erofs_mount_opts opt; - struct erofs_dev_context *devs; - char *fsid; - char *domain_id; -}; - /* all filesystem-wide lz4 configurations */ struct erofs_sb_lz4_info { /* # of pages needed for EROFS lz4 rolling decompression */ diff --git a/fs/erofs/super.c b/fs/erofs/super.c index c0eb139adb07..21faa49bc970 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -370,18 +370,18 @@ static int erofs_read_superblock(struct super_block *sb) return ret; } -static void erofs_default_options(struct erofs_fs_context *ctx) +static void erofs_default_options(struct erofs_sb_info *sbi) { #ifdef CONFIG_EROFS_FS_ZIP - ctx->opt.cache_strategy = EROFS_ZIP_CACHE_READAROUND; - ctx->opt.max_sync_decompress_pages = 3; - ctx->opt.sync_decompress = EROFS_SYNC_DECOMPRESS_AUTO; + sbi->opt.cache_strategy = EROFS_ZIP_CACHE_READAROUND; + sbi->opt.max_sync_decompress_pages = 3; + sbi->opt.sync_decompress = EROFS_SYNC_DECOMPRESS_AUTO; #endif #ifdef CONFIG_EROFS_FS_XATTR - set_opt(&ctx->opt, XATTR_USER); + set_opt(&sbi->opt, XATTR_USER); #endif #ifdef CONFIG_EROFS_FS_POSIX_ACL - set_opt(&ctx->opt, POSIX_ACL); + set_opt(&sbi->opt, POSIX_ACL); #endif } @@ -426,16 +426,16 @@ static const struct fs_parameter_spec erofs_fs_parameters[] = { static bool erofs_fc_set_dax_mode(struct fs_context *fc, unsigned int mode) { #ifdef CONFIG_FS_DAX - struct erofs_fs_context *ctx = fc->fs_private; + struct erofs_sb_info *sbi = fc->s_fs_info; switch (mode) { case EROFS_MOUNT_DAX_ALWAYS: - set_opt(&ctx->opt, DAX_ALWAYS); - clear_opt(&ctx->opt, DAX_NEVER); + set_opt(&sbi->opt, DAX_ALWAYS); + clear_opt(&sbi->opt, DAX_NEVER); return true; case EROFS_MOUNT_DAX_NEVER: - set_opt(&ctx->opt, DAX_NEVER); - clear_opt(&ctx->opt, DAX_ALWAYS); + set_opt(&sbi->opt, DAX_NEVER); + clear_opt(&sbi->opt, DAX_ALWAYS); return true; default: DBG_BUGON(1); @@ -450,7 +450,7 @@ static bool erofs_fc_set_dax_mode(struct fs_context *fc, unsigned int mode) static int erofs_fc_parse_param(struct fs_context *fc, struct fs_parameter *param) { - struct erofs_fs_context *ctx = fc->fs_private; + struct erofs_sb_info *sbi = fc->s_fs_info; struct fs_parse_result result; struct erofs_device_info *dif; int opt, ret; @@ -463,9 +463,9 @@ static int erofs_fc_parse_param(struct fs_context *fc, case Opt_user_xattr: #ifdef CONFIG_EROFS_FS_XATTR if (result.boolean) - set_opt(&ctx->opt, XATTR_USER); + set_opt(&sbi->opt, XATTR_USER); else - clear_opt(&ctx->opt, XATTR_USER); + clear_opt(&sbi->opt, XATTR_USER); #else errorfc(fc, "{,no}user_xattr options not supported"); #endif @@ -473,16 +473,16 @@ static int erofs_fc_parse_param(struct fs_context *fc, case Opt_acl: #ifdef CONFIG_EROFS_FS_POSIX_ACL if (result.boolean) - set_opt(&ctx->opt, POSIX_ACL); + set_opt(&sbi->opt, POSIX_ACL); else - clear_opt(&ctx->opt, POSIX_ACL); + clear_opt(&sbi->opt, POSIX_ACL); #else errorfc(fc, "{,no}acl options not supported"); #endif break; case Opt_cache_strategy: #ifdef CONFIG_EROFS_FS_ZIP - ctx->opt.cache_strategy = result.uint_32; + sbi->opt.cache_strategy = result.uint_32; #else errorfc(fc, "compression not supported, cache_strategy ignored"); #endif @@ -504,27 +504,27 @@ static int erofs_fc_parse_param(struct fs_context *fc, kfree(dif); return -ENOMEM; } - down_write(&ctx->devs->rwsem); - ret = idr_alloc(&ctx->devs->tree, dif, 0, 0, GFP_KERNEL); - up_write(&ctx->devs->rwsem); + down_write(&sbi->devs->rwsem); + ret = idr_alloc(&sbi->devs->tree, dif, 0, 0, GFP_KERNEL); + up_write(&sbi->devs->rwsem); if (ret < 0) { kfree(dif->path); kfree(dif); return ret; } - ++ctx->devs->extra_devices; + ++sbi->devs->extra_devices; break; #ifdef CONFIG_EROFS_FS_ONDEMAND case Opt_fsid: - kfree(ctx->fsid); - ctx->fsid = kstrdup(param->string, GFP_KERNEL); - if (!ctx->fsid) + kfree(sbi->fsid); + sbi->fsid = kstrdup(param->string, GFP_KERNEL); + if (!sbi->fsid) return -ENOMEM; break; case Opt_domain_id: - kfree(ctx->domain_id); - ctx->domain_id = kstrdup(param->string, GFP_KERNEL); - if (!ctx->domain_id) + kfree(sbi->domain_id); + sbi->domain_id = kstrdup(param->string, GFP_KERNEL); + if (!sbi->domain_id) return -ENOMEM; break; #else @@ -581,8 +581,7 @@ static const struct export_operations erofs_export_ops = { static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) { struct inode *inode; - struct erofs_sb_info *sbi; - struct erofs_fs_context *ctx = fc->fs_private; + struct erofs_sb_info *sbi = EROFS_SB(sb); int err; sb->s_magic = EROFS_SUPER_MAGIC; @@ -590,19 +589,6 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) sb->s_maxbytes = MAX_LFS_FILESIZE; sb->s_op = &erofs_sops; - sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); - if (!sbi) - return -ENOMEM; - - sb->s_fs_info = sbi; - sbi->opt = ctx->opt; - sbi->devs = ctx->devs; - ctx->devs = NULL; - sbi->fsid = ctx->fsid; - ctx->fsid = NULL; - sbi->domain_id = ctx->domain_id; - ctx->domain_id = NULL; - sbi->blkszbits = PAGE_SHIFT; if (erofs_is_fscache_mode(sb)) { sb->s_blocksize = PAGE_SIZE; @@ -706,9 +692,9 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) static int erofs_fc_get_tree(struct fs_context *fc) { - struct erofs_fs_context *ctx = fc->fs_private; + struct erofs_sb_info *sbi = fc->s_fs_info; - if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && ctx->fsid) + if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && sbi->fsid) return get_tree_nodev(fc, erofs_fc_fill_super); return get_tree_bdev(fc, erofs_fc_fill_super); @@ -718,19 +704,19 @@ static int erofs_fc_reconfigure(struct fs_context *fc) { struct super_block *sb = fc->root->d_sb; struct erofs_sb_info *sbi = EROFS_SB(sb); - struct erofs_fs_context *ctx = fc->fs_private; + struct erofs_sb_info *new_sbi = fc->s_fs_info; DBG_BUGON(!sb_rdonly(sb)); - if (ctx->fsid || ctx->domain_id) + if (new_sbi->fsid || new_sbi->domain_id) erofs_info(sb, "ignoring reconfiguration for fsid|domain_id."); - if (test_opt(&ctx->opt, POSIX_ACL)) + if (test_opt(&new_sbi->opt, POSIX_ACL)) fc->sb_flags |= SB_POSIXACL; else fc->sb_flags &= ~SB_POSIXACL; - sbi->opt = ctx->opt; + sbi->opt = new_sbi->opt; fc->sb_flags |= SB_RDONLY; return 0; @@ -761,12 +747,15 @@ static void erofs_free_dev_context(struct erofs_dev_context *devs) static void erofs_fc_free(struct fs_context *fc) { - struct erofs_fs_context *ctx = fc->fs_private; + struct erofs_sb_info *sbi = fc->s_fs_info; + + if (!sbi) + return; - erofs_free_dev_context(ctx->devs); - kfree(ctx->fsid); - kfree(ctx->domain_id); - kfree(ctx); + erofs_free_dev_context(sbi->devs); + kfree(sbi->fsid); + kfree(sbi->domain_id); + kfree(sbi); } static const struct fs_context_operations erofs_context_ops = { @@ -778,21 +767,22 @@ static const struct fs_context_operations erofs_context_ops = { static int erofs_init_fs_context(struct fs_context *fc) { - struct erofs_fs_context *ctx; + struct erofs_sb_info *sbi; - ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); - if (!ctx) + sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); + if (!sbi) return -ENOMEM; - ctx->devs = kzalloc(sizeof(struct erofs_dev_context), GFP_KERNEL); - if (!ctx->devs) { - kfree(ctx); + + sbi->devs = kzalloc(sizeof(struct erofs_dev_context), GFP_KERNEL); + if (!sbi->devs) { + kfree(sbi); return -ENOMEM; } - fc->fs_private = ctx; + fc->s_fs_info = sbi; - idr_init(&ctx->devs->tree); - init_rwsem(&ctx->devs->rwsem); - erofs_default_options(ctx); + idr_init(&sbi->devs->tree); + init_rwsem(&sbi->devs->rwsem); + erofs_default_options(sbi); fc->ops = &erofs_context_ops; return 0; } -- 2.31.1 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH -next v3 1/2] erofs: get rid of erofs_fs_context 2024-04-19 12:36 ` [PATCH -next v3 1/2] erofs: get rid of erofs_fs_context Baokun Li via Linux-erofs @ 2024-04-22 10:25 ` Jingbo Xu 2024-04-22 11:31 ` Baokun Li via Linux-erofs 2024-04-23 10:37 ` Gao Xiang ` (2 subsequent siblings) 3 siblings, 1 reply; 12+ messages in thread From: Jingbo Xu @ 2024-04-22 10:25 UTC (permalink / raw) To: Baokun Li, linux-erofs; +Cc: brauner, yangerkun, linux-kernel, huyue2, viro On 4/19/24 8:36 PM, Baokun Li wrote: > @@ -761,12 +747,15 @@ static void erofs_free_dev_context(struct erofs_dev_context *devs) > > static void erofs_fc_free(struct fs_context *fc) > { > - struct erofs_fs_context *ctx = fc->fs_private; > + struct erofs_sb_info *sbi = fc->s_fs_info; > + > + if (!sbi) > + return; This is the only difference comparing to the original code literally. Is there any chance that fc->s_fs_info can be NULL when erofs_fc_free() is called? Otherwise looks good to me. -- Thanks, Jingbo ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH -next v3 1/2] erofs: get rid of erofs_fs_context 2024-04-22 10:25 ` Jingbo Xu @ 2024-04-22 11:31 ` Baokun Li via Linux-erofs 2024-04-22 11:39 ` Jingbo Xu 0 siblings, 1 reply; 12+ messages in thread From: Baokun Li via Linux-erofs @ 2024-04-22 11:31 UTC (permalink / raw) To: Jingbo Xu, linux-erofs; +Cc: brauner, yangerkun, linux-kernel, huyue2, viro Hi Jingbo, On 2024/4/22 18:25, Jingbo Xu wrote: > > On 4/19/24 8:36 PM, Baokun Li wrote: > >> @@ -761,12 +747,15 @@ static void erofs_free_dev_context(struct erofs_dev_context *devs) >> >> static void erofs_fc_free(struct fs_context *fc) >> { >> - struct erofs_fs_context *ctx = fc->fs_private; >> + struct erofs_sb_info *sbi = fc->s_fs_info; >> + >> + if (!sbi) >> + return; > > This is the only difference comparing to the original code literally. > Is there any chance that fc->s_fs_info can be NULL when erofs_fc_free() > is called? > > Otherwise looks good to me. > When sget_fc() executes successfully, fc->s_fs_info is set to NULL, so the following NULL pointer dereference may occur: do_new_mount vfs_get_tree erofs_fc_get_tree get_tree_bdev sget_dev sget_fc s = alloc_super s->s_fs_info = fc->s_fs_info; fc->s_fs_info = NULL; fill_super // return error deactivate_locked_super kfree(sbi); put_fs_context sbi = fc->s_fs_info kfree(sbi->fsid) Thank you very much for the review! -- With Best Regards, Baokun Li ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH -next v3 1/2] erofs: get rid of erofs_fs_context 2024-04-22 11:31 ` Baokun Li via Linux-erofs @ 2024-04-22 11:39 ` Jingbo Xu 0 siblings, 0 replies; 12+ messages in thread From: Jingbo Xu @ 2024-04-22 11:39 UTC (permalink / raw) To: Baokun Li, linux-erofs; +Cc: brauner, yangerkun, linux-kernel, huyue2, viro On 4/22/24 7:31 PM, Baokun Li wrote: > Hi Jingbo, > > On 2024/4/22 18:25, Jingbo Xu wrote: >> >> On 4/19/24 8:36 PM, Baokun Li wrote: >> >>> @@ -761,12 +747,15 @@ static void erofs_free_dev_context(struct >>> erofs_dev_context *devs) >>> static void erofs_fc_free(struct fs_context *fc) >>> { >>> - struct erofs_fs_context *ctx = fc->fs_private; >>> + struct erofs_sb_info *sbi = fc->s_fs_info; >>> + >>> + if (!sbi) >>> + return; >> >> This is the only difference comparing to the original code literally. >> Is there any chance that fc->s_fs_info can be NULL when erofs_fc_free() >> is called? >> >> Otherwise looks good to me. >> > When sget_fc() executes successfully, fc->s_fs_info is set to NULL, > so the following NULL pointer dereference may occur: > > do_new_mount > vfs_get_tree > erofs_fc_get_tree > get_tree_bdev > sget_dev > sget_fc > s = alloc_super > s->s_fs_info = fc->s_fs_info; > fc->s_fs_info = NULL; > fill_super > // return error > deactivate_locked_super > kfree(sbi); > put_fs_context > sbi = fc->s_fs_info > kfree(sbi->fsid) > Alright, fc->s_fs_info is transferred to s->s_fs_info and set to NULL. Feel free to add: Reviewed-by: Jingbo Xu <jefflexu@linux.alibaba.com> -- Thanks, Jingbo ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH -next v3 1/2] erofs: get rid of erofs_fs_context 2024-04-19 12:36 ` [PATCH -next v3 1/2] erofs: get rid of erofs_fs_context Baokun Li via Linux-erofs 2024-04-22 10:25 ` Jingbo Xu @ 2024-04-23 10:37 ` Gao Xiang 2024-04-28 7:10 ` Gao Xiang 2024-04-28 10:00 ` Chao Yu 3 siblings, 0 replies; 12+ messages in thread From: Gao Xiang @ 2024-04-23 10:37 UTC (permalink / raw) To: Baokun Li, linux-erofs; +Cc: brauner, yangerkun, linux-kernel, huyue2, viro On 2024/4/19 20:36, Baokun Li wrote: > Instead of allocating the erofs_sb_info in fill_super() allocate it during > erofs_init_fs_context() and ensure that erofs can always have the info > available during erofs_kill_sb(). After this erofs_fs_context is no longer > needed, replace ctx with sbi, no functional changes. > > Suggested-by: Jingbo Xu <jefflexu@linux.alibaba.com> > Signed-off-by: Baokun Li <libaokun1@huawei.com> Thanks, it looks good to me, let's see how it behaves after applying to -next. Thanks, Gao Xiang ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH -next v3 1/2] erofs: get rid of erofs_fs_context 2024-04-19 12:36 ` [PATCH -next v3 1/2] erofs: get rid of erofs_fs_context Baokun Li via Linux-erofs 2024-04-22 10:25 ` Jingbo Xu 2024-04-23 10:37 ` Gao Xiang @ 2024-04-28 7:10 ` Gao Xiang 2024-04-28 10:00 ` Chao Yu 3 siblings, 0 replies; 12+ messages in thread From: Gao Xiang @ 2024-04-28 7:10 UTC (permalink / raw) To: Baokun Li, linux-erofs; +Cc: brauner, yangerkun, linux-kernel, huyue2, viro On 2024/4/19 20:36, Baokun Li wrote: > Instead of allocating the erofs_sb_info in fill_super() allocate it during > erofs_init_fs_context() and ensure that erofs can always have the info > available during erofs_kill_sb(). After this erofs_fs_context is no longer > needed, replace ctx with sbi, no functional changes. > > Suggested-by: Jingbo Xu <jefflexu@linux.alibaba.com> > Signed-off-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com> Thanks, Gao Xiang ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH -next v3 1/2] erofs: get rid of erofs_fs_context 2024-04-19 12:36 ` [PATCH -next v3 1/2] erofs: get rid of erofs_fs_context Baokun Li via Linux-erofs ` (2 preceding siblings ...) 2024-04-28 7:10 ` Gao Xiang @ 2024-04-28 10:00 ` Chao Yu 3 siblings, 0 replies; 12+ messages in thread From: Chao Yu @ 2024-04-28 10:00 UTC (permalink / raw) To: Baokun Li, linux-erofs; +Cc: brauner, yangerkun, linux-kernel, huyue2, viro On 2024/4/19 20:36, Baokun Li wrote: > Instead of allocating the erofs_sb_info in fill_super() allocate it during > erofs_init_fs_context() and ensure that erofs can always have the info > available during erofs_kill_sb(). After this erofs_fs_context is no longer > needed, replace ctx with sbi, no functional changes. > > Suggested-by: Jingbo Xu <jefflexu@linux.alibaba.com> > Signed-off-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Chao Yu <chao@kernel.org> Thanks, ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH -next v3 2/2] erofs: reliably distinguish block based and fscache mode 2024-04-19 12:36 [PATCH -next v3 0/2] erofs: reliably distinguish block based and fscache mode Baokun Li via Linux-erofs 2024-04-19 12:36 ` [PATCH -next v3 1/2] erofs: get rid of erofs_fs_context Baokun Li via Linux-erofs @ 2024-04-19 12:36 ` Baokun Li via Linux-erofs 2024-04-22 11:52 ` Jingbo Xu ` (2 more replies) 1 sibling, 3 replies; 12+ messages in thread From: Baokun Li via Linux-erofs @ 2024-04-19 12:36 UTC (permalink / raw) To: linux-erofs; +Cc: brauner, yangerkun, linux-kernel, huyue2, viro From: Christian Brauner <brauner@kernel.org> When erofs_kill_sb() is called in block dev based mode, s_bdev may not have been initialised yet, and if CONFIG_EROFS_FS_ONDEMAND is enabled, it will be mistaken for fscache mode, and then attempt to free an anon_dev that has never been allocated, triggering the following warning: ============================================ ida_free called for id=0 which is not allocated. WARNING: CPU: 14 PID: 926 at lib/idr.c:525 ida_free+0x134/0x140 Modules linked in: CPU: 14 PID: 926 Comm: mount Not tainted 6.9.0-rc3-dirty #630 RIP: 0010:ida_free+0x134/0x140 Call Trace: <TASK> erofs_kill_sb+0x81/0x90 deactivate_locked_super+0x35/0x80 get_tree_bdev+0x136/0x1e0 vfs_get_tree+0x2c/0xf0 do_new_mount+0x190/0x2f0 [...] ============================================ Now when erofs_kill_sb() is called, erofs_sb_info must have been initialised, so use sbi->fsid to distinguish between the two modes. Signed-off-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Baokun Li <libaokun1@huawei.com> --- fs/erofs/super.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 21faa49bc970..30b49b2eee53 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -789,17 +789,13 @@ static int erofs_init_fs_context(struct fs_context *fc) static void erofs_kill_sb(struct super_block *sb) { - struct erofs_sb_info *sbi; + struct erofs_sb_info *sbi = EROFS_SB(sb); - if (erofs_is_fscache_mode(sb)) + if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && sbi->fsid) kill_anon_super(sb); else kill_block_super(sb); - sbi = EROFS_SB(sb); - if (!sbi) - return; - erofs_free_dev_context(sbi->devs); fs_put_dax(sbi->dax_dev, NULL); erofs_fscache_unregister_fs(sb); -- 2.31.1 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH -next v3 2/2] erofs: reliably distinguish block based and fscache mode 2024-04-19 12:36 ` [PATCH -next v3 2/2] erofs: reliably distinguish block based and fscache mode Baokun Li via Linux-erofs @ 2024-04-22 11:52 ` Jingbo Xu 2024-04-28 7:17 ` Gao Xiang 2024-04-28 10:03 ` Chao Yu 2 siblings, 0 replies; 12+ messages in thread From: Jingbo Xu @ 2024-04-22 11:52 UTC (permalink / raw) To: Baokun Li, linux-erofs; +Cc: brauner, yangerkun, linux-kernel, huyue2, viro On 4/19/24 8:36 PM, Baokun Li wrote: > From: Christian Brauner <brauner@kernel.org> > > When erofs_kill_sb() is called in block dev based mode, s_bdev may not > have been initialised yet, and if CONFIG_EROFS_FS_ONDEMAND is enabled, > it will be mistaken for fscache mode, and then attempt to free an anon_dev > that has never been allocated, triggering the following warning: > > ============================================ > ida_free called for id=0 which is not allocated. > WARNING: CPU: 14 PID: 926 at lib/idr.c:525 ida_free+0x134/0x140 > Modules linked in: > CPU: 14 PID: 926 Comm: mount Not tainted 6.9.0-rc3-dirty #630 > RIP: 0010:ida_free+0x134/0x140 > Call Trace: > <TASK> > erofs_kill_sb+0x81/0x90 > deactivate_locked_super+0x35/0x80 > get_tree_bdev+0x136/0x1e0 > vfs_get_tree+0x2c/0xf0 > do_new_mount+0x190/0x2f0 > [...] > ============================================ > > Now when erofs_kill_sb() is called, erofs_sb_info must have been > initialised, so use sbi->fsid to distinguish between the two modes. > > Signed-off-by: Christian Brauner <brauner@kernel.org> > Signed-off-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Jingbo Xu <jefflexu@linux.alibaba.com> > --- > fs/erofs/super.c | 8 ++------ > 1 file changed, 2 insertions(+), 6 deletions(-) > > diff --git a/fs/erofs/super.c b/fs/erofs/super.c > index 21faa49bc970..30b49b2eee53 100644 > --- a/fs/erofs/super.c > +++ b/fs/erofs/super.c > @@ -789,17 +789,13 @@ static int erofs_init_fs_context(struct fs_context *fc) > > static void erofs_kill_sb(struct super_block *sb) > { > - struct erofs_sb_info *sbi; > + struct erofs_sb_info *sbi = EROFS_SB(sb); > > - if (erofs_is_fscache_mode(sb)) > + if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && sbi->fsid) > kill_anon_super(sb); > else > kill_block_super(sb); > > - sbi = EROFS_SB(sb); > - if (!sbi) > - return; > - > erofs_free_dev_context(sbi->devs); > fs_put_dax(sbi->dax_dev, NULL); > erofs_fscache_unregister_fs(sb); -- Thanks, Jingbo ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH -next v3 2/2] erofs: reliably distinguish block based and fscache mode 2024-04-19 12:36 ` [PATCH -next v3 2/2] erofs: reliably distinguish block based and fscache mode Baokun Li via Linux-erofs 2024-04-22 11:52 ` Jingbo Xu @ 2024-04-28 7:17 ` Gao Xiang 2024-04-28 10:03 ` Chao Yu 2 siblings, 0 replies; 12+ messages in thread From: Gao Xiang @ 2024-04-28 7:17 UTC (permalink / raw) To: Baokun Li, linux-erofs; +Cc: brauner, yangerkun, linux-kernel, huyue2, viro On 2024/4/19 20:36, Baokun Li wrote: > From: Christian Brauner <brauner@kernel.org> > > When erofs_kill_sb() is called in block dev based mode, s_bdev may not > have been initialised yet, and if CONFIG_EROFS_FS_ONDEMAND is enabled, > it will be mistaken for fscache mode, and then attempt to free an anon_dev > that has never been allocated, triggering the following warning: > > ============================================ > ida_free called for id=0 which is not allocated. > WARNING: CPU: 14 PID: 926 at lib/idr.c:525 ida_free+0x134/0x140 > Modules linked in: > CPU: 14 PID: 926 Comm: mount Not tainted 6.9.0-rc3-dirty #630 > RIP: 0010:ida_free+0x134/0x140 > Call Trace: > <TASK> > erofs_kill_sb+0x81/0x90 > deactivate_locked_super+0x35/0x80 > get_tree_bdev+0x136/0x1e0 > vfs_get_tree+0x2c/0xf0 > do_new_mount+0x190/0x2f0 > [...] > ============================================ > > Now when erofs_kill_sb() is called, erofs_sb_info must have been > initialised, so use sbi->fsid to distinguish between the two modes. > > Signed-off-by: Christian Brauner <brauner@kernel.org> > Signed-off-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com> Thanks, Gao Xiang ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH -next v3 2/2] erofs: reliably distinguish block based and fscache mode 2024-04-19 12:36 ` [PATCH -next v3 2/2] erofs: reliably distinguish block based and fscache mode Baokun Li via Linux-erofs 2024-04-22 11:52 ` Jingbo Xu 2024-04-28 7:17 ` Gao Xiang @ 2024-04-28 10:03 ` Chao Yu 2 siblings, 0 replies; 12+ messages in thread From: Chao Yu @ 2024-04-28 10:03 UTC (permalink / raw) To: Baokun Li, linux-erofs; +Cc: brauner, yangerkun, linux-kernel, huyue2, viro On 2024/4/19 20:36, Baokun Li wrote: > From: Christian Brauner <brauner@kernel.org> > > When erofs_kill_sb() is called in block dev based mode, s_bdev may not > have been initialised yet, and if CONFIG_EROFS_FS_ONDEMAND is enabled, > it will be mistaken for fscache mode, and then attempt to free an anon_dev > that has never been allocated, triggering the following warning: > > ============================================ > ida_free called for id=0 which is not allocated. > WARNING: CPU: 14 PID: 926 at lib/idr.c:525 ida_free+0x134/0x140 > Modules linked in: > CPU: 14 PID: 926 Comm: mount Not tainted 6.9.0-rc3-dirty #630 > RIP: 0010:ida_free+0x134/0x140 > Call Trace: > <TASK> > erofs_kill_sb+0x81/0x90 > deactivate_locked_super+0x35/0x80 > get_tree_bdev+0x136/0x1e0 > vfs_get_tree+0x2c/0xf0 > do_new_mount+0x190/0x2f0 > [...] > ============================================ > > Now when erofs_kill_sb() is called, erofs_sb_info must have been > initialised, so use sbi->fsid to distinguish between the two modes. > > Signed-off-by: Christian Brauner <brauner@kernel.org> > Signed-off-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Chao Yu <chao@kernel.org> Thanks, ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2024-04-28 10:03 UTC | newest] Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-04-19 12:36 [PATCH -next v3 0/2] erofs: reliably distinguish block based and fscache mode Baokun Li via Linux-erofs 2024-04-19 12:36 ` [PATCH -next v3 1/2] erofs: get rid of erofs_fs_context Baokun Li via Linux-erofs 2024-04-22 10:25 ` Jingbo Xu 2024-04-22 11:31 ` Baokun Li via Linux-erofs 2024-04-22 11:39 ` Jingbo Xu 2024-04-23 10:37 ` Gao Xiang 2024-04-28 7:10 ` Gao Xiang 2024-04-28 10:00 ` Chao Yu 2024-04-19 12:36 ` [PATCH -next v3 2/2] erofs: reliably distinguish block based and fscache mode Baokun Li via Linux-erofs 2024-04-22 11:52 ` Jingbo Xu 2024-04-28 7:17 ` Gao Xiang 2024-04-28 10:03 ` Chao Yu
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).