Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3075354pxu; Mon, 19 Oct 2020 03:20:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdvmm9qz2TOyVZjHgexsqVxxonoji0bmVUKZm/ProJcRIrR+Pj7f1jn0ltjo2fi7jr7Ii/ X-Received: by 2002:a05:6402:1c8f:: with SMTP id cy15mr17382481edb.335.1603102835249; Mon, 19 Oct 2020 03:20:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603102835; cv=none; d=google.com; s=arc-20160816; b=inNxwMS1Kiug1LzCbOA6TVWJM9hYJgdqMVt0/QVabeAo4HpbGzc2xcPCYwYSYwIs+t nqM5RbTqRkDQT8iFB6WUkuAzAYvylciSZdOdkp4mfVminO3nudS3z2VZvkXgKK17qLeq vH3aYwWOjH0lEAIAsnBasa+0mRKUZ4jLY6VUl3rdZiuOvIgV4+PR86Kjdll+vK9bPgLH S568LBkkjnG/2dK7KLHkYS5waJmMLFJbTBphgSCf34Eniom+ev2WHg3wQjSAlhUCGrQr 90Odgw+TBk2uClSUgPQPs9sFdB6R4XBQA8uY08s8qZEUVTP7HIKTSe05fXlU4xVzAQcD E7eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=jCpHy3uFUMCZVPnnWE5/9MU9rsbVFF1/jf/pMZAVwaQ=; b=W5/WPVv7oKJ59CLywaYwoI7sn+BDfoDiT2nkReDPqsw3Qyml4yD+JswvwLPLBFLeok fRBTm3HcdHuKvTXkBcMIBgAx7TU5icE0evitSJHOshStDQ/XIe7A82ANzYC63mR1OJ0V xx6+KAP9XKm7OQnW/eZp7p2iYz+14sPR1wEVigMfVWKchAbJKu+yh7nTZC7w5r/nC61S TGRmz/XBWHAN83lgClnkmhEeKI2PwY3I+p8Sq+wmaM0KPRW27MOdDrNrRHrTRw8yEyM3 ST5fdyCrhr9HMYNOeQjfCsIIu5TL6QHZA64+8VwsCQLzxxApxChGzG10pTXgfaLw46SL SRBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id p16si7313106ejb.522.2020.10.19.03.20.12; Mon, 19 Oct 2020 03:20:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726736AbgJSGSs (ORCPT + 99 others); Mon, 19 Oct 2020 02:18:48 -0400 Received: from mga17.intel.com ([192.55.52.151]:53114 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726724AbgJSGSp (ORCPT ); Mon, 19 Oct 2020 02:18:45 -0400 IronPort-SDR: BxF1mBO/P/M1GF1pomsvn10GEaCdgtJk8qzm94a6y0faI+CnjIaplSNMCC8xE8oN1IZPFzC/Pc uZYaHY01+2Kg== X-IronPort-AV: E=McAfee;i="6000,8403,9778"; a="146835895" X-IronPort-AV: E=Sophos;i="5.77,393,1596524400"; d="scan'208";a="146835895" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2020 23:18:45 -0700 IronPort-SDR: DOOwrRxhlREUnfzF3P4fBwkTL1xx19kF8mup+GPAhbAfIsxq052ClY1rm8MR3KvikhGbQulU7W N7N6TS/K9erw== X-IronPort-AV: E=Sophos;i="5.77,393,1596524400"; d="scan'208";a="320159384" Received: from shsi6026.sh.intel.com (HELO localhost) ([10.239.147.88]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2020 23:18:38 -0700 From: shuo.a.liu@intel.com To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Greg Kroah-Hartman , "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Sean Christopherson , Yu Wang , Reinette Chatre , Shuo Liu , Yakui Zhao , Dave Hansen , Dan Williams , Fengwei Yin , Zhi Wang , Zhenyu Wang , Arvind Sankar , Peter Zijlstra , Nick Desaulniers , Segher Boessenkool Subject: [PATCH v5 04/17] x86/acrn: Introduce hypercall interfaces Date: Mon, 19 Oct 2020 14:17:50 +0800 Message-Id: <20201019061803.13298-5-shuo.a.liu@intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201019061803.13298-1-shuo.a.liu@intel.com> References: <20201019061803.13298-1-shuo.a.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shuo Liu The Service VM communicates with the hypervisor via conventional hypercalls. VMCALL instruction is used to make the hypercalls. ACRN hypercall ABI: * Hypercall number is in R8 register. * Up to 2 parameters are in RDI and RSI registers. * Return value is in RAX register. Introduce the ACRN hypercall interfaces. Because GCC doesn't support R8 register as direct register constraints, use supported constraint as input with a explicit MOV to R8 in beginning of asm. Originally-by: Yakui Zhao Signed-off-by: Shuo Liu Reviewed-by: Reinette Chatre Cc: Dave Hansen Cc: Sean Christopherson Cc: Dan Williams Cc: Fengwei Yin Cc: Zhi Wang Cc: Zhenyu Wang Cc: Yu Wang Cc: Reinette Chatre Cc: Greg Kroah-Hartman Cc: Borislav Petkov Cc: Arvind Sankar Cc: Peter Zijlstra Cc: Nick Desaulniers Cc: Segher Boessenkool --- arch/x86/include/asm/acrn.h | 54 +++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/arch/x86/include/asm/acrn.h b/arch/x86/include/asm/acrn.h index a2d4aea3a80d..03e420245505 100644 --- a/arch/x86/include/asm/acrn.h +++ b/arch/x86/include/asm/acrn.h @@ -14,4 +14,58 @@ void acrn_setup_intr_handler(void (*handler)(void)); void acrn_remove_intr_handler(void); bool acrn_is_privileged_vm(void); +/* + * Hypercalls for ACRN + * + * - VMCALL instruction is used to implement ACRN hypercalls. + * - ACRN hypercall ABI: + * - Hypercall number is passed in R8 register. + * - Up to 2 arguments are passed in RDI, RSI. + * - Return value will be placed in RAX. + * + * Because GCC doesn't support R8 register as direct register constraints, use + * supported constraint as input with a explicit MOV to R8 in beginning of asm. + */ +static inline long acrn_hypercall0(unsigned long hcall_id) +{ + long result; + + asm volatile("movl %1, %%r8d\n\t" + "vmcall\n\t" + : "=a" (result) + : "ir" (hcall_id) + : "r8", "memory"); + + return result; +} + +static inline long acrn_hypercall1(unsigned long hcall_id, + unsigned long param1) +{ + long result; + + asm volatile("movl %1, %%r8d\n\t" + "vmcall\n\t" + : "=a" (result) + : "ir" (hcall_id), "D" (param1) + : "r8", "memory"); + + return result; +} + +static inline long acrn_hypercall2(unsigned long hcall_id, + unsigned long param1, + unsigned long param2) +{ + long result; + + asm volatile("movl %1, %%r8d\n\t" + "vmcall\n\t" + : "=a" (result) + : "ir" (hcall_id), "D" (param1), "S" (param2) + : "r8", "memory"); + + return result; +} + #endif /* _ASM_X86_ACRN_H */ -- 2.28.0