mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] uprobe: add UPROBE_ALTER_PC flag for uprobe handlers
@ 2022-09-16  7:28 luolongjun
  0 siblings, 0 replies; only message in thread
From: luolongjun @ 2022-09-16  7:28 UTC (permalink / raw)
  To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa, namhyung
  Cc: linux-kernel, linux-perf-users, sangyan, luanjianhai, zhuling8,
	lizongwu, Longjun Luo

From: Longjun Luo <luolongjun@huawei.com>

Within uprobe handlers, the pc register could be
modified. In this situation, there is no need to
do a single stepping. Just like the kprobe, we
skip it.

Signed-off-by: Longjun Luo <luolongjun@huawei.com>
---
 include/linux/uprobes.h |  5 +++--
 kernel/events/uprobes.c | 16 +++++++++++++---
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h
index f46e0ca0169c..0670fecbe1ce 100644
--- a/include/linux/uprobes.h
+++ b/include/linux/uprobes.h
@@ -22,8 +22,9 @@ struct inode;
 struct notifier_block;
 struct page;
 
-#define UPROBE_HANDLER_REMOVE		1
-#define UPROBE_HANDLER_MASK		1
+#define UPROBE_HANDLER_REMOVE   0x1
+#define UPROBE_ALTER_PC         0x2
+#define UPROBE_HANDLER_MASK     0x3 /* (UPROBE_HANDLER_REMOVE | UPROBE_ALTER_PC) */
 
 #define MAX_URETPROBE_DEPTH		64
 
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 2eaa327f8158..d01a668fecae 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -2064,10 +2064,16 @@ static struct uprobe *find_active_uprobe(unsigned long bp_vaddr, int *is_swbp)
 	return uprobe;
 }
 
-static void handler_chain(struct uprobe *uprobe, struct pt_regs *regs)
+/*
+ * The return value of handler_chain tags events that happen during
+ * calling handlers. If UPROBE_ALTER_PC happens, we must skip the
+ * single stepping.
+ */
+static int handler_chain(struct uprobe *uprobe, struct pt_regs *regs)
 {
 	struct uprobe_consumer *uc;
 	int remove = UPROBE_HANDLER_REMOVE;
+	int all_events = 0;
 	bool need_prep = false; /* prepare return uprobe, when needed */
 
 	down_read(&uprobe->register_rwsem);
@@ -2084,6 +2090,7 @@ static void handler_chain(struct uprobe *uprobe, struct pt_regs *regs)
 			need_prep = true;
 
 		remove &= rc;
+		all_events |= rc;
 	}
 
 	if (need_prep && !remove)
@@ -2094,6 +2101,7 @@ static void handler_chain(struct uprobe *uprobe, struct pt_regs *regs)
 		unapply_uprobe(uprobe, current->mm);
 	}
 	up_read(&uprobe->register_rwsem);
+	return all_events;
 }
 
 static void
@@ -2183,7 +2191,7 @@ static void handle_swbp(struct pt_regs *regs)
 {
 	struct uprobe *uprobe;
 	unsigned long bp_vaddr;
-	int is_swbp;
+	int is_swbp, all_events;
 
 	bp_vaddr = uprobe_get_swbp_addr(regs);
 	if (bp_vaddr == get_trampoline_vaddr())
@@ -2235,7 +2243,9 @@ static void handle_swbp(struct pt_regs *regs)
 	if (arch_uprobe_ignore(&uprobe->arch, regs))
 		goto out;
 
-	handler_chain(uprobe, regs);
+	all_events = handler_chain(uprobe, regs);
+	if (all_events & UPROBE_ALTER_PC)
+		goto out;
 
 	if (arch_uprobe_skip_sstep(&uprobe->arch, regs))
 		goto out;
-- 
2.37.3


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-09-16  7:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-16  7:28 [PATCH] uprobe: add UPROBE_ALTER_PC flag for uprobe handlers luolongjun

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®