From nobody Sat Feb 7 08:27:20 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 2DB0C330640; Fri, 23 Jan 2026 15:00:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769180435; cv=none; b=buMu6fJ5aWt4+4IQob7CO2JEaDtU8EvaQRRLGYKNcJU1pHqNzCZTeyHELLg93Ws+qlWgZrmLx/O2lj2/6gr7oxys7Nigqbb9F7HI5uqK2DJZxA5+dmlGifo9dOvxz/qLcDcVdbyyqpZQvwxWGv1WJPQaB5fOKQxfVxyfcflTbtM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769180435; c=relaxed/simple; bh=zY5aVbwXxUTAc4TRpLTMQoaPT5wFuMGqIm8BtbmOegs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nz5ZOz5aPP+kfJTw/E105jnlcNF2eDSpKri6HJg3g9c3HwJvNz82FEijRujKSAn+xm796T9wyWDxJOd/hWvF8SGRgU7gzJJNSK6smw1loavnF7X05MCdm9jwal8tqQfvXay7M8f9ZQz3SBI/g0A2NcTurdwD+iX71LMeqiQHWIQ= 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=Fx0K1vD7; arc=none smtp.client-ip=192.198.163.17 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="Fx0K1vD7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1769180433; x=1800716433; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zY5aVbwXxUTAc4TRpLTMQoaPT5wFuMGqIm8BtbmOegs=; b=Fx0K1vD7jS/bH+EJyXwoQ74qM/XDEGrT7sI4cBS1OMYtT5nq3KNBkQfi wq+6CEe4Qtw6D0x7CGwsTnemX7PfKvTn8QGZaa8kRyxqB4YXPDR/SWv1j HqiffwaDweNfHWreFcqxkph+gz1/DypUWSd6oeRQiFx0SeJl4dHZMyL06 +efRE7WUbVChzEu0vh89AL5RE2QV4QV5euvn8rOrpOO38hUGw6SXVNjUL 6AlxX4RDXt/kWGCPvRBSsN1IhH8mPYoZN2P7w5F+EY4wdNXpjmSpi4wuo EReQOjv+z8X8+p9CNp62sX71enim12DVGhm6cG+5ar7eWgZHt1QPcglNe w==; X-CSE-ConnectionGUID: HIhAMTyeStq7TAurFVhRqw== X-CSE-MsgGUID: EIAMG8bzSsq3D4+rXYdJEg== X-IronPort-AV: E=McAfee;i="6800,10657,11680"; a="70334469" X-IronPort-AV: E=Sophos;i="6.21,248,1763452800"; d="scan'208";a="70334469" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2026 07:00:17 -0800 X-CSE-ConnectionGUID: LFFzWEJHTqWcEsfK3UXMVA== X-CSE-MsgGUID: 314T0wDFQyy+zhy6lsj1Bg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,248,1763452800"; d="scan'208";a="237697174" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2026 07:00:17 -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, Chao Gao , Farrah Chen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Subject: [PATCH v3 17/26] x86/virt/tdx: Reset software states after TDX module shutdown Date: Fri, 23 Jan 2026 06:55:25 -0800 Message-ID: <20260123145645.90444-18-chao.gao@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260123145645.90444-1-chao.gao@intel.com> References: <20260123145645.90444-1-chao.gao@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" 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 Tested-by: Farrah Chen 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 8b36a80cf229..2763c1869b78 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -54,6 +54,8 @@ static struct tdmr_info_list tdx_tdmr_list; =20 static enum tdx_module_status_t tdx_module_status; static DEFINE_MUTEX(tdx_module_lock); +static bool sysinit_done; +static int sysinit_ret; =20 /* All TDX-usable memory regions. Protected by mem_hotplug_lock. */ static LIST_HEAD(tdx_memlist); @@ -69,8 +71,6 @@ static int try_init_module_global(void) { struct tdx_module_args args =3D {}; static DEFINE_RAW_SPINLOCK(sysinit_lock); - static bool sysinit_done; - static int sysinit_ret; =20 lockdep_assert_irqs_disabled(); =20 @@ -1178,6 +1178,7 @@ EXPORT_SYMBOL_FOR_KVM(tdx_enable); int tdx_module_shutdown(void) { struct tdx_module_args args =3D {}; + int ret, cpu; =20 /* * Shut down the TDX Module and prepare handoff data for the next @@ -1188,7 +1189,17 @@ int tdx_module_shutdown(void) * hand-off version. */ args.rcx =3D tdx_sysinfo.handoff.module_hv; - return seamcall_prerr(TDH_SYS_SHUTDOWN, &args); + ret =3D seamcall_prerr(TDH_SYS_SHUTDOWN, &args); + if (ret) + return ret; + + tdx_module_status =3D TDX_MODULE_UNINITIALIZED; + sysinit_done =3D false; + sysinit_ret =3D 0; + + for_each_online_cpu(cpu) + per_cpu(tdx_lp_initialized, cpu) =3D false; + return 0; } =20 static bool is_pamt_page(unsigned long phys) --=20 2.47.3