summary refs log tree commit diff stats
path: root/include/system/memory.h
diff options
context:
space:
mode:
authorPeter Xu <peterx@redhat.com>2025-09-29 15:42:27 +0100
committerPeter Xu <peterx@redhat.com>2025-10-03 09:48:02 -0400
commit041600e23f2fe2a9c252c9a8b26c7d147bedf982 (patch)
tree29c9f29a2ce3969e4021d8529a7057f36b2a9a48 /include/system/memory.h
parent9e7bfda4909cc688dd0327e17985019f08a78d5d (diff)
downloadfocaccia-qemu-041600e23f2fe2a9c252c9a8b26c7d147bedf982.tar.gz
focaccia-qemu-041600e23f2fe2a9c252c9a8b26c7d147bedf982.zip
memory: New AS helper to serialize destroy+free
If an AddressSpace has been created in its own allocated
memory, cleaning it up requires first destroying the AS
and then freeing the memory. Doing this doesn't work:

    address_space_destroy(as);
    g_free_rcu(as, rcu);

because both address_space_destroy() and g_free_rcu()
try to use the same 'rcu' node in the AddressSpace struct
and the address_space_destroy hook gets overwritten.

Provide a new address_space_destroy_free() function which
will destroy the AS and then free the memory it uses, all
in one RCU callback.

(CC to stable because the next commit needs this function.)

Cc: qemu-stable@nongnu.org
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: David Hildenbrand <david@redhat.com>
Link: https://lore.kernel.org/r/20250929144228.1994037-3-peter.maydell@linaro.org
Signed-off-by: Peter Xu <peterx@redhat.com>
Diffstat (limited to 'include/system/memory.h')
-rw-r--r--include/system/memory.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/system/memory.h b/include/system/memory.h
index 827e2c5aa4..08daf0fc59 100644
--- a/include/system/memory.h
+++ b/include/system/memory.h
@@ -2735,12 +2735,25 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name);
  * Note that destruction of the AddressSpace is done via RCU;
  * it is therefore not valid to free the memory the AddressSpace
  * struct is in until after that RCU callback has completed.
+ * If you want to g_free() the AddressSpace after destruction you
+ * can do that with address_space_destroy_free().
  *
  * @as: address space to be destroyed
  */
 void address_space_destroy(AddressSpace *as);
 
 /**
+ * address_space_destroy_free: destroy an address space and free it
+ *
+ * This does the same thing as address_space_destroy(), and then also
+ * frees (via g_free()) the AddressSpace itself once the destruction
+ * is complete.
+ *
+ * @as: address space to be destroyed
+ */
+void address_space_destroy_free(AddressSpace *as);
+
+/**
  * address_space_remove_listeners: unregister all listeners of an address space
  *
  * Removes all callbacks previously registered with memory_listener_register()