From: Kevin Wolf <kwolf@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>,
Mark Kanda <mark.kanda@oracle.com>,
ameya.more@oracle.com, pbonzini@redhat.com,
qemu-devel@nongnu.org, qemu-block@nongnu.org
Subject: Re: [Qemu-devel] [Qemu-block] [PATCH] virtio-blk: check for NULL BlockDriverState
Date: Tue, 30 Jan 2018 16:56:12 +0100 [thread overview]
Message-ID: <20180130155612.GA4503@localhost.localdomain> (raw)
In-Reply-To: <20180130123823.GE15551@stefanha-x1.localdomain>
[-- Attachment #1: Type: text/plain, Size: 3182 bytes --]
Am 30.01.2018 um 13:38 hat Stefan Hajnoczi geschrieben:
> On Mon, Jan 29, 2018 at 04:41:07PM +0100, Kevin Wolf wrote:
> > Am 24.01.2018 um 12:31 hat Stefan Hajnoczi geschrieben:
> > > On Mon, Jan 22, 2018 at 09:01:49AM -0600, Mark Kanda wrote:
> > > > Add a BlockDriverState NULL check to virtio_blk_handle_request()
> > > > to prevent a segfault if the drive is forcibly removed using HMP
> > > > 'drive_del' (without performing a hotplug 'device_del' first).
> > > >
> > > > Signed-off-by: Mark Kanda <mark.kanda@oracle.com>
> > > > Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com>
> > > > Reviewed-by: Ameya More <ameya.more@oracle.com>
> > > > ---
> > > > hw/block/virtio-blk.c | 7 +++++++
> > > > 1 file changed, 7 insertions(+)
> > > >
> > > > diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
> > > > index b1532e4..76ddbbf 100644
> > > > --- a/hw/block/virtio-blk.c
> > > > +++ b/hw/block/virtio-blk.c
> > > > @@ -507,6 +507,13 @@ static int virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb)
> > > > return -1;
> > > > }
> > > >
> > > > + /* If the drive was forcibly removed (e.g. HMP 'drive_del'), the block
> > > > + * driver state may be NULL and there is nothing left to do. */
> > > > + if (!blk_bs(req->dev->blk)) {
> > >
> > > Adding Markus Armbruster to check my understanding of drive_del:
> > >
> > > 1. If id is a node name (e.g. created via blockdev-add) then attempting
> > > to remove the root node produces the "Node %s is in use" error. In
> > > that case this patch isn't needed.
> > >
> > > 2. If id is a BlockBackend (e.g. created via -drive) then removing the
> > > root node is allowed. The BlockBackend stays in place but blk->root
> > > becomes NULL, hence this patch is needed.
> > >
> > > Markus: What are the valid use cases for #2? If blk->bs becomes NULL I
> > > would think a lot more code beyond virtio-blk can segfault.
> >
> > blk->root = NULL is completely normal, it is what happens with removable
> > media when the drive is empty.
> >
> > The problem, which was first reported during the 2.10 RC phase and was
> > worked around in IDE code then, is that Paolo's commit 99723548561 added
> > unconditional bdrv_inc/dec_in_flight() calls. I am pretty sure that any
> > segfaults that Mark is seeing have the same cause.
> >
> > We do need an in-flight counter even for those requests so that
> > blk_drain() works correctly, so just making the calls condition wouldn't
> > be right. However, this needs to become a separate counter in
> > BlockBackend, and the drain functions must be changed to make use of it.
> >
> > I did post rough patches back then, but they weren't quite ready, and
> > since then they have fallen through the cracks.
>
> Will you send a new version of that patch series?
I would like to continue my work on the drain functions (which this
would be a part of) sooner or later, but the work to enable libvirt to
use blockdev-add is at a higher priority at the moment.
So if you can wait, I'll get to it eventually. If not, feel free to pick
up the patches.
Kevin
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]
next prev parent reply other threads:[~2018-01-30 15:56 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-22 15:01 [Qemu-devel] [PATCH] virtio-blk: check for NULL BlockDriverState Mark Kanda
2018-01-24 11:31 ` Stefan Hajnoczi
2018-01-29 15:41 ` [Qemu-devel] [Qemu-block] " Kevin Wolf
2018-01-29 16:13 ` Mark Kanda
2018-02-01 17:58 ` Stefan Hajnoczi
2018-01-30 12:38 ` Stefan Hajnoczi
2018-01-30 15:56 ` Kevin Wolf [this message]
2018-01-30 19:04 ` John Snow
2018-02-01 18:00 ` Stefan Hajnoczi
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=20180130155612.GA4503@localhost.localdomain \
--to=kwolf@redhat.com \
--cc=ameya.more@oracle.com \
--cc=armbru@redhat.com \
--cc=mark.kanda@oracle.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@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).