pci: handle zero size ROM files gracefully
cover pci: handle zero size ROM files gracefully
This is a fix for https://bugs.launchpad.net/qemu/+bug/1127053.
If pxe-e1000.rom has 0 size we allocate the same RAMBlock offset twice and fail with an assertion in qemu_ram_set_idstr() later on.
Two fixes:
1. Print an error when the ROM file has zero size. Use -device ...,romfile= instead to disable the ROM.
2. Add an assertion to find_ram_offset() so we watch this inconsistency if it ever happens again.
Stefan Hajnoczi (2):
pci: refuse empty ROM files
exec: assert that RAMBlock size is non-zero
exec.c | 2 ++ hw/pci/pci.c | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.1.4
PATCH 1/2 pci: refuse empty ROM files
A zero size ROM file is invalid and should produce a warning. Attempting to use a zero size file ends up hitting an assertion qemu_ram_set_idstr() because RAMBlocks with duplicate addresses are allocated - due to zero size the allocator doesn't increment the next available RAMBlock offset.
Also convert __FUNCTION__ to __func__ while we're touching this code. There are no other __FUNCTION__ instances in pci.c anymore.
--- hw/pci/pci.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
hw/pci/pci.c +6 -1
@@ -1852,7 +1852,12 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom) size =get_image_size (path);if (size <0 ) {error_report ("%s: failed to find romfile \"%s\"" , - __FUNCTION__, pdev->romfile); + __func__, pdev->romfile); +g_free (path); +return -1 ; + }else if (size ==0 ) { +error_report ("%s: ignoring empty romfile \"%s\"" , + __func__, pdev->romfile);g_free (path);return -1 ; }
Signature · 1 line
1.8.1.4
PATCH 2/2 exec: assert that RAMBlock size is non-zero
In reply to Stefan Hajnoczifind_ram_offset() does not handle size=0 gracefully. It hands out the same RAMBlock offset multiple times, leading to obscure failures later on.
Add an assert to warn early if something is incorrectly allocating a zero size RAMBlock.
--- exec.c | 2 ++ 1 file changed, 2 insertions(+)
exec.c +2 -0
@@ -912,6 +912,8 @@ static ram_addr_t find_ram_offset(ram_addr_t size)RAMBlock *block, *next_block;ram_addr_t offset =RAM_ADDR_MAX , mingap =RAM_ADDR_MAX ; +assert (size !=0 );/* it would hand out same offset multiple times */ +if (QTAILQ_EMPTY (&ram_list.blocks))return 0 ;
Signature · 1 line
1.8.1.4
Michael S. Tsirkin
AppliedQuoted 13 lines · Stefan Hajnoczi
This is a fix for https://bugs.launchpad.net/qemu/+bug/1127053.
If pxe-e1000.rom has 0 size we allocate the same RAMBlock offset twice and fail with an assertion in
qemu_ram_set_idstr()later on.Two fixes:
1. Print an error when the ROM file has zero size. Use -device ...,romfile= instead to disable the ROM.
2. Add an assertion to
find_ram_offset()so we watch this inconsistency if it ever happens again.
Quoted 7 lines
Stefan Hajnoczi (2):
pci: refuse empty ROM files
exec: assert that RAMBlock size is non-zeroexec.c | 2 ++ hw/pci/pci.c | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-)
Applied, thanks.
Quoted 2 lines
Signature · 1 line
1.8.1.4