All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v7 0/4] KASAN for arm64
@ 2015-10-12 15:52 ` Andrey Ryabinin
  0 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-10-12 15:52 UTC (permalink / raw)
  To: Will Deacon, Catalin Marinas, linux-arm-kernel
  Cc: Andrey Ryabinin, Linus Walleij, Alexander Potapenko,
	Dmitry Vyukov, Arnd Bergmann, linux-kernel, David Keitel,
	linux-mm, kasan-dev, Alexey Klimov, Yury, Andrey Konovalov,
	Ard Biesheuvel

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

-- 
2.4.9


^ permalink raw reply	[flat|nested] 54+ messages in thread

* [PATCH v7 0/4] KASAN for arm64
@ 2015-10-12 15:52 ` Andrey Ryabinin
  0 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-10-12 15:52 UTC (permalink / raw)
  To: Will Deacon, Catalin Marinas, linux-arm-kernel
  Cc: Andrey Ryabinin, Linus Walleij, Alexander Potapenko,
	Dmitry Vyukov, Arnd Bergmann, linux-kernel, David Keitel,
	linux-mm, kasan-dev, Alexey Klimov, Yury, Andrey Konovalov,
	Ard Biesheuvel

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

-- 
2.4.9

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [PATCH v7 0/4] KASAN for arm64
@ 2015-10-12 15:52 ` Andrey Ryabinin
  0 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-10-12 15:52 UTC (permalink / raw)
  To: linux-arm-kernel

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

-- 
2.4.9

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [PATCH v7 1/4] arm64: move PGD_SIZE definition to pgalloc.h
  2015-10-12 15:52 ` Andrey Ryabinin
  (?)
@ 2015-10-12 15:52   ` Andrey Ryabinin
  -1 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-10-12 15:52 UTC (permalink / raw)
  To: Will Deacon, Catalin Marinas, linux-arm-kernel
  Cc: Andrey Ryabinin, Linus Walleij, Alexander Potapenko,
	Dmitry Vyukov, Arnd Bergmann, linux-kernel, David Keitel,
	linux-mm, kasan-dev, Alexey Klimov, Yury, Andrey Konovalov,
	Ard Biesheuvel

This will be used by KASAN latter.

Signed-off-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
---
 arch/arm64/include/asm/pgalloc.h | 1 +
 arch/arm64/mm/pgd.c              | 2 --
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/pgalloc.h b/arch/arm64/include/asm/pgalloc.h
index 7642056..c150539 100644
--- a/arch/arm64/include/asm/pgalloc.h
+++ b/arch/arm64/include/asm/pgalloc.h
@@ -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
 
diff --git a/arch/arm64/mm/pgd.c b/arch/arm64/mm/pgd.c
index 71ca104..cb3ba1b 100644
--- a/arch/arm64/mm/pgd.c
+++ b/arch/arm64/mm/pgd.c
@@ -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)
-- 
2.4.9


^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v7 1/4] arm64: move PGD_SIZE definition to pgalloc.h
@ 2015-10-12 15:52   ` Andrey Ryabinin
  0 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-10-12 15:52 UTC (permalink / raw)
  To: Will Deacon, Catalin Marinas, linux-arm-kernel
  Cc: Andrey Ryabinin, Linus Walleij, Alexander Potapenko,
	Dmitry Vyukov, Arnd Bergmann, linux-kernel, David Keitel,
	linux-mm, kasan-dev, Alexey Klimov, Yury, Andrey Konovalov,
	Ard Biesheuvel

This will be used by KASAN latter.

Signed-off-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
---
 arch/arm64/include/asm/pgalloc.h | 1 +
 arch/arm64/mm/pgd.c              | 2 --
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/pgalloc.h b/arch/arm64/include/asm/pgalloc.h
index 7642056..c150539 100644
--- a/arch/arm64/include/asm/pgalloc.h
+++ b/arch/arm64/include/asm/pgalloc.h
@@ -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
 
diff --git a/arch/arm64/mm/pgd.c b/arch/arm64/mm/pgd.c
index 71ca104..cb3ba1b 100644
--- a/arch/arm64/mm/pgd.c
+++ b/arch/arm64/mm/pgd.c
@@ -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)
-- 
2.4.9

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v7 1/4] arm64: move PGD_SIZE definition to pgalloc.h
@ 2015-10-12 15:52   ` Andrey Ryabinin
  0 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-10-12 15:52 UTC (permalink / raw)
  To: linux-arm-kernel

This will be used by KASAN latter.

Signed-off-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
---
 arch/arm64/include/asm/pgalloc.h | 1 +
 arch/arm64/mm/pgd.c              | 2 --
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/pgalloc.h b/arch/arm64/include/asm/pgalloc.h
index 7642056..c150539 100644
--- a/arch/arm64/include/asm/pgalloc.h
+++ b/arch/arm64/include/asm/pgalloc.h
@@ -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
 
diff --git a/arch/arm64/mm/pgd.c b/arch/arm64/mm/pgd.c
index 71ca104..cb3ba1b 100644
--- a/arch/arm64/mm/pgd.c
+++ b/arch/arm64/mm/pgd.c
@@ -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)
-- 
2.4.9

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v7 2/4] arm64: add KASAN support
  2015-10-12 15:52 ` Andrey Ryabinin
  (?)
@ 2015-10-12 15:52   ` Andrey Ryabinin
  -1 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-10-12 15:52 UTC (permalink / raw)
  To: Will Deacon, Catalin Marinas, linux-arm-kernel
  Cc: Andrey Ryabinin, Linus Walleij, Alexander Potapenko,
	Dmitry Vyukov, Arnd Bergmann, linux-kernel, David Keitel,
	linux-mm, kasan-dev, Alexey Klimov, Yury, Andrey Konovalov,
	Ard Biesheuvel

This 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.

Signed-off-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Tested-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
---
 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

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 1b35bdb..2782c11 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -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
diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index f9914d7..f41c676 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -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/
diff --git a/arch/arm64/include/asm/kasan.h b/arch/arm64/include/asm/kasan.h
new file mode 100644
index 0000000..71dfe14
--- /dev/null
+++ b/arch/arm64/include/asm/kasan.h
@@ -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
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 3f481ef..e3b515f 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -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))
diff --git a/arch/arm64/include/asm/string.h b/arch/arm64/include/asm/string.h
index 64d2d48..2eb714c 100644
--- a/arch/arm64/include/asm/string.h
+++ b/arch/arm64/include/asm/string.h
@@ -36,17 +36,33 @@ extern __kernel_size_t strnlen(const char *, __kernel_size_t);
 
 #define __HAVE_ARCH_MEMCPY
 extern void *memcpy(void *, const void *, __kernel_size_t);
+extern void *__memcpy(void *, const void *, __kernel_size_t);
 
 #define __HAVE_ARCH_MEMMOVE
 extern void *memmove(void *, const void *, __kernel_size_t);
+extern void *__memmove(void *, const void *, __kernel_size_t);
 
 #define __HAVE_ARCH_MEMCHR
 extern void *memchr(const void *, int, __kernel_size_t);
 
 #define __HAVE_ARCH_MEMSET
 extern void *memset(void *, int, __kernel_size_t);
+extern void *__memset(void *, int, __kernel_size_t);
 
 #define __HAVE_ARCH_MEMCMP
 extern 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
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 7b17f62..1b6bda2 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -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
diff --git a/arch/arm64/kernel/arm64ksyms.c b/arch/arm64/kernel/arm64ksyms.c
index a85843d..3b6d8cc 100644
--- a/arch/arm64/kernel/arm64ksyms.c
+++ b/arch/arm64/kernel/arm64ksyms.c
@@ -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);
 
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index 28a81e9..2a8c1d5 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -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)
 
diff --git a/arch/arm64/kernel/image.h b/arch/arm64/kernel/image.h
index e083af0..6eb8fee 100644
--- a/arch/arm64/kernel/image.h
+++ b/arch/arm64/kernel/image.h
@@ -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;
diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c
index 876eb8d..f4bc779 100644
--- a/arch/arm64/kernel/module.c
+++ b/arch/arm64/kernel/module.c
@@ -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 {
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 6bab21f..79df79a 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -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();
diff --git a/arch/arm64/lib/memcpy.S b/arch/arm64/lib/memcpy.S
index 36a6a62..6761393 100644
--- a/arch/arm64/lib/memcpy.S
+++ b/arch/arm64/lib/memcpy.S
@@ -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)
diff --git a/arch/arm64/lib/memmove.S b/arch/arm64/lib/memmove.S
index 68e2f20..a5a4459 100644
--- a/arch/arm64/lib/memmove.S
+++ b/arch/arm64/lib/memmove.S
@@ -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)
diff --git a/arch/arm64/lib/memset.S b/arch/arm64/lib/memset.S
index 29f405f..f2670a9 100644
--- a/arch/arm64/lib/memset.S
+++ b/arch/arm64/lib/memset.S
@@ -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)
diff --git a/arch/arm64/mm/Makefile b/arch/arm64/mm/Makefile
index 773d37a..57f57fd 100644
--- a/arch/arm64/mm/Makefile
+++ b/arch/arm64/mm/Makefile
@@ -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
diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c
new file mode 100644
index 0000000..b6a92f5
--- /dev/null
+++ b/arch/arm64/mm/kasan_init.c
@@ -0,0 +1,165 @@
+/*
+ * This file contains kasan initialization code for ARM64.
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Author: Andrey Ryabinin <ryabinin.a.a@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#define pr_fmt(fmt) "kasan: " fmt
+#include <linux/kasan.h>
+#include <linux/kernel.h>
+#include <linux/memblock.h>
+#include <linux/start_kernel.h>
+
+#include <asm/page.h>
+#include <asm/pgalloc.h>
+#include <asm/pgtable.h>
+#include <asm/tlbflush.h>
+
+static pgd_t tmp_pg_dir[PTRS_PER_PGD] __initdata __aligned(PGD_SIZE);
+
+static void __init kasan_early_pte_populate(pmd_t *pmd, unsigned long addr,
+					unsigned long end)
+{
+	pte_t *pte;
+	unsigned long next;
+
+	if (pmd_none(*pmd))
+		pmd_populate_kernel(&init_mm, pmd, kasan_zero_pte);
+
+	pte = pte_offset_kernel(pmd, addr);
+	do {
+		next = addr + PAGE_SIZE;
+		set_pte(pte, pfn_pte(virt_to_pfn(kasan_zero_page),
+					PAGE_KERNEL));
+	} while (pte++, addr = next, addr != end && pte_none(*pte));
+}
+
+static void __init kasan_early_pmd_populate(pud_t *pud,
+					unsigned long addr,
+					unsigned long end)
+{
+	pmd_t *pmd;
+	unsigned long next;
+
+	if (pud_none(*pud))
+		pud_populate(&init_mm, pud, kasan_zero_pmd);
+
+	pmd = pmd_offset(pud, addr);
+	do {
+		next = pmd_addr_end(addr, end);
+		kasan_early_pte_populate(pmd, addr, next);
+	} while (pmd++, addr = next, addr != end && pmd_none(*pmd));
+}
+
+static void __init kasan_early_pud_populate(pgd_t *pgd,
+					unsigned long addr,
+					unsigned long end)
+{
+	pud_t *pud;
+	unsigned long next;
+
+	if (pgd_none(*pgd))
+		pgd_populate(&init_mm, pgd, kasan_zero_pud);
+
+	pud = pud_offset(pgd, addr);
+	do {
+		next = pud_addr_end(addr, end);
+		kasan_early_pmd_populate(pud, addr, next);
+	} while (pud++, addr = next, addr != end && pud_none(*pud));
+}
+
+static void __init kasan_map_early_shadow(void)
+{
+	unsigned long addr = KASAN_SHADOW_START;
+	unsigned long end = KASAN_SHADOW_END;
+	unsigned long next;
+	pgd_t *pgd;
+
+	pgd = pgd_offset_k(addr);
+	do {
+		next = pgd_addr_end(addr, end);
+		kasan_early_pud_populate(pgd, addr, next);
+	} while (pgd++, addr = next, addr != end);
+}
+
+void __init kasan_early_init(void)
+{
+	BUILD_BUG_ON(KASAN_SHADOW_OFFSET != KASAN_SHADOW_END - (1UL << 61));
+	BUILD_BUG_ON(!IS_ALIGNED(KASAN_SHADOW_START, PGDIR_SIZE));
+	BUILD_BUG_ON(!IS_ALIGNED(KASAN_SHADOW_END, PGDIR_SIZE));
+	kasan_map_early_shadow();
+}
+
+static void __init clear_pgds(unsigned long start,
+			unsigned long end)
+{
+	/*
+	 * Remove references to kasan page tables from
+	 * swapper_pg_dir. pgd_clear() can't be used
+	 * here because it's nop on 2,3-level pagetable setups
+	 */
+	for (; start < end; start += PGDIR_SIZE)
+		set_pgd(pgd_offset_k(start), __pgd(0));
+}
+
+static void __init cpu_set_ttbr1(unsigned long ttbr1)
+{
+	asm(
+	"	msr	ttbr1_el1, %0\n"
+	"	isb"
+	:
+	: "r" (ttbr1));
+}
+
+void __init kasan_init(void)
+{
+	struct memblock_region *reg;
+
+	/*
+	 * 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));
+	cpu_set_ttbr1(__pa(tmp_pg_dir));
+	flush_tlb_all();
+
+	clear_pgds(KASAN_SHADOW_START, KASAN_SHADOW_END);
+
+	kasan_populate_zero_shadow((void *)KASAN_SHADOW_START,
+			kasan_mem_to_shadow((void *)MODULES_VADDR));
+
+	for_each_memblock(memory, reg) {
+		void *start = (void *)__phys_to_virt(reg->base);
+		void *end = (void *)__phys_to_virt(reg->base + reg->size);
+
+		if (start >= end)
+			break;
+
+		/*
+		 * end + 1 here is intentional. We check several shadow bytes in
+		 * advance to slightly speed up fastpath. In some rare cases
+		 * we could cross boundary of mapped shadow, so we just map
+		 * some more here.
+		 */
+		vmemmap_populate((unsigned long)kasan_mem_to_shadow(start),
+				(unsigned long)kasan_mem_to_shadow(end) + 1,
+				pfn_to_nid(virt_to_pfn(start)));
+	}
+
+	memset(kasan_zero_page, 0, PAGE_SIZE);
+	cpu_set_ttbr1(__pa(swapper_pg_dir));
+	flush_tlb_all();
+
+	/* At this point kasan is fully initialized. Enable error messages */
+	init_task.kasan_depth = 0;
+	pr_info("KernelAddressSanitizer initialized\n");
+}
diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile
index 6fd3da9..413fcf2 100644
--- a/drivers/firmware/efi/Makefile
+++ b/drivers/firmware/efi/Makefile
@@ -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
diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan
index 3f874d2..37323b0 100644
--- a/scripts/Makefile.kasan
+++ b/scripts/Makefile.kasan
@@ -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))
 
-- 
2.4.9


^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v7 2/4] arm64: add KASAN support
@ 2015-10-12 15:52   ` Andrey Ryabinin
  0 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-10-12 15:52 UTC (permalink / raw)
  To: Will Deacon, Catalin Marinas, linux-arm-kernel
  Cc: Andrey Ryabinin, Linus Walleij, Alexander Potapenko,
	Dmitry Vyukov, Arnd Bergmann, linux-kernel, David Keitel,
	linux-mm, kasan-dev, Alexey Klimov, Yury, Andrey Konovalov,
	Ard Biesheuvel

This 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.

Signed-off-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Tested-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
---
 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

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 1b35bdb..2782c11 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -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
diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index f9914d7..f41c676 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -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/
diff --git a/arch/arm64/include/asm/kasan.h b/arch/arm64/include/asm/kasan.h
new file mode 100644
index 0000000..71dfe14
--- /dev/null
+++ b/arch/arm64/include/asm/kasan.h
@@ -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
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 3f481ef..e3b515f 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -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))
diff --git a/arch/arm64/include/asm/string.h b/arch/arm64/include/asm/string.h
index 64d2d48..2eb714c 100644
--- a/arch/arm64/include/asm/string.h
+++ b/arch/arm64/include/asm/string.h
@@ -36,17 +36,33 @@ extern __kernel_size_t strnlen(const char *, __kernel_size_t);
 
 #define __HAVE_ARCH_MEMCPY
 extern void *memcpy(void *, const void *, __kernel_size_t);
+extern void *__memcpy(void *, const void *, __kernel_size_t);
 
 #define __HAVE_ARCH_MEMMOVE
 extern void *memmove(void *, const void *, __kernel_size_t);
+extern void *__memmove(void *, const void *, __kernel_size_t);
 
 #define __HAVE_ARCH_MEMCHR
 extern void *memchr(const void *, int, __kernel_size_t);
 
 #define __HAVE_ARCH_MEMSET
 extern void *memset(void *, int, __kernel_size_t);
+extern void *__memset(void *, int, __kernel_size_t);
 
 #define __HAVE_ARCH_MEMCMP
 extern 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
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 7b17f62..1b6bda2 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -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
diff --git a/arch/arm64/kernel/arm64ksyms.c b/arch/arm64/kernel/arm64ksyms.c
index a85843d..3b6d8cc 100644
--- a/arch/arm64/kernel/arm64ksyms.c
+++ b/arch/arm64/kernel/arm64ksyms.c
@@ -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);
 
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index 28a81e9..2a8c1d5 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -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)
 
