From: Christopher Clark <christopher.w.clark@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: "Juergen Gross" <jgross@suse.com>, "Wei Liu" <wl@xen.org>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Rich Persaud" <persaur@gmail.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [Xen-devel] [RFC 2/9] x86: Introduce Xen detection as separate logic from Xen Guest support.
Date: Wed, 19 Jun 2019 17:30:46 -0700 [thread overview]
Message-ID: <20190620003053.21993-3-christopher.w.clark@gmail.com> (raw)
In-Reply-To: <20190620003053.21993-1-christopher.w.clark@gmail.com>
Add Kconfig option XEN_DETECT for:
"Support for Xen detecting when it is running under Xen".
If running under Xen is detected, a boot message will indicate the
hypervisor version obtained from cpuid.
Update the XEN_GUEST Kconfig option text to reflect its current
purpose:
"Common PVH_GUEST and PV_SHIM logic for Xen as a Xen-aware guest".
Update calibrate_APIC_clock to use Xen-specific init if nested Xen is
detected, even if not operating as a PV shim or booted as PVH.
This work is a precursor to adding the interface for support of
PV drivers on nested Xen.
Signed-off-by: Christopher Clark <christopher.clark@starlab.io>
---
xen/arch/x86/Kconfig | 11 ++++++++++-
xen/arch/x86/Makefile | 2 +-
xen/arch/x86/apic.c | 4 ++--
xen/arch/x86/guest/Makefile | 2 +-
xen/arch/x86/guest/xen-guest.c | 10 ++++++++++
xen/arch/x86/guest/xen.c | 23 ++++++++++++++++++-----
xen/arch/x86/setup.c | 3 +++
xen/include/asm-x86/guest/xen.h | 26 +++++++++++++++++++++-----
8 files changed, 66 insertions(+), 15 deletions(-)
diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig
index f502d765ba..31e5ffd2f2 100644
--- a/xen/arch/x86/Kconfig
+++ b/xen/arch/x86/Kconfig
@@ -161,11 +161,20 @@ config XEN_ALIGN_2M
endchoice
+config XEN_DETECT
+ def_bool y
+ prompt "Xen Detection"
+ ---help---
+ Support for Xen detecting when it is running under Xen.
+
+ If unsure, say Y.
+
config XEN_GUEST
def_bool n
prompt "Xen Guest"
+ depends on XEN_DETECT
---help---
- Support for Xen detecting when it is running under Xen.
+ Common PVH_GUEST and PV_SHIM logic for Xen as a Xen-aware guest.
If unsure, say N.
diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 8a8d8f060f..763077b0a3 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -1,7 +1,7 @@
subdir-y += acpi
subdir-y += cpu
subdir-y += genapic
-subdir-$(CONFIG_XEN_GUEST) += guest
+subdir-$(CONFIG_XEN_DETECT) += guest
subdir-$(CONFIG_HVM) += hvm
subdir-y += mm
subdir-$(CONFIG_XENOPROF) += oprofile
diff --git a/xen/arch/x86/apic.c b/xen/arch/x86/apic.c
index 9c3c998d34..5949a95d58 100644
--- a/xen/arch/x86/apic.c
+++ b/xen/arch/x86/apic.c
@@ -1247,7 +1247,7 @@ static int __init calibrate_APIC_clock(void)
*/
__setup_APIC_LVTT(1000000000);
- if ( !xen_guest )
+ if ( !xen_detected )
/*
* The timer chip counts down to zero. Let's wait
* for a wraparound to start exact measurement:
@@ -1267,7 +1267,7 @@ static int __init calibrate_APIC_clock(void)
* Let's wait LOOPS ticks:
*/
for (i = 0; i < LOOPS; i++)
- if ( !xen_guest )
+ if ( !xen_detected )
wait_8254_wraparound();
else
wait_tick_pvh();
diff --git a/xen/arch/x86/guest/Makefile b/xen/arch/x86/guest/Makefile
index 6ddaa3748f..d3a7844e61 100644
--- a/xen/arch/x86/guest/Makefile
+++ b/xen/arch/x86/guest/Makefile
@@ -1,4 +1,4 @@
-obj-y += hypercall_page.o
+obj-$(CONFIG_XEN_GUEST) += hypercall_page.o
obj-y += xen.o
obj-$(CONFIG_XEN_GUEST) += xen-guest.o
diff --git a/xen/arch/x86/guest/xen-guest.c b/xen/arch/x86/guest/xen-guest.c
index 65596ab1b1..b6d89e02a3 100644
--- a/xen/arch/x86/guest/xen-guest.c
+++ b/xen/arch/x86/guest/xen-guest.c
@@ -35,6 +35,8 @@
#include <public/arch-x86/cpuid.h>
#include <public/hvm/params.h>
+extern char hypercall_page[];
+
bool __read_mostly xen_guest;
static struct rangeset *mem;
@@ -45,6 +47,14 @@ static struct vcpu_info *vcpu_info;
static unsigned long vcpu_info_mapped[BITS_TO_LONGS(NR_CPUS)];
DEFINE_PER_CPU(struct vcpu_info *, vcpu_info);
+void xen_guest_enable(void)
+{
+ /* Fill the hypercall page. */
+ wrmsrl(cpuid_ebx(hypervisor_cpuid_base() + 2), __pa(hypercall_page));
+
+ xen_guest = true;
+}
+
static void map_shared_info(void)
{
mfn_t mfn;
diff --git a/xen/arch/x86/guest/xen.c b/xen/arch/x86/guest/xen.c
index 90d464bdbd..b0b603a11a 100644
--- a/xen/arch/x86/guest/xen.c
+++ b/xen/arch/x86/guest/xen.c
@@ -33,8 +33,10 @@
#include <public/arch-x86/cpuid.h>
#include <public/hvm/params.h>
+/* xen_detected: Xen running on Xen detected */
+bool __read_mostly xen_detected;
+
static __read_mostly uint32_t xen_cpuid_base;
-extern char hypercall_page[];
static void __init find_xen_leaves(void)
{
@@ -58,7 +60,7 @@ static void __init find_xen_leaves(void)
void __init probe_hypervisor(void)
{
- if ( xen_guest )
+ if ( xen_detected )
return;
/* Too early to use cpu_has_hypervisor */
@@ -70,10 +72,21 @@ void __init probe_hypervisor(void)
if ( !xen_cpuid_base )
return;
- /* Fill the hypercall page. */
- wrmsrl(cpuid_ebx(xen_cpuid_base + 2), __pa(hypercall_page));
+ xen_detected = true;
+
+ xen_guest_enable();
+}
+
+void __init hypervisor_print_info(void)
+{
+ uint32_t eax, ebx, ecx, edx;
+ unsigned int major, minor;
+
+ cpuid(xen_cpuid_base + 1, &eax, &ebx, &ecx, &edx);
- xen_guest = true;
+ major = eax >> 16;
+ minor = eax & 0xffff;
+ printk("Nested Xen version %u.%u.\n", major, minor);
}
uint32_t hypervisor_cpuid_base(void)
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index d2011910fa..58f499edaf 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -774,6 +774,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)
ehci_dbgp_init();
console_init_preirq();
+ if ( xen_detected )
+ hypervisor_print_info();
+
if ( pvh_boot )
pvh_print_info();
diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xen.h
index 7e04e4a7ab..27c854ab8a 100644
--- a/xen/include/asm-x86/guest/xen.h
+++ b/xen/include/asm-x86/guest/xen.h
@@ -24,20 +24,37 @@
#include <asm/e820.h>
#include <asm/fixmap.h>
-#define XEN_shared_info ((struct shared_info *)fix_to_virt(FIX_XEN_SHARED_INFO))
+#ifdef CONFIG_XEN_DETECT
+
+extern bool xen_detected;
+
+void probe_hypervisor(void);
+void hypervisor_print_info(void);
+uint32_t hypervisor_cpuid_base(void);
+
+#else
+
+#define xen_detected 0
+
+static inline void probe_hypervisor(void) {}
+static inline void hypervisor_print_info(void) {
+ ASSERT_UNREACHABLE();
+}
+
+#endif /* CONFIG_XEN_DETECT */
#ifdef CONFIG_XEN_GUEST
+#define XEN_shared_info ((struct shared_info *)fix_to_virt(FIX_XEN_SHARED_INFO))
extern bool xen_guest;
extern bool pv_console;
-void probe_hypervisor(void);
void hypervisor_setup(void);
void hypervisor_ap_setup(void);
int hypervisor_alloc_unused_page(mfn_t *mfn);
int hypervisor_free_unused_page(mfn_t mfn);
-uint32_t hypervisor_cpuid_base(void);
void hypervisor_resume(void);
+void xen_guest_enable(void);
DECLARE_PER_CPU(unsigned int, vcpu_id);
DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
@@ -47,8 +64,6 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
#define xen_guest 0
#define pv_console 0
-static inline void probe_hypervisor(void) {}
-
static inline void hypervisor_setup(void)
{
ASSERT_UNREACHABLE();
@@ -57,6 +72,7 @@ static inline void hypervisor_ap_setup(void)
{
ASSERT_UNREACHABLE();
}
+static inline void xen_guest_enable(void) {}
#endif /* CONFIG_XEN_GUEST */
#endif /* __X86_GUEST_XEN_H__ */
--
2.17.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2019-06-20 0:31 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-20 0:30 [Xen-devel] [RFC 0/9] The Xen Blanket: hypervisor interface for PV drivers on nested Xen Christopher Clark
2019-06-20 0:30 ` [Xen-devel] [RFC 1/9] x86/guest: code movement to separate Xen detection from guest functions Christopher Clark
2019-06-20 0:30 ` Christopher Clark [this message]
2019-06-20 0:30 ` [Xen-devel] [RFC 3/9] x86/nested: add nested_xen_version hypercall Christopher Clark
2019-06-20 0:30 ` [Xen-devel] [RFC 4/9] XSM: Add hook for nested xen version op; revises non-nested version op Christopher Clark
2019-06-20 0:30 ` [Xen-devel] [RFC 5/9] x86/nested, xsm: add nested_memory_op hypercall Christopher Clark
2019-06-20 0:30 ` [Xen-devel] [RFC 6/9] x86/nested, xsm: add nested_hvm_op hypercall Christopher Clark
2019-06-20 0:30 ` [Xen-devel] [RFC 7/9] x86/nested, xsm: add nested_grant_table_op hypercall Christopher Clark
2019-06-20 0:30 ` [Xen-devel] [RFC 8/9] x86/nested, xsm: add nested_event_channel_op hypercall Christopher Clark
2019-06-20 0:30 ` [Xen-devel] [RFC 9/9] x86/nested, xsm: add nested_schedop_shutdown hypercall Christopher Clark
2019-06-20 4:18 ` [Xen-devel] [RFC 0/9] The Xen Blanket: hypervisor interface for PV drivers on nested Xen Juergen Gross
2019-06-20 8:39 ` Paul Durrant
2019-06-21 5:51 ` Christopher Clark
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190620003053.21993-3-christopher.w.clark@gmail.com \
--to=christopher.w.clark@gmail.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=jgross@suse.com \
--cc=persaur@gmail.com \
--cc=roger.pau@citrix.com \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.