diff mbox series

[2/4] btrfs: Use module_subinit{_noexit} and module_subeixt helper macros

Message ID 20240723083239.41533-3-youling.tang@linux.dev (mailing list archive)
State New, archived
Headers show
Series Add module_subinit{_noexit} and module_subeixt helper macros | expand

Commit Message

Youling Tang July 23, 2024, 8:32 a.m. UTC
From: Youling Tang <tangyouling@kylinos.cn>

Use module_{subinit, subinit} to ensure that modules init and exit
are in sequence and to simplify the code.

Signed-off-by: Youling Tang <tangyouling@kylinos.cn>
---
 fs/btrfs/super.c | 123 +++++++++--------------------------------------
 1 file changed, 23 insertions(+), 100 deletions(-)

Comments

kernel test robot July 23, 2024, 10:24 p.m. UTC | #1
Hi Youling,

kernel test robot noticed the following build warnings:

[auto build test WARNING on kdave/for-next]
[also build test WARNING on linus/master next-20240723]
[cannot apply to jaegeuk-f2fs/dev-test jaegeuk-f2fs/dev soc/for-next v6.10]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Youling-Tang/module-Add-module_subinit-_noexit-and-module_subeixt-helper-macros/20240723-164434
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
patch link:    https://lore.kernel.org/r/20240723083239.41533-3-youling.tang%40linux.dev
patch subject: [PATCH 2/4] btrfs: Use module_subinit{_noexit} and module_subeixt helper macros
config: arm64-randconfig-004-20240724 (https://download.01.org/0day-ci/archive/20240724/202407240648.afyUbKEP-lkp@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240724/202407240648.afyUbKEP-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202407240648.afyUbKEP-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> aarch64-linux-ld: warning: orphan section `.subexitcall.exit' from `fs/btrfs/super.o' being placed in section `.subexitcall.exit'
>> aarch64-linux-ld: warning: orphan section `.subinitcall.init' from `fs/btrfs/super.o' being placed in section `.subinitcall.init'
>> aarch64-linux-ld: warning: orphan section `.subexitcall.exit' from `fs/btrfs/super.o' being placed in section `.subexitcall.exit'
>> aarch64-linux-ld: warning: orphan section `.subinitcall.init' from `fs/btrfs/super.o' being placed in section `.subinitcall.init'
>> aarch64-linux-ld: warning: orphan section `.subexitcall.exit' from `fs/btrfs/super.o' being placed in section `.subexitcall.exit'
>> aarch64-linux-ld: warning: orphan section `.subinitcall.init' from `fs/btrfs/super.o' being placed in section `.subinitcall.init'
Youling Tang July 24, 2024, 6:29 a.m. UTC | #2
On 24/07/2024 06:24, kernel test robot wrote:
> Hi Youling,
>
> kernel test robot noticed the following build warnings:
>
> [auto build test WARNING on kdave/for-next]
> [also build test WARNING on linus/master next-20240723]
> [cannot apply to jaegeuk-f2fs/dev-test jaegeuk-f2fs/dev soc/for-next v6.10]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
>
> url:    https://github.com/intel-lab-lkp/linux/commits/Youling-Tang/module-Add-module_subinit-_noexit-and-module_subeixt-helper-macros/20240723-164434
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
> patch link:    https://lore.kernel.org/r/20240723083239.41533-3-youling.tang%40linux.dev
> patch subject: [PATCH 2/4] btrfs: Use module_subinit{_noexit} and module_subeixt helper macros
> config: arm64-randconfig-004-20240724 (https://download.01.org/0day-ci/archive/20240724/202407240648.afyUbKEP-lkp@intel.com/config)
> compiler: aarch64-linux-gcc (GCC) 14.1.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240724/202407240648.afyUbKEP-lkp@intel.com/reproduce)
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202407240648.afyUbKEP-lkp@intel.com/
>
> All warnings (new ones prefixed by >>):
>
>>> aarch64-linux-ld: warning: orphan section `.subexitcall.exit' from `fs/btrfs/super.o' being placed in section `.subexitcall.exit'
>>> aarch64-linux-ld: warning: orphan section `.subinitcall.init' from `fs/btrfs/super.o' being placed in section `.subinitcall.init'
>>> aarch64-linux-ld: warning: orphan section `.subexitcall.exit' from `fs/btrfs/super.o' being placed in section `.subexitcall.exit'
>>> aarch64-linux-ld: warning: orphan section `.subinitcall.init' from `fs/btrfs/super.o' being placed in section `.subinitcall.init'
>>> aarch64-linux-ld: warning: orphan section `.subexitcall.exit' from `fs/btrfs/super.o' being placed in section `.subexitcall.exit'
>>> aarch64-linux-ld: warning: orphan section `.subinitcall.init' from `fs/btrfs/super.o' being placed in section `.subinitcall.init'
The warning above is because arm64 does not use INIT_DATA_SECTION in link
scripts (some other architectures have similar problems), and it will be 
fixed
with the following changes:

```
diff --git a/arch/arc/kernel/vmlinux.lds.S b/arch/arc/kernel/vmlinux.lds.S
index 61a1b2b96e1d..2e3ce4c98550 100644
--- a/arch/arc/kernel/vmlinux.lds.S
+++ b/arch/arc/kernel/vmlinux.lds.S
@@ -66,6 +66,7 @@ SECTIONS
                 INIT_DATA
                 INIT_SETUP(L1_CACHE_BYTES)
                 INIT_CALLS
+               SUBINIT_CALL
                 CON_INITCALL
         }

diff --git a/arch/arm/kernel/vmlinux-xip.lds.S 
b/arch/arm/kernel/vmlinux-xip.lds.S
index c16d196b5aad..c9c2880db953 100644
--- a/arch/arm/kernel/vmlinux-xip.lds.S
+++ b/arch/arm/kernel/vmlinux-xip.lds.S
@@ -94,6 +94,7 @@ SECTIONS
         .init.rodata : {
                 INIT_SETUP(16)
                 INIT_CALLS
+               SUBINIT_CALL
                 CON_INITCALL
                 INIT_RAM_FS
         }
diff --git a/arch/arm64/kernel/vmlinux.lds.S 
b/arch/arm64/kernel/vmlinux.lds.S
index 55a8e310ea12..35549fb50cd2 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -256,6 +256,7 @@ SECTIONS
                 INIT_DATA
                 INIT_SETUP(16)
                 INIT_CALLS
+               SUBINIT_CALL
                 CON_INITCALL
                 INIT_RAM_FS
                 *(.init.altinstructions .init.bss)      /* from the EFI 
stub */
diff --git a/arch/microblaze/kernel/vmlinux.lds.S 
b/arch/microblaze/kernel/vmlinux.lds.S
index ae50d3d04a7d..113bbe4fe0fd 100644
--- a/arch/microblaze/kernel/vmlinux.lds.S
+++ b/arch/microblaze/kernel/vmlinux.lds.S
@@ -115,6 +115,10 @@ SECTIONS {
                 INIT_CALLS
         }

+       .subinitcall.init : AT(ADDR(.subinitcall.init) - LOAD_OFFSET ) {
+               SUBINIT_CALL
+       }
+
         .con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) {
                 CON_INITCALL
         }
diff --git a/arch/riscv/kernel/vmlinux-xip.lds.S 
b/arch/riscv/kernel/vmlinux-xip.lds.S
index 8c3daa1b0531..cfb108fe9d5c 100644
--- a/arch/riscv/kernel/vmlinux-xip.lds.S
+++ b/arch/riscv/kernel/vmlinux-xip.lds.S
@@ -55,6 +55,7 @@ SECTIONS
         .init.rodata : {
                 INIT_SETUP(16)
                 INIT_CALLS
+               SUBINIT_CALL
                 CON_INITCALL
                 INIT_RAM_FS
         }
diff --git a/arch/um/include/asm/common.lds.S 
b/arch/um/include/asm/common.lds.S
index fd481ac371de..59286d987936 100644
--- a/arch/um/include/asm/common.lds.S
+++ b/arch/um/include/asm/common.lds.S
@@ -48,6 +48,10 @@
         INIT_CALLS
    }

+  .subinitcall.init : {
+       SUBINIT_CALL
+  }
+
    .con_initcall.init : {
         CON_INITCALL
    }
diff --git a/arch/xtensa/kernel/vmlinux.lds.S 
b/arch/xtensa/kernel/vmlinux.lds.S
index f47e9bbbd291..1f4f921d9068 100644
--- a/arch/xtensa/kernel/vmlinux.lds.S
+++ b/arch/xtensa/kernel/vmlinux.lds.S
@@ -219,6 +219,7 @@ SECTIONS

      INIT_SETUP(XCHAL_ICACHE_LINESIZE)
      INIT_CALLS
+    SUBINIT_CALL
      CON_INITCALL
      INIT_RAM_FS
    }
```
diff mbox series

Patch

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 08d33cb372fb..620493b3f319 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -2490,115 +2490,38 @@  static void unregister_btrfs(void)
 	unregister_filesystem(&btrfs_fs_type);
 }
 
