Skip to contentSkip to conversation

Target CPU=Host implementation for KVM ARM/ARM64

PATCH New Anup Patel 3 participants 8 messages Sep 30, 2013 – Oct 2, 2013

Subsystems (5)
Documentation Arm (32-bit) KVM arm64 +1 more subsystems
lore
Share & tools
lore

Anup Patel

author
#0 lore raw

v5 cover Target CPU=Host implementation for KVM ARM/ARM64

It will be very useful for user space (QEMU/KVMTOOL) if it has a method of querying VCPU target type matching to underlying Host. We can use such querying mechanism and implement machine models in user space where VCPU target type is always same-as/similar-to underlying Host (i.e. Target CPU=Host).

This patch series implements KVM_ARM_PREFERRED_TARGET vm ioclt for querying VCPU target type matching underlying host. Using this new ioctl we can implement VCPU target CPU=Host in user space.

Also, it is not mandatory to call KVM_ARM_PREFERRED_TARGET vm ioctl and the old method of trying all possible target types using the KVM_ARM_VCPU_INIT ioctl to initialize VCPU works fine.

V5:
- Update documentation based on review comments

V4:
- Fixed files exchanged between patches
- For now return zeroed features in struct kvm_vcpu_init instance

V3:
- Return -ENODEV if no preferred target available for host
- Make KVM_ARM_PREFERRED_TARGET ioctl as vm ioctl

V2:
- Renamed the ioclt to KVM_ARM_PREFERRED_TARGET
- Return struct kvm_vcpu_init instace instead of just target type

V1:
- Initial patch-set with ioctl named as KVM_ARM_SUITABLE_TARGET

Anup Patel (4):
ARM: KVM: Implement kvm_vcpu_preferred_target() function
ARM64: KVM: Implement kvm_vcpu_preferred_target() function ARM/ARM64: KVM: Implement KVM_ARM_PREFERRED_TARGET ioctl
KVM: Add documentation for KVM_ARM_PREFERRED_TARGET ioctl

 Documentation/virtual/kvm/api.txt |   31 +++++++++++++++++++++++++++----
 arch/arm/include/asm/kvm_host.h   |    1 +
 arch/arm/kvm/arm.c                |   13 +++++++++++++
 arch/arm/kvm/guest.c              |   20 ++++++++++++++++++++
 arch/arm64/include/asm/kvm_host.h |    1 +
 arch/arm64/kvm/guest.c            |   20 ++++++++++++++++++++
 include/uapi/linux/kvm.h          |    1 +
 7 files changed, 83 insertions(+), 4 deletions(-)
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH v5 1/4 ARM: KVM: Implement kvm_vcpu_preferred_target() function

This patch implements kvm_vcpu_preferred_target() function for KVM ARM which will help us implement KVM_ARM_PREFERRED_TARGET ioctl for user space.

---
 arch/arm/include/asm/kvm_host.h |    1 +
 arch/arm/kvm/guest.c            |   20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)
arch/arm/include/asm/kvm_host.h +1 -0
index 7d22517..76f3c19 100644
@@ -154,6 +154,7 @@ struct kvm_vcpu_stat {
 struct kvm_vcpu_init;
 int kvm_vcpu_set_target(struct kvm_vcpu *vcpu,
 			const struct kvm_vcpu_init *init);
+int kvm_vcpu_preferred_target(struct kvm_vcpu_init *init);
 unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu);
 int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices);
 struct kvm_one_reg;
arch/arm/kvm/guest.c +20 -0
index 152d036..21beea0 100644
@@ -222,6 +222,26 @@ int kvm_vcpu_set_target(struct kvm_vcpu *vcpu,
 	return kvm_reset_vcpu(vcpu);
 }
 
+int kvm_vcpu_preferred_target(struct kvm_vcpu_init *init)
+{
+	int target = kvm_target_cpu();
+
+	if (target < 0)
+		return -ENODEV;
+
+	memset(init, 0, sizeof(*init));
+
+	/* 
+	 * For now, we don't return any features.
+	 * In future, we might use features to return target
+	 * specific features available for the preferred
+	 * target type.
+	 */
+	init->target = (__u32)target;
+
+	return 0;
+}
+
 int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
 {
 	return -EINVAL;
Signature · 1 line
1.7.9.5
author
#2 lore raw

PATCH v5 2/4 ARM64: KVM: Implement kvm_vcpu_preferred_target() function

In reply to Anup Patel

This patch implements kvm_vcpu_preferred_target() function for KVM ARM64 which will help us implement KVM_ARM_PREFERRED_TARGET ioctl for user space.

---
 arch/arm64/include/asm/kvm_host.h |    1 +
 arch/arm64/kvm/guest.c            |   20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)
