2022-10-28 14:45:55

by Sathvika Vasireddy

[permalink] [raw]
Subject: [PATCH v5 00/16] objtool: Enable and implement --mcount option on powerpc

This patchset enables and implements objtool --mcount
option on powerpc. This applies atop powerpc/merge branch.

Changelog:

----
v5:

* Patch 02/16 - Add Reviewed-by tag from Christophe Leroy

* Patch 03/16 - Fix merge conflicts with latest powerpc/merge branch

* Patch 06/16 - Files arch/powerpc/kernel/cpu_setup_fsl_booke.S and
arch/powerpc/kernel/head_fsl_booke.S are not present
today. Removed annotations in those assembly files.

* Patch 11/16 - Add Reviewed-by tag from Christophe Leroy
- Changed scripts/Makefile.lib file to make
CONFIG_HAVE_OBJTOOL_NOP_MCOUNT depend on
CONFIG_FTRACE_MCOUNT_USE_OBJTOOL.

* Patch 12/16 - Add Reviewed-by tag from Christophe Leroy

* Patch 16/16 - Add Reviewed-by tag from Christophe Leroy

* For this series - Add Acked-by tag from Josh Poimboeuf
- Add Tested-by tag from Naveen N. Rao
- Add Reviewed-by tag from Naveen N. Rao
----
v4:

* Patch 11/16 - Introduce a new config option
CONFIG_HAVE_OBJTOOL_NOP_MCOUNT as a means for
architectures to enable nop'ing ftrace locations.

- Remove Acked-by tag from Peter Zijlstra (Intel),
and Reviewed-by tag from Christophe Leroy.
[This is done because I reworked the patch to add
a new config option to objtool. Please let me know
if you want me to retain the tags. Thanks!]

* Patch 16/16 - Rework the patch to handle only 'bl' instruction
decoding.

----
v3:

* Patch 01/16 - Rework patch subject.
- Rework changelog.
- Add Reviewed-by tag from Christophe Leroy.

* Patch 02/16 - Rework changelog to update details based on feedback
from Nicholas Piggin and Michael Ellerman.
- Use quotes instead of __stringify macro, based on
suggestion from Christophe Leroy.

* Patch 03/16 - Add Reviewed-by tag from Christophe Leroy.
- Based on Christophe's suggestion, keep all <linux/...>
before <asm/...>.
- Rework changelog.

* Patch 04/16 - Add Reviewed-by tag from Christophe Leroy.

* Patch 05/16 - Add Reviewed-by tag from Christophe Leroy.

* Patch 06/16 - No change.

* Patch 07/16 - Add Reviewed-by tag from Christophe Leroy.

* Patch 08/16 - Add Acked-by tag from Peter Zijlstra.

* Patch 09/16 - Add Acked-by tag from Peter Zijlstra.

* Patch 10/16 - Reorder local variable declarations to use reverse
xmas tree format.
- Add Signed-off-by tag from Sathvika Vasireddy indicating
changes done.
- Add Acked-by tag from Peter Zijlstra.

* Patch 11/16 - Update changelog to indicate that powerpc kernel does
not support nop'ed out ftrace locations.
- Add Acked-by tag from Peter Zijlstra.
- Add Reviewed-by tag from Christophe Leroy.

* Patch 12/16 - Per Christophe's comment, rework changelog.

* Patch 13/16 - Add Acked-by tag from Peter Zijlstra.
- Add Reviewed-by tag from Christophe Leroy.

* Patch 14/16 - Simplify arch_ftrace_match() function, based on
Christophe's suggestion.
- Add Reviewed-by tag from Christophe Leroy.

* Patch 15/16 - Include code from Christophe Leroy to use local vars for
type and imm, and to adapt len for prefixed
instructions.

* Patch 16/16 - Based on suggestion from Christophe Leroy, setup
immediate value calculation outside the check for
specific instruction under case 18.
- Set instruction type to INSN_CALL for 'bla'
instruction as well.

----
v2:

* Change subject of patch 01/16
* As suggested by Christophe Leroy, add barrier_before_unreachable()
before __builtin_unreachable() to work around a gcc problem.
* Fix issues reported by Kernel Test Robot.
* Include suggestions from Christophe Leroy, and change commit
messages for patches 01/16, 02/16, 03/16, 05/16.

----

Christophe Leroy (4):
objtool: Fix SEGFAULT
objtool: Use target file endianness instead of a compiled constant
objtool: Use target file class size instead of a compiled constant
powerpc: Fix objtool unannotated intra-function call warnings on PPC32

Sathvika Vasireddy (12):
powerpc: Fix __WARN_FLAGS() for use with Objtool
powerpc: Override __ALIGN and __ALIGN_STR macros
powerpc: Fix objtool unannotated intra-function call warnings
powerpc: Curb objtool unannotated intra-function warnings
powerpc: Skip objtool from running on drivers/crypto/vmx/aesp8-ppc.o
powerpc: Skip objtool from running on VDSO files
objtool: Add --mnop as an option to --mcount
objtool: Read special sections with alts only when specific options are selected
objtool: Use macros to define arch specific reloc types
objtool: Add arch specific function arch_ftrace_match()
objtool/powerpc: Enable objtool to be built on ppc
objtool/powerpc: Add --mcount specific implementation

Makefile | 4 +-
arch/powerpc/Kconfig | 2 +
arch/powerpc/include/asm/asm.h | 7 ++
arch/powerpc/include/asm/bug.h | 3 +-
arch/powerpc/include/asm/linkage.h | 3 +
arch/powerpc/kernel/cpu_setup_6xx.S | 26 +++--
arch/powerpc/kernel/entry_32.S | 9 +-
arch/powerpc/kernel/entry_64.S | 2 +
arch/powerpc/kernel/exceptions-64s.S | 4 +-
arch/powerpc/kernel/head_40x.S | 5 +-
arch/powerpc/kernel/head_64.S | 7 +-
arch/powerpc/kernel/head_8xx.S | 5 +-
arch/powerpc/kernel/head_book3s_32.S | 29 +++--
arch/powerpc/kernel/misc_64.S | 4 +-
arch/powerpc/kernel/swsusp_32.S | 5 +-
arch/powerpc/kernel/vdso/Makefile | 2 +
arch/powerpc/kernel/vector.S | 4 +-
arch/powerpc/kvm/book3s_hv_interrupts.S | 4 +-
arch/powerpc/kvm/book3s_hv_rmhandlers.S | 25 +++--
arch/powerpc/kvm/fpu.S | 17 ++-
arch/powerpc/platforms/52xx/lite5200_sleep.S | 15 ++-
arch/x86/Kconfig | 1 +
drivers/crypto/vmx/Makefile | 2 +
kernel/trace/Kconfig | 7 ++
scripts/Makefile.lib | 3 +
tools/objtool/arch/powerpc/Build | 2 +
tools/objtool/arch/powerpc/decode.c | 101 ++++++++++++++++++
.../arch/powerpc/include/arch/cfi_regs.h | 11 ++
tools/objtool/arch/powerpc/include/arch/elf.h | 10 ++
.../arch/powerpc/include/arch/special.h | 21 ++++
tools/objtool/arch/powerpc/special.c | 19 ++++
tools/objtool/arch/x86/decode.c | 5 +
tools/objtool/arch/x86/include/arch/elf.h | 2 +
.../arch/x86/include/arch/endianness.h | 9 --
tools/objtool/builtin-check.c | 14 +++
tools/objtool/check.c | 53 ++++-----
tools/objtool/elf.c | 8 +-
tools/objtool/include/objtool/arch.h | 2 +
tools/objtool/include/objtool/builtin.h | 1 +
tools/objtool/include/objtool/elf.h | 8 ++
tools/objtool/include/objtool/endianness.h | 32 +++---
tools/objtool/orc_dump.c | 11 +-
tools/objtool/orc_gen.c | 4 +-
tools/objtool/special.c | 3 +-
44 files changed, 408 insertions(+), 103 deletions(-)
create mode 100644 arch/powerpc/include/asm/asm.h
create mode 100644 tools/objtool/arch/powerpc/Build
create mode 100644 tools/objtool/arch/powerpc/decode.c
create mode 100644 tools/objtool/arch/powerpc/include/arch/cfi_regs.h
create mode 100644 tools/objtool/arch/powerpc/include/arch/elf.h
create mode 100644 tools/objtool/arch/powerpc/include/arch/special.h
create mode 100644 tools/objtool/arch/powerpc/special.c
delete mode 100644 tools/objtool/arch/x86/include/arch/endianness.h

--
2.31.1



2022-10-28 15:04:10

by Sathvika Vasireddy

[permalink] [raw]
Subject: [PATCH v5 14/16] objtool: Add arch specific function arch_ftrace_match()

Add architecture specific function to look for relocation records
pointing to architecture specific symbols.

Suggested-by: Christophe Leroy <[email protected]>
Tested-by: Naveen N. Rao <[email protected]>
Reviewed-by: Naveen N. Rao <[email protected]>
Reviewed-by: Christophe Leroy <[email protected]>
Acked-by: Josh Poimboeuf <[email protected]>
Signed-off-by: Sathvika Vasireddy <[email protected]>
---
tools/objtool/arch/x86/decode.c | 5 +++++
tools/objtool/check.c | 2 +-
tools/objtool/include/objtool/arch.h | 2 ++
3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c
index 1c253b4b7ce0..af7ad09c926c 100644
--- a/tools/objtool/arch/x86/decode.c
+++ b/tools/objtool/arch/x86/decode.c
@@ -23,6 +23,11 @@
#include <objtool/builtin.h>
#include <arch/elf.h>

