KVM: PPC: booke: Add watchdog emulation
Subsystems (3)
PATCH 32/56 KVM: PPC: booke: Add watchdog emulation
From: Bharat Bhushan <[email protected]>
This patch adds the watchdog emulation in KVM. The watchdog emulation is enabled by KVM_ENABLE_CAP(KVM_CAP_PPC_BOOKE_WATCHDOG) ioctl. The kernel timer are used for watchdog emulation and emulates h/w watchdog state machine. On watchdog timer expiry, it exit to QEMU if TCR.WRC is non ZERO. QEMU can reset/shutdown etc depending upon how it is configured.
Signed-off-by Liu Yu <[email protected]>
Signed-off-by Scott Wood <[email protected]>
[[email protected]: reworked patch]
Signed-off-by Bharat Bhushan <[email protected]>
[agraf: adjust to new request framework]
Signed-off-by Alexander Graf <[email protected]>
--- arch/powerpc/include/asm/kvm_host.h | 3 + arch/powerpc/include/asm/kvm_ppc.h | 2 + arch/powerpc/include/asm/reg_booke.h | 7 ++ arch/powerpc/kvm/book3s.c | 9 ++ arch/powerpc/kvm/booke.c | 155 ++++++++++++++++++++++++++++++++++ arch/powerpc/kvm/booke_emulate.c | 8 ++ arch/powerpc/kvm/powerpc.c | 14 +++- include/linux/kvm.h | 2 + include/linux/kvm_host.h | 1 + 9 files changed, 199 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/kvm_host.h +3 -0
@@ -471,6 +471,8 @@ struct kvm_vcpu_arch {ulong fault_esr;ulong queued_dear;ulong queued_esr; +spinlock_t wdt_lock; +struct timer_list wdt_timer;u32 tlbcfg[4 ];u32 mmucfg;u32 epr;
@@ -486,6 +488,7 @@ struct kvm_vcpu_arch {u8 osi_needed;u8 osi_enabled;u8 papr_enabled; +u8 watchdog_enabled;u8 sane;u8 cpu_type;u8 hcall_needed;
arch/powerpc/include/asm/kvm_ppc.h +2 -0
@@ -68,6 +68,8 @@ extern void kvmppc_emulate_dec(struct kvm_vcpu *vcpu);extern u32 kvmppc_get_dec (struct kvm_vcpu *vcpu,u64 tb);extern void kvmppc_decrementer_func (unsigned long data);extern int kvmppc_sanity_check (struct kvm_vcpu *vcpu); +extern int kvmppc_subarch_vcpu_init (struct kvm_vcpu *vcpu); +extern void kvmppc_subarch_vcpu_uninit (struct kvm_vcpu *vcpu);/* Core-specific hooks */
arch/powerpc/include/asm/reg_booke.h +7 -0
@@ -539,6 +539,13 @@#define TCR_FIE 0x00800000/* FIT Interrupt Enable */ #define TCR_ARE 0x00400000/* Auto Reload Enable */ +#ifdef CONFIG_E500 +#define TCR_GET_WP (tcr) ((((tcr) & 0xC0000000) >> 30) | \ + (((tcr) & 0x1E0000) >> 15)) +#else +#define TCR_GET_WP (tcr) (((tcr) & 0xC0000000) >> 30) +#endif +/* Bit definitions for the TSR. */ #define TSR_ENW 0x80000000/* Enable Next Watchdog */ #define TSR_WIS 0x40000000/* WDT Interrupt Status */
arch/powerpc/kvm/book3s.c +9 -0
@@ -411,6 +411,15 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)return 0 ; } +int kvmppc_subarch_vcpu_init (struct kvm_vcpu *vcpu) +{ +return 0 ; +} + +void kvmppc_subarch_vcpu_uninit (struct kvm_vcpu *vcpu) +{ +} +int kvm_arch_vcpu_ioctl_get_regs (struct kvm_vcpu *vcpu,struct kvm_regs *regs) {int i;
arch/powerpc/kvm/booke.c +155 -0
210 lines not on this page · raw message
arch/powerpc/kvm/booke_emulate.c +8 -0
@@ -145,6 +145,14 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)kvmppc_clr_tsr_bits (vcpu, spr_val);break ;case SPRN_TCR : +/* +* WRC is a 2-bit field that is supposed to preserve its +* value once written to non-zero. +*/ +if (vcpu->arch.tcr &TCR_WRC_MASK ) { + spr_val &= ~TCR_WRC_MASK ; + spr_val |= vcpu->arch.tcr &TCR_WRC_MASK ; + }kvmppc_set_tcr (vcpu, spr_val);break ;
arch/powerpc/kvm/powerpc.c +12 -2
@@ -300,6 +300,7 @@ int kvm_dev_ioctl_check_extension(long ext)switch (ext) {#ifdef CONFIG_BOOKE case KVM_CAP_PPC_BOOKE_SREGS : +case KVM_CAP_PPC_BOOKE_WATCHDOG :#else case KVM_CAP_PPC_SEGSTATE :case KVM_CAP_PPC_HIOR :
@@ -476,6 +477,8 @@ enum hrtimer_restart kvmppc_decrementer_wakeup(struct hrtimer *timer)int kvm_arch_vcpu_init (struct kvm_vcpu *vcpu) { +int ret; +hrtimer_init (&vcpu->arch.dec_timer,CLOCK_REALTIME ,HRTIMER_MODE_ABS );tasklet_init (&vcpu->arch.tasklet, kvmppc_decrementer_func, (ulong )vcpu); vcpu->arch.dec_timer.function = kvmppc_decrementer_wakeup;
@@ -484,13 +487,14 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)#ifdef CONFIG_KVM_EXIT_TIMING mutex_init (&vcpu->arch.exit_timing_lock);#endif - -return 0 ; + ret =kvmppc_subarch_vcpu_init (vcpu); +return ret; }void kvm_arch_vcpu_uninit (struct kvm_vcpu *vcpu) {kvmppc_mmu_destroy (vcpu); +kvmppc_subarch_vcpu_uninit (vcpu); }void kvm_arch_vcpu_load (struct kvm_vcpu *vcpu,int cpu)
@@ -735,6 +739,12 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu, r =0 ; vcpu->arch.papr_enabled = true;break ; +#ifdef CONFIG_BOOKE +case KVM_CAP_PPC_BOOKE_WATCHDOG : + r =0 ; + vcpu->arch.watchdog_enabled = true; +break ; +#endif #if defined(CONFIG_KVM_E500V2 ) || defined(CONFIG_KVM_E500MC )case KVM_CAP_SW_TLB : {struct kvm_config_tlb cfg;
include/linux/kvm.h +2 -0
@@ -167,6 +167,7 @@ struct kvm_pit_config {#define KVM_EXIT_OSI 18#define KVM_EXIT_PAPR_HCALL 19#define KVM_EXIT_S390_UCONTROL 20 +#define KVM_EXIT_WATCHDOG 21/* For KVM_EXIT_INTERNAL_ERROR */ #define KVM_INTERNAL_ERROR_EMULATION 1
@@ -627,6 +628,7 @@ struct kvm_ppc_smmu_info {#ifdef __KVM_HAVE_READONLY_MEM#define KVM_CAP_READONLY_MEM 81#endif +#define KVM_CAP_PPC_BOOKE_WATCHDOG 82#ifdef KVM_CAP_IRQ_ROUTING
include/linux/kvm_host.h +1 -0
@@ -118,6 +118,7 @@ static inline bool is_error_page(struct page *page)#define KVM_REQ_IMMEDIATE_EXIT 15#define KVM_REQ_PMU 16#define KVM_REQ_PMI 17 +#define KVM_REQ_WATCHDOG 18#define KVM_USERSPACE_IRQ_SOURCE_ID 0
Signature · 1 line
1.6.0.2