From patchwork Mon May 31 08:26:07 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 54075 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 19716B7D5E for ; Mon, 31 May 2010 18:27:23 +1000 (EST) Received: from localhost ([127.0.0.1]:47349 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OJ0L9-0006jN-SN for incoming@patchwork.ozlabs.org; Mon, 31 May 2010 04:27:19 -0400 Received: from [140.186.70.92] (port=43208 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OJ0K9-0006iV-OW for qemu-devel@nongnu.org; Mon, 31 May 2010 04:26:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OJ0K8-0002GZ-BA for qemu-devel@nongnu.org; Mon, 31 May 2010 04:26:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60327) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OJ0K8-0002FY-56 for qemu-devel@nongnu.org; Mon, 31 May 2010 04:26:16 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4V8QAv8006962 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 31 May 2010 04:26:10 -0400 Received: from blackfin.pond.sub.org (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4V8Q81C009692; Mon, 31 May 2010 04:26:09 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 500) id CF6326E; Mon, 31 May 2010 10:26:07 +0200 (CEST) From: Markus Armbruster To: Avi Kivity Subject: Re: [Qemu-devel] [PATCH v3 04/17] qdev: Give qtree names precedence over user-assigned IDs References: <3715da16813f7cdcb7ec023167a84a94e8a37089.1274612367.git.jan.kiszka@web.de> <4C021ED5.1080703@redhat.com> Date: Mon, 31 May 2010 10:26:07 +0200 In-Reply-To: <4C021ED5.1080703@redhat.com> (Avi Kivity's message of "Sun, 30 May 2010 11:16:21 +0300") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Anthony Liguori , Juan Quintela , Jan Kiszka , qemu-devel@nongnu.org, Luiz Capitulino , Blue Swirl , Jan Kiszka , Gerd Hoffmann X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org [cc: kraxel] Avi Kivity writes: > On 05/29/2010 11:01 AM, Markus Armbruster wrote: >> Jan Kiszka writes: >> >> >>> From: Jan Kiszka >>> >>> As the user may specify ambiguous device IDs, let's search for their >>> official names first before considering the user-supplied identifiers. >>> >>> Signed-off-by: Jan Kiszka >>> >> The problem is letting the user specify ambiguous device IDs in the >> first place! That way is madness... >> > > Agreed, we're sowing the seeds for future problems. On closer look, we have some protection against duplicate IDs, but it got holes. We don't assign IDs to default devices. -device and device_add use the ID of a qemu_device_opts. Which rejects duplicate IDs. pci_add nic -net use either the ID or option "name" of qemu_net_opts. And there's our hole. Reproducible with "-net user -net nic,id=foo -device lsi,id=foo". We better check for duplicates right where we create qdevs. Gerd, what do you think about the appended patch? Acked-by: Gerd Hoffmann diff --git a/hw/qdev.c b/hw/qdev.c index b91bed1..beb4235 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -40,6 +40,7 @@ DeviceInfo *device_info_list; static BusState *qbus_find_recursive(BusState *bus, const char *name, const BusInfo *info); static BusState *qbus_find(const char *path); +static DeviceState *qdev_find_recursive(BusState *bus, const char *id); /* Register a new device type. */ void qdev_register(DeviceInfo *info) @@ -242,6 +243,10 @@ DeviceState *qdev_device_add(QemuOpts *opts) qdev = qdev_create_from_info(bus, info); id = qemu_opts_id(opts); if (id) { + if (qdev_find_recursive(main_system_bus, id)) { + qerror_report(QERR_DUPLICATE_ID, id, "device"); + return NULL; + } qdev->id = id; } if (qemu_opt_foreach(opts, set_property, qdev, 1) != 0) {