Skip to content

Commit 8702f78

Browse files
Xunlei PangAlex Shi
authored andcommitted
s390/kexec: consolidate crash_map/unmap_reserved_pages() and arch_kexec_protect(unprotect)_crashkres()
Commit 3f625002581b ("kexec: introduce a protection mechanism for the crashkernel reserved memory") is a similar mechanism for protecting the crash kernel reserved memory to previous crash_map/unmap_reserved_pages() implementation, the new one is more generic in name and cleaner in code (besides, some arch may not be allowed to unmap the pgtable). Therefore, this patch consolidates them, and uses the new arch_kexec_protect(unprotect)_crashkres() to replace former crash_map/unmap_reserved_pages() which by now has been only used by S390. The consolidation work needs the crash memory to be mapped initially, this is done in machine_kdump_pm_init() which is after reserve_crashkernel(). Once kdump kernel is loaded, the new arch_kexec_protect_crashkres() implemented for S390 will actually unmap the pgtable like before. Signed-off-by: Xunlei Pang <xlpang@redhat.com> Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com> Acked-by: Michael Holzheu <holzheu@linux.vnet.ibm.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Minfei Huang <mhuang@redhat.com> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: Dave Young <dyoung@redhat.com> Cc: Baoquan He <bhe@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> (cherry picked from commit 7a0058ec78602da02b34fa2ae3afc523e90d1ab2) Signed-off-by: Alex Shi <alex.shi@linaro.org>
1 parent d54d972 commit 8702f78

4 files changed

Lines changed: 20 additions & 33 deletions

File tree

arch/s390/kernel/machine_kexec.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ static int machine_kdump_pm_cb(struct notifier_block *nb, unsigned long action,
8383
switch (action) {
8484
case PM_SUSPEND_PREPARE:
8585
case PM_HIBERNATION_PREPARE:
86-
if (crashk_res.start)
87-
crash_map_reserved_pages();
86+
if (kexec_crash_image)
87+
arch_kexec_unprotect_crashkres();
8888
break;
8989
case PM_POST_SUSPEND:
9090
case PM_POST_HIBERNATION:
91-
if (crashk_res.start)
92-
crash_unmap_reserved_pages();
91+
if (kexec_crash_image)
92+
arch_kexec_protect_crashkres();
9393
break;
9494
default:
9595
return NOTIFY_DONE;
@@ -100,6 +100,8 @@ static int machine_kdump_pm_cb(struct notifier_block *nb, unsigned long action,
100100
static int __init machine_kdump_pm_init(void)
101101
{
102102
pm_notifier(machine_kdump_pm_cb, 0);
103+
/* Create initial mapping for crashkernel memory */
104+
arch_kexec_unprotect_crashkres();
103105
return 0;
104106
}
105107
arch_initcall(machine_kdump_pm_init);
@@ -134,6 +136,8 @@ static int kdump_csum_valid(struct kimage *image)
134136
#endif
135137
}
136138

139+
#ifdef CONFIG_CRASH_DUMP
140+
137141
/*
138142
* Map or unmap crashkernel memory
139143
*/
@@ -155,21 +159,25 @@ static void crash_map_pages(int enable)
155159
}
156160

157161
/*
158-
* Map crashkernel memory
162+
* Unmap crashkernel memory
159163
*/
160-
void crash_map_reserved_pages(void)
164+
void arch_kexec_protect_crashkres(void)
161165
{
162-
crash_map_pages(1);
166+
if (crashk_res.end)
167+
crash_map_pages(0);
163168
}
164169

165170
/*
166-
* Unmap crashkernel memory
171+
* Map crashkernel memory
167172
*/
168-
void crash_unmap_reserved_pages(void)
173+
void arch_kexec_unprotect_crashkres(void)
169174
{
170-
crash_map_pages(0);
175+
if (crashk_res.end)
176+
crash_map_pages(1);
171177
}
172178

179+
#endif
180+
173181
/*
174182
* Give back memory to hypervisor before new kdump is loaded
175183
*/

include/linux/kexec.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,6 @@ extern void crash_kexec(struct pt_regs *);
241241
int kexec_should_crash(struct task_struct *);
242242
void crash_save_cpu(struct pt_regs *regs, int cpu);
243243
void crash_save_vmcoreinfo(void);
244-
void crash_map_reserved_pages(void);
245-
void crash_unmap_reserved_pages(void);
246244
void arch_crash_save_vmcoreinfo(void);
247245
__printf(1, 2)
248246
void vmcoreinfo_append_str(const char *fmt, ...);

kernel/kexec.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,6 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
136136
if (ret)
137137
return ret;
138138

139-
if (flags & KEXEC_ON_CRASH)
140-
crash_map_reserved_pages();
141-
142139
if (flags & KEXEC_PRESERVE_CONTEXT)
143140
image->preserve_context = 1;
144141

@@ -161,12 +158,6 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
161158
if ((flags & KEXEC_ON_CRASH) && kexec_crash_image)
162159
arch_kexec_protect_crashkres();
163160

164-
/*
165-
* Once the reserved memory is mapped, we should unmap this memory
166-
* before returning
167-
*/
168-
if (flags & KEXEC_ON_CRASH)
169-
crash_unmap_reserved_pages();
170161
kimage_free(image);
171162
return ret;
172163
}
@@ -232,9 +223,6 @@ SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments,
232223

233224
result = do_kexec_load(entry, nr_segments, segments, flags);
234225

235-
if ((flags & KEXEC_ON_CRASH) && kexec_crash_image)
236-
arch_kexec_protect_crashkres();
237-
238226
mutex_unlock(&kexec_mutex);
239227

240228
return result;

kernel/kexec_core.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,6 @@ int crash_shrink_memory(unsigned long new_size)
926926
start = roundup(start, KEXEC_CRASH_MEM_ALIGN);
927927
end = roundup(start + new_size, KEXEC_CRASH_MEM_ALIGN);
928928

929-
crash_map_reserved_pages();
930929
crash_free_reserved_phys_range(end, crashk_res.end);
931930

932931
if ((start == end) && (crashk_res.parent != NULL))
@@ -940,7 +939,6 @@ int crash_shrink_memory(unsigned long new_size)
940939
crashk_res.end = end - 1;
941940

942941
insert_resource(&iomem_resource, ram_res);
943-
crash_unmap_reserved_pages();
944942

945943
unlock:
946944
mutex_unlock(&kexec_mutex);
@@ -1522,17 +1520,12 @@ int kernel_kexec(void)
15221520
}
15231521

15241522
/*
1525-
* Add and remove page tables for crashkernel memory
1523+
* Protection mechanism for crashkernel reserved memory after
1524+
* the kdump kernel is loaded.
15261525
*
15271526
* Provide an empty default implementation here -- architecture
15281527
* code may override this
15291528
*/
1530-
void __weak crash_map_reserved_pages(void)
1531-
{}
1532-
1533-
void __weak crash_unmap_reserved_pages(void)
1534-
{}
1535-
15361529
void __weak arch_kexec_protect_crashkres(void)
15371530
{}
15381531

0 commit comments

Comments
 (0)