Received: from eggs.gnu.org ([2001:4830:134:3::10]:49886) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aL6Nt-0001Jg-Dn for qemu-devel@nongnu.org; Mon, 18 Jan 2016 04:46:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aL6Nq-0001jB-7G for qemu-devel@nongnu.org; Mon, 18 Jan 2016 04:46:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50839) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aL6Nq-0001j1-0b for qemu-devel@nongnu.org; Mon, 18 Jan 2016 04:45:58 -0500 From: Markus Armbruster References: <1445253099-16894-1-git-send-email-pbonzini@redhat.com> <87ziytehr2.fsf@blackfin.pond.sub.org> <563B4629.10903@suse.de> <563B49C1.9080305@redhat.com> <87a8qswr33.fsf@blackfin.pond.sub.org> <5699266B.7080209@suse.de> <56992959.9070504@redhat.com> Date: Mon, 18 Jan 2016 10:45:54 +0100 In-Reply-To: <56992959.9070504@redhat.com> (Paolo Bonzini's message of "Fri, 15 Jan 2016 18:16:09 +0100") Message-ID: <87r3hfte3x.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] qdev: free qemu-opts when the QOM path goes away List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org, Andreas =?utf-8?Q?F=C3=A4rber?= , "Michael S. Tsirkin" Paolo Bonzini writes: > On 15/01/2016 18:03, Andreas F=C3=A4rber wrote: >> Am 05.11.2015 um 13:47 schrieb Markus Armbruster: >>> Paolo Bonzini writes: >>>> On 05/11/2015 13:06, Andreas F=C3=A4rber wrote: >>>>>> 1. Wouldn't it be cleaner to delete dev-opts *before* sending >>>>>> DEVICE_DELETED? Like this: >>>>>> >>>>>> +++ b/hw/core/qdev.c >>>>>> @@ -1244,6 +1244,9 @@ static void device_unparent(Object *obj) >>>>>> dev->parent_bus =3D NULL; >>>>>> } >>>>>> >>>>>> + qemu_opts_del(dev->opts); >>>>>> + dev->opts =3D NULL; >>>>>> + >>>>>> /* Only send event if the device had been completely realiz= ed */ >>>>>> if (dev->pending_deleted_event) { >>>>>> gchar *path =3D object_get_canonical_path(OBJECT(dev)); >>>>> >>>>> To me this proposal sounds sane, but I did not get to tracing the code >>>>> flow here. Paolo, which approach do you prefer and why? >>>> >>>> It doesn't really matter, because the BQL is being held here. >>>> >>>> On the other hand, if the opts are deleted in finalize, there is an >>>> arbitrary delay because finalize is typically called after a >>>> synchronize_rcu period. >>>> >>>>>>> 2. If the device is a block device, then unplugging it also deletes= its >>>>>>> backend (ugly wart we keep for backward compatibility; *not* for >>>>>>> blockdev-add, though). This backend also has a QemuOpts. It ge= ts >>>>>>> deleted in drive_info_del(). Just like device_finalize(), it ru= ns >>>>>>> within object_unref(), i.e. after DEVICE_DELETED is sent. Same = race, >>>>>>> different ID, or am I missing something? >>>>>>> >>>>>>> See also https://bugzilla.redhat.com/show_bug.cgi?id=3D1256044 >>>>> >>>>> If we can leave this patch decoupled from block layer and decide soon= ish >>>>> on the desired approach, I'd be happy to include it in my upcoming >>>>> qom-devices pull. >>>> >>>> I agree with you, the block layer bug is separate. >>> >>> Related, but clearly separate. Mentioning it in the commit message >>> would be nice, though. >>=20 >> Paolo, pong: I gathered that I should queue the original patch without >> Markus's proposed change, correct? And do you want to add some sentence >> to the commit message as requested by Markus? > > Yes, thanks: > > ---- > Note that similar races exist for other QemuOpts, which this patch > does not attempt to fix. > > For example, if the device is a block device, then unplugging it also > deletes its backend. However, this backend's get deleted in > drive_info_del(), which is only called when properties are > destroyed. Just like device_finalize(), drive_info_del() is called > some time after DEVICE_DELETED is sent. A separate patch series has > been sent to plug this other bug. Character devices also have yet to > be fixed. With this addition to the commit message: Reviewed-by: Markus Armbruster