Re: [PATCH 07/21] MIPS memblock: Alter elfcorehdr parameters parser

2016-12-18 Thread kbuild test robot
Hi Serge,

[auto build test ERROR on linus/master]
[also build test ERROR on v4.9 next-20161216]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Serge-Semin/MIPS-memblock-Remove-bootmem-code-and-switch-to-NO_BOOTMEM/20161219-105045
config: mips-allyesconfig (attached as .config)
compiler: mips-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget 
https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross
 -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=mips 

All errors (new ones prefixed by >>):

   arch/mips/kernel/setup.c: In function 'mips_reserve_elfcorehdr':
>> arch/mips/kernel/setup.c:439:7: error: implicit declaration of function 
>> 'is_vmcore_usable' [-Werror=implicit-function-declaration]
 if (!is_vmcore_usable())
  ^~~~
>> arch/mips/kernel/setup.c:443:6: error: 'elfcorehdr_addr' undeclared (first 
>> use in this function)
 if (elfcorehdr_addr + elfcorehdr_size >= mips_lowmem_limit) {
 ^~~
   arch/mips/kernel/setup.c:443:6: note: each undeclared identifier is reported 
only once for each function it appears in
>> arch/mips/kernel/setup.c:443:24: error: 'elfcorehdr_size' undeclared (first 
>> use in this function)
 if (elfcorehdr_addr + elfcorehdr_size >= mips_lowmem_limit) {
   ^~~
   cc1: some warnings being treated as errors

vim +/is_vmcore_usable +439 arch/mips/kernel/setup.c

   433  {
   434  #ifdef CONFIG_PROC_VMCORE
   435  /*
   436   * Don't reserve anything if kernel isn't booting after a panic 
and
   437   * vmcore is usable (see linux/crash_dump.h for details)
   438   */
 > 439  if (!is_vmcore_usable())
   440  return;
   441  
   442  /* Check whether the passed address belongs to low memory */
 > 443  if (elfcorehdr_addr + elfcorehdr_size >= mips_lowmem_limit) {
   444  pr_err("Elfcorehdr %08zx @ %pa doesn't belong to low 
memory",
   445  (size_t)elfcorehdr_size, _addr);
   446  return;

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


Re: [PATCH 07/21] MIPS memblock: Alter elfcorehdr parameters parser

2016-12-18 Thread kbuild test robot
Hi Serge,

[auto build test ERROR on linus/master]
[also build test ERROR on v4.9 next-20161216]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Serge-Semin/MIPS-memblock-Remove-bootmem-code-and-switch-to-NO_BOOTMEM/20161219-105045
config: mips-allyesconfig (attached as .config)
compiler: mips-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget 
https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross
 -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=mips 

All errors (new ones prefixed by >>):

   arch/mips/kernel/setup.c: In function 'mips_reserve_elfcorehdr':
>> arch/mips/kernel/setup.c:439:7: error: implicit declaration of function 
>> 'is_vmcore_usable' [-Werror=implicit-function-declaration]
 if (!is_vmcore_usable())
  ^~~~
>> arch/mips/kernel/setup.c:443:6: error: 'elfcorehdr_addr' undeclared (first 
>> use in this function)
 if (elfcorehdr_addr + elfcorehdr_size >= mips_lowmem_limit) {
 ^~~
   arch/mips/kernel/setup.c:443:6: note: each undeclared identifier is reported 
only once for each function it appears in
>> arch/mips/kernel/setup.c:443:24: error: 'elfcorehdr_size' undeclared (first 
>> use in this function)
 if (elfcorehdr_addr + elfcorehdr_size >= mips_lowmem_limit) {
   ^~~
   cc1: some warnings being treated as errors

vim +/is_vmcore_usable +439 arch/mips/kernel/setup.c

   433  {
   434  #ifdef CONFIG_PROC_VMCORE
   435  /*
   436   * Don't reserve anything if kernel isn't booting after a panic 
and
   437   * vmcore is usable (see linux/crash_dump.h for details)
   438   */
 > 439  if (!is_vmcore_usable())
   440  return;
   441  
   442  /* Check whether the passed address belongs to low memory */
 > 443  if (elfcorehdr_addr + elfcorehdr_size >= mips_lowmem_limit) {
   444  pr_err("Elfcorehdr %08zx @ %pa doesn't belong to low 
memory",
   445  (size_t)elfcorehdr_size, _addr);
   446  return;

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


[PATCH 07/21] MIPS memblock: Alter elfcorehdr parameters parser

2016-12-18 Thread Serge Semin
Memblock API can be successfully used to verify whether elfcorehdr
memory region belongs to lowmemory, then it can be reserved within
memblock allocator. There is also available default method for
early parameters parser in kernel/crash_dump.c: setup_elfcorehdr(),
so it's wise to use one instead of creating our own doing actually
the same thing.

Signed-off-by: Serge Semin 
---
 arch/mips/kernel/setup.c | 91 +-
 1 file changed, 52 insertions(+), 39 deletions(-)

diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index cc6d06b..52205fb 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -426,6 +426,55 @@ static void __init mips_reserve_initrd_mem(void) { }
 
 #endif
 
+/*
+ * Reserve memory occupied by elfcorehdr
+ */
+static void __init mips_reserve_elfcorehdr(void)
+{
+#ifdef CONFIG_PROC_VMCORE
+   /*
+* Don't reserve anything if kernel isn't booting after a panic and
+* vmcore is usable (see linux/crash_dump.h for details)
+*/
+   if (!is_vmcore_usable())
+   return;
+
+   /* Check whether the passed address belongs to low memory */
+   if (elfcorehdr_addr + elfcorehdr_size >= mips_lowmem_limit) {
+   pr_err("Elfcorehdr %08zx @ %pa doesn't belong to low memory",
+   (size_t)elfcorehdr_size, _addr);
+   return;
+   }
+
+   /*
+* If elfcorehdr_size hasn't been specified, then try to reserve upto
+* low memory limit
+*/
+   if (!elfcorehdr_size)
+   elfcorehdr_size = mips_lowmem_limit - elfcorehdr_addr;
+
+   /* Check the region belongs to actual memory (size can be zero) */
+   if (!memblock_is_region_memory(elfcorehdr_addr, elfcorehdr_size)) {
+   pr_err("Elfcorehdr %08zx @ %pa is not a memory region",
+   (size_t)elfcorehdr_size, _addr);
+   return;
+   }
+
+   /* Check whether elfcorehdr region is free */
+   if (memblock_is_region_reserved(elfcorehdr_addr, elfcorehdr_size)) {
+   pr_err("Elfcorehdr %08zx @ %pa overlaps in-use memory",
+   (size_t)elfcorehdr_size, _addr);
+   return;
+   }
+
+   /* Reserve elfcorehdr within memblock */
+   memblock_reserve(elfcorehdr_addr, PAGE_ALIGN(elfcorehdr_size));
+
+   pr_info("Reserved memory for kdump at %08zx @ %pa\n",
+   (size_t)elfcorehdr_size, _addr);
+#endif /* CONFIG_PROC_VMCORE */
+}
+
 #ifdef CONFIG_KEXEC
 /*
  * Parse passed crashkernel parameter and reserve corresponding memory
@@ -499,6 +548,9 @@ static void __init bootmem_init(void)
/* Check and reserve memory occupied by initrd */
mips_reserve_initrd_mem();
 
+   /* Reserve memory for elfcorehdr */
+   mips_reserve_elfcorehdr();
+
/* Parse crashkernel parameter */
mips_parse_crashkernel();
 
@@ -719,37 +771,6 @@ static void __init bootmem_init(void)
  * initialization hook for anything else was introduced.
  */
 
-#ifdef CONFIG_PROC_VMCORE
-unsigned long setup_elfcorehdr, setup_elfcorehdr_size;
-static int __init early_parse_elfcorehdr(char *p)
-{
-   int i;
-
-   setup_elfcorehdr = memparse(p, );
-
-   for (i = 0; i < boot_mem_map.nr_map; i++) {
-   unsigned long start = boot_mem_map.map[i].addr;
-   unsigned long end = (boot_mem_map.map[i].addr +
-boot_mem_map.map[i].size);
-   if (setup_elfcorehdr >= start && setup_elfcorehdr < end) {
-   /*
-* Reserve from the elf core header to the end of
-* the memory segment, that should all be kdump
-* reserved memory.
-*/
-   setup_elfcorehdr_size = end - setup_elfcorehdr;
-   break;
-   }
-   }
-   /*
-* If we don't find it in the memory map, then we shouldn't
-* have to worry about it, as the new kernel won't use it.
-*/
-   return 0;
-}
-early_param("elfcorehdr", early_parse_elfcorehdr);
-#endif
-
 static void __init arch_mem_addpart(phys_addr_t mem, phys_addr_t end, int type)
 {
phys_addr_t size;
@@ -833,14 +854,6 @@ static void __init arch_mem_init(char **cmdline_p)
parse_early_param();
 
bootmem_init();
-#ifdef CONFIG_PROC_VMCORE
-   if (setup_elfcorehdr && setup_elfcorehdr_size) {
-   printk(KERN_INFO "kdump reserved memory at %lx-%lx\n",
-  setup_elfcorehdr, setup_elfcorehdr_size);
-   reserve_bootmem(setup_elfcorehdr, setup_elfcorehdr_size,
-   BOOTMEM_DEFAULT);
-   }
-#endif
 
device_tree_init();
sparse_init();
-- 
2.6.6



[PATCH 07/21] MIPS memblock: Alter elfcorehdr parameters parser

2016-12-18 Thread Serge Semin
Memblock API can be successfully used to verify whether elfcorehdr
memory region belongs to lowmemory, then it can be reserved within
memblock allocator. There is also available default method for
early parameters parser in kernel/crash_dump.c: setup_elfcorehdr(),
so it's wise to use one instead of creating our own doing actually
the same thing.

Signed-off-by: Serge Semin 
---
 arch/mips/kernel/setup.c | 91 +-
 1 file changed, 52 insertions(+), 39 deletions(-)

diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index cc6d06b..52205fb 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -426,6 +426,55 @@ static void __init mips_reserve_initrd_mem(void) { }
 
 #endif
 
+/*
+ * Reserve memory occupied by elfcorehdr
+ */
+static void __init mips_reserve_elfcorehdr(void)
+{
+#ifdef CONFIG_PROC_VMCORE
+   /*
+* Don't reserve anything if kernel isn't booting after a panic and
+* vmcore is usable (see linux/crash_dump.h for details)
+*/
+   if (!is_vmcore_usable())
+   return;
+
+   /* Check whether the passed address belongs to low memory */
+   if (elfcorehdr_addr + elfcorehdr_size >= mips_lowmem_limit) {
+   pr_err("Elfcorehdr %08zx @ %pa doesn't belong to low memory",
+   (size_t)elfcorehdr_size, _addr);
+   return;
+   }
+
+   /*
+* If elfcorehdr_size hasn't been specified, then try to reserve upto
+* low memory limit
+*/
+   if (!elfcorehdr_size)
+   elfcorehdr_size = mips_lowmem_limit - elfcorehdr_addr;
+
+   /* Check the region belongs to actual memory (size can be zero) */
+   if (!memblock_is_region_memory(elfcorehdr_addr, elfcorehdr_size)) {
+   pr_err("Elfcorehdr %08zx @ %pa is not a memory region",
+   (size_t)elfcorehdr_size, _addr);
+   return;
+   }
+
+   /* Check whether elfcorehdr region is free */
+   if (memblock_is_region_reserved(elfcorehdr_addr, elfcorehdr_size)) {
+   pr_err("Elfcorehdr %08zx @ %pa overlaps in-use memory",
+   (size_t)elfcorehdr_size, _addr);
+   return;
+   }
+
+   /* Reserve elfcorehdr within memblock */
+   memblock_reserve(elfcorehdr_addr, PAGE_ALIGN(elfcorehdr_size));
+
+   pr_info("Reserved memory for kdump at %08zx @ %pa\n",
+   (size_t)elfcorehdr_size, _addr);
+#endif /* CONFIG_PROC_VMCORE */
+}
+
 #ifdef CONFIG_KEXEC
 /*
  * Parse passed crashkernel parameter and reserve corresponding memory
@@ -499,6 +548,9 @@ static void __init bootmem_init(void)
/* Check and reserve memory occupied by initrd */
mips_reserve_initrd_mem();
 
+   /* Reserve memory for elfcorehdr */
+   mips_reserve_elfcorehdr();
+
/* Parse crashkernel parameter */
mips_parse_crashkernel();
 
@@ -719,37 +771,6 @@ static void __init bootmem_init(void)
  * initialization hook for anything else was introduced.
  */
 
-#ifdef CONFIG_PROC_VMCORE
-unsigned long setup_elfcorehdr, setup_elfcorehdr_size;
-static int __init early_parse_elfcorehdr(char *p)
-{
-   int i;
-
-   setup_elfcorehdr = memparse(p, );
-
-   for (i = 0; i < boot_mem_map.nr_map; i++) {
-   unsigned long start = boot_mem_map.map[i].addr;
-   unsigned long end = (boot_mem_map.map[i].addr +
-boot_mem_map.map[i].size);
-   if (setup_elfcorehdr >= start && setup_elfcorehdr < end) {
-   /*
-* Reserve from the elf core header to the end of
-* the memory segment, that should all be kdump
-* reserved memory.
-*/
-   setup_elfcorehdr_size = end - setup_elfcorehdr;
-   break;
-   }
-   }
-   /*
-* If we don't find it in the memory map, then we shouldn't
-* have to worry about it, as the new kernel won't use it.
-*/
-   return 0;
-}
-early_param("elfcorehdr", early_parse_elfcorehdr);
-#endif
-
 static void __init arch_mem_addpart(phys_addr_t mem, phys_addr_t end, int type)
 {
phys_addr_t size;
@@ -833,14 +854,6 @@ static void __init arch_mem_init(char **cmdline_p)
parse_early_param();
 
bootmem_init();
-#ifdef CONFIG_PROC_VMCORE
-   if (setup_elfcorehdr && setup_elfcorehdr_size) {
-   printk(KERN_INFO "kdump reserved memory at %lx-%lx\n",
-  setup_elfcorehdr, setup_elfcorehdr_size);
-   reserve_bootmem(setup_elfcorehdr, setup_elfcorehdr_size,
-   BOOTMEM_DEFAULT);
-   }
-#endif
 
device_tree_init();
sparse_init();
-- 
2.6.6