From: Anup Patel Subject: [PATCH v3 1/4] kvmtool: ARM: Use KVM_ARM_PREFERRED_TARGET vm ioctl to determine target cpu Date: Mon, 8 Sep 2014 13:47:35 +0530 Message-ID: <1410164258-27469-2-git-send-email-anup.patel@linaro.org> References: <1410164258-27469-1-git-send-email-anup.patel@linaro.org> Cc: kvm@vger.kernel.org, patches@apm.com, will.deacon@arm.com, marc.zyngier@arm.com, penberg@kernel.org, christoffer.dall@linaro.org, pranavkumar@linaro.org, andre.przywara@arm.com, Anup Patel To: kvmarm@lists.cs.columbia.edu Return-path: Received: from mail-pa0-f44.google.com ([209.85.220.44]:60687 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752980AbaIHISF (ORCPT ); Mon, 8 Sep 2014 04:18:05 -0400 Received: by mail-pa0-f44.google.com with SMTP id kx10so2561386pab.3 for ; Mon, 08 Sep 2014 01:18:04 -0700 (PDT) In-Reply-To: <1410164258-27469-1-git-send-email-anup.patel@linaro.org> Sender: kvm-owner@vger.kernel.org List-ID: 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. If KVM_ARM_PREFERRED_TARGET vm ioctl fails then we fallback to old method of trying all known target types. If KVM_ARM_PREFERRED_TARGET vm ioctl succeeds but the returned target type is not known to KVMTOOL then we forcefully init VCPU with target type returned by KVM_ARM_PREFERRED_TARGET vm ioctl. Signed-off-by: Pranavkumar Sawargaonkar Signed-off-by: Anup Patel --- tools/kvm/arm/kvm-cpu.c | 52 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/tools/kvm/arm/kvm-cpu.c b/tools/kvm/arm/kvm-cpu.c index aeaa4cf..ba7a762 100644 --- a/tools/kvm/arm/kvm-cpu.c +++ b/tools/kvm/arm/kvm-cpu.c @@ -33,7 +33,8 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) struct kvm_arm_target *target; struct kvm_cpu *vcpu; int coalesced_offset, mmap_size, err = -1; - unsigned int i; + unsigned int i, target_type; + struct kvm_vcpu_init preferred_init; struct kvm_vcpu_init vcpu_init = { .features = ARM_VCPU_FEATURE_FLAGS(kvm, cpu_id) }; @@ -55,19 +56,47 @@ 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. */ - 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) - break; + /* + * If preferred target ioctl successful then use preferred target + * else try each and every target type. + */ + err = ioctl(kvm->vm_fd, KVM_ARM_PREFERRED_TARGET, &preferred_init); + if (!err) { + /* Match preferred target CPU type. */ + target = NULL; + for (i = 0; i < ARRAY_SIZE(kvm_arm_targets); ++i) { + if (!kvm_arm_targets[i]) + continue; + if (kvm_arm_targets[i]->id == preferred_init.target) { + target = kvm_arm_targets[i]; + target_type = kvm_arm_targets[i]->id; + break; + } + } + if (!target) { + target = kvm_arm_targets[0]; + target_type = preferred_init.target; + } + } else { + /* Find an appropriate target CPU type. */ + for (i = 0; i < ARRAY_SIZE(kvm_arm_targets); ++i) { + if (!kvm_arm_targets[i]) + continue; + target = kvm_arm_targets[i]; + target_type = target->id; + vcpu_init.target = target_type; + err = ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_INIT, &vcpu_init); + if (!err) + break; + } + if (err) + die("Unable to find matching target"); } + vcpu_init.target = target_type; + err = ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_INIT, &vcpu_init); if (err || target->init(vcpu)) - die("Unable to initialise ARM vcpu"); + die("Unable to initialise vcpu"); coalesced_offset = ioctl(kvm->sys_fd, KVM_CHECK_EXTENSION, KVM_CAP_COALESCED_MMIO); @@ -81,6 +110,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