aboutsummaryrefslogtreecommitdiff
path: root/hw/xen
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2021-02-03 14:18:28 +0100
committerMichael S. Tsirkin <mst@redhat.com>2021-02-05 08:52:58 -0500
commit08b1df8ff463e72b0875538fb991d5393047606c (patch)
treec9f9b9a66917481bd350eaa346bb51d29d252920 /hw/xen
parent7c16b5bbb6c0f797945327d17e4be60f25a4427d (diff)
pci: add romsize property
This property can be useful for distros to set up known-good ROM sizes for migration purposes. The VM will fail to start if the ROM is too large, and migration compatibility will not be broken if the ROM is too small. Note that even though romsize is a uint32_t, it has to be between 1 (because empty ROM files are not accepted, and romsize must be greater than the file) and 2^31 (because values above are not powers of two and are rejected). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Reviewed-by: Peter Xu <peterx@redhat.com> Message-Id: <20201218182736.1634344-1-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <20210203131828.156467-3-pbonzini@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: David Edmondson <david.edmondson@oracle.com> Acked-by: Laszlo Ersek <lersek@redhat.com>
Diffstat (limited to 'hw/xen')
-rw-r--r--hw/xen/xen_pt_load_rom.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/hw/xen/xen_pt_load_rom.c b/hw/xen/xen_pt_load_rom.c
index a50a80837e..03422a8a71 100644
--- a/hw/xen/xen_pt_load_rom.c
+++ b/hw/xen/xen_pt_load_rom.c
@@ -53,10 +53,20 @@ void *pci_assign_dev_load_option_rom(PCIDevice *dev,
}
fseek(fp, 0, SEEK_SET);
+ if (dev->romsize != -1) {
+ if (st.st_size > dev->romsize) {
+ error_report("ROM BAR \"%s\" (%ld bytes) is too large for ROM size %u",
+ rom_file, (long) st.st_size, dev->romsize);
+ goto close_rom;
+ }
+ } else {
+ dev->romsize = st.st_size;
+ }
+
snprintf(name, sizeof(name), "%s.rom", object_get_typename(owner));
- memory_region_init_ram(&dev->rom, owner, name, st.st_size, &error_abort);
+ memory_region_init_ram(&dev->rom, owner, name, dev->romsize, &error_abort);
ptr = memory_region_get_ram_ptr(&dev->rom);
- memset(ptr, 0xff, st.st_size);
+ memset(ptr, 0xff, dev->romsize);
if (!fread(ptr, 1, st.st_size, fp)) {
error_report("pci-assign: Cannot read from host %s", rom_file);