linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/6] Implement inline static calls on PPC32 - v3
@ 2022-09-01 11:48 Christophe Leroy
  2022-09-01 11:48 ` [PATCH v3 1/6] Fixup for "objtool/powerpc: Add --mcount specific implementation" Christophe Leroy
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Christophe Leroy @ 2022-09-01 11:48 UTC (permalink / raw)
  To: Michael Ellerman, Nicholas Piggin, sv, bgray, agust, jpoimboe,
	peterz, jbaron, rostedt, ardb, tglx, mingo, bp, dave.hansen, hpa
  Cc: Christophe Leroy, linux-kernel, linuxppc-dev, x86, chenzhongjin

This series applies on top of the series v2 "objtool: Enable and
implement --mcount option on powerpc" [1]

A few modifications are done to core parts to enable powerpc
implementation:
- R_X86_64_PC32 is abstracted to R_REL32 so that it can then be
redefined as R_PPC_REL32.
- A call to static_call_init() is added to start_kernel() to avoid
every architecture to have to call it
- Trampoline address is provided to arch_static_call_transform() even
when setting a site to fallback on a call to the trampoline when the
target is too far.

[1] https://lore.kernel.org/all/20220829055223.24767-8-sv@linux.ibm.com/T/

This version of the series includes a preliminary patch (patch 1) that
should be squashed into Sathvika's series.

Christophe Leroy (6):
  Fixup for "objtool/powerpc: Add --mcount specific implementation"
  objtool: Add architecture specific R_REL32 macro
  init: Call static_call_init() from start_kernel()
  static_call_inline: Provide trampoline address when updating sites
  powerpc: Prepare arch_static_call_transform() for supporting inline
    static calls
  powerpc/static_call: Implement inline static calls

 arch/powerpc/Kconfig                          |  1 +
 arch/powerpc/include/asm/static_call.h        |  2 +
 arch/powerpc/kernel/static_call.c             | 58 ++++++++++++++-----
 arch/x86/kernel/static_call.c                 |  2 +-
 init/main.c                                   |  1 +
 kernel/static_call_inline.c                   |  2 +-
 tools/objtool/arch/powerpc/decode.c           | 39 +++++++++----
 tools/objtool/arch/powerpc/include/arch/elf.h |  1 +
 tools/objtool/arch/x86/include/arch/elf.h     |  1 +
 tools/objtool/check.c                         | 10 ++--
 tools/objtool/orc_gen.c                       |  2 +-
 11 files changed, 85 insertions(+), 34 deletions(-)

-- 
2.37.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 1/6] Fixup for "objtool/powerpc: Add --mcount specific implementation"
  2022-09-01 11:48 [PATCH v3 0/6] Implement inline static calls on PPC32 - v3 Christophe Leroy
@ 2022-09-01 11:48 ` Christophe Leroy
  2022-09-01 11:48 ` [PATCH v3 2/6] objtool: Add architecture specific R_REL32 macro Christophe Leroy
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Christophe Leroy @ 2022-09-01 11:48 UTC (permalink / raw)
  To: Michael Ellerman, Nicholas Piggin, sv, bgray, agust, jpoimboe,
	peterz, jbaron, rostedt, ardb, tglx, mingo, bp, dave.hansen, hpa
  Cc: Christophe Leroy, linux-kernel, linuxppc-dev, x86, chenzhongjin

Make arch_decode_instruction() more future proof and less error prone:
- Use local vars for type and imm so that GCC will detect when we
forget to update them
- Handle imm outside the branch type check
- Adapt len for prefixed instructions

Handle the four branch types b, bl, ba, bla

Part of it should probably go into "objtool/powerpc: Enable objtool
to be built on ppc" for instance the setup of the len. Maybe all the
skeleton with the local vars, the switch with its default, etc ...
Then following patches only have to add stuff inside the switch.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 tools/objtool/arch/powerpc/decode.c | 39 +++++++++++++++++++++--------
 1 file changed, 28 insertions(+), 11 deletions(-)

diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/powerpc/decode.c
index b71c265ed503..f9932351908c 100644
--- a/tools/objtool/arch/powerpc/decode.c
+++ b/tools/objtool/arch/powerpc/decode.c
@@ -50,31 +50,48 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
 {
 	u32 insn;
 	unsigned int opcode;
+	unsigned long imm;
+	enum insn_type typ;
 
-	*immediate = 0;
 	insn = bswap_if_needed(file->elf, *(u32 *)(sec->data->d_buf + offset));
-	*len = 4;
-	*type = INSN_OTHER;
 
 	opcode = insn >> 26;
 
 	switch (opcode) {
-	case 18: /* bl */
-		if ((insn & 3) == 1) {
-			*type = INSN_CALL;
-			*immediate = insn & 0x3fffffc;
-			if (*immediate & 0x2000000)
-				*immediate -= 0x4000000;
-		}
+	case 18: /* bl/b/bla/ba */
+		if (insn & 1)
+			typ = INSN_CALL;
+		else
+			typ = INSN_JUMP_UNCONDITIONAL;
+
+		imm = insn & 0x3fffffc;
+		if (imm & 0x2000000)
+			imm -= 0x4000000;
+		imm |= insn & 2;	/* AA flag */
+		break;
+	default:
+		typ = INSN_OTHER;
+		imm = 0;
 		break;
 	}
 
+	if (opcode == 1)
+		*len = 8;
+	else
+		*len = 4;
+
+	*type = typ;
+	*immediate = imm;
+
 	return 0;
 }
 
 unsigned long arch_jump_destination(struct instruction *insn)
 {
-	return insn->offset +  insn->immediate;
+	if (insn->immediate & 2)
+		return insn->immediate & ~2;
+
+	return insn->offset + insn->immediate;
 }
 
 void arch_initial_func_cfi_state(struct cfi_init_state *state)
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 2/6] objtool: Add architecture specific R_REL32 macro
  2022-09-01 11:48 [PATCH v3 0/6] Implement inline static calls on PPC32 - v3 Christophe Leroy
  2022-09-01 11:48 ` [PATCH v3 1/6] Fixup for "objtool/powerpc: Add --mcount specific implementation" Christophe Leroy
