[PATCH v9 09/14] x86/hotplug/keylocker: Ensure wrapping key backup capability

From: Chang S. Bae
Date: Thu Mar 28 2024 - 22:12:38 EST


To facilitate CPU hotplug, the wrapping key needs to be loaded during CPU
hotplug bringup. setup_keylocker() already establishes the routine
for the wakeup path by copying the key from the backup state.

Disable the feature if it's missing with CONFIG_HOTPLUG_CPU=y. Also,
update the code comment to indicate support for CPU hotplug.

Signed-off-by: Chang S. Bae <chang.seok.bae@xxxxxxxxx>
Cc: Sangwhan Moon <sxm@xxxxxxxxxx>
---
Changes from v8:
* Add as a new patch.
---
arch/x86/kernel/keylocker.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/keylocker.c b/arch/x86/kernel/keylocker.c
index d5d11d0263b7..1b57e11d93ad 100644
--- a/arch/x86/kernel/keylocker.c
+++ b/arch/x86/kernel/keylocker.c
@@ -69,6 +69,8 @@ static bool copy_keylocker(void)
* On wakeup, APs copy a wrapping key after the boot CPU verifies a valid
* backup status through restore_keylocker(). Subsequently, they adhere
* to the error handling protocol by invalidating the flag.
+ *
+ * This setup routine is also invoked in the hotplug bringup path.
*/
void setup_keylocker(void)
{
@@ -135,11 +137,11 @@ static int __init init_keylocker(void)

/*
* The backup is critical for restoring the wrapping key upon
- * wakeup.
+ * wakeup or during hotplug bringup.
*/
backup_available = !!(ebx & KEYLOCKER_CPUID_EBX_BACKUP);
- if (!backup_available && IS_ENABLED(CONFIG_SUSPEND)) {
- pr_debug("x86/keylocker: No key backup with possible S3/4.\n");
+ if (!backup_available && (IS_ENABLED(CONFIG_SUSPEND) || IS_ENABLED(CONFIG_HOTPLUG_CPU))) {
+ pr_debug("x86/keylocker: No key backup with possible S3/4 or CPU hotplug.\n");
goto clear_cap;
}

--
2.34.1