All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Petr Mladek <pmladek@suse.cz>
Cc: Jiri Kosina <jkosina@suse.cz>,
	linux-kernel@vger.kernel.org,
	virtualization@lists.linux-foundation.org,
	Tejun Heo <tj@kernel.org>, Jeff Epler <jepler@unpythonic.net>
Subject: Re: [PATCH v3] virtio_balloon: Convert "vballoon" kthread into a workqueue
Date: Thu, 20 Nov 2014 19:00:16 +0200	[thread overview]
Message-ID: <20141120170016.GC7495@redhat.com> (raw)
In-Reply-To: <20141120165558.GB19165@pathway.suse.cz>

On Thu, Nov 20, 2014 at 05:55:58PM +0100, Petr Mladek wrote:
> On Thu 2014-11-20 11:29:35, Tejun Heo wrote:
> > On Thu, Nov 20, 2014 at 06:26:24PM +0200, Michael S. Tsirkin wrote:
> > > On Thu, Nov 20, 2014 at 06:25:43PM +0200, Michael S. Tsirkin wrote:
> > > > On Thu, Nov 20, 2014 at 11:07:46AM -0500, Tejun Heo wrote:
> > > > > On Thu, Nov 20, 2014 at 05:03:17PM +0100, Petr Mladek wrote:
> > > > > ...
> > > > > > @@ -476,7 +460,6 @@ static void virtballoon_remove(struct virtio_device *vdev)
> > > > > >  {
> > > > > >  	struct virtio_balloon *vb = vdev->priv;
> > > > > >  
> > > > > > -	kthread_stop(vb->thread);
> > > > > >  	remove_common(vb);
> > > > > >  	kfree(vb);
> > > > > >  }
> > > > > 
> > > > > Shouldn't the work item be flushed before removal is complete?
> 
> Great catch!
> 
> > > > In fact, flushing it won't help because it can requeue itself, right?
> > 
> > There's cancel_work_sync() to stop the self-requeueing ones.
> 
> Ah, one more problem is that remove_common(vb) calls leak_balloon()
> that queues the work if not finished. We would need to add some flag
> or variant that would disable the queuing when called here.
> 

That's why Tejun suggested cancel_work_sync, IIUC it stops
the requeuing without need for extra flags.

> > > From that POV a dedicated WQ kept it simple.
> > 
> > A dedicated wq doesn't do anything for that.  You can't shut down a
> > workqueue with a pending work item on it.  destroy_workqueue() will
> > try to drain the target wq, warn if it doesn't finish in certain
> > number of iterations and just keep trying indefinitely.
> 
> I wonder if it is guaranteed that none would trigger
> stats_request() or virtballoon_changed() when virtballoon_remove() is
> being called. I guess so because the original code would fail
> otherwise. The two functions access "vb->config_change"
> and the structure is freed in virtballoon_remove() without
> any protection.
> 
> I am trying to confirm this by reading the code but it is not that
> easy.
> 
> Best Regards,
> Petr

It's synchronized through hardware.  remove_common calls reset and
del_vqs which will prevent new interrupts.

-- 
MST

WARNING: multiple messages have this Message-ID (diff)
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Petr Mladek <pmladek@suse.cz>
Cc: Tejun Heo <tj@kernel.org>, Rusty Russell <rusty@rustcorp.com.au>,
	Jeff Epler <jepler@unpythonic.net>, Jiri Kosina <jkosina@suse.cz>,
	virtualization@lists.linux-foundation.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] virtio_balloon: Convert "vballoon" kthread into a workqueue
Date: Thu, 20 Nov 2014 19:00:16 +0200	[thread overview]
Message-ID: <20141120170016.GC7495@redhat.com> (raw)
In-Reply-To: <20141120165558.GB19165@pathway.suse.cz>