@ 2022-09-01 11:48 ` Christophe Leroy
  2022-09-01 19:38   ` Peter Zijlstra
  2022-09-01 11:48 ` [PATCH v3 3/6] init: Call static_call_init() from start_kernel() Christophe Leroy
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 8+ messages in thread
From: Christophe Leroy @ 2022-09-01 11:48 UTC (permalink / raw)
  To: Michael Ellerman, Nicholas Piggin, sv, bgray, agust, jpoimboe,
	peterz, jbaron, rostedt, ardb, tglx, mingo, bp, dave.hansen, hpa
  Cc: Christophe Leroy, linux-kernel, linuxppc-dev, x86, chenzhongjin

In order to allow other architectures than x86 to use 32 bits
PC relative relocations (S+A-P), define a R_REL32 macro that each
architecture will define, in the same way as already done for
R_NONE, R_ABS32 and R_ABS64.

For x86 that corresponds to R_X86_64_PC32.
For powerpc it is R_PPC_REL32/R_PPC64_REL32.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
v3: Added powerpc in the patch
v2: Improved commit message based on feedback from Segher
---
 tools/objtool/arch/powerpc/include/arch/elf.h |  1 +
 tools/objtool/arch/x86/include/arch/elf.h     |  1 +
 tools/objtool/check.c                         | 10 +++++-----
 tools/objtool/orc_gen.c                       |  2 +-
 4 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/tools/objtool/arch/powerpc/include/arch/elf.h b/tools/objtool/arch/powerpc/include/arch/elf.h
index 73f9ae172fe5..befc2e30d38b 100644
--- a/tools/objtool/arch/powerpc/include/arch/elf.h
+++ b/tools/objtool/arch/powerpc/include/arch/elf.h
@@ -6,5 +6,6 @@
 #define R_NONE R_PPC_NONE
 #define R_ABS64 R_PPC64_ADDR64
 #define R_ABS32 R_PPC_ADDR32
+#define R_REL32 R_PPC_REL32 /* R_PPC64_REL32 is identical */
 
 #endif /* _OBJTOOL_ARCH_ELF */
diff --git a/tools/objtool/arch/x86/include/arch/elf.h b/tools/objtool/arch/x86/include/arch/elf.h
index ac14987cf687..e7d228c686db 100644
--- a/tools/objtool/arch/x86/include/arch/elf.h
+++ b/tools/objtool/arch/x86/include/arch/elf.h
@@ -4,5 +4,6 @@
 #define R_NONE R_X86_64_NONE
 #define R_ABS64 R_X86_64_64
 #define R_ABS32 R_X86_64_32
+#define R_REL32	R_X86_64_PC32
 
 #endif /* _OBJTOOL_ARCH_ELF */
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 9ee48d0761f0..00fdaa86db70 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -655,7 +655,7 @@ static int create_static_call_sections(struct objtool_file *file)
 		/* populate reloc for 'addr' */
 		if (elf_add_reloc_to_insn(file->elf, sec,
 					  idx * sizeof(struct static_call_site),
-					  R_X86_64_PC32,
+					  R_REL32,
 					  insn->sec, insn->offset))
 			return -1;
 
@@ -696,7 +696,7 @@ static int create_static_call_sections(struct objtool_file *file)
 		/* populate reloc for 'key' */
 		if (elf_add_reloc(file->elf, sec,
 				  idx * sizeof(struct static_call_site) + 4,
-				  R_X86_64_PC32, key_sym,
+				  R_REL32, key_sym,
 				  is_sibling_call(insn) * STATIC_CALL_SITE_TAIL))
 			return -1;
 
@@ -740,7 +740,7 @@ static int create_retpoline_sites_sections(struct objtool_file *file)
 
 		if (elf_add_reloc_to_insn(file->elf, sec,
 					  idx * sizeof(int),
-					  R_X86_64_PC32,
+					  R_REL32,
 					  insn->sec, insn->offset)) {
 			WARN("elf_add_reloc_to_insn: .retpoline_sites");
 			return -1;
@@ -838,7 +838,7 @@ static int create_ibt_endbr_seal_sections(struct objtool_file *file)
 
 		if (elf_add_reloc_to_insn(file->elf, sec,
 					  idx * sizeof(int),
-					  R_X86_64_PC32,
+					  R_REL32,
 					  insn->sec, insn->offset)) {
 			WARN("elf_add_reloc_to_insn: .ibt_endbr_seal");
 			return -1;
@@ -4004,7 +4004,7 @@ static int validate_ibt_insn(struct objtool_file *file, struct instruction *insn
 			continue;
 
 		off = reloc->sym->offset;
-		if (reloc->type == R_X86_64_PC32 || reloc->type == R_X86_64_PLT32)
+		if (reloc->type == R_REL32 || reloc->type == R_X86_64_PLT32)
 			off += arch_dest_reloc_offset(reloc->addend);
 		else
 			off += reloc->addend;
diff --git a/tools/objtool/orc_gen.c b/tools/objtool/orc_gen.c
index 1f22b7ebae58..49a877b9c879 100644
--- a/tools/objtool/orc_gen.c
+++ b/tools/objtool/orc_gen.c
@@ -101,7 +101,7 @@ static int write_orc_entry(struct elf *elf, struct section *orc_sec,
 	orc->bp_offset = bswap_if_needed(elf, orc->bp_offset);
 
 	/* populate reloc for ip */
-	if (elf_add_reloc_to_insn(elf, ip_sec, idx * sizeof(int), R_X86_64_PC32,
+	if (elf_add_reloc_to_insn(elf, ip_sec, idx * sizeof(int), R_REL32,
 				  insn_sec, insn_off))
 		return -1;
 
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 3/6] init: Call static_call_init() from start_kernel()
  2022-09-01 11:48 [PATCH v3 0/6] Implement inline static calls on PPC32 - v3 Christophe Leroy
  2022-09-01 11:48 ` [PATCH v3 1/6] Fixup for "objtool/powerpc: Add --mcount specific implementation" Christophe Leroy
  2022-09-01 11:48 ` [PATCH v3 2/6] objtool: Add architecture specific R_REL32 macro Christophe Leroy
@ 2022-09-01 11:48 ` Christophe Leroy
  2022-09-01 11:48 ` [PATCH v3 4/6] static_call_inline: Provide trampoline address when updating sites Christophe Leroy
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Christophe Leroy @ 2022-09-01 11:48 UTC (permalink / raw)
  To: Michael Ellerman, Nicholas Piggin, sv, bgray, agust, jpoimboe,
	peterz, jbaron, rostedt, ardb, tglx, mingo, bp, dave.hansen, hpa
  Cc: Christophe Leroy, linux-kernel, linuxppc-dev, x86, chenzhongjin

Call static_call_init() just after jump_label_init().

x86 already called it from setup_arch(). This is not a
problem as static_call_init() is guarded from double call.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 init/main.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/init/main.c b/init/main.c
index 1fe7942f5d4a..71e7c96e1149 100644
--- a/init/main.c
+++ b/init/main.c
@@ -963,6 +963,7 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
 	pr_notice("Kernel command line: %s\n", saved_command_line);
 	/* parameters may set static keys */
 	jump_label_init();
+	static_call_init();
 	parse_early_param();
 	after_dashes = parse_args("Booting kernel",
 				  static_command_line, __start___param,
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 4/6] static_call_inline: Provide trampoline address when updating sites
  2022-09-01 11:48 [PATCH v3 0/6] Implement inline static calls on PPC32 - v3 Christophe Leroy
                   ` (2 preceding siblings ...)
  2022-09-01 11:48 ` [PATCH v3 3/6] init: Call static_call_init() from start_kernel() Christophe Leroy
@ 2022-09-01 11:48 ` Christophe Leroy
  2022-09-01 11:48 ` [PATCH v3 5/6] powerpc: Prepare arch_static_call_transform() for supporting inline static calls Christophe Leroy
  2022-09-01 11:48 ` [PATCH v3 6/6] powerpc/static_call: Implement " Christophe Leroy
  5 siblings, 0 replies; 8+ messages in thread
