mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Liran Alon <liran.alon@oracle.com>
To: <pbonzini@redhat.com>
Cc: <mingo@redhat.com>, <chao.gao@intel.com>, <x86@kernel.org>,
	<tglx@linutronix.de>, <rkrcmar@redhat.com>,
	<linux-kernel@vger.kernel.org>, <hpa@zytor.com>,
	<kvm@vger.kernel.org>
Subject: Re: [PATCH] x86/kvm/vmx: Don't halt vcpu when L1 is injecting events to L2
Date: Fri, 9 Feb 2018 18:16:39 -0800 (PST)	[thread overview]
Message-ID: <3b565dd4-0b90-4301-b918-aba529d54a81@default> (raw)


----- pbonzini@redhat.com wrote:

> On 08/02/2018 13:09, Liran Alon wrote:
> > ----- pbonzini@redhat.com wrote:
> >> On 08/02/2018 06:13, Chao Gao wrote:
> > 
> > A possible patch to fix this is to change vmx_hwapic_irr_update()
> such that
> > if is_guest_mode(vcpu)==true, we should return max(max_irr, rvi) and
> return
> > that value into apic_has_interrupt_for_ppr().
> > Need to verify that it doesn't break other flows but I think it
> makes sense.
> > What do you think?
> 
> Yeah, I think it makes sense though I'd need to look a lot more at
> arch/x86/kvm/lapic.c and arch/x86/kvm/vmx.c to turn that into a
> patch!
> 
> Paolo

After thinking about this a bit more, I don't like my previous suggestion.
As we don't semantically want to change the value returned from kvm_apic_has_interrupt().
Instead, it makes more sense to change kvm_cpu_has_interrupt() to check for RVI>PPR
in case is_guest_mode(vcpu)==true.

Something like (partial theoretical patch):

@@ -97,6 +97,14 @@ int kvm_cpu_has_interrupt(struct kvm_vcpu *v)
        if (kvm_cpu_has_extint(v))
                return 1;
 
+       /*
+        * When running L2, L1 controls vmcs02 RVI via vmcs12.
+        * Therefore, it is possible RVI indicates pending interrupt
+        * for vCPU while LAPIC IRR is empty.
+        */
+       if (is_guest_mode(v) &&
+           (kvm_x86_ops->hwapic_has_interrupt(v) != -1))
+               return 1;
+
        return kvm_apic_has_interrupt(v) != -1; /* LAPIC */
 }

Where:

+static int vmx_get_rvi(void)
+{
+       return ((u8)vmcs_read16(GUEST_INTR_STATUS) & 0xff);
+}

+static int vmx_hwapic_has_interrupt(struct kvm_vcpu *vcpu)
+{
+       int vector = vmx_get_rvi(vcpu);
+       return kvm_apic_has_interrupt_for_vector(vector);
+}

+int kvm_apic_has_interrupt_for_vector(struct kvm_vcpu *vcpu, int vector)
+{
+       struct kvm_lapic *apic = vcpu->arch.apic;
+       u32 ppr;
+
+       if (!apic_enabled(apic))
+               return -1;
+
+       __apic_update_ppr(apic, &ppr);
+       return (((vector & 0xF0) > ppr) ? (vector) : (-1));
+}
+EXPORT_SYMBOL_GPL(kvm_apic_has_interrupt_for_vector);

Regards,
-Liran

             reply	other threads:[~2018-02-10  2:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-10  2:16 Liran Alon [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-02-08 12:09 Liran Alon
2018-02-08 12:04 ` Chao Gao
2018-02-08 13:53 ` Paolo Bonzini
2018-02-08  5:13 Chao Gao
2018-02-08 10:29 ` Paolo Bonzini
2018-02-08 11:20   ` Chao Gao

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=3b565dd4-0b90-4301-b918-aba529d54a81@default \
    --to=liran.alon@oracle.com \
    --cc=chao.gao@intel.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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®