Arthur Heymans has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/51186 )
Change subject: cpu/x86/smm_loaderv2: Use the permanent stack top during relocation ......................................................................
cpu/x86/smm_loaderv2: Use the permanent stack top during relocation
Use the same stack location during relocation as for the permanent handler.
During relocation having the stack inside the default SMRAM segment at 0x30000 when the number of CPUs is too large. Currently the code would just let the CPU stack base grow downwards outside of the default SMM segment which would corrupt lower memory if S3 is implemented.
Change-Id: I6a0a890e8b1c2408301564c22772032cfee4d296 Signed-off-by: Arthur Heymans arthur@aheymans.xyz --- M src/cpu/x86/mp_init.c M src/cpu/x86/smm/smm_module_loader.c M src/cpu/x86/smm/smm_module_loaderv2.c M src/include/cpu/x86/smm.h 4 files changed, 12 insertions(+), 20 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/86/51186/1
diff --git a/src/cpu/x86/mp_init.c b/src/cpu/x86/mp_init.c index be26d3d..8a4b671 100644 --- a/src/cpu/x86/mp_init.c +++ b/src/cpu/x86/mp_init.c @@ -769,19 +769,11 @@ }
static int install_relocation_handler(int num_cpus, size_t real_save_state_size, - size_t save_state_size) + size_t save_state_size, uintptr_t perm_smbase) { - int cpus = num_cpus; -#if CONFIG(X86_SMM_LOADER_VERSION2) - /* Default SMRAM size is not big enough to concurrently - * handle relocation for more than ~32 CPU threads - * therefore, relocate 1 by 1. */ - cpus = 1; -#endif - struct smm_loader_params smm_params = { .per_cpu_stack_size = CONFIG_SMM_STUB_STACK_SIZE, - .num_concurrent_stacks = cpus, + .num_concurrent_stacks = num_cpus, .real_cpu_save_state_size = real_save_state_size, .per_cpu_save_state_size = save_state_size, .num_concurrent_save_states = 1, @@ -792,7 +784,7 @@ if (mp_state.ops.adjust_smm_params != NULL) mp_state.ops.adjust_smm_params(&smm_params, 0);
- if (smm_setup_relocation_handler(&smm_params)) { + if (smm_setup_relocation_handler((void*)perm_smbase, &smm_params)) { printk(BIOS_ERR, "%s: smm setup failed\n", __func__); return -1; } @@ -847,9 +839,8 @@ return;
/* Install handlers. */ - if (install_relocation_handler(mp_state.cpu_count, - real_save_state_size, - smm_save_state_size) < 0) { + if (install_relocation_handler(mp_state.cpu_count, real_save_state_size, + smm_save_state_size, mp_state.perm_smbase) < 0) { printk(BIOS_ERR, "Unable to install SMM relocation handler.\n"); smm_disable(); } diff --git a/src/cpu/x86/smm/smm_module_loader.c b/src/cpu/x86/smm/smm_module_loader.c index 9b025a8..a8f2c92 100644 --- a/src/cpu/x86/smm/smm_module_loader.c +++ b/src/cpu/x86/smm/smm_module_loader.c @@ -267,7 +267,7 @@ * assumption is that the stub will be entered from the default SMRAM * location: 0x30000 -> 0x40000. */ -int smm_setup_relocation_handler(struct smm_loader_params *params) +int smm_setup_relocation_handler(void * const perm_smram, struct smm_loader_params *params) { void *smram = (void *)SMM_DEFAULT_BASE;
diff --git a/src/cpu/x86/smm/smm_module_loaderv2.c b/src/cpu/x86/smm/smm_module_loaderv2.c index 694e25d..2e60eb8 100644 --- a/src/cpu/x86/smm/smm_module_loaderv2.c +++ b/src/cpu/x86/smm/smm_module_loaderv2.c @@ -315,6 +315,7 @@ * permanent SMM handler. */ static int smm_module_setup_stub(void * const smbase, const size_t smm_size, + void * const perm_smbase, struct smm_loader_params *params, void * const fxsave_area) { @@ -385,7 +386,7 @@ * for default handler, but for relocated handler it lives at the beginning * of SMRAM which is TSEG base */ - stacks_top = smm_stub_place_stacks(smbase, params); + stacks_top = smm_stub_place_stacks(perm_smbase, params); if (stacks_top == NULL) { printk(BIOS_ERR, "%s: error assigning stacks\n", __func__); return -1; @@ -442,7 +443,7 @@ * assumption is that the stub will be entered from the default SMRAM * location: 0x30000 -> 0x40000. */ -int smm_setup_relocation_handler(struct smm_loader_params *params) +int smm_setup_relocation_handler(void * const perm_smram, struct smm_loader_params *params) { void *smram = (void *)(SMM_DEFAULT_BASE); printk(BIOS_SPEW, "%s: enter\n", __func__); @@ -461,7 +462,7 @@ params->num_concurrent_stacks = CONFIG_MAX_CPUS;
return smm_module_setup_stub(smram, SMM_DEFAULT_SIZE, - params, fxsave_area_relocation); + perm_smram, params, fxsave_area_relocation); printk(BIOS_SPEW, "%s: exit\n", __func__); }
@@ -628,5 +629,5 @@ cpus[i].ss_start + params->per_cpu_save_state_size; }
- return smm_module_setup_stub(base, size, params, fxsave_area); + return smm_module_setup_stub(base, size, base, params, fxsave_area); } diff --git a/src/include/cpu/x86/smm.h b/src/include/cpu/x86/smm.h index 35b3da1..20e1b9f 100644 --- a/src/include/cpu/x86/smm.h +++ b/src/include/cpu/x86/smm.h @@ -160,7 +160,7 @@ };
/* Both of these return 0 on success, < 0 on failure. */ -int smm_setup_relocation_handler(struct smm_loader_params *params); +int smm_setup_relocation_handler(void * const perm_smram, struct smm_loader_params *params); int smm_load_module(void *smram, size_t size, struct smm_loader_params *params);
u32 smm_get_cpu_smbase(unsigned int cpu_num);