You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
4.2 KiB
106 lines
4.2 KiB
1 month ago
|
From e1f2265b5f6bf5b63bf3808bb540888f3cf8badb Mon Sep 17 00:00:00 2001
|
||
|
From: Bernhard Beschow <shentey@gmail.com>
|
||
|
Date: Wed, 8 May 2024 19:55:05 +0200
|
||
|
Subject: [PATCH 041/100] hw/i386/x86: Don't leak "pc.bios" memory region
|
||
|
MIME-Version: 1.0
|
||
|
Content-Type: text/plain; charset=UTF-8
|
||
|
Content-Transfer-Encoding: 8bit
|
||
|
|
||
|
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
|
||
|
RH-MergeRequest: 245: SEV-SNP support
|
||
|
RH-Jira: RHEL-39544
|
||
|
RH-Acked-by: Thomas Huth <thuth@redhat.com>
|
||
|
RH-Acked-by: Bandan Das <bdas@redhat.com>
|
||
|
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
|
||
|
RH-Commit: [41/91] a9cd61d8d240134c09c46e244efb89217cadf60c (bonzini/rhel-qemu-kvm)
|
||
|
|
||
|
Fix the leaking in x86_bios_rom_init() by adding a "bios" attribute to
|
||
|
X86MachineState. Note that it is only used in the -bios case.
|
||
|
|
||
|
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
|
||
|
Signed-off-by: Bernhard Beschow <shentey@gmail.com>
|
||
|
Message-ID: <20240508175507.22270-5-shentey@gmail.com>
|
||
|
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
|
||
|
(cherry picked from commit 865d95321ffc8d9941e33000b10140550f094556)
|
||
|
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
||
|
---
|
||
|
hw/i386/x86.c | 13 ++++++-------
|
||
|
include/hw/i386/x86.h | 6 ++++++
|
||
|
2 files changed, 12 insertions(+), 7 deletions(-)
|
||
|
|
||
|
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
|
||
|
index 457e8a34a5..29167de97d 100644
|
||
|
--- a/hw/i386/x86.c
|
||
|
+++ b/hw/i386/x86.c
|
||
|
@@ -1133,7 +1133,6 @@ void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware,
|
||
|
{
|
||
|
const char *bios_name;
|
||
|
char *filename;
|
||
|
- MemoryRegion *bios;
|
||
|
int bios_size, isa_bios_size;
|
||
|
ssize_t ret;
|
||
|
|
||
|
@@ -1149,8 +1148,8 @@ void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware,
|
||
|
(bios_size % 65536) != 0) {
|
||
|
goto bios_error;
|
||
|
}
|
||
|
- bios = g_malloc(sizeof(*bios));
|
||
|
- memory_region_init_ram(bios, NULL, "pc.bios", bios_size, &error_fatal);
|
||
|
+ memory_region_init_ram(&x86ms->bios, NULL, "pc.bios", bios_size,
|
||
|
+ &error_fatal);
|
||
|
if (sev_enabled()) {
|
||
|
/*
|
||
|
* The concept of a "reset" simply doesn't exist for
|
||
|
@@ -1159,11 +1158,11 @@ void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware,
|
||
|
* the firmware as rom to properly re-initialize on reset.
|
||
|
* Just go for a straight file load instead.
|
||
|
*/
|
||
|
- void *ptr = memory_region_get_ram_ptr(bios);
|
||
|
+ void *ptr = memory_region_get_ram_ptr(&x86ms->bios);
|
||
|
load_image_size(filename, ptr, bios_size);
|
||
|
x86_firmware_configure(ptr, bios_size);
|
||
|
} else {
|
||
|
- memory_region_set_readonly(bios, !isapc_ram_fw);
|
||
|
+ memory_region_set_readonly(&x86ms->bios, !isapc_ram_fw);
|
||
|
ret = rom_add_file_fixed(bios_name, (uint32_t)(-bios_size), -1);
|
||
|
if (ret != 0) {
|
||
|
goto bios_error;
|
||
|
@@ -1173,7 +1172,7 @@ void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware,
|
||
|
|
||
|
/* map the last 128KB of the BIOS in ISA space */
|
||
|
isa_bios_size = MIN(bios_size, 128 * KiB);
|
||
|
- memory_region_init_alias(&x86ms->isa_bios, NULL, "isa-bios", bios,
|
||
|
+ memory_region_init_alias(&x86ms->isa_bios, NULL, "isa-bios", &x86ms->bios,
|
||
|
bios_size - isa_bios_size, isa_bios_size);
|
||
|
memory_region_add_subregion_overlap(rom_memory,
|
||
|
0x100000 - isa_bios_size,
|
||
|
@@ -1184,7 +1183,7 @@ void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware,
|
||
|
/* map all the bios at the top of memory */
|
||
|
memory_region_add_subregion(rom_memory,
|
||
|
(uint32_t)(-bios_size),
|
||
|
- bios);
|
||
|
+ &x86ms->bios);
|
||
|
return;
|
||
|
|
||
|
bios_error:
|
||
|
diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h
|
||
|
index a07de79167..55c6809ae0 100644
|
||
|
--- a/include/hw/i386/x86.h
|
||
|
+++ b/include/hw/i386/x86.h
|
||
|
@@ -53,6 +53,12 @@ struct X86MachineState {
|
||
|
GMappedFile *initrd_mapped_file;
|
||
|
HotplugHandler *acpi_dev;
|
||
|
|
||
|
+ /*
|
||
|
+ * Map the whole BIOS just underneath the 4 GiB address boundary. Only used
|
||
|
+ * in the ROM (-bios) case.
|
||
|
+ */
|
||
|
+ MemoryRegion bios;
|
||
|
+
|
||
|
/*
|
||
|
* Map the upper 128 KiB of the BIOS just underneath the 1 MiB address
|
||
|
* boundary.
|
||
|
--
|
||
|
2.39.3
|
||
|
|