]> www.infradead.org Git - users/jedix/linux-maple.git/commit
powerpc/code-patching: Add generic memory patching
authorBenjamin Gray <bgray@linux.ibm.com>
Wed, 15 May 2024 02:44:41 +0000 (12:44 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 21 Aug 2024 10:15:12 +0000 (20:15 +1000)
commite6b8940e7e80cdfe98ba8493214922998920dd9c
treea119cdae4ded82a1736c23ee25e27bdf3c423537
parenta540ad3e386f8f84bc6d600b93792a50861a81ef
powerpc/code-patching: Add generic memory patching

patch_instruction() is designed for patching instructions in otherwise
readonly memory. Other consumers also sometimes need to patch readonly
memory, so have abused patch_instruction() for arbitrary data patches.

This is a problem on ppc64 as patch_instruction() decides on the patch
width using the 'instruction' opcode to see if it's a prefixed
instruction. Data that triggers this can lead to larger writes, possibly
crossing a page boundary and failing the write altogether.

Introduce patch_uint(), and patch_ulong(), with aliases patch_u32(), and
patch_u64() (on ppc64) designed for aligned data patches. The patch
size is now determined by the called function, and is passed as an
additional parameter to generic internals.

While the instruction flushing is not required for data patches, it
remains unconditional in this patch. A followup series is possible if
benchmarking shows fewer flushes gives an improvement in some
data-patching workload.

ppc32 does not support prefixed instructions, so is unaffected by the
original issue. Care is taken in not exposing the size parameter in the
public (non-static) interface, so the compiler can const-propagate it
away.

Signed-off-by: Benjamin Gray <bgray@linux.ibm.com>
Reviewed-by: Hari Bathini <hbathini@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20240515024445.236364-2-bgray@linux.ibm.com
arch/powerpc/include/asm/code-patching.h
arch/powerpc/lib/code-patching.c