Skip to contentSkip to conversation

IA64 kprobe invalidate icache of jump buffer

PATCH In review bibo, mao 2 participants 2 messages Jun 30, 2006 kprobes

lore
Share & tools
lore

bibo, mao

author
#0 lore raw

PATCH 1/1 IA64 kprobe invalidate icache of jump buffer

Hi,
Kprobe inserts breakpoint instruction in probepoint and then jumps
to instruction slot when breakpoint is hit, the instruction slot icache must be consistent with dcache. Here is the patch which invalidates instruction slot icache area in IA64 platform.
Without this patch, in some machines there will be fault when executing
instruction slot where icache content is inconsistent with dcache.

thanks
bibo,mao

 arch/ia64/kernel/kprobes.c    |   10 ++++++++++
 include/asm-i386/kprobes.h    |    1 +
 include/asm-ia64/kprobes.h    |    1 +
 include/asm-powerpc/kprobes.h |    1 +
 include/asm-sparc64/kprobes.h |    1 +
 include/asm-x86_64/kprobes.h  |    1 +
 kernel/kprobes.c              |    1 +
 7 files changed, 16 insertions(+)

-------------------------------------------------------------------------------

arch/ia64/kernel/kprobes.c +10 -0
diff -Nruap 2.6.17.org/arch/ia64/kernel/kprobes.c 2.6.17/arch/ia64/kernel/kprobes.c
@@ -456,6 +456,8 @@ void __kprobes arch_arm_kprobe(struct kp
 
 	memcpy((char *)arm_addr, &p->ainsn.insn.bundle, sizeof(bundle_t));
 	flush_icache_range(arm_addr, arm_addr + sizeof(bundle_t));
+	arm_addr = (unsigned long)&p->opcode.bundle & ~0xFULL;
+	flush_icache_range(arm_addr, arm_addr + sizeof(bundle_t));
 }
 
 void __kprobes arch_disarm_kprobe(struct kprobe *p)
@@ -468,6 +470,14 @@ void __kprobes arch_disarm_kprobe(struct
 	flush_icache_range(arm_addr, arm_addr + sizeof(bundle_t));
 }
 
+void __kprobes flush_insn_slot(struct kprobe *p)
+{
+	unsigned long arm_addr;
+
+	arm_addr = ((unsigned long)&p->opcode.bundle) & ~0xFULL;
+	flush_icache_range(arm_addr, arm_addr + sizeof(bundle_t));
+}
+
 /*
  * We are resuming execution after a single step fault, so the pt_regs
  * structure reflects the register state after we executed the instruction
include/asm-i386/kprobes.h +1 -0
diff -Nruap 2.6.17.org/include/asm-i386/kprobes.h 2.6.17/include/asm-i386/kprobes.h
@@ -44,6 +44,7 @@ typedef u8 kprobe_opcode_t;
 
 #define JPROBE_ENTRY(pentry)	(kprobe_opcode_t *)pentry
 #define ARCH_SUPPORTS_KRETPROBES
+#define flush_insn_slot(p)	do { } while (0)
 
 void arch_remove_kprobe(struct kprobe *p);
 void kretprobe_trampoline(void);
include/asm-ia64/kprobes.h +1 -0
diff -Nruap 2.6.17.org/include/asm-ia64/kprobes.h 2.6.17/include/asm-ia64/kprobes.h
@@ -124,5 +124,6 @@ static inline void jprobe_return(void)
 }
 extern void invalidate_stacked_regs(void);
 extern void flush_register_stack(void);
+extern void flush_insn_slot(struct kprobe *p);
 
 #endif				/* _ASM_KPROBES_H */
include/asm-powerpc/kprobes.h +1 -0
diff -Nruap 2.6.17.org/include/asm-powerpc/kprobes.h 2.6.17/include/asm-powerpc/kprobes.h
@@ -50,6 +50,7 @@ typedef unsigned int kprobe_opcode_t;
 			IS_TWI(instr) || IS_TDI(instr))
 
 #define ARCH_SUPPORTS_KRETPROBES
+#define flush_insn_slot(p)	do { } while (0)
 void kretprobe_trampoline(void);
 extern void arch_remove_kprobe(struct kprobe *p);
 
include/asm-sparc64/kprobes.h +1 -0
diff -Nruap 2.6.17.org/include/asm-sparc64/kprobes.h 2.6.17/include/asm-sparc64/kprobes.h
@@ -13,6 +13,7 @@ typedef u32 kprobe_opcode_t;
 
 #define JPROBE_ENTRY(pentry)	(kprobe_opcode_t *)pentry
 #define arch_remove_kprobe(p)	do {} while (0)
+#define flush_insn_slot(p)	do { } while (0)
 
 /* Architecture specific copy of original instruction*/
 struct arch_specific_insn {
include/asm-x86_64/kprobes.h +1 -0
diff -Nruap 2.6.17.org/include/asm-x86_64/kprobes.h 2.6.17/include/asm-x86_64/kprobes.h
@@ -43,6 +43,7 @@ typedef u8 kprobe_opcode_t;
 
 #define JPROBE_ENTRY(pentry)	(kprobe_opcode_t *)pentry
 #define ARCH_SUPPORTS_KRETPROBES
+#define flush_insn_slot(p)	do { } while (0)
 
 void kretprobe_trampoline(void);
 extern void arch_remove_kprobe(struct kprobe *p);
kernel/kprobes.c +1 -0
diff -Nruap 2.6.17.org/kernel/kprobes.c 2.6.17/kernel/kprobes.c
@@ -420,6 +420,7 @@ static int __kprobes register_aggr_kprob
 		add_aggr_kprobe(ap, old_p);
 		copy_kprobe(ap, p);
 		ret = add_new_kprobe(ap, p);
+		flush_insn_slot(ap);
 	}
 	return ret;
 }
#1 lore raw
Quoted 9 lines · mao

Hi,
Kprobe inserts breakpoint instruction in probepoint and then jumps
to instruction slot when breakpoint is hit, the instruction slot icache must be consistent with dcache. Here is the patch which invalidates instruction slot icache area in IA64 platform.
Without this patch, in some machines there will be fault when executing
instruction slot where icache content is inconsistent with dcache.

Bibo,
This patch looks lot better than your earlier one.
Please see minor comments below and once you fix them please post the same onto lkml for inclusion.

