Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp171081pxk; Wed, 9 Sep 2020 02:11:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzD3XNXQF7hIqZQJjzovBOFzTWv+uQPEdMUGZ+Ftd5fjOGB6+4DPCXT17mtkNSM54t+tsCK X-Received: by 2002:a17:906:72d2:: with SMTP id m18mr2621634ejl.220.1599642670610; Wed, 09 Sep 2020 02:11:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599642670; cv=none; d=google.com; s=arc-20160816; b=QWe3Gaise4jl1qoPdEBJzgQ4T6ZHnpefvmG+sja0AKmfjuqljEu1LViK367hsG6Ovp TkEff4De2uL9QiJLZJ0Tq7cCLZL6PQEJxVS+5vbz3qT7mvYOC4NyXywWhSOyTnzpEwcy oE/MxQmqLq+8fpIRTlUHWw95533NHQg8FxXFt3ujvCM6ipmhvJ2m/GpRe4qPmCJXZsWd sM3SSb0rGA6bLJapO75btrPENjeT8p+FiJxybrUP/Ux8poyallKa2qmeXS2q1REn4FMs LjM0faD5ycS707Z490aRG50+1LXDeax4W6dOxunW+6M2DmcZT5e16r5xLRNVq3yaTqYz qnng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=6j0bAlixLCF0Ifi23UPvpW2LGDesfk/BUFVfeMqNZ+Q=; b=Db91DFDcTc26Dzf9eFNvNwbQFsVruW4PnzQH7yjXn4SfLfiX1V39Pv5py8t/thMhfE 0bYRm+ws0o0JCRr4qTSzL5uAqTIchLaD/7Y4SiG2375/iPHib3gM3CyQL1TYlXGQAEji gEpFj5NmCVaxvMgoLOygv15sNlN5WDeKqwOzpv2xVTDXqYKYU6wDn6p5DSORPewYmmzK fJI7w8jVHJ6cG8GD3RfFLX0ElGK9/Ofm42wYgUxZBaIf9llSE3Ns4tyVysBbHbc2tPjU pJR2s0jNbM1hSpdkl2UvaGgtWpCX4qUecayUBeIppyGRZQCMTS9pBz0x8jR6A8yI5t+E jRGA== 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 m7si1188151edq.314.2020.09.09.02.10.48; Wed, 09 Sep 2020 02:11:10 -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 S1729621AbgIIJJg (ORCPT + 99 others); Wed, 9 Sep 2020 05:09:36 -0400 Received: from mga02.intel.com ([134.134.136.20]:23145 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729413AbgIIJJZ (ORCPT ); Wed, 9 Sep 2020 05:09:25 -0400 IronPort-SDR: xacC1qa1fMVjFOgKdCT/DcLecQBlMG+q9Il+PX7x4yZ3uAipYa8il5q/P/ABYCKBdLBLmwH//P geerHtQC0HaQ== X-IronPort-AV: E=McAfee;i="6000,8403,9738"; a="146014513" X-IronPort-AV: E=Sophos;i="5.76,409,1592895600"; d="scan'208";a="146014513" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Sep 2020 02:09:24 -0700 IronPort-SDR: BY9NToljSf06TCFp1oPzyJSMWcFj5CjltF2EwqLhzTd8xQ25aHG+vntDQRTv6TP7oe/5Iqy84G 9Jy1rITGuPZg== X-IronPort-AV: E=Sophos;i="5.76,409,1592895600"; d="scan'208";a="300089962" Received: from shsi6026.sh.intel.com (HELO localhost) ([10.239.147.135]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Sep 2020 02:09:20 -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 Subject: [PATCH v3 04/17] x86/acrn: Introduce hypercall interfaces Date: Wed, 9 Sep 2020 17:08:23 +0800 Message-Id: <20200909090836.46762-5-shuo.a.liu@intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200909090836.46762-1-shuo.a.liu@intel.com> References: <20200909090836.46762-1-shuo.a.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org 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, here are two ways to use R8 in extended asm: 1) use explicit register variable as input 2) use supported constraint as input with a explicit MOV to R8 in beginning of asm The number of instructions of above two ways are same. Asm code from 1) 38: 41 b8 00 00 00 80 mov $0x80000000,%r8d 3e: 48 89 c7 mov %rax,%rdi 41: 0f 01 c1 vmcall Here, writes to the lower dword (%r8d) clear the upper dword of %r8 when the CPU is in 64-bit mode. Asm code from 2) 38: 48 89 c7 mov %rax,%rdi 3b: 49 b8 00 00 00 80 00 movabs $0x80000000,%r8 42: 00 00 00 45: 0f 01 c1 vmcall Choose 1) for code simplicity and a little bit of code size optimization. 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 --- arch/x86/include/asm/acrn.h | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/arch/x86/include/asm/acrn.h b/arch/x86/include/asm/acrn.h index a2d4aea3a80d..23a93b87edeb 100644 --- a/arch/x86/include/asm/acrn.h +++ b/arch/x86/include/asm/acrn.h @@ -14,4 +14,61 @@ 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. + */ +static inline long acrn_hypercall0(unsigned long hcall_id) +{ + register long r8 asm("r8"); + long result; + + /* Nothing can come between the r8 assignment and the asm: */ + r8 = hcall_id; + asm volatile("vmcall\n\t" + : "=a" (result) + : "r" (r8) + : ); + + return result; +} + +static inline long acrn_hypercall1(unsigned long hcall_id, + unsigned long param1) +{ + register long r8 asm("r8"); + long result; + + /* Nothing can come between the r8 assignment and the asm: */ + r8 = hcall_id; + asm volatile("vmcall\n\t" + : "=a" (result) + : "r" (r8), "D" (param1) + : ); + + return result; +} + +static inline long acrn_hypercall2(unsigned long hcall_id, + unsigned long param1, + unsigned long param2) +{ + register long r8 asm("r8"); + long result; + + /* Nothing can come between the r8 assignment and the asm: */ + r8 = hcall_id; + asm volatile("vmcall\n\t" + : "=a" (result) + : "r" (r8), "D" (param1), "S" (param2) + : ); + + return result; +} + #endif /* _ASM_X86_ACRN_H */ -- 2.28.0