Skip to content

Commit

Permalink
csky: kprobe: Fixup code in simulate without 'long'
Browse files Browse the repository at this point in the history
The type of 'val' is 'unsigned long' in simulate_blz32, so 'val < 0'
can't be true.

Cast 'val' to 'long' here to determine branch token or not,

Fixup instructions: bnezad32, bhsz32, bhz32, blsz32, blz32

Link: https://lore.kernel.org/linux-csky/CAJF2gTQjKXR9gpo06WAWG1aquiT87mATiMGorXs6ChxOxoe90Q@mail.gmail.com/T/#t
Signed-off-by: Guo Ren <[email protected]>
Co-developed-by: Menglong Dong <[email protected]>
Signed-off-by: Menglong Dong <[email protected]>
  • Loading branch information
guoren83 committed Feb 27, 2021
1 parent af94002 commit 8dcbc61
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions arch/csky/kernel/probes/simulate-insn.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ void __kprobes
simulate_bnezad32(u32 opcode, long addr, struct pt_regs *regs)
{
unsigned long tmp = opcode & 0x1f;
unsigned long val;
long val;

csky_insn_reg_get_val(regs, tmp, &val);
csky_insn_reg_get_val(regs, tmp, (unsigned long *)&val);

val -= 1;

Expand All @@ -286,7 +286,7 @@ simulate_bnezad32(u32 opcode, long addr, struct pt_regs *regs)
} else
instruction_pointer_set(regs, addr + 4);

csky_insn_reg_set_val(regs, tmp, val);
csky_insn_reg_set_val(regs, tmp, (unsigned long)val);
}

void __kprobes
Expand All @@ -297,13 +297,11 @@ simulate_bhsz32(u32 opcode, long addr, struct pt_regs *regs)

csky_insn_reg_get_val(regs, tmp, &val);

if (val >= 0) {
if ((long) val >= 0) {
instruction_pointer_set(regs,
addr + sign_extend32((opcode & 0xffff0000) >> 15, 15));
} else
instruction_pointer_set(regs, addr + 4);

csky_insn_reg_set_val(regs, tmp, val);
}

void __kprobes
Expand All @@ -314,13 +312,11 @@ simulate_bhz32(u32 opcode, long addr, struct pt_regs *regs)

csky_insn_reg_get_val(regs, tmp, &val);

if (val > 0) {
if ((long) val > 0) {
instruction_pointer_set(regs,
addr + sign_extend32((opcode & 0xffff0000) >> 15, 15));
} else
instruction_pointer_set(regs, addr + 4);

csky_insn_reg_set_val(regs, tmp, val);
}

void __kprobes
Expand All @@ -331,13 +327,11 @@ simulate_blsz32(u32 opcode, long addr, struct pt_regs *regs)

csky_insn_reg_get_val(regs, tmp, &val);

if (val <= 0) {
if ((long) val <= 0) {
instruction_pointer_set(regs,
addr + sign_extend32((opcode & 0xffff0000) >> 15, 15));
} else
instruction_pointer_set(regs, addr + 4);

csky_insn_reg_set_val(regs, tmp, val);
}

void __kprobes
Expand All @@ -348,13 +342,11 @@ simulate_blz32(u32 opcode, long addr, struct pt_regs *regs)

csky_insn_reg_get_val(regs, tmp, &val);

if (val < 0) {
if ((long) val < 0) {
instruction_pointer_set(regs,
addr + sign_extend32((opcode & 0xffff0000) >> 15, 15));
} else
instruction_pointer_set(regs, addr + 4);

csky_insn_reg_set_val(regs, tmp, val);
}

void __kprobes
Expand Down

0 comments on commit 8dcbc61

Please sign in to comment.