Skip to contentSkip to conversation

kvmtool: ARM/ARM64: Misc updates

PATCH Superseded Anup Patel 2 participants 11 messages Sep 18, 2014 – Oct 1, 2014 KVM

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

v4 cover kvmtool: ARM/ARM64: Misc updates

This patchset updates KVMTOOL to use some of the features supported by Linux-3.16 KVM ARM/ARM64, such as:

1. Target CPU == Host using KVM_ARM_PREFERRED_TARGET vm ioctl
2. Target CPU type Potenza for using KVMTOOL on X-Gene
3. PSCI v0.2 support for Aarch32 and Aarch64 guest
4. System event exit reason

Changes since v3:
- Add generic targets for aarch32 and aarch64 which are used by KVMTOOL when target type returned by KVM_ARM_PREFERRED_TARGET vm ioctl is not known to KVMTOOL
- Print more info when handling system reset event

Changes since v2:
- Use target type returned by KVM_ARM_PREFERRED_TARGET vm ioctl for VCPU init such that we don't need to update KVMTOOL for every new host hardware
- Simplify DTB generation for PSCI node

Changes since v1:
- Drop the patch to fix compile error for aarch64
- Fallback to old method of trying all target types if KVM_ARM_PREFERRED_TARGET vm ioctl fails
- Print more info when handling KVM_EXIT_SYSTEM_EVENT

Anup Patel (4):
kvmtool: ARM: Use KVM_ARM_PREFERRED_TARGET vm ioctl to determine
target cpu
kvmtool: ARM64: Add target type potenza for aarch64
kvmtool: Handle exit reason KVM_EXIT_SYSTEM_EVENT
kvmtool: ARM/ARM64: Provide PSCI-0.2 to guest when KVM supports it

 tools/kvm/arm/aarch32/arm-cpu.c |    9 ++++++-
 tools/kvm/arm/aarch64/arm-cpu.c |   19 ++++++++++---
 tools/kvm/arm/fdt.c             |   52 +++++++++++++++++++++++++++++++----
 tools/kvm/arm/kvm-cpu.c         |   57 +++++++++++++++++++++++++++++++--------
 tools/kvm/kvm-cpu.c             |   21 +++++++++++++++
 5 files changed, 138 insertions(+), 20 deletions(-)
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH v4 1/4 kvmtool: ARM: Use KVM_ARM_PREFERRED_TARGET vm ioctl to determine target cpu

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.

---
 tools/kvm/arm/aarch32/arm-cpu.c |    9 ++++++-
 tools/kvm/arm/aarch64/arm-cpu.c |   10 ++++++--
 tools/kvm/arm/kvm-cpu.c         |   52 ++++++++++++++++++++++++++++++---------
 3 files changed, 57 insertions(+), 14 deletions(-)
tools/kvm/arm/aarch32/arm-cpu.c +8 -1
index 71b98fe..0d2ff11 100644
@@ -22,6 +22,12 @@ static int arm_cpu__vcpu_init(struct kvm_cpu *vcpu)
 	return 0;
 }
 