diff --git a/arch/arm64/kernel/image.h b/arch/arm64/kernel/image.h
index e083af0..6eb8fee 100644
--- a/arch/arm64/kernel/image.h
+++ b/arch/arm64/kernel/image.h
@@ -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;
diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c
index 876eb8d..f4bc779 100644
--- a/arch/arm64/kernel/module.c
+++ b/arch/arm64/kernel/module.c
@@ -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 {
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 6bab21f..79df79a 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -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();
diff --git a/arch/arm64/lib/memcpy.S b/arch/arm64/lib/memcpy.S
index 36a6a62..6761393 100644
--- a/arch/arm64/lib/memcpy.S
+++ b/arch/arm64/lib/memcpy.S
@@ -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)
diff --git a/arch/arm64/lib/memmove.S b/arch/arm64/lib/memmove.S
index 68e2f20..a5a4459 100644
--- a/arch/arm64/lib/memmove.S
+++ b/arch/arm64/lib/memmove.S
@@ -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)
diff --git a/arch/arm64/lib/memset.S b/arch/arm64/lib/memset.S
index 29f405f..f2670a9 100644
--- a/arch/arm64/lib/memset.S
+++ b/arch/arm64/lib/memset.S
@@ -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)
diff --git a/arch/arm64/mm/Makefile b/arch/arm64/mm/Makefile
index 773d37a..57f57fd 100644
--- a/arch/arm64/mm/Makefile
+++ b/arch/arm64/mm/Makefile
@@ -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
diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c
new file mode 100644
index 0000000..b6a92f5
--- /dev/null
+++ b/arch/arm64/mm/kasan_init.c
@@ -0,0 +1,165 @@
+/*
+ * This file contains kasan initialization code for ARM64.
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Author: Andrey Ryabinin <ryabinin.a.a@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#define pr_fmt(fmt) "kasan: " fmt
+#include <linux/kasan.h>
+#include <linux/kernel.h>
+#include <linux/memblock.h>
+#include <linux/start_kernel.h>
+
+#include <asm/page.h>
+#include <asm/pgalloc.h>
+#include <asm/pgtable.h>
+#include <asm/tlbflush.h>
+
+static pgd_t tmp_pg_dir[PTRS_PER_PGD] __initdata __aligned(PGD_SIZE);
+
+static void __init kasan_early_pte_populate(pmd_t *pmd, unsigned long addr,
+					unsigned long end)
+{
+	pte_t *pte;
+	unsigned long next;
+
+	if (pmd_none(*pmd))
+		pmd_populate_kernel(&init_mm, pmd, kasan_zero_pte);
+
+	pte = pte_offset_kernel(pmd, addr);
+	do {
+		next = addr + PAGE_SIZE;
+		set_pte(pte, pfn_pte(virt_to_pfn(kasan_zero_page),
+					PAGE_KERNEL));
+	} while (pte++, addr = next, addr != end && pte_none(*pte));
+}
+
+static void __init kasan_early_pmd_populate(pud_t *pud,
+					unsigned long addr,
+					unsigned long end)
+{
+	pmd_t *pmd;
+	unsigned long next;
+
+	if (pud_none(*pud))
+		pud_populate(&init_mm, pud, kasan_zero_pmd);
+
+	pmd = pmd_offset(pud, addr);
+	do {
+		next = pmd_addr_end(addr, end);
+		kasan_early_pte_populate(pmd, addr, next);
+	} while (pmd++, addr = next, addr != end && pmd_none(*pmd));
+}
+
+static void __init kasan_early_pud_populate(pgd_t *pgd,
+					unsigned long addr,
+					unsigned long end)
+{
+	pud_t *pud;
+	unsigned long next;
+
+	if (pgd_none(*pgd))
+		pgd_populate(&init_mm, pgd, kasan_zero_pud);
+
+	pud = pud_offset(pgd, addr);
+	do {
+		next = pud_addr_end(addr, end);
+		kasan_early_pmd_populate(pud, addr, next);
+	} while (pud++, addr = next, addr != end && pud_none(*pud));
+}
+
+static void __init kasan_map_early_shadow(void)
+{
+	unsigned long addr = KASAN_SHADOW_START;
+	unsigned long end = KASAN_SHADOW_END;
+	unsigned long next;
+	pgd_t *pgd;
+
+	pgd = pgd_offset_k(addr);
+	do {
+		next = pgd_addr_end(addr, end);
+		kasan_early_pud_populate(pgd, addr, next);
+	} while (pgd++, addr = next, addr != end);
+}
+
+void __init kasan_early_init(void)
+{
+	BUILD_BUG_ON(KASAN_SHADOW_OFFSET != KASAN_SHADOW_END - (1UL << 61));
+	BUILD_BUG_ON(!IS_ALIGNED(KASAN_SHADOW_START, PGDIR_SIZE));
+	BUILD_BUG_ON(!IS_ALIGNED(KASAN_SHADOW_END, PGDIR_SIZE));
+	kasan_map_early_shadow();
+}
+
+static void __init clear_pgds(unsigned long start,
+			unsigned long end)
+{
+	/*
+	 * Remove references to kasan page tables from
+	 * swapper_pg_dir. pgd_clear() can't be used
+	 * here because it's nop on 2,3-level pagetable setups
+	 */
+	for (; start < end; start += PGDIR_SIZE)
+		set_pgd(pgd_offset_k(start), __pgd(0));
+}
+
+static void __init cpu_set_ttbr1(unsigned long ttbr1)
+{
+	asm(
+	"	msr	ttbr1_el1, %0\n"
+	"	isb"
+	:
+	: "r" (ttbr1));
+}
+
+void __init kasan_init(void)
+{
+	struct memblock_region *reg;
+
+	/*
+	 * 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));
+	cpu_set_ttbr1(__pa(tmp_pg_dir));
+	flush_tlb_all();
+
+	clear_pgds(KASAN_SHADOW_START, KASAN_SHADOW_END);
+
+	kasan_populate_zero_shadow((void *)KASAN_SHADOW_START,
+			kasan_mem_to_shadow((void *)MODULES_VADDR));
+
+	for_each_memblock(memory, reg) {
+		void *start = (void *)__phys_to_virt(reg->base);
+		void *end = (void *)__phys_to_virt(reg->base + reg->size);
+
+		if (start >= end)
+			break;
+
+		/*
+		 * end + 1 here is intentional. We check several shadow bytes in
+		 * advance to slightly speed up fastpath. In some rare cases
+		 * we could cross boundary of mapped shadow, so we just map
+		 * some more here.
+		 */
+		vmemmap_populate((unsigned long)kasan_mem_to_shadow(start),
+				(unsigned long)kasan_mem_to_shadow(end) + 1,
+				pfn_to_nid(virt_to_pfn(start)));
+	}
+
+	memset(kasan_zero_page, 0, PAGE_SIZE);
+	cpu_set_ttbr1(__pa(swapper_pg_dir));
+	flush_tlb_all();
+
+	/* At this point kasan is fully initialized. Enable error messages */
+	init_task.kasan_depth = 0;
+	pr_info("KernelAddressSanitizer initialized\n");
+}
diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile
index 6fd3da9..413fcf2 100644
--- a/drivers/firmware/efi/Makefile
+++ b/drivers/firmware/efi/Makefile
@@ -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
diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan
index 3f874d2..37323b0 100644
--- a/scripts/Makefile.kasan
+++ b/scripts/Makefile.kasan
@@ -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))
 
