-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
x86: kmsan: enable KMSAN builds for x86
Make KMSAN usable by adding the necessary Kconfig bits. Also declare x86-specific functions checking address validity in arch/x86/include/asm/kmsan.h. Signed-off-by: Alexander Potapenko <glider@google.com> --- v4: -- per Marco Elver's request, create arch/x86/include/asm/kmsan.h and move arch-specific inline functions there. Link: https://linux-review.googlesource.com/id/I1d295ce8159ce15faa496d20089d953a919c125e
- Loading branch information
1 parent
bf65716
commit ad8e4e8
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* | ||
* x86 KMSAN support. | ||
* | ||
* Copyright (C) 2022, Google LLC | ||
* Author: Alexander Potapenko <glider@google.com> | ||
*/ | ||
|
||
#ifndef _ASM_X86_KMSAN_H | ||
#define _ASM_X86_KMSAN_H | ||
|
||
#ifndef MODULE | ||
|
||
#include <asm/processor.h> | ||
#include <linux/mmzone.h> | ||
|
||
/* | ||
* Taken from arch/x86/mm/physaddr.h to avoid using an instrumented version. | ||
*/ | ||
static inline bool kmsan_phys_addr_valid(unsigned long addr) | ||
{ | ||
if (IS_ENABLED(CONFIG_PHYS_ADDR_T_64BIT)) | ||
return !(addr >> boot_cpu_data.x86_phys_bits); | ||
else | ||
return true; | ||
} | ||
|
||
/* | ||
* Taken from arch/x86/mm/physaddr.c to avoid using an instrumented version. | ||
*/ | ||
static inline bool kmsan_virt_addr_valid(void *addr) | ||
{ | ||
unsigned long x = (unsigned long)addr; | ||
unsigned long y = x - __START_KERNEL_map; | ||
|
||
/* use the carry flag to determine if x was < __START_KERNEL_map */ | ||
if (unlikely(x > y)) { | ||
x = y + phys_base; | ||
|
||
if (y >= KERNEL_IMAGE_SIZE) | ||
return false; | ||
} else { | ||
x = y + (__START_KERNEL_map - PAGE_OFFSET); | ||
|
||
/* carry flag will be set if starting x was >= PAGE_OFFSET */ | ||
if ((x > y) || !kmsan_phys_addr_valid(x)) | ||
return false; | ||
} | ||
|
||
return pfn_valid(x >> PAGE_SHIFT); | ||
} | ||
|
||
#endif /* !MODULE */ | ||
|
||
#endif /* _ASM_X86_KMSAN_H */ |