9ae3a8
From d8cc073c06a4c79e24a86a958b8c1ac7a26fa039 Mon Sep 17 00:00:00 2001
9ae3a8
From: Alex Williamson <alex.williamson@redhat.com>
9ae3a8
Date: Fri, 10 Apr 2015 16:33:45 +0200
9ae3a8
Subject: [PATCH 02/14] vfio: Do not reattempt a failed rom read
9ae3a8
9ae3a8
Message-id: <20150410163345.15324.23733.stgit@gimli.home>
9ae3a8
Patchwork-id: 64790
9ae3a8
O-Subject: [RHEL7.2 qemu-kvm PATCH 2/8] vfio: Do not reattempt a failed rom read
9ae3a8
Bugzilla: 1210503
9ae3a8
RH-Acked-by: Thomas Huth <thuth@redhat.com>
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Bandan Das <bsd@redhat.com>
9ae3a8
9ae3a8
From: Bandan Das <bsd@redhat.com>
9ae3a8
9ae3a8
Upstream: e638073c569e801ce9def2016a84f955cbbca779
9ae3a8
9ae3a8
During lazy rom loading, if rom read fails, and the
9ae3a8
guest attempts a read again, vfio will again attempt it.
9ae3a8
Add a boolean to prevent this. There could be a case where
9ae3a8
a failed rom read might succeed the next time because of
9ae3a8
a device reset or such, but it's best to exclude unpredictable
9ae3a8
behavior
9ae3a8
9ae3a8
Signed-off-by: Bandan Das <bsd@redhat.com>
9ae3a8
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 hw/misc/vfio.c | 6 ++++++
9ae3a8
 1 file changed, 6 insertions(+)
9ae3a8
9ae3a8
diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
9ae3a8
index c9dbc28..f3bf491 100644
9ae3a8
--- a/hw/misc/vfio.c
9ae3a8
+++ b/hw/misc/vfio.c
9ae3a8
@@ -206,6 +206,7 @@ typedef struct VFIODevice {
9ae3a8
     bool has_flr;
9ae3a8
     bool has_pm_reset;
9ae3a8
     bool needs_reset;
9ae3a8
+    bool rom_read_failed;
9ae3a8
 } VFIODevice;
9ae3a8
 
9ae3a8
 typedef struct VFIOGroup {
9ae3a8
@@ -1197,6 +1198,7 @@ static void vfio_pci_load_rom(VFIODevice *vdev)
9ae3a8
     vdev->rom_offset = reg_info.offset;
9ae3a8
 
9ae3a8
     if (!vdev->rom_size) {
9ae3a8
+        vdev->rom_read_failed = true;
9ae3a8
         error_report("vfio-pci: Cannot read device rom at "
9ae3a8
                     "%04x:%02x:%02x.%x\n",
9ae3a8
                     vdev->host.domain, vdev->host.bus, vdev->host.slot,
9ae3a8
@@ -1235,6 +1237,9 @@ static uint64_t vfio_rom_read(void *opaque, hwaddr addr, unsigned size)
9ae3a8
     /* Load the ROM lazily when the guest tries to read it */
9ae3a8
     if (unlikely(!vdev->rom)) {
9ae3a8
         vfio_pci_load_rom(vdev);
9ae3a8
+        if (unlikely(!vdev->rom && !vdev->rom_read_failed)) {
9ae3a8
+            vfio_pci_load_rom(vdev);
9ae3a8
+        }
9ae3a8
     }
9ae3a8
 
9ae3a8
     memcpy(&val, vdev->rom + addr,
9ae3a8
@@ -1352,6 +1357,7 @@ static void vfio_pci_size_rom(VFIODevice *vdev)
9ae3a8
                      PCI_BASE_ADDRESS_SPACE_MEMORY, &vdev->pdev.rom);
9ae3a8
 
9ae3a8
     vdev->pdev.has_rom = true;
9ae3a8
+    vdev->rom_read_failed = false;
9ae3a8
 }
9ae3a8
 
9ae3a8
 static void vfio_vga_write(void *opaque, hwaddr addr,
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8