From patchwork Sun Dec 29 18:33:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11312367 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 7C4FA138C for ; Sun, 29 Dec 2019 18:35:16 +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 58C4620748 for ; Sun, 29 Dec 2019 18:35:16 +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="JgLyZz0T" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 58C4620748 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 1ildOQ-0008TC-9e; Sun, 29 Dec 2019 18:34:22 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ildOP-0008Sd-3s for xen-devel@lists.xenproject.org; Sun, 29 Dec 2019 18:34:21 +0000 X-Inumbo-ID: c73e166e-2a69-11ea-a1e1-bc764e2007e4 Received: from mail-wm1-x341.google.com (unknown [2a00:1450:4864:20::341]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c73e166e-2a69-11ea-a1e1-bc764e2007e4; Sun, 29 Dec 2019 18:33:59 +0000 (UTC) Received: by mail-wm1-x341.google.com with SMTP id u2so12582280wmc.3 for ; Sun, 29 Dec 2019 10:33:59 -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=asb9o+xNQOO3u3ZzsBKwpRrK8IPM5jQNg7xWqM9F3KI=; b=JgLyZz0TTlhU4o9sVht7VWWxB4MwDi78qPrKGJnxkdr84WHBeGEzsRQZ3n2vC+enLl 3A2yLT0aTPK8EUhUT1rer7u8iCyYG79xvZvq5DcoiRMsx7wAuYHbDyRJBmuaWcSIHdom TITyQMSlhqyECseyN4dbX3SJzK+leuMLzNKp9UiUAk0X3S6ptqBJ8wKZn6Q7XblVPnE1 zHFWeZIh8IUZGvmtxNWj7ZH9NdEKr8U6MsPy1QQhmTnuinOBFgKbPl1QOUqEGttQUwkE hhsOPHNcKyFrlBsD6kdJ6G7BI30ftu5J75l40nyK0bD1eTX2PZZ+LibszBKLR2wns0yV KPYw== 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=asb9o+xNQOO3u3ZzsBKwpRrK8IPM5jQNg7xWqM9F3KI=; b=IefAebYaNMN58zBdYtUjXW8tVRfjNv4UO/G/sNqs9Tb5L+QqglaUvP/J89mS2Ftsiv 9Drz753tf4FuXqVotXm0l/FcZqvs86zMmhh56rUTGG5Wt29edjmVqxFEuMDimDzKp7Y+ fzGFGl9rIy9yoVdmUH98Yw4GYFSRbRbtTztt9bWvEfkl5SC5d4ulTL+G6IQP3lrV6ZtB jt3+SjjU5TN7BoZya6INrs2Ga+1ETzPHQnT4lbPTkFNTODKKDQfW98T1cUq5RcpIYxGy DSO9tL/lm3VbYmpFdZ1/c9IsNrLCxvSUjjGI0pmGxt1kNfY7ZsITXiRXhtkWSaxDzFf7 NqVg== X-Gm-Message-State: APjAAAWWAlIZALjFxnYUfknEFAaqIS9WzHtttg4xwxIIfrvUF6wrL3c+ 0ULdWzyY8TrO0knPqQs+t8eYuIUOm74= X-Google-Smtp-Source: APXvYqxK16Szy+NwFppVU3dxWcnXH2X9+bWRzo14fFbTnWTN3tHw1swQbWvNuMmBQJqcKyb4HC023w== X-Received: by 2002:a1c:4e10:: with SMTP id g16mr29792019wmh.94.1577644438582; Sun, 29 Dec 2019 10:33:58 -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:58 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Sun, 29 Dec 2019 18:33:38 +0000 Message-Id: <20191229183341.14877-6-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 5/8] 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 --- xen/include/asm-x86/guest/hyperv-hypercall.h | 105 +++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 xen/include/asm-x86/guest/hyperv-hypercall.h diff --git a/xen/include/asm-x86/guest/hyperv-hypercall.h b/xen/include/asm-x86/guest/hyperv-hypercall.h new file mode 100644 index 0000000000..6017123be5 --- /dev/null +++ b/xen/include/asm-x86/guest/hyperv-hypercall.h @@ -0,0 +1,105 @@ +/****************************************************************************** + * asm-x86/guest/hyperv-hypercall.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_HYPERCALL_H__ +#define __X86_HYPERV_HYPERCALL_H__ + +#include + +#include +#include +#include + +extern void *hv_hypercall; + +static inline uint64_t hv_do_hypercall(uint64_t control, paddr_t input, paddr_t output) +{ + uint64_t status; + + if ( !hv_hypercall ) + return ~0ULL; + + asm volatile ("mov %[output], %%r8\n" + "call *%[hypercall_page]" + : "=a" (status), "+c" (control), + "+d" (input) ASM_CALL_CONSTRAINT + : [output] "rm" (output), + [hypercall_page] "m" (hv_hypercall) + : "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; + + if ( !hv_hypercall ) + return ~0ULL; + + asm volatile ("mov %[input2], %%r8\n" + "call *%[hypercall_page]" + : "=a" (status), "+c" (control), + "+d" (input1) ASM_CALL_CONSTRAINT + : [input2] "rm" (input2), + [hypercall_page] "m" (hv_hypercall) + : "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_HYPERCALL_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */