diff mbox series

[5/8] crash_core: add generic function to do reservation

Message ID 20230827101128.70931-6-bhe@redhat.com (mailing list archive)
State New, archived
Headers show
Series kdump: use generic functions to simplify crashkernel reservation in architectures | expand

Commit Message

Baoquan He Aug. 27, 2023, 10:11 a.m. UTC
In architecture like x86_64, arm64 and riscv, they have vast virtual
address space and usually have huge physical memory RAM. Their
crashkernel reservation doesn't have to be limited under 4G RAM,
but can be extended to the whole physical memory via crashkernel=,high
support.

Now add function reserve_crashkernel_generic() to reserve crashkernel
memory if users specify any case of kernel pamameters, like
crashkernel=xM[@offset] or crashkernel=,high|low.

This is preparation to simplify code of crashkernel=,high support
in architecutures.

Signed-off-by: Baoquan He <bhe@redhat.com>
---
 include/linux/crash_core.h |  34 ++++++++++--
 kernel/crash_core.c        | 109 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 136 insertions(+), 7 deletions(-)

Comments

kernel test robot Aug. 27, 2023, 1:53 p.m. UTC | #1
Hi Baoquan,

kernel test robot noticed the following build errors:

[auto build test ERROR on tip/x86/core]
[also build test ERROR on powerpc/next powerpc/fixes linus/master v6.5-rc7]
[cannot apply to arm64/for-next/core next-20230825]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Baoquan-He/crash_core-c-remove-unnecessary-parameter-of-function/20230827-181555
base:   tip/x86/core
patch link:    https://lore.kernel.org/r/20230827101128.70931-6-bhe%40redhat.com
patch subject: [PATCH 5/8] crash_core: add generic function to do reservation
config: csky-defconfig (https://download.01.org/0day-ci/archive/20230827/202308272150.p3kRkMoF-lkp@intel.com/config)
compiler: csky-linux-gcc (GCC) 13.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230827/202308272150.p3kRkMoF-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202308272150.p3kRkMoF-lkp@intel.com/

All errors (new ones prefixed by >>):

     537 | void __weak arch_crash_save_vmcoreinfo(void)
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/crash_core.c:540:20: warning: no previous prototype for 'paddr_vmcoreinfo_note' [-Wmissing-prototypes]
     540 | phys_addr_t __weak paddr_vmcoreinfo_note(void)
         |                    ^~~~~~~~~~~~~~~~~~~~~
   kernel/crash_core.c: In function 'crash_save_vmcoreinfo_init':
   kernel/crash_core.c:554:45: error: 'VMCOREINFO_NOTE_SIZE' undeclared (first use in this function)
     554 |         vmcoreinfo_note = alloc_pages_exact(VMCOREINFO_NOTE_SIZE,
         |                                             ^~~~~~~~~~~~~~~~~~~~
   kernel/crash_core.c:563:9: error: implicit declaration of function 'VMCOREINFO_OSRELEASE' [-Werror=implicit-function-declaration]
     563 |         VMCOREINFO_OSRELEASE(init_uts_ns.name.release);
         |         ^~~~~~~~~~~~~~~~~~~~
   kernel/crash_core.c:564:9: error: implicit declaration of function 'VMCOREINFO_BUILD_ID' [-Werror=implicit-function-declaration]
     564 |         VMCOREINFO_BUILD_ID();
         |         ^~~~~~~~~~~~~~~~~~~
   kernel/crash_core.c:565:9: error: implicit declaration of function 'VMCOREINFO_PAGESIZE' [-Werror=implicit-function-declaration]
     565 |         VMCOREINFO_PAGESIZE(PAGE_SIZE);
         |         ^~~~~~~~~~~~~~~~~~~
   kernel/crash_core.c:567:9: error: implicit declaration of function 'VMCOREINFO_SYMBOL' [-Werror=implicit-function-declaration]
     567 |         VMCOREINFO_SYMBOL(init_uts_ns);
         |         ^~~~~~~~~~~~~~~~~
   kernel/crash_core.c:568:9: error: implicit declaration of function 'VMCOREINFO_OFFSET' [-Werror=implicit-function-declaration]
     568 |         VMCOREINFO_OFFSET(uts_namespace, name);
         |         ^~~~~~~~~~~~~~~~~
   kernel/crash_core.c:568:27: error: 'uts_namespace' undeclared (first use in this function)
     568 |         VMCOREINFO_OFFSET(uts_namespace, name);
         |                           ^~~~~~~~~~~~~
   kernel/crash_core.c:568:42: error: 'name' undeclared (first use in this function)
     568 |         VMCOREINFO_OFFSET(uts_namespace, name);
         |                                          ^~~~
   kernel/crash_core.c:571:9: error: implicit declaration of function 'VMCOREINFO_SYMBOL_ARRAY' [-Werror=implicit-function-declaration]
     571 |         VMCOREINFO_SYMBOL_ARRAY(swapper_pg_dir);
         |         ^~~~~~~~~~~~~~~~~~~~~~~
   kernel/crash_core.c:588:9: error: implicit declaration of function 'VMCOREINFO_STRUCT_SIZE' [-Werror=implicit-function-declaration]
     588 |         VMCOREINFO_STRUCT_SIZE(page);
         |         ^~~~~~~~~~~~~~~~~~~~~~
   kernel/crash_core.c:588:32: error: 'page' undeclared (first use in this function)
     588 |         VMCOREINFO_STRUCT_SIZE(page);
         |                                ^~~~
   kernel/crash_core.c:589:32: error: 'pglist_data' undeclared (first use in this function)
     589 |         VMCOREINFO_STRUCT_SIZE(pglist_data);
         |                                ^~~~~~~~~~~
   kernel/crash_core.c:590:32: error: 'zone' undeclared (first use in this function)
     590 |         VMCOREINFO_STRUCT_SIZE(zone);
         |                                ^~~~
   kernel/crash_core.c:591:32: error: 'free_area' undeclared (first use in this function)
     591 |         VMCOREINFO_STRUCT_SIZE(free_area);
         |                                ^~~~~~~~~
   kernel/crash_core.c:592:32: error: 'list_head' undeclared (first use in this function)
     592 |         VMCOREINFO_STRUCT_SIZE(list_head);
         |                                ^~~~~~~~~
   kernel/crash_core.c:593:9: error: implicit declaration of function 'VMCOREINFO_SIZE' [-Werror=implicit-function-declaration]
     593 |         VMCOREINFO_SIZE(nodemask_t);
         |         ^~~~~~~~~~~~~~~
   kernel/crash_core.c:593:25: error: expected expression before 'nodemask_t'
     593 |         VMCOREINFO_SIZE(nodemask_t);
         |                         ^~~~~~~~~~
   kernel/crash_core.c:594:33: error: 'flags' undeclared (first use in this function); did you mean 'fls'?
     594 |         VMCOREINFO_OFFSET(page, flags);
         |                                 ^~~~~
         |                                 fls
   kernel/crash_core.c:595:33: error: '_refcount' undeclared (first use in this function); did you mean 'seqcount'?
     595 |         VMCOREINFO_OFFSET(page, _refcount);
         |                                 ^~~~~~~~~
         |                                 seqcount
   kernel/crash_core.c:596:33: error: 'mapping' undeclared (first use in this function)
     596 |         VMCOREINFO_OFFSET(page, mapping);
         |                                 ^~~~~~~
   kernel/crash_core.c:597:33: error: 'lru' undeclared (first use in this function)
     597 |         VMCOREINFO_OFFSET(page, lru);
         |                                 ^~~
   kernel/crash_core.c:598:33: error: '_mapcount' undeclared (first use in this function); did you mean 'nmi_count'?
     598 |         VMCOREINFO_OFFSET(page, _mapcount);
         |                                 ^~~~~~~~~
         |                                 nmi_count
   kernel/crash_core.c:599:33: error: 'private' undeclared (first use in this function); did you mean 'PG_private'?
     599 |         VMCOREINFO_OFFSET(page, private);
         |                                 ^~~~~~~
         |                                 PG_private
   kernel/crash_core.c:600:27: error: 'folio' undeclared (first use in this function)
     600 |         VMCOREINFO_OFFSET(folio, _folio_dtor);
         |                           ^~~~~
   kernel/crash_core.c:600:34: error: '_folio_dtor' undeclared (first use in this function)
     600 |         VMCOREINFO_OFFSET(folio, _folio_dtor);
         |                                  ^~~~~~~~~~~
   kernel/crash_core.c:601:34: error: '_folio_order' undeclared (first use in this function); did you mean 'folio_order'?
     601 |         VMCOREINFO_OFFSET(folio, _folio_order);
         |                                  ^~~~~~~~~~~~
         |                                  folio_order
   kernel/crash_core.c:602:33: error: 'compound_head' undeclared (first use in this function); did you mean '_compound_head'?
     602 |         VMCOREINFO_OFFSET(page, compound_head);
         |                                 ^~~~~~~~~~~~~
         |                                 _compound_head
   kernel/crash_core.c:603:40: error: 'node_zones' undeclared (first use in this function); did you mean 'node_zonelist'?
     603 |         VMCOREINFO_OFFSET(pglist_data, node_zones);
         |                                        ^~~~~~~~~~
         |                                        node_zonelist
   kernel/crash_core.c:604:40: error: 'nr_zones' undeclared (first use in this function)
     604 |         VMCOREINFO_OFFSET(pglist_data, nr_zones);
         |                                        ^~~~~~~~
>> kernel/crash_core.c:606:40: error: 'node_mem_map' undeclared (first use in this function); did you mean 'node_remap'?
     606 |         VMCOREINFO_OFFSET(pglist_data, node_mem_map);
         |                                        ^~~~~~~~~~~~
         |                                        node_remap
   kernel/crash_core.c:608:40: error: 'node_start_pfn' undeclared (first use in this function)
     608 |         VMCOREINFO_OFFSET(pglist_data, node_start_pfn);
         |                                        ^~~~~~~~~~~~~~
   kernel/crash_core.c:609:40: error: 'node_spanned_pages' undeclared (first use in this function); did you mean 'zone_managed_pages'?
     609 |         VMCOREINFO_OFFSET(pglist_data, node_spanned_pages);
         |                                        ^~~~~~~~~~~~~~~~~~
         |                                        zone_managed_pages
   kernel/crash_core.c:610:40: error: 'node_id' undeclared (first use in this function)
     610 |         VMCOREINFO_OFFSET(pglist_data, node_id);
         |                                        ^~~~~~~
   kernel/crash_core.c:612:33: error: 'vm_stat' undeclared (first use in this function); did you mean 'vfs_stat'?
     612 |         VMCOREINFO_OFFSET(zone, vm_stat);
         |                                 ^~~~~~~
         |                                 vfs_stat
   kernel/crash_core.c:613:33: error: 'spanned_pages' undeclared (first use in this function); did you mean 'shake_page'?
     613 |         VMCOREINFO_OFFSET(zone, spanned_pages);
         |                                 ^~~~~~~~~~~~~
         |                                 shake_page
   kernel/crash_core.c:614:38: error: 'free_list' undeclared (first use in this function); did you mean 'kfree_link'?
     614 |         VMCOREINFO_OFFSET(free_area, free_list);
         |                                      ^~~~~~~~~
         |                                      kfree_link
   kernel/crash_core.c:615:38: error: 'next' undeclared (first use in this function); did you mean 'net'?
     615 |         VMCOREINFO_OFFSET(list_head, next);
         |                                      ^~~~
         |                                      net
   kernel/crash_core.c:616:38: error: 'prev' undeclared (first use in this function)
     616 |         VMCOREINFO_OFFSET(list_head, prev);
         |                                      ^~~~
   kernel/crash_core.c:617:27: error: 'vmap_area' undeclared (first use in this function)
     617 |         VMCOREINFO_OFFSET(vmap_area, va_start);
         |                           ^~~~~~~~~
   kernel/crash_core.c:617:38: error: 'va_start' undeclared (first use in this function); did you mean '_start'?
     617 |         VMCOREINFO_OFFSET(vmap_area, va_start);
         |                                      ^~~~~~~~
         |                                      _start
   kernel/crash_core.c:618:38: error: 'list' undeclared (first use in this function)
     618 |         VMCOREINFO_OFFSET(vmap_area, list);
         |                                      ^~~~
   kernel/crash_core.c:619:9: error: implicit declaration of function 'VMCOREINFO_LENGTH' [-Werror=implicit-function-declaration]
     619 |         VMCOREINFO_LENGTH(zone.free_area, MAX_ORDER + 1);
         |         ^~~~~~~~~~~~~~~~~
   kernel/crash_core.c:622:9: error: implicit declaration of function 'VMCOREINFO_NUMBER' [-Werror=implicit-function-declaration]
     622 |         VMCOREINFO_NUMBER(NR_FREE_PAGES);
         |         ^~~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors


vim +606 kernel/crash_core.c

692f66f26a4c19d Hari Bathini            2017-05-08  545  
692f66f26a4c19d Hari Bathini            2017-05-08  546  static int __init crash_save_vmcoreinfo_init(void)
692f66f26a4c19d Hari Bathini            2017-05-08  547  {
203e9e41219b4e7 Xunlei Pang             2017-07-12  548  	vmcoreinfo_data = (unsigned char *)get_zeroed_page(GFP_KERNEL);
203e9e41219b4e7 Xunlei Pang             2017-07-12  549  	if (!vmcoreinfo_data) {
203e9e41219b4e7 Xunlei Pang             2017-07-12  550  		pr_warn("Memory allocation for vmcoreinfo_data failed\n");
203e9e41219b4e7 Xunlei Pang             2017-07-12  551  		return -ENOMEM;
203e9e41219b4e7 Xunlei Pang             2017-07-12  552  	}
203e9e41219b4e7 Xunlei Pang             2017-07-12  553  
203e9e41219b4e7 Xunlei Pang             2017-07-12  554  	vmcoreinfo_note = alloc_pages_exact(VMCOREINFO_NOTE_SIZE,
203e9e41219b4e7 Xunlei Pang             2017-07-12  555  						GFP_KERNEL | __GFP_ZERO);
203e9e41219b4e7 Xunlei Pang             2017-07-12  556  	if (!vmcoreinfo_note) {
203e9e41219b4e7 Xunlei Pang             2017-07-12  557  		free_page((unsigned long)vmcoreinfo_data);
203e9e41219b4e7 Xunlei Pang             2017-07-12  558  		vmcoreinfo_data = NULL;
203e9e41219b4e7 Xunlei Pang             2017-07-12  559  		pr_warn("Memory allocation for vmcoreinfo_note failed\n");
203e9e41219b4e7 Xunlei Pang             2017-07-12  560  		return -ENOMEM;
203e9e41219b4e7 Xunlei Pang             2017-07-12  561  	}
203e9e41219b4e7 Xunlei Pang             2017-07-12  562  
692f66f26a4c19d Hari Bathini            2017-05-08  563  	VMCOREINFO_OSRELEASE(init_uts_ns.name.release);
44e8a5e9120bf4f Stephen Boyd            2021-07-07  564  	VMCOREINFO_BUILD_ID();
692f66f26a4c19d Hari Bathini            2017-05-08  565  	VMCOREINFO_PAGESIZE(PAGE_SIZE);
692f66f26a4c19d Hari Bathini            2017-05-08  566  
692f66f26a4c19d Hari Bathini            2017-05-08  567  	VMCOREINFO_SYMBOL(init_uts_ns);
ca4a9241cc5e718 Alexander Egorenkov     2020-12-15  568  	VMCOREINFO_OFFSET(uts_namespace, name);
692f66f26a4c19d Hari Bathini            2017-05-08  569  	VMCOREINFO_SYMBOL(node_online_map);
692f66f26a4c19d Hari Bathini            2017-05-08  570  #ifdef CONFIG_MMU
eff4345e7fba0aa Omar Sandoval           2018-08-21  571  	VMCOREINFO_SYMBOL_ARRAY(swapper_pg_dir);
692f66f26a4c19d Hari Bathini            2017-05-08  572  #endif
692f66f26a4c19d Hari Bathini            2017-05-08  573  	VMCOREINFO_SYMBOL(_stext);
692f66f26a4c19d Hari Bathini            2017-05-08  574  	VMCOREINFO_SYMBOL(vmap_area_list);
692f66f26a4c19d Hari Bathini            2017-05-08  575  
a9ee6cf5c60ed10 Mike Rapoport           2021-06-28  576  #ifndef CONFIG_NUMA
692f66f26a4c19d Hari Bathini            2017-05-08  577  	VMCOREINFO_SYMBOL(mem_map);
692f66f26a4c19d Hari Bathini            2017-05-08  578  	VMCOREINFO_SYMBOL(contig_page_data);
692f66f26a4c19d Hari Bathini            2017-05-08  579  #endif
692f66f26a4c19d Hari Bathini            2017-05-08  580  #ifdef CONFIG_SPARSEMEM
a0b1280368d1e91 Kirill A. Shutemov      2018-01-12  581  	VMCOREINFO_SYMBOL_ARRAY(mem_section);
692f66f26a4c19d Hari Bathini            2017-05-08  582  	VMCOREINFO_LENGTH(mem_section, NR_SECTION_ROOTS);
692f66f26a4c19d Hari Bathini            2017-05-08  583  	VMCOREINFO_STRUCT_SIZE(mem_section);
692f66f26a4c19d Hari Bathini            2017-05-08  584  	VMCOREINFO_OFFSET(mem_section, section_mem_map);
4f5aecdff25f59f Pingfan Liu             2021-06-15  585  	VMCOREINFO_NUMBER(SECTION_SIZE_BITS);
1d50e5d0c505244 Bhupesh Sharma          2020-05-14  586  	VMCOREINFO_NUMBER(MAX_PHYSMEM_BITS);
692f66f26a4c19d Hari Bathini            2017-05-08  587  #endif
692f66f26a4c19d Hari Bathini            2017-05-08  588  	VMCOREINFO_STRUCT_SIZE(page);
692f66f26a4c19d Hari Bathini            2017-05-08  589  	VMCOREINFO_STRUCT_SIZE(pglist_data);
692f66f26a4c19d Hari Bathini            2017-05-08  590  	VMCOREINFO_STRUCT_SIZE(zone);
692f66f26a4c19d Hari Bathini            2017-05-08  591  	VMCOREINFO_STRUCT_SIZE(free_area);
692f66f26a4c19d Hari Bathini            2017-05-08  592  	VMCOREINFO_STRUCT_SIZE(list_head);
692f66f26a4c19d Hari Bathini            2017-05-08  593  	VMCOREINFO_SIZE(nodemask_t);
692f66f26a4c19d Hari Bathini            2017-05-08  594  	VMCOREINFO_OFFSET(page, flags);
692f66f26a4c19d Hari Bathini            2017-05-08  595  	VMCOREINFO_OFFSET(page, _refcount);
692f66f26a4c19d Hari Bathini            2017-05-08  596  	VMCOREINFO_OFFSET(page, mapping);
692f66f26a4c19d Hari Bathini            2017-05-08  597  	VMCOREINFO_OFFSET(page, lru);
692f66f26a4c19d Hari Bathini            2017-05-08  598  	VMCOREINFO_OFFSET(page, _mapcount);
692f66f26a4c19d Hari Bathini            2017-05-08  599  	VMCOREINFO_OFFSET(page, private);
1c5509be58f636a Matthew Wilcox (Oracle  2023-01-11  600) 	VMCOREINFO_OFFSET(folio, _folio_dtor);
1c5509be58f636a Matthew Wilcox (Oracle  2023-01-11  601) 	VMCOREINFO_OFFSET(folio, _folio_order);
692f66f26a4c19d Hari Bathini            2017-05-08  602  	VMCOREINFO_OFFSET(page, compound_head);
692f66f26a4c19d Hari Bathini            2017-05-08  603  	VMCOREINFO_OFFSET(pglist_data, node_zones);
692f66f26a4c19d Hari Bathini            2017-05-08  604  	VMCOREINFO_OFFSET(pglist_data, nr_zones);
43b02ba93b25b1c Mike Rapoport           2021-06-28  605  #ifdef CONFIG_FLATMEM
692f66f26a4c19d Hari Bathini            2017-05-08 @606  	VMCOREINFO_OFFSET(pglist_data, node_mem_map);
692f66f26a4c19d Hari Bathini            2017-05-08  607  #endif
692f66f26a4c19d Hari Bathini            2017-05-08  608  	VMCOREINFO_OFFSET(pglist_data, node_start_pfn);
692f66f26a4c19d Hari Bathini            2017-05-08  609  	VMCOREINFO_OFFSET(pglist_data, node_spanned_pages);
692f66f26a4c19d Hari Bathini            2017-05-08  610  	VMCOREINFO_OFFSET(pglist_data, node_id);
692f66f26a4c19d Hari Bathini            2017-05-08  611  	VMCOREINFO_OFFSET(zone, free_area);
692f66f26a4c19d Hari Bathini            2017-05-08  612  	VMCOREINFO_OFFSET(zone, vm_stat);
692f66f26a4c19d Hari Bathini            2017-05-08  613  	VMCOREINFO_OFFSET(zone, spanned_pages);
692f66f26a4c19d Hari Bathini            2017-05-08  614  	VMCOREINFO_OFFSET(free_area, free_list);
692f66f26a4c19d Hari Bathini            2017-05-08  615  	VMCOREINFO_OFFSET(list_head, next);
692f66f26a4c19d Hari Bathini            2017-05-08  616  	VMCOREINFO_OFFSET(list_head, prev);
692f66f26a4c19d Hari Bathini            2017-05-08  617  	VMCOREINFO_OFFSET(vmap_area, va_start);
692f66f26a4c19d Hari Bathini            2017-05-08  618  	VMCOREINFO_OFFSET(vmap_area, list);
23baf831a32c04f Kirill A. Shutemov      2023-03-15  619  	VMCOREINFO_LENGTH(zone.free_area, MAX_ORDER + 1);
692f66f26a4c19d Hari Bathini            2017-05-08  620  	log_buf_vmcoreinfo_setup();
692f66f26a4c19d Hari Bathini            2017-05-08  621  	VMCOREINFO_LENGTH(free_area.free_list, MIGRATE_TYPES);
692f66f26a4c19d Hari Bathini            2017-05-08  622  	VMCOREINFO_NUMBER(NR_FREE_PAGES);
692f66f26a4c19d Hari Bathini            2017-05-08  623  	VMCOREINFO_NUMBER(PG_lru);
692f66f26a4c19d Hari Bathini            2017-05-08  624  	VMCOREINFO_NUMBER(PG_private);
692f66f26a4c19d Hari Bathini            2017-05-08  625  	VMCOREINFO_NUMBER(PG_swapcache);
1cbf29da3628b66 Petr Tesarik            2018-04-13  626  	VMCOREINFO_NUMBER(PG_swapbacked);
692f66f26a4c19d Hari Bathini            2017-05-08  627  	VMCOREINFO_NUMBER(PG_slab);
692f66f26a4c19d Hari Bathini            2017-05-08  628  #ifdef CONFIG_MEMORY_FAILURE
692f66f26a4c19d Hari Bathini            2017-05-08  629  	VMCOREINFO_NUMBER(PG_hwpoison);
692f66f26a4c19d Hari Bathini            2017-05-08  630  #endif
692f66f26a4c19d Hari Bathini            2017-05-08  631  	VMCOREINFO_NUMBER(PG_head_mask);
6e292b9be7f4358 Matthew Wilcox          2018-06-07  632  #define PAGE_BUDDY_MAPCOUNT_VALUE	(~PG_buddy)
692f66f26a4c19d Hari Bathini            2017-05-08  633  	VMCOREINFO_NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE);
692f66f26a4c19d Hari Bathini            2017-05-08  634  #ifdef CONFIG_HUGETLB_PAGE
692f66f26a4c19d Hari Bathini            2017-05-08  635  	VMCOREINFO_NUMBER(HUGETLB_PAGE_DTOR);
e04b742f74c2362 David Hildenbrand       2019-03-05  636  #define PAGE_OFFLINE_MAPCOUNT_VALUE	(~PG_offline)
e04b742f74c2362 David Hildenbrand       2019-03-05  637  	VMCOREINFO_NUMBER(PAGE_OFFLINE_MAPCOUNT_VALUE);
692f66f26a4c19d Hari Bathini            2017-05-08  638  #endif
692f66f26a4c19d Hari Bathini            2017-05-08  639
Baoquan He Aug. 28, 2023, 12:57 p.m. UTC | #2
On 08/27/23 at 09:53pm, kernel test robot wrote:
> Hi Baoquan,
> 
> kernel test robot noticed the following build errors:
> 
> [auto build test ERROR on tip/x86/core]
> [also build test ERROR on powerpc/next powerpc/fixes linus/master v6.5-rc7]
> [cannot apply to arm64/for-next/core next-20230825]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/Baoquan-He/crash_core-c-remove-unnecessary-parameter-of-function/20230827-181555
> base:   tip/x86/core
> patch link:    https://lore.kernel.org/r/20230827101128.70931-6-bhe%40redhat.com
> patch subject: [PATCH 5/8] crash_core: add generic function to do reservation
> config: csky-defconfig (https://download.01.org/0day-ci/archive/20230827/202308272150.p3kRkMoF-lkp@intel.com/config)
> compiler: csky-linux-gcc (GCC) 13.2.0
> reproduce: (https://download.01.org/0day-ci/archive/20230827/202308272150.p3kRkMoF-lkp@intel.com/reproduce)
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202308272150.p3kRkMoF-lkp@intel.com/

Thanks for reporting this. The error is caused by patch 3:
[PATCH 3/8] include/linux/kexec.h: move down crash_core.h including

In this lkp's config, CONFIG_CRASH_CORE=y and CONFIG_KEXEC_CORE=n, the
moving down of crash_core.h including will triger the error. I will
think of another way to fix this.

> 
> All errors (new ones prefixed by >>):
> 
>      537 | void __weak arch_crash_save_vmcoreinfo(void)
>          |             ^~~~~~~~~~~~~~~~~~~~~~~~~~
>    kernel/crash_core.c:540:20: warning: no previous prototype for 'paddr_vmcoreinfo_note' [-Wmissing-prototypes]
>      540 | phys_addr_t __weak paddr_vmcoreinfo_note(void)
>          |                    ^~~~~~~~~~~~~~~~~~~~~
>    kernel/crash_core.c: In function 'crash_save_vmcoreinfo_init':
>    kernel/crash_core.c:554:45: error: 'VMCOREINFO_NOTE_SIZE' undeclared (first use in this function)
>      554 |         vmcoreinfo_note = alloc_pages_exact(VMCOREINFO_NOTE_SIZE,
>          |                                             ^~~~~~~~~~~~~~~~~~~~
>    kernel/crash_core.c:563:9: error: implicit declaration of function 'VMCOREINFO_OSRELEASE' [-Werror=implicit-function-declaration]
>      563 |         VMCOREINFO_OSRELEASE(init_uts_ns.name.release);
>          |         ^~~~~~~~~~~~~~~~~~~~
>    kernel/crash_core.c:564:9: error: implicit declaration of function 'VMCOREINFO_BUILD_ID' [-Werror=implicit-function-declaration]
>      564 |         VMCOREINFO_BUILD_ID();
>          |         ^~~~~~~~~~~~~~~~~~~
>    kernel/crash_core.c:565:9: error: implicit declaration of function 'VMCOREINFO_PAGESIZE' [-Werror=implicit-function-declaration]
>      565 |         VMCOREINFO_PAGESIZE(PAGE_SIZE);
>          |         ^~~~~~~~~~~~~~~~~~~
>    kernel/crash_core.c:567:9: error: implicit declaration of function 'VMCOREINFO_SYMBOL' [-Werror=implicit-function-declaration]
>      567 |         VMCOREINFO_SYMBOL(init_uts_ns);
>          |         ^~~~~~~~~~~~~~~~~
>    kernel/crash_core.c:568:9: error: implicit declaration of function 'VMCOREINFO_OFFSET' [-Werror=implicit-function-declaration]
>      568 |         VMCOREINFO_OFFSET(uts_namespace, name);
>          |         ^~~~~~~~~~~~~~~~~
>    kernel/crash_core.c:568:27: error: 'uts_namespace' undeclared (first use in this function)
>      568 |         VMCOREINFO_OFFSET(uts_namespace, name);
>          |                           ^~~~~~~~~~~~~
>    kernel/crash_core.c:568:42: error: 'name' undeclared (first use in this function)
>      568 |         VMCOREINFO_OFFSET(uts_namespace, name);
>          |                                          ^~~~
>    kernel/crash_core.c:571:9: error: implicit declaration of function 'VMCOREINFO_SYMBOL_ARRAY' [-Werror=implicit-function-declaration]
>      571 |         VMCOREINFO_SYMBOL_ARRAY(swapper_pg_dir);
>          |         ^~~~~~~~~~~~~~~~~~~~~~~
>    kernel/crash_core.c:588:9: error: implicit declaration of function 'VMCOREINFO_STRUCT_SIZE' [-Werror=implicit-function-declaration]
>      588 |         VMCOREINFO_STRUCT_SIZE(page);
>          |         ^~~~~~~~~~~~~~~~~~~~~~
>    kernel/crash_core.c:588:32: error: 'page' undeclared (first use in this function)
>      588 |         VMCOREINFO_STRUCT_SIZE(page);
>          |                                ^~~~
>    kernel/crash_core.c:589:32: error: 'pglist_data' undeclared (first use in this function)
>      589 |         VMCOREINFO_STRUCT_SIZE(pglist_data);
>          |                                ^~~~~~~~~~~
>    kernel/crash_core.c:590:32: error: 'zone' undeclared (first use in this function)
>      590 |         VMCOREINFO_STRUCT_SIZE(zone);
>          |                                ^~~~
>    kernel/crash_core.c:591:32: error: 'free_area' undeclared (first use in this function)
>      591 |         VMCOREINFO_STRUCT_SIZE(free_area);
>          |                                ^~~~~~~~~
>    kernel/crash_core.c:592:32: error: 'list_head' undeclared (first use in this function)
>      592 |         VMCOREINFO_STRUCT_SIZE(list_head);
>          |                                ^~~~~~~~~
>    kernel/crash_core.c:593:9: error: implicit declaration of function 'VMCOREINFO_SIZE' [-Werror=implicit-function-declaration]
>      593 |         VMCOREINFO_SIZE(nodemask_t);
>          |         ^~~~~~~~~~~~~~~
>    kernel/crash_core.c:593:25: error: expected expression before 'nodemask_t'
>      593 |         VMCOREINFO_SIZE(nodemask_t);
>          |                         ^~~~~~~~~~
>    kernel/crash_core.c:594:33: error: 'flags' undeclared (first use in this function); did you mean 'fls'?
>      594 |         VMCOREINFO_OFFSET(page, flags);
>          |                                 ^~~~~
>          |                                 fls
>    kernel/crash_core.c:595:33: error: '_refcount' undeclared (first use in this function); did you mean 'seqcount'?
>      595 |         VMCOREINFO_OFFSET(page, _refcount);
>          |                                 ^~~~~~~~~
>          |                                 seqcount
>    kernel/crash_core.c:596:33: error: 'mapping' undeclared (first use in this function)
>      596 |         VMCOREINFO_OFFSET(page, mapping);
>          |                                 ^~~~~~~
>    kernel/crash_core.c:597:33: error: 'lru' undeclared (first use in this function)
>      597 |         VMCOREINFO_OFFSET(page, lru);
>          |                                 ^~~
>    kernel/crash_core.c:598:33: error: '_mapcount' undeclared (first use in this function); did you mean 'nmi_count'?
>      598 |         VMCOREINFO_OFFSET(page, _mapcount);
>          |                                 ^~~~~~~~~
>          |                                 nmi_count
>    kernel/crash_core.c:599:33: error: 'private' undeclared (first use in this function); did you mean 'PG_private'?
>      599 |         VMCOREINFO_OFFSET(page, private);
>          |                                 ^~~~~~~
>          |                                 PG_private
>    kernel/crash_core.c:600:27: error: 'folio' undeclared (first use in this function)
>      600 |         VMCOREINFO_OFFSET(folio, _folio_dtor);
>          |                           ^~~~~
>    kernel/crash_core.c:600:34: error: '_folio_dtor' undeclared (first use in this function)
>      600 |         VMCOREINFO_OFFSET(folio, _folio_dtor);
>          |                                  ^~~~~~~~~~~
>    kernel/crash_core.c:601:34: error: '_folio_order' undeclared (first use in this function); did you mean 'folio_order'?
>      601 |         VMCOREINFO_OFFSET(folio, _folio_order);
>          |                                  ^~~~~~~~~~~~
>          |                                  folio_order
>    kernel/crash_core.c:602:33: error: 'compound_head' undeclared (first use in this function); did you mean '_compound_head'?
>      602 |         VMCOREINFO_OFFSET(page, compound_head);
>          |                                 ^~~~~~~~~~~~~
>          |                                 _compound_head
>    kernel/crash_core.c:603:40: error: 'node_zones' undeclared (first use in this function); did you mean 'node_zonelist'?
>      603 |         VMCOREINFO_OFFSET(pglist_data, node_zones);
>          |                                        ^~~~~~~~~~
>          |                                        node_zonelist
>    kernel/crash_core.c:604:40: error: 'nr_zones' undeclared (first use in this function)
>      604 |         VMCOREINFO_OFFSET(pglist_data, nr_zones);
>          |                                        ^~~~~~~~
> >> kernel/crash_core.c:606:40: error: 'node_mem_map' undeclared (first use in this function); did you mean 'node_remap'?
>      606 |         VMCOREINFO_OFFSET(pglist_data, node_mem_map);
>          |                                        ^~~~~~~~~~~~
>          |                                        node_remap
>    kernel/crash_core.c:608:40: error: 'node_start_pfn' undeclared (first use in this function)
>      608 |         VMCOREINFO_OFFSET(pglist_data, node_start_pfn);
>          |                                        ^~~~~~~~~~~~~~
>    kernel/crash_core.c:609:40: error: 'node_spanned_pages' undeclared (first use in this function); did you mean 'zone_managed_pages'?
>      609 |         VMCOREINFO_OFFSET(pglist_data, node_spanned_pages);
>          |                                        ^~~~~~~~~~~~~~~~~~
>          |                                        zone_managed_pages
>    kernel/crash_core.c:610:40: error: 'node_id' undeclared (first use in this function)
>      610 |         VMCOREINFO_OFFSET(pglist_data, node_id);
>          |                                        ^~~~~~~
>    kernel/crash_core.c:612:33: error: 'vm_stat' undeclared (first use in this function); did you mean 'vfs_stat'?
>      612 |         VMCOREINFO_OFFSET(zone, vm_stat);
>          |                                 ^~~~~~~
>          |                                 vfs_stat
>    kernel/crash_core.c:613:33: error: 'spanned_pages' undeclared (first use in this function); did you mean 'shake_page'?
>      613 |         VMCOREINFO_OFFSET(zone, spanned_pages);
>          |                                 ^~~~~~~~~~~~~
>          |                                 shake_page
>    kernel/crash_core.c:614:38: error: 'free_list' undeclared (first use in this function); did you mean 'kfree_link'?
>      614 |         VMCOREINFO_OFFSET(free_area, free_list);
>          |                                      ^~~~~~~~~
>          |                                      kfree_link
>    kernel/crash_core.c:615:38: error: 'next' undeclared (first use in this function); did you mean 'net'?
>      615 |         VMCOREINFO_OFFSET(list_head, next);
>          |                                      ^~~~
>          |                                      net
>    kernel/crash_core.c:616:38: error: 'prev' undeclared (first use in this function)
>      616 |         VMCOREINFO_OFFSET(list_head, prev);
>          |                                      ^~~~
>    kernel/crash_core.c:617:27: error: 'vmap_area' undeclared (first use in this function)
>      617 |         VMCOREINFO_OFFSET(vmap_area, va_start);
>          |                           ^~~~~~~~~
>    kernel/crash_core.c:617:38: error: 'va_start' undeclared (first use in this function); did you mean '_start'?
>      617 |         VMCOREINFO_OFFSET(vmap_area, va_start);
>          |                                      ^~~~~~~~
>          |                                      _start
>    kernel/crash_core.c:618:38: error: 'list' undeclared (first use in this function)
>      618 |         VMCOREINFO_OFFSET(vmap_area, list);
>          |                                      ^~~~
>    kernel/crash_core.c:619:9: error: implicit declaration of function 'VMCOREINFO_LENGTH' [-Werror=implicit-function-declaration]
>      619 |         VMCOREINFO_LENGTH(zone.free_area, MAX_ORDER + 1);
>          |         ^~~~~~~~~~~~~~~~~
>    kernel/crash_core.c:622:9: error: implicit declaration of function 'VMCOREINFO_NUMBER' [-Werror=implicit-function-declaration]
>      622 |         VMCOREINFO_NUMBER(NR_FREE_PAGES);
>          |         ^~~~~~~~~~~~~~~~~
>    cc1: some warnings being treated as errors
> 
> 
> vim +606 kernel/crash_core.c
> 
> 692f66f26a4c19d Hari Bathini            2017-05-08  545  
> 692f66f26a4c19d Hari Bathini            2017-05-08  546  static int __init crash_save_vmcoreinfo_init(void)
> 692f66f26a4c19d Hari Bathini            2017-05-08  547  {
> 203e9e41219b4e7 Xunlei Pang             2017-07-12  548  	vmcoreinfo_data = (unsigned char *)get_zeroed_page(GFP_KERNEL);
> 203e9e41219b4e7 Xunlei Pang             2017-07-12  549  	if (!vmcoreinfo_data) {
> 203e9e41219b4e7 Xunlei Pang             2017-07-12  550  		pr_warn("Memory allocation for vmcoreinfo_data failed\n");
> 203e9e41219b4e7 Xunlei Pang             2017-07-12  551  		return -ENOMEM;
> 203e9e41219b4e7 Xunlei Pang             2017-07-12  552  	}
> 203e9e41219b4e7 Xunlei Pang             2017-07-12  553  
> 203e9e41219b4e7 Xunlei Pang             2017-07-12  554  	vmcoreinfo_note = alloc_pages_exact(VMCOREINFO_NOTE_SIZE,
> 203e9e41219b4e7 Xunlei Pang             2017-07-12  555  						GFP_KERNEL | __GFP_ZERO);
> 203e9e41219b4e7 Xunlei Pang             2017-07-12  556  	if (!vmcoreinfo_note) {
> 203e9e41219b4e7 Xunlei Pang             2017-07-12  557  		free_page((unsigned long)vmcoreinfo_data);
> 203e9e41219b4e7 Xunlei Pang             2017-07-12  558  		vmcoreinfo_data = NULL;
> 203e9e41219b4e7 Xunlei Pang             2017-07-12  559  		pr_warn("Memory allocation for vmcoreinfo_note failed\n");
> 203e9e41219b4e7 Xunlei Pang             2017-07-12  560  		return -ENOMEM;
> 203e9e41219b4e7 Xunlei Pang             2017-07-12  561  	}
> 203e9e41219b4e7 Xunlei Pang             2017-07-12  562  
> 692f66f26a4c19d Hari Bathini            2017-05-08  563  	VMCOREINFO_OSRELEASE(init_uts_ns.name.release);
> 44e8a5e9120bf4f Stephen Boyd            2021-07-07  564  	VMCOREINFO_BUILD_ID();
> 692f66f26a4c19d Hari Bathini            2017-05-08  565  	VMCOREINFO_PAGESIZE(PAGE_SIZE);
> 692f66f26a4c19d Hari Bathini            2017-05-08  566  
> 692f66f26a4c19d Hari Bathini            2017-05-08  567  	VMCOREINFO_SYMBOL(init_uts_ns);
> ca4a9241cc5e718 Alexander Egorenkov     2020-12-15  568  	VMCOREINFO_OFFSET(uts_namespace, name);
> 692f66f26a4c19d Hari Bathini            2017-05-08  569  	VMCOREINFO_SYMBOL(node_online_map);
> 692f66f26a4c19d Hari Bathini            2017-05-08  570  #ifdef CONFIG_MMU
> eff4345e7fba0aa Omar Sandoval           2018-08-21  571  	VMCOREINFO_SYMBOL_ARRAY(swapper_pg_dir);
> 692f66f26a4c19d Hari Bathini            2017-05-08  572  #endif
> 692f66f26a4c19d Hari Bathini            2017-05-08  573  	VMCOREINFO_SYMBOL(_stext);
> 692f66f26a4c19d Hari Bathini            2017-05-08  574  	VMCOREINFO_SYMBOL(vmap_area_list);
> 692f66f26a4c19d Hari Bathini            2017-05-08  575  
> a9ee6cf5c60ed10 Mike Rapoport           2021-06-28  576  #ifndef CONFIG_NUMA
> 692f66f26a4c19d Hari Bathini            2017-05-08  577  	VMCOREINFO_SYMBOL(mem_map);
> 692f66f26a4c19d Hari Bathini            2017-05-08  578  	VMCOREINFO_SYMBOL(contig_page_data);
> 692f66f26a4c19d Hari Bathini            2017-05-08  579  #endif
> 692f66f26a4c19d Hari Bathini            2017-05-08  580  #ifdef CONFIG_SPARSEMEM
> a0b1280368d1e91 Kirill A. Shutemov      2018-01-12  581  	VMCOREINFO_SYMBOL_ARRAY(mem_section);
> 692f66f26a4c19d Hari Bathini            2017-05-08  582  	VMCOREINFO_LENGTH(mem_section, NR_SECTION_ROOTS);
> 692f66f26a4c19d Hari Bathini            2017-05-08  583  	VMCOREINFO_STRUCT_SIZE(mem_section);
> 692f66f26a4c19d Hari Bathini            2017-05-08  584  	VMCOREINFO_OFFSET(mem_section, section_mem_map);
> 4f5aecdff25f59f Pingfan Liu             2021-06-15  585  	VMCOREINFO_NUMBER(SECTION_SIZE_BITS);
> 1d50e5d0c505244 Bhupesh Sharma          2020-05-14  586  	VMCOREINFO_NUMBER(MAX_PHYSMEM_BITS);
> 692f66f26a4c19d Hari Bathini            2017-05-08  587  #endif
> 692f66f26a4c19d Hari Bathini            2017-05-08  588  	VMCOREINFO_STRUCT_SIZE(page);
> 692f66f26a4c19d Hari Bathini            2017-05-08  589  	VMCOREINFO_STRUCT_SIZE(pglist_data);
> 692f66f26a4c19d Hari Bathini            2017-05-08  590  	VMCOREINFO_STRUCT_SIZE(zone);
> 692f66f26a4c19d Hari Bathini            2017-05-08  591  	VMCOREINFO_STRUCT_SIZE(free_area);
> 692f66f26a4c19d Hari Bathini            2017-05-08  592  	VMCOREINFO_STRUCT_SIZE(list_head);
> 692f66f26a4c19d Hari Bathini            2017-05-08  593  	VMCOREINFO_SIZE(nodemask_t);
> 692f66f26a4c19d Hari Bathini            2017-05-08  594  	VMCOREINFO_OFFSET(page, flags);
> 692f66f26a4c19d Hari Bathini            2017-05-08  595  	VMCOREINFO_OFFSET(page, _refcount);
> 692f66f26a4c19d Hari Bathini            2017-05-08  596  	VMCOREINFO_OFFSET(page, mapping);
> 692f66f26a4c19d Hari Bathini            2017-05-08  597  	VMCOREINFO_OFFSET(page, lru);
> 692f66f26a4c19d Hari Bathini            2017-05-08  598  	VMCOREINFO_OFFSET(page, _mapcount);
> 692f66f26a4c19d Hari Bathini            2017-05-08  599  	VMCOREINFO_OFFSET(page, private);
> 1c5509be58f636a Matthew Wilcox (Oracle  2023-01-11  600) 	VMCOREINFO_OFFSET(folio, _folio_dtor);
> 1c5509be58f636a Matthew Wilcox (Oracle  2023-01-11  601) 	VMCOREINFO_OFFSET(folio, _folio_order);
> 692f66f26a4c19d Hari Bathini            2017-05-08  602  	VMCOREINFO_OFFSET(page, compound_head);
> 692f66f26a4c19d Hari Bathini            2017-05-08  603  	VMCOREINFO_OFFSET(pglist_data, node_zones);
> 692f66f26a4c19d Hari Bathini            2017-05-08  604  	VMCOREINFO_OFFSET(pglist_data, nr_zones);
> 43b02ba93b25b1c Mike Rapoport           2021-06-28  605  #ifdef CONFIG_FLATMEM
> 692f66f26a4c19d Hari Bathini            2017-05-08 @606  	VMCOREINFO_OFFSET(pglist_data, node_mem_map);
> 692f66f26a4c19d Hari Bathini            2017-05-08  607  #endif
> 692f66f26a4c19d Hari Bathini            2017-05-08  608  	VMCOREINFO_OFFSET(pglist_data, node_start_pfn);
> 692f66f26a4c19d Hari Bathini            2017-05-08  609  	VMCOREINFO_OFFSET(pglist_data, node_spanned_pages);
> 692f66f26a4c19d Hari Bathini            2017-05-08  610  	VMCOREINFO_OFFSET(pglist_data, node_id);
> 692f66f26a4c19d Hari Bathini            2017-05-08  611  	VMCOREINFO_OFFSET(zone, free_area);
> 692f66f26a4c19d Hari Bathini            2017-05-08  612  	VMCOREINFO_OFFSET(zone, vm_stat);
> 692f66f26a4c19d Hari Bathini            2017-05-08  613  	VMCOREINFO_OFFSET(zone, spanned_pages);
> 692f66f26a4c19d Hari Bathini            2017-05-08  614  	VMCOREINFO_OFFSET(free_area, free_list);
> 692f66f26a4c19d Hari Bathini            2017-05-08  615  	VMCOREINFO_OFFSET(list_head, next);
> 692f66f26a4c19d Hari Bathini            2017-05-08  616  	VMCOREINFO_OFFSET(list_head, prev);
> 692f66f26a4c19d Hari Bathini            2017-05-08  617  	VMCOREINFO_OFFSET(vmap_area, va_start);
> 692f66f26a4c19d Hari Bathini            2017-05-08  618  	VMCOREINFO_OFFSET(vmap_area, list);
> 23baf831a32c04f Kirill A. Shutemov      2023-03-15  619  	VMCOREINFO_LENGTH(zone.free_area, MAX_ORDER + 1);
> 692f66f26a4c19d Hari Bathini            2017-05-08  620  	log_buf_vmcoreinfo_setup();
> 692f66f26a4c19d Hari Bathini            2017-05-08  621  	VMCOREINFO_LENGTH(free_area.free_list, MIGRATE_TYPES);
> 692f66f26a4c19d Hari Bathini            2017-05-08  622  	VMCOREINFO_NUMBER(NR_FREE_PAGES);
> 692f66f26a4c19d Hari Bathini            2017-05-08  623  	VMCOREINFO_NUMBER(PG_lru);
> 692f66f26a4c19d Hari Bathini            2017-05-08  624  	VMCOREINFO_NUMBER(PG_private);
> 692f66f26a4c19d Hari Bathini            2017-05-08  625  	VMCOREINFO_NUMBER(PG_swapcache);
> 1cbf29da3628b66 Petr Tesarik            2018-04-13  626  	VMCOREINFO_NUMBER(PG_swapbacked);
> 692f66f26a4c19d Hari Bathini            2017-05-08  627  	VMCOREINFO_NUMBER(PG_slab);
> 692f66f26a4c19d Hari Bathini            2017-05-08  628  #ifdef CONFIG_MEMORY_FAILURE
> 692f66f26a4c19d Hari Bathini            2017-05-08  629  	VMCOREINFO_NUMBER(PG_hwpoison);
> 692f66f26a4c19d Hari Bathini            2017-05-08  630  #endif
> 692f66f26a4c19d Hari Bathini            2017-05-08  631  	VMCOREINFO_NUMBER(PG_head_mask);
> 6e292b9be7f4358 Matthew Wilcox          2018-06-07  632  #define PAGE_BUDDY_MAPCOUNT_VALUE	(~PG_buddy)
> 692f66f26a4c19d Hari Bathini            2017-05-08  633  	VMCOREINFO_NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE);
> 692f66f26a4c19d Hari Bathini            2017-05-08  634  #ifdef CONFIG_HUGETLB_PAGE
> 692f66f26a4c19d Hari Bathini            2017-05-08  635  	VMCOREINFO_NUMBER(HUGETLB_PAGE_DTOR);
> e04b742f74c2362 David Hildenbrand       2019-03-05  636  #define PAGE_OFFLINE_MAPCOUNT_VALUE	(~PG_offline)
> e04b742f74c2362 David Hildenbrand       2019-03-05  637  	VMCOREINFO_NUMBER(PAGE_OFFLINE_MAPCOUNT_VALUE);
> 692f66f26a4c19d Hari Bathini            2017-05-08  638  #endif
> 692f66f26a4c19d Hari Bathini            2017-05-08  639  
> 
> -- 
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki
>
diff mbox series

Patch

diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
index 85260bf4a734..2f732493e922 100644
--- a/include/linux/crash_core.h
+++ b/include/linux/crash_core.h
@@ -77,12 +77,6 @@  Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type,
 			  void *data, size_t data_len);
 void final_note(Elf_Word *buf);
 
-#ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION
-#ifndef DEFAULT_CRASH_KERNEL_LOW_SIZE
-#define DEFAULT_CRASH_KERNEL_LOW_SIZE  (128UL << 20)
-#endif
-#endif
-
 int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
 		unsigned long long *crash_size, unsigned long long *crash_base,
 		unsigned long long *low_size, bool *high);
@@ -91,4 +85,32 @@  int parse_crashkernel_high(char *cmdline, unsigned long long system_ram,
 int parse_crashkernel_low(char *cmdline, unsigned long long system_ram,
 		unsigned long long *crash_size, unsigned long long *crash_base);
 
+#ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION
+#ifndef DEFAULT_CRASH_KERNEL_LOW_SIZE
+#define DEFAULT_CRASH_KERNEL_LOW_SIZE	(128UL << 20)
+#endif
+#ifndef CRASH_ALIGN
+#define CRASH_ALIGN			SZ_2M
+#endif
+#ifndef CRASH_ADDR_LOW_MAX
+#define CRASH_ADDR_LOW_MAX		SZ_4G
+#endif
+#ifndef CRASH_ADDR_HIGH_MAX
+#define CRASH_ADDR_HIGH_MAX		memblock_end_of_DRAM()
+#endif
+
+void __init reserve_crashkernel_generic(char *cmdline,
+		unsigned long long crash_size,
+		unsigned long long crash_base,
+		unsigned long long crash_low_size,
+		bool high);
+#else
+static inline void __init reserve_crashkernel_generic(char *cmdline,
+		unsigned long long crash_size,
+		unsigned long long crash_base,
+		unsigned long long crash_low_size,
+		bool high)
+{}
+#endif
+
 #endif /* LINUX_CRASH_CORE_H */
diff --git a/kernel/crash_core.c b/kernel/crash_core.c
index 355b0ab5189c..6bc00cc390b5 100644
--- a/kernel/crash_core.c
+++ b/kernel/crash_core.c
@@ -5,11 +5,13 @@ 
  */
 
 #include <linux/buildid.h>
-#include <linux/crash_core.h>
 #include <linux/init.h>
 #include <linux/utsname.h>
 #include <linux/vmalloc.h>
 #include <linux/sizes.h>
+#include <linux/memblock.h>
+#include <linux/kexec.h>
+#include <linux/kmemleak.h>
 
 #include <asm/page.h>
 #include <asm/sections.h>
@@ -349,6 +351,111 @@  static int __init parse_crashkernel_dummy(char *arg)
 }
 early_param("crashkernel", parse_crashkernel_dummy);
 
+#ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION
+static int __init reserve_crashkernel_low(unsigned long long low_size)
+{
+#ifdef CONFIG_64BIT
+	unsigned long long low_base;
+
+	low_base = memblock_phys_alloc_range(low_size, CRASH_ALIGN, 0, CRASH_ADDR_LOW_MAX);
+	if (!low_base) {
+		pr_err("cannot allocate crashkernel low memory (size:0x%llx).\n", low_size);
+		return -ENOMEM;
+	}
+
+	pr_info("crashkernel low memory reserved: 0x%08llx - 0x%08llx (%lld MB)\n",
+		low_base, low_base + low_size, low_size >> 20);
+
+	crashk_low_res.start = low_base;
+	crashk_low_res.end   = low_base + low_size - 1;
+	insert_resource(&iomem_resource, &crashk_low_res);
+#endif
+	return 0;
+}
+
+void __init reserve_crashkernel_generic(char *cmdline,
+			     unsigned long long crash_size,
+			     unsigned long long crash_base,
+			     unsigned long long crash_low_size,
+			     bool high)
+{
+	unsigned long long search_end = CRASH_ADDR_LOW_MAX, search_base = 0;
+	bool fixed_base = false;
+
+	/* User specifies base address explicitly. */
+	if (crash_base) {
+		fixed_base = true;
+		search_base = crash_base;
+		search_end = crash_base + crash_size;
+	}
+
+	if (high) {
+		search_base = CRASH_ADDR_LOW_MAX;
+		search_end = CRASH_ADDR_HIGH_MAX;
+	}
+
+retry:
+	crash_base = memblock_phys_alloc_range(crash_size, CRASH_ALIGN,
+					       search_base, search_end);
+	if (!crash_base) {
+		/*
+		 * For crashkernel=size[KMG]@offset[KMG], print out failure
+		 * message if can't reserve the specified region.
+		 */
+		if (fixed_base) {
+			pr_warn("crashkernel reservation failed - memory is in use.\n");
+			return;
+		}
+
+		/*
+		 * For crashkernel=size[KMG], if the first attempt was for
+		 * low memory, fall back to high memory, the minimum required
+		 * low memory will be reserved later.
+		 */
+		if (!high && search_end == CRASH_ADDR_LOW_MAX) {
+			search_end = CRASH_ADDR_HIGH_MAX;
+			search_base = CRASH_ADDR_LOW_MAX;
+			crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE;
+			goto retry;
+		}
+
+		/*
+		 * For crashkernel=size[KMG],high, if the first attempt was
+		 * for high memory, fall back to low memory.
+		 */
+		if (high && search_end == CRASH_ADDR_HIGH_MAX) {
+			search_end = CRASH_ADDR_LOW_MAX;
+			search_base = 0;
+			goto retry;
+		}
+		pr_warn("cannot allocate crashkernel (size:0x%llx)\n",
+			crash_size);
+		return;
+	}
+
+	if ((crash_base > CRASH_ADDR_LOW_MAX) &&
+	     crash_low_size && reserve_crashkernel_low(crash_low_size)) {
+		memblock_phys_free(crash_base, crash_size);
+		return;
+	}
+
+	pr_info("crashkernel reserved: 0x%016llx - 0x%016llx (%lld MB)\n",
+		crash_base, crash_base + crash_size, crash_size >> 20);
+
+	/*
+	 * The crashkernel memory will be removed from the kernel linear
+	 * map. Inform kmemleak so that it won't try to access it.
+	 */
+	kmemleak_ignore_phys(crash_base);
+	if (crashk_low_res.end)
+		kmemleak_ignore_phys(crashk_low_res.start);
+
+	crashk_res.start = crash_base;
+	crashk_res.end = crash_base + crash_size - 1;
+	insert_resource(&iomem_resource, &crashk_res);
+}
+#endif
+
 Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type,
 			  void *data, size_t data_len)
 {