+int arch_ftrace_match(char *name)
+{
+ return !strcmp(name, "__fentry__");
+}
+
static int is_x86_64(const struct elf *elf)
{
switch (elf->ehdr.e_machine) {
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 2d7153b5d5d1..7580c66ca5c8 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2316,7 +2316,7 @@ static int classify_symbols(struct objtool_file *file)
if (arch_is_rethunk(func))
func->return_thunk = true;

- if (!strcmp(func->name, "__fentry__"))
+ if (arch_ftrace_match(func->name))
func->fentry = true;

if (is_profiling_func(func->name))
diff --git a/tools/objtool/include/objtool/arch.h b/tools/objtool/include/objtool/arch.h
index beb2f3aa94ff..5149330f400f 100644
--- a/tools/objtool/include/objtool/arch.h
+++ b/tools/objtool/include/objtool/arch.h
@@ -69,6 +69,8 @@ struct stack_op {

struct instruction;

+int arch_ftrace_match(char *name);
+
void arch_initial_func_cfi_state(struct cfi_init_state *state);

int arch_decode_instruction(struct objtool_file *file, const struct section *sec,
--
2.31.1


2022-10-28 15:04:41

by Sathvika Vasireddy

[permalink] [raw]
Subject: [PATCH v5 15/16] objtool/powerpc: Enable objtool to be built on ppc

This patch adds [stub] implementations for required functions, inorder
to enable objtool build on powerpc.

Tested-by: Naveen N. Rao <[email protected]>
Reviewed-by: Naveen N. Rao <[email protected]>
Acked-by: Josh Poimboeuf <[email protected]>
Signed-off-by: Sathvika Vasireddy <[email protected]>
[Christophe Leroy: powerpc: Add missing asm/asm.h for objtool,
Use local variables for type and imm in arch_decode_instruction(),
Adapt len for prefixed instructions.]
Signed-off-by: Christophe Leroy <[email protected]>
---
arch/powerpc/Kconfig | 1 +
arch/powerpc/include/asm/asm.h | 7 ++
tools/objtool/arch/powerpc/Build | 2 +
tools/objtool/arch/powerpc/decode.c | 85 +++++++++++++++++++
.../arch/powerpc/include/arch/cfi_regs.h | 11 +++
tools/objtool/arch/powerpc/include/arch/elf.h | 8 ++
.../arch/powerpc/include/arch/special.h | 21 +++++
tools/objtool/arch/powerpc/special.c | 19 +++++
8 files changed, 154 insertions(+)
create mode 100644 arch/powerpc/include/asm/asm.h
create mode 100644 tools/objtool/arch/powerpc/Build
create mode 100644 tools/objtool/arch/powerpc/decode.c
create mode 100644 tools/objtool/arch/powerpc/include/arch/cfi_regs.h
create mode 100644 tools/objtool/arch/powerpc/include/arch/elf.h
create mode 100644 tools/objtool/arch/powerpc/include/arch/special.h
create mode 100644 tools/objtool/arch/powerpc/special.c

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 699df27b0e2f..12e6c16be54e 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -238,6 +238,7 @@ config PPC
select HAVE_MOD_ARCH_SPECIFIC
select HAVE_NMI if PERF_EVENTS || (PPC64 && PPC_BOOK3S)
select HAVE_OPTPROBES
+ select HAVE_OBJTOOL if PPC32 || MPROFILE_KERNEL
select HAVE_PERF_EVENTS
select HAVE_PERF_EVENTS_NMI if PPC64
select HAVE_PERF_REGS
diff --git a/arch/powerpc/include/asm/asm.h b/arch/powerpc/include/asm/asm.h
new file mode 100644
index 000000000000..86f46b604e9a
--- /dev/null
+++ b/arch/powerpc/include/asm/asm.h
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_POWERPC_ASM_H
+#define _ASM_POWERPC_ASM_H
+
+#define _ASM_PTR " .long "
+
+#endif /* _ASM_POWERPC_ASM_H */
diff --git a/tools/objtool/arch/powerpc/Build b/tools/objtool/arch/powerpc/Build
new file mode 100644
index 000000000000..d24d5636a5b8
--- /dev/null
+++ b/tools/objtool/arch/powerpc/Build
@@ -0,0 +1,2 @@
+objtool-y += decode.o
+objtool-y += special.o
diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/powerpc/decode.c
new file mode 100644
index 000000000000..dcd0975cad6b
--- /dev/null
+++ b/tools/objtool/arch/powerpc/decode.c
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <objtool/check.h>
+#include <objtool/elf.h>
+#include <objtool/arch.h>
+#include <objtool/warn.h>
+#include <objtool/builtin.h>
+#include <objtool/endianness.h>
+
+unsigned long arch_dest_reloc_offset(int addend)
+{
+ return addend;
+}
+
+bool arch_callee_saved_reg(unsigned char reg)
+{
+ return false;
+}
+
+int arch_decode_hint_reg(u8 sp_reg, int *base)
+{
+ exit(-1);
+}
+
+const char *arch_nop_insn(int len)
+{
+ exit(-1);
+}
+
+const char *arch_ret_insn(int len)
+{
+ exit(-1);
+}
+
+int arch_decode_instruction(struct objtool_file *file, const struct section *sec,
+ unsigned long offset, unsigned int maxlen,
+ unsigned int *len, enum insn_type *type,
+ unsigned long *immediate,
+ struct list_head *ops_list)
+{
+ unsigned int opcode;
+ enum insn_type typ;
+ unsigned long imm;
+ u32 insn;
+
+ insn = bswap_if_needed(file->elf, *(u32 *)(sec->data->d_buf + offset));
+ opcode = insn >> 26;
+ typ = INSN_OTHER;
+ imm = 0;
+
+ 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;
+}
+
+void arch_initial_func_cfi_state(struct cfi_init_state *state)
+{
+ int i;
+
+ for (i = 0; i < CFI_NUM_REGS; i++) {
+ state->regs[i].base = CFI_UNDEFINED;
+ state->regs[i].offset = 0;
+ }
+
+ /* initial CFA (call frame address) */
+ state->cfa.base = CFI_SP;
+ state->cfa.offset = 0;
+
+ /* initial LR (return address) */
+ state->regs[CFI_RA].base = CFI_CFA;
+ state->regs[CFI_RA].offset = 0;
+}
diff --git a/tools/objtool/arch/powerpc/include/arch/cfi_regs.h b/tools/objtool/arch/powerpc/include/arch/cfi_regs.h
new file mode 100644
index 000000000000..59638ebeafc8
--- /dev/null
+++ b/tools/objtool/arch/powerpc/include/arch/cfi_regs.h
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef _OBJTOOL_CFI_REGS_H
+#define _OBJTOOL_CFI_REGS_H
+
+#define CFI_BP 1
+#define CFI_SP CFI_BP
+#define CFI_RA 32
+#define CFI_NUM_REGS 33
+
+#endif
diff --git a/tools/objtool/arch/powerpc/include/arch/elf.h b/tools/objtool/arch/powerpc/include/arch/elf.h
new file mode 100644
index 000000000000..3c8ebb7d2a6b
--- /dev/null
+++ b/tools/objtool/arch/powerpc/include/arch/elf.h
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef _OBJTOOL_ARCH_ELF
+#define _OBJTOOL_ARCH_ELF
+
+#define R_NONE R_PPC_NONE
+
+#endif /* _OBJTOOL_ARCH_ELF */
diff --git a/tools/objtool/arch/powerpc/include/arch/special.h b/tools/objtool/arch/powerpc/include/arch/special.h
new file mode 100644
index 000000000000..ffef9ada7133
--- /dev/null
+++ b/tools/objtool/arch/powerpc/include/arch/special.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef _PPC_ARCH_SPECIAL_H
+#define _PPC_ARCH_SPECIAL_H
+
+#define EX_ENTRY_SIZE 8
+#define EX_ORIG_OFFSET 0
+#define EX_NEW_OFFSET 4
+
+#define JUMP_ENTRY_SIZE 16
+#define JUMP_ORIG_OFFSET 0
+#define JUMP_NEW_OFFSET 4
+#define JUMP_KEY_OFFSET 8
+
+#define ALT_ENTRY_SIZE 12
+#define ALT_ORIG_OFFSET 0
+#define ALT_NEW_OFFSET 4
+#define ALT_FEATURE_OFFSET 8
+#define ALT_ORIG_LEN_OFFSET 10
+#define ALT_NEW_LEN_OFFSET 11
+
+#endif /* _PPC_ARCH_SPECIAL_H */
diff --git a/tools/objtool/arch/powerpc/special.c b/tools/objtool/arch/powerpc/special.c
new file mode 100644
index 000000000000..d33868147196
--- /dev/null
+++ b/tools/objtool/arch/powerpc/special.c
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include <string.h>
+#include <stdlib.h>
+#include <objtool/special.h>
+#include <objtool/builtin.h>
+
+
+bool arch_support_alt_relocation(struct special_alt *special_alt,
+ struct instruction *insn,
+ struct reloc *reloc)
+{
+ exit(-1);
+}
+
+struct reloc *arch_find_switch_table(struct objtool_file *file,
+ struct instruction *insn)
+{
+ exit(-1);
+}
--
2.31.1


2022-10-28 15:05:03

by Sathvika Vasireddy

[permalink] [raw]
Subject: [PATCH v5 02/16] powerpc: Override __ALIGN and __ALIGN_STR macros

In a subsequent patch, we would want to annotate powerpc assembly functions
with SYM_FUNC_START_LOCAL macro. This macro depends on __ALIGN macro.

The default expansion of __ALIGN macro is:
#define __ALIGN .align 4,0x90

So, override __ALIGN and __ALIGN_STR macros to use the same alignment as
that of the existing _GLOBAL macro. Also, do not pad with 0x90, because
repeated 0x90s are not a nop or trap on powerpc.

Tested-by: Naveen N. Rao <[email protected]>
Reviewed-by: Naveen N. Rao <[email protected]>
Reviewed-by: Christophe Leroy <[email protected]>
Acked-by: Josh Poimboeuf <[email protected]>
Signed-off-by: Sathvika Vasireddy <[email protected]>
---
arch/powerpc/include/asm/linkage.h | 3 +++
1 file changed, 3 insertions(+)

diff --git a/arch/powerpc/include/asm/linkage.h b/arch/powerpc/include/asm/linkage.h
index b71b9582e754..b88d1d2cf304 100644
--- a/arch/powerpc/include/asm/linkage.h
+++ b/arch/powerpc/include/asm/linkage.h
@@ -4,6 +4,9 @@

#include <asm/types.h>

+#define __ALIGN .align 2
+#define __ALIGN_STR ".align 2"
+
#ifdef CONFIG_PPC64_ELF_ABI_V1
#define cond_syscall(x) \
asm ("\t.weak " #x "\n\t.set " #x ", sys_ni_syscall\n" \
--
2.31.1


2022-10-28 15:05:12

by Sathvika Vasireddy

[permalink] [raw]
Subject: [PATCH v5 06/16] powerpc: Fix objtool unannotated intra-function call warnings on PPC32

From: Christophe Leroy <[email protected]>

Fix several annotations in assembly files on PPC32.

Tested-by: Naveen N. Rao <[email protected]>
Reviewed-by: Naveen N. Rao <[email protected]>
Acked-by: Josh Poimboeuf <[email protected]>
Signed-off-by: Christophe Leroy <[email protected]>
[Sathvika Vasireddy: Changed subject line from "objtool/powerpc: Activate
objtool on PPC32" to "powerpc: Fix objtool unannotated intra-function call
warnings on PPC32", and removed Kconfig change to enable objtool, as it
is a part of "objtool/powerpc: Enable objtool to be built on ppc" patch in
this series.]
Signed-off-by: Sathvika Vasireddy <[email protected]>
---
arch/powerpc/kernel/cpu_setup_6xx.S | 26 ++++++++++++------
arch/powerpc/kernel/entry_32.S | 9 ++++--
arch/powerpc/kernel/head_40x.S | 5 +++-
arch/powerpc/kernel/head_8xx.S | 5 +++-
arch/powerpc/kernel/head_book3s_32.S | 29 ++++++++++++++------
arch/powerpc/kernel/swsusp_32.S | 5 +++-
arch/powerpc/kvm/fpu.S | 17 ++++++++----
arch/powerpc/platforms/52xx/lite5200_sleep.S | 15 +++++++---
8 files changed, 79 insertions(+), 32 deletions(-)

diff --git a/arch/powerpc/kernel/cpu_setup_6xx.S b/arch/powerpc/kernel/cpu_setup_6xx.S
index f8b5ff64b604..f29ce3dd6140 100644
--- a/arch/powerpc/kernel/cpu_setup_6xx.S
+++ b/arch/powerpc/kernel/cpu_setup_6xx.S
@@ -4,6 +4,8 @@
* Copyright (C) 2003 Benjamin Herrenschmidt ([email protected])
*/

+#include <linux/linkage.h>
+
#include <asm/processor.h>
#include <asm/page.h>
#include <asm/cputable.h>
@@ -81,7 +83,7 @@ _GLOBAL(__setup_cpu_745x)
blr

/* Enable caches for 603's, 604, 750 & 7400 */
-setup_common_caches:
+SYM_FUNC_START_LOCAL(setup_common_caches)
mfspr r11,SPRN_HID0
andi. r0,r11,HID0_DCE
ori r11,r11,HID0_ICE|HID0_DCE
@@ -95,11 +97,12 @@ setup_common_caches:
sync
isync
blr
+SYM_FUNC_END(setup_common_caches)

/* 604, 604e, 604ev, ...
* Enable superscalar execution & branch history table
*/
-setup_604_hid0:
+SYM_FUNC_START_LOCAL(setup_604_hid0)
mfspr r11,SPRN_HID0
ori r11,r11,HID0_SIED|HID0_BHTE
ori r8,r11,HID0_BTCD
@@ -110,6 +113,7 @@ setup_604_hid0:
sync
isync
blr
+SYM_FUNC_END(setup_604_hid0)

/* 7400 <= rev 2.7 and 7410 rev = 1.0 suffer from some
* erratas we work around here.
@@ -125,13 +129,14 @@ setup_604_hid0:
* needed once we have applied workaround #5 (though it's
* not set by Apple's firmware at least).
*/
-setup_7400_workarounds:
+SYM_FUNC_START_LOCAL(setup_7400_workarounds)
mfpvr r3
rlwinm r3,r3,0,20,31
cmpwi 0,r3,0x0207
ble 1f
blr
-setup_7410_workarounds:
+SYM_FUNC_END(setup_7400_workarounds)
+SYM_FUNC_START_LOCAL(setup_7410_workarounds)
mfpvr r3
rlwinm r3,r3,0,20,31
cmpwi 0,r3,0x0100
@@ -151,6 +156,7 @@ setup_7410_workarounds:
sync
isync
blr
+SYM_FUNC_END(setup_7410_workarounds)

/* 740/750/7400/7410
* Enable Store Gathering (SGE), Address Broadcast (ABE),
@@ -158,7 +164,7 @@ setup_7410_workarounds:
* Dynamic Power Management (DPM), Speculative (SPD)
* Clear Instruction cache throttling (ICTC)
*/
-setup_750_7400_hid0:
+SYM_FUNC_START_LOCAL(setup_750_7400_hid0)
mfspr r11,SPRN_HID0
ori r11,r11,HID0_SGE | HID0_ABE | HID0_BHTE | HID0_BTIC
oris r11,r11,HID0_DPM@h
@@ -177,12 +183,13 @@ END_FTR_SECTION_IFSET(CPU_FTR_NO_DPM)
sync
isync
blr
+SYM_FUNC_END(setup_750_7400_hid0)

/* 750cx specific
* Looks like we have to disable NAP feature for some PLL settings...
* (waiting for confirmation)
*/
-setup_750cx:
+SYM_FUNC_START_LOCAL(setup_750cx)
mfspr r10, SPRN_HID1
rlwinm r10,r10,4,28,31
cmpwi cr0,r10,7
@@ -196,11 +203,13 @@ setup_750cx:
andc r6,r6,r7
stw r6,CPU_SPEC_FEATURES(r4)
blr
+SYM_FUNC_END(setup_750cx)

/* 750fx specific
*/
-setup_750fx:
+SYM_FUNC_START_LOCAL(setup_750fx)
blr
+SYM_FUNC_END(setup_750fx)

/* MPC 745x
* Enable Store Gathering (SGE), Branch Folding (FOLD)
@@ -212,7 +221,7 @@ setup_750fx:
* Clear Instruction cache throttling (ICTC)
* Enable L2 HW prefetch
*/
-setup_745x_specifics:
+SYM_FUNC_START_LOCAL(setup_745x_specifics)
/* We check for the presence of an L3 cache setup by
* the firmware. If any, we disable NAP capability as
* it's known to be bogus on rev 2.1 and earlier
@@ -270,6 +279,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_NO_DPM)
sync
isync
blr
+SYM_FUNC_END(setup_745x_specifics)

/*
* Initialize the FPU registers. This is needed to work around an errata
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 3fc7c9886bb7..5e0763be1549 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -18,6 +18,8 @@
#include <linux/err.h>
#include <linux/sys.h>
#include <linux/threads.h>
+#include <linux/linkage.h>
+
#include <asm/reg.h>
#include <asm/page.h>
#include <asm/mmu.h>
@@ -74,17 +76,18 @@ _ASM_NOKPROBE_SYMBOL(prepare_transfer_to_handler)
#endif /* CONFIG_PPC_BOOK3S_32 || CONFIG_PPC_E500 */

#if defined(CONFIG_PPC_KUEP) && defined(CONFIG_PPC_BOOK3S_32)
- .globl __kuep_lock
-__kuep_lock:
+SYM_FUNC_START(__kuep_lock)
lwz r9, THREAD+THSR0(r2)
update_user_segments_by_4 r9, r10, r11, r12
blr
+SYM_FUNC_END(__kuep_lock)

-__kuep_unlock:
+SYM_FUNC_START_LOCAL(__kuep_unlock)
lwz r9, THREAD+THSR0(r2)
rlwinm r9,r9,0,~SR_NX
update_user_segments_by_4 r9, r10, r11, r12
blr
+SYM_FUNC_END(__kuep_unlock)

.macro kuep_lock
bl __kuep_lock
diff --git a/arch/powerpc/kernel/head_40x.S b/arch/powerpc/kernel/head_40x.S
index 088f500896c7..9110fe9d6747 100644
--- a/arch/powerpc/kernel/head_40x.S
+++ b/arch/powerpc/kernel/head_40x.S
@@ -28,6 +28,8 @@
#include <linux/init.h>
#include <linux/pgtable.h>
#include <linux/sizes.h>
+#include <linux/linkage.h>
+
#include <asm/processor.h>
#include <asm/page.h>
#include <asm/mmu.h>
@@ -662,7 +664,7 @@ start_here:
* kernel initialization. This maps the first 32 MBytes of memory 1:1
* virtual to physical and more importantly sets the cache mode.
*/
-initial_mmu:
+SYM_FUNC_START_LOCAL(initial_mmu)
tlbia /* Invalidate all TLB entries */
isync

@@ -711,6 +713,7 @@ initial_mmu:
mtspr SPRN_EVPR,r0

blr
+SYM_FUNC_END(initial_mmu)

_GLOBAL(abort)
mfspr r13,SPRN_DBCR0
diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S
index 0b05f2be66b9..c94ed5a08c93 100644
--- a/arch/powerpc/kernel/head_8xx.S
+++ b/arch/powerpc/kernel/head_8xx.S
@@ -18,6 +18,8 @@
#include <linux/magic.h>
#include <linux/pgtable.h>
#include <linux/sizes.h>
+#include <linux/linkage.h>
+
#include <asm/processor.h>
#include <asm/page.h>
#include <asm/mmu.h>
@@ -625,7 +627,7 @@ start_here:
* 24 Mbytes of data, and the 512k IMMR space. Anything not covered by
* these mappings is mapped by page tables.
*/
-initial_mmu:
+SYM_FUNC_START_LOCAL(initial_mmu)
li r8, 0
mtspr SPRN_MI_CTR, r8 /* remove PINNED ITLB entries */
lis r10, MD_TWAM@h
@@ -686,6 +688,7 @@ initial_mmu:
#endif
mtspr SPRN_DER, r8
blr
+SYM_FUNC_END(initial_mmu)

_GLOBAL(mmu_pin_tlb)
lis r9, (1f - PAGE_OFFSET)@h
diff --git a/arch/powerpc/kernel/head_book3s_32.S b/arch/powerpc/kernel/head_book3s_32.S
index 519b60695167..4af12447dc0b 100644
--- a/arch/powerpc/kernel/head_book3s_32.S
+++ b/arch/powerpc/kernel/head_book3s_32.S
@@ -18,6 +18,8 @@

#include <linux/init.h>
#include <linux/pgtable.h>
+#include <linux/linkage.h>
+
#include <asm/reg.h>
#include <asm/page.h>
#include <asm/mmu.h>
@@ -877,7 +879,7 @@ END_MMU_FTR_SECTION_IFCLR(MMU_FTR_HPTE_TABLE)
* Load stuff into the MMU. Intended to be called with
* IR=0 and DR=0.
*/
-early_hash_table:
+SYM_FUNC_START_LOCAL(early_hash_table)
sync /* Force all PTE updates to finish */
isync
tlbia /* Clear all TLB entries */
@@ -888,8 +890,9 @@ early_hash_table:
ori r6, r6, 3 /* 256kB table */
mtspr SPRN_SDR1, r6
blr
+SYM_FUNC_END(early_hash_table)

-load_up_mmu:
+SYM_FUNC_START_LOCAL(load_up_mmu)
sync /* Force all PTE updates to finish */
isync
tlbia /* Clear all TLB entries */
@@ -918,6 +921,7 @@ BEGIN_MMU_FTR_SECTION
LOAD_BAT(7,r3,r4,r5)
END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
blr
+SYM_FUNC_END(load_up_mmu)

_GLOBAL(load_segment_registers)
li r0, NUM_USER_SEGMENTS /* load up user segment register values */
@@ -1028,7 +1032,7 @@ END_MMU_FTR_SECTION_IFCLR(MMU_FTR_HPTE_TABLE)
* this makes sure it's done.
* -- Cort
*/
-clear_bats:
+SYM_FUNC_START_LOCAL(clear_bats)
li r10,0

mtspr SPRN_DBAT0U,r10
@@ -1072,6 +1076,7 @@ BEGIN_MMU_FTR_SECTION
mtspr SPRN_IBAT7L,r10
END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
blr
+SYM_FUNC_END(clear_bats)

_GLOBAL(update_bats)
lis r4, 1f@h
@@ -1108,15 +1113,16 @@ END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
mtspr SPRN_SRR1, r6
rfi

-flush_tlbs:
+SYM_FUNC_START_LOCAL(flush_tlbs)
lis r10, 0x40
1: addic. r10, r10, -0x1000
tlbie r10
bgt 1b
sync
blr
+SYM_FUNC_END(flush_tlbs)

-mmu_off:
+SYM_FUNC_START_LOCAL(mmu_off)
addi r4, r3, __after_mmu_off - _start
mfmsr r3
andi. r0,r3,MSR_DR|MSR_IR /* MMU enabled? */
@@ -1128,9 +1134,10 @@ mmu_off:
mtspr SPRN_SRR1,r3
sync
rfi
+SYM_FUNC_END(mmu_off)

/* We use one BAT to map up to 256M of RAM at _PAGE_OFFSET */
-initial_bats:
+SYM_FUNC_START_LOCAL(initial_bats)
lis r11,PAGE_OFFSET@h
tophys(r8,r11)
#ifdef CONFIG_SMP
@@ -1146,9 +1153,10 @@ initial_bats:
mtspr SPRN_IBAT0U,r11
isync
blr
+SYM_FUNC_END(initial_bats)

#ifdef CONFIG_BOOTX_TEXT
-setup_disp_bat:
+SYM_FUNC_START_LOCAL(setup_disp_bat)
/*
* setup the display bat prepared for us in prom.c
*/
@@ -1164,10 +1172,11 @@ setup_disp_bat:
mtspr SPRN_DBAT3L,r8
mtspr SPRN_DBAT3U,r11
blr
+SYM_FUNC_END(setup_disp_bat)
#endif /* CONFIG_BOOTX_TEXT */

#ifdef CONFIG_PPC_EARLY_DEBUG_CPM
-setup_cpm_bat:
+SYM_FUNC_START_LOCAL(setup_cpm_bat)
lis r8, 0xf000
ori r8, r8, 0x002a
mtspr SPRN_DBAT1L, r8
@@ -1177,10 +1186,11 @@ setup_cpm_bat:
mtspr SPRN_DBAT1U, r11

blr
+SYM_FUNC_END(setup_cpm_bat)
#endif

#ifdef CONFIG_PPC_EARLY_DEBUG_USBGECKO
-setup_usbgecko_bat:
+SYM_FUNC_START_LOCAL(setup_usbgecko_bat)
/* prepare a BAT for early io */
#if defined(CONFIG_GAMECUBE)
lis r8, 0x0c00
@@ -1199,6 +1209,7 @@ setup_usbgecko_bat:
mtspr SPRN_DBAT1L, r8
mtspr SPRN_DBAT1U, r11
blr
+SYM_FUNC_END(setup_usbgecko_bat)
#endif

.data
diff --git a/arch/powerpc/kernel/swsusp_32.S b/arch/powerpc/kernel/swsusp_32.S
index e0cbd63007f2..ffb79326483c 100644
--- a/arch/powerpc/kernel/swsusp_32.S
+++ b/arch/powerpc/kernel/swsusp_32.S
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0 */
#include <linux/threads.h>
+#include <linux/linkage.h>
+
#include <asm/processor.h>
#include <asm/page.h>
#include <asm/cputable.h>
@@ -400,7 +402,7 @@ _ASM_NOKPROBE_SYMBOL(swsusp_arch_resume)
/* FIXME:This construct is actually not useful since we don't shut
* down the instruction MMU, we could just flip back MSR-DR on.
*/
-turn_on_mmu:
+SYM_FUNC_START_LOCAL(turn_on_mmu)
mflr r4
mtsrr0 r4
mtsrr1 r3
@@ -408,4 +410,5 @@ turn_on_mmu:
isync
rfi
_ASM_NOKPROBE_SYMBOL(turn_on_mmu)
+SYM_FUNC_END(turn_on_mmu)

diff --git a/arch/powerpc/kvm/fpu.S b/arch/powerpc/kvm/fpu.S
index 315c94946bad..b68e7f26a81f 100644
--- a/arch/powerpc/kvm/fpu.S
+++ b/arch/powerpc/kvm/fpu.S
@@ -6,6 +6,8 @@
*/

#include <linux/pgtable.h>
+#include <linux/linkage.h>
+
#include <asm/reg.h>
#include <asm/page.h>
#include <asm/mmu.h>
@@ -110,18 +112,22 @@ FPS_THREE_IN(fsel)
* R8 = (double*)&param3 [load_three]
* LR = instruction call function
*/
-fpd_load_three:
+SYM_FUNC_START_LOCAL(fpd_load_three)
lfd 2,0(r8) /* load param3 */
-fpd_load_two:
+SYM_FUNC_START_LOCAL(fpd_load_two)
lfd 1,0(r7) /* load param2 */
-fpd_load_one:
+SYM_FUNC_START_LOCAL(fpd_load_one)
lfd 0,0(r6) /* load param1 */
-fpd_load_none:
+SYM_FUNC_START_LOCAL(fpd_load_none)
lfd 3,0(r3) /* load up fpscr value */
MTFSF_L(3)
lwz r6, 0(r4) /* load cr */
mtcr r6
blr
+SYM_FUNC_END(fpd_load_none)
+SYM_FUNC_END(fpd_load_one)
+SYM_FUNC_END(fpd_load_two)
+SYM_FUNC_END(fpd_load_three)

/*
* End of double instruction processing
@@ -131,13 +137,14 @@ fpd_load_none:
* R5 = (double*)&result
* LR = caller of instruction call function
*/
-fpd_return:
+SYM_FUNC_START_LOCAL(fpd_return)
mfcr r6
stfd 0,0(r5) /* save result */
mffs 0
stfd 0,0(r3) /* save new fpscr value */
stw r6,0(r4) /* save new cr value */
blr
+SYM_FUNC_END(fpd_return)

/*
* Double operation with no input operand
diff --git a/arch/powerpc/platforms/52xx/lite5200_sleep.S b/arch/powerpc/platforms/52xx/lite5200_sleep.S
index afee8b1515a8..0b12647e7b42 100644
--- a/arch/powerpc/platforms/52xx/lite5200_sleep.S
+++ b/arch/powerpc/platforms/52xx/lite5200_sleep.S
@@ -1,4 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0 */
+#include <linux/linkage.h>
+
#include <asm/reg.h>
#include <asm/ppc_asm.h>
#include <asm/processor.h>
@@ -178,7 +180,8 @@ sram_code:


/* local udelay in sram is needed */
- udelay: /* r11 - tb_ticks_per_usec, r12 - usecs, overwrites r13 */
+SYM_FUNC_START_LOCAL(udelay)
+ /* r11 - tb_ticks_per_usec, r12 - usecs, overwrites r13 */
mullw r12, r12, r11
mftb r13 /* start */
add r12, r13, r12 /* end */
@@ -187,6 +190,7 @@ sram_code:
cmp cr0, r13, r12
blt 1b
blr
+SYM_FUNC_END(udelay)

sram_code_end:

@@ -271,7 +275,7 @@ _ASM_NOKPROBE_SYMBOL(lite5200_wakeup)
SAVE_SR(n+2, addr+2); \
SAVE_SR(n+3, addr+3);

-save_regs:
+SYM_FUNC_START_LOCAL(save_regs)
stw r0, 0(r4)
stw r1, 0x4(r4)
stw r2, 0x8(r4)
@@ -317,6 +321,7 @@ save_regs:
SAVE_SPRN(TBRU, 0x5b)

blr
+SYM_FUNC_END(save_regs)


/* restore registers */
@@ -336,7 +341,7 @@ save_regs:
LOAD_SR(n+2, addr+2); \
LOAD_SR(n+3, addr+3);

-restore_regs:
+SYM_FUNC_START_LOCAL(restore_regs)
lis r4, registers@h
ori r4, r4, registers@l

@@ -393,6 +398,7 @@ restore_regs:

blr
_ASM_NOKPROBE_SYMBOL(restore_regs)
+SYM_FUNC_END(restore_regs)



@@ -403,7 +409,7 @@ _ASM_NOKPROBE_SYMBOL(restore_regs)
* Flush data cache
* Do this by just reading lots of stuff into the cache.
*/
-flush_data_cache:
+SYM_FUNC_START_LOCAL(flush_data_cache)
lis r3,CONFIG_KERNEL_START@h
ori r3,r3,CONFIG_KERNEL_START@l
li r4,NUM_CACHE_LINES
@@ -413,3 +419,4 @@ flush_data_cache:
addi r3,r3,L1_CACHE_BYTES /* Next line, please */
bdnz 1b
blr
+SYM_FUNC_END(flush_data_cache)
--
2.31.1


2022-10-28 15:06:08

by Sathvika Vasireddy

[permalink] [raw]
Subject: [PATCH v5 08/16] objtool: Fix SEGFAULT

From: Christophe Leroy <[email protected]>

find_insn() will return NULL in case of failure. Check insn in order
to avoid a kernel Oops for NULL pointer dereference.

Tested-by: Naveen N. Rao <[email protected]>
Reviewed-by: Naveen N. Rao <[email protected]>
Acked-by: Josh Poimboeuf <[email protected]>
Acked-by: Peter Zijlstra (Intel) <[email protected]>
Signed-off-by: Christophe Leroy <[email protected]>
---
tools/objtool/check.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 43ec14c29a60..8427af808221 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -207,7 +207,7 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
return false;

insn = find_insn(file, func->sec, func->offset);
- if (!insn->func)
+ if (!insn || !insn->func)
return false;

func_for_each_insn(file, func, insn) {
--
2.31.1


2022-10-28 15:06:08

by Sathvika Vasireddy

[permalink] [raw]
Subject: [PATCH v5 09/16] objtool: Use target file endianness instead of a compiled constant

From: Christophe Leroy <[email protected]>

Some architectures like powerpc support both endianness, it's
therefore not possible to fix the endianness via arch/endianness.h
because there is no easy way to get the target endianness at
build time.

Use the endianness recorded in the file objtool is working on.

Tested-by: Naveen N. Rao <[email protected]>
Reviewed-by: Naveen N. Rao <[email protected]>
Acked-by: Josh Poimboeuf <[email protected]>
Acked-by: Peter Zijlstra (Intel) <[email protected]>
Signed-off-by: Christophe Leroy <[email protected]>
---
.../arch/x86/include/arch/endianness.h | 9 ------
tools/objtool/check.c | 2 +-
tools/objtool/include/objtool/endianness.h | 32 +++++++++----------
tools/objtool/orc_dump.c | 11 +++++--
tools/objtool/orc_gen.c | 4 +--
tools/objtool/special.c | 3 +-
6 files changed, 30 insertions(+), 31 deletions(-)
delete mode 100644 tools/objtool/arch/x86/include/arch/endianness.h

diff --git a/tools/objtool/arch/x86/include/arch/endianness.h b/tools/objtool/arch/x86/include/arch/endianness.h
deleted file mode 100644
index 7c362527da20..000000000000
--- a/tools/objtool/arch/x86/include/arch/endianness.h
+++ /dev/null
@@ -1,9 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-#ifndef _ARCH_ENDIANNESS_H
-#define _ARCH_ENDIANNESS_H
-
-#include <endian.h>
-
-#define __TARGET_BYTE_ORDER __LITTLE_ENDIAN
-
-#endif /* _ARCH_ENDIANNESS_H */
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 8427af808221..ad5dab175701 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2100,7 +2100,7 @@ static int read_unwind_hints(struct objtool_file *file)
return -1;
}

- cfi.cfa.offset = bswap_if_needed(hint->sp_offset);
+ cfi.cfa.offset = bswap_if_needed(file->elf, hint->sp_offset);
cfi.type = hint->type;
cfi.end = hint->end;

diff --git a/tools/objtool/include/objtool/endianness.h b/tools/objtool/include/objtool/endianness.h
index 10241341eff3..4d2aa9b0fe2f 100644
--- a/tools/objtool/include/objtool/endianness.h
+++ b/tools/objtool/include/objtool/endianness.h
@@ -2,33 +2,33 @@
#ifndef _OBJTOOL_ENDIANNESS_H
#define _OBJTOOL_ENDIANNESS_H

-#include <arch/endianness.h>
#include <linux/kernel.h>
#include <endian.h>
-
-#ifndef __TARGET_BYTE_ORDER
-#error undefined arch __TARGET_BYTE_ORDER
-#endif
-
-#if __BYTE_ORDER != __TARGET_BYTE_ORDER
-#define __NEED_BSWAP 1
-#else
-#define __NEED_BSWAP 0
-#endif
+#include <objtool/elf.h>

/*
- * Does a byte swap if target endianness doesn't match the host, i.e. cross
+ * Does a byte swap if target file endianness doesn't match the host, i.e. cross
* compilation for little endian on big endian and vice versa.
* To be used for multi-byte values conversion, which are read from / about
* to be written to a target native endianness ELF file.
*/
-#define bswap_if_needed(val) \
+static inline bool need_bswap(struct elf *elf)
+{
+ return (__BYTE_ORDER == __LITTLE_ENDIAN) ^
+ (elf->ehdr.e_ident[EI_DATA] == ELFDATA2LSB);
+}
+
+#define bswap_if_needed(elf, val) \
({ \
__typeof__(val) __ret; \
+ bool __need_bswap = need_bswap(elf); \
switch (sizeof(val)) { \
- case 8: __ret = __NEED_BSWAP ? bswap_64(val) : (val); break; \
- case 4: __ret = __NEED_BSWAP ? bswap_32(val) : (val); break; \
- case 2: __ret = __NEED_BSWAP ? bswap_16(val) : (val); break; \
+ case 8: \
+ __ret = __need_bswap ? bswap_64(val) : (val); break; \
+ case 4: \
+ __ret = __need_bswap ? bswap_32(val) : (val); break; \
+ case 2: \
+ __ret = __need_bswap ? bswap_16(val) : (val); break; \
default: \
BUILD_BUG(); break; \
} \
diff --git a/tools/objtool/orc_dump.c b/tools/objtool/orc_dump.c
index f5a8508c42d6..4f1211fec82c 100644
--- a/tools/objtool/orc_dump.c
+++ b/tools/objtool/orc_dump.c
@@ -76,6 +76,7 @@ int orc_dump(const char *_objname)
GElf_Rela rela;
GElf_Sym sym;
Elf_Data *data, *symtab = NULL, *rela_orc_ip = NULL;
+ struct elf dummy_elf = {};


objname = _objname;
@@ -94,6 +95,12 @@ int orc_dump(const char *_objname)
return -1;
}

+ if (!elf64_getehdr(elf)) {
+ WARN_ELF("elf64_getehdr");
+ return -1;
+ }
+ memcpy(&dummy_elf.ehdr, elf64_getehdr(elf), sizeof(dummy_elf.ehdr));
+
if (elf_getshdrnum(elf, &nr_sections)) {
WARN_ELF("elf_getshdrnum");
return -1;
@@ -198,11 +205,11 @@ int orc_dump(const char *_objname)

printf(" sp:");

- print_reg(orc[i].sp_reg, bswap_if_needed(orc[i].sp_offset));
+ print_reg(orc[i].sp_reg, bswap_if_needed(&dummy_elf, orc[i].sp_offset));

printf(" bp:");

- print_reg(orc[i].bp_reg, bswap_if_needed(orc[i].bp_offset));
+ print_reg(orc[i].bp_reg, bswap_if_needed(&dummy_elf, orc[i].bp_offset));

printf(" type:%s end:%d\n",
orc_type_name(orc[i].type), orc[i].end);
diff --git a/tools/objtool/orc_gen.c b/tools/objtool/orc_gen.c
index dd3c64af9db2..1f22b7ebae58 100644
--- a/tools/objtool/orc_gen.c
+++ b/tools/objtool/orc_gen.c
@@ -97,8 +97,8 @@ static int write_orc_entry(struct elf *elf, struct section *orc_sec,
/* populate ORC data */
orc = (struct orc_entry *)orc_sec->data->d_buf + idx;
memcpy(orc, o, sizeof(*orc));
- orc->sp_offset = bswap_if_needed(orc->sp_offset);
- orc->bp_offset = bswap_if_needed(orc->bp_offset);
+ orc->sp_offset = bswap_if_needed(elf, orc->sp_offset);
+ 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,
diff --git a/tools/objtool/special.c b/tools/objtool/special.c
index e2223dd91c37..9c8d827f69af 100644
--- a/tools/objtool/special.c
+++ b/tools/objtool/special.c
@@ -87,7 +87,8 @@ static int get_alt_entry(struct elf *elf, struct special_entry *entry,
if (entry->feature) {
unsigned short feature;

- feature = bswap_if_needed(*(unsigned short *)(sec->data->d_buf +
+ feature = bswap_if_needed(elf,
+ *(unsigned short *)(sec->data->d_buf +
offset +
entry->feature));
arch_handle_alternative(feature, alt);
--
2.31.1


2022-10-28 15:06:48

by Sathvika Vasireddy

[permalink] [raw]
Subject: [PATCH v5 12/16] objtool: Read special sections with alts only when specific options are selected

Call add_special_section_alts() only when stackval or orc or uaccess or
noinstr options are passed to objtool.

Tested-by: Naveen N. Rao <[email protected]>
Reviewed-by: Naveen N. Rao <[email protected]>
Reviewed-by: Christophe Leroy <[email protected]>
Acked-by: Josh Poimboeuf <[email protected]>
Signed-off-by: Sathvika Vasireddy <[email protected]>
---
tools/objtool/check.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 71cf4b4ba1da..752a6ffd5c4c 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2392,9 +2392,11 @@ static int decode_sections(struct objtool_file *file)
* Must be before add_jump_destinations(), which depends on 'func'
* being set for alternatives, to enable proper sibling call detection.
*/
- ret = add_special_section_alts(file);
- if (ret)
- return ret;
+ if (opts.stackval || opts.orc || opts.uaccess || opts.noinstr) {
+ ret = add_special_section_alts(file);
+ if (ret)
+ return ret;
+ }

ret = add_jump_destinations(file);
if (ret)
--
2.31.1


2022-10-28 15:06:56

by Sathvika Vasireddy

[permalink] [raw]
Subject: [PATCH v5 07/16] powerpc: Skip objtool from running on VDSO files

Do not run objtool on VDSO files, by using OBJECT_FILES_NON_STANDARD.

Suggested-by: Christophe Leroy <[email protected]>
Tested-by: Naveen N. Rao <[email protected]>
Reviewed-by: Naveen N. Rao <[email protected]>
Reviewed-by: Christophe Leroy <[email protected]>
Acked-by: Josh Poimboeuf <[email protected]>
Signed-off-by: Sathvika Vasireddy <[email protected]>
---
arch/powerpc/kernel/vdso/Makefile | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/kernel/vdso/Makefile b/arch/powerpc/kernel/vdso/Makefile
index a2e7b0ce5b19..6a977b0d8ffc 100644
--- a/arch/powerpc/kernel/vdso/Makefile
+++ b/arch/powerpc/kernel/vdso/Makefile
@@ -102,3 +102,5 @@ quiet_cmd_vdso64ld_and_check = VDSO64L $@
cmd_vdso64ld_and_check = $(VDSOCC) $(c_flags) $(CC64FLAGS) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^) -z noexecstack ; $(cmd_vdso_check)
quiet_cmd_vdso64as = VDSO64A $@
cmd_vdso64as = $(VDSOCC) $(a_flags) $(CC64FLAGS) $(AS64FLAGS) -c -o $@ $<
+
+OBJECT_FILES_NON_STANDARD := y
--
2.31.1


2022-10-28 15:09:06

by Sathvika Vasireddy

[permalink] [raw]
Subject: [PATCH v5 11/16] objtool: Add --mnop as an option to --mcount

Some architectures (powerpc) may not support ftrace locations being nop'ed
out at build time. Introduce CONFIG_HAVE_OBJTOOL_NOP_MCOUNT for objtool, as
a means for architectures to enable nop'ing of ftrace locations. Add --mnop
as an option to objtool --mcount, to indicate support for the same.

Also, make sure that --mnop can be passed as an option to objtool only when
--mcount is passed.

Tested-by: Naveen N. Rao <[email protected]>
Reviewed-by: Naveen N. Rao <[email protected]>
Acked-by: Josh Poimboeuf <[email protected]>
Reviewed-by: Christophe Leroy <[email protected]>
Signed-off-by: Sathvika Vasireddy <[email protected]>
---
Makefile | 4 +++-
arch/x86/Kconfig | 1 +
kernel/trace/Kconfig | 7 +++++++
scripts/Makefile.lib | 3 +++
tools/objtool/builtin-check.c | 14 ++++++++++++++
tools/objtool/check.c | 19 ++++++++++---------
tools/objtool/include/objtool/builtin.h | 1 +
7 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile
index d148a55bfd0f..53c2b715d0bf 100644
--- a/Makefile
+++ b/Makefile
@@ -933,7 +933,9 @@ ifdef CONFIG_FTRACE_MCOUNT_USE_CC
endif
endif
ifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL
- CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT
+ ifdef CONFIG_HAVE_OBJTOOL_NOP_MCOUNT
+ CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT
+ endif
endif
ifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
ifdef CONFIG_HAVE_C_RECORDMCOUNT
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 67745ceab0db..4be7c06a5d18 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -195,6 +195,7 @@ config X86
select HAVE_CONTEXT_TRACKING_USER_OFFSTACK if HAVE_CONTEXT_TRACKING_USER
select HAVE_C_RECORDMCOUNT
select HAVE_OBJTOOL_MCOUNT if HAVE_OBJTOOL
+ select HAVE_OBJTOOL_NOP_MCOUNT if HAVE_OBJTOOL_MCOUNT
select HAVE_BUILDTIME_MCOUNT_SORT
select HAVE_DEBUG_KMEMLEAK
select HAVE_DMA_CONTIGUOUS
diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig
index e9e95c790b8e..2b782321376a 100644
--- a/kernel/trace/Kconfig
+++ b/kernel/trace/Kconfig
@@ -82,6 +82,13 @@ config HAVE_OBJTOOL_MCOUNT
help
Arch supports objtool --mcount

+config HAVE_OBJTOOL_NOP_MCOUNT
+ bool
+ help
+ Arch supports the objtool options --mcount with --mnop.
+ An architecture can select this if it wants to enable nop'ing
+ of ftrace locations.
+
config HAVE_C_RECORDMCOUNT
bool
help
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 3aa384cec76b..658f541c2782 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -256,6 +256,9 @@ objtool-args-$(CONFIG_HAVE_JUMP_LABEL_HACK) += --hacks=jump_label
objtool-args-$(CONFIG_HAVE_NOINSTR_HACK) += --hacks=noinstr
objtool-args-$(CONFIG_X86_KERNEL_IBT) += --ibt
objtool-args-$(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL) += --mcount
+ifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL
+objtool-args-$(CONFIG_HAVE_OBJTOOL_NOP_MCOUNT) += --mnop
+endif
objtool-args-$(CONFIG_UNWINDER_ORC) += --orc
objtool-args-$(CONFIG_RETPOLINE) += --retpoline
objtool-args-$(CONFIG_RETHUNK) += --rethunk
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index 24fbe803a0d3..9bd347d3c244 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -82,6 +82,7 @@ const struct option check_options[] = {
OPT_BOOLEAN(0, "dry-run", &opts.dryrun, "don't write modifications"),
OPT_BOOLEAN(0, "link", &opts.link, "object is a linked object"),
OPT_BOOLEAN(0, "module", &opts.module, "object is part of a kernel module"),
+ OPT_BOOLEAN(0, "mnop", &opts.mnop, "nop out mcount call sites"),
OPT_BOOLEAN(0, "no-unreachable", &opts.no_unreachable, "skip 'unreachable instruction' warnings"),
OPT_BOOLEAN(0, "sec-address", &opts.sec_address, "print section addresses in warnings"),
OPT_BOOLEAN(0, "stats", &opts.stats, "print statistics"),
@@ -150,6 +151,16 @@ static bool opts_valid(void)
return false;
}

+static bool mnop_opts_valid(void)
+{
+ if (opts.mnop && !opts.mcount) {
+ ERROR("--mnop requires --mcount");
+ return false;
+ }
+
+ return true;
+}
+
static bool link_opts_valid(struct objtool_file *file)
{
if (opts.link)
@@ -198,6 +209,9 @@ int objtool_run(int argc, const char **argv)
if (!file)
return 1;

+ if (!mnop_opts_valid())
+ return 1;
+
if (!link_opts_valid(file))
return 1;

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index b64518c7c7b4..71cf4b4ba1da 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -1256,17 +1256,18 @@ static void annotate_call_site(struct objtool_file *file,
if (opts.mcount && sym->fentry) {
if (sibling)
WARN_FUNC("Tail call to __fentry__ !?!?", insn->sec, insn->offset);
+ if (opts.mnop) {
+ if (reloc) {
+ reloc->type = R_NONE;
+ elf_write_reloc(file->elf, reloc);
+ }

- if (reloc) {
- reloc->type = R_NONE;
- elf_write_reloc(file->elf, reloc);
- }
-
- elf_write_insn(file->elf, insn->sec,
- insn->offset, insn->len,
- arch_nop_insn(insn->len));
+ elf_write_insn(file->elf, insn->sec,
+ insn->offset, insn->len,
+ arch_nop_insn(insn->len));

- insn->type = INSN_NOP;
+ insn->type = INSN_NOP;
+ }

list_add_tail(&insn->call_node, &file->mcount_loc_list);
return;
diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/include/objtool/builtin.h
index 42a52f1a0add..0785707c5a92 100644
--- a/tools/objtool/include/objtool/builtin.h
+++ b/tools/objtool/include/objtool/builtin.h
@@ -31,6 +31,7 @@ struct opts {
bool backup;
bool dryrun;
bool link;
+ bool mnop;
bool module;
bool no_unreachable;
bool sec_address;
--
2.31.1


2022-10-28 15:09:16

by Sathvika Vasireddy

[permalink] [raw]
Subject: [PATCH v5 13/16] objtool: Use macros to define arch specific reloc types

Make relocation types architecture specific.

Tested-by: Naveen N. Rao <[email protected]>
Reviewed-by: Naveen N. Rao <[email protected]>
Reviewed-by: Christophe Leroy <[email protected]>
Acked-by: Peter Zijlstra (Intel) <[email protected]>
Acked-by: Josh Poimboeuf <[email protected]>
Signed-off-by: Sathvika Vasireddy <[email protected]>
---
tools/objtool/arch/x86/include/arch/elf.h | 2 ++
tools/objtool/check.c | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/objtool/arch/x86/include/arch/elf.h b/tools/objtool/arch/x86/include/arch/elf.h
index 69cc4264b28a..ac14987cf687 100644
--- a/tools/objtool/arch/x86/include/arch/elf.h
+++ b/tools/objtool/arch/x86/include/arch/elf.h
@@ -2,5 +2,7 @@
#define _OBJTOOL_ARCH_ELF

#define R_NONE R_X86_64_NONE
+#define R_ABS64 R_X86_64_64
+#define R_ABS32 R_X86_64_32

#endif /* _OBJTOOL_ARCH_ELF */
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 752a6ffd5c4c..2d7153b5d5d1 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -885,7 +885,7 @@ static int create_mcount_loc_sections(struct objtool_file *file)
memset(loc, 0, addrsize);

if (elf_add_reloc_to_insn(file->elf, sec, idx,
- R_X86_64_64,
+ addrsize == sizeof(u64) ? R_ABS64 : R_ABS32,
insn->sec, insn->offset))
return -1;

--
2.31.1


2022-10-28 15:22:24

by Sathvika Vasireddy

[permalink] [raw]
Subject: [PATCH v5 16/16] objtool/powerpc: Add --mcount specific implementation

This patch enables objtool --mcount on powerpc, and adds implementation
specific to powerpc.

Tested-by: Naveen N. Rao <[email protected]>
Reviewed-by: Naveen N. Rao <[email protected]>
Reviewed-by: Christophe Leroy <[email protected]>
Acked-by: Josh Poimboeuf <[email protected]>
Signed-off-by: Sathvika Vasireddy <[email protected]>
---
arch/powerpc/Kconfig | 1 +
tools/objtool/arch/powerpc/decode.c | 16 ++++++++++++++++
tools/objtool/arch/powerpc/include/arch/elf.h | 2 ++
3 files changed, 19 insertions(+)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 12e6c16be54e..9c07068ba5e5 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -239,6 +239,7 @@ config PPC
select HAVE_NMI if PERF_EVENTS || (PPC64 && PPC_BOOK3S)
select HAVE_OPTPROBES
select HAVE_OBJTOOL if PPC32 || MPROFILE_KERNEL
+ select HAVE_OBJTOOL_MCOUNT if HAVE_OBJTOOL
select HAVE_PERF_EVENTS
select HAVE_PERF_EVENTS_NMI if PPC64
select HAVE_PERF_REGS
diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/powerpc/decode.c
index dcd0975cad6b..01cade98b49e 100644
--- a/tools/objtool/arch/powerpc/decode.c
+++ b/tools/objtool/arch/powerpc/decode.c
@@ -9,6 +9,11 @@
#include <objtool/builtin.h>
#include <objtool/endianness.h>

+int arch_ftrace_match(char *name)
+{
+ return !strcmp(name, "_mcount");
+}
+
unsigned long arch_dest_reloc_offset(int addend)
{
return addend;
@@ -50,6 +55,17 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
typ = INSN_OTHER;
imm = 0;

+ switch (opcode) {
+ case 18: /* b[l][a] */
+ if ((insn & 3) == 1) /* bl */
+ typ = INSN_CALL;
+
+ imm = insn & 0x3fffffc;
+ if (imm & 0x2000000)
+ imm -= 0x4000000;
+ break;
+ }
+
if (opcode == 1)
*len = 8;
else
diff --git a/tools/objtool/arch/powerpc/include/arch/elf.h b/tools/objtool/arch/powerpc/include/arch/elf.h
index 3c8ebb7d2a6b..73f9ae172fe5 100644
--- a/tools/objtool/arch/powerpc/include/arch/elf.h
+++ b/tools/objtool/arch/powerpc/include/arch/elf.h
@@ -4,5 +4,7 @@
#define _OBJTOOL_ARCH_ELF

#define R_NONE R_PPC_NONE
+#define R_ABS64 R_PPC64_ADDR64
+#define R_ABS32 R_PPC_ADDR32

#endif /* _OBJTOOL_ARCH_ELF */
--
2.31.1


2022-11-02 13:29:32

by Christophe Leroy

[permalink] [raw]
Subject: Re: [PATCH v5 06/16] powerpc: Fix objtool unannotated intra-function call warnings on PPC32



Le 28/10/2022 à 16:33, Sathvika Vasireddy a écrit :
> From: Christophe Leroy <[email protected]>
>
> Fix several annotations in assembly files on PPC32.
>
> Tested-by: Naveen N. Rao <[email protected]>
> Reviewed-by: Naveen N. Rao <[email protected]>
> Acked-by: Josh Poimboeuf <[email protected]>
> Signed-off-by: Christophe Leroy <[email protected]>
> [Sathvika Vasireddy: Changed subject line from "objtool/powerpc: Activate
> objtool on PPC32" to "powerpc: Fix objtool unannotated intra-function call
> warnings on PPC32", and removed Kconfig change to enable objtool, as it
> is a part of "objtool/powerpc: Enable objtool to be built on ppc" patch in
> this series.]
> Signed-off-by: Sathvika Vasireddy <[email protected]>
> ---
> arch/powerpc/kernel/cpu_setup_6xx.S | 26 ++++++++++++------
> arch/powerpc/kernel/entry_32.S | 9 ++++--
> arch/powerpc/kernel/head_40x.S | 5 +++-
> arch/powerpc/kernel/head_8xx.S | 5 +++-
> arch/powerpc/kernel/head_book3s_32.S | 29 ++++++++++++++------
> arch/powerpc/kernel/swsusp_32.S | 5 +++-
> arch/powerpc/kvm/fpu.S | 17 ++++++++----
> arch/powerpc/platforms/52xx/lite5200_sleep.S | 15 +++++++---
> 8 files changed, 79 insertions(+), 32 deletions(-)

You are missing cpu_setup_e500.S and head_85xx.S in
arch/powerpc/kernel/, see my commit to the cover letter.

>
> diff --git a/arch/powerpc/kernel/cpu_setup_6xx.S b/arch/powerpc/kernel/cpu_setup_6xx.S
> index f8b5ff64b604..f29ce3dd6140 100644
> --- a/arch/powerpc/kernel/cpu_setup_6xx.S
> +++ b/arch/powerpc/kernel/cpu_setup_6xx.S
> @@ -4,6 +4,8 @@
> * Copyright (C) 2003 Benjamin Herrenschmidt ([email protected])
> */
>
> +#include <linux/linkage.h>
> +
> #include <asm/processor.h>
> #include <asm/page.h>
> #include <asm/cputable.h>
> @@ -81,7 +83,7 @@ _GLOBAL(__setup_cpu_745x)
> blr
>
> /* Enable caches for 603's, 604, 750 & 7400 */
> -setup_common_caches:
> +SYM_FUNC_START_LOCAL(setup_common_caches)
> mfspr r11,SPRN_HID0
> andi. r0,r11,HID0_DCE
> ori r11,r11,HID0_ICE|HID0_DCE
> @@ -95,11 +97,12 @@ setup_common_caches:
> sync
> isync
> blr
> +SYM_FUNC_END(setup_common_caches)
>
> /* 604, 604e, 604ev, ...
> * Enable superscalar execution & branch history table
> */
> -setup_604_hid0:
> +SYM_FUNC_START_LOCAL(setup_604_hid0)
> mfspr r11,SPRN_HID0
> ori r11,r11,HID0_SIED|HID0_BHTE
> ori r8,r11,HID0_BTCD
> @@ -110,6 +113,7 @@ setup_604_hid0:
> sync
> isync
> blr
> +SYM_FUNC_END(setup_604_hid0)
>
> /* 7400 <= rev 2.7 and 7410 rev = 1.0 suffer from some
> * erratas we work around here.
> @@ -125,13 +129,14 @@ setup_604_hid0:
> * needed once we have applied workaround #5 (though it's
> * not set by Apple's firmware at least).
> */
> -setup_7400_workarounds:
> +SYM_FUNC_START_LOCAL(setup_7400_workarounds)
> mfpvr r3
> rlwinm r3,r3,0,20,31
> cmpwi 0,r3,0x0207
> ble 1f
> blr
> -setup_7410_workarounds:
> +SYM_FUNC_END(setup_7400_workarounds)
> +SYM_FUNC_START_LOCAL(setup_7410_workarounds)
> mfpvr r3
> rlwinm r3,r3,0,20,31
> cmpwi 0,r3,0x0100
> @@ -151,6 +156,7 @@ setup_7410_workarounds:
> sync
> isync
> blr
> +SYM_FUNC_END(setup_7410_workarounds)
>
> /* 740/750/7400/7410
> * Enable Store Gathering (SGE), Address Broadcast (ABE),
> @@ -158,7 +164,7 @@ setup_7410_workarounds:
> * Dynamic Power Management (DPM), Speculative (SPD)
> * Clear Instruction cache throttling (ICTC)
> */
> -setup_750_7400_hid0:
> +SYM_FUNC_START_LOCAL(setup_750_7400_hid0)
> mfspr r11,SPRN_HID0
> ori r11,r11,HID0_SGE | HID0_ABE | HID0_BHTE | HID0_BTIC
> oris r11,r11,HID0_DPM@h
> @@ -177,12 +183,13 @@ END_FTR_SECTION_IFSET(CPU_FTR_NO_DPM)
> sync
> isync
> blr
> +SYM_FUNC_END(setup_750_7400_hid0)
>
> /* 750cx specific
> * Looks like we have to disable NAP feature for some PLL settings...
> * (waiting for confirmation)
> */
> -setup_750cx:
> +SYM_FUNC_START_LOCAL(setup_750cx)
> mfspr r10, SPRN_HID1
> rlwinm r10,r10,4,28,31
> cmpwi cr0,r10,7
> @@ -196,11 +203,13 @@ setup_750cx:
> andc r6,r6,r7
> stw r6,CPU_SPEC_FEATURES(r4)
> blr
> +SYM_FUNC_END(setup_750cx)
>
> /* 750fx specific
> */
> -setup_750fx:
> +SYM_FUNC_START_LOCAL(setup_750fx)
> blr
> +SYM_FUNC_END(setup_750fx)
>
> /* MPC 745x
> * Enable Store Gathering (SGE), Branch Folding (FOLD)
> @@ -212,7 +221,7 @@ setup_750fx:
> * Clear Instruction cache throttling (ICTC)
> * Enable L2 HW prefetch
> */
> -setup_745x_specifics:
> +SYM_FUNC_START_LOCAL(setup_745x_specifics)
> /* We check for the presence of an L3 cache setup by
> * the firmware. If any, we disable NAP capability as
> * it's known to be bogus on rev 2.1 and earlier
> @@ -270,6 +279,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_NO_DPM)
> sync
> isync
> blr
> +SYM_FUNC_END(setup_745x_specifics)
>
> /*
> * Initialize the FPU registers. This is needed to work around an errata
> diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
> index 3fc7c9886bb7..5e0763be1549 100644
> --- a/arch/powerpc/kernel/entry_32.S
> +++ b/arch/powerpc/kernel/entry_32.S
> @@ -18,6 +18,8 @@
> #include <linux/err.h>
> #include <linux/sys.h>
> #include <linux/threads.h>
> +#include <linux/linkage.h>
> +
> #include <asm/reg.h>
> #include <asm/page.h>
> #include <asm/mmu.h>
> @@ -74,17 +76,18 @@ _ASM_NOKPROBE_SYMBOL(prepare_transfer_to_handler)
> #endif /* CONFIG_PPC_BOOK3S_32 || CONFIG_PPC_E500 */
>
> #if defined(CONFIG_PPC_KUEP) && defined(CONFIG_PPC_BOOK3S_32)
> - .globl __kuep_lock
> -__kuep_lock:
> +SYM_FUNC_START(__kuep_lock)
> lwz r9, THREAD+THSR0(r2)
> update_user_segments_by_4 r9, r10, r11, r12
> blr
> +SYM_FUNC_END(__kuep_lock)
>
> -__kuep_unlock:
> +SYM_FUNC_START_LOCAL(__kuep_unlock)
> lwz r9, THREAD+THSR0(r2)
> rlwinm r9,r9,0,~SR_NX
> update_user_segments_by_4 r9, r10, r11, r12
> blr
> +SYM_FUNC_END(__kuep_unlock)
>
> .macro kuep_lock
> bl __kuep_lock
> diff --git a/arch/powerpc/kernel/head_40x.S b/arch/powerpc/kernel/head_40x.S
> index 088f500896c7..9110fe9d6747 100644
> --- a/arch/powerpc/kernel/head_40x.S
> +++ b/arch/powerpc/kernel/head_40x.S
> @@ -28,6 +28,8 @@
> #include <linux/init.h>
> #include <linux/pgtable.h>
> #include <linux/sizes.h>
> +#include <linux/linkage.h>
> +
> #include <asm/processor.h>
> #include <asm/page.h>
> #include <asm/mmu.h>
> @@ -662,7 +664,7 @@ start_here:
> * kernel initialization. This maps the first 32 MBytes of memory 1:1
> * virtual to physical and more importantly sets the cache mode.
> */
> -initial_mmu:
> +SYM_FUNC_START_LOCAL(initial_mmu)
> tlbia /* Invalidate all TLB entries */
> isync
>
> @@ -711,6 +713,7 @@ initial_mmu:
> mtspr SPRN_EVPR,r0
>
> blr
> +SYM_FUNC_END(initial_mmu)
>
> _GLOBAL(abort)
> mfspr r13,SPRN_DBCR0
> diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S
> index 0b05f2be66b9..c94ed5a08c93 100644
> --- a/arch/powerpc/kernel/head_8xx.S
> +++ b/arch/powerpc/kernel/head_8xx.S
> @@ -18,6 +18,8 @@
> #include <linux/magic.h>
> #include <linux/pgtable.h>
> #include <linux/sizes.h>
> +#include <linux/linkage.h>
> +
> #include <asm/processor.h>
> #include <asm/page.h>
> #include <asm/mmu.h>
> @@ -625,7 +627,7 @@ start_here:
> * 24 Mbytes of data, and the 512k IMMR space. Anything not covered by
> * these mappings is mapped by page tables.
> */
> -initial_mmu:
> +SYM_FUNC_START_LOCAL(initial_mmu)
> li r8, 0
> mtspr SPRN_MI_CTR, r8 /* remove PINNED ITLB entries */
> lis r10, MD_TWAM@h
> @@ -686,6 +688,7 @@ initial_mmu:
> #endif
> mtspr SPRN_DER, r8
> blr
> +SYM_FUNC_END(initial_mmu)
>
> _GLOBAL(mmu_pin_tlb)
> lis r9, (1f - PAGE_OFFSET)@h
> diff --git a/arch/powerpc/kernel/head_book3s_32.S b/arch/powerpc/kernel/head_book3s_32.S
> index 519b60695167..4af12447dc0b 100644
> --- a/arch/powerpc/kernel/head_book3s_32.S
> +++ b/arch/powerpc/kernel/head_book3s_32.S
> @@ -18,6 +18,8 @@
>
> #include <linux/init.h>
> #include <linux/pgtable.h>
> +#include <linux/linkage.h>
> +
> #include <asm/reg.h>
> #include <asm/page.h>
> #include <asm/mmu.h>
> @@ -877,7 +879,7 @@ END_MMU_FTR_SECTION_IFCLR(MMU_FTR_HPTE_TABLE)
> * Load stuff into the MMU. Intended to be called with
> * IR=0 and DR=0.
> */
> -early_hash_table:
> +SYM_FUNC_START_LOCAL(early_hash_table)
> sync /* Force all PTE updates to finish */
> isync
> tlbia /* Clear all TLB entries */
> @@ -888,8 +890,9 @@ early_hash_table:
> ori r6, r6, 3 /* 256kB table */
> mtspr SPRN_SDR1, r6
> blr
> +SYM_FUNC_END(early_hash_table)
>
> -load_up_mmu:
> +SYM_FUNC_START_LOCAL(load_up_mmu)
> sync /* Force all PTE updates to finish */
> isync
> tlbia /* Clear all TLB entries */
> @@ -918,6 +921,7 @@ BEGIN_MMU_FTR_SECTION
> LOAD_BAT(7,r3,r4,r5)
> END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
> blr
> +SYM_FUNC_END(load_up_mmu)
>
> _GLOBAL(load_segment_registers)
> li r0, NUM_USER_SEGMENTS /* load up user segment register values */
> @@ -1028,7 +1032,7 @@ END_MMU_FTR_SECTION_IFCLR(MMU_FTR_HPTE_TABLE)
> * this makes sure it's done.
> * -- Cort
> */
> -clear_bats:
> +SYM_FUNC_START_LOCAL(clear_bats)
> li r10,0
>
> mtspr SPRN_DBAT0U,r10
> @@ -1072,6 +1076,7 @@ BEGIN_MMU_FTR_SECTION
> mtspr SPRN_IBAT7L,r10
> END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
> blr
> +SYM_FUNC_END(clear_bats)
>
> _GLOBAL(update_bats)
> lis r4, 1f@h
> @@ -1108,15 +1113,16 @@ END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
> mtspr SPRN_SRR1, r6
> rfi
>
> -flush_tlbs:
> +SYM_FUNC_START_LOCAL(flush_tlbs)
> lis r10, 0x40
> 1: addic. r10, r10, -0x1000
> tlbie r10
> bgt 1b
> sync
> blr
> +SYM_FUNC_END(flush_tlbs)
>
> -mmu_off:
> +SYM_FUNC_START_LOCAL(mmu_off)
> addi r4, r3, __after_mmu_off - _start
> mfmsr r3
> andi. r0,r3,MSR_DR|MSR_IR /* MMU enabled? */
> @@ -1128,9 +1134,10 @@ mmu_off:
> mtspr SPRN_SRR1,r3
> sync
> rfi
> +SYM_FUNC_END(mmu_off)
>
> /* We use one BAT to map up to 256M of RAM at _PAGE_OFFSET */
> -initial_bats:
> +SYM_FUNC_START_LOCAL(initial_bats)
> lis r11,PAGE_OFFSET@h
> tophys(r8,r11)
> #ifdef CONFIG_SMP
> @@ -1146,9 +1153,10 @@ initial_bats:
> mtspr SPRN_IBAT0U,r11
> isync
> blr
> +SYM_FUNC_END(initial_bats)
>
> #ifdef CONFIG_BOOTX_TEXT
> -setup_disp_bat:
> +SYM_FUNC_START_LOCAL(setup_disp_bat)
> /*
> * setup the display bat prepared for us in prom.c
> */
> @@ -1164,10 +1172,11 @@ setup_disp_bat:
> mtspr SPRN_DBAT3L,r8
> mtspr SPRN_DBAT3U,r11
> blr
> +SYM_FUNC_END(setup_disp_bat)
> #endif /* CONFIG_BOOTX_TEXT */
>
> #ifdef CONFIG_PPC_EARLY_DEBUG_CPM
> -setup_cpm_bat:
> +SYM_FUNC_START_LOCAL(setup_cpm_bat)
> lis r8, 0xf000
> ori r8, r8, 0x002a
> mtspr SPRN_DBAT1L, r8
> @@ -1177,10 +1186,11 @@ setup_cpm_bat:
> mtspr SPRN_DBAT1U, r11
>
> blr
> +SYM_FUNC_END(setup_cpm_bat)
> #endif
>
> #ifdef CONFIG_PPC_EARLY_DEBUG_USBGECKO
> -setup_usbgecko_bat:
> +SYM_FUNC_START_LOCAL(setup_usbgecko_bat)
> /* prepare a BAT for early io */
> #if defined(CONFIG_GAMECUBE)
> lis r8, 0x0c00
> @@ -1199,6 +1209,7 @@ setup_usbgecko_bat:
> mtspr SPRN_DBAT1L, r8
> mtspr SPRN_DBAT1U, r11
> blr
> +SYM_FUNC_END(setup_usbgecko_bat)
> #endif
>
> .data
> diff --git a/arch/powerpc/kernel/swsusp_32.S b/arch/powerpc/kernel/swsusp_32.S
> index e0cbd63007f2..ffb79326483c 100644
> --- a/arch/powerpc/kernel/swsusp_32.S
> +++ b/arch/powerpc/kernel/swsusp_32.S
> @@ -1,5 +1,7 @@
> /* SPDX-License-Identifier: GPL-2.0 */
> #include <linux/threads.h>
> +#include <linux/linkage.h>
> +
> #include <asm/processor.h>
> #include <asm/page.h>
> #include <asm/cputable.h>
> @@ -400,7 +402,7 @@ _ASM_NOKPROBE_SYMBOL(swsusp_arch_resume)
> /* FIXME:This construct is actually not useful since we don't shut
> * down the instruction MMU, we could just flip back MSR-DR on.
> */
> -turn_on_mmu:
> +SYM_FUNC_START_LOCAL(turn_on_mmu)
> mflr r4
> mtsrr0 r4
> mtsrr1 r3
> @@ -408,4 +410,5 @@ turn_on_mmu:
> isync
> rfi
> _ASM_NOKPROBE_SYMBOL(turn_on_mmu)
> +SYM_FUNC_END(turn_on_mmu)
>
> diff --git a/arch/powerpc/kvm/fpu.S b/arch/powerpc/kvm/fpu.S
> index 315c94946bad..b68e7f26a81f 100644
> --- a/arch/powerpc/kvm/fpu.S
> +++ b/arch/powerpc/kvm/fpu.S
> @@ -6,6 +6,8 @@
> */
>
> #include <linux/pgtable.h>
> +#include <linux/linkage.h>
> +
> #include <asm/reg.h>
> #include <asm/page.h>
> #include <asm/mmu.h>
> @@ -110,18 +112,22 @@ FPS_THREE_IN(fsel)
> * R8 = (double*)&param3 [load_three]
> * LR = instruction call function
> */
> -fpd_load_three:
> +SYM_FUNC_START_LOCAL(fpd_load_three)
> lfd 2,0(r8) /* load param3 */
> -fpd_load_two:
> +SYM_FUNC_START_LOCAL(fpd_load_two)
> lfd 1,0(r7) /* load param2 */
> -fpd_load_one:
> +SYM_FUNC_START_LOCAL(fpd_load_one)
> lfd 0,0(r6) /* load param1 */
> -fpd_load_none:
> +SYM_FUNC_START_LOCAL(fpd_load_none)
> lfd 3,0(r3) /* load up fpscr value */
> MTFSF_L(3)
> lwz r6, 0(r4) /* load cr */
> mtcr r6
> blr
> +SYM_FUNC_END(fpd_load_none)
> +SYM_FUNC_END(fpd_load_one)
> +SYM_FUNC_END(fpd_load_two)
> +SYM_FUNC_END(fpd_load_three)
>
> /*
> * End of double instruction processing
> @@ -131,13 +137,14 @@ fpd_load_none:
> * R5 = (double*)&result
> * LR = caller of instruction call function
> */
> -fpd_return:
> +SYM_FUNC_START_LOCAL(fpd_return)
> mfcr r6
> stfd 0,0(r5) /* save result */
> mffs 0
> stfd 0,0(r3) /* save new fpscr value */
> stw r6,0(r4) /* save new cr value */
> blr
> +SYM_FUNC_END(fpd_return)
>
> /*
> * Double operation with no input operand
> diff --git a/arch/powerpc/platforms/52xx/lite5200_sleep.S b/arch/powerpc/platforms/52xx/lite5200_sleep.S
> index afee8b1515a8..0b12647e7b42 100644
> --- a/arch/powerpc/platforms/52xx/lite5200_sleep.S
> +++ b/arch/powerpc/platforms/52xx/lite5200_sleep.S
> @@ -1,4 +1,6 @@
> /* SPDX-License-Identifier: GPL-2.0 */
> +#include <linux/linkage.h>
> +
> #include <asm/reg.h>
> #include <asm/ppc_asm.h>
> #include <asm/processor.h>
> @@ -178,7 +180,8 @@ sram_code:
>
>
> /* local udelay in sram is needed */
> - udelay: /* r11 - tb_ticks_per_usec, r12 - usecs, overwrites r13 */
> +SYM_FUNC_START_LOCAL(udelay)
> + /* r11 - tb_ticks_per_usec, r12 - usecs, overwrites r13 */
> mullw r12, r12, r11
> mftb r13 /* start */
> add r12, r13, r12 /* end */
> @@ -187,6 +190,7 @@ sram_code:
> cmp cr0, r13, r12
> blt 1b
> blr
> +SYM_FUNC_END(udelay)
>
> sram_code_end:
>
> @@ -271,7 +275,7 @@ _ASM_NOKPROBE_SYMBOL(lite5200_wakeup)
> SAVE_SR(n+2, addr+2); \
> SAVE_SR(n+3, addr+3);
>
> -save_regs:
> +SYM_FUNC_START_LOCAL(save_regs)
> stw r0, 0(r4)
> stw r1, 0x4(r4)
> stw r2, 0x8(r4)
> @@ -317,6 +321,7 @@ save_regs:
> SAVE_SPRN(TBRU, 0x5b)
>
> blr
> +SYM_FUNC_END(save_regs)
>
>
> /* restore registers */
> @@ -336,7 +341,7 @@ save_regs:
> LOAD_SR(n+2, addr+2); \
> LOAD_SR(n+3, addr+3);
>
> -restore_regs:
> +SYM_FUNC_START_LOCAL(restore_regs)
> lis r4, registers@h
> ori r4, r4, registers@l
>
> @@ -393,6 +398,7 @@ restore_regs:
>
> blr
> _ASM_NOKPROBE_SYMBOL(restore_regs)
> +SYM_FUNC_END(restore_regs)
>
>
>
> @@ -403,7 +409,7 @@ _ASM_NOKPROBE_SYMBOL(restore_regs)
> * Flush data cache
> * Do this by just reading lots of stuff into the cache.
> */
> -flush_data_cache:
> +SYM_FUNC_START_LOCAL(flush_data_cache)
> lis r3,CONFIG_KERNEL_START@h
> ori r3,r3,CONFIG_KERNEL_START@l
> li r4,NUM_CACHE_LINES
> @@ -413,3 +419,4 @@ flush_data_cache:
> addi r3,r3,L1_CACHE_BYTES /* Next line, please */
> bdnz 1b
> blr
> +SYM_FUNC_END(flush_data_cache)

2022-11-02 13:30:02

by Christophe Leroy

[permalink] [raw]
Subject: Re: [PATCH v5 02/16] powerpc: Override __ALIGN and __ALIGN_STR macros



Le 28/10/2022 à 16:33, Sathvika Vasireddy a écrit :
> In a subsequent patch, we would want to annotate powerpc assembly functions
> with SYM_FUNC_START_LOCAL macro. This macro depends on __ALIGN macro.
>
> The default expansion of __ALIGN macro is:
> #define __ALIGN .align 4,0x90
>
> So, override __ALIGN and __ALIGN_STR macros to use the same alignment as
> that of the existing _GLOBAL macro. Also, do not pad with 0x90, because
> repeated 0x90s are not a nop or trap on powerpc.

By the way, do we know what the instruction 0x90909090 is on powerpc ?
Is that something valid or not ?

>
> Tested-by: Naveen N. Rao <[email protected]>
> Reviewed-by: Naveen N. Rao <[email protected]>
> Reviewed-by: Christophe Leroy <[email protected]>
> Acked-by: Josh Poimboeuf <[email protected]>
> Signed-off-by: Sathvika Vasireddy <[email protected]>
> ---
> arch/powerpc/include/asm/linkage.h | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/arch/powerpc/include/asm/linkage.h b/arch/powerpc/include/asm/linkage.h
> index b71b9582e754..b88d1d2cf304 100644
> --- a/arch/powerpc/include/asm/linkage.h
> +++ b/arch/powerpc/include/asm/linkage.h
> @@ -4,6 +4,9 @@
>
> #include <asm/types.h>
>
> +#define __ALIGN .align 2
> +#define __ALIGN_STR ".align 2"
> +
> #ifdef CONFIG_PPC64_ELF_ABI_V1
> #define cond_syscall(x) \
> asm ("\t.weak " #x "\n\t.set " #x ", sys_ni_syscall\n" \

2022-11-02 13:39:29

by Christophe Leroy

[permalink] [raw]
Subject: Re: [PATCH v5 00/16] objtool: Enable and implement --mcount option on powerpc



Le 28/10/2022 à 16:33, Sathvika Vasireddy a écrit :
> This patchset enables and implements objtool --mcount
> option on powerpc. This applies atop powerpc/merge branch.
>
> Changelog:
>
> ----
> v5:
>
> * Patch 02/16 - Add Reviewed-by tag from Christophe Leroy
>
> * Patch 03/16 - Fix merge conflicts with latest powerpc/merge branch
>
> * Patch 06/16 - Files arch/powerpc/kernel/cpu_setup_fsl_booke.S and
> arch/powerpc/kernel/head_fsl_booke.S are not present
> today. Removed annotations in those assembly files.

Those files have not disappeared but have been renamed. The changes
should have followed automatically during a rebase. If not, please don't
miss them:

Commit 3e7318584dfe ("powerpc: Remove CONFIG_PPC_FSL_BOOK3E")
arch/powerpc/kernel/{cpu_setup_fsl_booke.S => cpu_setup_e500.S}

Commit dfc3095cec27 ("powerpc: Remove CONFIG_FSL_BOOKE")
arch/powerpc/kernel/{head_fsl_booke.S => head_85xx.S}


>
> * Patch 11/16 - Add Reviewed-by tag from Christophe Leroy
> - Changed scripts/Makefile.lib file to make
> CONFIG_HAVE_OBJTOOL_NOP_MCOUNT depend on
> CONFIG_FTRACE_MCOUNT_USE_OBJTOOL.
>
> * Patch 12/16 - Add Reviewed-by tag from Christophe Leroy
>
> * Patch 16/16 - Add Reviewed-by tag from Christophe Leroy
>
> * For this series - Add Acked-by tag from Josh Poimboeuf
> - Add Tested-by tag from Naveen N. Rao
> - Add Reviewed-by tag from Naveen N. Rao
> ----
> v4:
>
> * Patch 11/16 - Introduce a new config option
> CONFIG_HAVE_OBJTOOL_NOP_MCOUNT as a means for
> architectures to enable nop'ing ftrace locations.
>
> - Remove Acked-by tag from Peter Zijlstra (Intel),
> and Reviewed-by tag from Christophe Leroy.
> [This is done because I reworked the patch to add
> a new config option to objtool. Please let me know
> if you want me to retain the tags. Thanks!]
>
> * Patch 16/16 - Rework the patch to handle only 'bl' instruction
> decoding.
>
> ----
> v3:
>
> * Patch 01/16 - Rework patch subject.
> - Rework changelog.
> - Add Reviewed-by tag from Christophe Leroy.
>
> * Patch 02/16 - Rework changelog to update details based on feedback
> from Nicholas Piggin and Michael Ellerman.
> - Use quotes instead of __stringify macro, based on
> suggestion from Christophe Leroy.
>
> * Patch 03/16 - Add Reviewed-by tag from Christophe Leroy.
> - Based on Christophe's suggestion, keep all <linux/...>
> before <asm/...>.
> - Rework changelog.
>
> * Patch 04/16 - Add Reviewed-by tag from Christophe Leroy.
>
> * Patch 05/16 - Add Reviewed-by tag from Christophe Leroy.
>
> * Patch 06/16 - No change.
>
> * Patch 07/16 - Add Reviewed-by tag from Christophe Leroy.
>
> * Patch 08/16 - Add Acked-by tag from Peter Zijlstra.
>
> * Patch 09/16 - Add Acked-by tag from Peter Zijlstra.
>
> * Patch 10/16 - Reorder local variable declarations to use reverse
> xmas tree format.
> - Add Signed-off-by tag from Sathvika Vasireddy indicating
> changes done.
> - Add Acked-by tag from Peter Zijlstra.
>
> * Patch 11/16 - Update changelog to indicate that powerpc kernel does
> not support nop'ed out ftrace locations.
> - Add Acked-by tag from Peter Zijlstra.
> - Add Reviewed-by tag from Christophe Leroy.
>
> * Patch 12/16 - Per Christophe's comment, rework changelog.
>
> * Patch 13/16 - Add Acked-by tag from Peter Zijlstra.
> - Add Reviewed-by tag from Christophe Leroy.
>
> * Patch 14/16 - Simplify arch_ftrace_match() function, based on
> Christophe's suggestion.
> - Add Reviewed-by tag from Christophe Leroy.
>
> * Patch 15/16 - Include code from Christophe Leroy to use local vars for
> type and imm, and to adapt len for prefixed
> instructions.
>
> * Patch 16/16 - Based on suggestion from Christophe Leroy, setup
> immediate value calculation outside the check for
> specific instruction under case 18.
> - Set instruction type to INSN_CALL for 'bla'
> instruction as well.
>
> ----
> v2:
>
> * Change subject of patch 01/16
> * As suggested by Christophe Leroy, add barrier_before_unreachable()
> before __builtin_unreachable() to work around a gcc problem.
> * Fix issues reported by Kernel Test Robot.
> * Include suggestions from Christophe Leroy, and change commit
> messages for patches 01/16, 02/16, 03/16, 05/16.
>
> ----
>
> Christophe Leroy (4):
> objtool: Fix SEGFAULT
> objtool: Use target file endianness instead of a compiled constant
> objtool: Use target file class size instead of a compiled constant
> powerpc: Fix objtool unannotated intra-function call warnings on PPC32
>
> Sathvika Vasireddy (12):
> powerpc: Fix __WARN_FLAGS() for use with Objtool
> powerpc: Override __ALIGN and __ALIGN_STR macros
> powerpc: Fix objtool unannotated intra-function call warnings
> powerpc: Curb objtool unannotated intra-function warnings
> powerpc: Skip objtool from running on drivers/crypto/vmx/aesp8-ppc.o
> powerpc: Skip objtool from running on VDSO files
> objtool: Add --mnop as an option to --mcount
> objtool: Read special sections with alts only when specific options are selected
> objtool: Use macros to define arch specific reloc types
> objtool: Add arch specific function arch_ftrace_match()
> objtool/powerpc: Enable objtool to be built on ppc
> objtool/powerpc: Add --mcount specific implementation
>
> Makefile | 4 +-
> arch/powerpc/Kconfig | 2 +
> arch/powerpc/include/asm/asm.h | 7 ++
> arch/powerpc/include/asm/bug.h | 3 +-
> arch/powerpc/include/asm/linkage.h | 3 +
> arch/powerpc/kernel/cpu_setup_6xx.S | 26 +++--
> arch/powerpc/kernel/entry_32.S | 9 +-
> arch/powerpc/kernel/entry_64.S | 2 +
> arch/powerpc/kernel/exceptions-64s.S | 4 +-
> arch/powerpc/kernel/head_40x.S | 5 +-
> arch/powerpc/kernel/head_64.S | 7 +-
> arch/powerpc/kernel/head_8xx.S | 5 +-
> arch/powerpc/kernel/head_book3s_32.S | 29 +++--
> arch/powerpc/kernel/misc_64.S | 4 +-
> arch/powerpc/kernel/swsusp_32.S | 5 +-
> arch/powerpc/kernel/vdso/Makefile | 2 +
> arch/powerpc/kernel/vector.S | 4 +-
> arch/powerpc/kvm/book3s_hv_interrupts.S | 4 +-
> arch/powerpc/kvm/book3s_hv_rmhandlers.S | 25 +++--
> arch/powerpc/kvm/fpu.S | 17 ++-
> arch/powerpc/platforms/52xx/lite5200_sleep.S | 15 ++-
> arch/x86/Kconfig | 1 +
> drivers/crypto/vmx/Makefile | 2 +
> kernel/trace/Kconfig | 7 ++
> scripts/Makefile.lib | 3 +
> tools/objtool/arch/powerpc/Build | 2 +
> tools/objtool/arch/powerpc/decode.c | 101 ++++++++++++++++++
> .../arch/powerpc/include/arch/cfi_regs.h | 11 ++
> tools/objtool/arch/powerpc/include/arch/elf.h | 10 ++
> .../arch/powerpc/include/arch/special.h | 21 ++++
> tools/objtool/arch/powerpc/special.c | 19 ++++
> tools/objtool/arch/x86/decode.c | 5 +
> tools/objtool/arch/x86/include/arch/elf.h | 2 +
> .../arch/x86/include/arch/endianness.h | 9 --
> tools/objtool/builtin-check.c | 14 +++
> tools/objtool/check.c | 53 ++++-----
> tools/objtool/elf.c | 8 +-
> tools/objtool/include/objtool/arch.h | 2 +
> tools/objtool/include/objtool/builtin.h | 1 +
> tools/objtool/include/objtool/elf.h | 8 ++
> tools/objtool/include/objtool/endianness.h | 32 +++---
> tools/objtool/orc_dump.c | 11 +-
> tools/objtool/orc_gen.c | 4 +-
> tools/objtool/special.c | 3 +-
> 44 files changed, 408 insertions(+), 103 deletions(-)
> create mode 100644 arch/powerpc/include/asm/asm.h
> create mode 100644 tools/objtool/arch/powerpc/Build
> create mode 100644 tools/objtool/arch/powerpc/decode.c
> create mode 100644 tools/objtool/arch/powerpc/include/arch/cfi_regs.h
> create mode 100644 tools/objtool/arch/powerpc/include/arch/elf.h
> create mode 100644 tools/objtool/arch/powerpc/include/arch/special.h
> create mode 100644 tools/objtool/arch/powerpc/special.c
> delete mode 100644 tools/objtool/arch/x86/include/arch/endianness.h
>

2022-11-03 01:05:41

by Michael Ellerman

[permalink] [raw]
Subject: Re: [PATCH v5 02/16] powerpc: Override __ALIGN and __ALIGN_STR macros

Christophe Leroy <[email protected]> writes:
> Le 28/10/2022 à 16:33, Sathvika Vasireddy a écrit :
>> In a subsequent patch, we would want to annotate powerpc assembly functions
>> with SYM_FUNC_START_LOCAL macro. This macro depends on __ALIGN macro.
>>
>> The default expansion of __ALIGN macro is:
>> #define __ALIGN .align 4,0x90
>>
>> So, override __ALIGN and __ALIGN_STR macros to use the same alignment as
>> that of the existing _GLOBAL macro. Also, do not pad with 0x90, because
>> repeated 0x90s are not a nop or trap on powerpc.
>
> By the way, do we know what the instruction 0x90909090 is on powerpc ?
> Is that something valid or not ?

According to objdump it's:

stw r4,-28528(r16)

cheers

2022-11-03 08:56:55

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [PATCH v5 02/16] powerpc: Override __ALIGN and __ALIGN_STR macros

On Wed, Nov 02, 2022 at 12:35:07PM +0000, Christophe Leroy wrote:
>
>
> Le 28/10/2022 ? 16:33, Sathvika Vasireddy a ?crit?:
> > In a subsequent patch, we would want to annotate powerpc assembly functions
> > with SYM_FUNC_START_LOCAL macro. This macro depends on __ALIGN macro.
> >
> > The default expansion of __ALIGN macro is:
> > #define __ALIGN .align 4,0x90
> >
> > So, override __ALIGN and __ALIGN_STR macros to use the same alignment as
> > that of the existing _GLOBAL macro. Also, do not pad with 0x90, because
> > repeated 0x90s are not a nop or trap on powerpc.
>
> By the way, do we know what the instruction 0x90909090 is on powerpc ?
> Is that something valid or not ?

Please also look at the version that's in tip/x86/core (and next). This
stuff should be gone now.

include/linux/linkage.h now reads like:

#ifndef __ALIGN
#define __ALIGN .balign CONFIG_FUNCTION_ALIGNMENT
#define __ALIGN_STR __stringify(__ALIGN)
#endif

2022-11-14 04:33:23

by Sathvika Vasireddy

[permalink] [raw]
Subject: Re: [PATCH v5 02/16] powerpc: Override __ALIGN and __ALIGN_STR macros

Hi Peter,

On 03/11/22 14:18, Peter Zijlstra wrote:
> On Wed, Nov 02, 2022 at 12:35:07PM +0000, Christophe Leroy wrote:
>>
>> Le 28/10/2022 à 16:33, Sathvika Vasireddy a écrit :
>>> In a subsequent patch, we would want to annotate powerpc assembly functions
>>> with SYM_FUNC_START_LOCAL macro. This macro depends on __ALIGN macro.
>>>
>>> The default expansion of __ALIGN macro is:
>>> #define __ALIGN .align 4,0x90
>>>
>>> So, override __ALIGN and __ALIGN_STR macros to use the same alignment as
>>> that of the existing _GLOBAL macro. Also, do not pad with 0x90, because
>>> repeated 0x90s are not a nop or trap on powerpc.
>> By the way, do we know what the instruction 0x90909090 is on powerpc ?
>> Is that something valid or not ?
> Please also look at the version that's in tip/x86/core (and next). This
> stuff should be gone now.
>
> include/linux/linkage.h now reads like:
>
> #ifndef __ALIGN
> #define __ALIGN .balign CONFIG_FUNCTION_ALIGNMENT
> #define __ALIGN_STR __stringify(__ALIGN)
> #endif

Since the above mentioned changes are not a part of powerpc/merge branch
yet, I am retaining this patch for this merge cycle and will post a
cleanup patch (to move to using FUNCTION_ALIGNMENT_4B) after the next -rc1.

Thanks,
Sathvika