]> git.ipfire.org Git - thirdparty/linux.git/blobdiff - arch/s390/boot/kaslr.c
s390/kasan: avoid mapping KASAN shadow for standby memory
[thirdparty/linux.git] / arch / s390 / boot / kaslr.c
index e8d74d4f62aa5ff0cd2284dc66dffca5a5e8ed56..70ff68dd1feec1cb1253817cb7f73b8d6c348cf6 100644 (file)
@@ -172,26 +172,20 @@ static unsigned long position_to_address(unsigned long pos, unsigned long kernel
 
 unsigned long get_random_base(unsigned long safe_addr)
 {
+       unsigned long online_mem_total = get_mem_detect_online_total();
        unsigned long memory_limit = get_mem_detect_end();
        unsigned long base_pos, max_pos, kernel_size;
-       unsigned long kasan_needs;
        int i;
 
-       memory_limit = min(memory_limit, ident_map_size);
-
        /*
         * Avoid putting kernel in the end of physical memory
-        * which kasan will use for shadow memory and early pgtable
-        * mapping allocations.
+        * which vmem and kasan code will use for shadow memory and
+        * pgtable mapping allocations.
         */
-       memory_limit -= kasan_estimate_memory_needs(memory_limit);
+       memory_limit -= kasan_estimate_memory_needs(online_mem_total);
+       memory_limit -= vmem_estimate_memory_needs(online_mem_total);
 
-       if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && initrd_data.start && initrd_data.size) {
-               if (safe_addr < initrd_data.start + initrd_data.size)
-                       safe_addr = initrd_data.start + initrd_data.size;
-       }
        safe_addr = ALIGN(safe_addr, THREAD_SIZE);
-
        kernel_size = vmlinux.image_size + vmlinux.bss_size;
        if (safe_addr + kernel_size > memory_limit)
                return 0;