From: Christophe Leroy @ 2022-09-01 11:48 UTC (permalink / raw)
  To: Michael Ellerman, Nicholas Piggin, sv, bgray, agust, jpoimboe,
	peterz, jbaron, rostedt, ardb, tglx, mingo, bp, dave.hansen, hpa
  Cc: Christophe Leroy, linux-kernel, linuxppc-dev, x86, chenzhongjin

In preparation of support of inline static calls on powerpc, provide
trampoline address when updating sites, so that when the destination
function is too far for a direct function call, the call site is
patched with a call to the trampoline.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 arch/x86/kernel/static_call.c | 2 +-
 kernel/static_call_inline.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/static_call.c b/arch/x86/kernel/static_call.c
index aaaba85d6d7f..1c0072272214 100644
--- a/arch/x86/kernel/static_call.c
+++ b/arch/x86/kernel/static_call.c
@@ -113,7 +113,7 @@ void arch_static_call_transform(void *site, void *tramp, void *func, bool tail)
 {
 	mutex_lock(&text_mutex);
 
-	if (tramp) {
+	if (tramp && !site) {
 		__static_call_validate(tramp, true, true);
 		__static_call_transform(tramp, __sc_insn(!func, true), func, false);
 	}
diff --git a/kernel/static_call_inline.c b/kernel/static_call_inline.c
index dc5665b62814..b5de9d92fa4e 100644
--- a/kernel/static_call_inline.c
+++ b/kernel/static_call_inline.c
@@ -195,7 +195,7 @@ void __static_call_update(struct static_call_key *key, void *tramp, void *func)
 				continue;
 			}
 
-			arch_static_call_transform(site_addr, NULL, func,
+			arch_static_call_transform(site_addr, tramp, func,
 						   static_call_is_tail(site));
 		}
 	}
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 5/6] powerpc: Prepare arch_static_call_transform() for supporting inline static calls
  2022-09-01 11:48 [PATCH v3 0/6] Implement inline static calls on PPC32 - v3 Christophe Leroy
                   ` (3 preceding siblings ...)
  2022-09-01 11:48 ` [PATCH v3 4/6] static_call_inline: Provide trampoline address when updating sites Christophe Leroy