+static struct kvm_arm_target target_generic_v7 = {
+	.id		= UINT_MAX,
+	.compatible	= "arm,arm-v7",
+	.init		= arm_cpu__vcpu_init,
+};
+
 static struct kvm_arm_target target_cortex_a15 = {
 	.id		= KVM_ARM_TARGET_CORTEX_A15,
 	.compatible	= "arm,cortex-a15",
@@ -36,7 +42,8 @@ static struct kvm_arm_target target_cortex_a7 = {
 
 static int arm_cpu__core_init(struct kvm *kvm)
 {
-	return (kvm_cpu__register_kvm_arm_target(&target_cortex_a15) ||
+	return (kvm_cpu__register_kvm_arm_target(&target_generic_v7) ||
+		kvm_cpu__register_kvm_arm_target(&target_cortex_a15) ||
 		kvm_cpu__register_kvm_arm_target(&target_cortex_a7));
 }
 core_init(arm_cpu__core_init);
tools/kvm/arm/aarch64/arm-cpu.c +8 -2
index ce5ea2f..9ee3da3 100644
@@ -16,13 +16,18 @@ static void generate_fdt_nodes(void *fdt, struct kvm *kvm, u32 gic_phandle)
 	timer__generate_fdt_nodes(fdt, kvm, timer_interrupts);
 }
 
-
 static int arm_cpu__vcpu_init(struct kvm_cpu *vcpu)
 {
 	vcpu->generate_fdt_nodes = generate_fdt_nodes;
 	return 0;
 }
 
+static struct kvm_arm_target target_generic_v8 = {
+	.id		= UINT_MAX,
+	.compatible	= "arm,arm-v8",
+	.init		= arm_cpu__vcpu_init,
+};
+
 static struct kvm_arm_target target_aem_v8 = {
 	.id		= KVM_ARM_TARGET_AEM_V8,
 	.compatible	= "arm,arm-v8",
@@ -43,7 +48,8 @@ static struct kvm_arm_target target_cortex_a57 = {
 
 static int arm_cpu__core_init(struct kvm *kvm)
 {
-	return (kvm_cpu__register_kvm_arm_target(&target_aem_v8) ||
+	return (kvm_cpu__register_kvm_arm_target(&target_generic_v8) ||
+		kvm_cpu__register_kvm_arm_target(&target_aem_v8) ||
 		kvm_cpu__register_kvm_arm_target(&target_foundation_v8) ||
 		kvm_cpu__register_kvm_arm_target(&target_cortex_a57));
 }
tools/kvm/arm/kvm-cpu.c +41 -11

80 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#2 lore raw

Re: [PATCH v4 1/4] kvmtool: ARM: Use KVM_ARM_PREFERRED_TARGET vm ioctl to determine target cpu

Hi Anup,

thanks for the re-spin and sorry for the delay.

Looks better now, some minor comments below.

Quoted 37 lines · Anup Patel

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.

---
 tools/kvm/arm/aarch32/arm-cpu.c |    9 ++++++-
 tools/kvm/arm/aarch64/arm-cpu.c |   10 ++++++--
 tools/kvm/arm/kvm-cpu.c         |   52 ++++++++++++++++++++++++++++++---------
 3 files changed, 57 insertions(+), 14 deletions(-)
tools/kvm/arm/aarch32/arm-cpu.c +6 -0
index 71b98fe..0d2ff11 100644
@@ -22,6 +22,12 @@ static int arm_cpu__vcpu_init(struct kvm_cpu *vcpu)
 	return 0;
 }
 
+static struct kvm_arm_target target_generic_v7 = {
+	.id		= UINT_MAX,
+	.compatible	= "arm,arm-v7",
+	.init		= arm_cpu__vcpu_init,
+};
+
 static struct kvm_arm_target target_cortex_a15 = {
 	.id		= KVM_ARM_TARGET_CORTEX_A15,
 	.compatible	= "arm,cortex-a15",

tools/kvm/arm/aarch32/arm-cpu.c static struct kvm_arm_target target_cortex_a7 = { · line 48

Quoted 8 lines
tools/kvm/arm/aarch32/arm-cpu.c +2 -1
@@ -36,7 +42,8 @@ static struct kvm_arm_target target_cortex_a7 = {
 
 static int arm_cpu__core_init(struct kvm *kvm)
 {
-	return (kvm_cpu__register_kvm_arm_target(&target_cortex_a15) ||
+	return (kvm_cpu__register_kvm_arm_target(&target_generic_v7) ||
+		kvm_cpu__register_kvm_arm_target(&target_cortex_a15) ||
 		kvm_cpu__register_kvm_arm_target(&target_cortex_a7));
 }

I wonder if you could avoid the registration of this target and instead reference it later directly (instead of using a magic 0 index)? This way you wouldn't need to care about avoiding accidental .id matches with the UINT_MAX above.

Quoted 26 lines
tools/kvm/arm/aarch32/arm-cpu.c +0 -0
 core_init(arm_cpu__core_init);
tools/kvm/arm/aarch64/arm-cpu.c +6 -1
index ce5ea2f..9ee3da3 100644
@@ -16,13 +16,18 @@ static void generate_fdt_nodes(void *fdt, struct kvm *kvm, u32 gic_phandle)
 	timer__generate_fdt_nodes(fdt, kvm, timer_interrupts);
 }
 
-
 static int arm_cpu__vcpu_init(struct kvm_cpu *vcpu)
 {
 	vcpu->generate_fdt_nodes = generate_fdt_nodes;
 	return 0;
 }
 
+static struct kvm_arm_target target_generic_v8 = {
+	.id		= UINT_MAX,
+	.compatible	= "arm,arm-v8",
+	.init		= arm_cpu__vcpu_init,
+};
+
 static struct kvm_arm_target target_aem_v8 = {
 	.id		= KVM_ARM_TARGET_AEM_V8,
 	.compatible	= "arm,arm-v8",

tools/kvm/arm/aarch64/arm-cpu.c static struct kvm_arm_target target_cortex_a57 = { · line 55

Quoted 9 lines
tools/kvm/arm/aarch64/arm-cpu.c +2 -1
@@ -43,7 +48,8 @@ static struct kvm_arm_target target_cortex_a57 = {
 
 static int arm_cpu__core_init(struct kvm *kvm)
 {
-	return (kvm_cpu__register_kvm_arm_target(&target_aem_v8) ||
+	return (kvm_cpu__register_kvm_arm_target(&target_generic_v8) ||
+		kvm_cpu__register_kvm_arm_target(&target_aem_v8) ||
 		kvm_cpu__register_kvm_arm_target(&target_foundation_v8) ||
 		kvm_cpu__register_kvm_arm_target(&target_cortex_a57));
 }

(same thing like for v7 here)

tools/kvm/arm/kvm-cpu.c int kvm_cpu__get_debug_fd(void) · line 16

Quoted 10 lines
tools/kvm/arm/kvm-cpu.c +1 -1
index aeaa4cf..6de5344 100644
@@ -13,7 +13,7 @@ int kvm_cpu__get_debug_fd(void)
 	return debug_fd;
 }
 
-static struct kvm_arm_target *kvm_arm_targets[KVM_ARM_NUM_TARGETS];
+static struct kvm_arm_target *kvm_arm_targets[KVM_ARM_NUM_TARGETS+1];

w/s issue

Quoted 15 lines
tools/kvm/arm/kvm-cpu.c +2 -1
 int kvm_cpu__register_kvm_arm_target(struct kvm_arm_target *target)
 {
 	unsigned int i = 0;
@@ -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)

tools/kvm/arm/kvm-cpu.c struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) · line 60

Quoted 10 lines
tools/kvm/arm/kvm-cpu.c +2 -6
 		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;
+	/*
+	 * If preferred target ioctl successful then use preferred target

the is

Quoted 7 lines
tools/kvm/arm/kvm-cpu.c +7 -0
+	 * 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) {

tools/kvm/arm/kvm-cpu.c struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) · line 77

Quoted 10 lines
tools/kvm/arm/kvm-cpu.c +10 -0
+			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];

As hinted above, I'd rather see a name for the magic 0 here or the default target_generic referenced directly.

tools/kvm/arm/kvm-cpu.c struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) · line 80

Quoted 3 lines
tools/kvm/arm/kvm-cpu.c +3 -0
+			target_type = preferred_init.target;
+		}
+		vcpu_init.target = target_type;

I think you can get rid of the target_type variable at all:

if (!target) {
	target = &target_generic_v8;
	vcpu_init.target = preferred_init.target;
} else
	vcpu_init.target = target->id;

tools/kvm/arm/kvm-cpu.c struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) · line 89

Quoted 11 lines
tools/kvm/arm/kvm-cpu.c +8 -2
 		err = ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_INIT, &vcpu_init);
-		if (!err)
-			break;
+	} 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;

even more obvious here.

Quoted 15 lines
tools/kvm/arm/kvm-cpu.c +7 -1
+			err = ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_INIT, &vcpu_init);
+			if (!err)
+				break;
+		}
+		if (err)
+			die("Unable to find matching target");
 	}
 
 	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);

tools/kvm/arm/kvm-cpu.c struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) · line 110

Quoted 1 line
tools/kvm/arm/kvm-cpu.c +0 -0
@@ -81,6 +110,7 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id)
 	vcpu->cpu_type		= target->id;

If I am not mistaken, this value is bogus when we use PREFERRED_TARGET. Please use vcpu_init.target here instead.

Regards,
Andre.

Quoted 7 lines
tools/kvm/arm/kvm-cpu.c +1 -0
 	vcpu->cpu_compatible	= target->compatible;
 	vcpu->is_running	= true;
+
 	return vcpu;
 }
 
author
#3 lore raw

Re: [PATCH v4 1/4] kvmtool: ARM: Use KVM_ARM_PREFERRED_TARGET vm ioctl to determine target cpu

Quoted 204 lines · Andre Przywara

Hi Anup,

thanks for the re-spin and sorry for the delay.

Looks better now, some minor comments below.

Quoted 37 lines · Anup Patel

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.

---
 tools/kvm/arm/aarch32/arm-cpu.c |    9 ++++++-
 tools/kvm/arm/aarch64/arm-cpu.c |   10 ++++++--
 tools/kvm/arm/kvm-cpu.c         |   52 ++++++++++++++++++++++++++++++---------
 3 files changed, 57 insertions(+), 14 deletions(-)
tools/kvm/arm/aarch32/arm-cpu.c +6 -0
index 71b98fe..0d2ff11 100644
@@ -22,6 +22,12 @@ static int arm_cpu__vcpu_init(struct kvm_cpu *vcpu)
      return 0;
 }
 
+static struct kvm_arm_target target_generic_v7 = {
+     .id             = UINT_MAX,
+     .compatible     = "arm,arm-v7",
+     .init           = arm_cpu__vcpu_init,
+};
+
 static struct kvm_arm_target target_cortex_a15 = {
      .id             = KVM_ARM_TARGET_CORTEX_A15,
      .compatible     = "arm,cortex-a15",

tools/kvm/arm/aarch32/arm-cpu.c static struct kvm_arm_target target_cortex_a7 = { · line 48

Quoted 8 lines
tools/kvm/arm/aarch32/arm-cpu.c +2 -1
@@ -36,7 +42,8 @@ static struct kvm_arm_target target_cortex_a7 = {
 
 static int arm_cpu__core_init(struct kvm *kvm)
 {
-     return (kvm_cpu__register_kvm_arm_target(&target_cortex_a15) ||
+     return (kvm_cpu__register_kvm_arm_target(&target_generic_v7) ||
+             kvm_cpu__register_kvm_arm_target(&target_cortex_a15) ||
              kvm_cpu__register_kvm_arm_target(&target_cortex_a7));
 }

I wonder if you could avoid the registration of this target and instead reference it later directly (instead of using a magic 0 index)? This way you wouldn't need to care about avoiding accidental .id matches with the UINT_MAX above.

Quoted 26 lines
tools/kvm/arm/aarch32/arm-cpu.c +0 -0
 core_init(arm_cpu__core_init);
tools/kvm/arm/aarch64/arm-cpu.c +6 -1
index ce5ea2f..9ee3da3 100644
@@ -16,13 +16,18 @@ static void generate_fdt_nodes(void *fdt, struct kvm *kvm, u32 gic_phandle)
      timer__generate_fdt_nodes(fdt, kvm, timer_interrupts);
 }
 
-
 static int arm_cpu__vcpu_init(struct kvm_cpu *vcpu)
 {
      vcpu->generate_fdt_nodes = generate_fdt_nodes;
      return 0;
 }
 
+static struct kvm_arm_target target_generic_v8 = {
+     .id             = UINT_MAX,
+     .compatible     = "arm,arm-v8",
+     .init           = arm_cpu__vcpu_init,
+};
+
 static struct kvm_arm_target target_aem_v8 = {
      .id             = KVM_ARM_TARGET_AEM_V8,
      .compatible     = "arm,arm-v8",

tools/kvm/arm/aarch64/arm-cpu.c static struct kvm_arm_target target_cortex_a57 = { · line 55

Quoted 9 lines
tools/kvm/arm/aarch64/arm-cpu.c +2 -1
@@ -43,7 +48,8 @@ static struct kvm_arm_target target_cortex_a57 = {
 
 static int arm_cpu__core_init(struct kvm *kvm)
 {
-     return (kvm_cpu__register_kvm_arm_target(&target_aem_v8) ||
+     return (kvm_cpu__register_kvm_arm_target(&target_generic_v8) ||
+             kvm_cpu__register_kvm_arm_target(&target_aem_v8) ||
              kvm_cpu__register_kvm_arm_target(&target_foundation_v8) ||
              kvm_cpu__register_kvm_arm_target(&target_cortex_a57));
 }

(same thing like for v7 here)

tools/kvm/arm/kvm-cpu.c int kvm_cpu__get_debug_fd(void) · line 16

Quoted 10 lines
tools/kvm/arm/kvm-cpu.c +1 -1
index aeaa4cf..6de5344 100644
@@ -13,7 +13,7 @@ int kvm_cpu__get_debug_fd(void)
      return debug_fd;
 }
 
-static struct kvm_arm_target *kvm_arm_targets[KVM_ARM_NUM_TARGETS];
+static struct kvm_arm_target *kvm_arm_targets[KVM_ARM_NUM_TARGETS+1];

w/s issue

Quoted 15 lines
tools/kvm/arm/kvm-cpu.c +2 -1
 int kvm_cpu__register_kvm_arm_target(struct kvm_arm_target *target)
 {
      unsigned int i = 0;
@@ -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)

tools/kvm/arm/kvm-cpu.c struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) · line 60

Quoted 10 lines
tools/kvm/arm/kvm-cpu.c +2 -6
              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;
+     /*
+      * If preferred target ioctl successful then use preferred target

the is

Quoted 7 lines
tools/kvm/arm/kvm-cpu.c +7 -0
+      * 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) {

tools/kvm/arm/kvm-cpu.c struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) · line 77

Quoted 10 lines
tools/kvm/arm/kvm-cpu.c +10 -0
+                     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];

As hinted above, I'd rather see a name for the magic 0 here or the default target_generic referenced directly.

tools/kvm/arm/kvm-cpu.c struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) · line 80

Quoted 3 lines
tools/kvm/arm/kvm-cpu.c +3 -0
+                     target_type = preferred_init.target;
+             }
+             vcpu_init.target = target_type;

I think you can get rid of the target_type variable at all:

if (!target) {
        target = &target_generic_v8;
        vcpu_init.target = preferred_init.target;
} else
        vcpu_init.target = target->id;

tools/kvm/arm/kvm-cpu.c struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) · line 89

Quoted 11 lines
tools/kvm/arm/kvm-cpu.c +8 -2
              err = ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_INIT, &vcpu_init);
-             if (!err)
-                     break;
+     } 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;

even more obvious here.

Quoted 15 lines
tools/kvm/arm/kvm-cpu.c +7 -1
+                     err = ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_INIT, &vcpu_init);
+                     if (!err)
+                             break;
+             }
+             if (err)
+                     die("Unable to find matching target");
      }
 
      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);

tools/kvm/arm/kvm-cpu.c struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) · line 110

Quoted 1 line
tools/kvm/arm/kvm-cpu.c +0 -0
@@ -81,6 +110,7 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id)
      vcpu->cpu_type          = target->id;

If I am not mistaken, this value is bogus when we use PREFERRED_TARGET. Please use vcpu_init.target here instead.

Quoted 10 lines

Regards,
Andre.

Quoted 7 lines
tools/kvm/arm/kvm-cpu.c +1 -0
      vcpu->cpu_compatible    = target->compatible;
      vcpu->is_running        = true;
+
      return vcpu;
 }
 

Sure, will incorporate all your suggestions.

Regards,
Anup

author
#4 lore raw

PATCH v4 2/4 kvmtool: ARM64: Add target type potenza for aarch64

In reply to Anup Patel

The VCPU target type KVM_ARM_TARGET_XGENE_POTENZA is available in latest Linux-3.16-rcX or higher hence register aarch64 target type for it.

This patch enables us to run KVMTOOL on X-Gene Potenza host.

---
 tools/kvm/arm/aarch64/arm-cpu.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/kvm/arm/aarch64/arm-cpu.c +8 -1
index 9ee3da3..51a1e2f 100644
@@ -46,11 +46,18 @@ static struct kvm_arm_target target_cortex_a57 = {
 	.init		= arm_cpu__vcpu_init,
 };
 
+static struct kvm_arm_target target_potenza = {
+	.id		= KVM_ARM_TARGET_XGENE_POTENZA,
+	.compatible	= "arm,arm-v8",
+	.init		= arm_cpu__vcpu_init,
+};
+
 static int arm_cpu__core_init(struct kvm *kvm)
 {
 	return (kvm_cpu__register_kvm_arm_target(&target_generic_v8) ||
 		kvm_cpu__register_kvm_arm_target(&target_aem_v8) ||
 		kvm_cpu__register_kvm_arm_target(&target_foundation_v8) ||
-		kvm_cpu__register_kvm_arm_target(&target_cortex_a57));
+		kvm_cpu__register_kvm_arm_target(&target_cortex_a57) ||
+		kvm_cpu__register_kvm_arm_target(&target_potenza));
 }
 core_init(arm_cpu__core_init);
Signature · 1 line
1.7.9.5
#5 lore raw

Re: [PATCH v4 2/4] kvmtool: ARM64: Add target type potenza for aarch64

Quoted 5 lines · Anup Patel

The VCPU target type KVM_ARM_TARGET_XGENE_POTENZA is available in latest Linux-3.16-rcX or higher hence register aarch64 target type for it.

This patch enables us to run KVMTOOL on X-Gene Potenza host.

I still don't like the addition of another CPU, but for the sake of running older kernels (which seems to have a use-case in your case) I am OK with this.
Maybe it's worth adding a comment which states that this list is "closed" and just provided to support older kernels?
So that other SoCs don't get funny ideas... ;-)

Cheers,
Andre.

Quoted 22 lines
---
 tools/kvm/arm/aarch64/arm-cpu.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/kvm/arm/aarch64/arm-cpu.c +6 -0
index 9ee3da3..51a1e2f 100644
@@ -46,11 +46,18 @@ static struct kvm_arm_target target_cortex_a57 = {
      .init           = arm_cpu__vcpu_init,
 };
 
+static struct kvm_arm_target target_potenza = {
+     .id             = KVM_ARM_TARGET_XGENE_POTENZA,
+     .compatible     = "arm,arm-v8",
+     .init           = arm_cpu__vcpu_init,
+};
+

tools/kvm/arm/aarch64/arm-cpu.c static struct kvm_arm_target target_cortex_a57 = { · line 63

Quoted 10 lines
tools/kvm/arm/aarch64/arm-cpu.c +2 -1
 static int arm_cpu__core_init(struct kvm *kvm)
 {
      return (kvm_cpu__register_kvm_arm_target(&target_generic_v8) ||
              kvm_cpu__register_kvm_arm_target(&target_aem_v8) ||
              kvm_cpu__register_kvm_arm_target(&target_foundation_v8) ||
-             kvm_cpu__register_kvm_arm_target(&target_cortex_a57));
+             kvm_cpu__register_kvm_arm_target(&target_cortex_a57) ||
+             kvm_cpu__register_kvm_arm_target(&target_potenza));
 }
 core_init(arm_cpu__core_init);

-- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

ARM Limited, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, Registered in England & Wales, Company No: 2557590 ARM Holdings plc, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, Registered in England & Wales, Company No: 2548782

author
#6 lore raw

Re: [PATCH v4 2/4] kvmtool: ARM64: Add target type potenza for aarch64

Quoted 6 lines · Andre Przywara
Quoted 4 lines · Anup Patel

The VCPU target type KVM_ARM_TARGET_XGENE_POTENZA is available in latest Linux-3.16-rcX or higher hence register aarch64 target type for it.

Quoted 8 lines
Quoted 1 line

This patch enables us to run KVMTOOL on X-Gene Potenza host.

I still don't like the addition of another CPU, but for the sake of running older kernels (which seems to have a use-case in your case) I am OK with this.
Maybe it's worth adding a comment which states that this list is "closed" and just provided to support older kernels?
So that other SoCs don't get funny ideas... ;-)

Sure, I will add a comment for this.

Regards,
Anup

Quoted 42 lines

Cheers,
Andre.

Quoted 22 lines
---
 tools/kvm/arm/aarch64/arm-cpu.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/kvm/arm/aarch64/arm-cpu.c +6 -0
index 9ee3da3..51a1e2f 100644
@@ -46,11 +46,18 @@ static struct kvm_arm_target target_cortex_a57 = {
      .init           = arm_cpu__vcpu_init,
 };
 
+static struct kvm_arm_target target_potenza = {
+     .id             = KVM_ARM_TARGET_XGENE_POTENZA,
+     .compatible     = "arm,arm-v8",
+     .init           = arm_cpu__vcpu_init,
+};
+

tools/kvm/arm/aarch64/arm-cpu.c static struct kvm_arm_target target_cortex_a57 = { · line 63

Quoted 10 lines
tools/kvm/arm/aarch64/arm-cpu.c +2 -1
 static int arm_cpu__core_init(struct kvm *kvm)
 {
      return (kvm_cpu__register_kvm_arm_target(&target_generic_v8) ||
              kvm_cpu__register_kvm_arm_target(&target_aem_v8) ||
              kvm_cpu__register_kvm_arm_target(&target_foundation_v8) ||
-             kvm_cpu__register_kvm_arm_target(&target_cortex_a57));
+             kvm_cpu__register_kvm_arm_target(&target_cortex_a57) ||
+             kvm_cpu__register_kvm_arm_target(&target_potenza));
 }
 core_init(arm_cpu__core_init);

-- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

ARM Limited, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, Registered in England & Wales, Company No: 2557590 ARM Holdings plc, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, Registered in England & Wales, Company No: 2548782

author
#7 lore raw

PATCH v4 3/4 kvmtool: Handle exit reason KVM_EXIT_SYSTEM_EVENT

In reply to Anup Patel

The KVM_EXIT_SYSTEM_EVENT exit reason was added to define architecture independent system-wide events for a Guest.

Currently, it is used by in-kernel PSCI-0.2 emulation of KVM ARM/ARM64 to inform user space about PSCI SYSTEM_OFF or PSCI SYSTEM_RESET request.

For now, we simply treat all system-wide guest events as shutdown request in KVMTOOL.

---
 tools/kvm/kvm-cpu.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
tools/kvm/kvm-cpu.c +21 -0
index ee0a8ec..5180039 100644
@@ -160,6 +160,27 @@ int kvm_cpu__start(struct kvm_cpu *cpu)
 			goto exit_kvm;
 		case KVM_EXIT_SHUTDOWN:
 			goto exit_kvm;
+		case KVM_EXIT_SYSTEM_EVENT:
+			/*
+			 * Print the type of system event and
+			 * treat all system events as shutdown request.
+			 */
+			switch (cpu->kvm_run->system_event.type) {
+			case KVM_SYSTEM_EVENT_SHUTDOWN:
+				printf("  # Info: shutdown system event\n");
+				goto exit_kvm;
+			case KVM_SYSTEM_EVENT_RESET:
+				printf("  # Info: reset system event\n");
+				printf("  # Info: KVMTOOL does not support VM reset\n");
+				printf("  # Info: please re-launch the VM manually\n");
+				goto exit_kvm;
+			default:
+				printf("  # Warning: unknown system event type=%d\n",
+				       cpu->kvm_run->system_event.type);
+				printf("  # Info: exiting KVMTOOL\n");
+				goto exit_kvm;
+			};
+			break;
 		default: {
 			bool ret;
 
Signature · 1 line
1.7.9.5
Reviewed-by on v4 3/4
#8 lore raw

Re: [PATCH v4 3/4] kvmtool: Handle exit reason KVM_EXIT_SYSTEM_EVENT

Quoted 39 lines · Anup Patel

The KVM_EXIT_SYSTEM_EVENT exit reason was added to define architecture independent system-wide events for a Guest.

Currently, it is used by in-kernel PSCI-0.2 emulation of KVM ARM/ARM64 to inform user space about PSCI SYSTEM_OFF or PSCI SYSTEM_RESET request.

For now, we simply treat all system-wide guest events as shutdown request in KVMTOOL.

---
 tools/kvm/kvm-cpu.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
tools/kvm/kvm-cpu.c +14 -0
index ee0a8ec..5180039 100644
@@ -160,6 +160,27 @@ int kvm_cpu__start(struct kvm_cpu *cpu)
 			goto exit_kvm;
 		case KVM_EXIT_SHUTDOWN:
 			goto exit_kvm;
+		case KVM_EXIT_SYSTEM_EVENT:
+			/*
+			 * Print the type of system event and
+			 * treat all system events as shutdown request.
+			 */
+			switch (cpu->kvm_run->system_event.type) {
+			case KVM_SYSTEM_EVENT_SHUTDOWN:
+				printf("  # Info: shutdown system event\n");
+				goto exit_kvm;
+			case KVM_SYSTEM_EVENT_RESET:
+				printf("  # Info: reset system event\n");
+				printf("  # Info: KVMTOOL does not support VM reset\n");
+				printf("  # Info: please re-launch the VM manually\n");
+				goto exit_kvm;

tools/kvm/kvm-cpu.c int kvm_cpu__start(struct kvm_cpu *cpu) · line 186

Quoted 10 lines
tools/kvm/kvm-cpu.c +7 -0
+			default:
+				printf("  # Warning: unknown system event type=%d\n",
+				       cpu->kvm_run->system_event.type);
+				printf("  # Info: exiting KVMTOOL\n");
+				goto exit_kvm;
+			};
+			break;
 		default: {
 			bool ret;
 

Looks good to me.

Cheers,
Andre.

author
#9 lore raw

PATCH v4 4/4 kvmtool: ARM/ARM64: Provide PSCI-0.2 to guest when KVM supports it

In reply to Anup Patel

If in-kernel KVM support PSCI-0.2 emulation then we should set KVM_ARM_VCPU_PSCI_0_2 feature for each guest VCPU and also provide "arm,psci-0.2","arm,psci" as PSCI compatible string.

This patch updates kvm_cpu__arch_init() and setup_fdt() as per above.

---
 tools/kvm/arm/fdt.c     |   52 ++++++++++++++++++++++++++++++++++++++++++-----
 tools/kvm/arm/kvm-cpu.c |    5 +++++
 2 files changed, 52 insertions(+), 5 deletions(-)
tools/kvm/arm/fdt.c +47 -5
index 186a718..a15450e 100644
@@ -13,6 +13,7 @@
 #include <linux/byteorder.h>
 #include <linux/kernel.h>
 #include <linux/sizes.h>
+#include <linux/psci.h>
 
 static char kern_cmdline[COMMAND_LINE_SIZE];
 
@@ -84,6 +85,34 @@ static void generate_irq_prop(void *fdt, u8 irq)
 	_FDT(fdt_property(fdt, "interrupts", irq_prop, sizeof(irq_prop)));
 }
 
+struct psci_fns {
+	u32 cpu_suspend;
+	u32 cpu_off;
+	u32 cpu_on;
+	u32 migrate;
+};
+
+static struct psci_fns psci_0_1_fns = {
+	.cpu_suspend = KVM_PSCI_FN_CPU_SUSPEND,
+	.cpu_off = KVM_PSCI_FN_CPU_OFF,
+	.cpu_on = KVM_PSCI_FN_CPU_ON,
+	.migrate = KVM_PSCI_FN_MIGRATE,
+};
+
+static struct psci_fns psci_0_2_aarch32_fns = {
+	.cpu_suspend = PSCI_0_2_FN_CPU_SUSPEND,
+	.cpu_off = PSCI_0_2_FN_CPU_OFF,
+	.cpu_on = PSCI_0_2_FN_CPU_ON,
+	.migrate = PSCI_0_2_FN_MIGRATE,
+};
+
+static struct psci_fns psci_0_2_aarch64_fns = {
+	.cpu_suspend = PSCI_0_2_FN64_CPU_SUSPEND,
+	.cpu_off = PSCI_0_2_FN_CPU_OFF,
+	.cpu_on = PSCI_0_2_FN64_CPU_ON,
+	.migrate = PSCI_0_2_FN64_MIGRATE,
+};
+
 static int setup_fdt(struct kvm *kvm)
 {
 	struct device_header *dev_hdr;
@@ -93,6 +122,7 @@ static int setup_fdt(struct kvm *kvm)
 		cpu_to_fdt64(kvm->arch.memory_guest_start),
 		cpu_to_fdt64(kvm->ram_size),
 	};
+	struct psci_fns *fns;
 	void *fdt		= staging_fdt;
 	void *fdt_dest		= guest_flat_to_host(kvm,
 						     kvm->arch.dtb_guest_start);
@@ -162,12 +192,24 @@ static int setup_fdt(struct kvm *kvm)
 
 	/* PSCI firmware */
 	_FDT(fdt_begin_node(fdt, "psci"));
-	_FDT(fdt_property_string(fdt, "compatible", "arm,psci"));
+	if (kvm__supports_extension(kvm, KVM_CAP_ARM_PSCI_0_2)) {
+		const char compatible[] = "arm,psci-0.2\0arm,psci";
+		_FDT(fdt_property(fdt, "compatible",
+				  compatible, sizeof(compatible)));
+		if (kvm->cfg.arch.aarch32_guest) {
+			fns = &psci_0_2_aarch32_fns;
+		} else {
+			fns = &psci_0_2_aarch64_fns;
+		}
+	} else {
+		_FDT(fdt_property_string(fdt, "compatible", "arm,psci"));
+		fns = &psci_0_1_fns;
+	}
 	_FDT(fdt_property_string(fdt, "method", "hvc"));
-	_FDT(fdt_property_cell(fdt, "cpu_suspend", KVM_PSCI_FN_CPU_SUSPEND));
-	_FDT(fdt_property_cell(fdt, "cpu_off", KVM_PSCI_FN_CPU_OFF));
-	_FDT(fdt_property_cell(fdt, "cpu_on", KVM_PSCI_FN_CPU_ON));
-	_FDT(fdt_property_cell(fdt, "migrate", KVM_PSCI_FN_MIGRATE));
+	_FDT(fdt_property_cell(fdt, "cpu_suspend", fns->cpu_suspend));
+	_FDT(fdt_property_cell(fdt, "cpu_off", fns->cpu_off));
+	_FDT(fdt_property_cell(fdt, "cpu_on", fns->cpu_on));
+	_FDT(fdt_property_cell(fdt, "migrate", fns->migrate));
 	_FDT(fdt_end_node(fdt));
 
 	/* Finalise. */
tools/kvm/arm/kvm-cpu.c +5 -0
index 6de5344..219de16 100644
@@ -56,6 +56,11 @@ 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");
 
+	/* Set KVM_ARM_VCPU_PSCI_0_2 if available */
+	if (kvm__supports_extension(kvm, KVM_CAP_ARM_PSCI_0_2)) {
+		vcpu_init.features[0] |= (1UL << KVM_ARM_VCPU_PSCI_0_2);
+	}
+
 	/*
 	 * If preferred target ioctl successful then use preferred target
 	 * else try each and every target type.
Signature · 1 line
1.7.9.5
Reviewed-by on v4 4/4
#10 lore raw

Re: [PATCH v4 4/4] kvmtool: ARM/ARM64: Provide PSCI-0.2 to guest when KVM supports it

Hi Anup,

this looks good now, only one minor formatting thing below.

Quoted 73 lines · Anup Patel

If in-kernel KVM support PSCI-0.2 emulation then we should set KVM_ARM_VCPU_PSCI_0_2 feature for each guest VCPU and also provide "arm,psci-0.2","arm,psci" as PSCI compatible string.

This patch updates kvm_cpu__arch_init() and setup_fdt() as per above.

---
 tools/kvm/arm/fdt.c     |   52 ++++++++++++++++++++++++++++++++++++++++++-----
 tools/kvm/arm/kvm-cpu.c |    5 +++++
 2 files changed, 52 insertions(+), 5 deletions(-)
tools/kvm/arm/fdt.c +30 -0
index 186a718..a15450e 100644
@@ -13,6 +13,7 @@
 #include <linux/byteorder.h>
 #include <linux/kernel.h>
 #include <linux/sizes.h>
+#include <linux/psci.h>
 
 static char kern_cmdline[COMMAND_LINE_SIZE];
 
@@ -84,6 +85,34 @@ static void generate_irq_prop(void *fdt, u8 irq)
 	_FDT(fdt_property(fdt, "interrupts", irq_prop, sizeof(irq_prop)));
 }
 
+struct psci_fns {
+	u32 cpu_suspend;
+	u32 cpu_off;
+	u32 cpu_on;
+	u32 migrate;
+};
+
+static struct psci_fns psci_0_1_fns = {
+	.cpu_suspend = KVM_PSCI_FN_CPU_SUSPEND,
+	.cpu_off = KVM_PSCI_FN_CPU_OFF,
+	.cpu_on = KVM_PSCI_FN_CPU_ON,
+	.migrate = KVM_PSCI_FN_MIGRATE,
+};
+
+static struct psci_fns psci_0_2_aarch32_fns = {
+	.cpu_suspend = PSCI_0_2_FN_CPU_SUSPEND,
+	.cpu_off = PSCI_0_2_FN_CPU_OFF,
+	.cpu_on = PSCI_0_2_FN_CPU_ON,
+	.migrate = PSCI_0_2_FN_MIGRATE,
+};
+
+static struct psci_fns psci_0_2_aarch64_fns = {
+	.cpu_suspend = PSCI_0_2_FN64_CPU_SUSPEND,
+	.cpu_off = PSCI_0_2_FN_CPU_OFF,
+	.cpu_on = PSCI_0_2_FN64_CPU_ON,
+	.migrate = PSCI_0_2_FN64_MIGRATE,
+};
+
 static int setup_fdt(struct kvm *kvm)
 {
 	struct device_header *dev_hdr;
@@ -93,6 +122,7 @@ static int setup_fdt(struct kvm *kvm)
 		cpu_to_fdt64(kvm->arch.memory_guest_start),
 		cpu_to_fdt64(kvm->ram_size),
 	};
+	struct psci_fns *fns;
 	void *fdt		= staging_fdt;
 	void *fdt_dest		= guest_flat_to_host(kvm,
 						     kvm->arch.dtb_guest_start);
@@ -162,12 +192,24 @@ static int setup_fdt(struct kvm *kvm)
 
 	/* PSCI firmware */
 	_FDT(fdt_begin_node(fdt, "psci"));

tools/kvm/arm/fdt.c static int setup_fdt(struct kvm *kvm) · line 203

Quoted 10 lines
tools/kvm/arm/fdt.c +9 -1
-	_FDT(fdt_property_string(fdt, "compatible", "arm,psci"));
+	if (kvm__supports_extension(kvm, KVM_CAP_ARM_PSCI_0_2)) {
+		const char compatible[] = "arm,psci-0.2\0arm,psci";
+		_FDT(fdt_property(fdt, "compatible",
+				  compatible, sizeof(compatible)));
+		if (kvm->cfg.arch.aarch32_guest) {
+			fns = &psci_0_2_aarch32_fns;
+		} else {
+			fns = &psci_0_2_aarch64_fns;
+		}

You can remove the braces here.

Given that you fix that:

Thanks!
Andre

Quoted 33 lines
tools/kvm/arm/fdt.c +8 -4
+	} else {
+		_FDT(fdt_property_string(fdt, "compatible", "arm,psci"));
+		fns = &psci_0_1_fns;
+	}
 	_FDT(fdt_property_string(fdt, "method", "hvc"));
-	_FDT(fdt_property_cell(fdt, "cpu_suspend", KVM_PSCI_FN_CPU_SUSPEND));
-	_FDT(fdt_property_cell(fdt, "cpu_off", KVM_PSCI_FN_CPU_OFF));
-	_FDT(fdt_property_cell(fdt, "cpu_on", KVM_PSCI_FN_CPU_ON));
-	_FDT(fdt_property_cell(fdt, "migrate", KVM_PSCI_FN_MIGRATE));
+	_FDT(fdt_property_cell(fdt, "cpu_suspend", fns->cpu_suspend));
+	_FDT(fdt_property_cell(fdt, "cpu_off", fns->cpu_off));
+	_FDT(fdt_property_cell(fdt, "cpu_on", fns->cpu_on));
+	_FDT(fdt_property_cell(fdt, "migrate", fns->migrate));
 	_FDT(fdt_end_node(fdt));
 
 	/* Finalise. */
tools/kvm/arm/kvm-cpu.c +5 -0
index 6de5344..219de16 100644
@@ -56,6 +56,11 @@ 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");
 
+	/* Set KVM_ARM_VCPU_PSCI_0_2 if available */
+	if (kvm__supports_extension(kvm, KVM_CAP_ARM_PSCI_0_2)) {
+		vcpu_init.features[0] |= (1UL << KVM_ARM_VCPU_PSCI_0_2);
+	}
+
 	/*
 	 * If preferred target ioctl successful then use preferred target
 	 * else try each and every target type.