From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.19 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796187348; b=v50hhcpD8I/UkAFM+qOLCtfF4id/ocmOBopkfG+fY7SC7RzL/Pl70HPoNC3SwzLCuIeI WC37Qf3Vm0waPmdy7nOpieZob/Vgd/VLa9abzfMcPhPR2qpyAFWbg40ZkMvu2cA7oLZh8 Izak+AwT8X9aq1YjnB8tKxadnES/Li3EUa60/38PQllWtXLuNXWrjKPqx2tooU7TzjVew nV8le22yXBVPH3IzD1viHWMiSNA4E/LPD7c7mqb2NUs4q6yx4BmjjYvkS/7DQ/aSu83AY i8E3E8RBo38R8KmcYcPtGXhMfNF9wdz4yCjLn1Kj9LE4KmkxrnW09/E8U6WRdFsb98Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796187348; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:Date:Subject: MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id: References:In-Reply-To:To:Cc:X-Mailer:X-Developer-Signature: X-Developer-Key; bh=rZVXt9LrFk4nWqSoqPEf8DwjAnp9BxZGOYIRQ1/7VrU=; b=R4SZSg/y+zi0aofYwfL9floLGOo+4I3QbOJwwcs6NZQFWAvuAaalMKvwT5mPN2qSGpld ePg4Te18ZB0tq6OVIVAp23mLM40R4yXBCKyOryNoRpCUkJTQ+lnj9BJp3OzMRsShQ0aSb Fww2dh0XbkPIpK+4uACsafPzeMrpxH29N8QQVERTjAmUl1YmZ63CReX5GAAosKU+CKdlf oApalu2dRvAhS1GJ/AvM2iXi8jOSFO/KMoyfhTwAJnAlaAz8tCBztnxptbZ/izFISd6xb bQQRiay9xGF8W9/9sg5iEU9BMVjDNfSKYp4kwVAsD/r5HimC79P6yEzHRllntULm1aw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=B4xRGATp; arc=none smtp.remote-ip=192.198.163.19 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F949606A325; Wed, 2 Dec 2026 04:55:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5F949606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=B4xRGATp DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796187348; x=1827723348; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=rZVXt9LrFk4nWqSoqPEf8DwjAnp9BxZGOYIRQ1/7VrU=; b=B4xRGATpDct+s9uTFJmPjE151bJmTUq7PSJkEnIzmbKHCp6vVlqomHpX 2L/kVkzFqB4w9gN1U/tXa9YNV4AdwO+XoMYb63HQm8TitbT/s8y+uFtaN +prJoJ08cD6LT6/3BJTV6OakZoNt+jX0kfYly8Z9ke1HEVVG+H5lTXTOn lV+oPIhOmEEifv4WFp7zhUVw4NxamASbonSKPasmg3mdxKMc1GsYa4qZY 77uMH/nXz4y/HXyOTCL72TNKt3EfP2+WO0l88YLFHqW1Q3SWIug3cfmad GMFYnxtGZBQNq2cfyY8uzwqvNmpFhaFTqelhnP2qxUnZp46sG07YKPLu6 g==; X-CSE-ConnectionGUID: HQIJl2KyR+GhXh66c97Klw== X-CSE-MsgGUID: gluH9s8MSe6ioMQjStUfOw== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5108520" X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="5108520" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 20:55:46 -0800 X-CSE-ConnectionGUID: PueVrRmrTcGYWmv7b2qbkw== X-CSE-MsgGUID: OxSk+xa2SW2IxWAa3W0aVw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="13411241" Received: from yilunxu-optiplex-7050.sh.intel.com (HELO [127.0.1.1]) ([10.239.47.46]) by orviesa002.jf.intel.com with ESMTP; 01 Dec 2026 20:55:42 -0800 From: Xu Yilun Date: Wed, 02 Dec 2026 12:43:30 +0800 Subject: [PATCH v6 6/6] x86/virt/tdx: Re-initialize the extensions on runtime TDX module update X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261202-tdx-module-ext-v6-6-f6d8510fe498@linux.intel.com> References: <20261202-tdx-module-ext-v6-0-f6d8510fe498@linux.intel.com> In-Reply-To: <20261202-tdx-module-ext-v6-0-f6d8510fe498@linux.intel.com> To: x86@kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Kiryl Shutsemau , Rick Edgecombe , Dave Hansen , dave.hansen@intel.com, kvm@vger.kernel.org, yilun.xu@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, sohil.mehta@intel.com, adrian.hunter@intel.com, kishen.maloor@intel.com, tony.lindgren@linux.intel.com, peter.fang@intel.com, baolu.lu@linux.intel.com, zhenzhong.duan@intel.com, chao.gao@intel.com, artem.bityutskiy@linux.intel.com, nik.borisov@suse.com X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3701; i=yilun.xu@linux.intel.com; h=from:subject:message-id; bh=XdBfePiWvrrQz0iQeNl5Epj2n78q7wIc/O2MlLw71js=; b=owGbwMvMwCH2Zztz45IFPbcYT6slMWTzL1JhsY5ZJHhstY3Ix1zxjOVXWgRqZP8Ya71uWnRSU qvoQYljRycLgxgHg6GYIssCj1lOU9pnMW39tPMazBxWJpAhwjKVmTmleXoVpQ6ZeSWpOXrJ+bkM XJwCMFXuYYwMN6V+31UpUShhWHlnnvr8uZnC3xrk/Cqfxd3pUZDrmLT/M8NfecHuJ0Y7PmxbXWx Rc2jJ1gNvngk1Hl/4Onz3IUYdjf79DAA= X-Developer-Key: i=yilun.xu@linux.intel.com; a=openpgp; fpr=A612D44FA98BA699FECC642BE2C8D72186AC3949 Runtime TDX module update introduces a mechanism to update the module firmware while preserving and restoring TDX operations. The extensions functionalities should also be re-initialized as part of the restoration process. The TDX architecture supports an update flow which allows updated extensions to consume more memory than their original boot-time requirement. So the arch defines the extensions re-initialization flow the same as boot-up initialization: the host queries TDX module how much additional memory needed, allocates it, adds it to the module via TDH.EXT.MEM.ADD, then re-initializes the extensions via TDH.EXT.INIT. Linux runs the updates in stop_machine() context, which prevents memory allocation. So for Linux, a compatible update must not install updated extensions that require additional memory. Given that the memory for the extensions must not increase, the re-initialization skips the memory adding steps. It is simplified as: - Check if the extensions are supported via TDX_FEATURES0_EXT. If not, skip the extensions re-initialization. - Re-initialize the extensions via TDH.EXT.INIT. The SEAMCALL leaf will fail if the updated extensions require more memory, which indicates the update image is not compatible. Signed-off-by: Xu Yilun Reviewed-by: Tony Lindgren Reviewed-by: Kiryl Shutsemau (Meta) Reviewed-by: Rick Edgecombe --- v6: - Remove the AI usage in the log (Rick) v5: - Better clarify the AI usage v4: - Collect Reviewed-by tags v3: - Add this patch back because the latest discussion decides the re-initialization won't be integrated in TDH.SYS.UPDATE, a dedicated TDH.EXT.INIT call is still needed (Dave & Rick) - Drop the ext_required check (Rick) - Rename the reinit function as reinit_tdx_module_extensions() (Tony) - Move the reinit function right under tdh_sys_update() (Rick) v2: - Removed this patch because the TDX module is expected to re-initialize the extensions on TDH.SYS.UPDATE v1: - Don't update the extensions metadata any more, only check the metadata originated at boot time. - Remove memory_pool_required_pages check, let TDH.EXT.INIT fail if more memory required. - Changelog & code comments --- arch/x86/virt/vmx/tdx/tdx.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index 85387c3f606f..dbe17a136dce 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -1344,7 +1344,7 @@ static __init int tdx_ext_mem_setup(void) return ret; } -static __init int tdx_ext_init(void) +static int tdx_ext_init(void) { struct tdx_module_args args = {}; u64 ret; @@ -1375,6 +1375,19 @@ static __init int init_tdx_module_extensions(void) return tdx_ext_init(); } +/* + * Don't update the memory requirement metadata or try memory allocation in + * stop_machine(). If an incompatible update requires more memory, let the + * extensions re-initialization fail. + */ +static int reinit_tdx_module_extensions(void) +{ + if (!(tdx_sysinfo.features.tdx_features0 & TDX_FEATURES0_EXT)) + return 0; + + return tdx_ext_init(); +} + static __init int init_tdx_module(void) { int ret; @@ -1558,6 +1571,10 @@ int tdx_module_run_update(void) if (ret) return ret; + ret = reinit_tdx_module_extensions(); + if (ret) + return ret; + ret = get_tdx_sys_info_version(&tdx_sysinfo.version); /* * Only fails if there is something unexpected -- 2.25.1