From: Paolo Bonzini <pbonzini@redhat.com>
To: yadong.qi@intel.com, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, x86@kernel.org
Cc: sean.j.christopherson@intel.com, vkuznets@redhat.com,
wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org,
tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
hpa@zytor.com, liran.alon@oracle.com,
nikita.leshchenko@oracle.com, chao.gao@intel.com,
kevin.tian@intel.com, luhai.chen@intel.com, bing.zhu@intel.com,
kai.z.wang@intel.com
Subject: Re: [PATCH] KVM: x86: emulate wait-for-SIPI and SIPI-VMExit
Date: Thu, 5 Nov 2020 17:08:49 +0100 [thread overview]
Message-ID: <187635d0-7786-5d8f-a41a-45a6abd9d001@redhat.com> (raw)
In-Reply-To: <20200922052343.84388-1-yadong.qi@intel.com>
On 22/09/20 07:23, yadong.qi@intel.com wrote:
> From: Yadong Qi <yadong.qi@intel.com>
>
> Background: We have a lightweight HV, it needs INIT-VMExit and
> SIPI-VMExit to wake-up APs for guests since it do not monitor
> the Local APIC. But currently virtual wait-for-SIPI(WFS) state
> is not supported in nVMX, so when running on top of KVM, the L1
> HV cannot receive the INIT-VMExit and SIPI-VMExit which cause
> the L2 guest cannot wake up the APs.
>
> According to Intel SDM Chapter 25.2 Other Causes of VM Exits,
> SIPIs cause VM exits when a logical processor is in
> wait-for-SIPI state.
>
> In this patch:
> 1. introduce SIPI exit reason,
> 2. introduce wait-for-SIPI state for nVMX,
> 3. advertise wait-for-SIPI support to guest.
>
> When L1 hypervisor is not monitoring Local APIC, L0 need to emulate
> INIT-VMExit and SIPI-VMExit to L1 to emulate INIT-SIPI-SIPI for
> L2. L2 LAPIC write would be traped by L0 Hypervisor(KVM), L0 should
> emulate the INIT/SIPI vmexit to L1 hypervisor to set proper state
> for L2's vcpu state.
There is a problem in this patch, in that this change is incorrect:
>
> @@ -2847,7 +2847,8 @@ void kvm_apic_accept_events(struct kvm_vcpu *vcpu)
> */
> if (kvm_vcpu_latch_init(vcpu)) {
> WARN_ON_ONCE(vcpu->arch.mp_state == KVM_MP_STATE_INIT_RECEIVED);
> - if (test_bit(KVM_APIC_SIPI, &apic->pending_events))
> + if (test_bit(KVM_APIC_SIPI, &apic->pending_events) &&
> + !is_guest_mode(vcpu))
> clear_bit(KVM_APIC_SIPI, &apic->pending_events);
> return;
> }
Here you're not trying to process a latched INIT; you just want to delay
the processing of the SIPI until check_nested_events.
The change does have a correct part in it. In particular,
vmx_apic_init_signal_blocked should have been
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 47b8357b9751..64339121a4f0 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -7558,7 +7558,7 @@ static void enable_smi_window(struct kvm_vcpu *vcpu)
static bool vmx_apic_init_signal_blocked(struct kvm_vcpu *vcpu)
{
- return to_vmx(vcpu)->nested.vmxon;
+ return to_vmx(vcpu)->nested.vmxon && !is_guest_mode(vcpu);
}
static void vmx_migrate_timers(struct kvm_vcpu *vcpu)
to only latch INIT signals in root mode. However, SIPI must be cleared
unconditionally on SVM; the "!is_guest_mode" test in that case is incorrect.
The right way to do it is to call check_nested_events from
kvm_apic_accept_events. This will cause an INIT or SIPI vmexit, as
required. There is some extra complication to read pending_events
*before* kvm_apic_accept_events and not steal from the guest any INIT or
SIPI that is sent after kvm_apic_accept_events returns.
Thanks to your test case, I will test a patch and send it.
Paolo
next prev parent reply other threads:[~2020-11-05 16:08 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-22 5:23 yadong.qi
2020-09-22 9:09 ` Paolo Bonzini
2020-09-23 0:42 ` Qi, Yadong
2020-09-27 1:51 ` Qi, Yadong
2020-09-27 6:54 ` Paolo Bonzini
2020-11-02 5:42 ` Qi, Yadong
2020-11-05 16:08 ` Paolo Bonzini [this message]
2020-11-06 6:47 ` Qi, Yadong
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=187635d0-7786-5d8f-a41a-45a6abd9d001@redhat.com \
--to=pbonzini@redhat.com \
--cc=bing.zhu@intel.com \
--cc=bp@alien8.de \
--cc=chao.gao@intel.com \
--cc=hpa@zytor.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kai.z.wang@intel.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liran.alon@oracle.com \
--cc=luhai.chen@intel.com \
--cc=mingo@redhat.com \
--cc=nikita.leshchenko@oracle.com \
--cc=sean.j.christopherson@intel.com \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--cc=x86@kernel.org \
--cc=yadong.qi@intel.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®