Skip to content

Commit f1e5250

Browse files
jgross1suryasaimadhu
authored andcommitted
x86/boot: Skip realmode init code when running as Xen PV guest
When running as a Xen PV guest there is no need for setting up the realmode trampoline, as realmode isn't supported in this environment. Trying to setup the trampoline has been proven to be problematic in some cases, especially when trying to debug early boot problems with Xen requiring to keep the EFI boot-services memory mapped (some firmware variants seem to claim basically all memory below 1Mb for boot services). Introduce new x86_platform_ops operations for that purpose, which can be set to a NOP by the Xen PV specific kernel boot code. [ bp: s/call_init_real_mode/do_init_real_mode/ ] Fixes: 084ee1c ("x86, realmode: Relocator for realmode code") Suggested-by: H. Peter Anvin <[email protected]> Signed-off-by: Juergen Gross <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent cc3fdda commit f1e5250

File tree

6 files changed

+17
-3
lines changed

6 files changed

+17
-3
lines changed

arch/x86/include/asm/realmode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ static inline void set_real_mode_mem(phys_addr_t mem)
9191

9292
void reserve_real_mode(void);
9393
void load_trampoline_pgtable(void);
94+
void init_real_mode(void);
9495

9596
#endif /* __ASSEMBLY__ */
9697

arch/x86/include/asm/x86_init.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ struct x86_hyper_runtime {
285285
* possible in x86_early_init_platform_quirks() by
286286
* only using the current x86_hardware_subarch
287287
* semantics.
288+
* @realmode_reserve: reserve memory for realmode trampoline
289+
* @realmode_init: initialize realmode trampoline
288290
* @hyper: x86 hypervisor specific runtime callbacks
289291
*/
290292
struct x86_platform_ops {
@@ -301,6 +303,8 @@ struct x86_platform_ops {
301303
void (*apic_post_init)(void);
302304
struct x86_legacy_features legacy;
303305
void (*set_legacy_features)(void);
306+
void (*realmode_reserve)(void);
307+
void (*realmode_init)(void);
304308
struct x86_hyper_runtime hyper;
305309
struct x86_guest guest;
306310
};

arch/x86/kernel/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ void __init setup_arch(char **cmdline_p)
11751175
* Moreover, on machines with SandyBridge graphics or in setups that use
11761176
* crashkernel the entire 1M is reserved anyway.
11771177
*/
1178-
reserve_real_mode();
1178+
x86_platform.realmode_reserve();
11791179

11801180
init_mem_mapping();
11811181

arch/x86/kernel/x86_init.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <asm/iommu.h>
2626
#include <asm/mach_traps.h>
2727
#include <asm/irqdomain.h>
28+
#include <asm/realmode.h>
2829

2930
void x86_init_noop(void) { }
3031
void __init x86_init_uint_noop(unsigned int unused) { }
@@ -145,6 +146,8 @@ struct x86_platform_ops x86_platform __ro_after_init = {
145146
.get_nmi_reason = default_get_nmi_reason,
146147
.save_sched_clock_state = tsc_save_sched_clock_state,
147148
.restore_sched_clock_state = tsc_restore_sched_clock_state,
149+
.realmode_reserve = reserve_real_mode,
150+
.realmode_init = init_real_mode,
148151
.hyper.pin_vcpu = x86_op_int_noop,
149152

150153
.guest = {

arch/x86/realmode/init.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,18 @@ static void __init set_real_mode_permissions(void)
200200
set_memory_x((unsigned long) text_start, text_size >> PAGE_SHIFT);
201201
}
202202

203-
static int __init init_real_mode(void)
203+
void __init init_real_mode(void)
204204
{
205205
if (!real_mode_header)
206206
panic("Real mode trampoline was not allocated");
207207

208208
setup_real_mode();
209209
set_real_mode_permissions();
210+
}
210211

212+
static int __init do_init_real_mode(void)
213+
{
214+
x86_platform.realmode_init();
211215
return 0;
212216
}
213-
early_initcall(init_real_mode);
217+
early_initcall(do_init_real_mode);

arch/x86/xen/enlighten_pv.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,8 @@ asmlinkage __visible void __init xen_start_kernel(struct start_info *si)
12661266
xen_vcpu_info_reset(0);
12671267

12681268
x86_platform.get_nmi_reason = xen_get_nmi_reason;
1269+
x86_platform.realmode_reserve = x86_init_noop;
1270+
x86_platform.realmode_init = x86_init_noop;
12691271

12701272
x86_init.resources.memory_setup = xen_memory_setup;
12711273
x86_init.irqs.intr_mode_select = x86_init_noop;

0 commit comments

Comments
 (0)