public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Gleb Natapov <gleb@redhat.com>
Cc: "Zhang, Yang Z" <yang.z.zhang@intel.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"Shan, Haitao" <haitao.shan@intel.com>,
	"Zhang, Xiantao" <xiantao.zhang@intel.com>,
	"Nakajima, Jun" <jun.nakajima@intel.com>,
	"Anvin, H Peter" <h.peter.anvin@intel.com>
Subject: Re: [PATCH 2/2] x86, apicv: Add Posted Interrupt supporting
Date: Fri, 8 Feb 2013 11:46:16 -0200	[thread overview]
Message-ID: <20130208134616.GA18427@amt.cnet> (raw)
In-Reply-To: <20130208122844.GD19412@redhat.com>

On Fri, Feb 08, 2013 at 02:28:44PM +0200, Gleb Natapov wrote:
> On Thu, Feb 07, 2013 at 07:49:47PM -0200, Marcelo Tosatti wrote:
> > On Thu, Feb 07, 2013 at 04:01:11PM +0200, Gleb Natapov wrote:
> > > On Wed, Feb 06, 2013 at 08:49:23PM -0200, Marcelo Tosatti wrote:
> > > > > Second is that interrupt may be
> > > > > reported as delivered, but it will be coalesced (possible only with the self
> > > > > IPI with the same vector):
> > > > > 
> > > > > Starting condition: PIR=0, IRR=0 vcpu is in a guest mode
> > > > > 
> > > > > io thread                 |           vcpu
> > > > > accept_apic_interrupt()   |
> > > > >  PIR and IRR is zero      |
> > > > >  set PIR                  |
> > > > >  return delivered         |
> > > > >                           |      self IPI
> > > > >                           |      set IRR
> > > > >                           |     merge PIR to IRR (*)
> > > > > 
> > > > > At (*) interrupt that was reported as delivered is coalesced.
> > > > 
> > > > Only vcpu itself should send self-IPI, so its fine.
> > > > 
> > > It is fine only because this is not happening in practice (I hope) for single interrupt
> > > we care about. Otherwise this is serious problem.
> > 
> > Coalesced information is only interesting for non IPI cases, that
> > is, device emulation (at the moment, at least).
> > 
> And incorrect result will be returned for an interrupt injected by an emulated device
> in the scenario above.
>
> > The above cause can happen when loading APIC registers, but delivered
> > is not interesting in that case. Good to document, however.
> > 
> > > > > > Or:
> > > > > > 
> > > > > > apic_accept_interrupt() {
> > > > > > 
> > > > > > 1. Read ORIG_PIR=PIR, ORIG_IRR=IRR.
> > > > > > Never set IRR when HWAPIC enabled, even if outside of guest mode.
> > > > > > 2. Set PIR and let HW or SW VM-entry transfer it to IRR.
> > > > > > 3. set_irq return value: (ORIG_PIR or ORIG_IRR set).
> > > > > > }
> > > > > > 
> > > > > This can report interrupt as coalesced, but it will be eventually delivered
> > > > > as separate interrupt:
> > > > > 
> > > > > Starting condition: PIR=0, IRR=1 vcpu is in a guest mode
> > > > > 
> > > > >  io thread              |         vcpu
> > > > >                         |         
> > > > > accept_apic_interrupt() |
> > > > > ORIG_PIR=0, ORIG_IRR=1  |
> > > > >                         |    EOI
> > > > >                         |    clear IRR, set ISR
> > > > > set PIR                 |
> > > > > return coalesced        |
> > > > >                         |    clear PIR, set IRR
> > > > >                         |    EOI
> > > > >                         |    clear IRR, set ISR (*)
> > > > > 
> > > > > At (*) interrupt that was reported as coalesced is delivered.
> > > > > 
> > > > > 
> > > > > So still no perfect solution. But first one has much less serious
> > > > > problems for our practical needs.
> > > > > 
> > > > > > Two or more concurrent set_irq can race with each other, though. Can
> > > > > > either document the race or add a lock.
> > > > > > 
> > > > > 
> > > > > --
> > > > > 			Gleb.
> > > > 
> > > > Ok, then:
> > > > 
> > > > accept_apic_irq:
> > > > 1. coalesced = test_and_set_bit(PIR)
> > > > 2. set KVM_REQ_EVENT bit 	(*)
> > > > 3. if (vcpu->in_guest_mode)
> > > > 4.	if (test_and_set_bit(pir notification bit))
> > > > 5.		send PIR IPI
> > > > 6. return coalesced
> > > Do not see how it will help.
> > > 
> > > Starting condition: PIR=0, IRR=1 vcpu is in a guest mode
> > > 
> > > io thread                  |              vcpu
> > > accept_apic_interrupt()    |
> > > coalesced = 0, PIR=1       |
> > > vcpu in a guest mode:      |
> > >     send PIR IPI           |
> > >                            |      receive PIR IPI
> > >                            |      merge PIR to IRR (*)
> > > return not coalesced       |
> > > 
> > > At (*) interrupt that was reported as delivered is coalesced.
> > 
> > Of course!
> > 
> > > The point is that we need to check PIR and IRR atomically and this is
> > > impossible.
> > 
> > Ok, next try:
> > 
> > 1. orig_irr = read irr from vapic page
> > 2. if (orig_irr == 0)
> > 3. 	return test_and_test_bit(pir)
> > 4. return 0
> > 
> I think this is exactly same solution we are discussing above:
> 
> apic_accept_interrupt() {
>  if (PIR || IRR)
>    return coalesced;
>  else
>    set PIR;
> }

