qemu/include
David Hildenbrand 68318a7a90 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>
(cherry picked from commit b84f06c2be)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
(Mjt: context fix due to lack of
 v9.0.0-rc4-49-g15f7a80c49cb "RAMBlock: Add support of KVM private guest memfd")
2024-09-12 04:24:55 +03:00
..
authz
block nbd/server: CVE-2024-7409: Cap default max-connections to 100 2024-08-28 08:37:29 +03:00
chardev chardev: use bool for fe_is_open 2024-01-12 13:23:48 +00:00
crypto crypto: Modify the qcrypto_block_create to support creation flags 2024-02-09 12:50:37 +00:00
disas disas: introduce show_opcodes 2024-03-06 12:35:51 +00:00
exec softmmu/physmem: fix memory leak in dirty_memory_extend() 2024-09-12 04:24:55 +03:00
fpu fpu: Add conversions between bfloat16 and [u]int8 2023-09-16 14:57:15 +00:00
gdbstub gdbstub: Save target's siginfo 2024-03-13 11:43:52 +00:00
hw virtio-net: Fix network stall at the host side waiting for kick 2024-08-28 08:37:28 +03:00
io io: Introduce qio_channel_file_new_dupfd 2024-03-12 15:22:23 -04:00
libdecnumber
migration migration: purge MigrationState from public interface 2024-03-11 16:28:59 -04:00
monitor
net Revert "tap: setting error appropriately when calling net_init_tap_one()" 2024-03-29 14:59:07 +08:00
qapi error: Add error_vprepend() in comment of ERRP_GUARD() rules 2024-03-12 11:45:33 +01:00
qemu mirror: Don't call job_pause_point() under graph lock 2024-03-18 12:03:04 +01:00
qom include/qom/object.h: New OBJECT_DEFINE_SIMPLE_TYPE{, _WITH_INTERFACES} macros 2024-02-27 13:01:42 +00:00
scsi
semihosting * util/log: re-allow switching away from stderr log file 2023-10-09 10:11:18 -04:00
standard-headers Revert "hw/virtio: Add support for VDPA network simulation devices" 2024-04-09 02:30:18 -04:00
sysemu Revert "replay: stop us hanging in rr_wait_io_event" 2024-08-28 08:37:29 +03:00
tcg tcg: Add TCGContext.emit_before_op 2024-04-09 07:45:01 -10:00
ui ui/curses: Do not use console_select() 2024-03-20 10:27:58 +04:00
user {linux,bsd}-user: Introduce get_task_state() 2024-03-06 12:35:19 +00:00
elf.h
glib-compat.h
qemu-io.h
qemu-main.h