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 From patchwork Sun Jan 5 16:47:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11318503 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 DD909138C for ; Sun, 5 Jan 2020 16:49:28 +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 B999120866 for ; Sun, 5 Jan 2020 16:49:28 +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="mQmEZXhB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B999120866 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 1io94k-0003lp-JE; Sun, 05 Jan 2020 16:48:26 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1io94j-0003lc-GK for xen-devel@lists.xenproject.org; Sun, 05 Jan 2020 16:48:25 +0000 X-Inumbo-ID: 2b4e09f4-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 2b4e09f4-2fdb-11ea-88e7-bc764e2007e4; Sun, 05 Jan 2020 16:48:16 +0000 (UTC) Received: by mail-wr1-x443.google.com with SMTP id b6so47138754wrq.0 for ; Sun, 05 Jan 2020 08:48:16 -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=UZghIdEEuygXxe0vKMiX29LXHwMAJ7Mkp6vmawf/dbA=; b=mQmEZXhB7VPIFcfgOi698RXGYpFhpBbpFa2D0mmd9VFRtWPYhRCizWsQ0UmyDTu6xZ ViFGHO5Med49c4oPX4gWvDDt3AeXRxJBuYlweslOZ4EmIz7AkL5xs+VoBAgplX+BT40g b2ubVZ8CrnyOxIQlgUGxlDDeBhcS6xHN/lPezi4tir3yHdwPMUgE3ZUG+22BnjCd/hbx v5iUhGdZ68ELJoMXR8l3nyegof4DVyMT6bohg8A8IYj49FXLWOMtupy7PgMkg74rTjpG t3kB/wXLsT+PHUAtqFMD3vRdwNboMi9j5fzJ/3V2OOuaEpC1e9XuNq/YRLMX99VCFBeJ fQMw== 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=UZghIdEEuygXxe0vKMiX29LXHwMAJ7Mkp6vmawf/dbA=; b=an6GPKQRqpX+CvMW8PdDQ7XaxPhPgr/aCBZBcfrf/JjYPd7esYwzF/skqMxUNAg8f4 iajFjzIPbKyn42sQFQvnLHKfMueNjK4fCGxFiMykjEqvO/CIUHmJ6ZhSvt3Tuhq+bVxq ocB9k5/dEeS02+AK5gqCQJK6xJJevZCS1Q8Pdk0Z1fkfsBhYIT6AkKwphRR31ekMbYXg 2x9nq1I2GOVzUzZzzMaGxgHptX8BmlzWVr2a5fK14X0Vt8RmDRmWVbJESVR8zdl5fu7t bSLRw+/rZHUWlDBOU8mcpbvxxS2XVCfJAt6NREp6JGpn6mRzn2n2TPXW+ZSCsWxhc2wI tx4Q== X-Gm-Message-State: APjAAAVVwuLYTByAg7fR0k+MwfJwhJwL1hh9YnmIyBvgzHOKZhtoFLra d5tn1u64Z9iT00ZraFrXqwm7OFEs3yE= X-Google-Smtp-Source: APXvYqxe+PMLJlbq5uHUsneNkt9zW2JDyI5rUmbq/nJE4tjK2l+RPX25Uym2WdbACXpflObTy9PHIA== X-Received: by 2002:adf:c147:: with SMTP id w7mr102064995wre.389.1578242895459; Sun, 05 Jan 2020 08:48:15 -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:15 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Sun, 5 Jan 2020 16:47:58 +0000 Message-Id: <20200105164801.26278-3-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 2/5] x86/hyperv: provide Hyper-V hypercall functions 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" These functions will be used later to make hypercalls to Hyper-V. I couldn't find reference in TLFS that Hyper-V clobbers flags and r9-r11, but Linux's commit message says it does. Err on the safe side. Signed-off-by: Wei Liu --- v3: 1. Name the file hyperv-hcall.h v2: 1. Use direct call --- xen/include/asm-x86/guest/hyperv-hcall.h | 95 ++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 xen/include/asm-x86/guest/hyperv-hcall.h diff --git a/xen/include/asm-x86/guest/hyperv-hcall.h b/xen/include/asm-x86/guest/hyperv-hcall.h new file mode 100644 index 0000000000..4b87dcfe64 --- /dev/null +++ b/xen/include/asm-x86/guest/hyperv-hcall.h @@ -0,0 +1,95 @@ +/****************************************************************************** + * asm-x86/guest/hyperv-hcall.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_HYPERV_HCALL_H__ +#define __X86_HYPERV_HCALL_H__ + +#include + +#include +#include +#include + +static inline uint64_t hv_do_hypercall(uint64_t control, paddr_t input, paddr_t output) +{ + uint64_t status; + + asm volatile ("mov %[output], %%r8\n" + "call hv_hypercall_page" + : "=a" (status), "+c" (control), + "+d" (input) ASM_CALL_CONSTRAINT + : [output] "rm" (output) + : "cc", "memory", "r8", "r9", "r10", "r11"); + + return status; +} + +static inline uint64_t hv_do_fast_hypercall(uint16_t code, + uint64_t input1, uint64_t input2) +{ + uint64_t status; + uint64_t control = (uint64_t)code | HV_HYPERCALL_FAST_BIT; + + asm volatile ("mov %[input2], %%r8\n" + "call hv_hypercall_page" + : "=a" (status), "+c" (control), + "+d" (input1) ASM_CALL_CONSTRAINT + : [input2] "rm" (input2) + : "cc", "r8", "r9", "r10", "r11"); + + return status; +} + +static inline uint64_t hv_do_rep_hypercall(uint16_t code, uint16_t rep_count, + uint16_t varhead_size, + paddr_t input, paddr_t output) +{ + uint64_t control = code; + uint64_t status; + uint16_t rep_comp; + + control |= (uint64_t)varhead_size << HV_HYPERCALL_VARHEAD_OFFSET; + control |= (uint64_t)rep_count << HV_HYPERCALL_REP_COMP_OFFSET; + + do { + status = hv_do_hypercall(control, input, output); + if ( (status & HV_HYPERCALL_RESULT_MASK) != HV_STATUS_SUCCESS ) + break; + + rep_comp = (status & HV_HYPERCALL_REP_COMP_MASK) >> + HV_HYPERCALL_REP_COMP_OFFSET; + + control &= ~HV_HYPERCALL_REP_START_MASK; + control |= (uint64_t)rep_comp << HV_HYPERCALL_REP_COMP_OFFSET; + + } while ( rep_comp < rep_count ); + + return status; +} + +#endif /* __X86_HYPERV_HCALL_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ From patchwork Sun Jan 5 16:47:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11318507 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 7EB78138C for ; Sun, 5 Jan 2020 16:49:32 +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 5B5352077B for ; Sun, 5 Jan 2020 16:49:32 +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="qoANYLeO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5B5352077B 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 1io94p-0003ms-RQ; Sun, 05 Jan 2020 16:48:31 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1io94o-0003mZ-Fw for xen-devel@lists.xenproject.org; Sun, 05 Jan 2020 16:48:30 +0000 X-Inumbo-ID: 2bcd9796-2fdb-11ea-b6f1-bc764e2007e4 Received: from mail-wr1-x441.google.com (unknown [2a00:1450:4864:20::441]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 2bcd9796-2fdb-11ea-b6f1-bc764e2007e4; Sun, 05 Jan 2020 16:48:17 +0000 (UTC) Received: by mail-wr1-x441.google.com with SMTP id q6so46992760wro.9 for ; Sun, 05 Jan 2020 08:48:17 -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=/ARCb3PeIG/kpr3xyc38m7PUJesXNvhlAaIIhN3mhTE=; b=qoANYLeOghT30R0fPBO4/xMRrkYbamKNWwld+OQNb+kMPWoiars7LuIh/tyE4/dDp5 GHv94/RDrmSuWE0kbbhELFEGCtI2vhXj0C4EkYzIflTb6tyhE1Dqd38v35TKLz1oH8gf jjMwJiqqwV+xXAo8z+ahiT4Zey72Gj4ozt7dO5NKE/Ccwd8R/FwYvm3NXdx0Le3FO+mC SLDVqSvgWDRycevPgar9CV4n/r5WBWW+zW0S2WGATbwrFs25qZCW0i97tOQosCP/F7mZ qna6tc1KnncSMyDTiGx8qe8SwuwkT6vfuTcDcSkRSjKxo1P27pGsIk+RCPB1rwJgoNX7 KeVw== 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=/ARCb3PeIG/kpr3xyc38m7PUJesXNvhlAaIIhN3mhTE=; b=EtT0B10KSVJTVLPoV/S5F6Dby8bZ7hMDwXztpupAW0HnWBq2I/3+HFlrmQh3rnjwXR JAz2QtCCV9m5Qtng0Xr0mvLbIgeAK1KRa3gvLjP2QcNG7K5JkK9wTcaB+g9RBt4SXtpz lcJfCNbzG0bwq7mTQPKg1cwhjG28aH8BLQs7EiMj2VKpLjrf4y2KPMJ4hEdEv+MRDqh5 2JLCOkkmsZ1DNnhjLJZ48wJGnfjQm1HTjm/m4GkXTOPQHGet+wyo6nVM2HKLrajZ2vqX ouLrgjs+srC30C/2iWixskQwzV8NSqKL6TFVIF9hmBhfHOyKUJk7d3fBu1de5BfPjAjD TaRg== X-Gm-Message-State: APjAAAUuR0Db0HpvYiYxfPtk31/PZqnD7ZzrcqK/Cqlw9bsmYCs4dFeP TPp2XfRTMi8jCwPh46V5JFShQyKUj80= X-Google-Smtp-Source: APXvYqzJDVBX0cV6hin7+5B+KYwQ+CZTxir4dQ1XVQl5rrj28zwQ/o0VAboBKwDoenJeF4HpdE7yvQ== X-Received: by 2002:adf:fc4b:: with SMTP id e11mr33096478wrs.326.1578242896305; Sun, 05 Jan 2020 08:48:16 -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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jan 2020 08:48:15 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Sun, 5 Jan 2020 16:47:59 +0000 Message-Id: <20200105164801.26278-4-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 3/5] x86/hyperv: provide percpu hypercall input 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" Hyper-V's input / output argument must be 8 bytes aligned an not cross page boundary. The easiest way to satisfy those requirements is to use percpu page. For the foreseeable future we only need to provide input for TLB and APIC hypercalls, so skip setting up an output page. We will also need to provide an ap_setup hook for secondary cpus to setup its own input page. Signed-off-by: Wei Liu --- v3: 1. Use xenheap page instead 2. Drop page tracking structure 3. Drop Paul's review tag --- xen/arch/x86/guest/hyperv/hyperv.c | 20 ++++++++++++++++++++ xen/include/asm-x86/guest/hyperv.h | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index 381be2a68c..7e046dfc04 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -27,6 +27,7 @@ struct ms_hyperv_info __read_mostly ms_hyperv; extern char hv_hypercall_page[]; +DEFINE_PER_CPU_READ_MOSTLY(void *, hv_pcpu_input_arg); static const struct hypervisor_ops ops; const struct hypervisor_ops *__init hyperv_probe(void) @@ -83,14 +84,33 @@ static void __init setup_hypercall_page(void) wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); } +static void setup_hypercall_pcpu_arg(void) +{ + void *mapping; + + mapping = alloc_xenheap_page(); + if ( !mapping ) + panic("Failed to allocate hypercall input page for %u\n", + smp_processor_id()); + + this_cpu(hv_pcpu_input_arg) = mapping; +} + static void __init setup(void) { setup_hypercall_page(); + setup_hypercall_pcpu_arg(); +} + +static void ap_setup(void) +{ + setup_hypercall_pcpu_arg(); } static const struct hypervisor_ops ops = { .name = "Hyper-V", .setup = setup, + .ap_setup = ap_setup, }; /* diff --git a/xen/include/asm-x86/guest/hyperv.h b/xen/include/asm-x86/guest/hyperv.h index c7a7f32bd5..6cf2eab62f 100644 --- a/xen/include/asm-x86/guest/hyperv.h +++ b/xen/include/asm-x86/guest/hyperv.h @@ -51,6 +51,8 @@ static inline uint64_t hv_scale_tsc(uint64_t tsc, uint64_t scale, #ifdef CONFIG_HYPERV_GUEST +#include + #include struct ms_hyperv_info { @@ -63,6 +65,8 @@ struct ms_hyperv_info { }; extern struct ms_hyperv_info ms_hyperv; +DECLARE_PER_CPU(void *, hv_pcpu_input_arg); + const struct hypervisor_ops *hyperv_probe(void); #else From patchwork Sun Jan 5 16:48:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11318509 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 5F9C66C1 for ; Sun, 5 Jan 2020 16:49:34 +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 3C3A52077B for ; Sun, 5 Jan 2020 16:49:34 +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="Pecq2HSH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3C3A52077B 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 1io94u-0003nz-4e; Sun, 05 Jan 2020 16:48: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 1io94t-0003nm-Hm for xen-devel@lists.xenproject.org; Sun, 05 Jan 2020 16:48:35 +0000 X-Inumbo-ID: 2c464d4e-2fdb-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 2c464d4e-2fdb-11ea-a1e1-bc764e2007e4; Sun, 05 Jan 2020 16:48:18 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id a5so12670468wmb.0 for ; Sun, 05 Jan 2020 08:48:18 -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=WF8WbKtTBhS4BHGj5cB1aEH2QagI1ZAGsiQPgtzAOMw=; b=Pecq2HSHZroLPuNAiwy0aVovMUhQaNl5eW+t42s/BKtCEhQwadEAeik73V656FJISM XLkPanOOEV0CiZb26QWdY0+zcVgcladeC3NK+GaKxAaOxYpzmZEIvKwXtjDU5Dx4uOXy o/I5YPPMP/AM2vi8LO13kXcprpnlo8xFd1g78D0P9TB1PaNasF8k1XKihI269+OSsJd8 93EzXkIdz6hI5jeWPlRJhqpMWsSD+RJr6JxfST2rWEoG8V3skkHeFl2DNCLworzkD8UT BUJP0bG0pgtYyWwYtlFQpAJgCy/ksd+oQjOc+Vdc+alZVVIKwSOmANB5YFiCWG5+heH7 w1og== 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=WF8WbKtTBhS4BHGj5cB1aEH2QagI1ZAGsiQPgtzAOMw=; b=YCZoyflbz/kdu+vJgzfwUO84iLQJIZq9cxOlPo7yCGhURuogKp7imVtT9fXjPS1lBe 6aABKWE3U8UQkQB1cPWxwQ+qiTZe34L9Luao4tEETRIX9FwP0eun4f2Dxg3aABHVZM34 N/uQ77qEwcEEzBmV8Uf6Uuu2EaAd69VriqTJKxEA/mdYXhITDg6YIpsEGRE2EFMM0qii qM/UMdp4wFLEl08nJ5d+MutSbgIGqGFg/FQpTadHCGlIczuf4Zm+4puBtZ7EAboAS1Gi fws2b/5K2A9oEvGXK3mpbqPgqpWYIx1TX+vS4cVsM0++5L+H18ZS8nx7PCMMDT6VZKaA tElg== X-Gm-Message-State: APjAAAXTah0dU8W6egmB4eu1z6LKf0qDnKJIgexJzZuO3YA8oXOuxz2u 7Iyp9jRWs5H+w3XmFaY3t/3mYKzL2y4= X-Google-Smtp-Source: APXvYqx2DIQd26D44159xlchspxu/nXkZ5hTAc6k5+voMv2DpaDhI7uHFedu6PAXTvCWdOovCKxaqA== X-Received: by 2002:a1c:770e:: with SMTP id t14mr32371711wmi.101.1578242897110; Sun, 05 Jan 2020 08:48:17 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jan 2020 08:48:16 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Sun, 5 Jan 2020 16:48:00 +0000 Message-Id: <20200105164801.26278-5-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 4/5] x86/hyperv: retrieve vp_index from Hyper-V 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" This will be useful when invoking hypercall that targets specific vcpu(s). Signed-off-by: Wei Liu Reviewed-by: Paul Durrant --- v2: 1. Fold into setup_pcpu_arg function --- xen/arch/x86/guest/hyperv/hyperv.c | 5 +++++ xen/include/asm-x86/guest/hyperv.h | 1 + 2 files changed, 6 insertions(+) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index 7e046dfc04..e5f258c946 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -28,6 +28,7 @@ struct ms_hyperv_info __read_mostly ms_hyperv; extern char hv_hypercall_page[]; DEFINE_PER_CPU_READ_MOSTLY(void *, hv_pcpu_input_arg); +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, hv_vp_index); static const struct hypervisor_ops ops; const struct hypervisor_ops *__init hyperv_probe(void) @@ -87,6 +88,7 @@ static void __init setup_hypercall_page(void) static void setup_hypercall_pcpu_arg(void) { void *mapping; + uint64_t vp_index_msr; mapping = alloc_xenheap_page(); if ( !mapping ) @@ -94,6 +96,9 @@ static void setup_hypercall_pcpu_arg(void) smp_processor_id()); this_cpu(hv_pcpu_input_arg) = mapping; + + rdmsrl(HV_X64_MSR_VP_INDEX, vp_index_msr); + this_cpu(hv_vp_index) = vp_index_msr; } static void __init setup(void) diff --git a/xen/include/asm-x86/guest/hyperv.h b/xen/include/asm-x86/guest/hyperv.h index 6cf2eab62f..bae06c8a3a 100644 --- a/xen/include/asm-x86/guest/hyperv.h +++ b/xen/include/asm-x86/guest/hyperv.h @@ -66,6 +66,7 @@ struct ms_hyperv_info { extern struct ms_hyperv_info ms_hyperv; DECLARE_PER_CPU(void *, hv_pcpu_input_arg); +DECLARE_PER_CPU(unsigned int, hv_vp_index); const struct hypervisor_ops *hyperv_probe(void); From patchwork Sun Jan 5 16:48:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11318511 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 7BB00138C for ; Sun, 5 Jan 2020 16:49:40 +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 580542077B for ; Sun, 5 Jan 2020 16:49:40 +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="qqEb8PLb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 580542077B 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 1io94z-0003qc-Ig; Sun, 05 Jan 2020 16:48:41 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1io94y-0003pz-H4 for xen-devel@lists.xenproject.org; Sun, 05 Jan 2020 16:48:40 +0000 X-Inumbo-ID: 2cb8ba8c-2fdb-11ea-a914-bc764e2007e4 Received: from mail-wm1-x344.google.com (unknown [2a00:1450:4864:20::344]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 2cb8ba8c-2fdb-11ea-a914-bc764e2007e4; Sun, 05 Jan 2020 16:48:18 +0000 (UTC) Received: by mail-wm1-x344.google.com with SMTP id c127so10348821wme.1 for ; Sun, 05 Jan 2020 08:48:18 -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=z0cjj/lBQl0c9w1vDyVAOKv50SGygVYLUy39Nar8kbQ=; b=qqEb8PLbYwd+C8pWU6U9Z01IXdSrrma0roIdjxBrgKgPvumCHDa1ujNwFIaKwpE9QQ wkWkDfwCI/jYddKFQuUoYOMk+VspFVzI0bznyhSELZ6J5nDkUtLzf2442f4JW7j1YJhc Ki+M9Z4ZzwJi5rcQX1jkkQQuW6zn9CsiLyRmgsZ4MmfZwb8K+QxzZOeImGZ4QOKFMPhi JoW25wbNgKa+4ppgyQP6Cb9z7sYt2doz+yS9Vwfp0HDmn7b9uC9BHX6Ft+96CxEjr08R HbgJR4osfNI1s65vyqjI9SonmiPvRGurxRZPEMPCH0YQoSOABGuyadJ4Mtfed04mcORd KhhQ== 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=z0cjj/lBQl0c9w1vDyVAOKv50SGygVYLUy39Nar8kbQ=; b=nfQhJJzMb0rjetfPggissXHuSq6AwCa1Y92rwm4cU/ggs2hvRXDi/xbd0QflyTgYB0 fT2mLAeNZ1n2fwUc6aJ0hZut0pb4rDVp+6SF9w6h9vqNtqRbcaIa36Qo//cdpo+d9F8K 6KFw2LhtN80yCbO/XkuL/TeGKpse3ozt0q2PWZSctsri5FyelfbqTJqy8Mz6E5zv4il6 b7iDvQOR9nbFZg7L5Z77aehDOEFRydNZDXC/VkufwZPchiMRVEVZAmn0fSI+8vSAUIA1 f2T+x8RioN6AQUugBwW2aFr3tSVgC6lPkJgFuGf125bwam2cg/aM6d6tsrWU/JLkvQ3B kucg== X-Gm-Message-State: APjAAAVcKW6zLWt9+ybktgsWDjezU2LUoDji4mD9LpwECjEsFRRkTt8l Djk0AcrLAs/bozJhsKBDYekkyQBqV94= X-Google-Smtp-Source: APXvYqwzJDSMmx3E/QqOTDjHNRu3BYDa6GcOcWslL6+9+unRjR45tgun0vDm11rOLWIZGvMdNYUzzw== X-Received: by 2002:a05:600c:21c5:: with SMTP id x5mr29046737wmj.72.1578242897883; Sun, 05 Jan 2020 08:48:17 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jan 2020 08:48:17 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Sun, 5 Jan 2020 16:48:01 +0000 Message-Id: <20200105164801.26278-6-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 5/5] x86/hyperv: setup VP assist 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" VP assist page is rather important as we need to toggle some bits in it for efficient nested virtualisation. Signed-off-by: Wei Liu --- v3: 1. Use xenheap page 2. Drop set_vp_assist v2: 1. Use HV_HYP_PAGE_SHIFT instead --- xen/arch/x86/guest/hyperv/hyperv.c | 21 +++++++++++++++++++++ xen/include/asm-x86/guest/hyperv.h | 1 + 2 files changed, 22 insertions(+) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index e5f258c946..17488f8c40 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -29,6 +29,7 @@ struct ms_hyperv_info __read_mostly ms_hyperv; extern char hv_hypercall_page[]; DEFINE_PER_CPU_READ_MOSTLY(void *, hv_pcpu_input_arg); DEFINE_PER_CPU_READ_MOSTLY(unsigned int, hv_vp_index); +DEFINE_PER_CPU_READ_MOSTLY(void *, hv_vp_assist); static const struct hypervisor_ops ops; const struct hypervisor_ops *__init hyperv_probe(void) @@ -101,15 +102,35 @@ static void setup_hypercall_pcpu_arg(void) this_cpu(hv_vp_index) = vp_index_msr; } +static void setup_vp_assist(void) +{ + void *mapping; + uint64_t val; + + mapping = alloc_xenheap_page(); + if ( !mapping ) + panic("Failed to allocate vp_assist page for %u\n", + smp_processor_id()); + + clear_page(mapping); + + this_cpu(hv_vp_assist) = mapping; + val = (virt_to_mfn(mapping) << HV_HYP_PAGE_SHIFT) + | HV_X64_MSR_VP_ASSIST_PAGE_ENABLE; + wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, val); +} + static void __init setup(void) { setup_hypercall_page(); setup_hypercall_pcpu_arg(); + setup_vp_assist(); } static void ap_setup(void) { setup_hypercall_pcpu_arg(); + setup_vp_assist(); } static const struct hypervisor_ops ops = { diff --git a/xen/include/asm-x86/guest/hyperv.h b/xen/include/asm-x86/guest/hyperv.h index bae06c8a3a..2ddfd53f8c 100644 --- a/xen/include/asm-x86/guest/hyperv.h +++ b/xen/include/asm-x86/guest/hyperv.h @@ -67,6 +67,7 @@ extern struct ms_hyperv_info ms_hyperv; DECLARE_PER_CPU(void *, hv_pcpu_input_arg); DECLARE_PER_CPU(unsigned int, hv_vp_index); +DECLARE_PER_CPU(void *, hv_vp_assist); const struct hypervisor_ops *hyperv_probe(void);