Skip to content

Commit 8020791

Browse files
xairytorvalds
authored andcommitted
kasan: move and hide kasan_save_enable/restore_multi_shot
- Move kasan_save_enable/restore_multi_shot() declarations to mm/kasan/kasan.h, as there is no need for them to be visible outside of KASAN implementation. - Only define and export these functions when KASAN tests are enabled. - Move their definitions closer to other test-related code in report.c. Link: https://lkml.kernel.org/r/6ba637333b78447f027d775f2d55ab1a40f63c99.1646237226.git.andreyknvl@google.com Signed-off-by: Andrey Konovalov <andreyknvl@google.com> Cc: Alexander Potapenko <glider@google.com> Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Marco Elver <elver@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 865bfa2 commit 8020791

3 files changed

Lines changed: 24 additions & 17 deletions

File tree

include/linux/kasan.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,6 @@ static __always_inline bool kasan_check_byte(const void *addr)
267267
return true;
268268
}
269269

270-
271-
bool kasan_save_enable_multi_shot(void);
272-
void kasan_restore_multi_shot(bool enabled);
273-
274270
#else /* CONFIG_KASAN */
275271

276272
static inline slab_flags_t kasan_never_merge(void)

mm/kasan/kasan.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,13 @@ static inline bool kasan_arch_is_ready(void) { return true; }
492492
#error kasan_arch_is_ready only works in KASAN generic outline mode!
493493
#endif
494494

495+
#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST) || IS_ENABLED(CONFIG_KASAN_MODULE_TEST)
496+
497+
bool kasan_save_enable_multi_shot(void);
498+
void kasan_restore_multi_shot(bool enabled);
499+
500+
#endif
501+
495502
/*
496503
* Exported functions for interfaces called from assembly or from generated
497504
* code. Declarations here to avoid warning about missing declarations.

mm/kasan/report.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,6 @@ static int __init early_kasan_fault(char *arg)
6464
}
6565
early_param("kasan.fault", early_kasan_fault);
6666

67-
bool kasan_save_enable_multi_shot(void)
68-
{
69-
return test_and_set_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags);
70-
}
71-
EXPORT_SYMBOL_GPL(kasan_save_enable_multi_shot);
72-
73-
void kasan_restore_multi_shot(bool enabled)
74-
{
75-
if (!enabled)
76-
clear_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags);
77-
}
78-
EXPORT_SYMBOL_GPL(kasan_restore_multi_shot);
79-
8067
static int __init kasan_set_multi_shot(char *str)
8168
{
8269
set_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags);
@@ -109,6 +96,23 @@ static bool report_enabled(void)
10996
return !test_and_set_bit(KASAN_BIT_REPORTED, &kasan_flags);
11097
}
11198

99+
#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST) || IS_ENABLED(CONFIG_KASAN_MODULE_TEST)
100+
101+
bool kasan_save_enable_multi_shot(void)
102+
{
103+
return test_and_set_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags);
104+
}
105+
EXPORT_SYMBOL_GPL(kasan_save_enable_multi_shot);
106+
107+
void kasan_restore_multi_shot(bool enabled)
108+
{
109+
if (!enabled)
110+
clear_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags);
111+
}
112+
EXPORT_SYMBOL_GPL(kasan_restore_multi_shot);
113+
114+
#endif
115+
112116
#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST)
113117
static void update_kunit_status(bool sync)
114118
{

0 commit comments

Comments
 (0)