kasan: few improvements on kunit tests
Subsystems (2)
cover kasan: few improvements on kunit tests
This patch series addresses the issue [1] with KASAN symbols used in the Kunit test, but exported as EXPORT_SYMBOL_GPL.
Also a small tweak of marking kasan_atomics() as KUNIT_CASE_SLOW to avoid kunit report that the test should be marked as slow.
Both patches have been tested on (CONFIG_KASAN_KUNIT_TEST=y):
- x86_64: CONFIG_KASAN=y
- arm64: CONFIG_KASAN_HW_TAGS=y
[1] https://lore.kernel.org/linux-mm/[email protected]/T/
EXPORT_SYMBOL_IF_KUNIT
Sabyrzhan Tasbolatov (2):
kasan: use EXPORT_SYMBOL_IF_KUNIT to export symbols for kunit tests
kasan: change kasan_atomics kunit test as KUNIT_CASE_SLOW
mm/kasan/hw_tags.c | 7 ++++--- mm/kasan/kasan_test_c.c | 4 +++- mm/kasan/report.c | 17 +++++++++-------- 3 files changed, 16 insertions(+), 12 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 kasan: use EXPORT_SYMBOL_IF_KUNIT to export symbols
Replace EXPORT_SYMBOL_GPL with EXPORT_SYMBOL_IF_KUNIT to mark the symbols as visible only if CONFIG_KUNIT is enabled.
KASAN Kunit test should import the namespace EXPORTED_FOR_KUNIT_TESTING to use these marked symbols.
--- mm/kasan/hw_tags.c | 7 ++++--- mm/kasan/kasan_test_c.c | 2 ++ mm/kasan/report.c | 17 +++++++++-------- 3 files changed, 15 insertions(+), 11 deletions(-)
mm/kasan/hw_tags.c +4 -3
@@ -8,6 +8,7 @@#define pr_fmt (fmt) "kasan: " fmt +#include <kunit/visibility.h> #include <linux/init.h> #include <linux/kasan.h> #include <linux/kernel.h>
@@ -394,12 +395,12 @@ void kasan_enable_hw_tags(void)#if IS_ENABLED (CONFIG_KASAN_KUNIT_TEST ) -EXPORT_SYMBOL_GPL (kasan_enable_hw_tags); +EXPORT_SYMBOL_IF_KUNIT (kasan_enable_hw_tags); -void kasan_force_async_fault (void ) +VISIBLE_IF_KUNIT void kasan_force_async_fault(void) {hw_force_async_tag_fault (); } -EXPORT_SYMBOL_GPL (kasan_force_async_fault); +EXPORT_SYMBOL_IF_KUNIT (kasan_force_async_fault);#endif
mm/kasan/kasan_test_c.c +2 -0
@@ -33,6 +33,8 @@#define OOB_TAG_OFF (IS_ENABLED(CONFIG_KASAN_GENERIC) ? 0 : KASAN_GRANULE_SIZE) +MODULE_IMPORT_NS (EXPORTED_FOR_KUNIT_TESTING ); +static bool multishot;/* Fields set based on lines observed in the console. */
mm/kasan/report.c +9 -8
@@ -10,6 +10,7 @@*/ #include <kunit/test.h> +#include <kunit/visibility.h> #include <linux/bitops.h> #include <linux/ftrace.h> #include <linux/init.h>
@@ -134,18 +135,18 @@ static bool report_enabled(void)#if IS_ENABLED (CONFIG_KASAN_KUNIT_TEST ) ||IS_ENABLED (CONFIG_KASAN_MODULE_TEST ) -bool kasan_save_enable_multi_shot (void ) +VISIBLE_IF_KUNIT bool kasan_save_enable_multi_shot(void) {return test_and_set_bit (KASAN_BIT_MULTI_SHOT , &kasan_flags); } -EXPORT_SYMBOL_GPL (kasan_save_enable_multi_shot); +EXPORT_SYMBOL_IF_KUNIT (kasan_save_enable_multi_shot); -void kasan_restore_multi_shot (bool enabled) +VISIBLE_IF_KUNIT void kasan_restore_multi_shot(bool enabled) {if (!enabled)clear_bit (KASAN_BIT_MULTI_SHOT , &kasan_flags); } -EXPORT_SYMBOL_GPL (kasan_restore_multi_shot); +EXPORT_SYMBOL_IF_KUNIT (kasan_restore_multi_shot);#endif
@@ -157,17 +158,17 @@ EXPORT_SYMBOL_GPL(kasan_restore_multi_shot);*/ static bool kasan_kunit_executing; -void kasan_kunit_test_suite_start (void ) +VISIBLE_IF_KUNIT void kasan_kunit_test_suite_start(void) {WRITE_ONCE (kasan_kunit_executing, true); } -EXPORT_SYMBOL_GPL (kasan_kunit_test_suite_start); +EXPORT_SYMBOL_IF_KUNIT (kasan_kunit_test_suite_start); -void kasan_kunit_test_suite_end (void ) +VISIBLE_IF_KUNIT void kasan_kunit_test_suite_end(void) {WRITE_ONCE (kasan_kunit_executing, false); } -EXPORT_SYMBOL_GPL (kasan_kunit_test_suite_end); +EXPORT_SYMBOL_IF_KUNIT (kasan_kunit_test_suite_end);static bool kasan_kunit_test_suite_executing (void ) {
Signature · 1 line
2.34.1
Re: [PATCH 1/2] kasan: use EXPORT_SYMBOL_IF_KUNIT to export symbols
Quoted 115 lines · Sabyrzhan Tasbolatov
Replace
EXPORT_SYMBOL_GPLwithEXPORT_SYMBOL_IF_KUNITto mark the symbols as visible only ifCONFIG_KUNITis enabled.KASAN Kunit test should import the namespace
EXPORTED_FOR_KUNIT_TESTINGto use these marked symbols.Reported-by Andrey Konovalov <[email protected]>Signed-off-by Sabyrzhan Tasbolatov <[email protected]>--- mm/kasan/hw_tags.c | 7 ++++--- mm/kasan/kasan_test_c.c | 2 ++ mm/kasan/report.c | 17 +++++++++-------- 3 files changed, 15 insertions(+), 11 deletions(-)mm/kasan/hw_tags.c +4
-3@@ -8,6 +8,7 @@#define pr_fmt (fmt) "kasan: " fmt +#include <kunit/visibility.h> #include <linux/init.h> #include <linux/kasan.h> #include <linux/kernel.h> @@ -394,12 +395,12 @@ void kasan_enable_hw_tags(void)#if IS_ENABLED (CONFIG_KASAN_KUNIT_TEST ) -EXPORT_SYMBOL_GPL (kasan_enable_hw_tags); +EXPORT_SYMBOL_IF_KUNIT (kasan_enable_hw_tags); -void kasan_force_async_fault (void ) +VISIBLE_IF_KUNIT void kasan_force_async_fault(void) {hw_force_async_tag_fault (); } -EXPORT_SYMBOL_GPL (kasan_force_async_fault); +EXPORT_SYMBOL_IF_KUNIT (kasan_force_async_fault);#endif mm/kasan/kasan_test_c.c +2
-0@@ -33,6 +33,8 @@#define OOB_TAG_OFF (IS_ENABLED(CONFIG_KASAN_GENERIC) ? 0 : KASAN_GRANULE_SIZE) +MODULE_IMPORT_NS (EXPORTED_FOR_KUNIT_TESTING ); +static bool multishot;/* Fields set based on lines observed in the console. */ mm/kasan/report.c +9
-9@@ -10,6 +10,7 @@*/ #include <kunit/test.h> +#include <kunit/visibility.h> #include <linux/bitops.h> #include <linux/ftrace.h> #include <linux/init.h> @@ -134,18 +135,18 @@ static bool report_enabled(void)#if IS_ENABLED (CONFIG_KASAN_KUNIT_TEST ) ||IS_ENABLED (CONFIG_KASAN_MODULE_TEST ) -bool kasan_save_enable_multi_shot (void ) +VISIBLE_IF_KUNIT bool kasan_save_enable_multi_shot(void) {return test_and_set_bit (KASAN_BIT_MULTI_SHOT , &kasan_flags); } -EXPORT_SYMBOL_GPL (kasan_save_enable_multi_shot); +EXPORT_SYMBOL_IF_KUNIT (kasan_save_enable_multi_shot); -void kasan_restore_multi_shot (bool enabled) +VISIBLE_IF_KUNIT void kasan_restore_multi_shot(bool enabled) {if (!enabled)clear_bit (KASAN_BIT_MULTI_SHOT , &kasan_flags); } -EXPORT_SYMBOL_GPL (kasan_restore_multi_shot); +EXPORT_SYMBOL_IF_KUNIT (kasan_restore_multi_shot);#endif @@ -157,17 +158,17 @@ EXPORT_SYMBOL_GPL(kasan_restore_multi_shot);*/ static bool kasan_kunit_executing; -void kasan_kunit_test_suite_start (void ) +VISIBLE_IF_KUNIT void kasan_kunit_test_suite_start(void) {WRITE_ONCE (kasan_kunit_executing, true); } -EXPORT_SYMBOL_GPL (kasan_kunit_test_suite_start); +EXPORT_SYMBOL_IF_KUNIT (kasan_kunit_test_suite_start); -void kasan_kunit_test_suite_end (void ) +VISIBLE_IF_KUNIT void kasan_kunit_test_suite_end(void) {WRITE_ONCE (kasan_kunit_executing, false); } -EXPORT_SYMBOL_GPL (kasan_kunit_test_suite_end); +EXPORT_SYMBOL_IF_KUNIT (kasan_kunit_test_suite_end);static bool kasan_kunit_test_suite_executing (void ) { --
Quoted 2 lines
2.34.1
Thank you!
kernel test robot
build botRe: [PATCH 1/2] kasan: use EXPORT_SYMBOL_IF_KUNIT to export symbols
In reply to Sabyrzhan Tasbolatovkernel test robot noticed the following build errors:
Hi Sabyrzhan,
kernel test robot noticed the following build errors:
[auto build test ERROR on v6.12-rc5]
[also build test ERROR on linus/master]
[cannot apply to akpm-mm/mm-everything]
[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/Sabyrzhan-Tasbolatov/kasan-use-EXPORT_SYMBOL_IF_KUNIT-to-export-symbols/20241102-024138 base: v6.12-rc5 patch link: https://lore.kernel.org/r/20241101184011.3369247-2-snovitoll%40gmail.com patch subject: [PATCH 1/2] kasan: use EXPORT_SYMBOL_IF_KUNIT to export symbols config: x86_64-randconfig-102-20241102 (https://download.01.org/0day-ci/archive/20241102/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241102/[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 >>, old ones prefixed by <<):
WARNING: modpost: missing MODULE_DESCRIPTION() in mm/kasan/kasan_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in mm/kasan/kasan_test_module.o
WARNING: modpost: missing MODULE_DESCRIPTION() in lib/slub_kunit.o
>> ERROR: modpost: module kasan_test_module uses symbol kasan_save_enable_multi_shot from namespace EXPORTED_FOR_KUNIT_TESTING, but does not import it. >> ERROR: modpost: module kasan_test_module uses symbol kasan_restore_multi_shot from namespace EXPORTED_FOR_KUNIT_TESTING, but does not import it.
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH 1/2] kasan: use EXPORT_SYMBOL_IF_KUNIT to export symbols
Sabyrzhan
Quoted 25 lines · kernel test robot
Hi Sabyrzhan,
kernel test robot noticed the following build errors:
[auto build test ERROR on v6.12-rc5]
[also build test ERROR on linus/master]
[cannot apply to akpm-mm/mm-everything]
[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/Sabyrzhan-Tasbolatov/kasan-use-EXPORT_SYMBOL_IF_KUNIT-to-export-symbols/20241102-024138 base: v6.12-rc5 patch link: https://lore.kernel.org/r/20241101184011.3369247-2-snovitoll%40gmail.com patch subject: [PATCH 1/2] kasan: use EXPORT_SYMBOL_IF_KUNIT to export symbols config: x86_64-randconfig-102-20241102 (https://download.01.org/0day-ci/archive/20241102/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241102/[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]/
Quoted 5 lines
All errors (new ones prefixed by >>, old ones prefixed by <<):
WARNING: modpost: missing
MODULE_DESCRIPTION()inmm/kasan/kasan_test.o
WARNING: modpost: missingMODULE_DESCRIPTION()inmm/kasan/kasan_test_module.o
WARNING: modpost: missingMODULE_DESCRIPTION()inlib/slub_kunit.o
I will make a v2 to add MODULE_DESCRIPTION().
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
ERROR: modpost: module
kasan_test_moduleuses symbolkasan_save_enable_multi_shotfrom namespaceEXPORTED_FOR_KUNIT_TESTING, but does not import it.
ERROR: modpost: modulekasan_test_moduleuses symbolkasan_restore_multi_shotfrom namespaceEXPORTED_FOR_KUNIT_TESTING, but does not import it.
kernel_test_module.c has been deleted in commit 906917f951ea("kasan:
migrate copy_user_test to kunit"), in linux-next tree.
So I'm not sure if I should include the header in this file.
Quoted 4 lines
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH 1/2] kasan: use EXPORT_SYMBOL_IF_KUNIT to export symbols
Quoted 30 lines · Sabyrzhan Tasbolatov
Sabyrzhan
Quoted 26 lines · kernel test robot
Hi Sabyrzhan,
kernel test robot noticed the following build errors:
[auto build test ERROR on v6.12-rc5]
[also build test ERROR on linus/master]
[cannot apply to akpm-mm/mm-everything]
[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/Sabyrzhan-Tasbolatov/kasan-use-EXPORT_SYMBOL_IF_KUNIT-to-export-symbols/20241102-024138 base: v6.12-rc5 patch link: https://lore.kernel.org/r/20241101184011.3369247-2-snovitoll%40gmail.com patch subject: [PATCH 1/2] kasan: use EXPORT_SYMBOL_IF_KUNIT to export symbols config: x86_64-randconfig-102-20241102 (https://download.01.org/0day-ci/archive/20241102/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241102/[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 >>, old ones prefixed by <<):
+ Andrey, please advise.
Quoted 6 lines
Quoted 4 lines
WARNING: modpost: missing
MODULE_DESCRIPTION()inmm/kasan/kasan_test.o
WARNING: modpost: missingMODULE_DESCRIPTION()inmm/kasan/kasan_test_module.o
WARNING: modpost: missingMODULE_DESCRIPTION()inlib/slub_kunit.oI will make a v2 to add
MODULE_DESCRIPTION().
I don't quite understand this as there is no mm/kasan/kasan_test.c, but kasan_test_c.c.
Also kasan_test_module.c is going to be removed in linux-next (patch is already there).
Should I create another patch or v2 of [1] my prev. patch with MODULE_DESCRIPTION()?
[1] https://lore.kernel.org/linux-mm/[email protected]/
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
ERROR: modpost: module
kasan_test_moduleuses symbolkasan_save_enable_multi_shotfrom namespaceEXPORTED_FOR_KUNIT_TESTING, but does not import it.
ERROR: modpost: modulekasan_test_moduleuses symbolkasan_restore_multi_shotfrom namespaceEXPORTED_FOR_KUNIT_TESTING, but does not import it.
kernel_test_module.chas been deleted in commit 906917f951ea("kasan:
migratecopy_user_testto kunit"), in linux-next tree.
So I'm not sure if I should include the header in this file.
Ditto here as well. Should I add #include <kunit/visibility.h> to kasan_test_module.c
which is deleted in linux-next tree?
Quoted 5 lines
Quoted 5 lines
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Andrey Konovalov
reviewerRe: [PATCH 1/2] kasan: use EXPORT_SYMBOL_IF_KUNIT to export symbols
Quoted 8 lines · Sabyrzhan Tasbolatov
Quoted 7 lines
Quoted 5 lines
WARNING: modpost: missing
MODULE_DESCRIPTION()inmm/kasan/kasan_test.o
WARNING: modpost: missingMODULE_DESCRIPTION()inmm/kasan/kasan_test_module.o
WARNING: modpost: missingMODULE_DESCRIPTION()inlib/slub_kunit.oI will make a v2 to add
MODULE_DESCRIPTION().
Quoted 8 lines
I don't quite understand this as there is no
mm/kasan/kasan_test.c, butkasan_test_c.c.
Alsokasan_test_module.cis going to be removed in linux-next (patch is already there).Should I create another patch or v2 of [1] my prev. patch with
MODULE_DESCRIPTION()?
[1] https://lore.kernel.org/linux-mm/[email protected]/
Adding MODULE_DESCRIPTION is unrelated to your patches, so it makes sense to send a separate patch to fix this report.
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
ERROR: modpost: module
kasan_test_moduleuses symbolkasan_save_enable_multi_shotfrom namespaceEXPORTED_FOR_KUNIT_TESTING, but does not import it.
ERROR: modpost: modulekasan_test_moduleuses symbolkasan_restore_multi_shotfrom namespaceEXPORTED_FOR_KUNIT_TESTING, but does not import it.
kernel_test_module.chas been deleted in commit 906917f951ea("kasan:
migratecopy_user_testto kunit"), in linux-next tree.
So I'm not sure if I should include the header in this file.Ditto here as well. Should I add #include <
kunit/visibility.h> tokasan_test_module.c
which is deleted in linux-next tree?
No, if the file is to be deleted by a queued patch, no need to fix anything in it. Just need to make sure that the same issue doesn't affect the queued patch.
Thanks!
PATCH 2/2 kasan: change kasan_atomics kunit test as KUNIT_CASE_SLOW
In reply to Sabyrzhan TasbolatovDuring running KASAN Kunit tests with CONFIG_KASAN enabled, the following "warning" is reported by kunit framework:
# kasan_atomics: Test should be marked slow (runtime: 2.604703115s)
It took 2.6 seconds on my PC (Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz), apparently, due to multiple atomic checks in kasan_atomics_helper().
Let's mark it with KUNIT_CASE_SLOW which reports now as:
# kasan_atomics.speed: slow
--- mm/kasan/kasan_test_c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/kasan/kasan_test_c.c +1 -1
@@ -2020,7 +2020,7 @@ static struct kunit_case kasan_kunit_test_cases[] = {KUNIT_CASE (kasan_strings),KUNIT_CASE (kasan_bitops_generic),KUNIT_CASE (kasan_bitops_tags), -KUNIT_CASE (kasan_atomics), +KUNIT_CASE_SLOW (kasan_atomics),KUNIT_CASE (vmalloc_helpers_tags),KUNIT_CASE (vmalloc_oob), KUNIT_CASE(vmap_tags),
Signature · 1 line
2.34.1
Re: [PATCH 2/2] kasan: change kasan_atomics kunit test as KUNIT_CASE_SLOW
Quoted 32 lines · Sabyrzhan Tasbolatov
During running KASAN Kunit tests with
CONFIG_KASANenabled, the following "warning" is reported by kunit framework:# kasan_atomics: Test should be marked slow (runtime: 2.604703115s)It took 2.6 seconds on my PC (Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz), apparently, due to multiple atomic checks in
kasan_atomics_helper().Let's mark it with
KUNIT_CASE_SLOWwhich reports now as:# kasan_atomics.speed: slow
Signed-off-by Sabyrzhan Tasbolatov <[email protected]>--- mm/kasan/kasan_test_c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/kasan/kasan_test_c.c +1
-2@@ -2020,7 +2020,7 @@ static struct kunit_case kasan_kunit_test_cases[] = {KUNIT_CASE (kasan_strings),KUNIT_CASE (kasan_bitops_generic),KUNIT_CASE (kasan_bitops_tags), -KUNIT_CASE (kasan_atomics), +KUNIT_CASE_SLOW (kasan_atomics),KUNIT_CASE (vmalloc_helpers_tags),KUNIT_CASE (vmalloc_oob), KUNIT_CASE(vmap_tags), --
Quoted 2 lines
2.34.1