kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wanpeng Li <kernellwp@gmail.com>
To: "Radim Krčmář" <rkrcmar@redhat.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	kvm <kvm@vger.kernel.org>, Paolo Bonzini <pbonzini@redhat.com>,
	Wanpeng Li <wanpeng.li@hotmail.com>
Subject: Re: [PATCH v2] KVM: nVMX: Fix attempting to emulate "Acknowledge interrupt on exit" when there is no interrupt which L1 requires to inject to L2
Date: Fri, 4 Aug 2017 09:23:34 +0800	[thread overview]
Message-ID: <CANRm+Cw9+zBrk24MZo5YSw4j2KxyRsuk+dh8QNT9q0orVo7egA@mail.gmail.com> (raw)
In-Reply-To: <20170803134636.GG32403@flask>

2017-08-03 21:46 GMT+08:00 Radim Krčmář <rkrcmar@redhat.com>:
> 2017-07-31 19:25-0700, Wanpeng Li:
>> From: Wanpeng Li <wanpeng.li@hotmail.com>
>>
>> ------------[ cut here ]------------
>>  WARNING: CPU: 5 PID: 2288 at arch/x86/kvm/vmx.c:11124 nested_vmx_vmexit+0xd64/0xd70 [kvm_intel]
>>  CPU: 5 PID: 2288 Comm: qemu-system-x86 Not tainted 4.13.0-rc2+ #7
>>  RIP: 0010:nested_vmx_vmexit+0xd64/0xd70 [kvm_intel]
>> Call Trace:
>>   vmx_check_nested_events+0x131/0x1f0 [kvm_intel]
>>   ? vmx_check_nested_events+0x131/0x1f0 [kvm_intel]
>>   kvm_arch_vcpu_ioctl_run+0x5dd/0x1be0 [kvm]
>>   ? vmx_vcpu_load+0x1be/0x220 [kvm_intel]
>>   ? kvm_arch_vcpu_load+0x62/0x230 [kvm]
>>   kvm_vcpu_ioctl+0x340/0x700 [kvm]
>>   ? kvm_vcpu_ioctl+0x340/0x700 [kvm]
>>   ? __fget+0xfc/0x210
>>   do_vfs_ioctl+0xa4/0x6a0
>>   ? __fget+0x11d/0x210
>>   SyS_ioctl+0x79/0x90
>>   do_syscall_64+0x8f/0x750
>>   ? trace_hardirqs_on_thunk+0x1a/0x1c
>>   entry_SYSCALL64_slow_path+0x25/0x25
>>
>> This can be reproduced by booting L1 guest w/ 'noapic' grub parameter, which
>> means that tells the kernel to not make use of any IOAPICs that may be present
>> in the system.
>>
>> Actually external_intr variable in nested_vmx_vmexit() is the req_int_win
>> variable passed from vcpu_enter_guest() which means that the L0's userspace
>> requests an irq window. I observed the scenario (!kvm_cpu_has_interrupt(vcpu) &&
>> L0's userspace reqeusts an irq window) is true, so there is no interrupt which
>> L1 requires to inject to L2, we should not attempt to emualte "Acknowledge
>> interrupt on exit" for the irq window requirement in this scenario.
>>
>> This patch fixes it by not attempt to emulate "Acknowledge interrupt on exit"
>> if there is no L1 requirement to inject an interrupt to L2.
>>
>> Cc: Paolo Bonzini <pbonzini@redhat.com>
>> Cc: Radim Krčmář <rkrcmar@redhat.com>
>> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
>> ---
>> v1 -> v2:
>>  * update patch description
>>  * check nested_exit_intr_ack_set() first
>>
>>  arch/x86/kvm/vmx.c | 5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
>> index 2737343..c5a0ab5 100644
>> --- a/arch/x86/kvm/vmx.c
>> +++ b/arch/x86/kvm/vmx.c
>> @@ -11118,8 +11118,9 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
>>
>>       vmx_switch_vmcs(vcpu, &vmx->vmcs01);
>>
>> -     if ((exit_reason == EXIT_REASON_EXTERNAL_INTERRUPT)
>> -         && nested_exit_intr_ack_set(vcpu)) {
>
> I've added a TODO comment so it's clearer that we should not be here if
> there is no interrupt.
>
>> +     if (nested_exit_intr_ack_set(vcpu) &&
>> +             exit_reason == EXIT_REASON_EXTERNAL_INTERRUPT &&
>> +             kvm_cpu_has_interrupt(vcpu)) {
>>               int irq = kvm_cpu_get_interrupt(vcpu);
>>               WARN_ON(irq < 0);
>>               vmcs12->vm_exit_intr_info = irq |
>
> Changed the indentation to the original alignment.
> Please don't use 1 tab -- the condition and body meld, which makes it
> harder to read.  (2 tabs would be ok too.)
>
> And the subject was way too long, so I changed it to
> KVM: nVMX: Fix interrupt window request with "Acknowledge interrupt on exit"
>
> Applied as it results in better behavior, even if it still is incorrect,
> thanks.

Thanks Radim. :) In addition, I will think more about it and figure
out a finial solution.

Regards,
Wanpeng Li

  reply	other threads:[~2017-08-04  1:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-01  2:25 Wanpeng Li
2017-08-01 19:59 ` Radim Krčmář
2017-08-01 22:42   ` Wanpeng Li
2017-08-02  8:05     ` Wanpeng Li
2017-08-02  8:13       ` Paolo Bonzini
2017-08-03 13:46 ` Radim Krčmář
2017-08-04  1:23   ` Wanpeng Li [this message]
2019-10-18 21:12     ` Jim Mattson

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=CANRm+Cw9+zBrk24MZo5YSw4j2KxyRsuk+dh8QNT9q0orVo7egA@mail.gmail.com \
    --to=kernellwp@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=wanpeng.li@hotmail.com \
    --subject='Re: [PATCH v2] KVM: nVMX: Fix attempting to emulate "Acknowledge interrupt on exit" when there is no interrupt which L1 requires to inject to L2' \
    /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

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox