aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/kvm
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2018-12-14 12:29:43 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2018-12-14 18:00:08 +0100
commit5132411985e14b8dda69173abee8ea9ba942698f (patch)
treed6e59f0f4e943ab0ac68cbb4e3679486e68d1cfc /tools/testing/selftests/kvm
parentkvm: x86: Dynamically allocate guest_fpu (diff)
downloadlinux-dev-5132411985e14b8dda69173abee8ea9ba942698f.tar.xz
linux-dev-5132411985e14b8dda69173abee8ea9ba942698f.zip
kvm: selftests: ucall: improve ucall placement in memory, fix unsigned comparison
Based on a patch by Andrew Jones. Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tools/testing/selftests/kvm')
-rw-r--r--tools/testing/selftests/kvm/lib/ucall.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/tools/testing/selftests/kvm/lib/ucall.c b/tools/testing/selftests/kvm/lib/ucall.c
index 4777f9bb5194..694bc2eaa63e 100644
--- a/tools/testing/selftests/kvm/lib/ucall.c
+++ b/tools/testing/selftests/kvm/lib/ucall.c
@@ -34,7 +34,7 @@ void ucall_init(struct kvm_vm *vm, ucall_type_t type, void *arg)
return;
if (type == UCALL_MMIO) {
- vm_paddr_t gpa, start, end, step;
+ vm_paddr_t gpa, start, end, step, offset;
bool ret;
if (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.
* Here we start with a guess that the addresses around two
* 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);
end = 1ul << vm->va_bits;
- step = 1ul << (vm->va_bits / 6);
- for (gpa = start; gpa >= 0; gpa -= step) {
- if (ucall_mmio_init(vm, gpa & ~(vm->page_size - 1)))
+ step = 1ul << (vm->va_bits / 12);
+ for (offset = 0; offset < end - start; offset += step) {
+ if (ucall_mmio_init(vm, (gpa - offset) & ~(vm->page_size - 1)))
return;
- }
- for (gpa = start + step; gpa < end; gpa += step) {
- if (ucall_mmio_init(vm, gpa & ~(vm->page_size - 1)))
+ if (ucall_mmio_init(vm, (gpa + offset) & ~(vm->page_size - 1)))
return;
}
TEST_ASSERT(false, "Can't find a ucall mmio address");