From 18b6e8931b3aebefbbccf545165ccc6fcdd09a1e Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 17 May 2019 06:51:10 +0200 Subject: [PATCH 43/53] sysbus: Fix latent bug with onboard devices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RH-Author: Markus Armbruster Message-id: <20190517065120.12028-22-armbru@redhat.com> Patchwork-id: 87995 O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH v3 21/31] sysbus: Fix latent bug with onboard devices Bugzilla: 1624009 RH-Acked-by: Philippe Mathieu-Daudé RH-Acked-by: Thomas Huth RH-Acked-by: Miroslav Rezanina The first call of sysbus_get_default() creates the main system bus and stores it in QOM as "/machine/unattached/sysbus". This must not happen before main() creates "/machine", or else container_get() would "helpfully" create it as "container" object, and the real creation of "/machine" would later abort with "attempt to add duplicate property 'machine' to object (type 'container')". Has been that way ever since we wired up busses in QOM (commit f968fc6892d, v1.2.0). I believe the bug is latent. I got it to bite by trying to qdev_create() a sysbus device from a machine's .instance_init() method. The fix is obvious: store the main system bus in QOM right after creating "/machine". Signed-off-by: Markus Armbruster Reviewed-by: Marc-André Lureau Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Thomas Huth Message-Id: <20190308131445.17502-5-armbru@redhat.com> Reviewed-by: Michael S. Tsirkin (cherry picked from commit e2fb3fbbf9ce6b8eed00b53a91d3a316362f1b0d) Signed-off-by: Miroslav Rezanina --- hw/core/sysbus.c | 3 --- vl.c | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c index 5d0887f..db95cb0 100644 --- a/hw/core/sysbus.c +++ b/hw/core/sysbus.c @@ -359,9 +359,6 @@ static void main_system_bus_create(void) qbus_create_inplace(main_system_bus, system_bus_info.instance_size, TYPE_SYSTEM_BUS, NULL, "main-system-bus"); OBJECT(main_system_bus)->free = g_free; - object_property_add_child(container_get(qdev_get_machine(), - "/unattached"), - "sysbus", OBJECT(main_system_bus), NULL); } BusState *sysbus_get_default(void) diff --git a/vl.c b/vl.c index d46dff6..d89ac3a 100644 --- a/vl.c +++ b/vl.c @@ -4162,6 +4162,10 @@ int main(int argc, char **argv, char **envp) } object_property_add_child(object_get_root(), "machine", OBJECT(current_machine), &error_abort); + object_property_add_child(container_get(OBJECT(current_machine), + "/unattached"), + "sysbus", OBJECT(sysbus_get_default()), + NULL); if (machine_class->minimum_page_bits) { if (!set_preferred_target_page_bits(machine_class->minimum_page_bits)) { -- 1.8.3.1