From patchwork Tue Sep 12 23:44:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 138682 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp910255vqx; Wed, 13 Sep 2023 00:30:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGAnc+HK7j4Y64iHz4ZyE9LCQPeFNN6fH8pkhHbOsPNDD2jX5X1D8BU1OK5Cygq20beFE0S X-Received: by 2002:a17:90b:149:b0:268:b0b:a084 with SMTP id em9-20020a17090b014900b002680b0ba084mr1384760pjb.46.1694590223037; Wed, 13 Sep 2023 00:30:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694590223; cv=none; d=google.com; s=arc-20160816; b=rH4zTncb0jcrxV6up8kbVb4cc914ry607WVg8uU9Ps4L6MnQqqaeilYgCc04DZ7rQc ok/Smv9o6ia0bEE8ykvjWYPmFBDydBLuXDTfR1DAebKZE3xd5WBSqTaA6wKWDZBkYC19 wnUj1dLnwrzDQgYk4WbN6xc2asw/cuJrZutN7AkIGEQ+kYobnGGi1SNgq71LiEOjd10Y SGvyY4ualhL5nOE85ldYnMHBlCUUOw/kOcEp4FdHVTPBXQmyGOXcO99kvoGBGdLkVZpL 6ZDcgGRGFo8oJLOf6dC01zbh2i4+WO2QXPKrkOpZm1AJg7wX7rFObGqDf9B2YD1xT3QS utsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=1t279XtwDUnmPy7ug/Cle94fwl3qpfmej2l+HGTQNhc=; fh=tokEOB3Y0iQhJ4/yHLC9nqS2lpWkIee/+HvLmm47UHQ=; b=L5VxZ/W7c+AbXUxHMgCAC7khksAN/CwZla7n3M2FeR2N3+dulprlzGM7LuI/NyrC3y lCBduDnwOIm0V+mJbxAMn4lsukEp06QzCCBSBRpVAgdSsxUdWTlPW0yrXhny7dWAPj2O KBGoZ5C3C6ixje2WwgPCf7lMmWUCEnlN2skv1t9S9cLbxAwtyY+yQoXJ+TRzN7gzY63T kLjZFYiONWEb/wk1VTEptp9K9Cp77s5KSWakSzhfnXQt23GjAX04R7ZfSXzQZBnY+a7/ 87gGhAzFAGZ8/dMSbvVUy4fkmlJyWrn34rAkTp37h1BmOtntT7QMtvviRPPwaoHKUOKg cDJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=P8MW9i6P; dkim=neutral (no key) header.i=@linutronix.de header.b=Hg44kiKR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id m21-20020a17090aab1500b00263c23a5693si951145pjq.13.2023.09.13.00.30.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 00:30:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=P8MW9i6P; dkim=neutral (no key) header.i=@linutronix.de header.b=Hg44kiKR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 9E9748260FB0; Tue, 12 Sep 2023 16:44:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237902AbjILXo1 (ORCPT + 36 others); Tue, 12 Sep 2023 19:44:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234366AbjILXoZ (ORCPT ); Tue, 12 Sep 2023 19:44:25 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D32B1704; Tue, 12 Sep 2023 16:44:21 -0700 (PDT) Date: Tue, 12 Sep 2023 23:44:19 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694562259; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1t279XtwDUnmPy7ug/Cle94fwl3qpfmej2l+HGTQNhc=; b=P8MW9i6PW9yWA4R2ft5LBxusnXGBcZgsioDOvCEJol1Cuk0KJovWoBP2iLBq2q/Wer8qDb T42EoufPIN1b5zdkaVvp20eUyahY6FjIVqrf02Zjc0vCLTowaodtQJxCN1QPrnpe0ZSdRz w7YFtVB8raEGUKVezm7Vy8tA11Q/yr+Ug1rIG+xXA64VWiMyVGdjhRHXACmudmQIKi2vm0 K0URfExZcCJ+6nWY9YiWaiGxRMVCiNX++18JJjxzGkkkMTCywBmmFWpVreOVtJ4aWt+e9j jAP0GQw7yX0eCQb9Qo91tZLEN2Aiuy3qdmSHPNgGjEPK0EraWVeO897cpCQJYA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694562259; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1t279XtwDUnmPy7ug/Cle94fwl3qpfmej2l+HGTQNhc=; b=Hg44kiKRcDEivVeRUIDatISrSsEAgEHZyhI9fI++M7xfB3pFmcmzWUE0t0azZj5i6TdLyL 78cWDjAveBjjggBQ== From: "tip-bot2 for Kai Huang" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/tdx] x86/virt/tdx: Wire up basic SEAMCALL functions Cc: Kai Huang , Dave Hansen , "Kirill A. Shutemov" , "Peter Zijlstra (Intel)" , Isaku Yamahata , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <169456225924.27769.10034121733735537314.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 12 Sep 2023 16:44:49 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776850210292190257 X-GMAIL-MSGID: 1776906637642126677 The following commit has been merged into the x86/tdx branch of tip: Commit-ID: c33621b4c5ad5b6b8b245754013cc506f9ded2b8 Gitweb: https://git.kernel.org/tip/c33621b4c5ad5b6b8b245754013cc506f9ded2b8 Author: Kai Huang AuthorDate: Tue, 15 Aug 2023 23:02:04 +12:00 Committer: Dave Hansen CommitterDate: Tue, 12 Sep 2023 16:30:27 -07:00 x86/virt/tdx: Wire up basic SEAMCALL functions Intel Trust Domain Extensions (TDX) protects guest VMs from malicious host and certain physical attacks. A CPU-attested software module called 'the TDX module' runs inside a new isolated memory range as a trusted hypervisor to manage and run protected VMs. TDX introduces a new CPU mode: Secure Arbitration Mode (SEAM). This mode runs only the TDX module itself or other code to load the TDX module. The host kernel communicates with SEAM software via a new SEAMCALL instruction. This is conceptually similar to a guest->host hypercall, except it is made from the host to SEAM software instead. The TDX module establishes a new SEAMCALL ABI which allows the host to initialize the module and to manage VMs. The SEAMCALL ABI is very similar to the TDCALL ABI and leverages much TDCALL infrastructure. Wire up basic functions to make SEAMCALLs for the basic support of running TDX guests: __seamcall(), __seamcall_ret(), and __seamcall_saved_ret() for TDH.VP.ENTER. All SEAMCALLs involved in the basic TDX support don't use "callee-saved" registers as input and output, except the TDH.VP.ENTER. To start to support TDX, create a new arch/x86/virt/vmx/tdx/tdx.c for TDX host kernel support. Add a new Kconfig option CONFIG_INTEL_TDX_HOST to opt-in TDX host kernel support (to distinguish with TDX guest kernel support). So far only KVM uses TDX. Make the new config option depend on KVM_INTEL. Signed-off-by: Kai Huang Signed-off-by: Dave Hansen Reviewed-by: Kirill A. Shutemov Acked-by: Peter Zijlstra (Intel) Tested-by: Isaku Yamahata Link: https://lore.kernel.org/all/4db7c3fc085e6af12acc2932294254ddb3d320b3.1692096753.git.kai.huang%40intel.com --- arch/x86/Kconfig | 12 ++++++- arch/x86/Makefile | 2 +- arch/x86/include/asm/tdx.h | 7 ++++- arch/x86/virt/Makefile | 2 +- arch/x86/virt/vmx/Makefile | 2 +- arch/x86/virt/vmx/tdx/Makefile | 2 +- arch/x86/virt/vmx/tdx/seamcall.S | 61 +++++++++++++++++++++++++++++++- 7 files changed, 88 insertions(+) create mode 100644 arch/x86/virt/Makefile create mode 100644 arch/x86/virt/vmx/Makefile create mode 100644 arch/x86/virt/vmx/tdx/Makefile create mode 100644 arch/x86/virt/vmx/tdx/seamcall.S diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 982b777..3b3594f 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1939,6 +1939,18 @@ config X86_USER_SHADOW_STACK If unsure, say N. +config INTEL_TDX_HOST + bool "Intel Trust Domain Extensions (TDX) host support" + depends on CPU_SUP_INTEL + depends on X86_64 + depends on KVM_INTEL + help + Intel Trust Domain Extensions (TDX) protects guest VMs from malicious + host and certain physical attacks. This option enables necessary TDX + support in the host kernel to run confidential VMs. + + If unsure, say N. + config EFI bool "EFI runtime service support" depends on ACPI diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 5bfe5ca..d43981a 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -252,6 +252,8 @@ archheaders: libs-y += arch/x86/lib/ +core-y += arch/x86/virt/ + # drivers-y are linked after core-y drivers-$(CONFIG_MATH_EMULATION) += arch/x86/math-emu/ drivers-$(CONFIG_PCI) += arch/x86/pci/ diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index 603e6d1..a69bb7d 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -72,5 +72,12 @@ static inline long tdx_kvm_hypercall(unsigned int nr, unsigned long p1, return -ENODEV; } #endif /* CONFIG_INTEL_TDX_GUEST && CONFIG_KVM_GUEST */ + +#ifdef CONFIG_INTEL_TDX_HOST +u64 __seamcall(u64 fn, struct tdx_module_args *args); +u64 __seamcall_ret(u64 fn, struct tdx_module_args *args); +u64 __seamcall_saved_ret(u64 fn, struct tdx_module_args *args); +#endif /* CONFIG_INTEL_TDX_HOST */ + #endif /* !__ASSEMBLY__ */ #endif /* _ASM_X86_TDX_H */ diff --git a/arch/x86/virt/Makefile b/arch/x86/virt/Makefile new file mode 100644 index 0000000..1e36502 --- /dev/null +++ b/arch/x86/virt/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-y += vmx/ diff --git a/arch/x86/virt/vmx/Makefile b/arch/x86/virt/vmx/Makefile new file mode 100644 index 0000000..feebda2 --- /dev/null +++ b/arch/x86/virt/vmx/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_INTEL_TDX_HOST) += tdx/ diff --git a/arch/x86/virt/vmx/tdx/Makefile b/arch/x86/virt/vmx/tdx/Makefile new file mode 100644 index 0000000..46ef8f7 --- /dev/null +++ b/arch/x86/virt/vmx/tdx/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-y += seamcall.o diff --git a/arch/x86/virt/vmx/tdx/seamcall.S b/arch/x86/virt/vmx/tdx/seamcall.S new file mode 100644 index 0000000..5b1f228 --- /dev/null +++ b/arch/x86/virt/vmx/tdx/seamcall.S @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include +#include + +#include "tdxcall.S" + +/* + * __seamcall() - Host-side interface functions to SEAM software + * (the P-SEAMLDR or the TDX module). + * + * __seamcall() function ABI: + * + * @fn (RDI) - SEAMCALL Leaf number, moved to RAX + * @args (RSI) - struct tdx_module_args for input + * + * Only RCX/RDX/R8-R11 are used as input registers. + * + * Return (via RAX) TDX_SEAMCALL_VMFAILINVALID if the SEAMCALL itself + * fails, or the completion status of the SEAMCALL leaf function. + */ +SYM_FUNC_START(__seamcall) + TDX_MODULE_CALL host=1 +SYM_FUNC_END(__seamcall) + +/* + * __seamcall_ret() - Host-side interface functions to SEAM software + * (the P-SEAMLDR or the TDX module), with saving output registers to + * the 'struct tdx_module_args' used as input. + * + * __seamcall_ret() function ABI: + * + * @fn (RDI) - SEAMCALL Leaf number, 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 (via RAX) TDX_SEAMCALL_VMFAILINVALID if the SEAMCALL itself + * fails, or the completion status of the SEAMCALL leaf function. + */ +SYM_FUNC_START(__seamcall_ret) + TDX_MODULE_CALL host=1 ret=1 +SYM_FUNC_END(__seamcall_ret) + +/* + * __seamcall_saved_ret() - Host-side interface functions to SEAM software + * (the P-SEAMLDR or the TDX module), with saving output registers to the + * 'struct tdx_module_args' used as input. + * + * __seamcall_saved_ret() function ABI: + * + * @fn (RDI) - SEAMCALL Leaf number, moved to RAX + * @args (RSI) - struct tdx_module_args for input and output + * + * All registers in @args are used as input/output registers. + * + * Return (via RAX) TDX_SEAMCALL_VMFAILINVALID if the SEAMCALL itself + * fails, or the completion status of the SEAMCALL leaf function. + */ +SYM_FUNC_START(__seamcall_saved_ret) + TDX_MODULE_CALL host=1 ret=1 saved=1 +SYM_FUNC_END(__seamcall_saved_ret)