From patchwork Sun Dec 29 18:33:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11312365 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 3C1A414DB for ; Sun, 29 Dec 2019 18:35:14 +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 18A7820748 for ; Sun, 29 Dec 2019 18:35:14 +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="Wm0uGfM6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 18A7820748 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 1ildOK-0008R9-W0; Sun, 29 Dec 2019 18:34:16 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ildOK-0008Qq-43 for xen-devel@lists.xenproject.org; Sun, 29 Dec 2019 18:34:16 +0000 X-Inumbo-ID: c6ba7d36-2a69-11ea-a1e1-bc764e2007e4 Received: from mail-wm1-x343.google.com (unknown [2a00:1450:4864:20::343]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c6ba7d36-2a69-11ea-a1e1-bc764e2007e4; Sun, 29 Dec 2019 18:33:58 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id t14so12582604wmi.5 for ; Sun, 29 Dec 2019 10:33:58 -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=yUTd1JvE33R5YeeJoO6ibJUr87M2fq2cnap5F1T4Coo=; b=Wm0uGfM6hWk8ZafajtIAZFnjIh6xQ1k4yOyITXMZLz1rWcp7VujvIHAiyj+Zlvh8PA x8um2YQWFzgbKiQsD89HIdzqWuRYu+2mLkwMNPmt8u74DbLJcyVYVtV+aRuy5PPHPyYX xDjts14mKc2dtohOz5TRSyvcpc+oIu1mCqSaLpu7CCxzMqiWk6iaGxs7c4paIc+2iIZS OoEOqYF7C+qg8Py2/GHARXGErInL+YJroGTmL3xBZVwuMnBqn2bWPejpVMMtEEhsXLBg FZYh4QlPZF6Eucdo0yC5AFTAGKTnJGp+K8Zcd5bTUIj0WNsgEivwlU1JzTj6FsxCfB56 uv/A== 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=yUTd1JvE33R5YeeJoO6ibJUr87M2fq2cnap5F1T4Coo=; b=TBrwjfdt/BC4APCbb9Gs1xYxF2AUhklSQNA+u2FBKWbHymjHMQLGbNvdd1AW095txT lF2aw5uMMMqvYPEULoAWAlQKLm87m8D93T5hvO7QqdGtI/Zqadu3Faal0kVPaoJtxEOi bwQSf1icDMNGoZ/1YX7REBuCmtxZ3+T1P3g6wvUY7osmvCm7Qnzv7T/08OqDbYrDxp9d Oag0HalVAUPg4YYTiNrkienQjlEhO6HMf4R2zwRSorEbSVTBSM0D5Nkoc5eju61TYJGQ Vnz7aiTRN4OFbviNdgRkYbXSU0BuqzSUadz0TpLSyJpFwEo1iiBhLXBBgCSXuGW+7Kiv zSfg== X-Gm-Message-State: APjAAAXkgwt1xpTXRzwatB2RcIsmdC6OES0BPpReL77Pm61fOZ8KYl/w rwKvBJdJ6J5CHKBr7y/Ov7s222JCCH0= X-Google-Smtp-Source: APXvYqxvZHLSgFp1w4L8h63Ft9w6NohjU7jzmD9SL+fwvxhj1RPLSp7MME6k71NQVXZLFxYklWeFpQ== X-Received: by 2002:a1c:3189:: with SMTP id x131mr28988125wmx.59.1577644437764; Sun, 29 Dec 2019 10:33:57 -0800 (PST) Received: from localhost.localdomain (38.163.200.146.dyn.plus.net. [146.200.163.38]) by smtp.gmail.com with ESMTPSA id f207sm19667903wme.9.2019.12.29.10.33.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Dec 2019 10:33:57 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Sun, 29 Dec 2019 18:33:37 +0000 Message-Id: <20191229183341.14877-5-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191229183341.14877-1-liuwe@microsoft.com> References: <20191229183341.14877-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 4/8] x86/hyperv: setup hypercall page 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 , Paul Durrant , 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" Signed-off-by: Wei Liu --- xen/arch/x86/guest/hyperv/hyperv.c | 41 +++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index c6a26c5453..438910c8cb 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -19,16 +19,17 @@ * Copyright (c) 2019 Microsoft. */ #include +#include #include #include struct ms_hyperv_info __read_mostly ms_hyperv; -static const struct hypervisor_ops ops = { - .name = "Hyper-V", -}; +void *hv_hypercall; +static struct page_info *hv_hypercall_page; +static const struct hypervisor_ops ops; const struct hypervisor_ops *__init hyperv_probe(void) { uint32_t eax, ebx, ecx, edx; @@ -71,6 +72,40 @@ const struct hypervisor_ops *__init hyperv_probe(void) return &ops; } +static void __init setup_hypercall_page(void) +{ + union hv_x64_msr_hypercall_contents hypercall_msr; + + /* Unfortunately there isn't a really good way to unwind Xen to + * not use Hyper-V hooks, so panic if anything goes wrong. + * + * In practice if page allocation fails this early on it is + * unlikely we can get a working system later. + */ + hv_hypercall_page = alloc_domheap_page(NULL, 0); + if ( !hv_hypercall_page ) + panic("Failed to allocate Hyper-V hypercall page\n"); + + hv_hypercall = __map_domain_page_global(hv_hypercall_page); + if ( !hv_hypercall ) + panic("Failed to map Hyper-V hypercall page\n"); + + rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + hypercall_msr.enable = 1; + hypercall_msr.guest_physical_address = page_to_maddr(hv_hypercall_page); + wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); +} + +static void __init setup(void) +{ + setup_hypercall_page(); +} + +static const struct hypervisor_ops ops = { + .name = "Hyper-V", + .setup = setup, +}; + /* * Local variables: * mode: C