Re: [PATCH v8 11/21] x86/virt/tdx: Reset software states during TDX module shutdown

Dave Hansen
2026-04-30T18:58:12Z

On 4/27/26 08:28, Chao Gao wrote:
> + /*
> + * Clear global and per-CPU initialization flags so the new module
> + * can be fully re-initialized after a successful update.
> + *
> + * No locks needed as no concurrent accesses can occur here.
> + */
> + tdx_module_initialized = false;
> + sysinit_done = false;
> + sysinit_ret = 0;
> + for_each_possible_cpu(cpu)
> + per_cpu(tdx_lp_initialized, cpu) = false;

This speaks to needing refactoring.

If there's global TDX state, it needs to be in a global TDX state
structure, not scattered across random global variables.

Imagine the structure is:

struct tdx_module_config foo;

That's 0's at boot. You have to init the TDX module to bring it out of
0's to valid state. It actually means something if you do:

memset(&foo, 0, sizeof(foo));

Because it takes it right back to its bss state. That ^ is also handy
because it naturally just works if new state gets added.

Guess what will happen the next time someone adds:

int sysinit_new_fancy_thing;

Someone will forget to add it to this code. Then the module gets updated
and breaks things in fun ways.