From patchwork Tue Nov 29 16:47:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 84877 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1677813qgi; Tue, 29 Nov 2016 08:49:51 -0800 (PST) X-Received: by 10.98.7.151 with SMTP id 23mr28671813pfh.5.1480438191254; Tue, 29 Nov 2016 08:49:51 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 205si60616819pgg.273.2016.11.29.08.49.50; Tue, 29 Nov 2016 08:49:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757220AbcK2Qto (ORCPT + 25 others); Tue, 29 Nov 2016 11:49:44 -0500 Received: from mail-io0-f173.google.com ([209.85.223.173]:33404 "EHLO mail-io0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756453AbcK2QrY (ORCPT ); Tue, 29 Nov 2016 11:47:24 -0500 Received: by mail-io0-f173.google.com with SMTP id j65so299645893iof.0 for ; Tue, 29 Nov 2016 08:47:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OMSYe8BpKLNYTGl3jmbmwmglNLRh+lIbRFrOvtjtj3c=; b=NJPNAYhiQF0CRftxEReGS7ua95OFhOcANpTKV9XaUPjfjSpfykFizRBWqaQmn/XNMr LGUrthO31iDdCobbtlUGYBXbLE561YZoWbQaN9WEgjK2RJx/PGbpnQIQsiv6ebZRvjuo YEGnk5GeVmNOF8jRa0Afe7BSgI6wb0XYyzkAQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OMSYe8BpKLNYTGl3jmbmwmglNLRh+lIbRFrOvtjtj3c=; b=VbJtontwYBxABWvlkzhE8U/mgeEjCU6w4/IbchzvcKaeSk8MpBmbawthoJweBr8Z4A KtMb2BGCssR/J3Su+Yw7qIgLCVwbgm+msf+CNCryp8e0PEM4paOapsqxM9Qo60vAYhko Wrqmbpnu7ci9fOjZ7ArEqPku+0NZ4Wqz882brkrm6Osojnb3qJpDU9geVESO81U4T2S8 pDgmvGuLT5HzryLNbMwlQdF3VOYFcuH8boJ/8/lutar/F+SFuuqUxVZ5vhD9SJVPv8B4 a0oKPY0NuWWz/pRvMvMonchpVIVXtG9idxY2vc/HnKityeVaq6M2h+b4v2jHJCr2gpzI 5eHA== X-Gm-Message-State: AKaTC00GCyyrXb2ZEgIne8GOXQEe2zyOih0MeLdYwOD1jUdrQuaZYX4jcbKXy/FvoIPBhLR3 X-Received: by 10.107.169.150 with SMTP id f22mr25074784ioj.7.1480438043764; Tue, 29 Nov 2016 08:47:23 -0800 (PST) Received: from t430.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id l3sm21810442ioa.7.2016.11.29.08.47.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 29 Nov 2016 08:47:23 -0800 (PST) From: Mathieu Poirier To: gregkh@linuxfoundation.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/9] coresight: etm3x: Adding missing features of Coresight PTM components Date: Tue, 29 Nov 2016 09:47:13 -0700 Message-Id: <1480438039-24960-4-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1480438039-24960-1-git-send-email-mathieu.poirier@linaro.org> References: <1480438039-24960-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Muhammad Abdul WAHAB In the current driver for Coresight components, two features of PTM components are missing: 1. Branch Broadcasting (present also in ETM but called Branch Output) 2. Return Stack (only present in PTM v1.0 and PTMv1.1) These features can be added simply to the code using `mode` field of `etm_config` struct. 1. **Branch Broadcast** : The branch broadcast feature is present in ETM components as well and is called Branch output. It allows to retrieve addresses for direct branch addresses alongside the indirect branch addresses. For example, it could be useful in cases when tracing without source code. 2. **Return Stack** : The return stack option allows to retrieve the return addresses of function calls. It can be useful to avoid CRA (Code Reuse Attacks) by keeping a shadowstack. Signed-off-by: Muhammad Abdul Wahab Signed-off-by: Mathieu Poirier --- drivers/hwtracing/coresight/coresight-etm.h | 5 +++++ drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 10 ++++++++++ 2 files changed, 15 insertions(+) -- 2.7.4 diff --git a/drivers/hwtracing/coresight/coresight-etm.h b/drivers/hwtracing/coresight/coresight-etm.h index 4a18ee499965..ad063d7444e1 100644 --- a/drivers/hwtracing/coresight/coresight-etm.h +++ b/drivers/hwtracing/coresight/coresight-etm.h @@ -89,11 +89,13 @@ /* ETMCR - 0x00 */ #define ETMCR_PWD_DWN BIT(0) #define ETMCR_STALL_MODE BIT(7) +#define ETMCR_BRANCH_BROADCAST BIT(8) #define ETMCR_ETM_PRG BIT(10) #define ETMCR_ETM_EN BIT(11) #define ETMCR_CYC_ACC BIT(12) #define ETMCR_CTXID_SIZE (BIT(14)|BIT(15)) #define ETMCR_TIMESTAMP_EN BIT(28) +#define ETMCR_RETURN_STACK BIT(29) /* ETMCCR - 0x04 */ #define ETMCCR_FIFOFULL BIT(23) /* ETMPDCR - 0x310 */ @@ -110,8 +112,11 @@ #define ETM_MODE_STALL BIT(2) #define ETM_MODE_TIMESTAMP BIT(3) #define ETM_MODE_CTXID BIT(4) +#define ETM_MODE_BBROAD BIT(5) +#define ETM_MODE_RET_STACK BIT(6) #define ETM_MODE_ALL (ETM_MODE_EXCLUDE | ETM_MODE_CYCACC | \ ETM_MODE_STALL | ETM_MODE_TIMESTAMP | \ + ETM_MODE_BBROAD | ETM_MODE_RET_STACK | \ ETM_MODE_CTXID | ETM_MODE_EXCL_KERN | \ ETM_MODE_EXCL_USER) diff --git a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c index 5ea090955c08..ca98ad13bb8c 100644 --- a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +++ b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c @@ -164,6 +164,16 @@ static ssize_t mode_store(struct device *dev, else config->ctrl &= ~ETMCR_CTXID_SIZE; + if (config->mode & ETM_MODE_BBROAD) + config->ctrl |= ETMCR_BRANCH_BROADCAST; + else + config->ctrl &= ~ETMCR_BRANCH_BROADCAST; + + if (config->mode & ETM_MODE_RET_STACK) + config->ctrl |= ETMCR_RETURN_STACK; + else + config->ctrl &= ~ETMCR_RETURN_STACK; + if (config->mode & (ETM_MODE_EXCL_KERN | ETM_MODE_EXCL_USER)) etm_config_trace_mode(config);