From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Oliver Upton <oupton@google.com>,
Jim Mattson <jmattson@google.com>, kvm list <kvm@vger.kernel.org>,
liam.merwick@oracle.com, wanpeng.li@hotmail.com
Subject: Re: [PATCH v3 11/11] KVM: nVMX: Wake L2 from HLT when nested posted-interrupt pending
Date: Mon, 30 Nov 2020 19:14:59 +0000 [thread overview]
Message-ID: <X8VEsw4ENJ3MH+3o@google.com> (raw)
In-Reply-To: <89fe1772-36c7-7338-69aa-25d84a9febe8@redhat.com>
On Thu, Nov 26, 2020, Paolo Bonzini wrote:
> On 25/11/20 19:32, Sean Christopherson wrote:
> > I'm pretty sure the exiting vCPU needs to wait
> > for all senders to finish their sequence, otherwise pi_pending could be left
> > set, but spinning on pi_pending is wrong.
>
> What if you set it before?
That doesn't help. nested.pi_pending will be left set, with a valid vIRQ in the
PID, after vmx_vcpu_run() if kvm_vcpu_trigger_posted_interrupt() succeeds but
the PINV is delivered in the host.
Side topic, for the "wait" sequence to work, vmx_vcpu_run() would need to do
kvm_vcpu_exiting_guest_mode() prior to waiting for senders to completely their
sequence.
>
> static int vmx_deliver_nested_posted_interrupt(struct kvm_vcpu *vcpu,
> int vector)
> {
> struct vcpu_vmx *vmx = to_vmx(vcpu);
>
> if (is_guest_mode(vcpu) &&
> vector == vmx->nested.posted_intr_nv) {
> /*
> * Set pi_pending after ON.
> */
> smp_store_release(&vmx->nested.pi_pending, true);
> if (!kvm_vcpu_trigger_posted_interrupt(vcpu, true)) {
> /*
> * The guest was not running, let's try again
> * on the next vmentry.
> */
> <set PINV in L1 vIRR>
> kvm_make_request(KVM_REQ_EVENT, vcpu);
> kvm_vcpu_kick(vcpu);
> vmx->nested.pi_pending = false;
> }
> write_seqcount_end(&vmx->nested.pi_pending_sc);
> return 0;
> }
> return -1;
> }
>
> On top of this:
>
> - kvm_x86_ops.hwapic_irr_update can be deleted. It is already done
> unconditionally by vmx_sync_pir_to_irr before every vmentry. This gives
> more freedom in changing vmx_sync_pir_to_irr and vmx_hwapic_irr_update.
And would lower the barrier of entry for understanding this code :-)
> - VCPU entry must check if max_irr == vmx->nested.posted_intr_nv, and if so
> send a POSTED_INTR_NESTED_VECTOR self-IPI.
Hmm, there's also this snippet in vmx_sync_pir_to_irr() that needs to be dealt
with. If the new max_irr in this case is the nested PI vector, KVM will bail
from the run loop instead of continuing on.
/*
* If we are running L2 and L1 has a new pending interrupt
* which can be injected, we should re-evaluate
* what should be done with this new L1 interrupt.
* If L1 intercepts external-interrupts, we should
* exit from L2 to L1. Otherwise, interrupt should be
* delivered directly to L2.
*/
if (is_guest_mode(vcpu) && max_irr_updated) {
if (nested_exit_on_intr(vcpu))
kvm_vcpu_exiting_guest_mode(vcpu);
else
kvm_make_request(KVM_REQ_EVENT, vcpu);
}
> Combining both (and considering that AMD doesn't do anything interesting in
> vmx_sync_pir_to_irr), I would move the whole call to vmx_sync_pir_to_irr
> from x86.c to vmx/vmx.c, so that we know that vmx_hwapic_irr_update is
> called with interrupts disabled and right before vmentry:
>
> static int vmx_sync_pir_to_irr(struct kvm_vcpu *vcpu)
> {
> ...
> - vmx_hwapic_irr_update(vcpu, max_irr);
> return max_irr;
> }
>
> -static void vmx_hwapic_irr_update(struct kvm_vcpu *vcpu, int max_irr)
> +static void vmx_hwapic_irr_update(struct kvm_vcpu *vcpu)
I would also vote to rename this helper; not sure what to call it, but for me
the current name doesn't help understand its purpose.
> {
> + int max_irr;
> +
> + WARN_ON(!irqs_disabled());
> + max_irr = vmx_sync_pir_to_irr(vcpu);
> if (!is_guest_mode(vcpu))
> vmx_set_rvi(max_irr);
> + else if (max_irr == vmx->nested.posted_intr_nv) {
> + ...
> + }
> }
>
> and in vmx_vcpu_run:
>
> + if (kvm_lapic_enabled(vcpu) && vcpu->arch.apicv_active)
> + vmx_hwapic_irr_update(vcpu);
And also drop the direct call to vmx_sync_pir_to_irr() in the fastpath exit.
> If you agree, feel free to send this (without the else of course) as a
> separate cleanup patch immediately.
Without what "else"?
next prev parent reply other threads:[~2020-11-30 19:15 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-24 16:12 [PATCH v3 00/11] KVM: nVMX: Fix multiple issues in nested posted-interrupts Liran Alon
2017-12-24 16:12 ` [PATCH v3 01/11] KVM: x86: Optimization: Create SVM stubs for sync_pir_to_irr() Liran Alon
2017-12-27 9:56 ` Paolo Bonzini
2017-12-27 10:01 ` Liran Alon
2017-12-24 16:12 ` [PATCH v3 02/11] KVM: x86: Change __kvm_apic_update_irr() to also return if max IRR updated Liran Alon
2018-01-02 1:51 ` Quan Xu
2017-12-24 16:12 ` [PATCH v3 03/11] KVM: nVMX: Re-evaluate L1 pending events when running L2 and L1 got posted-interrupt Liran Alon
2018-01-02 2:45 ` Quan Xu
2018-01-02 9:57 ` Liran Alon
2018-01-02 11:21 ` Quan Xu
2018-01-02 11:52 ` Quan Xu
2018-01-02 12:20 ` Liran Alon
2018-01-03 5:32 ` Quan Xu
2018-01-03 5:35 ` Quan Xu
2017-12-24 16:12 ` [PATCH v3 04/11] KVM: nVMX: Fix injection to L2 when L1 don't intercept external-interrupts Liran Alon
2017-12-24 16:12 ` [PATCH v3 05/11] KVM: x86: Rename functions which saves vCPU in per-cpu var Liran Alon
2017-12-24 16:12 ` [PATCH v3 06/11] KVM: x86: Set current_vcpu per-cpu var before enabling interrupts at host Liran Alon
2017-12-27 10:06 ` Paolo Bonzini
2017-12-27 10:44 ` Liran Alon
2017-12-24 16:12 ` [PATCH v3 07/11] KVM: x86: Add util for getting current vCPU running on CPU Liran Alon
2017-12-24 16:13 ` [PATCH v3 08/11] KVM: x86: Register empty handler for POSTED_INTR_NESTED_VECTOR IPI Liran Alon
2017-12-24 16:13 ` [PATCH v3 09/11] KVM: nVMX: Deliver missed nested-PI notification-vector via self-IPI while interrupts disabled Liran Alon
2017-12-24 16:13 ` [PATCH v3 10/11] KVM: nVMX: Wake halted L2 on nested posted-interrupt Liran Alon
2017-12-27 11:31 ` Paolo Bonzini
2017-12-27 12:01 ` Liran Alon
2017-12-27 12:27 ` Paolo Bonzini
2017-12-27 12:52 ` Liran Alon
2017-12-27 13:05 ` Paolo Bonzini
2017-12-27 15:33 ` Liran Alon
2017-12-27 15:54 ` Paolo Bonzini
2018-01-01 21:32 ` Paolo Bonzini
2018-01-01 22:37 ` Liran Alon
2018-01-02 7:25 ` Paolo Bonzini
2017-12-24 16:13 ` [PATCH v3 11/11] KVM: nVMX: Wake L2 from HLT when nested posted-interrupt pending Liran Alon
2017-12-27 10:15 ` Paolo Bonzini
2017-12-27 10:51 ` Liran Alon
2017-12-27 12:55 ` Paolo Bonzini
2017-12-27 15:15 ` Liran Alon
2017-12-27 15:55 ` Paolo Bonzini
2020-11-23 19:22 ` Oliver Upton
2020-11-23 22:42 ` Paolo Bonzini
2020-11-24 0:10 ` Oliver Upton
2020-11-24 0:13 ` Oliver Upton
2020-11-24 1:55 ` Sean Christopherson
2020-11-24 3:19 ` Sean Christopherson
2020-11-24 11:39 ` Paolo Bonzini
2020-11-24 21:22 ` Sean Christopherson
2020-11-25 0:10 ` Paolo Bonzini
2020-11-25 1:14 ` Sean Christopherson
2020-11-25 17:00 ` Paolo Bonzini
2020-11-25 18:32 ` Sean Christopherson
2020-11-26 13:13 ` Paolo Bonzini
2020-11-30 19:14 ` Sean Christopherson [this message]
2020-11-30 19:36 ` Paolo Bonzini
2020-12-03 22:07 ` Jim Mattson
2020-11-24 11:09 ` Paolo Bonzini
2020-12-03 21:45 ` 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=X8VEsw4ENJ3MH+3o@google.com \
--to=seanjc@google.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=liam.merwick@oracle.com \
--cc=oupton@google.com \
--cc=pbonzini@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.