x86/smpboot: Don't unconditionally call memguard_guard_stack() in cpu_smpboot_alloc()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 5 Oct 2020 11:46:30 +0000 (12:46 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 16 Oct 2020 10:56:59 +0000 (11:56 +0100)
commita7952a320c1e202a218702bfdb14f75132f04894
tree48f15747afd0be657dfdd6513b8658032d061491
parent04182d8b795dcdabf4f3873d3f5c78b67cbc04b0
x86/smpboot: Don't unconditionally call memguard_guard_stack() in cpu_smpboot_alloc()

cpu_smpboot_alloc() is designed to be idempotent with respect to partially
initialised state.  This occurs for S3 and CPU parking, where enough state to
handle NMIs/#MCs needs to remain valid for the entire lifetime of Xen, even
when we otherwise want to offline the CPU.

For simplicity between various configuration, Xen always uses shadow stack
mappings (Read-only + Dirty) for the guard page, irrespective of whether
CET-SS is enabled.

Unfortunately, the CET-SS changes in memguard_guard_stack() broke idempotency
by first writing out the supervisor shadow stack tokens with plain writes,
then changing the mapping to being read-only.

This ordering is strictly necessary to configure the BSP, which cannot have
the supervisor tokens be written with WRSS.

Instead of calling memguard_guard_stack() unconditionally, call it only when
actually allocating a new stack.  Xenheap allocates are guaranteed to be
writeable, and the net result is idempotency WRT configuring stack_base[].

Fixes: 91d26ed304f ("x86/shstk: Create shadow stacks")
Reported-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/smpboot.c