powerpc/objtool: First step towards uaccess validation (v1)
Subsystems (14)
cover powerpc/objtool: First step towards uaccess validation (v1)
This RFC is a first step towards the validation of userspace accesses.
For the time being it targets only PPC32 and includes hacks directly in core part of objtool.
It doesn't yet include handling of uaccess at all but is a first step to support objtool validation.
Assembly files have been kept aside as they require a huge work before being ready for objtool validation and are not directly relevant for uaccess validation.
Please have a look and hold hand if I'm going in the wrong direction.
For the few hacks done directly in the core part of objtool don't hesitate to suggest ways to make it more generic.
Christophe Leroy (3):
Revert "powerpc/bug: Provide better flexibility to
WARN_ON/__WARN_FLAGS() with asm goto"
powerpc: Mark all .S files invalid for objtool
powerpc: WIP draft support to objtool check
arch/powerpc/Kconfig | 1 + arch/powerpc/boot/Makefile | 17 +++++ arch/powerpc/crypto/Makefile | 13 ++++ arch/powerpc/include/asm/book3s/64/kup.h | 2 +- arch/powerpc/include/asm/bug.h | 67 +++---------------- arch/powerpc/include/asm/extable.h | 14 ---- arch/powerpc/include/asm/ppc_asm.h | 11 ++- arch/powerpc/kernel/Makefile | 44 ++++++++++++ arch/powerpc/kernel/misc_32.S | 2 +- arch/powerpc/kernel/trace/Makefile | 4 ++ arch/powerpc/kernel/traps.c | 9 +-- arch/powerpc/kernel/vdso/Makefile | 11 +++ arch/powerpc/kexec/Makefile | 2 + arch/powerpc/kvm/Makefile | 13 ++++ arch/powerpc/lib/Makefile | 25 +++++++ arch/powerpc/mm/book3s32/Makefile | 3 + arch/powerpc/mm/nohash/Makefile | 3 + arch/powerpc/perf/Makefile | 2 + arch/powerpc/platforms/44x/Makefile | 2 + arch/powerpc/platforms/52xx/Makefile | 3 + arch/powerpc/platforms/83xx/Makefile | 2 + arch/powerpc/platforms/cell/spufs/Makefile | 3 + arch/powerpc/platforms/pasemi/Makefile | 2 + arch/powerpc/platforms/powermac/Makefile | 3 + arch/powerpc/platforms/powernv/Makefile | 3 + arch/powerpc/platforms/ps3/Makefile | 2 + arch/powerpc/platforms/pseries/Makefile | 2 + arch/powerpc/purgatory/Makefile | 3 + arch/powerpc/sysdev/Makefile | 3 + arch/powerpc/xmon/Makefile | 3 + scripts/Makefile.lib | 2 +- tools/objtool/arch/powerpc/decode.c | 60 +++++++++++++++-- .../arch/powerpc/include/arch/special.h | 2 +- tools/objtool/arch/powerpc/special.c | 44 +++++++++++- tools/objtool/check.c | 29 ++++---- tools/objtool/include/objtool/elf.h | 1 + tools/objtool/include/objtool/special.h | 2 +- .../powerpc/primitives/asm/extable.h | 1 - 38 files changed, 311 insertions(+), 104 deletions(-) delete mode 120000 tools/testing/selftests/powerpc/primitives/asm/extable.h
Signature · 1 line
2.40.1
RFC PATCH 1/3 Revert "powerpc/bug: Provide better flexibility to WARN_ON/__WARN_FLAGS() with asm goto"
This reverts commit 1e688dd2a3d6759d416616ff07afc4bb836c4213.
That commit aimed at optimising the code around generation of WARN_ON/BUG_ON but this leads to a lot of dead code erroneously generated by GCC.
text data bss dec hex filename
9551585 3627834 224376 13403795 cc8693 vmlinux.before
9535281 3628358 224376 13388015 cc48ef vmlinux.after
Once this change is reverted, in a standard configuration (pmac32 + function tracer) the text is reduced by 16k which is around 1.7%
--- arch/powerpc/include/asm/book3s/64/kup.h | 2 +- arch/powerpc/include/asm/bug.h | 67 +++---------------- arch/powerpc/include/asm/extable.h | 14 ---- arch/powerpc/include/asm/ppc_asm.h | 11 ++- arch/powerpc/kernel/misc_32.S | 2 +- arch/powerpc/kernel/traps.c | 9 +-- .../powerpc/primitives/asm/extable.h | 1 - 7 files changed, 25 insertions(+), 81 deletions(-) delete mode 120000 tools/testing/selftests/powerpc/primitives/asm/extable.h
arch/powerpc/include/asm/book3s/64/kup.h +1 -1
@@ -90,7 +90,7 @@/* Prevent access to userspace using any key values */ LOAD_REG_IMMEDIATE(\gpr2, AMR_KUAP_BLOCKED) 999: tdne \gpr1, \gpr2 - EMIT_WARN_ENTRY 999b, __FILE__, __LINE__, (BUGFLAG_WARNING | BUGFLAG_ONCE) + EMIT_BUG_ENTRY 999b, __FILE__, __LINE__, (BUGFLAG_WARNING | BUGFLAG_ONCE) END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_BOOK3S_KUAP, 67) #endif .endm
arch/powerpc/include/asm/bug.h +11 -56
118 lines not on this page · raw message
arch/powerpc/include/asm/extable.h +0 -14
@@ -17,8 +17,6 @@#define ARCH_HAS_RELATIVE_EXTABLE -#ifndef __ASSEMBLY__ -struct exception_table_entry {int insn;int fixup;
@@ -30,15 +28,3 @@ static inline unsigned long extable_fixup(const struct exception_table_entry *x) }#endif - -/* -* Helper macro for exception table entries -*/ -#define EX_TABLE (_fault, _target) \ - stringify_in_c(.section __ex_table,"a";)\ - stringify_in_c(.balign 4;) \ - stringify_in_c(.long (_fault) - . ;) \ - stringify_in_c(.long (_target) - . ;) \ - stringify_in_c(.previous) - -#endif
arch/powerpc/include/asm/ppc_asm.h +10 -1
@@ -10,7 +10,6 @@#include <asm/ppc-opcode.h> #include <asm/firmware.h> #include <asm/feature-fixups.h> -#include <asm/extable.h> #ifdef __ASSEMBLY__
@@ -836,6 +835,16 @@ END_FTR_SECTION_NESTED(CPU_FTR_CELL_TB_BUG, CPU_FTR_CELL_TB_BUG, 96)#endif /* __ASSEMBLY__ */ +/* +* Helper macro for exception table entries +*/ +#define EX_TABLE (_fault, _target) \ + stringify_in_c(.section __ex_table,"a";)\ + stringify_in_c(.balign 4;) \ + stringify_in_c(.long (_fault) - . ;) \ + stringify_in_c(.long (_target) - . ;) \ + stringify_in_c(.previous) +#define SOFT_MASK_TABLE (_start, _end) \ stringify_in_c(.section __soft_mask_table,"a";)\ stringify_in_c(.balign 8;) \
arch/powerpc/kernel/misc_32.S +1 -1
@@ -237,7 +237,7 @@ _GLOBAL(copy_page) addi r3,r3,-4 0: twnei r5, 0 /* WARN if r3 is not cache aligned */ - EMIT_WARN_ENTRY 0b,__FILE__,__LINE__, BUGFLAG_WARNING + EMIT_BUG_ENTRY 0b,__FILE__,__LINE__, BUGFLAG_WARNING addi r4,r4,-4
arch/powerpc/kernel/traps.c +2 -7
@@ -1508,13 +1508,8 @@ static void do_program_check(struct pt_regs *regs)if (!(regs->msr &MSR_PR ) &&/* not user-mode */ report_bug (bugaddr, regs) ==BUG_TRAP_TYPE_WARN ) { -const struct exception_table_entry *entry; - - entry =search_exception_tables (bugaddr); -if (entry) { -regs_set_return_ip (regs,extable_fixup (entry) + regs->nip - bugaddr); -return ; - } +regs_add_return_ip (regs,4 ); +return ; }_exception (SIGTRAP , regs,TRAP_BRKPT , regs->nip);return ;
tools/testing/selftests/powerpc/primitives/asm/extable.h deleted +0 -1
@@ -1 +0,0 @@ -../../../../../../arch/powerpc/include/asm/extable.h
Signature · 1 line
2.40.1
Re: [RFC PATCH v1 1/3] Revert "powerpc/bug: Provide better flexibility to WARN_ON/__WARN_FLAGS() with asm goto"
Quoted 6 lines · Christophe Leroy
This reverts commit
1e688dd2a3d6759d416616ff07afc4bb836c4213.That commit aimed at optimising the code around generation of WARN_ON/BUG_ON but this leads to a lot of dead code erroneously generated by GCC.
Quoted 6 lines
text data bss dec hex filename
9551585 3627834 224376 13403795 cc8693 vmlinux.before
9535281 3628358 224376 13388015 cc48ef vmlinux.afterOnce this change is reverted, in a standard configuration (pmac32 + function tracer) the text is reduced by 16k which is around 1.7%
Aneesh recently reported a build failure due to the use of 'asm goto' in WARN_ON(). We were able to root-cause it to the use of 'asm goto' with two config options: CONFIG_CC_OPTIMIZE_FOR_SIZE and CONFIG_DEBUG_SECTION_MISMATCH.
Along with the issues we found with 'asm goto' during objtool enablement, I think it might be better to disable it for now.
- Naveen
Peter Zijlstra
maintainerRe: [RFC PATCH v1 1/3] Revert "powerpc/bug: Provide better flexibility to WARN_ON/__WARN_FLAGS() with asm goto"
Quoted 11 lines · Naveen N Rao
Quoted 10 lines · Christophe Leroy
This reverts commit
1e688dd2a3d6759d416616ff07afc4bb836c4213.That commit aimed at optimising the code around generation of WARN_ON/BUG_ON but this leads to a lot of dead code erroneously generated by GCC.
text data bss dec hex filename
9551585 3627834 224376 13403795 cc8693 vmlinux.before
9535281 3628358 224376 13388015 cc48ef vmlinux.after
Quoted 7 lines
Quoted 2 lines
Once this change is reverted, in a standard configuration (pmac32 + function tracer) the text is reduced by 16k which is around 1.7%
Aneesh recently reported a build failure due to the use of 'asm goto' in
WARN_ON(). We were able to root-cause it to the use of 'asm goto' with two config options:CONFIG_CC_OPTIMIZE_FOR_SIZEandCONFIG_DEBUG_SECTION_MISMATCH.
FWIW;
I recently had clang-powerpc report a very dodgy build error that was due to a combination of these asm-goto and the usage of __cleanup__. For some reason the label of the asm-goto crossed over the __cleanup__ variable declaration -- which is not valid, but also was completely insane for that's not what the code called for.
https://lkml.kernel.org/r/[email protected]
But in my book that's a compiler issue, not a kernel issue and I'd be hesitant to pull the asm-goto use just for that.
RFC PATCH 2/3 powerpc: Mark all .S files invalid for objtool
In reply to Christophe LeroyA lot of work is required in .S files in order to get them ready for objtool checks.
For the time being, exclude them from the checks.
This is done with the script below:
#!/bin/sh
DIRS=find arch/powerpc -name "*.S" -exec dirname {} \; | sort | uniq for d in $DIRS
do
pushd $d
echo >> Makefile
for f in *.S
do
echo "OBJECT_FILES_NON_STANDARD_$f := y" | sed s/"\.S"/".o"/g
done >> Makefile
popd
done
--- arch/powerpc/boot/Makefile | 17 +++++++++ arch/powerpc/crypto/Makefile | 13 +++++++ arch/powerpc/kernel/Makefile | 44 ++++++++++++++++++++++ arch/powerpc/kernel/trace/Makefile | 4 ++ arch/powerpc/kernel/vdso/Makefile | 11 ++++++ arch/powerpc/kexec/Makefile | 2 + arch/powerpc/kvm/Makefile | 13 +++++++ arch/powerpc/lib/Makefile | 25 ++++++++++++ arch/powerpc/mm/book3s32/Makefile | 3 ++ arch/powerpc/mm/nohash/Makefile | 3 ++ arch/powerpc/perf/Makefile | 2 + arch/powerpc/platforms/44x/Makefile | 2 + arch/powerpc/platforms/52xx/Makefile | 3 ++ arch/powerpc/platforms/83xx/Makefile | 2 + arch/powerpc/platforms/cell/spufs/Makefile | 3 ++ arch/powerpc/platforms/pasemi/Makefile | 2 + arch/powerpc/platforms/powermac/Makefile | 3 ++ arch/powerpc/platforms/powernv/Makefile | 3 ++ arch/powerpc/platforms/ps3/Makefile | 2 + arch/powerpc/platforms/pseries/Makefile | 2 + arch/powerpc/purgatory/Makefile | 3 ++ arch/powerpc/sysdev/Makefile | 3 ++ arch/powerpc/xmon/Makefile | 3 ++ 23 files changed, 168 insertions(+)
arch/powerpc/boot/Makefile +17 -0
@@ -513,3 +513,20 @@ $(wrapper-installed): $(DESTDIR)$(WRAPPER_BINDIR) $(srctree)/$(obj)/wrapper | $( $(call cmd,install_wrapper) $(obj)/bootwrapper_install: $(all-installed) + +OBJECT_FILES_NON_STANDARD_crt0.o := y +OBJECT_FILES_NON_STANDARD_crtsavres.o := y +OBJECT_FILES_NON_STANDARD_div64.o := y +OBJECT_FILES_NON_STANDARD_fixed-head.o := y +OBJECT_FILES_NON_STANDARD_gamecube-head.o := y +OBJECT_FILES_NON_STANDARD_motload-head.o := y +OBJECT_FILES_NON_STANDARD_opal-calls.o := y +OBJECT_FILES_NON_STANDARD_ps3-head.o := y +OBJECT_FILES_NON_STANDARD_ps3-hvcall.o := y +OBJECT_FILES_NON_STANDARD_pseries-head.o := y +OBJECT_FILES_NON_STANDARD_string.o := y +OBJECT_FILES_NON_STANDARD_util.o := y +OBJECT_FILES_NON_STANDARD_wii-head.o := y +OBJECT_FILES_NON_STANDARD_zImage.coff.lds.o := y +OBJECT_FILES_NON_STANDARD_zImage.lds.o := y +OBJECT_FILES_NON_STANDARD_zImage.ps3.lds.o := y
arch/powerpc/crypto/Makefile +13 -0
@@ -34,3 +34,16 @@ $(obj)/aesp10-ppc.S $(obj)/ghashp10-ppc.S: $(obj)/%.S: $(src)/%.pl FORCE OBJECT_FILES_NON_STANDARD_aesp10-ppc.o := y OBJECT_FILES_NON_STANDARD_ghashp10-ppc.o := y + +OBJECT_FILES_NON_STANDARD_aes-gcm-p10.o := y +OBJECT_FILES_NON_STANDARD_aes-spe-core.o := y +OBJECT_FILES_NON_STANDARD_aes-spe-keys.o := y +OBJECT_FILES_NON_STANDARD_aes-spe-modes.o := y +OBJECT_FILES_NON_STANDARD_aes-tab-4k.o := y +OBJECT_FILES_NON_STANDARD_crc32c-vpmsum_asm.o := y +OBJECT_FILES_NON_STANDARD_crc32-vpmsum_core.o := y +OBJECT_FILES_NON_STANDARD_crct10dif-vpmsum_asm.o := y +OBJECT_FILES_NON_STANDARD_md5-asm.o := y +OBJECT_FILES_NON_STANDARD_sha1-powerpc-asm.o := y +OBJECT_FILES_NON_STANDARD_sha1-spe-asm.o := y +OBJECT_FILES_NON_STANDARD_sha256-spe-asm.o := y
arch/powerpc/kernel/Makefile +44 -0
47 lines not on this page · raw message
arch/powerpc/kernel/trace/Makefile +4 -0
@@ -25,3 +25,7 @@ GCOV_PROFILE_ftrace.o := n KCOV_INSTRUMENT_ftrace.o := n KCSAN_SANITIZE_ftrace.o := n UBSAN_SANITIZE_ftrace.o := n + +OBJECT_FILES_NON_STANDARD_ftrace_64_pg.o := y +OBJECT_FILES_NON_STANDARD_ftrace_low.o := y +OBJECT_FILES_NON_STANDARD_ftrace_mprofile.o := y
arch/powerpc/kernel/vdso/Makefile +11 -0
@@ -114,3 +114,14 @@ quiet_cmd_vdso64as = VDSO64A $@ cmd_vdso64as = $(VDSOCC) $(a_flags) $(AS64FLAGS) -c -o $@ $< OBJECT_FILES_NON_STANDARD := y + +OBJECT_FILES_NON_STANDARD_cacheflush.o := y +OBJECT_FILES_NON_STANDARD_datapage.o := y +OBJECT_FILES_NON_STANDARD_getcpu.o := y +OBJECT_FILES_NON_STANDARD_gettimeofday.o := y +OBJECT_FILES_NON_STANDARD_note.o := y +OBJECT_FILES_NON_STANDARD_sigtramp32.o := y +OBJECT_FILES_NON_STANDARD_sigtramp64.o := y +OBJECT_FILES_NON_STANDARD_vdso32.lds.o := y +OBJECT_FILES_NON_STANDARD_vdso64.lds.o := y +OBJECT_FILES_NON_STANDARD_vgetrandom-chacha.o := y
arch/powerpc/kexec/Makefile +2 -0
@@ -15,3 +15,5 @@ KCOV_INSTRUMENT_core_$(BITS).o := n UBSAN_SANITIZE_core_$(BITS).o := n KASAN_SANITIZE_core.o := n KASAN_SANITIZE_core_$(BITS) := n + +OBJECT_FILES_NON_STANDARD_relocate_32.o := y
arch/powerpc/kvm/Makefile +13 -0
@@ -137,3 +137,16 @@ obj-y += $(kvm-book3s_64-builtin-objs-y) ifdef CONFIG_PPC_BOOK3S_64 KASAN_SANITIZE := n endif + +OBJECT_FILES_NON_STANDARD_book3s_32_sr.o := y +OBJECT_FILES_NON_STANDARD_book3s_64_entry.o := y +OBJECT_FILES_NON_STANDARD_book3s_64_slb.o := y +OBJECT_FILES_NON_STANDARD_book3s_hv_interrupts.o := y +OBJECT_FILES_NON_STANDARD_book3s_hv_rmhandlers.o := y +OBJECT_FILES_NON_STANDARD_book3s_interrupts.o := y +OBJECT_FILES_NON_STANDARD_book3s_rmhandlers.o := y +OBJECT_FILES_NON_STANDARD_book3s_segment.o := y +OBJECT_FILES_NON_STANDARD_bookehv_interrupts.o := y +OBJECT_FILES_NON_STANDARD_booke_interrupts.o := y +OBJECT_FILES_NON_STANDARD_fpu.o := y +OBJECT_FILES_NON_STANDARD_tm.o := y
arch/powerpc/lib/Makefile +25 -0
@@ -81,3 +81,28 @@ CFLAGS_xor_vmx.o += -maltivec $(call cc-option,-mabi=altivec) CFLAGS_xor_vmx.o += -isystem $(shell $(CC) -print-file-name=include) obj-$(CONFIG_PPC64) += $(obj64-y) + +OBJECT_FILES_NON_STANDARD_checksum_32.o := y +OBJECT_FILES_NON_STANDARD_checksum_64.o := y +OBJECT_FILES_NON_STANDARD_copy_32.o := y +OBJECT_FILES_NON_STANDARD_copy_mc_64.o := y +OBJECT_FILES_NON_STANDARD_copypage_64.o := y +OBJECT_FILES_NON_STANDARD_copypage_power7.o := y +OBJECT_FILES_NON_STANDARD_copyuser_64.o := y +OBJECT_FILES_NON_STANDARD_copyuser_power7.o := y +OBJECT_FILES_NON_STANDARD_crtsavres.o := y +OBJECT_FILES_NON_STANDARD_div64.o := y +OBJECT_FILES_NON_STANDARD_feature-fixups-test.o := y +OBJECT_FILES_NON_STANDARD_hweight_64.o := y +OBJECT_FILES_NON_STANDARD_ldstfp.o := y +OBJECT_FILES_NON_STANDARD_mem_64.o := y +OBJECT_FILES_NON_STANDARD_memcmp_32.o := y +OBJECT_FILES_NON_STANDARD_memcmp_64.o := y +OBJECT_FILES_NON_STANDARD_memcpy_64.o := y +OBJECT_FILES_NON_STANDARD_memcpy_power7.o := y +OBJECT_FILES_NON_STANDARD_quad.o := y +OBJECT_FILES_NON_STANDARD_string_32.o := y +OBJECT_FILES_NON_STANDARD_string_64.o := y +OBJECT_FILES_NON_STANDARD_string.o := y +OBJECT_FILES_NON_STANDARD_strlen_32.o := y +OBJECT_FILES_NON_STANDARD_test_emulate_step_exec_instr.o := y
arch/powerpc/mm/book3s32/Makefile +3 -0
@@ -10,3 +10,6 @@ obj-y += mmu.o mmu_context.o obj-$(CONFIG_PPC_BOOK3S_603) += nohash_low.o obj-$(CONFIG_PPC_BOOK3S_604) += hash_low.o tlb.o obj-$(CONFIG_PPC_KUAP) += kuap.o + +OBJECT_FILES_NON_STANDARD_hash_low.o := y +OBJECT_FILES_NON_STANDARD_nohash_low.o := y
arch/powerpc/mm/nohash/Makefile +3 -0
@@ -17,3 +17,6 @@ endif # This is necessary for booting with kcov enabled on book3e machines KCOV_INSTRUMENT_tlb.o := n KCOV_INSTRUMENT_e500.o := n + +OBJECT_FILES_NON_STANDARD_tlb_low_64e.o := y +OBJECT_FILES_NON_STANDARD_tlb_low.o := y
arch/powerpc/perf/Makefile +2 -0
@@ -20,3 +20,5 @@ obj-$(CONFIG_PPC_8xx) += 8xx-pmu.o obj-$(CONFIG_PPC64) += $(obj64-y) obj-$(CONFIG_PPC32) += $(obj32-y) + +OBJECT_FILES_NON_STANDARD_bhrb.o := y
arch/powerpc/platforms/44x/Makefile +2 -0
@@ -12,3 +12,5 @@ obj-$(CONFIG_CANYONLANDS)+= canyonlands.o obj-$(CONFIG_CURRITUCK) += ppc476.o obj-$(CONFIG_AKEBONO) += ppc476.o obj-$(CONFIG_FSP2) += fsp2.o + +OBJECT_FILES_NON_STANDARD_misc_44x.o := y
arch/powerpc/platforms/52xx/Makefile +3 -0
@@ -14,3 +14,6 @@ obj-$(CONFIG_PM) += mpc52xx_sleep.o mpc52xx_pm.o ifdef CONFIG_PPC_LITE5200 obj-$(CONFIG_PM) += lite5200_sleep.o lite5200_pm.o endif + +OBJECT_FILES_NON_STANDARD_lite5200_sleep.o := y +OBJECT_FILES_NON_STANDARD_mpc52xx_sleep.o := y
arch/powerpc/platforms/83xx/Makefile +2 -0
@@ -13,3 +13,5 @@ obj-$(CONFIG_MPC836x_RDK) += mpc836x_rdk.o obj-$(CONFIG_MPC837x_RDB) += mpc837x_rdb.o obj-$(CONFIG_ASP834x) += asp834x.o obj-$(CONFIG_KMETER1) += km83xx.o + +OBJECT_FILES_NON_STANDARD_suspend-asm.o := y
arch/powerpc/platforms/cell/spufs/Makefile +3 -0
@@ -61,3 +61,6 @@ cmd_hexdump = ( \ quiet_cmd_hexdump = HEXDUMP $@ $(obj)/%_dump.h: $(obj)/%.bin $(call if_changed,hexdump) + +OBJECT_FILES_NON_STANDARD_spu_restore_crt0.o := y +OBJECT_FILES_NON_STANDARD_spu_save_crt0.o := y
arch/powerpc/platforms/pasemi/Makefile +2 -0
@@ -2,3 +2,5 @@ obj-y += setup.o pci.o time.o idle.o powersave.o iommu.o dma_lib.o misc.o obj-$(CONFIG_PPC_PASEMI_MDIO) += gpio_mdio.o obj-$(CONFIG_PCI_MSI) += msi.o + +OBJECT_FILES_NON_STANDARD_powersave.o := y
arch/powerpc/platforms/powermac/Makefile +3 -0
@@ -23,3 +23,6 @@ obj-$(CONFIG_PMAC_BACKLIGHT) += backlight.o obj-$(CONFIG_NVRAM:m=y) += nvram.o obj-$(CONFIG_PPC32) += bootx_init.o obj-$(CONFIG_SMP) += smp.o + +OBJECT_FILES_NON_STANDARD_cache.o := y +OBJECT_FILES_NON_STANDARD_sleep.o := y
arch/powerpc/platforms/powernv/Makefile +3 -0
@@ -31,3 +31,6 @@ obj-$(CONFIG_PPC_VAS) += vas.o vas-window.o vas-debug.o vas-fault.o obj-$(CONFIG_OCXL_BASE) += ocxl.o obj-$(CONFIG_SCOM_DEBUGFS) += opal-xscom.o obj-$(CONFIG_PPC_SECURE_BOOT) += opal-secvar.o + +OBJECT_FILES_NON_STANDARD_opal-wrappers.o := y +OBJECT_FILES_NON_STANDARD_subcore-asm.o := y
arch/powerpc/platforms/ps3/Makefile +2 -0
@@ -7,3 +7,5 @@ obj-$(CONFIG_PS3GELIC_UDBG) += gelic_udbg.o obj-$(CONFIG_SMP) += smp.o obj-$(CONFIG_SPU_BASE) += spu.o obj-y += device-init.o + +OBJECT_FILES_NON_STANDARD_hvcall.o := y
arch/powerpc/platforms/pseries/Makefile +2 -0
@@ -37,3 +37,5 @@ obj-$(CONFIG_ARCH_HAS_CC_PLATFORM) += cc_platform.o # nothing that operates in real mode is safe for KASAN KASAN_SANITIZE_ras.o := n KASAN_SANITIZE_kexec.o := n + +OBJECT_FILES_NON_STANDARD_hvCall.o := y
arch/powerpc/purgatory/Makefile +3 -0
@@ -13,3 +13,6 @@ $(obj)/purgatory.ro: $(obj)/trampoline_$(BITS).o FORCE $(obj)/kexec-purgatory.o: $(obj)/purgatory.ro obj-y += kexec-purgatory.o + +OBJECT_FILES_NON_STANDARD_kexec-purgatory.o := y +OBJECT_FILES_NON_STANDARD_trampoline_64.o := y
arch/powerpc/sysdev/Makefile +3 -0
@@ -51,3 +51,6 @@ obj-$(CONFIG_PPC_XICS) += xics/ obj-$(CONFIG_PPC_XIVE) += xive/ obj-$(CONFIG_GE_FPGA) += ge/ + +OBJECT_FILES_NON_STANDARD_6xx-suspend.o := y +OBJECT_FILES_NON_STANDARD_dcr-low.o := y
arch/powerpc/xmon/Makefile +3 -0
@@ -24,3 +24,6 @@ ifdef CONFIG_XMON_DISASSEMBLY obj-y += ppc-dis.o ppc-opc.o obj-$(CONFIG_SPU_BASE) += spu-dis.o spu-opc.o endif + +OBJECT_FILES_NON_STANDARD_spr_access.o := y +OBJECT_FILES_NON_STANDARD_xmon_bpts.o := y
Signature · 1 line
2.40.1
Re: [RFC PATCH v1 2/3] powerpc: Mark all .S files invalid for objtool
Quoted 38 lines · Christophe Leroy
A lot of work is required in .S files in order to get them ready for objtool checks.
For the time being, exclude them from the checks.
This is done with the script below:
#!/bin/sh
DIRS=find arch/powerpc -name "*.S" -exec dirname {} \; | sort | uniqfor d in $DIRS
do
pushd $d
echo >>Makefile
for f in *.S
do
echo "OBJECT_FILES_NON_STANDARD_$f := y" | sed s/"\.S"/".o"/g
done >>Makefile
popd
doneSigned-off-by Christophe Leroy <[email protected]>--- arch/powerpc/boot/Makefile | 17 +++++++++ arch/powerpc/crypto/Makefile | 13 +++++++ arch/powerpc/kernel/Makefile | 44 ++++++++++++++++++++++ arch/powerpc/kernel/trace/Makefile | 4 ++ arch/powerpc/kernel/vdso/Makefile | 11 ++++++ arch/powerpc/kexec/Makefile | 2 + arch/powerpc/kvm/Makefile | 13 +++++++ arch/powerpc/lib/Makefile | 25 ++++++++++++ arch/powerpc/mm/book3s32/Makefile | 3 ++ arch/powerpc/mm/nohash/Makefile | 3 ++ arch/powerpc/perf/Makefile | 2 + arch/powerpc/platforms/44x/Makefile | 2 + arch/powerpc/platforms/52xx/Makefile | 3 ++ arch/powerpc/platforms/83xx/Makefile | 2 + arch/powerpc/platforms/cell/spufs/Makefile | 3 ++ arch/powerpc/platforms/pasemi/Makefile | 2 +
Quoted 9 lines
arch/powerpc/platforms/powermac/Makefile | 3 ++ arch/powerpc/platforms/powernv/Makefile | 3 ++ arch/powerpc/platforms/ps3/Makefile | 2 + arch/powerpc/platforms/pseries/Makefile | 2 + arch/powerpc/purgatory/Makefile | 3 ++ arch/powerpc/sysdev/Makefile | 3 ++ arch/powerpc/xmon/Makefile | 3 ++ 23 files changed, 168 insertions(+)
I think it might be better to have a config option so that architectures can opt-in to skip objtool on asm files. We can then do:
scripts/Makefile.build +0 -0
@@ -359,7 +359,11 @@ $(obj)/%.s: $(src)/%.S FORCE $(call if_changed_dep,cpp_s_S)
quiet_cmd_as_o_S = AS $(quiet_modtag) $@
+ifndef CONFIG_ARCH_OBJTOOL_SKIP_ASM
cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< $(cmd_objtool)
+else
+ cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
+endif
ifdef CONFIG_ASM_MODVERSIONS
- Naveen
Re: [RFC PATCH v1 2/3] powerpc: Mark all .S files invalid for objtool
Le 20/06/2023 à 08:04, Naveen N Rao a écrit :
Quoted 50 lines
Quoted 46 lines · Christophe Leroy
A lot of work is required in .S files in order to get them ready for objtool checks.
For the time being, exclude them from the checks.
This is done with the script below:
#!/bin/sh
DIRS=find arch/powerpc -name "*.S" -exec dirname {} \; | sort | uniq
for d in $DIRS
do
pushd $d
echo >>Makefile
for f in *.S
do
echo "OBJECT_FILES_NON_STANDARD_$f := y" | sed s/"\.S"/".o"/g done >>Makefile
popd
doneSigned-off-by Christophe Leroy <[email protected]>---
arch/powerpc/boot/Makefile | 17 +++++++++ arch/powerpc/crypto/Makefile | 13 +++++++ arch/powerpc/kernel/Makefile | 44 ++++++++++++++++++++++ arch/powerpc/kernel/trace/Makefile | 4 ++ arch/powerpc/kernel/vdso/Makefile | 11 ++++++ arch/powerpc/kexec/Makefile | 2 + arch/powerpc/kvm/Makefile | 13 +++++++ arch/powerpc/lib/Makefile | 25 ++++++++++++ arch/powerpc/mm/book3s32/Makefile | 3 ++ arch/powerpc/mm/nohash/Makefile | 3 ++ arch/powerpc/perf/Makefile | 2 + arch/powerpc/platforms/44x/Makefile | 2 + arch/powerpc/platforms/52xx/Makefile | 3 ++ arch/powerpc/platforms/83xx/Makefile | 2 +arch/powerpc/platforms/cell/spufs/Makefile| 3 ++ arch/powerpc/platforms/pasemi/Makefile | 2 + arch/powerpc/platforms/powermac/Makefile | 3 ++ arch/powerpc/platforms/powernv/Makefile | 3 ++ arch/powerpc/platforms/ps3/Makefile | 2 + arch/powerpc/platforms/pseries/Makefile | 2 + arch/powerpc/purgatory/Makefile | 3 ++ arch/powerpc/sysdev/Makefile | 3 ++ arch/powerpc/xmon/Makefile | 3 ++Quoted 2 lines
23 files changed, 168 insertions(+)
Quoted 2 lines
I think it might be better to have a config option so that architectures can opt-in to skip objtool on asm files. We can then do:
Well, the idea here was to initially opt out every file in order to quickly add support for objtool uaccess checking, and then opt-in back files one by one once they are ready for it.
In most files,all we have to do is to replace all _GLOBAL() by SYM_FUNC_START(), add a SYM_FUNC_END() at the end of the function, then do the same with SYM_FUNC_START_LOCAL() with all non global functions.
That's easy to do and worth it but it takes time, hence the idea of an incremental approach.
Christophe
Re: [RFC PATCH v1 2/3] powerpc: Mark all .S files invalid for objtool
Quoted 52 lines · Christophe Leroy
Le 20/06/2023 à 08:04, Naveen N Rao a écrit :
Quoted 49 lines
Quoted 47 lines · Christophe Leroy
A lot of work is required in .S files in order to get them ready for objtool checks.
For the time being, exclude them from the checks.
This is done with the script below:
#!/bin/sh
DIRS=find arch/powerpc -name "*.S" -exec dirname {} \; | sort | uniqfor d in $DIRS
do
pushd $d
echo >>Makefile
for f in *.S
do
echo "OBJECT_FILES_NON_STANDARD_$f := y" | sed s/"\.S"/".o"/g done >>Makefile
popd
doneSigned-off-by Christophe Leroy <[email protected]>---
arch/powerpc/boot/Makefile | 17 +++++++++ arch/powerpc/crypto/Makefile | 13 +++++++ arch/powerpc/kernel/Makefile | 44 ++++++++++++++++++++++ arch/powerpc/kernel/trace/Makefile | 4 ++ arch/powerpc/kernel/vdso/Makefile | 11 ++++++ arch/powerpc/kexec/Makefile | 2 + arch/powerpc/kvm/Makefile | 13 +++++++ arch/powerpc/lib/Makefile | 25 ++++++++++++ arch/powerpc/mm/book3s32/Makefile | 3 ++ arch/powerpc/mm/nohash/Makefile | 3 ++ arch/powerpc/perf/Makefile | 2 + arch/powerpc/platforms/44x/Makefile | 2 + arch/powerpc/platforms/52xx/Makefile | 3 ++ arch/powerpc/platforms/83xx/Makefile | 2 +arch/powerpc/platforms/cell/spufs/Makefile| 3 ++ arch/powerpc/platforms/pasemi/Makefile | 2 + arch/powerpc/platforms/powermac/Makefile | 3 ++ arch/powerpc/platforms/powernv/Makefile | 3 ++ arch/powerpc/platforms/ps3/Makefile | 2 + arch/powerpc/platforms/pseries/Makefile | 2 + arch/powerpc/purgatory/Makefile | 3 ++ arch/powerpc/sysdev/Makefile | 3 ++ arch/powerpc/xmon/Makefile | 3 ++23 files changed, 168 insertions(+)
Quoted 3 lines
Quoted 1 line
I think it might be better to have a config option so that architectures can opt-in to skip objtool on asm files. We can then do:
Well, the idea here was to initially opt out every file in order to quickly add support for objtool uaccess checking, and then opt-in back files one by one once they are ready for it.
That was my initial thought too.
Quoted 4 lines
In most files,all we have to do is to replace all
_GLOBAL()bySYM_FUNC_START(), add aSYM_FUNC_END()at the end of the function, then do the same withSYM_FUNC_START_LOCAL()with all non global functions.That's easy to do and worth it but it takes time, hence the idea of an incremental approach.
Right. But until that's done, I am not sure it is worth the churn to the Makefiles.
Besides, it isn't clear to me that the existing features we are targeting for objtool on powerpc need objtool to run on asm files (so, an incremental approach may not really get us much). Objtool --mcount doesn't care about .S files. I suppose uaccess validation also doesn't need it. It's likely just stack validation (should we choose to enable it) that needs objtool to be run on asm files.
The first patch series converting much of our .S files can drop the config option and exclude the remaining files.
- Naveen
RFC PATCH 3/3 powerpc: WIP draft support to objtool check
In reply to Christophe LeroyThis draft messy patch is first try to add support of objtool check for powerpc. This is in preparation of doing uaccess validation for powerpc.
For the time being, this is implemented for PPC32 only breaking support for other targets eventually. Will be reworked to be more generic once a final working status has been achieved.
All assembly files have been deactivated as they require huge work and are not really needed at the first place for uaccess validation.
--- arch/powerpc/Kconfig | 1 + scripts/Makefile.lib | 2 +- tools/objtool/arch/powerpc/decode.c | 60 +++++++++++++++++-- .../arch/powerpc/include/arch/special.h | 2 +- tools/objtool/arch/powerpc/special.c | 44 +++++++++++++- tools/objtool/check.c | 29 +++++---- tools/objtool/include/objtool/elf.h | 1 + tools/objtool/include/objtool/special.h | 2 +- 8 files changed, 118 insertions(+), 23 deletions(-)
arch/powerpc/Kconfig +1 -0
@@ -259,6 +259,7 @@ config PPC select HAVE_OPTPROBES select HAVE_OBJTOOL if PPC32 || MPROFILE_KERNEL select HAVE_OBJTOOL_MCOUNT if HAVE_OBJTOOL + select HAVE_UACCESS_VALIDATION if HAVE_OBJTOOL select HAVE_PERF_EVENTS select HAVE_PERF_EVENTS_NMI if PPC64 select HAVE_PERF_REGS
scripts/Makefile.lib +1 -1
@@ -267,7 +267,7 @@ objtool-args-$(CONFIG_RETHUNK) += --rethunk objtool-args-$(CONFIG_SLS) += --sls objtool-args-$(CONFIG_STACK_VALIDATION) += --stackval objtool-args-$(CONFIG_HAVE_STATIC_CALL_INLINE) += --static-call -objtool-args-$(CONFIG_HAVE_UACCESS_VALIDATION) += --uaccess +objtool-args-$(CONFIG_HAVE_UACCESS_VALIDATION) += --uaccess --sec-address objtool-args-$(CONFIG_GCOV_KERNEL) += --no-unreachable objtool-args-$(CONFIG_PREFIX_SYMBOLS) += --prefix=$(CONFIG_FUNCTION_PADDING_BYTES)
tools/objtool/arch/powerpc/decode.c +55 -5
92 lines not on this page · raw message
tools/objtool/arch/powerpc/include/arch/special.h +1 -1
@@ -6,7 +6,7 @@#define EX_ORIG_OFFSET 0#define EX_NEW_OFFSET 4 -#define JUMP_ENTRY_SIZE 16 +#define JUMP_ENTRY_SIZE 12#define JUMP_ORIG_OFFSET 0#define JUMP_NEW_OFFSET 4#define JUMP_KEY_OFFSET 8
tools/objtool/arch/powerpc/special.c +42 -2
49 lines not on this page · raw message
tools/objtool/check.c +16 -13
@@ -236,6 +236,7 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,"x86_64_start_reservations" ,"xen_cpu_bringup_again" ,"xen_start_kernel" , + "longjmp", };if (!func)
@@ -2060,13 +2061,12 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn,* instruction. */ list_for_each_entry_from (reloc, &table->sec->reloc_list, list) { -/* Check for the end of the table: */ if (reloc != table && reloc->jump_table_start)break ;/* Make sure the table entries are consecutive: */ -if (prev_offset && reloc->offset != prev_offset +8 ) +if (prev_offset && reloc->offset != prev_offset +4 )break ;/* Detect function pointers from contiguous objects: */
@@ -2074,7 +2074,10 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn, reloc->addend == pfunc->offset)break ; - dest_insn =find_insn (file, reloc->sym->sec, reloc->addend); +if (table->jump_table_is_rel) + dest_insn =find_insn (file, reloc->sym->sec, reloc->addend + table->offset - reloc->offset); +else + dest_insn =find_insn (file, reloc->sym->sec, reloc->addend);if (!dest_insn)break ;
@@ -2108,7 +2111,7 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn,*/ static struct reloc *find_jump_table (struct objtool_file *file,struct symbol *func, -struct instruction *insn) +struct instruction *insn,bool *is_rel) {struct reloc *table_reloc;struct instruction *dest_insn, *orig_insn = insn;
@@ -2125,14 +2128,7 @@ static struct reloc *find_jump_table(struct objtool_file *file,if (insn != orig_insn && insn->type ==INSN_JUMP_DYNAMIC )break ; -/* allow small jumps within the range */ -if (insn->type ==INSN_JUMP_UNCONDITIONAL && - insn->jump_dest && - (insn->jump_dest->offset <= insn->offset || - insn->jump_dest->offset > orig_insn->offset)) -break ; - - table_reloc =arch_find_switch_table (file, insn); + table_reloc =arch_find_switch_table (file, insn, is_rel);if (!table_reloc)continue ; dest_insn =find_insn (file, table_reloc->sym->sec, table_reloc->addend);
@@ -2154,6 +2150,7 @@ static void mark_func_jump_tables(struct objtool_file *file, {struct instruction *insn, *last =NULL ;struct reloc *reloc; +bool is_rel;func_for_each_insn (file, func, insn) {if (!last)
@@ -2176,9 +2173,10 @@ static void mark_func_jump_tables(struct objtool_file *file,if (insn->type !=INSN_JUMP_DYNAMIC )continue ; - reloc =find_jump_table (file, func, insn); + reloc =find_jump_table (file, func, insn, &is_rel);if (reloc) { reloc->jump_table_start = true; + reloc->jump_table_is_rel = is_rel; insn->_jump_table = reloc; } }
@@ -4024,6 +4022,11 @@ static bool ignore_unreachable_insn(struct objtool_file *file, struct instructioif (insn->ignore || insn->type ==INSN_NOP || insn->type ==INSN_TRAP )return true; +/* powerpc relocatable files have a word in front of each relocatable function */ +if ((file->elf->ehdr.e_machine ==EM_PPC || file->elf->ehdr.e_machine ==EM_PPC64 ) && + (file->elf->ehdr.e_flags &EF_PPC_RELOCATABLE_LIB ) && +insn_func (next_insn_same_sec (file, insn))) +return true;/* * Ignore alternative replacement instructions. This can happen * when a whitelisted function uses one of the ALTERNATIVE macros.
tools/objtool/include/objtool/elf.h +1 -0
@@ -80,6 +80,7 @@ struct reloc {s64 addend;int idx;bool jump_table_start; +bool jump_table_is_rel; };#define ELF_HASH_BITS 20
tools/objtool/include/objtool/special.h +1 -1
@@ -38,5 +38,5 @@ bool arch_support_alt_relocation(struct special_alt *special_alt,struct instruction *insn, struct reloc *reloc);struct reloc *arch_find_switch_table (struct objtool_file *file, -struct instruction *insn); +struct instruction *insn,bool *is_rel);#endif /* _SPECIAL_H */
Signature · 1 line
2.40.1
Peter Zijlstra
maintainerRe: [RFC PATCH v1 3/3] powerpc: WIP draft support to objtool check
Few comments..
Quoted 14 lines · Christophe Leroy
tools/objtool/check.c +1
-0@@ -236,6 +236,7 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,"x86_64_start_reservations" ,"xen_cpu_bringup_again" ,"xen_start_kernel" , + "longjmp", };if (!func)@@ -2060,13 +2061,12 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn,* instruction.
tools/objtool/check.c static int add_jump_table(struct objtool_file *file, struct instruction *insn, · line 2069
Quoted 10 lines
tools/objtool/check.c +1
-2*/ list_for_each_entry_from (reloc, &table->sec->reloc_list, list) { -/* Check for the end of the table: */ if (reloc != table && reloc->jump_table_start)break ;/* Make sure the table entries are consecutive: */ -if (prev_offset && reloc->offset != prev_offset +8 ) +if (prev_offset && reloc->offset != prev_offset +4 )
Do we want a global variable (from elf.c) called elf_sizeof_long or so?
tools/objtool/check.c static int add_jump_table(struct objtool_file *file, struct instruction *insn, · line 2080
Quoted 12 lines
tools/objtool/check.c +4
-1break ;/* Detect function pointers from contiguous objects: */ @@ -2074,7 +2074,10 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn, reloc->addend == pfunc->offset)break ; - dest_insn =find_insn (file, reloc->sym->sec, reloc->addend); +if (table->jump_table_is_rel) + dest_insn =find_insn (file, reloc->sym->sec, reloc->addend + table->offset - reloc->offset); +else + dest_insn =find_insn (file, reloc->sym->sec, reloc->addend);
offset = reloc->addend; if (table->jump_table_is_rel) offset += table->offset - reloc->offset; dest_insn = find_insn(file, reloc->sym->sec, offset);
perhaps?
tools/objtool/check.c static bool ignore_unreachable_insn(struct objtool_file *file, struct instructio · line 4029
Quoted 12 lines
tools/objtool/check.c +5
-0if (!dest_insn)break ;@@ -4024,6 +4022,11 @@ static bool ignore_unreachable_insn(struct objtool_file *file, struct instructioif (insn->ignore || insn->type ==INSN_NOP || insn->type ==INSN_TRAP )return true; +/* powerpc relocatable files have a word in front of each relocatable function */ +if ((file->elf->ehdr.e_machine ==EM_PPC || file->elf->ehdr.e_machine ==EM_PPC64 ) && + (file->elf->ehdr.e_flags &EF_PPC_RELOCATABLE_LIB ) && +insn_func (next_insn_same_sec (file, insn))) +return true;
Can't you simply decode that word to INSN_NOP or so?