console_end_sync();
- microcode_resume_cpu(0);
+ microcode_resume_cpu();
if ( !recheck_cpu_features(0) )
panic("Missing previously available feature(s)\n");
char buffer[1];
};
-int microcode_resume_cpu(unsigned int cpu)
+int microcode_resume_cpu(void)
{
int err;
- struct cpu_signature *sig = &per_cpu(cpu_sig, cpu);
+ struct cpu_signature *sig = &this_cpu(cpu_sig);
if ( !microcode_ops )
return 0;
spin_lock(µcode_mutex);
- err = microcode_ops->collect_cpu_info(cpu, sig);
+ err = microcode_ops->collect_cpu_info(sig);
if ( likely(!err) )
- err = microcode_ops->apply_microcode(cpu);
+ err = microcode_ops->apply_microcode();
spin_unlock(µcode_mutex);
return err;
spin_lock(µcode_mutex);
- err = microcode_ops->collect_cpu_info(cpu, sig);
+ err = microcode_ops->collect_cpu_info(sig);
if ( likely(!err) )
- err = microcode_ops->cpu_request_microcode(cpu, buf, size);
+ err = microcode_ops->cpu_request_microcode(buf, size);
spin_unlock(µcode_mutex);
return err;
int __init early_microcode_update_cpu(bool start_update)
{
- unsigned int cpu = smp_processor_id();
- struct cpu_signature *sig = &per_cpu(cpu_sig, cpu);
int rc = 0;
void *data = NULL;
size_t len;
data = bootstrap_map(&ucode_mod);
}
- microcode_ops->collect_cpu_info(cpu, sig);
+ microcode_ops->collect_cpu_info(&this_cpu(cpu_sig));
if ( data )
{
int __init early_microcode_init(void)
{
- unsigned int cpu = smp_processor_id();
- struct cpu_signature *sig = &per_cpu(cpu_sig, cpu);
int rc;
rc = microcode_init_intel();
if ( microcode_ops )
{
- microcode_ops->collect_cpu_info(cpu, sig);
+ microcode_ops->collect_cpu_info(&this_cpu(cpu_sig));
if ( ucode_mod.mod_end || ucode_blob.size )
rc = early_microcode_update_cpu(true);
static DEFINE_SPINLOCK(microcode_update_lock);
/* See comment in start_update() for cases when this routine fails */
-static int collect_cpu_info(unsigned int cpu, struct cpu_signature *csig)
+static int collect_cpu_info(struct cpu_signature *csig)
{
+ unsigned int cpu = smp_processor_id();
struct cpuinfo_x86 *c = &cpu_data[cpu];
memset(csig, 0, sizeof(*csig));
}
static enum microcode_match_result microcode_fits(
- const struct microcode_amd *mc_amd, unsigned int cpu)
+ const struct microcode_amd *mc_amd)
{
+ unsigned int cpu = smp_processor_id();
const struct cpu_signature *sig = &per_cpu(cpu_sig, cpu);
const struct microcode_header_amd *mc_header = mc_amd->mpb;
const struct equiv_cpu_entry *equiv_cpu_table = mc_amd->equiv_cpu_table;
unsigned int current_cpu_id;
unsigned int equiv_cpu_id;
- /* We should bind the task to the CPU */
- BUG_ON(cpu != raw_smp_processor_id());
-
current_cpu_id = cpuid_eax(0x00000001);
if ( !find_equiv_cpu_id(equiv_cpu_table, current_cpu_id, &equiv_cpu_id) )
static bool match_cpu(const struct microcode_patch *patch)
{
- if ( !patch )
- return false;
- return microcode_fits(patch->mc_amd, smp_processor_id()) == NEW_UCODE;
+ return patch && (microcode_fits(patch->mc_amd) == NEW_UCODE);
}
static struct microcode_patch *alloc_microcode_patch(
const struct microcode_header_amd *old_header = old->mc_amd->mpb;
/* Both patches to compare are supposed to be applicable to local CPU. */
- ASSERT(microcode_fits(new->mc_amd, smp_processor_id()) != MIS_UCODE);
- ASSERT(microcode_fits(new->mc_amd, smp_processor_id()) != MIS_UCODE);
+ ASSERT(microcode_fits(new->mc_amd) != MIS_UCODE);
+ ASSERT(microcode_fits(new->mc_amd) != MIS_UCODE);
if ( new_header->processor_rev_id == old_header->processor_rev_id )
return (new_header->patch_id > old_header->patch_id) ?
return MIS_UCODE;
}
-static int apply_microcode(unsigned int cpu)
+static int apply_microcode(void)
{
unsigned long flags;
uint32_t rev;
int hw_err;
+ unsigned int cpu = smp_processor_id();
struct cpu_signature *sig = &per_cpu(cpu_sig, cpu);
const struct microcode_header_amd *hdr;
const struct microcode_patch *patch = microcode_get_cache();
- /* We should bind the task to the CPU */
- BUG_ON(raw_smp_processor_id() != cpu);
-
if ( !patch )
return -ENOENT;
return 0;
}
-static int cpu_request_microcode(unsigned int cpu, const void *buf,
- size_t bufsize)
+static int cpu_request_microcode(const void *buf, size_t bufsize)
{
struct microcode_amd *mc_amd;
size_t offset = 0;
int error = 0;
unsigned int current_cpu_id;
unsigned int equiv_cpu_id;
+ unsigned int cpu = smp_processor_id();
const struct cpu_signature *sig = &per_cpu(cpu_sig, cpu);
- /* We should bind the task to the CPU */
- BUG_ON(cpu != raw_smp_processor_id());
-
current_cpu_id = cpuid_eax(0x00000001);
if ( *(const uint32_t *)buf != UCODE_MAGIC )
}
/* Update cache if this patch covers current CPU */
- if ( microcode_fits(new_patch->mc_amd, cpu) != MIS_UCODE )
+ if ( microcode_fits(new_patch->mc_amd) != MIS_UCODE )
microcode_update_cache(new_patch);
else
microcode_free_patch(new_patch);
if ( match_cpu(microcode_get_cache()) )
{
- error = apply_microcode(cpu);
+ error = apply_microcode();
if ( error )
break;
}
/* serialize access to the physical write to MSR 0x79 */
static DEFINE_SPINLOCK(microcode_update_lock);
-static int collect_cpu_info(unsigned int cpu_num, struct cpu_signature *csig)
+static int collect_cpu_info(struct cpu_signature *csig)
{
+ unsigned int cpu_num = smp_processor_id();
struct cpuinfo_x86 *c = &cpu_data[cpu_num];
uint64_t msr_content;
- BUG_ON(cpu_num != smp_processor_id());
-
memset(csig, 0, sizeof(*csig));
if ( (c->x86_vendor != X86_VENDOR_INTEL) || (c->x86 < 6) )
/* Check an update against the CPU signature and current update revision */
static enum microcode_match_result microcode_update_match(
- const struct microcode_header_intel *mc_header, unsigned int cpu)
+ const struct microcode_header_intel *mc_header)
{
const struct extended_sigtable *ext_header;
const struct extended_signature *ext_sig;
unsigned int i;
- struct cpu_signature *cpu_sig = &per_cpu(cpu_sig, cpu);
+ struct cpu_signature *cpu_sig = &this_cpu(cpu_sig);
unsigned int sig = cpu_sig->sig;
unsigned int pf = cpu_sig->pf;
unsigned int rev = cpu_sig->rev;
if ( !patch )
return false;
- return microcode_update_match(&patch->mc_intel->hdr,
- smp_processor_id()) == NEW_UCODE;
+ return microcode_update_match(&patch->mc_intel->hdr) == NEW_UCODE;
}
static void free_patch(void *mc)
* Both patches to compare are supposed to be applicable to local CPU.
* Just compare the revision number.
*/
- ASSERT(microcode_update_match(&old->mc_intel->hdr, smp_processor_id()) !=
- MIS_UCODE);
- ASSERT(microcode_update_match(&new->mc_intel->hdr, smp_processor_id()) !=
- MIS_UCODE);
+ ASSERT(microcode_update_match(&old->mc_intel->hdr) != MIS_UCODE);
+ ASSERT(microcode_update_match(&new->mc_intel->hdr) != MIS_UCODE);
return (new->mc_intel->hdr.rev > old->mc_intel->hdr.rev) ? NEW_UCODE
: OLD_UCODE;
* return 1 - found update
* return < 0 - error
*/
-static int get_matching_microcode(const void *mc, unsigned int cpu)
+static int get_matching_microcode(const void *mc)
{
const struct microcode_header_intel *mc_header = mc;
unsigned long total_size = get_totalsize(mc_header);
new_patch->mc_intel = new_mc;
/* Make sure that this patch covers current CPU */
- if ( microcode_update_match(mc, cpu) == MIS_UCODE )
+ if ( microcode_update_match(mc) == MIS_UCODE )
{
microcode_free_patch(new_patch);
return 0;
pr_debug("microcode: CPU%d found a matching microcode update with"
" version %#x (current=%#x)\n",
- cpu, mc_header->rev, per_cpu(cpu_sig, cpu).rev);
+ smp_processor_id(), mc_header->rev, this_cpu(cpu_sig).rev);
return 1;
}
-static int apply_microcode(unsigned int cpu)
+static int apply_microcode(void)
{
unsigned long flags;
uint64_t msr_content;
unsigned int val[2];
unsigned int cpu_num = raw_smp_processor_id();
- struct cpu_signature *sig = &per_cpu(cpu_sig, cpu);
+ struct cpu_signature *sig = &this_cpu(cpu_sig);
const struct microcode_intel *mc_intel;
const struct microcode_patch *patch = microcode_get_cache();
- /* We should bind the task to the CPU */
- BUG_ON(cpu_num != cpu);
-
if ( !patch )
return -ENOENT;
return offset + total_size;
}
-static int cpu_request_microcode(unsigned int cpu, const void *buf,
- size_t size)
+static int cpu_request_microcode(const void *buf, size_t size)
{
long offset = 0;
int error = 0;
void *mc;
- /* We should bind the task to the CPU */
- BUG_ON(cpu != raw_smp_processor_id());
-
while ( (offset = get_next_ucode_from_buffer(&mc, buf, size, offset)) > 0 )
{
error = microcode_sanity_check(mc);
if ( error )
break;
- error = get_matching_microcode(mc, cpu);
+ error = get_matching_microcode(mc);
if ( error < 0 )
break;
/*
error = offset;
if ( !error && match_cpu(microcode_get_cache()) )
- error = apply_microcode(cpu);
+ error = apply_microcode();
return error;
}
if ( system_state <= SYS_STATE_smp_boot )
early_microcode_update_cpu(false);
else
- microcode_resume_cpu(cpu);
+ microcode_resume_cpu();
/*
* If MSR_SPEC_CTRL is available, apply Xen's default setting and discard
};
struct microcode_ops {
- int (*cpu_request_microcode)(unsigned int cpu, const void *buf,
- size_t size);
- int (*collect_cpu_info)(unsigned int cpu, struct cpu_signature *csig);
- int (*apply_microcode)(unsigned int cpu);
+ int (*cpu_request_microcode)(const void *buf, size_t size);
+ int (*collect_cpu_info)(struct cpu_signature *csig);
+ int (*apply_microcode)(void);
int (*start_update)(void);
void (*free_patch)(void *mc);
bool (*match_cpu)(const struct microcode_patch *patch);
void microcode_set_module(unsigned int);
int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void), unsigned long len);
-int microcode_resume_cpu(unsigned int cpu);
+int microcode_resume_cpu(void);
int early_microcode_update_cpu(bool start_update);
int early_microcode_init(void);
int microcode_init_intel(void);