Skip to contentSkip to conversation

PV extension of HVM (Hybrid) for Xen

PATCH Superseded Sheng Yang 1 participant 8 messages Mar 11, 2010

Subsystems (8)

v8 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Sheng Yang

author
#0 lore raw

v8 cover PV extension of HVM (Hybrid) for Xen

The 8th version of patchset to enable PV extension of HVM support in Linux kernel of Xen.

The patch based on upstream 2.6.33, also applied to 2.6.33-rc1-tip+. And we target for Linux upstream as well.

The PV extension of HVM is started from real mode like HVM guest, but also with a a range of PV features(e.g. PV timer, event channel, and PV
drivers in the future). So guest with this feature can takes the advantages of both H/W virtualization and Para-Virtualization.

The first two of the patchset imported several header file from Jeremy's tree and Xen tree, respect to Jeremy and Keir's works.

The whole patchset based on Linux upstream.

You need a line like:

cpuid = [ '0x40000002:edx=0x7' ]

in HVM configuration file to expose all PV feature to guest, and

CONFIG_XEN

in the guest kernel configuration file to enable the PV extension support. It would implicit enable CONFIG_XEN_HVM_PV if CONFIG_X86_64 is selected as well.

And the compiled image can be used as native/pv domU/hvm guest/pv feature hvm kernel.

Change from v7:
1. Move evtchn related macro to patch 7. So that the patch 1-6 can be cleanly applied.

Change from v6:
1. Make PV clocksource as a separate feature rather than default one. Notice PV evtchn still depends on it.
2. Some comments update.

Change from v5:
Update the comments from Jeremy.

Change from v4:
1. Add a new CONFIG_XEN_HVM_PV to enable the feature in kernel
2. Separate the related code form enlighted.c to hvmpv.c
3. Separate the feature "PV clocksource" from evtchn. Now we can support HVM guest with PV clocksource. This would be enabled by default.
4. Drop PV halt and pv drivers in this edition. We can work on that later.
5. Update the patchset following Jeremy's comments.

Change from v3:
1. Rebase to Linux 2.6.33 release.
2. change the name to "PV extension of HVM"
3. Some minor coding polishing.

Change from v2:
1. change the name "hybrid" to "PV featured HVM".
2. Unified the PV driver's judgement of xen_domain() to xen_evtchn_enabled().
3. Move the function(evtchn) initialize hypercall near the real enabling place, rather than a unified place before function enabled.
4. Remove the reserved E820 region for grant table. Use QEmu Xen platform device's MMIO instead.

The major change from v1:
1. SMP support.
2. Modify the entrance point to avoid most of genernic kernel modification.
3. Binding PV timer with event channel mechanism.

--
regards
Yang, Sheng

Jeremy Fitzhardinge (1):
xen: add support for hvm_op

Keir Fraser (1):
xen: Import cpuid.h from Xen

Sheng Yang (5):
xen: Make pv drivers only work with xen_pv_domain() xen/hvm: Xen PV extension of HVM initialization x86/xen: The entrance for PV extension of HVM
xen: Enable PV clocksource for HVM
xen: Enable event channel of PV extension of HVM

 arch/x86/include/asm/xen/cpuid.h      |   75 +++++++++++
 arch/x86/include/asm/xen/hypercall.h  |    6 +
 arch/x86/include/asm/xen/hypervisor.h |    6 +
 arch/x86/kernel/setup.c               |    4 +
 arch/x86/xen/Kconfig                  |    4 +
 arch/x86/xen/Makefile                 |    1 +
 arch/x86/xen/enlighten.c              |    6 +-
 arch/x86/xen/hvmpv.c                  |  228 +++++++++++++++++++++++++++++++++
 arch/x86/xen/irq.c                    |    9 ++
 arch/x86/xen/smp.c                    |   76 +++++++++++-
 arch/x86/xen/time.c                   |   12 ++-
 arch/x86/xen/xen-ops.h                |   17 +++
 drivers/block/xen-blkfront.c          |    2 +-
 drivers/input/xen-kbdfront.c          |    2 +-
 drivers/net/xen-netfront.c            |    2 +-
 drivers/video/xen-fbfront.c           |    2 +-
 drivers/xen/events.c                  |   74 ++++++++++-
 drivers/xen/grant-table.c             |    2 +-
 drivers/xen/xenbus/xenbus_probe.c     |    4 +-
 include/xen/events.h                  |    4 +
 include/xen/hvm.h                     |   28 ++++
 include/xen/interface/hvm/hvm_op.h    |   80 ++++++++++++
 include/xen/interface/hvm/params.h    |  111 ++++++++++++++++
 include/xen/interface/xen.h           |    6 +-
 include/xen/xen.h                     |   15 ++
 25 files changed, 754 insertions(+), 22 deletions(-)
 create mode 100644 arch/x86/include/asm/xen/cpuid.h
 create mode 100644 arch/x86/xen/hvmpv.c
 create mode 100644 include/xen/hvm.h
 create mode 100644 include/xen/interface/hvm/hvm_op.h
 create mode 100644 include/xen/interface/hvm/params.h
