Skip to content

Commit 7672150

Browse files
mrutland-armctmarinas
authored andcommitted
arm64: kasan: mte: remove redundant mte_report_once logic
We have special logic to suppress MTE tag check fault reporting, based on a global `mte_report_once` and `reported` variables. These can be used to suppress calling kasan_report() when taking a tag check fault, but do not prevent taking the fault in the first place, nor does they affect the way we disable tag checks upon taking a fault. The core KASAN code already defaults to reporting a single fault, and has a `multi_shot` control to permit reporting multiple faults. The only place we transiently alter `mte_report_once` is in lib/test_kasan.c, where we also the `multi_shot` state as the same time. Thus `mte_report_once` and `reported` are redundant, and can be removed. When a tag check fault is taken, tag checking will be disabled by `do_tag_recovery` and must be explicitly re-enabled if desired. The test code does this by calling kasan_enable_tagging_sync(). This patch removes the redundant mte_report_once() logic and associated variables. Signed-off-by: Mark Rutland <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Andrey Konovalov <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Will Deacon <[email protected]> Cc: Vincenzo Frascino <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Reviewed-by: Andrey Konovalov <[email protected]> Tested-by: Andrey Konovalov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 8286824 commit 7672150

File tree

7 files changed

+1
-54
lines changed

7 files changed

+1
-54
lines changed

arch/arm64/include/asm/memory.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ static inline const void *__tag_set(const void *addr, u8 tag)
243243
#ifdef CONFIG_KASAN_HW_TAGS
244244
#define arch_enable_tagging_sync() mte_enable_kernel_sync()
245245
#define arch_enable_tagging_async() mte_enable_kernel_async()
246-
#define arch_set_tagging_report_once(state) mte_set_report_once(state)
247246
#define arch_force_async_tag_fault() mte_check_tfsr_exit()
248247
#define arch_get_random_tag() mte_get_random_tag()
249248
#define arch_get_mem_tag(addr) mte_get_mem_tag(addr)

arch/arm64/include/asm/mte-kasan.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,6 @@ static inline void mte_set_mem_tag_range(void *addr, size_t size, u8 tag,
131131
void mte_enable_kernel_sync(void);
132132
void mte_enable_kernel_async(void);
133133

134-
void mte_set_report_once(bool state);
135-
bool mte_report_once(void);
136-
137134
#else /* CONFIG_ARM64_MTE */
138135

139136
static inline u8 mte_get_ptr_tag(void *ptr)
@@ -164,15 +161,6 @@ static inline void mte_enable_kernel_async(void)
164161
{
165162
}
166163

167-
static inline void mte_set_report_once(bool state)
168-
{
169-
}
170-
171-
static inline bool mte_report_once(void)
172-
{
173-
return false;
174-
}
175-
176164
#endif /* CONFIG_ARM64_MTE */
177165

178166
#endif /* __ASSEMBLY__ */

arch/arm64/kernel/mte.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#include <asm/ptrace.h>
2424
#include <asm/sysreg.h>
2525

26-
static bool report_fault_once = true;
27-
2826
static DEFINE_PER_CPU_READ_MOSTLY(u64, mte_tcf_preferred);
2927

3028
#ifdef CONFIG_KASAN_HW_TAGS
@@ -141,16 +139,6 @@ void mte_enable_kernel_async(void)
141139
}
142140
#endif
143141

