]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
powerpc/code-patching: Add data patch alignment check
authorBenjamin Gray <bgray@linux.ibm.com>
Wed, 15 May 2024 02:44:42 +0000 (12:44 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 21 Aug 2024 10:15:12 +0000 (20:15 +1000)
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 <bgray@linux.ibm.com>
Reviewed-by: Hari Bathini <hbathini@linux.ibm.com>
Acked-by: Naveen N Rao <naveen@kernel.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20240515024445.236364-3-bgray@linux.ibm.com
arch/powerpc/include/asm/code-patching.h
arch/powerpc/lib/code-patching.c

index 21a36e2c4e262446b95cc8f57189f985384aebf3..e7f14720f630724553b108b6b3a1da0225385660 100644 (file)
@@ -95,11 +95,17 @@ int patch_ulong(void *addr, unsigned long val);
 
 static inline int patch_uint(void *addr, unsigned int val)
 {
+       if (!IS_ALIGNED((unsigned long)addr, sizeof(unsigned int)))
+               return -EINVAL;
+
        return patch_instruction(addr, ppc_inst(val));
 }
 
 static inline int patch_ulong(void *addr, unsigned long val)
 {
+       if (!IS_ALIGNED((unsigned long)addr, sizeof(unsigned long)))
+               return -EINVAL;
+
        return patch_instruction(addr, ppc_inst(val));
 }
 
index 7f423fa3c51be8806ce6796e0d1fa38a46aaf7e2..acdab294b340a89c5ce84b17b721745d3a10ac4d 100644 (file)
@@ -386,12 +386,18 @@ NOKPROBE_SYMBOL(patch_instruction);
 
 int patch_uint(void *addr, unsigned int val)
 {
+       if (!IS_ALIGNED((unsigned long)addr, sizeof(unsigned int)))
+               return -EINVAL;
+
        return patch_mem(addr, val, false);
 }
 NOKPROBE_SYMBOL(patch_uint);
 
 int patch_ulong(void *addr, unsigned long val)
 {
+       if (!IS_ALIGNED((unsigned long)addr, sizeof(unsigned long)))
+               return -EINVAL;
+
        return patch_mem(addr, val, true);
 }
 NOKPROBE_SYMBOL(patch_ulong);