@ 2022-09-01 11:48 ` Christophe Leroy
  2022-09-01 11:48 ` [PATCH v3 6/6] powerpc/static_call: Implement " Christophe Leroy
  5 siblings, 0 replies; 8+ messages in thread
From: Christophe Leroy @ 2022-09-01 11:48 UTC (permalink / raw)
  To: Michael Ellerman, Nicholas Piggin, sv, bgray, agust, jpoimboe,
	peterz, jbaron, rostedt, ardb, tglx, mingo, bp, dave.hansen, hpa
  Cc: Christophe Leroy, linux-kernel, linuxppc-dev, x86, chenzhongjin

Reorganise arch_static_call_transform() in order to ease the support
of inline static calls in following patch:
- remove 'target' to nhide whether it is a 'return 0' or not.
- Don't bail out if 'tramp' is NULL, just do nothing until next patch.

Note that 'target' was 'tramp + PPC_SCT_RET0', is_short was perforce
true. So in the 'if (func && !is_short)' leg, target was perforce
equal to 'func'.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
v3: New. Split out of following patch.
---
 arch/powerpc/kernel/static_call.c | 36 ++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/kernel/static_call.c b/arch/powerpc/kernel/static_call.c
index 863a7aa24650..97765b9e1c5b 100644
--- a/arch/powerpc/kernel/static_call.c
+++ b/arch/powerpc/kernel/static_call.c
@@ -8,26 +8,32 @@ void arch_static_call_transform(void *site, void *tramp, void *func, bool tail)
 {
 	int err;
 	bool is_ret0 = (func == __static_call_return0);
-	unsigned long target = (unsigned long)(is_ret0 ? tramp + PPC_SCT_RET0 : func);
-	bool is_short = is_offset_in_branch_range((long)target - (long)tramp);
-
-	if (!tramp)
-		return;
+	unsigned long _tramp = (unsigned long)tramp;
+	unsigned long _func = (unsigned long)func;
+	unsigned long _ret0 = _tramp + PPC_SCT_RET0;
+	bool is_short = is_offset_in_branch_range((long)func - (long)(site ? : tramp));
 
 	mutex_lock(&text_mutex);
 
-	if (func && !is_short) {
-		err = patch_instruction(tramp + PPC_SCT_DATA, ppc_inst(target));
-		if (err)
-			goto out;
+	if (tramp) {
+		if (func && !is_short) {
+			err = patch_instruction(tramp + PPC_SCT_DATA, ppc_inst(_func));
+			if (err)
+				goto out;
+		}
+
+		if (!func)
+			err = patch_instruction(tramp, ppc_inst(PPC_RAW_BLR()));
+		else if (is_ret0)
+			err = patch_branch(tramp, _ret0, 0);
+		else if (is_short)
+			err = patch_branch(tramp, _func, 0);
+		else
+			err = patch_instruction(tramp, ppc_inst(PPC_RAW_NOP()));
+	} else {
+		err = 0;
 	}
 
-	if (!func)
-		err = patch_instruction(tramp, ppc_inst(PPC_RAW_BLR()));
-	else if (is_short)
-		err = patch_branch(tramp, target, 0);
-	else
-		err = patch_instruction(tramp, ppc_inst(PPC_RAW_NOP()));
 out:
 	mutex_unlock(&text_mutex);
 
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 6/6] powerpc/static_call: Implement inline static calls
  2022-09-01 11:48 [PATCH v3 0/6] Implement inline static calls on PPC32 - v3 Christophe Leroy
                   ` (4 preceding siblings ...)
  2022-09-01 11:48 ` [PATCH v3 5/6] powerpc: Prepare arch_static_call_transform() for supporting inline static calls Christophe Leroy
@ 2022-09-01 11:48 ` Christophe Leroy
  5 siblings, 0 replies; 8+ messages in thread
From: Christophe Leroy @ 2022-09-01 11:48 UTC (permalink / raw)
  To: Michael Ellerman, Nicholas Piggin, sv, bgray, agust, jpoimboe,
	peterz, jbaron, rostedt, ardb, tglx, mingo, bp, dave.hansen, hpa
  Cc: Christophe Leroy, linux-kernel, linuxppc-dev, x86, chenzhongjin

Implement inline static calls:
- Put a 'bl' to the destination function ('b' if tail call)
- Put a 'nop' when the destination function is NULL ('blr' if tail call)
- Put a 'li r3,0' when the destination is the RET0 function and not
a tail call.

If the destination is too far (over the 32Mb limit), go via the
trampoline.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 arch/powerpc/Kconfig                   |  1 +
 arch/powerpc/include/asm/static_call.h |  2 ++
 arch/powerpc/kernel/static_call.c      | 24 +++++++++++++++++++++++-
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 6be2e68fa9eb..9deb97c28304 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -251,6 +251,7 @@ config PPC
 	select HAVE_STACKPROTECTOR		if PPC32 && $(cc-option,-mstack-protector-guard=tls -mstack-protector-guard-reg=r2)
 	select HAVE_STACKPROTECTOR		if PPC64 && $(cc-option,-mstack-protector-guard=tls -mstack-protector-guard-reg=r13)
 	select HAVE_STATIC_CALL			if PPC32
+	select HAVE_STATIC_CALL_INLINE		if PPC32
 	select HAVE_SYSCALL_TRACEPOINTS
 	select HAVE_VIRT_CPU_ACCOUNTING
 	select HUGETLB_PAGE_SIZE_VARIABLE	if PPC_BOOK3S_64 && HUGETLB_PAGE
diff --git a/arch/powerpc/include/asm/static_call.h b/arch/powerpc/include/asm/static_call.h
index de1018cc522b..e3d5d3823dac 100644
--- a/arch/powerpc/include/asm/static_call.h
+++ b/arch/powerpc/include/asm/static_call.h
@@ -26,4 +26,6 @@
 #define ARCH_DEFINE_STATIC_CALL_NULL_TRAMP(name)	__PPC_SCT(name, "blr")
 #define ARCH_DEFINE_STATIC_CALL_RET0_TRAMP(name)	__PPC_SCT(name, "b .+20")
 
+#define CALL_INSN_SIZE		4
+
 #endif /* _ASM_POWERPC_STATIC_CALL_H */
diff --git a/arch/powerpc/kernel/static_call.c b/arch/powerpc/kernel/static_call.c
index 97765b9e1c5b..ba59e987f92d 100644
--- a/arch/powerpc/kernel/static_call.c
+++ b/arch/powerpc/kernel/static_call.c
@@ -15,7 +15,29 @@ void arch_static_call_transform(void *site, void *tramp, void *func, bool tail)
 
 	mutex_lock(&text_mutex);
 
-	if (tramp) {
+	if (site && tail) {
+		if (!func)
+			err = patch_instruction(site, ppc_inst(PPC_RAW_BLR()));
+		else if (is_ret0)
+			err = patch_branch(site, _ret0, 0);
+		else if (is_short)
+			err = patch_branch(site, _func, 0);
+		else if (tramp)
+			err = patch_branch(site, _tramp, 0);
+		else
+			err = 0;
+	} else if (site) {
+		if (!func)
+			err = patch_instruction(site, ppc_inst(PPC_RAW_NOP()));
+		else if (is_ret0)
+			err = patch_instruction(site, ppc_inst(PPC_RAW_LI(_R3, 0)));
+		else if (is_short)
+			err = patch_branch(site, _func, BRANCH_SET_LINK);
+		else if (tramp)
+			err = patch_branch(site, _tramp, BRANCH_SET_LINK);
+		else
+			err = 0;
+	} else if (tramp) {
 		if (func && !is_short) {
 			err = patch_instruction(tramp + PPC_SCT_DATA, ppc_inst(_func));
 			if (err)
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 2/6] objtool: Add architecture specific R_REL32 macro
  2022-09-01 11:48 ` [PATCH v3 2/6] objtool: Add architecture specific R_REL32 macro Christophe Leroy
@ 2022-09-01 19:38   ` Peter Zijlstra
  0 siblings, 0 replies; 8+ messages in thread
From: Peter Zijlstra @ 2022-09-01 19:38 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: Michael Ellerman, Nicholas Piggin, sv, bgray, agust, jpoimboe,
	jbaron, rostedt, ardb, tglx, mingo, bp, dave.hansen, hpa,
	linux-kernel, linuxppc-dev, x86, chenzhongjin

On Thu, Sep 01, 2022 at 01:48:21PM +0200, Christophe Leroy wrote:
> In order to allow other architectures than x86 to use 32 bits
> PC relative relocations (S+A-P), define a R_REL32 macro that each
> architecture will define, in the same way as already done for
> R_NONE, R_ABS32 and R_ABS64.
> 
> For x86 that corresponds to R_X86_64_PC32.
> For powerpc it is R_PPC_REL32/R_PPC64_REL32.
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-09-01 19:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-01 11:48 [PATCH v3 0/6] Implement inline static calls on PPC32 - v3 Christophe Leroy
2022-09-01 11:48 ` [PATCH v3 1/6] Fixup for "objtool/powerpc: Add --mcount specific implementation" Christophe Leroy
2022-09-01 11:48 ` [PATCH v3 2/6] objtool: Add architecture specific R_REL32 macro Christophe Leroy
2022-09-01 19:38   ` Peter Zijlstra
2022-09-01 11:48 ` [PATCH v3 3/6] init: Call static_call_init() from start_kernel() Christophe Leroy
2022-09-01 11:48 ` [PATCH v3 4/6] static_call_inline: Provide trampoline address when updating sites Christophe Leroy
2022-09-01 11:48 ` [PATCH v3 5/6] powerpc: Prepare arch_static_call_transform() for supporting inline static calls Christophe Leroy
2022-09-01 11:48 ` [PATCH v3 6/6] powerpc/static_call: Implement " Christophe Leroy

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