From patchwork Sat Nov 30 11:57:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11267937 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 41277112B for ; Sat, 30 Nov 2019 11:58:49 +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 1D1D52075A for ; Sat, 30 Nov 2019 11:58:49 +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="LsMaQvDg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1D1D52075A 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 1ib1Nz-0004pJ-AR; Sat, 30 Nov 2019 11:58:03 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ib1Ny-0004p0-KG for xen-devel@lists.xenproject.org; Sat, 30 Nov 2019 11:58:02 +0000 X-Inumbo-ID: 9f10bdf8-1368-11ea-b155-bc764e2007e4 Received: from mail-wr1-x443.google.com (unknown [2a00:1450:4864:20::443]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9f10bdf8-1368-11ea-b155-bc764e2007e4; Sat, 30 Nov 2019 11:57:45 +0000 (UTC) Received: by mail-wr1-x443.google.com with SMTP id j42so12278295wrj.12 for ; Sat, 30 Nov 2019 03:57:45 -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=P1aIvZ8fTBz3xENcDC1X1bofcpCEFX/45dhlRoFAdhU=; b=LsMaQvDge7dI9UkFINm/bUnDbeSJXtJH9VqQMtrETjo+I8B4dg91BTpSa5b/fcwv1w 3m5wQaQsgtzIdWhMr+fI1tKlKM6p78bHpau+2ZHnlhI9i3V5lh81HFOVc8xNB9J9TCYB U/IwkVFoj/0zL+t/MlXXVVHZ69EBWXj+CeChVl4uPK7xUbSW2AUkET7vcVQOdB14dd1t 6BcC6DRHsIAMZ+XqpwzOssQYbZGwLKH4nCGf1d+RQT0TRUnQ6MsZlruhRdV+x+5419NA hDHBCRhW8SmvxcNibQhrkhXtNrOHu4Jd1lqkoAYEdnwZdFp6QyceF7/FQQ1DuKmVqPVB AGiA== 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=P1aIvZ8fTBz3xENcDC1X1bofcpCEFX/45dhlRoFAdhU=; b=sVXEAHGVtUnm1QxEXTH96NsnBXHT4D0d9c1zcRjvDLtI0K20OXSv1otWFZlRQVYr1u nGC+ChFRm50Zj0Tk8Gl+M7rm1uU/WqO+Ss4LsalSvmlJzUuNWi2VgJ0+j0+h8GIv9vdW 4HEQwZ1Y1WCmPfAdifkzOLL1JNlmr0qXov7TGJtyfwZ2vY2KomlMxYiF5zNr2iasKhHK rm3+nTUvmsqFwZcbauwpC/eoVwd+/ZhTzd7+jZFJm7Gl+4FpmASY8LZ5oGbyc+I1HXJ0 IAPQWJbUDNLVzF6gG178ukG8j5RxTEVI6ymyIUSXKEr3Wz0Y/Wkwuwzo/OikQh8QWnTe DVOw== X-Gm-Message-State: APjAAAUhKGt689QenRmoQCF3yKfVJi+/itwU6Bq7JrLEC9WUgw1Zuv8x AZWTGIdbZbd43uVRzeldZoXCPMP+ci0= X-Google-Smtp-Source: APXvYqwJEl4pRyWaaonV+bUsFXMXE3Jz98ibJ6okhcKk5LIlN9sQ8AjXKfHzKGGp1Fl7wTgD894DuQ== X-Received: by 2002:adf:e78a:: with SMTP id n10mr39504343wrm.62.1575115064930; Sat, 30 Nov 2019 03:57:44 -0800 (PST) Received: from debian.mshome.net (122.163.200.146.dyn.plus.net. [146.200.163.122]) by smtp.gmail.com with ESMTPSA id z11sm2227769wrt.82.2019.11.30.03.57.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Nov 2019 03:57:44 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Sat, 30 Nov 2019 11:57:33 +0000 Message-Id: <20191130115737.15752-5-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191130115737.15752-1-liuwe@microsoft.com> References: <20191130115737.15752-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 4/8] 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 Acked-by: Jan Beulich --- Changes in v5: 1. Make hypervisor_probe return const char *. Changes in v4: 1. Add ASSERT_UNREACHABLE to stubs. 2. Move __read_mostly. 3. Return hops directly. 4. Drop Paul's review tag. --- 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 | 62 ++++++++++++++++++++++++++ xen/include/asm-x86/guest/xen.h | 12 ----- 5 files changed, 110 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..c35c610d01 --- /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 +#include + +static const struct hypervisor_ops __read_mostly *ops; + +const char *__init hypervisor_probe(void) +{ + if ( ops ) + return ops->name; + + return NULL; +} + +/* + * 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..392f4b90ae --- /dev/null +++ b/xen/include/asm-x86/guest/hypervisor.h @@ -0,0 +1,62 @@ +/****************************************************************************** + * 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__ + +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); +}; + +#ifdef CONFIG_GUEST + +const char *hypervisor_probe(void); +void hypervisor_setup(void); +void hypervisor_ap_setup(void); +void hypervisor_resume(void); + +#else + +#include +#include + +static inline const char *hypervisor_probe(void) { return NULL; } +static inline void hypervisor_setup(void) { ASSERT_UNREACHABLE(); } +static inline void hypervisor_ap_setup(void) { ASSERT_UNREACHABLE(); } +static inline void hypervisor_resume(void) { ASSERT_UNREACHABLE(); } + +#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__ */