-- 
2.4.9

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v7 2/4] arm64: add KASAN support
@ 2015-10-12 15:52   ` Andrey Ryabinin
  0 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-10-12 15:52 UTC (permalink / raw)
  To: linux-arm-kernel

This 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.

Signed-off-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Tested-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
---
 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

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 1b35bdb..2782c11 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -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
diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index f9914d7..f41c676 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -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/
diff --git a/arch/arm64/include/asm/kasan.h b/arch/arm64/include/asm/kasan.h
new file mode 100644
index 0000000..71dfe14
--- /dev/null
+++ b/arch/arm64/include/asm/kasan.h
@@ -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
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 3f481ef..e3b515f 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -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))
diff --git a/arch/arm64/include/asm/string.h b/arch/arm64/include/asm/string.h
index 64d2d48..2eb714c 100644
--- a/arch/arm64/include/asm/string.h
+++ b/arch/arm64/include/asm/string.h
@@ -36,17 +36,33 @@ extern __kernel_size_t strnlen(const char *, __kernel_size_t);
 
 #define __HAVE_ARCH_MEMCPY
 extern void *memcpy(void *, const void *, __kernel_size_t);
+extern void *__memcpy(void *, const void *, __kernel_size_t);
 
 #define __HAVE_ARCH_MEMMOVE
 extern void *memmove(void *, const void *, __kernel_size_t);
+extern void *__memmove(void *, const void *, __kernel_size_t);
 
 #define __HAVE_ARCH_MEMCHR
 extern void *memchr(const void *, int, __kernel_size_t);
 
 #define __HAVE_ARCH_MEMSET
 extern void *memset(void *, int, __kernel_size_t);
+extern void *__memset(void *, int, __kernel_size_t);
 
 #define __HAVE_ARCH_MEMCMP
 extern 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
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 7b17f62..1b6bda2 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -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
diff --git a/arch/arm64/kernel/arm64ksyms.c b/arch/arm64/kernel/arm64ksyms.c
index a85843d..3b6d8cc 100644
--- a/arch/arm64/kernel/arm64ksyms.c
+++ b/arch/arm64/kernel/arm64ksyms.c
@@ -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);
 
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index 28a81e9..2a8c1d5 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -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)
 
diff --git a/arch/arm64/kernel/image.h b/arch/arm64/kernel/image.h
index e083af0..6eb8fee 100644
--- a/arch/arm64/kernel/image.h
+++ b/arch/arm64/kernel/image.h
@@ -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;
diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c
index 876eb8d..f4bc779 100644
--- a/arch/arm64/kernel/module.c
+++ b/arch/arm64/kernel/module.c
@@ -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 {
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 6bab21f..79df79a 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -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();
diff --git a/arch/arm64/lib/memcpy.S b/arch/arm64/lib/memcpy.S
index 36a6a62..6761393 100644
--- a/arch/arm64/lib/memcpy.S
+++ b/arch/arm64/lib/memcpy.S
@@ -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)
diff --git a/arch/arm64/lib/memmove.S b/arch/arm64/lib/memmove.S
index 68e2f20..a5a4459 100644
--- a/arch/arm64/lib/memmove.S
+++ b/arch/arm64/lib/memmove.S
@@ -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)
diff --git a/arch/arm64/lib/memset.S b/arch/arm64/lib/memset.S
index 29f405f..f2670a9 100644
--- a/arch/arm64/lib/memset.S
+++ b/arch/arm64/lib/memset.S
@@ -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)
diff --git a/arch/arm64/mm/Makefile b/arch/arm64/mm/Makefile
index 773d37a..57f57fd 100644
--- a/arch/arm64/mm/Makefile
+++ b/arch/arm64/mm/Makefile
@@ -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
diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c
new file mode 100644
index 0000000..b6a92f5
--- /dev/null
+++ b/arch/arm64/mm/kasan_init.c
@@ -0,0 +1,165 @@
+/*
+ * This file contains kasan initialization code for ARM64.
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Author: Andrey Ryabinin <ryabinin.a.a@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#define pr_fmt(fmt) "kasan: " fmt
+#include <linux/kasan.h>
+#include <linux/kernel.h>
+#include <linux/memblock.h>
+#include <linux/start_kernel.h>
+
+#include <asm/page.h>
+#include <asm/pgalloc.h>
+#include <asm/pgtable.h>
+#include <asm/tlbflush.h>
+
+static pgd_t tmp_pg_dir[PTRS_PER_PGD] __initdata __aligned(PGD_SIZE);
+
+static void __init kasan_early_pte_populate(pmd_t *pmd, unsigned long addr,
+					unsigned long end)
+{
+	pte_t *pte;
+	unsigned long next;
+
+	if (pmd_none(*pmd))
+		pmd_populate_kernel(&init_mm, pmd, kasan_zero_pte);
+
+	pte = pte_offset_kernel(pmd, addr);
+	do {
+		next = addr + PAGE_SIZE;
+		set_pte(pte, pfn_pte(virt_to_pfn(kasan_zero_page),
+					PAGE_KERNEL));
+	} while (pte++, addr = next, addr != end && pte_none(*pte));
+}
+
+static void __init kasan_early_pmd_populate(pud_t *pud,
+					unsigned long addr,
+					unsigned long end)
+{
+	pmd_t *pmd;
+	unsigned long next;
+
+	if (pud_none(*pud))
+		pud_populate(&init_mm, pud, kasan_zero_pmd);
+
+	pmd = pmd_offset(pud, addr);
+	do {
+		next = pmd_addr_end(addr, end);
+		kasan_early_pte_populate(pmd, addr, next);
+	} while (pmd++, addr = next, addr != end && pmd_none(*pmd));
+}
+
+static void __init kasan_early_pud_populate(pgd_t *pgd,
+					unsigned long addr,
+					unsigned long end)
+{
+	pud_t *pud;
+	unsigned long next;
+
+	if (pgd_none(*pgd))
+		pgd_populate(&init_mm, pgd, kasan_zero_pud);
+
+	pud = pud_offset(pgd, addr);
+	do {
+		next = pud_addr_end(addr, end);
+		kasan_early_pmd_populate(pud, addr, next);
+	} while (pud++, addr = next, addr != end && pud_none(*pud));
+}
+
+static void __init kasan_map_early_shadow(void)
+{
+	unsigned long addr = KASAN_SHADOW_START;
+	unsigned long end = KASAN_SHADOW_END;
+	unsigned long next;
+	pgd_t *pgd;
+
+	pgd = pgd_offset_k(addr);
+	do {
+		next = pgd_addr_end(addr, end);
+		kasan_early_pud_populate(pgd, addr, next);
+	} while (pgd++, addr = next, addr != end);
+}
+
+void __init kasan_early_init(void)
+{
+	BUILD_BUG_ON(KASAN_SHADOW_OFFSET != KASAN_SHADOW_END - (1UL << 61));
+	BUILD_BUG_ON(!IS_ALIGNED(KASAN_SHADOW_START, PGDIR_SIZE));
+	BUILD_BUG_ON(!IS_ALIGNED(KASAN_SHADOW_END, PGDIR_SIZE));
+	kasan_map_early_shadow();
+}
+
+static void __init clear_pgds(unsigned long start,
+			unsigned long end)
+{
+	/*
+	 * Remove references to kasan page tables from
+	 * swapper_pg_dir. pgd_clear() can't be used
+	 * here because it's nop on 2,3-level pagetable setups
+	 */
+	for (; start < end; start += PGDIR_SIZE)
+		set_pgd(pgd_offset_k(start), __pgd(0));
+}
+
+static void __init cpu_set_ttbr1(unsigned long ttbr1)
+{
+	asm(
+	"	msr	ttbr1_el1, %0\n"
+	"	isb"
+	:
+	: "r" (ttbr1));
+}
+
+void __init kasan_init(void)
+{
+	struct memblock_region *reg;
+
+	/*
+	 * 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));
+	cpu_set_ttbr1(__pa(tmp_pg_dir));
+	flush_tlb_all();
+
+	clear_pgds(KASAN_SHADOW_START, KASAN_SHADOW_END);
+
+	kasan_populate_zero_shadow((void *)KASAN_SHADOW_START,
+			kasan_mem_to_shadow((void *)MODULES_VADDR));
+
+	for_each_memblock(memory, reg) {
+		void *start = (void *)__phys_to_virt(reg->base);
+		void *end = (void *)__phys_to_virt(reg->base + reg->size);
+
+		if (start >= end)
+			break;
+
+		/*
+		 * end + 1 here is intentional. We check several shadow bytes in
+		 * advance to slightly speed up fastpath. In some rare cases
+		 * we could cross boundary of mapped shadow, so we just map
+		 * some more here.
+		 */
+		vmemmap_populate((unsigned long)kasan_mem_to_shadow(start),
+				(unsigned long)kasan_mem_to_shadow(end) + 1,
+				pfn_to_nid(virt_to_pfn(start)));
+	}
+
+	memset(kasan_zero_page, 0, PAGE_SIZE);
+	cpu_set_ttbr1(__pa(swapper_pg_dir));
+	flush_tlb_all();
+
+	/* At this point kasan is fully initialized. Enable error messages */
+	init_task.kasan_depth = 0;
+	pr_info("KernelAddressSanitizer initialized\n");
+}
diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile
index 6fd3da9..413fcf2 100644
--- a/drivers/firmware/efi/Makefile
+++ b/drivers/firmware/efi/Makefile
@@ -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
diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan
index 3f874d2..37323b0 100644
--- a/scripts/Makefile.kasan
+++ b/scripts/Makefile.kasan
@@ -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))
 
-- 
2.4.9

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v7 3/4] ARM64: kasan: print memory assignment
  2015-10-12 15:52 ` Andrey Ryabinin
  (?)
@ 2015-10-12 15:52   ` Andrey Ryabinin
  -1 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-10-12 15:52 UTC (permalink / raw)
  To: Will Deacon, Catalin Marinas, linux-arm-kernel
  Cc: Linus Walleij, Andrey Ryabinin, Alexander Potapenko,
	Dmitry Vyukov, Arnd Bergmann, linux-kernel, David Keitel,
	linux-mm, kasan-dev, Alexey Klimov, Yury, Andrey Konovalov,
	Ard Biesheuvel

From: Linus Walleij <linus.walleij@linaro.org>

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)

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
---
 arch/arm64/mm/init.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index f5c0680..7a1f9a0 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -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,
-- 
2.4.9


^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v7 3/4] ARM64: kasan: print memory assignment
@ 2015-10-12 15:52   ` Andrey Ryabinin
  0 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-10-12 15:52 UTC (permalink / raw)
  To: Will Deacon, Catalin Marinas, linux-arm-kernel
  Cc: Linus Walleij, Andrey Ryabinin, Alexander Potapenko,
	Dmitry Vyukov, Arnd Bergmann, linux-kernel, David Keitel,
	linux-mm, kasan-dev, Alexey Klimov, Yury, Andrey Konovalov,
	Ard Biesheuvel

From: Linus Walleij <linus.walleij@linaro.org>

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)

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
---
 arch/arm64/mm/init.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index f5c0680..7a1f9a0 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -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,
-- 
2.4.9

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v7 3/4] ARM64: kasan: print memory assignment
@ 2015-10-12 15:52   ` Andrey Ryabinin
  0 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-10-12 15:52 UTC (permalink / raw)
  To: linux-arm-kernel

From: Linus Walleij <linus.walleij@linaro.org>

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)

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
---
 arch/arm64/mm/init.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index f5c0680..7a1f9a0 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -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,
-- 
2.4.9

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v7 4/4] Documentation/features/KASAN: arm64 supports KASAN now
  2015-10-12 15:52 ` Andrey Ryabinin
  (?)
@ 2015-10-12 15:53   ` Andrey Ryabinin
  -1 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-10-12 15:53 UTC (permalink / raw)
  To: Will Deacon, Catalin Marinas, linux-arm-kernel
  Cc: Andrey Ryabinin, Linus Walleij, Alexander Potapenko,
	Dmitry Vyukov, Arnd Bergmann, linux-kernel, David Keitel,
	linux-mm, kasan-dev, Alexey Klimov, Yury, Andrey Konovalov,
	Ard Biesheuvel

Signed-off-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
---
 Documentation/features/debug/KASAN/arch-support.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/features/debug/KASAN/arch-support.txt b/Documentation/features/debug/KASAN/arch-support.txt
index 14531da..703f578 100644
--- a/Documentation/features/debug/KASAN/arch-support.txt
+++ b/Documentation/features/debug/KASAN/arch-support.txt
@@ -9,7 +9,7 @@
     |       alpha: | TODO |
     |         arc: | TODO |
     |         arm: | TODO |
-    |       arm64: | TODO |
+    |       arm64: |  ok  |
     |       avr32: | TODO |
     |    blackfin: | TODO |
     |         c6x: | TODO |
-- 
2.4.9


^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v7 4/4] Documentation/features/KASAN: arm64 supports KASAN now
@ 2015-10-12 15:53   ` Andrey Ryabinin
  0 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-10-12 15:53 UTC (permalink / raw)
  To: Will Deacon, Catalin Marinas, linux-arm-kernel
  Cc: Andrey Ryabinin, Linus Walleij, Alexander Potapenko,
	Dmitry Vyukov, Arnd Bergmann, linux-kernel, David Keitel,
	linux-mm, kasan-dev, Alexey Klimov, Yury, Andrey Konovalov,
	Ard Biesheuvel

Signed-off-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
---
 Documentation/features/debug/KASAN/arch-support.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/features/debug/KASAN/arch-support.txt b/Documentation/features/debug/KASAN/arch-support.txt
index 14531da..703f578 100644
--- a/Documentation/features/debug/KASAN/arch-support.txt
+++ b/Documentation/features/debug/KASAN/arch-support.txt
@@ -9,7 +9,7 @@
     |       alpha: | TODO |
     |         arc: | TODO |
     |         arm: | TODO |
-    |       arm64: | TODO |
+    |       arm64: |  ok  |
     |       avr32: | TODO |
     |    blackfin: | TODO |
     |         c6x: | TODO |
