]> Git Repo - linux.git/commitdiff
x86/mm: Report which part of kernel image is freed
authorKees Cook <[email protected]>
Tue, 29 Oct 2019 21:13:49 +0000 (14:13 -0700)
committerBorislav Petkov <[email protected]>
Mon, 4 Nov 2019 17:50:33 +0000 (18:50 +0100)
The memory freeing report wasn't very useful for figuring out which
parts of the kernel image were being freed. Add the details for clearer
reporting in dmesg.

Before:

  Freeing unused kernel image memory: 1348K
  Write protecting the kernel read-only data: 20480k
  Freeing unused kernel image memory: 2040K
  Freeing unused kernel image memory: 172K

After:

  Freeing unused kernel image (initmem) memory: 1348K
  Write protecting the kernel read-only data: 20480k
  Freeing unused kernel image (text/rodata gap) memory: 2040K
  Freeing unused kernel image (rodata/data gap) memory: 172K

Signed-off-by: Kees Cook <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: Heiko Carstens <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: Michael Ellerman <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Rick Edgecombe <[email protected]>
Cc: Segher Boessenkool <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: x86-ml <[email protected]>
Cc: Yoshinori Sato <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
arch/x86/include/asm/processor.h
arch/x86/mm/init.c
arch/x86/mm/init_64.c

index 6e0a3b43d027a5696739cf647a28cd530f8edb80..790f250d39a897c0326303b3f58e274727ff79a4 100644 (file)
@@ -958,7 +958,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
 
 extern unsigned long arch_align_stack(unsigned long sp);
 void free_init_pages(const char *what, unsigned long begin, unsigned long end);
-extern void free_kernel_image_pages(void *begin, void *end);
+extern void free_kernel_image_pages(const char *what, void *begin, void *end);
 
 void default_idle(void);
 #ifdef CONFIG_XEN
index fd10d91a61152dd18e289f5cf716584a71063100..e7bb483557c9f62a927563f2c748979a0ca1941e 100644 (file)
@@ -829,14 +829,13 @@ void free_init_pages(const char *what, unsigned long begin, unsigned long end)
  * used for the kernel image only.  free_init_pages() will do the
  * right thing for either kind of address.
  */
-void free_kernel_image_pages(void *begin, void *end)
+void free_kernel_image_pages(const char *what, void *begin, void *end)
 {
        unsigned long begin_ul = (unsigned long)begin;
        unsigned long end_ul = (unsigned long)end;
        unsigned long len_pages = (end_ul - begin_ul) >> PAGE_SHIFT;
 
-
-       free_init_pages("unused kernel image", begin_ul, end_ul);
+       free_init_pages(what, begin_ul, end_ul);
 
        /*
         * PTI maps some of the kernel into userspace.  For performance,
@@ -865,7 +864,8 @@ void __ref free_initmem(void)
 
        mem_encrypt_free_decrypted_mem();
 
-       free_kernel_image_pages(&__init_begin, &__init_end);
+       free_kernel_image_pages("unused kernel image (initmem)",
+                               &__init_begin, &__init_end);
 }
 
 #ifdef CONFIG_BLK_DEV_INITRD
index e67ddca8b7a84f24ab2463cfb2379f7a56043677..dcb9bc961b39c3e2928eb4d15f681c8dad29591e 100644 (file)
@@ -1334,8 +1334,10 @@ void mark_rodata_ro(void)
        set_memory_ro(start, (end-start) >> PAGE_SHIFT);
 #endif
 
-       free_kernel_image_pages((void *)text_end, (void *)rodata_start);
-       free_kernel_image_pages((void *)rodata_end, (void *)_sdata);
+       free_kernel_image_pages("unused kernel image (text/rodata gap)",
+                               (void *)text_end, (void *)rodata_start);
+       free_kernel_image_pages("unused kernel image (rodata/data gap)",
+                               (void *)rodata_end, (void *)_sdata);
 
        debug_checkwx();
 }
This page took 0.066103 seconds and 4 git commands to generate.