diff --git a/sys/dev/cpuctl/cpuctl.c b/sys/dev/cpuctl/cpuctl.c index 1553457..3c25434 100644 --- a/sys/dev/cpuctl/cpuctl.c +++ b/sys/dev/cpuctl/cpuctl.c @@ -351,13 +351,19 @@ fail: return (ret); } +static void +amd_ucode_wrmsr(void *ucode_ptr) +{ + uint32_t tmp[4]; + + wrmsr_safe(MSR_K8_UCODE_UPDATE, (uintptr_t)ucode_ptr); + do_cpuid(0, tmp); +} + static int update_amd(int cpu, cpuctl_update_args_t *args, struct thread *td) { - void *ptr = NULL; - uint32_t tmp[4]; - int is_bound = 0; - int oldcpu; + void *ptr; int ret; if (args->size == 0 || args->data == NULL) { @@ -371,7 +377,8 @@ update_amd(int cpu, cpuctl_update_args_t *args, struct thread *td) /* * XXX Might not require contignous address space - needs check */ - ptr = contigmalloc(args->size, M_CPUCTL, 0, 0, 0xffffffff, 16, 0); + ptr = contigmalloc(args->size, M_CPUCTL, M_ZERO, 0, 0xffffffff, + PAGE_SIZE, 0); if (ptr == NULL) { DPRINTF("[cpuctl,%d]: cannot allocate %zd bytes of memory", __LINE__, args->size); @@ -383,22 +390,7 @@ update_amd(int cpu, cpuctl_update_args_t *args, struct thread *td) ret = EFAULT; goto fail; } - oldcpu = td->td_oncpu; - is_bound = cpu_sched_is_bound(td); - set_cpu(cpu, td); - critical_enter(); - - /* - * Perform update. - */ - wrmsr_safe(MSR_K8_UCODE_UPDATE, (uintptr_t)ptr); - - /* - * Serialize instruction flow. - */ - do_cpuid(0, tmp); - critical_exit(); - restore_cpu(oldcpu, is_bound, td); + smp_rendezvous(NULL, amd_ucode_wrmsr, NULL, ptr); ret = 0; fail: if (ptr != NULL)