From patchwork Thu Nov 21 18:50:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11256839 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 55340930 for ; Thu, 21 Nov 2019 18:52:05 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 30AF62067D for ; Thu, 21 Nov 2019 18:52:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IkngiqlT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 30AF62067D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iXrY5-0007Hc-Mr; Thu, 21 Nov 2019 18:51:25 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iXrY4-0007Gy-HE for xen-devel@lists.xenproject.org; Thu, 21 Nov 2019 18:51:24 +0000 X-Inumbo-ID: db58437e-0c8f-11ea-adbe-bc764e2007e4 Received: from mail-wr1-x442.google.com (unknown [2a00:1450:4864:20::442]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id db58437e-0c8f-11ea-adbe-bc764e2007e4; Thu, 21 Nov 2019 18:50:59 +0000 (UTC) Received: by mail-wr1-x442.google.com with SMTP id s5so5768410wrw.2 for ; Thu, 21 Nov 2019 10:50:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jmehIbWhQZXdoUxqvv2nAE9/O4n7ZGXTOOruyuVNHSs=; b=IkngiqlTkjNea7bGBPVnXACVbqM6xI4KEZgbGHD6t9H9M9yHG+zPD3jIN1fOEB1OgZ qRd3YBh4k0lSJvA+1t1IXQ19sxrAUgkxs9QU4ad4CipzpvCUpkd4/QjqIb3jtMHcrVkI Q2KlV3NvpdBVKtLnFwrTipM3FUpYQjtUixLFbspIcsLssNTfgXGgm3Ev5msgCgiGFvdF xrZiiTgsc1vrysTKaQfrXBu0VQ0nPO4zmH02W0a1XHgX/LUpDUzKDUTTbG+PDSNNsDc+ MTLTjoiKTTbJf1tKpuXjmf92usCZaAEMqFYnwYalBZJJcv4wq3rWz3sd8oYWfyPsmxjc +q7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=jmehIbWhQZXdoUxqvv2nAE9/O4n7ZGXTOOruyuVNHSs=; b=ESgvjMjaxbLflewmdLzKdjZdbFQSDn8T5wbBByq00lqpo67C2bWmRsGvz/QEiF/kxu DmiBgBvMhbHInl9W4RROHQfAQnXM3XdTEO53b/cU75kqo+kdUYv3FIR9uABgLVX4gZdk IU+6w1+3UNEGMsqYjJy5Lhdvv9Tt7uoUdrsx+fvOsXql3rN/ZjsKtCOn6TeyOi0AGNaF pV0liQVvxB1KofbuogtJ30JectwJUphzpRdPquIyfb2mSY7WJQHLAdE+7c4hCfixi9YC JMEfL+L/NyYJF4OwlQ2g/fUlHBmGM86zvcO3r651SALZ5uTkzPCLigsxzsNzfb+uISmW wlgQ== X-Gm-Message-State: APjAAAXZ8ex9l1D7pK21QnjvI+j9mhLkXCW/UpqE/Zb2ILF2qTfybkL9 QXCBIo0XWKMugpyJudZCq/JptQGa709uXw== X-Google-Smtp-Source: APXvYqy2zlru4pM8V+dttgjt7cGZa47POMDpLNWukAwn3g5e+CeRyvXcn5iZQ1t0HdIlg/zz8b+Law== X-Received: by 2002:adf:db51:: with SMTP id f17mr12500221wrj.85.1574362258219; Thu, 21 Nov 2019 10:50:58 -0800 (PST) Received: from debian.mshome.net (74.162.147.147.dyn.plus.net. [147.147.162.74]) by smtp.gmail.com with ESMTPSA id f24sm535776wmb.37.2019.11.21.10.50.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2019 10:50:57 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Thu, 21 Nov 2019 18:50:47 +0000 Message-Id: <20191121185049.16666-7-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191121185049.16666-1-liuwe@microsoft.com> References: <20191121185049.16666-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 6/8] x86: switch xen guest implementation to use hypervisor framework 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: Wei Liu , Wei Liu , Andrew Cooper , Michael Kelley , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Signed-off-by: Wei Liu Reviewed-by: Paul Durrant --- Changes in v4: 1. xen_probe returns address of ops directly. 2. Add __init to hypervisor_setup. 3. Drop Paul's review tag. --- xen/arch/x86/guest/hypervisor.c | 32 ++++++++++++++++++++- xen/arch/x86/guest/xen/pvh-boot.c | 2 +- xen/arch/x86/guest/xen/xen.c | 47 ++++++++++++++++++------------- xen/arch/x86/setup.c | 2 +- xen/include/asm-x86/guest/xen.h | 5 ++-- 5 files changed, 64 insertions(+), 24 deletions(-) diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c index 103feba5d8..a067cacecb 100644 --- a/xen/arch/x86/guest/hypervisor.c +++ b/xen/arch/x86/guest/hypervisor.c @@ -19,18 +19,48 @@ * Copyright (c) 2019 Microsoft. */ +#include #include #include -#include +#include static const struct hypervisor_ops __read_mostly *hops; const struct hypervisor_ops *hypervisor_probe(void) { + if ( hops ) + goto out; + + if ( !cpu_has_hypervisor ) + goto out; + + hops = xen_probe(); + if ( hops ) + goto out; + + out: return hops; } +void __init hypervisor_setup(void) +{ + if ( hops && hops->setup ) + hops->setup(); +} + +void hypervisor_ap_setup(void) +{ + if ( hops && hops->ap_setup ) + hops->ap_setup(); +} + +void hypervisor_resume(void) +{ + if ( hops && hops->resume ) + hops->resume(); +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/guest/xen/pvh-boot.c b/xen/arch/x86/guest/xen/pvh-boot.c index ca8e156f7d..498625eae0 100644 --- a/xen/arch/x86/guest/xen/pvh-boot.c +++ b/xen/arch/x86/guest/xen/pvh-boot.c @@ -103,7 +103,7 @@ void __init pvh_init(multiboot_info_t **mbi, module_t **mod) { convert_pvh_info(mbi, mod); - probe_hypervisor(); + hypervisor_probe(); ASSERT(xen_guest); get_memory_map(); diff --git a/xen/arch/x86/guest/xen/xen.c b/xen/arch/x86/guest/xen/xen.c index 0f5b5267c5..8cfe059887 100644 --- a/xen/arch/x86/guest/xen/xen.c +++ b/xen/arch/x86/guest/xen/xen.c @@ -67,22 +67,6 @@ static void __init find_xen_leaves(void) } } -void __init probe_hypervisor(void) -{ - if ( xen_guest || !cpu_has_hypervisor ) - return; - - find_xen_leaves(); - - if ( !xen_cpuid_base ) - return; - - /* Fill the hypercall page. */ - wrmsrl(cpuid_ebx(xen_cpuid_base + 2), __pa(hypercall_page)); - - xen_guest = true; -} - static void map_shared_info(void) { mfn_t mfn; @@ -245,7 +229,7 @@ static void init_evtchn(void) } } -void __init hypervisor_setup(void) +static void __init xen_setup(void) { init_memmap(); @@ -273,7 +257,7 @@ void __init hypervisor_setup(void) init_evtchn(); } -void hypervisor_ap_setup(void) +static void xen_ap_setup(void) { set_vcpu_id(); map_vcpuinfo(); @@ -303,7 +287,7 @@ static void ap_resume(void *unused) init_evtchn(); } -void hypervisor_resume(void) +static void xen_resume(void) { /* Reset shared info page. */ map_shared_info(); @@ -326,6 +310,31 @@ void hypervisor_resume(void) pv_console_init(); } +static const struct hypervisor_ops xg_ops = { + .name = "Xen", + .setup = xen_setup, + .ap_setup = xen_ap_setup, + .resume = xen_resume, +}; + +const struct hypervisor_ops * __init xen_probe(void) +{ + if ( xen_guest ) + return &xg_ops; + + find_xen_leaves(); + + if ( !xen_cpuid_base ) + return NULL; + + /* Fill the hypercall page. */ + wrmsrl(cpuid_ebx(xen_cpuid_base + 2), __pa(hypercall_page)); + + xen_guest = true; + + return &xg_ops; +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 00ee87bde5..19606d909b 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -763,7 +763,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) * allocing any xenheap structures wanted in lower memory. */ kexec_early_calculations(); - probe_hypervisor(); + hypervisor_probe(); parse_video_info(); diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xen.h index 01dc3ee6f6..db90b550a7 100644 --- a/xen/include/asm-x86/guest/xen.h +++ b/xen/include/asm-x86/guest/xen.h @@ -23,6 +23,7 @@ #include #include +#include #define XEN_shared_info ((struct shared_info *)fix_to_virt(FIX_XEN_SHARED_INFO)) @@ -32,7 +33,7 @@ extern bool xen_guest; extern bool pv_console; extern uint32_t xen_cpuid_base; -void probe_hypervisor(void); +const struct hypervisor_ops *xen_probe(void); int xg_alloc_unused_page(mfn_t *mfn); int xg_free_unused_page(mfn_t mfn); @@ -44,7 +45,7 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info); #define xen_guest 0 #define pv_console 0 -static inline void probe_hypervisor(void) {} +static inline const struct hypervisor_ops *xen_probe(void) { return NULL; } #endif /* CONFIG_XEN_GUEST */ #endif /* __X86_GUEST_XEN_H__ */