From patchwork Mon Aug 10 13:26:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhichao Huang X-Patchwork-Id: 52259 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by patches.linaro.org (Postfix) with ESMTPS id E18C822919 for ; Mon, 10 Aug 2015 13:34:02 +0000 (UTC) Received: by lbck9 with SMTP id k9sf10374597lbc.0 for ; Mon, 10 Aug 2015 06:34:01 -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:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:cc:mime-version :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=sFBwcVnVBsBxOxYEr601URz0j144/grDTqGBbi5jLqc=; b=XgQr4rhzRT9gEQ+AiDJLGCViAjyGsJTw0dzmtEdmBJj1QesYP49KESyDGW3VqsjBmX lFgbPvnBCQzCx9o08LPSI/0G7kU7GOHiCdoc2aCw/8xYp4JXnYUlfAWvjpec07jQHb89 CoFuWt4t24jvjp6DHCDoX08oWMPWvFkRjMJcnH45sdcQ7XuNPkYn2SM84MbVh7s8Mdqe x/nMm1IsHeV1jIsN1UKjBRY88cJ7odJ2sBbulyipX4NUS0xsvUXRyvxGSbIPMeHs7E0C qJ2f0knJCPBswGh0jvn1MPILFbjSyGUVcZpPTk2jLwLdVF21foDWkh2sqJcNf9g1yyaH brkg== X-Gm-Message-State: ALoCoQko+cdQrIs8axbbMoENz5SWQXvzB2RAVl7N1OCKVmojAtiDI3CxlAPxjdKZK7jcToWhDYJy X-Received: by 10.180.82.101 with SMTP id h5mr1125133wiy.1.1439213641850; Mon, 10 Aug 2015 06:34:01 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.1 with SMTP id m1ls349477laj.32.gmail; Mon, 10 Aug 2015 06:34:01 -0700 (PDT) X-Received: by 10.152.3.199 with SMTP id e7mr19818963lae.98.1439213641557; Mon, 10 Aug 2015 06:34:01 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id lc8si13994231lac.151.2015.08.10.06.34.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Aug 2015 06:34:01 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by lbbpu9 with SMTP id pu9so67692273lbb.3 for ; Mon, 10 Aug 2015 06:34:01 -0700 (PDT) X-Received: by 10.112.129.137 with SMTP id nw9mr13899839lbb.19.1439213641122; Mon, 10 Aug 2015 06:34:01 -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.7.198 with SMTP id l6csp1938111lba; Mon, 10 Aug 2015 06:34:00 -0700 (PDT) X-Received: by 10.70.38.69 with SMTP id e5mr44588983pdk.27.1439213639988; Mon, 10 Aug 2015 06:33:59 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id ea3si33172883pbb.1.2015.08.10.06.33.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Aug 2015 06:33:59 -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 1ZOnBw-0004Mn-42; Mon, 10 Aug 2015 13:32:40 +0000 Received: from mail-pa0-f42.google.com ([209.85.220.42]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZOn8W-0007r4-12 for linux-arm-kernel@lists.infradead.org; Mon, 10 Aug 2015 13:29:15 +0000 Received: by pacgr6 with SMTP id gr6so27304966pac.2 for ; Mon, 10 Aug 2015 06:28:48 -0700 (PDT) X-Received: by 10.66.185.199 with SMTP id fe7mr45335709pac.48.1439213328803; Mon, 10 Aug 2015 06:28:48 -0700 (PDT) Received: from localhost ([199.168.112.128]) by smtp.gmail.com with ESMTPSA id ew13sm5368084pac.25.2015.08.10.06.28.46 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 10 Aug 2015 06:28:47 -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, will.deacon@arm.com Subject: [PATCH v4 12/15] KVM: arm: keep track of host use of the debug registers Date: Mon, 10 Aug 2015 21:26:04 +0800 Message-Id: <1439213167-8988-13-git-send-email-zhichao.huang@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1439213167-8988-1-git-send-email-zhichao.huang@linaro.org> References: <1439213167-8988-1-git-send-email-zhichao.huang@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150810_062908_660214_7724065D X-CRM114-Status: GOOD ( 13.61 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.220.42 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.220.42 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Cc: huangzhichao@huawei.com, Zhichao Huang 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.217.169 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 Every guest entry, we need to keep track of host use of the debug registers. We only call the function upon guest entry, after preempt_disable() and local_irq_disable(), so there is no race for it. Signed-off-by: Zhichao Huang --- arch/arm/include/asm/kvm_asm.h | 3 +++ arch/arm/include/asm/kvm_host.h | 4 ++++ arch/arm/kernel/asm-offsets.c | 1 + arch/arm/kvm/arm.c | 2 ++ arch/arm/kvm/coproc.c | 8 ++++++++ arch/arm64/include/asm/kvm_host.h | 1 + 6 files changed, 19 insertions(+) diff --git a/arch/arm/include/asm/kvm_asm.h b/arch/arm/include/asm/kvm_asm.h index 7443a3a..5b1c3eb 100644 --- a/arch/arm/include/asm/kvm_asm.h +++ b/arch/arm/include/asm/kvm_asm.h @@ -64,6 +64,9 @@ #define cp14_DBGDSCRext 65 /* Debug Status and Control external */ #define NR_CP14_REGS 66 /* Number of regs (incl. invalid) */ +#define KVM_ARM_DEBUG_HOST_INUSE_SHIFT 0 +#define KVM_ARM_DEBUG_HOST_INUSE (1 << KVM_ARM_DEBUG_HOST_INUSE_SHIFT) + #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 fc461ac..7338f34 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -131,6 +131,9 @@ struct kvm_vcpu_arch { /* System control coprocessor (cp14) */ u32 cp14[NR_CP14_REGS]; + /* Debug State */ + u32 debug_flags; + /* * Anything that is not used directly from assembly code goes * here. @@ -237,5 +240,6 @@ static inline void kvm_arch_hardware_unsetup(void) {} static inline void kvm_arch_sync_events(struct kvm *kvm) {} static inline void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) {} static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} +void kvm_arm_setup_debug(struct kvm_vcpu *vcpu); #endif /* __ARM_KVM_HOST_H__ */ diff --git a/arch/arm/kernel/asm-offsets.c b/arch/arm/kernel/asm-offsets.c index cee4254..7750597 100644 --- a/arch/arm/kernel/asm-offsets.c +++ b/arch/arm/kernel/asm-offsets.c @@ -178,6 +178,7 @@ int main(void) DEFINE(VCPU_HOST_CONTEXT, offsetof(struct kvm_vcpu, arch.host_cpu_context)); DEFINE(VCPU_VFP_HOST, offsetof(struct kvm_cpu_context, vfp)); DEFINE(VCPU_CP14_HOST, offsetof(struct kvm_cpu_context, cp14)); + DEFINE(VCPU_DEBUG_FLAGS, offsetof(struct kvm_vcpu, arch.debug_flags)); DEFINE(VCPU_REGS, offsetof(struct kvm_vcpu, arch.regs)); DEFINE(VCPU_USR_REGS, offsetof(struct kvm_vcpu, arch.regs.usr_regs)); DEFINE(VCPU_SVC_REGS, offsetof(struct kvm_vcpu, arch.regs.svc_regs)); diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index bc738d2..0129346 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -550,6 +550,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) continue; } + kvm_arm_setup_debug(vcpu); + /************************************************************** * Enter the guest */ diff --git a/arch/arm/kvm/coproc.c b/arch/arm/kvm/coproc.c index d15b250..b37afd6 100644 --- a/arch/arm/kvm/coproc.c +++ b/arch/arm/kvm/coproc.c @@ -1516,3 +1516,11 @@ void kvm_reset_coprocs(struct kvm_vcpu *vcpu) if (vcpu->arch.cp15[num] == 0x42424242) panic("Didn't reset vcpu->arch.cp15[%zi]", num); } + +void kvm_arm_setup_debug(struct kvm_vcpu *vcpu) +{ + if (hw_breakpoint_enabled()) + vcpu->arch.debug_flags |= KVM_ARM_DEBUG_HOST_INUSE; + else + vcpu->arch.debug_flags &= ~KVM_ARM_DEBUG_HOST_INUSE; +} diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 2709db2..84fa4f0 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -226,5 +226,6 @@ static inline void kvm_arch_hardware_unsetup(void) {} static inline void kvm_arch_sync_events(struct kvm *kvm) {} static inline void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) {} static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} +static inline void kvm_arm_setup_debug(struct kvm_vcpu *vcpu) {} #endif /* __ARM64_KVM_HOST_H__ */