-- 
2.4.9

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v7 4/4] Documentation/features/KASAN: arm64 supports KASAN now
@ 2015-10-12 15:53   ` Andrey Ryabinin
  0 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-10-12 15:53 UTC (permalink / raw)
  To: linux-arm-kernel

Signed-off-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
---
 Documentation/features/debug/KASAN/arch-support.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/features/debug/KASAN/arch-support.txt b/Documentation/features/debug/KASAN/arch-support.txt
index 14531da..703f578 100644
--- a/Documentation/features/debug/KASAN/arch-support.txt
+++ b/Documentation/features/debug/KASAN/arch-support.txt
@@ -9,7 +9,7 @@
     |       alpha: | TODO |
     |         arc: | TODO |
     |         arm: | TODO |
-    |       arm64: | TODO |
+    |       arm64: |  ok  |
     |       avr32: | TODO |
     |    blackfin: | TODO |
     |         c6x: | TODO |
-- 
2.4.9

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
  2015-10-12 15:52 ` Andrey Ryabinin
  (?)
@ 2015-10-13  8:34   ` Catalin Marinas
  -1 siblings, 0 replies; 54+ messages in thread
From: Catalin Marinas @ 2015-10-13  8:34 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: Will Deacon, linux-arm-kernel, Yury, Alexey Klimov,
	Arnd Bergmann, linux-mm, Andrey Konovalov, Linus Walleij,
	Ard Biesheuvel, linux-kernel, kasan-dev, David Keitel,
	Alexander Potapenko, Dmitry Vyukov

On Mon, Oct 12, 2015 at 06:52:56PM +0300, Andrey Ryabinin wrote:
> 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

Patches queued for 4.4. Thanks.

-- 
Catalin

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
@ 2015-10-13  8:34   ` Catalin Marinas
  0 siblings, 0 replies; 54+ messages in thread
From: Catalin Marinas @ 2015-10-13  8:34 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: Will Deacon, linux-arm-kernel, Yury, Alexey Klimov,
	Arnd Bergmann, linux-mm, Andrey Konovalov, Linus Walleij,
	Ard Biesheuvel, linux-kernel, kasan-dev, David Keitel,
	Alexander Potapenko, Dmitry Vyukov

On Mon, Oct 12, 2015 at 06:52:56PM +0300, Andrey Ryabinin wrote:
> 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

Patches queued for 4.4. Thanks.

-- 
Catalin

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [PATCH v7 0/4] KASAN for arm64
@ 2015-10-13  8:34   ` Catalin Marinas
  0 siblings, 0 replies; 54+ messages in thread
From: Catalin Marinas @ 2015-10-13  8:34 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Oct 12, 2015 at 06:52:56PM +0300, Andrey Ryabinin wrote:
> 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

Patches queued for 4.4. Thanks.

-- 
Catalin

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
  2015-10-13  8:34   ` Catalin Marinas
  (?)
@ 2015-11-16 11:16     ` Suzuki K. Poulose
  -1 siblings, 0 replies; 54+ messages in thread
From: Suzuki K. Poulose @ 2015-11-16 11:16 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, Yury,
	Alexey Klimov, Arnd Bergmann, linux-mm, Andrey Konovalov,
	Linus Walleij, Ard Biesheuvel, linux-kernel, kasan-dev,
	David Keitel, Alexander Potapenko, Dmitry Vyukov

On 13/10/15 09:34, Catalin Marinas wrote:
> On Mon, Oct 12, 2015 at 06:52:56PM +0300, Andrey Ryabinin wrote:
>> 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
>
> Patches 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


^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
@ 2015-11-16 11:16     ` Suzuki K. Poulose
  0 siblings, 0 replies; 54+ messages in thread
From: Suzuki K. Poulose @ 2015-11-16 11:16 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, Yury,
	Alexey Klimov, Arnd Bergmann, linux-mm, Andrey Konovalov,
	Linus Walleij, Ard Biesheuvel, linux-kernel, kasan-dev,
	David Keitel, Alexander Potapenko, Dmitry Vyukov

On 13/10/15 09:34, Catalin Marinas wrote:
> On Mon, Oct 12, 2015 at 06:52:56PM +0300, Andrey Ryabinin wrote:
>> 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
>
> Patches 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

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [PATCH v7 0/4] KASAN for arm64
@ 2015-11-16 11:16     ` Suzuki K. Poulose
  0 siblings, 0 replies; 54+ messages in thread
From: Suzuki K. Poulose @ 2015-11-16 11:16 UTC (permalink / raw)
  To: linux-arm-kernel

On 13/10/15 09:34, Catalin Marinas wrote:
> On Mon, Oct 12, 2015 at 06:52:56PM +0300, Andrey Ryabinin wrote:
>> 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
>
> Patches 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

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
  2015-11-16 11:16     ` Suzuki K. Poulose
  (?)
@ 2015-11-16 15:34       ` Andrey Ryabinin
  -1 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-11-16 15:34 UTC (permalink / raw)
  To: Suzuki K. Poulose
  Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, Yury,
	Alexey Klimov, Arnd Bergmann, linux-mm, Andrey Konovalov,
	Linus Walleij, Ard Biesheuvel, linux-kernel, kasan-dev,
	David Keitel, Alexander Potapenko, Dmitry Vyukov

On 11/16/2015 02:16 PM, Suzuki K. Poulose wrote:
> On 13/10/15 09:34, Catalin Marinas wrote:
>> On Mon, Oct 12, 2015 at 06:52:56PM +0300, Andrey Ryabinin wrote:
>>> 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
>>
>> Patches 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 ?
> 

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().



> Cheers
> Suzuki
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
@ 2015-11-16 15:34       ` Andrey Ryabinin
  0 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-11-16 15:34 UTC (permalink / raw)
  To: Suzuki K. Poulose
  Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, Yury,
	Alexey Klimov, Arnd Bergmann, linux-mm, Andrey Konovalov,
	Linus Walleij, Ard Biesheuvel, linux-kernel, kasan-dev,
	David Keitel, Alexander Potapenko, Dmitry Vyukov

On 11/16/2015 02:16 PM, Suzuki K. Poulose wrote:
> On 13/10/15 09:34, Catalin Marinas wrote:
>> On Mon, Oct 12, 2015 at 06:52:56PM +0300, Andrey Ryabinin wrote:
>>> 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
>>
>> Patches 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 ?
> 

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().



> Cheers
> Suzuki
> 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [PATCH v7 0/4] KASAN for arm64
@ 2015-11-16 15:34       ` Andrey Ryabinin
  0 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-11-16 15:34 UTC (permalink / raw)
  To: linux-arm-kernel

On 11/16/2015 02:16 PM, Suzuki K. Poulose wrote:
> On 13/10/15 09:34, Catalin Marinas wrote:
>> On Mon, Oct 12, 2015 at 06:52:56PM +0300, Andrey Ryabinin wrote:
>>> 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
>>
>> Patches 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 ?
> 

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().



> Cheers
> Suzuki
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
  2015-11-16 15:34       ` Andrey Ryabinin
  (?)
@ 2015-11-16 16:51         ` Catalin Marinas
  -1 siblings, 0 replies; 54+ messages in thread
From: Catalin Marinas @ 2015-11-16 16:51 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: Suzuki K. Poulose, Yury, Arnd Bergmann, linux-mm, Linus Walleij,
	Ard Biesheuvel, Will Deacon, linux-kernel, kasan-dev,
	Alexey Klimov, Alexander Potapenko, Dmitry Vyukov,
	Andrey Konovalov, David Keitel, linux-arm-kernel

On Mon, Nov 16, 2015 at 06:34:27PM +0300, Andrey Ryabinin wrote:
> On 11/16/2015 02:16 PM, Suzuki K. Poulose wrote:
> > On 13/10/15 09:34, Catalin Marinas wrote:
> >> On Mon, Oct 12, 2015 at 06:52:56PM +0300, Andrey Ryabinin wrote:
> >>> 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
> >>
> >> Patches 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_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 ?
> 
> 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.

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).

-- 
Catalin

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
@ 2015-11-16 16:51         ` Catalin Marinas
  0 siblings, 0 replies; 54+ messages in thread
From: Catalin Marinas @ 2015-11-16 16:51 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: Suzuki K. Poulose, Yury, Arnd Bergmann, linux-mm, Linus Walleij,
	Ard Biesheuvel, Will Deacon, linux-kernel, kasan-dev,
	Alexey Klimov, Alexander Potapenko, Dmitry Vyukov,
	Andrey Konovalov, David Keitel, linux-arm-kernel

On Mon, Nov 16, 2015 at 06:34:27PM +0300, Andrey Ryabinin wrote:
> On 11/16/2015 02:16 PM, Suzuki K. Poulose wrote:
> > On 13/10/15 09:34, Catalin Marinas wrote:
> >> On Mon, Oct 12, 2015 at 06:52:56PM +0300, Andrey Ryabinin wrote:
> >>> 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
> >>
> >> Patches 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_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 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_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 ?
> 
> 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.

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).

-- 
Catalin

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [PATCH v7 0/4] KASAN for arm64
@ 2015-11-16 16:51         ` Catalin Marinas
  0 siblings, 0 replies; 54+ messages in thread
From: Catalin Marinas @ 2015-11-16 16:51 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Nov 16, 2015 at 06:34:27PM +0300, Andrey Ryabinin wrote:
> On 11/16/2015 02:16 PM, Suzuki K. Poulose wrote:
> > On 13/10/15 09:34, Catalin Marinas wrote:
> >> On Mon, Oct 12, 2015 at 06:52:56PM +0300, Andrey Ryabinin wrote:
> >>> 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
> >>
> >> Patches 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_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 ?
> 
> 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.

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).

-- 
Catalin

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
  2015-11-16 15:34       ` Andrey Ryabinin
  (?)
