x86/xen: untangle PV and PVHVM guest support code
Subsystems (3)
cover x86/xen: untangle PV and PVHVM guest support code
Hi,
I have a long-standing idea to separate PV and PVHVM code in kernel and introduce Kconfig options to make it possible to enable the required parts only breaking the current 'all or nothing' approach.
Motivation:
- Xen related x86 code in kernel is rather big and it is unclear which parts of it are required for PV, for HVM or for both. With PVH coming into picture is becomes even more tangled. It makes it hard to understand/audit the code.
- In some case we may want to avoid bloating kernel by supporting Xen guests we don't need. In particular, 90% of the code in arch/x86/xen/ is required to support PV guests and one may require PVHVM support only.
- PV guests are supposed to go away one day and such code separation would help us to get ready.
This RFC adds XEN_PV Kconfig option and makes it possible to build PV-only and PVHVM-only kernels. It also makes it possible to disable Dom0 support. The series is incomplete and probably dirty in some places, I didn't pay much attention to the current PVH implementation as (as far as I understand) it is supposed to be replaced with PVHv2 but before investing more I'd like to get opinions whether such refactoring will be welcomed.
Patches are rather big but this is mostly just moving code around, no functional changes intended. I smoke tested it with PV-only and PVHVM-only builds.
Vitaly Kuznetsov (4):
x86/xen: start untangling PV and PVHVM guest support code x86/xen: split smp.c for PV and PVHVM guests x86/xen: put setup.c, mmu.c and p2m.c under CONFIG_XEN_PV x86/xen: put setup.c, pmu.c and apic.c under CONFIG_XEN_PV
arch/x86/include/asm/hypervisor.h | 3 +- arch/x86/include/asm/xen/page.h | 44 ++++- arch/x86/kernel/cpu/hypervisor.c | 7 +- arch/x86/kernel/process_64.c | 2 +- arch/x86/xen/Kconfig | 35 +++- arch/x86/xen/Makefile | 14 +- arch/x86/xen/enlighten.c | 396 +++----------------------------------- arch/x86/xen/enlighten_common.c | 216 +++++++++++++++++++++ arch/x86/xen/enlighten_hvm.c | 202 +++++++++++++++++++ arch/x86/xen/mmu.c | 286 +-------------------------- arch/x86/xen/mmu_common.c | 219 +++++++++++++++++++++ arch/x86/xen/mmu_hvm.c | 77 ++++++++ arch/x86/xen/pmu.h | 5 + arch/x86/xen/smp.c | 301 +++-------------------------- arch/x86/xen/smp.h | 23 +++ arch/x86/xen/smp_common.c | 246 +++++++++++++++++++++++ arch/x86/xen/smp_hvm.c | 54 ++++++ arch/x86/xen/suspend.c | 4 + arch/x86/xen/xen-head.S | 4 + arch/x86/xen/xen-ops.h | 2 + drivers/xen/balloon.c | 30 ++- include/xen/xen-ops.h | 20 ++ 22 files changed, 1230 insertions(+), 960 deletions(-) create mode 100644 arch/x86/xen/enlighten_common.c create mode 100644 arch/x86/xen/enlighten_hvm.c create mode 100644 arch/x86/xen/mmu_common.c create mode 100644 arch/x86/xen/mmu_hvm.c create mode 100644 arch/x86/xen/smp_common.c create mode 100644 arch/x86/xen/smp_hvm.c
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 1/4 x86/xen: start untangling PV and PVHVM guest support code
Introduce CONFIG_XEN_PV config option and split enlighten.c into 3 files. Temporary add #ifdef CONFIG_XEN_PV to smp.c and mmu.c to not break the build and not make the patch even bigger.
xen_cpu_up_prepare*/xen_cpu_die hooks require separation to support future xen_smp_intr_init() split.
--- arch/x86/include/asm/hypervisor.h | 3 +- arch/x86/kernel/cpu/hypervisor.c | 7 +- arch/x86/kernel/process_64.c | 2 +- arch/x86/xen/Kconfig | 25 ++- arch/x86/xen/Makefile | 7 +- arch/x86/xen/enlighten.c | 388 ++------------------------------------ arch/x86/xen/enlighten_common.c | 216 +++++++++++++++++++++ arch/x86/xen/enlighten_hvm.c | 202 ++++++++++++++++++++ arch/x86/xen/mmu.c | 2 + arch/x86/xen/smp.c | 40 ++-- arch/x86/xen/suspend.c | 4 + arch/x86/xen/xen-head.S | 4 + arch/x86/xen/xen-ops.h | 2 + include/xen/xen-ops.h | 7 + 14 files changed, 510 insertions(+), 399 deletions(-) create mode 100644 arch/x86/xen/enlighten_common.c create mode 100644 arch/x86/xen/enlighten_hvm.c
arch/x86/include/asm/hypervisor.h +2 -1
@@ -53,7 +53,8 @@ extern const struct hypervisor_x86 *x86_hyper;/* Recognized hypervisors */ extern const struct hypervisor_x86 x86_hyper_vmware;extern const struct hypervisor_x86 x86_hyper_ms_hyperv; -extern const struct hypervisor_x86 x86_hyper_xen; +extern const struct hypervisor_x86 x86_hyper_xen_pv; +extern const struct hypervisor_x86 x86_hyper_xen_pvhvm;extern const struct hypervisor_x86 x86_hyper_kvm;extern void init_hypervisor (struct cpuinfo_x86 *c);
arch/x86/kernel/cpu/hypervisor.c +5 -2
@@ -28,8 +28,11 @@static const __initconst struct hypervisor_x86 *const hypervisors[] = { -#ifdef CONFIG_XEN - &x86_hyper_xen, +#ifdef CONFIG_XEN_PV + &x86_hyper_xen_pv, +#endif +#ifdef CONFIG_XEN_PVHVM + &x86_hyper_xen_pvhvm, #endif &x86_hyper_vmware, &x86_hyper_ms_hyperv,
arch/x86/kernel/process_64.c +1 -1
@@ -434,7 +434,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p) task_thread_info(prev_p)->flags & _TIF_WORK_CTXSW_PREV))__switch_to_xtra (prev_p, next_p, tss); -#ifdef CONFIG_XEN +#ifdef CONFIG_XEN_PV /* * On Xen PV, IOPL bits in pt_regs->flags have no effect, and * current_pt_regs()->flags may not match the current task's
arch/x86/xen/Kconfig +19 -6
@@ -6,7 +6,6 @@ config XEN bool "Xen guest support" depends on PARAVIRT select PARAVIRT_CLOCK - select XEN_HAVE_PVMMU select XEN_HAVE_VPMU depends on X86_64 || (X86_32 && X86_PAE) depends on X86_LOCAL_APIC && X86_TSC
@@ -15,18 +14,32 @@ config XEN kernel to boot in a paravirtualized environment under the Xen hypervisor. +config XEN_PV + bool "Xen PV guest support" + default y + depends on XEN + help + Support running as a Xen PV guest. + config XEN_DOM0 - def_bool y - depends on XEN && PCI_XEN && SWIOTLB_XEN + bool "Xen PV Dom0 support" + default y + depends on XEN_PV && PCI_XEN && SWIOTLB_XEN depends on X86_IO_APIC && ACPI && PCI + select XEN_HAVE_PVMMU + help + Support running as a Xen PV Dom0 guest. config XEN_PVHVM - def_bool y + bool "Xen PVHVM guest support" + default y depends on XEN && PCI && X86_LOCAL_APIC + help + Support running as a Xen PVHVM guest. config XEN_512GB bool "Limit Xen pv-domain memory to 512GB" - depends on XEN && X86_64 + depends on XEN_PV && X86_64 default y help Limit paravirtualized user domains to 512GB of RAM.
@@ -53,5 +66,5 @@ config XEN_DEBUG_FS config XEN_PVH bool "Support for running as a PVH guest" - depends on X86_64 && XEN && XEN_PVHVM + depends on X86_64 && XEN_PV && XEN_PVHVM def_bool n
arch/x86/xen/Makefile +5 -2
@@ -10,11 +10,14 @@ nostackp := $(call cc-option, -fno-stack-protector) CFLAGS_enlighten.o := $(nostackp) CFLAGS_mmu.o := $(nostackp) -obj-y := enlighten.o setup.o multicalls.o mmu.o irq.o \ - time.o xen-asm.o xen-asm_$(BITS).o \ +obj-y := enlighten_common.o setup.o multicalls.o \ + mmu.o irq.o time.o xen-asm.o xen-asm_$(BITS).o \ grant-table.o suspend.o platform-pci-unplug.o \ p2m.o apic.o pmu.o +obj-$(CONFIG_XEN_PV) += enlighten.o +obj-$(CONFIG_XEN_PVHVM) += enlighten_hvm.o + obj-$(CONFIG_EVENT_TRACING) += trace.o obj-$(CONFIG_SMP) += smp.o
arch/x86/xen/enlighten.c +17 -371
456 lines not on this page · raw message
arch/x86/xen/enlighten_common.c new file +216 -0
216 lines not on this page · raw message
arch/x86/xen/enlighten_hvm.c new file +202 -0
202 lines not on this page · raw message
arch/x86/xen/mmu.c +2 -0
@@ -1295,7 +1295,9 @@ static void __init xen_pagetable_init(void)if (!xen_feature (XENFEAT_auto_translated_physmap))xen_remap_memory (); +#ifdef CONFIG_XEN_PV xen_setup_shared_info (); +#endif }static void xen_write_cr2 (unsigned long cr2) {
arch/x86/xen/smp.c +24 -16
@@ -253,6 +253,7 @@ int xen_smp_intr_init(unsigned int cpu)return rc; } +#ifdef CONFIG_XEN_PV static void __init xen_fill_possible_map (void ) {int i, rc;
@@ -304,6 +305,7 @@ static void __init xen_filter_cpu_maps(void) #endif } +#endif static void __init xen_smp_prepare_boot_cpu (void ) {
@@ -311,6 +313,7 @@ static void __init xen_smp_prepare_boot_cpu(void)native_smp_prepare_boot_cpu ();if (xen_pv_domain ()) { +#ifdef CONFIG_XEN_PV if (!xen_feature (XENFEAT_writable_page_tables))/* We've switched to the "real" per-cpu gdt, so make * sure the old memory can be recycled. */
@@ -327,6 +330,7 @@ static void __init xen_smp_prepare_boot_cpu(void)xen_filter_cpu_maps ();xen_setup_vcpu_info_placement (); +#endif }/*
@@ -344,6 +348,7 @@ static void __init xen_smp_prepare_boot_cpu(void)xen_init_spinlocks (); } +#ifdef CONFIG_XEN_PV static void __init xen_smp_prepare_cpus (unsigned int max_cpus) {unsigned cpu;
@@ -525,22 +530,6 @@ static int xen_cpu_disable(void)return 0 ; } -static void xen_cpu_die (unsigned int cpu) -{ -while (xen_pv_domain () &&HYPERVISOR_vcpu_op (VCPUOP_is_up, -xen_vcpu_nr (cpu),NULL )) { -__set_current_state (TASK_UNINTERRUPTIBLE ); -schedule_timeout (HZ /10 ); - } - -if (common_cpu_die (cpu) ==0 ) { -xen_smp_intr_free (cpu); -xen_uninit_lock_cpu (cpu); -xen_teardown_timer (cpu); -xen_pmu_finish (cpu); - } -} -static void xen_play_dead (void )/* used only with HOTPLUG_CPU */ {play_dead_common ();
@@ -592,6 +581,23 @@ static void xen_stop_other_cpus(int wait) {smp_call_function (stop_self,NULL , wait); } +#endif /* CONFIG_XEN_PV */ + +static void xen_cpu_die (unsigned int cpu) +{ +while (xen_pv_domain () &&HYPERVISOR_vcpu_op (VCPUOP_is_up, +xen_vcpu_nr (cpu),NULL )) { +__set_current_state (TASK_UNINTERRUPTIBLE ); +schedule_timeout (HZ /10 ); + } + +if (common_cpu_die (cpu) ==0 ) { +xen_smp_intr_free (cpu); +xen_uninit_lock_cpu (cpu); +xen_teardown_timer (cpu); +xen_pmu_finish (cpu); + } +}static void xen_smp_send_reschedule (int cpu) {
@@ -738,6 +744,7 @@ static irqreturn_t xen_irq_work_interrupt(int irq, void *dev_id)return IRQ_HANDLED ; } +#ifdef CONFIG_XEN_PV static const struct smp_ops xen_smp_ops__initconst = { .smp_prepare_boot_cpu = xen_smp_prepare_boot_cpu, .smp_prepare_cpus = xen_smp_prepare_cpus,
@@ -760,6 +767,7 @@ void __init xen_smp_init(void) smp_ops = xen_smp_ops; xen_fill_possible_map(); } +#endif static void __init xen_hvm_smp_prepare_cpus (unsigned int max_cpus) {
arch/x86/xen/suspend.c +4 -0
@@ -16,6 +16,7 @@static void xen_pv_pre_suspend (void ) { +#ifdef CONFIG_XEN_PV xen_mm_pin_all (); xen_start_info->store_mfn =mfn_to_pfn (xen_start_info->store_mfn);
@@ -28,6 +29,7 @@ static void xen_pv_pre_suspend(void)if (HYPERVISOR_update_va_mapping (fix_to_virt (FIX_PARAVIRT_BOOTMAP ),__pte_ma (0 ),0 ))BUG (); +#endif }static void xen_hvm_post_suspend (int suspend_cancelled)
@@ -48,6 +50,7 @@ static void xen_hvm_post_suspend(int suspend_cancelled)static void xen_pv_post_suspend (int suspend_cancelled) { +#ifdef CONFIG_XEN_PV xen_build_mfn_list_list ();xen_setup_shared_info ();
@@ -66,6 +69,7 @@ static void xen_pv_post_suspend(int suspend_cancelled) }xen_mm_unpin_all (); +#endif }void xen_arch_pre_suspend (void )
arch/x86/xen/xen-head.S +4 -0
@@ -35,6 +35,7 @@ #define PVH_FEATURES (0) #endif +#ifdef CONFIG_XEN_PV __INIT ENTRY(startup_xen) cld
@@ -53,6 +54,7 @@ ENTRY(startup_xen) jmp xen_start_kernel __FINIT +#endif #ifdef CONFIG_XEN_PVH /*
@@ -112,7 +114,9 @@ ENTRY(hypercall_page) /* Map the p2m table to a 512GB-aligned user address. */ ELFNOTE(Xen, XEN_ELFNOTE_INIT_P2M, .quad PGDIR_SIZE) #endif +#ifdef CONFIG_XEN_PV ELFNOTE(Xen, XEN_ELFNOTE_ENTRY, _ASM_PTR startup_xen) +#endif ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, _ASM_PTR hypercall_page) ELFNOTE(Xen, XEN_ELFNOTE_FEATURES, .ascii "!writable_page_tables|pae_pgdir_above_4gb"; .asciz PVH_FEATURES_STR) ELFNOTE(Xen, XEN_ELFNOTE_SUPPORTED_FEATURES, .long (PVH_FEATURES) |
arch/x86/xen/xen-ops.h +2 -0
@@ -76,6 +76,8 @@ irqreturn_t xen_debug_interrupt(int irq, void *dev_id);bool xen_vcpu_stolen (int vcpu); +extern int have_vcpu_info_placement; +void xen_vcpu_setup (int cpu);void xen_setup_vcpu_info_placement (void );
include/xen/xen-ops.h +7 -0
@@ -15,6 +15,8 @@ static inline uint32_t xen_vcpu_nr(int cpu)return per_cpu (xen_vcpu_id, cpu); } +extern bool xen_nopv; +void xen_arch_pre_suspend (void );void xen_arch_post_suspend (int suspend_cancelled);
@@ -33,6 +35,11 @@ u64 xen_steal_clock(int cpu);int xen_setup_shutdown_event (void ); +int xen_cpuhp_setup (int (*cpu_up_prepare_cb)(unsigned int ), +int (*cpu_dead_cb)(unsigned int )); + +void xen_reboot (int reason); +extern unsigned long *xen_contiguous_bitmap; int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order, unsigned int address_bits,
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [RFC PATCH KERNEL 1/4] x86/xen: start untangling PV and PVHVM guest support code
Quoted 8 lines · Vitaly Kuznetsov
Introduce
CONFIG_XEN_PVconfig option and splitenlighten.cinto 3 files. Temporary add #ifdefCONFIG_XEN_PVtosmp.candmmu.cto not break the build and not make the patch even bigger.xen_cpu_up_prepare*/xen_cpu_die hooks require separation to support future
xen_smp_intr_init()split.Signed-off-by Vitaly Kuznetsov <[email protected]>
Quoted 9 lines
--- arch/x86/include/asm/hypervisor.h | 3 +- arch/x86/kernel/cpu/hypervisor.c | 7 +- arch/x86/kernel/process_64.c | 2 +- arch/x86/xen/Kconfig | 25 ++- arch/x86/xen/Makefile | 7 +- arch/x86/xen/enlighten.c | 388 ++------------------------------------ arch/x86/xen/enlighten_common.c | 216 +++++++++++++++++++++ arch/x86/xen/enlighten_hvm.c | 202 ++++++++++++++++++++
I think I'd prefer:
enlighten.c, enlighten_pv.c and enlighten_hvm.c
And similarly for the other files you split.
David
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [RFC PATCH KERNEL 1/4] x86/xen: start untangling PV and PVHVM guest support code
Quoted 19 lines · David Vrabel
Quoted 8 lines · Vitaly Kuznetsov
Introduce
CONFIG_XEN_PVconfig option and splitenlighten.cinto 3 files. Temporary add #ifdefCONFIG_XEN_PVtosmp.candmmu.cto not break the build and not make the patch even bigger.xen_cpu_up_prepare*/xen_cpu_die hooks require separation to support future
xen_smp_intr_init()split.Signed-off-by Vitaly Kuznetsov <[email protected]>Quoted 9 lines
--- arch/x86/include/asm/hypervisor.h | 3 +- arch/x86/kernel/cpu/hypervisor.c | 7 +- arch/x86/kernel/process_64.c | 2 +- arch/x86/xen/Kconfig | 25 ++- arch/x86/xen/Makefile | 7 +- arch/x86/xen/enlighten.c | 388 ++------------------------------------ arch/x86/xen/enlighten_common.c | 216 +++++++++++++++++++++ arch/x86/xen/enlighten_hvm.c | 202 ++++++++++++++++++++
Quoted 5 lines
I think I'd prefer:
enlighten.c,enlighten_pv.candenlighten_hvm.cAnd similarly for the other files you split.
Sure,
in this case we'll basically be renaming enlighten.c -> enlighten_pv.c and enlighten_common.c will become new enlighten.c. I'll now wait till PVHv2 stuff lands, do some cleanups and send v1.
Thanks!
Signature · 6 lines
Vitaly _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Boris Ostrovsky
reviewerRe: [RFC PATCH KERNEL 1/4] x86/xen: start untangling PV and PVHVM guest support code
In reply to Vitaly Kuznetsovarch/x86/xen/Kconfig config XEN · line 24
Quoted 9 lines · Vitaly Kuznetsov
arch/x86/xen/Kconfig +7
-0+config XEN_PV + bool "Xen PV guest support" + default y + depends on XEN + help + Support running as a Xen PV guest. + config XEN_DOM0
We might consider renaming this to XEN_PV_DOM0 to distinguish it from eventual XEN_PVH_DOM0.
-boris
arch/x86/xen/Kconfig config XEN · line 31
Quoted 11 lines
arch/x86/xen/Kconfig +6
-2- def_bool y - depends on XEN && PCI_XEN && SWIOTLB_XEN + bool "Xen PV Dom0 support" + default y + depends on XEN_PV && PCI_XEN && SWIOTLB_XEN depends on X86_IO_APIC && ACPI && PCI + select XEN_HAVE_PVMMU + help + Support running as a Xen PV Dom0 guest.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
RFC PATCH 2/4 x86/xen: split smp.c for PV and PVHVM guests
In reply to Vitaly KuznetsovMore or less mechanically split smp.c into 3 files. XEN_PV_SMP and XEN_PVHVM_SMP config options added to support the change.
--- arch/x86/xen/Kconfig | 8 ++ arch/x86/xen/Makefile | 5 +- arch/x86/xen/enlighten.c | 8 ++ arch/x86/xen/smp.c | 295 +++------------------------------------------- arch/x86/xen/smp.h | 23 ++++ arch/x86/xen/smp_common.c | 246 ++++++++++++++++++++++++++++++++++++++ arch/x86/xen/smp_hvm.c | 54 +++++++++ 7 files changed, 359 insertions(+), 280 deletions(-) create mode 100644 arch/x86/xen/smp_common.c create mode 100644 arch/x86/xen/smp_hvm.c
arch/x86/xen/Kconfig +8 -0
@@ -21,6 +21,10 @@ config XEN_PV help Support running as a Xen PV guest. +config XEN_PV_SMP + def_bool y + depends on XEN_PV && SMP + config XEN_DOM0 bool "Xen PV Dom0 support" default y
@@ -37,6 +41,10 @@ config XEN_PVHVM help Support running as a Xen PVHVM guest. +config XEN_PVHVM_SMP + def_bool y + depends on XEN_PVHVM && SMP + config XEN_512GB bool "Limit Xen pv-domain memory to 512GB" depends on XEN_PV && X86_64
arch/x86/xen/Makefile +4 -1
@@ -20,7 +20,10 @@ obj-$(CONFIG_XEN_PVHVM) += enlighten_hvm.o obj-$(CONFIG_EVENT_TRACING) += trace.o -obj-$(CONFIG_SMP) += smp.o +obj-$(CONFIG_SMP) += smp_common.o +obj-$(CONFIG_XEN_PV_SMP) += smp.o +obj-$(CONFIG_XEN_PVHVM_SMP) += smp_hvm.o + obj-$(CONFIG_PARAVIRT_SPINLOCKS)+= spinlock.o obj-$(CONFIG_XEN_DEBUG_FS) += debugfs.o obj-$(CONFIG_XEN_DOM0) += vga.o
arch/x86/xen/enlighten.c +8 -0
@@ -1603,12 +1603,20 @@ static int xen_cpu_up_prepare_pv(unsigned int cpu) cpu, rc);return rc; } + + rc =xen_smp_intr_init_pv (cpu); +if (rc) { +WARN (1 ,"xen_smp_intr_init_pv() for CPU %d failed: %d\n" , + cpu, rc); +return rc; + }return 0 ; }static int xen_cpu_dead_pv (unsigned int cpu) {xen_smp_intr_free (cpu); +xen_smp_intr_free_pv (cpu);if (xen_pv_domain () ||xen_feature (XENFEAT_hvm_safe_pvclock))xen_teardown_timer (cpu);
arch/x86/xen/smp.c +16 -279
410 lines not on this page · raw message
arch/x86/xen/smp.h +23 -0
@@ -8,9 +8,22 @@ extern void xen_send_IPI_mask_allbutself(const struct cpumask *mask,extern void xen_send_IPI_allbutself (int vector);extern void xen_send_IPI_all (int vector);extern void xen_send_IPI_self (int vector); +extern void xen_send_IPI_mask (const struct cpumask *mask,int vector);extern int xen_smp_intr_init (unsigned int cpu);extern void xen_smp_intr_free (unsigned int cpu); +#ifdef CONFIG_XEN_PV +extern int xen_smp_intr_init_pv (unsigned int cpu); +extern void xen_smp_intr_free_pv (unsigned int cpu); +#endif +extern void xen_smp_send_reschedule (int cpu); +extern void xen_smp_send_call_function_ipi (const struct cpumask *mask); +extern void xen_smp_send_call_function_single_ipi (int cpu); + +struct xen_common_irq { +int irq; +char *name; +};#else /* CONFIG_SMP */
@@ -18,6 +31,16 @@ static inline int xen_smp_intr_init(unsigned int cpu) {return 0 ; } + +#ifdef CONFIG_XEN_PV +static inline int xen_smp_intr_init_pv (unsigned int cpu) +{ +return 0 ; +} + +static inline void xen_smp_intr_free_pv (unsigned int cpu) {} +#endif +static inline void xen_smp_intr_free (unsigned int cpu) {}#endif /* CONFIG_SMP */
arch/x86/xen/smp_common.c new file +246 -0
246 lines not on this page · raw message
arch/x86/xen/smp_hvm.c new file +54 -0
54 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 3/4 x86/xen: put setup.c, mmu.c and p2m.c under CONFIG_XEN_PV
In reply to Vitaly KuznetsovThese three files (mmu.c, p2m.c, setup.c) are mostly required to support PV guests, in fact p2m.c and setup.c have no code for PVHVM at all. mmu.c has some, move it to mmu_common.c and mmu_hvm.c.
Some additional changes are required:
- In the balloon driver we can't use xen_start_info, xen_released_pages and xen_extra_mem it is PV-only. Decorate it with #ifdef CONFIG_XEN_PV
- Some PV-only functions are used by drivers and for PVHVM guests these functions have 'if (xen_feature(XENFEAT_auto_translated_physmap))' check in the beginning. Create required stubs for PVHVM-only builds.
--- arch/x86/include/asm/xen/page.h | 44 ++++++- arch/x86/xen/Makefile | 10 +- arch/x86/xen/mmu.c | 284 ---------------------------------------- arch/x86/xen/mmu_common.c | 219 +++++++++++++++++++++++++++++++ arch/x86/xen/mmu_hvm.c | 77 +++++++++++ drivers/xen/balloon.c | 30 +++-- include/xen/xen-ops.h | 13 ++ 7 files changed, 376 insertions(+), 301 deletions(-) create mode 100644 arch/x86/xen/mmu_common.c create mode 100644 arch/x86/xen/mmu_hvm.c
arch/x86/include/asm/xen/page.h +42 -2
@@ -43,9 +43,10 @@ extern unsigned long *xen_p2m_addr;extern unsigned long xen_p2m_size;extern unsigned long xen_max_p2m_pfn; -extern int xen_alloc_p2m_entry (unsigned long pfn); -extern unsigned long get_phys_to_machine (unsigned long pfn); + +#ifdef CONFIG_XEN_PV +extern int xen_alloc_p2m_entry (unsigned long pfn);extern bool set_phys_to_machine (unsigned long pfn,unsigned long mfn);extern bool __set_phys_to_machine (unsigned long pfn,unsigned long mfn); extern unsigned long __init set_phys_range_identity(unsigned long pfn_s,
@@ -57,6 +58,38 @@ extern int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops,extern int clear_foreign_p2m_mapping (struct gnttab_unmap_grant_ref *unmap_ops,struct gnttab_unmap_grant_ref *kunmap_ops,struct page **pages,unsigned int count); +#else /* CONFIG_XEN_PV */ +static inline int xen_alloc_p2m_entry (unsigned long pfn) +{ +return 0 ; +} + +static inline bool set_phys_to_machine (unsigned long pfn,unsigned long mfn) +{ +return true; +} + +static inline bool __set_phys_to_machine (unsigned long pfn,unsigned long mfn) +{ +return true; +} + +static inline int +set_foreign_p2m_mapping (struct gnttab_map_grant_ref *map_ops, +struct gnttab_map_grant_ref *kmap_ops, +struct page **pages,unsigned int count) +{ +return 0 ; +} + +static inline int +clear_foreign_p2m_mapping (struct gnttab_unmap_grant_ref *unmap_ops, +struct gnttab_unmap_grant_ref *kunmap_ops, +struct page **pages,unsigned int count) +{ +return 0 ; +} +#endif /* CONFIG_XEN_PV */ /* * Helper functions to write or read unsigned long values to/from
@@ -82,6 +115,7 @@ static inline int xen_safe_read_ulong(unsigned long *addr, unsigned long *val)* - get_phys_to_machine() is to be called by __pfn_to_mfn() only in special * cases needing an extended handling. */ +#ifdef CONFIG_XEN_PV static inline unsigned long __pfn_to_mfn (unsigned long pfn) {unsigned long mfn;
@@ -98,6 +132,12 @@ static inline unsigned long __pfn_to_mfn(unsigned long pfn) return mfn; } +#else +static inline unsigned long __pfn_to_mfn (unsigned long pfn) +{ +return pfn; +} +#endif static inline unsigned long pfn_to_mfn (unsigned long pfn) {
arch/x86/xen/Makefile +5 -5
@@ -10,13 +10,13 @@ nostackp := $(call cc-option, -fno-stack-protector) CFLAGS_enlighten.o := $(nostackp) CFLAGS_mmu.o := $(nostackp) -obj-y := enlighten_common.o setup.o multicalls.o \ - mmu.o irq.o time.o xen-asm.o xen-asm_$(BITS).o \ +obj-y := enlighten_common.o multicalls.o \ + irq.o time.o xen-asm.o xen-asm_$(BITS).o \ grant-table.o suspend.o platform-pci-unplug.o \ - p2m.o apic.o pmu.o + apic.o pmu.o mmu_common.o -obj-$(CONFIG_XEN_PV) += enlighten.o -obj-$(CONFIG_XEN_PVHVM) += enlighten_hvm.o +obj-$(CONFIG_XEN_PV) += enlighten.o setup.o mmu.o p2m.o +obj-$(CONFIG_XEN_PVHVM) += enlighten_hvm.o mmu_hvm.o obj-$(CONFIG_EVENT_TRACING) += trace.o
arch/x86/xen/mmu.c +0 -284
305 lines not on this page · raw message
arch/x86/xen/mmu_common.c new file +219 -0
219 lines not on this page · raw message
arch/x86/xen/mmu_hvm.c new file +77 -0
77 lines not on this page · raw message
drivers/xen/balloon.c +20 -10
@@ -710,6 +710,7 @@ void free_xenballooned_pages(int nr_pages, struct page **pages) }EXPORT_SYMBOL (free_xenballooned_pages); +#ifdef CONFIG_XEN_PV static void __init balloon_add_region (unsigned long start_pfn,unsigned long pages) {
@@ -733,19 +734,22 @@ static void __init balloon_add_region(unsigned long start_pfn, balloon_stats.total_pages += extra_pfn_end - start_pfn; } +#endif static int __init balloon_init (void ) { -int i; -if (!xen_domain ())return -ENODEV ;pr_info ("Initialising balloon driver\n" ); +#ifdef CONFIG_XEN_PV balloon_stats.current_pages =xen_pv_domain () ?min (xen_start_info->nr_pages - xen_released_pages, max_pfn) :get_num_physpages (); +#else + balloon_stats.current_pages =get_num_physpages (); +#endif balloon_stats.target_pages = balloon_stats.current_pages; balloon_stats.balloon_low =0 ; balloon_stats.balloon_high =0 ;
@@ -762,14 +766,20 @@ static int __init balloon_init(void)register_sysctl_table (xen_root);#endif -/* -* Initialize the balloon with pages from the extra memory -* regions (see arch/x86/xen/setup.c). -*/ -for (i =0 ; i <XEN_EXTRA_MEM_MAX_REGIONS ; i++) -if (xen_extra_mem[i].n_pfns) -balloon_add_region (xen_extra_mem[i].start_pfn, - xen_extra_mem[i].n_pfns); +#ifdef CONFIG_XEN_PV + { +int i; + +/* +* Initialize the balloon with pages from the extra memory +* regions (see arch/x86/xen/setup.c). +*/ +for (i =0 ; i <XEN_EXTRA_MEM_MAX_REGIONS ; i++) +if (xen_extra_mem[i].n_pfns) +balloon_add_region (xen_extra_mem[i].start_pfn, + xen_extra_mem[i].n_pfns); + } +#endif return 0 ; }
include/xen/xen-ops.h +13 -0
@@ -41,11 +41,24 @@ int xen_cpuhp_setup(int (*cpu_up_prepare_cb)(unsigned int),void xen_reboot (int reason);extern unsigned long *xen_contiguous_bitmap; +#ifdef CONFIG_XEN_PV int xen_create_contiguous_region (phys_addr_t pstart,unsigned int order,unsigned int address_bits,dma_addr_t *dma_handle);void xen_destroy_contiguous_region (phys_addr_t pstart,unsigned int order); +#else +static inline int xen_create_contiguous_region (phys_addr_t pstart, +unsigned int order, +unsigned int address_bits, +dma_addr_t *dma_handle) +{ +return 0 ; +} + +static inline void xen_destroy_contiguous_region (phys_addr_t pstart, +unsigned int order) { } +#endif struct vm_area_struct ;
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 4/4 x86/xen: put setup.c, pmu.c and apic.c under CONFIG_XEN_PV
In reply to Vitaly Kuznetsovxen_pmu_init/finish() functions are used in suspend.c and enlighten_common.c, add stubs for now.
--- arch/x86/xen/Kconfig | 2 +- arch/x86/xen/Makefile | 4 ++-- arch/x86/xen/pmu.h | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-)
arch/x86/xen/Kconfig +1 -1
@@ -6,7 +6,6 @@ config XEN bool "Xen guest support" depends on PARAVIRT select PARAVIRT_CLOCK - select XEN_HAVE_VPMU depends on X86_64 || (X86_32 && X86_PAE) depends on X86_LOCAL_APIC && X86_TSC help
@@ -18,6 +17,7 @@ config XEN_PV bool "Xen PV guest support" default y depends on XEN + select XEN_HAVE_VPMU help Support running as a Xen PV guest.
arch/x86/xen/Makefile +2 -2
@@ -13,9 +13,9 @@ CFLAGS_mmu.o := $(nostackp) obj-y := enlighten_common.o multicalls.o \ irq.o time.o xen-asm.o xen-asm_$(BITS).o \ grant-table.o suspend.o platform-pci-unplug.o \ - apic.o pmu.o mmu_common.o + mmu_common.o -obj-$(CONFIG_XEN_PV) += enlighten.o setup.o mmu.o p2m.o +obj-$(CONFIG_XEN_PV) += enlighten.o setup.o mmu.o p2m.o pmu.o apic.o obj-$(CONFIG_XEN_PVHVM) += enlighten_hvm.o mmu_hvm.o obj-$(CONFIG_EVENT_TRACING) += trace.o
arch/x86/xen/pmu.h +5 -0
@@ -4,8 +4,13 @@#include <xen/interface/xenpmu.h> irqreturn_t xen_pmu_irq_handler (int irq,void *dev_id); +#ifdef CONFIG_XEN_HAVE_VPMU void xen_pmu_init (int cpu);void xen_pmu_finish (int cpu); +#else +static inline void xen_pmu_init (int cpu) {} +static inline void xen_pmu_finish (int cpu) {} +#endif bool is_xen_pmu (int cpu);bool pmu_msr_read (unsigned int msr,uint64_t *val,int *err);bool pmu_msr_write (unsigned int msr,uint32_t low,uint32_t high,int *err);
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 12 lines · Vitaly Kuznetsov
Hi,
I have a long-standing idea to separate PV and PVHVM code in kernel and introduce
Kconfigoptions to make it possible to enable the required parts only breaking the current 'all or nothing' approach.Motivation:
- Xen related x86 code in kernel is rather big and it is unclear which parts of it are required for PV, for HVM or for both. With PVH coming into picture is becomes even more tangled. It makes it hard to understand/audit the code.
Quoted 6 lines
- In some case we may want to avoid bloating kernel by supporting Xen guests we don't need. In particular, 90% of the code in
arch/x86/xen/is required to support PV guests and one may require PVHVM support only.- PV guests are supposed to go away one day and such code separation would help us to get ready.
All good reasons.
Quoted 6 lines
This RFC adds
XEN_PVKconfigoption and makes it possible to build PV-only and PVHVM-only kernels. It also makes it possible to disable Dom0 support. The series is incomplete and probably dirty in some places, I didn't pay much attention to the current PVH implementation as (as far as I understand) it is supposed to be replaced with PVHv2 but before investing more I'd like to get opinions whether such refactoring will be welcomed.
This series might be best done after PVHv1 is removed. Boris, any thoughts on the best approach here?
David
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Boris Ostrovsky
reviewerQuoted 21 lines · David Vrabel
Quoted 12 lines · Vitaly Kuznetsov
Hi,
I have a long-standing idea to separate PV and PVHVM code in kernel and introduce
Kconfigoptions to make it possible to enable the required parts only breaking the current 'all or nothing' approach.Motivation:
- Xen related x86 code in kernel is rather big and it is unclear which parts of it are required for PV, for HVM or for both. With PVH coming into picture is becomes even more tangled. It makes it hard to understand/audit the code.Quoted 6 lines
- In some case we may want to avoid bloating kernel by supporting Xen guests we don't need. In particular, 90% of the code in
arch/x86/xen/is required to support PV guests and one may require PVHVM support only.- PV guests are supposed to go away one day and such code separation would help us to get ready.
All good reasons.
Quoted 8 lines
Quoted 6 lines
This RFC adds
XEN_PVKconfigoption and makes it possible to build PV-only and PVHVM-only kernels. It also makes it possible to disable Dom0 support. The series is incomplete and probably dirty in some places, I didn't pay much attention to the current PVH implementation as (as far as I understand) it is supposed to be replaced with PVHv2 but before investing more I'd like to get opinions whether such refactoring will be welcomed.This series might be best done after PVHv1 is removed. Boris, any thoughts on the best approach here?
I would prefer to wait until at least domU PVHv2 (together with removal of v1) happens. As soon as I am done with ACPI hotplug on the hypervisor side I will post the new version.
-boris
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 14 lines · Boris Ostrovsky
Quoted 13 lines · David Vrabel
Quoted 12 lines · Vitaly Kuznetsov
Hi,
I have a long-standing idea to separate PV and PVHVM code in kernel and introduce
Kconfigoptions to make it possible to enable the required parts only breaking the current 'all or nothing' approach.Motivation:
- Xen related x86 code in kernel is rather big and it is unclear which parts of it are required for PV, for HVM or for both. With PVH coming into picture is becomes even more tangled. It makes it hard to understand/audit the code.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
- In some case we may want to avoid bloating kernel by supporting Xen guests we don't need. In particular, 90% of the code in
arch/x86/xen/is required to support PV guests and one may require PVHVM support only.- PV guests are supposed to go away one day and such code separation would help us to get ready.
All good reasons.
Good, let's do it then)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
This RFC adds
XEN_PVKconfigoption and makes it possible to build PV-only and PVHVM-only kernels. It also makes it possible to disable Dom0 support. The series is incomplete and probably dirty in some places, I didn't pay much attention to the current PVH implementation as (as far as I understand) it is supposed to be replaced with PVHv2 but before investing more I'd like to get opinions whether such refactoring will be welcomed.
Quoted 6 lines
Quoted 2 lines
This series might be best done after PVHv1 is removed. Boris, any thoughts on the best approach here?
I would prefer to wait until at least domU PVHv2 (together with removal of v1) happens. As soon as I am done with ACPI hotplug on the hypervisor side I will post the new version.
Sure, there is no rush here.
Signature · 6 lines
Vitaly _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel