mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: wangxu <wangxu72@huawei.com>
To: <peterz@infradead.org>, <mingo@redhat.com>, <acme@kernel.org>,
	<mark.rutland@arm.com>, <alexander.shishkin@linux.intel.com>,
	<namhyung@kernel.org>, <gregkh@linuxfoundation.org>
Cc: <tglx@linutronix.de>, <rfontana@redhat.com>,
	<allison@lohutok.net>, <linux-kernel@vger.kernel.org>
Subject: [PATCH] sample/hw_breakpoint: avoid sample hw_breakpoint recursion for arm/arm64
Date: Mon, 23 Sep 2019 16:09:35 +0800	[thread overview]
Message-ID: <1569226175-101782-1-git-send-email-wangxu72@huawei.com> (raw)

From: Wang Xu <wangxu72@huawei.com>

For x86/ppc, hw_breakpoint is triggered after the instruction is
executed.

For arm/arm64, which is triggered before the instruction executed.
Arm/arm64 skips the instruction by using single step. But it only
supports default overflow_handler.

This patch provides a chance to avoid sample hw_breakpoint recursion
for arm/arm64 by adding 'struct perf_event_attr.bp_step'.

Signed-off-by: Wang Xu <wangxu72@huawei.com>
---
 include/linux/perf_event.h              | 3 +++
 include/uapi/linux/perf_event.h         | 3 ++-
 samples/hw_breakpoint/data_breakpoint.c | 1 +
 3 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 61448c1..f270eb7 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1024,6 +1024,9 @@ extern int perf_event_output(struct perf_event *event,
 		return true;
 	if (unlikely(event->overflow_handler == perf_event_output_backward))
 		return true;
+	/* avoid sample hw_breakpoint recursion */
+	if (unlikely(event->attr.bp_step))
+		return true;
 	return false;
 }
 
diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index bb7b271..95b81c2 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -375,7 +375,8 @@ struct perf_event_attr {
 				ksymbol        :  1, /* include ksymbol events */
 				bpf_event      :  1, /* include bpf events */
 				aux_output     :  1, /* generate AUX records instead of events */
-				__reserved_1   : 32;
+				bp_step        :  1,
+				__reserved_1   : 31;
 
 	union {
 		__u32		wakeup_events;	  /* wakeup every n events */
diff --git a/samples/hw_breakpoint/data_breakpoint.c b/samples/hw_breakpoint/data_breakpoint.c
index c585047..9fe1351 100644
--- a/samples/hw_breakpoint/data_breakpoint.c
+++ b/samples/hw_breakpoint/data_breakpoint.c
@@ -46,6 +46,7 @@ static int __init hw_break_module_init(void)
 	attr.bp_addr = kallsyms_lookup_name(ksym_name);
 	attr.bp_len = HW_BREAKPOINT_LEN_4;
 	attr.bp_type = HW_BREAKPOINT_W | HW_BREAKPOINT_R;
+	attr.bp_step = true;
 
 	sample_hbp = register_wide_hw_breakpoint(&attr, sample_hbp_handler, NULL);
 	if (IS_ERR((void __force *)sample_hbp)) {
-- 
1.8.5.6


             reply	other threads:[~2019-09-23  8:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-23  8:09 wangxu [this message]
2019-09-26  9:13 ` Peter Zijlstra
2019-09-26 10:15   ` wangxu (AE)
2019-10-01  9:14 ` Will Deacon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1569226175-101782-1-git-send-email-wangxu72@huawei.com \
    --to=wangxu72@huawei.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=allison@lohutok.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rfontana@redhat.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®