Grzegorz Bernacki has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/74777 )
Change subject: soc/amd/common/block/cpu: Add missing cbfs_unmap() ......................................................................
soc/amd/common/block/cpu: Add missing cbfs_unmap()
cbfs_map() can allocate memory, so cbfs_unmap() should be called before leaving the function.
BUG=278264488 TEST=Build and run with additional debug prints added to confirm that data are correctly unmapped
Change-Id: I200d24df6157cc6d06bade34809faefea9f0090a Signed-off-by: Grzegorz Bernacki bernacki@google.com --- M src/soc/amd/common/block/cpu/update_microcode.c 1 file changed, 34 insertions(+), 10 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/77/74777/1
diff --git a/src/soc/amd/common/block/cpu/update_microcode.c b/src/soc/amd/common/block/cpu/update_microcode.c index 0edb9d2..d3d7993 100644 --- a/src/soc/amd/common/block/cpu/update_microcode.c +++ b/src/soc/amd/common/block/cpu/update_microcode.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */
+#include <amdblocks/cpu.h> #include <cbfs.h> #include <commonlib/helpers.h> #include <console/console.h> @@ -75,37 +76,43 @@
void amd_update_microcode_from_cbfs(void) { - static const struct microcode *ucode_cache; - static bool cache_valid; + static const struct microcode *ucode; + static int cpus_updated;
- struct microcode *ucode; char name[] = CPU_MICROCODE_BLOB_NAME; uint16_t equivalent_processor_rev_id;
/* Cache the buffer so each CPU doesn't need to read the uCode from flash */ /* Note that this code assumes all cores are the same */ - if (!cache_valid) { + if (!ucode) { timestamp_add_now(TS_READ_UCODE_START); equivalent_processor_rev_id = get_equivalent_processor_rev_id(); snprintf(name, sizeof(name), CPU_MICROCODE_BLOB_FORMAT, equivalent_processor_rev_id); + ucode = cbfs_map(name, NULL); if (!ucode) { printk(BIOS_WARNING, "%s not found. Skipping updates.\n", name); + timestamp_add_now(TS_READ_UCODE_END); return; }
- ucode_cache = find_microcode(ucode, equivalent_processor_rev_id); - - if (!ucode_cache) { - cbfs_unmap(ucode); + if (find_microcode(ucode, equivalent_processor_rev_id) == NULL) { + cbfs_unmap((void *)ucode); + ucode = NULL; + timestamp_add_now(TS_READ_UCODE_END); return; }
- cache_valid = true; timestamp_add_now(TS_READ_UCODE_END); }
- apply_microcode_patch(ucode_cache); + apply_microcode_patch(ucode); + cpus_updated++; + + if (cpus_updated >= get_cpu_count()) { + cbfs_unmap((void *)ucode); + ucode = NULL; + } }
void preload_microcode(void)