From nobody Sun Feb 8 12:38:57 2026 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1560990747; cv=none; d=zoho.com; s=zohoarc; b=Sh6YCHM8mcNXxCw4aBr/c71H5LkN2QyAthyOFujxogW7SyZoKjQEVFNA9/PcFZ+EUmQutuLw6GDD+t4MD+QHA3QNbQByRjSNae8cI9Bfnu4sqCpx6pmc/Jq9n+p8SkEEiOVk3n9sCy+24B9Ke9+1dnTI/ccKQ76bm7WiXQk+3bQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560990747; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=E2+muMKjTZn+LDpLdK8IzDnF2VMvnfbwAf4utHkCBYA=; b=Y3Wu/jarKYakusXEojcSLGDckyRT+x6fNgj9j9DhLhLhgWjpmKjXvYy/Q/nptJDyn0Jn/Ez7v4woJq0VFgLLJ7lImKk+b8cHiDpHO99dmhB4lqK8Vmo6YiHm2jgvPnW1Eeuv09qijHtVGmpJB26D4AZ2LuwQJGtj2IQwUbKRKAo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1560990747152650.8413038092044; Wed, 19 Jun 2019 17:32:27 -0700 (PDT) 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 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) 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) X-Inumbo-ID: b85a27a8-92f2-11e9-8980-bc764e045a96 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) 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=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 =20 endchoice =20 +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. =20 If unsure, say N. =20 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 +=3D acpi subdir-y +=3D cpu subdir-y +=3D genapic -subdir-$(CONFIG_XEN_GUEST) +=3D guest +subdir-$(CONFIG_XEN_DETECT) +=3D guest subdir-$(CONFIG_HVM) +=3D hvm subdir-y +=3D mm subdir-$(CONFIG_XENOPROF) +=3D 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); =20 - 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 =3D 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 +=3D hypercall_page.o +obj-$(CONFIG_XEN_GUEST) +=3D hypercall_page.o obj-y +=3D xen.o obj-$(CONFIG_XEN_GUEST) +=3D xen-guest.o =20 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 =20 +extern char hypercall_page[]; + bool __read_mostly xen_guest; =20 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); =20 +void xen_guest_enable(void) +{ + /* Fill the hypercall page. */ + wrmsrl(cpuid_ebx(hypervisor_cpuid_base() + 2), __pa(hypercall_page)); + + xen_guest =3D 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 =20 +/* xen_detected: Xen running on Xen detected */ +bool __read_mostly xen_detected; + static __read_mostly uint32_t xen_cpuid_base; -extern char hypercall_page[]; =20 static void __init find_xen_leaves(void) { @@ -58,7 +60,7 @@ static void __init find_xen_leaves(void) =20 void __init probe_hypervisor(void) { - if ( xen_guest ) + if ( xen_detected ) return; =20 /* Too early to use cpu_has_hypervisor */ @@ -70,10 +72,21 @@ void __init probe_hypervisor(void) if ( !xen_cpuid_base ) return; =20 - /* Fill the hypercall page. */ - wrmsrl(cpuid_ebx(xen_cpuid_base + 2), __pa(hypercall_page)); + xen_detected =3D 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); =20 - xen_guest =3D true; + major =3D eax >> 16; + minor =3D eax & 0xffff; + printk("Nested Xen version %u.%u.\n", major, minor); } =20 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(); =20 + if ( xen_detected ) + hypervisor_print_info(); + if ( pvh_boot ) pvh_print_info(); =20 diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xe= n.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 =20 -#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 */ =20 #ifdef CONFIG_XEN_GUEST +#define XEN_shared_info ((struct shared_info *)fix_to_virt(FIX_XEN_SHARED_= INFO)) =20 extern bool xen_guest; extern bool pv_console; =20 -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); =20 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 =20 -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) {} =20 #endif /* CONFIG_XEN_GUEST */ #endif /* __X86_GUEST_XEN_H__ */ --=20 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel