Skip to contentSkip to conversation

Kprobes: Indicate kretprobe support in arch/<arch>/Kconfig

PATCH Superseded Ananth N Mavinakayanahalli 3 participants 8 messages Dec 10, 2007 – Dec 11, 2007

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Kprobes: Indicate kretprobe support in arch/<arch>/Kconfig

From: Ananth N Mavinakayanahalli <[email protected]>

This patch adds CONFIG_HAVE_KRETPROBES to the arch/<arch>/Kconfig file for relevant architectures with kprobes support. This facilitates easy handling of in-kernel modules (like samples/kprobes/kretprobe_example.c) that depend on kretprobes being present in the kernel.

This patch depends on Mathieu Desnoyers' "Instrumentation menu removal" patchset (http://marc.info/?l=linux-kernel&m=119496432229633&w=2)

Updated to apply on 2.6.24-rc4-mm1.

---
 arch/avr32/Kconfig            |    5 +++++
 arch/ia64/Kconfig             |    5 +++++
 arch/powerpc/Kconfig          |    5 +++++
 arch/s390/Kconfig             |    5 +++++
 arch/sparc64/Kconfig          |    5 +++++
 arch/x86/Kconfig              |    5 +++++
 include/asm-ia64/kprobes.h    |    1 -
 include/asm-powerpc/kprobes.h |    1 -
 include/asm-s390/kprobes.h    |    1 -
 include/asm-x86/kprobes_32.h  |    1 -
 include/asm-x86/kprobes_64.h  |    1 -
 include/linux/kprobes.h       |    6 +++---
 kernel/kprobes.c              |    8 +++-----
 13 files changed, 36 insertions(+), 13 deletions(-)
arch/avr32/Kconfig +5 -0
Index: linux-2.6.24-rc4/arch/avr32/Kconfig
===================================================================
@@ -66,6 +66,11 @@ config GENERIC_BUG
 	def_bool y
 	depends on BUG
 
+config HAVE_KRETPROBES
+	bool
+	depends on HAVE_KPROBES
+	default n
+
 source "init/Kconfig"
 
 menu "System Type and features"
arch/ia64/Kconfig +5 -0
Index: linux-2.6.24-rc4/arch/ia64/Kconfig
===================================================================
@@ -101,6 +101,11 @@ config AUDIT_ARCH
 	bool
 	default y
 
+config HAVE_KRETPROBES
+	bool
+	depends on HAVE_KPROBES
+	default y
+
 choice
 	prompt "System type"
 	default IA64_GENERIC
arch/powerpc/Kconfig +5 -0
Index: linux-2.6.24-rc4/arch/powerpc/Kconfig
===================================================================
@@ -165,6 +165,11 @@ config PPC_OF_PLATFORM_PCI
 	depends on PPC64 # not supported on 32 bits yet
 	default n
 
+config HAVE_KRETPROBES
+	bool
+	depends on HAVE_KPROBES
+	default y
+
 source "init/Kconfig"
 
 source "arch/powerpc/platforms/Kconfig"
arch/s390/Kconfig +5 -0
Index: linux-2.6.24-rc4/arch/s390/Kconfig
===================================================================
@@ -54,6 +54,11 @@ config S390
 	select HAVE_OPROFILE
 	select HAVE_KPROBES
 
+config HAVE_KRETPROBES
+	bool
+	depends on HAVE_KPROBES
+	default y
+
 source "init/Kconfig"
 
 menu "Base setup"
arch/sparc64/Kconfig +5 -0
Index: linux-2.6.24-rc4/arch/sparc64/Kconfig
===================================================================
@@ -81,6 +81,11 @@ config GENERIC_HARDIRQS_NO__DO_IRQ
 config ARCH_SUPPORTS_AOUT
 	def_bool y
 
+config HAVE_KRETPROBES
+	bool
+	depends on HAVE_KPROBES
+	default n
+
 choice
 	prompt "Kernel page size"
 	default SPARC64_PAGE_SIZE_8KB
arch/x86/Kconfig +5 -0
Index: linux-2.6.24-rc4/arch/x86/Kconfig
===================================================================
@@ -145,6 +145,11 @@ config X86_TRAMPOLINE
 config KTIME_SCALAR
 	def_bool X86_32
 
+config HAVE_KRETPROBES
+	bool
+	depends on HAVE_KPROBES
+	default y
+
 source "init/Kconfig"
 
 menu "Processor type and features"
include/asm-ia64/kprobes.h +0 -1
Index: linux-2.6.24-rc4/include/asm-ia64/kprobes.h
===================================================================
@@ -82,7 +82,6 @@ struct kprobe_ctlblk {
 	struct prev_kprobe prev_kprobe[ARCH_PREV_KPROBE_SZ];
 };
 
-#define ARCH_SUPPORTS_KRETPROBES
 #define kretprobe_blacklist_size 0
 
 #define SLOT0_OPCODE_SHIFT	(37)
include/asm-powerpc/kprobes.h +0 -1
Index: linux-2.6.24-rc4/include/asm-powerpc/kprobes.h
===================================================================
@@ -80,7 +80,6 @@ typedef unsigned int kprobe_opcode_t;
 #define is_trap(instr)	(IS_TW(instr) || IS_TWI(instr))
 #endif
 
-#define ARCH_SUPPORTS_KRETPROBES
 #define flush_insn_slot(p)	do { } while (0)
 #define kretprobe_blacklist_size 0
 
include/asm-s390/kprobes.h +0 -1
Index: linux-2.6.24-rc4/include/asm-s390/kprobes.h
===================================================================
@@ -46,7 +46,6 @@ typedef u16 kprobe_opcode_t;
 	? (MAX_STACK_SIZE) \
 	: (((unsigned long)current_thread_info()) + THREAD_SIZE - (ADDR)))
 
-#define ARCH_SUPPORTS_KRETPROBES
 #define kretprobe_blacklist_size 0
 
 #define KPROBE_SWAP_INST	0x10
include/asm-x86/kprobes_32.h +0 -1
Index: linux-2.6.24-rc4/include/asm-x86/kprobes_32.h
===================================================================
@@ -42,7 +42,6 @@ typedef u8 kprobe_opcode_t;
 	? (MAX_STACK_SIZE) \
 	: (((unsigned long)current_thread_info()) + THREAD_SIZE - (ADDR)))
 
-#define ARCH_SUPPORTS_KRETPROBES
 #define flush_insn_slot(p)	do { } while (0)
 
 extern const int kretprobe_blacklist_size;
include/asm-x86/kprobes_64.h +0 -1
Index: linux-2.6.24-rc4/include/asm-x86/kprobes_64.h
===================================================================
@@ -41,7 +41,6 @@ typedef u8 kprobe_opcode_t;
 	? (MAX_STACK_SIZE) \
 	: (((unsigned long)current_thread_info()) + THREAD_SIZE - (ADDR)))
 
-#define ARCH_SUPPORTS_KRETPROBES
 extern const int kretprobe_blacklist_size;
 
 void kretprobe_trampoline(void);
