Skip to content

Commit

Permalink
pc: avoid duplicate names for ROM MRs
Browse files Browse the repository at this point in the history
Since
commit 04920fc
    loader: store FW CFG ROM files in RAM
RAM MRs including ROM files in FW CFGs are created
and named using the file basename.

This becomes problematic if these names are
supplied by user, since the basename might not
be unique.

There are two cases we care about:
- option-rom flag.
- option ROM for devices. This triggers e.g. when
  using rombar=0.

At the moment we get an assert. E.g
qemu -option-rom /usr/share/ipxe/8086100e.rom -option-rom
/usr/share/ipxe.efi/8086100e.rom
RAMBlock "/rom@genroms/8086100e.rom" already registered, abort!

This is a regression from 1.6.

For now let's keep it simple and just avoid creating the
MRs in case of option ROMs.

when using 1.7 machine types, enable
option ROMs in RAM to match that version.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
  • Loading branch information
mstsirkin committed Mar 11, 2014
1 parent 98bc3ab commit ac41881
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
10 changes: 6 additions & 4 deletions hw/core/loader.c
Expand Up @@ -54,6 +54,7 @@

#include <zlib.h>

bool option_rom_has_mr = false;
bool rom_file_has_mr = true;

static int roms_loaded;
Expand Down Expand Up @@ -642,7 +643,8 @@ static void *rom_set_mr(Rom *rom, Object *owner, const char *name)
}

int rom_add_file(const char *file, const char *fw_dir,
hwaddr addr, int32_t bootindex)
hwaddr addr, int32_t bootindex,
bool option_rom)
{
Rom *rom;
int rc, fd = -1;
Expand Down Expand Up @@ -694,7 +696,7 @@ int rom_add_file(const char *file, const char *fw_dir,
basename);
snprintf(devpath, sizeof(devpath), "/rom@%s", fw_file_name);

if (rom_file_has_mr) {
if ((!option_rom || option_rom_has_mr) && rom_file_has_mr) {
data = rom_set_mr(rom, OBJECT(fw_cfg), devpath);
} else {
data = rom->data;
Expand Down Expand Up @@ -773,12 +775,12 @@ int rom_add_elf_program(const char *name, void *data, size_t datasize,

int rom_add_vga(const char *file)
{
return rom_add_file(file, "vgaroms", 0, -1);
return rom_add_file(file, "vgaroms", 0, -1, true);
}

int rom_add_option(const char *file, int32_t bootindex)
{
return rom_add_file(file, "genroms", 0, bootindex);
return rom_add_file(file, "genroms", 0, bootindex, true);
}

static void rom_reset(void *unused)
Expand Down
1 change: 1 addition & 0 deletions hw/i386/pc_piix.c
Expand Up @@ -266,6 +266,7 @@ static void pc_compat_1_7(QEMUMachineInitArgs *args)
{
smbios_type1_defaults = false;
gigabyte_align = false;
option_rom_has_mr = true;
}

static void pc_compat_1_6(QEMUMachineInitArgs *args)
Expand Down
1 change: 1 addition & 0 deletions hw/i386/pc_q35.c
Expand Up @@ -244,6 +244,7 @@ static void pc_compat_1_7(QEMUMachineInitArgs *args)
{
smbios_type1_defaults = false;
gigabyte_align = false;
option_rom_has_mr = true;
}

static void pc_compat_1_6(QEMUMachineInitArgs *args)
Expand Down
6 changes: 4 additions & 2 deletions include/hw/loader.h
Expand Up @@ -49,10 +49,12 @@ void pstrcpy_targphys(const char *name,
hwaddr dest, int buf_size,
const char *source);

extern bool option_rom_has_mr;
extern bool rom_file_has_mr;

int rom_add_file(const char *file, const char *fw_dir,
hwaddr addr, int32_t bootindex);
hwaddr addr, int32_t bootindex,
bool option_rom);
void *rom_add_blob(const char *name, const void *blob, size_t len,
hwaddr addr, const char *fw_file_name,
FWCfgReadCallback fw_callback, void *callback_opaque);
Expand All @@ -66,7 +68,7 @@ void *rom_ptr(hwaddr addr);
void do_info_roms(Monitor *mon, const QDict *qdict);

#define rom_add_file_fixed(_f, _a, _i) \
rom_add_file(_f, NULL, _a, _i)
rom_add_file(_f, NULL, _a, _i, false)
#define rom_add_blob_fixed(_f, _b, _l, _a) \
rom_add_blob(_f, _b, _l, _a, NULL, NULL, NULL)

Expand Down

0 comments on commit ac41881

Please sign in to comment.