Instead, of trying out each and every target type we should use KVM_ARM_PREFERRED_TARGET vm ioctl to determine target type for KVM ARM/ARM64. We bail-out target type returned by KVM_ARM_PREFERRED_TARGET vm ioctl is not known to kvmtool. Signed-off-by: Pranavkumar Sawargaonkar <pranavkumar@xxxxxxxxxx> Signed-off-by: Anup Patel <anup.patel@xxxxxxxxxx> --- tools/kvm/arm/kvm-cpu.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tools/kvm/arm/kvm-cpu.c b/tools/kvm/arm/kvm-cpu.c index aeaa4cf..7478f8f 100644 --- a/tools/kvm/arm/kvm-cpu.c +++ b/tools/kvm/arm/kvm-cpu.c @@ -34,6 +34,7 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) struct kvm_cpu *vcpu; int coalesced_offset, mmap_size, err = -1; unsigned int i; + struct kvm_vcpu_init preferred_init; struct kvm_vcpu_init vcpu_init = { .features = ARM_VCPU_FEATURE_FLAGS(kvm, cpu_id) }; @@ -46,6 +47,10 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) if (vcpu->vcpu_fd < 0) die_perror("KVM_CREATE_VCPU ioctl"); + err = ioctl(kvm->vm_fd, KVM_ARM_PREFERRED_TARGET, &preferred_init); + if (err < 0) + die_perror("KVM_ARM_PREFERRED_TARGET ioctl"); + mmap_size = ioctl(kvm->sys_fd, KVM_GET_VCPU_MMAP_SIZE, 0); if (mmap_size < 0) die_perror("KVM_GET_VCPU_MMAP_SIZE ioctl"); @@ -55,17 +60,22 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) if (vcpu->kvm_run == MAP_FAILED) die("unable to mmap vcpu fd"); - /* Find an appropriate target CPU type. */ + /* Match preferred target CPU type. */ + target = NULL; for (i = 0; i < ARRAY_SIZE(kvm_arm_targets); ++i) { if (!kvm_arm_targets[i]) continue; - target = kvm_arm_targets[i]; - vcpu_init.target = target->id; - err = ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_INIT, &vcpu_init); - if (!err) + if (kvm_arm_targets[i]->id == preferred_init.target) { + target = kvm_arm_targets[i]; break; + } + } + if (!target) { + die("preferred target not available\n"); } + vcpu_init.target = preferred_init.target; + err = ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_INIT, &vcpu_init); if (err || target->init(vcpu)) die("Unable to initialise ARM vcpu"); @@ -81,6 +91,7 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) vcpu->cpu_type = target->id; vcpu->cpu_compatible = target->compatible; vcpu->is_running = true; + return vcpu; } -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html