@ 2015-11-17 14:58         ` Suzuki K. Poulose
  -1 siblings, 0 replies; 54+ messages in thread
From: Suzuki K. Poulose @ 2015-11-17 14:58 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, Yury,
	Alexey Klimov, Arnd Bergmann, linux-mm, Andrey Konovalov,
	Linus Walleij, Ard Biesheuvel, linux-kernel, kasan-dev,
	David Keitel, Alexander Potapenko, Dmitry Vyukov

On 16/11/15 15:34, Andrey Ryabinin wrote:
> On 11/16/2015 02:16 PM, Suzuki K. Poulose wrote:
>> On 13/10/15 09:34, Catalin Marinas wrote:
>>> 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_ON failed: !IS_ALIGNED(KASAN_SHADOW_END, PGDIR_SIZE)
>>    _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
>>                                        ^

...

>
> 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.

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 <will.deacon@arm.com>
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.
     
...

diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 0953a97..15ff5b4 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -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


^ permalink raw reply related	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
@ 2015-11-17 14:58         ` Suzuki K. Poulose
  0 siblings, 0 replies; 54+ messages in thread
From: Suzuki K. Poulose @ 2015-11-17 14:58 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, Yury,
	Alexey Klimov, Arnd Bergmann, linux-mm, Andrey Konovalov,
	Linus Walleij, Ard Biesheuvel, linux-kernel, kasan-dev,
	David Keitel, Alexander Potapenko, Dmitry Vyukov

On 16/11/15 15:34, Andrey Ryabinin wrote:
> On 11/16/2015 02:16 PM, Suzuki K. Poulose wrote:
>> On 13/10/15 09:34, Catalin Marinas wrote:
>>> 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_ON failed: !IS_ALIGNED(KASAN_SHADOW_END, PGDIR_SIZE)
>>    _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
>>                                        ^

...

>
> 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.

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 <will.deacon@arm.com>
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.
     
...

diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 0953a97..15ff5b4 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -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

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v7 0/4] KASAN for arm64
@ 2015-11-17 14:58         ` Suzuki K. Poulose
  0 siblings, 0 replies; 54+ messages in thread
From: Suzuki K. Poulose @ 2015-11-17 14:58 UTC (permalink / raw)
  To: linux-arm-kernel

On 16/11/15 15:34, Andrey Ryabinin wrote:
> On 11/16/2015 02:16 PM, Suzuki K. Poulose wrote:
>> On 13/10/15 09:34, Catalin Marinas wrote:
>>> 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_ON failed: !IS_ALIGNED(KASAN_SHADOW_END, PGDIR_SIZE)
>>    _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
>>                                        ^

...

>
> 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.

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 <will.deacon@arm.com>
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.
     
...

diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 0953a97..15ff5b4 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -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

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
  2015-11-17 14:58         ` Suzuki K. Poulose
  (?)
@ 2015-11-17 15:47           ` Andrey Ryabinin
  -1 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-11-17 15:47 UTC (permalink / raw)
  To: Suzuki K. Poulose
  Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, Yury,
	Alexey Klimov, Arnd Bergmann, linux-mm, Andrey Konovalov,
	Linus Walleij, Ard Biesheuvel, linux-kernel, kasan-dev,
	David Keitel, Alexander Potapenko, Dmitry Vyukov



On 11/17/2015 05:58 PM, Suzuki K. Poulose wrote:
> On 16/11/15 15:34, Andrey Ryabinin wrote:
>> On 11/16/2015 02:16 PM, Suzuki K. Poulose wrote:
>>> On 13/10/15 09:34, Catalin Marinas wrote:
>>>> 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_ON failed: !IS_ALIGNED(KASAN_SHADOW_END, PGDIR_SIZE)
>>>    _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
>>>                                        ^
> 
> ...
> 
>>
>> 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.
> 
> 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 <aryabinin@virtuozzo.com>
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.

Reported-by: Suzuki K. Poulose <Suzuki.Poulose@arm.com>
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 arch/arm64/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 9ac16a4..bf7de69 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -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
-- 
2.4.10


^ permalink raw reply related	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
@ 2015-11-17 15:47           ` Andrey Ryabinin
  0 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-11-17 15:47 UTC (permalink / raw)
  To: Suzuki K. Poulose
  Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, Yury,
	Alexey Klimov, Arnd Bergmann, linux-mm, Andrey Konovalov,
	Linus Walleij, Ard Biesheuvel, linux-kernel, kasan-dev,
	David Keitel, Alexander Potapenko, Dmitry Vyukov



On 11/17/2015 05:58 PM, Suzuki K. Poulose wrote:
> On 16/11/15 15:34, Andrey Ryabinin wrote:
>> On 11/16/2015 02:16 PM, Suzuki K. Poulose wrote:
>>> On 13/10/15 09:34, Catalin Marinas wrote:
>>>> 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_ON failed: !IS_ALIGNED(KASAN_SHADOW_END, PGDIR_SIZE)
>>>    _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
>>>                                        ^
> 
> ...
> 
>>
>> 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.
> 
> 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 <aryabinin@virtuozzo.com>
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.

Reported-by: Suzuki K. Poulose <Suzuki.Poulose@arm.com>
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 arch/arm64/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 9ac16a4..bf7de69 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -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
-- 
2.4.10

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v7 0/4] KASAN for arm64
@ 2015-11-17 15:47           ` Andrey Ryabinin
  0 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-11-17 15:47 UTC (permalink / raw)
  To: linux-arm-kernel



On 11/17/2015 05:58 PM, Suzuki K. Poulose wrote:
> On 16/11/15 15:34, Andrey Ryabinin wrote:
>> On 11/16/2015 02:16 PM, Suzuki K. Poulose wrote:
>>> On 13/10/15 09:34, Catalin Marinas wrote:
>>>> 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_ON failed: !IS_ALIGNED(KASAN_SHADOW_END, PGDIR_SIZE)
>>>    _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
>>>                                        ^
> 
> ...
> 
>>
>> 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.
> 
> 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 <aryabinin@virtuozzo.com>
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.

Reported-by: Suzuki K. Poulose <Suzuki.Poulose@arm.com>
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 arch/arm64/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 9ac16a4..bf7de69 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -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
-- 
2.4.10

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
  2015-11-16 16:51         ` Catalin Marinas
  (?)
@ 2015-11-18 14:33           ` Andrey Ryabinin
  -1 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-11-18 14:33 UTC (permalink / raw)
  To: Catalin Marinas
  Cc: Suzuki K. Poulose, Yury, Arnd Bergmann, linux-mm, Linus Walleij,
	Ard Biesheuvel, Will Deacon, linux-kernel, kasan-dev,
	Alexey Klimov, Alexander Potapenko, Dmitry Vyukov,
	Andrey Konovalov, David Keitel, linux-arm-kernel



On 11/16/2015 07:51 PM, Catalin Marinas wrote:
> On Mon, Nov 16, 2015 at 06:34:27PM +0300, Andrey Ryabinin wrote:
>> On 11/16/2015 02:16 PM, Suzuki K. Poulose wrote:
>>> On 13/10/15 09:34, Catalin Marinas wrote:
>>>> On Mon, Oct 12, 2015 at 06:52:56PM +0300, Andrey Ryabinin wrote:
>>>>> 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
>>>>
>>>> Patches 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_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 ?
>>
>> 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.
> 
> 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).
> 

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.





^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
@ 2015-11-18 14:33           ` Andrey Ryabinin
  0 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-11-18 14:33 UTC (permalink / raw)
  To: Catalin Marinas
  Cc: Suzuki K. Poulose, Yury, Arnd Bergmann, linux-mm, Linus Walleij,
	Ard Biesheuvel, Will Deacon, linux-kernel, kasan-dev,
	Alexey Klimov, Alexander Potapenko, Dmitry Vyukov,
	Andrey Konovalov, David Keitel, linux-arm-kernel



On 11/16/2015 07:51 PM, Catalin Marinas wrote:
> On Mon, Nov 16, 2015 at 06:34:27PM +0300, Andrey Ryabinin wrote:
>> On 11/16/2015 02:16 PM, Suzuki K. Poulose wrote:
>>> On 13/10/15 09:34, Catalin Marinas wrote:
>>>> On Mon, Oct 12, 2015 at 06:52:56PM +0300, Andrey Ryabinin wrote:
>>>>> 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
>>>>
>>>> Patches 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_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 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_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 ?
>>
>> 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.
> 
> 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).
> 

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 majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [PATCH v7 0/4] KASAN for arm64
@ 2015-11-18 14:33           ` Andrey Ryabinin
  0 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-11-18 14:33 UTC (permalink / raw)
  To: linux-arm-kernel



On 11/16/2015 07:51 PM, Catalin Marinas wrote:
> On Mon, Nov 16, 2015 at 06:34:27PM +0300, Andrey Ryabinin wrote:
>> On 11/16/2015 02:16 PM, Suzuki K. Poulose wrote:
>>> On 13/10/15 09:34, Catalin Marinas wrote:
>>>> On Mon, Oct 12, 2015 at 06:52:56PM +0300, Andrey Ryabinin wrote:
>>>>> 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
>>>>
>>>> Patches 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_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 ?
>>
>> 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.
> 
> 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).
> 

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.

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
  2015-11-18 14:33           ` Andrey Ryabinin
  (?)
@ 2015-11-18 15:48             ` Suzuki K. Poulose
  -1 siblings, 0 replies; 54+ messages in thread
From: Suzuki K. Poulose @ 2015-11-18 15:48 UTC (permalink / raw)
  To: Andrey Ryabinin, Catalin Marinas
  Cc: Yury, Arnd Bergmann, linux-mm, Linus Walleij, Ard Biesheuvel,
	Will Deacon, linux-kernel, kasan-dev, Alexey Klimov,
	Alexander Potapenko, Dmitry Vyukov, Andrey Konovalov,
	David Keitel, linux-arm-kernel

On 18/11/15 14:33, Andrey Ryabinin wrote:

> 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


^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
@ 2015-11-18 15:48             ` Suzuki K. Poulose
  0 siblings, 0 replies; 54+ messages in thread