Its not exactly the same. Without test_and_set_bit(PIR) two vcpus can race.

> with the same self-IPI problem. IMO this is the best we can do and will
> work correctly for RTC interrupt re-injection case.

Yes.


  reply	other threads:[~2013-02-08 13:46 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-13  7:29 [PATCH 0/2] KVM: Add posted interrupt supporting Yang Zhang
2012-12-13  7:29 ` [PATCH 1/2] x86: Enable ack interrupt on vmexit Yang Zhang
2012-12-13  7:51   ` Gleb Natapov
2012-12-13  7:54     ` Zhang, Yang Z
2012-12-13  7:58       ` Gleb Natapov
2012-12-13  8:03         ` Zhang, Yang Z
2012-12-13  8:05           ` Gleb Natapov
2012-12-13  8:19             ` Zhang, Yang Z
2012-12-13  8:22               ` Gleb Natapov
2012-12-13  8:23                 ` Zhang, Yang Z
2012-12-16 13:26                 ` Zhang, Yang Z
2012-12-18  9:11                   ` Gleb Natapov
2012-12-13  7:29 ` [PATCH 2/2] x86, apicv: Add Posted Interrupt supporting Yang Zhang
2013-01-22 22:59   ` Marcelo Tosatti
2013-01-23  5:09     ` Zhang, Yang Z
2013-01-24 23:43   ` Marcelo Tosatti
2013-01-25  0:40     ` Zhang, Yang Z
2013-01-30 23:03       ` Marcelo Tosatti
2013-01-30 23:57         ` Marcelo Tosatti
2013-01-31  7:35         ` Gleb Natapov
2013-01-31  9:43         ` Gleb Natapov
2013-01-31 13:32           ` Marcelo Tosatti
2013-01-31 13:38             ` Gleb Natapov
2013-01-31 13:44               ` Marcelo Tosatti
2013-01-31 13:55                 ` Gleb Natapov
2013-02-04  0:57                   ` Marcelo Tosatti
2013-02-04  9:10                     ` Zhang, Yang Z
2013-02-04  9:55                     ` Gleb Natapov
2013-02-04 14:43                       ` Marcelo Tosatti
2013-02-04 17:13                         ` Gleb Natapov
2013-02-04 19:59                           ` Marcelo Tosatti
2013-02-04 20:47                             ` Marcelo Tosatti
2013-02-05  5:57                               ` Zhang, Yang Z
2013-02-05  8:00                                 ` Gleb Natapov
2013-02-05 10:35                                   ` Zhang, Yang Z
2013-02-05 10:54                                     ` Gleb Natapov
2013-02-05 10:58                                       ` Zhang, Yang Z
2013-02-05 11:16                                         ` Gleb Natapov
2013-02-05 13:26                                           ` Zhang, Yang Z
2013-02-05 13:29                                             ` Gleb Natapov
2013-02-05 13:40                                               ` Zhang, Yang Z
2013-02-05 13:43                                                 ` Gleb Natapov
2013-02-07  1:23                                                 ` Marcelo Tosatti
2013-02-05  7:32                               ` Gleb Natapov
2013-02-06 22:49                                 ` Marcelo Tosatti
2013-02-07  0:24                                   ` Marcelo Tosatti
2013-02-07 13:52                                     ` Gleb Natapov
2013-02-08  2:07                                       ` Marcelo Tosatti
2013-02-08 12:18                                         ` Gleb Natapov
2013-02-07 14:01                                   ` Gleb Natapov
2013-02-07 21:49                                     ` Marcelo Tosatti
2013-02-08 12:28                                       ` Gleb Natapov
2013-02-08 13:46                                         ` Marcelo Tosatti [this message]
2013-01-31  9:37   ` Gleb Natapov
2013-02-04  9:11     ` Zhang, Yang Z

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=20130208134616.GA18427@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=gleb@redhat.com \
    --cc=h.peter.anvin@intel.com \
    --cc=haitao.shan@intel.com \
    --cc=jun.nakajima@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=xiantao.zhang@intel.com \
    --cc=yang.z.zhang@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