[PATCH v2] powerpc/dexcr: Move HASHCHK trap handler

2023-09-14 Thread Benjamin Gray
use we are only interested in HASHCHK if it's a user space trap. Fixes: 5bcba4e6c13f ("powerpc/dexcr: Handle hashchk exception") Signed-off-by: Benjamin Gray --- v1: https://lore.kernel.org/all/20230825014910.488822-1-bg...@linux.ibm.com/ v1 -> v2: Changed commit description to mentio

[PATCH] powerpc/configs: Set more PPC debug configs

2023-08-29 Thread Benjamin Gray
manipulation CONFIG_PPC_KUAP_DEBUG Adds some extra KAUP checks around interrupts/context switching CONFIG_PPC_RFI_SRR_DEBUG Adds some extra SSR checks around interrupts/syscalls Signed-off-by: Benjamin Gray --- arch/powerpc/configs/debug.config | 4 1 file changed, 4 insertions

Re: [PATCH v2 0/3] Add generic data patching functions

2023-10-17 Thread Benjamin Gray
On 17/10/23 5:39 pm, Christophe Leroy wrote: Le 16/10/2023 à 07:01, Benjamin Gray a écrit : Currently patch_instruction() bases the write length on the value being written. If the value looks like a prefixed instruction it writes 8 bytes, otherwise it writes 4 bytes. This makes it potentially

[RFC PATCH 3/6] prctl: Define PowerPC DEXCR interface

2023-10-08 Thread Benjamin Gray
Adds the definitions and generic handler for prctl control of the PowerPC Dynamic Execution Control Register (DEXCR). Signed-off-by: Benjamin Gray --- include/uapi/linux/prctl.h | 13 + kernel/sys.c | 16 2 files changed, 29 insertions(+) diff --git

[RFC PATCH 4/6] powerpc/dexcr: Add prctl implementation

2023-10-08 Thread Benjamin Gray
by the hypervisor via SPR 455. A bitwise OR of these two SPRs will give the effective DEXCR aspect state of the process. Signed-off-by: Benjamin Gray --- arch/powerpc/include/asm/processor.h | 10 +++ arch/powerpc/kernel/Makefile | 1 + arch/powerpc/kernel/dexcr.c | 128

[RFC PATCH 5/6] powerpc/dexcr: Add sysctl entry for SBHE system override

2023-10-09 Thread Benjamin Gray
: Disable DEXCR SBHE sysctl override 0: Override and set DEXCR[SBHE] aspect to 0 1: Override and set DEXCR[SBHE] aspect to 1 Internally, introduces a mechanism to apply arbitrary system wide overrides on top of the prctl() config. Signed-off-by: Benjamin Gray --- arch/powerpc

[RFC PATCH 6/6] powerpc/dexcr: Add enforced userspace ROP protection config

2023-10-08 Thread Benjamin Gray
. If set, don't report NPHIE as editable via prctl(), as the prctl() value can never take effect. Signed-off-by: Benjamin Gray --- arch/powerpc/Kconfig| 5 + arch/powerpc/kernel/dexcr.c | 7 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/Kconfig b/arch

[RFC PATCH 0/6] Add dynamic DEXCR support

2023-10-08 Thread Benjamin Gray
interface could still handle that. [1]: https://patchwork.ozlabs.org/project/linuxppc-dev/cover/20230616034846.311705-1-bg...@linux.ibm.com/ Benjamin Gray (6): powerpc/dexcr: Make all aspects CPU features powerpc/dexcr: Add thread specific DEXCR configuration prctl: Define PowerPC DEXCR

[RFC PATCH 1/6] powerpc/dexcr: Make all aspects CPU features

2023-10-08 Thread Benjamin Gray
r accessed or exposed to userspace, so there is no breakage. Signed-off-by: Benjamin Gray --- arch/powerpc/include/asm/cputable.h | 6 +- arch/powerpc/kernel/prom.c | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/include/asm/cputable.h b/arch/power

[RFC PATCH 2/6] powerpc/dexcr: Add thread specific DEXCR configuration

2023-10-08 Thread Benjamin Gray
Add capability to track a DEXCR value per thread. Nothing actually changes these values yet, but they are correctly tracked, propagated, and used to set the hardware register. Signed-off-by: Benjamin Gray --- arch/powerpc/include/asm/processor.h | 12 arch/powerpc/kernel/process.c

[PATCH 03/12] powerpc: Explicitly reverse bytes when checking for byte reversal

2023-10-10 Thread Benjamin Gray
of the code. Signed-off-by: Benjamin Gray --- arch/powerpc/sysdev/mpic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/sysdev/mpic.c b/arch/powerpc/sysdev/mpic.c index ba287abcb008..dabbdd356664 100644 --- a/arch/powerpc/sysdev/mpic.c +++ b/arch/powerpc/sysdev

[PATCH 00/12] Miscellaneous Sparse fixes

2023-10-10 Thread Benjamin Gray
instead of continuing to sit on it indefinitely. Benjamin Gray (12): powerpc/xive: Fix endian conversion size powerpc/pseries: Restructure hvc_get_chars() endianness powerpc: Explicitly reverse bytes when checking for byte reversal powerpc: Use NULL instead of 0 for null pointers powerpc

[PATCH 01/12] powerpc/xive: Fix endian conversion size

2023-10-10 Thread Benjamin Gray
: 88ec6b93c8e7 ("powerpc/xive: add OPAL extensions for the XIVE native exploitation support") Signed-off-by: Benjamin Gray --- arch/powerpc/sysdev/xive/native.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/sysdev/xive/native.c b/arch/powerpc/sysdev/xive/nati

[PATCH 08/12] powerpc/opal: Annotate out param endianness

2023-10-10 Thread Benjamin Gray
-by: Benjamin Gray --- arch/powerpc/include/asm/opal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h index a9b31cc258fc..b66b0c615f4f 100644 --- a/arch/powerpc/include/asm/opal.h +++ b/arch/powerpc/include/asm/opal.h

[PATCH 10/12] powerpc: Cast away __iomem in low level IO routines

2023-10-10 Thread Benjamin Gray
Sparse reports dereferencing an __iomem pointer. These routines are clearly low level handlers for IO memory, so force cast away the __iomem annotation to tell sparse the dereferences are safe. Signed-off-by: Benjamin Gray --- arch/powerpc/kernel/io.c | 12 ++-- 1 file changed, 6

[PATCH 11/12] powerpc/eeh: Remove unnecessary cast

2023-10-10 Thread Benjamin Gray
Sparse reports a warning when casting to an int. There is no need to cast in the first place, so drop them. Signed-off-by: Benjamin Gray --- arch/powerpc/kernel/eeh_driver.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kernel/eeh_driver.c b/arch/powerpc

[PATCH 09/12] powerpc/uaccess: Cast away __user annotation after verification

2023-10-10 Thread Benjamin Gray
Sparse reports dereference of a __user pointer. copy_mc_to_user() takes a __user pointer, verifies it, then calls the generic copy routine copy_mc_generic(). As we have verified the pointer, cast out the __user annotation when passing to copy_mc_generic(). Signed-off-by: Benjamin Gray --- arch

[PATCH 02/12] powerpc/pseries: Restructure hvc_get_chars() endianness

2023-10-10 Thread Benjamin Gray
with cpu_to_be64() and cast lbuf as an array of __be64 to match the semantics closer. Signed-off-by: Benjamin Gray --- arch/powerpc/platforms/pseries/hvconsole.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/platforms/pseries/hvconsole.c b/arch/powerpc

[PATCH 05/12] powerpc: Remove extern from function implementations

2023-10-10 Thread Benjamin Gray
Sparse reports several function implementations annotated with extern. This is clearly incorrect, likely just copied from an actual extern declaration in another file. Fix the sparse warnings by removing extern. Signed-off-by: Benjamin Gray --- arch/powerpc/kernel/iommu.c | 8

[PATCH 04/12] powerpc: Use NULL instead of 0 for null pointers

2023-10-10 Thread Benjamin Gray
Sparse reports several uses of 0 for pointer arguments and comparisons. Replace with NULL to better convey the intent. Remove entirely if a comparison to follow the kernel style of implicit boolean conversions. Signed-off-by: Benjamin Gray --- arch/powerpc/kernel/setup_64.c| 2 +- arch

[PATCH 12/12] powerpc/fadump: Annotate endianness cast with __force

2023-10-10 Thread Benjamin Gray
ignore it. Signed-off-by: Benjamin Gray --- arch/powerpc/platforms/powernv/opal-fadump.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/platforms/powernv/opal-fadump.h b/arch/powerpc/platforms/powernv/opal-fadump.h index 3f715efb0aa6..5eeb794b5eb1 100644 ---

[PATCH 07/12] powerpc/kvm: Force cast endianness of KVM shared regs

2023-10-10 Thread Benjamin Gray
Sparse reports endianness mismatches in the KVM shared regs getter and setter helpers. This code has dynamic endianness behind a safe interface, so a force is warranted here to tell sparse this is OK. Signed-off-by: Benjamin Gray --- arch/powerpc/include/asm/kvm_ppc.h | 8 1 file

[PATCH 06/12] powerpc: Annotate endianness of various variables and functions

2023-10-11 Thread Benjamin Gray
are introduced by this patch. Signed-off-by: Benjamin Gray --- arch/powerpc/include/asm/book3s/64/pgtable.h| 2 +- arch/powerpc/include/asm/imc-pmu.h | 16 arch/powerpc/kernel/prom_init.c | 2 +- arch/powerpc/kexec/core_64.c| 4

[PATCH v2 1/3] powerpc/code-patching: Add generic memory patching

2023-10-15 Thread Benjamin Gray
the compiler can const-propagate it away. Signed-off-by: Benjamin Gray --- v2: * Deduplicate patch_32() definition * Use u32 for val32 * Remove noinline --- arch/powerpc/include/asm/code-patching.h | 33 arch/powerpc/lib/code-patching.c | 66 ++-- 2

[PATCH v2 0/3] Add generic data patching functions

2023-10-15 Thread Benjamin Gray
: * Addressed the v1 review actions * Removed noinline (for now) v1: https://patchwork.ozlabs.org/project/linuxppc-dev/cover/20230207015643.590684-1-bg...@linux.ibm.com/ Benjamin Gray (3): powerpc/code-patching: Add generic memory patching powerpc/64: Convert patch_instruction

[PATCH v2 2/3] powerpc/64: Convert patch_instruction() to patch_u32()

2023-10-15 Thread Benjamin Gray
ink: https://lore.kernel.org/all/20230203004649.1f59dbd4@yea/ Signed-off-by: Benjamin Gray --- v2: * Added the fixes tag, it seems appropriate even if the subject does mention a more robust solution being required. patch_u64() should be more efficient, but judging from the bug report it doesn't

[PATCH v2 3/3] powerpc/32: Convert patch_instruction() to patch_uint()

2023-10-15 Thread Benjamin Gray
flushing when patching data). Signed-off-by: Benjamin Gray --- arch/powerpc/kernel/static_call.c | 2 +- arch/powerpc/platforms/powermac/smp.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kernel/static_call.c b/arch/powerpc/kernel/static_call.c index

[PATCH 1/3] powerpc/watchpoints: Disable preemption in thread_change_pc()

2023-08-29 Thread Benjamin Gray
s_cpu_read() call in thread_change_pc(). However the existing __this_cpu_read() that runs if a breakpoint does need to be re-inserted has the same issue. Signed-off-by: Benjamin Gray --- There's probably a more idiomatic way to express this. We technically don't need to disable preemption for

Re: [PATCH 0/3] Fix preemption errors in watchpoints

2023-08-29 Thread Benjamin Gray
On 29/8/23 4:34 pm, Benjamin Gray wrote: When enabling debug config options relating to preemption, several bugs appear in the kernel log. With this series applied, the breakpoint code no longer prints bugs when running the powerpc/ptrace selftests. Benjamin Gray (3): powerpc/watchpoints

[PATCH 2/3] powerpc/watchpoint: Disable pagefaults when getting user instruction

2023-08-29 Thread Benjamin Gray
because we are reading the instruction that just triggered the watchpoint trap. Signed-off-by: Benjamin Gray --- arch/powerpc/kernel/hw_breakpoint_constraints.c | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/hw_breakpoint_constraints.c b/arch/powerpc

[PATCH 0/3] Fix preemption errors in watchpoints

2023-08-29 Thread Benjamin Gray
When enabling debug config options relating to preemption, several bugs appear in the kernel log. With this series applied, the breakpoint code no longer prints bugs when running the powerpc/ptrace selftests. Benjamin Gray (3): powerpc/watchpoints: Disable preemption in thread_change_pc

[PATCH 3/3] powerpc/watchpoints: Annotate atomic context in more places

2023-08-29 Thread Benjamin Gray
It can be easy to miss that the notifier mechanism invokes the callbacks in an atomic context, so add some comments to that effect on the two handlers we register here. Signed-off-by: Benjamin Gray --- arch/powerpc/kernel/hw_breakpoint.c | 9 + 1 file changed, 9 insertions(+) diff

[PATCH] powerpc/dexcr: Move HASHCHK trap handler

2023-08-24 Thread Benjamin Gray
a user space trap. Fixes: 5bcba4e6c13f ("powerpc/dexcr: Handle hashchk exception") Signed-off-by: Benjamin Gray --- arch/powerpc/kernel/traps.c | 56 - 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/arch/powerpc/kernel/traps.c b/ar

[RFC PATCH 0/4] Out-of-line static calls for powerpc64 ELF V2

2022-09-01 Thread Benjamin Gray
necessary info, but I could not find one. Benjamin Gray (3): static_call: Move static call selftest to static_call.c powerpc/64: Add support for out-of-line static calls powerpc/64: Add tests for out-of-line static calls Russell Currey (1): powerpc/code-patching: add patch_memo

[RFC PATCH 3/4] powerpc/64: Add support for out-of-line static calls

2022-09-01 Thread Benjamin Gray
rate local entry point), and so does not insert the appropriate restoration at the call site. Signed-off-by: Benjamin Gray --- arch/powerpc/Kconfig | 13 +++- arch/powerpc/include/asm/code-patching.h | 1 + arch/powerpc/include/asm/static_call.h | 45 - arch/pow

[RFC PATCH 1/4] powerpc/code-patching: add patch_memory() for writing RO text

2022-09-01 Thread Benjamin Gray
. Signed-off-by: Russell Currey Signed-off-by: Benjamin Gray --- arch/powerpc/include/asm/code-patching.h | 1 + arch/powerpc/lib/code-patching.c | 65 2 files changed, 66 insertions(+) diff --git a/arch/powerpc/include/asm/code-patching.h b/arch/powerpc/include

[RFC PATCH 2/4] static_call: Move static call selftest to static_call.c

2022-09-01 Thread Benjamin Gray
These tests are out-of-line only, so moving them to the out-of-line file allows them to be run when an arch does not implement inline static calls. Signed-off-by: Benjamin Gray --- kernel/static_call.c| 43 + kernel/static_call_inline.c | 43

[RFC PATCH 4/4] powerpc/64: Add tests for out-of-line static calls

2022-09-01 Thread Benjamin Gray
possible errors can be caught by this, but it makes certain kinds of errors easier to debug. Currently the large arg count test is failing due to the trampoline implementation using the stack. Signed-off-by: Benjamin Gray --- arch/powerpc/Kconfig | 10 + arch/powerpc/kernel

