Commit 51324119 authored by Paolo Bonzini's avatar Paolo Bonzini

kvm: selftests: ucall: improve ucall placement in memory, fix unsigned comparison

Based on a patch by Andrew Jones.
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent b666a4b6
...@@ -34,7 +34,7 @@ void ucall_init(struct kvm_vm *vm, ucall_type_t type, void *arg) ...@@ -34,7 +34,7 @@ void ucall_init(struct kvm_vm *vm, ucall_type_t type, void *arg)
return; return;
if (type == UCALL_MMIO) { if (type == UCALL_MMIO) {
vm_paddr_t gpa, start, end, step; vm_paddr_t gpa, start, end, step, offset;
bool ret; bool ret;
if (arg) { if (arg) {
...@@ -53,17 +53,15 @@ void ucall_init(struct kvm_vm *vm, ucall_type_t type, void *arg) ...@@ -53,17 +53,15 @@ void ucall_init(struct kvm_vm *vm, ucall_type_t type, void *arg)
* KVM_EXIT_MMIO. Well, at least that's how it works for AArch64. * KVM_EXIT_MMIO. Well, at least that's how it works for AArch64.
* Here we start with a guess that the addresses around two * Here we start with a guess that the addresses around two
* thirds of the VA space are unmapped and then work both down * thirds of the VA space are unmapped and then work both down
* and up from there in 1/6 VA space sized steps. * and up from there in 1/12 VA space sized steps.
*/ */
start = 1ul << (vm->va_bits * 2 / 3); start = 1ul << (vm->va_bits * 2 / 3);
end = 1ul << vm->va_bits; end = 1ul << vm->va_bits;
step = 1ul << (vm->va_bits / 6); step = 1ul << (vm->va_bits / 12);
for (gpa = start; gpa >= 0; gpa -= step) { for (offset = 0; offset < end - start; offset += step) {
if (ucall_mmio_init(vm, gpa & ~(vm->page_size - 1))) if (ucall_mmio_init(vm, (gpa - offset) & ~(vm->page_size - 1)))
return; return;
} if (ucall_mmio_init(vm, (gpa + offset) & ~(vm->page_size - 1)))
for (gpa = start + step; gpa < end; gpa += step) {
if (ucall_mmio_init(vm, gpa & ~(vm->page_size - 1)))
return; return;
} }
TEST_ASSERT(false, "Can't find a ucall mmio address"); TEST_ASSERT(false, "Can't find a ucall mmio address");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment