From patchwork Fri Jun 27 06:25:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharat Bhushan X-Patchwork-Id: 4433611 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 089A7BEEAA for ; Fri, 27 Jun 2014 06:26:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0484420221 for ; Fri, 27 Jun 2014 06:26:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CC30F2021F for ; Fri, 27 Jun 2014 06:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751836AbaF0G0e (ORCPT ); Fri, 27 Jun 2014 02:26:34 -0400 Received: from mail-bn1blp0184.outbound.protection.outlook.com ([207.46.163.184]:17595 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750819AbaF0G0d (ORCPT ); Fri, 27 Jun 2014 02:26:33 -0400 Received: from BN3PR0301CA0084.namprd03.prod.outlook.com (25.160.152.180) by BY2PR03MB572.namprd03.prod.outlook.com (10.141.143.152) with Microsoft SMTP Server (TLS) id 15.0.949.11; Fri, 27 Jun 2014 06:26:23 +0000 Received: from BY2FFO11FD024.protection.gbl (2a01:111:f400:7c0c::115) by BN3PR0301CA0084.outlook.office365.com (2a01:111:e400:401e::52) with Microsoft SMTP Server (TLS) id 15.0.969.15 via Frontend Transport; Fri, 27 Jun 2014 06:26:22 +0000 Received: from az84smr01.freescale.net (192.88.158.2) by BY2FFO11FD024.mail.protection.outlook.com (10.1.15.213) with Microsoft SMTP Server (TLS) id 15.0.969.12 via Frontend Transport; Fri, 27 Jun 2014 06:26:21 +0000 Received: from kvm.ap.freescale.net (kvm.ap.freescale.net [10.232.14.24]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id s5R6QDjf029441; Thu, 26 Jun 2014 23:26:19 -0700 From: Bharat Bhushan To: CC: , , , Bharat Bhushan Subject: [PATCH 2/2] KVM : powerpc/booke: Allow debug interrupt injection to guest Date: Fri, 27 Jun 2014 11:55:06 +0530 Message-ID: <1403850306-12394-3-git-send-email-Bharat.Bhushan@freescale.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1403850306-12394-1-git-send-email-Bharat.Bhushan@freescale.com> References: <1403850306-12394-1-git-send-email-Bharat.Bhushan@freescale.com> X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:CAL; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(6009001)(189002)(199002)(19580405001)(85852003)(62966002)(77982001)(81342001)(48376002)(44976005)(104166001)(19580395003)(50986999)(76482001)(79102001)(89996001)(99396002)(2351001)(102836001)(87936001)(20776003)(76176999)(81542001)(83072002)(64706001)(46102001)(87286001)(84676001)(80022001)(88136002)(6806004)(21056001)(26826002)(4396001)(47776003)(74662001)(68736004)(69596002)(95666004)(105606002)(107046002)(104016002)(74502001)(81156004)(93916002)(83322001)(106466001)(92726001)(97736001)(36756003)(50466002)(50226001)(31966008)(85306003)(77156001)(86362001)(92566001); DIR:OUT; SFP:; SCL:1; SRVR:BY2PR03MB572; H:az84smr01.freescale.net; FPR:; MLV:ovrnspm; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:; MIME-Version: 1.0 X-Microsoft-Antispam: BL:0; ACTION:Default; RISK:Low; SCL:0; SPMLVL:NotSpam; PCL:0; RULEID: X-Forefront-PRVS: 0255DF69B9 Received-SPF: Fail (: domain of freescale.com does not designate 192.88.158.2 as permitted sender) receiver=; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=Bharat.Bhushan@freescale.com; X-OriginatorOrg: freescale.com Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch allow userspace to inject debug interrupt to guest. Signed-off-by: Bharat Bhushan --- arch/powerpc/kvm/booke.c | 31 +++++++++++++++++++++++++++++-- arch/powerpc/kvm/e500mc.c | 10 +++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index bb25937..63ac38c 100644 --- a/arch/powerpc/kvm/booke.c +++ b/arch/powerpc/kvm/booke.c @@ -135,6 +135,11 @@ static void kvmppc_vcpu_sync_fpu(struct kvm_vcpu *vcpu) #endif } +static int kvmppc_core_pending_debug(struct kvm_vcpu *vcpu) +{ + return test_bit(BOOKE_IRQPRIO_DEBUG, &vcpu->arch.pending_exceptions); +} + static void kvmppc_vcpu_sync_debug(struct kvm_vcpu *vcpu) { /* Synchronize guest's desire to get debug interrupts into shadow MSR */ @@ -143,8 +148,11 @@ static void kvmppc_vcpu_sync_debug(struct kvm_vcpu *vcpu) vcpu->arch.shadow_msr |= vcpu->arch.shared->msr & MSR_DE; #endif - /* Force enable debug interrupts when user space wants to debug */ - if (vcpu->guest_debug) { + /* + * Force enable debug interrupts when user space wants to debug + * and there is no debug interrupt pending for guest to handle. + */ + if (vcpu->guest_debug && !kvmppc_core_pending_debug(vcpu)) { #ifdef CONFIG_KVM_BOOKE_HV /* * Since there is no shadow MSR, sync MSR_DE into the guest @@ -264,6 +272,16 @@ static void kvmppc_core_dequeue_watchdog(struct kvm_vcpu *vcpu) clear_bit(BOOKE_IRQPRIO_WATCHDOG, &vcpu->arch.pending_exceptions); } +static void kvmppc_core_queue_debug(struct kvm_vcpu *vcpu) +{ + kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DEBUG); +} + +static void kvmppc_core_dequeue_debug(struct kvm_vcpu *vcpu) +{ + clear_bit(BOOKE_IRQPRIO_DEBUG, &vcpu->arch.pending_exceptions); +} + static void set_guest_srr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1) { #ifdef CONFIG_KVM_BOOKE_HV @@ -1332,6 +1350,7 @@ static void get_sregs_base(struct kvm_vcpu *vcpu, sregs->u.e.dec = kvmppc_get_dec(vcpu, tb); sregs->u.e.tb = tb; sregs->u.e.vrsave = vcpu->arch.vrsave; + sregs->u.e.dbsr = vcpu->arch.dbsr; } static int set_sregs_base(struct kvm_vcpu *vcpu, @@ -1356,6 +1375,14 @@ static int set_sregs_base(struct kvm_vcpu *vcpu, if (sregs->u.e.update_special & KVM_SREGS_E_UPDATE_TSR) kvmppc_set_tsr(vcpu, sregs->u.e.tsr); + if (sregs->u.e.update_special & KVM_SREGS_E_UPDATE_DBSR) { + vcpu->arch.dbsr = sregs->u.e.dbsr; + if (vcpu->arch.dbsr) + kvmppc_core_queue_debug(vcpu); + else + kvmppc_core_dequeue_debug(vcpu); + } + return 0; } diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c index 17e4562..ea724f2 100644 --- a/arch/powerpc/kvm/e500mc.c +++ b/arch/powerpc/kvm/e500mc.c @@ -212,7 +212,7 @@ static int kvmppc_core_get_sregs_e500mc(struct kvm_vcpu *vcpu, struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu); sregs->u.e.features |= KVM_SREGS_E_ARCH206_MMU | KVM_SREGS_E_PM | - KVM_SREGS_E_PC; + KVM_SREGS_E_PC | KVM_SREGS_E_ED; sregs->u.e.impl_id = KVM_SREGS_E_IMPL_FSL; sregs->u.e.impl.fsl.features = 0; @@ -220,6 +220,9 @@ static int kvmppc_core_get_sregs_e500mc(struct kvm_vcpu *vcpu, sregs->u.e.impl.fsl.hid0 = vcpu_e500->hid0; sregs->u.e.impl.fsl.mcar = vcpu_e500->mcar; + sregs->u.e.dsrr0 = vcpu->arch.dsrr0; + sregs->u.e.dsrr1 = vcpu->arch.dsrr1; + kvmppc_get_sregs_e500_tlb(vcpu, sregs); sregs->u.e.ivor_high[3] = @@ -261,6 +264,11 @@ static int kvmppc_core_set_sregs_e500mc(struct kvm_vcpu *vcpu, sregs->u.e.ivor_high[5]; } + if (sregs->u.e.features & KVM_SREGS_E_ED) { + vcpu->arch.dsrr0 = sregs->u.e.dsrr0; + vcpu->arch.dsrr1 = sregs->u.e.dsrr1; + } + return kvmppc_set_sregs_ivor(vcpu, sregs); }