Skip to content

Commit 16ef976

Browse files
committed
powerpc: Add ppc_inst_as_u64()
The code patching code wants to get the value of a struct ppc_inst as a u64 when the instruction is prefixed, so we can pass the u64 down to __put_user_asm() and write it with a single store. The optprobes code wants to load a struct ppc_inst as an immediate into a register so it is useful to have it as a u64 to use the existing helper function. Currently this is a bit awkward because the value differs based on the CPU endianness, so add a helper to do the conversion. This fixes the usage in arch_prepare_optimized_kprobe() which was previously incorrect on big endian. Fixes: 650b55b ("powerpc: Add prefixed instructions to instruction data type") Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Tested-by: Jordan Niethe <jniethe5@gmail.com> Link: https://lore.kernel.org/r/20200526072630.2487363-1-mpe@ellerman.id.au
1 parent c5ff46d commit 16ef976

3 files changed

Lines changed: 11 additions & 9 deletions

File tree

‎arch/powerpc/include/asm/inst.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ static inline struct ppc_inst *ppc_inst_next(void *location, struct ppc_inst *va
113113
return location + ppc_inst_len(tmp);
114114
}
115115

116+
static inline u64 ppc_inst_as_u64(struct ppc_inst x)
117+
{
118+
#ifdef CONFIG_CPU_LITTLE_ENDIAN
119+
return (u64)ppc_inst_suffix(x) << 32 | ppc_inst_val(x);
120+
#else
121+
return (u64)ppc_inst_val(x) << 32 | ppc_inst_suffix(x);
122+
#endif
123+
}
124+
116125
int probe_user_read_inst(struct ppc_inst *inst,
117126
struct ppc_inst __user *nip);
118127

‎arch/powerpc/kernel/optprobes.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op, struct kprobe *p)
283283
* 3. load instruction to be emulated into relevant register, and
284284
*/
285285
temp = ppc_inst_read((struct ppc_inst *)p->ainsn.insn);
286-
patch_imm64_load_insns(ppc_inst_val(temp) | ((u64)ppc_inst_suffix(temp) << 32),
287-
4, buff + TMPL_INSN_IDX);
286+
patch_imm64_load_insns(ppc_inst_as_u64(temp), 4, buff + TMPL_INSN_IDX);
288287

289288
/*
290289
* 4. branch back from trampoline

‎arch/powerpc/lib/code-patching.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@ static int __patch_instruction(struct ppc_inst *exec_addr, struct ppc_inst instr
2727
if (!ppc_inst_prefixed(instr)) {
2828
__put_user_asm(ppc_inst_val(instr), patch_addr, err, "stw");
2929
} else {
30-
#ifdef CONFIG_CPU_LITTLE_ENDIAN
31-
__put_user_asm((u64)ppc_inst_suffix(instr) << 32 |
32-
ppc_inst_val(instr), patch_addr, err, "std");
33-
#else
34-
__put_user_asm((u64)ppc_inst_val(instr) << 32 |
35-
ppc_inst_suffix(instr), patch_addr, err, "std");
36-
#endif
30+
__put_user_asm(ppc_inst_as_u64(instr), patch_addr, err, "std");
3731
}
3832

3933
if (err)

0 commit comments

Comments
 (0)