Received: from eggs.gnu.org ([2001:4830:134:3::10]:43532) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XkcNf-0000CD-5c for qemu-devel@nongnu.org; Sat, 01 Nov 2014 13:22:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XkcNX-0006PC-1w for qemu-devel@nongnu.org; Sat, 01 Nov 2014 13:22:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36640) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XkcNW-0006P4-Rm for qemu-devel@nongnu.org; Sat, 01 Nov 2014 13:22:19 -0400 Date: Sat, 1 Nov 2014 15:22:11 -0200 From: Eduardo Habkost Message-ID: <20141101172211.GF3298@thinpad.lan.raisama.net> References: <1414857371-12294-1-git-send-email-ehabkost@redhat.com> <1414857371-12294-4-git-send-email-ehabkost@redhat.com> <54550CF4.3050200@suse.de> <20141101164545.GD3298@thinpad.lan.raisama.net> <54550ED3.5090504@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <54550ED3.5090504@suse.de> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 3/3] qdev: Use qdev_device_add_get_class() for -device , help List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Andreas =?iso-8859-1?Q?F=E4rber?= Cc: Igor Mammedov , Gonglei , qemu-devel@nongnu.org, Stefan Hajnoczi , Paolo Bonzini On Sat, Nov 01, 2014 at 05:48:19PM +0100, Andreas F=E4rber wrote: > Am 01.11.2014 um 17:45 schrieb Eduardo Habkost: > > On Sat, Nov 01, 2014 at 05:40:20PM +0100, Andreas F=E4rber wrote: > >> Am 01.11.2014 um 16:56 schrieb Eduardo Habkost: > >>> Make sure we try to list properties from classes that can be safely= used with > >>> "-device". > >>> > >>> Fixes the following crashes: > >>> > >>> $ qemu-system-x86_64 -device x86_64-cpu,help > >>> ** > >>> ERROR:qom/object.c:336:object_initialize_with_type: assertion fai= led: (type->abstract =3D=3D false) > >>> Aborted (core dumped) > >>> $ qemu-system-x86_64 -device host-x86_64-cpu,help > >>> qemu-system-x86_64: [...]/target-i386/cpu.c:1329: host_x86_cpu_in= itfn: Assertion `(kvm_allowed)' failed. > >>> Aborted (core dumped) > >>> > >>> After applying this patch: > >>> > >>> $ qemu-system-x86_64 -device x86_64-cpu,help > >>> Parameter 'driver' expects non-abstract device type > >>> $ qemu-system-x86_64 -device host-x86_64-cpu,help > >>> Parameter 'driver' expects pluggable device type > >>> > >>> Signed-off-by: Eduardo Habkost > >>> --- > >>> qdev-monitor.c | 9 +++------ > >>> 1 file changed, 3 insertions(+), 6 deletions(-) > >>> > >>> diff --git a/qdev-monitor.c b/qdev-monitor.c > >>> index a9702d8..ebfa701 100644 > >>> --- a/qdev-monitor.c > >>> +++ b/qdev-monitor.c > >>> @@ -235,12 +235,9 @@ int qdev_device_help(QemuOpts *opts) > >>> return 0; > >>> } > >>> =20 > >>> - if (!object_class_by_name(driver)) { > >>> - const char *typename =3D find_typename_by_alias(driver); > >>> - > >>> - if (typename) { > >>> - driver =3D typename; > >>> - } > >>> + qdev_get_device_class(&driver, &local_err); > >>> + if (local_err) { > >>> + goto error; > >>> } > >>> =20 > >>> prop_list =3D qmp_device_list_properties(driver, &local_err); > >> > >> Is dc->cannot_instantiate_with_device_add_yet || (qdev_hotplug && > >> !dc->hotpluggable) really relevant here? Or should that rather remai= n > >> outside the common function in 1/3? > >=20 > > cannot_instantiate_with_device_add_yet makes sure we won't try to > > instantiate classes that are not device_add-safe yet (like X86CPU, th= at > > has lots of assumptions and side-effects inside instance_init()). >=20 > Maybe I'm misunderstanding? Does this code path apply only to device_ad= d > (then you are right) or does it also apply to -device? It applies to both -device and device_add, and both reject cannot_instantiate_with_device_add_yet classes. The question here is whether it is safe to blindly call object_new() on the class or not. I assume that a non-hotpluggable or cannot_instantiate_with_device_add_yet class indicates it is not safe to do that. I am being conservative because I don't know how many classes have side-effects on instance_init today. I believe the next steps could be: 1) Moving the dc->hotpluggable check to qdev_device_add(). Preferably after ensuring all (!hotpluggable && !cannot_instantiate_with_device_a= dd_yet) classes have no side-effects on instance_init. 2) Moving the cannot_instantiate_with_device_add_yet check to qdev_device_add(). Preferably after ensuring all classes have no side-effects on instance_init. Or we could just move directly to (1) or (2), and live with the possibility of having QEMU crashing or misbehaving when using "-device ...,help" or "device_add ...,help" with some class names. --=20 Eduardo