From: Suzuki K. Poulose @ 2015-11-18 15:48 UTC (permalink / raw)
  To: Andrey Ryabinin, Catalin Marinas
  Cc: Yury, Arnd Bergmann, linux-mm, Linus Walleij, Ard Biesheuvel,
	Will Deacon, linux-kernel, kasan-dev, Alexey Klimov,
	Alexander Potapenko, Dmitry Vyukov, Andrey Konovalov,
	David Keitel, linux-arm-kernel

On 18/11/15 14:33, Andrey Ryabinin wrote:

> 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

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [PATCH v7 0/4] KASAN for arm64
@ 2015-11-18 15:48             ` Suzuki K. Poulose
  0 siblings, 0 replies; 54+ messages in thread
From: Suzuki K. Poulose @ 2015-11-18 15:48 UTC (permalink / raw)
  To: linux-arm-kernel

On 18/11/15 14:33, Andrey Ryabinin wrote:

> 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

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
  2015-11-18 15:48             ` Suzuki K. Poulose
  (?)
@ 2015-11-18 15:52               ` Ard Biesheuvel
  -1 siblings, 0 replies; 54+ messages in thread
From: Ard Biesheuvel @ 2015-11-18 15:52 UTC (permalink / raw)
  To: Suzuki K. Poulose
  Cc: Andrey Ryabinin, Catalin Marinas, Yury, Arnd Bergmann, linux-mm,
	Linus Walleij, Will Deacon, linux-kernel, kasan-dev,
	Alexey Klimov, Alexander Potapenko, Dmitry Vyukov,
	Andrey Konovalov, David Keitel, linux-arm-kernel

On 18 November 2015 at 16:48, Suzuki K. Poulose <Suzuki.Poulose@arm.com> wrote:
> On 18/11/15 14:33, Andrey Ryabinin wrote:
>
>> 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.

-- 
Ard.

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
@ 2015-11-18 15:52               ` Ard Biesheuvel
  0 siblings, 0 replies; 54+ messages in thread
From: Ard Biesheuvel @ 2015-11-18 15:52 UTC (permalink / raw)
  To: Suzuki K. Poulose
  Cc: Andrey Ryabinin, Catalin Marinas, Yury, Arnd Bergmann, linux-mm,
	Linus Walleij, Will Deacon, linux-kernel, kasan-dev,
	Alexey Klimov, Alexander Potapenko, Dmitry Vyukov,
	Andrey Konovalov, David Keitel, linux-arm-kernel

On 18 November 2015 at 16:48, Suzuki K. Poulose <Suzuki.Poulose@arm.com> wrote:
> On 18/11/15 14:33, Andrey Ryabinin wrote:
>
>> 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.

-- 
Ard.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [PATCH v7 0/4] KASAN for arm64
@ 2015-11-18 15:52               ` Ard Biesheuvel
  0 siblings, 0 replies; 54+ messages in thread
From: Ard Biesheuvel @ 2015-11-18 15:52 UTC (permalink / raw)
  To: linux-arm-kernel

On 18 November 2015 at 16:48, Suzuki K. Poulose <Suzuki.Poulose@arm.com> wrote:
> On 18/11/15 14:33, Andrey Ryabinin wrote:
>
>> 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.

-- 
Ard.

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
  2015-11-18 14:33           ` Andrey Ryabinin
  (?)
@ 2015-11-18 17:24             ` Catalin Marinas
  -1 siblings, 0 replies; 54+ messages in thread
From: Catalin Marinas @ 2015-11-18 17:24 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: linux-arm-kernel, Yury, Arnd Bergmann, Ard Biesheuvel,
	Andrey Konovalov, Linus Walleij, Suzuki K. Poulose, Will Deacon,
	linux-kernel, kasan-dev, linux-mm, Alexander Potapenko,
	Alexey Klimov, David Keitel, Dmitry Vyukov

On Wed, Nov 18, 2015 at 05:33:43PM +0300, Andrey Ryabinin wrote:
> On 11/16/2015 07:51 PM, Catalin Marinas wrote:
> > On Mon, Nov 16, 2015 at 06:34:27PM +0300, Andrey Ryabinin wrote:
> >> On 11/16/2015 02:16 PM, Suzuki K. Poulose wrote:
> >>> 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 ?
> >>
> >> 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.
> > 
> > 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).
> 
> 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));
> 		}

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.

-- 
Catalin

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
@ 2015-11-18 17:24             ` Catalin Marinas
  0 siblings, 0 replies; 54+ messages in thread
From: Catalin Marinas @ 2015-11-18 17:24 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: linux-arm-kernel, Yury, Arnd Bergmann, Ard Biesheuvel,
	Andrey Konovalov, Linus Walleij, Suzuki K. Poulose, Will Deacon,
	linux-kernel, kasan-dev, linux-mm, Alexander Potapenko,
	Alexey Klimov, David Keitel, Dmitry Vyukov

On Wed, Nov 18, 2015 at 05:33:43PM +0300, Andrey Ryabinin wrote:
> On 11/16/2015 07:51 PM, Catalin Marinas wrote:
> > On Mon, Nov 16, 2015 at 06:34:27PM +0300, Andrey Ryabinin wrote:
> >> On 11/16/2015 02:16 PM, Suzuki K. Poulose wrote:
> >>> 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_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 ?
> >>
> >> 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.
> > 
> > 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).
> 
> 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));
> 		}

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.

-- 
Catalin

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [PATCH v7 0/4] KASAN for arm64
@ 2015-11-18 17:24             ` Catalin Marinas
  0 siblings, 0 replies; 54+ messages in thread
From: Catalin Marinas @ 2015-11-18 17:24 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Nov 18, 2015 at 05:33:43PM +0300, Andrey Ryabinin wrote:
> On 11/16/2015 07:51 PM, Catalin Marinas wrote:
> > On Mon, Nov 16, 2015 at 06:34:27PM +0300, Andrey Ryabinin wrote:
> >> On 11/16/2015 02:16 PM, Suzuki K. Poulose wrote:
> >>> 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 ?
> >>
> >> 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.
> > 
> > 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).
> 
> 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));
> 		}

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.

-- 
Catalin

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
  2015-11-17 15:47           ` Andrey Ryabinin
  (?)
@ 2015-11-26 12:10             ` Mark Rutland
  -1 siblings, 0 replies; 54+ messages in thread
From: Mark Rutland @ 2015-11-26 12:10 UTC (permalink / raw)
  To: Andrey Ryabinin, Catalin Marinas
  Cc: Suzuki K. Poulose, Yury, Arnd Bergmann, linux-mm, Linus Walleij,
	Ard Biesheuvel, Will Deacon, linux-kernel, kasan-dev,
	Alexey Klimov, Alexander Potapenko, Dmitry Vyukov,
	Andrey Konovalov, David Keitel, linux-arm-kernel

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:

Acked-by: Mark Rutland <mark.rutland@arm.com>

Thanks,
Mark.

On Tue, Nov 17, 2015 at 06:47:08PM +0300, Andrey Ryabinin wrote:
> We should either add proper Kconfig dependency for now, or just make it work.
> 
> 
> From: Andrey Ryabinin <aryabinin@virtuozzo.com>
> 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.
> 
> Reported-by: Suzuki K. Poulose <Suzuki.Poulose@arm.com>
> Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
> ---
>  arch/arm64/Kconfig | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index 9ac16a4..bf7de69 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -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
> -- 
> 2.4.10
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
@ 2015-11-26 12:10             ` Mark Rutland
  0 siblings, 0 replies; 54+ messages in thread
From: Mark Rutland @ 2015-11-26 12:10 UTC (permalink / raw)
  To: Andrey Ryabinin, Catalin Marinas
  Cc: Suzuki K. Poulose, Yury, Arnd Bergmann, linux-mm, Linus Walleij,
	Ard Biesheuvel, Will Deacon, linux-kernel, kasan-dev,
	Alexey Klimov, Alexander Potapenko, Dmitry Vyukov,
	Andrey Konovalov, David Keitel, linux-arm-kernel

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:

Acked-by: Mark Rutland <mark.rutland@arm.com>

Thanks,
Mark.

On Tue, Nov 17, 2015 at 06:47:08PM +0300, Andrey Ryabinin wrote:
> We should either add proper Kconfig dependency for now, or just make it work.
> 
> 
> From: Andrey Ryabinin <aryabinin@virtuozzo.com>
> 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_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.
> 
> Reported-by: Suzuki K. Poulose <Suzuki.Poulose@arm.com>
> Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
> ---
>  arch/arm64/Kconfig | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index 9ac16a4..bf7de69 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -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
> -- 
> 2.4.10
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [PATCH v7 0/4] KASAN for arm64
@ 2015-11-26 12:10             ` Mark Rutland
  0 siblings, 0 replies; 54+ messages in thread
From: Mark Rutland @ 2015-11-26 12:10 UTC (permalink / raw)
  To: linux-arm-kernel

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:

Acked-by: Mark Rutland <mark.rutland@arm.com>

Thanks,
Mark.

On Tue, Nov 17, 2015 at 06:47:08PM +0300, Andrey Ryabinin wrote:
> We should either add proper Kconfig dependency for now, or just make it work.
> 
> 
> From: Andrey Ryabinin <aryabinin@virtuozzo.com>
> 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.
> 
> Reported-by: Suzuki K. Poulose <Suzuki.Poulose@arm.com>
> Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
> ---
>  arch/arm64/Kconfig | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index 9ac16a4..bf7de69 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -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
> -- 
> 2.4.10
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
  2015-11-26 12:10             ` Mark Rutland
  (?)
