From: <luolongjun@huawei.com>
To: <peterz@infradead.org>, <mingo@redhat.com>, <acme@kernel.org>,
<mark.rutland@arm.com>, <alexander.shishkin@linux.intel.com>,
<jolsa@kernel.org>, <namhyung@kernel.org>
Cc: <linux-kernel@vger.kernel.org>,
<linux-perf-users@vger.kernel.org>, <sangyan@huawei.com>,
<luanjianhai@huawei.com>, <zhuling8@huawei.com>,
<lizongwu@huawei.com>, Longjun Luo <luolongjun@huawei.com>
Subject: [PATCH] uprobe: add UPROBE_ALTER_PC flag for uprobe handlers
Date: Fri, 16 Sep 2022 15:28:46 +0800 [thread overview]
Message-ID: <20220916072846.2145735-1-luolongjun@huawei.com> (raw)
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
reply other threads:[~2022-09-16 7:31 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220916072846.2145735-1-luolongjun@huawei.com \
--to=luolongjun@huawei.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=lizongwu@huawei.com \
--cc=luanjianhai@huawei.com \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=sangyan@huawei.com \
--cc=zhuling8@huawei.com \
/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®