Skip to contentSkip to conversation

kunit: run test suites only after module initialization completes

RFC PATCH New Marco Pagani 2 participants 2 messages Sep 27, 2023 – Sep 29, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 kunit: run test suites only after module initialization completes

Commit 2810c1e99867 ("kunit: Fix wild-memory-access bug in kunit_free_suite_set()") causes test suites to run while the test module is still in MODULE_STATE_COMING. In that state, the module is not fully initialized, lacking sysfs, module_memory, args, init function. This behavior can cause all sorts of problems while using fake devices.

This RFC patch restores the normal execution flow, waiting for module initialization to complete before running the tests, and uses the refcount to avoid calling kunit_free_suite_set() if load_module() fails.

Fixes 2810c1e99867 ("kunit: Fix wild-memory-access bug in kunit_free_suite_set()")
---
 lib/kunit/test.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/kunit/test.c +3 -3
index 421f13981412..242f26ad387a 100644
@@ -784,13 +784,13 @@ static int kunit_module_notify(struct notifier_block *nb, unsigned long val,
 
 	switch (val) {
 	case MODULE_STATE_LIVE:
+		kunit_module_init(mod);
 		break;
 	case MODULE_STATE_GOING:
-		kunit_module_exit(mod);
+		if (module_refcount(mod) == -1)
+			kunit_module_exit(mod);
 		break;
 	case MODULE_STATE_COMING:
-		kunit_module_init(mod);
-		break;
 	case MODULE_STATE_UNFORMED:
 		break;
 	}
Signature · 1 line
2.41.0
#1 lore raw
kernel test robot noticed the following build errors:

Hi Marco,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.6-rc3 next-20230929]
[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/Marco-Pagani/kunit-run-test-suites-only-after-module-initialization-completes/20230927-235155
base:   linus/master
patch link:    https://lore.kernel.org/r/20230927154828.122280-1-marpagan%40redhat.com
patch subject: [RFC PATCH] kunit: run test suites only after module initialization completes
config: csky-randconfig-002-20230929 (https://download.01.org/0day-ci/archive/20230929/[email protected]/config)
compiler: csky-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230929/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

lib/kunit/test.c: In function 'kunit_module_notify':

>> lib/kunit/test.c:790:21: error: implicit declaration of function 'module_refcount' [-Werror=implicit-function-declaration]
     790 |                 if (module_refcount(mod) == -1)
         |                     ^~~~~~~~~~~~~~~

cc1: some warnings being treated as errors

vim +/module_refcount +790 lib/kunit/test.c

779
780 static int kunit_module_notify(struct notifier_block *nb, unsigned long val,
781 void *data)
782 {
783 struct module *mod = data;
784
785 switch (val) {
786 case MODULE_STATE_LIVE:
787 kunit_module_init(mod);
788 break;
789 case MODULE_STATE_GOING:

 > 790			if (module_refcount(mod) == -1)

791 kunit_module_exit(mod);
792 break;
793 case MODULE_STATE_COMING:
794 case MODULE_STATE_UNFORMED:
795 break;
796 }
797
798 return 0;
799 }
800

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki