cpu/x86/smm: Fix get_save_state calculation

When the SMI transfer monitor (STM) is configured, get_save_state
returns an incorrect pointer to the cpu save state because the size
(rounded up to 0x100) of the processor System Management Mode (SMM)
descriptor needs to be subtracted out in this case.

This patch addresses the issue identified in CB:76601, which means
that SMMSTOREv2 now works with the STM.

Thanks to Jeremy Compostella for suggesting this version of the patch.

Resolves: https://ticket.coreboot.org/issues/511

Change-Id: I0233c6d13bdffb3853845ac6ef25c066deaab747
Signed-off-by: Eugene D. Myers <edmyers@cyberpackventures.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/78889
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
This commit is contained in:
Eugene D. Myers 2023-11-02 13:34:56 -07:00 committed by Felix Held
parent 42f1fef5a6
commit d205cf7e4e
3 changed files with 13 additions and 5 deletions

View File

@ -1087,10 +1087,7 @@ static void fill_mp_state_smm(struct mp_state *state, const struct mp_ops *ops)
/*
* Make sure there is enough room for the SMM descriptor
*/
if (CONFIG(STM)) {
state->smm_save_state_size +=
ALIGN_UP(sizeof(TXT_PROCESSOR_SMM_DESCRIPTOR), 0x100);
}
state->smm_save_state_size += STM_PSD_SIZE;
/*
* Default to smm_initiate_relocation() if trigger callback isn't

View File

@ -9,6 +9,7 @@
#include <cpu/x86/smm.h>
#include <rmodule.h>
#include <types.h>
#include <security/intel/stm/SmmStm.h>
#if CONFIG(SPI_FLASH_SMM)
#include <spi-generic.h>
@ -103,7 +104,8 @@ void *smm_get_save_state(int cpu)
if (cpu > smm_runtime.num_cpus)
return NULL;
return (void *)(smm_runtime.save_state_top[cpu] - smm_runtime.save_state_size);
return (void *)(smm_runtime.save_state_top[cpu] -
(smm_runtime.save_state_size - STM_PSD_SIZE));
}
uint32_t smm_revision(void)

View File

@ -33,6 +33,15 @@
#define SMM_PCI_RESOURCE_STORE_NUM_RESOURCES 6
/*
* SMI Transfer Monitor (STM) descriptor reserved in SMM save state.
*/
#if CONFIG(STM)
#define STM_PSD_SIZE ALIGN_UP(sizeof(TXT_PROCESSOR_SMM_DESCRIPTOR), 0x100)
#else
#define STM_PSD_SIZE 0
#endif
/* Send cmd to APM_CNT with HAVE_SMI_HANDLER checking. */
int apm_control(u8 cmd);
u8 apm_get_apmc(void);