From patchwork Mon Oct 21 15:57:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11202583 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 7995013BD for ; Mon, 21 Oct 2019 15:59:08 +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 556752084B for ; Mon, 21 Oct 2019 15:59:08 +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="RpYQA9UT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 556752084B 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 1iMa4G-0008M6-Rw; Mon, 21 Oct 2019 15:58:00 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iMa4E-0008Kx-Sc for xen-devel@lists.xenproject.org; Mon, 21 Oct 2019 15:57:58 +0000 X-Inumbo-ID: 7b970542-f41b-11e9-bbab-bc764e2007e4 Received: from mail-wm1-x341.google.com (unknown [2a00:1450:4864:20::341]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7b970542-f41b-11e9-bbab-bc764e2007e4; Mon, 21 Oct 2019 15:57:29 +0000 (UTC) Received: by mail-wm1-x341.google.com with SMTP id f22so13350541wmc.2 for ; Mon, 21 Oct 2019 08:57:29 -0700 (PDT) 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=uz0cS8L1R521fTEVFm/na4uChFFZ0A6x5sP6HVSJ75Y=; b=RpYQA9UTZA3W/Fwz6T+Ti1SufM8dwZLv3CQz4+1q0tT0Je3aWk4yrmQyAKYOqw5rpz e1cbfcVBK4BP7ADh/HbgIRaF16e15L6o4tM1z11xF2Lhx0Pif73lZA1KbLRSanOifRSG T8PJSn4erosWoMqoQCXtt6ph1fxCvm8WXr3bQk01cXquEtuwu0v3VIvb7J249RiPxAw0 H/6/jPE/hgrdHBJLPGOGr9l9We5HdrKYbdyntQuRsUtka42gvlAMfTuEPB5/NR4D8Cjc wl8uUGCJK1gpgOoY2vxYkS1tNOtxyKsLlF/gmofBjPH2U8Rb7CGDURCdKkZ9/ziIeCRh OS1Q== 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=uz0cS8L1R521fTEVFm/na4uChFFZ0A6x5sP6HVSJ75Y=; b=atxhQHj84L4nrLKLhvovjqovyaUV6Xhc+lqoEXIJzutcgaqs4M4vciYCpdVvdSKhD3 O2DCpyGCjGOf6P32Lf6CWIKM7+JTF9GyCMPEesTBfS0yUZi+CE09Ml4GQq+GNReIEwx2 55gFjBxEyqDHL3McclubNk83EeN5F8ww+OE9E6Ydp9rZHaVgQ2P19n07pxYBI270j54t uv0AweW2oHF/l5VCWvvsN3biMrjckvsn7ZX/EcjNA8mBPeO8vXgwPVl8zvpyND8bwHSs S2k/JCIho/7xz8n2xa/9znv0nzzm41kBq1YsT7za+9pn18aFIJy5q8AuTRLkKk7zcPY+ JOLA== X-Gm-Message-State: APjAAAWSFhEU2wGmiyJZZqje10sfJm5WSgPj5r4nffitv5ifIbFP9NjU JdEtwRcIprNKFacBtCCEpx6GVGBO+FU= X-Google-Smtp-Source: APXvYqxl/DJi3lmFlYPpP/hatAwpG7yl3D+pn563UVteuV6a/m3MEG3ZuxYSWnxyh0y0HFEqN4Kjiw== X-Received: by 2002:a1c:a78b:: with SMTP id q133mr7388392wme.115.1571673448058; Mon, 21 Oct 2019 08:57:28 -0700 (PDT) Received: from debian.mshome.net (54.163.200.146.dyn.plus.net. [146.200.163.54]) by smtp.gmail.com with ESMTPSA id x12sm5667410wru.93.2019.10.21.08.57.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 08:57:27 -0700 (PDT) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Mon, 21 Oct 2019 16:57:16 +0100 Message-Id: <20191021155718.28653-8-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191021155718.28653-1-liuwe@microsoft.com> References: <20191021155718.28653-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH for-next v3 7/9] x86: switch xen 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" Take the chance to change probe_hypervisor to hypervisor_probe. Signed-off-by: Wei Liu Reviewed-by: Paul Durrant Acked-by: Jan Beulich --- V3: 1. Address Roger's comments 2. Change xen_hypervisor_ops to xen_ops --- xen/arch/x86/guest/hypervisor.c | 32 ++++++++++++++++++++++++++++++- xen/arch/x86/guest/xen/pvh-boot.c | 2 +- xen/arch/x86/guest/xen/xen.c | 26 +++++++++++++------------ xen/arch/x86/setup.c | 2 +- xen/include/asm-x86/guest/xen.h | 6 ++++-- 5 files changed, 51 insertions(+), 17 deletions(-) diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c index 89b9ae4de0..33bf1a769d 100644 --- a/xen/arch/x86/guest/hypervisor.c +++ b/xen/arch/x86/guest/hypervisor.c @@ -22,7 +22,7 @@ #include #include -#include +#include static struct hypervisor_ops *hops __read_mostly; @@ -31,9 +31,39 @@ bool hypervisor_probe(void) if ( hops ) return true; + /* Too early to use cpu_has_hypervisor */ + if ( !(cpuid_ecx(1) & cpufeat_mask(X86_FEATURE_HYPERVISOR)) ) + return false; + +#ifdef CONFIG_XEN_GUEST + if ( xen_probe() ) + { + hops = &xen_ops; + return true; + } +#endif + return false; } +void 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 9895025d02..655435c1f7 100644 --- a/xen/arch/x86/guest/xen/xen.c +++ b/xen/arch/x86/guest/xen/xen.c @@ -67,24 +67,19 @@ static void __init find_xen_leaves(void) } } -void __init probe_hypervisor(void) +bool __init xen_probe(void) { - if ( xen_guest ) - return; - - /* Too early to use cpu_has_hypervisor */ - if ( !(cpuid_ecx(1) & cpufeat_mask(X86_FEATURE_HYPERVISOR)) ) - return; - find_xen_leaves(); if ( !xen_cpuid_base ) - return; + return false; /* Fill the hypercall page. */ wrmsrl(cpuid_ebx(xen_cpuid_base + 2), __pa(hypercall_page)); xen_guest = true; + + return true; } static void map_shared_info(void) @@ -249,7 +244,7 @@ static void init_evtchn(void) } } -void __init hypervisor_setup(void) +static void __init xen_setup(void) { init_memmap(); @@ -277,7 +272,7 @@ void __init hypervisor_setup(void) init_evtchn(); } -void hypervisor_ap_setup(void) +static void xen_ap_setup(void) { set_vcpu_id(); map_vcpuinfo(); @@ -307,7 +302,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(); @@ -330,6 +325,13 @@ void hypervisor_resume(void) pv_console_init(); } +struct hypervisor_ops xen_ops = { + .name = "Xen", + .setup = xen_setup, + .ap_setup = xen_ap_setup, + .resume = xen_resume, +}; + /* * Local variables: * mode: C diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index dec60d0301..0ee11b15a6 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 8221fc1325..c3c6bea24f 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)) @@ -31,8 +32,9 @@ extern bool xen_guest; extern bool pv_console; extern uint32_t xen_cpuid_base; +extern struct hypervisor_ops xen_ops; -void probe_hypervisor(void); +bool xen_probe(void); int xen_alloc_unused_page(mfn_t *mfn); int xen_free_unused_page(mfn_t mfn); @@ -44,7 +46,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 bool xen_probe(void) { return false; } #endif /* CONFIG_XEN_GUEST */ #endif /* __X86_GUEST_XEN_H__ */