From: Markus Armbruster <armbru@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "Akihiko Odaki" <odaki@rsg.ci.i.u-tokyo.ac.jp>,
qemu-devel@nongnu.org, "BALATON Zoltan" <balaton@eik.bme.hu>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Eduardo Habkost" <eduardo@habkost.net>
Subject: Re: [PATCH v2] qdev: Clarify instantiation and realization
Date: Mon, 13 Jul 2026 17:05:23 +0200 [thread overview]
Message-ID: <87ik6jdj64.fsf@pond.sub.org> (raw)
In-Reply-To: <CAFEAcA-rv3ZCBjUc3Z42NkQFV1wHWrxocCeCNAd1Eov7HUxrYg@mail.gmail.com> (Peter Maydell's message of "Mon, 13 Jul 2026 14:58:34 +0100")
Peter Maydell <peter.maydell@linaro.org> writes:
> On Mon, 13 Jul 2026 at 14:20, Markus Armbruster <armbru@redhat.com> wrote:
>>
>> Peter Maydell <peter.maydell@linaro.org> writes:
>> > OK. We could make the text clearer then, I think. Maybe
>> >
>> > "#TypeInfo.instance_init may not fail. #DeviceClass.realize can
>> > fail, returning error information to the caller. A device realize
>> > method should handle being called again after it has failed once."
>> >
>> > ?
>>
>> In general, a function should either do its job, or fail cleanly,
>> i.e. without side effects.
>>
>> For .realize() "without side effects" includes:
>>
>> * The failed call is invisible to the guest.
>>
>> * The device behaves as if the failed call never happened. This means
>> you can try .realize() again.
>>
>> Does the comment need to spell this out?
>
> If we want that, I think we should spell it out. I have generally
> assumed when writing realize functions that the semantics are
> "if this fails, the only thing the caller can usefully do with
> the object is destroy it". Realize code very very rarely attempts
> to cleanly unwind if it finds an error partway through. I would
> expect the only cases where it works at all are the ones where
> the only errors are "sanity check of property values etc" that
> happens up front.
>
> I would prefer it if we did not require this, because I think
> it imposes extra burden on implementations in order to provide
> something that is not of any benefit to anybody.
No objection, as long as the function contract is clear.
> Analogy: for unix sockets, you need to first open() and then
> connect(). The connect() manpage and the POSIX spec say that if
> connect() fails the only thing you can validly do with the socket
> is call close(): you're not allowed to keep it around and try
> connect() or some other operation on it.
>
> (We also undoubtedly have a lot of bugs where an error in realize
> leaves bits of the device visible to the emulation, or doesn't
> free things that were allocated, etc. But that's a separate and
> uncontroversial kind of bug. We don't notice these because for
> almost all devices the response to "realize failed" is that we're
> going to exit QEMU, because the device is part of the machine.)
Yes.
next prev parent reply other threads:[~2026-07-13 15:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-29 8:16 [PATCH v2] qdev: Clarify instantiation and realization Akihiko Odaki
2026-07-13 9:13 ` Peter Maydell
2026-07-13 11:20 ` Akihiko Odaki
2026-07-13 11:33 ` Peter Maydell
2026-07-13 12:39 ` Akihiko Odaki
2026-07-13 13:20 ` Markus Armbruster
2026-07-13 13:58 ` Peter Maydell
2026-07-13 15:05 ` Markus Armbruster [this message]
2026-07-13 22:29 ` Akihiko Odaki
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=87ik6jdj64.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=balaton@eik.bme.hu \
--cc=berrange@redhat.com \
--cc=eduardo@habkost.net \
--cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
--cc=pbonzini@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 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.