PSCI v0.2 support for KVM ARM/ARM64
v2 cover PSCI v0.2 support for KVM ARM/ARM64
Recentely patches have been posted for in-kernel emulation of PSCI v0.2
http://www.spinics.net/lists/arm-kernel/msg305467.html
This patchset adds the QEMU side changes for providing PSCI v0.2 to VM.
ChangeLog:
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 (6):
linux-headers: Update KVM headers from v3.14
kvm: Handle exit reason KVM_EXIT_SYSTEM_EVENT
target-arm: Enable KVM_ARM_VCPU_PSCI_0_2 feature when possible
target-arm: Implement kvm_arch_reset_vcpu() for KVM ARM64
target-arm: Provide PSCI v0.2 constants to generic QEMU code hw/arm/virt: Use PSCI v0.2 function IDs when kernel supports its
hw/arm/virt.c | 28 ++++++++++++++---- kvm-all.c | 16 +++++++++++ linux-headers/asm-arm/kvm.h | 19 +++++++------ linux-headers/asm-arm64/kvm.h | 21 +++++++------- linux-headers/linux/kvm.h | 10 +++++++ linux-headers/linux/psci.h | 55 +++++++++++++++++++++++++++++++++++ target-arm/kvm-consts.h | 63 ++++++++++++++++++++++++++++++++++------- target-arm/kvm32.c | 5 +++- target-arm/kvm64.c | 9 +++++- 9 files changed, 189 insertions(+), 37 deletions(-) create mode 100644 linux-headers/linux/psci.h
Signature · 1 line
1.7.9.5
RFC PATCH v2 1/6 linux-headers: Update KVM headers from v3.14
Syncup KVM related linux headers from v3.14.
--- linux-headers/asm-arm/kvm.h | 19 +++++++------- linux-headers/asm-arm64/kvm.h | 21 ++++++++-------- linux-headers/linux/kvm.h | 10 ++++++++ linux-headers/linux/psci.h | 55 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 19 deletions(-) create mode 100644 linux-headers/linux/psci.h
linux-headers/asm-arm/kvm.h +10 -9
@@ -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;
@@ -194,16 +196,15 @@ struct kvm_arch_memory_slot {/* PSCI interface */ #define KVM_PSCI_FN_BASE 0x95c1ba5e -#define KVM_PSCI_FN (n) (KVM_PSCI_FN_BASE + (n)) -#define KVM_PSCI_FN_CPU_SUSPEND KVM_PSCI_FN(0) -#define KVM_PSCI_FN_CPU_OFF KVM_PSCI_FN(1) -#define KVM_PSCI_FN_CPU_ON KVM_PSCI_FN(2) -#define KVM_PSCI_FN_MIGRATE KVM_PSCI_FN(3) +#define KVM_PSCI_FN_CPU_SUSPEND PSCI_FN(KVM_PSCI_FN_BASE, 0) +#define KVM_PSCI_FN_CPU_OFF PSCI_FN(KVM_PSCI_FN_BASE, 1) +#define KVM_PSCI_FN_CPU_ON PSCI_FN(KVM_PSCI_FN_BASE, 2) +#define KVM_PSCI_FN_MIGRATE PSCI_FN(KVM_PSCI_FN_BASE, 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 +11 -10
@@ -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;
@@ -177,19 +179,18 @@ struct kvm_arch_memory_slot {/* Highest supported SPI, from VGIC_NR_IRQS */ #define KVM_ARM_IRQ_GIC_MAX 127 -/* PSCI interface */ +/* PSCI v0.1 interface */ #define KVM_PSCI_FN_BASE 0x95c1ba5e -#define KVM_PSCI_FN (n) (KVM_PSCI_FN_BASE + (n)) -#define KVM_PSCI_FN_CPU_SUSPEND KVM_PSCI_FN(0) -#define KVM_PSCI_FN_CPU_OFF KVM_PSCI_FN(1) -#define KVM_PSCI_FN_CPU_ON KVM_PSCI_FN(2) -#define KVM_PSCI_FN_MIGRATE KVM_PSCI_FN(3) +#define KVM_PSCI_FN_CPU_SUSPEND PSCI_FN(KVM_PSCI_FN_BASE, 0) +#define KVM_PSCI_FN_CPU_OFF PSCI_FN(KVM_PSCI_FN_BASE, 1) +#define KVM_PSCI_FN_CPU_ON PSCI_FN(KVM_PSCI_FN_BASE, 2) +#define KVM_PSCI_FN_MIGRATE PSCI_FN(KVM_PSCI_FN_BASE, 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/linux/kvm.h +10 -0
@@ -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 ]; };
@@ -740,6 +748,8 @@ struct kvm_ppc_smmu_info {#define KVM_CAP_SPAPR_MULTITCE 94#define KVM_CAP_EXT_EMUL_CPUID 95#define KVM_CAP_HYPERV_TIME 96 +#define KVM_CAP_IOAPIC_POLARITY_IGNORED 97 +#define KVM_CAP_ARM_PSCI_0_2 98#ifdef KVM_CAP_IRQ_ROUTING
linux-headers/linux/psci.h new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
1.7.9.5
RFC PATCH v2 2/6 kvm: Handle exit reason KVM_EXIT_SYSTEM_EVENT
In reply to Pranavkumar SawargaonkarIn-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
@@ -1724,6 +1724,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
RFC PATCH v2 3/6 target-arm: Enable KVM_ARM_VCPU_PSCI_0_2 feature when possible
In reply to Pranavkumar SawargaonkarLatest 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 | 5 ++++- target-arm/kvm64.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-)
target-arm/kvm32.c +4 -1
@@ -181,7 +181,10 @@ int kvm_arch_init_vcpu(CPUState *cs) init.target = cpu->kvm_target;memset (init.features,0 ,sizeof (init.features));if (cpu->start_powered_off) { - init.features[0 ] =1 <<KVM_ARM_VCPU_POWER_OFF ; + init.features[0 ] |=1 <<KVM_ARM_VCPU_POWER_OFF ; + } +if (kvm_check_extension (cs->kvm_state,KVM_CAP_ARM_PSCI_0_2 )) { + init.features[0 ] |=1 <<KVM_ARM_VCPU_PSCI_0_2 ; } ret =kvm_vcpu_ioctl (cs,KVM_ARM_VCPU_INIT , &init);if (ret) {
target-arm/kvm64.c +4 -1
@@ -90,7 +90,10 @@ int kvm_arch_init_vcpu(CPUState *cs) init.target = cpu->kvm_target;memset (init.features,0 ,sizeof (init.features));if (cpu->start_powered_off) { - init.features[0 ] =1 <<KVM_ARM_VCPU_POWER_OFF ; + init.features[0 ] |=1 <<KVM_ARM_VCPU_POWER_OFF ; + } +if (kvm_check_extension (cs->kvm_state,KVM_CAP_ARM_PSCI_0_2 )) { + init.features[0 ] |=1 <<KVM_ARM_VCPU_PSCI_0_2 ; } ret =kvm_vcpu_ioctl (cs,KVM_ARM_VCPU_INIT , &init);
Signature · 1 line
1.7.9.5
RFC PATCH v2 4/6 target-arm: Implement kvm_arch_reset_vcpu() for KVM ARM64
In reply to Pranavkumar SawargaonkarTo implement kvm_arch_reset_vcpu(), we simply re-init the VCPU using kvm_arch_init_vcpu() 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
@@ -204,4 +204,8 @@ int kvm_arch_get_registers(CPUState *cs)void kvm_arch_reset_vcpu (CPUState *cs) { +/* Re-init VCPU so that all registers are set to their +* respective reset values. +*/ +kvm_arch_init_vcpu (cs); }
Signature · 1 line
1.7.9.5
RFC PATCH v2 5/6 target-arm: Provide PSCI v0.2 constants to generic QEMU code
In reply to Pranavkumar SawargaonkarProvide QEMU PSCI v0.2 constants for non-KVM code; this will allow us to avoid an #ifdef in boards which set up a PSCI v0.2 node in the device tree.
--- target-arm/kvm-consts.h | 63 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 11 deletions(-)
target-arm/kvm-consts.h +52 -11
@@ -38,17 +38,58 @@ MISMATCH_CHECK(CP_REG_SIZE_U64, KVM_REG_SIZE_U64) MISMATCH_CHECK(CP_REG_ARM, KVM_REG_ARM)MISMATCH_CHECK (CP_REG_ARCH_MASK ,KVM_REG_ARCH_MASK ) -#define PSCI_FN_BASE 0x95c1ba5e -#define PSCI_FN (n) (PSCI_FN_BASE + (n)) -#define PSCI_FN_CPU_SUSPEND PSCI_FN(0) -#define PSCI_FN_CPU_OFF PSCI_FN(1) -#define PSCI_FN_CPU_ON PSCI_FN(2) -#define PSCI_FN_MIGRATE PSCI_FN(3) - -MISMATCH_CHECK(PSCI_FN_CPU_SUSPEND, KVM_PSCI_FN_CPU_SUSPEND) -MISMATCH_CHECK(PSCI_FN_CPU_OFF, KVM_PSCI_FN_CPU_OFF) -MISMATCH_CHECK(PSCI_FN_CPU_ON, KVM_PSCI_FN_CPU_ON) -MISMATCH_CHECK (PSCI_FN_MIGRATE ,KVM_PSCI_FN_MIGRATE ) +/* PSCI v0.1 interface */ +#define QEMU_PSCI_FN_BASE 0x95c1ba5e +#define QEMU_PSCI_FN (n) (QEMU_PSCI_FN_BASE + (n)) +#define QEMU_PSCI_FN_CPU_SUSPEND QEMU_PSCI_FN(0) +#define QEMU_PSCI_FN_CPU_OFF QEMU_PSCI_FN(1) +#define QEMU_PSCI_FN_CPU_ON QEMU_PSCI_FN(2) +#define QEMU_PSCI_FN_MIGRATE QEMU_PSCI_FN(3) + +MISMATCH_CHECK(QEMU_PSCI_FN_CPU_SUSPEND, KVM_PSCI_FN_CPU_SUSPEND) +MISMATCH_CHECK(QEMU_PSCI_FN_CPU_OFF, KVM_PSCI_FN_CPU_OFF) +MISMATCH_CHECK(QEMU_PSCI_FN_CPU_ON, KVM_PSCI_FN_CPU_ON) +MISMATCH_CHECK (QEMU_PSCI_FN_MIGRATE ,KVM_PSCI_FN_MIGRATE ) + +/* PSCI v0.2 interface */ +#define QEMU_PSCI_0_2_FN_BASE 0x84000000 +#define QEMU_PSCI_0_2_FN (n) (QEMU_PSCI_0_2_FN_BASE + (n)) +#define QEMU_PSCI_0_2_FN64_BASE 0xC4000000 +#define QEMU_PSCI_0_2_FN64 (n) (QEMU_PSCI_0_2_FN64_BASE + (n)) +#define QEMU_PSCI_0_2_FN_PSCI_VERSION QEMU_PSCI_0_2_FN(0) +#define QEMU_PSCI_0_2_FN_CPU_SUSPEND QEMU_PSCI_0_2_FN(1) +#define QEMU_PSCI_0_2_FN_CPU_OFF QEMU_PSCI_0_2_FN(2) +#define QEMU_PSCI_0_2_FN_CPU_ON QEMU_PSCI_0_2_FN(3) +#define QEMU_PSCI_0_2_FN_AFFINITY_INFO QEMU_PSCI_0_2_FN(4) +#define QEMU_PSCI_0_2_FN_MIGRATE QEMU_PSCI_0_2_FN(5) +#define QEMU_PSCI_0_2_FN_MIGRATE_INFO_TYPE QEMU_PSCI_0_2_FN(6) +#define QEMU_PSCI_0_2_FN_MIGRATE_INFO_UP_CPU QEMU_PSCI_0_2_FN(7) +#define QEMU_PSCI_0_2_FN_SYSTEM_OFF QEMU_PSCI_0_2_FN(8) +#define QEMU_PSCI_0_2_FN_SYSTEM_RESET QEMU_PSCI_0_2_FN(9) +#define QEMU_PSCI_0_2_FN64_CPU_SUSPEND QEMU_PSCI_0_2_FN64(1) +#define QEMU_PSCI_0_2_FN64_CPU_ON QEMU_PSCI_0_2_FN64(3) +#define QEMU_PSCI_0_2_FN64_AFFINITY_INFO QEMU_PSCI_0_2_FN64(4) +#define QEMU_PSCI_0_2_FN64_MIGRATE QEMU_PSCI_0_2_FN64(5) +#define QEMU_PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU QEMU_PSCI_0_2_FN64(7) + +MISMATCH_CHECK(QEMU_PSCI_0_2_FN_PSCI_VERSION, PSCI_0_2_FN_PSCI_VERSION) +MISMATCH_CHECK(QEMU_PSCI_0_2_FN_CPU_SUSPEND, PSCI_0_2_FN_CPU_SUSPEND) +MISMATCH_CHECK(QEMU_PSCI_0_2_FN_CPU_OFF, PSCI_0_2_FN_CPU_OFF) +MISMATCH_CHECK(QEMU_PSCI_0_2_FN_CPU_ON, PSCI_0_2_FN_CPU_ON) +MISMATCH_CHECK(QEMU_PSCI_0_2_FN_AFFINITY_INFO, PSCI_0_2_FN_AFFINITY_INFO) +MISMATCH_CHECK(QEMU_PSCI_0_2_FN_MIGRATE, PSCI_0_2_FN_MIGRATE) +MISMATCH_CHECK (QEMU_PSCI_0_2_FN_MIGRATE_INFO_TYPE , \ + PSCI_0_2_FN_MIGRATE_INFO_TYPE) +MISMATCH_CHECK (QEMU_PSCI_0_2_FN_MIGRATE_INFO_UP_CPU , \ + PSCI_0_2_FN_MIGRATE_INFO_UP_CPU) +MISMATCH_CHECK(QEMU_PSCI_0_2_FN_SYSTEM_OFF, PSCI_0_2_FN_SYSTEM_OFF) +MISMATCH_CHECK(QEMU_PSCI_0_2_FN_SYSTEM_RESET, PSCI_0_2_FN_SYSTEM_RESET) +MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_CPU_SUSPEND, PSCI_0_2_FN64_CPU_SUSPEND) +MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_CPU_ON, PSCI_0_2_FN64_CPU_ON) +MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_AFFINITY_INFO, PSCI_0_2_FN64_AFFINITY_INFO) +MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_MIGRATE, PSCI_0_2_FN64_MIGRATE) +MISMATCH_CHECK (QEMU_PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU , \ +PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU )/* Note that KVM uses overlapping values for AArch32 and AArch64 * target CPU numbers. AArch32 targets:
Signature · 1 line
1.7.9.5
RFC PATCH v2 6/6 hw/arm/virt: Use PSCI v0.2 function IDs when kernel supports its
In reply to Pranavkumar SawargaonkarIf we have in-kernel emulation of PSCI v0.2 for KVM ARM/ARM64 then we enable PSCI v0.2 for each VCPU at the time of VCPU init hence we need to provide PSCI v0.2 function IDs via generated DTB.
This patch updates generated DTB to have PSCI v0.2 function IDs when we have in-kernel emulation PSCI v0.2 for KVM ARM/ARM64.
--- hw/arm/virt.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-)
hw/arm/virt.c +23 -5
@@ -187,11 +187,29 @@ static void create_fdt(VirtBoardInfo *vbi)qemu_fdt_add_subnode (fdt,"/psci" );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 ); -qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_off" ,PSCI_FN_CPU_OFF ); -qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_on" ,PSCI_FN_CPU_ON ); -qemu_fdt_setprop_cell (fdt,"/psci" ,"migrate" ,PSCI_FN_MIGRATE ); +if (kvm_check_extension (kvm_state,KVM_CAP_ARM_PSCI_0_2 )) { +qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_suspend" , +QEMU_PSCI_0_2_FN_CPU_SUSPEND ); +qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_off" , +QEMU_PSCI_0_2_FN_CPU_OFF ); +qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_on" , +QEMU_PSCI_0_2_FN_CPU_ON ); +qemu_fdt_setprop_cell (fdt,"/psci" ,"migrate" , +QEMU_PSCI_0_2_FN_MIGRATE ); +qemu_fdt_setprop_cell (fdt,"/psci" ,"system_off" , +QEMU_PSCI_0_2_FN_SYSTEM_OFF ); +qemu_fdt_setprop_cell (fdt,"/psci" ,"system_reset" , +QEMU_PSCI_0_2_FN_SYSTEM_RESET ); + }else { +qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_suspend" , +QEMU_PSCI_FN_CPU_SUSPEND ); +qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_off" , +QEMU_PSCI_FN_CPU_OFF ); +qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_on" , +QEMU_PSCI_FN_CPU_ON ); +qemu_fdt_setprop_cell (fdt,"/psci" ,"migrate" , +QEMU_PSCI_FN_MIGRATE ); + } } }
Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [RFC PATCH V2 6/6] hw/arm/virt: Use PSCI v0.2 function IDs when kernel supports its
Hi Rob/Mark,
Quoted 18 lines · Pranavkumar Sawargaonkar
If we have in-kernel emulation of PSCI v0.2 for KVM ARM/ARM64 then we enable PSCI v0.2 for each VCPU at the time of VCPU init hence we need to provide PSCI v0.2 function IDs via generated DTB.
This patch updates generated DTB to have PSCI v0.2 function IDs when we have in-kernel emulation PSCI v0.2 for KVM ARM/ARM64.
Signed-off-by Pranavkumar Sawargaonkar <[email protected]>Signed-off-by Anup Patel <[email protected]>--- hw/arm/virt.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-)hw/arm/virt.c +0
-0
hw/arm/virt.c static void create_fdt(VirtBoardInfo *vbi) · line 188
Quoted 2 lines
hw/arm/virt.c +0
-0@@ -187,11 +187,29 @@ static void create_fdt(VirtBoardInfo *vbi)qemu_fdt_add_subnode (fdt,"/psci" );qemu_fdt_setprop_string (fdt,"/psci" ,"compatible" ,"arm,psci" );
I have not updated compatible string to arm,psci-0,2 because still stable dt bindings are not available in linux kernel. Once they are available I will update this patch accordingly.
Quoted 33 lines
hw/arm/virt.c +23
-6qemu_fdt_setprop_string (fdt,"/psci" ,"method" ,"hvc" ); -qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_suspend" , -PSCI_FN_CPU_SUSPEND ); -qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_off" ,PSCI_FN_CPU_OFF ); -qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_on" ,PSCI_FN_CPU_ON ); -qemu_fdt_setprop_cell (fdt,"/psci" ,"migrate" ,PSCI_FN_MIGRATE ); +if (kvm_check_extension (kvm_state,KVM_CAP_ARM_PSCI_0_2 )) { +qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_suspend" , +QEMU_PSCI_0_2_FN_CPU_SUSPEND ); +qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_off" , +QEMU_PSCI_0_2_FN_CPU_OFF ); +qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_on" , +QEMU_PSCI_0_2_FN_CPU_ON ); +qemu_fdt_setprop_cell (fdt,"/psci" ,"migrate" , +QEMU_PSCI_0_2_FN_MIGRATE ); +qemu_fdt_setprop_cell (fdt,"/psci" ,"system_off" , +QEMU_PSCI_0_2_FN_SYSTEM_OFF ); +qemu_fdt_setprop_cell (fdt,"/psci" ,"system_reset" , +QEMU_PSCI_0_2_FN_SYSTEM_RESET ); + }else { +qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_suspend" , +QEMU_PSCI_FN_CPU_SUSPEND ); +qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_off" , +QEMU_PSCI_FN_CPU_OFF ); +qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_on" , +QEMU_PSCI_FN_CPU_ON ); +qemu_fdt_setprop_cell (fdt,"/psci" ,"migrate" , +QEMU_PSCI_FN_MIGRATE ); + } } } --
Quoted 2 lines
1.7.9.5
Thanks,
Pranav
Re: [Qemu-devel] [RFC PATCH V2 4/6] target-arm: Implement kvm_arch_reset_vcpu() for KVM ARM64
In reply to Pranavkumar SawargaonkarQuoted 15 lines · Pranavkumar Sawargaonkar
To implement
kvm_arch_reset_vcpu(), we simply re-init the VCPU usingkvm_arch_init_vcpu()so that all registers of VCPU are set to their reset values by in-kernel KVM code.Signed-off-by Pranavkumar Sawargaonkar <[email protected]>Signed-off-by Anup Patel <[email protected]>--- target-arm/kvm64.c | 4 ++++ 1 file changed, 4 insertions(+)target-arm/kvm64.c +0
-0
target-arm/kvm64.c int kvm_arch_get_registers(CPUState *cs) · line 211
Quoted 8 lines
target-arm/kvm64.c +4
-0@@ -204,4 +204,8 @@ int kvm_arch_get_registers(CPUState *cs)void kvm_arch_reset_vcpu (CPUState *cs) { +/* Re-init VCPU so that all registers are set to their +* respective reset values. +*/ +kvm_arch_init_vcpu (cs); }
Calling kvm_arch_init_vcpu() will end up doing more work than we really need, because it will end up filling in the cpreg tuple list [code not yet present for 64 bit but you can see from the 32 bit kvm_arch_init_vcpu() what it will look like]. So we should have a QEMU function for doing the vcpu init.
I think I would suggest adding a uint32_t kvm_target_features to ARMCPU (under kvm_target). Then kvm_arch_init_vcpu and kvm_arch_reset_vcpu can both call a small function which does
int kvm_arm_reinit_vcpu(CPUState *cs)
{
struct kvm_vcpu_init init;
init.target = cpu->kvm_target;
memset(init.features, 0, sizeof(init.features));
init.features[0] = cpu->kvm_target_features;
return kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init);
}(put that in target-arm/kvm.c, prototype in target-arm/kvm_arm.h, needs a proper doc comment in the .h file.)
thanks
-- PMM
Re: [Qemu-devel] [RFC PATCH V2 3/6] target-arm: Enable KVM_ARM_VCPU_PSCI_0_2 feature when possible
In reply to Pranavkumar SawargaonkarQuoted 22 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_2feature usingKVM_ARM_VCPU_INITioctl.Also, we can use
KVM_ARM_VCPU_PSCI_0_2feature for VCPU only when linux kernel hasKVM_CAP_ARM_PSCI_0_2capability.This patch updates
kvm_arch_init_vcpu()to enableKVM_ARM_VCPU_PSCI_0_2feature for VCPU when KVM ARM/ARM64 hasKVM_CAP_ARM_PSCI_0_2capability.Signed-off-by Pranavkumar Sawargaonkar <[email protected]>Signed-off-by Anup Patel <[email protected]>--- target-arm/kvm32.c | 5 ++++- target-arm/kvm64.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-)target-arm/kvm32.c +0
-0
target-arm/kvm32.c int kvm_arch_init_vcpu(CPUState *cs) · line 188
Quoted 9 lines
target-arm/kvm32.c +4
-1@@ -181,7 +181,10 @@ int kvm_arch_init_vcpu(CPUState *cs) init.target = cpu->kvm_target;memset (init.features,0 ,sizeof (init.features));if (cpu->start_powered_off) { - init.features[0 ] =1 <<KVM_ARM_VCPU_POWER_OFF ; + init.features[0 ] |=1 <<KVM_ARM_VCPU_POWER_OFF ; + } +if (kvm_check_extension (cs->kvm_state,KVM_CAP_ARM_PSCI_0_2 )) { + init.features[0 ] |=1 <<KVM_ARM_VCPU_PSCI_0_2 ; }
I vaguely remember mentioning migration incompatibilities last time round. You can't do this because this means that a QEMU running on a non-0.2-aware kernel won't be able to migrate its VM to a QEMU running on a 0.2-aware kernel. PSCI version is probably going to need to be a CPU property; needs more thought.
thanks
-- PMM
Re: [Qemu-devel] [RFC PATCH V2 3/6] target-arm: Enable KVM_ARM_VCPU_PSCI_0_2 feature when possible
Hi Peter,
Quoted 31 lines · Peter Maydell
Quoted 30 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_2feature usingKVM_ARM_VCPU_INITioctl.Also, we can use
KVM_ARM_VCPU_PSCI_0_2feature for VCPU only when linux kernel hasKVM_CAP_ARM_PSCI_0_2capability.This patch updates
kvm_arch_init_vcpu()to enableKVM_ARM_VCPU_PSCI_0_2feature for VCPU when KVM ARM/ARM64 hasKVM_CAP_ARM_PSCI_0_2capability.Signed-off-by Pranavkumar Sawargaonkar <[email protected]>Signed-off-by Anup Patel <[email protected]>--- target-arm/kvm32.c | 5 ++++- target-arm/kvm64.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-)target-arm/kvm32.c +4
-1@@ -181,7 +181,10 @@ int kvm_arch_init_vcpu(CPUState *cs) init.target = cpu->kvm_target;memset (init.features,0 ,sizeof (init.features));if (cpu->start_powered_off) { - init.features[0 ] =1 <<KVM_ARM_VCPU_POWER_OFF ; + init.features[0 ] |=1 <<KVM_ARM_VCPU_POWER_OFF ; + } +if (kvm_check_extension (cs->kvm_state,KVM_CAP_ARM_PSCI_0_2 )) { + init.features[0 ] |=1 <<KVM_ARM_VCPU_PSCI_0_2 ;
Quoted 9 lines
target-arm/kvm32.c int kvm_arch_init_vcpu(CPUState *cs) · line 188
Quoted 1 line
target-arm/kvm32.c +0
-0}I vaguely remember mentioning migration incompatibilities last time round. You can't do this because this means that a QEMU running on a non-0.2-aware kernel won't be able to migrate its VM to a QEMU running on a 0.2-aware kernel. PSCI version is probably going to need to be a CPU property; needs more thought.
Yes you had mentioned about this issue in v1.
During V1 of this patch-set Christoffer mentioned that he will address this issue in migration for ARMv8.
But till that time can we go with this current approach ? (May be I can add a comment about this)
Quoted 2 lines
thanks
-- PMM
Thanks,
Pranav
Re: [Qemu-devel] [RFC PATCH V2 4/6] target-arm: Implement kvm_arch_reset_vcpu() for KVM ARM64
In reply to Peter MaydellQuoted 47 lines · Peter Maydell
Quoted 15 lines · Pranavkumar Sawargaonkar
To implement
kvm_arch_reset_vcpu(), we simply re-init the VCPU usingkvm_arch_init_vcpu()so that all registers of VCPU are set to their reset values by in-kernel KVM code.Signed-off-by Pranavkumar Sawargaonkar <[email protected]>Signed-off-by Anup Patel <[email protected]>--- target-arm/kvm64.c | 4 ++++ 1 file changed, 4 insertions(+)target-arm/kvm64.c +0
-0target-arm/kvm64.c int kvm_arch_get_registers(CPUState *cs) · line 211
Quoted 8 lines
target-arm/kvm64.c +4
-0@@ -204,4 +204,8 @@ int kvm_arch_get_registers(CPUState *cs)void kvm_arch_reset_vcpu (CPUState *cs) { +/* Re-init VCPU so that all registers are set to their +* respective reset values. +*/ +kvm_arch_init_vcpu (cs); }Calling
kvm_arch_init_vcpu()will end up doing more work than we really need, because it will end up filling in the cpreg tuple list [code not yet present for 64 bit but you can see from the 32 bitkvm_arch_init_vcpu()what it will look like]. So we should have a QEMU function for doing the vcpu init.I think I would suggest adding a
uint32_tkvm_target_featuresto ARMCPU (underkvm_target). Thenkvm_arch_init_vcpuandkvm_arch_reset_vcpucan both call a small function which doesint
kvm_arm_reinit_vcpu(CPUState *cs){ struct kvm_vcpu_init init; init.target = cpu->kvm_target; memset(init.features, 0, sizeof(init.features)); init.features[0] = cpu->kvm_target_features; return kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init); }
Quoted 2 lines
(put that in
target-arm/kvm.c, prototype intarget-arm/kvm_arm.h, needs a proper doc comment in the .h file.)
Sure I will update this as per your suggestion.
Quoted 3 lines
thanks
-- PMM
Thanks,
Pranav