Skip to content

Commit c28432a

Browse files
novitollakpm00
authored andcommitted
kasan: use EXPORT_SYMBOL_IF_KUNIT to export symbols
Patch series "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. This patch (of 2): 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. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Sabyrzhan Tasbolatov <[email protected]> Reported-by: Andrey Konovalov <[email protected]> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218315 Reviewed-by: Andrey Konovalov <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Marco Elver <[email protected]> Cc: Vincenzo Frascino <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent ad2bc88 commit c28432a

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

mm/kasan/hw_tags.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#define pr_fmt(fmt) "kasan: " fmt
1010

11+
#include <kunit/visibility.h>
1112
#include <linux/init.h>
1213
#include <linux/kasan.h>
1314
#include <linux/kernel.h>
@@ -394,12 +395,12 @@ void kasan_enable_hw_tags(void)
394395

395396
#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST)
396397

397-
EXPORT_SYMBOL_GPL(kasan_enable_hw_tags);
398+
EXPORT_SYMBOL_IF_KUNIT(kasan_enable_hw_tags);
398399

399-
void kasan_force_async_fault(void)
400+
VISIBLE_IF_KUNIT void kasan_force_async_fault(void)
400401
{
401402
hw_force_async_tag_fault();
402403
}
403-
EXPORT_SYMBOL_GPL(kasan_force_async_fault);
404+
EXPORT_SYMBOL_IF_KUNIT(kasan_force_async_fault);
404405

405406
#endif

mm/kasan/kasan_test_c.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
#define OOB_TAG_OFF (IS_ENABLED(CONFIG_KASAN_GENERIC) ? 0 : KASAN_GRANULE_SIZE)
3535

36+
MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING);
37+
3638
static bool multishot;
3739

3840
/* Fields set based on lines observed in the console. */

mm/kasan/report.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
#include <kunit/test.h>
13+
#include <kunit/visibility.h>
1314
#include <linux/bitops.h>
1415
#include <linux/ftrace.h>
1516
#include <linux/init.h>
@@ -134,18 +135,18 @@ static bool report_enabled(void)
134135

135136
#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST)
136137

137-
bool kasan_save_enable_multi_shot(void)
138+
VISIBLE_IF_KUNIT bool kasan_save_enable_multi_shot(void)
138139
{
139140
return test_and_set_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags);
140141
}
141-
EXPORT_SYMBOL_GPL(kasan_save_enable_multi_shot);
142+
EXPORT_SYMBOL_IF_KUNIT(kasan_save_enable_multi_shot);
142143

143-
void kasan_restore_multi_shot(bool enabled)
144+
VISIBLE_IF_KUNIT void kasan_restore_multi_shot(bool enabled)
144145
{
145146
if (!enabled)
146147
clear_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags);
147148
}
148-
EXPORT_SYMBOL_GPL(kasan_restore_multi_shot);
149+
EXPORT_SYMBOL_IF_KUNIT(kasan_restore_multi_shot);
149150

150151
#endif
151152

@@ -157,17 +158,17 @@ EXPORT_SYMBOL_GPL(kasan_restore_multi_shot);
157158
*/
158159
static bool kasan_kunit_executing;
159160

160-
void kasan_kunit_test_suite_start(void)
161+
VISIBLE_IF_KUNIT void kasan_kunit_test_suite_start(void)
161162
{
162163
WRITE_ONCE(kasan_kunit_executing, true);
163164
}
164-
EXPORT_SYMBOL_GPL(kasan_kunit_test_suite_start);
165+
EXPORT_SYMBOL_IF_KUNIT(kasan_kunit_test_suite_start);
165166

166-
void kasan_kunit_test_suite_end(void)
167+
VISIBLE_IF_KUNIT void kasan_kunit_test_suite_end(void)
167168
{
168169
WRITE_ONCE(kasan_kunit_executing, false);
169170
}
170-
EXPORT_SYMBOL_GPL(kasan_kunit_test_suite_end);
171+
EXPORT_SYMBOL_IF_KUNIT(kasan_kunit_test_suite_end);
171172

172173
static bool kasan_kunit_test_suite_executing(void)
173174
{

0 commit comments

Comments
 (0)