Share same error handing, and put it in #ifdef MCE && i386. Rename this function after MCIP (Machine Check In Progress) flag. Signed-off-by: Hidetoshi Seto <seto.hidetoshi@xxxxxxxxxxxxxx> Tested-by: Jin Dongming <jin.dongming@xxxxxxxxxxxxxxxxxx> --- qemu-kvm.c | 47 ++++++++++++++++++++--------------------------- 1 files changed, 20 insertions(+), 27 deletions(-) diff --git a/qemu-kvm.c b/qemu-kvm.c index 1338e99..a71c07c 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -1131,6 +1131,21 @@ static void sigbus_reraise(void) } #if defined(KVM_CAP_MCE) && defined(TARGET_I386) +static int kvm_mce_in_progress(CPUState *env) +{ + struct kvm_msr_entry msr_mcg_status = { + .index = MSR_MCG_STATUS, + }; + int r; + + r = kvm_get_msrs(env, &msr_mcg_status, 1); + if (r == -1 || r == 0) { + perror("Failed to get MCE status"); + return 0; + } + return !!(msr_mcg_status.data & MCG_STATUS_MCIP); +} + static void kvm_do_set_mce(CPUState *env, struct kvm_x86_mce *mce, int abort_on_error) { @@ -1315,20 +1330,6 @@ static void flush_queued_work(CPUState *env) pthread_cond_broadcast(&qemu_work_cond); } -static int kvm_mce_in_exception(CPUState *env) -{ - struct kvm_msr_entry msr_mcg_status = { - .index = MSR_MCG_STATUS, - }; - int r; - - r = kvm_get_msrs(env, &msr_mcg_status, 1); - if (r == -1 || r == 0) { - return -1; - } - return !!(msr_mcg_status.data & MCG_STATUS_MCIP); -} - static void kvm_on_sigbus(CPUState *env, siginfo_t *siginfo) { #if defined(KVM_CAP_MCE) && defined(TARGET_I386) @@ -1338,7 +1339,6 @@ static void kvm_on_sigbus(CPUState *env, siginfo_t *siginfo) void *vaddr; ram_addr_t ram_addr; unsigned long paddr; - int r; if ((env->mcg_cap & MCG_SER_P) && siginfo->si_addr && (siginfo->si_code == BUS_MCEERR_AR @@ -1355,12 +1355,10 @@ static void kvm_on_sigbus(CPUState *env, siginfo_t *siginfo) * If there is an MCE excpetion being processed, ignore * this SRAO MCE */ - r = kvm_mce_in_exception(env); - if (r == -1) { - fprintf(stderr, "Failed to get MCE status\n"); - } else if (r) { + if (kvm_mce_in_progress(env)) { return; } + /* Fake an Intel architectural Memory scrubbing UCR */ mce.status = MCI_STATUS_VAL | MCI_STATUS_UC | MCI_STATUS_EN | MCI_STATUS_MISCV | MCI_STATUS_ADDRV | MCI_STATUS_S @@ -1913,17 +1911,12 @@ struct kvm_x86_mce_data { static void kvm_do_inject_x86_mce(void *_data) { struct kvm_x86_mce_data *data = _data; - int r; /* If there is an MCE exception being processed, ignore this SRAO MCE */ if ((data->env->mcg_cap & MCG_SER_P) && - !(data->mce->status & MCI_STATUS_AR)) { - r = kvm_mce_in_exception(data->env); - if (r == -1) { - fprintf(stderr, "Failed to get MCE status\n"); - } else if (r) { - return; - } + !(data->mce->status & MCI_STATUS_AR) && + kvm_mce_in_progress(data->env)) { + return; } kvm_do_set_mce(data->env, data->mce, data->abort_on_error); -- 1.7.1.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html