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 3/6] powerpc/module: Optimise nearby branches in ELF V2 ABI stub
Date: Fri, 16 Sep 2022 16:23:27 +1000	[thread overview]
Message-ID: <20220916062330.430468-4-bgray@linux.ibm.com> (raw)
In-Reply-To: <20220916062330.430468-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, 11 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c
index 3656476097c2..03ab28d86008 100644
--- a/arch/powerpc/kernel/module_64.c
+++ b/arch/powerpc/kernel/module_64.c
@@ -432,8 +432,17 @@ static inline int create_stub(const Elf64_Shdr *sechdrs,
 		return create_ftrace_stub(entry, addr, me);
 
 	for (i = 0; i < ARRAY_SIZE(ppc64_stub_insns); i++) {
-		if (patch_instruction(&entry->jump[i],
-				      ppc_inst(ppc64_stub_insns[i])))
+		ppc_inst_t inst = ppc_inst(ppc64_stub_insns[i]);
+
+		// Replace the indirect branch with a direct branch where possible
+		if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2) && i == 4) {
+			ppc_inst_t direct;
+			if (create_branch(&direct, (void*) entry + (i * 4), addr, 0) == 0) {
+				inst = direct;
+			}
+		}
+
+		if (patch_instruction(&entry->jump[i], inst))
 			return 0;
 	}
 
-- 
2.37.3


  parent reply	other threads:[~2022-09-16  6:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-16  6:23 [PATCH 0/6] Out-of-line static calls for powerpc64 ELF V2 Benjamin Gray
2022-09-16  6:23 ` [PATCH 1/6] powerpc/code-patching: Implement generic text patching function Benjamin Gray
2022-09-16  9:39   ` kernel test robot
2022-09-16 11:16   ` kernel test robot
2022-09-19  6:04   ` Christophe Leroy
2022-09-19  6:49     ` Benjamin Gray
2022-09-19  7:16       ` Christophe Leroy
2022-09-20  2:32         ` Benjamin Gray
2022-09-20  5:44           ` Christophe Leroy
2022-09-20  7:01             ` Benjamin Gray
2022-09-19  6:38   ` Christophe Leroy
2022-09-20  1:49     ` Benjamin Gray
2022-09-16  6:23 ` [PATCH 2/6] powerpc/module: Handle caller-saved TOC in module linker Benjamin Gray
2022-09-19  6:09   ` Christophe Leroy
2022-09-16  6:23 ` Benjamin Gray [this message]
2022-09-19  6:11   ` [PATCH 3/6] powerpc/module: Optimise nearby branches in ELF V2 ABI stub Christophe Leroy
2022-09-16  6:23 ` [PATCH 4/6] static_call: Move static call selftest to static_call_selftest.c Benjamin Gray
2022-09-20  4:30   ` Andrew Donnellan
2022-09-16  6:23 ` [PATCH 5/6] powerpc/64: Add support for out-of-line static calls Benjamin Gray
2022-09-16  8:32   ` kernel test robot
2022-09-16  6:23 ` [PATCH 6/6] powerpc/64: Add tests " Benjamin Gray

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=20220916062330.430468-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).