linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] Adding missing features of Coresight PTM components
@ 2016-10-05 11:42 Muhammad Abdul WAHAB
  2016-10-05 21:15 ` Mathieu Poirier
  2016-10-06 12:18 ` [PATCH v3] " Muhammad Abdul WAHAB
  0 siblings, 2 replies; 9+ messages in thread
From: Muhammad Abdul WAHAB @ 2016-10-05 11:42 UTC (permalink / raw)
  To: Mathieu Poirier, linux-arm-kernel; +Cc: linux-kernel

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 <muhammadabdul.wahab@centralesupelec.fr>
---
changes in v2 :
	- modified patch description
	- removed additional comments on testing
	- removed a check on architecture version of ETM
	- generated using "git format-patch"
	- same email address in from: and SOB
	
  drivers/hwtracing/coresight/coresight-etm.h         |  3 +++
  drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 12 ++++++++++++
  2 files changed, 15 insertions(+)

diff --git a/drivers/hwtracing/coresight/coresight-etm.h 
b/drivers/hwtracing/coresight/coresight-etm.h
index 4a18ee4..7a34860 100644
--- a/drivers/hwtracing/coresight/coresight-etm.h
+++ b/drivers/hwtracing/coresight/coresight-etm.h
@@ -110,8 +110,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 5ea0909..4e0eab7 100644
--- a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
+++ b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
@@ -164,6 +164,18 @@ 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) {
+		if (config->mode & ETM_MODE_BBROAD)
+			dev_warn(drvdata->dev, "behavior is unpredictable\n");
+		config->ctrl |= ETMCR_RETURN_STACK_EN;
+	} else
+		config->ctrl &= ~ETMCR_RETURN_STACK_EN;
+
  	if (config->mode & (ETM_MODE_EXCL_KERN | ETM_MODE_EXCL_USER))
  		etm_config_trace_mode(config);

-- 
1.9.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] Adding missing features of Coresight PTM components
  2016-10-05 11:42 [PATCH v2] Adding missing features of Coresight PTM components Muhammad Abdul WAHAB
@ 2016-10-05 21:15 ` Mathieu Poirier
  2016-10-06 12:20   ` Muhammad Abdul WAHAB
  2016-10-06 12:18 ` [PATCH v3] " Muhammad Abdul WAHAB
  1 sibling, 1 reply; 9+ messages in thread
From: Mathieu Poirier @ 2016-10-05 21:15 UTC (permalink / raw)
  To: Muhammad Abdul WAHAB; +Cc: linux-arm-kernel, linux-kernel

On 5 October 2016 at 05:42, Muhammad Abdul WAHAB
<muhammadabdul.wahab@centralesupelec.fr> wrote:
> 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 <muhammadabdul.wahab@centralesupelec.fr>
> ---
> changes in v2 :
>         - modified patch description
>         - removed additional comments on testing
>         - removed a check on architecture version of ETM
>         - generated using "git format-patch"
>         - same email address in from: and SOB
>
>  drivers/hwtracing/coresight/coresight-etm.h         |  3 +++
>  drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 12 ++++++++++++
>  2 files changed, 15 insertions(+)
>
> diff --git a/drivers/hwtracing/coresight/coresight-etm.h
> b/drivers/hwtracing/coresight/coresight-etm.h
> index 4a18ee4..7a34860 100644
> --- a/drivers/hwtracing/coresight/coresight-etm.h
> +++ b/drivers/hwtracing/coresight/coresight-etm.h
> @@ -110,8 +110,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 5ea0909..4e0eab7 100644
> --- a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
> +++ b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
> @@ -164,6 +164,18 @@ 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) {
> +               if (config->mode & ETM_MODE_BBROAD)
> +                       dev_warn(drvdata->dev, "behavior is
> unpredictable\n");

Please remove the warning message as well - there is no point having
it there because:

1) From sysFS users are supposed to know what they're doing.
2) If we start warning users on all the things that can go wrong the
code will become unbelievably cluttered.

Thanks,
Mathieu

> +               config->ctrl |= ETMCR_RETURN_STACK_EN;
> +       } else
> +               config->ctrl &= ~ETMCR_RETURN_STACK_EN;
> +
>         if (config->mode & (ETM_MODE_EXCL_KERN | ETM_MODE_EXCL_USER))
>                 etm_config_trace_mode(config);
>
> --
> 1.9.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v3] Adding missing features of Coresight PTM components
  2016-10-05 11:42 [PATCH v2] Adding missing features of Coresight PTM components Muhammad Abdul WAHAB
  2016-10-05 21:15 ` Mathieu Poirier
