/* Update fake mce registers on current CPU. */ staticvoid inject_mce(struct mce *m)
{ struct mce *i = &per_cpu(injectm, m->extcpu);
/* Make sure no one reads partially written injectm */
i->finished = 0;
mb();
m->finished = 0; /* First set the fields after finished */
i->extcpu = m->extcpu;
mb(); /* Now write record in order, finished last (except above) */
memcpy(i, m, sizeof(struct mce)); /* Finally activate it */
mb();
i->finished = 1;
}
/* Inject mce on current CPU */ staticint raise_local(void)
{ struct mce *m = this_cpu_ptr(&injectm); int context = MCJ_CTX(m->inject_flags); int ret = 0; int cpu = m->extcpu;
if (m->inject_flags & MCJ_EXCEPTION) {
pr_info("Triggering MCE exception on CPU %d\n", cpu); switch (context) { case MCJ_CTX_IRQ: /* *Coulddomoretofakeinterruptslike *callingirq_enter,butthenecessary *machineryisn'texportedcurrently.
*/
fallthrough; case MCJ_CTX_PROCESS:
raise_exception(m, NULL); break; default:
pr_info("Invalid MCE context\n");
ret = -EINVAL;
}
pr_info("MCE exception done on CPU %d\n", cpu);
} elseif (m->status) {
pr_info("Starting machine check poll CPU %d\n", cpu);
raise_poll(m);
pr_info("Machine check poll done on CPU %d\n", cpu);
} else
m->finished = 0;
return ret;
}
staticvoid __maybe_unused raise_mce(struct mce *m)
{ int context = MCJ_CTX(m->inject_flags);
inject_mce(m);
if (context == MCJ_CTX_RANDOM) return;
if (m->inject_flags & (MCJ_IRQ_BROADCAST | MCJ_NMI_BROADCAST)) { unsignedlong start; int cpu;
for (i = 0; i < N_INJ_TYPES; i++) { if (!strncmp(flags_options[i], buf, strlen(flags_options[i]))) { if (i > SW_INJ && !hw_injection_possible) continue;
inj_type = i; return0;
}
} return -EINVAL;
}
/* Get bank count on target CPU so we can handle non-uniform values. */
rdmsrq_on_cpu(m->extcpu, MSR_IA32_MCG_CAP, &cap);
n_banks = cap & MCG_BANKCNT_MASK;
if (val >= n_banks) {
pr_err("MCA bank %llu non-existent on CPU%d\n", val, m->extcpu); return -EINVAL;
}
m->bank = val;
/* *sw-onlyinjectionallowstowritearbitraryvaluesintotheMCA *registersbecauseittestsonlythedecodingpaths.
*/ if (inj_type == SW_INJ) goto inject;
/* *ReadIPIDvaluetodetermineifabankispopulatedonthetarget *CPU.
*/ if (cpu_feature_enabled(X86_FEATURE_SMCA)) {
u64 ipid;
if (rdmsrq_on_cpu(m->extcpu, MSR_AMD64_SMCA_MCx_IPID(val), &ipid)) {
pr_err("Error reading IPID on CPU%d\n", m->extcpu); return -EINVAL;
}
if (!ipid) {
pr_err("Cannot inject into unpopulated bank %llu\n", val); return -ENODEV;
}
}
staticconstchar readme_msg[] = "Description of the files and their usages:\n" "\n" "Note1: i refers to the bank number below.\n" "Note2: See respective BKDGs for the exact bit definitions of the files below\n" "as they mirror the hardware registers.\n" "\n" "status:\t Set MCi_STATUS: the bits in that MSR control the error type and\n" "\t attributes of the error which caused the MCE.\n" "\n" "misc:\t Set MCi_MISC: provide auxiliary info about the error. It is mostly\n" "\t used for error thresholding purposes and its validity is indicated by\n" "\t MCi_STATUS[MiscV].\n" "\n" "synd:\t Set MCi_SYND: provide syndrome info about the error. Only valid on\n" "\t Scalable MCA systems, and its validity is indicated by MCi_STATUS[SyndV].\n" "\n" "addr:\t Error address value to be written to MCi_ADDR. Log address information\n" "\t associated with the error.\n" "\n" "cpu:\t The CPU to inject the error on.\n" "\n" "bank:\t Specify the bank you want to inject the error into: the number of\n" "\t banks in a processor varies and is family/model-specific, therefore, the\n" "\t supplied value is sanity-checked. Setting the bank value also triggers the\n" "\t injection.\n" "\n" "flags:\t Injection type to be performed. Writing to this file will trigger a\n" "\t real machine check, an APIC interrupt or invoke the error decoder routines\n" "\t for AMD processors.\n" "\n" "\t Allowed error injection types:\n" "\t - \"sw\": Software error injection. Decode error to a human-readable \n" "\t format only. Safe to use.\n" "\t - \"hw\": Hardware error injection. Causes the #MC exception handler to \n" "\t handle the error. Be warned: might cause system panic if MCi_STATUS[PCC] \n" "\t is set. Therefore, consider setting (debugfs_mountpoint)/mce/fake_panic \n" "\t before injecting.\n" "\t - \"df\": Trigger APIC interrupt for Deferred error. Causes deferred \n" "\t error APIC interrupt handler to handle the error if the feature is \n" "\t is present in hardware. \n" "\t - \"th\": Trigger APIC interrupt for Threshold errors. Causes threshold \n" "\t APIC interrupt handler to handle the error. \n" "\n" "ipid:\t IPID (AMD-specific)\n" "\n";
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.