arch/ia64/kernel/kprobes.c void __kprobes arch_arm_kprobe(struct kp · line 460

Quoted 12 lines

-------------------------------------------------------------------------------

diff -Nruap 2.6.17.org/arch/ia64/kernel/kprobes.c 2.6.17/arch/ia64/kernel/kprobes.c

arch/ia64/kernel/kprobes.c +2 -0
@@ -456,6 +456,8 @@ void __kprobes arch_arm_kprobe(struct kp
 
 	memcpy((char *)arm_addr, &p->ainsn.insn.bundle, sizeof(bundle_t));
 	flush_icache_range(arm_addr, arm_addr + sizeof(bundle_t));
+	arm_addr = (unsigned long)&p->opcode.bundle & ~0xFULL;
+	flush_icache_range(arm_addr, arm_addr + sizeof(bundle_t));

Please use flush_insn_slot() instead of the above two line change and should move above memcpy() as you need to flush the jump buffer before arming the probe.

Quoted 76 lines
arch/ia64/kernel/kprobes.c +8 -0
 }
 
 void __kprobes arch_disarm_kprobe(struct kprobe *p)
@@ -468,6 +470,14 @@ void __kprobes arch_disarm_kprobe(struct
 	flush_icache_range(arm_addr, arm_addr + sizeof(bundle_t));
 }
 
+void __kprobes flush_insn_slot(struct kprobe *p)
+{
+	unsigned long arm_addr;
+
+	arm_addr = ((unsigned long)&p->opcode.bundle) & ~0xFULL;
+	flush_icache_range(arm_addr, arm_addr + sizeof(bundle_t));
+}
+
 /*
  * We are resuming execution after a single step fault, so the pt_regs
  * structure reflects the register state after we executed the instruction

diff -Nruap 2.6.17.org/include/asm-i386/kprobes.h 2.6.17/include/asm-i386/kprobes.h

include/asm-i386/kprobes.h +1 -0
@@ -44,6 +44,7 @@ typedef u8 kprobe_opcode_t;
 
 #define JPROBE_ENTRY(pentry)	(kprobe_opcode_t *)pentry
 #define ARCH_SUPPORTS_KRETPROBES
+#define flush_insn_slot(p)	do { } while (0)
 
 void arch_remove_kprobe(struct kprobe *p);
 void kretprobe_trampoline(void);

diff -Nruap 2.6.17.org/include/asm-ia64/kprobes.h 2.6.17/include/asm-ia64/kprobes.h

include/asm-ia64/kprobes.h +1 -0
@@ -124,5 +124,6 @@ static inline void jprobe_return(void)
 }
 extern void invalidate_stacked_regs(void);
 extern void flush_register_stack(void);
+extern void flush_insn_slot(struct kprobe *p);
 
 #endif				/* _ASM_KPROBES_H */

diff -Nruap 2.6.17.org/include/asm-powerpc/kprobes.h 2.6.17/include/asm-powerpc/kprobes.h

include/asm-powerpc/kprobes.h +1 -0
@@ -50,6 +50,7 @@ typedef unsigned int kprobe_opcode_t;
 			IS_TWI(instr) || IS_TDI(instr))
 
 #define ARCH_SUPPORTS_KRETPROBES
+#define flush_insn_slot(p)	do { } while (0)
 void kretprobe_trampoline(void);
 extern void arch_remove_kprobe(struct kprobe *p);
 

diff -Nruap 2.6.17.org/include/asm-sparc64/kprobes.h 2.6.17/include/asm-sparc64/kprobes.h

include/asm-sparc64/kprobes.h +1 -0
@@ -13,6 +13,7 @@ typedef u32 kprobe_opcode_t;
 
 #define JPROBE_ENTRY(pentry)	(kprobe_opcode_t *)pentry
 #define arch_remove_kprobe(p)	do {} while (0)
+#define flush_insn_slot(p)	do { } while (0)
 
 /* Architecture specific copy of original instruction*/
 struct arch_specific_insn {

diff -Nruap 2.6.17.org/include/asm-x86_64/kprobes.h 2.6.17/include/asm-x86_64/kprobes.h

include/asm-x86_64/kprobes.h +1 -0
@@ -43,6 +43,7 @@ typedef u8 kprobe_opcode_t;
 
 #define JPROBE_ENTRY(pentry)	(kprobe_opcode_t *)pentry
 #define ARCH_SUPPORTS_KRETPROBES
+#define flush_insn_slot(p)	do { } while (0)
 
 void kretprobe_trampoline(void);
 extern void arch_remove_kprobe(struct kprobe *p);

diff -Nruap 2.6.17.org/kernel/kprobes.c 2.6.17/kernel/kprobes.c

kernel/kprobes.c static int __kprobes register_aggr_kprob · line 423

Quoted 4 lines
kernel/kprobes.c +1 -0
@@ -420,6 +420,7 @@ static int __kprobes register_aggr_kprob
 		add_aggr_kprobe(ap, old_p);
 		copy_kprobe(ap, p);
 		ret = add_new_kprobe(ap, p);
+		flush_insn_slot(ap);

Same here..you need to flush_insn_slot(ap) before add_new_kprobe(ap, p).

Quoted 3 lines
kernel/kprobes.c +0 -0
 	}
 	return ret;
 }