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=1796187347; b=TEYlXdj/WRNoRREcFZRf9IrxgVgoR/ujBWN9nmqjLe7trci7DgviRVg9/eLK+Sm2NlPV 0X9UTLd+MmtUV3xDrI7r+U+sEx6DHTuBwJRJ5uFyc0vahxjVZ+V2MtAgSpgOVcQWHYK9z e2Y3hb9LtqJO8Nzeoje/S6XQ6KydR2fPcfJV/NESsaUjUSY1BfcnROAk3RRQKvy4sfUJS aZz89vGbq0i2IvrYH+70eewH+r9I8iuw/OCVpORuMX2FAA3iERJLd1m53wwwnN3sjH05s KCeYZA8M6t5HC19LlUe+AJSSKUUhzrb0uMBc17drBh3FRo9IlbckQrItSMF3ONBUjmQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796187347; 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=gWwvSTg54WG0327CGYzXsjzzyDj9/zCRMcWh3ji5BpLlF7OlwGppKjahRMPfBk51iOcA MPTf0+lyZSUP5072Pv4KT/t1lcH0alqFwRqjEkHWMguJHLZ+TcRYCRWSA/Elj55tXP6bk 3lLe3lzsiakiTgx+qhjmilu0By8o6Yg2FJxuCa36x+pYxdTx2EZcImWxm5KgHZaXigHW5 fsFqxYHkXM3baC9qD0QZE4bgfji8k5I82fsaLJ42aT3OCNPQlTezWIbw3i73SFGuWg5Ug 1EA1fnHzhe2vTaQ6zbCHN9xmzLosa5b6IpF6TzOqPECkcEMqriMexDzp7SgOu/vc1OA== 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=dwvAxzDt; 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 61399606A327 for ; Wed, 2 Dec 2026 04:55:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 61399606A327 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=dwvAxzDt DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796187347; x=1827723347; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=rZVXt9LrFk4nWqSoqPEf8DwjAnp9BxZGOYIRQ1/7VrU=; b=dwvAxzDtC5iljpySMJbk1jL9KoideQnwN3CysfvJVxJ6YNJWZTbqiHXb svitpRZ9iasxtuOvzL2kaad/YFKYIuiLNInlRKYpIgP5ZpBCOGbL0qYMG R+ZkzzioqZpMcz3C/E/RwF0dpf+L9h0SvxI16DmN15CJHFDxQn33H7022 FIqfWNEqVGHwu/kQZ7LHHNVjqKBk1agLUEJOzMwY8R1PlCKVxaSdkunrk 1p7ofiejxnBea5kYsStlc2i7H1i4SooIMMu21WWHv6TT7cJYUduvfoYSo CB9JsOYKMUmUpUKLCggJTeGXubbFyxUXpAOgyE5OysQSBNaL+x7d5jDV4 w==; X-CSE-ConnectionGUID: xP77YGUiQB2h7WNL5uAZCA== X-CSE-MsgGUID: mDtHRTLvSPuJ9cRMzcHnfA== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5108522" X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="5108522" 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-coco@lists.linux.dev 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