On Thu, Nov 20, 2014 at 05:55:58PM +0100, Petr Mladek wrote:
> On Thu 2014-11-20 11:29:35, Tejun Heo wrote:
> > On Thu, Nov 20, 2014 at 06:26:24PM +0200, Michael S. Tsirkin wrote:
> > > On Thu, Nov 20, 2014 at 06:25:43PM +0200, Michael S. Tsirkin wrote:
> > > > On Thu, Nov 20, 2014 at 11:07:46AM -0500, Tejun Heo wrote:
> > > > > On Thu, Nov 20, 2014 at 05:03:17PM +0100, Petr Mladek wrote:
> > > > > ...
> > > > > > @@ -476,7 +460,6 @@ static void virtballoon_remove(struct virtio_device *vdev)
> > > > > >  {
> > > > > >  	struct virtio_balloon *vb = vdev->priv;
> > > > > >  
> > > > > > -	kthread_stop(vb->thread);
> > > > > >  	remove_common(vb);
> > > > > >  	kfree(vb);
> > > > > >  }
> > > > > 
> > > > > Shouldn't the work item be flushed before removal is complete?
> 
> Great catch!
> 
> > > > In fact, flushing it won't help because it can requeue itself, right?
> > 
> > There's cancel_work_sync() to stop the self-requeueing ones.
> 
> Ah, one more problem is that remove_common(vb) calls leak_balloon()
> that queues the work if not finished. We would need to add some flag
> or variant that would disable the queuing when called here.
> 

That's why Tejun suggested cancel_work_sync, IIUC it stops
the requeuing without need for extra flags.

> > > From that POV a dedicated WQ kept it simple.
> > 
> > A dedicated wq doesn't do anything for that.  You can't shut down a
> > workqueue with a pending work item on it.  destroy_workqueue() will
> > try to drain the target wq, warn if it doesn't finish in certain
> > number of iterations and just keep trying indefinitely.
> 
> I wonder if it is guaranteed that none would trigger
> stats_request() or virtballoon_changed() when virtballoon_remove() is
> being called. I guess so because the original code would fail
> otherwise. The two functions access "vb->config_change"
> and the structure is freed in virtballoon_remove() without
> any protection.
> 
> I am trying to confirm this by reading the code but it is not that
> easy.
> 
> Best Regards,
> Petr

It's synchronized through hardware.  remove_common calls reset and
del_vqs which will prevent new interrupts.

-- 
MST

  reply	other threads:[~2014-11-20 17:00 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-20 16:03 [PATCH v3] virtio_balloon: Convert "vballoon" kthread into a workqueue Petr Mladek
2014-11-20 16:03 ` Petr Mladek
2014-11-20 16:07 ` Tejun Heo
2014-11-20 16:07   ` Tejun Heo
2014-11-20 16:25   ` Michael S. Tsirkin
2014-11-20 16:25     ` Michael S. Tsirkin
2014-11-20 16:26     ` Michael S. Tsirkin
2014-11-20 16:26       ` Michael S. Tsirkin
2014-11-20 16:29       ` Tejun Heo
2014-11-20 16:29         ` Tejun Heo
2014-11-20 16:47         ` Michael S. Tsirkin
2014-11-20 16:47           ` Michael S. Tsirkin
2014-11-20 16:49           ` Tejun Heo
2014-11-20 16:49             ` Tejun Heo
2014-11-20 16:50             ` Tejun Heo
2014-11-20 16:50               ` Tejun Heo
2014-11-20 16:55             ` Michael S. Tsirkin
2014-11-20 16:55               ` Michael S. Tsirkin
2014-11-20 16:55         ` Petr Mladek
2014-11-20 16:55           ` Petr Mladek
2014-11-20 17:00           ` Michael S. Tsirkin [this message]
2014-11-20 17:00             ` Michael S. Tsirkin
2014-11-20 17:17             ` Petr Mladek
2014-11-20 17:17               ` Petr Mladek

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=20141120170016.GC7495@redhat.com \
    --to=mst@redhat.com \
    --cc=jepler@unpythonic.net \
    --cc=jkosina@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmladek@suse.cz \
    --cc=tj@kernel.org \
    --cc=virtualization@lists.linux-foundation.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 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.