From patchwork Mon Sep 30 15:00:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11166855 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 958E8112B for ; Mon, 30 Sep 2019 15:03: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 7091F20679 for ; Mon, 30 Sep 2019 15:03: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="qtS87TNU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7091F20679 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 1iExBA-0006Nv-8s; Mon, 30 Sep 2019 15:01:36 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iExB9-0006NC-AP for xen-devel@lists.xenproject.org; Mon, 30 Sep 2019 15:01:35 +0000 X-Inumbo-ID: 1b30296a-e393-11e9-97fb-bc764e2007e4 Received: from mail-wr1-x441.google.com (unknown [2a00:1450:4864:20::441]) by localhost (Halon) with ESMTPS id 1b30296a-e393-11e9-97fb-bc764e2007e4; Mon, 30 Sep 2019 15:00:57 +0000 (UTC) Received: by mail-wr1-x441.google.com with SMTP id o18so11698925wrv.13 for ; Mon, 30 Sep 2019 08:00:57 -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=DlRmra7nMXyOp1zRJYHjAUTN98YVR6jQ+ZVEzgeJdtg=; b=qtS87TNUBWPDNK/Glrb7l3AQj+UveA3TOaqF7jSdZUp8owi17FbfYw1OiH1t+apfwV fwn3HC4GiO5CfORSSzdP+pigksjhYLMjHsnZ9WVpMSXO6TEXoFVHzENTT11yYvhZl0+Y +0oGlrgcTV7ie/fXLD2/AoB2G/KnkPqC0gg4maEmNl+N11WgWJoJYmM4pLGAZmDlyVNP 6J+XKWUgzbZy3xcwC6NMTYg6Vu8d9hbd3zYLD1/kXwVYJ1Vz0u9CZyOwnUERzq9Z4Sox rEO7GjTW1YFRu9CQjS8Zk1JOVr96RiWl7tlODBLNXcO4/YbwvVWV31UwHOSZqlD7YEMO APjg== 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=DlRmra7nMXyOp1zRJYHjAUTN98YVR6jQ+ZVEzgeJdtg=; b=nk8+CWWYA9KjSxKREdeGgPxFl5YcJZ4Q4SgQ3nT+jXV4cLx/hdOdf0YsI40BiLzRuQ u4rmBTCf4oUKHGAgT4n8vDCsWAULP0MEiIv7fjqqrTbCKVQf8XUcEghJv9q1RzHkYI3s LHqZ2J7clSeI/3LAQho13T7btE2E/jWSMnLyACHi4943S3yQEXfm1ypysAipLlB5l5MU YX5mIjbVSFQNsKgKanBNwIajDy8CFCUg4UdpXmejt/wv3Xv3BOycvTtlKLHmojNaayLO PzlXO5+bIuNMXK687btAcTweKGfGqcKWv396Im02WkJFoXxzkEPTwpXtAtOY7imkZ9SU rjIg== X-Gm-Message-State: APjAAAW8n9i82nLwc/uDqGFWVtNR9HmTz33VAnfnzY9CIN/SbxBJcCKI 3DmpZHLgGAiprAriU/TUXEa6lIRkXvM= X-Google-Smtp-Source: APXvYqznt4+mXcvnxau6YBOyOZ88md4XZ6EwU/yZ321SSukGpRelkLTNyubRmXQ27AFfjNYfgYt7SQ== X-Received: by 2002:a5d:4983:: with SMTP id r3mr14667428wrq.194.1569855656122; Mon, 30 Sep 2019 08:00:56 -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 f143sm32870852wme.40.2019.09.30.08.00.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2019 08:00:55 -0700 (PDT) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Mon, 30 Sep 2019 16:00:43 +0100 Message-Id: <20190930150044.5734-10-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190930150044.5734-1-liuwe@microsoft.com> References: <20190930150044.5734-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH for-next v2 9/9] x86: introduce CONFIG_HYPERV and detection 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_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" We use the same code structure as we die for Xen. As starters, detect Hyper-V in probe routine. More complex functionalities will be added later. Signed-off-by: Wei Liu --- xen/arch/x86/Kconfig | 9 ++++ xen/arch/x86/guest/Makefile | 1 + xen/arch/x86/guest/hyperv/Makefile | 1 + xen/arch/x86/guest/hyperv/hyperv.c | 69 ++++++++++++++++++++++++++++++ xen/arch/x86/guest/hypervisor.c | 5 +++ xen/include/asm-x86/guest.h | 1 + xen/include/asm-x86/guest/hyperv.h | 45 +++++++++++++++++++ 7 files changed, 131 insertions(+) create mode 100644 xen/arch/x86/guest/hyperv/Makefile create mode 100644 xen/arch/x86/guest/hyperv/hyperv.c create mode 100644 xen/include/asm-x86/guest/hyperv.h diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 584bdc1bb8..c5a93babfe 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -163,6 +163,15 @@ endchoice config GUEST bool +config HYPERV_GUEST + def_bool n + select GUEST + prompt "Hyper-V Guest" + ---help--- + Support for Xen detecting when it is running under Hyper-V. + + If unsure, say N. + config XEN_GUEST def_bool n select GUEST diff --git a/xen/arch/x86/guest/Makefile b/xen/arch/x86/guest/Makefile index f63d64bbee..f164196772 100644 --- a/xen/arch/x86/guest/Makefile +++ b/xen/arch/x86/guest/Makefile @@ -1,3 +1,4 @@ obj-y += hypervisor.o +subdir-$(CONFIG_HYPERV_GUEST) += hyperv subdir-$(CONFIG_XEN_GUEST) += xen diff --git a/xen/arch/x86/guest/hyperv/Makefile b/xen/arch/x86/guest/hyperv/Makefile new file mode 100644 index 0000000000..68170109a9 --- /dev/null +++ b/xen/arch/x86/guest/hyperv/Makefile @@ -0,0 +1 @@ +obj-y += hyperv.o diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c new file mode 100644 index 0000000000..4494b87fe8 --- /dev/null +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -0,0 +1,69 @@ +/****************************************************************************** + * arch/x86/guest/hyperv/hyperv.c + * + * Support for detecting and running under Hyper-V. + * + * 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 + +bool __init hyperv_probe(void) +{ + uint32_t eax, ebx, ecx, edx; + bool hyperv_guest = false; + + cpuid(0x40000000, &eax, &ebx, &ecx, &edx); + if ( (ebx == 0x7263694d) && /* "Micr" */ + (ecx == 0x666f736f) && /* "osof" */ + (edx == 0x76482074) ) /* "t Hv" */ + hyperv_guest = true; + + return hyperv_guest; +} + +void __init hyperv_setup(void) +{ + /* Nothing yet */ +} + +void hyperv_ap_setup(void) +{ + /* Nothing yet */ +} + +void hyperv_resume(void) +{ + /* Nothing yet */ +} + +struct hypervisor_ops hyperv_hypervisor_ops = { + .name = "Hyper-V", + .setup = hyperv_setup, + .ap_setup = hyperv_ap_setup, + .resume = hyperv_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/hypervisor.c b/xen/arch/x86/guest/hypervisor.c index 8161b26c5a..87a195e888 100644 --- a/xen/arch/x86/guest/hypervisor.c +++ b/xen/arch/x86/guest/hypervisor.c @@ -40,6 +40,11 @@ bool hypervisor_probe(void) hops = &xen_hypervisor_ops; #endif +#ifdef CONFIG_HYPERV_GUEST + if ( hyperv_probe() ) + hops = &hyperv_hypervisor_ops; +#endif + return !!hops; } diff --git a/xen/include/asm-x86/guest.h b/xen/include/asm-x86/guest.h index 8e167165ae..94448606d4 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/hyperv.h b/xen/include/asm-x86/guest/hyperv.h new file mode 100644 index 0000000000..a2d8ee8987 --- /dev/null +++ b/xen/include/asm-x86/guest/hyperv.h @@ -0,0 +1,45 @@ +/****************************************************************************** + * asm-x86/guest/hyperv.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_GUEST_HYPERV_H__ +#define __X86_GUEST_HYPERV_H__ + +#ifdef CONFIG_HYPERV_GUEST + +#include + +extern struct hypervisor_ops hyperv_hypervisor_ops; + +bool hyperv_probe(void); + +#else + +static inline bool hyperv_probe(void) { return false; } + +#endif /* CONFIG_HYPERV_GUEST */ +#endif /* __X86_GUEST_HYPERV_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */