From nobody Wed Feb 11 01:26:15 2026 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="CaFquHj2" 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: quoted-printable Content-Type: text/plain; charset="utf-8" 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=3D0 ret=3D1 saved=3D1 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 ha= s to + * deal with it. + * + * Input: + * RAX - Type of call, TDX_HYPERCALL_STANDARD for calls defined in GHCI sp= ec + * 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 --=20 2.43.0 From nobody Wed Feb 11 01:26:15 2026 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 70AAB5FDA5; 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=1715955600; cv=none; b=iT+oIeDCX/JO3Y4EJdEwpagjR99mDy4ltRpbYiAuxaaUDF1ZG2/ylURHVEmi0ikQ0yBwyWGd0PKh/pwwir4TBt7A9PyHn8fm/+Er6RfSNGW2qkYh/wqTdtsi+7advCVMGZiKZzp/QhhJjS9Zud9KrWIVcFoU/xISTEDzOiBIP4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955600; c=relaxed/simple; bh=bZilNGVw8GXYGxLxRYDja6LYOeRiibYaLxUxsni4eow=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q6BK6r1FWMi3wNvLwpfA94GZvra13baL5yDFrDs7GBhgfNsTFsgk0ENZOS9BUupmLcYQHORfjXnjJyMwl1sV8GIxnZNynfcdnbh0+GijzPtjcJmMV9kfrw9oXJ7rsrfeIYm9LP533HFVvwpa1pVHnY/y5t9Lq1R6n+gPZokPzw4= 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=lMSBqwi4; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="lMSBqwi4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715955599; x=1747491599; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bZilNGVw8GXYGxLxRYDja6LYOeRiibYaLxUxsni4eow=; b=lMSBqwi4WfG6ETEkI1JZXZcqlrH6KrSSwSVl+dVwK+bXMBtqqknyK76V NIxCdZwnu2RRCPsNTp+4QRBkj2o1YyJ/z59ot7oDnJ4Immn8/J1I4AYdz ylt2X+3xE1GIyqTmZK4h066tHwJ36H3Y07TkwVO4uXHswtca7Vl4ozfTX a/9+5loPyn9IrN4J/bXPqfKtflhNqkqSLPr58BWuFwZpNHoGZ0I8EgbqE 75Tkrdb0kj/XSkjHJbevc/GngHyymhQQcW+K6M7ALl2n/jq1RjdJ1PEaU hxUa2Jh5AYR1UA0XMn4MePnF6LMoNpKuX1rgtbXE/lnU4WQzVLnEEug7I A==; X-CSE-ConnectionGUID: +XR0d0mKTuy5yGhgdzQSPw== X-CSE-MsgGUID: maSgJuqORu2llOyduAjwlw== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808597" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808597" 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: 3AIT/8JQT1CLr++1r11kTA== X-CSE-MsgGUID: jF4VjyVnTNu8IdmSTVuKvQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="69253346" 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 A91EF9F6; 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 02/20] x86/tdx: Add macros to generate TDVMCALL wrappers Date: Fri, 17 May 2024 17:19:20 +0300 Message-ID: <20240517141938.4177174-3-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: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce a set of macros that allow to generate wrappers for TDVMCALL leafs. The macros uses tdvmcall_trmapoline() and provides SYSV-complaint ABI on top of it. There are three macros differentiated by number of return parameters. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/shared/tdx.h | 54 +++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/arch/x86/include/asm/shared/tdx.h b/arch/x86/include/asm/share= d/tdx.h index 89f7fcade8ae..ddf2cc4a45da 100644 --- a/arch/x86/include/asm/shared/tdx.h +++ b/arch/x86/include/asm/shared/tdx.h @@ -76,6 +76,60 @@ =20 #include =20 +#define TDVMCALL_0(reason, in_r12, in_r13, in_r14, in_r15) \ +({ \ + long __ret; \ + \ + asm( \ + "call tdvmcall_trampoline\n\t" \ + "movq %%r10, %[r10_out]\n\t" \ + : [r10_out] "=3Dr" (__ret), ASM_CALL_CONSTRAINT \ + : "a" (TDX_HYPERCALL_STANDARD), "b" (reason), \ + "D" (in_r12), "S"(in_r13), "d"(in_r14), "c" (in_r15) \ + : "r12", "r13", "r14", "r15" \ + ); \ + __ret; \ +}) + +#define TDVMCALL_1(reason, in_r12, in_r13, in_r14, in_r15, out_r11) \ +({ \ + long __ret; \ + \ + asm( \ + "call tdvmcall_trampoline\n\t" \ + "movq %%r10, %[r10_out]\n\t" \ + "movq %%r11, %[r11_out]\n\t" \ + : [r10_out] "=3Dr" (__ret), [r11_out] "=3Dr" (out_r11), \ + ASM_CALL_CONSTRAINT \ + : "a" (TDX_HYPERCALL_STANDARD), "b" (reason), \ + "D" (in_r12), "S"(in_r13), "d"(in_r14), "c" (in_r15) \ + : "r10", "r11", "r12", "r13", "r14", "r15" \ + ); \ + __ret; \ +}) + +#define TDVMCALL_4(reason, in_r12, in_r13, in_r14, in_r15, \ + out_r12, out_r13, out_r14, out_r15) \ +({ \ + long __ret; \ + \ + asm( \ + "call tdvmcall_trampoline\n\t" \ + "movq %%r10, %[r10_out]\n\t" \ + "movq %%r12, %[r12_out]\n\t" \ + "movq %%r13, %[r13_out]\n\t" \ + "movq %%r14, %[r14_out]\n\t" \ + "movq %%r15, %[r15_out]\n\t" \ + : [r10_out] "=3Dr" (__ret), ASM_CALL_CONSTRAINT, \ + [r12_out] "=3Dr" (out_r12), [r13_out] "=3Dr" (out_r13), \ + [r14_out] "=3Dr" (out_r14), [r15_out] "=3Dr" (out_r15) \ + : "a" (TDX_HYPERCALL_STANDARD), "b" (reason), \ + "D" (in_r12), "S"(in_r13), "d"(in_r14), "c" (in_r15) \ + : "r10", "r12", "r13", "r14", "r15" \ + ); \ + __ret; \ +}) + /* * Used in __tdcall*() to gather the input/output registers' values of the * TDCALL instruction when requesting services from the TDX module. This i= s a --=20 2.43.0 From nobody Wed Feb 11 01:26:15 2026 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 4F7BE5D49A; Fri, 17 May 2024 14:19:58 +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=1715955599; cv=none; b=KCLxiG6BL5K+AUXfx6dmIc29kJOQD2t0iVRMlV4aqAbnDfFjXmDHh35h8rCfFRACSHYhffJ58H8DJ+WUgPqBSdHX5hL9Yru/CpnQwLp9bFu5oIjRR7vmay97Wgh3wrp1X66PVY10GAVvIQvAydJ1FIixFlu6yoKSfpZGnCPRwwQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955599; c=relaxed/simple; bh=V+o4+Ha3FKRn9857krkLJDLMciI8lqvyQSf3/EAKodM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D/Hmewgd4TO6ZVIhCJZEV4SO/PVYEyDciB+5tDsSMtzeYrpU758tdcA/e7dGFjI92jxpqN82y7HUahdi5vh+frVTuN1khcWDAgLKTdSKZJ22CgeUIsOGwZeUUVQVPrnFmdRCtKRzwfO5eBSYhWDcmgLY6yEmmk2N/7e6QRUkcaM= 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=Q7S9Uijp; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Q7S9Uijp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715955598; x=1747491598; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=V+o4+Ha3FKRn9857krkLJDLMciI8lqvyQSf3/EAKodM=; b=Q7S9UijpiB5R7Sj3pVC/XgAb5fQImZjNteR/qiqeDy+gagxm4i3jLkjb IwcSTXQ6D2ZIEnmifOhOipljGOpNcY5LhX29aaqz8jf56FRHoSfh8Qq7o HWtXTWJZuP+/4AB7DQzz358qzl+i4gBgh1hk9vcZDh9ZVYVOstC+NfvpN KBOW0pA2VvCd5KHwPjW/TL/mnRiYpDJ1emJPXZ+ZY3AZl1LB6xiLOCqGo 4fdTUp13CIesGxv4DW3tTY7LQCZWBvFdYpLdmmGce8tD/Bzlzl+mYWa5F WJIv5gYacOMqYycP8O9jrM+9EByNGnqB6TsGyuKlhxuqIt8hebLvionjO Q==; X-CSE-ConnectionGUID: Dg+ZIbNJQeW/Uvp/tV1QJQ== X-CSE-MsgGUID: yaH+BUimSmWsUJlfzcsA8g== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808576" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808576" 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: /GvqC1X0Samm8onB6nNcgA== X-CSE-MsgGUID: YvXG09S8RqCsj/kVS9vgrA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="69253343" 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 B086B97D; 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 03/20] x86/tdx: Convert port I/O handling to use new TDVMCALL macros Date: Fri, 17 May 2024 17:19:21 +0300 Message-ID: <20240517141938.4177174-4-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: quoted-printable Content-Type: text/plain; charset="utf-8" Use newly introduced TDVMCALL_0() and TDVMCALL_1() instead of __tdx_hypercall() to handle port I/O in TDX guest. It cuts handle_io() size in half: Function old new delta handle_io 436 202 -234 Signed-off-by: Kirill A. Shutemov --- arch/x86/boot/compressed/tdx.c | 26 +++++++------------------- arch/x86/coco/tdx/tdx.c | 23 +++++++---------------- arch/x86/include/asm/shared/tdx.h | 4 ++++ 3 files changed, 18 insertions(+), 35 deletions(-) diff --git a/arch/x86/boot/compressed/tdx.c b/arch/x86/boot/compressed/tdx.c index 8451d6a1030c..0ae05edc7d42 100644 --- a/arch/x86/boot/compressed/tdx.c +++ b/arch/x86/boot/compressed/tdx.c @@ -18,32 +18,20 @@ void __tdx_hypercall_failed(void) =20 static inline unsigned int tdx_io_in(int size, u16 port) { - struct tdx_module_args args =3D { - .r10 =3D TDX_HYPERCALL_STANDARD, - .r11 =3D hcall_func(EXIT_REASON_IO_INSTRUCTION), - .r12 =3D size, - .r13 =3D 0, - .r14 =3D port, - }; + u64 out; =20 - if (__tdx_hypercall(&args)) + if (TDVMCALL_1(hcall_func(EXIT_REASON_IO_INSTRUCTION), + size, TDX_PORT_READ, port, 0, out)) { return UINT_MAX; + } =20 - return args.r11; + return out; } =20 static inline void tdx_io_out(int size, u16 port, u32 value) { - struct tdx_module_args args =3D { - .r10 =3D TDX_HYPERCALL_STANDARD, - .r11 =3D hcall_func(EXIT_REASON_IO_INSTRUCTION), - .r12 =3D size, - .r13 =3D 1, - .r14 =3D port, - .r15 =3D value, - }; - - __tdx_hypercall(&args); + TDVMCALL_0(hcall_func(EXIT_REASON_IO_INSTRUCTION), + size, TDX_PORT_WRITE, port, value); } =20 static inline u8 tdx_inb(u16 port) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index cadd583d6f62..6e0e5648ebd1 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -21,10 +21,6 @@ #define EPT_READ 0 #define EPT_WRITE 1 =20 -/* Port I/O direction */ -#define PORT_READ 0 -#define PORT_WRITE 1 - /* See Exit Qualification for I/O Instructions in VMX documentation */ #define VE_IS_IO_IN(e) ((e) & BIT(3)) #define VE_GET_IO_SIZE(e) (((e) & GENMASK(2, 0)) + 1) @@ -612,14 +608,7 @@ static int handle_mmio(struct pt_regs *regs, struct ve= _info *ve) =20 static bool handle_in(struct pt_regs *regs, int size, int port) { - struct tdx_module_args args =3D { - .r10 =3D TDX_HYPERCALL_STANDARD, - .r11 =3D hcall_func(EXIT_REASON_IO_INSTRUCTION), - .r12 =3D size, - .r13 =3D PORT_READ, - .r14 =3D port, - }; - u64 mask =3D GENMASK(BITS_PER_BYTE * size, 0); + u64 mask, out; bool success; =20 /* @@ -627,12 +616,14 @@ static bool handle_in(struct pt_regs *regs, int size,= int port) * in TDX Guest-Host-Communication Interface (GHCI) section titled * "TDG.VP.VMCALL". */ - success =3D !__tdx_hypercall(&args); + success =3D !TDVMCALL_1(hcall_func(EXIT_REASON_IO_INSTRUCTION), + size, TDX_PORT_READ, port, 0, out); =20 /* Update part of the register affected by the emulated instruction */ + mask =3D GENMASK(BITS_PER_BYTE * size, 0); regs->ax &=3D ~mask; if (success) - regs->ax |=3D args.r11 & mask; + regs->ax |=3D out & mask; =20 return success; } @@ -646,8 +637,8 @@ static bool handle_out(struct pt_regs *regs, int size, = int port) * in TDX Guest-Host-Communication Interface (GHCI) section titled * "TDG.VP.VMCALL". */ - return !_tdx_hypercall(hcall_func(EXIT_REASON_IO_INSTRUCTION), size, - PORT_WRITE, port, regs->ax & mask); + return !TDVMCALL_0(hcall_func(EXIT_REASON_IO_INSTRUCTION), + size, TDX_PORT_WRITE, port, regs->ax & mask); } =20 /* diff --git a/arch/x86/include/asm/shared/tdx.h b/arch/x86/include/asm/share= d/tdx.h index ddf2cc4a45da..46c299dc9cf0 100644 --- a/arch/x86/include/asm/shared/tdx.h +++ b/arch/x86/include/asm/shared/tdx.h @@ -72,6 +72,10 @@ #define TDX_PS_1G 2 #define TDX_PS_NR (TDX_PS_1G + 1) =20 +/* Port I/O direction */ +#define TDX_PORT_READ 0 +#define TDX_PORT_WRITE 1 + #ifndef __ASSEMBLY__ =20 #include --=20 2.43.0 From nobody Wed Feb 11 01:26:15 2026 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 E90975C61C; Fri, 17 May 2024 14:19:57 +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=1715955599; cv=none; b=sQm8paT+0BpK7Zmi/s0DB2qmbZblBePJMFzEP+io+Sgevh9k2vhWQuL+otD81cwv//RgJdblPXYU49SyROZxSFiLdwFrRNj6ezyQfbeyfr9v+kr/PDvc+tTwzxwNwfMF//WYaCQinPlsVIkSNtEj5Rmybd70FbKbZHB/GJ+GGg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955599; c=relaxed/simple; bh=gUQwV2IPZDrjdWlz6cSzIXD3iiQavq2X5QqqGPE9TCs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BthUPtmib0yGSclx0X9/be+jYMcwAWn/J4JA8rh7BxOJeTlsuWkQz4SGH/isAaR66t0b26Fdtr57yWNsZMzUDGvAh06JYOYl9xQJBA0KdHxoZo2Ic2HVHSaueUxzq3l4CYRPXLrBrZFi51OfyhlfyoWlpDQsuNEE+GRnlxv9cMg= 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=Y3PbA2Jc; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Y3PbA2Jc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715955598; x=1747491598; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gUQwV2IPZDrjdWlz6cSzIXD3iiQavq2X5QqqGPE9TCs=; b=Y3PbA2JcX/DXkFNLBQ/5p9L92wx6q0WSjxd5QpBvqpoeL9YZ5sr7vjot 3/hxSM9IbqdNtOlZhc3ZIC/CcGgku/8s8/GkPkctaW/IHFnJcy79JXSWC s6CZY2svQlM3iYN7G6WirzWNRy+0/uwgt07xyj1lUCPaTZ0GZWRrV7ukP yhUH5A2nGQyV2F8NH88nsSrsGsEtl3VXyT/xUml3zHX8Mkji8exie/ivP j+TNo6p2N4O12PcEyAvr0AaMktnRqiHbN3mF3FIs+ZADSi5ssm2df+EXm +zAPL73GToaCuRrVNMGMNj9yeW3owWcG3ktpLxrDUKhPuOJ6OU5N0ZqqR Q==; X-CSE-ConnectionGUID: O3PJM71dQoWEce1tQEwS3w== X-CSE-MsgGUID: mLaoq83mTpqqFla74z4+4Q== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808563" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808563" 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:19:55 -0700 X-CSE-ConnectionGUID: o5lTv1OzQjC7OWiR8ekdMA== X-CSE-MsgGUID: fb+T84JAQ2+KBcIRl2f4eg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="31944606" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa009.jf.intel.com with ESMTP; 17 May 2024 07:19:51 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id C299BAFB; 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 04/20] x86/tdx: Convert HLT handling to use new TDVMCALL_0() Date: Fri, 17 May 2024 17:19:22 +0300 Message-ID: <20240517141938.4177174-5-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: quoted-printable Content-Type: text/plain; charset="utf-8" Use newly introduced TDVMCALL_0() instead of __tdx_hypercall() to handle HLT instruction emulation. It cuts code bloat substantially: Function old new delta tdx_safe_halt 58 88 +30 tdx_handle_virt_exception 2023 2052 +29 __pfx___halt 16 - -16 __halt 171 - -171 Total: Before=3D6350, After=3D6222, chg -2.02% Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdx.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 6e0e5648ebd1..dce7d6f9f895 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -350,18 +350,12 @@ static int ve_instr_len(struct ve_info *ve) } } =20 -static u64 __cpuidle __halt(const bool irq_disabled) +static int handle_halt(struct ve_info *ve) { - struct tdx_module_args args =3D { - .r10 =3D TDX_HYPERCALL_STANDARD, - .r11 =3D hcall_func(EXIT_REASON_HLT), - .r12 =3D irq_disabled, - }; - /* * Emulate HLT operation via hypercall. More info about ABI * can be found in TDX Guest-Host-Communication Interface - * (GHCI), section 3.8 TDG.VP.VMCALL. + * (GHCI), section TDG.VP.VMCALL. * * The VMM uses the "IRQ disabled" param to understand IRQ * enabled status (RFLAGS.IF) of the TD guest and to determine @@ -370,14 +364,7 @@ static u64 __cpuidle __halt(const bool irq_disabled) * can keep the vCPU in virtual HLT, even if an IRQ is * pending, without hanging/breaking the guest. */ - return __tdx_hypercall(&args); -} - -static int handle_halt(struct ve_info *ve) -{ - const bool irq_disabled =3D irqs_disabled(); - - if (__halt(irq_disabled)) + if (TDVMCALL_0(hcall_func(EXIT_REASON_HLT), irqs_disabled(), 0, 0, 0)) return -EIO; =20 return ve_instr_len(ve); @@ -385,13 +372,9 @@ static int handle_halt(struct ve_info *ve) =20 void __cpuidle tdx_safe_halt(void) { - const bool irq_disabled =3D false; - - /* - * Use WARN_ONCE() to report the failure. - */ - if (__halt(irq_disabled)) - WARN_ONCE(1, "HLT instruction emulation failed\n"); + /* See comment in handle_halt() */ + WARN_ONCE(TDVMCALL_0(hcall_func(EXIT_REASON_HLT), false, 0, 0, 0), + "HLT instruction emulation failed"); } =20 static int read_msr(struct pt_regs *regs, struct ve_info *ve) --=20 2.43.0 From nobody Wed Feb 11 01:26:15 2026 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 E6C1061694; Fri, 17 May 2024 14:20:00 +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=1715955602; cv=none; b=nnL6UdK1q/7aklS9OL+1uR4dmQtV9UrWEIWlOBA7FeMlO1d4yhGIPHmIUqHA491BoMntE7+X7rZSruBvhnv01EWqVIpCO4dsYiuVfV6D48KG6KiR60yFNW7v7gpxfYJverHBq4sDSwtNGgUBzHmWPT/MJZe/xVyoJ8f7Pdv9agA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955602; c=relaxed/simple; bh=9o7OkNWhk4M5OjqgrrOwQuKgzxn4CUBaIjbPSPykHS4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cetbAIkq8hnowhAg1LKDlRd1LWRBBBjMn1dWEVODXhp+BhVpq5kiljbbIHe8bgzAQ5+hRouF+TLn7Wfj/TdxxGHF7fZZB1NehILu/Efgk9J678VrG2OoPq2ETlHjsi03H2c4YsZuqPRfBFdB56Qdcyr0sx4E5COlJ/xFyyapH2g= 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=MnYNdrRH; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MnYNdrRH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715955601; x=1747491601; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9o7OkNWhk4M5OjqgrrOwQuKgzxn4CUBaIjbPSPykHS4=; b=MnYNdrRHV1Y7iKeb+qMPtn8O4YaqY2bW+JuP+7QRW8aAKWs3XWe7U34i dngtM7wQMWpAdXdn/oNaTOCEymGX4XpO3FOW2jJDXuGGmvbUog/ejvGjm lXfvVGKm0S5tVDdHHLFlmTVV48rcxweUmBmBuBRYCoqhEr7MTK8eDYZfm 3cBfWEFMLs5PssmcNhUgiyihci886pYJXNr/OZfooYVW2EfCe0sitimHC TChlr+9/g3w2VM8AaLPPkmNHXx3DQr7+O7QLKkCMyShkmhTE/xm2kWE9O kGylq0WV94KZ7PdbItNQgcTScWIgg1IGOFXRW9Y1A7MpvQSex/Krogil3 w==; X-CSE-ConnectionGUID: +pNCB1DYQdiQIVK7aZD9Mg== X-CSE-MsgGUID: 2ifYq6vCTqahhvFy5Es+Tw== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808620" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808620" 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:00 -0700 X-CSE-ConnectionGUID: ttjwq58OTeayZh8UADZ9+Q== X-CSE-MsgGUID: GVV75GydQySnzWchBoQHbg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="31944615" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa009.jf.intel.com with ESMTP; 17 May 2024 07:19:56 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id CE720C04; 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 05/20] x86/tdx: Convert MSR read handling to use new TDVMCALL_1() Date: Fri, 17 May 2024 17:19:23 +0300 Message-ID: <20240517141938.4177174-6-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: quoted-printable Content-Type: text/plain; charset="utf-8" Use newly introduced TDVMCALL_1() instead of __tdx_hypercall() to handle MSR read emulation. It cuts code bloat substantially: Function old new delta tdx_handle_virt_exception 2052 1947 -105 Signed-off-by: Kirill A. Shutemov Acked-by: Wei Liu --- arch/x86/coco/tdx/tdx.c | 15 +++++++-------- arch/x86/hyperv/ivm.c | 10 ++-------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index dce7d6f9f895..32c519d096de 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -379,22 +379,21 @@ void __cpuidle tdx_safe_halt(void) =20 static int read_msr(struct pt_regs *regs, struct ve_info *ve) { - struct tdx_module_args args =3D { - .r10 =3D TDX_HYPERCALL_STANDARD, - .r11 =3D hcall_func(EXIT_REASON_MSR_READ), - .r12 =3D regs->cx, - }; + u64 val; =20 /* * Emulate the MSR read via hypercall. More info about ABI * can be found in TDX Guest-Host-Communication Interface * (GHCI), section titled "TDG.VP.VMCALL". */ - if (__tdx_hypercall(&args)) + if (TDVMCALL_1(hcall_func(EXIT_REASON_MSR_READ), + regs->cx, 0, 0, 0, val)) { return -EIO; + } + + regs->ax =3D lower_32_bits(val); + regs->dx =3D upper_32_bits(val); =20 - regs->ax =3D lower_32_bits(args.r11); - regs->dx =3D upper_32_bits(args.r11); return ve_instr_len(ve); } =20 diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index b4a851d27c7c..3e2cbfb2203d 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -399,18 +399,12 @@ static void hv_tdx_msr_write(u64 msr, u64 val) =20 static void hv_tdx_msr_read(u64 msr, u64 *val) { - struct tdx_module_args args =3D { - .r10 =3D TDX_HYPERCALL_STANDARD, - .r11 =3D EXIT_REASON_MSR_READ, - .r12 =3D msr, - }; + u64 ret; =20 - u64 ret =3D __tdx_hypercall(&args); + ret =3D TDVMCALL_1(hcall_func(EXIT_REASON_MSR_READ), msr, 0, 0, 0, *val); =20 if (WARN_ONCE(ret, "Failed to emulate MSR read: %lld\n", ret)) *val =3D 0; - else - *val =3D args.r11; } =20 u64 hv_tdx_hypercall(u64 control, u64 param1, u64 param2) --=20 2.43.0 From nobody Wed Feb 11 01:26:15 2026 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 E77D56024B; 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=o0ZDC8bDokFascb4zrOm7da/Uegea7KaK/yZB40esYc/YGUDSy2WOMPN6+VDyDCsl7w0cT/9EEO1ydPOdvza52vipRVkPMoDtKOfc0g1hlPkw4B4re1M8qm1gH8GkSdgMzKwuTeDq6c4tjpYHeily9R8rBBnBjRkSAzD5mkUnkY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955601; c=relaxed/simple; bh=C22Kxw6sw8vKzGrlwtwyA3njMblbtBv6zILkHx7dXVQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hh6WGZhrbnPpV0Ci2b9o+wOEnk1QZDIcwgjQk65V4CDi07mcaVCU5Yc/QR7i0yde0Dib4cBamLRNivpIr8sSN+JbvvgoOYruifduGZfQDEcTYtSNj+wLv7EGF2bSQFuqQJQqiTN8iz6z0qv0P8TnWpg4nl57uPYQR9jMAWU7rQ4= 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=cfZGWAD/; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="cfZGWAD/" 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=C22Kxw6sw8vKzGrlwtwyA3njMblbtBv6zILkHx7dXVQ=; b=cfZGWAD/+kpV83pHG0qYw/YTYX39kFo/PUuNakrmYGaXLFnLW/wF97Od qNn2rT7aR/9z+al1eZWd9gG8pyXHZRgiDRQ5uj55/VfJlKB5YaqzU+Gn4 95JTAH+Vzp/QepdaCU0Nioy2eN5GCoWczhlHnJEyAqr9Q89pPkVuuUdBI fHlHDf5/B43x/x1DQoC3Q8fuI9HAoVBHIrWus6kkc7lod6tr+re6j32uq dbiCP0dPfG8ytL0hDx3Ir4QLmAmQE1XX9/FkGhz7MtOg4i0rGIeaBD7oL ZXFvkabk82RMJxdgbFtlnPi+KiB7JajSG1W0EhQRG0GUCyW3ITYLBOyMo g==; X-CSE-ConnectionGUID: yjNnK90jSGKtMY4N4OHp1w== X-CSE-MsgGUID: JBD6cxc9TFq6hou8nCvk0A== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808611" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808611" 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:20:00 -0700 X-CSE-ConnectionGUID: eaFtlg1vR2Cyl5mlkS8bqA== X-CSE-MsgGUID: kCX6iRTtR7iVkWQawvVEgw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="69253380" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 17 May 2024 07:19:55 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id DEBC4C4D; 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 06/20] x86/tdx: Convert MSR write handling to use new TDVMCALL_0() Date: Fri, 17 May 2024 17:19:24 +0300 Message-ID: <20240517141938.4177174-7-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: quoted-printable Content-Type: text/plain; charset="utf-8" Use newly introduced TDVMCALL_0() instead of __tdx_hypercall() to handle MSR write emulation. It cuts code bloat substantially: Function old new delta tdx_handle_virt_exception 1947 1819 -128 Signed-off-by: Kirill A. Shutemov Acked-by: Wei Liu --- arch/x86/coco/tdx/tdx.c | 9 ++------- arch/x86/hyperv/ivm.c | 9 ++------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 32c519d096de..f59a2b3500db 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -399,19 +399,14 @@ static int read_msr(struct pt_regs *regs, struct ve_i= nfo *ve) =20 static int write_msr(struct pt_regs *regs, struct ve_info *ve) { - struct tdx_module_args args =3D { - .r10 =3D TDX_HYPERCALL_STANDARD, - .r11 =3D hcall_func(EXIT_REASON_MSR_WRITE), - .r12 =3D regs->cx, - .r13 =3D (u64)regs->dx << 32 | regs->ax, - }; + u64 val =3D (u64)regs->dx << 32 | regs->ax; =20 /* * Emulate the MSR write via hypercall. More info about ABI * can be found in TDX Guest-Host-Communication Interface * (GHCI) section titled "TDG.VP.VMCALL". */ - if (__tdx_hypercall(&args)) + if (TDVMCALL_0(hcall_func(EXIT_REASON_MSR_WRITE), regs->cx, val, 0, 0)) return -EIO; =20 return ve_instr_len(ve); diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 3e2cbfb2203d..18d0892d9fc4 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -385,14 +385,9 @@ static inline void hv_ghcb_msr_read(u64 msr, u64 *valu= e) {} #ifdef CONFIG_INTEL_TDX_GUEST static void hv_tdx_msr_write(u64 msr, u64 val) { - struct tdx_module_args args =3D { - .r10 =3D TDX_HYPERCALL_STANDARD, - .r11 =3D EXIT_REASON_MSR_WRITE, - .r12 =3D msr, - .r13 =3D val, - }; + u64 ret; =20 - u64 ret =3D __tdx_hypercall(&args); + ret =3D TDVMCALL_0(hcall_func(EXIT_REASON_MSR_WRITE), msr, val, 0, 0); =20 WARN_ONCE(ret, "Failed to emulate MSR write: %lld\n", ret); } --=20 2.43.0 From nobody Wed Feb 11 01:26:15 2026 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 84C806A353; Fri, 17 May 2024 14:20:02 +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=1715955604; cv=none; b=Jw4iFfoetF3gKlnVE2adUlbe5sJkx1KGVNrHCyQpoENLlSCWXhRc8RWWyGHOo6SYw9s7Ey2ENCXtDrtATVYgCDoN3/SLw27Gq1UQ9OEBE0eOBR06hPHIe58/lBMWzuCeMpA92HaF6s5WKCgVzVNtjsIBn0vLTKCnynYXd6BJ3CQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955604; c=relaxed/simple; bh=mwZWrFqPlAATgrpluzFmNP8LOZ2SkfC+w1PDY7N0GkI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fJe13V1JFvkOIBGnPbDnGXl8Lhdub9oYxSBDnfvmJBtpPT30W0QujV97oTb+x6JolY5JsdWlNxok475P57VpMuxUSr0j8BPXRTQxH7oj7dPUQZF9hk/9zbSHrJpoR2ADqs0yWPHXTluVLt7rEUFxW0dbwr6ENgJ6Sm5Jv4JudlA= 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=b5jGO0Pw; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="b5jGO0Pw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715955603; x=1747491603; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mwZWrFqPlAATgrpluzFmNP8LOZ2SkfC+w1PDY7N0GkI=; b=b5jGO0Pwvig4hkqyQ8EH7jMxAQwjZWo2Nb9Lr2kp0M6a4G+Zr7hGD2Tl q2dWa5mfSbX6Vl93vNAv3tq5k/BBQ5cunhGVOZryO5JreOffTDKX8reUl 1KRycxXkTvy7MYnfCVl5BbcVWMe/bZpml2KF/gCG1sOv4kkvJ0qxI6MX7 L22BWBvOM/EwP1qIXaTCeTxFnkbNYm98kgQ7Hh68/2NfiaP88xcEH3tYy Qtq+Mk2Vhx2/YH3QGUmu6Lg5k9VbpvwF7Unhr4nBMynoybNQ+aCvWm+MZ euDp8i4dINuWxDITb+9XACNfYwE1WYggKXG8Zi59G+fvaCThWewI0/duU A==; X-CSE-ConnectionGUID: srDpFdgbRD2LdUQDHIQsEw== X-CSE-MsgGUID: C1vK2izGQJeDCi4sTCX51w== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808661" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808661" 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:20:00 -0700 X-CSE-ConnectionGUID: u/UyLr5SQ0md6MvEb5xcUw== X-CSE-MsgGUID: Lot0qZVdQp6wzxYOJB6H/Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="69253383" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 17 May 2024 07:19:56 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id EEF7CD0D; 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 07/20] x86/tdx: Convert CPUID handling to use new TDVMCALL_4() Date: Fri, 17 May 2024 17:19:25 +0300 Message-ID: <20240517141938.4177174-8-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: quoted-printable Content-Type: text/plain; charset="utf-8" Use newly introduced TDVMCALL_4() instead of __tdx_hypercall() to handle CPUID instruction emulation. It cuts code bloat substantially: Function old new delta tdx_handle_virt_exception 1819 1747 -72 Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdx.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index f59a2b3500db..c436cab355e0 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -414,13 +414,6 @@ static int write_msr(struct pt_regs *regs, struct ve_i= nfo *ve) =20 static int handle_cpuid(struct pt_regs *regs, struct ve_info *ve) { - struct tdx_module_args args =3D { - .r10 =3D TDX_HYPERCALL_STANDARD, - .r11 =3D hcall_func(EXIT_REASON_CPUID), - .r12 =3D regs->ax, - .r13 =3D regs->cx, - }; - /* * Only allow VMM to control range reserved for hypervisor * communication. @@ -438,19 +431,10 @@ static int handle_cpuid(struct pt_regs *regs, struct = ve_info *ve) * ABI can be found in TDX Guest-Host-Communication Interface * (GHCI), section titled "VP.VMCALL". */ - if (__tdx_hypercall(&args)) + if (TDVMCALL_4(EXIT_REASON_CPUID, regs->ax, regs->cx, 0, 0, + regs->ax, regs->bx, regs->cx, regs->dx)) return -EIO; =20 - /* - * As per TDX GHCI CPUID ABI, r12-r15 registers contain contents of - * EAX, EBX, ECX, EDX registers after the CPUID instruction execution. - * So copy the register contents back to pt_regs. - */ - regs->ax =3D args.r12; - regs->bx =3D args.r13; - regs->cx =3D args.r14; - regs->dx =3D args.r15; - return ve_instr_len(ve); } =20 --=20 2.43.0 From nobody Wed Feb 11 01:26:15 2026 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 D201E6D1BD; Fri, 17 May 2024 14:20:05 +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=1715955607; cv=none; b=m3RSTYMlp4Oa517TOZaXBrbqTf4fNeDl9ii2V4nPDokmj/nrdj8MNTapf97wnSVBggF8UJ0+28VQNZEujtJGAuO0/pDw5jGoJFd75moxDCIfwrslh29+tosOogrQHHM9mMfDRZfo8PO4jNP6WXhMfMePPRBkfmLSe89B5v5Atck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955607; c=relaxed/simple; bh=uZslm5QlIILoGAKr67d4nChGhXyvxobqw1oaGUf7Wmw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T6rfuwyVwZik6c4PjeqJl0m35WKDvTSJRzTS8I4GQ8+3SkPc7HpP6auXDZocquJzaAB8Z4XsSGKSzOwWAdUhOmjfymW4CqonJyLTwXnlv5jLCvist5CzZhcnhliKygYUfcMGAfvObJrMMrP48nDt5bHAJt+TyHlER2tyILEzO60= 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=apwMsSsm; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="apwMsSsm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715955606; x=1747491606; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uZslm5QlIILoGAKr67d4nChGhXyvxobqw1oaGUf7Wmw=; b=apwMsSsm67zIN4V3vPRH1K8wRfdy00TacNB4YbTOGPtQOXt6MlIzwKpw G6VMRqR8aO6LrO20duZ6fKRhgcCsFX1vS9r1bmUF/KnywBH6If3BRE4J1 VsnkCvG57NNMGjUXagr0lOKugoKzgYyWFtgvdFuaIR56RIuauKZ9g8QuG o7mpKaJb3c9NxyRM//3e9+oR59FLSqey9BuL0h1ak5xNWuWgz/zt5cT4n iawDe0uSrmqh/+7jptSUv8pRYC3GX1mEnCxPkoSR0WGCNkUuEuMrRnMCU rkBVbo69LaLziZDwla5RQwf3f5cNgb/DSWVw3OYkE7xg19B5iV/qDML/P w==; X-CSE-ConnectionGUID: sBHaPP5iQUGYSMBLK5+cVQ== X-CSE-MsgGUID: jZGmxltyRDaGh7syT267Sw== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808701" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808701" 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: pXhzlloYT5qbB8tq6NLaxg== X-CSE-MsgGUID: uylrdJESTaeGMuYVlF1JCg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="31944617" 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 0B7DDD61; 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 08/20] x86/tdx: Convert MMIO handling to use new TDVMCALL macros Date: Fri, 17 May 2024 17:19:26 +0300 Message-ID: <20240517141938.4177174-9-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: quoted-printable Content-Type: text/plain; charset="utf-8" Use newly introduced TDVMCALL_0() and TDVMCALL_1() instead of __tdx_hypercall() to handle MMIO emulation. It cuts code bloat substantially: Function old new delta tdx_handle_virt_exception 1747 1383 -364 Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdx.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index c436cab355e0..df3e10d899b3 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -438,38 +438,34 @@ static int handle_cpuid(struct pt_regs *regs, struct = ve_info *ve) return ve_instr_len(ve); } =20 -static bool mmio_read(int size, unsigned long addr, unsigned long *val) +static bool mmio_read(int size, unsigned long gpa, u64 *val) { - struct tdx_module_args args =3D { - .r10 =3D TDX_HYPERCALL_STANDARD, - .r11 =3D hcall_func(EXIT_REASON_EPT_VIOLATION), - .r12 =3D size, - .r13 =3D EPT_READ, - .r14 =3D addr, - .r15 =3D *val, - }; + bool ret; + u64 out; =20 - if (__tdx_hypercall(&args)) - return false; + ret =3D !TDVMCALL_1(hcall_func(EXIT_REASON_EPT_VIOLATION), + size, EPT_READ, gpa, 0, out); + if (ret) + *val =3D out; =20 - *val =3D args.r11; - return true; + return ret; } =20 -static bool mmio_write(int size, unsigned long addr, unsigned long val) +static bool mmio_write(int size, u64 gpa, u64 val) { - return !_tdx_hypercall(hcall_func(EXIT_REASON_EPT_VIOLATION), size, - EPT_WRITE, addr, val); + return !TDVMCALL_0(hcall_func(EXIT_REASON_EPT_VIOLATION), + size, EPT_WRITE, gpa, val); } =20 static int handle_mmio(struct pt_regs *regs, struct ve_info *ve) { - unsigned long *reg, val, vaddr; + unsigned long *reg, vaddr; char buffer[MAX_INSN_SIZE]; enum insn_mmio_type mmio; struct insn insn =3D {}; int size, extend_size; u8 extend_val =3D 0; + u64 val; =20 /* Only in-kernel MMIO is supported */ if (WARN_ON_ONCE(user_mode(regs))) --=20 2.43.0 From nobody Wed Feb 11 01:26:15 2026 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 425246BB5C; Fri, 17 May 2024 14:20:03 +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=1715955604; cv=none; b=J/CtXoHMPrXyQY5qGCwJ5Bz0GMIIE07T934r6Bf1TQ9/oKnyn7N/lkyaKzIvSzEPP/qDrpqIHs7HtjPnxaRn8K9uYkPPb5d2Np9l2QtWdyLCnorTIfTfi90dPCymLzbYDx3NVHHDeLV+ZPixQnr2aJLpE3W77Sm8VhJSryK+oZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955604; c=relaxed/simple; bh=/CzwNXVaKGEQ3E9bwjs3O7QSiO6r7/AsWG/VCkB8/H8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a8lJNI2GENWEid1g0bC0FBK3qrY4f239LKOqBMiqHXO+90J8k1V+8+kGwZE2a4EIdjOXECrMKg1zv2TZITBkSV6Ai/NFJh2ZDdUyagaC/gWJQ4Jjj6LCfvW1yN1t1VnM0dcs+TMGwPaYVXOXxpd2yiBMzBYmouVpzadk1MjmoWw= 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=GeYX4kLf; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="GeYX4kLf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715955603; x=1747491603; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/CzwNXVaKGEQ3E9bwjs3O7QSiO6r7/AsWG/VCkB8/H8=; b=GeYX4kLfsL0UwjJEYow6qfzUGE11Ss/1A8u0vQijmQ495EDPRFD8Aqj5 kIGxp24XyI/neMdz/oTblSvCwIYtLJJiu54hU6bVbwiZo+xuJTWuQViSo zV2S1YK7HeYz9McVaByO6uvIhfx7mrteGgfDEH3ywFFsshNg68rU1bdMa s3BrIXQBRQiHZRDbFMELcUcw2KF/G5XmeZqrs9POQeBxe8TverPnxi2aL YuznDNSfDg8JsI4SHlpOm+dhgIfxC5Mls4fYUEo96uEcyQv0gX0l0qKTj +Ecu2tYV7jPv41XHgos8at78XtAvtvbD0AqBLTnnyil1Jg/9btjWYT2Dk w==; X-CSE-ConnectionGUID: DweLtl8/S/CHnxpctj+VsA== X-CSE-MsgGUID: +I+bi5KdREiNlwC0CJdCzA== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808692" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808692" 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:20:01 -0700 X-CSE-ConnectionGUID: O4NnF3dCRe+gATw4xDL+bg== X-CSE-MsgGUID: Ps04XFBGQCydR14R0EDIpA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="69253384" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 17 May 2024 07:19:56 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 1B2CED7B; 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 09/20] x86/tdx: Convert MAP_GPA hypercall to use new TDVMCALL macros Date: Fri, 17 May 2024 17:19:27 +0300 Message-ID: <20240517141938.4177174-10-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: quoted-printable Content-Type: text/plain; charset="utf-8" Use newly introduced TDVMCALL_1() instead of __tdx_hypercall() to issue MAP_GPA hypercall. It cuts code bloat substantially: Function old new delta tdx_enc_status_changed 352 242 -110 tdx_kexec_finish 645 530 -115 tdx_enc_status_change_prepare 326 181 -145 Total: Before=3D5553, After=3D5183, chg -6.66% Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdx.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index df3e10d899b3..7c874a50a319 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -797,15 +797,10 @@ static bool tdx_map_gpa(phys_addr_t start, phys_addr_= t end, bool enc) } =20 while (retry_count < max_retries_per_page) { - struct tdx_module_args args =3D { - .r10 =3D TDX_HYPERCALL_STANDARD, - .r11 =3D TDVMCALL_MAP_GPA, - .r12 =3D start, - .r13 =3D end - start }; - - u64 map_fail_paddr; - u64 ret =3D __tdx_hypercall(&args); + u64 map_fail_paddr, ret; =20 + ret =3D TDVMCALL_1(TDVMCALL_MAP_GPA, + start, end - start, 0, 0, map_fail_paddr); if (ret !=3D TDVMCALL_STATUS_RETRY) return !ret; /* @@ -813,7 +808,6 @@ static bool tdx_map_gpa(phys_addr_t start, phys_addr_t = end, bool enc) * region starting at the GPA specified in R11. R11 comes * from the untrusted VMM. Sanity check it. */ - map_fail_paddr =3D args.r11; if (map_fail_paddr < start || map_fail_paddr >=3D end) return false; =20 --=20 2.43.0 From nobody Wed Feb 11 01:26:15 2026 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 73C7D657C6; Fri, 17 May 2024 14:20:01 +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=1715955603; cv=none; b=gpiZoxg60uZyYa3ehZLkj6h1Q5vUrTXMFnpH40YCQHLUA4MHQFJ+/vI58V9xfgQ43oEI861gSPSdNbpcZww4egBZ/Qb+j5gbFO/u7dQ5URAttjHl/KcWQct1a4uUJ4resPdE9+W7037SBL7dyXGaWY5IHmTIiAruFLFW4Laz8Lg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955603; c=relaxed/simple; bh=tHoxgIZyyik8ZVUSPgSNSEV0q6AJ2EgF7vlCRqN3mxE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kbyIbm4Fg58vA36b8IfsR5mFgbFPjJhJBPysKCzwZARRZRBHWGjnAPtihmswGvLkAS+eGsASR8zsrxeY75u/12dy3GCJ+oQq2VHQfpP9EX1OoYOq6Bvn6hAmnTxNF2DbkgfzCsAlsqFcn7x5EZtHkuEuNGFjTs9utlrN/dlJdIY= 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=EYyUwNdA; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="EYyUwNdA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715955602; x=1747491602; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tHoxgIZyyik8ZVUSPgSNSEV0q6AJ2EgF7vlCRqN3mxE=; b=EYyUwNdAoyjDI0w7glAiWiRowI1D6xRHpZZKIpCAYQ7h7TS4r5IvyVAY vUZFXukfB9cVZqvznMGvC6w+Hbr4J2Nf0FYTlgbgq9/DBgY+XXpDtJcfS 1hsqOubVbryDFFG4d6WtJn8iTnjvGXoX2Oz3fl5ZTPRjrWSwZassklLL8 cOeKk80PSJ6rMhyfs/Dz1VJOoaoAI/8ERl3XoBQ0jVtbHzh6nmM9uU2JU Ox3pGvVmm1V1DFHqf/MqcW4hm1yxE5jZCbxnzl2tH8OCPE7PgK+Va+860 ZwqfJEDupNHo/SVEAdHQXnngZ6T7+qiDS4arhNfm8tk0F/Nm7bX+jgwhH A==; X-CSE-ConnectionGUID: K31UD5VdQSuGlpc2zf8SVw== X-CSE-MsgGUID: mzBs00YySEKi7HZ9DpCmbQ== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808631" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808631" 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:00 -0700 X-CSE-ConnectionGUID: uDULCkgOSQu2dl08FomWMA== X-CSE-MsgGUID: W/Vz89qaTeKWBaSMYfnBdg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="31944618" 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 26C60D7E; 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 10/20] x86/tdx: Convert GET_QUOTE hypercall to use new TDVMCALL macros Date: Fri, 17 May 2024 17:19:28 +0300 Message-ID: <20240517141938.4177174-11-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: quoted-printable Content-Type: text/plain; charset="utf-8" Use newly introduced TDVMCALL_0() instead of __tdx_hypercall() to issue GET_QUOTE hypercall. It cuts code bloat substantially: Function old new delta tdx_hcall_get_quote 188 76 -112 Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 7c874a50a319..3f0be1d3cccb 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -150,7 +150,8 @@ EXPORT_SYMBOL_GPL(tdx_mcall_get_report0); u64 tdx_hcall_get_quote(u8 *buf, size_t size) { /* Since buf is a shared memory, set the shared (decrypted) bits */ - return _tdx_hypercall(TDVMCALL_GET_QUOTE, cc_mkdec(virt_to_phys(buf)), si= ze, 0, 0); + return TDVMCALL_0(TDVMCALL_GET_QUOTE, + cc_mkdec(virt_to_phys(buf)), size, 0, 0); } EXPORT_SYMBOL_GPL(tdx_hcall_get_quote); =20 --=20 2.43.0 From nobody Wed Feb 11 01:26:15 2026 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 2A7C26BB50; Fri, 17 May 2024 14:20:03 +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=tQ4t/W6qwINhk7d/jgDwU9UljvReheAEtJIScvkG/mY2sI5CfOys5f82yn7ADBMWldj9YeBMsWOQL8oLmH9yjOEThX3NpQpm3bwRUv5AYhmVbAIcsybr0S0TQPoHxtclU1n/NyP6x4fSrrLcfmet6AtcNc4OgpNmOiahy31IElo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955605; c=relaxed/simple; bh=LfJF40bu9175MoXsqPC9Kp+73oOf88kFkC5j1mad8BY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VwHWwW6tmcmFZFgHCpDtA2BXQ7y0o22N+/tYHHj/WthPMSt+NQSPEkEOv6MkryaKW5w0RG+OPiE+KllcKZvA4gV6TuL+NV1Dy6m5IoOqaJ/hnme80IgckN6mrK16Lex6+q5/5hu6pyvt5NLNS3sM7/pAJNdY2hv5Zqi/Qmm5NoI= 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=F6ihWJEF; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="F6ihWJEF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715955603; x=1747491603; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LfJF40bu9175MoXsqPC9Kp+73oOf88kFkC5j1mad8BY=; b=F6ihWJEFuz0/oUxuOQgh6i9X4pHTaF6t9gM3m7CkZUHlbwWtVCG8ywCs 5DJtq6QIQwM4QVrlmDTs+BffbYk9O8TtcP9re0GYG9RKp8WzKqV6HgT6H o5gLu1ItaNoqcBhhgb9TcmWhw9Qk90MhaQ9/+sJTOW0GYH6m7DF6XpXDw h+oCWdKhLqrYLCpkORgCJAcm7Gjz6nuQUAoP33YOLStfXFCEiq0RK2KGS EZ/Ci8S4qOemyuhDljoXdCefsx5jn8YDahnFqWTY3zEV17sWqWNxwv2GA BuSGWH38aJDD0Ucgp+r9LKRA7hwVZl0gJcNvOpm04TUS/SF23dzDWUXJV Q==; X-CSE-ConnectionGUID: ka3kU7SRSPOBdWTd/mG+Bg== X-CSE-MsgGUID: VMliNjHeSb+qXaGmzQK80w== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808664" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808664" 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: YAzxi36sQCyTHCwxlOrAoA== X-CSE-MsgGUID: hcJwi3EFQf+FLkPXCWj8Ig== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="31944620" 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 32777E27; 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 11/20] x86/tdx: Rewrite tdx_panic() without __tdx_hypercall() Date: Fri, 17 May 2024 17:19:29 +0300 Message-ID: <20240517141938.4177174-12-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: quoted-printable Content-Type: text/plain; charset="utf-8" tdx_panic() uses REPORT_FATAL_ERROR hypercall to deliver panic message in ealy boot. Rewrite it without using __tdx_hypercall(). REPORT_FATAL_ERROR hypercall is special. It uses pretty much all available registers to pass down the error message. TDVMCALL macros are not usable here. Implement the hypercall directly in assembly. It cuts code bloat substantially: Function old new delta tdx_panic 222 59 -163 Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdcall.S | 28 ++++++++++++++++++++++++++++ arch/x86/coco/tdx/tdx.c | 31 +++---------------------------- arch/x86/include/asm/tdx.h | 2 ++ tools/objtool/noreturns.h | 1 + 4 files changed, 34 insertions(+), 28 deletions(-) diff --git a/arch/x86/coco/tdx/tdcall.S b/arch/x86/coco/tdx/tdcall.S index 12185fbd33ba..269e5789672a 100644 --- a/arch/x86/coco/tdx/tdcall.S +++ b/arch/x86/coco/tdx/tdcall.S @@ -110,3 +110,31 @@ SYM_FUNC_START(tdvmcall_trampoline) ud2 SYM_FUNC_END(tdvmcall_trampoline) .popsection + +SYM_FUNC_START(tdvmcall_report_fatal_error) + movq $TDX_HYPERCALL_STANDARD, %r10 + movq $TDVMCALL_REPORT_FATAL_ERROR, %r11 + movq %rdi, %r12 + movq $0, %r13 + + movq %rsi, %rcx + + /* Order according to the GHCI */ + movq 0*8(%rcx), %r14 + movq 1*8(%rcx), %r15 + movq 2*8(%rcx), %rbx + movq 3*8(%rcx), %rdi + movq 4*8(%rcx), %rsi + movq 5*8(%rcx), %r8 + movq 6*8(%rcx), %r9 + movq 7*8(%rcx), %rdx + + movq $TDG_VP_VMCALL, %rax + movq $(TDX_RDX | TDX_RBX | TDX_RSI | TDX_RDI | TDX_R8 | TDX_R9 | \ + TDX_R10 | TDX_R11 | TDX_R12 | TDX_R13 | TDX_R14 | TDX_R15), \ + %rcx + + tdcall + + ud2 +SYM_FUNC_END(tdvmcall_report_fatal_error) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 3f0be1d3cccb..b7299e668564 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -157,37 +157,12 @@ EXPORT_SYMBOL_GPL(tdx_hcall_get_quote); =20 static void __noreturn tdx_panic(const char *msg) { - struct tdx_module_args args =3D { - .r10 =3D TDX_HYPERCALL_STANDARD, - .r11 =3D TDVMCALL_REPORT_FATAL_ERROR, - .r12 =3D 0, /* Error code: 0 is Panic */ - }; - union { - /* Define register order according to the GHCI */ - struct { u64 r14, r15, rbx, rdi, rsi, r8, r9, rdx; }; - - char str[64]; - } message; + char str[64]; =20 /* VMM assumes '\0' in byte 65, if the message took all 64 bytes */ - strtomem_pad(message.str, msg, '\0'); + strtomem_pad(str, msg, '\0'); =20 - args.r8 =3D message.r8; - args.r9 =3D message.r9; - args.r14 =3D message.r14; - args.r15 =3D message.r15; - args.rdi =3D message.rdi; - args.rsi =3D message.rsi; - args.rbx =3D message.rbx; - args.rdx =3D message.rdx; - - /* - * This hypercall should never return and it is not safe - * to keep the guest running. Call it forever if it - * happens to return. - */ - while (1) - __tdx_hypercall(&args); + tdvmcall_report_fatal_error(0, str); } =20 /* diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index eba178996d84..f67e5e6b66ad 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -54,6 +54,8 @@ struct ve_info { =20 void __init tdx_early_init(void); =20 +void __noreturn tdvmcall_report_fatal_error(u64 error_code, const char str= [64]); + void tdx_get_ve_info(struct ve_info *ve); =20 bool tdx_handle_virt_exception(struct pt_regs *regs, struct ve_info *ve); diff --git a/tools/objtool/noreturns.h b/tools/objtool/noreturns.h index 7ebf29c91184..0670cacf0734 100644 --- a/tools/objtool/noreturns.h +++ b/tools/objtool/noreturns.h @@ -39,6 +39,7 @@ NORETURN(sev_es_terminate) NORETURN(snp_abort) NORETURN(start_kernel) NORETURN(stop_this_cpu) +NORETURN(tdvmcall_report_fatal_error) NORETURN(usercopy_abort) NORETURN(x86_64_start_kernel) NORETURN(x86_64_start_reservations) --=20 2.43.0 From nobody Wed Feb 11 01:26:15 2026 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 1048C6E610; Fri, 17 May 2024 14:20:05 +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=1715955606; cv=none; b=RFsbFDq0omYF/YVdD+Q8RnYDhbbPah0Xlb725UEh3SoDIucVFlmnAp6m+JW1E+kfwzZwpyx8LMktPkwNkGp+1i8SkZnMwdx9Mae7A9ZrYY2mZAkgE68OM8xoSPu4DuXnP3VobgP2+0RbDGmqdc+lpVuJ42sg2StLsfCu9UTCA0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955606; c=relaxed/simple; bh=k2swUgV0BCGyXi52V0yVB3FayPL92XVdPDIburVHsSw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rguFlhnr9zjdNmfXzw2zRgKXXqQUEUdLiGooldbsVB3KY/rLGyLBlI9yz8RsdbJ0Q7DqRpJnbR58cbX3sGJS6AQcFcrLBetoj2f0ye+eY9how9D3SLyIOTqygB1A1orZWNpCb2iNh7FxwQElPguWH7/h6fubypGuSYwC0SRKNa0= 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=XrZe/1x1; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="XrZe/1x1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715955605; x=1747491605; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=k2swUgV0BCGyXi52V0yVB3FayPL92XVdPDIburVHsSw=; b=XrZe/1x1Rl1HpJRcGtYx8fHH3EHH3GTCzuEUi2gVawORFRbtuXmhlh9M Kj94M1iu0HJ8mlwRaOjGaLav5Z9GU5fPinIYV8LdwaWgUfnw3Eh5RbUVC ZmFuH3h6MhTPTbXXbRV2h8SCgX4k7epENAErhEJMlGiVZtcRCuBBD7GnC EIhk3EJL1DdjUMs/RQVEdbU0qYonzWeHXUOT2NfvXLVJMUGNlSrxkTt2/ 7UwrWHHji5ytS6aaDNOxvxqxsdASAzCRjvAfesIMsPHTx5CLaUWJ5PMbB WF6tRwUJs8Kl8pavclsjIpEQ3gY4/e8vlY03uBG+A50aMaazmP/UNIRJr g==; X-CSE-ConnectionGUID: f8DPN3N/Q86QsVpeQaxgJg== X-CSE-MsgGUID: zGaDOI8/ScOwoo2+62OIUg== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808713" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808713" 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: uVe0gu2iR3agrMF4Qt0k3w== X-CSE-MsgGUID: q1iY+mGRSqK697dMyL56+Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="31944621" 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 42E2AEB0; 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 12/20] x86/tdx: Rewrite tdx_kvm_hypercall() without __tdx_hypercall() Date: Fri, 17 May 2024 17:19:30 +0300 Message-ID: <20240517141938.4177174-13-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: quoted-printable Content-Type: text/plain; charset="utf-8" tdx_kvm_hypercall() issues KVM hypercall. Rewrite it without using __tdx_hypercall(). Use tdvmcall_trampoline() instead. It cuts code bloat substantially: Function old new delta tdx_kvm_hypercall 160 53 -107 Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdx.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index b7299e668564..e7ffe1cd6d32 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -49,15 +49,15 @@ noinstr void __noreturn __tdx_hypercall_failed(void) long tdx_kvm_hypercall(unsigned int nr, unsigned long p1, unsigned long p2, unsigned long p3, unsigned long p4) { - struct tdx_module_args args =3D { - .r10 =3D nr, - .r11 =3D p1, - .r12 =3D p2, - .r13 =3D p3, - .r14 =3D p4, - }; + long ret; =20 - return __tdx_hypercall(&args); + asm("call tdvmcall_trampoline\n\t" + "movq %%r10, %0\n\t" + : "=3Dr" (ret) + : "a" (nr), "b" (p1), "D" (p2), "S"(p3), "d"(p4), "c" (0) + : "r12", "r13", "r14", "r15"); + + return ret; } EXPORT_SYMBOL_GPL(tdx_kvm_hypercall); #endif --=20 2.43.0 From nobody Wed Feb 11 01:26:15 2026 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 61EA165189; Fri, 17 May 2024 14:20:01 +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=1715955603; cv=none; b=E5mMhO5ugIjVmi9h1D5OjB+21qq54X4J9osPCeAI3ndzPJlPNXzKlGWvPtPmPnN9gXfw3pDsaanTnQcz4n5XFQ2GLL9s2uZb0YBmdlnf6Jci2KK97JHDut6+ixifYRrKzOEs/h7nDe1v1qs3lhCiFYdFmJvuUSTUuJmwJx/tRcE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955603; c=relaxed/simple; bh=CcujIUVW1JuDql5JHxHA+AIa8M0XntpfPmL9/r3uwTE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jHuqPEkyN6p+BP1OnwGbgA8U1tMswwKGoB4SVmf7k2ZBhWk81o2dw9uMRYsSEP/tLe7092SslE7G+Zpi/KsskDZZDGX5z4FyvTqOrBTMbTNyhyDXnexyc4oXEY44+gGB/tqMDAg/lGth+PWzRMWOboVXfO2drxcElAO0O7IzKB0= 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=nApBNqp0; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="nApBNqp0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715955601; x=1747491601; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CcujIUVW1JuDql5JHxHA+AIa8M0XntpfPmL9/r3uwTE=; b=nApBNqp0+GlOPdZLvn6cE696oBdlX3yrlq+7lUsSJdUGsPtlXfDhAF9n OL3rBrtBe1z1M1mtWSHimm5L9f1NnXniFHB1UJVICWFr1nbmdYlLR79hx U9aC09ww6oEKh9DOB5S9xFdZisXRYzdarNA1orIJlkyOKB3UoiKALYThh mSWsW6Gd+K9voDtVRgAWPgOGsWd4K1ra/99XOg6DR9lEeRTdm4Bzr9sDM adeF3Q3pWmGPgovfqb9VVGL4d1sFwZc7UA3fENnBBB4RP4vTuACCQALMl xTm2hPHGqBuRlrcMRPwq5PZ1dFq+hBFYSZSmZ3aIREZpbPNt8TFiPJDZi g==; X-CSE-ConnectionGUID: SOBTzdVRSq2bDFaFWiT/0A== X-CSE-MsgGUID: Lx/P0NlGRfu3CNklrWwDRg== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808642" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808642" 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:20:00 -0700 X-CSE-ConnectionGUID: IOisXNc3SImubkKPm9L17Q== X-CSE-MsgGUID: tE0r8QJERR+mBnF5pQKlxA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="69253385" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 17 May 2024 07:19:56 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 4D265AD3; 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 13/20] x86/tdx: Rewrite hv_tdx_hypercall() without __tdx_hypercall() Date: Fri, 17 May 2024 17:19:31 +0300 Message-ID: <20240517141938.4177174-14-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: quoted-printable Content-Type: text/plain; charset="utf-8" Rewrite hv_tdx_hypercall() in assembly to remove one more __tdx_hypercall() user. tdvmcall_trampoline() cannot be used here as Hyper-V uses R8 and RDX to pass down parameters which is incompatible with tdvmcall_trampoline() The rewrite cuts code bloat substantially: Function old new delta hv_tdx_hypercall 171 42 -129 Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdcall.S | 30 ++++++++++++++++++++++++++++++ arch/x86/hyperv/ivm.c | 14 -------------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/arch/x86/coco/tdx/tdcall.S b/arch/x86/coco/tdx/tdcall.S index 269e5789672a..5b60b9c8799f 100644 --- a/arch/x86/coco/tdx/tdcall.S +++ b/arch/x86/coco/tdx/tdcall.S @@ -138,3 +138,33 @@ SYM_FUNC_START(tdvmcall_report_fatal_error) =20 ud2 SYM_FUNC_END(tdvmcall_report_fatal_error) + +#ifdef CONFIG_HYPERV +/* + * hv_tdx_hypercall() - Issue Hyper-V hypercall + * + * RDI - Hypercall ID + * RSI - Parameter 1 + * RCX - Parameter 2 + */ +SYM_FUNC_START(hv_tdx_hypercall) + movq %rdi, %r10 + movq %rsi, %rdx + movq %rcx, %r8 + + movq $TDG_VP_VMCALL, %rax + movq $(TDX_R8 | TDX_R10 | TDX_RDX), %rcx + + tdcall + + /* TDG.VP.VMCALL never fails on correct use. Panic if it fails. */ + testq %rax, %rax + jnz .Lpanic_hv + + movq %r11, %rax + + RET +.Lpanic_hv: + ud2 +SYM_FUNC_END(hv_tdx_hypercall) +#endif diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 18d0892d9fc4..562980e19d68 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -401,20 +401,6 @@ static void hv_tdx_msr_read(u64 msr, u64 *val) if (WARN_ONCE(ret, "Failed to emulate MSR read: %lld\n", ret)) *val =3D 0; } - -u64 hv_tdx_hypercall(u64 control, u64 param1, u64 param2) -{ - struct tdx_module_args args =3D { }; - - args.r10 =3D control; - args.rdx =3D param1; - args.r8 =3D param2; - - (void)__tdx_hypercall(&args); - - return args.r11; -} - #else static inline void hv_tdx_msr_write(u64 msr, u64 value) {} static inline void hv_tdx_msr_read(u64 msr, u64 *value) {} --=20 2.43.0 From nobody Wed Feb 11 01:26:15 2026 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="P4GUPNu0" 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: quoted-printable Content-Type: text/plain; charset="utf-8" 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/share= d/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 @@ =20 #include =20 +#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 \ + : "=3Da" (__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" \ + : "=3Da" (__ret), ASM_CALL_CONSTRAINT, [r8_out] "=3Drm" (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" \ + : "=3Da" (__ret), ASM_CALL_CONSTRAINT, \ + "=3Dc" (out_rcx), "=3Dd" (out_rdx), \ + [r8_out] "=3Drm" (out_r8), [r9_out] "=3Drm" (out_r9), \ + [r10_out] "=3Drm" (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; \ --=20 2.43.0 From nobody Wed Feb 11 01:26:15 2026 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 17D0271750; Fri, 17 May 2024 14:20:06 +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=1715955607; cv=none; b=eXq7euzZohIjYNG3hlpiNgglVW3sNLYQzPW/rqjwRsDfo9+JR6bWWOfME0W4I9SD8O4jvdhQJmyq+SYcEagr3lETy4vOTS4nCKfFUVp7R1yCHVxsyPJa5R9e+sI0b0ngHJkh0IvpqGxGxue0bImXBI5maw4YfYrZrbwHM5Fq2qc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955607; c=relaxed/simple; bh=0sOCyuIE9yUNs9m+zPMFvR+dpm6EUDIzGSm4n+Yw9H8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AN+Z1/MQxsNjmcpqmmKzWMKsSLBZzDG6FtCLucxB2Z2tnffszyZpE1IXB5EuEQHXVKkn3ROvNAT7GW6FNwcFVgDL9ghahPZ4mxOcJF7vkxHC0Sz7Q/q/wr9wGynG2CG+Zjb5yy13gwo98QzowNdO7CHeRqJZ/OdWcBsb3SjBGpU= 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=fa+jE+S9; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="fa+jE+S9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715955606; x=1747491606; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0sOCyuIE9yUNs9m+zPMFvR+dpm6EUDIzGSm4n+Yw9H8=; b=fa+jE+S9VKRCFbxq+aimz5+aVgZPokraQl8xD9uVOcQjnXVfoeIj/2hY iTtD3w+ImUWYJz8xUHMWdCuUHF/83IlKteBtUWji2uWjMnjAm5XUQZluS E2Cc71KsDFM/a/cdd+0QqBbzU/cTs/x9UN+eHC3iCITBafCIBf0iLH03/ vltlmwdOpr55EkHH1ETNK6XxeDXDj4CRq4IcTxtYT5qXv0Sc0IQwugqRA XI+92kINmdGIRtedwQlVWX7Xl7W9gpkWlNsZnuJUQynkvglwyLHLkVcax Sh/4ZEwZpYXMaYBzpNNcmQvgI3YcnXIJkrFdJ31skuWmCwwRT1vj2Q7fh A==; X-CSE-ConnectionGUID: +boyJUc8T2OD97z34jwl4w== X-CSE-MsgGUID: 4xCxoDkkSsmfXGbgmuhBQA== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808729" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808729" 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:20:04 -0700 X-CSE-ConnectionGUID: Yq5WDUTCRuOlXKKW2AH2Qw== X-CSE-MsgGUID: KD9wOimsS0GmnoCnwUgOkQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="69253422" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 17 May 2024 07:20:00 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 69760F21; 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 15/20] x86/tdx: Convert PAGE_ACCEPT tdcall to use new TDCALL_0() macro Date: Fri, 17 May 2024 17:19:33 +0300 Message-ID: <20240517141938.4177174-16-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: quoted-printable Content-Type: text/plain; charset="utf-8" Use newly introduced TDCALL_0() instead of __tdcall() to issue PAGE_ACCEPT tdcall. It cuts code bloat substantially: Function old new delta tdx_accept_memory 592 233 -359 Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdx-shared.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/coco/tdx/tdx-shared.c b/arch/x86/coco/tdx/tdx-shared.c index 1655aa56a0a5..9104e96eeefd 100644 --- a/arch/x86/coco/tdx/tdx-shared.c +++ b/arch/x86/coco/tdx/tdx-shared.c @@ -5,8 +5,8 @@ static unsigned long try_accept_one(phys_addr_t start, unsi= gned long len, enum pg_level pg_level) { unsigned long accept_size =3D page_level_size(pg_level); - struct tdx_module_args args =3D {}; u8 page_size; + u64 ret; =20 if (!IS_ALIGNED(start, accept_size)) return 0; @@ -34,8 +34,8 @@ static unsigned long try_accept_one(phys_addr_t start, un= signed long len, return 0; } =20 - args.rcx =3D start | page_size; - if (__tdcall(TDG_MEM_PAGE_ACCEPT, &args)) + ret =3D TDCALL_0(TDG_MEM_PAGE_ACCEPT, start | page_size, 0, 0, 0); + if (ret) return 0; =20 return accept_size; --=20 2.43.0 From nobody Wed Feb 11 01:26:15 2026 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 AA23D73165; Fri, 17 May 2024 14:20:06 +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=1715955608; cv=none; b=SpXKmZae8tv3E1SxxYYoSf/VpbA//wOvSDLDCihe4hetei/ziCuj+1EwnSpFLZI+56kOz+kChrtjMagYDFNAz7OQcrMeh7vIvzsfCizTRjB26/hsPQfUl/PwzvBmVt+Yy54w5+uAmubiQPr5jmvmGxacUvTF7ql83tZRcIR1s3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955608; c=relaxed/simple; bh=mpeI7dxGBjXJkH2OOGSAH6mbSJNyYYKdgngapiZV/lM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qthxnX5NUiDf0gBofzMRZhWHAFsPz525zxNKz8yvv9Yz7vIRaP+c0azvqR/6+8PHodxBpXHN8xeqTH3PeUc6CKabt3agDNal2z5RNQpxl5UtMpWRwG3mvnUh2cAUGV2RTUGQ8AwR7qIeyeDHjuMKftpOY9hla25VCd0B6FSKrXI= 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=FbWaeQgy; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="FbWaeQgy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715955607; x=1747491607; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mpeI7dxGBjXJkH2OOGSAH6mbSJNyYYKdgngapiZV/lM=; b=FbWaeQgyXb6f9UJWMqeDMueYJbo0BW2fiXikr/E8Zh/zhHn7JAeum2iG PQaqUV/V+qTbN58bL8VMwS8kZOw8TU6/wyoaF0ZGXAzECQ7ADD+Sv65Jj RS1ZEdvNi8IN0dQd1q7k7Pwe1hsp3howTqdvMuFgLaMy3g0zTyIGQukMC CxBq932OOl5ZVFv2Ra2CI2FjHajcQ78eGCbU316ICSqnhiXRXr4zl+Zg6 2gJTgvqK4XwUkl5/tkbTX8K2pbwzVOwIwME3f8fPi+wE7/azz/uzQLu0T //rPl9vXKPR902kKXYlwTxBbI6mMuzOYnH1sVxqOh1OKaQY55eaw+TAtt g==; X-CSE-ConnectionGUID: C2Hwg27xR5KrPOTjBaezhA== X-CSE-MsgGUID: NOcnVgdHS362lSNKt+W4NQ== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808741" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808741" 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:05 -0700 X-CSE-ConnectionGUID: E0nY6EjER3W1Z8B9VDY4QQ== X-CSE-MsgGUID: XFBXlvQ6QW2hjlEr2xFsAQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="31944628" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa009.jf.intel.com with ESMTP; 17 May 2024 07:20:01 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 756D11084; 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 16/20] x86/tdx: Convert VP_INFO tdcall to use new TDCALL_5() macro Date: Fri, 17 May 2024 17:19:34 +0300 Message-ID: <20240517141938.4177174-17-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: quoted-printable Content-Type: text/plain; charset="utf-8" Use newly introduced TDCALL_5() instead of tdcall() to issue VP_INFO tdcall. It cuts code bloat slightly: Function old new delta tdx_early_init 780 744 -36 Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdx.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index e7ffe1cd6d32..e1849878f3bc 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -247,20 +247,22 @@ static void enable_cpu_topology_enumeration(void) tdg_vm_wr(TDCS_TD_CTLS, TD_CTLS_ENUM_TOPOLOGY, TD_CTLS_ENUM_TOPOLOGY); } =20 +static void tdg_vp_info(u64 *gpa_width, u64 *attributes) +{ + u64 dummy, ret; + + ret =3D TDCALL_5(TDG_VP_INFO, 0, 0, 0, 0, *gpa_width, *attributes, dummy, + dummy, dummy); + BUG_ON(ret); + + *gpa_width &=3D GENMASK(5, 0); +} + static void tdx_setup(u64 *cc_mask) { - struct tdx_module_args args =3D {}; - unsigned int gpa_width; - u64 td_attr; + u64 gpa_width, td_attr; =20 - /* - * TDINFO TDX module call is used to get the TD execution environment - * information like GPA width, number of available vcpus, debug mode - * information, etc. More details about the ABI can be found in TDX - * Guest-Host-Communication Interface (GHCI), section 2.4.2 TDCALL - * [TDG.VP.INFO]. - */ - tdcall(TDG_VP_INFO, &args); + tdg_vp_info(&gpa_width, &td_attr); =20 /* * The highest bit of a guest physical address is the "sharing" bit. @@ -269,11 +271,8 @@ static void tdx_setup(u64 *cc_mask) * The GPA width that comes out of this call is critical. TDX guests * can not meaningfully run without it. */ - gpa_width =3D args.rcx & GENMASK(5, 0); *cc_mask =3D BIT_ULL(gpa_width - 1); =20 - td_attr =3D args.rdx; - /* Kernel does not use NOTIFY_ENABLES and does not need random #VEs */ tdg_vm_wr(TDCS_NOTIFY_ENABLES, 0, -1ULL); =20 --=20 2.43.0 From nobody Wed Feb 11 01:26:15 2026 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 91F6974C14; Fri, 17 May 2024 14:20:08 +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=1715955610; cv=none; b=jc2IhbaknSenjxcrYapFjH7Au44hfz/10fn+du9zYm4CXIIr1rBiLIPS6AkretpeF2+b9zvvd1klwlLDmLNrRYDylCw0+F5/xa/ZTXzBpBwVoKndIj8JnR+FwxbFeIMUTUFMtN5/Ncv1JgoX7qAw1SVAdMhiBnRNVz8GK++OvoA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955610; c=relaxed/simple; bh=C3SOvLF3a7cbP+wZzmvHsHcoeWpug9aDQsg/WGa80aU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QIIkRhK3e3SJJBYZO49HEzHXJYic6Jw+Ubn5oiogkOd9jApnPtCmcQQUcD4fhbY/v8xOHksHfAiqRY6rxvMiiMn1x/5wahzCtHDzlyypWD2cUP1rY5grVSdJa86c6OZxGEX1riWiD5irCjlqOeLiuwaIeNA9aMRtrAWmk++XIeE= 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=jRopIITK; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jRopIITK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715955609; x=1747491609; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=C3SOvLF3a7cbP+wZzmvHsHcoeWpug9aDQsg/WGa80aU=; b=jRopIITKB0S4lvnnH9F1Zp8x0bVm+r29Tl9x+tbEQGU9BbEVJ4kK4aGI HKyisarX4G6YUKLzMoasKO1EQdzYicEYh2vGfTaQKGtOK8zzIsSNoLSNi mvExHr3qro6slp1+DGnMx+iLbTqzb+Lf+7x1stdJD85GUqPXITCe/do9S 1H/efnWYYsZl9Zxdzoi4w67wlokuxNy/EcI+QUUXv3WZdlHO8cl3xlL+n VnhNmX9HjQQWi8Xm20vegd9lJYRjntyVwnhb1XCNBk+EsSDllHMVPzecn iW9yy9o/JSnNCHM1RGbw5DpqAP8TQ0lI80fP/YckwPpCF/SBE43n+TDRh w==; X-CSE-ConnectionGUID: nTMIvi+OSo6mB3yavzPZsg== X-CSE-MsgGUID: OS1miaUbTB23Q/x1TUjsng== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808776" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808776" 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:05 -0700 X-CSE-ConnectionGUID: Epx+dGTEQkK5Jo4YWkd2lg== X-CSE-MsgGUID: R+1g+lUET1K9XNzHKwBZqA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="31944631" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa009.jf.intel.com with ESMTP; 17 May 2024 07:20:01 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 84A4010A3; 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 17/20] x86/tdx: Convert VM_RD/VM_WR tdcalls to use new TDCALL macros Date: Fri, 17 May 2024 17:19:35 +0300 Message-ID: <20240517141938.4177174-18-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: quoted-printable Content-Type: text/plain; charset="utf-8" Use newly introduced TDCALL instead of tdcall() to issue VM_RD/VM_WR tdcalls It increase code slightly: Function old new delta tdx_early_init 744 776 +32 but combined with VP_INFO changes the total effect on tdx_early_init() is code reduction. Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdx.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index e1849878f3bc..6559f3842f67 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -76,27 +76,13 @@ static inline void tdcall(u64 fn, struct tdx_module_arg= s *args) /* Read TD-scoped metadata */ static inline u64 tdg_vm_rd(u64 field, u64 *value) { - struct tdx_module_args args =3D { - .rdx =3D field, - }; - u64 ret; - - ret =3D __tdcall_ret(TDG_VM_RD, &args); - *value =3D args.r8; - - return ret; + return TDCALL_1(TDG_VM_RD, 0, field, 0, 0, value); } =20 /* Write TD-scoped metadata */ static inline u64 tdg_vm_wr(u64 field, u64 value, u64 mask) { - struct tdx_module_args args =3D { - .rdx =3D field, - .r8 =3D value, - .r9 =3D mask, - }; - - return __tdcall(TDG_VM_WR, &args); + return TDCALL_1(TDG_VM_WR, 0, field, value, mask, value); } =20 /** --=20 2.43.0 From nobody Wed Feb 11 01:26:15 2026 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 A33F874262; Fri, 17 May 2024 14:20:07 +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=1715955609; cv=none; b=dZRfq297E8cN0Epx5nlEPUQbavUa8y693w16PZlsBY29wsgpB6qygFNEVEnC+jPV2K6ajEraJ0lmOoqQU5E9wUvMZH8S/y8oefUdMW4+8oQGbKGiZPvxya00dEE227PiLDRBe8IZ5ay1HyDHa8jGiS5NB9f5MtuJRkCDI57GJfI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955609; c=relaxed/simple; bh=WocfCtclpVmI7/9b65p2gbJIFvpIqrPqyDYD9iiubjI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Sfr1A+AjdoaFvKVmGNx64+w6CEhLtvNI9r1yFPxEsGWBKD1ha1R4UEHa8rwPzey1IJ/tIGnV+nxXgp0kw3TO/4NZlk9GOu/6aO6NeWmeQSVQGhZtzuv+r9JpI0jSVKkKM8CNb0DJ0AFV888dO8WroQ7nYc/jJE/YNmEkOg/sceo= 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=W3he+NxE; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="W3he+NxE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715955608; x=1747491608; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WocfCtclpVmI7/9b65p2gbJIFvpIqrPqyDYD9iiubjI=; b=W3he+NxEBxI8dMWdlWlAkrrvvArPUVDnqmXpo/OZeCOnd4rRp0u+luex EAaYD8sdNl2AY8WgaLc3O8CnNI0IyoZIxRSY/V7Y07IWe+VNzwqmW8G9i 3lPySQr7c/mjmTVcRzGv5/19MKnAkdmLWtJ1EL75uaP9SEjbTtO2dE4b/ MzRPrszhlvdOMj7s8Zg5ycV/iXu7WJ0hABWINb14Qw1VQdC31tPlEk/FZ B3bcGpEK4svcqDeMT3vmFzsQf4uSBCH4XDV2LJbBwyjVrZSez/xSi/d8F kycp1wwxQdv/YwDN1RP37UPEi7dJlP3SWTeii1uEpDFF1S5IKAll5Ov0X Q==; X-CSE-ConnectionGUID: ie+0S6v0QNOILJTs6vjGUA== X-CSE-MsgGUID: 0BTd5nDxQoiCVQX7w6xz/A== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808764" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808764" 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:05 -0700 X-CSE-ConnectionGUID: gYjuXclTQtSwzEcwcK8DUw== X-CSE-MsgGUID: WJVtLYOmRje/oWByI/JzNg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="31944632" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa009.jf.intel.com with ESMTP; 17 May 2024 07:20:01 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 8D7701140; 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 18/20] x86/tdx: Convert VP_VEINFO_GET tdcall to use new TDCALL_5() macro Date: Fri, 17 May 2024 17:19:36 +0300 Message-ID: <20240517141938.4177174-19-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: quoted-printable Content-Type: text/plain; charset="utf-8" Use newly introduced TDCALL_5() instead of tdcall() to issue VP_VEINFO_GET tdcall. It cuts code bloat substantially: Function old new delta tdx_get_ve_info 253 116 -137 Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdx.c | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 6559f3842f67..42436a43bb49 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -615,32 +615,15 @@ __init bool tdx_early_handle_ve(struct pt_regs *regs) =20 void tdx_get_ve_info(struct ve_info *ve) { - struct tdx_module_args args =3D {}; + u64 instr_info, ret; =20 - /* - * Called during #VE handling to retrieve the #VE info from the - * TDX module. - * - * This has to be called early in #VE handling. A "nested" #VE which - * occurs before this will raise a #DF and is not recoverable. - * - * The call retrieves the #VE info from the TDX module, which also - * clears the "#VE valid" flag. This must be done before anything else - * because any #VE that occurs while the valid flag is set will lead to - * #DF. - * - * Note, the TDX module treats virtual NMIs as inhibited if the #VE - * valid flag is set. It means that NMI=3D>#VE will not result in a #DF. - */ - tdcall(TDG_VP_VEINFO_GET, &args); + ret =3D TDCALL_5(TDG_VP_VEINFO_GET, 0, 0, 0, 0, + ve->exit_reason, ve->exit_qual, ve->gla, ve->gpa, instr_info); =20 - /* Transfer the output parameters */ - ve->exit_reason =3D args.rcx; - ve->exit_qual =3D args.rdx; - ve->gla =3D args.r8; - ve->gpa =3D args.r9; - ve->instr_len =3D lower_32_bits(args.r10); - ve->instr_info =3D upper_32_bits(args.r10); + BUG_ON(ret); + + ve->instr_len =3D lower_32_bits(instr_info); + ve->instr_info =3D upper_32_bits(instr_info); } =20 /* --=20 2.43.0 From nobody Wed Feb 11 01:26:15 2026 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 6E44173514; Fri, 17 May 2024 14:20:07 +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=1715955609; cv=none; b=qCqmY4mE48CJ2ip35NQ2RHZhBcvvyFJn1Kn4xN/T30CtkaSw17uA7rmDDzlPdPL+7Wx2N9w9pAfcSbqrVEinUxMbgCqC5P/VKsZcBsEWDle5Jjyx4vV500RVsjBL8OL+Q/d9/yEa19p3gWjCgUSsNekTN5WzBwZRzdGhhivcnvs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955609; c=relaxed/simple; bh=+tEVi3m8qovNSY+AQYMMcgzTha+KB60hRspc+QX9Oac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q/KLPd4txaThLjarI2npf2Q+UOUcEOVI61oqQXBfFMcaejVvNe4lwA89yg/iiLiA24oRUvCFgmSLAbJbTNWJGAdq7+iOxsf7pYuP8uoYENJrZYacd82uma8iRGIV3bRUuerWnqI8JK+aZ5MXb23Db2tQ0UAdkNLbWtkfez/B3wY= 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=FkT9baaF; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="FkT9baaF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715955608; x=1747491608; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+tEVi3m8qovNSY+AQYMMcgzTha+KB60hRspc+QX9Oac=; b=FkT9baaF1BrrZuHMQw93q8He0AX5jBqQz/DlcZZMVYKCP6e0URtBMTjY DFPyVGafWCRMWbPBuLbq0LL6P/11Ofh+oeGte3CojTMQqbX/LJKqutAOF IqIWkpOki3J7le+579o0cA/WoDeB+zhfTILNk1MpS9CTATKz7AXGX5Pju E4v/trbAlAIMmEEeE/E7xjfsi3DpcAu2hBJd0wnTRt1bBCXmftK0664yC vUdUipf4TmbIl3y0xMLVMCF8Bbzr+sjudbfm7WUmDCZLtHh1Oa+zhkEuZ 9x2J9B74l3v3s/9wkaHA/kX8aQlwX8bAbiohHdrz8QBKbEKRLEVMm+Cb8 g==; X-CSE-ConnectionGUID: ueQn+DTQR82svELmu6qOHg== X-CSE-MsgGUID: wUAaKOE4Tv2qZtfldrttQw== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808754" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808754" 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:20:05 -0700 X-CSE-ConnectionGUID: 0/qU8eDTSq6mSdb2tK0n+Q== X-CSE-MsgGUID: C1NoCwySQLm2a2euxgmfAA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="69253427" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 17 May 2024 07:20:01 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 9AADB1146; 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 19/20] x86/tdx: Convert MR_REPORT tdcall to use new TDCALL_0() macro Date: Fri, 17 May 2024 17:19:37 +0300 Message-ID: <20240517141938.4177174-20-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: quoted-printable Content-Type: text/plain; charset="utf-8" Use newly introduced TDCALL_0() instead of tdcall() to issue MR_REPORT tdcall. It cuts code bloat substantially: Function old new delta tdx_mcall_get_report0 229 111 -118 Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdx.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 42436a43bb49..45be53d5eeb4 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -101,19 +101,15 @@ static inline u64 tdg_vm_wr(u64 field, u64 value, u64= mask) */ int tdx_mcall_get_report0(u8 *reportdata, u8 *tdreport) { - struct tdx_module_args args =3D { - .rcx =3D virt_to_phys(tdreport), - .rdx =3D virt_to_phys(reportdata), - .r8 =3D TDREPORT_SUBTYPE_0, - }; u64 ret; =20 - ret =3D __tdcall(TDG_MR_REPORT, &args); - if (ret) { - if (TDCALL_RETURN_CODE(ret) =3D=3D TDCALL_INVALID_OPERAND) - return -EINVAL; + ret =3D TDCALL_0(TDG_MR_REPORT, virt_to_phys(tdreport), + virt_to_phys(reportdata), TDREPORT_SUBTYPE_0, 0); + + if (TDCALL_RETURN_CODE(ret) =3D=3D TDCALL_INVALID_OPERAND) + return -EINVAL; + else if (ret) return -EIO; - } =20 return 0; } --=20 2.43.0 From nobody Wed Feb 11 01:26:15 2026 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 4D52A7580D; Fri, 17 May 2024 14:20:09 +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=1715955611; cv=none; b=aKNW583Fp9ekvt2pbSvlZRpGakfl2tUhnLrrlwsK/k6Kwn6gZE1KifQVjv5x1EcVcRehzjvL0Doqdav3Zt+cSDG8BFxgRipQqTQ9qNrN9mtU/XLcDqIzrYTxbkPBtPQUMoOHNdJvr4s5R1jiDXsTdgdhQ/XtQJ44iMT6vP1YIbs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955611; c=relaxed/simple; bh=le6yIb+KkrwbWU/kef10H7UOenEhvxZ9rTsGqSJuqRQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dUePCu9cjVbAjQucJsmCJ6/JT7UaKzy9zzPyr9qGv1ZhPKwSlsT6YEDB4Ru5fPivW+eVRZzxueEVeSfPSVlBkHKR7gBqW4TM3sxy+R2n40FOxtWf8uBZzbBaybpfa4GceUbYbiKzB01GJax32NcRM6StodyRtiLYU5HMMpG0dj8= 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=RURYOxlF; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="RURYOxlF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715955609; x=1747491609; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=le6yIb+KkrwbWU/kef10H7UOenEhvxZ9rTsGqSJuqRQ=; b=RURYOxlFawyAhJ4YY7UuHe/LjILJuNLfMOV3pAdn2rfi21NPpi8KAMQg aDwdxEsZsdXwWCGrl+sIo8wA8Y7STLXY3w4g4NXgQvaIEPytlUP4T+92Y UjTDk6FqNzctXlP3Yxd0/qi8/Mt0bkf/zuyineeCoRgWLULrZ/2SGu/Fy PhgGm8v2PNSBpY4JUXVUiyc2tOTE5ync05+faSvDUb/RdB9JkFwp4QUvH WEe2jM8vVN9AX0cRkyq+pt6E0+/rfojNGW4tvk+mFKzBYxjVmSEUUH1Dx O3MejvTax5r2ud4d6Fbh68UPchDoYaBecPVBOFK1z6mnA9sw3lQbeU/YP A==; X-CSE-ConnectionGUID: aFyu5bW+QCixFcncv4lcJA== X-CSE-MsgGUID: uhM4qc6VT5mCowsVpz82rg== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808782" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808782" 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:20:05 -0700 X-CSE-ConnectionGUID: 8b0g7edORxeleq05MX/vxg== X-CSE-MsgGUID: pFaPFft6R127eW8Oa6P7+Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="69253428" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 17 May 2024 07:20:01 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id A86DD125F; 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 20/20] x86/tdx: Remove old TDCALL wrappers Date: Fri, 17 May 2024 17:19:38 +0300 Message-ID: <20240517141938.4177174-21-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: quoted-printable Content-Type: text/plain; charset="utf-8" All code has been converted to new TDCALL wrappers. Drop the old wrappers. Signed-off-by: Kirill A. Shutemov --- arch/x86/boot/compressed/tdx.c | 6 ---- arch/x86/coco/tdx/tdcall.S | 60 ++----------------------------- arch/x86/coco/tdx/tdx-shared.c | 20 ----------- arch/x86/coco/tdx/tdx.c | 18 ---------- arch/x86/include/asm/shared/tdx.h | 43 +--------------------- arch/x86/virt/vmx/tdx/tdxcall.S | 29 +++++---------- tools/objtool/noreturns.h | 1 - 7 files changed, 12 insertions(+), 165 deletions(-) diff --git a/arch/x86/boot/compressed/tdx.c b/arch/x86/boot/compressed/tdx.c index 0ae05edc7d42..b74084a46f2f 100644 --- a/arch/x86/boot/compressed/tdx.c +++ b/arch/x86/boot/compressed/tdx.c @@ -10,12 +10,6 @@ =20 #include =20 -/* Called from __tdx_hypercall() for unrecoverable failure */ -void __tdx_hypercall_failed(void) -{ - error("TDVMCALL failed. TDX module bug?"); -} - static inline unsigned int tdx_io_in(int size, u16 port) { u64 out; diff --git a/arch/x86/coco/tdx/tdcall.S b/arch/x86/coco/tdx/tdcall.S index 5b60b9c8799f..407e2b7ae515 100644 --- a/arch/x86/coco/tdx/tdcall.S +++ b/arch/x86/coco/tdx/tdcall.S @@ -1,66 +1,12 @@ /* SPDX-License-Identifier: GPL-2.0 */ #include #include +#include =20 #include -#include =20 -#include "../../virt/vmx/tdx/tdxcall.S" - -.section .noinstr.text, "ax" - -/* - * __tdcall() - Used by TDX guests to request services from the TDX - * module (does not include VMM services) using TDCALL instruction. - * - * __tdcall() function ABI: - * - * @fn (RDI) - TDCALL Leaf ID, moved to RAX - * @args (RSI) - struct tdx_module_args for input - * - * Only RCX/RDX/R8-R11 are used as input registers. - * - * Return status of TDCALL via RAX. - */ -SYM_FUNC_START(__tdcall) - TDX_MODULE_CALL host=3D0 -SYM_FUNC_END(__tdcall) - -/* - * __tdcall_ret() - Used by TDX guests to request services from the TDX - * module (does not include VMM services) using TDCALL instruction, with - * saving output registers to the 'struct tdx_module_args' used as input. - * - * __tdcall_ret() function ABI: - * - * @fn (RDI) - TDCALL Leaf ID, moved to RAX - * @args (RSI) - struct tdx_module_args for input and output - * - * Only RCX/RDX/R8-R11 are used as input/output registers. - * - * Return status of TDCALL via RAX. - */ -SYM_FUNC_START(__tdcall_ret) - TDX_MODULE_CALL host=3D0 ret=3D1 -SYM_FUNC_END(__tdcall_ret) - -/* - * __tdcall_saved_ret() - Used by TDX guests to request services from the - * TDX module (including VMM services) using TDCALL instruction, with - * saving output registers to the 'struct tdx_module_args' used as input. - * - * __tdcall_saved_ret() function ABI: - * - * @fn (RDI) - TDCALL leaf ID, moved to RAX - * @args (RSI) - struct tdx_module_args for input/output - * - * All registers in @args are used as input/output registers. - * - * On successful completion, return the hypercall error code. - */ -SYM_FUNC_START(__tdcall_saved_ret) - TDX_MODULE_CALL host=3D0 ret=3D1 saved=3D1 -SYM_FUNC_END(__tdcall_saved_ret) +/* TDCALL is supported in Binutils >=3D 2.36 */ +#define tdcall .byte 0x66,0x0f,0x01,0xcc =20 /* * tdvmcall_trampoline() - Wrapper for TDG.VP.VMCALL. Covers common cases:= up diff --git a/arch/x86/coco/tdx/tdx-shared.c b/arch/x86/coco/tdx/tdx-shared.c index 9104e96eeefd..b181f7d4d3b9 100644 --- a/arch/x86/coco/tdx/tdx-shared.c +++ b/arch/x86/coco/tdx/tdx-shared.c @@ -69,23 +69,3 @@ bool tdx_accept_memory(phys_addr_t start, phys_addr_t en= d) =20 return true; } - -noinstr u64 __tdx_hypercall(struct tdx_module_args *args) -{ - /* - * For TDVMCALL explicitly set RCX to the bitmap of shared registers. - * The caller isn't expected to set @args->rcx anyway. - */ - args->rcx =3D TDVMCALL_EXPOSE_REGS_MASK; - - /* - * Failure of __tdcall_saved_ret() indicates a failure of the TDVMCALL - * mechanism itself and that something has gone horribly wrong with - * the TDX module. __tdx_hypercall_failed() never returns. - */ - if (__tdcall_saved_ret(TDG_VP_VMCALL, args)) - __tdx_hypercall_failed(); - - /* TDVMCALL leaf return code is in R10 */ - return args->r10; -} diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 45be53d5eeb4..7d9306bd67af 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -38,13 +38,6 @@ =20 static atomic_long_t nr_shared; =20 -/* Called from __tdx_hypercall() for unrecoverable failure */ -noinstr void __noreturn __tdx_hypercall_failed(void) -{ - instrumentation_begin(); - panic("TDVMCALL failed. TDX module bug?"); -} - #ifdef CONFIG_KVM_GUEST long tdx_kvm_hypercall(unsigned int nr, unsigned long p1, unsigned long p2, unsigned long p3, unsigned long p4) @@ -62,17 +55,6 @@ long tdx_kvm_hypercall(unsigned int nr, unsigned long p1= , unsigned long p2, EXPORT_SYMBOL_GPL(tdx_kvm_hypercall); #endif =20 -/* - * Used for TDX guests to make calls directly to the TD module. This - * should only be used for calls that have no legitimate reason to fail - * or where the kernel can not survive the call failing. - */ -static inline void tdcall(u64 fn, struct tdx_module_args *args) -{ - if (__tdcall_ret(fn, args)) - panic("TDCALL %lld failed (Buggy TDX module!)\n", fn); -} - /* Read TD-scoped metadata */ static inline u64 tdg_vm_rd(u64 field, u64 *value) { diff --git a/arch/x86/include/asm/shared/tdx.h b/arch/x86/include/asm/share= d/tdx.h index 70190ebc63ca..cbbc679d64a2 100644 --- a/arch/x86/include/asm/shared/tdx.h +++ b/arch/x86/include/asm/shared/tdx.h @@ -55,17 +55,6 @@ #define TDX_R14 BIT(14) #define TDX_R15 BIT(15) =20 -/* - * These registers are clobbered to hold arguments for each - * TDVMCALL. They are safe to expose to the VMM. - * Each bit in this mask represents a register ID. Bit field - * details can be found in TDX GHCI specification, section - * titled "TDCALL [TDG.VP.VMCALL] leaf". - */ -#define TDVMCALL_EXPOSE_REGS_MASK \ - (TDX_RDX | TDX_RBX | TDX_RSI | TDX_RDI | TDX_R8 | TDX_R9 | \ - TDX_R10 | TDX_R11 | TDX_R12 | TDX_R13 | TDX_R14 | TDX_R15) - /* TDX supported page sizes from the TDX module ABI. */ #define TDX_PS_4K 0 #define TDX_PS_2M 1 @@ -193,7 +182,7 @@ }) =20 /* - * Used in __tdcall*() to gather the input/output registers' values of the + * Used in __seamcall*() to gather the input/output registers' values of t= he * TDCALL instruction when requesting services from the TDX module. This i= s a * software only structure and not part of the TDX module/VMM ABI */ @@ -216,36 +205,6 @@ struct tdx_module_args { u64 rsi; }; =20 -/* Used to communicate with the TDX module */ -u64 __tdcall(u64 fn, struct tdx_module_args *args); -u64 __tdcall_ret(u64 fn, struct tdx_module_args *args); -u64 __tdcall_saved_ret(u64 fn, struct tdx_module_args *args); - -/* Used to request services from the VMM */ -u64 __tdx_hypercall(struct tdx_module_args *args); - -/* - * Wrapper for standard use of __tdx_hypercall with no output aside from - * return code. - */ -static inline u64 _tdx_hypercall(u64 fn, u64 r12, u64 r13, u64 r14, u64 r1= 5) -{ - struct tdx_module_args args =3D { - .r10 =3D TDX_HYPERCALL_STANDARD, - .r11 =3D fn, - .r12 =3D r12, - .r13 =3D r13, - .r14 =3D r14, - .r15 =3D r15, - }; - - return __tdx_hypercall(&args); -} - - -/* Called from __tdx_hypercall() for unrecoverable failure */ -void __noreturn __tdx_hypercall_failed(void); - bool tdx_accept_memory(phys_addr_t start, phys_addr_t end); =20 /* diff --git a/arch/x86/virt/vmx/tdx/tdxcall.S b/arch/x86/virt/vmx/tdx/tdxcal= l.S index 016a2a1ec1d6..7ad2fc6ba9c8 100644 --- a/arch/x86/virt/vmx/tdx/tdxcall.S +++ b/arch/x86/virt/vmx/tdx/tdxcall.S @@ -4,33 +4,28 @@ #include #include =20 -/* - * TDCALL and SEAMCALL are supported in Binutils >=3D 2.36. - */ -#define tdcall .byte 0x66,0x0f,0x01,0xcc +/* SEAMCALL is supported in Binutils >=3D 2.36 */ #define seamcall .byte 0x66,0x0f,0x01,0xcf =20 /* * TDX_MODULE_CALL - common helper macro for both * TDCALL and SEAMCALL instructions. * - * TDCALL - used by TDX guests to make requests to the - * TDX module and hypercalls to the VMM. * SEAMCALL - used by TDX hosts to make requests to the * TDX module. * *------------------------------------------------------------------------- - * TDCALL/SEAMCALL ABI: + * SEAMCALL ABI: *------------------------------------------------------------------------- * Input Registers: * - * RAX - TDCALL/SEAMCALL Leaf number. - * RCX,RDX,RDI,RSI,RBX,R8-R15 - TDCALL/SEAMCALL Leaf specific input regist= ers. + * RAX - SEAMCALL Leaf number. + * RCX,RDX,RDI,RSI,RBX,R8-R15 - SEAMCALL Leaf specific input registers. * * Output Registers: * - * RAX - TDCALL/SEAMCALL instruction error code. - * RCX,RDX,RDI,RSI,RBX,R8-R15 - TDCALL/SEAMCALL Leaf specific output regis= ters. + * RAX - SEAMCALL instruction error code. + * RCX,RDX,RDI,RSI,RBX,R8-R15 - SEAMCALL Leaf specific output registers. * *------------------------------------------------------------------------- * @@ -42,7 +37,7 @@ * also tramples on RDI,RSI. This isn't strictly true, see for example * TDH.EXPORT.MEM. */ -.macro TDX_MODULE_CALL host:req ret=3D0 saved=3D0 +.macro TDX_MODULE_CALL ret=3D0 saved=3D0 FRAME_BEGIN =20 /* Move Leaf ID to RAX */ @@ -85,7 +80,6 @@ movq TDX_MODULE_rsi(%rsi), %rsi .endif /* \saved */ =20 -.if \host .Lseamcall\@: seamcall /* @@ -100,9 +94,6 @@ * it is from the Reserved status code class. */ jc .Lseamcall_vmfailinvalid\@ -.else - tdcall -.endif =20 .if \ret .if \saved @@ -172,11 +163,9 @@ xorl %r15d, %r15d xorl %ebx, %ebx xorl %edi, %edi -.endif /* \ret && \host */ +.endif /* \saved && \ret */ =20 -.if \host .Lout\@: -.endif =20 .if \saved /* Restore callee-saved GPRs as mandated by the x86_64 ABI */ @@ -190,7 +179,6 @@ FRAME_END RET =20 -.if \host .Lseamcall_vmfailinvalid\@: mov $TDX_SEAMCALL_VMFAILINVALID, %rax jmp .Lseamcall_fail\@ @@ -215,6 +203,5 @@ jmp .Lout\@ =20 _ASM_EXTABLE_FAULT(.Lseamcall\@, .Lseamcall_trap\@) -.endif /* \host */ =20 .endm diff --git a/tools/objtool/noreturns.h b/tools/objtool/noreturns.h index 0670cacf0734..1e82a96ba960 100644 --- a/tools/objtool/noreturns.h +++ b/tools/objtool/noreturns.h @@ -11,7 +11,6 @@ NORETURN(__kunit_abort) NORETURN(__module_put_and_kthread_exit) NORETURN(__reiserfs_panic) NORETURN(__stack_chk_fail) -NORETURN(__tdx_hypercall_failed) NORETURN(__ubsan_handle_builtin_unreachable) NORETURN(arch_cpu_idle_dead) NORETURN(bch2_trans_in_restart_error) --=20 2.43.0