[PATCH v4 0/5] Add generic data patching functions

2024-05-14 Thread Benjamin Gray
-bg...@linux.ibm.com/ v2: https://patchwork.ozlabs.org/project/linuxppc-dev/cover/20231016050147.115686-1-bg...@linux.ibm.com/ v1: https://patchwork.ozlabs.org/project/linuxppc-dev/cover/20230207015643.590684-1-bg...@linux.ibm.com/ Benjamin Gray (5): powerpc/code-patching: Add generic memory

[PATCH v4 5/5] powerpc/code-patching: Add boot selftest for data patching

2024-05-14 Thread Benjamin Gray
Extend the code patching selftests with some basic coverage of the new data patching variants too. Signed-off-by: Benjamin Gray --- v4: * Change store to a check * Account for doubleword alignment v3: * New in v3 --- arch/powerpc/lib/test-code-patching.c | 41

[PATCH v4 1/5] powerpc/code-patching: Add generic memory patching

2024-05-14 Thread Benjamin Gray
-by: Benjamin Gray --- v3: * Rename from *_memory to *_mem * Change type of ppc32 patch_uint() address to void* * Explain introduction of val32 for big endian * Some formatting v2: * Deduplicate patch_32() definition * Use u32 for val32 * Remove noinline --- arch/powerpc/include/asm

[PATCH v4 2/5] powerpc/code-patching: Add data patch alignment check

2024-05-14 Thread Benjamin Gray
The new data patching still needs to be aligned within a cacheline too for the flushes to work correctly. To simplify this requirement, we just say data patches must be aligned. Detect when data patching is not aligned, returning an invalid argument error. Signed-off-by: Benjamin Gray --- v3

[PATCH v4 4/5] powerpc/32: Convert patch_instruction() to patch_uint()

2024-05-14 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 v4 3/5] powerpc/64: Convert patch_instruction() to patch_u32()

2024-05-14 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

Re: [PATCH v3 3/5] powerpc/64: Convert patch_instruction() to patch_u32()

2024-05-13 Thread Benjamin Gray
On Tue, 2024-04-23 at 15:09 +0530, Naveen N Rao wrote: > On Mon, Mar 25, 2024 at 04:53:00PM +1100, Benjamin Gray wrote: > > This use of patch_instruction() is working on 32 bit data, and can > > fail > > if the data looks like a prefixed instruction and the extra write > &

[PATCH v1 9/9] Documentation: Document PowerPC kernel dynamic DEXCR interface

2024-04-17 Thread Benjamin Gray
Documents how to use the PR_PPC_GET_DEXCR and PR_PPC_SET_DEXCR prctl()'s for changing a process's DEXCR or its process tree default value. Signed-off-by: Benjamin Gray --- Documentation/arch/powerpc/dexcr.rst | 141 ++- 1 file changed, 139 insertions(+), 2 deletions

[PATCH v1 8/9] selftests/powerpc/dexcr: Add chdexcr utility

2024-04-17 Thread Benjamin Gray
Adds a utility to exercise the prctl DEXCR inheritance in the shell. Supports setting and clearing each aspect. Signed-off-by: Benjamin Gray --- .../selftests/powerpc/dexcr/.gitignore| 1 + .../testing/selftests/powerpc/dexcr/Makefile | 2 +- .../testing/selftests/powerpc/dexcr

[PATCH v1 7/9] selftests/powerpc/dexcr: Add DEXCR config details to lsdexcr

2024-04-17 Thread Benjamin Gray
Now that the DEXCR can be configured with prctl, add a section in lsdexcr that explains why each aspect is set the way it is. Signed-off-by: Benjamin Gray --- .../testing/selftests/powerpc/dexcr/lsdexcr.c | 113 +- 1 file changed, 111 insertions(+), 2 deletions(-) diff --git

[PATCH v1 6/9] selftests/powerpc/dexcr: Attempt to enable NPHIE in hashchk selftest

2024-04-17 Thread Benjamin Gray
Now that a process can control its DEXCR to some extent, make the hashchk tests more reliable by explicitly setting the local and onexec NPHIE aspect. Signed-off-by: Benjamin Gray --- tools/testing/selftests/powerpc/dexcr/hashchk_test.c | 8 +++- 1 file changed, 7 insertions(+), 1 deletion

[PATCH v1 5/9] selftests/powerpc/dexcr: Add DEXCR prctl interface test

2024-04-17 Thread Benjamin Gray
Some basic tests of the prctl interface of the DEXCR. Signed-off-by: Benjamin Gray --- .../selftests/powerpc/dexcr/.gitignore| 1 + .../testing/selftests/powerpc/dexcr/Makefile | 4 +- tools/testing/selftests/powerpc/dexcr/dexcr.c | 40 tools/testing/selftests/powerpc/dexcr

[PATCH v1 3/9] powerpc/dexcr: Reset DEXCR value across exec

2024-04-17 Thread Benjamin Gray
binaries that expect hash instructions to act as NOPs could configure the reset value of the container root to control the default reset value for all members of the container. Signed-off-by: Benjamin Gray --- This differs from the previous iterations by making the reset value totally independent

[PATCH v1 4/9] powerpc/dexcr: Add DEXCR prctl interface

2024-04-17 Thread Benjamin Gray
or in future). The getter shows the current state of the process config, and the setter allows setting/clearing the aspect. Signed-off-by: Benjamin Gray --- I'm intentionally trying to avoid saying 'enabling' or 'disabling' the aspect, as that could be confusing when the aspects themselves may

[PATCH v1 1/9] selftests/powerpc/dexcr: Add -no-pie to hashchk tests

2024-04-17 Thread Benjamin Gray
added, -no-pie is also required. Fixes: ca64da7574f8 ("selftests/powerpc/dexcr: Add hashst/hashchk test") Signed-off-by: Benjamin Gray --- This is not related to features introduced in this series, just fixes the test added in the static DEXCR series. --- tools/testing/selftests/pow

[PATCH v1 2/9] powerpc/dexcr: Track the DEXCR per-process

2024-04-17 Thread Benjamin Gray
aspects will synchronize upon returning to userspace). Signed-off-by: Benjamin Gray --- arch/powerpc/include/asm/processor.h | 1 + arch/powerpc/kernel/process.c| 10 ++ arch/powerpc/kernel/ptrace/ptrace-view.c | 7 +-- 3 files changed, 12 insertions(+), 6 deletions

[PATCH v1 0/9] Add dynamic DEXCR support

2024-04-17 Thread Benjamin Gray
. These features could be added in a future series (or the next version of this one :) ) though. Benjamin Gray (9): selftests/powerpc/dexcr: Add -no-pie to hashchk tests powerpc/dexcr: Track the DEXCR per-process powerpc/dexcr: Reset DEXCR value across exec powerpc/dexcr: Add DEXCR prctl interface

[PATCH v1] powerpc: Error on assembly warnings

2024-03-25 Thread Benjamin Gray
as the immediate value 5. To prevent this in assembly files and inline assembly, add the -fatal-warnings option to assembler invocations. Signed-off-by: Benjamin Gray --- arch/powerpc/Kbuild | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/Kbuild b/arch/powerpc

[PATCH v2 3/3] powerpc/code-patching: Restore 32-bit patching performance

2024-03-25 Thread Benjamin Gray
flushing selection. [1]: https://lore.kernel.org/all/77fdcdeb-4af5-4ad0-a4c6-57bf0762d...@csgroup.eu/ Suggested-by: Christophe Leroy Signed-off-by: Benjamin Gray --- v2: * New in v2 I think Suggested-by is an appropriate tag. The patch is Christophe's from the link, I just added the commit

[PATCH v2 1/3] powerpc/code-patching: Introduce open_patch_window()/close_patch_window()

2024-03-25 Thread Benjamin Gray
-by: Benjamin Gray --- v1: https://lore.kernel.org/all/20240315025937.407590-1-bg...@linux.ibm.com/ This design can be readily extended to remap the writable page to another physical page without incurring all of the entry and exit overhead. But that might have problems with spending too long

[PATCH v2 2/3] powerpc/code-patching: Convert to open_patch_window()/close_patch_window()

2024-03-25 Thread Benjamin Gray
and flushing beyond the changes they make in the patching window. Signed-off-by: Benjamin Gray --- v2: * Removed an outdated comment about syncing --- arch/powerpc/lib/code-patching.c | 179 +++ 1 file changed, 15 insertions(+), 164 deletions(-) diff --git a/arch

Re: [PATCH v1 2/2] powerpc64/dexcr: Enable PHIE on all CPUs

2024-03-24 Thread Benjamin Gray
OK, so I compile for corenet64 but not corenet32 apparently. I'll fix the shift overflow in the next round.

[PATCH v3 5/5] powerpc/code-patching: Add boot selftest for data patching

2024-03-24 Thread Benjamin Gray
Extend the code patching selftests with some basic coverage of the new data patching variants too. Signed-off-by: Benjamin Gray --- v3: * New in v3 --- arch/powerpc/lib/test-code-patching.c | 36 +++ 1 file changed, 36 insertions(+) diff --git a/arch/powerpc/lib/test

[PATCH v3 1/5] powerpc/code-patching: Add generic memory patching

2024-03-24 Thread Benjamin Gray
-by: Benjamin Gray --- v3: * Rename from *_memory to *_mem * Change type of ppc32 patch_uint() address to void* * Explain introduction of val32 for big endian * Some formatting v2: * Deduplicate patch_32() definition * Use u32 for val32 * Remove noinline --- arch/powerpc/include/asm

[PATCH v3 4/5] powerpc/32: Convert patch_instruction() to patch_uint()

2024-03-24 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 v3 0/5] Add generic data patching functions

2024-03-24 Thread Benjamin Gray
: * Addressed the v1 review actions * Removed noinline (for now) v2: https://patchwork.ozlabs.org/project/linuxppc-dev/cover/20231016050147.115686-1-bg...@linux.ibm.com/ v1: https://patchwork.ozlabs.org/project/linuxppc-dev/cover/20230207015643.590684-1-bg...@linux.ibm.com/ Benjamin Gray (5

[PATCH v3 2/5] powerpc/code-patching: Add data patch alignment check

2024-03-24 Thread Benjamin Gray
The new data patching still needs to be aligned within a cacheline too for the flushes to work correctly. To simplify this requirement, we just say data patches must be aligned. Detect when data patching is not aligned, returning an invalid argument error. Signed-off-by: Benjamin Gray --- v3

[PATCH v3 3/5] powerpc/64: Convert patch_instruction() to patch_u32()

2024-03-24 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 1/2] powerpc/code-patching: Test patch_instructions() during boot

2024-03-24 Thread Benjamin Gray
-by: Benjamin Gray --- v1: https://lore.kernel.org/all/20240315025736.404867-1-bg...@linux.ibm.com/ v2: * Shrink the code array to reduce frame size. It still crosses a page, and 32 vs 256 words is unlikely to make a difference in test coverage otherwise. --- arch/powerpc/lib/test-code

[PATCH v2 2/2] powerpc/code-patching: Use dedicated memory routines for patching

2024-03-24 Thread Benjamin Gray
does. Signed-off-by: Benjamin Gray --- v2: * Fix typo in EAA (from EEA) * Fix references to quadrant number (0, not 1) * Use copy_to_kernel_nofault() over custom memcpy * Drop custom memcpy optimisation patch --- arch/powerpc/lib/code-patching.c | 31

[PATCH v1 1/2] powerpc64/dexcr: Compile kernel with privileged hash instructions

2024-03-24 Thread Benjamin Gray
says they are inserted for Power8 or higher). Signed-off-by: Benjamin Gray --- arch/powerpc/Makefile | 3 +++ arch/powerpc/platforms/Kconfig.cputype | 12 2 files changed, 15 insertions(+) diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile index

[PATCH v1 2/2] powerpc64/dexcr: Enable PHIE on all CPUs

2024-03-24 Thread Benjamin Gray
-by: Benjamin Gray --- This patch is probably incompatible with the per-task DEXCR tracking in the userspace DEXCR series, but I'll fix up whichever one lands last. I tested on a Power10 (TCG and KVM) and Power9. I also tried enabling ftrace; no apparent issues, and the trace probes were definitely

Re: [PATCH v1 1/3] powerpc/code-patching: Test patch_instructions() during boot

2024-03-17 Thread Benjamin Gray
User-Agent: Evolution 3.50.4 (3.50.4-1.fc39) X-Trend-IP-HD: ip=[9.192.253.14]helo={ozlabs.au.ibm.com}sender=(bg...@linux.ibm.com)recipient= On Mon, 2024-03-18 at 08:38 +1100, Benjamin Gray wrote: > On Fri, 2024-03-15 at 07:14 +, Christophe Leroy wrote: > >=20 > >=20 >

Re: [PATCH v1 1/3] powerpc/code-patching: Test patch_instructions() during boot

2024-03-17 Thread Benjamin Gray
On Mon, 2024-03-18 at 08:38 +1100, Benjamin Gray wrote: > On Fri, 2024-03-15 at 07:14 +, Christophe Leroy wrote: > > > > > > Le 15/03/2024 à 03:57, Benjamin Gray a écrit : > > > patch_instructions() introduces new behaviour with a couple of &g

Re: [PATCH v1 3/3] powerpc/code-patching: Optimise patch_memcpy() to 4 byte chunks

2024-03-17 Thread Benjamin Gray
On Fri, 2024-03-15 at 06:39 +, Christophe Leroy wrote: > > > Le 15/03/2024 à 03:57, Benjamin Gray a écrit : > > As we are patching instructions, we can assume the length is a > > multiple > > of 4 and the destination address is aligned. > > > > Atomi

Re: [PATCH v1 2/3] powerpc/code-patching: Use dedicated memory routines for patching

2024-03-17 Thread Benjamin Gray
On Fri, 2024-03-15 at 06:36 +, Christophe Leroy wrote: > > > Le 15/03/2024 à 03:57, Benjamin Gray a écrit : > > The patching page set up as a writable alias may be in quadrant 1 > > (userspace) if the temporary mm path is used. This causes sanitiser > > failure

Re: [PATCH v1 1/3] powerpc/code-patching: Test patch_instructions() during boot

2024-03-17 Thread Benjamin Gray
On Fri, 2024-03-15 at 07:14 +, Christophe Leroy wrote: > > > Le 15/03/2024 à 03:57, Benjamin Gray a écrit : > > patch_instructions() introduces new behaviour with a couple of > > variations. Test each case of > > > >    * a repeated 32-bit instruction, >

Re: [PATCH v1 2/2] powerpc/code-patching: Convert to open_patch_window()/close_patch_window()

2024-03-17 Thread Benjamin Gray
On Sat, 2024-03-16 at 10:10 +, Christophe Leroy wrote: > > > Le 15/03/2024 à 09:38, Christophe Leroy a écrit : > > > > > > Le 15/03/2024 à 03:59, Benjamin Gray a écrit : > > > The existing patching alias page setup and teardown sections can > > &g

Re: [PATCH v1 2/3] powerpc/code-patching: Use dedicated memory routines for patching

2024-03-14 Thread Benjamin Gray
Also supersedes https://lore.kernel.org/all/20240213043638.168048-1-bg...@linux.ibm.com/

[PATCH v1 2/2] powerpc/code-patching: Convert to open_patch_window()/close_patch_window()

2024-03-14 Thread Benjamin Gray
and flushing beyond the changes they make in the patching window. Signed-off-by: Benjamin Gray --- arch/powerpc/lib/code-patching.c | 180 +++ 1 file changed, 16 insertions(+), 164 deletions(-) diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code

[PATCH v1 1/2] powerpc/code-patching: Introduce open_patch_window()/close_patch_window()

2024-03-14 Thread Benjamin Gray
-by: Benjamin Gray --- This design can be readily extended to remap the writable page to another physical page without incurring all of the entry and exit overhead. But that might have problems with spending too long in an interrupts disabled context, so I've left it out for now. --- arch/powerpc/lib/code

[PATCH v1 3/3] powerpc/code-patching: Optimise patch_memcpy() to 4 byte chunks

2024-03-14 Thread Benjamin Gray
As we are patching instructions, we can assume the length is a multiple of 4 and the destination address is aligned. Atomicity of patching a prefixed instruction is not a concern, as the original implementation doesn't provide it anyway. Signed-off-by: Benjamin Gray --- arch/powerpc/lib/code

[PATCH v1 2/3] powerpc/code-patching: Use dedicated memory routines for patching

2024-03-14 Thread Benjamin Gray
does. Signed-off-by: Benjamin Gray --- The patch_memcpy() can be optimised to 4 bytes at a time assuming the same requirements as regular instruction patching are being followed for the 'copy sequence of instructions' mode (i.e., they actually are instructions following instruction alignment

[PATCH v1 1/3] powerpc/code-patching: Test patch_instructions() during boot

2024-03-14 Thread Benjamin Gray
-by: Benjamin Gray --- arch/powerpc/lib/test-code-patching.c | 92 +++ 1 file changed, 92 insertions(+) diff --git a/arch/powerpc/lib/test-code-patching.c b/arch/powerpc/lib/test-code-patching.c index c44823292f73..35a3756272df 100644 --- a/arch/powerpc/lib/test-code-patching.c

Re: BUG: KASAN: vmalloc-out-of-bounds in memset32 (bpf_prog_pack_free)

2024-02-22 Thread Benjamin Gray
On Wed, 2024-01-31 at 11:46 +, Christophe Leroy wrote: > Hi, > > Got the following BUG while loading module test_bpf.ko > > No time to investigate for now. > > root@vgoip:~# insmod test_bpf.ko > [  263.409030] > == > [ 

Re: [PATCH] powerpc/ftrace: Ignore ftrace locations in exit text sections

2024-02-12 Thread Benjamin Gray
mlinux.lds.S > b/arch/powerpc/kernel/vmlinux.lds.S > index 1c5970df3233..9c376ae6857d 100644 > --- a/arch/powerpc/kernel/vmlinux.lds.S > +++ b/arch/powerpc/kernel/vmlinux.lds.S > @@ -281,7 +281,9 @@ SECTIONS >   * to deal with references from __bug_table >   */ >   .exit.text : AT(ADDR

[PATCH] powerpc/code-patching: Disable KASAN in __patch_instructions()

2024-02-12 Thread Benjamin Gray
The memset/memcpy functions are by default instrumented by KASAN, which complains about user memory access when using a poking page in userspace. Using a userspace address is expected though, so don't instrument with KASAN for this function. Signed-off-by: Benjamin Gray --- I tried to replace

Re: [PATCH] powerpc/kasan: Limit KASAN thread size increase to 32KB

2024-02-12 Thread Benjamin Gray
a 64-bit KASAN build. > > So only increase the stack for KASAN if the stack size is < 32KB. > > Link: > https://lore.kernel.org/linuxppc-dev/bug-207129-206...@https.bugzilla.kernel.org%2F/ > Reported-by: Spoorthy > Reported-by: Benjamin Gray > Fixes: 18f14afe28

Re: [PATCH] powerpc/kasan: Limit KASAN thread size increase to 32KB

2024-02-12 Thread Benjamin Gray

[PATCH] powerpc64/kasan: Pass virtual addresses to kasan_init_phys_region()

2024-02-11 Thread Benjamin Gray
) of the kasan_mem_to_shadow() calculation are the same for the real and virtual addresses, so the actual PTE value is the same in the end. But virtual addresses are the intended input, so fix it. Signed-off-by: Benjamin Gray --- arch/powerpc/mm/kasan/init_book3e_64.c | 2 +- arch/powerpc/mm

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

2024-02-04 Thread Benjamin Gray
On Thu, 2023-11-30 at 15:55 +0530, Naveen N Rao wrote: > On Mon, Oct 16, 2023 at 04:01:45PM +1100, Benjamin Gray wrote: > > patch_instruction() is designed for patching instructions in > > otherwise > > readonly memory. Other consumers also sometimes need to patch > > r

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

[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 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 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 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 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 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 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 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 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 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 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 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 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 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

[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 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

[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 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 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 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

[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 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 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 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 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 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

[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

Re: [PATCH 2/2] powerpc/xmon: use KSYM_NAME_LEN in array size

2023-08-02 Thread Benjamin Gray
On 30/5/23 10:54 pm, Miguel Ojeda wrote: Side-note: in `get_function_bounds()`, I see `kallsyms_lookup()` being used, but the name seems discarded? Can `kallsyms_lookup_size_offset()` be used instead, thus avoiding the usage of the buffer there to begin with? I'm not familiar with the kallsyms

[PATCH 7/7] perf/hw_breakpoint: Remove arch breakpoint hooks

2023-07-31 Thread Benjamin Gray
PowerPC was the only user of these hooks, and has been refactored to no longer require them. There is no need to keep them around, so remove them to reduce complexity. Signed-off-by: Benjamin Gray --- include/linux/hw_breakpoint.h | 3 --- kernel/events/hw_breakpoint.c | 28

[PATCH 6/7] selftests/powerpc/ptrace: Update ptrace-perf watchpoint selftest

2023-07-31 Thread Benjamin Gray
Now that ptrace and perf are no longer exclusive, update the test to exercise interesting interactions. An assembly file is used for the children to allow precise instruction choice and addresses, while avoiding any compiler quirks. Signed-off-by: Benjamin Gray --- .../testing/selftests

[PATCH 5/7] powerpc/watchpoints: Remove ptrace/perf exclusion tracking

2023-07-31 Thread Benjamin Gray
watchpoint is involved. Signed-off-by: Benjamin Gray --- Whether it's a _good_ idea to mix ptrace and perf is another thing entirely mind... . But they are not inherently incompatible. --- arch/powerpc/kernel/hw_breakpoint.c | 249 +--- 1 file changed, 1 insertion(+), 248

[PATCH 4/7] powerpc/watchpoints: Simplify watchpoint reinsertion

2023-07-31 Thread Benjamin Gray
We only remove watchpoints when they have the perf_single_step flag set, so we can reinsert them during the first iteration. Signed-off-by: Benjamin Gray --- arch/powerpc/kernel/hw_breakpoint.c | 12 +--- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/arch/powerpc/kernel

[PATCH 1/7] powerpc/watchpoints: Explain thread_change_pc() more

2023-07-31 Thread Benjamin Gray
The behaviour of the thread_change_pc() function is a bit cryptic without being more familiar with how the watchpoint logic handles perf's after-execute semantics. Expand the comment to explain why we can re-insert the breakpoint and unset the perf_single_step flag. Signed-off-by: Benjamin Gray

[PATCH 3/7] powerpc/watchpoints: Track perf single step directly on the breakpoint

2023-07-31 Thread Benjamin Gray
dabr_instruction() without a way to check their validity. This patch moves the tracking of this information to the breakpoint itself. This means we no longer have to do anything special to clean up. Signed-off-by: Benjamin Gray --- arch/powerpc/include/asm/hw_breakpoint.h | 1 + arch/powerpc/include

[PATCH 2/7] powerpc/watchpoints: Don't track info persistently

2023-07-31 Thread Benjamin Gray
just use the local bp array to track whether we are ignoring a breakpoint. Signed-off-by: Benjamin Gray --- arch/powerpc/kernel/hw_breakpoint.c | 60 +++-- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/arch/powerpc/kernel/hw_breakpoint.c b/arch/powerpc

[PATCH 0/7] Rework perf and ptrace watchpoint tracking

2023-07-31 Thread Benjamin Gray
. It also simplifies handling of ptrace and perf breakpoints, making insertion less restrictive. If merged, it allows several arch hooks that PowerPC was the sole user of to be removed. Benjamin Gray (7): powerpc/watchpoints: Explain thread_change_pc() more powerpc/watchpoints: Don't t

[PATCH v1 3/4] selftests/powerpc/ptrace: Fix typo in pid_max search error

2023-07-24 Thread Benjamin Gray
pid_max_addr() searches for the 'pid_max' symbol in /proc/kallsyms, and prints an error if it cannot find it. The error message has a typo, calling it pix_max. Signed-off-by: Benjamin Gray --- tools/testing/selftests/powerpc/ptrace/ptrace-perf-hwbreak.c | 2 +- 1 file changed, 1 insertion(+), 1

[PATCH v1 2/4] selftests/powerpc/ptrace: Explain why tests are skipped

2023-07-24 Thread Benjamin Gray
(), with appropriate descriptions of why the test is being skipped. This gives a general idea of why a test is skipped, which can be looked into further if it doesn't make sense. Signed-off-by: Benjamin Gray --- tools/testing/selftests/powerpc/ptrace/child.h | 4 ++-- tools/testing

[PATCH v1 4/4] selftests/powerpc/ptrace: Declare test temporary variables as volatile

2023-07-24 Thread Benjamin Gray
of the dependency on compiler behaviour. Signed-off-by: Benjamin Gray --- .../selftests/powerpc/ptrace/ptrace-hwbreak.c | 24 +-- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/powerpc/ptrace/ptrace-hwbreak.c b/tools/testing/selftests/powerpc

[PATCH v1 1/4] Documentation/powerpc: Fix ptrace request names

2023-07-24 Thread Benjamin Gray
The documented ptrace request names are currently wrong/incomplete. Fix this to improve correctness and searchability. Signed-off-by: Benjamin Gray --- Documentation/powerpc/ptrace.rst | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Documentation/powerpc/ptrace.rst b

[PATCH v1 0/4] Improve ptrace selftest usability

2023-07-24 Thread Benjamin Gray
While trying to test changes to the breakpoint implementation in the kernel, I tried to run the ptrace tests and met many unexplained skips and failures. This series addresses the pain points of trying to run these tests and learn what they are doing. Benjamin Gray (4): Documentation/powerpc

[PATCH] powerpc/kasan: Disable KCOV in KASAN code

2023-07-09 Thread Benjamin Gray
Signed-off-by: Benjamin Gray --- The generic makefile has other disabled sanitisers / hooks, but this patch is just an upstream of fixing a blocking issue for running syzkaller. The blocker is resolved by this; kernels stop hanging on boot with KCOV + KASAN. This works as an alternative to https

Re: [PATCH] powerpc/powermac: Use early_* IO variants in via_calibrate_decr

2023-07-06 Thread Benjamin Gray
On Thu, 2023-07-06 at 11:08 +1000, Benjamin Gray wrote: > The issue is pre-existing, but is surfaced by commit 721255b9826b > ("genirq: Use a maple tree for interrupt descriptor management"). > It's not clear to me why this causes it to surface. >From the thread chain

  1   2   3   4   >