From: Alex Williamson <alex.williamson@redhat.com>
To: qemu-devel@nongnu.org
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>, alex.williamson@redhat.com
Subject: [Qemu-devel] [PULL 3/4] vfio: Make BARs native endian
Date: Mon, 30 Jun 2014 11:28:03 -0600 [thread overview]
Message-ID: <20140630172803.24172.50309.stgit@bling.home> (raw)
In-Reply-To: <20140630172611.24172.93339.stgit@bling.home>
From: Alexey Kardashevskiy <aik@ozlabs.ru>
Slow BAR access path is used when VFIO fails to mmap() BAR.
Since this is just a transport between the guest and a device, there is
no need to do endianness swapping.
This changes BARs to use native endianness. Since non-ROM BARs were
doing byte swapping, we need to remove it so does the patch.
As the result, this eliminates cancelling byte swaps and there is
no change in behavior for non-ROM BARs.
ROM BARs were declared little endian too but byte swapping was not
implemented for them so they never actually worked on big endian systems
as there was no cancelling byte swap. This fixes endiannes for ROM BARs
by declaring them native endian and only fixing access sizes as it is
done for non-ROM BARs.
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
hw/misc/vfio.c | 41 +++++++++++++++++++++++++++++++----------
1 file changed, 31 insertions(+), 10 deletions(-)
diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
index 7312ce2..d32678e 100644
--- a/hw/misc/vfio.c
+++ b/hw/misc/vfio.c
@@ -1082,10 +1082,10 @@ static void vfio_bar_write(void *opaque, hwaddr addr,
buf.byte = data;
break;
case 2:
- buf.word = cpu_to_le16(data);
+ buf.word = data;
break;
case 4:
- buf.dword = cpu_to_le32(data);
+ buf.dword = data;
break;
default:
hw_error("vfio: unsupported write size, %d bytes", size);
@@ -1142,10 +1142,10 @@ static uint64_t vfio_bar_read(void *opaque,
data = buf.byte;
break;
case 2:
- data = le16_to_cpu(buf.word);
+ data = buf.word;
break;
case 4:
- data = le32_to_cpu(buf.dword);
+ data = buf.dword;
break;
default:
hw_error("vfio: unsupported read size, %d bytes", size);
@@ -1172,7 +1172,7 @@ static uint64_t vfio_bar_read(void *opaque,
static const MemoryRegionOps vfio_bar_ops = {
.read = vfio_bar_read,
.write = vfio_bar_write,
- .endianness = DEVICE_LITTLE_ENDIAN,
+ .endianness = DEVICE_NATIVE_ENDIAN,
};
static void vfio_pci_load_rom(VFIODevice *vdev)
@@ -1234,21 +1234,42 @@ static void vfio_pci_load_rom(VFIODevice *vdev)
static uint64_t vfio_rom_read(void *opaque, hwaddr addr, unsigned size)
{
VFIODevice *vdev = opaque;
- uint64_t val = ((uint64_t)1 << (size * 8)) - 1;
+ union {
+ uint8_t byte;
+ uint16_t word;
+ uint32_t dword;
+ uint64_t qword;
+ } buf;
+ uint64_t data = 0;
/* Load the ROM lazily when the guest tries to read it */
if (unlikely(!vdev->rom && !vdev->rom_read_failed)) {
vfio_pci_load_rom(vdev);
}
- memcpy(&val, vdev->rom + addr,
+ memcpy(&buf, vdev->rom + addr,
(addr < vdev->rom_size) ? MIN(size, vdev->rom_size - addr) : 0);
+ switch (size) {
+ case 1:
+ data = buf.byte;
+ break;
+ case 2:
+ data = buf.word;
+ break;
+ case 4:
+ data = buf.dword;
+ break;
+ default:
+ hw_error("vfio: unsupported read size, %d bytes", size);
+ break;
+ }
+
DPRINTF("%s(%04x:%02x:%02x.%x, 0x%"HWADDR_PRIx", 0x%x) = 0x%"PRIx64"\n",
__func__, vdev->host.domain, vdev->host.bus, vdev->host.slot,
- vdev->host.function, addr, size, val);
+ vdev->host.function, addr, size, data);
- return val;
+ return data;
}
static void vfio_rom_write(void *opaque, hwaddr addr,
@@ -1259,7 +1280,7 @@ static void vfio_rom_write(void *opaque, hwaddr addr,
static const MemoryRegionOps vfio_rom_ops = {
.read = vfio_rom_read,
.write = vfio_rom_write,
- .endianness = DEVICE_LITTLE_ENDIAN,
+ .endianness = DEVICE_NATIVE_ENDIAN,
};
static bool vfio_blacklist_opt_rom(VFIODevice *vdev)
next prev parent reply other threads:[~2014-06-30 17:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-30 17:27 [Qemu-devel] [PULL 0/4] VFIO fixes for QEMU 2.1 Alex Williamson
2014-06-30 17:27 ` [Qemu-devel] [PULL 1/4] vfio-pci: Fix MSI/X debug code Alex Williamson
2014-06-30 17:27 ` [Qemu-devel] [PULL 2/4] vfio-pci: Fix MSI-X masking performance Alex Williamson
2014-06-30 17:28 ` Alex Williamson [this message]
2014-09-08 12:32 ` [Qemu-devel] [PULL 3/4] vfio: Make BARs native endian Alexander Graf
2014-06-30 17:28 ` [Qemu-devel] [PULL 4/4] vfio: use correct runstate Alex Williamson
2014-06-30 17:47 ` [Qemu-devel] [PULL 0/4] VFIO fixes for QEMU 2.1 Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140630172803.24172.50309.stgit@bling.home \
--to=alex.williamson@redhat.com \
--cc=aik@ozlabs.ru \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).