All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: Russell King <linux@armlinux.org.uk>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will.deacon@arm.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H . Peter Anvin" <hpa@zytor.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Thierry Reding <treding@nvidia.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	x86@kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
	Masami Hiramatsu <mhiramat@kernel.org>
Subject: [PATCH -tip 1/4] x86: Add in_entry_text() helper function
Date: Thu, 17 Aug 2017 16:13:55 +0900	[thread overview]
Message-ID: <150295402564.14424.15300433101224423177.stgit@devbox> (raw)
In-Reply-To: <150295395797.14424.968407208436624832.stgit@devbox>

Add in_entry_text() helper function to cleanup
entry/irqentry section checking code in kprobes and
unwind_frame.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 arch/x86/include/asm/sections.h |   15 +++++++++++++++
 arch/x86/kernel/kprobes/opt.c   |    5 +----
 arch/x86/kernel/unwind_frame.c  |   15 +--------------
 3 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/arch/x86/include/asm/sections.h b/arch/x86/include/asm/sections.h
index 2f75f30cb2f6..bb72ea0f4367 100644
--- a/arch/x86/include/asm/sections.h
+++ b/arch/x86/include/asm/sections.h
@@ -11,4 +11,19 @@ extern struct exception_table_entry __stop___ex_table[];
 extern char __end_rodata_hpage_align[];
 #endif
 
+/**
+ * in_entry_text - check if an address is in entry_text or irqentry_text
+ * @addr: virtual address to be checked
+ *
+ * Returns: true if the address specified by @addr is in the entry_text or
+ * irqentry_text, false otherwise.
+ */
+static inline bool in_entry_text(unsigned long addr)
+{
+	return memory_contains(__entry_text_start, __entry_text_end,
+			       (void *)addr, 0) ||
+		memory_contains(__irqentry_text_start, __irqentry_text_end,
+				(void *)addr, 0);
+}
+
 #endif	/* _ASM_X86_SECTIONS_H */
diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
index 4f98aad38237..74c5ad55ba6a 100644
--- a/arch/x86/kernel/kprobes/opt.c
+++ b/arch/x86/kernel/kprobes/opt.c
@@ -254,10 +254,7 @@ static int can_optimize(unsigned long paddr)
 	 * Do not optimize in the entry code due to the unstable
 	 * stack handling and registers setup.
 	 */
-	if (((paddr >= (unsigned long)__entry_text_start) &&
-	     (paddr <  (unsigned long)__entry_text_end)) ||
-	    ((paddr >= (unsigned long)__irqentry_text_start) &&
-	     (paddr <  (unsigned long)__irqentry_text_end)))
+	if (in_entry_text(paddr))
 		return 0;
 
 	/* Check there is enough space for a relative jump. */
diff --git a/arch/x86/kernel/unwind_frame.c b/arch/x86/kernel/unwind_frame.c
index d145a0b1f529..508cef8904f4 100644
--- a/arch/x86/kernel/unwind_frame.c
+++ b/arch/x86/kernel/unwind_frame.c
@@ -77,19 +77,6 @@ static size_t regs_size(struct pt_regs *regs)
 	return sizeof(*regs);
 }
 
