Skip to contentSkip to conversation

PSCI v0.2 support for KVM ARM/ARM64

PATCH Superseded Pranavkumar Sawargaonkar 3 participants 15 messages May 22, 2014 – May 23, 2014

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v6 cover PSCI v0.2 support for KVM ARM/ARM64

This patchset adds the QEMU side changes for providing PSCI v0.2 to VM.

ChangeLog:

V6:
- Add psci_version field in ARMCPU struct.
- Misc cleanups suggested on RFC V5 of this patch. ( http://www.spinics.net/lists/kvm-arm/msg09400.html)
- Dropping RFC prefix from patch.

V5:
- Updated "scripts/update-linux-headers.sh" to include linux/psci.h
- Synced linux headers using update-linux-headers.sh with linux-next tree
- Added per cpu field for kvm init features.
- Set psci-0.2 compatible string in generated dtb sucn that it works for guest kernel not having psci 0.2 support.
- Added QEMU_KVM_CAP_ARM_PSCI_0_2 define in target-arm/kvm-consts.h

V4:
- Rebase this patch against v11 patchset for in-kernel PSCI v0.2 emulation
(http://www.spinics.net/lists/kvm-arm/msg09182.html)
- Used PSCI 0.2 DT bindings for linux kernel.
(http://www.spinics.net/lists/arm-kernel/msg326044.html).

V3:
- Rebase this patchset against v8 patchset for in-kernel PSCI v0.2 emulation
(http://www.spinics.net/lists/kvm-arm/msg08780.html)
- Added common kvm_arm_vcpu_init() function for kvm arm and kvm arm64

V2:
- Rebase this patchset against v6 patchset for in-kernel PSCI v0.2 emulation
(http://www.spinics.net/lists/arm-kernel/msg319037.html)
- Handle KVM_EXIT_SYSTEM_EVENT in kvm-all.c:kvm_cpu_exec()
- Drop change in kvm_arm_get_host_cpu_features()
- Improve comments and description of kvm_arch_reset_vcpu() implementation

V1:
- Initial RFC patchset

Pranavkumar Sawargaonkar (8):
update-linux-headers.sh: Add psci.h to linux header sync-up script
linux-headers: Update KVM headers from linux-next tag next-20140508
kvm: Handle exit reason KVM_EXIT_SYSTEM_EVENT
target-arm: Common kvm_arm_vcpu_init() for KVM ARM and KVM ARM64
target-arm: Enable KVM_ARM_VCPU_PSCI_0_2 feature when possible
target-arm: Implement kvm_arch_reset_vcpu() for KVM ARM64
target-arm: Introduce per-CPU field for PSCI version hw/arm/virt: Use PSCI v0.2 compatible string when KVM or TCG provides
it

 hw/arm/virt.c                   |   16 ++++++-
 kvm-all.c                       |   16 +++++++
 linux-headers/asm-arm/kvm.h     |   10 +++--
 linux-headers/asm-arm64/kvm.h   |   10 +++--
 linux-headers/asm-s390/kvm.h    |   28 ++++++++++++
 linux-headers/linux/kvm.h       |   14 +++++-
 linux-headers/linux/psci.h      |   90 +++++++++++++++++++++++++++++++++++++++
 scripts/update-linux-headers.sh |    3 +-
 target-arm/cpu-qom.h            |    9 ++++
 target-arm/cpu.c                |    1 +
 target-arm/kvm.c                |   11 +++++
 target-arm/kvm32.c              |   16 ++++---
 target-arm/kvm64.c              |   26 ++++++++---
 target-arm/kvm_arm.h            |   12 ++++++
 14 files changed, 239 insertions(+), 23 deletions(-)
 create mode 100644 linux-headers/linux/psci.h
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v6 1/8 update-linux-headers.sh: Add psci.h to linux header sync-up script

We will be using linux/psci.h for KVM ARM/ARM64 hence add it to linux header sync-up script.

---
 scripts/update-linux-headers.sh |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/update-linux-headers.sh +2 -1
index 120a694..35d1960 100755
@@ -61,7 +61,8 @@ done
 
 rm -rf "$output/linux-headers/linux"
 mkdir -p "$output/linux-headers/linux"
-for header in kvm.h kvm_para.h vfio.h vhost.h virtio_config.h virtio_ring.h; do
+for header in kvm.h kvm_para.h psci.h vfio.h vhost.h virtio_config.h \
+virtio_ring.h; do
     cp "$tmpdir/include/linux/$header" "$output/linux-headers/linux"
 done
 rm -rf "$output/linux-headers/asm-generic"
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v6 2/8 linux-headers: Update KVM headers from linux-next tag next-20140508

In reply to Pranavkumar Sawargaonkar

Syncup KVM related linux headers from linux-next tree using scripts/update-linux-headers.sh.

---
 linux-headers/asm-arm/kvm.h   |   10 +++--
 linux-headers/asm-arm64/kvm.h |   10 +++--
 linux-headers/asm-s390/kvm.h  |   28 +++++++++++++
 linux-headers/linux/kvm.h     |   14 ++++++-
 linux-headers/linux/psci.h    |   90 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 143 insertions(+), 9 deletions(-)
 create mode 100644 linux-headers/linux/psci.h
linux-headers/asm-arm/kvm.h +6 -4
index ef0c878..e6ebdd3 100644
@@ -20,6 +20,7 @@
 #define __ARM_KVM_H__
 
 #include <linux/types.h>
+#include <linux/psci.h>
 #include <asm/ptrace.h>
 
 #define __KVM_HAVE_GUEST_DEBUG
@@ -83,6 +84,7 @@ struct kvm_regs {
 #define KVM_VGIC_V2_CPU_SIZE		0x2000
 
 #define KVM_ARM_VCPU_POWER_OFF		0 /* CPU is started in OFF state */
+#define KVM_ARM_VCPU_PSCI_0_2		1 /* CPU uses PSCI v0.2 */
 
 struct kvm_vcpu_init {
 	__u32 target;
@@ -201,9 +203,9 @@ struct kvm_arch_memory_slot {
 #define KVM_PSCI_FN_CPU_ON		KVM_PSCI_FN(2)
 #define KVM_PSCI_FN_MIGRATE		KVM_PSCI_FN(3)
 
-#define KVM_PSCI_RET_SUCCESS		0
-#define KVM_PSCI_RET_NI			((unsigned long)-1)
-#define KVM_PSCI_RET_INVAL		((unsigned long)-2)
-#define KVM_PSCI_RET_DENIED		((unsigned long)-3)
+#define KVM_PSCI_RET_SUCCESS		PSCI_RET_SUCCESS
+#define KVM_PSCI_RET_NI			PSCI_RET_NOT_SUPPORTED
+#define KVM_PSCI_RET_INVAL		PSCI_RET_INVALID_PARAMS
+#define KVM_PSCI_RET_DENIED		PSCI_RET_DENIED
 
 #endif /* __ARM_KVM_H__ */
linux-headers/asm-arm64/kvm.h +6 -4
index eaf54a3..e6471da 100644
@@ -31,6 +31,7 @@
 #define KVM_NR_SPSR	5
 
 #ifndef __ASSEMBLY__
+#include <linux/psci.h>
 #include <asm/types.h>
 #include <asm/ptrace.h>
 
@@ -77,6 +78,7 @@ struct kvm_regs {
 
 #define KVM_ARM_VCPU_POWER_OFF		0 /* CPU is started in OFF state */
 #define KVM_ARM_VCPU_EL1_32BIT		1 /* CPU running a 32bit VM */
+#define KVM_ARM_VCPU_PSCI_0_2		2 /* CPU uses PSCI v0.2 */
 
 struct kvm_vcpu_init {
 	__u32 target;
@@ -186,10 +188,10 @@ struct kvm_arch_memory_slot {
 #define KVM_PSCI_FN_CPU_ON		KVM_PSCI_FN(2)
 #define KVM_PSCI_FN_MIGRATE		KVM_PSCI_FN(3)
 
-#define KVM_PSCI_RET_SUCCESS		0
-#define KVM_PSCI_RET_NI			((unsigned long)-1)
-#define KVM_PSCI_RET_INVAL		((unsigned long)-2)
-#define KVM_PSCI_RET_DENIED		((unsigned long)-3)
+#define KVM_PSCI_RET_SUCCESS		PSCI_RET_SUCCESS
+#define KVM_PSCI_RET_NI			PSCI_RET_NOT_SUPPORTED
+#define KVM_PSCI_RET_INVAL		PSCI_RET_INVALID_PARAMS
+#define KVM_PSCI_RET_DENIED		PSCI_RET_DENIED
 
 #endif
 
linux-headers/asm-s390/kvm.h +28 -0
index c003c6a..98bedf3 100644
@@ -15,6 +15,7 @@
 #include <linux/types.h>
 
 #define __KVM_S390
+#define __KVM_HAVE_GUEST_DEBUG
 
 /* Device control API: s390-specific devices */
 #define KVM_DEV_FLIC_GET_ALL_IRQS	1
@@ -54,6 +55,13 @@ struct kvm_s390_io_adapter_req {
 	__u64 addr;
 };
 
+/* kvm attr_group  on vm fd */
+#define KVM_S390_VM_MEM_CTRL		0
+
+/* kvm attributes for mem_ctrl */
+#define KVM_S390_VM_MEM_ENABLE_CMMA	0
+#define KVM_S390_VM_MEM_CLR_CMMA	1
+
 /* for KVM_GET_REGS and KVM_SET_REGS */
 struct kvm_regs {
 	/* general purpose regs for s390 */
@@ -72,11 +80,31 @@ struct kvm_fpu {
 	__u64 fprs[16];
 };
 
+#define KVM_GUESTDBG_USE_HW_BP		0x00010000
+
+#define KVM_HW_BP			1
+#define KVM_HW_WP_WRITE			2
+#define KVM_SINGLESTEP			4
+
 struct kvm_debug_exit_arch {
+	__u64 addr;
+	__u8 type;
+	__u8 pad[7]; /* Should be set to 0 */
+};
+
+struct kvm_hw_breakpoint {
+	__u64 addr;
+	__u64 phys_addr;
+	__u64 len;
+	__u8 type;
+	__u8 pad[7]; /* Should be set to 0 */
 };
 
 /* for KVM_SET_GUEST_DEBUG */
 struct kvm_guest_debug_arch {
+	__u32 nr_hw_bp;
+	__u32 pad; /* Should be set to 0 */
+	struct kvm_hw_breakpoint *hw_bp;
 };
 
 #define KVM_SYNC_PREFIX (1UL << 0)
linux-headers/linux/kvm.h +13 -1
index b278ab3..6a9a0fc 100644
@@ -171,6 +171,7 @@ struct kvm_pit_config {
 #define KVM_EXIT_WATCHDOG         21
 #define KVM_EXIT_S390_TSCH        22
 #define KVM_EXIT_EPR              23
+#define KVM_EXIT_SYSTEM_EVENT     24
 
 /* For KVM_EXIT_INTERNAL_ERROR */
 /* Emulate instruction failed. */
@@ -301,6 +302,13 @@ struct kvm_run {
 		struct {
 			__u32 epr;
 		} epr;
+		/* KVM_EXIT_SYSTEM_EVENT */
+		struct {
+#define KVM_SYSTEM_EVENT_SHUTDOWN       1
+#define KVM_SYSTEM_EVENT_RESET          2
+			__u32 type;
+			__u64 flags;
+		} system_event;
 		/* Fix the size of the union. */
 		char padding[256];
 	};
@@ -515,6 +523,7 @@ enum {
 	kvm_ioeventfd_flag_nr_pio,
 	kvm_ioeventfd_flag_nr_deassign,
 	kvm_ioeventfd_flag_nr_virtio_ccw_notify,
+	kvm_ioeventfd_flag_nr_fast_mmio,
 	kvm_ioeventfd_flag_nr_max,
 };
 
@@ -529,7 +538,7 @@ enum {
 struct kvm_ioeventfd {
 	__u64 datamatch;
 	__u64 addr;        /* legal pio/mmio address */
-	__u32 len;         /* 1, 2, 4, or 8 bytes    */
+	__u32 len;         /* 1, 2, 4, or 8 bytes; or 0 to ignore length */
 	__s32 fd;
 	__u32 flags;
 	__u8  pad[36];
@@ -743,6 +752,9 @@ struct kvm_ppc_smmu_info {
 #define KVM_CAP_IOAPIC_POLARITY_IGNORED 97
 #define KVM_CAP_ENABLE_CAP_VM 98
 #define KVM_CAP_S390_IRQCHIP 99
+#define KVM_CAP_IOEVENTFD_NO_LENGTH 100
+#define KVM_CAP_VM_ATTRIBUTES 101
+#define KVM_CAP_ARM_PSCI_0_2 102
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
linux-headers/linux/psci.h new file +90 -0

90 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#5 lore raw

PATCH v6 3/8 kvm: Handle exit reason KVM_EXIT_SYSTEM_EVENT

In reply to Pranavkumar Sawargaonkar

In-kernel PSCI v0.2 emulation of KVM ARM/ARM64 forwards SYSTEM_OFF and SYSTEM_RESET function calls to QEMU using KVM_EXIT_SYSTEM_EVENT exit reason.

This patch updates kvm_cpu_exec() to handle KVM_SYSTEM_EVENT_SHUTDOWN and KVM_SYSTEM_EVENT_RESET system-level events from QEMU-side.

---
 kvm-all.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)
kvm-all.c +16 -0
index a343ede..f87c1d5 100644
@@ -1713,6 +1713,22 @@ int kvm_cpu_exec(CPUState *cpu)
         case KVM_EXIT_INTERNAL_ERROR:
             ret = kvm_handle_internal_error(cpu, run);
             break;
+        case KVM_EXIT_SYSTEM_EVENT:
+            switch (run->system_event.type) {
+            case KVM_SYSTEM_EVENT_SHUTDOWN:
+                qemu_system_shutdown_request();
+                ret = EXCP_INTERRUPT;
+                break;
+            case KVM_SYSTEM_EVENT_RESET:
+                qemu_system_reset_request();
+                ret = EXCP_INTERRUPT;
+                break;
+            default:
+                DPRINTF("kvm_arch_handle_exit\n");
+                ret = kvm_arch_handle_exit(cpu, run);
+                break;
+            }
+            break;
         default:
             DPRINTF("kvm_arch_handle_exit\n");
             ret = kvm_arch_handle_exit(cpu, run);
Signature · 1 line
1.7.9.5
#6 lore raw

PATCH v6 4/8 target-arm: Common kvm_arm_vcpu_init() for KVM ARM and KVM ARM64

In reply to Pranavkumar Sawargaonkar

Introduce a common kvm_arm_vcpu_init() for doing KVM_ARM_VCPU_INIT ioctl in KVM ARM and KVM ARM64. This also helps us factor-out few common code lines from kvm_arch_init_vcpu() for KVM ARM/ARM64.

---
 target-arm/cpu-qom.h |    3 +++
 target-arm/kvm.c     |   11 +++++++++++
 target-arm/kvm32.c   |   12 +++++++-----
 target-arm/kvm64.c   |   18 +++++++++++-------
 target-arm/kvm_arm.h |   12 ++++++++++++
 5 files changed, 44 insertions(+), 12 deletions(-)
target-arm/cpu-qom.h +3 -0
index edc7f26..2bd7df8 100644
@@ -102,6 +102,9 @@ typedef struct ARMCPU {
      */
     uint32_t kvm_target;
 
+    /* KVM init features for this CPU */
+    uint32_t kvm_init_features[7];
+
     /* The instance init functions for implementation-specific subclasses
      * set these fields to specify the implementation-dependent values of
      * various constant registers and reset values of non-constant
target-arm/kvm.c +11 -0
index 39202d7..319784d 100644
@@ -27,6 +27,17 @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
     KVM_CAP_LAST_INFO
 };
 
+int kvm_arm_vcpu_init(CPUState *cs)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    struct kvm_vcpu_init init;
+
+    init.target = cpu->kvm_target;
+    memcpy(init.features, cpu->kvm_init_features, sizeof(init.features));
+
+    return kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init);
+}
+
 bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try,
                                       int *fdarray,
                                       struct kvm_vcpu_init *init)
target-arm/kvm32.c +7 -5
index b79750c..b142e90 100644
@@ -166,7 +166,6 @@ static int compare_u64(const void *a, const void *b)
 
 int kvm_arch_init_vcpu(CPUState *cs)
 {
-    struct kvm_vcpu_init init;
     int i, ret, arraylen;
     uint64_t v;
     struct kvm_one_reg r;
@@ -179,15 +178,18 @@ int kvm_arch_init_vcpu(CPUState *cs)
         return -EINVAL;
     }
 
-    init.target = cpu->kvm_target;
-    memset(init.features, 0, sizeof(init.features));
+    /* Determine init features for this CPU */
+    memset(cpu->kvm_init_features, 0, sizeof(cpu->kvm_init_features));
     if (cpu->start_powered_off) {
-        init.features[0] = 1 << KVM_ARM_VCPU_POWER_OFF;
+        cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_POWER_OFF;
     }
-    ret = kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init);
+
+    /* Do KVM_ARM_VCPU_INIT ioctl */
+    ret = kvm_arm_vcpu_init(cs);
     if (ret) {
         return ret;
     }
+
     /* Query the kernel to make sure it supports 32 VFP
      * registers: QEMU's "cortex-a15" CPU is always a
      * VFP-D32 core. The simplest way to do this is just
target-arm/kvm64.c +11 -7
index c729b9e..1980ddc 100644
@@ -77,9 +77,8 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUClass *ahcc)
 
 int kvm_arch_init_vcpu(CPUState *cs)
 {
-    ARMCPU *cpu = ARM_CPU(cs);
-    struct kvm_vcpu_init init;
     int ret;
+    ARMCPU *cpu = ARM_CPU(cs);
 
     if (cpu->kvm_target == QEMU_KVM_ARM_TARGET_NONE ||
         !arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
@@ -87,16 +86,21 @@ int kvm_arch_init_vcpu(CPUState *cs)
         return -EINVAL;
     }
 
-    init.target = cpu->kvm_target;
-    memset(init.features, 0, sizeof(init.features));
+    /* Determine init features for this CPU */
+    memset(cpu->kvm_init_features, 0, sizeof(cpu->kvm_init_features));
     if (cpu->start_powered_off) {
-        init.features[0] = 1 << KVM_ARM_VCPU_POWER_OFF;
+        cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_POWER_OFF;
+    }
+
+    /* Do KVM_ARM_VCPU_INIT ioctl */
+    ret = kvm_arm_vcpu_init(cs);
+    if (ret) {
+        return ret;
     }
-    ret = kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init);
 
     /* TODO : support for save/restore/reset of system regs via tuple list */
 
-    return ret;
+    return 0;
 }
 
 #define AARCH64_CORE_REG(x)   (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \
target-arm/kvm_arm.h +12 -0
index dc4e233..af93105 100644
@@ -15,6 +15,18 @@
 #include "exec/memory.h"
 
 /**
+ * kvm_arm_vcpu_init:
+ * @cs: CPUState
+ *
+ * Initialize (or reinitialize) the VCPU by invoking the
+ * KVM_ARM_VCPU_INIT ioctl with the CPU type and feature
+ * bitmask specified in the CPUState.
+ *
+ * Returns: 0 if success else < 0 error code
+ */
+int kvm_arm_vcpu_init(CPUState *cs);
+
+/**
  * kvm_arm_register_device:
  * @mr: memory region for this device
  * @devid: the KVM device ID
Signature · 1 line
1.7.9.5
#8 lore raw

PATCH v6 5/8 target-arm: Enable KVM_ARM_VCPU_PSCI_0_2 feature when possible

In reply to Pranavkumar Sawargaonkar

Latest linux kernel supports in-kernel emulation of PSCI v0.2 but to enable it we need to select KVM_ARM_VCPU_PSCI_0_2 feature using KVM_ARM_VCPU_INIT ioctl.

Also, we can use KVM_ARM_VCPU_PSCI_0_2 feature for VCPU only when linux kernel has KVM_CAP_ARM_PSCI_0_2 capability.

This patch updates kvm_arch_init_vcpu() to enable KVM_ARM_VCPU_PSCI_0_2 feature for VCPU when KVM ARM/ARM64 has KVM_CAP_ARM_PSCI_0_2 capability.

---
 target-arm/kvm32.c |    3 +++
 target-arm/kvm64.c |    3 +++
 2 files changed, 6 insertions(+)
target-arm/kvm32.c +3 -0
index b142e90..52d626c 100644
@@ -183,6 +183,9 @@ int kvm_arch_init_vcpu(CPUState *cs)
     if (cpu->start_powered_off) {
         cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_POWER_OFF;
     }
+    if (kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PSCI_0_2)) {
+        cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2;
+    }
 
     /* Do KVM_ARM_VCPU_INIT ioctl */
     ret = kvm_arm_vcpu_init(cs);
target-arm/kvm64.c +3 -0
index 1980ddc..dcf621f 100644
@@ -91,6 +91,9 @@ int kvm_arch_init_vcpu(CPUState *cs)
     if (cpu->start_powered_off) {
         cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_POWER_OFF;
     }
+    if (kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PSCI_0_2)) {
+        cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2;
+    }
 
     /* Do KVM_ARM_VCPU_INIT ioctl */
     ret = kvm_arm_vcpu_init(cs);
Signature · 1 line
1.7.9.5
#10 lore raw

PATCH v6 6/8 target-arm: Implement kvm_arch_reset_vcpu() for KVM ARM64

In reply to Pranavkumar Sawargaonkar

To implement kvm_arch_reset_vcpu(), we simply re-init the VCPU using kvm_arm_vcpu_init() so that all registers of VCPU are set to their reset values by in-kernel KVM code.

---
 target-arm/kvm64.c |    4 ++++
 1 file changed, 4 insertions(+)
target-arm/kvm64.c +4 -0
index dcf621f..feeac4a 100644
@@ -269,4 +269,8 @@ int kvm_arch_get_registers(CPUState *cs)
 
 void kvm_arm_reset_vcpu(ARMCPU *cpu)
 {
+    /* Re-init VCPU so that all registers are set to
+     * their respective reset values.
+     */
+    kvm_arm_vcpu_init(CPU(cpu));
 }
Signature · 1 line
1.7.9.5
#11 lore raw

PATCH v6 7/8 target-arm: Introduce per-CPU field for PSCI version

In reply to Pranavkumar Sawargaonkar

We require to know the PSCI version available to given CPU at potentially many places. Currently, we need to know PSCI version when generating DTB for virt machine.

This patch introduce per-CPU 32bit field representing the PSCI version available to the CPU. The encoding of this 32bit field is same as described in PSCI v0.2 spec.

---
 target-arm/cpu-qom.h |    6 ++++++
 target-arm/cpu.c     |    1 +
 target-arm/kvm32.c   |    1 +
 target-arm/kvm64.c   |    1 +
 4 files changed, 9 insertions(+)
target-arm/cpu-qom.h +6 -0
index 2bd7df8..eaee944 100644
@@ -94,6 +94,12 @@ typedef struct ARMCPU {
     /* 'compatible' string for this CPU for Linux device trees */
     const char *dtb_compatible;
 
+    /* PSCI version for this CPU
+     * Bits[31:16] = Major Version
+     * Bits[15:0] = Minor Version
+     */
+    uint32_t psci_version;
+
     /* Should CPU start in PSCI powered-off state? */
     bool start_powered_off;
 
target-arm/cpu.c +1 -0
index 6c6f2b3..589f34d 100644
@@ -260,6 +260,7 @@ static void arm_cpu_initfn(Object *obj)
      * picky DTB consumer will also provide a helpful error message.
      */
     cpu->dtb_compatible = "qemu,unknown";
+    cpu->psci_version = 1; /* By default assume PSCI v0.1 */
     cpu->kvm_target = QEMU_KVM_ARM_TARGET_NONE;
 
     if (tcg_enabled() && !inited) {
target-arm/kvm32.c +1 -0
index 52d626c..068af7d 100644
@@ -184,6 +184,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
         cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_POWER_OFF;
     }
     if (kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PSCI_0_2)) {
+        cpu->psci_version = 2;
         cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2;
     }
 
target-arm/kvm64.c +1 -0
index feeac4a..2634baf 100644
@@ -92,6 +92,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
         cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_POWER_OFF;
     }
     if (kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PSCI_0_2)) {
+        cpu->psci_version = 2;
         cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2;
     }
 
Signature · 1 line
1.7.9.5
#13 lore raw

PATCH v6 8/8 hw/arm/virt: Use PSCI v0.2 compatible string when KVM or TCG provides it

In reply to Pranavkumar Sawargaonkar

If we have PSCI v0.2 emulation available for KVM ARM/ARM64 or TCG then we need to provide PSCI v0.2 compatible string via generated DTB.

---
 hw/arm/virt.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
hw/arm/virt.c +15 -1
index ea4f02d..442363c 100644
@@ -180,10 +180,23 @@ static void create_fdt(VirtBoardInfo *vbi)
                                 "clk24mhz");
     qemu_fdt_setprop_cell(fdt, "/apb-pclk", "phandle", vbi->clock_phandle);
 
+}
+
+static void fdt_add_psci_node(const VirtBoardInfo *vbi)
+{
+    void *fdt = vbi->fdt;
+    ARMCPU *armcpu = ARM_CPU(qemu_get_cpu(0));
+
     /* No PSCI for TCG yet */
     if (kvm_enabled()) {
         qemu_fdt_add_subnode(fdt, "/psci");
-        qemu_fdt_setprop_string(fdt, "/psci", "compatible", "arm,psci");
+        if (armcpu->psci_version == 2) {
+            const char comp[] = "arm,psci-0.2\0arm,psci";
+            qemu_fdt_setprop(fdt, "/psci", "compatible", comp, sizeof(comp));
+        } else {
+            qemu_fdt_setprop_string(fdt, "/psci", "compatible", "arm,psci");
+        }
+
         qemu_fdt_setprop_string(fdt, "/psci", "method", "hvc");
         qemu_fdt_setprop_cell(fdt, "/psci", "cpu_suspend",
                                   PSCI_FN_CPU_SUSPEND);
@@ -446,6 +459,7 @@ static void machvirt_init(QEMUMachineInitArgs *args)
         object_property_set_bool(cpuobj, true, "realized", NULL);
     }
     fdt_add_cpu_nodes(vbi);
+    fdt_add_psci_node(vbi);
 
     memory_region_init_ram(ram, NULL, "mach-virt.ram", args->ram_size);
     vmstate_register_ram_global(ram);
Signature · 1 line
1.7.9.5
Reviewed-by on v6 8/8
#14 lore raw

Re: [Qemu-devel] [PATCH V6 8/8] hw/arm/virt: Use PSCI v0.2 compatible string when KVM or TCG provides it

Quoted 5 lines · Pranavkumar Sawargaonkar

If we have PSCI v0.2 emulation available for KVM ARM/ARM64 or TCG then we need to provide PSCI v0.2 compatible string via generated DTB.

Quoted 44 lines
---
 hw/arm/virt.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
hw/arm/virt.c +15 -2
index ea4f02d..442363c 100644
@@ -180,10 +180,23 @@ static void create_fdt(VirtBoardInfo *vbi)
                                 "clk24mhz");
     qemu_fdt_setprop_cell(fdt, "/apb-pclk", "phandle", vbi->clock_phandle);
 
+}
+
+static void fdt_add_psci_node(const VirtBoardInfo *vbi)
+{
+    void *fdt = vbi->fdt;
+    ARMCPU *armcpu = ARM_CPU(qemu_get_cpu(0));
+
     /* No PSCI for TCG yet */
     if (kvm_enabled()) {
         qemu_fdt_add_subnode(fdt, "/psci");
-        qemu_fdt_setprop_string(fdt, "/psci", "compatible", "arm,psci");
+        if (armcpu->psci_version == 2) {
+            const char comp[] = "arm,psci-0.2\0arm,psci";
+            qemu_fdt_setprop(fdt, "/psci", "compatible", comp, sizeof(comp));
+        } else {
+            qemu_fdt_setprop_string(fdt, "/psci", "compatible", "arm,psci");
+        }
+
         qemu_fdt_setprop_string(fdt, "/psci", "method", "hvc");
         qemu_fdt_setprop_cell(fdt, "/psci", "cpu_suspend",
                                   PSCI_FN_CPU_SUSPEND);
@@ -446,6 +459,7 @@ static void machvirt_init(QEMUMachineInitArgs *args)
         object_property_set_bool(cpuobj, true, "realized", NULL);
     }
     fdt_add_cpu_nodes(vbi);
+    fdt_add_psci_node(vbi);
 
     memory_region_init_ram(ram, NULL, "mach-virt.ram", args->ram_size);
     vmstate_register_ram_global(ram);
--

1.7.9.5

Reviewed-by on v6 1/8
#2 lore raw

Re: [Qemu-devel] [PATCH V6 1/8] update-linux-headers.sh: Add psci.h to linux header sync-up script

In reply to Pranavkumar Sawargaonkar
Quoted 14 lines · Pranavkumar Sawargaonkar

We will be using linux/psci.h for KVM ARM/ARM64 hence add it to linux header sync-up script.

---
 scripts/update-linux-headers.sh |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/update-linux-headers.sh +0 -0
index 120a694..35d1960 100755

scripts/update-linux-headers.sh done · line 65

Quoted 6 lines
scripts/update-linux-headers.sh +2 -1
@@ -61,7 +61,8 @@ done
 
 rm -rf "$output/linux-headers/linux"
 mkdir -p "$output/linux-headers/linux"
-for header in kvm.h kvm_para.h vfio.h vhost.h virtio_config.h virtio_ring.h; do
+for header in kvm.h kvm_para.h psci.h vfio.h vhost.h virtio_config.h \
+virtio_ring.h; do

This continued line should be indented, not just sat in column 1.

Otherwise

Quoted 6 lines
scripts/update-linux-headers.sh +0 -1
     cp "$tmpdir/include/linux/$header" "$output/linux-headers/linux"
 done
 rm -rf "$output/linux-headers/asm-generic"
--

1.7.9.5

thanks
-- PMM

#4 lore raw

Re: [Qemu-devel] [PATCH V6 2/8] linux-headers: Update KVM headers from linux-next tag next-20140508

In reply to Pranavkumar Sawargaonkar
Quoted 2 lines · Pranavkumar Sawargaonkar

Syncup KVM related linux headers from linux-next tree using scripts/update-linux-headers.sh.

We can't apply syncs against linux-next; have to wait for these to at least get into kvm-next. Christoffer said he'd be sending out the pull request for that today.

thanks
-- PMM

Reviewed-by on v6 4/8
#7 lore raw

Re: [Qemu-devel] [PATCH V6 4/8] target-arm: Common kvm_arm_vcpu_init() for KVM ARM and KVM ARM64

In reply to Pranavkumar Sawargaonkar
Quoted 6 lines · Pranavkumar Sawargaonkar

Introduce a common kvm_arm_vcpu_init() for doing KVM_ARM_VCPU_INIT ioctl in KVM ARM and KVM ARM64. This also helps us factor-out few common code lines from kvm_arch_init_vcpu() for KVM ARM/ARM64.

-- PMM

Reviewed-by on v6 5/8
#9 lore raw

Re: [Qemu-devel] [PATCH V6 5/8] target-arm: Enable KVM_ARM_VCPU_PSCI_0_2 feature when possible

In reply to Pranavkumar Sawargaonkar
Quoted 4 lines · Pranavkumar Sawargaonkar

Latest linux kernel supports in-kernel emulation of PSCI v0.2 but to enable it we need to select KVM_ARM_VCPU_PSCI_0_2 feature using KVM_ARM_VCPU_INIT ioctl.

Quoted 8 lines

Also, we can use KVM_ARM_VCPU_PSCI_0_2 feature for VCPU only when linux kernel has KVM_CAP_ARM_PSCI_0_2 capability.

This patch updates kvm_arch_init_vcpu() to enable KVM_ARM_VCPU_PSCI_0_2 feature for VCPU when KVM ARM/ARM64 has KVM_CAP_ARM_PSCI_0_2 capability.

-- PMM

Reviewed-by on v6 7/8
#12 lore raw

Re: [Qemu-devel] [PATCH V6 7/8] target-arm: Introduce per-CPU field for PSCI version

In reply to Pranavkumar Sawargaonkar
Quoted 11 lines · Pranavkumar Sawargaonkar

We require to know the PSCI version available to given CPU at potentially many places. Currently, we need to know PSCI version when generating DTB for virt machine.

This patch introduce per-CPU 32bit field representing the PSCI version available to the CPU. The encoding of this 32bit field is same as described in PSCI v0.2 spec.

---

-- PMM