@ 2015-11-26 12:22               ` Andrey Ryabinin
  -1 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-11-26 12:22 UTC (permalink / raw)
  To: Mark Rutland, Catalin Marinas
  Cc: Suzuki K. Poulose, Yury, Arnd Bergmann, linux-mm, Linus Walleij,
	Ard Biesheuvel, Will Deacon, linux-kernel, kasan-dev,
	Alexey Klimov, Alexander Potapenko, Dmitry Vyukov, David Keitel,
	linux-arm-kernel

On 11/26/2015 03:10 PM, Mark Rutland wrote:
> 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.

> I stumbled across this myself and was about to post a similar patch.
> 
> FWIW:
> 
> Acked-by: Mark Rutland <mark.rutland@arm.com>
> 
> Thanks,
> Mark.
> 
> On Tue, Nov 17, 2015 at 06:47:08PM +0300, Andrey Ryabinin wrote:
>> We should either add proper Kconfig dependency for now, or just make it work.
>>
>>
>> From: Andrey Ryabinin <aryabinin@virtuozzo.com>
>> 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.
>>
>> Reported-by: Suzuki K. Poulose <Suzuki.Poulose@arm.com>
>> Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
>> ---
>>  arch/arm64/Kconfig | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
>> index 9ac16a4..bf7de69 100644
>> --- a/arch/arm64/Kconfig
>> +++ b/arch/arm64/Kconfig
>> @@ -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
>> -- 
>> 2.4.10
>>
>>
>> _______________________________________________
>> linux-arm-kernel mailing list
>> linux-arm-kernel@lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
@ 2015-11-26 12:22               ` Andrey Ryabinin
  0 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-11-26 12:22 UTC (permalink / raw)
  To: Mark Rutland, Catalin Marinas
  Cc: Suzuki K. Poulose, Yury, Arnd Bergmann, linux-mm, Linus Walleij,
	Ard Biesheuvel, Will Deacon, linux-kernel, kasan-dev,
	Alexey Klimov, Alexander Potapenko, Dmitry Vyukov, David Keitel,
	linux-arm-kernel

On 11/26/2015 03:10 PM, Mark Rutland wrote:
> 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.

> I stumbled across this myself and was about to post a similar patch.
> 
> FWIW:
> 
> Acked-by: Mark Rutland <mark.rutland@arm.com>
> 
> Thanks,
> Mark.
> 
> On Tue, Nov 17, 2015 at 06:47:08PM +0300, Andrey Ryabinin wrote:
>> We should either add proper Kconfig dependency for now, or just make it work.
>>
>>
>> From: Andrey Ryabinin <aryabinin@virtuozzo.com>
>> 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_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.
>>
>> Reported-by: Suzuki K. Poulose <Suzuki.Poulose@arm.com>
>> Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
>> ---
>>  arch/arm64/Kconfig | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
>> index 9ac16a4..bf7de69 100644
>> --- a/arch/arm64/Kconfig
>> +++ b/arch/arm64/Kconfig
>> @@ -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
>> -- 
>> 2.4.10
>>
>>
>> _______________________________________________
>> linux-arm-kernel mailing list
>> linux-arm-kernel@lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [PATCH v7 0/4] KASAN for arm64
@ 2015-11-26 12:22               ` Andrey Ryabinin
  0 siblings, 0 replies; 54+ messages in thread
From: Andrey Ryabinin @ 2015-11-26 12:22 UTC (permalink / raw)
  To: linux-arm-kernel

On 11/26/2015 03:10 PM, Mark Rutland wrote:
> 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.

> I stumbled across this myself and was about to post a similar patch.
> 
> FWIW:
> 
> Acked-by: Mark Rutland <mark.rutland@arm.com>
> 
> Thanks,
> Mark.
> 
> On Tue, Nov 17, 2015 at 06:47:08PM +0300, Andrey Ryabinin wrote:
>> We should either add proper Kconfig dependency for now, or just make it work.
>>
>>
>> From: Andrey Ryabinin <aryabinin@virtuozzo.com>
>> 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.
>>
>> Reported-by: Suzuki K. Poulose <Suzuki.Poulose@arm.com>
>> Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
>> ---
>>  arch/arm64/Kconfig | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
>> index 9ac16a4..bf7de69 100644
>> --- a/arch/arm64/Kconfig
>> +++ b/arch/arm64/Kconfig
>> @@ -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
>> -- 
>> 2.4.10
>>
>>
>> _______________________________________________
>> linux-arm-kernel mailing list
>> linux-arm-kernel at lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
  2015-11-26 12:22               ` Andrey Ryabinin
  (?)
@ 2015-11-26 15:05                 ` Catalin Marinas
  -1 siblings, 0 replies; 54+ messages in thread
From: Catalin Marinas @ 2015-11-26 15:05 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: Mark Rutland, linux-arm-kernel, Yury, Arnd Bergmann,
	Ard Biesheuvel, Linus Walleij, Suzuki K. Poulose, Will Deacon,
	linux-kernel, kasan-dev, linux-mm, Alexander Potapenko,
	Alexey Klimov, David Keitel, Dmitry Vyukov

On Thu, Nov 26, 2015 at 03:22:41PM +0300, Andrey Ryabinin wrote:
> On 11/26/2015 03:10 PM, Mark Rutland wrote:
> > 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.

-- 
Catalin

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v7 0/4] KASAN for arm64
@ 2015-11-26 15:05                 ` Catalin Marinas
  0 siblings, 0 replies; 54+ messages in thread
From: Catalin Marinas @ 2015-11-26 15:05 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: Mark Rutland, linux-arm-kernel, Yury, Arnd Bergmann,
	Ard Biesheuvel, Linus Walleij, Suzuki K. Poulose, Will Deacon,
	linux-kernel, kasan-dev, linux-mm, Alexander Potapenko,
	Alexey Klimov, David Keitel, Dmitry Vyukov

On Thu, Nov 26, 2015 at 03:22:41PM +0300, Andrey Ryabinin wrote:
> On 11/26/2015 03:10 PM, Mark Rutland wrote:
> > 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.

-- 
Catalin

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [PATCH v7 0/4] KASAN for arm64
@ 2015-11-26 15:05                 ` Catalin Marinas
  0 siblings, 0 replies; 54+ messages in thread
From: Catalin Marinas @ 2015-11-26 15:05 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Nov 26, 2015 at 03:22:41PM +0300, Andrey Ryabinin wrote:
> On 11/26/2015 03:10 PM, Mark Rutland wrote:
> > 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.

-- 
Catalin

^ permalink raw reply	[flat|nested] 54+ messages in thread

end of thread, other threads:[~2015-11-26 15:05 UTC | newest]

Thread overview: 54+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-12 15:52 [PATCH v7 0/4] KASAN for arm64 Andrey Ryabinin
2015-10-12 15:52 ` Andrey Ryabinin
2015-10-12 15:52 ` Andrey Ryabinin
2015-10-12 15:52 ` [PATCH v7 1/4] arm64: move PGD_SIZE definition to pgalloc.h Andrey Ryabinin
2015-10-12 15:52   ` Andrey Ryabinin
2015-10-12 15:52   ` Andrey Ryabinin
2015-10-12 15:52 ` [PATCH v7 2/4] arm64: add KASAN support Andrey Ryabinin
2015-10-12 15:52   ` Andrey Ryabinin
2015-10-12 15:52   ` Andrey Ryabinin
2015-10-12 15:52 ` [PATCH v7 3/4] ARM64: kasan: print memory assignment Andrey Ryabinin
2015-10-12 15:52   ` Andrey Ryabinin
2015-10-12 15:52   ` Andrey Ryabinin
2015-10-12 15:53 ` [PATCH v7 4/4] Documentation/features/KASAN: arm64 supports KASAN now Andrey Ryabinin
2015-10-12 15:53   ` Andrey Ryabinin
2015-10-12 15:53   ` Andrey Ryabinin
2015-10-13  8:34 ` [PATCH v7 0/4] KASAN for arm64 Catalin Marinas
2015-10-13  8:34   ` Catalin Marinas
2015-10-13  8:34   ` Catalin Marinas
2015-11-16 11:16   ` Suzuki K. Poulose
2015-11-16 11:16     ` Suzuki K. Poulose
2015-11-16 11:16     ` Suzuki K. Poulose
2015-11-16 15:34     ` Andrey Ryabinin
2015-11-16 15:34       ` Andrey Ryabinin
2015-11-16 15:34       ` Andrey Ryabinin
2015-11-16 16:51       ` Catalin Marinas
2015-11-16 16:51         ` Catalin Marinas
2015-11-16 16:51         ` Catalin Marinas
2015-11-18 14:33         ` Andrey Ryabinin
2015-11-18 14:33           ` Andrey Ryabinin
2015-11-18 14:33           ` Andrey Ryabinin
2015-11-18 15:48           ` Suzuki K. Poulose
2015-11-18 15:48             ` Suzuki K. Poulose
2015-11-18 15:48             ` Suzuki K. Poulose
2015-11-18 15:52             ` Ard Biesheuvel
2015-11-18 15:52               ` Ard Biesheuvel
2015-11-18 15:52               ` Ard Biesheuvel
2015-11-18 17:24           ` Catalin Marinas
2015-11-18 17:24             ` Catalin Marinas
2015-11-18 17:24             ` Catalin Marinas
2015-11-17 14:58       ` Suzuki K. Poulose
2015-11-17 14:58         ` Suzuki K. Poulose
2015-11-17 14:58         ` Suzuki K. Poulose
2015-11-17 15:47         ` Andrey Ryabinin
2015-11-17 15:47           ` Andrey Ryabinin
2015-11-17 15:47           ` Andrey Ryabinin
2015-11-26 12:10           ` Mark Rutland
2015-11-26 12:10             ` Mark Rutland
2015-11-26 12:10             ` Mark Rutland
2015-11-26 12:22             ` Andrey Ryabinin
2015-11-26 12:22               ` Andrey Ryabinin
2015-11-26 12:22               ` Andrey Ryabinin
2015-11-26 15:05               ` Catalin Marinas
2015-11-26 15:05                 ` Catalin Marinas
2015-11-26 15:05                 ` Catalin Marinas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.