From patchwork Sun Jan 5 16:47:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11318505 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 4A146138C for ; Sun, 5 Jan 2020 16:49:31 +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 26E342077B for ; Sun, 5 Jan 2020 16:49:31 +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="r2DLRQln" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 26E342077B 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 1io94f-0003lK-AR; Sun, 05 Jan 2020 16:48:21 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1io94e-0003lE-GJ for xen-devel@lists.xenproject.org; Sun, 05 Jan 2020 16:48:20 +0000 X-Inumbo-ID: 2ad8ff7e-2fdb-11ea-88e7-bc764e2007e4 Received: from mail-wr1-x443.google.com (unknown [2a00:1450:4864:20::443]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 2ad8ff7e-2fdb-11ea-88e7-bc764e2007e4; Sun, 05 Jan 2020 16:48:15 +0000 (UTC) Received: by mail-wr1-x443.google.com with SMTP id t2so47085503wrr.1 for ; Sun, 05 Jan 2020 08:48:15 -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=r2DLRQlnqCJ7OG+Mer+waKGjvZSZCpgrzpLqRNHx1gEa4cCYhpLVd5NG0HeKiK0Sw9 voIZ1yQQxiplU5Bon+03bFsjCYg6SxNhWo8TsK4QYzyDpxYEDUHsW0HfZbRMQ5hbDgap Y0T+Yp5lW/v9wgT/7B1mkb/SKvcCS9L0fMf3s/RWTIS2EFsJYEZRWQi1B7ytAvbEiIn4 s1/ct04HglCk8qYtqVF4aqJ6TuQ0lB44tqRQy+RGHe0DH/K5eHQdQfUt1diy0hAedbaL udxhnPcaikQZASY7SLB9qhc2yJMUS8iwQBC1GJOkfoeSD1idI6+pkzIqKUXMt0cHxL61 EXMg== 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=azwgb+/a6sHlm9sOszb8duBIGLyBPBP+zKzydACqSevQtO/YPsHBMdEpYGxLyEziT0 nHJzqRPUyaKhabz57+uqVYPhBbLQuo7swbFDDwsifNmxBLJTABn8iI0YwI7q+HjnLeyv cz6o48zf3LNbVoOoAM5DqZ4rooI7R9EhCsMib/uHrxr9GxALR1jWgqTkBesCvjD/GQNs WU+sdy18aZQkQ/V8Qde7Tz6zsGazoivAKK5a8jsi7rongiqrLfbWNZmiYAXPqo75J0sg anQ6wII7io2eAsZQeRDGojUJ8qSNtUGjUCv91sNFHEQP37ocSVmpDBiQLBdnJxXb+lXI 5eVw== X-Gm-Message-State: APjAAAXhABOuDn+OCEAGpUin/vPxCBMn1r6zagAf5yr934PttSJJMf5g gb2uQ4c9f8gDKsXDQKrJ+HMsmXn0tsk= X-Google-Smtp-Source: APXvYqxiumd4z+uBIL06RQRkKx6Fu8H8snAD5+UsfaXvVHj4Wp8rcpwPsWGxoTHD527Xsy9yOKTG/A== X-Received: by 2002:a05:6000:118d:: with SMTP id g13mr3845255wrx.141.1578242894685; Sun, 05 Jan 2020 08:48:14 -0800 (PST) Received: from localhost.localdomain (38.163.200.146.dyn.plus.net. [146.200.163.38]) by smtp.gmail.com with ESMTPSA id y139sm20834028wmd.24.2020.01.05.08.48.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jan 2020 08:48:14 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Sun, 5 Jan 2020 16:47:57 +0000 Message-Id: <20200105164801.26278-2-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200105164801.26278-1-liuwe@microsoft.com> References: <20200105164801.26278-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 1/5] 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