diff options
author | Jason Wang <jasowang@redhat.com> | 2015-09-15 14:41:57 +0800 |
---|---|---|
committer | Sasha Levin <sasha.levin@oracle.com> | 2015-10-27 22:12:49 -0400 |
commit | 7d765ce07eff78ab78d09d4acaa3aecb71e322a4 (patch) | |
tree | acd1dedada9f57df5cae93919f327fb5d52fdef9 /virt/kvm/kvm_main.c | |
parent | d758df24a58e5160270c74b467dfa6453fceb91b (diff) | |
download | lwn-7d765ce07eff78ab78d09d4acaa3aecb71e322a4.tar.gz lwn-7d765ce07eff78ab78d09d4acaa3aecb71e322a4.zip |
kvm: fix zero length mmio searching
[ Upstream commit 8f4216c7d28976f7ec1b2bcbfa0a9f787133c45e ]
Currently, if we had a zero length mmio eventfd assigned on
KVM_MMIO_BUS. It will never be found by kvm_io_bus_cmp() since it
always compares the kvm_io_range() with the length that guest
wrote. This will cause e.g for vhost, kick will be trapped by qemu
userspace instead of vhost. Fixing this by using zero length if an
iodevice is zero length.
Cc: stable@vger.kernel.org
Cc: Gleb Natapov <gleb@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Diffstat (limited to 'virt/kvm/kvm_main.c')
-rw-r--r-- | virt/kvm/kvm_main.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 4e52bb926374..329c3c91bb68 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2875,10 +2875,25 @@ static void kvm_io_bus_destroy(struct kvm_io_bus *bus) static inline int kvm_io_bus_cmp(const struct kvm_io_range *r1, const struct kvm_io_range *r2) { - if (r1->addr < r2->addr) + gpa_t addr1 = r1->addr; + gpa_t addr2 = r2->addr; + + if (addr1 < addr2) return -1; - if (r1->addr + r1->len > r2->addr + r2->len) + + /* If r2->len == 0, match the exact address. If r2->len != 0, + * accept any overlapping write. Any order is acceptable for + * overlapping ranges, because kvm_io_bus_get_first_dev ensures + * we process all of them. + */ + if (r2->len) { + addr1 += r1->len; + addr2 += r2->len; + } + + if (addr1 > addr2) return 1; + return 0; } |