From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 8437D3612C7 for ; Thu, 12 Feb 2026 14:36:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770906988; cv=none; b=CRD9dAY9cV7jw8wkq5otcoIL98uUzdCWue3qh/K44EDt3vUPvAMCnJz4hQkccTNha6RbfRBhUzNkPxP0oUBBKGpW8zhz3vLExAk1jv2yVzscN3p5c8myHJffLVnQ8megaabYxicQh6yI0rWhEpCszXYjdASq2ZIHqPWy2D4doMI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770906988; c=relaxed/simple; bh=BX7ygtZFvJPEzVUbeQoXbZUlUOeLCwsJsHrJjyMR/G4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LFlTVhrERJBHS00dEDyizRkywdg4XM745qVge6aaZ3HzTEBI2/m+uv9fzcFvz57/p83MmGT8kDLpFQ7Fxry59kZ5fB8NxHDyh3R0BjdCeO2h2jmMy4CQ8sfS+3ZKmhiHWfjoF2JZMuQMHMr8eGMGN/w4q0PnbBFgN0TgxY3KOUo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=HDfUFUwx; arc=none smtp.client-ip=192.198.163.8 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="HDfUFUwx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770906985; x=1802442985; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BX7ygtZFvJPEzVUbeQoXbZUlUOeLCwsJsHrJjyMR/G4=; b=HDfUFUwxjX4VXKkIlsKSrmGAkTuasfdpZ2mn52PSjsyC95lGhKsZytTF lPej87fgxdxl+QKTtMfac2lh23hXRBDdZwfHj5sT9vUpD7SVmU9/C1rdI sGwrEAV/YRzqnfTamIobEfsqsyIYDgQgwvx5UAG3eJ1BIaVXAm4cC/jvh L836Rh694uz/GeM/PJM1rApVhpfB33yQXc9EUoFCTG5sOrCeXu830oC2i jcpWSKRlzbA/icMtF3IrjqpALNPFQHAskeOZ6wjKIllGOMOXxMQIRX+uE zj1sepDXMuU0c24xe9JwfcMCEoEDI6V0u+zMyd8W6qNDIZgP30uG3KyHc Q==; X-CSE-ConnectionGUID: kbzdHxQaS/GRJyqXJuPPpA== X-CSE-MsgGUID: SbNZUnhHQi+P3WqoH3KdxA== X-IronPort-AV: E=McAfee;i="6800,10657,11699"; a="89662852" X-IronPort-AV: E=Sophos;i="6.21,286,1763452800"; d="scan'208";a="89662852" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2026 06:36:24 -0800 X-CSE-ConnectionGUID: eoh/vWP7SXGN9Y1O7OXahA== X-CSE-MsgGUID: GtjqgFO6QYiGB/t6i1IDFw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,286,1763452800"; d="scan'208";a="211428270" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2026 06:36:24 -0800 From: Chao Gao To: linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org Cc: reinette.chatre@intel.com, ira.weiny@intel.com, kai.huang@intel.com, dan.j.williams@intel.com, yilun.xu@linux.intel.com, sagis@google.com, vannapurve@google.com, paulmck@kernel.org, nik.borisov@suse.com, zhenzhong.duan@intel.com, seanjc@google.com, rick.p.edgecombe@intel.com, kas@kernel.org, dave.hansen@linux.intel.com, vishal.l.verma@intel.com, binbin.wu@linux.intel.com, tony.lindgren@linux.intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Subject: [PATCH v4 14/24] x86/virt/tdx: Reset software states during TDX Module shutdown Date: Thu, 12 Feb 2026 06:35:17 -0800 Message-ID: <20260212143606.534586-15-chao.gao@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260212143606.534586-1-chao.gao@intel.com> References: <20260212143606.534586-1-chao.gao@intel.com> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The TDX module requires a one-time global initialization (TDH.SYS.INIT) and per-CPU initialization (TDH.SYS.LP.INIT) before use. These initializations are guarded by software flags to prevent repetition. After TDX module updates, the new TDX module requires the same global and per-CPU initializations, but the existing software flags prevent re-initialization. Reset all software flags guarding the initialization flows to allow the global and per-CPU initializations to be triggered again after updates. Signed-off-by: Chao Gao Reviewed-by: Tony Lindgren --- arch/x86/virt/vmx/tdx/tdx.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index f911c8c63800..a1193efc1156 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -55,6 +55,8 @@ static struct tdmr_info_list tdx_tdmr_list; static enum tdx_module_status_t tdx_module_status; static DEFINE_MUTEX(tdx_module_lock); +static bool sysinit_done; +static int sysinit_ret; /* All TDX-usable memory regions. Protected by mem_hotplug_lock. */ static LIST_HEAD(tdx_memlist); @@ -70,8 +72,6 @@ static int try_init_module_global(void) { struct tdx_module_args args = {}; static DEFINE_RAW_SPINLOCK(sysinit_lock); - static bool sysinit_done; - static int sysinit_ret; lockdep_assert_irqs_disabled(); @@ -1179,6 +1179,7 @@ EXPORT_SYMBOL_FOR_KVM(tdx_enable); int tdx_module_shutdown(void) { struct tdx_module_args args = {}; + int ret, cpu; /* * Shut down the TDX Module and prepare handoff data for the next @@ -1188,7 +1189,17 @@ int tdx_module_shutdown(void) * modules as new modules likely have higher handoff version. */ args.rcx = tdx_sysinfo.handoff.module_hv; - return seamcall_prerr(TDH_SYS_SHUTDOWN, &args); + ret = seamcall_prerr(TDH_SYS_SHUTDOWN, &args); + if (ret) + return ret; + + tdx_module_status = TDX_MODULE_UNINITIALIZED; + sysinit_done = false; + sysinit_ret = 0; + + for_each_online_cpu(cpu) + per_cpu(tdx_lp_initialized, cpu) = false; + return 0; } static bool is_pamt_page(unsigned long phys) -- 2.47.3