Skip to content

Commit 7c61a3d

Browse files
dwmw2bp3tk0v
authored andcommitted
x86/kexec: Use typedef for relocate_kernel_fn function prototype
Both i386 and x86_64 now copy the relocate_kernel() function into the control page and execute it from there, using an open-coded function pointer. Use a typedef for it instead. [ bp: Put relocate_kernel_ptr ptr arithmetic on a single line. ] Signed-off-by: David Woodhouse <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent e536057 commit 7c61a3d

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed

arch/x86/include/asm/kexec.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,21 @@ static inline void crash_setup_regs(struct pt_regs *newregs,
111111
}
112112

113113
#ifdef CONFIG_X86_32
114-
asmlinkage unsigned long
115-
relocate_kernel(unsigned long indirection_page,
116-
unsigned long control_page,
117-
unsigned long start_address,
118-
unsigned int has_pae,
119-
unsigned int preserve_context);
114+
typedef asmlinkage unsigned long
115+
relocate_kernel_fn(unsigned long indirection_page,
116+
unsigned long control_page,
117+
unsigned long start_address,
118+
unsigned int has_pae,
119+
unsigned int preserve_context);
120120
#else
121-
unsigned long
122-
relocate_kernel(unsigned long indirection_page,
123-
unsigned long pa_control_page,
124-
unsigned long start_address,
125-
unsigned int preserve_context,
126-
unsigned int host_mem_enc_active);
121+
typedef unsigned long
122+
relocate_kernel_fn(unsigned long indirection_page,
123+
unsigned long pa_control_page,
124+
unsigned long start_address,
125+
unsigned int preserve_context,
126+
unsigned int host_mem_enc_active);
127127
#endif
128-
128+
extern relocate_kernel_fn relocate_kernel;
129129
#define ARCH_HAS_KIMAGE_ARCH
130130

131131
#ifdef CONFIG_X86_32

arch/x86/kernel/machine_kexec_32.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,10 @@ void machine_kexec_cleanup(struct kimage *image)
160160
*/
161161
void machine_kexec(struct kimage *image)
162162
{
163+
relocate_kernel_fn *relocate_kernel_ptr;
163164
unsigned long page_list[PAGES_NR];
164165
void *control_page;
165166
int save_ftrace_enabled;
166-
asmlinkage unsigned long
167-
(*relocate_kernel_ptr)(unsigned long indirection_page,
168-
unsigned long control_page,
169-
unsigned long start_address,
170-
unsigned int has_pae,
171-
unsigned int preserve_context);
172167

173168
#ifdef CONFIG_KEXEC_JUMP
174169
if (image->preserve_context)

arch/x86/kernel/machine_kexec_64.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,8 @@ void machine_kexec_cleanup(struct kimage *image)
344344
*/
345345
void __nocfi machine_kexec(struct kimage *image)
346346
{
347-
unsigned long (*relocate_kernel_ptr)(unsigned long indirection_page,
348-
unsigned long pa_control_page,
349-
unsigned long start_address,
350-
unsigned int preserve_context,
351-
unsigned int host_mem_enc_active);
352347
unsigned long reloc_start = (unsigned long)__relocate_kernel_start;
348+
relocate_kernel_fn *relocate_kernel_ptr;
353349
unsigned int host_mem_enc_active;
354350
int save_ftrace_enabled;
355351
void *control_page;
@@ -391,8 +387,7 @@ void __nocfi machine_kexec(struct kimage *image)
391387
* Allow for the possibility that relocate_kernel might not be at
392388
* the very start of the page.
393389
*/
394-
relocate_kernel_ptr = control_page + (unsigned long)relocate_kernel -
395-
reloc_start;
390+
relocate_kernel_ptr = control_page + (unsigned long)relocate_kernel - reloc_start;
396391

397392
/*
398393
* The segment registers are funny things, they have both a

0 commit comments

Comments
 (0)