From: Masami Hiramatsu <mhiramat@kernel.org>
To: Josh Poimboeuf <jpoimboe@redhat.com>, Ingo Molnar <mingo@kernel.org>
Cc: X86 ML <x86@kernel.org>, Masami Hiramatsu <mhiramat@kernel.org>,
Daniel Xu <dxu@dxuuu.xyz>,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
kuba@kernel.org, mingo@redhat.com, ast@kernel.org,
tglx@linutronix.de, kernel-team@fb.com, yhs@fb.com,
Steven Rostedt <rostedt@goodmis.org>
Subject: [RFC PATCH -tip 2/3] kprobes: Add functions to find instruction buffer entry address
Date: Wed, 31 Mar 2021 14:44:45 +0900 [thread overview]
Message-ID: <161716948533.721514.17707467357877538662.stgit@devnote2> (raw)
In-Reply-To: <161716946413.721514.4057380464113663840.stgit@devnote2>
Add find_kprobe_{insn,optinsn}_slot_entry() functions to find
corresponding entry address of the kprobe instrurction buffer
which includes given address.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
include/linux/kprobes.h | 8 ++++++++
kernel/kprobes.c | 25 ++++++++++++++++++-------
2 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index f530f82a046d..08adfd6cf562 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -305,6 +305,8 @@ extern void __free_insn_slot(struct kprobe_insn_cache *c,
/* sleep-less address checking routine */
extern bool __is_insn_slot_addr(struct kprobe_insn_cache *c,
unsigned long addr);
+extern unsigned long
+__find_insn_slot_entry(struct kprobe_insn_cache *c, unsigned long addr);
#define DEFINE_INSN_CACHE_OPS(__name) \
extern struct kprobe_insn_cache kprobe_##__name##_slots; \
@@ -322,6 +324,12 @@ static inline void free_##__name##_slot(kprobe_opcode_t *slot, int dirty)\
static inline bool is_kprobe_##__name##_slot(unsigned long addr) \
{ \
return __is_insn_slot_addr(&kprobe_##__name##_slots, addr); \
+} \
+ \
+static inline unsigned long \
+find_kprobe_##__name##_slot_entry(unsigned long addr) \
+{ \
+ return __find_insn_slot_entry(&kprobe_##__name##_slots, addr); \
}
#define KPROBE_INSN_PAGE_SYM "kprobe_insn_page"
#define KPROBE_OPTINSN_PAGE_SYM "kprobe_optinsn_page"
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 4ce3e6f5d28d..b62635969fa6 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -277,26 +277,37 @@ void __free_insn_slot(struct kprobe_insn_cache *c,
}
/*
- * Check given address is on the page of kprobe instruction slots.
- * This will be used for checking whether the address on a stack
- * is on a text area or not.
+ * Find the entry address of the kprobe instruction slots where the
+ * @addr points.
*/
-bool __is_insn_slot_addr(struct kprobe_insn_cache *c, unsigned long addr)
+unsigned long
+__find_insn_slot_entry(struct kprobe_insn_cache *c, unsigned long addr)
{
struct kprobe_insn_page *kip;
- bool ret = false;
+ unsigned long entry = 0, index;
rcu_read_lock();
list_for_each_entry_rcu(kip, &c->pages, list) {
if (addr >= (unsigned long)kip->insns &&
addr < (unsigned long)kip->insns + PAGE_SIZE) {
- ret = true;
+ index = (addr - (unsigned long)kip->insns) / c->insn_size;
+ entry = (unsigned long)kip->insns + (index * c->insn_size);
break;
}
}
rcu_read_unlock();
- return ret;
+ return entry;
+}
+
+/*
+ * Check given address is on the page of kprobe instruction slots.
+ * This will be used for checking whether the address on a stack
+ * is on a text area or not.
+ */
+bool __is_insn_slot_addr(struct kprobe_insn_cache *c, unsigned long addr)
+{
+ return __find_insn_slot_entry(c, addr) != 0;
}
int kprobe_cache_get_kallsym(struct kprobe_insn_cache *c, unsigned int *symnum,
next prev parent reply other threads:[~2021-03-31 5:45 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-31 5:44 [RFC PATCH -tip 0/3] x86/kprobes,orc: Fix ORC unwinder to unwind stack with optimized probe Masami Hiramatsu
2021-03-31 5:44 ` [RFC PATCH -tip 1/3] x86/kprobes: Add ORC information to optprobe template Masami Hiramatsu
2021-03-31 5:44 ` Masami Hiramatsu [this message]
2021-03-31 5:44 ` [RFC PATCH -tip 3/3] x86/kprobes,orc: Unwind optprobe trampoline correctly Masami Hiramatsu
2021-03-31 15:57 ` Josh Poimboeuf
2021-04-01 1:44 ` Masami Hiramatsu
2021-04-01 2:19 ` Masami Hiramatsu
2021-04-01 1:54 ` Masami Hiramatsu
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=161716948533.721514.17707467357877538662.stgit@devnote2 \
--to=mhiramat@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dxu@dxuuu.xyz \
--cc=jpoimboe@redhat.com \
--cc=kernel-team@fb.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
--cc=yhs@fb.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