Skip to contentSkip to conversation

don't use vmemmap_populate() to initialize shadow

PATCH Applied Pavel Tatashin 3 participants 5 messages Nov 3, 2017 – Nov 23, 2017

Subsystems (5)
Memory management x86 arm64 x86 MM +1 more subsystems

v1 of 2 Applied 2/2 Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover don't use vmemmap_populate() to initialize shadow

Andrey Ryabinin asked to replace the three patches in my series:

x86-kasan-add-and-use-kasan_map_populate.patch arm64-kasan-add-and-use-kasan_map_populate.patch arm64-kasan-avoid-using-vmemmap_populate-to-initialise-shadow.patch

With two patches in this thread:

x86/mm/kasan: don't use vmemmap_populate() to initialize shadow arm64/mm/kasan: don't use vmemmap_populate() to initialize shadow

Pavel Tatashin (2):
x86/mm/kasan: don't use vmemmap_populate() to initialize shadow arm64/mm/kasan: don't use vmemmap_populate() to initialize shadow

 arch/arm64/Kconfig          |   2 +-
 arch/arm64/mm/kasan_init.c  | 130 ++++++++++++++++++++++++----------------
 arch/x86/Kconfig            |   2 +-
 arch/x86/mm/kasan_init_64.c | 143 +++++++++++++++++++++++++++++++++++++++++---
 4 files changed, 218 insertions(+), 59 deletions(-)
Signature · 1 line
2.15.0
#1 lore raw

PATCH 1/2 x86/mm/kasan: don't use vmemmap_populate() to initialize shadow

The kasan shadow is currently mapped using vmemmap_populate() since that provides a semi-convenient way to map pages into init_top_pgt. However, since that no longer zeroes the mapped pages, it is not suitable for kasan, which requires zeroed shadow memory.

Add kasan_populate_shadow() interface and use it instead of vmemmap_populate(). Besides, this allows us to take advantage of gigantic pages and use them to populate the shadow, which should save us some memory wasted on page tables and reduce TLB pressure.

---
 arch/x86/Kconfig            |   2 +-
 arch/x86/mm/kasan_init_64.c | 143 +++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 137 insertions(+), 8 deletions(-)
arch/x86/Kconfig +1 -1
index 2fdb23313dd5..2896c14da4c1 100644
@@ -108,7 +108,7 @@ config X86
 	select HAVE_ARCH_AUDITSYSCALL
 	select HAVE_ARCH_HUGE_VMAP		if X86_64 || X86_PAE
 	select HAVE_ARCH_JUMP_LABEL
-	select HAVE_ARCH_KASAN			if X86_64 && SPARSEMEM_VMEMMAP
+	select HAVE_ARCH_KASAN			if X86_64
 	select HAVE_ARCH_KGDB
 	select HAVE_ARCH_KMEMCHECK
 	select HAVE_ARCH_MMAP_RND_BITS		if MMU
arch/x86/mm/kasan_init_64.c +136 -7

178 lines not on this page · raw message

Signature · 1 line
2.15.0
#2 lore raw

[tip:x86/urgent] x86/mm/kasan: Don't use vmemmap_populate() to initialize shadow

x86/mm/kasan: Don't use vmemmap_populate() to initialize shadow
Commit-ID:  f68d62a56708b0c19dca7a998f408510f2fbc3a8
Gitweb:     https://git.kernel.org/tip/f68d62a56708b0c19dca7a998f408510f2fbc3a8
Author:     Andrey Ryabinin <[email protected]>
AuthorDate: Wed, 15 Nov 2017 17:36:35 -0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 22 Nov 2017 07:18:35 +0100

x86/mm/kasan: Don't use vmemmap_populate() to initialize shadow

[ Note, this commit is a cherry-picked version of:

    d17a1d97dc20: ("x86/mm/kasan: don't use vmemmap_populate() to initialize shadow")

... for easier x86 entry code testing and back-porting. ]

The KASAN shadow is currently mapped using vmemmap_populate() since that provides a semi-convenient way to map pages into init_top_pgt. However, since that no longer zeroes the mapped pages, it is not suitable for KASAN, which requires zeroed shadow memory.

