Skip to content

Commit 52fa82c

Browse files
Peter Zijlstrasuryasaimadhu
authored andcommitted
x86: Add insn_decode_kernel()
Add a helper to decode kernel instructions; there's no point in endlessly repeating those last two arguments. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 2304d14 commit 52fa82c

File tree

7 files changed

+10
-6
lines changed

7 files changed

+10
-6
lines changed

arch/x86/include/asm/insn.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ enum insn_mode {
150150

151151
extern int insn_decode(struct insn *insn, const void *kaddr, int buf_len, enum insn_mode m);
152152

153+
#define insn_decode_kernel(_insn, _ptr) insn_decode((_insn), (_ptr), MAX_INSN_SIZE, INSN_MODE_KERN)
154+
153155
/* Attribute will be determined after getting ModRM (for opcode groups) */
154156
static inline void insn_get_attribute(struct insn *insn)
155157
{

arch/x86/kernel/alternative.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@ static void text_poke_loc_init(struct text_poke_loc *tp, void *addr,
12801280
if (!emulate)
12811281
emulate = opcode;
12821282

1283-
ret = insn_decode(&insn, emulate, MAX_INSN_SIZE, INSN_MODE_KERN);
1283+
ret = insn_decode_kernel(&insn, emulate);
12841284

12851285
BUG_ON(ret < 0);
12861286
BUG_ON(len != insn.length);

arch/x86/kernel/cpu/mce/severity.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ static bool is_copy_from_user(struct pt_regs *regs)
225225
if (copy_from_kernel_nofault(insn_buf, (void *)regs->ip, MAX_INSN_SIZE))
226226
return false;
227227

228-
ret = insn_decode(&insn, insn_buf, MAX_INSN_SIZE, INSN_MODE_KERN);
228+
ret = insn_decode_kernel(&insn, insn_buf);
229229
if (ret < 0)
230230
return false;
231231

arch/x86/kernel/kprobes/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static int can_probe(unsigned long paddr)
285285
if (!__addr)
286286
return 0;
287287

288-
ret = insn_decode(&insn, (void *)__addr, MAX_INSN_SIZE, INSN_MODE_KERN);
288+
ret = insn_decode_kernel(&insn, (void *)__addr);
289289
if (ret < 0)
290290
return 0;
291291

@@ -322,7 +322,7 @@ int __copy_instruction(u8 *dest, u8 *src, u8 *real, struct insn *insn)
322322
MAX_INSN_SIZE))
323323
return 0;
324324

325-
ret = insn_decode(insn, dest, MAX_INSN_SIZE, INSN_MODE_KERN);
325+
ret = insn_decode_kernel(insn, dest);
326326
if (ret < 0)
327327
return 0;
328328

arch/x86/kernel/kprobes/opt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ static int can_optimize(unsigned long paddr)
324324
if (!recovered_insn)
325325
return 0;
326326

327-
ret = insn_decode(&insn, (void *)recovered_insn, MAX_INSN_SIZE, INSN_MODE_KERN);
327+
ret = insn_decode_kernel(&insn, (void *)recovered_insn);
328328
if (ret < 0)
329329
return 0;
330330

arch/x86/kernel/traps.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ static enum kernel_gp_hint get_kernel_gp_address(struct pt_regs *regs,
504504
MAX_INSN_SIZE))
505505
return GP_NO_HINT;
506506

507-
ret = insn_decode(&insn, insn_buf, MAX_INSN_SIZE, INSN_MODE_KERN);
507+
ret = insn_decode_kernel(&insn, insn_buf);
508508
if (ret < 0)
509509
return GP_NO_HINT;
510510

tools/arch/x86/include/asm/insn.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ enum insn_mode {
150150

151151
extern int insn_decode(struct insn *insn, const void *kaddr, int buf_len, enum insn_mode m);
152152

153+
#define insn_decode_kernel(_insn, _ptr) insn_decode((_insn), (_ptr), MAX_INSN_SIZE, INSN_MODE_KERN)
154+
153155
/* Attribute will be determined after getting ModRM (for opcode groups) */
154156
static inline void insn_get_attribute(struct insn *insn)
155157
{

0 commit comments

Comments
 (0)