x86/sev: Put PSC struct on the stack in prep for unaccepted memory support
authorTom Lendacky <thomas.lendacky@amd.com>
Tue, 6 Jun 2023 14:51:23 +0000 (09:51 -0500)
committerBorislav Petkov (AMD) <bp@alien8.de>
Tue, 6 Jun 2023 16:28:25 +0000 (18:28 +0200)
commit69dcb1e3bbbe7fe092ea7af70e295e43ab0c7bc7
tree5337f310e544abb2f00df3a5c210b64c6283d9d7
parent5dee19b6b2b194216919b99a1f5af2949a754016
x86/sev: Put PSC struct on the stack in prep for unaccepted memory support

In advance of providing support for unaccepted memory, switch from using
kmalloc() for allocating the Page State Change (PSC) structure to using a
local variable that lives on the stack. This is needed to avoid a possible
recursive call into set_pages_state() if the kmalloc() call requires
(more) memory to be accepted, which would result in a hang.

The current size of the PSC struct is 2,032 bytes. To make the struct more
stack friendly, reduce the number of PSC entries from 253 down to 64,
resulting in a size of 520 bytes. This is a nice compromise on struct size
and total PSC requests while still allowing parallel PSC operations across
vCPUs.

If the reduction in PSC entries results in any kind of performance issue
(that is not seen at the moment), use of a larger static PSC struct, with
fallback to the smaller stack version, can be investigated.

For more background info on this decision, see the subthread in the Link:
tag below.

Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/lkml/658c455c40e8950cb046dd885dd19dc1c52d060a.1659103274.git.thomas.lendacky@amd.com
arch/x86/include/asm/sev-common.h
arch/x86/kernel/sev.c