Add kasan_populate_shadow() interface and use it instead of vmemmap_populate(). Besides, this allows us to take advantage of gigantic pages and use them to populate the shadow, which should save us some memory wasted on page tables and reduce TLB pressure.

Cc Andy Lutomirski <[email protected]>
Cc Steven Sistare <[email protected]>
Cc Daniel Jordan <[email protected]>
Cc Bob Picco <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Alexander Potapenko <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Catalin Marinas <[email protected]>
Cc Christian Borntraeger <[email protected]>
Cc David S. Miller <[email protected]>
Cc Dmitry Vyukov <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Will Deacon <[email protected]>
---
 arch/x86/Kconfig            |   2 +-
 arch/x86/mm/kasan_init_64.c | 143 +++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 137 insertions(+), 8 deletions(-)
arch/x86/Kconfig +1 -1
index a0623f0..09dcc94 100644
@@ -110,7 +110,7 @@ config X86
 	select HAVE_ARCH_AUDITSYSCALL
 	select HAVE_ARCH_HUGE_VMAP		if X86_64 || X86_PAE
 	select HAVE_ARCH_JUMP_LABEL
-	select HAVE_ARCH_KASAN			if X86_64 && SPARSEMEM_VMEMMAP
+	select HAVE_ARCH_KASAN			if X86_64
 	select HAVE_ARCH_KGDB
 	select HAVE_ARCH_KMEMCHECK
 	select HAVE_ARCH_MMAP_RND_BITS		if MMU
arch/x86/mm/kasan_init_64.c +136 -7

178 lines not on this page · raw message

maintainer
#3 lore raw

Re: [tip:x86/urgent] x86/mm/kasan: Don't use vmemmap_populate() to initialize shadow

Quoted 7 lines · tip-bot for Andrey Ryabinin
Commit-ID:  f68d62a56708b0c19dca7a998f408510f2fbc3a8
Gitweb:     https://git.kernel.org/tip/f68d62a56708b0c19dca7a998f408510f2fbc3a8
Author:     Andrey Ryabinin <[email protected]>
AuthorDate: Wed, 15 Nov 2017 17:36:35 -0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 22 Nov 2017 07:18:35 +0100
Quoted 7 lines

x86/mm/kasan: Don't use vmemmap_populate() to initialize shadow

[ Note, this commit is a cherry-picked version of:

    d17a1d97dc20: ("x86/mm/kasan: don't use vmemmap_populate() to initialize shadow")

... for easier x86 entry code testing and back-porting. ]

I'm confused. Isn't this patch already in Linus' tree, merged in (I think) 7c225c69f86c934e3be9be63ecde754e286838d7?

#4 lore raw

PATCH 2/2 arm64/mm/kasan: don't use vmemmap_populate() to initialize shadow

In reply to Pavel Tatashin

The kasan shadow is currently mapped using vmemmap_populate() since that provides a semi-convenient way to map pages into init_top_pgt. However, since that no longer zeroes the mapped pages, it is not suitable for kasan, which requires zeroed shadow memory.

Add kasan_populate_shadow() interface and use it instead of vmemmap_populate(). Besides, this allows us to take advantage of gigantic pages and use them to populate the shadow, which should save us some memory wasted on page tables and reduce TLB pressure.

---
 arch/arm64/Kconfig         |   2 +-
 arch/arm64/mm/kasan_init.c | 130 ++++++++++++++++++++++++++++-----------------
 2 files changed, 81 insertions(+), 51 deletions(-)
arch/arm64/Kconfig +1 -1
index 0df64a6a56d4..888580b9036e 100644
@@ -68,7 +68,7 @@ config ARM64
 	select HAVE_ARCH_BITREVERSE
 	select HAVE_ARCH_HUGE_VMAP
 	select HAVE_ARCH_JUMP_LABEL
-	select HAVE_ARCH_KASAN if SPARSEMEM_VMEMMAP && !(ARM64_16K_PAGES && ARM64_VA_BITS_48)
+	select HAVE_ARCH_KASAN if !(ARM64_16K_PAGES && ARM64_VA_BITS_48)
 	select HAVE_ARCH_KGDB
 	select HAVE_ARCH_MMAP_RND_BITS
 	select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
arch/arm64/mm/kasan_init.c +80 -50

199 lines not on this page · raw message

Signature · 1 line
2.15.0