From patchwork Wed Jul 18 11:34:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharat Bhushan X-Patchwork-Id: 171653 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id B252C2C036E for ; Wed, 18 Jul 2012 21:32:38 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753373Ab2GRLcg (ORCPT ); Wed, 18 Jul 2012 07:32:36 -0400 Received: from va3ehsobe005.messaging.microsoft.com ([216.32.180.31]:41477 "EHLO va3outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753365Ab2GRLcf (ORCPT ); Wed, 18 Jul 2012 07:32:35 -0400 Received: from mail105-va3-R.bigfish.com (10.7.14.253) by VA3EHSOBE014.bigfish.com (10.7.40.64) with Microsoft SMTP Server id 14.1.225.23; Wed, 18 Jul 2012 11:32:34 +0000 Received: from mail105-va3 (localhost [127.0.0.1]) by mail105-va3-R.bigfish.com (Postfix) with ESMTP id 335564C00F1; Wed, 18 Jul 2012 11:32:34 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 6 X-BigFish: VS6(zz853kzz1202h1082kzz8275bhz2dh2a8h668h839he5bhf0ah) Received: from mail105-va3 (localhost.localdomain [127.0.0.1]) by mail105-va3 (MessageSwitch) id 1342611151349016_14146; Wed, 18 Jul 2012 11:32:31 +0000 (UTC) Received: from VA3EHSMHS023.bigfish.com (unknown [10.7.14.246]) by mail105-va3.bigfish.com (Postfix) with ESMTP id 4755E60067; Wed, 18 Jul 2012 11:32:31 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by VA3EHSMHS023.bigfish.com (10.7.99.33) with Microsoft SMTP Server (TLS) id 14.1.225.23; Wed, 18 Jul 2012 11:32:31 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-002.039d.mgd.msft.net (10.84.1.15) with Microsoft SMTP Server (TLS) id 14.2.298.5; Wed, 18 Jul 2012 06:32:30 -0500 Received: from freescale.com ([10.232.15.72]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with SMTP id q6IBWOOL010516; Wed, 18 Jul 2012 04:32:27 -0700 Received: by freescale.com (sSMTP sendmail emulation); Wed, 18 Jul 2012 17:04:41 +0530 From: Bharat Bhushan To: , , CC: Bharat Bhushan , Bharat Bhushan Subject: [PATCH 3/3 v3] Enable kvm emulated watchdog Date: Wed, 18 Jul 2012 17:04:39 +0530 Message-ID: <1342611279-22868-1-git-send-email-Bharat.Bhushan@freescale.com> X-Mailer: git-send-email 1.7.0.4 MIME-Version: 1.0 X-OriginatorOrg: freescale.com Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org Enable the KVM emulated watchdog if KVM supports (use the capability enablement in watchdog handler). Also watchdog exit (KVM_EXIT_WATCHDOG) handling is added. Watchdog state machine is cleared whenever VM state changes to running. This is to handle the cases like return from debug halt etc. Signed-off-by: Bharat Bhushan --- v3: - TSR clearing is removed in whatchdog exit handling as this is no more needed. v2: - Merged ([PATCH 3/4] Watchdog exit handling support) and ([PATCH 4/4] Enable to use kvm emulated watchdog) - Clear watchdog state machine when VM state changes to running. hw/ppc_booke.c | 5 +++ linux-headers/linux/kvm.h | 2 + target-ppc/cpu.h | 1 + target-ppc/kvm.c | 63 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 0 deletions(-) diff --git a/hw/ppc_booke.c b/hw/ppc_booke.c index 837a5b6..a9fba15 100644 --- a/hw/ppc_booke.c +++ b/hw/ppc_booke.c @@ -203,6 +203,11 @@ static void booke_wdt_cb(void *opaque) booke_timer->wdt_timer); } +void ppc_booke_wdt_clear_tsr(CPUPPCState *env, target_ulong tsr) +{ + env->spr[SPR_BOOKE_TSR] = tsr & ~(TSR_ENW | TSR_WIS | TSR_WRS_MASK); +} + void store_booke_tsr(CPUPPCState *env, target_ulong val) { env->spr[SPR_BOOKE_TSR] &= ~val; diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index 4b9e575..64d94da 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -163,6 +163,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 @@ -618,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/cpu.h b/target-ppc/cpu.h index ca2fc21..78212b4 100644 --- a/target-ppc/cpu.h +++ b/target-ppc/cpu.h @@ -1191,6 +1191,7 @@ void store_40x_dbcr0 (CPUPPCState *env, uint32_t val); void store_40x_sler (CPUPPCState *env, uint32_t val); void store_booke_tcr (CPUPPCState *env, target_ulong val); void store_booke_tsr (CPUPPCState *env, target_ulong val); +void ppc_booke_wdt_clear_tsr(CPUPPCState *env, target_ulong tsr); void booke206_flush_tlb(CPUPPCState *env, int flags, const int check_iprot); target_phys_addr_t booke206_tlb_to_page_size(CPUPPCState *env, ppcmas_tlb_t *tlb); int ppcmas_tlb_check(CPUPPCState *env, ppcmas_tlb_t *tlb, diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index b6ef72d..393214e 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -32,6 +32,7 @@ #include "device_tree.h" #include "hw/sysbus.h" #include "hw/spapr.h" +#include "hw/watchdog.h" #include "hw/sysbus.h" #include "hw/spapr.h" @@ -60,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 @@ -86,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 " @@ -168,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, @@ -371,6 +393,33 @@ static inline void kvm_fixup_page_sizes(CPUPPCState *env) #endif /* !defined (TARGET_PPC64) */ +static void cpu_state_change_handler(void *opaque, int running, RunState state) +{ + CPUPPCState *env = opaque; + + struct kvm_sregs sregs; + + printf("running = %d, state = %d \n", running, state); + if (!running) + return; + + /* + * Clear watchdog interrupt condition by clearing TSR. + * Similar logic needed to be implemented for watchdog + * emulation in qemu. + */ + if (cap_booke_sregs && cap_ppc_wdt) { + kvm_vcpu_ioctl(env, KVM_GET_SREGS, &sregs); + + /* Clear TSR.ENW, TSR.WIS and TSR.WRS */ + ppc_booke_wdt_clear_tsr(env, sregs.u.e.tsr); + sregs.u.e.tsr = env->spr[SPR_BOOKE_TSR]; + sregs.u.e.update_special = KVM_SREGS_E_BASE | KVM_SREGS_E_UPDATE_TSR; + + kvm_vcpu_ioctl(env, KVM_SET_SREGS, &sregs); + } +} + int kvm_arch_init_vcpu(CPUPPCState *cenv) { int ret; @@ -384,6 +433,13 @@ int kvm_arch_init_vcpu(CPUPPCState *cenv) return ret; } + ret = kvm_wdt_enable(cenv); + if (ret) { + return ret; + } + + qemu_add_vm_change_state_handler(cpu_state_change_handler, cenv); + idle_timer = qemu_new_timer_ns(vm_clock, kvm_kick_env, cenv); /* Some targets support access to KVM's guest TLB. */ @@ -769,6 +825,13 @@ int kvm_arch_handle_exit(CPUPPCState *env, struct kvm_run *run) ret = 1; break; #endif +#ifdef KVM_EXIT_WATCHDOG + case KVM_EXIT_WATCHDOG: + dprintf("booke watchdog action\n"); + watchdog_perform_action(); + ret = 0; + break; +#endif default: fprintf(stderr, "KVM: unknown exit reason %d\n", run->exit_reason); ret = -1;