KASAN for arm64
Subsystems (6)
Andrey Ryabinin
maintainerv7 cover KASAN for arm64
As usual patches available in git
git://github.com/aryabinin/linux.git kasan/arm64v7
Changes since v6:
- Rebased on top of arm64/for-next/core:
e8f3010f7326c00368dbc057bd052bec80dfc072 ("arm64/efi: isolate EFI stub from the kernel proper")This should fix boot as an EFI application once again.
Changes since v5:
- Rebase on top of 4.3-rc1
- Fixed EFI boot.
- Updated Doc/features/KASAN.
Changes since v4:
- Generate KASAN_SHADOW_OFFSET using 32 bit arithmetic
- merge patches x86/kasan: switch to generic kasan_populate_zero_shadow() and mm: introduce generic kasan_populate_zero_shadow() into one.
- remove useless check for start != 0 in clear_pgds()
- Don't generate KASAN_SHADOW_OFFSET in Makefile for x86, assign it in Makefile.kasan if CONFIG_KASAN_SHADOW_OFFSET was defined.
Changes since v3:
- Generate KASAN_SHADOW_OFFSET in Makefile
- zero_p*_populate() functions now return void
- Switch x86 to generic kasan_populate_zero_shadow() too
- Add license headers
- fix memleak in kasan_populate_zero_shadow:
Following code could leak memory when pgd_populate() is nop:
void *p = early_alloc(PAGE_SIZE, NUMA_NO_NODE);
pgd_populate(&init_mm, pgd, p);
This was replaced by:
pgd_populate(&init_mm, pgd, early_alloc(PAGE_SIZE, NUMA_NO_NODE));Changes since v2:
- Rebase on top of v4.2-rc3
- Address feedback from Catalin.
- Print memory assignment from Linus
- Add message about KASAN being initialized
Changes since v1:
- Address feedback from Catalin.
- Generalize some kasan init code from arch/x86/mm/kasan_init_64.c and reuse it for arm64.
- Some bugfixes, including:
add missing arm64/include/asm/kasan.h
add tlb flush after changing ttbr1
- Add code comments.
Andrey Ryabinin (3):
arm64: move PGD_SIZE definition to pgalloc.h
arm64: add KASAN support Documentation/features/KASAN: arm64 supports KASAN now
Linus Walleij (1):
ARM64: kasan: print memory assignment
.../features/debug/KASAN/arch-support.txt | 2 +- arch/arm64/Kconfig | 1 + arch/arm64/Makefile | 7 + arch/arm64/include/asm/kasan.h | 36 +++++ arch/arm64/include/asm/pgalloc.h | 1 + arch/arm64/include/asm/pgtable.h | 7 + arch/arm64/include/asm/string.h | 16 ++ arch/arm64/kernel/Makefile | 2 + arch/arm64/kernel/arm64ksyms.c | 3 + arch/arm64/kernel/head.S | 3 + arch/arm64/kernel/image.h | 6 + arch/arm64/kernel/module.c | 16 +- arch/arm64/kernel/setup.c | 4 + arch/arm64/lib/memcpy.S | 3 + arch/arm64/lib/memmove.S | 7 +- arch/arm64/lib/memset.S | 3 + arch/arm64/mm/Makefile | 3 + arch/arm64/mm/init.c | 6 + arch/arm64/mm/kasan_init.c | 165 +++++++++++++++++++++ arch/arm64/mm/pgd.c | 2 - drivers/firmware/efi/Makefile | 8 + scripts/Makefile.kasan | 4 +- 22 files changed, 296 insertions(+), 9 deletions(-) create mode 100644 arch/arm64/include/asm/kasan.h create mode 100644 arch/arm64/mm/kasan_init.c
Signature · 1 line
2.4.9
Andrey Ryabinin
maintainerPATCH v7 1/4 arm64: move PGD_SIZE definition to pgalloc.h
This will be used by KASAN latter.
--- arch/arm64/include/asm/pgalloc.h | 1 + arch/arm64/mm/pgd.c | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-)
arch/arm64/include/asm/pgalloc.h +1 -0
@@ -27,6 +27,7 @@#define check_pgt_cache () do { } while (0)#define PGALLOC_GFP (GFP_KERNEL | __GFP_NOTRACK | __GFP_REPEAT | __GFP_ZERO) +#define PGD_SIZE (PTRS_PER_PGD * sizeof(pgd_t))#if CONFIG_PGTABLE_LEVELS >2
arch/arm64/mm/pgd.c +0 -2
@@ -28,8 +28,6 @@#include "mm.h" -#define PGD_SIZE (PTRS_PER_PGD * sizeof(pgd_t)) -static struct kmem_cache *pgd_cache;pgd_t *pgd_alloc (struct mm_struct *mm)
Signature · 1 line
2.4.9
Andrey Ryabinin
maintainerPATCH v7 2/4 arm64: add KASAN support
In reply to Andrey RyabininThis patch adds arch specific code for kernel address sanitizer (see Documentation/kasan.txt).
1/8 of kernel addresses reserved for shadow memory. There was no big enough hole for this, so virtual addresses for shadow were stolen from vmalloc area.
At early boot stage the whole shadow region populated with just one physical page (kasan_zero_page). Later, this page reused as readonly zero shadow for some memory that KASan currently don't track (vmalloc).
After mapping the physical memory, pages for shadow memory are allocated and mapped.
Functions like memset/memmove/memcpy do a lot of memory accesses. If bad pointer passed to one of these function it is important to catch this. Compiler's instrumentation cannot do this since these functions are written in assembly.
KASan replaces memory functions with manually instrumented variants. Original functions declared as weak symbols so strong definitions in mm/kasan/kasan.c could replace them. Original functions have aliases with '__' prefix in name, so we could call non-instrumented variant if needed.
Some files built without kasan instrumentation (e.g. mm/slub.c). Original mem* function replaced (via #define) with prefixed variants to disable memory access checks for such files.
--- arch/arm64/Kconfig | 1 + arch/arm64/Makefile | 7 ++ arch/arm64/include/asm/kasan.h | 36 +++++++++ arch/arm64/include/asm/pgtable.h | 7 ++ arch/arm64/include/asm/string.h | 16 ++++ arch/arm64/kernel/Makefile | 2 + arch/arm64/kernel/arm64ksyms.c | 3 + arch/arm64/kernel/head.S | 3 + arch/arm64/kernel/image.h | 6 ++ arch/arm64/kernel/module.c | 16 +++- arch/arm64/kernel/setup.c | 4 + arch/arm64/lib/memcpy.S | 3 + arch/arm64/lib/memmove.S | 7 +- arch/arm64/lib/memset.S | 3 + arch/arm64/mm/Makefile | 3 + arch/arm64/mm/kasan_init.c | 165 +++++++++++++++++++++++++++++++++++++++ drivers/firmware/efi/Makefile | 8 ++ scripts/Makefile.kasan | 4 +- 18 files changed, 288 insertions(+), 6 deletions(-) create mode 100644 arch/arm64/include/asm/kasan.h create mode 100644 arch/arm64/mm/kasan_init.c
arch/arm64/Kconfig +1 -0
@@ -48,6 +48,7 @@ config ARM64 select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_BITREVERSE select HAVE_ARCH_JUMP_LABEL + select HAVE_ARCH_KASAN if SPARSEMEM_VMEMMAP select HAVE_ARCH_KGDB select HAVE_ARCH_SECCOMP_FILTER select HAVE_ARCH_TRACEHOOK
arch/arm64/Makefile +7 -0
@@ -55,6 +55,13 @@ else TEXT_OFFSET := 0x00080000 endif +# KASAN_SHADOW_OFFSET = VA_START + (1 << (VA_BITS - 3)) - (1 << 61) +# in 32-bit arithmetic +KASAN_SHADOW_OFFSET := $(shell printf "0x%08x00000000\n" $$(( \ + (0xffffffff & (-1 << ($(CONFIG_ARM64_VA_BITS) - 32))) \ + + (1 << ($(CONFIG_ARM64_VA_BITS) - 32 - 3)) \ + - (1 << (64 - 32 - 3)) )) ) + export TEXT_OFFSET GZFLAGS core-y += arch/arm64/kernel/ arch/arm64/mm/
arch/arm64/include/asm/kasan.h new file +36 -0
@@ -0,0 +1,36 @@ +#ifndef __ASM_KASAN_H +#define __ASM_KASAN_H + +#ifndef __ASSEMBLY__ + +#ifdef CONFIG_KASAN + +#include <asm/memory.h> + +/* +* KASAN_SHADOW_START: beginning of the kernel virtual addresses. +* KASAN_SHADOW_END: KASAN_SHADOW_START + 1/8 of kernel virtual addresses. +*/ +#define KASAN_SHADOW_START (VA_START) +#define KASAN_SHADOW_END (KASAN_SHADOW_START + (1UL << (VA_BITS - 3))) + +/* +* This value is used to map an address to the corresponding shadow +* address by the following formula: +* shadow_addr = (address >> 3) + KASAN_SHADOW_OFFSET; +* +* (1 << 61) shadow addresses - [KASAN_SHADOW_OFFSET,KASAN_SHADOW_END] +* cover all 64-bits of virtual addresses. So KASAN_SHADOW_OFFSET +* should satisfy the following equation: +* KASAN_SHADOW_OFFSET = KASAN_SHADOW_END - (1ULL << 61) +*/ +#define KASAN_SHADOW_OFFSET (KASAN_SHADOW_END - (1ULL << (64 - 3))) + +void kasan_init (void ); + +#else +static inline void kasan_init (void ) { } +#endif + +#endif +#endif
arch/arm64/include/asm/pgtable.h +7 -0
@@ -41,7 +41,14 @@* fixed mappings and modules */ #define VMEMMAP_SIZE ALIGN((1UL << (VA_BITS - PAGE_SHIFT)) * sizeof(struct page), PUD_SIZE) + +#ifndef CONFIG_KASAN #define VMALLOC_START (VA_START) +#else +#include <asm/kasan.h> +#define VMALLOC_START (KASAN_SHADOW_END + SZ_64K) +#endif +#define VMALLOC_END (PAGE_OFFSET - PUD_SIZE - VMEMMAP_SIZE - SZ_64K)#define vmemmap ((struct page *)(VMALLOC_END + SZ_64K))
arch/arm64/include/asm/string.h +16 -0
@@ -36,17 +36,33 @@ extern __kernel_size_t strnlen(const char *, __kernel_size_t);#define __HAVE_ARCH_MEMCPYextern void *memcpy (void *,const void *,__kernel_size_t ); +extern void *__memcpy (void *,const void *,__kernel_size_t );#define __HAVE_ARCH_MEMMOVEextern void *memmove (void *,const void *,__kernel_size_t ); +extern void *__memmove (void *,const void *,__kernel_size_t );#define __HAVE_ARCH_MEMCHRextern void *memchr (const void *,int ,__kernel_size_t );#define __HAVE_ARCH_MEMSETextern void *memset (void *,int ,__kernel_size_t ); +extern void *__memset (void *,int ,__kernel_size_t );#define __HAVE_ARCH_MEMCMPextern int memcmp (const void *,const void *,size_t ); + +#if defined(CONFIG_KASAN ) && !defined(__SANITIZE_ADDRESS__) + +/* +* For files that are not instrumented (e.g. mm/slub.c) we +* should use not instrumented version of mem* functions. +*/ + +#define memcpy (dst, src, len) __memcpy(dst, src, len) +#define memmove (dst, src, len) __memmove(dst, src, len) +#define memset (s, c, n) __memset(s, c, n) +#endif +#endif
arch/arm64/kernel/Makefile +2 -0
@@ -7,6 +7,8 @@ AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET) CFLAGS_efi-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) CFLAGS_armv8_deprecated.o := -I$(src) +KASAN_SANITIZE_efi-stub.o := n + CFLAGS_REMOVE_ftrace.o = -pg CFLAGS_REMOVE_insn.o = -pg CFLAGS_REMOVE_return_address.o = -pg
arch/arm64/kernel/arm64ksyms.c +3 -0
@@ -51,6 +51,9 @@ EXPORT_SYMBOL(strnlen);EXPORT_SYMBOL (memset);EXPORT_SYMBOL (memcpy);EXPORT_SYMBOL (memmove); +EXPORT_SYMBOL (__memset); +EXPORT_SYMBOL (__memcpy); +EXPORT_SYMBOL (__memmove);EXPORT_SYMBOL (memchr);EXPORT_SYMBOL (memcmp);
arch/arm64/kernel/head.S +3 -0
@@ -444,6 +444,9 @@ __mmap_switched: str_l x21, __fdt_pointer, x5 // Save FDT pointer str_l x24, memstart_addr, x6 // Save PHYS_OFFSET mov x29, #0 +#ifdef CONFIG_KASAN + bl kasan_early_init +#endif b start_kernel ENDPROC(__mmap_switched)
arch/arm64/kernel/image.h +6 -0
@@ -80,6 +80,12 @@ __efistub_strcmp = __pi_strcmp; __efistub_strncmp = __pi_strncmp; __efistub___flush_dcache_area = __pi___flush_dcache_area; +#ifdef CONFIG_KASAN +__efistub___memcpy = __pi_memcpy; +__efistub___memmove = __pi_memmove; +__efistub___memset = __pi_memset; +#endif + __efistub__text = _text; __efistub__end = _end; __efistub__edata = _edata;
arch/arm64/kernel/module.c +13 -3
@@ -21,6 +21,7 @@#include <linux/bitops.h> #include <linux/elf.h> #include <linux/gfp.h> +#include <linux/kasan.h> #include <linux/kernel.h> #include <linux/mm.h> #include <linux/moduleloader.h>
@@ -34,9 +35,18 @@void *module_alloc (unsigned long size) { -return __vmalloc_node_range (size,1 ,MODULES_VADDR ,MODULES_END , -GFP_KERNEL ,PAGE_KERNEL_EXEC ,0 , -NUMA_NO_NODE ,__builtin_return_address (0 )); +void *p; + + p =__vmalloc_node_range (size,MODULE_ALIGN ,MODULES_VADDR ,MODULES_END , +GFP_KERNEL ,PAGE_KERNEL_EXEC ,0 , +NUMA_NO_NODE ,__builtin_return_address (0 )); + +if (p && (kasan_module_alloc (p, size) <0 )) { +vfree (p); +return NULL ; + } + +return p; }enum aarch64_reloc_op {
arch/arm64/kernel/setup.c +4 -0
@@ -54,6 +54,7 @@#include <asm/elf.h> #include <asm/cpufeature.h> #include <asm/cpu_ops.h> +#include <asm/kasan.h> #include <asm/sections.h> #include <asm/setup.h> #include <asm/smp_plat.h>
@@ -434,6 +435,9 @@ void __init setup_arch(char **cmdline_p)paging_init ();relocate_initrd (); + +kasan_init (); +request_standard_resources ();early_ioremap_reset ();
arch/arm64/lib/memcpy.S +3 -0
@@ -68,7 +68,10 @@ stp \ptr, \regB, [\regC], \val .endm + .weak memcpy +ENTRY(__memcpy) ENTRY(memcpy) #include "copy_template.S" ret ENDPIPROC(memcpy) +ENDPROC(__memcpy)
arch/arm64/lib/memmove.S +5 -2
@@ -57,12 +57,14 @@ C_h .req x12 D_l .req x13 D_h .req x14 + .weak memmove +ENTRY(__memmove) ENTRY(memmove) cmp dstin, src - b.lo memcpy + b.lo __memcpy add tmp1, src, count cmp dstin, tmp1 - b.hs memcpy /* No overlap. */ + b.hs __memcpy /* No overlap. */ add dst, dstin, count add src, src, count
@@ -195,3 +197,4 @@ ENTRY(memmove) b.ne .Ltail63 ret ENDPIPROC(memmove) +ENDPROC(__memmove)
arch/arm64/lib/memset.S +3 -0
@@ -54,6 +54,8 @@ dst .req x8 tmp3w .req w9 tmp3 .req x9 + .weak memset +ENTRY(__memset) ENTRY(memset) mov dst, dstin /* Preserve return value. */ and A_lw, val, #255
@@ -214,3 +216,4 @@ ENTRY(memset) b.ne .Ltail_maybe_long ret ENDPIPROC(memset) +ENDPROC(__memset)
arch/arm64/mm/Makefile +3 -0
@@ -4,3 +4,6 @@ obj-y := dma-mapping.o extable.o fault.o init.o \ context.o proc.o pageattr.o obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o obj-$(CONFIG_ARM64_PTDUMP) += dump.o + +obj-$(CONFIG_KASAN) += kasan_init.o +KASAN_SANITIZE_kasan_init.o := n
arch/arm64/mm/kasan_init.c new file +165 -0
165 lines not on this page · raw message
drivers/firmware/efi/Makefile +8 -0
@@ -1,6 +1,14 @@ # # Makefile for linux kernel # + +# +# ARM64 maps efi runtime services in userspace addresses +# which don't have KASAN shadow. So dereference of these addresses +# in efi_call_virt() will cause crash if this code instrumented. +# +KASAN_SANITIZE_runtime-wrappers.o := n + obj-$(CONFIG_EFI) += efi.o vars.o reboot.o obj-$(CONFIG_EFI_VARS) += efivars.o obj-$(CONFIG_EFI_ESRT) += esrt.o
scripts/Makefile.kasan +3 -1
@@ -5,10 +5,12 @@ else call_threshold := 0 endif +KASAN_SHADOW_OFFSET ?= $(CONFIG_KASAN_SHADOW_OFFSET) + CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address CFLAGS_KASAN := $(call cc-option, -fsanitize=kernel-address \ - -fasan-shadow-offset=$(CONFIG_KASAN_SHADOW_OFFSET) \ + -fasan-shadow-offset=$(KASAN_SHADOW_OFFSET) \ --param asan-stack=1 --param asan-globals=1 \ --param asan-instrumentation-with-call-threshold=$(call_threshold))
Signature · 1 line
2.4.9
Andrey Ryabinin
maintainerPATCH v7 3/4 ARM64: kasan: print memory assignment
In reply to Andrey RyabininFrom: Linus Walleij <[email protected]>
This prints out the virtual memory assigned to KASan in the boot crawl along with other memory assignments, if and only if KASan is activated.
Example dmesg from the Juno Development board:
Memory: 1691156K/2080768K available (5465K kernel code, 444K rwdata, 2160K rodata, 340K init, 217K bss, 373228K reserved, 16384K cma-reserved) Virtual kernel memory layout:
kasan : 0xffffff8000000000 - 0xffffff9000000000 ( 64 GB)
vmalloc : 0xffffff9000000000 - 0xffffffbdbfff0000 ( 182 GB)
vmemmap : 0xffffffbdc0000000 - 0xffffffbfc0000000 ( 8 GB maximum)
0xffffffbdc2000000 - 0xffffffbdc3fc0000 ( 31 MB actual)
fixed : 0xffffffbffabfd000 - 0xffffffbffac00000 ( 12 KB)
PCI I/O : 0xffffffbffae00000 - 0xffffffbffbe00000 ( 16 MB)
modules : 0xffffffbffc000000 - 0xffffffc000000000 ( 64 MB)
memory : 0xffffffc000000000 - 0xffffffc07f000000 ( 2032 MB)
.init : 0xffffffc0007f5000 - 0xffffffc00084a000 ( 340 KB)
.text : 0xffffffc000080000 - 0xffffffc0007f45b4 ( 7634 KB)
.data : 0xffffffc000850000 - 0xffffffc0008bf200 ( 445 KB)--- arch/arm64/mm/init.c | 6 ++++++ 1 file changed, 6 insertions(+)
arch/arm64/mm/init.c +6 -0
@@ -298,6 +298,9 @@ void __init mem_init(void)#define MLK_ROUNDUP (b, t) b, t, DIV_ROUND_UP(((t) - (b)), SZ_1K) pr_notice("Virtual kernel memory layout:\n" +#ifdef CONFIG_KASAN + " kasan : 0x%16lx - 0x%16lx (%6ld GB)\n" +#endif" vmalloc : 0x%16lx - 0x%16lx (%6ld GB)\n" #ifdef CONFIG_SPARSEMEM_VMEMMAP " vmemmap : 0x%16lx - 0x%16lx (%6ld GB maximum)\n"
@@ -310,6 +313,9 @@ void __init mem_init(void) " .init : 0x%p" " - 0x%p" " (%6ld KB)\n" " .text : 0x%p" " - 0x%p" " (%6ld KB)\n" " .data : 0x%p" " - 0x%p" " (%6ld KB)\n", +#ifdef CONFIG_KASAN + MLG(KASAN_SHADOW_START, KASAN_SHADOW_END), +#endif MLG(VMALLOC_START, VMALLOC_END),#ifdef CONFIG_SPARSEMEM_VMEMMAP MLG((unsigned long)vmemmap,
Signature · 1 line
2.4.9
Andrey Ryabinin
maintainerPATCH v7 4/4 Documentation/features/KASAN: arm64 supports KASAN now
In reply to Andrey Ryabinin--- Documentation/features/debug/KASAN/arch-support.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/features/debug/KASAN/arch-support.txt +1 -1
@@ -9,7 +9,7 @@ | alpha: | TODO | | arc: | TODO | | arm: | TODO | - | arm64: | TODO | + | arm64: | ok | | avr32: | TODO | | blackfin: | TODO | | c6x: | TODO |
Signature · 1 line
2.4.9
Catalin Marinas
maintainerQuoted 7 lines · Andrey Ryabinin
Andrey Ryabinin (3):
arm64: movePGD_SIZEdefinition topgalloc.h
arm64: add KASAN supportDocumentation/features/KASAN: arm64 supports KASAN nowLinus Walleij (1):
ARM64: kasan: print memory assignment
Patches queued for 4.4. Thanks.
Signature · 1 line
Catalin
Quoted 11 lines · Catalin Marinas
Quoted 7 lines · Andrey Ryabinin
Andrey Ryabinin (3):
arm64: movePGD_SIZEdefinition topgalloc.h
arm64: add KASAN supportDocumentation/features/KASAN: arm64 supports KASAN nowLinus Walleij (1):
ARM64: kasan: print memory assignmentPatches queued for 4.4. Thanks.
Hi,
I get the following failure with KASAN + 16K_PAGES + 48BIT_VA, with 4.4-rc1:
arch/arm64/mm/kasan_init.c: In function ?kasan_early_init?:include/linux/compiler.h:484:38: error: call to ?__compiletime_assert_95? declared with attribute error: BUILD_BUG_ON failed: !IS_ALIGNED(KASAN_SHADOW_END, PGDIR_SIZE)
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
^
include/linux/compiler.h:467:4: note: in definition of macro ?__compiletime_assert?
prefix ## suffix(); \
^include/linux/compiler.h:484:2: note: in expansion of macro ?_compiletime_assert?
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__) ^include/linux/bug.h:50:37: note: in expansion of macro ?compiletime_assert?
#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
^include/linux/bug.h:74:2: note: in expansion of macro ?BUILD_BUG_ON_MSG?
BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition) ^arch/arm64/mm/kasan_init.c:95:2: note: in expansion of macro ?BUILD_BUG_ON?
BUILD_BUG_ON(!IS_ALIGNED(KASAN_SHADOW_END, PGDIR_SIZE));
---
The problem is that the PGDIR_SIZE is (1UL << 47) with 16K+48bit, which makes the KASAN_SHADOW_END unaligned(which is aligned to (1UL << (48 - 3)) ). Is the alignment really needed ? Thoughts on how best we could fix this ?
Cheers
Suzuki
Andrey Ryabinin
maintainerQuoted 38 lines · Suzuki K. Poulose
Quoted 11 lines · Catalin Marinas
Quoted 7 lines · Andrey Ryabinin
Andrey Ryabinin (3):
arm64: movePGD_SIZEdefinition topgalloc.h
arm64: add KASAN supportDocumentation/features/KASAN: arm64 supports KASAN nowLinus Walleij (1):
ARM64: kasan: print memory assignmentPatches queued for 4.4. Thanks.
Hi,
I get the following failure with KASAN + 16K_PAGES + 48BIT_VA, with 4.4-rc1:
arch/arm64/mm/kasan_init.c: In function ?kasan_early_init?:include/linux/compiler.h:484:38: error: call to ?__compiletime_assert_95? declared with attribute error:BUILD_BUG_ONfailed: !IS_ALIGNED(KASAN_SHADOW_END,PGDIR_SIZE)
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)^ include/linux/compiler.h:467:4: note: in definition of macro ?__compiletime_assert? prefix ## suffix(); \ ^
include/linux/compiler.h:484:2: note: in expansion of macro ?_compiletime_assert?
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)^include/linux/bug.h:50:37: note: in expansion of macro ?compiletime_assert?#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) ^
include/linux/bug.h:74:2: note: in expansion of macro ?BUILD_BUG_ON_MSG?
BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)^arch/arm64/mm/kasan_init.c:95:2: note: in expansion of macro ?BUILD_BUG_ON?
BUILD_BUG_ON(!IS_ALIGNED(KASAN_SHADOW_END, PGDIR_SIZE));
Quoted 6 lines
---
The problem is that the
PGDIR_SIZEis (1UL << 47) with 16K+48bit, which makes theKASAN_SHADOW_ENDunaligned(which is aligned to (1UL << (48 - 3)) ). Is the alignment really needed ? Thoughts on how best we could fix this ?
Yes, it's really needed, because some code relies on this (e.g. clear_pgs() and kasan_init()). But it should be possible to get rid of this requirement.
At first we need to rework clear_pgs().
The purpose of clear_pgs() is to remove kasan shadow from swapper_pg_dir.
So clear_pgs() should clear the top most kasan_zero_* entries from page tables. Previously it was enough to clear PGDs, in case of 16K_PAGES + 48BIT_VA we probably need to clear PMDs
We also have to change following part of kasan_init()
...
/*
* We are going to perform proper setup of shadow memory.
* At first we should unmap early shadow (clear_pgds() call bellow).
* However, instrumented code couldn't execute without shadow memory.
* tmp_pg_dir used to keep early shadow mapped until full shadow
* setup will be finished.
*/
memcpy(tmp_pg_dir, swapper_pg_dir, sizeof(tmp_pg_dir));
Besides tmp_pg_dir we will need one more temporary page table to store those entries which later will be removed from swapper_pg_dir by clear_pgds().
Quoted 3 lines
Cheers
Suzuki
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Catalin Marinas
maintainerQuoted 34 lines · Andrey Ryabinin
Quoted 33 lines · Suzuki K. Poulose
Quoted 10 lines · Catalin Marinas
Quoted 7 lines · Andrey Ryabinin
Andrey Ryabinin (3):
arm64: movePGD_SIZEdefinition topgalloc.h
arm64: add KASAN supportDocumentation/features/KASAN: arm64 supports KASAN nowLinus Walleij (1):
ARM64: kasan: print memory assignmentPatches queued for 4.4. Thanks.
I get the following failure with KASAN + 16K_PAGES + 48BIT_VA, with 4.4-rc1:
arch/arm64/mm/kasan_init.c: In function ?kasan_early_init?:include/linux/compiler.h:484:38: error: call to ?__compiletime_assert_95? declared with attribute error:BUILD_BUG_ONfailed: !IS_ALIGNED(KASAN_SHADOW_END,PGDIR_SIZE)
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)^ include/linux/compiler.h:467:4: note: in definition of macro ?__compiletime_assert? prefix ## suffix(); \ ^
include/linux/compiler.h:484:2: note: in expansion of macro ?_compiletime_assert?
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)^include/linux/bug.h:50:37: note: in expansion of macro ?compiletime_assert?#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) ^
include/linux/bug.h:74:2: note: in expansion of macro ?BUILD_BUG_ON_MSG?
BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)^arch/arm64/mm/kasan_init.c:95:2: note: in expansion of macro ?BUILD_BUG_ON?
BUILD_BUG_ON(!IS_ALIGNED(KASAN_SHADOW_END, PGDIR_SIZE));
Quoted 7 lines
Quoted 3 lines
The problem is that the
PGDIR_SIZEis (1UL << 47) with 16K+48bit, which makes theKASAN_SHADOW_ENDunaligned(which is aligned to (1UL << (48 - 3)) ). Is the alignment really needed ? Thoughts on how best we could fix this ?Yes, it's really needed, because some code relies on this (e.g.
clear_pgs()andkasan_init()). But it should be possible to get rid of this requirement.
I don't think clear_pgds() and kasan_init() are the only problems. IIUC, kasan_populate_zero_shadow() also assumes that KASan shadow covers multiple pgds. You need some kind of recursive writing which avoids populating an entry which is not empty (like kasan_early_pud_populate).
Signature · 1 line
Catalin
Andrey Ryabinin
maintainerQuoted 39 lines · Catalin Marinas
Quoted 38 lines · Andrey Ryabinin
Quoted 36 lines · Suzuki K. Poulose
Quoted 10 lines · Catalin Marinas
Quoted 7 lines · Andrey Ryabinin
Andrey Ryabinin (3):
arm64: movePGD_SIZEdefinition topgalloc.h
arm64: add KASAN supportDocumentation/features/KASAN: arm64 supports KASAN nowLinus Walleij (1):
ARM64: kasan: print memory assignmentPatches queued for 4.4. Thanks.
I get the following failure with KASAN + 16K_PAGES + 48BIT_VA, with 4.4-rc1:
arch/arm64/mm/kasan_init.c: In function a??kasan_early_inita??:include/linux/compiler.h:484:38: error: call to a??__compiletime_assert_95a?? declared with attribute error:BUILD_BUG_ONfailed: !IS_ALIGNED(KASAN_SHADOW_END,PGDIR_SIZE)
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)^ include/linux/compiler.h:467:4: note: in definition of macro a??__compiletime_asserta?? prefix ## suffix(); \ ^
include/linux/compiler.h:484:2: note: in expansion of macro a??_compiletime_asserta??
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)^include/linux/bug.h:50:37: note: in expansion of macro a??compiletime_asserta??#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) ^
include/linux/bug.h:74:2: note: in expansion of macro a??BUILD_BUG_ON_MSGa??
BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)^arch/arm64/mm/kasan_init.c:95:2: note: in expansion of macro a??BUILD_BUG_ONa??
BUILD_BUG_ON(!IS_ALIGNED(KASAN_SHADOW_END, PGDIR_SIZE));The problem is that the
PGDIR_SIZEis (1UL << 47) with 16K+48bit, which makes theKASAN_SHADOW_ENDunaligned(which is aligned to (1UL << (48 - 3)) ). Is the alignment really needed ? Thoughts on how best we could fix this ?
Quoted 9 lines
Quoted 3 lines
Yes, it's really needed, because some code relies on this (e.g.
clear_pgs()andkasan_init()). But it should be possible to get rid of this requirement.I don't think
clear_pgds()andkasan_init()are the only problems. IIUC,kasan_populate_zero_shadow()also assumes that KASan shadow covers multiple pgds. You need some kind of recursive writing which avoids populating an entry which is not empty (likekasan_early_pud_populate).
I think kasan_populate_zero_shadow() should be fine. We call pgd_populate() only if address range covers the entire pgd:
if (IS_ALIGNED(addr, PGDIR_SIZE) && end - addr >= PGDIR_SIZE) {
....
pgd_populate(&init_mm, pgd, kasan_zero_pud);....
and otherwise we check for pgd_none(*pgd):
if (pgd_none(*pgd)) {
pgd_populate(&init_mm, pgd,
early_alloc(PAGE_SIZE, NUMA_NO_NODE));
}Is there any way to run 16K pages on emulated environment? I've tried:
- ARM V8 Foundation Platformr0p0 (platform build 9.4.59)
- QEMU 2.4.0
and both just doesn't boot for me on 4.4-rc1 with 16k pages config.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 3 lines · Andrey Ryabinin
Is there any way to run 16K pages on emulated environment? I've tried:
- ARM V8 Foundation Platformr0p0 (platform build 9.4.59)
Have you tried with the following option ?
-C cluster<N>.has_16k_granule=1
Thanks
Suzuki
Quoted 11 lines · Suzuki K. Poulose
Quoted 3 lines · Andrey Ryabinin
Is there any way to run 16K pages on emulated environment? I've tried:
- ARM V8 Foundation Platformr0p0 (platform build 9.4.59)Have you tried with the following option ?
-C cluster<N>.has_16k_granule=1
That is only supported on FVP Base, not the Foundation model.
Signature · 1 line
Ard.
Catalin Marinas
maintainerQuoted 25 lines · Andrey Ryabinin
Quoted 9 lines · Catalin Marinas
Quoted 8 lines · Andrey Ryabinin
Quoted 6 lines · Suzuki K. Poulose
arch/arm64/mm/kasan_init.c:95:2: note: in expansion of macro ?BUILD_BUG_ON?
BUILD_BUG_ON(!IS_ALIGNED(KASAN_SHADOW_END, PGDIR_SIZE));The problem is that the
PGDIR_SIZEis (1UL << 47) with 16K+48bit, which makes theKASAN_SHADOW_ENDunaligned(which is aligned to (1UL << (48 - 3)) ). Is the alignment really needed ? Thoughts on how best we could fix this ?Quoted 8 lines
Quoted 3 lines
Yes, it's really needed, because some code relies on this (e.g.
clear_pgs()andkasan_init()). But it should be possible to get rid of this requirement.I don't think
clear_pgds()andkasan_init()are the only problems. IIUC,kasan_populate_zero_shadow()also assumes that KASan shadow covers multiple pgds. You need some kind of recursive writing which avoids populating an entry which is not empty (likekasan_early_pud_populate).I think
kasan_populate_zero_shadow()should be fine. We callpgd_populate()only if address range covers the entire pgd:if (IS_ALIGNED(addr, PGDIR_SIZE) && end - addr >= PGDIR_SIZE) { .... pgd_populate(&init_mm, pgd, kasan_zero_pud);
Quoted 7 lines
....
and otherwise we check for
pgd_none(*pgd):if (pgd_none(*pgd)) { pgd_populate(&init_mm, pgd, early_alloc(PAGE_SIZE, NUMA_NO_NODE)); }
OK, I missed the fact that zero_pud_populate() handles the pmd/pte population with kasan_zero_*.
So if it's only tmp_pg_dir, as you said already, you can add a tmp_pud for the case where KASAN_SHADOW_SIZE is smaller than PGDIR_SIZE and change clear_pgds() to erase the puds.
Signature · 1 line
Catalin
Quoted 13 lines · Andrey Ryabinin
Quoted 12 lines · Suzuki K. Poulose
Quoted 1 line · Catalin Marinas
On Mon, Oct 12, 2015 at 06:52:56PM +0300, Andrey Ryabinin wrote:
Hi,
I get the following failure with KASAN + 16K_PAGES + 48BIT_VA, with 4.4-rc1:
arch/arm64/mm/kasan_init.c: In function ?kasan_early_init?:include/linux/compiler.h:484:38: error: call to ?__compiletime_assert_95? declared with attribute error:BUILD_BUG_ONfailed: !IS_ALIGNED(KASAN_SHADOW_END,PGDIR_SIZE)
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)^
...
Quoted 3 lines
Yes, it's really needed, because some code relies on this (e.g.
clear_pgs()andkasan_init()). But it should be possible to get rid of this requirement.
And the other important point I missed mentioning was that, my tool chain doesn't support KASAN. But still the KASAN support files are still compiled and generates the above error. Shouldn't we disable it at build time if we detect that compiler doesn't support it ? Something like we do for LSE_ATOMICS.
commit c09d6a04d17d730b0463207a26ece082772b59ee
Author: Will Deacon <[email protected]> Date: Tue Feb 3 16:14:13 2015 +0000
arm64: atomics: patch in lse instructions when supported by the CPU
On CPUs which support the LSE atomic instructions introduced in ARMv8.1, it makes sense to use them in preference to ll/sc sequences.
...
arch/arm64/Makefile +12 -1
@@ -17,7 +17,18 @@ GZFLAGS :=-9 KBUILD_DEFCONFIG := defconfig -KBUILD_CFLAGS += -mgeneral-regs-only +# Check for binutils support for specific extensions +lseinstr := $(call as-instr,.arch_extension lse,-DCONFIG_AS_LSE=1) + +ifeq ($(CONFIG_ARM64_LSE_ATOMICS), y) + ifeq ($(lseinstr),) +$(warning LSE atomics not supported by binutils) + endif +endif + +KBUILD_CFLAGS += -mgeneral-regs-only $(lseinstr) +KBUILD_AFLAGS += $(lseinstr) +
Thanks
Suzuki
Quoted 18 lines · Suzuki K. Poulose
Quoted 13 lines · Andrey Ryabinin
Quoted 12 lines · Suzuki K. Poulose
Quoted 1 line · Catalin Marinas
On Mon, Oct 12, 2015 at 06:52:56PM +0300, Andrey Ryabinin wrote:
Hi,
I get the following failure with KASAN + 16K_PAGES + 48BIT_VA, with 4.4-rc1:
arch/arm64/mm/kasan_init.c: In function ?kasan_early_init?:include/linux/compiler.h:484:38: error: call to ?__compiletime_assert_95? declared with attribute error:BUILD_BUG_ONfailed: !IS_ALIGNED(KASAN_SHADOW_END,PGDIR_SIZE)
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)^...
Quoted 1 line
Quoted 8 lines
Quoted 2 lines
Yes, it's really needed, because some code relies on this (e.g.
clear_pgs()andkasan_init()). But it should be possible to get rid of this requirement.And the other important point I missed mentioning was that, my tool chain doesn't support KASAN. But still the KASAN support files are still compiled and generates the above error. Shouldn't we disable it at build time if we detect that compiler doesn't support it ? Something like we do for
LSE_ATOMICS.
We should either add proper Kconfig dependency for now, or just make it work.
From: Andrey Ryabinin <[email protected]>
Subject: [PATCH] arm64: KASAN depends on !(ARM64_16K_PAGES && ARM64_VA_BITS_48)
On KASAN + 16K_PAGES + 48BIT_VA
arch/arm64/mm/kasan_init.c: In function ?kasan_early_init?:
include/linux/compiler.h:484:38: error: call to ?__compiletime_assert_95? declared with attribute error: BUILD_BUG_ON failed: !IS_ALIGNED(KASAN_SHADOW_END, PGDIR_SIZE)
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
Currently KASAN will not work on 16K_PAGES and 48BIT_VA, so forbid such configuration to avoid above build failure.
--- arch/arm64/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/Kconfig +1 -1
@@ -49,7 +49,7 @@ config ARM64 select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_BITREVERSE select HAVE_ARCH_JUMP_LABEL - select HAVE_ARCH_KASAN if SPARSEMEM_VMEMMAP + select HAVE_ARCH_KASAN if SPARSEMEM_VMEMMAP && !(ARM64_16K_PAGES && ARM64_VA_BITS_48) select HAVE_ARCH_KGDB select HAVE_ARCH_SECCOMP_FILTER select HAVE_ARCH_TRACEHOOK
Signature · 7 lines
2.4.10 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi Catalin,
Can you pick up Andrey's patch below for v4.4, until we have a better solution?
I stumbled across this myself and was about to post a similar patch.
FWIW:
Thanks,
Mark.
Quoted 42 lines · Andrey Ryabinin
We should either add proper
Kconfigdependency for now, or just make it work.From: Andrey Ryabinin <[email protected]>
Subject: [PATCH] arm64: KASAN depends on !(ARM64_16K_PAGES &&ARM64_VA_BITS_48)On KASAN + 16K_PAGES + 48BIT_VA
arch/arm64/mm/kasan_init.c: In function ?kasan_early_init?:
include/linux/compiler.h:484:38: error: call to ?__compiletime_assert_95? declared with attribute error:BUILD_BUG_ONfailed: !IS_ALIGNED(KASAN_SHADOW_END,PGDIR_SIZE)
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)Currently KASAN will not work on 16K_PAGES and 48BIT_VA, so forbid such configuration to avoid above build failure.
Reported-by Suzuki K. Poulose <[email protected]>Signed-off-by Andrey Ryabinin <[email protected]>--- arch/arm64/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm64/Kconfig +1
-1@@ -49,7 +49,7 @@ config ARM64 select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_BITREVERSE select HAVE_ARCH_JUMP_LABEL - select HAVE_ARCH_KASAN if SPARSEMEM_VMEMMAP + select HAVE_ARCH_KASAN if SPARSEMEM_VMEMMAP && !(ARM64_16K_PAGES && ARM64_VA_BITS_48) select HAVE_ARCH_KGDB select HAVE_ARCH_SECCOMP_FILTER select HAVE_ARCH_TRACEHOOKSignature · 7 lines
2.4.10 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel at lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 5 lines · Mark Rutland
Hi Catalin,
Can you pick up Andrey's patch below for v4.4, until we have a better solution?
FYI, better solution is almost ready, I'm going to send it today. However, I don't know for sure whether it works or not :) I'm not able to test as I don't have any setup working with 16k pages.
Quoted 47 lines
I stumbled across this myself and was about to post a similar patch.
FWIW:
Acked-by Mark Rutland <[email protected]>Thanks,
Mark.Quoted 37 lines · Andrey Ryabinin
We should either add proper
Kconfigdependency for now, or just make it work.From: Andrey Ryabinin <[email protected]>
Subject: [PATCH] arm64: KASAN depends on !(ARM64_16K_PAGES &&ARM64_VA_BITS_48)On KASAN + 16K_PAGES + 48BIT_VA
arch/arm64/mm/kasan_init.c: In function a??kasan_early_inita??:
include/linux/compiler.h:484:38: error: call to a??__compiletime_assert_95a?? declared with attribute error:BUILD_BUG_ONfailed: !IS_ALIGNED(KASAN_SHADOW_END,PGDIR_SIZE)
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)Currently KASAN will not work on 16K_PAGES and 48BIT_VA, so forbid such configuration to avoid above build failure.
Reported-by Suzuki K. Poulose <[email protected]>Signed-off-by Andrey Ryabinin <[email protected]>--- arch/arm64/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm64/Kconfig +1
-1@@ -49,7 +49,7 @@ config ARM64 select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_BITREVERSE select HAVE_ARCH_JUMP_LABEL - select HAVE_ARCH_KASAN if SPARSEMEM_VMEMMAP + select HAVE_ARCH_KASAN if SPARSEMEM_VMEMMAP && !(ARM64_16K_PAGES && ARM64_VA_BITS_48) select HAVE_ARCH_KGDB select HAVE_ARCH_SECCOMP_FILTER select HAVE_ARCH_TRACEHOOKSignature · 1 line
2.4.10
Quoted 5 lines
Quoted 5 lines
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Catalin Marinas
maintainerQuoted 6 lines · Andrey Ryabinin
Quoted 2 lines · Mark Rutland
Can you pick up Andrey's patch below for v4.4, until we have a better solution?
FYI, better solution is almost ready, I'm going to send it today. However, I don't know for sure whether it works or not :)
I merged the Kconfig fix for 4.4, it's not a significant loss since I don't expect anyone to jump onto the 16K page configuration. We'll take the proper fix for 4.5.
Thanks.
Signature · 1 line
Catalin