144-
void mte_set_report_once(bool state)
145-
{
146-
WRITE_ONCE(report_fault_once, state);
147-
}
148-
149-
bool mte_report_once(void)
150-
{
151-
return READ_ONCE(report_fault_once);
152-
}
153-
154142
#ifdef CONFIG_KASAN_HW_TAGS
155143
void mte_check_tfsr_el1(void)
156144
{

arch/arm64/mm/fault.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -309,24 +309,11 @@ static void die_kernel_fault(const char *msg, unsigned long addr,
309309
static void report_tag_fault(unsigned long addr, unsigned int esr,
310310
struct pt_regs *regs)
311311
{
312-
static bool reported;
313-
bool is_write;
314-
315-
if (READ_ONCE(reported))
316-
return;
317-
318-
/*
319-
* This is used for KASAN tests and assumes that no MTE faults
320-
* happened before running the tests.
321-
*/
322-
if (mte_report_once())
323-
WRITE_ONCE(reported, true);
324-
325312
/*
326313
* SAS bits aren't set for all faults reported in EL1, so we can't
327314
* find out access size.
328315
*/
329-
is_write = !!(esr & ESR_ELx_WNR);
316+
bool is_write = !!(esr & ESR_ELx_WNR);
330317
kasan_report(addr, 0, is_write, regs->pc);
331318
}
332319
#else

lib/test_kasan.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ static int kasan_test_init(struct kunit *test)
5353
}
5454

5555
multishot = kasan_save_enable_multi_shot();
56-
kasan_set_tagging_report_once(false);
5756
fail_data.report_found = false;
5857
kunit_add_named_resource(test, NULL, NULL, &resource,
5958
"kasan_data", &fail_data);
@@ -62,7 +61,6 @@ static int kasan_test_init(struct kunit *test)
6261

6362
static void kasan_test_exit(struct kunit *test)
6463
{
65-
kasan_set_tagging_report_once(true);
6664
kasan_restore_multi_shot(multishot);
6765
KUNIT_EXPECT_FALSE(test, fail_data.report_found);
6866
}

mm/kasan/hw_tags.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,6 @@ void kasan_free_pages(struct page *page, unsigned int order)
248248

249249
#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST)
250250

251-
void kasan_set_tagging_report_once(bool state)
252-
{
253-
hw_set_tagging_report_once(state);
254-
}
255-
EXPORT_SYMBOL_GPL(kasan_set_tagging_report_once);
256-
257251
void kasan_enable_tagging_sync(void)
258252
{
259253
hw_enable_tagging_sync();

mm/kasan/kasan.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,6 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag)
290290
#ifndef arch_enable_tagging_async
291291
#define arch_enable_tagging_async()
292292
#endif
293-
#ifndef arch_set_tagging_report_once
294-
#define arch_set_tagging_report_once(state)
295-
#endif
296293
#ifndef arch_force_async_tag_fault
297294
#define arch_force_async_tag_fault()
298295
#endif
@@ -308,7 +305,6 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag)
308305

309306
#define hw_enable_tagging_sync() arch_enable_tagging_sync()
310307
#define hw_enable_tagging_async() arch_enable_tagging_async()
311-
#define hw_set_tagging_report_once(state) arch_set_tagging_report_once(state)
312308
#define hw_force_async_tag_fault() arch_force_async_tag_fault()
313309
#define hw_get_random_tag() arch_get_random_tag()
314310
#define hw_get_mem_tag(addr) arch_get_mem_tag(addr)
@@ -319,19 +315,16 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag)
319315

320316
#define hw_enable_tagging_sync()
321317
#define hw_enable_tagging_async()
322-
#define hw_set_tagging_report_once(state)
323318

324319
#endif /* CONFIG_KASAN_HW_TAGS */
325320

326321
#if defined(CONFIG_KASAN_HW_TAGS) && IS_ENABLED(CONFIG_KASAN_KUNIT_TEST)
327322

328-
void kasan_set_tagging_report_once(bool state);
329323
void kasan_enable_tagging_sync(void);
330324
void kasan_force_async_fault(void);
331325

332326
#else /* CONFIG_KASAN_HW_TAGS || CONFIG_KASAN_KUNIT_TEST */
333327

334-
static inline void kasan_set_tagging_report_once(bool state) { }
335328
static inline void kasan_enable_tagging_sync(void) { }
336329
static inline void kasan_force_async_fault(void) { }
337330

0 commit comments

Comments
 (0)