[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 16/19] kvm: fix ioeventfd endianness on bi-endian arc
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 16/19] kvm: fix ioeventfd endianness on bi-endian architectures |
Date: |
Wed, 18 Mar 2015 12:25:03 +0100 |
From: Greg Kurz <address@hidden>
KVM expects host endian values. Hosts that don't use the default endianness
need to negate the swap performed in adjust_endianness().
Suggested-by: Paolo Bonzini <address@hidden>
Signed-off-by: Greg Kurz <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
kvm-all.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/kvm-all.c b/kvm-all.c
index 55025cc..335438a 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -528,13 +528,33 @@ int kvm_vm_check_extension(KVMState *s, unsigned int
extension)
return ret;
}
+static uint32_t adjust_ioeventfd_endianness(uint32_t val, uint32_t size)
+{
+#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
+ /* The kernel expects ioeventfd values in HOST_WORDS_BIGENDIAN
+ * endianness, but the memory core hands them in target endianness.
+ * For example, PPC is always treated as big-endian even if running
+ * on KVM and on PPC64LE. Correct here.
+ */
+ switch (size) {
+ case 2:
+ val = bswap16(val);
+ break;
+ case 4:
+ val = bswap32(val);
+ break;
+ }
+#endif
+ return val;
+}
+
static int kvm_set_ioeventfd_mmio(int fd, hwaddr addr, uint32_t val,
bool assign, uint32_t size, bool datamatch)
{
int ret;
struct kvm_ioeventfd iofd;
- iofd.datamatch = datamatch ? val : 0;
+ iofd.datamatch = datamatch ? adjust_ioeventfd_endianness(val, size) : 0;
iofd.addr = addr;
iofd.len = size;
iofd.flags = 0;
@@ -564,7 +584,7 @@ static int kvm_set_ioeventfd_pio(int fd, uint16_t addr,
uint16_t val,
bool assign, uint32_t size, bool datamatch)
{
struct kvm_ioeventfd kick = {
- .datamatch = datamatch ? val : 0,
+ .datamatch = datamatch ? adjust_ioeventfd_endianness(val, size) : 0,
.addr = addr,
.flags = KVM_IOEVENTFD_FLAG_PIO,
.len = size,
--
2.3.0
- [Qemu-devel] [PULL 09/19] nbd: Set block size to BDRV_SECTOR_SIZE, (continued)
- [Qemu-devel] [PULL 09/19] nbd: Set block size to BDRV_SECTOR_SIZE, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 10/19] nbd: Fix nbd_receive_options(), Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 06/19] nbd: Handle blk_getlength() failure, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 07/19] qemu-nbd: fork() can fail, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 14/19] build: pass .d file name to scripts/make_device_config.sh, fix makefile target, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 11/19] nbd: Fix interpretation of the export flags, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 15/19] virtio-scsi: Fix assert in virtio_scsi_push_event, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 12/19] nbd: Drop unexpected data for NBD_OPT_LIST, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 18/19] virtio-scsi-dataplane: fix memory leak in virtio_scsi_vring_init, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 19/19] exec: Respect as_tranlsate_internal length clamp, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 16/19] kvm: fix ioeventfd endianness on bi-endian architectures,
Paolo Bonzini <=
- [Qemu-devel] [PULL 17/19] profiler: Reenable built-in profiler, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 13/19] coroutine-io: Return -errno in case of error, Paolo Bonzini, 2015/03/18
- Re: [Qemu-devel] [PULL 00/19] Misc bugfixes for 2.3.0-rc1, Peter Maydell, 2015/03/19