qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Damien Hedde <damien.hedde@greensocs.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Eduardo Habkost <ehabkost@redhat.com>
Subject: Re: qom device lifecycle interaction with hotplug/hotunplug ?
Date: Thu, 28 Nov 2019 18:27:05 +0100	[thread overview]
Message-ID: <20191128182705.0635d1d4@redhat.com> (raw)
In-Reply-To: <CAFEAcA9E-Z-RPwFsAiz9Pi3_MtBUFEU7enJFVrpOQ7UKW8e1DQ@mail.gmail.com>

On Thu, 28 Nov 2019 16:00:06 +0000
Peter Maydell <peter.maydell@linaro.org> wrote:

> Hi; this is a question which came up in Damien's reset series
> which I don't know the answer to:
> 
> What is the interaction of the QOM device lifecycle (instance_init/realize/
> unrealize/instance_finalize) with hotplug and hot-unplug ? I couldn't
> find any documentation of this but maybe I was looking in the wrong
> place...
> 
> Looking at device_set_realized() it seems like we treat "realize"
> as meaning "and also do the hot-plug if this is a device we're
> trying to hotplug". On the other hand hot-unplug is I think the
> other way around: when we get a hot-unplug event we assume that
> it should also imply an "unrealize" (but just unrealizing doesn't
> auto-hot-unplug) ?

Let me try to describe it.

device 'hotplug' interface is poorly named nowadays as it's
just 'plug' interface which checks/wires device into existing machine.
'hotplug' attribute is just informs plug controller that it might
wish to take additional actions to complete device initialization
and notify guest.

plug workflow is as follow:

  DeviceState::realize()
     hotplug_ctrl = qdev_get_hotplug_handler(dev);
     hotplug_handler_pre_plug(hotplug_ctrl, dev) // check / prepare / reserve resources, can fail
     // call concrete device realize_fn()
     hotplug_handler_plug(hotplug_ctrl, dev) // wire device up to board/bus/notify guest, shouldn't fail

 * now old bus based qdev hotplug are tied to _plug callback that
   controller (hotplug_ctrl) that owns bus sets during bus creation.
   (Ideally we should split that on _pre_plug and _plug parts)
 * also any other QOM object could be controller, to allow buss-less
   hotplug (ex: arm-virt machine or pc/q35 machines)

Unplug is a different beast, it could be originated from mgmt side
device_del() and/or from guest side.

device_del() can go 2 ways: qdev_unplug()
 * devices that support surprise removal (i.e. does not require guest cooperation)
   go directly to
       hotplug_handler_unplug() // tear down device from machine
       object_unparent(); -> unrealize() + finalize() // device gone
   essentially it's old qdev code behavior as is.
      
 * async removal a bit different, instead of removal it asks
   controller to process unplug request hotplug_handler_unplug_request()
   and does nothing else.
   After guest is prepared to device removal it notifies QEMU in some way
   to eject device. That calls the same sequence
     hotplug_handler_unplug()
     object_unparent()

> Once a device is hot-unplugged (and thus unrealized) is it valid
> for it to be re-hot-plugged, or is the assumption that it's then
> destroyed and a fresh device is created if the user wants to plug
> something in again later ? Put another way, is it valid for a qdev
> device to see state transitions realize -> unrealize -> realize ?

I don't think we do it currently (or maybe we do with failover but
I missed that train), but I don't see why it can't be done.

I theory it's upto the place where actual eject request is originated from,
it could do unrealize -> realize instead of unparent as far as it calls
hotplug_handler_unplug().

> 
> thanks
> -- PMM
> 



  parent reply	other threads:[~2019-11-28 17:37 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-28 16:00 qom device lifecycle interaction with hotplug/hotunplug ? Peter Maydell
2019-11-28 16:33 ` Eduardo Habkost
2019-11-29 12:40   ` Igor Mammedov
2019-11-29 19:53     ` Eduardo Habkost
2019-11-28 17:27 ` Igor Mammedov [this message]
2019-11-28 17:57   ` Peter Maydell
2019-11-29 12:26     ` Igor Mammedov
2019-11-29 12:45       ` Peter Maydell
2019-11-29 13:05         ` Damien Hedde
2019-11-29 14:23           ` Igor Mammedov
2019-11-29 20:05         ` Eduardo Habkost
2019-11-30 11:10           ` Peter Maydell
2019-12-03 21:40             ` Eduardo Habkost
2019-12-04  9:18               ` Jens Freimann
2019-12-04 14:35                 ` Eduardo Habkost
2019-12-04 16:21                   ` Jens Freimann
2019-12-04 18:51                     ` Eduardo Habkost
2019-12-11 12:52                       ` Damien Hedde
2019-12-18 15:14                         ` Jens Freimann
2019-12-11 16:01                       ` Igor Mammedov

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=20191128182705.0635d1d4@redhat.com \
    --to=imammedo@redhat.com \
    --cc=damien.hedde@greensocs.com \
    --cc=ehabkost@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.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).