-/* $OpenBSD: ucode.c,v 1.7 2023/08/09 02:59:41 jsg Exp $ */
+/* $OpenBSD: ucode.c,v 1.8 2023/09/10 09:32:31 jsg Exp $ */
/*
* Copyright (c) 2018 Stefan Fritsch <fritsch@genua.de>
* Copyright (c) 2018 Patrick Wildt <patrick@blueri.se>
uint16_t eid = 0;
uint32_t sig, ebx, ecx, edx;
uint64_t start = 0;
+ uint32_t patch_len = 0;
if (cpu_ucode_data == NULL || cpu_ucode_size == 0) {
DPRINTF(("%s: no microcode provided\n", __func__));
goto out;
}
memcpy(&ap, &cpu_ucode_data[i], sizeof(ap));
- if (ap.type == 1 && ap.eid == eid && ap.level > level)
+ if (ap.type == 1 && ap.eid == eid && ap.level > level) {
start = (uint64_t)&cpu_ucode_data[i + 8];
+ patch_len = ap.len;
+ }
if (i + ap.len + 8 > cpu_ucode_size) {
DPRINTF(("%s: truncated patch\n", __func__));
goto out;
}
if (start != 0) {
+ /* alignment required on fam 15h */
+ uint8_t *p = malloc(patch_len, M_TEMP, M_NOWAIT);
+ if (p == NULL)
+ goto out;
+ memcpy(p, (uint8_t *)start, patch_len);
+ start = (uint64_t)p;
wrmsr(MSR_PATCH_LOADER, start);
level = rdmsr(MSR_PATCH_LEVEL);
DPRINTF(("%s: new patch level 0x%llx\n", __func__, level));
+ free(p, M_TEMP, patch_len);
}
out:
mtx_leave(&cpu_ucode_mtx);
-/* $OpenBSD: ucode.c,v 1.5 2023/08/09 02:59:41 jsg Exp $ */
+/* $OpenBSD: ucode.c,v 1.6 2023/09/10 09:32:31 jsg Exp $ */
/*
* Copyright (c) 2018 Stefan Fritsch <fritsch@genua.de>
* Copyright (c) 2018 Patrick Wildt <patrick@blueri.se>
uint16_t eid = 0;
uint32_t sig, ebx, ecx, edx;
uint64_t start = 0;
+ uint32_t patch_len = 0;
if (cpu_ucode_data == NULL || cpu_ucode_size == 0) {
DPRINTF(("%s: no microcode provided\n", __func__));
goto out;
}
memcpy(&ap, &cpu_ucode_data[i], sizeof(ap));
- if (ap.type == 1 && ap.eid == eid && ap.level > level)
+ if (ap.type == 1 && ap.eid == eid && ap.level > level) {
start = (uint64_t)&cpu_ucode_data[i + 8];
+ patch_len = ap.len;
+ }
if (i + ap.len + 8 > cpu_ucode_size) {
DPRINTF(("%s: truncated patch\n", __func__));
goto out;
}
if (start != 0) {
+ /* alignment required on fam 15h */
+ uint8_t *p = malloc(patch_len, M_TEMP, M_NOWAIT);
+ if (p == NULL)
+ goto out;
+ memcpy(p, (uint8_t *)start, patch_len);
+ start = (uint64_t)p;
wrmsr(MSR_PATCH_LOADER, start);
level = rdmsr(MSR_PATCH_LEVEL);
DPRINTF(("%s: new patch level 0x%llx\n", __func__, level));
+ free(p, M_TEMP, patch_len);
}
out:
mtx_leave(&cpu_ucode_mtx);