From: Andre Przywara <andre.przywara@arm.com>
To: Anup Patel <anup.patel@linaro.org>,
"kvmarm@lists.cs.columbia.edu" <kvmarm@lists.cs.columbia.edu>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"patches@apm.com" <patches@apm.com>,
Will Deacon <Will.Deacon@arm.com>,
Marc Zyngier <Marc.Zyngier@arm.com>,
"penberg@kernel.org" <penberg@kernel.org>,
"christoffer.dall@linaro.org" <christoffer.dall@linaro.org>,
"pranavkumar@linaro.org" <pranavkumar@linaro.org>
Subject: Re: [PATCH v3 1/4] kvmtool: ARM: Use KVM_ARM_PREFERRED_TARGET vm ioctl to determine target cpu
Date: Thu, 11 Sep 2014 16:54:30 +0100 [thread overview]
Message-ID: <5411C5B6.6070400@arm.com> (raw)
In-Reply-To: <1410164258-27469-2-git-send-email-anup.patel@linaro.org>
Hi Anup,
On 08/09/14 09:17, Anup Patel wrote:
> 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 <pranavkumar@linaro.org>
> Signed-off-by: Anup Patel <anup.patel@linaro.org>
> ---
> 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];
I think you missed the part of the patch which adds the now magic zero
member of kvm_arm_targets[]. A simple static initializer should work.
> + target_type = preferred_init.target;
Can't you move that out of the loop, in front of it actually? Then you
can get rid of the line above setting the target_type also, since you
always use the same value now, regardless whether you found that CPU in
the list or not.
> + }
> + } 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);
You should do this only in the if-branch above, since you (try to) call
KVM_ARM_VCPU_INIT already in the else branch before. Otherwise in the
latter case you would do it twice.
Regards,
Andre.
> 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;
> }
>
>
next prev parent reply other threads:[~2014-09-11 15:54 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-08 8:17 [PATCH v3 0/4] kvmtool: ARM/ARM64: Misc updates Anup Patel
2014-09-08 8:17 ` [PATCH v3 1/4] kvmtool: ARM: Use KVM_ARM_PREFERRED_TARGET vm ioctl to determine target cpu Anup Patel
2014-09-11 15:54 ` Andre Przywara [this message]
2014-09-16 22:13 ` Anup Patel
2014-09-16 22:46 ` Anup Patel
2014-09-08 8:17 ` [PATCH v3 2/4] kvmtool: ARM64: Add target type potenza for aarch64 Anup Patel
2014-09-11 16:07 ` Andre Przywara
2014-09-16 22:24 ` Anup Patel
2014-09-16 22:46 ` Anup Patel
2014-09-08 8:17 ` [PATCH v3 3/4] kvmtool: Handle exit reason KVM_EXIT_SYSTEM_EVENT Anup Patel
2014-09-11 16:26 ` Andre Przywara
2014-09-16 22:29 ` Anup Patel
2014-09-16 22:47 ` Anup Patel
2014-09-08 8:17 ` [PATCH v3 4/4] kvmtool: ARM/ARM64: Provide PSCI-0.2 to guest when KVM supports it Anup Patel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5411C5B6.6070400@arm.com \
--to=andre.przywara@arm.com \
--cc=Marc.Zyngier@arm.com \
--cc=Will.Deacon@arm.com \
--cc=anup.patel@linaro.org \
--cc=christoffer.dall@linaro.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=patches@apm.com \
--cc=penberg@kernel.org \
--cc=pranavkumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.