All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: qemu-devel@nongnu.org, armbru@redhat.com,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: Re: [PATCH 13/41] RFC system/ioport: move embedded memory region cleanup to portio_list_destroy
Date: Wed, 29 Apr 2026 17:07:56 -0400	[thread overview]
Message-ID: <afJzLNnljU4hvZuu@x1.local> (raw)
In-Reply-To: <20260427-qom-tests-v1-13-c413f3605311@redhat.com>

On Mon, Apr 27, 2026 at 11:42:12PM +0400, Marc-André Lureau wrote:
> memory_region_portio_list_finalize() unconditionally calls
> object_unref() on the embedded MemoryRegion, but when the object was
> created via bare object_new() the MemoryRegion was never initialized
> and has a refcount of 0, triggering an assertion failure.
> 
> The unref in finalize drops the keep-alive reference added during the
> reparenting in portio_list_add_1(). Move it to portio_list_destroy()
> where the cleanup belongs, and assert the refcount is zero in
> finalize.
> 
> This is an alternative to "system/ioport: Fix qom-list-properties crash
> on portio list obj" patch, hence the RFC.
> 
> Fixes: 690705ca0b0f ("softmmu/ioport.c: make MemoryRegionPortioList owner of portio_list MemoryRegions")
> Cc: peterx@redhat.com
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  system/ioport.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/system/ioport.c b/system/ioport.c
> index 9209bff2eab..aa8f3229804 100644
> --- a/system/ioport.c
> +++ b/system/ioport.c
> @@ -145,6 +145,7 @@ void portio_list_destroy(PortioList *piolist)
>      for (i = 0; i < piolist->nr; ++i) {
>          mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
>          object_unparent(OBJECT(&mrpio->mr));
> +        object_unref(OBJECT(&mrpio->mr));
>          object_unref(mrpio);
>      }
>      g_free(piolist->regions);
> @@ -346,7 +347,8 @@ static void memory_region_portio_list_finalize(Object *obj)
>  {
>      MemoryRegionPortioList *mrpio = MEMORY_REGION_PORTIO_LIST(obj);
>  
> -    object_unref(&mrpio->mr);
> +    /* dropped by portio_list_destroy(), or never initialized */
> +    assert(!mrpio->mr.parent_obj.ref);

I'm not sure if it's worthwhile to just add such assert and violate the
layering here, by accessing mr's refcount. Shall we just drop this check?

OTOH, if we will move the unref to destroy, shall we move the ports below
over and just go ahead removing the whole finalize()?

>      g_free(mrpio->ports);
>  }
>  
> 
> -- 
> 2.53.0
> 

