Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 711F5CAC597 for ; Thu, 18 Sep 2025 20:04:09 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1126585.1468104 (Exim 4.92) (envelope-from ) id 1uzKrG-0002gC-Lr; Thu, 18 Sep 2025 20:03:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1126585.1468104; Thu, 18 Sep 2025 20:03:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uzKrG-0002g5-Hg; Thu, 18 Sep 2025 20:03:58 +0000 Received: by outflank-mailman (input) for mailman id 1126585; Thu, 18 Sep 2025 20:03:57 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uzKrF-0002fu-Il for xen-devel@lists.xenproject.org; Thu, 18 Sep 2025 20:03:57 +0000 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 9b815562-94ca-11f0-9d14-b5c5bf9af7f9; Thu, 18 Sep 2025 22:03:57 +0200 (CEST) Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-379-4FgNIfiwPGqI7IfuebIWrg-1; Thu, 18 Sep 2025 16:03:54 -0400 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-4b60dd9634dso28278751cf.2 for ; Thu, 18 Sep 2025 13:03:54 -0700 (PDT) Received: from x1.local (bras-base-aurron9134w-grc-11-174-89-135-121.dsl.bell.ca. [174.89.135.121]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4bda15f91a0sm19307741cf.1.2025.09.18.13.03.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Sep 2025 13:03:52 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9b815562-94ca-11f0-9d14-b5c5bf9af7f9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758225836; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LgVRs4qDWWl/SassPeYOJGunpCbcT4oPhyAu1oaWNOQ=; b=S7Ki0vBOvTkGsDnbAugmyhW83aFqvZGqXhokZtk3aQrUJoHeQUqU2emEfsUZxamDcOt7Wl 1phEZkaA+7AFuYsF20h6aEH3LBpVMtsVU1nLoSykrBjWfW8VWn59fYevUHxkQnT/GjQ9iL dIb5wk+wYHOMsIV4SsY5Lh08uHe1yDY= X-MC-Unique: 4FgNIfiwPGqI7IfuebIWrg-1 X-Mimecast-MFC-AGG-ID: 4FgNIfiwPGqI7IfuebIWrg_1758225834 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758225834; x=1758830634; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=LgVRs4qDWWl/SassPeYOJGunpCbcT4oPhyAu1oaWNOQ=; b=Zl4Wn99oGVdrl0ETQTPhTU8H/a1nYcOfUw9S/VvOd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0:4b7:a98b:8933 with SMTP id d75a77b69052e-4c072d2d400mr6025911cf.62.1758225833754; Thu, 18 Sep 2025 13:03:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEB62ZbYxbCV9ZW2QX6E1EIwlRMLvImUy5ZMYB2/qRwmfyMDoEyMnXIs2TXp5P2RdybchVl+g== X-Received: by 2002:a05:622a:5a88:b0:4b7:a98b:8933 with SMTP id d75a77b69052e-4c072d2d400mr6025121cf.62.1758225833133; Thu, 18 Sep 2025 13:03:53 -0700 (PDT) Date: Thu, 18 Sep 2025 16:03:49 -0400 From: Peter Xu To: Akihiko Odaki Cc: qemu-devel@nongnu.org, Alex Williamson , =?utf-8?Q?C=C3=A9dric?= Le Goater , Paolo Bonzini , Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= , Eduardo Habkost , David Hildenbrand , Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= , Richard Henderson , Helge Deller , =?utf-8?Q?Marc-Andr=C3=A9?= Lureau , "Michael S. Tsirkin" , Gerd Hoffmann , John Snow , qemu-block@nongnu.org, Keith Busch , Klaus Jensen , Jesper Devantier , Marcel Apfelbaum , Nicholas Piggin , qemu-ppc@nongnu.org, John Levon , Thanos Makatos , Yanan Wang , BALATON Zoltan , Jiaxun Yang , Daniel Henrique Barboza , David Gibson , Harsh Prateek Bora , Alexey Kardashevskiy , Alex =?utf-8?Q?Benn=C3=A9e?= , Fabiano Rosas , Thomas Huth , Laurent Vivier , Peter Maydell , Aurelien Jarno , Aleksandar Rikalo , Max Filippov , =?utf-8?B?SGVydsOp?= Poussineau , Mark Cave-Ayland , Artyom Tarasenko , Alistair Francis , "Maciej S. Szmigiero" , Bin Meng , Stefano Stabellini , Anthony PERARD , Paul Durrant , "Edgar E. Iglesias" , xen-devel@lists.xenproject.org Subject: Re: [PATCH v3 1/7] docs/devel: Do not unparent in instance_finalize() Message-ID: References: <20250917-use-v3-0-72c2a6887c6c@rsg.ci.i.u-tokyo.ac.jp> <20250917-use-v3-1-72c2a6887c6c@rsg.ci.i.u-tokyo.ac.jp> MIME-Version: 1.0 In-Reply-To: <20250917-use-v3-1-72c2a6887c6c@rsg.ci.i.u-tokyo.ac.jp> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: DP4OJgtEntgX6uPWD2zYiopcK8FreBLhMwm9YZLDtfI_1758225834 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline On Wed, Sep 17, 2025 at 07:13:26PM +0900, Akihiko Odaki wrote: > Children are automatically unparented so manually unparenting is > unnecessary. > > Worse, automatic unparenting happens before the instance_finalize() > callback of the parent gets called, so object_unparent() calls in > the callback will refer to objects that are already unparented, which > is semantically incorrect. > > Remove the instruction to call object_unparent(), and the exception > of the "do not call object_unparent()" rule for instance_finalize(). > > Signed-off-by: Akihiko Odaki > --- > docs/devel/memory.rst | 19 ++++++------------- > 1 file changed, 6 insertions(+), 13 deletions(-) > > diff --git a/docs/devel/memory.rst b/docs/devel/memory.rst > index 57fb2aec76e0..749f11d8a4dd 100644 > --- a/docs/devel/memory.rst > +++ b/docs/devel/memory.rst > @@ -161,18 +161,11 @@ or never. > Destruction of a memory region happens automatically when the owner > object dies. > > -If however the memory region is part of a dynamically allocated data > -structure, you should call object_unparent() to destroy the memory region > -before the data structure is freed. For an example see VFIOMSIXInfo > -and VFIOQuirk in hw/vfio/pci.c. Should we still keep some of these examples? After the series they'll be doing the right things. Dynamic MRs are still slightly tricky, I think it's still good to have some references. > - > You must not destroy a memory region as long as it may be in use by a > device or CPU. In order to do this, as a general rule do not create or > -destroy memory regions dynamically during a device's lifetime, and only > -call object_unparent() in the memory region owner's instance_finalize > -callback. The dynamically allocated data structure that contains the > -memory region then should obviously be freed in the instance_finalize > -callback as well. > +destroy memory regions dynamically during a device's lifetime. > +The dynamically allocated data structure that contains the > +memory region should be freed in the instance_finalize callback. > > If you break this rule, the following situation can happen: > > @@ -198,9 +191,9 @@ this exception is rarely necessary, and therefore it is discouraged, > but nevertheless it is used in a few places. > > For regions that "have no owner" (NULL is passed at creation time), the > -machine object is actually used as the owner. Since instance_finalize is > -never called for the machine object, you must never call object_unparent > -on regions that have no owner, unless they are aliases or containers. > +machine object is actually used as the owner. You must never call > +object_unparent on regions that have no owner, unless they are aliases > +or containers. This looks like a completely separate change. So we start to allow machines to be finalized now? I'm not familiar with machine object lifecycles. Maybe split it out even if it's true? -- Peter Xu