Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4431122yba; Mon, 29 Apr 2019 20:49:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqzk5Z4j5w5PG8U6uB/HnKoVPeTy01D0bfll7Sol41KtlO8VcaTFvhMESs+P3bfPTnBJJ1R4 X-Received: by 2002:a17:902:6949:: with SMTP id k9mr9235762plt.59.1556596177472; Mon, 29 Apr 2019 20:49:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556596177; cv=none; d=google.com; s=arc-20160816; b=G/dVyHRZIUSEhUT5pHkcWvnZsz5+PAd+PEWC/gr6/hmiN2UOQ/eMScPUJM69CvvkgY MjBuX6uM1fLUHVxsty7k/opiTF3IrKi8KHA+cUTDfSEwNDErtaykHBPo4fFX1FFEH+1g bsQaasfxoaWhESm+uGBUoCn9ehGptIrnO5qRteU45eAURDRep9uJsnT4u/84a6gFNyJA cz0QBp2xUb+/PGhRti11x7kQaf/GVxrSiV1N0Q93t6ntAXmvICZaqWuG8TVM/WB+tTtX thallf24Ja+TY4Sq9MgTNvVsDCp7U9VUEBhOZiISYJaa40vM1L3L1ZdTVzB6IHJ9r1/R jscg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=LPei39Vatbl7rRh0J/seWVGcQEiujeAbtbcWQDGYUdU=; b=QAq0acxeQY8Fk5q/vmMgCk62LuGqfwxyOezfXJpIdtaBzU9w8zj/JX7Cc1FPGK1aFp Zw3PibLcyOUdbNHS+08dcj9FS7pA8LIVyqhbhAin4yj7O/gyQhPaxIWfMRaXxu5GHVov hTg7tGr3bVGWHyreQVh/2VFOTMJcTZGEGPb1VihSlDVBZO0wTSWh3XQavCws4G01fXkN ssGQird5WxMXgEgImTdmvef6CrPkyCVh1vianQD6ntkTr9UMv6Ar1VSSlHrWxDCFm4Dc S1IOWAuPrCvZBGU4NBocQpfA2FkVn70chsR+J4YVMyBHbaggf26Rnk+fRrKeFbHSLsto CUvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l62si37049128pfc.65.2019.04.29.20.49.22; Mon, 29 Apr 2019 20:49:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730120AbfD3Ds1 (ORCPT + 99 others); Mon, 29 Apr 2019 23:48:27 -0400 Received: from mga18.intel.com ([134.134.136.126]:54863 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730095AbfD3DsY (ORCPT ); Mon, 29 Apr 2019 23:48:24 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Apr 2019 20:48:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,412,1549958400"; d="scan'208";a="138598254" Received: from genxtest-ykzhao.sh.intel.com ([10.239.143.71]) by orsmga008.jf.intel.com with ESMTP; 29 Apr 2019 20:48:22 -0700 From: Zhao Yakui To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: tglx@linutronix.de, bp@alien8.de, Zhao Yakui , Jason Chen CJ Subject: [PATCH v6 4/4] x86/acrn: Add hypercall for ACRN guest Date: Tue, 30 Apr 2019 11:45:26 +0800 Message-Id: <1556595926-17910-5-git-send-email-yakui.zhao@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556595926-17910-1-git-send-email-yakui.zhao@intel.com> References: <1556595926-17910-1-git-send-email-yakui.zhao@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the ACRN hypervisor is detected, the hypercall is needed so that the ACRN guest can query/config some settings. For example: it can be used to query the resources in hypervisor and manage the CPU/memory/device/ interrupt for guest operating system. Add the hypercall so that the ACRN guest can communicate with the low-level ACRN hypervisor. On x86 it is implemented with the VMCALL instruction. Co-developed-by: Jason Chen CJ Signed-off-by: Jason Chen CJ Signed-off-by: Zhao Yakui Reviewed-by: Thomas Gleixner --- V1->V2: Refine the comments for the function of acrn_hypercall0/1/2 v2->v3: Use the "vmcall" mnemonic to replace hard-code byte definition v4->v5: Use _ASM_X86_ACRN_HYPERCALL_H instead of _ASM_X86_ACRNHYPERCALL_H. Use the "VMCALL" mnemonic in comment/commit log. Uppercase r8/rdi/rsi/rax for hypercall parameter register in comment. v5->v6: Remove explicit local register variable for inline assembly --- arch/x86/include/asm/acrn_hypercall.h | 84 +++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 arch/x86/include/asm/acrn_hypercall.h diff --git a/arch/x86/include/asm/acrn_hypercall.h b/arch/x86/include/asm/acrn_hypercall.h new file mode 100644 index 0000000..5cb438e --- /dev/null +++ b/arch/x86/include/asm/acrn_hypercall.h @@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _ASM_X86_ACRN_HYPERCALL_H +#define _ASM_X86_ACRN_HYPERCALL_H + +#include + +#ifdef CONFIG_ACRN_GUEST + +/* + * Hypercalls for ACRN guest + * + * Hypercall number is passed in R8 register. + * Up to 2 arguments are passed in RDI, RSI. + * Return value will be placed in RAX. + */ + +static inline long acrn_hypercall0(unsigned long hcall_id) +{ + long result; + + /* the hypercall is implemented with the VMCALL instruction. + * volatile qualifier is added to avoid that it is dropped + * because of compiler optimization. + */ + asm volatile("movq %[hcall_id], %%r8\n\t" + "vmcall\n\t" + : "=a" (result) + : [hcall_id] "g" (hcall_id) + : "r8"); + + return result; +} + +static inline long acrn_hypercall1(unsigned long hcall_id, + unsigned long param1) +{ + long result; + + asm volatile("movq %[hcall_id], %%r8\n\t" + "vmcall\n\t" + : "=a" (result) + : [hcall_id] "g" (hcall_id), "D" (param1) + : "r8"); + + return result; +} + +static inline long acrn_hypercall2(unsigned long hcall_id, + unsigned long param1, + unsigned long param2) +{ + long result; + + asm volatile("movq %[hcall_id], %%r8\n\t" + "vmcall\n\t" + : "=a" (result) + : [hcall_id] "g" (hcall_id), "D" (param1), "S" (param2) + : "r8"); + + return result; +} + +#else + +static inline long acrn_hypercall0(unsigned long hcall_id) +{ + return -ENOTSUPP; +} + +static inline long acrn_hypercall1(unsigned long hcall_id, + unsigned long param1) +{ + return -ENOTSUPP; +} + +static inline long acrn_hypercall2(unsigned long hcall_id, + unsigned long param1, + unsigned long param2) +{ + return -ENOTSUPP; +} +#endif /* CONFIG_ACRN_GUEST */ +#endif /* _ASM_X86_ACRN_HYPERCALL_H */ -- 2.7.4