-/* Helper structure for long init/exit functions. */
-struct init_sequence {
-	int (*init_func)(void);
-	/* Can be NULL if the init_func doesn't need cleanup. */
-	void (*exit_func)(void);
-};
-
-static const struct init_sequence mod_init_seq[] = {
-	{
-		.init_func = btrfs_props_init,
-		.exit_func = NULL,
-	}, {
-		.init_func = btrfs_init_sysfs,
-		.exit_func = btrfs_exit_sysfs,
-	}, {
-		.init_func = btrfs_init_compress,
-		.exit_func = btrfs_exit_compress,
-	}, {
-		.init_func = btrfs_init_cachep,
-		.exit_func = btrfs_destroy_cachep,
-	}, {
-		.init_func = btrfs_init_dio,
-		.exit_func = btrfs_destroy_dio,
-	}, {
-		.init_func = btrfs_transaction_init,
-		.exit_func = btrfs_transaction_exit,
-	}, {
-		.init_func = btrfs_ctree_init,
-		.exit_func = btrfs_ctree_exit,
-	}, {
-		.init_func = btrfs_free_space_init,
-		.exit_func = btrfs_free_space_exit,
-	}, {
-		.init_func = extent_state_init_cachep,
-		.exit_func = extent_state_free_cachep,
-	}, {
-		.init_func = extent_buffer_init_cachep,
-		.exit_func = extent_buffer_free_cachep,
-	}, {
-		.init_func = btrfs_bioset_init,
-		.exit_func = btrfs_bioset_exit,
-	}, {
-		.init_func = extent_map_init,
-		.exit_func = extent_map_exit,
-	}, {
-		.init_func = ordered_data_init,
-		.exit_func = ordered_data_exit,
-	}, {
-		.init_func = btrfs_delayed_inode_init,
-		.exit_func = btrfs_delayed_inode_exit,
-	}, {
-		.init_func = btrfs_auto_defrag_init,
-		.exit_func = btrfs_auto_defrag_exit,
-	}, {
-		.init_func = btrfs_delayed_ref_init,
-		.exit_func = btrfs_delayed_ref_exit,
-	}, {
-		.init_func = btrfs_prelim_ref_init,
-		.exit_func = btrfs_prelim_ref_exit,
-	}, {
-		.init_func = btrfs_interface_init,
-		.exit_func = btrfs_interface_exit,
-	}, {
-		.init_func = btrfs_print_mod_info,
-		.exit_func = NULL,
-	}, {
-		.init_func = btrfs_run_sanity_tests,
-		.exit_func = NULL,
-	}, {
-		.init_func = register_btrfs,
-		.exit_func = unregister_btrfs,
-	}
-};
-
-static bool mod_init_result[ARRAY_SIZE(mod_init_seq)];
-
-static __always_inline void btrfs_exit_btrfs_fs(void)
-{
-	int i;
-
-	for (i = ARRAY_SIZE(mod_init_seq) - 1; i >= 0; i--) {
-		if (!mod_init_result[i])
-			continue;
-		if (mod_init_seq[i].exit_func)
-			mod_init_seq[i].exit_func();
-		mod_init_result[i] = false;
-	}
-}
+static struct subexitcall_rollback rollback;
 
 static void __exit exit_btrfs_fs(void)
 {
-	btrfs_exit_btrfs_fs();
+	module_subexit(&rollback);
 	btrfs_cleanup_fs_uuids();
 }
 
 static int __init init_btrfs_fs(void)
 {
-	int ret;
-	int i;
+	module_subinit_noexit(btrfs_props_init, &rollback);
+	module_subinit(btrfs_init_sysfs, btrfs_exit_sysfs, &rollback);
+	module_subinit(btrfs_init_compress, btrfs_exit_compress, &rollback);
+	module_subinit(btrfs_init_cachep, btrfs_destroy_cachep, &rollback);
+	module_subinit(btrfs_init_dio, btrfs_destroy_dio, &rollback);
+	module_subinit(btrfs_transaction_init, btrfs_transaction_exit, &rollback);
+	module_subinit(btrfs_ctree_init, btrfs_ctree_exit, &rollback);
+	module_subinit(btrfs_free_space_init, btrfs_free_space_exit, &rollback);
+	module_subinit(extent_state_init_cachep, extent_state_free_cachep, &rollback);
+	module_subinit(extent_buffer_init_cachep, extent_buffer_free_cachep, &rollback);
+	module_subinit(btrfs_bioset_init, btrfs_bioset_exit, &rollback);
+	module_subinit(extent_map_init, extent_map_exit, &rollback);
+	module_subinit(ordered_data_init, ordered_data_exit, &rollback);
+	module_subinit(btrfs_delayed_inode_init, btrfs_delayed_inode_exit, &rollback);
+	module_subinit(btrfs_auto_defrag_init, btrfs_auto_defrag_exit, &rollback);
+	module_subinit(btrfs_delayed_ref_init, btrfs_delayed_ref_exit, &rollback);
+	module_subinit(btrfs_prelim_ref_init, btrfs_prelim_ref_exit, &rollback);
+	module_subinit(btrfs_interface_init, btrfs_interface_exit, &rollback);
+	module_subinit_noexit(btrfs_print_mod_info, &rollback);
+	module_subinit_noexit(btrfs_run_sanity_tests, &rollback);
+	module_subinit(register_btrfs, unregister_btrfs, &rollback);
 
-	for (i = 0; i < ARRAY_SIZE(mod_init_seq); i++) {
-		ASSERT(!mod_init_result[i]);
-		ret = mod_init_seq[i].init_func();
-		if (ret < 0) {
-			btrfs_exit_btrfs_fs();
-			return ret;
-		}
-		mod_init_result[i] = true;
-	}
 	return 0;
 }