diff mbox series

[v2] sh: prefer _THIS_IP_ to current_text_addr

Message ID 20180801185331.39535-1-ndesaulniers@google.com (mailing list archive)
State New, archived
Headers show
Series [v2] sh: prefer _THIS_IP_ to current_text_addr | expand

Commit Message

Nick Desaulniers Aug. 1, 2018, 6:53 p.m. UTC
As part of the effort to reduce the code duplication between _THIS_IP_
and current_text_addr(), let's consolidate callers of
current_text_addr() to use _THIS_IP_.

Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
 arch/sh/include/asm/kexec.h | 3 ++-
 arch/sh/kernel/dwarf.c      | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

Comments

Andrew Morton Aug. 1, 2018, 9:55 p.m. UTC | #1
On Wed,  1 Aug 2018 11:53:31 -0700 Nick Desaulniers <ndesaulniers@google.com> wrote:

> As part of the effort to reduce the code duplication between _THIS_IP_
> and current_text_addr(), let's consolidate callers of
> current_text_addr() to use _THIS_IP_.

Why not switch everything to current_text_addr()?  _THIS_IP_ is ugly ;)

Several architectures (s390, sparc, sh, ...) do funky things in their
current_text_addr().  Does the generic kernel.h implementation of
current_text_addr() work OK on those architectures?

--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Nick Desaulniers Aug. 1, 2018, 10:06 p.m. UTC | #2
On Wed, Aug 1, 2018 at 2:55 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Wed,  1 Aug 2018 11:53:31 -0700 Nick Desaulniers <ndesaulniers@google.com> wrote:
>
> > As part of the effort to reduce the code duplication between _THIS_IP_
> > and current_text_addr(), let's consolidate callers of
> > current_text_addr() to use _THIS_IP_.
>
> Why not switch everything to current_text_addr()?  _THIS_IP_ is ugly ;)
>
> Several architectures (s390, sparc, sh, ...) do funky things in their
> current_text_addr().  Does the generic kernel.h implementation of
> current_text_addr() work OK on those architectures?

Good question, one I've been mulling over for a few days.  That's
definitely something that I've considered.  Mostly, it comes down to
there being fewer call sites of current_text_addr() than _THIS_IP_, so
it's IMO a smaller change that doesn't require coordinating tree-wide
changes.

What's interesting about current_text_addr() is that while there are
many arch specific definitions, there are only 5 call sites in the
whole kernel (and 4 of them are arch specific).  So unless there's an
arch specific reason to prefer inline assembly over higher level C
(yes, returning the address of a label in a statement expression is
ugly), (it looks like parisc might have a reason, at its lone call
site, see: https://lkml.org/lkml/2018/8/1/1678, TBD), then I don't
think that current_text_addr() has a raison d'ĂȘtre.  I suspect that
its use predates the GNU C extensions needed for the current generic C
implementation (statement expressions + addr of label) and has just
been reimplemented in every new arch's arch/*/include/asm/processor.h
simply because the other archs had it.

So the plan is to replace the 5 call sites of current_text_addr() with
_THIS_IP_ (if possible), then delete all definitions of the arch
specific current_text_addr()'s.  This can be done on a per tree basis,
rather than a treewide patch for converting _THIS_IP_ (who has many
more call sites) to current_text_addr().  What do you think?
Andrew Morton Aug. 1, 2018, 10:22 p.m. UTC | #3
On Wed, 1 Aug 2018 15:06:33 -0700 Nick Desaulniers <ndesaulniers@google.com> wrote:

> So the plan is to replace the 5 call sites of current_text_addr() with
> _THIS_IP_ (if possible), then delete all definitions of the arch
> specific current_text_addr()'s.  This can be done on a per tree basis,
> rather than a treewide patch for converting _THIS_IP_ (who has many
> more call sites) to current_text_addr().  What do you think?

Sounds good to me.
--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox series

Patch

diff --git a/arch/sh/include/asm/kexec.h b/arch/sh/include/asm/kexec.h
index fd5f331a3912..927d80ba2332 100644
--- a/arch/sh/include/asm/kexec.h
+++ b/arch/sh/include/asm/kexec.h
@@ -4,6 +4,7 @@ 
 
 #include <asm/ptrace.h>
 #include <asm/string.h>
+#include <linux/kernel.h>
 
 /*
  * KEXEC_SOURCE_MEMORY_LIMIT maximum page get_free_page can return.
@@ -61,7 +62,7 @@  static inline void crash_setup_regs(struct pt_regs *newregs,
 		__asm__ __volatile__ ("stc gbr, %0" : "=r" (newregs->gbr));
 		__asm__ __volatile__ ("stc sr, %0" : "=r" (newregs->sr));
 
-		newregs->pc = (unsigned long)current_text_addr();
+		newregs->pc = _THIS_IP_;
 	}
 }
 #else
diff --git a/arch/sh/kernel/dwarf.c b/arch/sh/kernel/dwarf.c
index 1a2526676a87..bb511e2d9d68 100644
--- a/arch/sh/kernel/dwarf.c
+++ b/arch/sh/kernel/dwarf.c
@@ -599,7 +599,7 @@  struct dwarf_frame *dwarf_unwind_stack(unsigned long pc,
 	 * time this function makes its first function call.
 	 */
 	if (!pc || !prev)
-		pc = (unsigned long)current_text_addr();
+		pc = _THIS_IP_;
 
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
 	/*