From patchwork Sat May 16 04:45:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhichao Huang X-Patchwork-Id: 48584 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5B4402121F for ; Sat, 16 May 2015 04:50:31 +0000 (UTC) Received: by wgtl5 with SMTP id l5sf36235623wgt.1 for ; Fri, 15 May 2015 21:50:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=hvXeZ72wvT31uKmcBnGy62T+gkq9Ymj2Vjl6TMdX5H0=; b=Ma1XkR8xCjdiD9lQkaCOTvzWYHiMDsW2yTDo8zUkf5NfO1bA2KgdM/OmT6QhW4z3eI PEWbnfvGk2/e8w5ocS+oUr67h0/ik5HthSzbTcQoutqFUN9izrC0Db1LYSa5/TvgzRYV pAtabKiI6HE7IqIC5YKdJgoMcd4NWG2X03orDAAnIl2L1n16fEbLrtR9e9wYcEgHTLB+ V5dQQL+XN02LQMOByrzJ3w+ovo+upLb5A/TSdOqF8LUfC3jolAYHsmPyxUyMRCv7WijR 95PRHn/NkO12uUNVIpAdK717qW4Asz9ulaUzgNYqUXrp+rZYPdzYLEqUm1n8k0rLk4Eg DXDg== X-Gm-Message-State: ALoCoQkUq3+KCQsEsJgFbKFsxGDLhWALFIAbIvqgIiNgPoGaEeEAkoFZW8nxE2iFr8XnpqCprxwx X-Received: by 10.180.83.72 with SMTP id o8mr1577995wiy.3.1431751830718; Fri, 15 May 2015 21:50:30 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.7.101 with SMTP id i5ls499658laa.58.gmail; Fri, 15 May 2015 21:50:30 -0700 (PDT) X-Received: by 10.112.47.73 with SMTP id b9mr9513164lbn.46.1431751830554; Fri, 15 May 2015 21:50:30 -0700 (PDT) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id db3si2359539lad.150.2015.05.15.21.50.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 May 2015 21:50:30 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by lagv1 with SMTP id v1so149493690lag.3 for ; Fri, 15 May 2015 21:50:30 -0700 (PDT) X-Received: by 10.112.204.104 with SMTP id kx8mr9456344lbc.72.1431751830084; Fri, 15 May 2015 21:50:30 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp2472597lbb; Fri, 15 May 2015 21:50:28 -0700 (PDT) X-Received: by 10.70.103.200 with SMTP id fy8mr24183836pdb.136.1431751828223; Fri, 15 May 2015 21:50:28 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id kr8si5601646pbc.207.2015.05.15.21.50.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 May 2015 21:50:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YtU1Z-0007Tx-Kt; Sat, 16 May 2015 04:48:33 +0000 Received: from mail-pa0-f49.google.com ([209.85.220.49]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YtU0B-0006dg-TJ for linux-arm-kernel@lists.infradead.org; Sat, 16 May 2015 04:47:09 +0000 Received: by pabts4 with SMTP id ts4so47565773pab.3 for ; Fri, 15 May 2015 21:46:45 -0700 (PDT) X-Received: by 10.70.63.1 with SMTP id c1mr24486522pds.90.1431751605835; Fri, 15 May 2015 21:46:45 -0700 (PDT) Received: from localhost ([167.160.116.91]) by mx.google.com with ESMTPSA id cp10sm3376058pdb.44.2015.05.15.21.46.42 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 15 May 2015 21:46:44 -0700 (PDT) From: Zhichao Huang To: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org, marc.zyngier@arm.com, alex.bennee@linaro.org Subject: [PATCH 06/10] KVM: arm: add trap handlers for 32-bit debug registers Date: Sat, 16 May 2015 12:45:47 +0800 Message-Id: <1431751551-4788-7-git-send-email-zhichao.huang@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1431751551-4788-1-git-send-email-zhichao.huang@linaro.org> References: <1431751551-4788-1-git-send-email-zhichao.huang@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150515_214708_053510_58977AA7 X-CRM114-Status: GOOD ( 15.51 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.220.49 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.220.49 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: huangzhichao@huawei.com, Zhichao Huang X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: zhichao.huang@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Add handlers for all the 32-bit debug registers. Signed-off-by: Zhichao Huang --- arch/arm/include/asm/kvm_asm.h | 12 ++++ arch/arm/include/asm/kvm_host.h | 3 + arch/arm/kernel/asm-offsets.c | 1 + arch/arm/kvm/coproc.c | 122 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 138 insertions(+) diff --git a/arch/arm/include/asm/kvm_asm.h b/arch/arm/include/asm/kvm_asm.h index 25410b2..ba65e05 100644 --- a/arch/arm/include/asm/kvm_asm.h +++ b/arch/arm/include/asm/kvm_asm.h @@ -52,6 +52,18 @@ #define c10_AMAIR1 30 /* Auxilary Memory Attribute Indirection Reg1 */ #define NR_CP15_REGS 31 /* Number of regs (incl. invalid) */ +/* 0 is reserved as an invalid value. */ +#define cp14_DBGBVR0 1 /* Debug Breakpoint Control Registers (0-15) */ +#define cp14_DBGBVR15 16 +#define cp14_DBGBCR0 17 /* Debug Breakpoint Value Registers (0-15) */ +#define cp14_DBGBCR15 32 +#define cp14_DBGWVR0 33 /* Debug Watchpoint Control Registers (0-15) */ +#define cp14_DBGWVR15 48 +#define cp14_DBGWCR0 49 /* Debug Watchpoint Value Registers (0-15) */ +#define cp14_DBGWCR15 64 +#define cp14_DBGDSCRext 65 /* Debug Status and Control external */ +#define NR_CP14_REGS 66 /* Number of regs (incl. invalid) */ + #define ARM_EXCEPTION_RESET 0 #define ARM_EXCEPTION_UNDEFINED 1 #define ARM_EXCEPTION_SOFTWARE 2 diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index d71607c..3d16820 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -124,6 +124,9 @@ struct kvm_vcpu_arch { struct vgic_cpu vgic_cpu; struct arch_timer_cpu timer_cpu; + /* System control coprocessor (cp14) */ + u32 cp14[NR_CP14_REGS]; + /* * Anything that is not used directly from assembly code goes * here. diff --git a/arch/arm/kernel/asm-offsets.c b/arch/arm/kernel/asm-offsets.c index 871b826..9158de0 100644 --- a/arch/arm/kernel/asm-offsets.c +++ b/arch/arm/kernel/asm-offsets.c @@ -172,6 +172,7 @@ int main(void) #ifdef CONFIG_KVM_ARM_HOST DEFINE(VCPU_KVM, offsetof(struct kvm_vcpu, kvm)); DEFINE(VCPU_MIDR, offsetof(struct kvm_vcpu, arch.midr)); + DEFINE(VCPU_CP14, offsetof(struct kvm_vcpu, arch.cp14)); DEFINE(VCPU_CP15, offsetof(struct kvm_vcpu, arch.cp15)); DEFINE(VCPU_VFP_GUEST, offsetof(struct kvm_vcpu, arch.vfp_guest)); DEFINE(VCPU_VFP_HOST, offsetof(struct kvm_vcpu, arch.host_cpu_context)); diff --git a/arch/arm/kvm/coproc.c b/arch/arm/kvm/coproc.c index 16d5f69..3d7c09e 100644 --- a/arch/arm/kvm/coproc.c +++ b/arch/arm/kvm/coproc.c @@ -220,6 +220,47 @@ bool access_vm_reg(struct kvm_vcpu *vcpu, return true; } +static bool trap_debug32(struct kvm_vcpu *vcpu, + const struct coproc_params *p, + const struct coproc_reg *r) +{ + if (p->is_write) + vcpu->arch.cp14[r->reg] = *vcpu_reg(vcpu, p->Rt1); + else + *vcpu_reg(vcpu, p->Rt1) = vcpu->arch.cp14[r->reg]; + + return true; +} + +/* DBGIDR (RO) Debug ID */ +static bool trap_dbgidr(struct kvm_vcpu *vcpu, + const struct coproc_params *p, + const struct coproc_reg *r) +{ + u32 val; + + if (p->is_write) + return ignore_write(vcpu, p); + + ARM_DBG_READ(c0, c0, 0, val); + *vcpu_reg(vcpu, p->Rt1) = val; + + return true; +} + +/* DBGDSCRint (RO) Debug Status and Control Register */ +static bool trap_dbgdscr(struct kvm_vcpu *vcpu, + const struct coproc_params *p, + const struct coproc_reg *r) +{ + if (p->is_write) + return ignore_write(vcpu, p); + + *vcpu_reg(vcpu, p->Rt1) = vcpu->arch.cp14[r->reg]; + + return true; +} + /* * We could trap ID_DFR0 and tell the guest we don't support performance * monitoring. Unfortunately the patch to make the kernel check ID_DFR0 was @@ -375,7 +416,88 @@ static const struct coproc_reg cp15_regs[] = { { CRn(15), CRm( 0), Op1( 4), Op2( 0), is32, access_cbar}, }; +#define DBG_BCR_BVR_WCR_WVR(n) \ + /* DBGBVRn */ \ + { CRn( 0), CRm((n)), Op1( 0), Op2( 4), is32, \ + trap_debug32, NULL, (cp14_DBGBVR0 + (n)) }, \ + /* DBGBCRn */ \ + { CRn( 0), CRm((n)), Op1( 0), Op2( 5), is32, \ + trap_debug32, NULL, (cp14_DBGBCR0 + (n)) }, \ + /* DBGWVRn */ \ + { CRn( 0), CRm((n)), Op1( 0), Op2( 6), is32, \ + trap_debug32, NULL, (cp14_DBGWVR0 + (n)) }, \ + /* DBGWCRn */ \ + { CRn( 0), CRm((n)), Op1( 0), Op2( 7), is32, \ + trap_debug32, NULL, (cp14_DBGWCR0 + (n)) } + +/* No OS DBGBXVR machanism implemented. */ +#define DBGBXVR(n) \ + { CRn( 1), CRm((n)), Op1( 0), Op2( 1), is32, trap_raz_wi } + +/* + * Trapped cp14 registers. We generally ignore most of the external + * debug, on the principle that they don't really make sense to a + * guest. Revisit this one day, whould this principle change. + */ static const struct coproc_reg cp14_regs[] = { + /* DBGIDR */ + { CRn( 0), CRm( 0), Op1( 0), Op2( 0), is32, trap_dbgidr}, + /* DBGDTRRXext */ + { CRn( 0), CRm( 0), Op1( 0), Op2( 2), is32, trap_raz_wi }, + DBG_BCR_BVR_WCR_WVR(0), + /* DBGDSCRint */ + { CRn( 0), CRm( 1), Op1( 0), Op2( 0), is32, trap_dbgdscr, + NULL, cp14_DBGDSCRext }, + DBG_BCR_BVR_WCR_WVR(1), + /* DBGDSCRext */ + { CRn( 0), CRm( 2), Op1( 0), Op2( 2), is32, trap_debug32, + NULL, cp14_DBGDSCRext }, + DBG_BCR_BVR_WCR_WVR(2), + /* DBGDTRRXext */ + { CRn( 0), CRm( 3), Op1( 0), Op2( 2), is32, trap_raz_wi }, + DBG_BCR_BVR_WCR_WVR(3), + DBG_BCR_BVR_WCR_WVR(4), + /* DBGDTR[RT]Xint */ + { CRn( 0), CRm( 5), Op1( 0), Op2( 0), is32, trap_raz_wi }, + DBG_BCR_BVR_WCR_WVR(5), + DBG_BCR_BVR_WCR_WVR(6), + /* DBGVCR */ + { CRn( 0), CRm( 7), Op1( 0), Op2( 0), is32, trap_debug32 }, + DBG_BCR_BVR_WCR_WVR(7), + DBG_BCR_BVR_WCR_WVR(8), + DBG_BCR_BVR_WCR_WVR(9), + DBG_BCR_BVR_WCR_WVR(10), + DBG_BCR_BVR_WCR_WVR(11), + DBG_BCR_BVR_WCR_WVR(12), + DBG_BCR_BVR_WCR_WVR(13), + DBG_BCR_BVR_WCR_WVR(14), + DBG_BCR_BVR_WCR_WVR(15), + + DBGBXVR(0), + /* DBGOSLAR */ + { CRn( 1), CRm( 0), Op1( 0), Op2( 4), is32, trap_raz_wi }, + DBGBXVR(1), + /* DBGOSLSR */ + { CRn( 1), CRm( 1), Op1( 0), Op2( 4), is32, trap_raz_wi }, + DBGBXVR(2), + DBGBXVR(3), + /* DBGOSDLRd */ + { CRn( 1), CRm( 3), Op1( 0), Op2( 4), is32, trap_raz_wi }, + DBGBXVR(4), + DBGBXVR(5), + /* DBGPRSRa */ + { CRn( 1), CRm( 5), Op1( 0), Op2( 4), is32, trap_raz_wi }, + + DBGBXVR(6), + DBGBXVR(7), + DBGBXVR(8), + DBGBXVR(9), + DBGBXVR(10), + DBGBXVR(11), + DBGBXVR(12), + DBGBXVR(13), + DBGBXVR(14), + DBGBXVR(15), }; /* Target specific emulation tables */