include/linux/kprobes.h +3 -3
Index: linux-2.6.24-rc4/include/linux/kprobes.h
===================================================================
@@ -125,11 +125,11 @@ struct jprobe {
 DECLARE_PER_CPU(struct kprobe *, current_kprobe);
 DECLARE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
 
-#ifdef ARCH_SUPPORTS_KRETPROBES
+#ifdef CONFIG_HAVE_KRETPROBES
 extern void arch_prepare_kretprobe(struct kretprobe_instance *ri,
 				   struct pt_regs *regs);
 extern int arch_trampoline_kprobe(struct kprobe *p);
-#else /* ARCH_SUPPORTS_KRETPROBES */
+#else /* CONFIG_HAVE_KRETPROBES */
 static inline void arch_prepare_kretprobe(struct kretprobe *rp,
 					struct pt_regs *regs)
 {
@@ -138,7 +138,7 @@ static inline int arch_trampoline_kprobe
 {
 	return 0;
 }
-#endif /* ARCH_SUPPORTS_KRETPROBES */
+#endif /* CONFIG_HAVE_KRETPROBES */
 /*
  * Function-return probe -
  * Note:
kernel/kprobes.c +3 -5
Index: linux-2.6.24-rc4/kernel/kprobes.c
===================================================================
@@ -678,8 +678,7 @@ void __kprobes unregister_jprobe(struct 
 	unregister_kprobe(&jp->kp);
 }
 
-#ifdef ARCH_SUPPORTS_KRETPROBES
-
+#ifdef CONFIG_HAVE_KRETPROBES
 /*
  * This kprobe pre_handler is registered with every kretprobe. When probe
  * hits it will set up the return probe.
@@ -762,7 +761,7 @@ int __kprobes register_kretprobe(struct 
 	return ret;
 }
 
-#else /* ARCH_SUPPORTS_KRETPROBES */
+#else /* CONFIG_HAVE_KRETPROBES */
 
 int __kprobes register_kretprobe(struct kretprobe *rp)
 {
@@ -774,8 +773,7 @@ static int __kprobes pre_handler_kretpro
 {
 	return 0;
 }
-
-#endif /* ARCH_SUPPORTS_KRETPROBES */
+#endif /* CONFIG_HAVE_KRETPROBES */
 
 void __kprobes unregister_kretprobe(struct kretprobe *rp)
 {
#1 lore raw

PATCH 2/2 Kprobes: Build kretprobe samples only if arch supports kretprobes

From: Ananth N Mavinakayanahalli <[email protected]>

This patch builds samples/kprobes/kretprobe_example.c only on archs that support kretprobes.

---
 samples/kprobes/Makefile |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
samples/kprobes/Makefile +5 -2
Index: linux-2.6.24-rc4/samples/kprobes/Makefile
===================================================================
@@ -1,5 +1,8 @@
 # builds the kprobes example kernel modules;
 # then to use one (as root):  insmod <module_name.ko>
 
-obj-$(CONFIG_SAMPLE_KPROBES) += kprobe_example.o jprobe_example.o \
-		kretprobe_example.o
+obj-$(CONFIG_SAMPLE_KPROBES) += kprobe_example.o jprobe_example.o
+
+ifeq ($(CONFIG_HAVE_KRETPROBES),y)
+obj-$(CONFIG_SAMPLE_KPROBES) += kretprobe_example.o
+endif
#2 lore raw

Re: [PATCH 2/2] Kprobes: Build kretprobe samples only if arch supports kretprobes

Quoted 16 lines · Ananth N Mavinakayanahalli

From: Ananth N Mavinakayanahalli <[email protected]>

This patch builds samples/kprobes/kretprobe_example.c only on archs that support kretprobes.

---
 samples/kprobes/Makefile |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

Index: linux-2.6.24-rc4/samples/kprobes/Makefile
===================================================================

samples/kprobes/Makefile line 8

Quoted 10 lines
samples/kprobes/Makefile +5 -2
@@ -1,5 +1,8 @@
 # builds the kprobes example kernel modules;
 # then to use one (as root):  insmod <module_name.ko>
 
-obj-$(CONFIG_SAMPLE_KPROBES) += kprobe_example.o jprobe_example.o \
-		kretprobe_example.o
+obj-$(CONFIG_SAMPLE_KPROBES) += kprobe_example.o jprobe_example.o
+
+ifeq ($(CONFIG_HAVE_KRETPROBES),y)
+obj-$(CONFIG_SAMPLE_KPROBES) += kretprobe_example.o
+endif

It would be nice to push this configuration dependency to Kconfig. Something like:

config SAMPLE_KRETPROBES
default y
depends on SAMPLE_KPROBES

And then in the Makefile have:
obj-$(CONFIG_SAMPLE_KRETPROBES) += kretprobe_example.o

Sam

#3 lore raw

Re: [PATCH 2/2] Kprobes: Build kretprobe samples only if arch supports kretprobes - updated

Quoted 31 lines · Sam Ravnborg
Quoted 16 lines · Ananth N Mavinakayanahalli

From: Ananth N Mavinakayanahalli <[email protected]>

This patch builds samples/kprobes/kretprobe_example.c only on archs that support kretprobes.

---
 samples/kprobes/Makefile |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

Index: linux-2.6.24-rc4/samples/kprobes/Makefile
===================================================================

samples/kprobes/Makefile line 8

Quoted 10 lines
samples/kprobes/Makefile +5 -2
@@ -1,5 +1,8 @@
 # builds the kprobes example kernel modules;
 # then to use one (as root):  insmod <module_name.ko>
 
-obj-$(CONFIG_SAMPLE_KPROBES) += kprobe_example.o jprobe_example.o \
-		kretprobe_example.o
+obj-$(CONFIG_SAMPLE_KPROBES) += kprobe_example.o jprobe_example.o
+
+ifeq ($(CONFIG_HAVE_KRETPROBES),y)
+obj-$(CONFIG_SAMPLE_KPROBES) += kretprobe_example.o
+endif

It would be nice to push this configuration dependency to Kconfig. Something like:

Quoted 6 lines

config SAMPLE_KRETPROBES
default y
depends on SAMPLE_KPROBES

And then in the Makefile have:
obj-$(CONFIG_SAMPLE_KRETPROBES) += kretprobe_example.o

Done. Updated patch below...

From: Ananth N Mavinakayanahalli <[email protected]>

This patch builds samples/kprobes/kretprobe_example.c only on archs that support kretprobes. Thanks to Sam Ravnborg for Kconfig suggestions.

---
 samples/Kconfig          |    5 +++++
 samples/kprobes/Makefile |    4 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)
samples/kprobes/Makefile +2 -2
Index: linux-2.6.24-rc4/samples/kprobes/Makefile
===================================================================
@@ -1,5 +1,5 @@
 # builds the kprobes example kernel modules;
 # then to use one (as root):  insmod <module_name.ko>
 
-obj-$(CONFIG_SAMPLE_KPROBES) += kprobe_example.o jprobe_example.o \
-		kretprobe_example.o
+obj-$(CONFIG_SAMPLE_KPROBES) += kprobe_example.o jprobe_example.o
+obj-$(CONFIG_SAMPLE_KRETPROBES) += kretprobe_example.o
samples/Kconfig +5 -0
Index: linux-2.6.24-rc4/samples/Kconfig
===================================================================
@@ -28,5 +28,10 @@ config SAMPLE_KPROBES
 	help
 	  This build several kprobes example modules.
 
+config SAMPLE_KRETPROBES
+	tristate "Build kretprobes example -- loadable modules only"
+	default m
+	depends on SAMPLE_KPROBES && HAVE_KRETPROBES
+
 endif # SAMPLES
 
#4 lore raw
In reply to Ananth N Mavinakayanahalli
Quoted 34 lines · Ananth N Mavinakayanahalli

From: Ananth N Mavinakayanahalli <[email protected]>

This patch adds CONFIG_HAVE_KRETPROBES to the arch/<arch>/Kconfig file for relevant architectures with kprobes support. This facilitates easy handling of in-kernel modules (like samples/kprobes/kretprobe_example.c) that depend on kretprobes being present in the kernel.

This patch depends on Mathieu Desnoyers' "Instrumentation menu removal" patchset (http://marc.info/?l=linux-kernel&m=119496432229633&w=2)

Updated to apply on 2.6.24-rc4-mm1.

---
 arch/avr32/Kconfig            |    5 +++++
 arch/ia64/Kconfig             |    5 +++++
 arch/powerpc/Kconfig          |    5 +++++
 arch/s390/Kconfig             |    5 +++++
 arch/sparc64/Kconfig          |    5 +++++
 arch/x86/Kconfig              |    5 +++++
 include/asm-ia64/kprobes.h    |    1 -
 include/asm-powerpc/kprobes.h |    1 -
 include/asm-s390/kprobes.h    |    1 -
 include/asm-x86/kprobes_32.h  |    1 -
 include/asm-x86/kprobes_64.h  |    1 -
 include/linux/kprobes.h       |    6 +++---
 kernel/kprobes.c              |    8 +++-----
 13 files changed, 36 insertions(+), 13 deletions(-)

Index: linux-2.6.24-rc4/arch/avr32/Kconfig
===================================================================

arch/avr32/Kconfig config GENERIC_BUG · line 73

Quoted 8 lines
arch/avr32/Kconfig +5 -0
@@ -66,6 +66,11 @@ config GENERIC_BUG
 	def_bool y
 	depends on BUG
 
+config HAVE_KRETPROBES
+	bool
+	depends on HAVE_KPROBES
+	default n
+

The symbol HAVE_KRETPROBES should be defined in the common file - so the only thing you have to do is a single line:
config AVR32
+ select HAVE_KRETPROBES

Much more dense than defining the symbols once for each arch.

Sam

#5 lore raw

Re: [PATCH 1/2] Kprobes: Indicate kretprobe support in arch/<arch>/Kconfig - updated

Quoted 50 lines · Sam Ravnborg
Quoted 34 lines · Ananth N Mavinakayanahalli

From: Ananth N Mavinakayanahalli <[email protected]>

This patch adds CONFIG_HAVE_KRETPROBES to the arch/<arch>/Kconfig file for relevant architectures with kprobes support. This facilitates easy handling of in-kernel modules (like samples/kprobes/kretprobe_example.c) that depend on kretprobes being present in the kernel.

This patch depends on Mathieu Desnoyers' "Instrumentation menu removal" patchset (http://marc.info/?l=linux-kernel&m=119496432229633&w=2)

Updated to apply on 2.6.24-rc4-mm1.

---
 arch/avr32/Kconfig            |    5 +++++
 arch/ia64/Kconfig             |    5 +++++
 arch/powerpc/Kconfig          |    5 +++++
 arch/s390/Kconfig             |    5 +++++
 arch/sparc64/Kconfig          |    5 +++++
 arch/x86/Kconfig              |    5 +++++
 include/asm-ia64/kprobes.h    |    1 -
 include/asm-powerpc/kprobes.h |    1 -
 include/asm-s390/kprobes.h    |    1 -
 include/asm-x86/kprobes_32.h  |    1 -
 include/asm-x86/kprobes_64.h  |    1 -
 include/linux/kprobes.h       |    6 +++---
 kernel/kprobes.c              |    8 +++-----
 13 files changed, 36 insertions(+), 13 deletions(-)

Index: linux-2.6.24-rc4/arch/avr32/Kconfig
===================================================================

arch/avr32/Kconfig config GENERIC_BUG · line 73

Quoted 8 lines
arch/avr32/Kconfig +5 -0
@@ -66,6 +66,11 @@ config GENERIC_BUG
 	def_bool y
 	depends on BUG
 
+config HAVE_KRETPROBES
+	bool
+	depends on HAVE_KPROBES
+	default n
+

The symbol HAVE_KRETPROBES should be defined in the common file - so the only thing you have to do is a single line:
config AVR32

(quoted diff) +1 -0
+	select HAVE_KRETPROBES
Quoted 1 line

Much more dense than defining the symbols once for each arch.

Agreed. Updated patch below.

From: Ananth N Mavinakayanahalli <[email protected]>

This patch adds CONFIG_HAVE_KRETPROBES to the arch/<arch>/Kconfig file for relevant architectures with kprobes support. This facilitates easy handling of in-kernel modules (like samples/kprobes/kretprobe_example.c) that depend on kretprobes being present in the kernel.

This patch depends on Mathieu Desnoyers' "Instrumentation menu removal" patchset (http://marc.info/?l=linux-kernel&m=119496432229633&w=2)

Updated to apply on 2.6.24-rc4-mm1. Thanks to Sam Ravnborg for helping make the patch more lean.

---
 arch/Kconfig                  |    4 ++++
 arch/ia64/Kconfig             |    1 +
 arch/powerpc/Kconfig          |    1 +
 arch/s390/Kconfig             |    1 +
 arch/x86/Kconfig              |    1 +
 include/asm-ia64/kprobes.h    |    1 -
 include/asm-powerpc/kprobes.h |    1 -
 include/asm-x86/kprobes_32.h  |    1 -
 include/asm-x86/kprobes_64.h  |    1 -
 include/linux/kprobes.h       |    6 +++---
 kernel/kprobes.c              |    8 +++-----
 11 files changed, 14 insertions(+), 12 deletions(-)
arch/Kconfig +4 -0
Index: linux-2.6.24-rc4/arch/Kconfig
===================================================================
@@ -29,3 +29,7 @@ config KPROBES
 
 config HAVE_KPROBES
 	def_bool n
+
+config HAVE_KRETPROBES
+	def_bool n
+	depends on HAVE_KPROBES
arch/ia64/Kconfig +1 -0
Index: linux-2.6.24-rc4/arch/ia64/Kconfig
===================================================================
@@ -17,6 +17,7 @@ config IA64
 	select ARCH_SUPPORTS_MSI
 	select HAVE_OPROFILE
 	select HAVE_KPROBES
+	select HAVE_KRETPROBES
 	default y
 	help
 	  The Itanium Processor Family is Intel's 64-bit successor to
arch/powerpc/Kconfig +1 -0
Index: linux-2.6.24-rc4/arch/powerpc/Kconfig
===================================================================
@@ -81,6 +81,7 @@ config PPC
 	default y
 	select HAVE_OPROFILE
 	select HAVE_KPROBES
+	select HAVE_KRETPROBES
 
 config EARLY_PRINTK
 	bool
arch/s390/Kconfig +1 -0
Index: linux-2.6.24-rc4/arch/s390/Kconfig
===================================================================
@@ -53,6 +53,7 @@ config S390
 	def_bool y
 	select HAVE_OPROFILE
 	select HAVE_KPROBES
+	select HAVE_KRETPROBES
 
 source "init/Kconfig"
 
arch/x86/Kconfig +1 -0
Index: linux-2.6.24-rc4/arch/x86/Kconfig
===================================================================
@@ -20,6 +20,7 @@ config X86
 	def_bool y
 	select HAVE_OPROFILE
 	select HAVE_KPROBES
+	select HAVE_KRETPROBES
 
 config GENERIC_TIME
 	def_bool y
include/asm-ia64/kprobes.h +0 -1
Index: linux-2.6.24-rc4/include/asm-ia64/kprobes.h
===================================================================
@@ -82,7 +82,6 @@ struct kprobe_ctlblk {
 	struct prev_kprobe prev_kprobe[ARCH_PREV_KPROBE_SZ];
 };
 
-#define ARCH_SUPPORTS_KRETPROBES
 #define kretprobe_blacklist_size 0
 
 #define SLOT0_OPCODE_SHIFT	(37)
include/asm-powerpc/kprobes.h +0 -1
Index: linux-2.6.24-rc4/include/asm-powerpc/kprobes.h
===================================================================
@@ -80,7 +80,6 @@ typedef unsigned int kprobe_opcode_t;
 #define is_trap(instr)	(IS_TW(instr) || IS_TWI(instr))
 #endif
 
-#define ARCH_SUPPORTS_KRETPROBES
 #define flush_insn_slot(p)	do { } while (0)
 #define kretprobe_blacklist_size 0
 
include/asm-x86/kprobes_32.h +0 -1
Index: linux-2.6.24-rc4/include/asm-x86/kprobes_32.h
===================================================================
@@ -42,7 +42,6 @@ typedef u8 kprobe_opcode_t;
 	? (MAX_STACK_SIZE) \
 	: (((unsigned long)current_thread_info()) + THREAD_SIZE - (ADDR)))
 
-#define ARCH_SUPPORTS_KRETPROBES
 #define flush_insn_slot(p)	do { } while (0)
 
 extern const int kretprobe_blacklist_size;
include/asm-x86/kprobes_64.h +0 -1
Index: linux-2.6.24-rc4/include/asm-x86/kprobes_64.h
===================================================================
@@ -41,7 +41,6 @@ typedef u8 kprobe_opcode_t;
 	? (MAX_STACK_SIZE) \
 	: (((unsigned long)current_thread_info()) + THREAD_SIZE - (ADDR)))
 
-#define ARCH_SUPPORTS_KRETPROBES
 extern const int kretprobe_blacklist_size;
 
 void kretprobe_trampoline(void);
include/linux/kprobes.h +3 -3
Index: linux-2.6.24-rc4/include/linux/kprobes.h
===================================================================
@@ -125,11 +125,11 @@ struct jprobe {
 DECLARE_PER_CPU(struct kprobe *, current_kprobe);
 DECLARE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
 
-#ifdef ARCH_SUPPORTS_KRETPROBES
+#ifdef CONFIG_HAVE_KRETPROBES
 extern void arch_prepare_kretprobe(struct kretprobe_instance *ri,
 				   struct pt_regs *regs);
 extern int arch_trampoline_kprobe(struct kprobe *p);
-#else /* ARCH_SUPPORTS_KRETPROBES */
+#else /* CONFIG_HAVE_KRETPROBES */
 static inline void arch_prepare_kretprobe(struct kretprobe *rp,
 					struct pt_regs *regs)
 {
@@ -138,7 +138,7 @@ static inline int arch_trampoline_kprobe
 {
 	return 0;
 }
-#endif /* ARCH_SUPPORTS_KRETPROBES */
+#endif /* CONFIG_HAVE_KRETPROBES */
 /*
  * Function-return probe -
  * Note:
kernel/kprobes.c +3 -5
Index: linux-2.6.24-rc4/kernel/kprobes.c
===================================================================
@@ -678,8 +678,7 @@ void __kprobes unregister_jprobe(struct 
 	unregister_kprobe(&jp->kp);
 }
 
-#ifdef ARCH_SUPPORTS_KRETPROBES
-
+#ifdef CONFIG_HAVE_KRETPROBES
 /*
  * This kprobe pre_handler is registered with every kretprobe. When probe
  * hits it will set up the return probe.
@@ -762,7 +761,7 @@ int __kprobes register_kretprobe(struct 
 	return ret;
 }
 
-#else /* ARCH_SUPPORTS_KRETPROBES */
+#else /* CONFIG_HAVE_KRETPROBES */
 
 int __kprobes register_kretprobe(struct kretprobe *rp)
 {
@@ -774,8 +773,7 @@ static int __kprobes pre_handler_kretpro
 {
 	return 0;
 }
-
-#endif /* ARCH_SUPPORTS_KRETPROBES */
+#endif /* CONFIG_HAVE_KRETPROBES */
 
 void __kprobes unregister_kretprobe(struct kretprobe *rp)
 {
#6 lore raw

Re: [PATCH 1/2] Kprobes: Indicate kretprobe support in arch/<arch>/Kconfig - updated

Quoted 196 lines · * Ananth N Mavinakayanahalli ([email protected]) wrote:
Quoted 50 lines · Sam Ravnborg
Quoted 34 lines · Ananth N Mavinakayanahalli

From: Ananth N Mavinakayanahalli <[email protected]>

This patch adds CONFIG_HAVE_KRETPROBES to the arch/<arch>/Kconfig file for relevant architectures with kprobes support. This facilitates easy handling of in-kernel modules (like samples/kprobes/kretprobe_example.c) that depend on kretprobes being present in the kernel.

This patch depends on Mathieu Desnoyers' "Instrumentation menu removal" patchset (http://marc.info/?l=linux-kernel&m=119496432229633&w=2)

Updated to apply on 2.6.24-rc4-mm1.

---
 arch/avr32/Kconfig            |    5 +++++
 arch/ia64/Kconfig             |    5 +++++
 arch/powerpc/Kconfig          |    5 +++++
 arch/s390/Kconfig             |    5 +++++
 arch/sparc64/Kconfig          |    5 +++++
 arch/x86/Kconfig              |    5 +++++
 include/asm-ia64/kprobes.h    |    1 -
 include/asm-powerpc/kprobes.h |    1 -
 include/asm-s390/kprobes.h    |    1 -
 include/asm-x86/kprobes_32.h  |    1 -
 include/asm-x86/kprobes_64.h  |    1 -
 include/linux/kprobes.h       |    6 +++---
 kernel/kprobes.c              |    8 +++-----
 13 files changed, 36 insertions(+), 13 deletions(-)

Index: linux-2.6.24-rc4/arch/avr32/Kconfig
===================================================================

arch/avr32/Kconfig config GENERIC_BUG · line 73

Quoted 8 lines
arch/avr32/Kconfig +5 -0
@@ -66,6 +66,11 @@ config GENERIC_BUG
 	def_bool y
 	depends on BUG
 
+config HAVE_KRETPROBES
+	bool
+	depends on HAVE_KPROBES
+	default n
+

The symbol HAVE_KRETPROBES should be defined in the common file - so the only thing you have to do is a single line:
config AVR32

(quoted diff) +1 -0
+	select HAVE_KRETPROBES
Quoted 1 line

Much more dense than defining the symbols once for each arch.

Agreed. Updated patch below.

From: Ananth N Mavinakayanahalli <[email protected]>

This patch adds CONFIG_HAVE_KRETPROBES to the arch/<arch>/Kconfig file for relevant architectures with kprobes support. This facilitates easy handling of in-kernel modules (like samples/kprobes/kretprobe_example.c) that depend on kretprobes being present in the kernel.

This patch depends on Mathieu Desnoyers' "Instrumentation menu removal" patchset (http://marc.info/?l=linux-kernel&m=119496432229633&w=2)

Updated to apply on 2.6.24-rc4-mm1. Thanks to Sam Ravnborg for helping make the patch more lean.

---
 arch/Kconfig                  |    4 ++++
 arch/ia64/Kconfig             |    1 +
 arch/powerpc/Kconfig          |    1 +
 arch/s390/Kconfig             |    1 +
 arch/x86/Kconfig              |    1 +
 include/asm-ia64/kprobes.h    |    1 -
 include/asm-powerpc/kprobes.h |    1 -
 include/asm-x86/kprobes_32.h  |    1 -
 include/asm-x86/kprobes_64.h  |    1 -
 include/linux/kprobes.h       |    6 +++---
 kernel/kprobes.c              |    8 +++-----
 11 files changed, 14 insertions(+), 12 deletions(-)

Index: linux-2.6.24-rc4/arch/Kconfig
===================================================================

arch/Kconfig +4 -0
@@ -29,3 +29,7 @@ config KPROBES
 
 config HAVE_KPROBES
 	def_bool n
+
+config HAVE_KRETPROBES
+	def_bool n
+	depends on HAVE_KPROBES

Index: linux-2.6.24-rc4/arch/ia64/Kconfig
===================================================================

arch/ia64/Kconfig +1 -0
@@ -17,6 +17,7 @@ config IA64
 	select ARCH_SUPPORTS_MSI
 	select HAVE_OPROFILE
 	select HAVE_KPROBES
+	select HAVE_KRETPROBES
 	default y
 	help
 	  The Itanium Processor Family is Intel's 64-bit successor to

Index: linux-2.6.24-rc4/arch/powerpc/Kconfig
===================================================================

arch/powerpc/Kconfig +1 -0
@@ -81,6 +81,7 @@ config PPC
 	default y
 	select HAVE_OPROFILE
 	select HAVE_KPROBES
+	select HAVE_KRETPROBES
 
 config EARLY_PRINTK
 	bool

Index: linux-2.6.24-rc4/arch/s390/Kconfig
===================================================================

arch/s390/Kconfig +1 -0
@@ -53,6 +53,7 @@ config S390
 	def_bool y
 	select HAVE_OPROFILE
 	select HAVE_KPROBES
+	select HAVE_KRETPROBES
 
 source "init/Kconfig"
 

Index: linux-2.6.24-rc4/arch/x86/Kconfig
===================================================================

arch/x86/Kconfig +1 -0
@@ -20,6 +20,7 @@ config X86
 	def_bool y
 	select HAVE_OPROFILE
 	select HAVE_KPROBES
+	select HAVE_KRETPROBES
 
 config GENERIC_TIME
 	def_bool y

Index: linux-2.6.24-rc4/include/asm-ia64/kprobes.h
===================================================================

include/asm-ia64/kprobes.h +0 -1
@@ -82,7 +82,6 @@ struct kprobe_ctlblk {
 	struct prev_kprobe prev_kprobe[ARCH_PREV_KPROBE_SZ];
 };
 
-#define ARCH_SUPPORTS_KRETPROBES
 #define kretprobe_blacklist_size 0
 
 #define SLOT0_OPCODE_SHIFT	(37)

Index: linux-2.6.24-rc4/include/asm-powerpc/kprobes.h
===================================================================

include/asm-powerpc/kprobes.h +0 -1
@@ -80,7 +80,6 @@ typedef unsigned int kprobe_opcode_t;
 #define is_trap(instr)	(IS_TW(instr) || IS_TWI(instr))
 #endif
 
-#define ARCH_SUPPORTS_KRETPROBES
 #define flush_insn_slot(p)	do { } while (0)
 #define kretprobe_blacklist_size 0
 

Index: linux-2.6.24-rc4/include/asm-x86/kprobes_32.h
===================================================================

include/asm-x86/kprobes_32.h +0 -1
@@ -42,7 +42,6 @@ typedef u8 kprobe_opcode_t;
 	? (MAX_STACK_SIZE) \
 	: (((unsigned long)current_thread_info()) + THREAD_SIZE - (ADDR)))
 
-#define ARCH_SUPPORTS_KRETPROBES
 #define flush_insn_slot(p)	do { } while (0)
 
 extern const int kretprobe_blacklist_size;

Index: linux-2.6.24-rc4/include/asm-x86/kprobes_64.h
===================================================================

include/asm-x86/kprobes_64.h +0 -1
@@ -41,7 +41,6 @@ typedef u8 kprobe_opcode_t;
 	? (MAX_STACK_SIZE) \
 	: (((unsigned long)current_thread_info()) + THREAD_SIZE - (ADDR)))
 
-#define ARCH_SUPPORTS_KRETPROBES
 extern const int kretprobe_blacklist_size;
 
 void kretprobe_trampoline(void);

Index: linux-2.6.24-rc4/include/linux/kprobes.h
===================================================================

include/linux/kprobes.h struct jprobe { · line 128

Quoted 5 lines
include/linux/kprobes.h +1 -1
@@ -125,11 +125,11 @@ struct jprobe {
 DECLARE_PER_CPU(struct kprobe *, current_kprobe);
 DECLARE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
 
-#ifdef ARCH_SUPPORTS_KRETPROBES
+#ifdef CONFIG_HAVE_KRETPROBES

Hi Ananth,

I just want to point out a detail: if someone sets CONFIG_KPROBES to n, the CONFIG_HAVE_KPROBES is still y, and so is CONFIG_HAVE_KRETPROBES. However, I doubt that you want to activate this code in this case ? The code paths are OK because they are nested into CONFIG_KPROBES ifdefs (or not built due to dependency on CONFIG_KPROBES in the Makfile), but if one wants to use CONFIG_HAVE_KRETPROBE for something else (Makefile), then it could become a problem.

Could we add a menu entry CONFIG_KRETPROBES that depends on CONFIG_HAVE_KRETPROBES and CONFIG_KPROBES, and also remove the CONFIG_HAVE_KPROBES dependency for the CONFIG_HAVE_KRETPROBE option ? This way, we would have much more flexibility (like specifiying if we want CONFIG_KRETPROBES to be default y or default n...)

Mathieu

Quoted 50 lines
include/linux/kprobes.h +2 -2
 extern void arch_prepare_kretprobe(struct kretprobe_instance *ri,
 				   struct pt_regs *regs);
 extern int arch_trampoline_kprobe(struct kprobe *p);
-#else /* ARCH_SUPPORTS_KRETPROBES */
+#else /* CONFIG_HAVE_KRETPROBES */
 static inline void arch_prepare_kretprobe(struct kretprobe *rp,
 					struct pt_regs *regs)
 {
@@ -138,7 +138,7 @@ static inline int arch_trampoline_kprobe
 {
 	return 0;
 }
-#endif /* ARCH_SUPPORTS_KRETPROBES */
+#endif /* CONFIG_HAVE_KRETPROBES */
 /*
  * Function-return probe -
  * Note:

Index: linux-2.6.24-rc4/kernel/kprobes.c
===================================================================

kernel/kprobes.c +3 -5
@@ -678,8 +678,7 @@ void __kprobes unregister_jprobe(struct 
 	unregister_kprobe(&jp->kp);
 }
 
-#ifdef ARCH_SUPPORTS_KRETPROBES
-
+#ifdef CONFIG_HAVE_KRETPROBES
 /*
  * This kprobe pre_handler is registered with every kretprobe. When probe
  * hits it will set up the return probe.
@@ -762,7 +761,7 @@ int __kprobes register_kretprobe(struct 
 	return ret;
 }
 
-#else /* ARCH_SUPPORTS_KRETPROBES */
+#else /* CONFIG_HAVE_KRETPROBES */
 
 int __kprobes register_kretprobe(struct kretprobe *rp)
 {
@@ -774,8 +773,7 @@ static int __kprobes pre_handler_kretpro
 {
 	return 0;
 }
-
-#endif /* ARCH_SUPPORTS_KRETPROBES */
+#endif /* CONFIG_HAVE_KRETPROBES */
 
 void __kprobes unregister_kretprobe(struct kretprobe *rp)
 {
Signature · 3 lines
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
#7 lore raw

Re: [PATCH 1/2] Kprobes: Indicate kretprobe support in arch/<arch>/Kconfig - updated

Quoted 5 lines · Mathieu Desnoyers
Quoted 4 lines · * Ananth N Mavinakayanahalli ([email protected]) wrote:
Quoted 3 lines · Sam Ravnborg
Quoted 2 lines · Ananth N Mavinakayanahalli

From: Ananth N Mavinakayanahalli <[email protected]>

<snip>

Quoted 21 lines

include/linux/kprobes.h struct jprobe { · line 128

Quoted 10 lines

Index: linux-2.6.24-rc4/include/linux/kprobes.h
===================================================================

include/linux/kprobes.h +1 -1
@@ -125,11 +125,11 @@ struct jprobe {
 DECLARE_PER_CPU(struct kprobe *, current_kprobe);
 DECLARE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
 
-#ifdef ARCH_SUPPORTS_KRETPROBES
+#ifdef CONFIG_HAVE_KRETPROBES

Hi Ananth,

I just want to point out a detail: if someone sets CONFIG_KPROBES to n, the CONFIG_HAVE_KPROBES is still y, and so is CONFIG_HAVE_KRETPROBES. However, I doubt that you want to activate this code in this case ? The code paths are OK because they are nested into CONFIG_KPROBES ifdefs (or not built due to dependency on CONFIG_KPROBES in the Makfile), but if one wants to use CONFIG_HAVE_KRETPROBE for something else (Makefile), then it could become a problem.

Quoted 5 lines

Could we add a menu entry CONFIG_KRETPROBES that depends on CONFIG_HAVE_KRETPROBES and CONFIG_KPROBES, and also remove the CONFIG_HAVE_KPROBES dependency for the CONFIG_HAVE_KRETPROBE option ? This way, we would have much more flexibility (like specifiying if we want CONFIG_KRETPROBES to be default y or default n...)

Done... Updated patch coming up.

Ananth