From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gleb Natapov Subject: Re: [PATCH 05/15] Coalesce userspace/kernel irqchip interrupt injection logic. Date: Sun, 19 Apr 2009 16:57:46 +0300 Message-ID: <20090419135745.GO10126@redhat.com> References: <1239616545-25199-1-git-send-email-gleb@redhat.com> <1239616545-25199-6-git-send-email-gleb@redhat.com> <49E99A7F.7000902@web.de> <20090418162820.GI27675@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Dmitry Eremin-Solenikov , kvm@vger.kernel.org, Avi Kivity , Joerg Roedel To: Jan Kiszka Return-path: Received: from mx2.redhat.com ([66.187.237.31]:48358 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760722AbZDSN56 (ORCPT ); Sun, 19 Apr 2009 09:57:58 -0400 Content-Disposition: inline In-Reply-To: <20090418162820.GI27675@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Sat, Apr 18, 2009 at 07:28:20PM +0300, Gleb Natapov wrote: > > > > So this patch may either expose a bug in the svm emulation of qemu or > > comes with a subtle regression that only triggers due to qemu's timing. > > This needs to be understood. Gleb, any progress on reproducing it on > > your side? > > > I reproduced it and I am debugging it. In my case the boot hangs on sti;hlt > sequence. Instrumentation thus far shows that at this point interrupts no longer > injected because ppr value is too big. Need to see why, but tpr handling > is not complete in qemu svm. May be this is the reason. Will know more > tomorrow. > I've looked into this and my conclusion is that if you are not going to develop SVM in qemu don't use it just yet. QEMU doesn't handle exceptions during event injection properly. Actually it does not handle it at all, so if PF happens during interrupt injection interrupt is lost and, what worse, is never acked. If interrupt was high prio it blocks all other interrupts. The patch below adds exception handling during event injection. Valid flag removed from EVENTINJ only after successful injection and EVENTINJ is copied to EXITINTINFO on exit. Can you give it a try? And this is not the only problem I saw, but the one that caused my guest to hang. diff --git a/target-i386/op_helper.c b/target-i386/op_helper.c index be09263..9264afd 100644 --- a/target-i386/op_helper.c +++ b/target-i386/op_helper.c @@ -1249,6 +1249,10 @@ void do_interrupt(int intno, int is_int, int error_code, } else { do_interrupt_real(intno, is_int, error_code, next_eip); } + if (env->hflags & HF_SVMI_MASK) { + uint32_t event_inj = ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj)); + stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj), event_inj & ~SVM_EVTINJ_VALID); + } } /* This should come from sysemu.h - if we could include it here... */ @@ -4994,7 +4998,6 @@ void helper_vmrun(int aflag, int next_eip_addend) uint8_t vector = event_inj & SVM_EVTINJ_VEC_MASK; uint16_t valid_err = event_inj & SVM_EVTINJ_VALID_ERR; uint32_t event_inj_err = ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj_err)); - stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj), event_inj & ~SVM_EVTINJ_VALID); qemu_log_mask(CPU_LOG_TB_IN_ASM, "Injecting(%#hx): ", valid_err); /* FIXME: need to implement valid_err */ @@ -5331,6 +5334,8 @@ void helper_vmexit(uint32_t exit_code, uint64_t exit_info_1) cpu_x86_set_cpl(env, 0); stq_phys(env->vm_vmcb + offsetof(struct vmcb, control.exit_code), exit_code); stq_phys(env->vm_vmcb + offsetof(struct vmcb, control.exit_info_1), exit_info_1); + stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.exit_int_info), ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj))); + stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.exit_int_info_err), ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj_err))); env->hflags2 &= ~HF2_GIF_MASK; /* FIXME: Resets the current ASID register to zero (host ASID). */ -- Gleb.