From nobody Tue Nov 11 08:48:48 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=1569233466; cv=none; d=zoho.com; s=zohoarc; b=DbFmcvnPCmsGfj5GU8RpWAxSAs5xAMter9RAzM1lt5llGsz5cXRYDoTqt06a+FRhWwkVlDK8Flhj3fnqrX+ptDL7IqLF5ki7z/sNyQnwv6AUaam5FNTOxHA3KFJMz5wfRJsMlJjaQ6w6n+jAmA3ycsAz/reZBR8b7AerKE+zVmA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569233466; 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=dXt0mlbnE+iAdyAajk7HDmpiVcAp7G0SFwwDGQZ+FXM=; b=byQ8+lmfslXUeeOTKTSBw18E33YsCK0Zk93w+6USVLfnK497jp1pJEKrR9S3IjnWwM247a/sp59hh4aHfVPZ2RkReYnl7EukdQZ5KvvplshijAjW5sjl+fbT7ZhbDz4SN2UVtcpPpKtE4+V+II9qlOnQPMLAupvwIj1ZC7HrvLI= 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 1569233466303977.4077797672285; Mon, 23 Sep 2019 03:11:06 -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 1iCLIC-000791-SC; Mon, 23 Sep 2019 10:10:04 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iCLIB-00071D-9F for xen-devel@lists.xenproject.org; Mon, 23 Sep 2019 10:10:03 +0000 Received: from mail-wm1-x341.google.com (unknown [2a00:1450:4864:20::341]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 42083da6-ddea-11e9-b76c-bc764e2007e4; Mon, 23 Sep 2019 10:09:41 +0000 (UTC) Received: by mail-wm1-x341.google.com with SMTP id a6so9172509wma.5 for ; Mon, 23 Sep 2019 03:09:41 -0700 (PDT) Received: from debian.mshome.net (207.148.159.143.dyn.plus.net. [143.159.148.207]) by smtp.gmail.com with ESMTPSA id s10sm18241662wmf.48.2019.09.23.03.09.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2019 03:09:40 -0700 (PDT) X-Inumbo-ID: 42083da6-ddea-11e9-b76c-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=faSPq0/FgKeXO1cnxCD0/aZRNuNgVtyb3U2iGwfHW2c=; b=Ix3DCsHFPzP3J3dL6O2hVzBd3LE9Un/nuiFBQcrq1KWyUftPQGzwsbLXnXk/5RAdbp rdEhtMpSeSdluGv1LAnaOzhr7lVx4ipZuODr5bXFRQtXWbfeM7SQBYGMGaN3JOK+AEIE iXD9VlYk0AfyBSGnjo/hUavTwnxilY5NsODhfTA2Dc7H7kJOxXVp0WSczR5p1s6xS4IN RuaV2/Mh44LqeSWJGyStcUtjq392q5QaSCnuvCqfsizgyMP6eoibIEya9lMa/b/w4ezf 3aTPETLb9tcIVqH1TnbP1tRgLcc1l1u5pwPZ9VOvAEr7geJr4uP9fRVcHFSjp9Z7vszq VWaw== 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=faSPq0/FgKeXO1cnxCD0/aZRNuNgVtyb3U2iGwfHW2c=; b=QJnitIT5TtuhCcFrJvzDxVc+F5VdO2ezLw1BfOlrYYckfrU32sa819IYFbtUEdGfrh D4sptlAtMXbFg2EXjTHVpHJiF66UWM3qH9mV5x083XMzRx062nrfPhwNe/6X66tFVMUP EjpE1cXgGoFp7qJn4/R8F1DxcnAHMEnXDG1LkMLu9kZg6v2c7lJnKWTiDFvSecplVGQh HOtiGqF3mX/4Nhmu/WyV4ov+QO+dzR/uUfuWEgdB24Ly1QrJpDzwpBDY/f3W0faHq4vL fiAWQxkIe6ac6SM8/+ZmHk8qlyMBXwUvLioYxD+uzcb5nRdDenKOQQDa/pvbYOiezaIM f8Nw== X-Gm-Message-State: APjAAAVgV0Roa8P7Wpf7IsCg530GI0P++pNEtJ7kv8XzoDblMD4mlSix f+jZNGIBcXmtmS5unSuEZDz6Gl87 X-Google-Smtp-Source: APXvYqwjh0Q6C3SRY+SzsVrgkwn4+OS9/PS6Ifq2LiKwvhdg3lABmd4ip5XFWOoA1xChqGi44NWjWg== X-Received: by 2002:a7b:cd83:: with SMTP id y3mr13582130wmj.165.1569233380548; Mon, 23 Sep 2019 03:09:40 -0700 (PDT) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Mon, 23 Sep 2019 11:09:28 +0100 Message-Id: <20190923100931.29670-6-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190923100931.29670-1-liuwe@microsoft.com> References: <20190923100931.29670-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH for-next RFC 5/8] x86: factor out hypervisor agnostic code 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) The only implementation there is Xen. No functional change. Signed-off-by: Wei Liu --- xen/arch/x86/guest/Makefile | 2 + xen/arch/x86/guest/hypervisor.c | 112 +++++++++++++++++++++++++ xen/arch/x86/guest/xen/xen.c | 81 +----------------- xen/include/asm-x86/guest.h | 1 + xen/include/asm-x86/guest/hypervisor.h | 58 +++++++++++++ xen/include/asm-x86/guest/xen.h | 21 ++--- 6 files changed, 182 insertions(+), 93 deletions(-) create mode 100644 xen/arch/x86/guest/hypervisor.c create mode 100644 xen/include/asm-x86/guest/hypervisor.h diff --git a/xen/arch/x86/guest/Makefile b/xen/arch/x86/guest/Makefile index 6806f04947..f63d64bbee 100644 --- a/xen/arch/x86/guest/Makefile +++ b/xen/arch/x86/guest/Makefile @@ -1 +1,3 @@ +obj-y +=3D hypervisor.o + subdir-$(CONFIG_XEN_GUEST) +=3D xen diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hyperviso= r.c new file mode 100644 index 0000000000..b0a724bf13 --- /dev/null +++ b/xen/arch/x86/guest/hypervisor.c @@ -0,0 +1,112 @@ +/*************************************************************************= ***** + * arch/x86/guest/hypervisor.c + * + * Support for detecting and running under a hypervisor. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; If not, see . + * + * Copyright (c) 2017 Citrix Systems Ltd. + */ + +#include +#include +#include + +#include +#include + +static struct rangeset *mem; + +void __init probe_hypervisor(void) +{ + /* Too early to use cpu_has_hypervisor */ + if ( !(cpuid_ecx(1) & cpufeat_mask(X86_FEATURE_HYPERVISOR)) ) + return; + + probe_xen(); +} + +static void __init init_memmap(void) +{ + unsigned int i; + + mem =3D rangeset_new(NULL, "host memory map", 0); + if ( !mem ) + panic("failed to allocate PFN usage rangeset\n"); + + /* + * Mark up to the last memory page (or 4GiB) as RAM. This is done beca= use + * Xen doesn't know the position of possible MMIO holes, so at least t= ry to + * avoid the know MMIO hole below 4GiB. Note that this is subject to f= uture + * discussion and improvements. + */ + if ( rangeset_add_range(mem, 0, max_t(unsigned long, max_page - 1, + PFN_DOWN(GB(4) - 1))) ) + panic("unable to add RAM to in-use PFN rangeset\n"); + + for ( i =3D 0; i < e820.nr_map; i++ ) + { + struct e820entry *e =3D &e820.map[i]; + + if ( rangeset_add_range(mem, PFN_DOWN(e->addr), + PFN_UP(e->addr + e->size - 1)) ) + panic("unable to add range [%#lx, %#lx] to in-use PFN rangeset= \n", + PFN_DOWN(e->addr), PFN_UP(e->addr + e->size - 1)); + } +} + +void __init hypervisor_setup(void) +{ + init_memmap(); + + xen_setup(); +} + +void hypervisor_ap_setup(void) +{ + xen_ap_setup(); +} + +int hypervisor_alloc_unused_page(mfn_t *mfn) +{ + unsigned long m; + int rc; + + rc =3D rangeset_claim_range(mem, 1, &m); + if ( !rc ) + *mfn =3D _mfn(m); + + return rc; +} + +int hypervisor_free_unused_page(mfn_t mfn) +{ + return rangeset_remove_range(mem, mfn_x(mfn), mfn_x(mfn)); +} + +void hypervisor_resume(void) +{ + xen_resume(); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ + diff --git a/xen/arch/x86/guest/xen/xen.c b/xen/arch/x86/guest/xen/xen.c index f93c8fbd1c..a730e6ad1b 100644 --- a/xen/arch/x86/guest/xen/xen.c +++ b/xen/arch/x86/guest/xen/xen.c @@ -39,7 +39,6 @@ bool __read_mostly xen_guest; =20 __read_mostly uint32_t xen_cpuid_base; extern char hypercall_page[]; -static struct rangeset *mem; =20 DEFINE_PER_CPU(unsigned int, vcpu_id); =20 @@ -67,15 +66,11 @@ static void __init find_xen_leaves(void) } } =20 -static void __init probe_xen(void) +void __init probe_xen(void) { if ( xen_guest ) return; =20 - /* Too early to use cpu_has_hypervisor */ - if ( !(cpuid_ecx(1) & cpufeat_mask(X86_FEATURE_HYPERVISOR)) ) - return; - find_xen_leaves(); =20 if ( !xen_cpuid_base ) @@ -87,11 +82,6 @@ static void __init probe_xen(void) xen_guest =3D true; } =20 -void __init probe_hypervisor(void) -{ - probe_xen(); -} - static void map_shared_info(void) { mfn_t mfn; @@ -166,35 +156,6 @@ static void set_vcpu_id(void) this_cpu(vcpu_id) =3D smp_processor_id(); } =20 -static void __init init_memmap(void) -{ - unsigned int i; - - mem =3D rangeset_new(NULL, "host memory map", 0); - if ( !mem ) - panic("failed to allocate PFN usage rangeset\n"); - - /* - * Mark up to the last memory page (or 4GiB) as RAM. This is done beca= use - * Xen doesn't know the position of possible MMIO holes, so at least t= ry to - * avoid the know MMIO hole below 4GiB. Note that this is subject to f= uture - * discussion and improvements. - */ - if ( rangeset_add_range(mem, 0, max_t(unsigned long, max_page - 1, - PFN_DOWN(GB(4) - 1))) ) - panic("unable to add RAM to in-use PFN rangeset\n"); - - for ( i =3D 0; i < e820.nr_map; i++ ) - { - struct e820entry *e =3D &e820.map[i]; - - if ( rangeset_add_range(mem, PFN_DOWN(e->addr), - PFN_UP(e->addr + e->size - 1)) ) - panic("unable to add range [%#lx, %#lx] to in-use PFN rangeset= \n", - PFN_DOWN(e->addr), PFN_UP(e->addr + e->size - 1)); - } -} - static void xen_evtchn_upcall(struct cpu_user_regs *regs) { struct vcpu_info *vcpu_info =3D this_cpu(vcpu_info); @@ -254,7 +215,7 @@ static void init_evtchn(void) } } =20 -static void __init xen_setup(void) +void __init xen_setup(void) { map_shared_info(); =20 @@ -280,49 +241,20 @@ static void __init xen_setup(void) init_evtchn(); } =20 -void __init hypervisor_setup(void) -{ - init_memmap(); - - xen_setup(); -} - -static void xen_ap_setup(void) +void xen_ap_setup(void) { set_vcpu_id(); map_vcpuinfo(); init_evtchn(); } =20 -void hypervisor_ap_setup(void) -{ - xen_ap_setup(); -} - -int hypervisor_alloc_unused_page(mfn_t *mfn) -{ - unsigned long m; - int rc; - - rc =3D rangeset_claim_range(mem, 1, &m); - if ( !rc ) - *mfn =3D _mfn(m); - - return rc; -} - -int hypervisor_free_unused_page(mfn_t mfn) -{ - return rangeset_remove_range(mem, mfn_x(mfn), mfn_x(mfn)); -} - static void ap_resume(void *unused) { map_vcpuinfo(); init_evtchn(); } =20 -static void xen_resume(void) +void xen_resume(void) { /* Reset shared info page. */ map_shared_info(); @@ -345,11 +277,6 @@ static void xen_resume(void) pv_console_init(); } =20 -void hypervisor_resume(void) -{ - xen_resume(); -} - /* * Local variables: * mode: C diff --git a/xen/include/asm-x86/guest.h b/xen/include/asm-x86/guest.h index a38c6b5b3f..8e167165ae 100644 --- a/xen/include/asm-x86/guest.h +++ b/xen/include/asm-x86/guest.h @@ -20,6 +20,7 @@ #define __X86_GUEST_H__ =20 #include +#include #include #include #include diff --git a/xen/include/asm-x86/guest/hypervisor.h b/xen/include/asm-x86/g= uest/hypervisor.h new file mode 100644 index 0000000000..135ad36f72 --- /dev/null +++ b/xen/include/asm-x86/guest/hypervisor.h @@ -0,0 +1,58 @@ +/*************************************************************************= ***** + * asm-x86/guest/hypervisor.h + * + * This program is free software; you can redistribute it and/or + * modify it under the terms and conditions of the GNU General Public + * License, version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; If not, see . + */ + +#ifndef __X86_GUEST_HYPERVISOR_H__ +#define __X86_GUEST_HYPERVISOR_H__ + +#ifdef CONFIG_GUEST + +#include + +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); + +#else + +#include + +static inline void probe_hypervisor(void) {} + +static inline void hypervisor_setup(void) +{ + ASSERT_UNREACHABLE(); +} +static inline void hypervisor_ap_setup(void) +{ + ASSERT_UNREACHABLE(); +} + +#endif /* CONFIG_GUEST */ +#endif /* __X86_GUEST_HYPERVISOR_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xe= n.h index b015ed1883..d031f1f70d 100644 --- a/xen/include/asm-x86/guest/xen.h +++ b/xen/include/asm-x86/guest/xen.h @@ -32,12 +32,10 @@ extern bool xen_guest; extern bool pv_console; extern uint32_t xen_cpuid_base; =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); -void hypervisor_resume(void); +void probe_xen(void); +void xen_setup(void); +void xen_ap_setup(void); +void xen_resume(void); =20 DECLARE_PER_CPU(unsigned int, vcpu_id); DECLARE_PER_CPU(struct vcpu_info *, vcpu_info); @@ -47,16 +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 void hypervisor_setup(void) -{ - ASSERT_UNREACHABLE(); -} -static inline void hypervisor_ap_setup(void) -{ - ASSERT_UNREACHABLE(); -} +static inline void probe_xen(void) {} =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