From patchwork Mon Oct 21 15:57:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11202579 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 48A731895 for ; Mon, 21 Oct 2019 15:59:04 +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 2503720B7C for ; Mon, 21 Oct 2019 15:59:04 +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="EWw8ev4X" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2503720B7C 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 1iMa46-0008GB-71; Mon, 21 Oct 2019 15:57:50 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iMa44-0008Fq-Sv for xen-devel@lists.xenproject.org; Mon, 21 Oct 2019 15:57:48 +0000 X-Inumbo-ID: 7a616f1e-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 7a616f1e-f41b-11e9-bbab-bc764e2007e4; Mon, 21 Oct 2019 15:57:27 +0000 (UTC) Received: by mail-wm1-x341.google.com with SMTP id c22so4239747wmd.1 for ; Mon, 21 Oct 2019 08:57:27 -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=jBrEUmLmtAmRmL0ZQe75O+VGK/lIBJ2eQ4PSZ4jPdH0=; b=EWw8ev4XbD5uXEbn9iAQyd79L3Ub3XQoA5XpmnAjHIi+p9yTY1qcYqgdbn4GuCwPKM Rlj59AsjeQkjg00V1xO4ftnx3kHRwVK7VzxVt2Z8n3RwgEwTa8Nwhw61i6Zr3N9wY8Te pZRJb5uvfKGtLhHMiEKM5RZd+dUZXSo6s3fuecIGR4zH3YDy7SP6QqHTs2cHDYfxN7dY S1fSMXGeHmmBBmDjE91bIX+R99nbh8xkDdmp2bkb3WPqw0SVNhDsQjvsCHEh0dHMduJ7 H0TrKGkcdRJ4yv+mYOzN3YN2nG234Y0RSM09557Xnkg7VZrZJULvTmLetIWIxAor1pjv aGNw== 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=jBrEUmLmtAmRmL0ZQe75O+VGK/lIBJ2eQ4PSZ4jPdH0=; b=M3IWEdkZQysJcPBKWUOKSgAvMUnJ68NyYIKLdfm2ap0D6poYWD0jHKzfZZgMg16Dx5 fM6nPFyKrGRd8QXZRZkigGGR+dTm3LzhI/MFTqnYb4T2FN4I6DuaFp9OXwo725zbXBuo eTCm5AaoVlZaoTcHbCGkJTPYBHkuQ5HJ172WZ+KDkWRWCJqiuZlQAUS4MtEpTU/0cG3e /NYF6Sx4PVSJQLI6WuKn2d8SOkYSgrX8JRmfccQVGp/AT1GUt/yqtynMALmYTpmjUfQq HD+z8J5SBU29WCkFwo7w2gNp3D6KVvy+QbB+Kt3kX0RWXXBal0LtcSUFtcrrLZUWusEa EWIA== X-Gm-Message-State: APjAAAWsUdrXRXqYLNIBgoST8qCD6RpyMBGEFzQvimWb+FggVRbiuunu fLgbJaAAqY5WHbjTMq9XBPGESGedAgI= X-Google-Smtp-Source: APXvYqyO/sJRzgkxKMuVKoWxsxZIEOo3Odlp+bUvQrXRafR6MoUmi6fT+irY1y0FjDTvsdfQs7drpw== X-Received: by 2002:a1c:38c3:: with SMTP id f186mr4252455wma.58.1571673445980; Mon, 21 Oct 2019 08:57:25 -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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 08:57:25 -0700 (PDT) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Mon, 21 Oct 2019 16:57:14 +0100 Message-Id: <20191021155718.28653-6-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 5/9] x86: introduce 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" We will soon implement Hyper-V support for Xen. Add a framework for that. This requires moving some of the hypervisor_* functions from xen.h to hypervisor.h. Signed-off-by: Wei Liu Reviewed-by: Paul Durrant --- xen/arch/x86/guest/Makefile | 2 + xen/arch/x86/guest/hypervisor.c | 45 +++++++++++++++++++ xen/include/asm-x86/guest.h | 1 + xen/include/asm-x86/guest/hypervisor.h | 61 ++++++++++++++++++++++++++ xen/include/asm-x86/guest/xen.h | 12 ----- 5 files changed, 109 insertions(+), 12 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 += hypervisor.o + subdir-$(CONFIG_XEN_GUEST) += xen diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c new file mode 100644 index 0000000000..89b9ae4de0 --- /dev/null +++ b/xen/arch/x86/guest/hypervisor.c @@ -0,0 +1,45 @@ +/****************************************************************************** + * 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) 2019 Microsoft. + */ + +#include + +#include +#include + +static struct hypervisor_ops *hops __read_mostly; + +bool hypervisor_probe(void) +{ + if ( hops ) + return true; + + return false; +} + +/* + * 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.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__ #include +#include #include #include #include diff --git a/xen/include/asm-x86/guest/hypervisor.h b/xen/include/asm-x86/guest/hypervisor.h new file mode 100644 index 0000000000..38344e2e89 --- /dev/null +++ b/xen/include/asm-x86/guest/hypervisor.h @@ -0,0 +1,61 @@ +/****************************************************************************** + * 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 . + * + * Copyright (c) 2019 Microsoft. + */ + +#ifndef __X86_HYPERVISOR_H__ +#define __X86_HYPERVISOR_H__ + +#ifdef CONFIG_GUEST + +struct hypervisor_ops { + /* Name of the hypervisor */ + const char *name; + /* Main setup routine */ + void (*setup)(void); + /* AP setup */ + void (*ap_setup)(void); + /* Resume from suspension */ + void (*resume)(void); +}; + +bool hypervisor_probe(void); +void hypervisor_setup(void); +void hypervisor_ap_setup(void); +void hypervisor_resume(void); + +#else + +#include + +static inline bool hypervisor_probe(void) { return false; } +static inline void hypervisor_setup(void) {} +static inline void hypervisor_ap_setup(void) {} +static inline void hypervisor_resume(void) {} + +#endif /* CONFIG_GUEST */ + +#endif /* __X86_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/xen.h index b015ed1883..3145f75361 100644 --- a/xen/include/asm-x86/guest/xen.h +++ b/xen/include/asm-x86/guest/xen.h @@ -33,11 +33,8 @@ extern bool pv_console; extern uint32_t xen_cpuid_base; 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); DECLARE_PER_CPU(unsigned int, vcpu_id); DECLARE_PER_CPU(struct vcpu_info *, vcpu_info); @@ -49,15 +46,6 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info); 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_XEN_GUEST */ #endif /* __X86_GUEST_XEN_H__ */