--- zzzz-none-000/linux-3.10.107/drivers/xen/mcelog.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/xen/mcelog.c 2021-02-04 17:41:59.000000000 +0000 @@ -32,6 +32,8 @@ * IN THE SOFTWARE. */ +#define pr_fmt(fmt) "xen_mcelog: " fmt + #include #include #include @@ -51,8 +53,6 @@ #include #include -#define XEN_MCELOG "xen_mcelog: " - static struct mc_info g_mi; static struct mcinfo_logical_cpu *g_physinfo; static uint32_t ncpus; @@ -227,7 +227,7 @@ mic = NULL; x86_mcinfo_lookup(&mic, mi, MC_TYPE_GLOBAL); if (unlikely(!mic)) { - pr_warning(XEN_MCELOG "Failed to find global error info\n"); + pr_warn("Failed to find global error info\n"); return -ENODEV; } @@ -241,8 +241,7 @@ if (g_physinfo[i].mc_apicid == m.apicid) break; if (unlikely(i == ncpus)) { - pr_warning(XEN_MCELOG "Failed to match cpu with apicid %d\n", - m.apicid); + pr_warn("Failed to match cpu with apicid %d\n", m.apicid); return -ENODEV; } @@ -254,7 +253,7 @@ mic = NULL; x86_mcinfo_lookup(&mic, mi, MC_TYPE_BANK); if (unlikely(!mic)) { - pr_warning(XEN_MCELOG "Fail to find bank error info\n"); + pr_warn("Fail to find bank error info\n"); return -ENODEV; } @@ -295,9 +294,8 @@ mc_op.u.mc_fetch.flags = flags; ret = HYPERVISOR_mca(&mc_op); if (ret) { - pr_err(XEN_MCELOG "Failed to fetch %s error log\n", - (flags == XEN_MC_URGENT) ? - "urgnet" : "nonurgent"); + pr_err("Failed to fetch %surgent error log\n", + flags == XEN_MC_URGENT ? "" : "non"); break; } @@ -307,15 +305,12 @@ else { ret = convert_log(&g_mi); if (ret) - pr_warning(XEN_MCELOG - "Failed to convert this error log, " - "continue acking it anyway\n"); + pr_warn("Failed to convert this error log, continue acking it anyway\n"); mc_op.u.mc_fetch.flags = flags | XEN_MC_ACK; ret = HYPERVISOR_mca(&mc_op); if (ret) { - pr_err(XEN_MCELOG - "Failed to ack previous error log\n"); + pr_err("Failed to ack previous error log\n"); break; } } @@ -334,15 +329,12 @@ /* urgent mc_info */ err = mc_queue_handle(XEN_MC_URGENT); if (err) - pr_err(XEN_MCELOG - "Failed to handle urgent mc_info queue, " - "continue handling nonurgent mc_info queue anyway.\n"); + pr_err("Failed to handle urgent mc_info queue, continue handling nonurgent mc_info queue anyway\n"); /* nonurgent mc_info */ err = mc_queue_handle(XEN_MC_NONURGENT); if (err) - pr_err(XEN_MCELOG - "Failed to handle nonurgent mc_info queue.\n"); + pr_err("Failed to handle nonurgent mc_info queue\n"); /* wake processes polling /dev/mcelog */ wake_up_interruptible(&xen_mce_chrdev_wait); @@ -370,7 +362,7 @@ set_xen_guest_handle(mc_op.u.mc_physcpuinfo.info, g_physinfo); ret = HYPERVISOR_mca(&mc_op); if (ret) { - pr_err(XEN_MCELOG "Failed to get CPU numbers\n"); + pr_err("Failed to get CPU numbers\n"); return ret; } @@ -383,7 +375,7 @@ set_xen_guest_handle(mc_op.u.mc_physcpuinfo.info, g_physinfo); ret = HYPERVISOR_mca(&mc_op); if (ret) { - pr_err(XEN_MCELOG "Failed to get CPU info\n"); + pr_err("Failed to get CPU info\n"); kfree(g_physinfo); return ret; } @@ -391,7 +383,7 @@ ret = bind_virq_to_irqhandler(VIRQ_MCA, 0, xen_mce_interrupt, 0, "mce", NULL); if (ret < 0) { - pr_err(XEN_MCELOG "Failed to bind virq\n"); + pr_err("Failed to bind virq\n"); kfree(g_physinfo); return ret; } @@ -401,14 +393,25 @@ static int __init xen_late_init_mcelog(void) { + int ret; + /* Only DOM0 is responsible for MCE logging */ - if (xen_initial_domain()) { - /* register character device /dev/mcelog for xen mcelog */ - if (misc_register(&xen_mce_chrdev_device)) - return -ENODEV; - return bind_virq_for_mce(); - } + if (!xen_initial_domain()) + return -ENODEV; - return -ENODEV; + /* register character device /dev/mcelog for xen mcelog */ + ret = misc_register(&xen_mce_chrdev_device); + if (ret) + return ret; + + ret = bind_virq_for_mce(); + if (ret) + goto deregister; + + return 0; + +deregister: + misc_deregister(&xen_mce_chrdev_device); + return ret; } device_initcall(xen_late_init_mcelog);