@ 2016-10-06 12:18 ` Muhammad Abdul WAHAB
  2016-10-06 15:52   ` Mathieu Poirier
  2016-10-07 12:16   ` [PATCH v4] " Muhammad Abdul WAHAB
  1 sibling, 2 replies; 9+ messages in thread
From: Muhammad Abdul WAHAB @ 2016-10-06 12:18 UTC (permalink / raw)
  To: Mathieu Poirier; +Cc: linux-arm-kernel, linux-kernel

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 <muhammadabdul.wahab@centralesupelec.fr>
---
changes in v3 :
	- deleted warning message
	- bit field definition of Branch Broadcast and Return Stack

  drivers/hwtracing/coresight/coresight-etm.h         |  5 +++++
  drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 10 ++++++++++
  2 files changed, 15 insertions(+)

diff --git a/drivers/hwtracing/coresight/coresight-etm.h 
b/drivers/hwtracing/coresight/coresight-etm.h
index 4a18ee4..ad063d7 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 5ea0909..a76009a 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_EN;
+	else
+		config->ctrl &= ~ETMCR_RETURN_STACK_EN;
+
  	if (config->mode & (ETM_MODE_EXCL_KERN | ETM_MODE_EXCL_USER))
  		etm_config_trace_mode(config);

-- 
1.9.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] Adding missing features of Coresight PTM components
  2016-10-05 21:15 ` Mathieu Poirier
@ 2016-10-06 12:20   ` Muhammad Abdul WAHAB
  0 siblings, 0 replies; 9+ messages in thread
From: Muhammad Abdul WAHAB @ 2016-10-06 12:20 UTC (permalink / raw)
  To: Mathieu Poirier; +Cc: linux-arm-kernel, linux-kernel

Hi Mathieu,

> Please remove the warning message as well - there is no point having
> it there because:
>
> 1) From sysFS users are supposed to know what they're doing.
> 2) If we start warning users on all the things that can go wrong the
> code will become unbelievably cluttered.
>
> Thanks,
> Mathieu

A third version of the patch was sent to you. Thank you for explanation 
about warnings. I had forgotten two defines that I added also in the patch.

Thanks,
M.Abdul WAHAB

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3] Adding missing features of Coresight PTM components
  2016-10-06 12:18 ` [PATCH v3] " Muhammad Abdul WAHAB
@ 2016-10-06 15:52   ` Mathieu Poirier
  2016-10-06 15:57     ` Muhammad Abdul WAHAB
  2016-10-07 12:16   ` [PATCH v4] " Muhammad Abdul WAHAB
  1 sibling, 1 reply; 9+ messages in thread
From: Mathieu Poirier @ 2016-10-06 15:52 UTC (permalink / raw)
  To: Muhammad Abdul WAHAB; +Cc: linux-arm-kernel, linux-kernel

On 6 October 2016 at 06:18, Muhammad Abdul WAHAB
<muhammadabdul.wahab@centralesupelec.fr> wrote:
> 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 <muhammadabdul.wahab@centralesupelec.fr>
> ---
> changes in v3 :
>         - deleted warning message
>         - bit field definition of Branch Broadcast and Return Stack
>
>  drivers/hwtracing/coresight/coresight-etm.h         |  5 +++++
>  drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 10 ++++++++++
>  2 files changed, 15 insertions(+)
>
> diff --git a/drivers/hwtracing/coresight/coresight-etm.h
> b/drivers/hwtracing/coresight/coresight-etm.h
> index 4a18ee4..ad063d7 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 5ea0909..a76009a 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_EN;
> +       else
> +               config->ctrl &= ~ETMCR_RETURN_STACK_EN;
> +

Where is ETMCR_RETURN_STACK_EN defined?  Did you send me code that
doesn't compile?

>         if (config->mode & (ETM_MODE_EXCL_KERN | ETM_MODE_EXCL_USER))
>                 etm_config_trace_mode(config);
>
> --
> 1.9.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3] Adding missing features of Coresight PTM components
  2016-10-06 15:52   ` Mathieu Poirier
@ 2016-10-06 15:57     ` Muhammad Abdul WAHAB
  2016-10-06 16:10       ` Mathieu Poirier
  0 siblings, 1 reply; 9+ messages in thread
From: Muhammad Abdul WAHAB @ 2016-10-06 15:57 UTC (permalink / raw)
  To: Mathieu Poirier; +Cc: linux-arm-kernel, linux-kernel

Hi,

 > Where is ETMCR_RETURN_STACK_EN defined?  Did you send me code that
 > doesn't compile?

I changed the naming in the .h file before submitting it and I forgot to 
change it in .c file. I am sorry. It is defined in coresight-etm.h.
Here is the correct patch.
---
  drivers/hwtracing/coresight/coresight-etm.h         |  5 +++++
  drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 10 ++++++++++
  2 files changed, 15 insertions(+)

