From: Paolo Bonzini <pbonzini@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>,
QEMU Developers <qemu-devel@nongnu.org>
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: Re: [Qemu-devel] qemu_chr_fe_add_watch interaction with VM start/stop/migrate
Date: Thu, 22 Jun 2017 12:31:11 +0200 [thread overview]
Message-ID: <d947c58b-d388-c432-0f40-b019af88c60a@redhat.com> (raw)
In-Reply-To: <CAFEAcA90vjbr=CM9i9m7-PdN0NB=MV8W0+wsG9UrNNR+KENsmA@mail.gmail.com>
On 22/06/2017 12:09, Peter Maydell wrote:
> For instance, suppose my UART tries to write to the chardev but
> can't, so it registers a callback with qemu_chr_fe_add_watch().
> Then the user stops the VM. Does the chardev UI guarantee that
> my callback won't get called until the user restarts the VM,
> or does my callback function have to do something to say "don't
> actually update the emulation state if we're stopped"?
> If the user then restarts the VM, do I need to do something to
> retry the chardev write?
Currently, chardev code runs normally between stop and start.
> For migration, if we're migrating in the state where I have a
> pending character I'd like to write to the chardev, what do I need
> to do on the destination side? Do I need to call qemu_chr_fe_add_watch
> in the post-load function, or is this too early and I need to do
> something to call it when the destination VM is actually restarted?
Post-load is fine. There could be interesting interactions with
interrupts, but these are not specific to character device backends
(real-time clocks are another example). So boards should create
interrupt controllers and distributors as soon as possible.
On the save side, when migration is about to finish, the mig thread
takes the I/O thread lock, so chardevs cannot run anymore at that point.
> More generally, am I guaranteed that my qemu_chr_fe_add_watch()
> callbacks are only called with the iothread mutex held (ie that
> I don't need to worry about races between device model functions
> called from the guest and the callbacks) ?
Yes. Chardev backends can be written to outside the iothread mutex, but
callbacks are always protected by the iothread mutex unless mentioned
specifically by the documentation and even then, only if you run in your
own IOThread.
> There are I think similar questions about the read handler and event
> handler functions that every UART model registers with the
> qemu_chr_fe_set_handlers function: are those only called when the
> VM is actually running, or is special casing required for "called
> when the VM is stopped?".
No special casing is currently done by the other backends. It seems to
work fine in practice...
> And one that I think is true but we don't document: is it the case
> that the chardev layer guarantees not to call the chardev's IOReadHandler
> unless its IOCanReadHandler has returned OK?
Yes, and no more bytes than the can_read handler has told him to return.
Paolo
> These all seem like things it would be nice to have documented in
> include/chardev/char-fe.h :-) What I would like the answer to be
> (as far as is possible) is "the chardev layer handles these issues
> so the frontends don't need to"...
next prev parent reply other threads:[~2017-06-22 10:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-22 10:09 [Qemu-devel] qemu_chr_fe_add_watch interaction with VM start/stop/migrate Peter Maydell
2017-06-22 10:31 ` Paolo Bonzini [this message]
2017-06-22 10:38 ` Peter Maydell
2017-06-22 10:43 ` Paolo Bonzini
2017-06-22 11:04 ` Dr. David Alan Gilbert
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=d947c58b-d388-c432-0f40-b019af88c60a@redhat.com \
--to=pbonzini@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).