linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Gray <bgray@linux.ibm.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: christophe.leroy@c-s.fr, ajd@linux.ibm.com, peterz@infradead.org,
	Benjamin Gray <bgray@linux.ibm.com>,
	npiggin@gmail.com, ardb@kernel.org, jbaron@akamai.com,
	rostedt@goodmis.org, jpoimboe@kernel.org
Subject: [PATCH v2 3/6] powerpc/module: Optimise nearby branches in ELF V2 ABI stub
Date: Mon, 26 Sep 2022 16:43:13 +1000	[thread overview]
Message-ID: <20220926064316.765967-4-bgray@linux.ibm.com> (raw)
In-Reply-To: <20220926064316.765967-1-bgray@linux.ibm.com>

Inserts a direct branch to the stub target when possible, replacing the
mtctr/btctr sequence.

The load into r12 could potentially be skipped too, but that change
would need to refactor the arguments to indicate that the address
does not have a separate local entry point.

This helps the static call implementation, where modules calling their
own trampolines are called through this stub and the trampoline is
easily within range of a direct branch.

Signed-off-by: Benjamin Gray <bgray@linux.ibm.com>
---
 arch/powerpc/kernel/module_64.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c
index 4d816f7785b4..745ce9097dcf 100644
--- a/arch/powerpc/kernel/module_64.c
+++ b/arch/powerpc/kernel/module_64.c
@@ -141,6 +141,12 @@ static u32 ppc64_stub_insns[] = {
 	PPC_RAW_BCTR(),
 };
 
+#ifdef CONFIG_PPC64_ELF_ABI_V1
+#define PPC64_STUB_MTCTR_OFFSET 5
+#else
+#define PPC64_STUB_MTCTR_OFFSET 4
+#endif
+
 /* Count how many different 24-bit relocations (different symbol,
    different addend) */
 static unsigned int count_relocs(const Elf64_Rela *rela, unsigned int num)
@@ -429,6 +435,8 @@ static inline int create_stub(const Elf64_Shdr *sechdrs,
 	long reladdr;
 	func_desc_t desc;
 	int i;
+	u32 *jump_seq_addr = &entry->jump[PPC64_STUB_MTCTR_OFFSET];
+	ppc_inst_t direct;
 
 	if (is_mprofile_ftrace_call(name))
 		return create_ftrace_stub(entry, addr, me);
@@ -439,6 +447,11 @@ static inline int create_stub(const Elf64_Shdr *sechdrs,
 			return 0;
 	}
 
+	/* Replace indirect branch sequence with direct branch where possible */
+	if (!create_branch(&direct, jump_seq_addr, addr, 0))
+		if (patch_instruction(jump_seq_addr, direct))
+			return 0;
+
 	/* Stub uses address relative to r2. */
 	reladdr = (unsigned long)entry - my_r2(sechdrs, me);
 	if (reladdr > 0x7FFFFFFF || reladdr < -(0x80000000L)) {
-- 
2.37.3


  parent reply	other threads:[~2022-09-26  6:46 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-26  6:43 [PATCH v2 0/6] Out-of-line static calls for powerpc64 ELF V2 Benjamin Gray
2022-09-26  6:43 ` [PATCH v2 1/6] powerpc/code-patching: Implement generic text patching function Benjamin Gray
2022-09-26  8:56   ` kernel test robot
2022-09-26 13:28   ` kernel test robot
2022-09-26 14:33   ` Christophe Leroy
2022-09-27  2:57     ` Benjamin Gray
2022-09-27  5:54       ` Christophe Leroy
2022-09-27  6:40   ` Christophe Leroy
2022-09-28  1:30     ` Benjamin Gray
2022-09-28 10:52       ` Christophe Leroy
2022-09-27  7:30   ` Christophe Leroy
2022-09-26  6:43 ` [PATCH v2 2/6] powerpc/module: Handle caller-saved TOC in module linker Benjamin Gray
2022-09-26  6:43 ` Benjamin Gray [this message]
2022-09-26 14:49   ` [PATCH v2 3/6] powerpc/module: Optimise nearby branches in ELF V2 ABI stub Christophe Leroy
2022-09-27  3:12     ` Benjamin Gray
2022-09-26  6:43 ` [PATCH v2 4/6] static_call: Move static call selftest to static_call_selftest.c Benjamin Gray
2022-09-26 14:50   ` Christophe Leroy
2022-09-26  6:43 ` [PATCH v2 5/6] powerpc/64: Add support for out-of-line static calls Benjamin Gray
2022-09-26 13:16   ` Christophe Leroy
2022-09-27  5:18     ` Benjamin Gray
2022-09-27  6:07       ` Christophe Leroy
2022-09-26 14:54   ` Christophe Leroy
2022-09-27  3:21     ` Benjamin Gray
2022-09-27  6:01       ` Christophe Leroy
2022-09-26  6:43 ` [PATCH v2 6/6] powerpc/64: Add tests " Benjamin Gray
2022-09-26 14:55   ` Christophe Leroy
2022-09-27  3:31     ` Benjamin Gray
2022-09-27  6:05       ` Christophe Leroy
2022-09-26 14:19 ` [PATCH v2 0/6] Out-of-line static calls for powerpc64 ELF V2 Christophe Leroy

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=20220926064316.765967-4-bgray@linux.ibm.com \
    --to=bgray@linux.ibm.com \
    --cc=ajd@linux.ibm.com \
    --cc=ardb@kernel.org \
    --cc=christophe.leroy@c-s.fr \
    --cc=jbaron@akamai.com \
    --cc=jpoimboe@kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=npiggin@gmail.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).