From patchwork Mon Oct 21 15:57:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11202587 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 EC6CA1895 for ; Mon, 21 Oct 2019 15:59:22 +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 C7A9A20B7C for ; Mon, 21 Oct 2019 15:59:22 +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="D99cQRcq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C7A9A20B7C 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 1iMa4P-0008Sb-MP; Mon, 21 Oct 2019 15:58:09 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iMa4O-0008S0-TW for xen-devel@lists.xenproject.org; Mon, 21 Oct 2019 15:58:08 +0000 X-Inumbo-ID: 7c946b7e-f41b-11e9-beca-bc764e2007e4 Received: from mail-wm1-x343.google.com (unknown [2a00:1450:4864:20::343]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7c946b7e-f41b-11e9-beca-bc764e2007e4; Mon, 21 Oct 2019 15:57:30 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id q13so3884654wmj.0 for ; Mon, 21 Oct 2019 08:57:30 -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=+9p0XoTnmWEXGbOkz/xPFNftw6o4q7PdA5mk2bpDbeo=; b=D99cQRcqnw8U2NSMpL3xgc3ED+ucuVjXTA8M/tyYbXW5S3WPrjhy3jUsnFiuFXowl8 Po0nnRoydLrfHnUEz3RXBz1vWj6CQjzmruUcxgYxggBWHCJl2bMGoLWXksIhSv0QH2KU MMOitG4ozrCQsN5226ODtMVHYJXTJH0REF39wfqE5J4bN3iJDzW31XUrrlJLZtwIwlq6 aBI24yWUE7QcITfFt3pLTTiElpuUR7Lrxks1ihOqeQXuIkqh8dTF1gmaukasx0eyU6VL 4A26xIcBne6MKGGA7LiiW6QBdLyXYza7CMhUDTHFLwDlTdX/zedH0xEn0A5gtxBCA6yE Rqiw== 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=+9p0XoTnmWEXGbOkz/xPFNftw6o4q7PdA5mk2bpDbeo=; b=pmjBprflwXZTCV4EA2MKxuWtHriZXURSN99Vm7UPKW5wJxaFqjpfwRdUuQ7w20JjVe 1E/ykO7SBDlz65uQcwY6aX3AxDwRbvcftDzLk49sRccROHcPFTgSgHj2QbKV9nq/A9Rg 7XBE9WD4emgFrsXedhNjQrfH5PfoCN3MqsQsXOXtDYKpMz2PBWs1YrAZuJlyfwrnlJxE gnUSFxXydju/6a6rcP5UBn7DcQCOvd0/jPE5Grr+jk2LMKdfZpWG6tsUu5AhvfwEuG4W VKDo43eVXc1K/E0aT+x49X5LtGva6ZblU2CnpzUbKNXDv2zsYitP1lMh6JOpkSxsUG1w hSVA== X-Gm-Message-State: APjAAAV+oVoNAzF6nAyHwFN+flJ0Hs2YqlGoEnhuuZbQA0Z1oziNqfKt d2owfI3MOvEkgt5zqED499g2v6F/x9A= X-Google-Smtp-Source: APXvYqxhbk/dKoNrV6v0Hv+TOIEoYaVGGEN1wftjCpczrGkIH8vWwuv/76XWVwiggV4bRtf1rnig/w== X-Received: by 2002:a05:600c:253:: with SMTP id 19mr18525827wmj.158.1571673449699; Mon, 21 Oct 2019 08:57:29 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 08:57:29 -0700 (PDT) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Mon, 21 Oct 2019 16:57:18 +0100 Message-Id: <20191021155718.28653-10-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 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 did for Xen. As starters, detect Hyper-V in probe routine. More complex functionalities will be added later. Signed-off-by: Wei Liu Reviewed-by: Paul Durrant --- V3: 1. Remove some unused code 2. Rename structure 3. Also detect HV#1 signature --- 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 | 54 ++++++++++++++++++++++++++++++ xen/arch/x86/guest/hypervisor.c | 8 +++++ xen/include/asm-x86/guest.h | 1 + xen/include/asm-x86/guest/hyperv.h | 45 +++++++++++++++++++++++++ 7 files changed, 119 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 867de857e8..56513c771c 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -164,6 +164,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..7ab4b127f3 --- /dev/null +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -0,0 +1,54 @@ +/****************************************************************************** + * 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; + + cpuid(0x40000000, &eax, &ebx, &ecx, &edx); + if ( !((ebx == 0x7263694d) && /* "Micr" */ + (ecx == 0x666f736f) && /* "osof" */ + (edx == 0x76482074)) ) /* "t Hv" */ + return false; + + cpuid(0x40000001, &eax, &ebx, &ecx, &edx); + if ( eax != 0x31237648 ) /* Hv#1 */ + return false; + + return true; +} + +struct hypervisor_ops hyperv_ops = { + .name = "Hyper-V", +}; + +/* + * 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 a666ad9526..17392d1ffa 100644 --- a/xen/arch/x86/guest/hypervisor.c +++ b/xen/arch/x86/guest/hypervisor.c @@ -43,6 +43,14 @@ bool hypervisor_probe(void) } #endif +#ifdef CONFIG_HYPERV_GUEST + if ( hyperv_probe() ) + { + hops = &hyperv_ops; + return true; + } +#endif + return false; } 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..4b9cc5a836 --- /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_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: + */