Blob Blame History Raw
From 4bb91ae660a2b4aa64c12b9f92227881edf13609 Mon Sep 17 00:00:00 2001
From: Alex Williamson <alex.williamson@redhat.com>
Date: Tue, 5 Nov 2013 15:37:52 +0100
Subject: [PATCH 17/25] vfio-pci: Fix endian issues in vfio_pci_size_rom()

RH-Author: Alex Williamson <alex.williamson@redhat.com>
Message-id: <20131105153752.16057.43832.stgit@bling.home>
Patchwork-id: 55426
O-Subject: [RHEL7 qemu-kvm PATCH 5/5] vfio-pci: Fix endian issues in vfio_pci_size_rom()
Bugzilla: 1026550
RH-Acked-by: Bandan Das <bsd@redhat.com>
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>

Bugzilla: 1026550
Upstream commit: b1c50c5f248805be747e96e89efbe784ee99f764

VFIO is always little endian so do byte swapping of our mask on the
way in and byte swapping of the size on the way out.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Reported-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
 hw/misc/vfio.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
 hw/misc/vfio.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
index d327b40..6178221 100644
--- a/hw/misc/vfio.c
+++ b/hw/misc/vfio.c
@@ -1140,7 +1140,7 @@ static const MemoryRegionOps vfio_rom_ops = {
 
 static void vfio_pci_size_rom(VFIODevice *vdev)
 {
-    uint32_t orig, size = (uint32_t)PCI_ROM_ADDRESS_MASK;
+    uint32_t orig, size = cpu_to_le32((uint32_t)PCI_ROM_ADDRESS_MASK);
     off_t offset = vdev->config_offset + PCI_ROM_ADDRESS;
     char name[32];
 
@@ -1162,7 +1162,7 @@ static void vfio_pci_size_rom(VFIODevice *vdev)
         return;
     }
 
-    size = ~(size & PCI_ROM_ADDRESS_MASK) + 1;
+    size = ~(le32_to_cpu(size) & PCI_ROM_ADDRESS_MASK) + 1;
 
     if (!size) {
         return;
-- 
1.7.1