-static bool in_entry_code(unsigned long ip)
-{
-	char *addr = (char *)ip;
-
-	if (addr >= __entry_text_start && addr < __entry_text_end)
-		return true;
-
-	if (addr >= __irqentry_text_start && addr < __irqentry_text_end)
-		return true;
-
-	return false;
-}
-
 static inline unsigned long *last_frame(struct unwind_state *state)
 {
 	return (unsigned long *)task_pt_regs(state->task) - 2;
@@ -321,7 +308,7 @@ bool unwind_next_frame(struct unwind_state *state)
 	 * Don't warn if the unwinder got lost due to an interrupt in entry
 	 * code or in the C handler before the first frame pointer got set up:
 	 */
-	if (state->got_irq && in_entry_code(state->ip))
+	if (state->got_irq && in_entry_text(state->ip))
 		goto the_end;
 	if (state->regs &&
 	    state->regs->sp >= (unsigned long)last_aligned_frame(state) &&

WARNING: multiple messages have this Message-ID (diff)
From: mhiramat@kernel.org (Masami Hiramatsu)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH -tip 1/4] x86: Add in_entry_text() helper function
Date: Thu, 17 Aug 2017 16:13:55 +0900	[thread overview]
Message-ID: <150295402564.14424.15300433101224423177.stgit@devbox> (raw)
In-Reply-To: <150295395797.14424.968407208436624832.stgit@devbox>

Add in_entry_text() helper function to cleanup
entry/irqentry section checking code in kprobes and
unwind_frame.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 arch/x86/include/asm/sections.h |   15 +++++++++++++++
 arch/x86/kernel/kprobes/opt.c   |    5 +----
 arch/x86/kernel/unwind_frame.c  |   15 +--------------
 3 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/arch/x86/include/asm/sections.h b/arch/x86/include/asm/sections.h
index 2f75f30cb2f6..bb72ea0f4367 100644
--- a/arch/x86/include/asm/sections.h
+++ b/arch/x86/include/asm/sections.h
@@ -11,4 +11,19 @@ extern struct exception_table_entry __stop___ex_table[];
 extern char __end_rodata_hpage_align[];
 #endif
 
+/**
+ * in_entry_text - check if an address is in entry_text or irqentry_text
+ * @addr: virtual address to be checked
+ *
+ * Returns: true if the address specified by @addr is in the entry_text or
+ * irqentry_text, false otherwise.
+ */
+static inline bool in_entry_text(unsigned long addr)
+{
+	return memory_contains(__entry_text_start, __entry_text_end,
+			       (void *)addr, 0) ||
+		memory_contains(__irqentry_text_start, __irqentry_text_end,
+				(void *)addr, 0);
+}
+
 #endif	/* _ASM_X86_SECTIONS_H */
diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
index 4f98aad38237..74c5ad55ba6a 100644
--- a/arch/x86/kernel/kprobes/opt.c
+++ b/arch/x86/kernel/kprobes/opt.c
@@ -254,10 +254,7 @@ static int can_optimize(unsigned long paddr)
 	 * Do not optimize in the entry code due to the unstable
 	 * stack handling and registers setup.
 	 */
-	if (((paddr >= (unsigned long)__entry_text_start) &&
-	     (paddr <  (unsigned long)__entry_text_end)) ||
-	    ((paddr >= (unsigned long)__irqentry_text_start) &&
-	     (paddr <  (unsigned long)__irqentry_text_end)))
+	if (in_entry_text(paddr))
 		return 0;
 
 	/* Check there is enough space for a relative jump. */
diff --git a/arch/x86/kernel/unwind_frame.c b/arch/x86/kernel/unwind_frame.c
index d145a0b1f529..508cef8904f4 100644
--- a/arch/x86/kernel/unwind_frame.c
+++ b/arch/x86/kernel/unwind_frame.c
@@ -77,19 +77,6 @@ static size_t regs_size(struct pt_regs *regs)
 	return sizeof(*regs);
 }
 
-static bool in_entry_code(unsigned long ip)
-{
-	char *addr = (char *)ip;
-
-	if (addr >= __entry_text_start && addr < __entry_text_end)
-		return true;
-
-	if (addr >= __irqentry_text_start && addr < __irqentry_text_end)
-		return true;
-
-	return false;
-}
-
 static inline unsigned long *last_frame(struct unwind_state *state)
 {
 	return (unsigned long *)task_pt_regs(state->task) - 2;
@@ -321,7 +308,7 @@ bool unwind_next_frame(struct unwind_state *state)
 	 * Don't warn if the unwinder got lost due to an interrupt in entry
 	 * code or in the C handler before the first frame pointer got set up:
 	 */
-	if (state->got_irq && in_entry_code(state->ip))
+	if (state->got_irq && in_entry_text(state->ip))
 		goto the_end;
 	if (state->regs &&
 	    state->regs->sp >= (unsigned long)last_aligned_frame(state) &&

  reply	other threads:[~2017-08-17  7:14 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-17  7:12 [PATCH -tip 0/4] Add section address checking helper Masami Hiramatsu
2017-08-17  7:12 ` Masami Hiramatsu
2017-08-17  7:12 ` Masami Hiramatsu
2017-08-17  7:13 ` Masami Hiramatsu [this message]
2017-08-17  7:13   ` [PATCH -tip 1/4] x86: Add in_entry_text() helper function Masami Hiramatsu
2017-08-17  7:15 ` [PATCH -tip 2/4] arm: Cleanup in_exception_text() and move it in asm/sections.h Masami Hiramatsu
2017-08-17  7:15   ` Masami Hiramatsu
2017-09-03 22:21   ` Russell King - ARM Linux
2017-09-03 22:21     ` Russell King - ARM Linux
2017-09-03 22:21     ` Russell King - ARM Linux
2017-09-04 15:22     ` Masami Hiramatsu
2017-09-04 15:22       ` Masami Hiramatsu
2017-08-17  7:16 ` [PATCH -tip 3/4] arm64: " Masami Hiramatsu
2017-08-17  7:16   ` Masami Hiramatsu
2017-08-17  7:17 ` [PATCH -tip 4/4] extable: kallsyms: Add in_init_text() and in_core_text() helper Masami Hiramatsu
2017-08-17  7:17   ` 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=150295402564.14424.15300433101224423177.stgit@devbox \
    --to=mhiramat@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=catalin.marinas@arm.com \
    --cc=hpa@zytor.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=treding@nvidia.com \
    --cc=will.deacon@arm.com \
    --cc=x86@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.