9ae3a8
From 5f8e45393355671d8793e4bb37c07c95c609fdcd Mon Sep 17 00:00:00 2001
9ae3a8
From: Michael S. Tsirkin <mst@redhat.com>
9ae3a8
Date: Sun, 9 Mar 2014 18:48:58 +0100
9ae3a8
Subject: [PATCH 10/16] pc: avoid duplicate names for ROM MRs
9ae3a8
9ae3a8
RH-Author: Michael S. Tsirkin <mst@redhat.com>
9ae3a8
Message-id: <1394390868-24135-2-git-send-email-mst@redhat.com>
9ae3a8
Patchwork-id: 58054
9ae3a8
O-Subject: [PATCH qemu-kvm RHEL7.0 v3 2/2] pc: avoid duplicate names for ROM MRs
9ae3a8
Bugzilla: 1064018
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
RH-Acked-by: Marcel Apfelbaum <marcel.a@redhat.com>
9ae3a8
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
9ae3a8
9ae3a8
Since
9ae3a8
commit 04920fc0faa4760f9c4fc0e73b992b768099be70
9ae3a8
    loader: store FW CFG ROM files in RAM
9ae3a8
RAM MRs including ROM files in FW CFGs are created
9ae3a8
and named using the file basename.
9ae3a8
9ae3a8
This becomes problematic if these names are
9ae3a8
supplied by user, since the basename might not
9ae3a8
be unique.
9ae3a8
9ae3a8
There are two cases we care about:
9ae3a8
- option-rom flag.
9ae3a8
- option ROM for devices. This triggers e.g. when
9ae3a8
  using rombar=0.
9ae3a8
9ae3a8
At the moment we get an assert. E.g
9ae3a8
qemu -option-rom /usr/share/ipxe/8086100e.rom -option-rom
9ae3a8
/usr/share/ipxe.efi/8086100e.rom
9ae3a8
RAMBlock "/rom@genroms/8086100e.rom" already registered, abort!
9ae3a8
9ae3a8
This is a regression from 1.7.
9ae3a8
9ae3a8
For now let's keep it simple and just avoid creating the
9ae3a8
MRs in case of option ROMs.
9ae3a8
9ae3a8
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
9ae3a8
9ae3a8
Upstream: posted
9ae3a8
Brew build: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=7173355
9ae3a8
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1064018#c6
9ae3a8
Tested: by developer
9ae3a8
---
9ae3a8
 include/hw/loader.h |  6 ++++--
9ae3a8
 hw/core/loader.c    | 10 ++++++----
9ae3a8
 2 files changed, 10 insertions(+), 6 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 hw/core/loader.c    |   10 ++++++----
9ae3a8
 include/hw/loader.h |    6 ++++--
9ae3a8
 2 files changed, 10 insertions(+), 6 deletions(-)
9ae3a8
9ae3a8
diff --git a/hw/core/loader.c b/hw/core/loader.c
9ae3a8
index c363aef..9309b8c 100644
9ae3a8
--- a/hw/core/loader.c
9ae3a8
+++ b/hw/core/loader.c
9ae3a8
@@ -54,6 +54,7 @@
9ae3a8
 
9ae3a8
 #include <zlib.h>
9ae3a8
 
9ae3a8
+bool option_rom_has_mr = false;
9ae3a8
 bool rom_file_has_mr = true;
9ae3a8
 
9ae3a8
 static int roms_loaded;
9ae3a8
@@ -590,7 +591,8 @@ static void *rom_set_mr(Rom *rom, const char *name)
9ae3a8
 }
9ae3a8
 
9ae3a8
 int rom_add_file(const char *file, const char *fw_dir,
9ae3a8
-                 hwaddr addr, int32_t bootindex)
9ae3a8
+                 hwaddr addr, int32_t bootindex,
9ae3a8
+                 bool option_rom)
9ae3a8
 {
9ae3a8
     Rom *rom;
9ae3a8
     int rc, fd = -1;
9ae3a8
@@ -642,7 +644,7 @@ int rom_add_file(const char *file, const char *fw_dir,
9ae3a8
                  basename);
9ae3a8
         snprintf(devpath, sizeof(devpath), "/rom@%s", fw_file_name);
9ae3a8
 
9ae3a8
-        if (rom_file_has_mr) {
9ae3a8
+        if ((!option_rom || option_rom_has_mr) && rom_file_has_mr) {
9ae3a8
             data = rom_set_mr(rom, devpath);
9ae3a8
         } else {
9ae3a8
             data = rom->data;
9ae3a8
@@ -721,12 +723,12 @@ int rom_add_elf_program(const char *name, void *data, size_t datasize,
9ae3a8
 
9ae3a8
 int rom_add_vga(const char *file)
9ae3a8
 {
9ae3a8
-    return rom_add_file(file, "vgaroms", 0, -1);
9ae3a8
+    return rom_add_file(file, "vgaroms", 0, -1, true);
9ae3a8
 }
9ae3a8
 
9ae3a8
 int rom_add_option(const char *file, int32_t bootindex)
9ae3a8
 {
9ae3a8
-    return rom_add_file(file, "genroms", 0, bootindex);
9ae3a8
+    return rom_add_file(file, "genroms", 0, bootindex, true);
9ae3a8
 }
9ae3a8
 
9ae3a8
 static void rom_reset(void *unused)
9ae3a8
diff --git a/include/hw/loader.h b/include/hw/loader.h
9ae3a8
index 7ceccce..a5e02ce 100644
9ae3a8
--- a/include/hw/loader.h
9ae3a8
+++ b/include/hw/loader.h
9ae3a8
@@ -23,10 +23,12 @@ void pstrcpy_targphys(const char *name,
9ae3a8
                       hwaddr dest, int buf_size,
9ae3a8
                       const char *source);
9ae3a8
 
9ae3a8
+extern bool option_rom_has_mr;
9ae3a8
 extern bool rom_file_has_mr;
9ae3a8
 
9ae3a8
 int rom_add_file(const char *file, const char *fw_dir,
9ae3a8
-                 hwaddr addr, int32_t bootindex);
9ae3a8
+                 hwaddr addr, int32_t bootindex,
9ae3a8
+                 bool option_rom);
9ae3a8
 void *rom_add_blob(const char *name, const void *blob, size_t len,
9ae3a8
                    hwaddr addr, const char *fw_file_name,
9ae3a8
                    FWCfgReadCallback fw_callback, void *callback_opaque);
9ae3a8
@@ -40,7 +42,7 @@ void *rom_ptr(hwaddr addr);
9ae3a8
 void do_info_roms(Monitor *mon, const QDict *qdict);
9ae3a8
 
9ae3a8
 #define rom_add_file_fixed(_f, _a, _i)          \
9ae3a8
-    rom_add_file(_f, NULL, _a, _i)
9ae3a8
+    rom_add_file(_f, NULL, _a, _i, false)
9ae3a8
 #define rom_add_blob_fixed(_f, _b, _l, _a)      \
9ae3a8
     (rom_add_blob(_f, _b, _l, _a, NULL, NULL, NULL) ? 0 : -1)
9ae3a8
 
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8