author
#1 lore raw

PATCH v8 1/7 xen: add support for hvm_op

From: Jeremy Fitzhardinge <[email protected]>

Add support for hvm_op hypercall.

---
 arch/x86/include/asm/xen/hypercall.h |    6 ++
 include/xen/hvm.h                    |   23 +++++++
 include/xen/interface/hvm/hvm_op.h   |   72 ++++++++++++++++++++++
 include/xen/interface/hvm/params.h   |  111 ++++++++++++++++++++++++++++++++++
 4 files changed, 212 insertions(+), 0 deletions(-)
 create mode 100644 include/xen/hvm.h
 create mode 100644 include/xen/interface/hvm/hvm_op.h
 create mode 100644 include/xen/interface/hvm/params.h
arch/x86/include/asm/xen/hypercall.h +6 -0
index 9c371e4..47c2ebb 100644
@@ -417,6 +417,12 @@ HYPERVISOR_nmi_op(unsigned long op, unsigned long arg)
 	return _hypercall2(int, nmi_op, op, arg);
 }
 
+static inline unsigned long __must_check
+HYPERVISOR_hvm_op(int op, void *arg)
+{
+	return _hypercall2(unsigned long, hvm_op, op, arg);
+}
+
 static inline void
 MULTI_fpu_taskswitch(struct multicall_entry *mcl, int set)
 {
include/xen/hvm.h new file +23 -0
new file mode 100644
index 0000000..4ea8887
@@ -0,0 +1,23 @@
+/* Simple wrappers around HVM functions */
+#ifndef XEN_HVM_H__
+#define XEN_HVM_H__
+
+#include <xen/interface/hvm/params.h>
+
+static inline unsigned long hvm_get_parameter(int idx)
+{
+	struct xen_hvm_param xhv;
+	int r;
+
+	xhv.domid = DOMID_SELF;
+	xhv.index = idx;
+	r = HYPERVISOR_hvm_op(HVMOP_get_param, &xhv);
+	if (r < 0) {
+		printk(KERN_ERR "cannot get hvm parameter %d: %d.\n",
+		       idx, r);
+		return 0;
+	}
+	return xhv.value;
+}
+
+#endif /* XEN_HVM_H__ */
include/xen/interface/hvm/hvm_op.h new file +72 -0

72 lines not on this page · raw message

include/xen/interface/hvm/params.h new file +111 -0

111 lines not on this page · raw message

Signature · 1 line
1.7.0.1
author
#2 lore raw

PATCH v8 2/7 xen: Import cpuid.h from Xen

In reply to Sheng Yang

From: Keir Fraser <[email protected]>

Which would be used by CPUID detection later

---
 arch/x86/include/asm/xen/cpuid.h |   68 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 68 insertions(+), 0 deletions(-)
 create mode 100644 arch/x86/include/asm/xen/cpuid.h
arch/x86/include/asm/xen/cpuid.h new file +68 -0
new file mode 100644
index 0000000..8787f03
@@ -0,0 +1,68 @@
+/******************************************************************************
+ * arch/include/asm/xen/cpuid.h
+ *
+ * CPUID interface to Xen.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (c) 2007 Citrix Systems, Inc.
+ *
+ * Authors:
+ *    Keir Fraser <[email protected]>
+ */
+
+#ifndef __ASM_X86_XEN_CPUID_H__
+#define __ASM_X86_XEN_CPUID_H__
+
+/* Xen identification leaves start at 0x40000000. */
+#define XEN_CPUID_FIRST_LEAF 0x40000000
+#define XEN_CPUID_LEAF(i)    (XEN_CPUID_FIRST_LEAF + (i))
+
+/*
+ * Leaf 1 (0x40000000)
+ * EAX: Largest Xen-information leaf. All leaves up to an including @EAX
+ *      are supported by the Xen host.
+ * EBX-EDX: "XenVMMXenVMM" signature, allowing positive identification
+ *      of a Xen host.
+ */
+#define XEN_CPUID_SIGNATURE_EBX 0x566e6558 /* "XenV" */
+#define XEN_CPUID_SIGNATURE_ECX 0x65584d4d /* "MMXe" */
+#define XEN_CPUID_SIGNATURE_EDX 0x4d4d566e /* "nVMM" */
+
+/*
+ * Leaf 2 (0x40000001)
+ * EAX[31:16]: Xen major version.
+ * EAX[15: 0]: Xen minor version.
+ * EBX-EDX: Reserved (currently all zeroes).
+ */
+
+/*
+ * Leaf 3 (0x40000002)
+ * EAX: Number of hypercall transfer pages. This register is always guaranteed
+ *      to specify one hypercall page.
+ * EBX: Base address of Xen-specific MSRs.
+ * ECX: Features 1. Unused bits are set to zero.
+ * EDX: Features 2. Unused bits are set to zero.
+ */
+
+/* Does the host support MMU_PT_UPDATE_PRESERVE_AD for this guest? */
+#define _XEN_CPUID_FEAT1_MMU_PT_UPDATE_PRESERVE_AD 0
+#define XEN_CPUID_FEAT1_MMU_PT_UPDATE_PRESERVE_AD  (1u<<0)
+
+#endif /* __XEN_PUBLIC_ARCH_X86_CPUID_H__ */
Signature · 1 line
1.7.0.1
author
#3 lore raw

PATCH v8 3/7 xen: Make pv drivers only work with xen_pv_domain()

In reply to Sheng Yang

Otherwise they would still try to enable with HVM domain type.

---
 drivers/block/xen-blkfront.c      |    2 +-
 drivers/input/xen-kbdfront.c      |    2 +-
 drivers/net/xen-netfront.c        |    2 +-
 drivers/video/xen-fbfront.c       |    2 +-
 drivers/xen/grant-table.c         |    2 +-
 drivers/xen/xenbus/xenbus_probe.c |    4 ++--
 6 files changed, 7 insertions(+), 7 deletions(-)
drivers/block/xen-blkfront.c +1 -1
index 05a31e5..32e28bd 100644
@@ -1068,7 +1068,7 @@ static struct xenbus_driver blkfront = {
 
 static int __init xlblk_init(void)
 {
-	if (!xen_domain())
+	if (!xen_pv_domain())
 		return -ENODEV;
 
 	if (register_blkdev(XENVBD_MAJOR, DEV_NAME)) {
drivers/input/xen-kbdfront.c +1 -1
index c721c0a..0c3f4ca 100644
@@ -338,7 +338,7 @@ static struct xenbus_driver xenkbd_driver = {
 
 static int __init xenkbd_init(void)
 {
-	if (!xen_domain())
+	if (!xen_pv_domain())
 		return -ENODEV;
 
 	/* Nothing to do if running in dom0. */
drivers/net/xen-netfront.c +1 -1
index a869b45..e3ae126 100644
@@ -1804,7 +1804,7 @@ static struct xenbus_driver netfront_driver = {
 
 static int __init netif_init(void)
 {
-	if (!xen_domain())
+	if (!xen_pv_domain())
 		return -ENODEV;
 
 	if (xen_initial_domain())
drivers/video/xen-fbfront.c +1 -1
index 603598f..3360470 100644
@@ -683,7 +683,7 @@ static struct xenbus_driver xenfb_driver = {
 
 static int __init xenfb_init(void)
 {
-	if (!xen_domain())
+	if (!xen_pv_domain())
 		return -ENODEV;
 
 	/* Nothing to do if running in dom0. */
drivers/xen/grant-table.c +1 -1
index 4c6c0bd..ade7f3d 100644
@@ -510,7 +510,7 @@ static int __devinit gnttab_init(void)
 	unsigned int max_nr_glist_frames, nr_glist_frames;
 	unsigned int nr_init_grefs;
 
-	if (!xen_domain())
+	if (!xen_pv_domain())
 		return -ENODEV;
 
 	nr_grant_frames = 1;
drivers/xen/xenbus/xenbus_probe.c +2 -2
index 2f7aaa9..a5712cd 100644
@@ -786,7 +786,7 @@ static int __init xenbus_probe_init(void)
 	DPRINTK("");
 
 	err = -ENODEV;
-	if (!xen_domain())
+	if (!xen_pv_domain())
 		goto out_error;
 
 	/* Register ourselves with the kernel bus subsystem */
@@ -922,7 +922,7 @@ static void wait_for_devices(struct xenbus_driver *xendrv)
 	struct device_driver *drv = xendrv ? &xendrv->driver : NULL;
 	unsigned int seconds_waited = 0;
 
-	if (!ready_to_wait_for_devices || !xen_domain())
+	if (!ready_to_wait_for_devices || !xen_pv_domain())
 		return;
 
 	while (exists_connecting_device(drv)) {
Signature · 1 line
1.7.0.1
author
#4 lore raw

PATCH v8 4/7 xen/hvm: Xen PV extension of HVM initialization

In reply to Sheng Yang

The PV extended HVM(once known as Hybrid) is started from real mode like HVM guest, but also with a component based PV feature selection(e.g. PV halt, PV timer, event channel, then PV drivers). So guest can takes the advantages of both H/W virtualization and Para-Virtualization.

This patch introduced the PV extension of HVM guest initialization.

Guest would detect the capability using CPUID 0x40000002.edx, then call HVMOP_enable_pv hypercall to enable pv support in hypervisor.

---
 arch/x86/include/asm/xen/cpuid.h   |    5 ++
 arch/x86/xen/Kconfig               |    4 +
 arch/x86/xen/Makefile              |    1 +
 arch/x86/xen/hvmpv.c               |  136 ++++++++++++++++++++++++++++++++++++
 include/xen/interface/hvm/hvm_op.h |    8 ++
 include/xen/xen.h                  |   12 +++
 6 files changed, 166 insertions(+), 0 deletions(-)
 create mode 100644 arch/x86/xen/hvmpv.c
arch/x86/include/asm/xen/cpuid.h +5 -0
index 8787f03..b3a0b3a 100644
@@ -65,4 +65,9 @@
 #define _XEN_CPUID_FEAT1_MMU_PT_UPDATE_PRESERVE_AD 0
 #define XEN_CPUID_FEAT1_MMU_PT_UPDATE_PRESERVE_AD  (1u<<0)
 
+#define _XEN_CPUID_FEAT2_HVM_PV 0
+#define XEN_CPUID_FEAT2_HVM_PV (1u<<0)
+#define _XEN_CPUID_FEAT2_HVM_PV_CLOCK 1
+#define XEN_CPUID_FEAT2_HVM_PV_CLOCK (1u<<1)
+
 #endif /* __XEN_PUBLIC_ARCH_X86_CPUID_H__ */
arch/x86/xen/Kconfig +4 -0
index b83e119..74fc233 100644
@@ -36,3 +36,7 @@ config XEN_DEBUG_FS
 	help
 	  Enable statistics output and various tuning options in debugfs.
 	  Enabling this option may incur a significant performance overhead.
+
+config XEN_HVM_PV
+	def_bool y
+	depends on XEN && X86_64
arch/x86/xen/Makefile +1 -0
index 3bb4fc2..73bd5db 100644
@@ -17,4 +17,5 @@ obj-y		:= enlighten.o setup.o multicalls.o mmu.o irq.o \
 obj-$(CONFIG_SMP)		+= smp.o
 obj-$(CONFIG_PARAVIRT_SPINLOCKS)+= spinlock.o
 obj-$(CONFIG_XEN_DEBUG_FS)	+= debugfs.o
+obj-$(CONFIG_XEN_HVM_PV)	+= hvmpv.o
 
arch/x86/xen/hvmpv.c new file +136 -0

136 lines not on this page · raw message

include/xen/interface/hvm/hvm_op.h +8 -0
index 7c74ba4..d229b50 100644
@@ -69,4 +69,12 @@ DEFINE_GUEST_HANDLE_STRUCT(xen_hvm_set_pci_link_route);
 /* Flushes all VCPU TLBs: @arg must be NULL. */
 #define HVMOP_flush_tlbs          5
 
+/* Enable PV extended HVM features. Should called by BSP */
+#define HVMOP_enable_pv 9
+struct xen_hvm_pv_type {
+	/* The features want to be enabled */
+	uint32_t flags;
+#define HVM_PV_CLOCK  (1ull<<0)
+};
+
 #endif /* __XEN_PUBLIC_HVM_HVM_OP_H__ */
include/xen/xen.h +12 -0
index a164024..ce7417d 100644
@@ -19,6 +19,18 @@ extern enum xen_domain_type xen_domain_type;
 #define xen_hvm_domain()	(xen_domain() &&			\
 				 xen_domain_type == XEN_HVM_DOMAIN)
 
+#ifdef CONFIG_XEN_HVM_PV
+
+#define XEN_HVM_PV_CLOCK_ENABLED   (1u << 0)
+#define XEN_HVM_PV_EVTCHN_ENABLED   (1u << 1)
+extern u32 xen_hvm_pv_features;
+
+#define xen_hvm_pv_clock_enabled() \
+		(xen_hvm_pv_features & XEN_HVM_PV_CLOCK_ENABLED)
+#else
+#define xen_hvm_pv_clock_enabled() 0
+#endif /* CONFIG_XEN_HVM_PV */
+
 #ifdef CONFIG_XEN_DOM0
 #include <xen/interface/xen.h>
 #include <asm/xen/hypervisor.h>
Signature · 1 line
1.7.0.1
author
#5 lore raw

PATCH v8 5/7 x86/xen: The entrance for PV extension of HVM

In reply to Sheng Yang

xen_guest_init() would setup the environment.

---
 arch/x86/include/asm/xen/hypervisor.h |    6 ++++++
 arch/x86/kernel/setup.c               |    4 ++++
 2 files changed, 10 insertions(+), 0 deletions(-)
arch/x86/include/asm/xen/hypervisor.h +6 -0
index 396ff4c..13e089a 100644
@@ -37,4 +37,10 @@
 extern struct shared_info *HYPERVISOR_shared_info;
 extern struct start_info *xen_start_info;
 
+#ifdef CONFIG_XEN_HVM_PV
+void __init xen_guest_init(void);
+#else
+static inline void xen_guest_init(void) {};
+#endif
+
 #endif /* _ASM_X86_XEN_HYPERVISOR_H */
arch/x86/kernel/setup.c +4 -0
index 5d9e40c..1cc4786 100644
@@ -113,6 +113,8 @@
 #endif
 #include <asm/mce.h>
 
+#include <asm/xen/hypervisor.h>
+
 /*
  * end_pfn only includes RAM, while max_pfn_mapped includes all e820 entries.
  * The direct mapping extends to max_pfn_mapped, so that we can directly access
@@ -740,6 +742,8 @@ void __init setup_arch(char **cmdline_p)
 
 	x86_init.oem.arch_setup();
 
+	xen_guest_init();
+
 	setup_memory_map();
 	parse_setup_data();
 	/* update the e820_saved too */
Signature · 1 line
1.7.0.1
author
#6 lore raw

PATCH v8 6/7 xen: Enable PV clocksource for HVM

In reply to Sheng Yang

PV clocksource can provide a reliable clocksource for HVM running on Xen.

To enable it, put following line to the HVM configure file:

cpuid = [ '0x40000002:edx=0x3' ]

It would set bit 0 and bit 1 in 0x40000002:edx, which enable PV extension framework and PV clocksource.

---
 arch/x86/xen/hvmpv.c   |   24 ++++++++++++++++++++++++
 arch/x86/xen/time.c    |   12 +++++++++++-
 arch/x86/xen/xen-ops.h |    1 +
 3 files changed, 36 insertions(+), 1 deletions(-)
arch/x86/xen/hvmpv.c +24 -0
index 0b200b7..792d740 100644
@@ -43,6 +43,8 @@ static void __init xen_hvm_pv_banner(void)
 		pv_info.name);
 	printk(KERN_INFO "Xen version: %d.%d%s\n",
 		version >> 16, version & 0xffff, extra.extraversion);
+	if (xen_hvm_pv_clock_enabled())
+		printk(KERN_INFO "PV feature: PV clocksource enabled\n");
 }
 
 static int __init xen_para_available(void)
@@ -81,6 +83,9 @@ static int __init init_hvm_pv_info(void)
 	if (!(edx & XEN_CPUID_FEAT2_HVM_PV))
 		return -ENODEV;
 
+	if (edx & XEN_CPUID_FEAT2_HVM_PV_CLOCK)
+		xen_hvm_pv_features |= XEN_HVM_PV_CLOCK_ENABLED;
+
 	if (pages < 1)
 		return -ENODEV;
 
@@ -111,6 +116,23 @@ static int __init init_shared_info(void)
 	return 0;
 }
 
+static void __init init_pv_clocksource(void)
+{
+	if (!xen_hvm_pv_clock_enabled())
+		return;
+
+	if (enable_hvm_pv(HVM_PV_CLOCK))
+		BUG();
+
+	pv_time_ops.sched_clock = xen_sched_clock;
+
+	x86_platform.calibrate_tsc = xen_tsc_khz;
+	x86_platform.get_wallclock = xen_get_wallclock;
+	x86_platform.set_wallclock = xen_set_wallclock;
+
+	xen_register_clocksource();
+}
+
 void __init xen_guest_init(void)
 {
 	int r;
@@ -133,4 +155,6 @@ void __init xen_guest_init(void)
 	pv_info = xen_hvm_pv_info;
 
 	xen_domain_type = XEN_HVM_DOMAIN;
+
+	init_pv_clocksource();
 }
arch/x86/xen/time.c +11 -1
index 0d3f07c..06b3e72 100644
@@ -472,11 +472,21 @@ void xen_timer_resume(void)
 	}
 }
 
+static bool xen_clocksource_enabled;
+
+void xen_register_clocksource(void)
+{
+	if (!xen_clocksource_enabled) {
+		clocksource_register(&xen_clocksource);
+		xen_clocksource_enabled = 1;
+	}
+}
+
 __init void xen_time_init(void)
 {
 	int cpu = smp_processor_id();
 
-	clocksource_register(&xen_clocksource);
+	xen_register_clocksource();
 
 	if (HYPERVISOR_vcpu_op(VCPUOP_stop_periodic_timer, cpu, NULL) == 0) {
 		/* Successfully turned off 100Hz tick, so we have the
arch/x86/xen/xen-ops.h +1 -0
index f9153a3..d56b660 100644
@@ -48,6 +48,7 @@ cycle_t xen_clocksource_read(void);
 void xen_setup_cpu_clockevents(void);
 unsigned long xen_tsc_khz(void);
 void __init xen_time_init(void);
+void xen_register_clocksource(void);
 unsigned long xen_get_wallclock(void);
 int xen_set_wallclock(unsigned long time);
 unsigned long long xen_sched_clock(void);
Signature · 1 line
1.7.0.1
author
#7 lore raw

PATCH v8 7/7 xen: Enable event channel of PV extension of HVM

In reply to Sheng Yang

We mapped each IOAPIC pin to a VIRQ, so that we can deliver interrupt through these VIRQs.

We used X86_PLATFORM_IPI_VECTOR as the notification vector for hypervisor to notify guest about the event.

The patch also enabled SMP support, then we can support IPI through evtchn as well.

When this feature is enabled, we would relay on Xen PV timer for clockevent, rather than other hardware emulated ones.

Then we don't use IOAPIC/LAPIC, eliminated the overhead brought by unnecessary VMExit caused by LAPIC.

PV evtchn depends on PV clocksource. To enable it, put following line in the HVM configure file:

cpuid = [ '0x40000002:edx=0x7' ]

It would enable PV extension framework(bit 0), PV clocksource(bit 1), as well as PV evtchn(bit 2).

Notice if you try to enable PV evtchn without other two bits set, the setting would be ignored.

---
 arch/x86/include/asm/xen/cpuid.h |    2 +
 arch/x86/xen/enlighten.c         |    6 +-
 arch/x86/xen/hvmpv.c             |   70 ++++++++++++++++++++++++++++++++++-
 arch/x86/xen/irq.c               |    9 ++++
 arch/x86/xen/smp.c               |   76 ++++++++++++++++++++++++++++++++++++--
 arch/x86/xen/xen-ops.h           |   16 ++++++++
 drivers/xen/events.c             |   74 ++++++++++++++++++++++++++++++++++---
 include/xen/events.h             |    4 ++
 include/xen/hvm.h                |    5 ++
 include/xen/interface/xen.h      |    6 ++-
 include/xen/xen.h                |    3 +
 11 files changed, 256 insertions(+), 15 deletions(-)
arch/x86/include/asm/xen/cpuid.h +2 -0
index b3a0b3a..eebc5bf 100644
@@ -69,5 +69,7 @@
 #define XEN_CPUID_FEAT2_HVM_PV (1u<<0)
 #define _XEN_CPUID_FEAT2_HVM_PV_CLOCK 1
 #define XEN_CPUID_FEAT2_HVM_PV_CLOCK (1u<<1)
+#define _XEN_CPUID_FEAT2_HVM_PV_EVTCHN 1
+#define XEN_CPUID_FEAT2_HVM_PV_EVTCHN (1u<<2)
 
 #endif /* __XEN_PUBLIC_ARCH_X86_CPUID_H__ */
arch/x86/xen/enlighten.c +3 -3
index 36daccb..2d60e70 100644
@@ -717,7 +717,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
         return 0;
 }
 
-static void set_xen_basic_apic_ops(void)
+void xen_set_basic_apic_ops(void)
 {
 	apic->read = xen_apic_read;
 	apic->write = xen_apic_write;
@@ -1026,7 +1026,7 @@ static void xen_crash_shutdown(struct pt_regs *regs)
 	xen_reboot(SHUTDOWN_crash);
 }
 
-static const struct machine_ops __initdata xen_machine_ops = {
+const struct machine_ops __initdata xen_machine_ops = {
 	.restart = xen_restart,
 	.halt = xen_machine_halt,
 	.power_off = xen_machine_halt,
@@ -1116,7 +1116,7 @@ asmlinkage void __init xen_start_kernel(void)
 	/*
 	 * set up the basic apic ops.
 	 */
-	set_xen_basic_apic_ops();
+	xen_set_basic_apic_ops();
 #endif
 
 	if (xen_feature(XENFEAT_mmu_pt_update_preserve_ad)) {
arch/x86/xen/hvmpv.c +69 -1

100 lines not on this page · raw message

arch/x86/xen/irq.c +9 -0
index 9d30105..3de2055 100644
@@ -2,6 +2,7 @@
 
 #include <asm/x86_init.h>
 
+#include <xen/xen.h>
 #include <xen/interface/xen.h>
 #include <xen/interface/sched.h>
 #include <xen/interface/vcpu.h>
@@ -131,3 +132,11 @@ void __init xen_init_irq_ops()
 	pv_irq_ops = xen_irq_ops;
 	x86_init.irqs.intr_init = xen_init_IRQ;
 }
+
+#ifdef CONFIG_XEN_HVM_PV
+void __init xen_hvm_pv_init_irq_ops(void)
+{
+	if (xen_hvm_pv_evtchn_enabled())
+		x86_init.irqs.intr_init = xen_hvm_pv_evtchn_init_IRQ;
+}
+#endif
arch/x86/xen/smp.c +72 -4

127 lines not on this page · raw message

arch/x86/xen/xen-ops.h +16 -0
index d56b660..4de9874 100644
@@ -52,6 +52,12 @@ void xen_register_clocksource(void);
 unsigned long xen_get_wallclock(void);
 int xen_set_wallclock(unsigned long time);
 unsigned long long xen_sched_clock(void);
+void xen_set_basic_apic_ops(void);
+
+#ifdef CONFIG_XEN_HVM_PV
+void __init xen_hvm_pv_init_irq_ops(void);
+void __init xen_hvm_pv_evtchn_init_IRQ(void);
+#endif /* CONFIG_XEN_HVM_PV */
 
 irqreturn_t xen_debug_interrupt(int irq, void *dev_id);
 
@@ -62,9 +68,17 @@ void xen_setup_vcpu_info_placement(void);
 #ifdef CONFIG_SMP
 void xen_smp_init(void);
 
+#ifdef CONFIG_XEN_HVM_PV
+void xen_hvm_pv_smp_init(void);
+#endif /* CONFIG_XEN_HVM_PV */
+
 extern cpumask_var_t xen_cpu_initialized_map;
 #else
 static inline void xen_smp_init(void) {}
+#ifdef CONFIG_XEN_HVM_PV
+static inline void xen_hvm_pv_smp_init(void) {}
+#endif /* CONFIG_XEN_HVM_PV */
+
 #endif
 
 #ifdef CONFIG_PARAVIRT_SPINLOCKS
@@ -102,4 +116,6 @@ void xen_sysret32(void);
 void xen_sysret64(void);
 void xen_adjust_exception_frame(void);
 
+extern const struct machine_ops xen_machine_ops;
+
 #endif /* XEN_OPS_H */
drivers/xen/events.c +68 -6

112 lines not on this page · raw message

include/xen/events.h +4 -0
index e68d59a..b9fbb3b 100644
@@ -56,4 +56,8 @@ void xen_poll_irq(int irq);
 /* Determine the IRQ which is bound to an event channel */
 unsigned irq_from_evtchn(unsigned int evtchn);
 
+#ifdef CONFIG_XEN_HVM_PV
+void xen_hvm_evtchn_do_upcall(struct pt_regs *regs);
+#endif
+
 #endif	/* _XEN_EVENTS_H */
include/xen/hvm.h +5 -0
index 4ea8887..c66d788 100644
@@ -20,4 +20,9 @@ static inline unsigned long hvm_get_parameter(int idx)
 	return xhv.value;
 }
 
+#define HVM_CALLBACK_VIA_TYPE_VECTOR 0x2
+#define HVM_CALLBACK_VIA_TYPE_SHIFT 56
+#define HVM_CALLBACK_VECTOR(x) (((uint64_t)HVM_CALLBACK_VIA_TYPE_VECTOR)<<\
+				HVM_CALLBACK_VIA_TYPE_SHIFT | (x))
+
 #endif /* XEN_HVM_H__ */
include/xen/interface/xen.h +5 -1
index 2befa3e..70a6c6e 100644
@@ -90,7 +90,11 @@
 #define VIRQ_ARCH_6    22
 #define VIRQ_ARCH_7    23
 
-#define NR_VIRQS       24
+#define VIRQ_EMUL_PIN_START 24
+#define VIRQ_EMUL_PIN_NUM 16
+
+#define NR_VIRQS       (VIRQ_EMUL_PIN_START + VIRQ_EMUL_PIN_NUM)
+
 /*
  * MMU-UPDATE REQUESTS
  *
include/xen/xen.h +3 -0
index ce7417d..fa95714 100644
@@ -27,8 +27,11 @@ extern u32 xen_hvm_pv_features;
 
 #define xen_hvm_pv_clock_enabled() \
 		(xen_hvm_pv_features & XEN_HVM_PV_CLOCK_ENABLED)
+#define xen_hvm_pv_evtchn_enabled() \
+		(xen_hvm_pv_features & XEN_HVM_PV_EVTCHN_ENABLED)
 #else
 #define xen_hvm_pv_clock_enabled() 0
+#define xen_hvm_pv_evtchn_enabled() 0
 #endif /* CONFIG_XEN_HVM_PV */
 
 #ifdef CONFIG_XEN_DOM0
Signature · 1 line
1.7.0.1