Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp555489pxk; Thu, 3 Sep 2020 06:57:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLue9d9vu+2X7UrO0HYjX0OvaJkfFEssZI/SKmarkhC+jwx2taRroubBxGybRwX5mt5e9a X-Received: by 2002:aa7:da10:: with SMTP id r16mr3252842eds.333.1599141476617; Thu, 03 Sep 2020 06:57:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599141476; cv=none; d=google.com; s=arc-20160816; b=B139lSdxeqrdf//A3m5uOhjBEivUcvisTwr9DMTHAXFPc/6zhF+VqKYqjjSySfvnpn QCIq5hhjcycc1sdY4Mhn6a/FH4/tFP9XqfwBjcalpImPF9Opg7V4N6D6GvAvnpP3on5Q K6Fwfur/8ArJMr93RvseHgmtzMb99ZwX8LBCsKwdWGdchRRAeN0hzyb3JkUZ/s9nXdYt zxVrTkq7HxXd07yVsPG7o99LRhcdoctNq1PR2JZ6E6FO0bvCt1nuP8zxvkoD5/Fa1zTE y8NMuAeqCUqMoIo1x6RNsPZrQs8ikjopS1YBw8Yj8DFN6Zw3TnFhtw7VKzV4g8wZubCc pOPg== 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=Ibq1edExTDQbpVXKWeXbdXWJXpeGrDrKfqHew5QHH9DAA8byvXOvkZaQoJ+mGgxhZa 32c36OgyqailON44U4oAe9ld2m9gSNc6ryxz3CCje7TSA3p9xX/H/JNHKgGbo2Y5DKfu O6uLiSLzhd7+/w0iVPp9P8Z9S28i9d09RTqdSrK/EYm0/L4k0i4G/hrwceIDXdYO0a6J bqwT5k9ntdyxDBp/MtrfMmp9tlm3ogOt38Pt/iMVicW4m7ZV9bzMvLWAe2wHaYOje7rG WanhkmOUd1WOGR0oLeLBRhdGqwFdOnPOYMFgChtRmnCj88m5NWGuBfQZsWh7eVjfrJX0 RoOQ== 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 bh4si2101450ejb.193.2020.09.03.06.57.33; Thu, 03 Sep 2020 06:57:56 -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 S1728944AbgICNyd (ORCPT + 99 others); Thu, 3 Sep 2020 09:54:33 -0400 Received: from mga07.intel.com ([134.134.136.100]:7159 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728829AbgICMpg (ORCPT ); Thu, 3 Sep 2020 08:45:36 -0400 IronPort-SDR: 1cPOsXju1Cesy+T0ylY0tB4sHHK4YQr9RHSHRkUQr+SOxpTQJKzY6XlOvGNgRSzSK/RscIrKG2 QgEnyfndDGPQ== X-IronPort-AV: E=McAfee;i="6000,8403,9732"; a="221778316" X-IronPort-AV: E=Sophos;i="5.76,386,1592895600"; d="scan'208";a="221778316" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Sep 2020 05:42:38 -0700 IronPort-SDR: DEofIp1Eg9atdh10eiBDxOGLDIYttoMTo+osfN7aOmSUr510EM+6v1gAfj2xD5C4VYIfCrTAp7 t4tr10ouWyWQ== X-IronPort-AV: E=Sophos;i="5.76,386,1592895600"; d="scan'208";a="302194918" Received: from shsi6026.sh.intel.com (HELO localhost) ([10.239.147.135]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Sep 2020 05:42:33 -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 v2 04/17] x86/acrn: Introduce hypercall interfaces Date: Thu, 3 Sep 2020 20:41:48 +0800 Message-Id: <20200903124201.17275-5-shuo.a.liu@intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200903124201.17275-1-shuo.a.liu@intel.com> References: <20200903124201.17275-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