]> git.ipfire.org Git - thirdparty/linux.git/commit
arm64: probes: Cleanup kprobes endianness conversions
authorMark Rutland <mark.rutland@arm.com>
Tue, 8 Oct 2024 15:58:50 +0000 (16:58 +0100)
committerCatalin Marinas <catalin.marinas@arm.com>
Tue, 15 Oct 2024 17:16:20 +0000 (18:16 +0100)
commitdd0eb50e7c71fdd74f2ab0ef4b60bd6b27bbc670
treecf1a375b008a60943d7885ff970a392a651c7776
parent6105c5d46d0b39ccf01e329fc4449ba840c2937d
arm64: probes: Cleanup kprobes endianness conversions

The core kprobes code uses kprobe_opcode_t for the in-memory
representation of an instruction, using 'kprobe_opcode_t *' for XOL
slots. As arm64 instructions are always little-endian 32-bit values,
kprobes_opcode_t should be __le32, but at the moment kprobe_opcode_t
is typedef'd to u32.

Today there is no functional issue as we convert values via
cpu_to_le32() and le32_to_cpu() where necessary, but these conversions
are inconsistent with the types used, causing sparse warnings:

|   CHECK   arch/arm64/kernel/probes/kprobes.c
| arch/arm64/kernel/probes/kprobes.c:102:21: warning: cast to restricted __le32
|   CHECK   arch/arm64/kernel/probes/decode-insn.c
| arch/arm64/kernel/probes/decode-insn.c:122:46: warning: cast to restricted __le32
| arch/arm64/kernel/probes/decode-insn.c:124:50: warning: cast to restricted __le32
| arch/arm64/kernel/probes/decode-insn.c:136:31: warning: cast to restricted __le32

Improve this by making kprobes_opcode_t a typedef for __le32 and
consistently using this for pointers to executable instructions. With
this change we can rely on the type system to tell us where conversions
are necessary.

Since kprobe::opcode is changed from u32 to __le32, the existing
le32_to_cpu() converion moves from the point this is initialized (in
arch_prepare_kprobe()) to the points this is consumed when passed to
a handler or text patching function. As kprobe::opcode isn't altered or
consumed elsewhere, this shouldn't result in a functional change.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20241008155851.801546-6-mark.rutland@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
arch/arm64/include/asm/probes.h
arch/arm64/kernel/probes/decode-insn.c
arch/arm64/kernel/probes/kprobes.c