Skip to content

Commit bef6e0a

Browse files
Zhenzhong Duanjgross1
authored andcommitted
x86/xen: Add "nopv" support for HVM guest
PVH guest needs PV extentions to work, so "nopv" parameter should be ignored for PVH but not for HVM guest. If PVH guest boots up via the Xen-PVH boot entry, xen_pvh is set early, we know it's PVH guest and ignore "nopv" parameter directly. If PVH guest boots up via the normal boot entry same as HVM guest, it's hard to distinguish PVH and HVM guest at that time. In this case, we have to panic early if PVH is detected and nopv is enabled to avoid a worse situation later. Remove static from bool_x86_init_noop/x86_op_int_noop so they could be used globally. Move xen_platform_hvm() after xen_hvm_guest_late_init() to avoid compile error. Signed-off-by: Zhenzhong Duan <zhenzhong.duan@oracle.com> Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: Juergen Gross <jgross@suse.com> Cc: Stefano Stabellini <sstabellini@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Signed-off-by: Juergen Gross <jgross@suse.com>
1 parent cc8f3b4 commit bef6e0a

3 files changed

Lines changed: 39 additions & 10 deletions

File tree

‎arch/x86/include/asm/x86_init.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ extern struct x86_apic_ops x86_apic_ops;
301301
extern void x86_early_init_platform_quirks(void);
302302
extern void x86_init_noop(void);
303303
extern void x86_init_uint_noop(unsigned int unused);
304+
extern bool bool_x86_init_noop(void);
305+
extern void x86_op_int_noop(int cpu);
304306
extern bool x86_pnpbios_disabled(void);
305307

306308
#endif

‎arch/x86/kernel/x86_init.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ void x86_init_noop(void) { }
2929
void __init x86_init_uint_noop(unsigned int unused) { }
3030
static int __init iommu_init_noop(void) { return 0; }
3131
static void iommu_shutdown_noop(void) { }
32-
static bool __init bool_x86_init_noop(void) { return false; }
33-
static void x86_op_int_noop(int cpu) { }
32+
bool __init bool_x86_init_noop(void) { return false; }
33+
void x86_op_int_noop(int cpu) { }
3434

3535
/*
3636
* The platform setup functions are preset with the default functions

‎arch/x86/xen/enlighten_hvm.c‎

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,6 @@ bool __init xen_hvm_need_lapic(void)
231231
return true;
232232
}
233233

234-
static uint32_t __init xen_platform_hvm(void)
235-
{
236-
if (xen_pv_domain())
237-
return 0;
238-
239-
return xen_cpuid_base();
240-
}
241-
242234
static __init void xen_hvm_guest_late_init(void)
243235
{
244236
#ifdef CONFIG_XEN_PVH
@@ -250,6 +242,9 @@ static __init void xen_hvm_guest_late_init(void)
250242
/* PVH detected. */
251243
xen_pvh = true;
252244

245+
if (nopv)
246+
panic("\"nopv\" and \"xen_nopv\" parameters are unsupported in PVH guest.");
247+
253248
/* Make sure we don't fall back to (default) ACPI_IRQ_MODEL_PIC. */
254249
if (!nr_ioapics && acpi_irq_model == ACPI_IRQ_MODEL_PIC)
255250
acpi_irq_model = ACPI_IRQ_MODEL_PLATFORM;
@@ -259,6 +254,37 @@ static __init void xen_hvm_guest_late_init(void)
259254
#endif
260255
}
261256

257+
static uint32_t __init xen_platform_hvm(void)
258+
{
259+
uint32_t xen_domain = xen_cpuid_base();
260+
struct x86_hyper_init *h = &x86_hyper_xen_hvm.init;
261+
262+
if (xen_pv_domain())
263+
return 0;
264+
265+
if (xen_pvh_domain() && nopv) {
266+
/* Guest booting via the Xen-PVH boot entry goes here */
267+
pr_info("\"nopv\" parameter is ignored in PVH guest\n");
268+
nopv = false;
269+
} else if (nopv && xen_domain) {
270+
/*
271+
* Guest booting via normal boot entry (like via grub2) goes
272+
* here.
273+
*
274+
* Use interface functions for bare hardware if nopv,
275+
* xen_hvm_guest_late_init is an exception as we need to
276+
* detect PVH and panic there.
277+
*/
278+
h->init_platform = x86_init_noop;
279+
h->x2apic_available = bool_x86_init_noop;
280+
h->init_mem_mapping = x86_init_noop;
281+
h->init_after_bootmem = x86_init_noop;
282+
h->guest_late_init = xen_hvm_guest_late_init;
283+
x86_hyper_xen_hvm.runtime.pin_vcpu = x86_op_int_noop;
284+
}
285+
return xen_domain;
286+
}
287+
262288
struct hypervisor_x86 x86_hyper_xen_hvm __initdata = {
263289
.name = "Xen HVM",
264290
.detect = xen_platform_hvm,
@@ -268,4 +294,5 @@ struct hypervisor_x86 x86_hyper_xen_hvm __initdata = {
268294
.init.init_mem_mapping = xen_hvm_init_mem_mapping,
269295
.init.guest_late_init = xen_hvm_guest_late_init,
270296
.runtime.pin_vcpu = xen_pin_vcpu,
297+
.ignore_nopv = true,
271298
};

0 commit comments

Comments
 (0)