Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1094595lqo; Fri, 17 May 2024 10:25:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU5muJ5FT3dK4OfE1hWErKJrf0S4LeHFVUp8tniEWcK0OHcOaLCvujeZ9zav6o5Rck7pSD4dblD4fIqQx61w4V77P0T0Ekpz/JcLl3T8g== X-Google-Smtp-Source: AGHT+IF+sAbM97fVcmun/s1/c71YZZweMWHWOm8oiLlQaZto8FMX7G87gUqNpRHrrxtusKhtjP29 X-Received: by 2002:a05:6a00:3994:b0:6f4:3b76:ebf7 with SMTP id d2e1a72fcca58-6f4e02db452mr22997646b3a.20.1715966714883; Fri, 17 May 2024 10:25:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715966714; cv=pass; d=google.com; s=arc-20160816; b=gexFSFIGqz8mmej6cKSwD1zMGTROYH0K7Oz1MdgK24BeiNj+j0LzCwOh2evgV7mUf/ 7sU3vhbgFJcdeSuhXK5FD9xWd3j3Nt9eTWxcKm6DXe4Wyg6vg/9/f+TOQvhO3dINUokm TzDwax2SvVEolu+G6u1DhS7DkKkoctwU5f6xwLXrXCGlzsjmWcMjRpcZlytAp63UtRkC mbZHJTQ3pgnatrhRCtE2d79y7jJtBondal89GA7TU2AuVPz9TmHqpXZpsWJRMGgkhOAR 90LFpLFp6VjxLwevxzH3VEsMhpsrtixhl2aJQjx6KZndTAsAzeroJHc/cPkl+Tc7mt/K K/IQ== 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=Qn/bNLeqMJEdwNUDi9Xq1A7KMcLVMjzw2u1FdI5lYss=; fh=hXU1gnBYTQtxPAarsVIsRjsd20EbUeSZmvMOiujEIyU=; b=0ytCKeVtCEQhqimR89ytAUF5QDwMI6ivJ0k72TAv1RkfhdSrjxRToQMeNDHXeYphDb rmz/ZVAixiqgnINZaVu7izdq4NhqF6yAVQwx3NKcP9ohrItY/ACjqmCaOxsH7Qad3ep6 JNuG+81hHnBnvjRCKUGI6nWjIf/l85RyRbo6TdYbqezhj3QchPyCDkMg9RxX+he5ybPn bdSa/RK7Fhn5CmsmqCWQ0Rq4BtnMcE2Ytg+qa2uONWJPS+E51IpKYFPnGMKv7FHspg6E BFkBadla4kOASm5v9j5SmIKAnUmi/IJRFedSDxyOnU3FDLCYI9n30soQ36j7Gz3DxG2C bKtw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CaFquHj2; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-182185-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182185-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-63413d729c4si17998105a12.842.2024.05.17.10.25.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 10:25:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182185-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CaFquHj2; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-182185-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182185-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9D02628544C for ; Fri, 17 May 2024 14:20:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 35FE66A33C; Fri, 17 May 2024 14:20:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="CaFquHj2" 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 C61E05FDDB; Fri, 17 May 2024 14:19:59 +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=1715955601; cv=none; b=uJeavWl4qPu/oTYmwHEiN/YbT3ziaOIk9N9ExR2RmRRj43HnfXp9pnpC9Z6xNNxW2wnkr33MO7U3U46j/CYKrbhvx549N1OhI3bYwyFg/nVlrZUIY8dGp4EKOvL4CRFXRUsjEf8/Vcx581zQPQrsq0KrgEtqk9//hcmjm2NBgec= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955601; c=relaxed/simple; bh=I0Mtjx/jDkprh2/rg4I3//FBBgLnzt/nU4tXQMcZ6N0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lxAJ7h33/a93q5qy5YRW9GDTkNrHYg4LZtNYXUSi7IegfOYC7hkiLdMHHLulbjZkowukcPQL61OgUMw7Ek14zQsiwq+VlUlHmBeMa0PKcGQwqt+iaTvkTThcMKCekCpjUsxeoNcb8g6sDK2Hc6qy+NvjZ37+xUIF7wjD9hwZBAo= 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=CaFquHj2; 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=1715955600; x=1747491600; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=I0Mtjx/jDkprh2/rg4I3//FBBgLnzt/nU4tXQMcZ6N0=; b=CaFquHj2MmtYf8ZrEW6/WnD4Stl/RiwEy+u7AO6NG16nrmuEP93xC0je VBOI8isnSPWp4NRmJA3pc4Lo9rc3YP5TBHboU53CDaMS2KetMyxQgyEEM lEg6bjsyAOSLpkn00XlSJYFC1qyGLosPkp2+CPXbX5uPuYzvTW9i3Gicg 13HFAd3FtUkon+GJR8s9ksMi72h2Cf8YcloLvd5NMs91M2CV0a7YYL+jF gwLxO8ted1FYdfS+c5VjXriVZ2Q32wNR9OaSIfA0L2sCl2pXZ8VS3rFG6 14d44xxUsMjE9Wjba1rtTmke1h+qSkb6M58ij6/LorfB1dCE0S30UD0U1 g==; X-CSE-ConnectionGUID: zaWN5DMXQn6ceZBEHkHWYg== X-CSE-MsgGUID: yCDnVyWMSw2mVrEicqZyug== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808586" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808586" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2024 07:19:55 -0700 X-CSE-ConnectionGUID: LvA/bHabS/ygmoK2DUHgTw== X-CSE-MsgGUID: 3SSb0ZOZTqC4k3nnoiLN6Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="69253345" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 17 May 2024 07:19:50 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 940C4122; Fri, 17 May 2024 17:19:49 +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 01/20] x86/tdx: Introduce tdvmcall_trampoline() Date: Fri, 17 May 2024 17:19:19 +0300 Message-ID: <20240517141938.4177174-2-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 TDCALL calls are centralized into a few megawrappers that take the struct tdx_module_args as input. Most of the call sites only use a few arguments, but they have to zero out unused fields in the structure to avoid data leaks to the VMM. This leads to the compiler generating inefficient code: dozens of instructions per call site to clear unused fields of the structure. This issue can be avoided by using more targeted wrappers. tdvmcall_trampoline() provides a common base for them. The function will be used from inline assembly to handle most TDVMCALL cases. Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdcall.S | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/arch/x86/coco/tdx/tdcall.S b/arch/x86/coco/tdx/tdcall.S index 52d9786da308..12185fbd33ba 100644 --- a/arch/x86/coco/tdx/tdcall.S +++ b/arch/x86/coco/tdx/tdcall.S @@ -61,3 +61,52 @@ SYM_FUNC_END(__tdcall_ret) SYM_FUNC_START(__tdcall_saved_ret) TDX_MODULE_CALL host=0 ret=1 saved=1 SYM_FUNC_END(__tdcall_saved_ret) + +/* + * tdvmcall_trampoline() - Wrapper for TDG.VP.VMCALL. Covers common cases: up + * to five input and out arguments. + * + * tdvmcall_trampoline() function ABI is not SYSV ABI compliant. Caller has to + * deal with it. + * + * Input: + * RAX - Type of call, TDX_HYPERCALL_STANDARD for calls defined in GHCI spec + * RBX - 1st argument (R11), leaf ID if RAX is TDX_HYPERCALL_STANDARD + * RDI - 2nd argument (R12) + * RSI - 3rd argument (R13) + * RDX - 4th argument (R14) + * RCX - 5th argument (R15) + * + * Output: + * R10 - TDVMCALL error code + * R11 - Output 1 + * R12 - Output 2 + * R13 - Output 3 + * R14 - Output 4 + * R15 - Output 5 + */ +.pushsection .noinstr.text, "ax" +SYM_FUNC_START(tdvmcall_trampoline) + movq %rax, %r10 + movq %rbx, %r11 + movq %rdi, %r12 + movq %rsi, %r13 + movq %rdx, %r14 + movq %rcx, %r15 + + movq $TDG_VP_VMCALL, %rax + + /* RCX is bitmap of registers exposed to VMM on TDG.VM.VMCALL */ + movq $(TDX_R10 | TDX_R11 | TDX_R12 | TDX_R13 | TDX_R14 | TDX_R15), %rcx + + tdcall + + /* TDG.VP.VMCALL never fails on correct use. Panic if it fails. */ + testq %rax, %rax + jnz .Lpanic + + RET +.Lpanic: + ud2 +SYM_FUNC_END(tdvmcall_trampoline) +.popsection -- 2.43.0