s390/kasan: avoid unnecessary moving of vmemmap
authorVasily Gorbik <gor@linux.ibm.com>
Thu, 10 Sep 2020 20:54:58 +0000 (22:54 +0200)
committerVasily Gorbik <gor@linux.ibm.com>
Wed, 16 Sep 2020 12:08:47 +0000 (14:08 +0200)
Currently vmemmap area is unconditionally moved beyond Kasan shadow
memory. When Kasan is not enabled vmemmap area position is calculated
in setup_memory_end() and depends on limiting factors like ultravisor
secure storage limit. Try to follow the same logic with Kasan enabled
as well and avoid unnecessary vmemmap area position changes unless it
really intersects with Kasan shadow.

Reviewed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
arch/s390/kernel/setup.c

index 0477939..d63b08b 100644 (file)
@@ -586,11 +586,15 @@ static void __init setup_memory_end(void)
        /* Take care that memory_end is set and <= vmemmap */
        memory_end = min(memory_end ?: max_physmem_end, (unsigned long)vmemmap);
 #ifdef CONFIG_KASAN
-       /* fit in kasan shadow memory region between 1:1 and vmemmap */
        memory_end = min(memory_end, KASAN_SHADOW_START);
-       vmemmap = max(vmemmap, (struct page *)KASAN_SHADOW_END);
 #endif
        vmemmap_size = SECTION_ALIGN_UP(memory_end / PAGE_SIZE) * sizeof(struct page);
+#ifdef CONFIG_KASAN
+       /* move vmemmap above kasan shadow only if stands in a way */
+       if (KASAN_SHADOW_END > (unsigned long)vmemmap &&
+           (unsigned long)vmemmap + vmemmap_size > KASAN_SHADOW_START)
+               vmemmap = max(vmemmap, (struct page *)KASAN_SHADOW_END);
+#endif
        max_pfn = max_low_pfn = PFN_DOWN(memory_end);
        memblock_remove(memory_end, ULONG_MAX);