Merge tag 'sched-urgent-2023-09-02' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-block.git] / kernel / crash_core.c
index 40388ad510348f366daf7e13a69376f8cc2d101d..03a7932cde0a518939f8325fb450c91391b08891 100644 (file)
@@ -367,8 +367,8 @@ int crash_prepare_elf64_headers(struct crash_mem *mem, int need_kernel_map,
        ehdr->e_ehsize = sizeof(Elf64_Ehdr);
        ehdr->e_phentsize = sizeof(Elf64_Phdr);
 
-       /* Prepare one phdr of type PT_NOTE for each present CPU */
-       for_each_present_cpu(cpu) {
+       /* Prepare one phdr of type PT_NOTE for each possible CPU */
+       for_each_possible_cpu(cpu) {
                phdr->p_type = PT_NOTE;
                notes_addr = per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpu));
                phdr->p_offset = phdr->p_paddr = notes_addr;
@@ -643,8 +643,6 @@ static int __init crash_save_vmcoreinfo_init(void)
        VMCOREINFO_OFFSET(page, lru);
        VMCOREINFO_OFFSET(page, _mapcount);
        VMCOREINFO_OFFSET(page, private);
-       VMCOREINFO_OFFSET(folio, _folio_dtor);
-       VMCOREINFO_OFFSET(folio, _folio_order);
        VMCOREINFO_OFFSET(page, compound_head);
        VMCOREINFO_OFFSET(pglist_data, node_zones);
        VMCOREINFO_OFFSET(pglist_data, nr_zones);
@@ -678,7 +676,7 @@ static int __init crash_save_vmcoreinfo_init(void)
 #define PAGE_BUDDY_MAPCOUNT_VALUE      (~PG_buddy)
        VMCOREINFO_NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE);
 #ifdef CONFIG_HUGETLB_PAGE
-       VMCOREINFO_NUMBER(HUGETLB_PAGE_DTOR);
+       VMCOREINFO_NUMBER(PG_hugetlb);
 #define PAGE_OFFLINE_MAPCOUNT_VALUE    (~PG_offline)
        VMCOREINFO_NUMBER(PAGE_OFFLINE_MAPCOUNT_VALUE);
 #endif
@@ -740,6 +738,33 @@ subsys_initcall(crash_notes_memory_init);
 #ifdef CONFIG_CRASH_HOTPLUG
 #undef pr_fmt
 #define pr_fmt(fmt) "crash hp: " fmt
+
+/*
+ * This routine utilized when the crash_hotplug sysfs node is read.
+ * It reflects the kernel's ability/permission to update the crash
+ * elfcorehdr directly.
+ */
+int crash_check_update_elfcorehdr(void)
+{
+       int rc = 0;
+
+       /* Obtain lock while reading crash information */
+       if (!kexec_trylock()) {
+               pr_info("kexec_trylock() failed, elfcorehdr may be inaccurate\n");
+               return 0;
+       }
+       if (kexec_crash_image) {
+               if (kexec_crash_image->file_mode)
+                       rc = 1;
+               else
+                       rc = kexec_crash_image->update_elfcorehdr;
+       }
+       /* Release lock now that update complete */
+       kexec_unlock();
+
+       return rc;
+}
+
 /*
  * To accurately reflect hot un/plug changes of cpu and memory resources
  * (including onling and offlining of those resources), the elfcorehdr
@@ -770,6 +795,10 @@ static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu)
 
        image = kexec_crash_image;
 
+       /* Check that updating elfcorehdr is permitted */
+       if (!(image->file_mode || image->update_elfcorehdr))
+               goto out;
+
        if (hp_action == KEXEC_CRASH_HP_ADD_CPU ||
                hp_action == KEXEC_CRASH_HP_REMOVE_CPU)
                pr_debug("hp_action %u, cpu %u\n", hp_action, cpu);