From patchwork Sun May 31 04:27:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhichao Huang X-Patchwork-Id: 49265 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4F57824588 for ; Sun, 31 May 2015 04:35:16 +0000 (UTC) Received: by wgme6 with SMTP id e6sf26358367wgm.3 for ; Sat, 30 May 2015 21:35:15 -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=dtMM4XL1sjSKAOLEvH3cFRyFPr77cgHPACGYgo/vX4E=; b=TLUDnoGRQtJ2sIuV5EhGTn3efzIimY/ZFfTnJJLovA8iMksmkpAMVfBieWHNCiJPot qX9Qgzej8dziEhT9nNq2YmmLtPPnTtLuX4mOscWWWu1thXg6xB1i8EYQZz7YCG7wIa/K uF+TunDB2CA6v2w5GsGHY0D+GwKlkBEYxF2zSMnsytUDdm+WtTnpQN0znsg1Jv9x4Yqg swvbwvvJCz1y9GveTn+utHiUFFggM9FVJiX5emj6CDHLlUbx2Z5Zb6Q1ltlnMEcRcKf3 MpwiIQAqot4uvUb7bdzGZoGQklYNHLPW3VJrpm/+TVZkE7qg8H6FaCnaorKNs0mzQy2C F1dQ== X-Gm-Message-State: ALoCoQmdTKSBgdWDRUnno11PyepkRGZ/zD4Fx0uGtLNa+d75ncAKuegZhLkiAwaBm5Gr39x8wTZc X-Received: by 10.194.175.36 with SMTP id bx4mr14652937wjc.1.1433046915640; Sat, 30 May 2015 21:35:15 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.100 with SMTP id z4ls420107laz.57.gmail; Sat, 30 May 2015 21:35:15 -0700 (PDT) X-Received: by 10.152.7.206 with SMTP id l14mr6922317laa.3.1433046915486; Sat, 30 May 2015 21:35:15 -0700 (PDT) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id uq2si8870911lbc.120.2015.05.30.21.35.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 30 May 2015 21:35:15 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by labko7 with SMTP id ko7so76978299lab.2 for ; Sat, 30 May 2015 21:35:15 -0700 (PDT) X-Received: by 10.152.87.204 with SMTP id ba12mr15480711lab.35.1433046914711; Sat, 30 May 2015 21:35:14 -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 hn6csp1398099lbb; Sat, 30 May 2015 21:35:13 -0700 (PDT) X-Received: by 10.68.131.196 with SMTP id oo4mr28446437pbb.119.1433046912906; Sat, 30 May 2015 21:35:12 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id ez11si15555405pac.113.2015.05.30.21.35.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 30 May 2015 21:35:12 -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 1Yyuvw-000100-AJ; Sun, 31 May 2015 04:33:12 +0000 Received: from mail-pd0-f180.google.com ([209.85.192.180]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YyutH-0006LH-Ht for linux-arm-kernel@lists.infradead.org; Sun, 31 May 2015 04:30:29 +0000 Received: by pdbqa5 with SMTP id qa5so83090658pdb.0 for ; Sat, 30 May 2015 21:30:06 -0700 (PDT) X-Received: by 10.70.126.225 with SMTP id nb1mr29033690pdb.71.1433046606427; Sat, 30 May 2015 21:30:06 -0700 (PDT) Received: from localhost ([167.160.116.87]) by mx.google.com with ESMTPSA id de4sm10147756pbb.95.2015.05.30.21.30.02 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sat, 30 May 2015 21:30:05 -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 v2 09/11] KVM: arm: disable debug mode if we don't actually need it. Date: Sun, 31 May 2015 12:27:10 +0800 Message-Id: <1433046432-1824-10-git-send-email-zhichao.huang@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1433046432-1824-1-git-send-email-zhichao.huang@linaro.org> References: <1433046432-1824-1-git-send-email-zhichao.huang@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150530_213027_739363_C9F34094 X-CRM114-Status: GOOD ( 15.34 ) X-Spam-Score: -1.8 (-) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-1.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.192.180 listed in list.dnswl.org] -1.1 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.192.180 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record 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.43 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 Until now we enable debug mode all the time even if we don't actually need it. Inspired by the implementation in arm64, disable debug mode if we don't need it. And then we are able to reduce unnecessary registers saving/restoring when the debug mode is disabled. Signed-off-by: Zhichao Huang --- arch/arm/kernel/hw_breakpoint.c | 55 ++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c index dc7d0a9..1d27563 100644 --- a/arch/arm/kernel/hw_breakpoint.c +++ b/arch/arm/kernel/hw_breakpoint.c @@ -266,8 +266,7 @@ static int enable_monitor_mode(void) } /* Check that the write made it through. */ - ARM_DBG_READ(c0, c1, 0, dscr); - if (!(dscr & ARM_DSCR_MDBGEN)) { + if (!monitor_mode_enabled()) { pr_warn_once("Failed to enable monitor mode on CPU %d.\n", smp_processor_id()); return -EPERM; @@ -277,6 +276,43 @@ out: return 0; } +static int disable_monitor_mode(void) +{ + u32 dscr; + + ARM_DBG_READ(c0, c1, 0, dscr); + + /* If monitor mode is already disabled, just return. */ + if (!(dscr & ARM_DSCR_MDBGEN)) + goto out; + + /* Write to the corresponding DSCR. */ + switch (get_debug_arch()) { + case ARM_DEBUG_ARCH_V6: + case ARM_DEBUG_ARCH_V6_1: + ARM_DBG_WRITE(c0, c1, 0, (dscr & ~ARM_DSCR_MDBGEN)); + break; + case ARM_DEBUG_ARCH_V7_ECP14: + case ARM_DEBUG_ARCH_V7_1: + case ARM_DEBUG_ARCH_V8: + ARM_DBG_WRITE(c0, c2, 2, (dscr & ~ARM_DSCR_MDBGEN)); + isb(); + break; + default: + return -ENODEV; + } + + /* Check that the write made it through. */ + if (monitor_mode_enabled()) { + pr_warn_once("Failed to disable monitor mode on CPU %d.\n", + smp_processor_id()); + return -EPERM; + } + +out: + return 0; +} + int hw_breakpoint_slots(int type) { if (!debug_arch_supported()) @@ -338,6 +374,8 @@ int arch_install_hw_breakpoint(struct perf_event *bp) int i, max_slots, ctrl_base, val_base; u32 addr, ctrl; + enable_monitor_mode(); + addr = info->address; ctrl = encode_ctrl_reg(info->ctrl) | 0x1; @@ -430,6 +468,8 @@ void arch_uninstall_hw_breakpoint(struct perf_event *bp) /* Reset the control register. */ write_wb_reg(base + i, 0); + + disable_monitor_mode(); } static int get_hbp_len(u8 hbp_len) @@ -598,9 +638,6 @@ int arch_validate_hwbkpt_settings(struct perf_event *bp) int ret = 0; u32 offset, alignment_mask = 0x3; - /* Ensure that we are in monitor debug mode. */ - if (!monitor_mode_enabled()) - return -ENODEV; /* Build the arch_hw_breakpoint. */ ret = arch_build_bp_info(bp); @@ -1013,12 +1050,12 @@ clear_vcr: } /* - * Have a crack at enabling monitor mode. We don't actually need - * it yet, but reporting an error early is useful if it fails. + * We don't enable monitor mode here as we don't actually need it yet. + * We would enable monitor mode when we actually install hwbreakpoint. */ out_mdbgen: - if (enable_monitor_mode()) - cpumask_or(&debug_err_mask, &debug_err_mask, cpumask_of(cpu)); + + return; } static int dbg_reset_notify(struct notifier_block *self,