arch/arm64/include/asm/kvm_host.h +1 -0
index f318c43..b609db3 100644
@@ -156,6 +156,7 @@ struct kvm_vcpu_stat {
 struct kvm_vcpu_init;
 int kvm_vcpu_set_target(struct kvm_vcpu *vcpu,
 			const struct kvm_vcpu_init *init);
+int kvm_vcpu_preferred_target(struct kvm_vcpu_init *init);
 unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu);
 int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices);
 struct kvm_one_reg;
arch/arm64/kvm/guest.c +20 -0
index d7bf7d6..94e4b7a 100644
@@ -254,6 +254,26 @@ int kvm_vcpu_set_target(struct kvm_vcpu *vcpu,
 	return kvm_reset_vcpu(vcpu);
 }
 
+int kvm_vcpu_preferred_target(struct kvm_vcpu_init *init)
+{
+	int target = kvm_target_cpu();
+
+	if (target < 0)
+		return -ENODEV;
+
+	memset(init, 0, sizeof(*init));
+
+	/* 
+	 * For now, we don't return any features.
+	 * In future, we might use features to return target
+	 * specific features available for the preferred
+	 * target type.
+	 */
+	init->target = (__u32)target;
+
+	return 0;
+}
+
 int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
 {
 	return -EINVAL;
Signature · 1 line
1.7.9.5
author
#3 lore raw

PATCH v5 3/4 ARM/ARM64: KVM: Implement KVM_ARM_PREFERRED_TARGET ioctl

In reply to Anup Patel

For implementing CPU=host, we need a mechanism for querying preferred VCPU target type on underlying Host.

This patch implements KVM_ARM_PREFERRED_TARGET vm ioctl which returns struct kvm_vcpu_init instance containing information about preferred VCPU target type and target specific features available for it.

---
 arch/arm/kvm/arm.c       |   13 +++++++++++++
 include/uapi/linux/kvm.h |    1 +
 2 files changed, 14 insertions(+)
arch/arm/kvm/arm.c +13 -0
index 9c697db..cc5adb9 100644
@@ -797,6 +797,19 @@ long kvm_arch_vm_ioctl(struct file *filp,
 			return -EFAULT;
 		return kvm_vm_ioctl_set_device_addr(kvm, &dev_addr);
 	}
+	case KVM_ARM_PREFERRED_TARGET: {
+		int err;
+		struct kvm_vcpu_init init;
+
+		err = kvm_vcpu_preferred_target(&init);
+		if (err)
+			return err;
+
+		if (copy_to_user(argp, &init, sizeof(init)))
+			return -EFAULT;
+
+		return 0;
+	}
 	default:
 		return -EINVAL;
 	}
include/uapi/linux/kvm.h +1 -0
index 99c2533..e32e776 100644
@@ -1012,6 +1012,7 @@ struct kvm_s390_ucas_mapping {
 /* VM is being stopped by host */
 #define KVM_KVMCLOCK_CTRL	  _IO(KVMIO,   0xad)
 #define KVM_ARM_VCPU_INIT	  _IOW(KVMIO,  0xae, struct kvm_vcpu_init)
+#define KVM_ARM_PREFERRED_TARGET  _IOR(KVMIO,  0xaf, struct kvm_vcpu_init)
 #define KVM_GET_REG_LIST	  _IOWR(KVMIO, 0xb0, struct kvm_reg_list)
 
 #define KVM_DEV_ASSIGN_ENABLE_IOMMU	(1 << 0)
Signature · 1 line
1.7.9.5
author
#4 lore raw

PATCH v5 4/4 KVM: Add documentation for KVM_ARM_PREFERRED_TARGET ioctl

In reply to Anup Patel

To implement CPU=Host we have added KVM_ARM_PREFERRED_TARGET vm ioctl which provides information to user space required for creating VCPU matching underlying Host.

This patch adds info related to this new KVM_ARM_PREFERRED_TARGET vm ioctl in the KVM API documentation.

---
 Documentation/virtual/kvm/api.txt |   31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)
Documentation/virtual/kvm/api.txt +27 -4
index 858aecf..076b849 100644
@@ -2304,7 +2304,31 @@ Possible features:
 	  Depends on KVM_CAP_ARM_EL1_32BIT (arm64 only).
 
 
