From patchwork Fri Jan 3 16:08:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11316983 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 43943138D for ; Fri, 3 Jan 2020 16:10:22 +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 203F9222C3 for ; Fri, 3 Jan 2020 16:10:22 +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="tUbHi0Dp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 203F9222C3 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 1inPVr-0005Wl-OM; Fri, 03 Jan 2020 16:09:23 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1inPVq-0005WC-LG for xen-devel@lists.xenproject.org; Fri, 03 Jan 2020 16:09:22 +0000 X-Inumbo-ID: 5b7ce030-2e43-11ea-a914-bc764e2007e4 Received: from mail-wm1-x343.google.com (unknown [2a00:1450:4864:20::343]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5b7ce030-2e43-11ea-a914-bc764e2007e4; Fri, 03 Jan 2020 16:09:02 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id p17so9045937wma.1 for ; Fri, 03 Jan 2020 08:09:02 -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=RUfnlZlwFuHWpde6sRvjxDfadwPtw2oJdC3k1kQv/fc=; b=tUbHi0DpRaYWZ3lxVGLFpcaSMEAc4PBWX+py0GYk/V1mca4StnwqTGD2Z8bGwK0gHF TP0q8tHZ1laPI1bmR1NaekYETPtGvI/oDtHmd9u0I/nTOFwudnzDUBjQ2rSAuQyfEH0X EbD4j5U0WdVJ1bOFO1IUN0bYFvMBgO0yWjWyFtadcVgF06PxsXKCxX4FrDmsmm35YuOT c/jT/Ups37cbNsCJNfZaBFqzPK5Y2tzG08cGxkiqLb1wQXLrJTF4eZ07XEhlIEou0ziz Rgu9RM3A8Ran/Goz8ne0+v3qZ1I4AmDZRM5qLX3qlx9e3RJhxNRyYS8+FktP4OMVES2t ASzQ== 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=RUfnlZlwFuHWpde6sRvjxDfadwPtw2oJdC3k1kQv/fc=; b=YLXS77vRzpJfoJ39+ceA06ITZhwkFdpk0lh+8JxadXFNy7gF5kqnQFtzqOyaolWsH+ Fp7eZtRcIz4cfnhXD02E58G4Ixun5rC8cQ2iwSO29XNCwR30jJ/2xO+BZKMAwkAssLCR jhuVk65fo2v/HPj/PUGKcVyp4cqnGUsf5YUuZ7aomUEvdW05D7CNMUtKMuoAJNAPGMSy 4ZIaDgXjqSPgcoonY7Fvr9Og5hYo5d16nWfpn81qTNT6wfKB5k0MsDKNS53p02oab+XD OlM/rEDMau2jBAaP9xaxMo0qlR4yAx4LWCj87kdgLgS2Dt/P8tME7Q2K7/O/qKVMVw+X dwEg== X-Gm-Message-State: APjAAAW5YAST86MrsxCxHquqR8BPf88pH8eicJp7KX8zYGsCs29GjPgR 7ANcS13juMadq697VC0vYbqLLOKrMg7YWA== X-Google-Smtp-Source: APXvYqxOVtQLjKCVbZacFTlx6nzgZtiAYBluSMVrihTmit9tKrvWHb/2hHm9MhvYZCCKCRH5ezfz1A== X-Received: by 2002:a7b:cf12:: with SMTP id l18mr21771776wmg.66.1578067741581; Fri, 03 Jan 2020 08:09:01 -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:01 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Fri, 3 Jan 2020 16:08:22 +0000 Message-Id: <20200103160825.19377-6-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 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 --- v2: 1. Use direct call --- xen/include/asm-x86/guest/hyperv-hypercall.h | 95 ++++++++++++++++++++ 1 file changed, 95 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..928d85ae7e --- /dev/null +++ b/xen/include/asm-x86/guest/hyperv-hypercall.h @@ -0,0 +1,95 @@ +/****************************************************************************** + * 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 + +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_HYPERCALL_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */