From patchwork Fri Jan 3 16:08:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11316985 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 F04951395 for ; Fri, 3 Jan 2020 16:10:26 +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 CC1C42084D for ; Fri, 3 Jan 2020 16:10:26 +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="f4X1oyi9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC1C42084D 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 1inPVm-0005Ua-Ek; Fri, 03 Jan 2020 16:09:18 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1inPVl-0005UK-Lp for xen-devel@lists.xenproject.org; Fri, 03 Jan 2020 16:09:17 +0000 X-Inumbo-ID: 5afe3b9a-2e43-11ea-88e7-bc764e2007e4 Received: from mail-wm1-x329.google.com (unknown [2a00:1450:4864:20::329]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5afe3b9a-2e43-11ea-88e7-bc764e2007e4; Fri, 03 Jan 2020 16:09:01 +0000 (UTC) Received: by mail-wm1-x329.google.com with SMTP id b19so8784888wmj.4 for ; Fri, 03 Jan 2020 08:09:01 -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=AeVdaCAPZTMCoRydrJF1kMnbXuo4DmKCUTwBKEx4Ftg=; b=f4X1oyi9sh1zTPgxK6RoOIEv5yHCPevuLRvYvmGuDyfr9FjEB0LxhAwbi8Exzfzy4v mzjBfnW5J7mE5yx3GHq2mSMGHPzXu3X+D6RlXQQxzlGJx5UH53s4Lg7DRRoS/P1yk7/Z c1mk6hbHBh1aNg6LSgTIDkB52V68a7SMx54j+Uv5/xq8+WgAbcFptDjceC9euxe/lA1l 0QHdrX+oB4XrfMHud3UZYDi8dEjFia9ymeOmnbiNlNBtkvXJ/0r9K/QdVvGZqG0OoMgI hRtLfCm99Hk2jzKoBHVj4DjhMz6FRiXAB86P6OBolTwy2Fqv2JHfV/8YhjVSDlWs/oRr W71A== 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=AeVdaCAPZTMCoRydrJF1kMnbXuo4DmKCUTwBKEx4Ftg=; b=XyfSTd9fKbDSEzDLvroDqw1Gxs+ghiuHJz0LK0rCiHp+zaWhDz4XTaas4xKMCk9tXh Hmly2z98Hyh60347vOmlXHLisW7V+T8vieXy55HoUQim6Z6C08p+yAsDuHX4sJ+ff+AV +IckcdqifCePajrigEYmeTs7Nv9RT01oVYA9iLPMo40W38IKcRVBsOx2LizCuG/4g8Be OWq7Wfba/PggMtxW78pUMKNboPqQDKsJAl6ODasf1iANVvp21K+3h6qYd9QUZZoqGR8N 4EFWL5HIG15Jne8PhB8nhhy+9dNC8wXup4FzFbFUmVTnDjJF1GeX0QCAhDYoWHnNcVV3 koSQ== X-Gm-Message-State: APjAAAXe1EdVGB6A/79Gq8bJsmEc0586U7IgjtRDiVdfBxop/jHeK4Rx VOvnineyHve6W/06ooQrPDfXBRUSWkdBkQ== X-Google-Smtp-Source: APXvYqxbMR8RYP5sL+FAKCqyBnntlD2gxHmRqxI+cznR9X69weUoxjSyDz5vfC81rfyr/nYC37V8VQ== X-Received: by 2002:a1c:a949:: with SMTP id s70mr20167401wme.69.1578067740767; Fri, 03 Jan 2020 08:09:00 -0800 (PST) Received: from localhost.localdomain (38.163.200.146.dyn.plus.net. [146.200.163.38]) by smtp.gmail.com with ESMTPSA id z11sm61000235wrt.82.2020.01.03.08.09.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jan 2020 08:09:00 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Fri, 3 Jan 2020 16:08:21 +0000 Message-Id: <20200103160825.19377-5-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200103160825.19377-1-liuwe@microsoft.com> References: <20200103160825.19377-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 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 --- v2: 1. Fix issue discovered by Michael 2. Use a statically allocated page as hypercall page --- xen/arch/x86/guest/hyperv/Makefile | 1 + xen/arch/x86/guest/hyperv/hypercall_page.S | 21 +++++++++++++++++ xen/arch/x86/guest/hyperv/hyperv.c | 27 +++++++++++++++++++--- 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 xen/arch/x86/guest/hyperv/hypercall_page.S diff --git a/xen/arch/x86/guest/hyperv/Makefile b/xen/arch/x86/guest/hyperv/Makefile index 68170109a9..1a8887d2f4 100644 --- a/xen/arch/x86/guest/hyperv/Makefile +++ b/xen/arch/x86/guest/hyperv/Makefile @@ -1 +1,2 @@ +obj-y += hypercall_page.o obj-y += hyperv.o diff --git a/xen/arch/x86/guest/hyperv/hypercall_page.S b/xen/arch/x86/guest/hyperv/hypercall_page.S new file mode 100644 index 0000000000..6d6ab913be --- /dev/null +++ b/xen/arch/x86/guest/hyperv/hypercall_page.S @@ -0,0 +1,21 @@ +#include +#include + + .section ".text.page_aligned", "ax", @progbits + .p2align PAGE_SHIFT +GLOBAL(hv_hypercall_page) + /* Return -1 for "not yet ready" state */ + mov -1, %rax + ret +1: + /* Fill the rest with `ret` */ + .fill PAGE_SIZE - (1b - hv_hypercall_page), 1, 0xc3 + .type hv_hypercall_page, STT_OBJECT + .size hv_hypercall_page, PAGE_SIZE + +/* + * Local variables: + * tab-width: 8 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index 8d38313d7a..381be2a68c 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -19,16 +19,16 @@ * 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", -}; +extern char hv_hypercall_page[]; +static const struct hypervisor_ops ops; const struct hypervisor_ops *__init hyperv_probe(void) { uint32_t eax, ebx, ecx, edx; @@ -72,6 +72,27 @@ 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; + + rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + hypercall_msr.enable = 1; + hypercall_msr.guest_physical_address = + __pa(hv_hypercall_page) >> HV_HYP_PAGE_SHIFT; + 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