From patchwork Thu Jun 20 00:30:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Clark X-Patchwork-Id: 11005597 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D39D924 for ; Thu, 20 Jun 2019 00:33:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4AFC4288BE for ; Thu, 20 Jun 2019 00:33:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E4A5288CB; Thu, 20 Jun 2019 00:33:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9F3C5288BE for ; Thu, 20 Jun 2019 00:33:05 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hdkz2-00008h-VD; Thu, 20 Jun 2019 00:31:20 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hdkz1-00007x-Eh for xen-devel@lists.xenproject.org; Thu, 20 Jun 2019 00:31:19 +0000 X-Inumbo-ID: b85a27a8-92f2-11e9-8980-bc764e045a96 Received: from mail-io1-xd42.google.com (unknown [2607:f8b0:4864:20::d42]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id b85a27a8-92f2-11e9-8980-bc764e045a96; Thu, 20 Jun 2019 00:31:18 +0000 (UTC) Received: by mail-io1-xd42.google.com with SMTP id r185so199926iod.6 for ; Wed, 19 Jun 2019 17:31:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AovapQVVTQQkmzcMTzk8JCvrp7vgRfayvjJZaS3T4LE=; b=ZPLGYcuewZuqVFVaFwv1q2+rhPU20zHVAw0jIF8slVGmOopj+4xFR6TkmvbtkYZeyH TJMk+tV+2uKt3s8q04oeJKwSiRDxHOK9IfNybZV6MvibV3bN8Ufe5d1pCEDmSOq4kgFl b0VzU7rlmA14Vbb9kNtWJiSm80L+n7aKDdRhOZdP24q6y1PfW1Dias4fr0NQt6IC9O8A ObUG8S2Flx9cMZ/zxOrHFwvjXe6N5+ab2anbEyh3B/bTRjX1La3NKo7YaEfca1dG0Exq 2D9RRrPLOJMqtoohHyMazQqjWq3gCYAsovUQrrk0l0I8xzBLLCcgD/hu8sbAKewOAfiy Z+xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AovapQVVTQQkmzcMTzk8JCvrp7vgRfayvjJZaS3T4LE=; b=PK5W6IDMP1IlBuMDD1EUrqu2VJsJaJKuZny65RkEHLpNyudl3boCD/3O4wxmF5a1Xh 2HyTMw0kw6lrbikcoWYlP9JU/iLS8z8oAxmC4P0OjHCCHKwphXAhbWFn0BcI1paS4woN kT0h2vHJ8KKB6QH77sg71G9bNda1+Z0iW5dr2/Sro1N+Li0dUtB6aacRrR1tHqz6EnVu pT56Y3S31IE2PxuP4BXOdTKWlejXfXm4aa9wc5ALZZO9vw4f8gV9sRCjfaozEGDrR30a kXtZmjO82GdxmaGaktMXMaN0AHdlgMdII+gMrEuZzoHul2oxBv+jQYEeY0FSvWfl0XqH Ae0A== X-Gm-Message-State: APjAAAWqEIjMMIC9j2T7W0+GEC3yYJk72rlyGFC+v1LZCzbuvlBgD/gf Ai0/QMT2HGz6pxtEB3N+ODO50Y3Sano= X-Google-Smtp-Source: APXvYqzGlSpiZIQtMj7yCzrhX6rFhS+7cPOwQc8eNg9DoeEKbdcODYvPG11Tkvqw/xWtOkR5gjU0JQ== X-Received: by 2002:a6b:4f14:: with SMTP id d20mr3528730iob.219.1560990677736; Wed, 19 Jun 2019 17:31:17 -0700 (PDT) Received: from desktop.ice.pyrology.org (static-50-53-74-115.bvtn.or.frontiernet.net. [50.53.74.115]) by smtp.gmail.com with ESMTPSA id e188sm22579016ioa.3.2019.06.19.17.31.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Jun 2019 17:31:16 -0700 (PDT) From: Christopher Clark To: xen-devel@lists.xenproject.org Date: Wed, 19 Jun 2019 17:30:46 -0700 Message-Id: <20190620003053.21993-3-christopher.w.clark@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190620003053.21993-1-christopher.w.clark@gmail.com> References: <20190620003053.21993-1-christopher.w.clark@gmail.com> Subject: [Xen-devel] [RFC 2/9] x86: Introduce Xen detection as separate logic from Xen Guest support. X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Wei Liu , Andrew Cooper , Rich Persaud , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 #include +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 #include +/* 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 #include -#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__ */