linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Avi Kivity <avi@redhat.com>,
	gleb@redhat.com, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v10 2/2] kvm: Add resampling irqfds for level triggered interrupts
Date: Wed, 19 Sep 2012 13:23:35 -0600	[thread overview]
Message-ID: <1348082615.28860.58.camel@bling.home> (raw)
In-Reply-To: <20120919184818.GB312@redhat.com>

On Wed, 2012-09-19 at 21:48 +0300, Michael S. Tsirkin wrote:
> On Wed, Sep 19, 2012 at 12:23:13PM -0600, Alex Williamson wrote:
> > On Wed, 2012-09-19 at 11:59 +0300, Avi Kivity wrote:
> > > On 09/18/2012 06:16 AM, Alex Williamson wrote:
> > > > @@ -92,6 +156,43 @@ irqfd_shutdown(struct work_struct *work)
> > > >  	 */
> > > >  	flush_work_sync(&irqfd->inject);
> > > >  
> > > > +	if (irqfd->resampler) {
> > > > +		struct _irqfd_resampler *resampler = irqfd->resampler;
> > > > +		struct kvm *kvm = resampler->kvm;
> > > > +
> > > > +		mutex_lock(&kvm->irq_lock);
> > > > +		spin_lock_irq(&irqfd->kvm->irqfds.lock);
> > > > +
> > > > +		list_del_rcu(&irqfd->resampler_list);
> > > > +
> > > > +		/*
> > > > +		 * On removal of the last irqfd in the resampler list,
> > > > +		 * remove the resampler and unregister the irq ack
> > > > +		 * notifier.  It's possible to race the ack of the final
> > > > +		 * injection here, so manually de-assert the gsi to avoid
> > > > +		 * leaving an unmanaged, asserted interrupt line.
> > > > +		 */
> > > > +		if (list_empty(&resampler->irqfds)) {
> > > > +			list_del(&resampler->list);
> > > > +			__kvm_unregister_irq_ack_notifier(kvm,
> > > > +							  &resampler->notifier);
> > > > +			kvm_set_irq(kvm, KVM_IRQFD_RESAMPLE_IRQ_SOURCE_ID,
> > > > +				    resampler->notifier.gsi, 0);
> > > > +			kfree(resampler);
> > > 
> > > Is this rcu safe?
> > 
> > No it's not and unfortunately this also points out another race in
> > trying to use a single source ID...
> > 
> > > > +		}
> > > > +
> > > > +		spin_unlock_irq(&irqfd->kvm->irqfds.lock);
> > > > +		mutex_unlock(&kvm->irq_lock);
> > > > +
> > > > +		/*
> > > > +		 * Both list_del_rcu & __kvm_unregister_irq_ack_notifier
> > > > +		 * require an rcu grace period/
> > > > +		 */
> > > > +		synchronize_rcu();
> > 
> > The kfree can't be done until here and we also have to assume that ack
> > notifies are firing until here.  That means that between the
> > mutex_unlock and the end of synchronize_rcu another resampling irqfd can
> > be registered, post an interrupt, and have it de-asserted by the wrong
> > resampler.  Maybe the conversion wasn't as clean as I first thought :(
> > > Quite ugly to expose the internals this way.
> > 
> > Yep.  I don't know how to clean it up though; between all the different
> > rcu operations and locks, it's a mess.  Thanks,
> > 
> > Alex
> 
> Add another mutex for the resamplers, keep it during the whole
> operation? This also removes the need for exposing the internals.
> If you do pls document lock nesting rules.

How does that hide the internals?  Seems like we'd just wrap this in yet
another mutex, but be largely the same.  Thanks,

Alex


  reply	other threads:[~2012-09-19 19:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-18  3:16 [PATCH v10 0/2] kvm: level irqfd support Alex Williamson
2012-09-18  3:16 ` [PATCH v10 1/2] kvm: Provide pre-locked setup to irq ack notifier Alex Williamson
2012-09-18  3:16 ` [PATCH v10 2/2] kvm: Add resampling irqfds for level triggered interrupts Alex Williamson
2012-09-18 23:29   ` Michael S. Tsirkin
2012-09-19  8:59   ` Avi Kivity
2012-09-19  9:08     ` Michael S. Tsirkin
2012-09-19  9:10       ` Avi Kivity
2012-09-19 13:54         ` Alex Williamson
2012-09-19 14:35           ` Avi Kivity
2012-09-19 18:23     ` Alex Williamson
2012-09-19 18:48       ` Michael S. Tsirkin
2012-09-19 19:23         ` Alex Williamson [this message]
2012-09-19 19:59           ` Michael S. Tsirkin

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=1348082615.28860.58.camel@bling.home \
    --to=alex.williamson@redhat.com \
    --cc=avi@redhat.com \
    --cc=gleb@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.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;
as well as URLs for NNTP newsgroup(s).