From: Paolo Bonzini <pbonzini@redhat.com>
To: Wanpeng Li <kernellwp@gmail.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
kvm <kvm@vger.kernel.org>, "Radim Krčmář" <rkrcmar@redhat.com>,
"Wanpeng Li" <wanpeng.li@hotmail.com>
Subject: Re: [PATCH v3 2/4] KVM: X86: Fix loss of exception which has not yet injected
Date: Thu, 24 Aug 2017 11:47:06 +0200 [thread overview]
Message-ID: <5424f512-3612-4f5a-2a10-36f4182f931d@redhat.com> (raw)
In-Reply-To: <CANRm+CzRS6enhr2Wh6M+1yNxgKROzPJ2d7p5gz4BumgH2Djfug@mail.gmail.com>
On 24/08/2017 11:34, Wanpeng Li wrote:
> 2017-08-24 17:13 GMT+08:00 Wanpeng Li <kernellwp@gmail.com>:
>> 2017-08-24 16:57 GMT+08:00 Paolo Bonzini <pbonzini@redhat.com>:
>>> On 24/08/2017 08:52, Wanpeng Li wrote:
>>>>> @@ -6862,6 +6876,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
>>>>> kvm_x86_ops->enable_nmi_window(vcpu);
>>>>> if (kvm_cpu_has_injectable_intr(vcpu) || req_int_win)
>>>>> kvm_x86_ops->enable_irq_window(vcpu);
>>>>> + WARN_ON(vcpu->arch.exception.pending);
>>>>
>>>> This WARN_ON() is suggested during the review of last version,
>>>> however, there are many cases in inject_pending_event() can result in
>>>> return directly w/ vcpu->arch.exception.pending is true. Actually I
>>>> have already catched the warning several times during the testing. I
>>>> think we should remove it when committing.
>>>
>>> No, it's a good thing that it's failing, because it's finding a bug.
>>> There's no such thing as an "exception window", so at the very least it
>>
>> Good point, the code looks good, I will fold it in next version.
>> However, I still can observe the warning.
>>
>> Regards,
>> Wanpeng Li
>
> I observed sometimes both vcpu->arch.exception.pending and
> vcpu->arch.expception.injected are true before executing below codes:
>
> if (vcpu->arch.exception.injected) {
> kvm_x86_ops->queue_exception(vcpu);
> return 0;
> }
More missing pieces:
1) kvm_x86_ops->queue_exception must be called in the
vcpu->arch.exception.pending case. Compare it with the others, which
are calling enter_smm, kvm_x86_ops->set_irq, kvm_x86_ops->set_nmi.
2) here:
if (!vcpu->arch.exception.pending ||
!vcpu->arch.exception.injected) {
queue:
if (has_error && !is_protmode(vcpu))
has_error = false;
if (reinject)
vcpu->arch.exception.injected = true;
else
vcpu->arch.exception.pending = true;
you need to reset the other field, because you can get here from the
double-fault case. Likewise below:
if ((class1 == EXCPT_CONTRIBUTORY && class2 == EXCPT_CONTRIBUTORY)
|| (class1 == EXCPT_PF && class2 != EXCPT_BENIGN)) {
/* generate double fault per SDM Table 5-5 */
vcpu->arch.exception.pending = true;
injected must be cleared.
> Regards,
> Wanpeng Li
>
>>
>>> should set req_immediate_exit to true.
>>>
>>> Does this help?
>>>
>>> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>>> index b698b2f135a2..76d5a192be6c 100644
>>> --- a/arch/x86/kvm/x86.c
>>> +++ b/arch/x86/kvm/x86.c
>>> @@ -6365,14 +6365,20 @@ static int inject_pending_event(struct kvm_vcpu *vcpu, bool req_int_win)
>>> return 0;
>>> }
>>>
>>> - if (vcpu->arch.nmi_injected) {
>>> - kvm_x86_ops->set_nmi(vcpu);
>>> - return 0;
>>> - }
>>> + /*
>>> + * Exceptions must be injected immediately, or the exception
>>> + * frame will have the address of the NMI or interrupt handler.
>>> + */
>>> + if (!vcpu->arch.exception.pending) {
>>> + if (vcpu->arch.nmi_injected) {
>>> + kvm_x86_ops->set_nmi(vcpu);
>>> + return 0;
>>> + }
>>>
>>> - if (vcpu->arch.interrupt.pending) {
>>> - kvm_x86_ops->set_irq(vcpu);
>>> - return 0;
>>> + if (vcpu->arch.interrupt.pending) {
>>> + kvm_x86_ops->set_irq(vcpu);
>>> + return 0;
>>> + }
>>> }
>>>
>>> if (is_guest_mode(vcpu) && kvm_x86_ops->check_nested_events) {
>>>
>>> Paolo
next prev parent reply other threads:[~2017-08-24 9:47 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-24 4:21 [PATCH v3 1/4] KVM: VMX: use kvm_event_needs_reinjection Wanpeng Li
2017-08-24 4:21 ` [PATCH v3 2/4] KVM: X86: Fix loss of exception which has not yet injected Wanpeng Li
2017-08-24 6:52 ` Wanpeng Li
2017-08-24 8:57 ` Paolo Bonzini
2017-08-24 9:13 ` Wanpeng Li
2017-08-24 9:34 ` Wanpeng Li
2017-08-24 9:47 ` Paolo Bonzini [this message]
2017-08-24 9:35 ` Paolo Bonzini
2017-08-24 9:47 ` Wanpeng Li
2018-01-07 7:26 ` Ross Zwisler
2018-01-09 1:24 ` Haozhong Zhang
2017-08-24 4:21 ` [PATCH v3 3/4] KVM: VMX: Move the nested_vmx_inject_exception_vmexit call from nested_vmx_check_exception to vmx_queue_exception Wanpeng Li
2017-08-24 4:21 ` [PATCH v3 4/4] KVM: nVMX: Fix trying to cancel vmlauch/vmresume Wanpeng Li
2018-01-09 8:57 [PATCH v3 2/4] KVM: X86: Fix loss of exception which has not yet injected Liran Alon
2018-01-09 9:06 ` Haozhong Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5424f512-3612-4f5a-2a10-36f4182f931d@redhat.com \
--to=pbonzini@redhat.com \
--cc=kernellwp@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rkrcmar@redhat.com \
--cc=wanpeng.li@hotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®