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: + */