From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56047) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYC7E-00080o-AN for qemu-devel@nongnu.org; Wed, 18 Mar 2015 07:26:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YYC7D-0001pS-AZ for qemu-devel@nongnu.org; Wed, 18 Mar 2015 07:26:24 -0400 Received: from mail-wi0-x235.google.com ([2a00:1450:400c:c05::235]:36551) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYC7D-0001pL-4L for qemu-devel@nongnu.org; Wed, 18 Mar 2015 07:26:23 -0400 Received: by wibg7 with SMTP id g7so87398058wib.1 for ; Wed, 18 Mar 2015 04:26:22 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Wed, 18 Mar 2015 12:25:03 +0100 Message-Id: <1426677906-51657-17-git-send-email-pbonzini@redhat.com> In-Reply-To: <1426677906-51657-1-git-send-email-pbonzini@redhat.com> References: <1426677906-51657-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 16/19] kvm: fix ioeventfd endianness on bi-endian architectures List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org From: Greg Kurz 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 Signed-off-by: Greg Kurz Message-Id: <20150313212337.31142.3991.stgit@bahia.local> Signed-off-by: Paolo Bonzini --- 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