public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: "Zhang, Yang Z" <yang.z.zhang@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"avi.kivity@gmail.com" <avi.kivity@gmail.com>,
	"Zhang, Xiantao" <xiantao.zhang@intel.com>
Subject: Re: [PATCH v4 2/2] KVM: VMX: Add Posted Interrupt supporting
Date: Sat, 23 Feb 2013 16:35:30 +0200	[thread overview]
Message-ID: <20130223143530.GA25155@redhat.com> (raw)
In-Reply-To: <A9667DDFB95DB7438FA9D7D576C3D87E099BAF6C@SHSMSX101.ccr.corp.intel.com>

On Sat, Feb 23, 2013 at 02:05:28PM +0000, Zhang, Yang Z wrote:
> >> +	return test_bit(vector, (unsigned long *)pi_desc->pir);
> >> +}
> >> +
> >> +static void pi_set_pir(int vector, struct pi_desc *pi_desc)
> >> +{
> >> +	__set_bit(vector, (unsigned long *)pi_desc->pir);
> >> +}
> > 
> > This must be locked atomic operation (set_bit).
> If using spinlock, pi_set_pir is not called concurrently. It safe to use _set_bit.
> 
HW still access it concurrently without bothering taking your lock.

>  
> >> +
> >>  struct vcpu_vmx {
> >>  	struct kvm_vcpu       vcpu;
> >>  	unsigned long         host_rsp;
> >> @@ -429,6 +465,10 @@ struct vcpu_vmx {
> >> 
> >>  	bool rdtscp_enabled;
> >> +	/* Posted interrupt descriptor */
> >> +	struct pi_desc pi_desc;
> >> +	spinlock_t pi_lock;
> > 
> > Don't see why the lock is necessary. Please use the following
> > pseudocode for vmx_deliver_posted_interrupt:
> > 
> > vmx_deliver_posted_interrupt(), returns 'bool injected'.
> > 
> > 1. orig_irr = read irr from vapic page
> > 2. if (orig_irr != 0)
> > 3.	return false;
> > 4. kvm_make_request(KVM_REQ_EVENT)
> > 5. bool injected = !test_and_set_bit(PIR)
> > 6. if (vcpu->guest_mode && injected)
> > 7. 	if (test_and_set_bit(PIR notification bit))
> > 8.		send PIR IPI
> > 9. return injected
> 
> Consider follow case:
> vcpu 0                      |                vcpu1
> send intr to vcpu1
> check irr
>                                             receive a posted intr
> 										pir->irr(pir is cleared, irr is set)
> injected=test_and_set_bit=true
> pir=set
> 
> Then both irr and pir have the interrupt pending, they may merge to one later, but injected reported as true. Wrong.
> 
I and Marcelo discussed the lockless logic that should be used here on
the previous patch submission. All is left for you is to implement it.
We worked hard to make irq injection path lockless, we will not going to
add one now.

--
			Gleb.

  reply	other threads:[~2013-02-23 14:35 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-22 13:42 [PATCH v4 0/2] KVM: VMX: Add Posted Interrupt supporting Yang Zhang
2013-02-22 13:42 ` [PATCH v4 1/2] KVM: VMX: enable acknowledge interupt on vmexit Yang Zhang
2013-02-22 13:42 ` [PATCH v4 2/2] KVM: VMX: Add Posted Interrupt supporting Yang Zhang
2013-02-23 13:43   ` Marcelo Tosatti
2013-02-23 14:05     ` Zhang, Yang Z
2013-02-23 14:35       ` Gleb Natapov [this message]
2013-02-23 14:48         ` Marcelo Tosatti
2013-02-23 15:31           ` Gleb Natapov
2013-02-23 17:05             ` Marcelo Tosatti
2013-02-23 19:42               ` Gleb Natapov
2013-02-23 19:52                 ` Marcelo Tosatti
2013-02-23 19:59                   ` Gleb Natapov
2013-02-24 13:55                 ` Zhang, Yang Z
2013-02-24 14:19                   ` Gleb Natapov
2013-02-24 14:26                     ` Zhang, Yang Z
2013-02-24 14:39                       ` Gleb Natapov
2013-02-24 18:08                     ` Marcelo Tosatti
2013-02-24 18:59                       ` Avi Kivity
2013-02-25  8:42                         ` Zhang, Yang Z
2013-02-25 11:01                           ` Gleb Natapov
2013-02-25 11:04                             ` Zhang, Yang Z
2013-02-25 11:07                               ` Gleb Natapov
2013-02-25 11:13                                 ` Zhang, Yang Z
2013-02-25 12:49                                   ` Marcelo Tosatti
2013-02-25 12:52                                     ` Zhang, Yang Z
2013-02-25 13:34                                   ` Gleb Natapov
2013-02-25 14:00                                     ` Marcelo Tosatti
2013-02-25 14:17                                       ` Marcelo Tosatti
2013-02-25 17:40                                         ` Gleb Natapov
2013-02-25 22:29                                           ` Marcelo Tosatti
2013-02-25 16:50                                     ` Avi Kivity
2013-02-25 17:43                                       ` Gleb Natapov
2013-02-25 18:56                                         ` Avi Kivity
2013-02-25 19:01                                           ` Gleb Natapov
2013-02-26  8:12                                             ` Gleb Natapov
2013-02-26 16:13                                               ` Avi Kivity
2013-02-24 17:44                   ` Marcelo Tosatti
2013-02-25  7:24                     ` Zhang, Yang Z
2013-02-23 14:44       ` Marcelo Tosatti
2013-02-23 15:16         ` Zhang, Yang Z
2013-02-23 16:50           ` Marcelo Tosatti
2013-02-24 13:17             ` Zhang, Yang Z
2013-02-24 17:39               ` Marcelo Tosatti
2013-02-25  6:55                 ` Zhang, Yang Z
2013-02-25 13:01                   ` Marcelo Tosatti
2013-02-25 14:32                     ` 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=20130223143530.GA25155@redhat.com \
    --to=gleb@redhat.com \
    --cc=avi.kivity@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --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