public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Stefan Hajnoczi <stefanha@gmail.com>
Cc: khoa@us.ibm.com, Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>,
	kvm@vger.kernel.org, virtualization@lists.linux-foundation.org
Subject: Re: [PATCH v3] virtio_blk: unlock vblk->lock during kick
Date: Fri, 8 Jun 2012 16:51:58 +0300	[thread overview]
Message-ID: <20120608135158.GA3925@redhat.com> (raw)
In-Reply-To: <CAJSP0QWkXeCQKOEMoV6XkNpwbnQczq9Smx85=Tg-73A9fmSyVQ@mail.gmail.com>

On Wed, Jun 06, 2012 at 04:25:55PM +0100, Stefan Hajnoczi wrote:
> On Mon, Jun 4, 2012 at 12:11 PM, Michael S. Tsirkin <mst@redhat.com> wrote:
> > On Fri, Jun 01, 2012 at 10:13:06AM +0100, Stefan Hajnoczi wrote:
> >> diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
> >> index 774c31d..d674977 100644
> >> --- a/drivers/block/virtio_blk.c
> >> +++ b/drivers/block/virtio_blk.c
> >> @@ -199,8 +199,14 @@ static void do_virtblk_request(struct request_queue *q)
> >>               issued++;
> >>       }
> >>
> >> -     if (issued)
> >> -             virtqueue_kick(vblk->vq);
> >> +     if (!issued)
> >> +             return;
> >> +
> >> +     if (virtqueue_kick_prepare(vblk->vq)) {
> >> +             spin_unlock_irq(vblk->disk->queue->queue_lock);
> >> +             virtqueue_notify(vblk->vq);
> >
> > If blk_done runs and completes the request at this point,
> > can hot unplug then remove the queue?
> > If yes will we get a use after free?
> 
> This is a difficult question, I haven't been able to decide one way or
> another.  The use-after-free is the
> spin_lock_irq(vblk->disk->queue->queue_lock).
> 
> It still doesn't explain why existing drivers are doing this.  In nbd,
> for example, I can't see anything preventing the same situation in
> drivers/block/nbd.c:do_nbd_request() between wake_up() and
> spin_lock_irq(q->queue_lock).  If the request completes (like in your
> example scenario) then the module remove code path has no way of
> knowing there is still a thread in do_nbd_request().
> 
> Any ideas?
> 
> Stefan

Try posting to a storage-related mailing list and/or lkml.

-- 
MST

  reply	other threads:[~2012-06-08 13:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-01  9:13 [PATCH v3] virtio_blk: unlock vblk->lock during kick Stefan Hajnoczi
2012-06-04  8:33 ` Asias He
2012-06-04 11:11 ` Michael S. Tsirkin
2012-06-06 15:25   ` Stefan Hajnoczi
2012-06-08 13:51     ` Michael S. Tsirkin [this message]
2012-06-04 11:15 ` Michael S. Tsirkin
2012-06-06  9:03   ` Stefan Hajnoczi
2012-06-04 21:13 ` Khoa Huynh

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=20120608135158.GA3925@redhat.com \
    --to=mst@redhat.com \
    --cc=khoa@us.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=stefanha@gmail.com \
    --cc=stefanha@linux.vnet.ibm.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox