From nobody Tue Nov 11 05:26:22 2025 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 ARC-Seal: i=1; a=rsa-sha256; t=1574362313; cv=none; d=zoho.com; s=zohoarc; b=Fyqkc6scvE2Fui9bCC8A9k0l7uPGFEgE6pEKYOhYDO6WlkjwS0qtwi//IYdCgkBJVEgH/QRK/e0/KoyffzEsw3gj1LRzwXlA63CEvcZx8cTRIh9Bt2XVugvaffGUNsxnPqKYQ/vWa+HwIABUJ2ufUXKQyT4ZgYdIFDcEbPUprfs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574362313; 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; bh=RlE7UpY4l3gurKMbikK5OEAHeL8EA5lz6fx9KFeAf2A=; b=X3KBmHdFJg52O5NxnAOLLvNa1ePuMOtu/xRxL7R8H4PBhYWgIuqbfU0wRK3Fk1S+1RZLxzI80WRV4sXr+Zf1NZDoXRhGZ2lop41WW5s4BdPij1I1L6aLv784UV2ZkPIrvkFWuZTKVj+4Oq4hkR2fLvfKSxP+zuZNzD2Zs/tnrf0= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 157436231380714.631375478934388; Thu, 21 Nov 2019 10:51:53 -0800 (PST) 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 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) 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) X-Inumbo-ID: db58437e-0c8f-11ea-adbe-bc764e2007e4 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) 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=20Pau=20Monn=C3=A9?= 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) Signed-off-by: Wei Liu --- 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/hyperviso= r.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. */ =20 +#include #include =20 #include -#include +#include =20 static const struct hypervisor_ops __read_mostly *hops; =20 const struct hypervisor_ops *hypervisor_probe(void) { + if ( hops ) + goto out; + + if ( !cpu_has_hypervisor ) + goto out; + + hops =3D xen_probe(); + if ( hops ) + goto out; + + out: return hops; } =20 +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); =20 - probe_hypervisor(); + hypervisor_probe(); ASSERT(xen_guest); =20 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) } } =20 -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 =3D true; -} - static void map_shared_info(void) { mfn_t mfn; @@ -245,7 +229,7 @@ static void init_evtchn(void) } } =20 -void __init hypervisor_setup(void) +static void __init xen_setup(void) { init_memmap(); =20 @@ -273,7 +257,7 @@ void __init hypervisor_setup(void) init_evtchn(); } =20 -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(); } =20 -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(); } =20 +static const struct hypervisor_ops xg_ops =3D { + .name =3D "Xen", + .setup =3D xen_setup, + .ap_setup =3D xen_ap_setup, + .resume =3D 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 =3D 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(); =20 - probe_hypervisor(); + hypervisor_probe(); =20 parse_video_info(); =20 diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xe= n.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 @@ =20 #include #include +#include =20 #define XEN_shared_info ((struct shared_info *)fix_to_virt(FIX_XEN_SHARED_= INFO)) =20 @@ -32,7 +33,7 @@ extern bool xen_guest; extern bool pv_console; extern uint32_t xen_cpuid_base; =20 -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); =20 @@ -44,7 +45,7 @@ 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 const struct hypervisor_ops *xen_probe(void) { return NULL; } =20 #endif /* CONFIG_XEN_GUEST */ #endif /* __X86_GUEST_XEN_H__ */ --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel