The host kernel filters the PCI option ROM, returning only bytes for the actual ROM size, not for the whole BAR. That means we typically do a short read of the PCI sysfs ROM file. Read it a byte at a time so we know how much to actually copy and only skip the copy if we get nothing. Signed-off-by: Alex Williamson <alex.williamson@xxxxxxxxxx> --- hw/device-assignment.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/device-assignment.c b/hw/device-assignment.c index 0e82a16..3bb7f0b 100644 --- a/hw/device-assignment.c +++ b/hw/device-assignment.c @@ -1680,19 +1680,20 @@ static void assigned_dev_load_option_rom(AssignedDevice *dev) return; } - ret = fread(buf, size, 1, fp); - if (!feof(fp) || ferror(fp) || ret != 1) { + if (!(ret = fread(buf, 1, size, fp))) { free(buf); fclose(fp); return; } fclose(fp); + /* The number of bytes read is often much smaller than the BAR size */ + size = ret; + /* Copy ROM contents into the space backing the ROM BAR */ if (dev->v_addrs[PCI_ROM_SLOT].r_size >= size && dev->v_addrs[PCI_ROM_SLOT].u.r_virtbase) { - memcpy(dev->v_addrs[PCI_ROM_SLOT].u.r_virtbase, - buf, size); + memcpy(dev->v_addrs[PCI_ROM_SLOT].u.r_virtbase, buf, size); } free(buf); -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html