Re: [PATCH v2 0/7] Implement inline static calls on PPC32 - v2

2022-09-07 Thread Benjamin Gray
On Thu, 2022-09-01 at 16:46 +, Christophe Leroy wrote: > Surprisingly, I get worst performance with inline static call than > with > out of line static call: I'm not sure what hackbench is doing, but when microbenchmarking 64 bit out-of-line calls in a loop I saw a similar thing where adding

Re: [PATCH v2 5/6] powerpc/64: Add support for out-of-line static calls

2022-09-26 Thread Benjamin Gray
On Mon, 2022-09-26 at 14:54 +, Christophe Leroy wrote: > > diff --git a/arch/powerpc/kernel/static_call.c > > b/arch/powerpc/kernel/static_call.c > > index 863a7aa24650..ecbb74e1b4d3 100644 > > --- a/arch/powerpc/kernel/static_call.c > > +++ b/arch/powerpc/kernel/static_call.c > > @@ -4,30

Re: [PATCH v2 6/6] powerpc/64: Add tests for out-of-line static calls

2022-09-26 Thread Benjamin Gray
On Mon, 2022-09-26 at 14:55 +, Christophe Leroy wrote: > > +config PPC_STATIC_CALL_KUNIT_TEST > > +   tristate "KUnit tests for PPC64 ELF ABI V2 static calls" > > +   default KUNIT_ALL_TESTS > > +   depends on HAVE_STATIC_CALL && PPC64_ELF_ABI_V2 && KUNIT && > > m > > Is there a

Re: [PATCH v2 3/6] powerpc/module: Optimise nearby branches in ELF V2 ABI stub

2022-09-26 Thread Benjamin Gray
On Mon, 2022-09-26 at 14:49 +, Christophe Leroy wrote: > > +   /* Replace indirect branch sequence with direct branch > > where possible */ > > +   if (!create_branch(, jump_seq_addr, addr, 0)) > > +   if (patch_instruction(jump_seq_addr, direct)) > > Why not use

Re: [PATCH v2 1/6] powerpc/code-patching: Implement generic text patching function

2022-09-26 Thread Benjamin Gray
On Mon, 2022-09-26 at 14:33 +, Christophe Leroy wrote: > > +#define patch_memory(addr, val) \ > > +({ \ > > +   BUILD_BUG_ON(!__native_word(val)); \ > > +   __patch_memory(addr, (unsigned long) val, sizeof(val)); \ > > +}) > > Can you do a static __always_inline function instead of a

Re: [PATCH v2 5/6] powerpc/64: Add support for out-of-line static calls