-- 
Peter Xu



  reply	other threads:[~2026-04-29 21:08 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-27 19:41 [PATCH 00/41] Fix various QOM object life-cycle issues Marc-André Lureau
2026-04-27 19:42 ` [PATCH 01/41] hw/pci: handle missing bus in prop_pci_busnr_get Marc-André Lureau
2026-04-27 19:42 ` [PATCH 02/41] chardev/char-socket: handle NULL addr in char_socket_get_addr Marc-André Lureau
2026-04-27 19:42 ` [PATCH 03/41] hw/pci-bridge: handle missing parent in prop_pxb_uid_get Marc-André Lureau
2026-04-27 19:42 ` [PATCH 04/41] hw/pci-host/i440fx: handle NULL bus in pci-hole64 getters Marc-André Lureau
2026-04-27 21:00   ` Philippe Mathieu-Daudé
2026-04-28  6:10     ` Marc-André Lureau
2026-04-28  6:14       ` Philippe Mathieu-Daudé
2026-04-27 19:42 ` [PATCH 05/41] hw/pci-host/q35: " Marc-André Lureau
2026-04-27 19:42 ` [PATCH 06/41] hw/remote: check visit return in vfu_object_set_socket Marc-André Lureau
2026-04-27 20:38   ` Jagannathan Raman
2026-04-27 19:42 ` [PATCH 07/41] qom: skip link property check callback when clearing link Marc-André Lureau
2026-04-30 15:48   ` Peter Maydell
2026-04-27 19:42 ` [PATCH 08/41] hw/intc/apic: guard against NULL cpu in set_id Marc-André Lureau
2026-04-27 20:40   ` Philippe Mathieu-Daudé
2026-05-03  8:19     ` marcandre.lureau
2026-04-27 19:42 ` [PATCH 09/41] RFC hw/remote: guard listener unregister in finalize Marc-André Lureau
2026-04-27 19:58   ` Jagannathan Raman
2026-04-28 10:17     ` Marc-André Lureau
2026-04-27 19:42 ` [PATCH 10/41] backends/cryptodev-lkcf: skip cleanup when not initialized Marc-André Lureau
2026-04-28  0:05   ` zhenwei pi
2026-04-27 19:42 ` [PATCH 11/41] RFC io/net-listener: move mutex init to instance_init Marc-André Lureau
2026-04-28  7:05   ` Daniel P. Berrangé
2026-04-29 21:08   ` Peter Xu
2026-04-27 19:42 ` [PATCH 12/41] RFC net/colo-compare: guard finalize against uninitialized state Marc-André Lureau
2026-04-29 20:58   ` Peter Xu
2026-04-29 21:09     ` Marc-André Lureau
2026-04-29 22:24       ` Peter Xu
2026-04-27 19:42 ` [PATCH 13/41] RFC system/ioport: move embedded memory region cleanup to portio_list_destroy Marc-André Lureau
2026-04-29 21:07   ` Peter Xu [this message]
2026-05-04  7:11     ` marcandre.lureau
2026-04-27 19:42 ` [PATCH 14/41] ui/console: remove console from global list on finalization Marc-André Lureau
2026-04-27 19:42 ` [PATCH 15/41] hw/i386/x86: free oem_id and oem_table_id " Marc-André Lureau
2026-04-27 20:41   ` Philippe Mathieu-Daudé
2026-04-27 19:42 ` [PATCH 16/41] hw/core/machine: free shim_filename " Marc-André Lureau
2026-04-27 19:42 ` [PATCH 17/41] hw/core/resetcontainer: free children array " Marc-André Lureau
2026-04-30 15:50   ` Peter Maydell
2026-04-27 19:42 ` [PATCH 18/41] net/filter: free old values in property setters Marc-André Lureau
2026-04-27 19:42 ` [PATCH 19/41] ui/console-vc: destroy fifo on text console finalization Marc-André Lureau
2026-04-27 19:42 ` [PATCH 20/41] target/i386/sev: add finalize functions and fix leaking setters Marc-André Lureau
2026-04-27 19:42 ` [PATCH 21/41] target/i386/kvm/tdx: free strings in tdx_guest_finalize Marc-André Lureau
2026-04-27 19:42 ` [PATCH 22/41] hw/i386/nitro_enclave: add instance finalize Marc-André Lureau
2026-04-27 19:42 ` [PATCH 23/41] net/can: free ifname on socketcan finalization Marc-André Lureau
2026-04-28  8:25   ` Pavel Pisa
2026-04-27 19:42 ` [PATCH 24/41] backends/igvm-cfg: free filename on finalization Marc-André Lureau
2026-04-28  6:55   ` Gerd Hoffmann
2026-04-27 19:42 ` [PATCH 25/41] scsi/pr-manager-helper: free path " Marc-André Lureau
2026-04-30 15:51   ` Peter Maydell
2026-04-27 19:42 ` [PATCH 26/41] accel/kvm: free device " Marc-André Lureau
2026-04-30 15:56   ` Peter Maydell
2026-04-27 19:42 ` [PATCH 27/41] system/qtest: free log " Marc-André Lureau
2026-04-30 16:01   ` Peter Maydell
2026-05-04  7:23     ` marcandre.lureau
2026-04-27 19:42 ` [PATCH 28/41] hw/i386/pc: free pcspk " Marc-André Lureau
2026-04-27 19:42 ` [PATCH 29/41] hw/fsi: move OPBus address space init to realize Marc-André Lureau
2026-04-30 16:09   ` Peter Maydell
2026-04-30 17:47     ` Cédric Le Goater
2026-04-27 19:42 ` [PATCH 30/41] hw/gpio/pca9552: fix state_str leak in pca955x_set_led Marc-André Lureau
2026-04-27 20:19   ` Miles Glenn
2026-04-27 20:46   ` Philippe Mathieu-Daudé
2026-04-27 19:42 ` [PATCH 31/41] hw/arm/aspeed: free fmc_model and spi_model on finalization Marc-André Lureau
2026-04-30 17:32   ` Cédric Le Goater
2026-04-27 19:42 ` [PATCH 32/41] hw/tpm: free PPI buffer " Marc-André Lureau
2026-04-27 20:29   ` Stefan Berger
2026-04-27 19:42 ` [PATCH 33/41] hw/arm/sbsa-ref: free unrealized flash devices " Marc-André Lureau
2026-04-27 20:49   ` Philippe Mathieu-Daudé
2026-04-27 19:42 ` [PATCH 34/41] hw/arm/virt: free flash devices and OEM strings " Marc-André Lureau
2026-04-27 20:50   ` Philippe Mathieu-Daudé
2026-04-30 15:12   ` Peter Maydell
2026-04-30 15:18     ` Philippe Mathieu-Daudé
2026-04-30 15:30       ` Peter Maydell
2026-05-11 13:01         ` Marc-André Lureau
2026-05-11 14:33           ` Peter Maydell
2026-04-27 19:42 ` [PATCH 35/41] hw/loongarch/virt: " Marc-André Lureau
2026-04-27 19:42 ` [PATCH 36/41] hw/ppc/spapr: free host_model and host_serial " Marc-André Lureau
2026-04-27 19:42 ` [PATCH 37/41] hw/ppc/pnv: drop extra ref on PHB after adding as child Marc-André Lureau
2026-04-27 20:20   ` Miles Glenn
2026-05-10  9:02   ` Aditya Gupta
2026-04-27 19:42 ` [PATCH 38/41] target/riscv: fix general_user_opts hash table leak Marc-André Lureau
2026-05-01  1:53   ` Alistair Francis
2026-05-04 10:29     ` marcandre.lureau
2026-05-05 15:43     ` Daniel Henrique Barboza
2026-04-27 19:42 ` [PATCH 39/41] hw/riscv/virt: free flash devices and OEM strings on finalization Marc-André Lureau
2026-04-27 20:51   ` Philippe Mathieu-Daudé
2026-04-28  2:19   ` Alistair Francis
2026-04-27 19:42 ` [PATCH 40/41] hw/i2c/pmbus: fix undefined behavior in pmbus_direct_mode2data Marc-André Lureau
2026-04-27 19:42 ` [PATCH 41/41] qtest: add "qom-tests" command Marc-André Lureau
2026-04-27 20:06   ` Peter Maydell
2026-04-28  6:37     ` Marc-André Lureau
2026-04-28  7:48       ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=afJzLNnljU4hvZuu@x1.local \
    --to=peterx@redhat.com \
    --cc=armbru@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.