qemu/include/exec
David Hildenbrand b84f06c2be softmmu/physmem: fix memory leak in dirty_memory_extend()
As reported by Peter, we might be leaking memory when removing the
highest RAMBlock (in the weird ram_addr_t space), and adding a new one.

We will fail to realize that we already allocated bitmaps for more
dirty memory blocks, and effectively discard the pointers to them.

Fix it by getting rid of last_ram_page() and by remembering the number
of dirty memory blocks that have been allocated already.

While at it, let's use "unsigned int" for the number of blocks, which
should be sufficient until we reach ~32 exabytes.

Looks like this leak was introduced as we switched from using a single
bitmap_zero_extend() to allocating multiple bitmaps:
bitmap_zero_extend() relies on g_renew() which should have taken care of
this.

Resolves: https://lkml.kernel.org/r/CAFEAcA-k7a+VObGAfCFNygQNfCKL=AfX6A4kScq=VSSK0peqPg@mail.gmail.com
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Fixes: 5b82b703b6 ("memory: RCU ram_list.dirty_memory[] for safe RAM hotplug")
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Tested-by: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-stable@nongnu.org
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: David Hildenbrand <david@redhat.com>
Link: https://lore.kernel.org/r/20240828090743.128647-1-david@redhat.com
Signed-off-by: Peter Xu <peterx@redhat.com>
2024-09-09 10:55:39 -04:00
..
abi_ptr.h exec: Declare abi_ptr type in its own 'abi_ptr.h' header 2024-04-26 17:03:05 +02:00
address-spaces.h exec/address-spaces.h: Remove unuseful 'exec/memory.h' include 2023-08-31 19:47:43 +02:00
breakpoint.h exec: Declare CPUBreakpoint/CPUWatchpoint type in 'breakpoint.h' header 2024-04-26 17:03:05 +02:00
confidential-guest-support.h machine: allow early use of machine_require_guest_memfd 2024-06-05 11:01:06 +02:00
cpu_ldst.h accel/tcg: Move {set,clear}_helper_retaddr to cpu_ldst.h 2024-07-23 10:56:04 +10:00
cpu-all.h exec/cpu: Extract page-protection definitions to page-protection.h 2024-05-06 11:17:15 +02:00
cpu-common.h cpu-common.c: export cpu_get_free_index to be reused later 2024-07-26 09:21:06 +10:00
cpu-defs.h exec: Rename NEED_CPU_H -> COMPILING_PER_TARGET 2024-04-26 09:49:51 +02:00
cputlb.h exec: Restrict TCG specific declarations of 'cputlb.h' 2024-04-26 17:03:05 +02:00
exec-all.h accel: Restrict probe_access*() functions to TCG 2024-07-23 18:08:44 +02:00
gdbstub.h gdbstub: Add helper function to unregister GDB register space 2024-07-22 20:15:41 -04:00
helper-gen-common.h plugins: Remove plugin helpers 2024-04-30 16:12:05 -07:00
helper-gen.h tcg: Split helper-gen.h 2023-06-05 12:04:29 -07:00
helper-gen.h.inc tcg: Pass function pointer to tcg_gen_call* 2024-04-30 16:12:05 -07:00
helper-head.h.inc accel/tcg: Rename helper-head.h -> helper-head.h.inc 2024-04-26 15:31:37 +02:00
helper-info.c.inc accel/tcg: Rename helper-head.h -> helper-head.h.inc 2024-04-26 15:31:37 +02:00
helper-proto-common.h plugins: Remove plugin helpers 2024-04-30 16:12:05 -07:00
helper-proto.h tcg: Split helper-proto.h 2023-06-05 12:04:29 -07:00
helper-proto.h.inc accel/tcg: Rename helper-head.h -> helper-head.h.inc 2024-04-26 15:31:37 +02:00
hwaddr.h bulk: Rename TARGET_FMT_plx -> HWADDR_FMT_plx 2023-01-18 11:14:34 +01:00
ioport.h exec/ioport: Add portio_list_set_enabled() 2024-02-14 06:09:32 -05:00
log.h include/exec/log: Do not reference QemuLogFile directly 2022-04-20 10:51:11 -07:00
memattrs.h accel/tcg: Add tlb_fill_flags to CPUTLBEntryFull 2024-03-05 13:22:56 +00:00
memop.h exec: Make the MemOp enum cast explicit 2024-06-19 12:52:21 +02:00
memopidx.h Normalize header guard symbol definition 2022-05-11 16:50:26 +02:00
memory_ldst_cached.h.inc exec/memory_ldst_cached: Use correct type size 2021-05-26 08:35:51 -07:00
memory_ldst_phys.h.inc exec/memory_ldst_phys: Use correct type sizes 2021-05-26 08:35:51 -07:00
memory_ldst.h.inc bulk: Do not declare function prototypes using 'extern' keyword 2023-08-31 19:47:43 +02:00
memory-internal.h exec/memory: Expose memory_region_access_valid() 2023-01-09 13:50:13 +01:00
memory.h softmmu: Support concurrent bounce buffers 2024-09-09 10:55:39 -04:00
mmu-access-type.h exec: Declare MMUAccessType type in 'mmu-access-type.h' header 2024-04-26 17:03:05 +02:00
page-protection.h exec/cpu: Extract page-protection definitions to page-protection.h 2024-05-06 11:17:15 +02:00
page-vary.h bulk: Do not declare function prototypes using 'extern' keyword 2023-08-31 19:47:43 +02:00
plugin-gen.h plugins: Read mem_only directly from TB cflags 2024-05-15 08:55:18 +02:00
poison.h target/nios2: Remove the deprecated Nios II target 2024-04-24 16:03:38 +02:00
ram_addr.h exec/cpu-all: Reduce 'qemu/rcu.h' header inclusion 2024-04-26 17:03:05 +02:00
ramblock.h Migration pull for 9.1 2024-04-23 21:32:22 -07:00
ramlist.h softmmu/physmem: fix memory leak in dirty_memory_extend() 2024-09-09 10:55:39 -04:00
replay-core.h replay: Extract core API to 'exec/replay-core.h' 2023-02-27 22:29:01 +01:00
target_long.h tcg: Define MO_TL 2023-10-22 16:34:21 -07:00
target_page.h softmmu: Introduce qemu_target_page_mask() helper 2023-06-23 02:54:44 -04:00
tb-flush.h accel/tcg: Declare tcg_flush_jmp_cache() in 'exec/tb-flush.h' 2023-11-07 12:13:27 +01:00
tlb-common.h tcg: Add tlb_fast_offset to TCGContext 2023-06-05 12:04:28 -07:00
translate-all.h accel/tcg: Remove tb_invalidate_phys_page() from system emulation 2024-01-19 12:28:59 +01:00
translation-block.h accel/tcg: Introduce CF_BP_PAGE 2024-05-06 12:55:51 -07:00
translator.h accel/tcg: Introduce translator_fake_ld 2024-05-15 08:55:19 +02:00
tswap.h exec: Declare target_words_bigendian() in 'exec/tswap.h' 2024-04-26 17:03:05 +02:00
vaddr.h include/exec: Move vaddr defines to separate file 2024-01-29 07:06:03 +10:00