2022-09-26 Thread Benjamin Gray
On Mon, 2022-09-26 at 13:16 +, Christophe Leroy wrote: > Build failure with GCC 5.5 (ppc64le_defconfig): > >    CC  arch/powerpc/kernel/ptrace/ptrace.o > {standard input}: Assembler messages: > {standard input}:10: Error: .localentry expression for > `__SCT__tp_func_sys_enter' is not a

[PATCH v8 4/6] powerpc/tlb: Add local flush for page given mm_struct and psize

2022-10-20 Thread Benjamin Gray
Adds a local TLB flush operation that works given an mm_struct, VA to flush, and page size representation. This removes the need to create a vm_area_struct, which the temporary patching mm work does not need. Signed-off-by: Benjamin Gray --- arch/powerpc/include/asm/book3s/32/tlbflush.h

[PATCH v8 3/6] powerpc/code-patching: Verify instruction patch succeeded

2022-10-20 Thread Benjamin Gray
Verifies that if the instruction patching did not return an error then the value stored at the given address to patch is now equal to the instruction we patched it to. Signed-off-by: Benjamin Gray --- arch/powerpc/lib/code-patching.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch

[PATCH v8 0/6] Use per-CPU temporary mappings for patching

2022-10-20 Thread Benjamin Gray
/all/20200603051912.23296-1-...@informatik.wtf/ RFC: https://lore.kernel.org/all/20200323045205.20314-1-...@informatik.wtf/ x86: https://lore.kernel.org/kernel-hardening/20190426232303.28381-1-nadav.a...@gmail.com/ Benjamin Gray (5): powerpc/code-patching: Use WARN_ON and fix check in poking_init powerpc/

[PATCH v8 1/6] powerpc: Allow clearing and restoring registers independent of saved breakpoint state

2022-10-20 Thread Benjamin Gray
current_brk[]. Add a pause_breakpoints() function which will clear the breakpoint registers without touching the state in current_bkr[]. Add a pair function unpause_breakpoints() which will move the state in current_brk[] back to the registers. Signed-off-by: Jordan Niethe Signed-off-by: Benjamin

[PATCH v8 2/6] powerpc/code-patching: Use WARN_ON and fix check in poking_init

2022-10-20 Thread Benjamin Gray
le". Also take this opportunity to fix the failure check in the WARN_ON(): cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, ...) returns a positive integer on success and a negative integer on failure. Signed-off-by: Benjamin Gray --- arch/powerpc/lib/code-patching.c | 13 + 1 file c

[PATCH v8 5/6] powerpc/code-patching: Use temporary mm for Radix MMU

2022-10-20 Thread Benjamin Gray
ches in a row (e.g., as ftrace would). Signed-off-by: Benjamin Gray --- arch/powerpc/lib/code-patching.c | 226 ++- 1 file changed, 221 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c index 9b9eba574d7e..eabdd74a

[PATCH v8 6/6] powerpc/code-patching: Use CPU local patch address directly

2022-10-20 Thread Benjamin Gray
With the isolated mm context support, there is a CPU local variable that can hold the patch address. Use it instead of adding a level of indirection through the text_poke_area vm_struct. Signed-off-by: Benjamin Gray --- arch/powerpc/lib/code-patching.c | 3 ++- 1 file changed, 2 insertions

[PATCH v9 5/7] powerpc/tlb: Add local flush for page given mm_struct and psize

2022-10-24 Thread Benjamin Gray
. This removes the need to create a vm_area_struct, which the temporary patching mm work does not need. Signed-off-by: Benjamin Gray --- v9: * Replace book3s/32/tlbflush.h implementation with warning --- arch/powerpc/include/asm/book3s/32/tlbflush.h | 9 + arch/powerpc/include/asm

[PATCH v9 1/7] powerpc: Allow clearing and restoring registers independent of saved breakpoint state

2022-10-24 Thread Benjamin Gray
-by: Benjamin Gray --- v9: * Renamed set_breakpoint to set_hw_breakpoint * Renamed pause/unpause to suspend/restore * Removed unrelated whitespace change --- arch/powerpc/include/asm/debug.h | 2 ++ arch/powerpc/kernel/process.c| 38 +--- 2 files

[PATCH v9 0/7] Use per-CPU temporary mappings for patching on Radix MMU

2022-10-24 Thread Benjamin Gray
rmatik.wtf/ x86: https://lore.kernel.org/kernel-hardening/20190426232303.28381-1-nadav.a...@gmail.com/ Benjamin Gray (7): powerpc: Allow clearing and restoring registers independent of saved breakpoint state powerpc/code-patching: Handle RWX patching initialisation error powerpc/cod

[PATCH v9 3/7] powerpc/code-patching: Use WARN_ON and fix check in poking_init

2022-10-24 Thread Benjamin Gray
of cpuhp_setup_state() is also >= 0 on success, so check for < 0. Signed-off-by: Benjamin Gray Reviewed-by: Russell Currey --- v9: * Reword commit message to explain why init failure is not fatal --- arch/powerpc/lib/code-patching.c | 13 + 1 file changed, 5 insertions(+), 8 del

Re: [PATCH v8 3/6] powerpc/code-patching: Verify instruction patch succeeded

2022-10-24 Thread Benjamin Gray
On Mon, 2022-10-24 at 14:20 +1100, Russell Currey wrote: > On Fri, 2022-10-21 at 16:22 +1100, Benjamin Gray wrote: > > diff --git a/arch/powerpc/lib/code-patching.c > > b/arch/powerpc/lib/code-patching.c > > index 34fc7ac34d91..9b9eba574d7e 100644 > > --- a/arch/

[PATCH v9 6/7] powerpc/code-patching: Use temporary mm for Radix MMU

2022-10-24 Thread Benjamin Gray
ignores the AMR (so no need to unlock/lock KUAP) according to PowerISA v3.0b Figure 35 on Radix. Based on x86 implementation: commit 4fc19708b165 ("x86/alternatives: Initialize temporary mm for patching") and: commit b3fd8e83ada0 ("x86/alternatives: Use temporary mm for

[PATCH v9 7/7] powerpc/code-patching: Consolidate and cache per-cpu patching context

2022-10-24 Thread Benjamin Gray
-by: Benjamin Gray --- v9: * Consolidate patching context into single struct --- arch/powerpc/lib/code-patching.c | 58 ++-- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c index

[PATCH v9 2/7] powerpc/code-patching: Handle RWX patching initialisation error

2022-10-24 Thread Benjamin Gray
is dereferenced. Signed-off-by: Benjamin Gray --- v9: * New in v9 --- arch/powerpc/lib/code-patching.c | 8 +++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c index ad0cf3108dd0..54e145247643 100644 --- a/arch/powerpc

[PATCH v9 4/7] powerpc/code-patching: Verify instruction patch succeeded

2022-10-24 Thread Benjamin Gray
Verifies that if the instruction patching did not return an error then the value stored at the given address to patch is now equal to the instruction we patched it to. Signed-off-by: Benjamin Gray --- arch/powerpc/lib/code-patching.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch

Re: [PATCH v9 4/7] powerpc/code-patching: Verify instruction patch succeeded

2022-10-25 Thread Benjamin Gray
It occurred to me that we don't require holding a lock when patching text. Many use cases do hold text_mutex, but it's not required, so it's possible for this warning to show false positives. If we do want text_mutex be held, then lockdep_assert_held(_mutex) ought to be added too.

Re: [PATCH v4 2/6] powerpc/module: Handle caller-saved TOC in module linker

2022-10-25 Thread Benjamin Gray
On Tue, 2022-10-25 at 13:10 +1100, Andrew Donnellan wrote: > On Mon, 2022-10-10 at 11:29 +1100, Benjamin Gray wrote: > > > A function symbol may set a value in the st_other field to > > > indicate > > > the TOC should be treated as caller-saved. The linker should &

Re: [PATCH v8 5/6] powerpc/code-patching: Use temporary mm for Radix MMU

2022-10-23 Thread Benjamin Gray
On Mon, 2022-10-24 at 14:45 +1100, Russell Currey wrote: > On Fri, 2022-10-21 at 16:22 +1100, Benjamin Gray wrote: > > From: "Christopher M. Riedl" > > > > x86 supports the notion of a temporary mm which restricts access to > > temporary PTEs to a

Re: [PATCH v8 4/6] powerpc/tlb: Add local flush for page given mm_struct and psize

2022-10-23 Thread Benjamin Gray
On Mon, 2022-10-24 at 14:30 +1100, Russell Currey wrote: > On Fri, 2022-10-21 at 16:22 +1100, Benjamin Gray wrote: > > Adds a local TLB flush operation that works given an mm_struct, VA > > to > > flush, and page size representation. > > > > This removes the need

Re: [PATCH 1/6] powerpc/code-patching: Implement generic text patching function

2022-09-19 Thread Benjamin Gray
On Mon, 2022-09-19 at 07:16 +, Christophe Leroy wrote: > Why would it be unpredictable ? Only one page is mapped. If it > crosses > the boundary, __put_kernel_nofault() will fail in a controled manner. > I see no point in doing the check before every write. Oh I didn't see that get_vm_area

Re: [PATCH 1/6] powerpc/code-patching: Implement generic text patching function

2022-09-19 Thread Benjamin Gray
On Mon, 2022-09-19 at 06:38 +, Christophe Leroy wrote: > Le 16/09/2022 à 08:23, Benjamin Gray a écrit : > > [...] > > +   /* Make sure we aren't patching a freed init section */ > > +   if (static_branch_likely(_mem_is_free) && >

Re: [PATCH 1/6] powerpc/code-patching: Implement generic text patching function

2022-09-20 Thread Benjamin Gray
On Tue, 2022-09-20 at 05:44 +, Christophe Leroy wrote: > > As far as I know, cachelines are minimum 64 bytes on PPC64 aren't > they ? In practice maybe. I don't know what the convention is in the kernel in cases where the ISA is less specific than what the supported machines do. > > Related

Re: [RFC PATCH 0/4] Out-of-line static calls for powerpc64 ELF V2

2022-09-12 Thread Benjamin Gray
On Thu, 2022-09-01 at 15:58 +1000, Benjamin Gray wrote: >     So not having a local entry point implies not using a TOC > pointer, which >     implies r2 is volatile if the trampoline does not guarantee that > it preserves >     r2. However experimenting with such a trampoline show

Re: [PATCH 1/6] powerpc/code-patching: Implement generic text patching function

2022-09-19 Thread Benjamin Gray
On Mon, 2022-09-19 at 06:04 +, Christophe Leroy wrote: > With CONFIG_STRICT_KERNEL_RWX, this patches causes a 15% time > increase > for activation/deactivation of ftrace. It's possible that new alignment check is the cause. I'll see > Without CONFIG_STRICT_KERNEL_RWX, it doesn't build.

[PATCH v2 1/6] powerpc/code-patching: Implement generic text patching function

2022-09-26 Thread Benjamin Gray
function. This generic implementation allows patching of arbitrary 64-bit data, whereas the original `patch_instruction` decided the size based on the 'instruction' opcode, so was not suitable for arbitrary data. Signed-off-by: Benjamin Gray --- arch/powerpc/include/asm/code-patching.h | 7 ++ arch

[PATCH v2 0/6] Out-of-line static calls for powerpc64 ELF V2

2022-09-26 Thread Benjamin Gray
-volatile registers in the init hook, but that's incorrect because it returns to the KUnit framework before the test case is called). * Some other minor refactoring in other patches Benjamin Gray (6): powerpc/code-patching: Implement generic text patching function powerpc/module: Handle

[PATCH v2 6/6] powerpc/64: Add tests for out-of-line static calls

2022-09-26 Thread Benjamin Gray
possible errors can be caught by this (we can't stop a trampoline from using a bad TOC itself), but it makes certain errors easier to debug. Signed-off-by: Benjamin Gray --- arch/powerpc/Kconfig | 10 + arch/powerpc/kernel/Makefile | 1 + arch/powerpc/kernel

[PATCH v2 3/6] powerpc/module: Optimise nearby branches in ELF V2 ABI stub

2022-09-26 Thread Benjamin Gray
call implementation, where modules calling their own trampolines are called through this stub and the trampoline is easily within range of a direct branch. Signed-off-by: Benjamin Gray --- arch/powerpc/kernel/module_64.c | 13 + 1 file changed, 13 insertions(+) diff --git a/arch

[PATCH v2 5/6] powerpc/64: Add support for out-of-line static calls

2022-09-26 Thread Benjamin Gray
text, so it's quite expensive. Signed-off-by: Benjamin Gray --- arch/powerpc/Kconfig | 2 +- arch/powerpc/include/asm/code-patching.h | 1 + arch/powerpc/include/asm/static_call.h | 80 +++-- arch/powerpc/kernel/Makefile | 3 +- arch/powerpc/ke

[PATCH v2 4/6] static_call: Move static call selftest to static_call_selftest.c

2022-09-26 Thread Benjamin Gray
These tests are out-of-line only, so moving them to the their own file allows them to be run when an arch does not implement inline static calls. Signed-off-by: Benjamin Gray --- kernel/Makefile | 1 + kernel/static_call_inline.c | 43 --- kernel

[PATCH v2 2/6] powerpc/module: Handle caller-saved TOC in module linker

2022-09-26 Thread Benjamin Gray
not preserve the TOC. Signed-off-by: Benjamin Gray --- arch/powerpc/kernel/module_64.c | 14 +- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c index 7e45dc98df8a..4d816f7785b4 100644 --- a/arch/powerpc/kernel

[PATCH 1/6] powerpc/code-patching: Implement generic text patching function

2022-09-16 Thread Benjamin Gray
. This generic implementation allows patching of arbitrary 64-bit data, whereas the original `patch_instruction` decided the size based on the 'instruction' opcode, so was not suitable for arbitrary data. Signed-off-by: Benjamin Gray --- arch/powerpc/include/asm/code-patching.h | 1 + arch/powerpc/lib

[PATCH 2/6] powerpc/module: Handle caller-saved TOC in module linker

2022-09-16 Thread Benjamin Gray
not preserve the TOC. Signed-off-by: Benjamin Gray --- arch/powerpc/kernel/module_64.c | 12 +++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c index 7e45dc98df8a..3656476097c2 100644 --- a/arch/powerpc/kernel

[PATCH 0/6] Out-of-line static calls for powerpc64 ELF V2

2022-09-16 Thread Benjamin Gray
is the same as the enum name it was generated from, which confuses the compiler when it reaches said enum definition. Benjamin Gray (6): powerpc/code-patching: Implement generic text patching function powerpc/module: Handle caller-saved TOC in module linker powerpc/module: Optimise nearby branch

[PATCH 3/6] powerpc/module: Optimise nearby branches in ELF V2 ABI stub

2022-09-16 Thread Benjamin Gray
call implementation, where modules calling their own trampolines are called through this stub and the trampoline is easily within range of a direct branch. Signed-off-by: Benjamin Gray --- arch/powerpc/kernel/module_64.c | 13 +++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff

[PATCH 5/6] powerpc/64: Add support for out-of-line static calls

2022-09-16 Thread Benjamin Gray
text, so it's quite expensive. Signed-off-by: Benjamin Gray --- arch/powerpc/Kconfig | 12 +++- arch/powerpc/include/asm/code-patching.h | 1 + arch/powerpc/include/asm/static_call.h | 80 +++-- arch/powerpc/kernel/Makefile | 3 +- arch/pow

[PATCH 6/6] powerpc/64: Add tests for out-of-line static calls

2022-09-16 Thread Benjamin Gray
possible errors can be caught by this (we can't stop a trampoline from using a bad TOC itself), but it makes certain errors easier to debug. Signed-off-by: Benjamin Gray --- arch/powerpc/Kconfig | 10 + arch/powerpc/kernel/Makefile | 1 + arch/powerpc/kernel

[PATCH 4/6] static_call: Move static call selftest to static_call_selftest.c

2022-09-16 Thread Benjamin Gray
These tests are out-of-line only, so moving them to the their own file allows them to be run when an arch does not implement inline static calls. Signed-off-by: Benjamin Gray --- kernel/Makefile | 1 + kernel/static_call_inline.c | 43 --- kernel

[PATCH v3 6/6] powerpc: Add tests for out-of-line static calls

2022-10-04 Thread Benjamin Gray
ELF V2 ABI the tests try to mitigate the chance of panicking by restoring the TOC after every static call. Not all possible errors can be caught by this (we can't stop a trampoline from using a bad TOC itself), but it makes certain errors easier to debug. Signed-off-by: Benjamin Gray --- arch

[PATCH v3 1/6] powerpc/code-patching: Implement generic text patching function

2022-10-04 Thread Benjamin Gray
noinline to prevent a mis-optimisation. Without noinline, inside patch_branch the compiler may inline all the way to do_patch_memory, preventing the compiler from inlining do_patch_memory into patch_int. This would needlessly force patch_int to be a branch to do_patch_memory. Signed-off-by: Benjamin

[PATCH v3 5/6] powerpc/64: Add support for out-of-line static calls

2022-10-04 Thread Benjamin Gray
text, so it's quite expensive. Signed-off-by: Benjamin Gray --- arch/powerpc/Kconfig | 14 ++- arch/powerpc/include/asm/code-patching.h | 1 + arch/powerpc/include/asm/static_call.h | 80 +- arch/powerpc/kernel/Makefile | 3 +- arch/powerpc/ke

[PATCH v3 2/6] powerpc/module: Handle caller-saved TOC in module linker

2022-10-04 Thread Benjamin Gray
not preserve the TOC. Signed-off-by: Benjamin Gray --- arch/powerpc/kernel/module_64.c | 14 +- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c index 7e45dc98df8a..4d816f7785b4 100644 --- a/arch/powerpc/kernel

[PATCH v3 0/6] Out-of-line static calls for powerpc64 ELF V2

2022-10-04 Thread Benjamin Gray
them in two steps. [6/6] * Replaced SAVE_REGS/RESTORE_REGS macros with functions * Reduced global register usage of tests * Support running on 32-bit as well Benjamin Gray (6): powerpc/code-patching: Implement generic text patching function powerpc/module: Handle caller-saved TOC in module li

[PATCH v3 4/6] static_call: Move static call selftest to static_call_selftest.c

2022-10-04 Thread Benjamin Gray
These tests are out-of-line only, so moving them to the their own file allows them to be run when an arch does not implement inline static calls. Signed-off-by: Benjamin Gray Reviewed-by: Andrew Donnellan --- kernel/Makefile | 1 + kernel/static_call_inline.c | 43

[PATCH v3 3/6] powerpc/module: Optimise nearby branches in ELF V2 ABI stub

2022-10-04 Thread Benjamin Gray
call implementation, where modules calling their own trampolines are called through this stub and the trampoline is easily within range of a direct branch. Signed-off-by: Benjamin Gray --- arch/powerpc/kernel/module_64.c | 12 1 file changed, 12 insertions(+) diff --git a/arch/powerpc

Re: [PATCH v3 5/6] powerpc/64: Add support for out-of-line static calls

2022-10-05 Thread Benjamin Gray
On Thu, 2022-10-06 at 11:39 +1100, Michael Ellerman wrote: > Christophe Leroy writes: > > However, thinking out loudly, I'm wondering, could we make things > > any > > simpler when CONFIG_MODULES is not selected, or is that a too much > > corner case on PPC64 ? > > I'd say it's mostly a corner

Re: [PATCH v3 1/6] powerpc/code-patching: Implement generic text patching function

2022-10-05 Thread Benjamin Gray
On Wed, 2022-10-05 at 17:55 +, Christophe Leroy wrote: > I'm on business trip this week so I can't test it on hardware, but > the > generated code looks horrid and sub-optimal, with a stack frame and > so > many registers saved into it. That's mpc885_ads_defconfig built with > GCC > 12,

Re: [PATCH v3 2/6] powerpc/module: Handle caller-saved TOC in module linker

2022-10-05 Thread Benjamin Gray
On Wed, 2022-10-05 at 19:18 +, Christophe Leroy wrote: > > > Le 05/10/2022 à 07:32, Benjamin Gray a écrit : > > The callee may set a field in st_other to 1 to indicate r2 should > > be > > treated as caller-saved. This means a trampoline must be used to > >

Re: [PATCH v3 1/6] powerpc/code-patching: Implement generic text patching function

2022-10-06 Thread Benjamin Gray
On Thu, 2022-10-06 at 09:19 +, Christophe Leroy wrote: > > > Le 06/10/2022 à 05:36, Benjamin Gray a écrit : > > On Wed, 2022-10-05 at 17:55 +, Christophe Leroy wrote: > > > I'm on business trip this week so I can't test it on hardware, > > > but >

[PATCH v4 2/6] powerpc/module: Handle caller-saved TOC in module linker

2022-10-09 Thread Benjamin Gray
not preserve the TOC. Signed-off-by: Benjamin Gray --- arch/powerpc/kernel/module_64.c | 14 +- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c index 7e45dc98df8a..83a6f6e22e3b 100644 --- a/arch/powerpc

[PATCH v4 1/6] powerpc/code-patching: Implement generic text patching function

2022-10-09 Thread Benjamin Gray
y 64-bit requires doubleword writes anyway, as ints and longs are the same size on 32-bit. Signed-off-by: Benjamin Gray --- arch/powerpc/include/asm/code-patching.h | 29 ++ arch/powerpc/lib/code-patching.c | 73 ++-- 2 files changed, 85 insertions(+), 17 d

[PATCH v4 4/6] static_call: Move static call selftest to static_call_selftest.c

2022-10-09 Thread Benjamin Gray
These tests are out-of-line only, so moving them to the their own file allows them to be run when an arch does not implement inline static calls. Signed-off-by: Benjamin Gray Reviewed-by: Andrew Donnellan Reviewed-by: Christophe Leroy --- kernel/Makefile | 1 + kernel

[PATCH v4 5/6] powerpc/64: Add support for out-of-line static calls

2022-10-09 Thread Benjamin Gray
text, so it's quite expensive. Signed-off-by: Benjamin Gray Reviewed-by: Christophe Leroy --- arch/powerpc/Kconfig | 14 ++- arch/powerpc/include/asm/code-patching.h | 1 + arch/powerpc/include/asm/static_call.h | 80 +- arch/powerpc/kernel/Make

[PATCH v4 3/6] powerpc/module: Optimise nearby branches in ELF V2 ABI stub

2022-10-09 Thread Benjamin Gray
call implementation, where modules calling their own trampolines are called through this stub and the trampoline is easily within range of a direct branch. Signed-off-by: Benjamin Gray Reviewed-by: Christophe Leroy Reviewed-by: Andrew Donnellan --- arch/powerpc/kernel/module_64.c | 12

[PATCH v4 0/6] Out-of-line static calls for powerpc64 ELF V2

2022-10-09 Thread Benjamin Gray
* Refactored need r2 save expression. Parens are intentional, C operator precedence can be difficult to remember, especially when three different kinds are used in a single expression. Benjamin Gray (6): powerpc/code-patching: Implement generic text patching function powerpc/module: Handle

  1   2   3   4   >