diff --git a/drivers/hwtracing/coresight/coresight-etm.h 
b/drivers/hwtracing/coresight/coresight-etm.h
index 4a18ee4..ad063d7 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 5ea0909..a76009a 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);

-- 
1.9.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v3] Adding missing features of Coresight PTM components
  2016-10-06 15:57     ` Muhammad Abdul WAHAB
@ 2016-10-06 16:10       ` Mathieu Poirier
  0 siblings, 0 replies; 9+ messages in thread
From: Mathieu Poirier @ 2016-10-06 16:10 UTC (permalink / raw)
  To: Muhammad Abdul WAHAB; +Cc: linux-arm-kernel, linux-kernel

On 6 October 2016 at 09:57, Muhammad Abdul WAHAB
<muhammadabdul.wahab@centralesupelec.fr> wrote:
> Hi,
>
>> Where is ETMCR_RETURN_STACK_EN defined?  Did you send me code that
>> doesn't compile?
>
> I changed the naming in the .h file before submitting it and I forgot to
> change it in .c file. I am sorry. It is defined in coresight-etm.h.
> Here is the correct patch.

Then send me a proper V4 patch.

>From hereon I suggest you compile your code before sending patches to
the mailing list - other people won't be as lenient as I am.

> ---
>  drivers/hwtracing/coresight/coresight-etm.h         |  5 +++++
>  drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 10 ++++++++++
>  2 files changed, 15 insertions(+)
>
> diff --git a/drivers/hwtracing/coresight/coresight-etm.h
> b/drivers/hwtracing/coresight/coresight-etm.h
> index 4a18ee4..ad063d7 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 5ea0909..a76009a 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);
>
> --
> 1.9.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v4] Adding missing features of Coresight PTM components
  2016-10-06 12:18 ` [PATCH v3] " Muhammad Abdul WAHAB
  2016-10-06 15:52   ` Mathieu Poirier
@ 2016-10-07 12:16   ` Muhammad Abdul WAHAB
  2016-10-07 21:44     ` Mathieu Poirier
  1 sibling, 1 reply; 9+ messages in thread
From: Muhammad Abdul WAHAB @ 2016-10-07 12:16 UTC (permalink / raw)
  To: Mathieu Poirier; +Cc: linux-arm-kernel, linux-kernel

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 <muhammadabdul.wahab@centralesupelec.fr>
---
change(s) in v4 :
	- syntax error correction (sorry did not compile after 1st version but 
did compile it before sending it this time)

drivers/hwtracing/coresight/coresight-etm.h         |  5 +++++
  drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 10 ++++++++++
  2 files changed, 15 insertions(+)

diff --git a/drivers/hwtracing/coresight/coresight-etm.h 
b/drivers/hwtracing/coresight/coresight-etm.h
index 4a18ee4..ad063d7 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 e9b0719..7308304 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);

-- 
1.9.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v4] Adding missing features of Coresight PTM components
  2016-10-07 12:16   ` [PATCH v4] " Muhammad Abdul WAHAB
@ 2016-10-07 21:44     ` Mathieu Poirier
  0 siblings, 0 replies; 9+ messages in thread
From: Mathieu Poirier @ 2016-10-07 21:44 UTC (permalink / raw)
  To: Muhammad Abdul WAHAB; +Cc: linux-arm-kernel, linux-kernel

On 7 October 2016 at 06:16, Muhammad Abdul WAHAB
<muhammadabdul.wahab@centralesupelec.fr> wrote:
> 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 <muhammadabdul.wahab@centralesupelec.fr>
> ---
> change(s) in v4 :
>         - syntax error correction (sorry did not compile after 1st version
> but did compile it before sending it this time)
>
> drivers/hwtracing/coresight/coresight-etm.h         |  5 +++++
>  drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 10 ++++++++++
>  2 files changed, 15 insertions(+)
>
> diff --git a/drivers/hwtracing/coresight/coresight-etm.h
> b/drivers/hwtracing/coresight/coresight-etm.h
> index 4a18ee4..ad063d7 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 e9b0719..7308304 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);

Applied.

Thanks,
Mathieu

>
> --
> 1.9.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-10-07 21:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-05 11:42 [PATCH v2] Adding missing features of Coresight PTM components Muhammad Abdul WAHAB
2016-10-05 21:15 ` Mathieu Poirier
2016-10-06 12:20   ` Muhammad Abdul WAHAB
2016-10-06 12:18 ` [PATCH v3] " Muhammad Abdul WAHAB
2016-10-06 15:52   ` Mathieu Poirier
2016-10-06 15:57     ` Muhammad Abdul WAHAB
2016-10-06 16:10       ` Mathieu Poirier
2016-10-07 12:16   ` [PATCH v4] " Muhammad Abdul WAHAB
2016-10-07 21:44     ` Mathieu Poirier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).