-4.83 KVM_GET_REG_LIST
+4.83 KVM_ARM_PREFERRED_TARGET
+
+Capability: basic
+Architectures: arm, arm64
+Type: vm ioctl
+Parameters: struct struct kvm_vcpu_init (out)
+Returns: 0 on success; -1 on error
+Errors:
+ ?ENODEV: ???no preferred target available for the host
+
+This queries KVM for preferred CPU target type which can be emulated
+by KVM on underlying host.
+
+The ioctl returns struct kvm_vcpu_init instance containing information
+about preferred CPU target type and recommended features for it.  The
+kvm_vcpu_init->features bitmap returned will have feature bits set if
+the preferred target recommends setting these features, but this is
+not mandatory.
+
+The information returned by this ioctl can be used to prepare an instance
+of struct kvm_vcpu_init for KVM_ARM_VCPU_INIT ioctl which will result in
+in VCPU matching underlying host.
+
+
+4.84 KVM_GET_REG_LIST
 
 Capability: basic
 Architectures: arm, arm64
@@ -2323,8 +2347,7 @@ struct kvm_reg_list {
 This ioctl returns the guest registers that are supported for the
 KVM_GET_ONE_REG/KVM_SET_ONE_REG calls.
 
-
-4.84 KVM_ARM_SET_DEVICE_ADDR
+4.85 KVM_ARM_SET_DEVICE_ADDR
 
 Capability: KVM_CAP_ARM_SET_DEVICE_ADDR
 Architectures: arm, arm64
@@ -2362,7 +2385,7 @@ must be called after calling KVM_CREATE_IRQCHIP, but before calling
 KVM_RUN on any of the VCPUs.  Calling this ioctl twice for any of the
 base addresses will return -EEXIST.
 
-4.85 KVM_PPC_RTAS_DEFINE_TOKEN
+4.86 KVM_PPC_RTAS_DEFINE_TOKEN
 
 Capability: KVM_CAP_PPC_RTAS
 Architectures: ppc
Signature · 1 line
1.7.9.5
#5 lore raw

v5 cover Target CPU=Host implementation for KVM ARM/ARM64

In reply to Anup Patel
Quoted 6 lines · Anup Patel

It will be very useful for user space (QEMU/KVMTOOL) if it has a method of querying VCPU target type matching to underlying Host. We can use such querying mechanism and implement machine models in user space where VCPU target type is always same-as/similar-to underlying Host (i.e. Target CPU=Host).

Quoted 8 lines

This patch series implements KVM_ARM_PREFERRED_TARGET vm ioclt for querying VCPU target type matching underlying host. Using this new ioctl we can implement VCPU target CPU=Host in user space.

Also, it is not mandatory to call KVM_ARM_PREFERRED_TARGET vm ioctl and the old method of trying all possible target types using the KVM_ARM_VCPU_INIT ioctl to initialize VCPU works fine.

Looks good to me, as soon as Marc acks this one, I'll merge it.

-Christoffer

#6 lore raw

v5 cover Target CPU=Host implementation for KVM ARM/ARM64

Quoted 11 lines · Christoffer Dall
Quoted 10 lines · Anup Patel

It will be very useful for user space (QEMU/KVMTOOL) if it has a method of querying VCPU target type matching to underlying Host. We can use such querying mechanism and implement machine models in user space where VCPU target type is always same-as/similar-to underlying Host (i.e. Target CPU=Host).

This patch series implements KVM_ARM_PREFERRED_TARGET vm ioclt for querying VCPU target type matching underlying host. Using this new ioctl we can implement VCPU target CPU=Host in user space.

Quoted 5 lines
Quoted 4 lines

Also, it is not mandatory to call KVM_ARM_PREFERRED_TARGET vm ioctl and the old method of trying all possible target types using the KVM_ARM_VCPU_INIT ioctl to initialize VCPU works fine.

Looks good to me, as soon as Marc acks this one, I'll merge it.

Yup, go for it:

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#7 lore raw

v5 cover Target CPU=Host implementation for KVM ARM/ARM64

Quoted 16 lines · Marc Zyngier
Quoted 15 lines · Christoffer Dall
Quoted 14 lines · Anup Patel

It will be very useful for user space (QEMU/KVMTOOL) if it has a method of querying VCPU target type matching to underlying Host. We can use such querying mechanism and implement machine models in user space where VCPU target type is always same-as/similar-to underlying Host (i.e. Target CPU=Host).

This patch series implements KVM_ARM_PREFERRED_TARGET vm ioclt for querying VCPU target type matching underlying host. Using this new ioctl we can implement VCPU target CPU=Host in user space.

Also, it is not mandatory to call KVM_ARM_PREFERRED_TARGET vm ioctl and the old method of trying all possible target types using the KVM_ARM_VCPU_INIT ioctl to initialize VCPU works fine.

Quoted 6 lines
Quoted 1 line

Looks good to me, as soon as Marc acks this one, I'll merge it.

Yup, go for it:

Cool, merged in kvm-arm-next, tested with changes to experimental qemu mach-virt patches on vexpress TC2.

-Christoffer