This patch adds the support to enable KVM emulated watchdog if KVM supports (use the capability enablement in watchdog handler). Signed-off-by: Bharat Bhushan <bharat.bhushan@xxxxxxxxxxxxx> --- linux-headers/linux/kvm.h | 1 + target-ppc/kvm.c | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletions(-) diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index c1169ff..8a149db 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -619,6 +619,7 @@ struct kvm_ppc_smmu_info { #define KVM_CAP_PPC_GET_SMMU_INFO 78 #define KVM_CAP_S390_COW 79 #define KVM_CAP_PPC_ALLOC_HTAB 80 +#define KVM_CAP_PPC_WDT 81 #ifdef KVM_CAP_IRQ_ROUTING diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index 6a37e94..52f00b5 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -61,6 +61,7 @@ static int cap_booke_sregs; static int cap_ppc_smt; static int cap_ppc_rma; static int cap_spapr_tce; +static int cap_ppc_wdt; /* XXX We have a race condition where we actually have a level triggered * interrupt, but the infrastructure can't expose that yet, so the guest @@ -87,6 +88,7 @@ int kvm_arch_init(KVMState *s) cap_ppc_smt = kvm_check_extension(s, KVM_CAP_PPC_SMT); cap_ppc_rma = kvm_check_extension(s, KVM_CAP_PPC_RMA); cap_spapr_tce = kvm_check_extension(s, KVM_CAP_SPAPR_TCE); + cap_ppc_wdt = kvm_check_extension(s, KVM_CAP_PPC_WDT); if (!cap_interrupt_level) { fprintf(stderr, "KVM: Couldn't find level irq capability. Expect the " @@ -169,6 +171,25 @@ static int kvm_booke206_tlb_init(CPUPPCState *env) return 0; } +static int kvm_wdt_enable(CPUPPCState *env) +{ + int ret; + struct kvm_enable_cap encap = {}; + + if (!kvm_enabled() || !cap_ppc_wdt) { + return 0; + } + + encap.cap = KVM_CAP_PPC_WDT; + ret = kvm_vcpu_ioctl(env, KVM_ENABLE_CAP, &encap); + if (ret < 0) { + fprintf(stderr, "%s: couldn't enable KVM_CAP_PPC_WDT: %s\n", + __func__, strerror(-ret)); + return ret; + } + + return ret; +} #if defined(TARGET_PPC64) static void kvm_get_fallback_smmu_info(CPUPPCState *env, @@ -385,6 +406,11 @@ int kvm_arch_init_vcpu(CPUPPCState *cenv) return ret; } + ret = kvm_wdt_enable(cenv); + if (ret) { + return ret; + } + idle_timer = qemu_new_timer_ns(vm_clock, kvm_kick_env, cenv); /* Some targets support access to KVM's guest TLB. */ @@ -755,7 +781,7 @@ static int kvm_arch_handle_watchdog(CPUPPCState *env) * Clear watchdog interrupt condition by clearing TSR. * Similar logic needed to be implemented for watchdog emulation in qemu */ - if (cap_booke_sregs) { + if (cap_booke_sregs && cap_ppc_wdt) { ret = kvm_vcpu_ioctl(env, KVM_GET_SREGS, &sregs); if (ret < 0) { return ret; -- 1.7.0.4 -- To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html