Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp985689lqo; Fri, 17 May 2024 07:32:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVYLVKtGh92XYYJ04MBOx2R8aLR1ph58mmmbzmoaMoYVK8yVrrITlgHUGxIOI8ztjckGcO71a4LiDTk6CA9EUJ3ge7T+NqahEZdcgePBw== X-Google-Smtp-Source: AGHT+IGT+nTw2PKt2X7mFNQkqj1JHwzBMPCpDMSmtzTycNZWzSNTl5jN5QjOk7h92lI7g6JZ3Q3j X-Received: by 2002:a05:6512:ac9:b0:51d:a78e:9036 with SMTP id 2adb3069b0e04-522100691e3mr16339057e87.69.1715956336553; Fri, 17 May 2024 07:32:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715956336; cv=pass; d=google.com; s=arc-20160816; b=I88YzHFCbhmIXP0AgnjOKaz3QfaU9joxhUCtF5jaFfr9d1BgSzmrQQCkoIMj9HV5hY 4FcIcTeql8s8tHT1BzINfQXiy3tjvPsSSAnA2tyMw+GeE19lg90hG8U5lL4aLhwISyAt Ken437ED21plmWu73rGQOUsXMGhDd3eqrHrKhTyfDCTJspAiCAJC7q6sSxynukvTdZC8 S3JJ8C0kNvFPaDKE2jWB/5+s1V5ZIo+7VSfNA3gBdnmZx3/8qyibm2QNG6zxfjdbsO7S njaqxKw5W/z9wpm5w6tvS4/WozjM7LyOhspeW+j2pxsUrMClSxdHNj++YCyqu+smDQ5h 7ZxQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=5tSs0WCAyKUgpXHig/bw/b489THu7M6GIdeIdPA3WMA=; fh=hXU1gnBYTQtxPAarsVIsRjsd20EbUeSZmvMOiujEIyU=; b=z37+AAJOiCYsO6vzPzP5jiVoc7zqYKLJ1mr5oZlqD1vhS2XrPRGFvMlr31abvEStXX aS9msNlBER25989cHfAqh5v4z2tOwCgKSVP/bL88a9DbsDNJh0Fwm3xATA/Sqg1tsgaH jOyJLIvfD/u6Eu9kSU9huOltnYaFPScrbVqGBgPjYry5FVfQZb0M+3CIkK8Mn0zlIXPI 4vmNjcGkWDAxYJMMQDkxuggXrjDml27IBo9k5VsgVs7KPxSKECdRyaXJ7dFdWdhFsURU c1HCfb4i7iLEpXBjJaH08+t2NJhlIhRa3GjZPZyyZEfpgr/l+greRyk5BaBxJtrUg741 2DXg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=P4GUPNu0; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-182192-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182192-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-574eb0fe10fsi3961449a12.261.2024.05.17.07.32.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 07:32:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182192-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=P4GUPNu0; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-182192-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182192-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A01501F237A3 for ; Fri, 17 May 2024 14:22:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A69A171B5C; Fri, 17 May 2024 14:20:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="P4GUPNu0" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49B1E6CDC4; Fri, 17 May 2024 14:20:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955605; cv=none; b=hzUzhqHYOA2UzLVP4gsWNwEd3Iyq2OK+7CHf+yejWfQX0pwCljJtbId8jDRNc0IAArGx7v48L/lbNWhaujXCSy1JZt2K9OaAnLfU3tKkgor+yLPbGf13u0kh+Cm2rJ6+ZxqugwF1skxuogFpVXMgUMBqDQsAeUTpFiprsUEImq4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955605; c=relaxed/simple; bh=5axqy4K+6T0Wr5Xr0Pz3IDEsBwfGRubQ1YJfQIDNdKs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pSs6qSiaIPhBdZ+DPfN9nudkSX1GYFEJ4DmkSyJ9dQVKTEoofloJ+7PJkTkrjOxn2JNs1+I4o7V5YcYbdLPhGWX7L8XYi2X4PPq+xdl1Ryba7KU02YDhHwX8TJwWO/8/zJ940/w+zFEpZ8O8sjl2qxQyX6oi1UvL0fUyIJdJDUk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.helo=mgamail.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=P4GUPNu0; arc=none smtp.client-ip=192.198.163.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.helo=mgamail.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715955604; x=1747491604; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5axqy4K+6T0Wr5Xr0Pz3IDEsBwfGRubQ1YJfQIDNdKs=; b=P4GUPNu0BJednJpKGFhfTRFAtru9JufVHSoT/9JV99cXb4mtCAIREo0d /UnOQglNyLLLZKvT0SIPoel8O1/+oTSwOLx5WvUe8F157GYVROQIQYIkD WM5/eJGk542ji1d+9vopfA8nk9NP5sK1H9S9C6N2eYWsE6d2X6aHBqyEW 5CLcaT8Fhxi19TKhe6xk/CQmdQwYM01thqeP7Q692V3BwG3GyHLWEXGps h4kaJ3wpdHhhzdDGjzeJVZ9UXDNfsIt4Zr0OMEVBM/nv4GyDKA/HPxNNk NqLJtSqrvSfEBPDLQKf1r6/3RllSEGfCDFpvdMX9BefOdJykaodc6loxR w==; X-CSE-ConnectionGUID: MsyMNdsNSnSIvh0urfQojg== X-CSE-MsgGUID: 965inIkRSlGSn4nDuu29Yw== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808690" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808690" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2024 07:20:01 -0700 X-CSE-ConnectionGUID: hRqtC+FOTkyM3zUtVPt6Ww== X-CSE-MsgGUID: yrpJTMtzTu2OuQ/PlTOepQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="31944622" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa009.jf.intel.com with ESMTP; 17 May 2024 07:19:57 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 5E0F6F56; Fri, 17 May 2024 17:19:50 +0300 (EEST) From: "Kirill A. Shutemov" To: Sean Christopherson , Paolo Bonzini , Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Josh Poimboeuf , Peter Zijlstra Cc: linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCH 14/20] x86/tdx: Add macros to generate TDCALL wrappers Date: Fri, 17 May 2024 17:19:32 +0300 Message-ID: <20240517141938.4177174-15-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240517141938.4177174-1-kirill.shutemov@linux.intel.com> References: <20240517141938.4177174-1-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Introduce a set of macros that allow to generate wrappers for TDCALL leafs. There are three macros differentiated by number of return parameters. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/shared/tdx.h | 58 +++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/arch/x86/include/asm/shared/tdx.h b/arch/x86/include/asm/shared/tdx.h index 46c299dc9cf0..70190ebc63ca 100644 --- a/arch/x86/include/asm/shared/tdx.h +++ b/arch/x86/include/asm/shared/tdx.h @@ -80,6 +80,64 @@ #include +#define TDCALL ".byte 0x66,0x0f,0x01,0xcc\n\t" + +#define TDCALL_0(reason, in_rcx, in_rdx, in_r8, in_r9) \ +({ \ + long __ret; \ + \ + asm( \ + "movq %[r8_in], %%r8\n\t" \ + "movq %[r9_in], %%r9\n\t" \ + TDCALL \ + : "=a" (__ret), ASM_CALL_CONSTRAINT \ + : "a" (reason), "c" (in_rcx), "d" (in_rdx), \ + [r8_in] "rm" ((u64)in_r8), [r9_in] "rm" ((u64)in_r9) \ + : "r8", "r9" \ + ); \ + __ret; \ +}) + +#define TDCALL_1(reason, in_rcx, in_rdx, in_r8, in_r9, out_r8) \ +({ \ + long __ret; \ + \ + asm( \ + "movq %[r8_in], %%r8\n\t" \ + "movq %[r9_in], %%r9\n\t" \ + TDCALL \ + "movq %%r8, %[r8_out]\n\t" \ + : "=a" (__ret), ASM_CALL_CONSTRAINT, [r8_out] "=rm" (out_r8) \ + : "a" (reason), "c" (in_rcx), "d" (in_rdx), \ + [r8_in] "rm" ((u64)in_r8), [r9_in] "rm" ((u64)in_r9) \ + : "r8", "r9" \ + ); \ + __ret; \ +}) + +#define TDCALL_5(reason, in_rcx, in_rdx, in_r8, in_r9, \ + out_rcx, out_rdx, out_r8, out_r9, out_r10) \ +({ \ + long __ret; \ + \ + asm( \ + "movq %[r8_in], %%r8\n\t" \ + "movq %[r9_in], %%r9\n\t" \ + TDCALL \ + "movq %%r8, %[r8_out]\n\t" \ + "movq %%r9, %[r9_out]\n\t" \ + "movq %%r10, %[r10_out]\n\t" \ + : "=a" (__ret), ASM_CALL_CONSTRAINT, \ + "=c" (out_rcx), "=d" (out_rdx), \ + [r8_out] "=rm" (out_r8), [r9_out] "=rm" (out_r9), \ + [r10_out] "=rm" (out_r10) \ + : "a" (reason), "c" (in_rcx), "d" (in_rdx), \ + [r8_in] "rm" ((u64)in_r8), [r9_in] "rm" ((u64)in_r9) \ + : "r8", "r9", "r10" \ + ); \ + __ret; \ +}) + #define TDVMCALL_0(reason, in_r12, in_r13, in_r14, in_r15) \ ({ \ long __ret; \ -- 2.43.0