From: Eduardo Habkost <ehabkost@redhat.com>
To: Laszlo Ersek <lersek@redhat.com>
Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>,
peter.maydell@linaro.org, mst@redhat.com, somlo@cmu.edu,
qemu-devel@nongnu.org, rjones@redhat.com, pbonzini@redhat.com,
imammedo@redhat.com
Subject: Re: [Qemu-devel] [PATCHv6 3/5] fw_cfg: move assert() and linking of fw_cfg device to the machine into instance_init()
Date: Fri, 23 Jun 2017 13:10:43 -0300 [thread overview]
Message-ID: <20170623161043.GA10204@localhost.localdomain> (raw)
In-Reply-To: <a5f86c32-c89b-98ff-dbdb-7457a2074f1a@redhat.com>
On Fri, Jun 23, 2017 at 05:52:03PM +0200, Laszlo Ersek wrote:
> On 06/23/17 13:50, Eduardo Habkost wrote:
> > On Fri, Jun 23, 2017 at 09:12:01AM +0100, Mark Cave-Ayland wrote:
> >> On 21/06/17 14:23, Eduardo Habkost wrote:
> >>
> >>>>>>> I now have a v7 patchset ready to go (currently hosted at
> >>>>>>> https://github.com/mcayland/qemu/tree/fwcfg7 for the curious). Laszlo,
> >>>>>>> I've currently left off your Tested-by tag since I'm not sure it's still
> >>>>>>> valid for less-than-trivial changes - if you're happy for me to re-add
> >>>>>>> it before I send the v7 patchset to the list, please let me know.
> >>>>>>
> >>>>>> I intend to test v7 when you post it.
> >>>>>
> >>>>> I still see the instance_init assert() in that branch (commit
> >>>>> 17d75643f880). Is that correct?
> >>>>
> >>>> Yes that was the intention. In 17d75643f880 both the assert() and
> >>>> object_property_add_child() are moved into the instance_init() function,
> >>>> and then in the follow-up commit eddedb5 the assert() is removed from
> >>>> instance_init() and the object_resolve_path_type() check added into
> >>>> fw_cfg_init1() as part of its conversion into the
> >>>> fw_cfg_common_realize() function.
> >>>
> >>> We can't move assert() + linking to instance_init even if it's
> >>> just temporary, as it makes device-list-properties crash.
> >>>
> >>> Just linking in instance_init is also a problem, because
> >>> instance_init should never affect global QEMU state.
> >>>
> >>> You could move linking to realize as well, but: just like you
> >>> already moved sysbus_add_io() calls outside realize, I believe
> >>> linking belongs outside realize too. I need to re-read the
> >>> discussion threads to understand the motivation behind that.
> >>
> >> Ultimately the question we're trying to answer is "has someone
> >> instantiated another fw_cfg device for this machine?" and the way it
> >> works currently is that fw_cfg_init_io() and fw_cfg_init_mem() attach
> >> the fw_cfg device to the /machine object and then check after realize
> >> whether a /machine/fw_cfg device already exists, aborting if it does.
> >>
> >> So in the current implementation we're not actually concerned with the
> >> placement of fw_cfg within the model itself, and indeed with a fixed
> >> location in the QOM tree it's already completely wrong. If you take a
> >> look at the QOM tree for the sparc/sparc64/ppc machines you'll see that
> >> they really are very far from reality.
> >>
> >> For me the use of object_resolve_path_type() during realize is a good
> >> solution since regardless of the location of the fw_cfg we can always
> >> detect whether we have more than one device instance.
> >>
> >> However what seems unappealing about this is that while all existing
> >> users which use fw_cfg_init_io() and fw_cfg_init_mem() are fine, in the
> >> case where I am wiring up the device myself then for my sun4u example
> >> the code looks like this:
> >>
> >> dev = qdev_create(NULL, TYPE_FW_CFG_IO);
> >> ...
> >> qdev_init_nofail(dev);
> >> memory_region_add_subregion(pci_address_space_io(ebus), BIOS_CFG_IOPORT,
> >> &FW_CFG_IO(dev)->comb_iomem);
> >>
> >> Here you can see that the device is active because it is mapped into the
> >> correct IO address space, but notice I have forgotten to link it to the
> >> QOM /machine object myself. Hence I can instantiate and map as many
> >> instances as I like and never trigger the duplicate instance check which
> >> makes the check fairly ineffective.
> >
> > This is a good point, but I have a question about that: will something
> > break if a machine decides to create two fw_cfg objects and map them to
> > different addresses? If it won't break, I see no reason to try to
> > enforce a single instance in the device code. If it will break, then a
> > check in realize is still a hack, but might be a good enough solution.
> >
>
> (1) For the guest, it makes no sense to encounter two fw_cfg devices.
> Also, a lot of the existent code in QEMU assumes at most one fw_cfg
> device (for example, there is some related ACPI generation).
This is an argument for making board code ensure there's only one
device, and possibly for providing a helper that board code can use.
But it doesn't require validation on realize.
>
> (2) Relatedly, the fw_cfg_find() helper function is used quite widely,
> and it shouldn't break -- either due to more-than-one device instances,
> or due to the one fw_cfg device being linked under a path that is
> different from FW_CFG_PATH.
This is also an argument for providing a helper that ensures
fw_cfg_find() will work, but doesn't require validation on realize.
All that said, I don't have a strong argument against doing it on
realize, except my gut feeling that this is not how qdev was
designed[1]. If doing it on realize is the simplest way to do it, I
won't be the one complaining.
[1] I believe the original intent was to make every single device
user-creatable and define boards in a declarative way in config
files. We are very far from that goal.
--
Eduardo
next prev parent reply other threads:[~2017-06-23 16:11 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-19 12:59 [Qemu-devel] [PATCHv6 0/5] fw_cfg: qdev-related tidy-ups Mark Cave-Ayland
2017-06-19 12:59 ` [Qemu-devel] [PATCHv6 1/5] fw_cfg: don't map the fw_cfg IO ports in fw_cfg_io_realize() Mark Cave-Ayland
2017-06-19 14:10 ` Eduardo Habkost
2017-06-19 12:59 ` [Qemu-devel] [PATCHv6 2/5] fw_cfg: move setting of FW_CFG_VERSION_DMA bit to fw_cfg_init1() Mark Cave-Ayland
2017-06-19 14:11 ` Eduardo Habkost
2017-06-20 3:18 ` Philippe Mathieu-Daudé
2017-06-19 12:59 ` [Qemu-devel] [PATCHv6 3/5] fw_cfg: move assert() and linking of fw_cfg device to the machine into instance_init() Mark Cave-Ayland
2017-06-19 14:28 ` Eduardo Habkost
2017-06-19 14:56 ` Laszlo Ersek
2017-06-19 16:57 ` Mark Cave-Ayland
2017-06-19 17:09 ` Laszlo Ersek
2017-06-19 18:49 ` Mark Cave-Ayland
2017-06-19 22:43 ` Laszlo Ersek
2017-06-21 6:58 ` Mark Cave-Ayland
2017-06-21 7:48 ` Laszlo Ersek
2017-06-21 11:36 ` Eduardo Habkost
2017-06-21 12:17 ` Mark Cave-Ayland
2017-06-21 13:23 ` Eduardo Habkost
2017-06-23 8:12 ` Mark Cave-Ayland
2017-06-23 11:50 ` Eduardo Habkost
2017-06-23 15:52 ` Laszlo Ersek
2017-06-23 16:10 ` Eduardo Habkost [this message]
2017-06-23 16:48 ` Laszlo Ersek
2017-06-23 18:50 ` Eduardo Habkost
2017-06-25 18:58 ` Mark Cave-Ayland
2017-06-27 0:49 ` Eduardo Habkost
2017-06-28 7:09 ` Mark Cave-Ayland
2017-06-28 14:12 ` Igor Mammedov
2017-06-28 14:21 ` Laszlo Ersek
2017-06-28 15:31 ` Igor Mammedov
2017-06-29 12:12 ` Mark Cave-Ayland
2017-06-19 12:59 ` [Qemu-devel] [PATCHv6 4/5] fw_cfg: move qdev_init_nofail() from fw_cfg_init1() to callers Mark Cave-Ayland
2017-06-19 12:59 ` [Qemu-devel] [PATCHv6 5/5] fw_cfg: move QOM type defines and fw_cfg types into fw_cfg.h Mark Cave-Ayland
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=20170623161043.GA10204@localhost.localdomain \
--to=ehabkost@redhat.com \
--cc=imammedo@redhat.com \
--cc=lersek@redhat.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=rjones@redhat.com \
--cc=somlo@cmu.edu \
/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).