qemu/include
David Hildenbrand 21ce2fb8f3 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 09:20:33 +03:00
..
authz
block nbd/server: CVE-2024-7409: Cap default max-connections to 100 2024-08-11 11:00:05 +03:00
chardev
crypto crypto: Support export akcipher to pkcs8 2022-11-02 06:56:32 -04:00
disas
exec softmmu/physmem: fix memory leak in dirty_memory_extend() 2024-09-12 09:20:33 +03:00
fpu
hw virtio-net: Fix network stall at the host side waiting for kick 2024-08-06 17:18:25 +03:00
io io: remove io watch if TLS channel is closed during handshake 2023-08-02 17:22:20 +03:00
libdecnumber
migration
monitor
net net: Update MemReentrancyGuard for NIC 2023-11-29 16:20:11 +03:00
qapi
qemu host-utils: Add muldiv64_round_up 2023-09-25 23:43:49 +03:00
qom
scsi
semihosting
standard-headers
sysemu kvm: Introduce kvm_arch_get_default_type hook 2023-09-11 10:53:50 +03:00
tcg
ui
user
elf.h
glib-compat.h
qemu-io.h
qemu-main.h