Received: from eggs.gnu.org ([209.51.188.92]:48011) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hBOtC-00082k-HZ for qemu-devel@nongnu.org; Tue, 02 Apr 2019 15:16:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hBOtB-0001ed-Mk for qemu-devel@nongnu.org; Tue, 02 Apr 2019 15:16:06 -0400 Date: Tue, 2 Apr 2019 16:16:02 -0300 From: Eduardo Habkost Message-ID: <20190402191602.GE22884@habkost.net> References: <1554194900-22817-1-git-send-email-like.xu@linux.intel.com> <871s2kejg1.fsf@dusky.pond.sub.org> <20190402174749.71da1efe@redhat.com> <871s2k8jxo.fsf@dusky.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [Qemu-devel] [PATCH v2] vl.c: make current_machine as non-global variable List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Markus Armbruster , Igor Mammedov , Like Xu , Thomas Huth , QEMU Trivial , QEMU Developers , Paolo Bonzini On Tue, Apr 02, 2019 at 11:23:42PM +0700, Peter Maydell wrote: > On Tue, 2 Apr 2019 at 23:13, Markus Armbruster wrote: > > > > Igor Mammedov writes: > > > maybe we can assert in qdev_get_machine() if machine hasn't been created yet? > > > with this at least it will be hard to misuse function or catch invalid users. > > > (but it still might miss some use cases/CLI options which are not tested) > > > > Good idea. When my code created "/machine" as a container, debugging > > the resulting crash took me a bit of time. The assertion you propose > > would've saved me some. > > One wrinkle to watch out for is code paths that are used in the > linux-user emulator, where there is no machine at all... For instance > cpu_common_realizefn() handles this case by explicitly checking > whether the thing it gets back from qdev_get_machine() is a > TYPE_MACHINE or not. Is there a real use case for calling qdev_get_machine() in user mode? I'd prefer to make qdev_get_machine() unavailable in user mode, so we could detect these cases at compile time (and treat them as bugs). -- Eduardo