public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1)
@ 2008-01-24 20:27 Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 01/26] Linux Kernel Markers Support for Proprierary Modules Mathieu Desnoyers
                   ` (25 more replies)
  0 siblings, 26 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel

Hi Andrew,

Here are the latest instrumentation support enhancements. These include :

* Markers support for proprierary modules
  (this is an updated version of the one I sent earlier, nothing big, just a
  small fuzz checked and refreshed)
* Instrumentation menu removal
* Text Edit Lock
* Immediate Values
* Linux Kernel Markers use Immediate Values

This patchset is fully bissectable, so if, for instance, someone is not happy
with the last functionnality (Linux Kernel Markers use Immediate Values), it can
be left out and the rest is completely usable as is.

Which apply on top of 2.6.24-rc8-mm1 in this order :

markers-support-for-proprietary-modules.patch
#
#Instrumentation menu removal
fix-arm-to-play-nicely-with-generic-instrumentation-menu.patch
move-kconfig-instrumentation-to-arch.patch
#
#Text Edit Lock
kprobes-use-mutex-for-insn-pages.patch
kprobes-dont-use-kprobes-mutex-in-arch-code.patch
kprobes-declare-kprobes-mutex-static.patch
declare-array.patch
text-edit-lock-architecture-independent-code.patch
text-edit-lock-alternative-i386-and-x86_64.patch
text-edit-lock-kprobes-architecture-independent.patch
text-edit-lock-kprobes-x86.patch
text-edit-lock-i386-standardize-debug-rodata.patch
text-edit-lock-x86_64-standardize-debug-rodata.patch
#
#Immediate Values
immediate-values-architecture-independent-code.patch
immediate-values-kconfig-embedded.patch
immediate-values-x86-optimization.patch
add-text-poke-to-powerpc.patch
immediate-values-powerpc-optimization.patch
immediate-values-documentation.patch
#
profiling-use-immediate-values.patch
#
#Linux Kernel Markers use Immediate Values
immediate-values-move-kprobes-x86-restore-interrupt-to-kdebug-h.patch
add-discard-section-to-x86.patch
immediate-values-x86-optimization-nmi-mce-support.patch
immediate-values-powerpc-optimization-nmi-mce-support.patch
immediate-values-use-arch-nmi-mce-support.patch
linux-kernel-markers-immediate-values.patch

Mathieu

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 01/26] Linux Kernel Markers Support for Proprierary Modules
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 22:19   ` Jon Masters
  2008-01-24 20:27 ` [patch 02/26] Fix ARM to play nicely with generic Instrumentation menu Mathieu Desnoyers
                   ` (24 subsequent siblings)
  25 siblings, 1 reply; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel
  Cc: Mathieu Desnoyers, Frank Ch. Eigler, Jon Masters, Rusty Russell,
	Christoph Hellwig, Linus Torvalds

[-- Attachment #1: markers-support-for-proprietary-modules.patch --]
[-- Type: text/plain, Size: 4672 bytes --]

There seems to be good arguments for markers to support proprierary modules. So
I am throwing this one-liner in and let's see how people react. It only makes
sure that a module that has been "forced" to be loaded won't have its markers
used. It is important to leave this check to make sure the kernel does not crash
by expecting the markers part of the struct module by mistake in the case there
is an incorrect checksum.


Discussion so far :
http://lkml.org/lkml/2008/1/22/226

Jon Masters <jcm@redhat.com> writes:
I notice in module.c:

#ifdef CONFIG_MARKERS
      if (!mod->taints)
              marker_update_probe_range(mod->markers,
                      mod->markers + mod->num_markers, NULL, NULL);
#endif

Is this an attempt to not set a marker for proprietary modules? [...]

* Frank Ch. Eigler (fche@redhat.com) wrote:
I can't seem to find any discussion about this aspect.  If this is the
intent, it seems misguided to me.  There may instead be a relationship
to TAINT_FORCED_{RMMOD,MODULE}.  Mathieu?

- FChE

On Tue, 2008-01-22 at 22:10 -0500, Mathieu Desnoyers wrote:
On my part, its mostly a matter of not crashing the kernel when someone
tries to force modprobe of a proprietary module (where the checksums
doesn't match) on a kernel that supports the markers. Not doing so
causes the markers to try to find the marker-specific information in
struct module which doesn't exist and OOPSes.

Christoph's point of view is rather more drastic than mine : it's not
interesting for the kernel community to help proprietary modules writers,
so it's a good idea not to give them marker support. (I CC'ed him so he
can clarify his position).

* Frank Ch. Eigler (fche@redhat.com) wrote:
[...]
Another way of looking at this though is that by allowing/encouraging
proprietary module writers to include markers, we and their users get
new diagnostic capabilities.  It constitutes a little bit of opening
up, which IMO we should reward rather than punish.


* Vladis Ketnieks (Valdis.Kletnieks@vt.edu) wrote:
On Wed, 23 Jan 2008 09:48:12 EST, Mathieu Desnoyers said:

> This specific one is a kernel policy matter, and I personally don't
> have a strong opinion about it. I agree that you raise a good counter
> argument : it can be useful to proprietary modules users to be able to
> extract tracing information from those modules to argue with their
> vendors that their driver/hardware is broken (a tracer is _very_ useful
> in that kind of situation).

Amen, brother. Been there, done that, got the tshirt (not on Linux, but
other operating systems).

>                             However, it is also useful to proprieraty
> module writers who can benefit from the merged kernel/modules traces.
> Do we want to give them this ability ?

The proprietary module writer has the *source* for the kernel and their module.
There's no way you can prevent the proprietary module writers from using this
feature as long as you allow other module writers to use it.

>                                           It would surely help writing
> better proprieraty kernel modules.

The biggest complaint against proprietary modules is that they make it
impossible for *us* to debug.  And you want to argue *against* a feature that
would allow them to develop better code that causes less crashes, and therefor
less people *asking* for us to debug it?

Remember - when a user tries a Linux box with a proprietary module, and the
experience sucks because the module sucks, they will walk away thinking
"Linux sucks", not "That module sucks".

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
CC: "Frank Ch. Eigler" <fche@redhat.com>
CC: Jon Masters <jcm@redhat.com>
CC: Rusty Russell <rusty@rustcorp.com.au>
CC: Christoph Hellwig <hch@infradead.org>
CC: Linus Torvalds <torvalds@linux-foundation.org>
CC: Andrew Morton <akpm@linux-foundation.org>
---
 kernel/module.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-2.6-lttng.mm/kernel/module.c
===================================================================
--- linux-2.6-lttng.mm.orig/kernel/module.c	2008-01-24 14:17:23.000000000 -0500
+++ linux-2.6-lttng.mm/kernel/module.c	2008-01-24 14:17:33.000000000 -0500
@@ -1989,7 +1989,7 @@ static struct module *load_module(void _
 	add_kallsyms(mod, sechdrs, symindex, strindex, secstrings);
 
 #ifdef CONFIG_MARKERS
-	if (!mod->taints)
+	if (!(mod->taints & TAINT_FORCED_MODULE))
 		marker_update_probe_range(mod->markers,
 			mod->markers + mod->num_markers);
 #endif

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 02/26] Fix ARM to play nicely with generic Instrumentation menu
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 01/26] Linux Kernel Markers Support for Proprierary Modules Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 21:13   ` Russell King
  2008-01-24 20:27 ` [patch 03/26] Move Kconfig.instrumentation to arch/Kconfig and init/Kconfig Mathieu Desnoyers
                   ` (23 subsequent siblings)
  25 siblings, 1 reply; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel
  Cc: Mathieu Desnoyers, Linus Torvalds, Russell King, ananth, dhowells,
	jdike, sam, Adrian Bunk, Randy Dunlap, phil.el, oprofile-list

[-- Attachment #1: fix-arm-to-play-nicely-with-generic-instrumentation-menu.patch --]
[-- Type: text/plain, Size: 4080 bytes --]

The conflicting commit for 
move-kconfiginstrumentation-to-arch-kconfig-and-init-kconfig.patch
is the ARM fix from Linus :

commit 38ad9aebe70dc72df08851bbd1620d89329129ba

He just seemed to agree that my approach (just putting the missing ARM
config options in arch/arm/Kconfig) works too. The main advantage it has
is that it is smaller, does not need a cleanup in the future and does
not break the following patches unnecessarily.

It's just been discussed here

http://lkml.org/lkml/2008/1/15/267

However, Linus might prefer to stay with his own patch and I would
totally understand it that late in the release cycle. Therefore I submit
this for the next release cycle.

After applying this patch,
move-kconfiginstrumentation-to-arch-kconfig-and-init-kconfig.patch
applies nicely in the -mm tree without any modification.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
CC: Linus Torvalds <torvalds@linux-foundation.org>
CC: Russell King <rmk+lkml@arm.linux.org.uk>
CC: Ingo Molnar <mingo@elte.hu>
CC: ananth@in.ibm.com
CC: dhowells@redhat.com
CC: jdike@addtoit.com
CC: sam@ravnborg.org
CC: Adrian Bunk <adrian.bunk@movial.fi>
CC: Randy Dunlap <randy.dunlap@oracle.com>
CC: phil.el@wanadoo.fr
CC: oprofile-list@lists.sourceforge.net
---
 arch/arm/Kconfig                 |   19 +++++++++++++-
 arch/arm/Kconfig.instrumentation |   52 ---------------------------------------
 2 files changed, 18 insertions(+), 53 deletions(-)

Index: linux-2.6-lttng.mm/arch/arm/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/arm/Kconfig	2008-01-24 14:10:37.000000000 -0500
+++ linux-2.6-lttng.mm/arch/arm/Kconfig	2008-01-24 14:18:00.000000000 -0500
@@ -144,6 +144,23 @@ config FIQ
 config ARCH_MTD_XIP
 	bool
 
+if OPROFILE
+
+config OPROFILE_ARMV6
+	def_bool y
+	depends on CPU_V6 && !SMP
+	select OPROFILE_ARM11_CORE
+
+config OPROFILE_MPCORE
+	def_bool y
+	depends on CPU_V6 && SMP
+	select OPROFILE_ARM11_CORE
+
+config OPROFILE_ARM11_CORE
+	bool
+
+endif
+
 config VECTORS_BASE
 	hex
 	default 0xffff0000 if MMU || CPU_HIGH_VECTOR
@@ -1132,7 +1149,7 @@ endmenu
 
 source "fs/Kconfig"
 
-source "arch/arm/Kconfig.instrumentation"
+source "kernel/Kconfig.instrumentation"
 
 source "arch/arm/Kconfig.debug"
 
Index: linux-2.6-lttng.mm/arch/arm/Kconfig.instrumentation
===================================================================
--- linux-2.6-lttng.mm.orig/arch/arm/Kconfig.instrumentation	2008-01-24 14:09:00.000000000 -0500
+++ /dev/null	1970-01-01 00:00:00.000000000 +0000
@@ -1,52 +0,0 @@
-menuconfig INSTRUMENTATION
-	bool "Instrumentation Support"
-	default y
-	---help---
-	  Say Y here to get to see options related to performance measurement,
-	  system-wide debugging, and testing. This option alone does not add any
-	  kernel code.
-
-	  If you say N, all options in this submenu will be skipped and
-	  disabled. If you're trying to debug the kernel itself, go see the
-	  Kernel Hacking menu.
-
-if INSTRUMENTATION
-
-config PROFILING
-	bool "Profiling support (EXPERIMENTAL)"
-	help
-	  Say Y here to enable the extended profiling support mechanisms used
-	  by profilers such as OProfile.
-
-config OPROFILE
-	tristate "OProfile system profiling (EXPERIMENTAL)"
-	depends on PROFILING && !UML
-	help
-	  OProfile is a profiling system capable of profiling the
-	  whole system, include the kernel, kernel modules, libraries,
-	  and applications.
-
-	  If unsure, say N.
-
-config OPROFILE_ARMV6
-	bool
-	depends on OPROFILE && CPU_V6 && !SMP
-	default y
-	select OPROFILE_ARM11_CORE
-
-config OPROFILE_MPCORE
-	bool
-	depends on OPROFILE && CPU_V6 && SMP
-	default y
-	select OPROFILE_ARM11_CORE
-
-config OPROFILE_ARM11_CORE
-	bool
-
-config MARKERS
-	bool "Activate markers"
-	help
-	  Place an empty function call at each marker site. Can be
-	  dynamically changed for a probe function.
-
-endif # INSTRUMENTATION

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 03/26] Move Kconfig.instrumentation to arch/Kconfig and init/Kconfig
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 01/26] Linux Kernel Markers Support for Proprierary Modules Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 02/26] Fix ARM to play nicely with generic Instrumentation menu Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 21:00   ` Randy Dunlap
                     ` (2 more replies)
  2008-01-24 20:27 ` [patch 04/26] Kprobes - use a mutex to protect the instruction pages list Mathieu Desnoyers
                   ` (22 subsequent siblings)
  25 siblings, 3 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel
  Cc: Mathieu Desnoyers, Linus Torvalds, Sam Ravnborg

[-- Attachment #1: move-kconfig-instrumentation-to-arch.patch --]
[-- Type: text/plain, Size: 15925 bytes --]

Move the instrumentation Kconfig to

arch/Kconfig for architecture dependent options
  - oprofile
  - kprobes

and

init/Kconfig for architecture independent options
  - profiling
  - markers

Remove the "Instrumentation Support" menu. Everything moves to "General setup".
Delete the kernel/Kconfig.instrumentation file.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
CC: Linus Torvalds <torvalds@linux-foundation.org>
CC: Sam Ravnborg <sam@ravnborg.org>
---
 arch/Kconfig                   |   28 ++++++++++++++++++++
 arch/alpha/Kconfig             |    2 -
 arch/arm/Kconfig               |    2 -
 arch/blackfin/Kconfig          |    2 -
 arch/cris/Kconfig              |    2 -
 arch/frv/Kconfig               |    2 -
 arch/h8300/Kconfig             |    2 -
 arch/ia64/Kconfig              |    2 -
 arch/m32r/Kconfig              |    2 -
 arch/m68k/Kconfig              |    2 -
 arch/m68knommu/Kconfig         |    2 -
 arch/mips/Kconfig              |    2 -
 arch/parisc/Kconfig            |    2 -
 arch/powerpc/Kconfig           |    2 -
 arch/ppc/Kconfig               |    2 -
 arch/s390/Kconfig              |    2 -
 arch/sh/Kconfig                |    2 -
 arch/sh64/Kconfig              |    2 -
 arch/sparc/Kconfig             |    2 -
 arch/sparc64/Kconfig           |    2 -
 arch/um/Kconfig                |    2 -
 arch/v850/Kconfig              |    2 -
 arch/x86/Kconfig               |    2 -
 arch/xtensa/Kconfig            |    2 -
 init/Kconfig                   |   12 ++++++++
 kernel/Kconfig.instrumentation |   55 -----------------------------------------
 26 files changed, 40 insertions(+), 101 deletions(-)

Index: linux-2.6-lttng.mm/arch/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/Kconfig	2008-01-24 14:10:37.000000000 -0500
+++ linux-2.6-lttng.mm/arch/Kconfig	2008-01-24 14:20:06.000000000 -0500
@@ -1,3 +1,31 @@
 #
 # General architecture dependent options
 #
+
+config OPROFILE
+	tristate "OProfile system profiling (EXPERIMENTAL)"
+	depends on PROFILING
+	depends on HAVE_OPROFILE
+	help
+	  OProfile is a profiling system capable of profiling the
+	  whole system, include the kernel, kernel modules, libraries,
+	  and applications.
+
+	  If unsure, say N.
+
+config HAVE_OPROFILE
+	def_bool n
+
+config KPROBES
+	bool "Kprobes"
+	depends on KALLSYMS && MODULES
+	depends on HAVE_KPROBES
+	help
+	  Kprobes allows you to trap at almost any kernel address and
+	  execute a callback function.  register_kprobe() establishes
+	  a probepoint and specifies the callback.  Kprobes is useful
+	  for kernel debugging, non-intrusive instrumentation and testing.
+	  If in doubt, say "N".
+
+config HAVE_KPROBES
+	def_bool n
Index: linux-2.6-lttng.mm/init/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/init/Kconfig	2008-01-24 14:10:55.000000000 -0500
+++ linux-2.6-lttng.mm/init/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -702,6 +702,18 @@ config PROC_PAGE_MONITOR
 	  /proc/kpagecount, and /proc/kpageflags. Disabling these
           interfaces will reduce the size of the kernel by approximately 4kb.
 
+config PROFILING
+	bool "Profiling support (EXPERIMENTAL)"
+	help
+	  Say Y here to enable the extended profiling support mechanisms used
+	  by profilers such as OProfile.
+
+config MARKERS
+	bool "Activate markers"
+	help
+	  Place an empty function call at each marker site. Can be
+	  dynamically changed for a probe function.
+
 source "arch/Kconfig"
 
 endmenu		# General setup
Index: linux-2.6-lttng.mm/arch/alpha/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/alpha/Kconfig	2008-01-24 14:10:37.000000000 -0500
+++ linux-2.6-lttng.mm/arch/alpha/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -653,8 +653,6 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/alpha/Kconfig.debug"
 
 # DUMMY_CONSOLE may be defined in drivers/video/console/Kconfig
Index: linux-2.6-lttng.mm/arch/arm/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/arm/Kconfig	2008-01-24 14:18:00.000000000 -0500
+++ linux-2.6-lttng.mm/arch/arm/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -1149,8 +1149,6 @@ endmenu
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/arm/Kconfig.debug"
 
 source "security/Kconfig"
Index: linux-2.6-lttng.mm/arch/blackfin/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/blackfin/Kconfig	2008-01-24 14:10:39.000000000 -0500
+++ linux-2.6-lttng.mm/arch/blackfin/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -1003,8 +1003,6 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/blackfin/Kconfig.debug"
 
 source "security/Kconfig"
Index: linux-2.6-lttng.mm/arch/cris/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/cris/Kconfig	2008-01-24 14:10:39.000000000 -0500
+++ linux-2.6-lttng.mm/arch/cris/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -214,8 +214,6 @@ source "drivers/pci/Kconfig"
 
 source "drivers/usb/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/cris/Kconfig.debug"
 
 source "security/Kconfig"
Index: linux-2.6-lttng.mm/arch/frv/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/frv/Kconfig	2008-01-24 14:10:39.000000000 -0500
+++ linux-2.6-lttng.mm/arch/frv/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -384,8 +384,6 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/frv/Kconfig.debug"
 
 source "security/Kconfig"
Index: linux-2.6-lttng.mm/arch/h8300/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/h8300/Kconfig	2008-01-24 14:10:39.000000000 -0500
+++ linux-2.6-lttng.mm/arch/h8300/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -226,8 +226,6 @@ endmenu
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/h8300/Kconfig.debug"
 
 source "security/Kconfig"
Index: linux-2.6-lttng.mm/arch/ia64/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/ia64/Kconfig	2008-01-24 14:10:39.000000000 -0500
+++ linux-2.6-lttng.mm/arch/ia64/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -602,8 +602,6 @@ config IRQ_PER_CPU
 
 source "arch/ia64/hp/sim/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/ia64/Kconfig.debug"
 
 source "security/Kconfig"
Index: linux-2.6-lttng.mm/arch/m32r/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/m32r/Kconfig	2008-01-24 14:10:39.000000000 -0500
+++ linux-2.6-lttng.mm/arch/m32r/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -430,8 +430,6 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/m32r/Kconfig.debug"
 
 source "security/Kconfig"
Index: linux-2.6-lttng.mm/arch/m68k/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/m68k/Kconfig	2008-01-24 14:10:39.000000000 -0500
+++ linux-2.6-lttng.mm/arch/m68k/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -667,8 +667,6 @@ endmenu
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/m68k/Kconfig.debug"
 
 source "security/Kconfig"
Index: linux-2.6-lttng.mm/arch/m68knommu/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/m68knommu/Kconfig	2008-01-24 14:10:39.000000000 -0500
+++ linux-2.6-lttng.mm/arch/m68knommu/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -710,8 +710,6 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/m68knommu/Kconfig.debug"
 
 source "security/Kconfig"
Index: linux-2.6-lttng.mm/arch/mips/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/mips/Kconfig	2008-01-24 14:10:39.000000000 -0500
+++ linux-2.6-lttng.mm/arch/mips/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -2096,8 +2096,6 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/mips/Kconfig.debug"
 
 source "security/Kconfig"
Index: linux-2.6-lttng.mm/arch/parisc/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/parisc/Kconfig	2008-01-24 14:10:40.000000000 -0500
+++ linux-2.6-lttng.mm/arch/parisc/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -276,8 +276,6 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/parisc/Kconfig.debug"
 
 source "security/Kconfig"
Index: linux-2.6-lttng.mm/arch/powerpc/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/powerpc/Kconfig	2008-01-24 14:10:40.000000000 -0500
+++ linux-2.6-lttng.mm/arch/powerpc/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -713,8 +713,6 @@ source "arch/powerpc/sysdev/qe_lib/Kconf
 
 source "lib/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/powerpc/Kconfig.debug"
 
 source "security/Kconfig"
Index: linux-2.6-lttng.mm/arch/ppc/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/ppc/Kconfig	2008-01-24 14:10:41.000000000 -0500
+++ linux-2.6-lttng.mm/arch/ppc/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -1319,8 +1319,6 @@ endmenu
 
 source "lib/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/ppc/Kconfig.debug"
 
 source "security/Kconfig"
Index: linux-2.6-lttng.mm/arch/s390/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/s390/Kconfig	2008-01-24 14:10:41.000000000 -0500
+++ linux-2.6-lttng.mm/arch/s390/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -528,8 +528,6 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/s390/Kconfig.debug"
 
 source "security/Kconfig"
Index: linux-2.6-lttng.mm/arch/sh/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/sh/Kconfig	2008-01-24 14:10:41.000000000 -0500
+++ linux-2.6-lttng.mm/arch/sh/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -899,8 +899,6 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/sh/Kconfig.debug"
 
 source "security/Kconfig"
Index: linux-2.6-lttng.mm/arch/sh64/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/sh64/Kconfig	2008-01-24 14:10:41.000000000 -0500
+++ linux-2.6-lttng.mm/arch/sh64/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -279,8 +279,6 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/sh64/Kconfig.debug"
 
 source "security/Kconfig"
Index: linux-2.6-lttng.mm/arch/sparc/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/sparc/Kconfig	2008-01-24 14:10:41.000000000 -0500
+++ linux-2.6-lttng.mm/arch/sparc/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -324,8 +324,6 @@ endmenu
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/sparc/Kconfig.debug"
 
 source "security/Kconfig"
Index: linux-2.6-lttng.mm/arch/sparc64/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/sparc64/Kconfig	2008-01-24 14:10:41.000000000 -0500
+++ linux-2.6-lttng.mm/arch/sparc64/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -470,8 +470,6 @@ source "drivers/sbus/char/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/sparc64/Kconfig.debug"
 
 source "security/Kconfig"
Index: linux-2.6-lttng.mm/arch/um/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/um/Kconfig	2008-01-24 14:10:42.000000000 -0500
+++ linux-2.6-lttng.mm/arch/um/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -271,6 +271,4 @@ config INPUT
 	bool
 	default n
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/um/Kconfig.debug"
Index: linux-2.6-lttng.mm/arch/v850/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/v850/Kconfig	2008-01-24 14:10:42.000000000 -0500
+++ linux-2.6-lttng.mm/arch/v850/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -334,8 +334,6 @@ source "sound/Kconfig"
 
 source "drivers/usb/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/v850/Kconfig.debug"
 
 source "security/Kconfig"
Index: linux-2.6-lttng.mm/arch/xtensa/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/xtensa/Kconfig	2008-01-24 14:10:42.000000000 -0500
+++ linux-2.6-lttng.mm/arch/xtensa/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -246,8 +246,6 @@ config EMBEDDED_RAMDISK_IMAGE
 	  provide one yourself.
 endmenu
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/xtensa/Kconfig.debug"
 
 source "security/Kconfig"
Index: linux-2.6-lttng.mm/arch/x86/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/x86/Kconfig	2008-01-24 14:10:42.000000000 -0500
+++ linux-2.6-lttng.mm/arch/x86/Kconfig	2008-01-24 14:18:34.000000000 -0500
@@ -1609,8 +1609,6 @@ source "drivers/firmware/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/x86/Kconfig.debug"
 
 source "security/Kconfig"
Index: linux-2.6-lttng.mm/kernel/Kconfig.instrumentation
===================================================================
--- linux-2.6-lttng.mm.orig/kernel/Kconfig.instrumentation	2008-01-24 14:10:55.000000000 -0500
+++ /dev/null	1970-01-01 00:00:00.000000000 +0000
@@ -1,55 +0,0 @@
-menuconfig INSTRUMENTATION
-	bool "Instrumentation Support"
-	default y
-	---help---
-	  Say Y here to get to see options related to performance measurement,
-	  system-wide debugging, and testing. This option alone does not add any
-	  kernel code.
-
-	  If you say N, all options in this submenu will be skipped and
-	  disabled. If you're trying to debug the kernel itself, go see the
-	  Kernel Hacking menu.
-
-if INSTRUMENTATION
-
-config PROFILING
-	bool "Profiling support (EXPERIMENTAL)"
-	help
-	  Say Y here to enable the extended profiling support mechanisms used
-	  by profilers such as OProfile.
-
-config OPROFILE
-	tristate "OProfile system profiling (EXPERIMENTAL)"
-	depends on PROFILING
-	depends on HAVE_OPROFILE
-	help
-	  OProfile is a profiling system capable of profiling the
-	  whole system, include the kernel, kernel modules, libraries,
-	  and applications.
-
-	  If unsure, say N.
-
-config HAVE_OPROFILE
-	def_bool n
-
-config KPROBES
-	bool "Kprobes"
-	depends on KALLSYMS && MODULES
-	depends on HAVE_KPROBES
-	help
-	  Kprobes allows you to trap at almost any kernel address and
-	  execute a callback function.  register_kprobe() establishes
-	  a probepoint and specifies the callback.  Kprobes is useful
-	  for kernel debugging, non-intrusive instrumentation and testing.
-	  If in doubt, say "N".
-
-config HAVE_KPROBES
-	def_bool n
-
-config MARKERS
-	bool "Activate markers"
-	help
-	  Place an empty function call at each marker site. Can be
-	  dynamically changed for a probe function.
-
-endif # INSTRUMENTATION

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 04/26] Kprobes - use a mutex to protect the instruction pages list.
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (2 preceding siblings ...)
  2008-01-24 20:27 ` [patch 03/26] Move Kconfig.instrumentation to arch/Kconfig and init/Kconfig Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 05/26] Kprobes - do not use kprobes mutex in arch code Mathieu Desnoyers
                   ` (21 subsequent siblings)
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel
  Cc: Mathieu Desnoyers, Ananth N Mavinakayanahalli, hch,
	anil.s.keshavamurthy, davem

[-- Attachment #1: kprobes-use-mutex-for-insn-pages.patch --]
[-- Type: text/plain, Size: 3601 bytes --]

Protect the instruction pages list by a specific insn pages mutex, called in 
get_insn_slot() and free_insn_slot(). It makes sure that architectures that does
not need to call arch_remove_kprobe() does not take an unneeded kprobes mutex.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Acked-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
CC: hch@infradead.org
CC: anil.s.keshavamurthy@intel.com
CC: davem@davemloft.net
---
 kernel/kprobes.c |   27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

Index: linux-2.6-lttng/kernel/kprobes.c
===================================================================
--- linux-2.6-lttng.orig/kernel/kprobes.c	2007-08-27 11:48:56.000000000 -0400
+++ linux-2.6-lttng/kernel/kprobes.c	2007-08-27 11:48:58.000000000 -0400
@@ -95,6 +95,10 @@ enum kprobe_slot_state {
 	SLOT_USED = 2,
 };
 
+/*
+ * Protects the kprobe_insn_pages list. Can nest into kprobe_mutex.
+ */
+static DEFINE_MUTEX(kprobe_insn_mutex);
 static struct hlist_head kprobe_insn_pages;
 static int kprobe_garbage_slots;
 static int collect_garbage_slots(void);
@@ -131,7 +135,9 @@ kprobe_opcode_t __kprobes *get_insn_slot
 {
 	struct kprobe_insn_page *kip;
 	struct hlist_node *pos;
+	kprobe_opcode_t *ret;
 
+	mutex_lock(&kprobe_insn_mutex);
  retry:
 	hlist_for_each_entry(kip, pos, &kprobe_insn_pages, hlist) {
 		if (kip->nused < INSNS_PER_PAGE) {
@@ -140,7 +146,8 @@ kprobe_opcode_t __kprobes *get_insn_slot
 				if (kip->slot_used[i] == SLOT_CLEAN) {
 					kip->slot_used[i] = SLOT_USED;
 					kip->nused++;
-					return kip->insns + (i * MAX_INSN_SIZE);
+					ret = kip->insns + (i * MAX_INSN_SIZE);
+					goto end;
 				}
 			}
 			/* Surprise!  No unused slots.  Fix kip->nused. */
@@ -154,8 +161,10 @@ kprobe_opcode_t __kprobes *get_insn_slot
 	}
 	/* All out of space.  Need to allocate a new page. Use slot 0. */
 	kip = kmalloc(sizeof(struct kprobe_insn_page), GFP_KERNEL);
-	if (!kip)
-		return NULL;
+	if (!kip) {
+		ret = NULL;
+		goto end;
+	}
 
 	/*
 	 * Use module_alloc so this page is within +/- 2GB of where the
@@ -165,7 +174,8 @@ kprobe_opcode_t __kprobes *get_insn_slot
 	kip->insns = module_alloc(PAGE_SIZE);
 	if (!kip->insns) {
 		kfree(kip);
-		return NULL;
+		ret = NULL;
+		goto end;
 	}
 	INIT_HLIST_NODE(&kip->hlist);
 	hlist_add_head(&kip->hlist, &kprobe_insn_pages);
@@ -173,7 +183,10 @@ kprobe_opcode_t __kprobes *get_insn_slot
 	kip->slot_used[0] = SLOT_USED;
 	kip->nused = 1;
 	kip->ngarbage = 0;
-	return kip->insns;
+	ret = kip->insns;
+end:
+	mutex_unlock(&kprobe_insn_mutex);
+	return ret;
 }
 
 /* Return 1 if all garbages are collected, otherwise 0. */
@@ -207,7 +220,7 @@ static int __kprobes collect_garbage_slo
 	struct kprobe_insn_page *kip;
 	struct hlist_node *pos, *next;
 
-	/* Ensure no-one is preepmted on the garbages */
+	/* Ensure no-one is preempted on the garbages */
 	if (check_safety() != 0)
 		return -EAGAIN;
 
@@ -231,6 +244,7 @@ void __kprobes free_insn_slot(kprobe_opc
 	struct kprobe_insn_page *kip;
 	struct hlist_node *pos;
 
+	mutex_lock(&kprobe_insn_mutex);
 	hlist_for_each_entry(kip, pos, &kprobe_insn_pages, hlist) {
 		if (kip->insns <= slot &&
 		    slot < kip->insns + (INSNS_PER_PAGE * MAX_INSN_SIZE)) {
@@ -247,6 +261,7 @@ void __kprobes free_insn_slot(kprobe_opc
 
 	if (dirty && ++kprobe_garbage_slots > INSNS_PER_PAGE)
 		collect_garbage_slots();
+	mutex_unlock(&kprobe_insn_mutex);
 }
 #endif
 

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 05/26] Kprobes - do not use kprobes mutex in arch code
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (3 preceding siblings ...)
  2008-01-24 20:27 ` [patch 04/26] Kprobes - use a mutex to protect the instruction pages list Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 06/26] Kprobes - declare kprobe_mutex static Mathieu Desnoyers
                   ` (20 subsequent siblings)
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel
  Cc: Mathieu Desnoyers, Ananth N Mavinakayanahalli,
	anil.s.keshavamurthy, davem

[-- Attachment #1: kprobes-dont-use-kprobes-mutex-in-arch-code.patch --]
[-- Type: text/plain, Size: 4574 bytes --]

Remove the kprobes mutex from kprobes.h, since it does not belong there. Also
remove all use of this mutex in the architecture specific code, replacing it by
a proper mutex lock/unlock in the architecture agnostic code.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Acked-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
CC: anil.s.keshavamurthy@intel.com
CC: davem@davemloft.net
---
 arch/ia64/kernel/kprobes.c    |    2 --
 arch/powerpc/kernel/kprobes.c |    2 --
 arch/s390/kernel/kprobes.c    |    2 --
 arch/x86/kernel/kprobes.c     |    2 --
 include/linux/kprobes.h       |    2 --
 kernel/kprobes.c              |    2 ++
 6 files changed, 2 insertions(+), 10 deletions(-)

Index: linux-2.6-lttng.mm/include/linux/kprobes.h
===================================================================
--- linux-2.6-lttng.mm.orig/include/linux/kprobes.h	2008-01-24 14:10:54.000000000 -0500
+++ linux-2.6-lttng.mm/include/linux/kprobes.h	2008-01-24 14:20:48.000000000 -0500
@@ -35,7 +35,6 @@
 #include <linux/percpu.h>
 #include <linux/spinlock.h>
 #include <linux/rcupdate.h>
-#include <linux/mutex.h>
 
 #ifdef CONFIG_KPROBES
 #include <asm/kprobes.h>
@@ -192,7 +191,6 @@ static inline int init_test_probes(void)
 #endif /* CONFIG_KPROBES_SANITY_TEST */
 
 extern spinlock_t kretprobe_lock;
-extern struct mutex kprobe_mutex;
 extern int arch_prepare_kprobe(struct kprobe *p);
 extern void arch_arm_kprobe(struct kprobe *p);
 extern void arch_disarm_kprobe(struct kprobe *p);
Index: linux-2.6-lttng.mm/kernel/kprobes.c
===================================================================
--- linux-2.6-lttng.mm.orig/kernel/kprobes.c	2008-01-24 14:20:17.000000000 -0500
+++ linux-2.6-lttng.mm/kernel/kprobes.c	2008-01-24 14:20:48.000000000 -0500
@@ -644,7 +644,9 @@ valid_p:
 			list_del_rcu(&p->list);
 			kfree(old_p);
 		}
+		mutex_lock(&kprobe_mutex);
 		arch_remove_kprobe(p);
+		mutex_unlock(&kprobe_mutex);
 	} else {
 		mutex_lock(&kprobe_mutex);
 		if (p->break_handler)
Index: linux-2.6-lttng.mm/arch/ia64/kernel/kprobes.c
===================================================================
--- linux-2.6-lttng.mm.orig/arch/ia64/kernel/kprobes.c	2008-01-24 14:09:02.000000000 -0500
+++ linux-2.6-lttng.mm/arch/ia64/kernel/kprobes.c	2008-01-24 14:20:48.000000000 -0500
@@ -582,9 +582,7 @@ void __kprobes arch_disarm_kprobe(struct
 
 void __kprobes arch_remove_kprobe(struct kprobe *p)
 {
-	mutex_lock(&kprobe_mutex);
 	free_insn_slot(p->ainsn.insn, 0);
-	mutex_unlock(&kprobe_mutex);
 }
 /*
  * We are resuming execution after a single step fault, so the pt_regs
Index: linux-2.6-lttng.mm/arch/powerpc/kernel/kprobes.c
===================================================================
--- linux-2.6-lttng.mm.orig/arch/powerpc/kernel/kprobes.c	2008-01-24 14:03:11.000000000 -0500
+++ linux-2.6-lttng.mm/arch/powerpc/kernel/kprobes.c	2008-01-24 14:20:48.000000000 -0500
@@ -88,9 +88,7 @@ void __kprobes arch_disarm_kprobe(struct
 
 void __kprobes arch_remove_kprobe(struct kprobe *p)
 {
-	mutex_lock(&kprobe_mutex);
 	free_insn_slot(p->ainsn.insn, 0);
-	mutex_unlock(&kprobe_mutex);
 }
 
 static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
Index: linux-2.6-lttng.mm/arch/s390/kernel/kprobes.c
===================================================================
--- linux-2.6-lttng.mm.orig/arch/s390/kernel/kprobes.c	2008-01-24 14:03:14.000000000 -0500
+++ linux-2.6-lttng.mm/arch/s390/kernel/kprobes.c	2008-01-24 14:20:48.000000000 -0500
@@ -220,9 +220,7 @@ void __kprobes arch_disarm_kprobe(struct
 
 void __kprobes arch_remove_kprobe(struct kprobe *p)
 {
-	mutex_lock(&kprobe_mutex);
 	free_insn_slot(p->ainsn.insn, 0);
-	mutex_unlock(&kprobe_mutex);
 }
 
 static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
Index: linux-2.6-lttng.mm/arch/x86/kernel/kprobes.c
===================================================================
--- linux-2.6-lttng.mm.orig/arch/x86/kernel/kprobes.c	2008-01-24 14:21:07.000000000 -0500
+++ linux-2.6-lttng.mm/arch/x86/kernel/kprobes.c	2008-01-24 14:22:46.000000000 -0500
@@ -376,9 +376,7 @@ void __kprobes arch_disarm_kprobe(struct
 
 void __kprobes arch_remove_kprobe(struct kprobe *p)
 {
-	mutex_lock(&kprobe_mutex);
 	free_insn_slot(p->ainsn.insn, (p->ainsn.boostable == 1));
-	mutex_unlock(&kprobe_mutex);
 }
 
 static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 06/26] Kprobes - declare kprobe_mutex static
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (4 preceding siblings ...)
  2008-01-24 20:27 ` [patch 05/26] Kprobes - do not use kprobes mutex in arch code Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 07/26] Add INIT_ARRAY() to kernel.h Mathieu Desnoyers
                   ` (19 subsequent siblings)
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel
  Cc: Mathieu Desnoyers, Ananth N Mavinakayanahalli, hch,
	anil.s.keshavamurthy, davem

[-- Attachment #1: kprobes-declare-kprobes-mutex-static.patch --]
[-- Type: text/plain, Size: 1205 bytes --]

Since it will not be used by other kernel objects, it makes sense to declare it
static.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Acked-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
CC: hch@infradead.org
CC: anil.s.keshavamurthy@intel.com
CC: davem@davemloft.net
---
 kernel/kprobes.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-2.6-lttng/kernel/kprobes.c
===================================================================
--- linux-2.6-lttng.orig/kernel/kprobes.c	2007-08-19 09:09:15.000000000 -0400
+++ linux-2.6-lttng/kernel/kprobes.c	2007-08-19 17:18:07.000000000 -0400
@@ -68,7 +68,7 @@ static struct hlist_head kretprobe_inst_
 /* NOTE: change this value only with kprobe_mutex held */
 static bool kprobe_enabled;
 
-DEFINE_MUTEX(kprobe_mutex);		/* Protects kprobe_table */
+static DEFINE_MUTEX(kprobe_mutex);	/* Protects kprobe_table */
 DEFINE_SPINLOCK(kretprobe_lock);	/* Protects kretprobe_inst_table */
 static DEFINE_PER_CPU(struct kprobe *, kprobe_instance) = NULL;
 

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 07/26] Add INIT_ARRAY() to kernel.h
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (5 preceding siblings ...)
  2008-01-24 20:27 ` [patch 06/26] Kprobes - declare kprobe_mutex static Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:39   ` Jan Engelhardt
                     ` (2 more replies)
  2008-01-24 20:27 ` [patch 08/26] Text Edit Lock - Architecture Independent Code Mathieu Desnoyers
                   ` (18 subsequent siblings)
  25 siblings, 3 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel; +Cc: Mathieu Desnoyers

[-- Attachment #1: declare-array.patch --]
[-- Type: text/plain, Size: 977 bytes --]

Add initialization of an array, which needs brackets that would pollute kernel
code, to kernel.h. It is used to declare arguments passed as function parameters
such as:
text_poke(addr, INIT_ARRAY(unsigned char, 0xf0, len), len);

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
---
 include/linux/kernel.h |    2 ++
 1 file changed, 2 insertions(+)

Index: linux-2.6-lttng.mm/include/linux/kernel.h
===================================================================
--- linux-2.6-lttng.mm.orig/include/linux/kernel.h	2008-01-24 14:10:54.000000000 -0500
+++ linux-2.6-lttng.mm/include/linux/kernel.h	2008-01-24 14:23:06.000000000 -0500
@@ -423,4 +423,6 @@ struct sysinfo {
 #define NUMA_BUILD 0
 #endif
 
+#define INIT_ARRAY(type, val, len) ((type [len]) { [0 ... (len)-1] = (val) })
+
 #endif

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 08/26] Text Edit Lock - Architecture Independent Code
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (6 preceding siblings ...)
  2008-01-24 20:27 ` [patch 07/26] Add INIT_ARRAY() to kernel.h Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 09/26] Text Edit Lock - Alternative code for x86 Mathieu Desnoyers
                   ` (17 subsequent siblings)
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel; +Cc: Mathieu Desnoyers, Andi Kleen

[-- Attachment #1: text-edit-lock-architecture-independent-code.patch --]
[-- Type: text/plain, Size: 3160 bytes --]

This is an architecture independant synchronization around kernel text
modifications through use of a global mutex.

A mutex has been chosen so that kprobes, the main user of this, can sleep during
memory allocation between the memory read of the instructions it must replace
and the memory write of the breakpoint.

Other user of this interface: immediate values.

Paravirt and alternatives are always done when SMP is inactive, so there is no
need to use locks.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
CC: Andi Kleen <andi@firstfloor.org>
---
 include/linux/memory.h |    7 +++++++
 mm/memory.c            |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

Index: linux-2.6-lttng.mm/include/linux/memory.h
===================================================================
--- linux-2.6-lttng.mm.orig/include/linux/memory.h	2008-01-24 14:10:54.000000000 -0500
+++ linux-2.6-lttng.mm/include/linux/memory.h	2008-01-24 14:23:14.000000000 -0500
@@ -92,4 +92,11 @@ extern int memory_notify(unsigned long v
 #define hotplug_memory_notifier(fn, pri) do { } while (0)
 #endif
 
+/*
+ * Take and release the kernel text modification lock, used for code patching.
+ * Users of this lock can sleep.
+ */
+extern void kernel_text_lock(void);
+extern void kernel_text_unlock(void);
+
 #endif /* _LINUX_MEMORY_H_ */
Index: linux-2.6-lttng.mm/mm/memory.c
===================================================================
--- linux-2.6-lttng.mm.orig/mm/memory.c	2008-01-24 14:10:56.000000000 -0500
+++ linux-2.6-lttng.mm/mm/memory.c	2008-01-24 14:23:41.000000000 -0500
@@ -51,6 +51,8 @@
 #include <linux/init.h>
 #include <linux/writeback.h>
 #include <linux/memcontrol.h>
+#include <linux/kprobes.h>
+#include <linux/mutex.h>
 
 #include <asm/pgalloc.h>
 #include <asm/uaccess.h>
@@ -85,6 +87,12 @@ EXPORT_SYMBOL(high_memory);
 
 int randomize_va_space __read_mostly = 1;
 
+/*
+ * mutex protecting text section modification (dynamic code patching).
+ * some users need to sleep (allocating memory...) while they hold this lock.
+ */
+static DEFINE_MUTEX(text_mutex);
+
 static int __init disable_randmaps(char *s)
 {
 	randomize_va_space = 0;
@@ -2674,3 +2682,29 @@ int access_process_vm(struct task_struct
 
 	return buf - old_buf;
 }
+
+/**
+ * kernel_text_lock     -   Take the kernel text modification lock
+ *
+ * Insures mutual write exclusion of kernel and modules text live text
+ * modification. Should be used for code patching.
+ * Users of this lock can sleep.
+ */
+void __kprobes kernel_text_lock(void)
+{
+	mutex_lock(&text_mutex);
+}
+EXPORT_SYMBOL_GPL(kernel_text_lock);
+
+/**
+ * kernel_text_unlock   -   Release the kernel text modification lock
+ *
+ * Insures mutual write exclusion of kernel and modules text live text
+ * modification. Should be used for code patching.
+ * Users of this lock can sleep.
+ */
+void __kprobes kernel_text_unlock(void)
+{
+	mutex_unlock(&text_mutex);
+}
+EXPORT_SYMBOL_GPL(kernel_text_unlock);

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 09/26] Text Edit Lock - Alternative code for x86
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (7 preceding siblings ...)
  2008-01-24 20:27 ` [patch 08/26] Text Edit Lock - Architecture Independent Code Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 10/26] Text Edit Lock - kprobes architecture independent support Mathieu Desnoyers
                   ` (16 subsequent siblings)
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel
  Cc: Mathieu Desnoyers, Andi Kleen, pageexec, Thomas Gleixner,
	Ingo Molnar, H. Peter Anvin

[-- Attachment #1: text-edit-lock-alternative-i386-and-x86_64.patch --]
[-- Type: text/plain, Size: 7593 bytes --]

Fix a memcpy that should be a text_poke (in apply_alternatives).

Use kernel_wp_save/kernel_wp_restore in text_poke to support DEBUG_RODATA
correctly and so the CPU HOTPLUG special case can be removed.

Add text_poke_early, for alternatives and paravirt boot-time and module load
time patching.

Notes:
- A macro is used instead of an inline function to deal with circular header
  include otherwise necessary for read_cr0 and preempt_disable/enable.

Changelog:

- Fix text_set and text_poke alignment check (mixed up bitwise and and or)
- Remove text_set
- Use the new macro INIT_ARRAY() to stop polluting the C files with ({ })
  brackets (which breaks some c parsers in editors).
- Export add_nops, so it can be used by others.
- Remove x86 test for "wp_works_ok", it will just be ignored by the architecture
  if not supported.
- Document text_poke_early.
- Remove clflush, since it breaks some VIA architectures and is not strictly
  necessary.
- Add kerneldoc to text_poke and text_poke_early.
- Remove arg cr0 from kernel_wp_save/restore. Change the macro name for
  kernel_wp_disable/enable.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
CC: Andi Kleen <andi@firstfloor.org>
CC: pageexec@freemail.hu
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Ingo Molnar <mingo@redhat.com>
CC: H. Peter Anvin <hpa@zytor.com>
---
 arch/x86/kernel/alternative.c |   56 ++++++++++++++++++++++++++++++++++--------
 include/asm-x86/alternative.h |   36 ++++++++++++++++++++++++++-
 2 files changed, 81 insertions(+), 11 deletions(-)

Index: linux-2.6-lttng.mm/arch/x86/kernel/alternative.c
===================================================================
--- linux-2.6-lttng.mm.orig/arch/x86/kernel/alternative.c	2008-01-24 14:10:42.000000000 -0500
+++ linux-2.6-lttng.mm/arch/x86/kernel/alternative.c	2008-01-24 14:23:52.000000000 -0500
@@ -173,7 +173,7 @@ static const unsigned char*const * find_
 #endif /* CONFIG_X86_64 */
 
 /* Use this to add nops to a buffer, then text_poke the whole buffer. */
-static void add_nops(void *insns, unsigned int len)
+void add_nops(void *insns, unsigned int len)
 {
 	const unsigned char *const *noptable = find_nop_table();
 
@@ -186,6 +186,7 @@ static void add_nops(void *insns, unsign
 		len -= noplen;
 	}
 }
+EXPORT_SYMBOL_GPL(add_nops);
 
 extern struct alt_instr __alt_instructions[], __alt_instructions_end[];
 extern u8 *__smp_locks[], *__smp_locks_end[];
@@ -219,7 +220,7 @@ void apply_alternatives(struct alt_instr
 		memcpy(insnbuf, a->replacement, a->replacementlen);
 		add_nops(insnbuf + a->replacementlen,
 			 a->instrlen - a->replacementlen);
-		text_poke(instr, insnbuf, a->instrlen);
+		text_poke_early(instr, insnbuf, a->instrlen);
 	}
 }
 
@@ -234,7 +235,8 @@ static void alternatives_smp_lock(u8 **s
 			continue;
 		if (*ptr > text_end)
 			continue;
-		text_poke(*ptr, ((unsigned char []){0xf0}), 1); /* add lock prefix */
+		/* add lock prefix */
+		text_poke(*ptr, INIT_ARRAY(unsigned char, 0xf0, 1), 1);
 	};
 }
 
@@ -397,7 +399,7 @@ void apply_paravirt(struct paravirt_patc
 
 		/* Pad the rest with nops */
 		add_nops(insnbuf + used, p->len - used);
-		text_poke(p->instr, insnbuf, p->len);
+		text_poke_early(p->instr, insnbuf, p->len);
 	}
 }
 extern struct paravirt_patch_site __start_parainstructions[],
@@ -458,18 +460,52 @@ void __init alternative_instructions(voi
 #endif
 }
 
-/*
- * Warning:
+/**
+ * text_poke_early - Update instructions on a live kernel at boot time
+ * @addr: address to modify
+ * @opcode: source of the copy
+ * @len: length to copy
+ *
  * When you use this code to patch more than one byte of an instruction
  * you need to make sure that other CPUs cannot execute this code in parallel.
- * Also no thread must be currently preempted in the middle of these instructions.
- * And on the local CPU you need to be protected again NMI or MCE handlers
- * seeing an inconsistent instruction while you patch.
+ * Also no thread must be currently preempted in the middle of these
+ * instructions.  And on the local CPU you need to be protected again NMI or MCE
+ * handlers seeing an inconsistent instruction while you patch.
+ * Warning: read_cr0 is modified by paravirt, this is why we have _early
+ * versions. They are not in the __init section because they can be used at
+ * module load time.
  */
-void __kprobes text_poke(void *addr, unsigned char *opcode, int len)
+void *text_poke_early(void *addr, const void *opcode, size_t len)
 {
 	memcpy(addr, opcode, len);
 	sync_core();
 	/* Could also do a CLFLUSH here to speed up CPU recovery; but
 	   that causes hangs on some VIA CPUs. */
+	return addr;
 }
+
+/**
+ * text_poke - Update instructions on a live kernel
+ * @addr: address to modify
+ * @opcode: source of the copy
+ * @len: length to copy
+ *
+ * Only atomic text poke/set should be allowed when not doing early patching.
+ * It means the size must be writable atomically and the address must be aligned
+ * in a way that permits an atomic write.
+ */
+void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
+{
+	BUG_ON(len > sizeof(long));
+	BUG_ON((((long)addr + len - 1) & ~(sizeof(long) - 1))
+		- ((long)addr & ~(sizeof(long) - 1)));
+	kernel_wp_disable();
+	memcpy(addr, opcode, len);
+	kernel_wp_enable();
+	sync_core();
+	/* Could also do a CLFLUSH here to speed up CPU recovery; but
+	   that causes hangs on some VIA CPUs. */
+	return addr;
+}
+
+
Index: linux-2.6-lttng.mm/include/asm-x86/alternative.h
===================================================================
--- linux-2.6-lttng.mm.orig/include/asm-x86/alternative.h	2008-01-24 14:25:01.000000000 -0500
+++ linux-2.6-lttng.mm/include/asm-x86/alternative.h	2008-01-24 14:26:11.000000000 -0500
@@ -4,6 +4,7 @@
 #include <linux/types.h>
 #include <linux/stddef.h>
 #include <asm/asm.h>
+#include <asm/processor-flags.h>
 
 /*
  * Alternative inline assembly for SMP.
@@ -156,6 +157,39 @@ apply_paravirt(struct paravirt_patch_sit
 #define __parainstructions_end	NULL
 #endif
 
-extern void text_poke(void *addr, unsigned char *opcode, int len);
+extern void add_nops(void *insns, unsigned int len);
+
+/*
+ * Clear and restore the kernel write-protection flag on the local CPU.
+ * Allows the kernel to edit read-only pages.
+ * Side-effect: any interrupt handler running between save and restore will have
+ * the ability to write to read-only pages.
+ *
+ * Warning:
+ * Code patching in the UP case is safe if NMIs and MCE handlers are stopped and
+ * no thread can be preempted in the instructions being modified (no iret to an
+ * invalid instruction possible) or if the instructions are changed from a
+ * consistent state to another consistent state atomically.
+ * More care must be taken when modifying code in the SMP case because of
+ * Intel's errata.
+ * On the local CPU you need to be protected again NMI or MCE handlers seeing an
+ * inconsistent instruction while you patch.
+ * The _early version does not use read_cr0(), which can be paravirtualized.
+ */
+
+extern void *text_poke(void *addr, const void *opcode, size_t len);
+extern void *text_poke_early(void *addr, const void *opcode, size_t len);
+
+#define kernel_wp_disable()			\
+do {						\
+	preempt_disable();			\
+	write_cr0(read_cr0() & ~X86_CR0_WP);	\
+} while (0)
+
+#define kernel_wp_enable()			\
+do {						\
+	write_cr0(read_cr0() | X86_CR0_WP);	\
+	preempt_enable();			\
+} while (0)
 
 #endif /* _ASM_X86_ALTERNATIVE_H */

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 10/26] Text Edit Lock - kprobes architecture independent support
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (8 preceding siblings ...)
  2008-01-24 20:27 ` [patch 09/26] Text Edit Lock - Alternative code for x86 Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 11/26] Text Edit Lock - kprobes x86 Mathieu Desnoyers
                   ` (15 subsequent siblings)
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel
  Cc: Mathieu Desnoyers, Ananth N Mavinakayanahalli,
	anil.s.keshavamurthy, davem, Roel Kluin

[-- Attachment #1: text-edit-lock-kprobes-architecture-independent.patch --]
[-- Type: text/plain, Size: 3352 bytes --]

Use the mutual exclusion provided by the text edit lock in the kprobes code. It
allows coherent manipulation of the kernel code by other subsystems.

Changelog:

Move the kernel_text_lock/unlock out of the for loops.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Acked-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
CC: ananth@in.ibm.com
CC: anil.s.keshavamurthy@intel.com
CC: davem@davemloft.net
CC: Roel Kluin <12o3l@tiscali.nl>
---
 kernel/kprobes.c |   19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

Index: linux-2.6-lttng.mm/kernel/kprobes.c
===================================================================
--- linux-2.6-lttng.mm.orig/kernel/kprobes.c	2008-01-24 14:23:02.000000000 -0500
+++ linux-2.6-lttng.mm/kernel/kprobes.c	2008-01-24 14:26:28.000000000 -0500
@@ -43,6 +43,7 @@
 #include <linux/seq_file.h>
 #include <linux/debugfs.h>
 #include <linux/kdebug.h>
+#include <linux/memory.h>
 
 #include <asm-generic/sections.h>
 #include <asm/cacheflush.h>
@@ -568,9 +569,10 @@ static int __kprobes __register_kprobe(s
 		goto out;
 	}
 
+	kernel_text_lock();
 	ret = arch_prepare_kprobe(p);
 	if (ret)
-		goto out;
+		goto out_unlock_text;
 
 	INIT_HLIST_NODE(&p->hlist);
 	hlist_add_head_rcu(&p->hlist,
@@ -578,7 +580,8 @@ static int __kprobes __register_kprobe(s
 
 	if (kprobe_enabled)
 		arch_arm_kprobe(p);
-
+out_unlock_text:
+	kernel_text_unlock();
 out:
 	mutex_unlock(&kprobe_mutex);
 
@@ -621,8 +624,11 @@ valid_p:
 		 * enabled - otherwise, the breakpoint would already have
 		 * been removed. We save on flushing icache.
 		 */
-		if (kprobe_enabled)
+		if (kprobe_enabled) {
+			kernel_text_lock();
 			arch_disarm_kprobe(p);
+			kernel_text_unlock();
+		}
 		hlist_del_rcu(&old_p->hlist);
 		cleanup_p = 1;
 	} else {
@@ -644,9 +650,7 @@ valid_p:
 			list_del_rcu(&p->list);
 			kfree(old_p);
 		}
-		mutex_lock(&kprobe_mutex);
 		arch_remove_kprobe(p);
-		mutex_unlock(&kprobe_mutex);
 	} else {
 		mutex_lock(&kprobe_mutex);
 		if (p->break_handler)
@@ -717,7 +721,6 @@ static int __kprobes pre_handler_kretpro
 		ri->rp = rp;
 		ri->task = current;
 		arch_prepare_kretprobe(ri, regs);
-
 		/* XXX(hch): why is there no hlist_move_head? */
 		hlist_del(&ri->uflist);
 		hlist_add_head(&ri->uflist, &ri->rp->used_instances);
@@ -940,11 +943,13 @@ static void __kprobes enable_all_kprobes
 	if (kprobe_enabled)
 		goto already_enabled;
 
+	kernel_text_lock();
 	for (i = 0; i < KPROBE_TABLE_SIZE; i++) {
 		head = &kprobe_table[i];
 		hlist_for_each_entry_rcu(p, node, head, hlist)
 			arch_arm_kprobe(p);
 	}
+	kernel_text_unlock();
 
 	kprobe_enabled = true;
 	printk(KERN_INFO "Kprobes globally enabled\n");
@@ -969,6 +974,7 @@ static void __kprobes disable_all_kprobe
 
 	kprobe_enabled = false;
 	printk(KERN_INFO "Kprobes globally disabled\n");
+	kernel_text_lock();
 	for (i = 0; i < KPROBE_TABLE_SIZE; i++) {
 		head = &kprobe_table[i];
 		hlist_for_each_entry_rcu(p, node, head, hlist) {
@@ -976,6 +982,7 @@ static void __kprobes disable_all_kprobe
 				arch_disarm_kprobe(p);
 		}
 	}
+	kernel_text_unlock();
 
 	mutex_unlock(&kprobe_mutex);
 	/* Allow all currently running kprobes to complete */

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 11/26] Text Edit Lock - kprobes x86
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (9 preceding siblings ...)
  2008-01-24 20:27 ` [patch 10/26] Text Edit Lock - kprobes architecture independent support Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 12/26] Text Edit Lock - x86_32 standardize debug rodata Mathieu Desnoyers
                   ` (14 subsequent siblings)
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel
  Cc: Mathieu Desnoyers, Andi Kleen, ananth, anil.s.keshavamurthy,
	davem, Thomas Gleixner, Ingo Molnar, H. Peter Anvin

[-- Attachment #1: text-edit-lock-kprobes-x86.patch --]
[-- Type: text/plain, Size: 1432 bytes --]

Make kprobes use INIT_ARRAY().

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Tested-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
CC: Andi Kleen <andi@firstfloor.org>
CC: ananth@in.ibm.com
CC: anil.s.keshavamurthy@intel.com
CC: davem@davemloft.net
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Ingo Molnar <mingo@redhat.com>
CC: H. Peter Anvin <hpa@zytor.com>
---
 arch/x86/kernel/kprobes.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Index: linux-2.6-lttng.mm/arch/x86/kernel/kprobes.c
===================================================================
--- linux-2.6-lttng.mm.orig/arch/x86/kernel/kprobes.c	2008-01-24 14:27:04.000000000 -0500
+++ linux-2.6-lttng.mm/arch/x86/kernel/kprobes.c	2008-01-24 14:27:47.000000000 -0500
@@ -366,12 +366,13 @@ int __kprobes arch_prepare_kprobe(struct
 
 void __kprobes arch_arm_kprobe(struct kprobe *p)
 {
-	text_poke(p->addr, ((unsigned char []){BREAKPOINT_INSTRUCTION}), 1);
+	text_poke(p->addr, INIT_ARRAY(unsigned char, BREAKPOINT_INSTRUCTION, 1),
+		1);
 }
 
 void __kprobes arch_disarm_kprobe(struct kprobe *p)
 {
-	text_poke(p->addr, &p->opcode, 1);
+	text_poke(p->addr, INIT_ARRAY(unsigned char, p->opcode, 1), 1);
 }
 
 void __kprobes arch_remove_kprobe(struct kprobe *p)

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 12/26] Text Edit Lock - x86_32 standardize debug rodata
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (10 preceding siblings ...)
  2008-01-24 20:27 ` [patch 11/26] Text Edit Lock - kprobes x86 Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 13/26] Text Edit Lock - x86_64 " Mathieu Desnoyers
                   ` (13 subsequent siblings)
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel
  Cc: Mathieu Desnoyers, Andi Kleen, pageexec, Thomas Gleixner,
	Ingo Molnar, H. Peter Anvin

[-- Attachment #1: text-edit-lock-i386-standardize-debug-rodata.patch --]
[-- Type: text/plain, Size: 2071 bytes --]

Standardize DEBUG_RODATA, removing special cases for hotplug and kprobes.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
CC: Andi Kleen <andi@firstfloor.org>
CC: pageexec@freemail.hu
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Ingo Molnar <mingo@redhat.com>
CC: H. Peter Anvin <hpa@zytor.com>
---
 arch/x86/mm/init_32.c |   20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

Index: linux-2.6-lttng.mm/arch/x86/mm/init_32.c
===================================================================
--- linux-2.6-lttng.mm.orig/arch/x86/mm/init_32.c	2008-01-24 14:10:42.000000000 -0500
+++ linux-2.6-lttng.mm/arch/x86/mm/init_32.c	2008-01-24 14:28:36.000000000 -0500
@@ -807,28 +807,21 @@ static int noinline do_test_wp_bit(void)
 }
 
 #ifdef CONFIG_DEBUG_RODATA
-
 void mark_rodata_ro(void)
 {
 	unsigned long start = PFN_ALIGN(_text);
 	unsigned long size = PFN_ALIGN(_etext) - start;
 
-#ifndef CONFIG_KPROBES
-#ifdef CONFIG_HOTPLUG_CPU
-	/* It must still be possible to apply SMP alternatives. */
-	if (num_possible_cpus() <= 1)
-#endif
-	{
-		change_page_attr(virt_to_page(start),
-		                 size >> PAGE_SHIFT, PAGE_KERNEL_RX);
-		printk("Write protecting the kernel text: %luk\n", size >> 10);
-	}
-#endif
+	change_page_attr(virt_to_page(start),
+		size >> PAGE_SHIFT, PAGE_KERNEL_RX);
+	printk(KERN_INFO "Write protecting the kernel text: %luk\n",
+		size >> 10);
+
 	start += size;
 	size = (unsigned long)__end_rodata - start;
 	change_page_attr(virt_to_page(start),
 	                 size >> PAGE_SHIFT, PAGE_KERNEL_RO);
-	printk("Write protecting the kernel read-only data: %luk\n",
+	printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n",
 	       size >> 10);
 
 	/*
@@ -839,6 +832,7 @@ void mark_rodata_ro(void)
 	 */
 	global_flush_tlb();
 }
+
 #endif
 
 void free_init_pages(char *what, unsigned long begin, unsigned long end)

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 13/26] Text Edit Lock - x86_64 standardize debug rodata
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (11 preceding siblings ...)
  2008-01-24 20:27 ` [patch 12/26] Text Edit Lock - x86_32 standardize debug rodata Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 14/26] Immediate Values - Architecture Independent Code Mathieu Desnoyers
                   ` (12 subsequent siblings)
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel
  Cc: Mathieu Desnoyers, Andi Kleen, pageexec, Thomas Gleixner,
	Ingo Molnar, H. Peter Anvin

[-- Attachment #1: text-edit-lock-x86_64-standardize-debug-rodata.patch --]
[-- Type: text/plain, Size: 1852 bytes --]

Standardize DEBUG_RODATA, removing special cases for hotplug and kprobes.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
CC: Andi Kleen <andi@firstfloor.org>
CC: pageexec@freemail.hu
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Ingo Molnar <mingo@redhat.com>
CC: H. Peter Anvin <hpa@zytor.com>
---
 arch/x86/mm/init_64.c |   23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)

Index: linux-2.6-lttng.mm/arch/x86/mm/init_64.c
===================================================================
--- linux-2.6-lttng.mm.orig/arch/x86/mm/init_64.c	2008-01-24 14:10:42.000000000 -0500
+++ linux-2.6-lttng.mm/arch/x86/mm/init_64.c	2008-01-24 14:28:40.000000000 -0500
@@ -714,25 +714,11 @@ void free_initmem(void)
 
 void mark_rodata_ro(void)
 {
-	unsigned long start = (unsigned long)_stext, end;
+	unsigned long start = PFN_ALIGN(_stext);
+	unsigned long end = PFN_ALIGN(__end_rodata);
 
-#ifdef CONFIG_HOTPLUG_CPU
-	/* It must still be possible to apply SMP alternatives. */
-	if (num_possible_cpus() > 1)
-		start = (unsigned long)_etext;
-#endif
-
-#ifdef CONFIG_KPROBES
-	start = (unsigned long)__start_rodata;
-#endif
-	
-	end = (unsigned long)__end_rodata;
-	start = (start + PAGE_SIZE - 1) & PAGE_MASK;
-	end &= PAGE_MASK;
-	if (end <= start)
-		return;
-
-	change_page_attr_addr(start, (end - start) >> PAGE_SHIFT, PAGE_KERNEL_RO);
+	change_page_attr_addr(start, (end - start) >> PAGE_SHIFT,
+				PAGE_KERNEL_RO);
 
 	printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n",
 	       (end - start) >> 10);
@@ -745,6 +731,7 @@ void mark_rodata_ro(void)
 	 */
 	global_flush_tlb();
 }
+
 #endif
 
 #ifdef CONFIG_BLK_DEV_INITRD

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 14/26] Immediate Values - Architecture Independent Code
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (12 preceding siblings ...)
  2008-01-24 20:27 ` [patch 13/26] Text Edit Lock - x86_64 " Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 15/26] Immediate Values - Kconfig menu in EMBEDDED Mathieu Desnoyers
                   ` (11 subsequent siblings)
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel; +Cc: Mathieu Desnoyers, Rusty Russell

[-- Attachment #1: immediate-values-architecture-independent-code.patch --]
[-- Type: text/plain, Size: 18663 bytes --]

Immediate values are used as read mostly variables that are rarely updated. They
use code patching to modify the values inscribed in the instruction stream. It
provides a way to save precious cache lines that would otherwise have to be used
by these variables.

There is a generic _imv_read() version, which uses standard global
variables, and optimized per architecture imv_read() implementations,
which use a load immediate to remove a data cache hit. When the immediate values
functionnality is disabled in the kernel, it falls back to global variables.

It adds a new rodata section "__imv" to place the pointers to the enable
value. Immediate values activation functions sits in kernel/immediate.c.

Immediate values refer to the memory address of a previously declared integer.
This integer holds the information about the state of the immediate values
associated, and must be accessed through the API found in linux/immediate.h.

At module load time, each immediate value is checked to see if it must be
enabled. It would be the case if the variable they refer to is exported from
another module and already enabled.

In the early stages of start_kernel(), the immediate values are updated to
reflect the state of the variable they refer to.

* Why should this be merged *

It improves performances on heavy memory I/O workloads.

An interesting result shows the potential this infrastructure has by
showing the slowdown a simple system call such as getppid() suffers when it is
used under heavy user-space cache trashing:

Random walk L1 and L2 trashing surrounding a getppid() call:
(note: in this test, do_syscal_trace was taken at each system call, see
Documentation/immediate.txt in these patches for details)
- No memory pressure :   getppid() takes  1573 cycles
- With memory pressure : getppid() takes 15589 cycles

We therefore have a slowdown of 10 times just to get the kernel variables from
memory. Another test on the same architecture (Intel P4) measured the memory
latency to be 559 cycles. Therefore, each cache line removed from the hot path
would improve the syscall time of 3.5% in these conditions.

Changelog:

- section __imv is already SHF_ALLOC
- Because of the wonders of ELF, section 0 has sh_addr and sh_size 0.  So
  the if (immediateindex) is unnecessary here.
- Remove module_mutex usage: depend on functions implemented in module.c for
  that.
- Does not update tainted module's immediate values.
- remove imv_*_t types, add DECLARE_IMV() and DEFINE_IMV().
  - imv_read(&var) becomes imv_read(var) because of this.
- Adding a new EXPORT_IMV_SYMBOL(_GPL).
- remove imv_if(). Should use if (unlikely(imv_read(var))) instead.
  - Wait until we have gcc support before we add the imv_if macro, since
    its form may have to change.
- Dont't declare the __imv section in vmlinux.lds.h, just put the content
  in the rodata section.
- Simplify interface : remove imv_set_early, keep track of kernel boot
  status internally.
- Remove the ALIGN(8) before the __imv section. It is packed now.
- Uses an IPI busy-loop on each CPU with interrupts disabled as a simple,
  architecture agnostic, update mechanism.
- Use imv_* instead of immediate_*.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
CC: Rusty Russell <rusty@rustcorp.com.au>
---
 include/asm-generic/vmlinux.lds.h |    3 
 include/linux/immediate.h         |   94 +++++++++++++++++++
 include/linux/module.h            |   16 +++
 init/main.c                       |    8 +
 kernel/Makefile                   |    1 
 kernel/immediate.c                |  187 ++++++++++++++++++++++++++++++++++++++
 kernel/module.c                   |   50 +++++++++-
 7 files changed, 358 insertions(+), 1 deletion(-)

Index: linux-2.6-lttng.mm/include/linux/immediate.h
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6-lttng.mm/include/linux/immediate.h	2008-01-24 14:28:47.000000000 -0500
@@ -0,0 +1,94 @@
+#ifndef _LINUX_IMMEDIATE_H
+#define _LINUX_IMMEDIATE_H
+
+/*
+ * Immediate values, can be updated at runtime and save cache lines.
+ *
+ * (C) Copyright 2007 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
+#ifdef CONFIG_IMMEDIATE
+
+struct __imv {
+	unsigned long var;	/* Pointer to the identifier variable of the
+				 * immediate value
+				 */
+	unsigned long imv;	/*
+				 * Pointer to the memory location of the
+				 * immediate value within the instruction.
+				 */
+	unsigned char size;	/* Type size. */
+} __attribute__ ((packed));
+
+#include <asm/immediate.h>
+
+/**
+ * imv_set - set immediate variable (with locking)
+ * @name: immediate value name
+ * @i: required value
+ *
+ * Sets the value of @name, taking the module_mutex if required by
+ * the architecture.
+ */
+#define imv_set(name, i)						\
+	do {								\
+		name##__imv = (i);					\
+		core_imv_update();					\
+		module_imv_update();					\
+	} while (0)
+
+/*
+ * Internal update functions.
+ */
+extern void core_imv_update(void);
+extern void imv_update_range(const struct __imv *begin,
+	const struct __imv *end);
+
+#else
+
+/*
+ * Generic immediate values: a simple, standard, memory load.
+ */
+
+/**
+ * imv_read - read immediate variable
+ * @name: immediate value name
+ *
+ * Reads the value of @name.
+ */
+#define imv_read(name)			_imv_read(name)
+
+/**
+ * imv_set - set immediate variable (with locking)
+ * @name: immediate value name
+ * @i: required value
+ *
+ * Sets the value of @name, taking the module_mutex if required by
+ * the architecture.
+ */
+#define imv_set(name, i)		(name##__imv = (i))
+
+static inline void core_imv_update(void) { }
+static inline void module_imv_update(void) { }
+
+#endif
+
+#define DECLARE_IMV(type, name) extern __typeof__(type) name##__imv
+#define DEFINE_IMV(type, name)  __typeof__(type) name##__imv
+
+#define EXPORT_IMV_SYMBOL(name) EXPORT_SYMBOL(name##__imv)
+#define EXPORT_IMV_SYMBOL_GPL(name) EXPORT_SYMBOL_GPL(name##__imv)
+
+/**
+ * _imv_read - Read immediate value with standard memory load.
+ * @name: immediate value name
+ *
+ * Force a data read of the immediate value instead of the immediate value
+ * based mechanism. Useful for __init and __exit section data read.
+ */
+#define _imv_read(name)		(name##__imv)
+
+#endif
Index: linux-2.6-lttng.mm/include/linux/module.h
===================================================================
--- linux-2.6-lttng.mm.orig/include/linux/module.h	2008-01-24 14:10:54.000000000 -0500
+++ linux-2.6-lttng.mm/include/linux/module.h	2008-01-24 14:28:47.000000000 -0500
@@ -15,6 +15,7 @@
 #include <linux/stringify.h>
 #include <linux/kobject.h>
 #include <linux/moduleparam.h>
+#include <linux/immediate.h>
 #include <linux/marker.h>
 #include <asm/local.h>
 
@@ -355,6 +356,10 @@ struct module
 	/* The command line arguments (may be mangled).  People like
 	   keeping pointers to this stuff */
 	char *args;
+#ifdef CONFIG_IMMEDIATE
+	const struct __imv *immediate;
+	unsigned int num_immediate;
+#endif
 #ifdef CONFIG_MARKERS
 	struct marker *markers;
 	unsigned int num_markers;
@@ -467,6 +472,9 @@ extern void print_modules(void);
 
 extern void module_update_markers(void);
 
+extern void _module_imv_update(void);
+extern void module_imv_update(void);
+
 #else /* !CONFIG_MODULES... */
 #define EXPORT_SYMBOL(sym)
 #define EXPORT_SYMBOL_GPL(sym)
@@ -572,6 +580,14 @@ static inline void module_update_markers
 {
 }
 
+static inline void _module_imv_update(void)
+{
+}
+
+static inline void module_imv_update(void)
+{
+}
+
 #endif /* CONFIG_MODULES */
 
 struct device_driver;
Index: linux-2.6-lttng.mm/kernel/module.c
===================================================================
--- linux-2.6-lttng.mm.orig/kernel/module.c	2008-01-24 14:17:33.000000000 -0500
+++ linux-2.6-lttng.mm/kernel/module.c	2008-01-24 14:28:47.000000000 -0500
@@ -33,6 +33,7 @@
 #include <linux/cpu.h>
 #include <linux/moduleparam.h>
 #include <linux/errno.h>
+#include <linux/immediate.h>
 #include <linux/err.h>
 #include <linux/vermagic.h>
 #include <linux/notifier.h>
@@ -1672,6 +1673,7 @@ static struct module *load_module(void _
 	unsigned int unusedcrcindex;
 	unsigned int unusedgplindex;
 	unsigned int unusedgplcrcindex;
+	unsigned int immediateindex;
 	unsigned int markersindex;
 	unsigned int markersstringsindex;
 	struct module *mod;
@@ -1770,6 +1772,7 @@ static struct module *load_module(void _
 #ifdef ARCH_UNWIND_SECTION_NAME
 	unwindex = find_sec(hdr, sechdrs, secstrings, ARCH_UNWIND_SECTION_NAME);
 #endif
+	immediateindex = find_sec(hdr, sechdrs, secstrings, "__imv");
 
 	/* Don't keep modinfo section */
 	sechdrs[infoindex].sh_flags &= ~(unsigned long)SHF_ALLOC;
@@ -1921,6 +1924,11 @@ static struct module *load_module(void _
 	mod->gpl_future_syms = (void *)sechdrs[gplfutureindex].sh_addr;
 	if (gplfuturecrcindex)
 		mod->gpl_future_crcs = (void *)sechdrs[gplfuturecrcindex].sh_addr;
+#ifdef CONFIG_IMMEDIATE
+	mod->immediate = (void *)sechdrs[immediateindex].sh_addr;
+	mod->num_immediate =
+		sechdrs[immediateindex].sh_size / sizeof(*mod->immediate);
+#endif
 
 	mod->unused_syms = (void *)sechdrs[unusedindex].sh_addr;
 	if (unusedcrcindex)
@@ -1988,11 +1996,16 @@ static struct module *load_module(void _
 
 	add_kallsyms(mod, sechdrs, symindex, strindex, secstrings);
 
+	if (!(mod->taints & TAINT_FORCED_MODULE)) {
 #ifdef CONFIG_MARKERS
-	if (!(mod->taints & TAINT_FORCED_MODULE))
 		marker_update_probe_range(mod->markers,
 			mod->markers + mod->num_markers);
 #endif
+#ifdef CONFIG_IMMEDIATE
+		imv_update_range(mod->immediate,
+			mod->immediate + mod->num_immediate);
+#endif
+	}
 	err = module_finalize(hdr, sechdrs, mod);
 	if (err < 0)
 		goto cleanup;
@@ -2536,3 +2549,38 @@ void module_update_markers(void)
 	mutex_unlock(&module_mutex);
 }
 #endif
+
+#ifdef CONFIG_IMMEDIATE
+/**
+ * _module_imv_update - update all immediate values in the kernel
+ *
+ * Iterate on the kernel core and modules to update the immediate values.
+ * Module_mutex must be held be the caller.
+ */
+void _module_imv_update(void)
+{
+	struct module *mod;
+
+	list_for_each_entry(mod, &modules, list) {
+		if (mod->taints)
+			continue;
+		imv_update_range(mod->immediate,
+			mod->immediate + mod->num_immediate);
+	}
+}
+EXPORT_SYMBOL_GPL(_module_imv_update);
+
+/**
+ * module_imv_update - update all immediate values in the kernel
+ *
+ * Iterate on the kernel core and modules to update the immediate values.
+ * Takes module_mutex.
+ */
+void module_imv_update(void)
+{
+	mutex_lock(&module_mutex);
+	_module_imv_update();
+	mutex_unlock(&module_mutex);
+}
+EXPORT_SYMBOL_GPL(module_imv_update);
+#endif
Index: linux-2.6-lttng.mm/kernel/immediate.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6-lttng.mm/kernel/immediate.c	2008-01-24 14:28:47.000000000 -0500
@@ -0,0 +1,187 @@
+/*
+ * Copyright (C) 2007 Mathieu Desnoyers
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/immediate.h>
+#include <linux/memory.h>
+#include <linux/cpu.h>
+
+#include <asm/cacheflush.h>
+
+/*
+ * Kernel ready to execute the SMP update that may depend on trap and ipi.
+ */
+static int imv_early_boot_complete;
+
+extern const struct __imv __start___imv[];
+extern const struct __imv __stop___imv[];
+
+/*
+ * imv_mutex nests inside module_mutex. imv_mutex protects builtin
+ * immediates and module immediates.
+ */
+static DEFINE_MUTEX(imv_mutex);
+
+static atomic_t wait_sync;
+
+struct ipi_loop_data {
+	long value;
+	const struct __imv *imv;
+} loop_data;
+
+static void ipi_busy_loop(void *arg)
+{
+	unsigned long flags;
+
+	local_irq_save(flags);
+	atomic_dec(&wait_sync);
+	do {
+		/* Make sure the wait_sync gets re-read */
+		smp_mb();
+	} while (atomic_read(&wait_sync) > loop_data.value);
+	atomic_dec(&wait_sync);
+	do {
+		/* Make sure the wait_sync gets re-read */
+		smp_mb();
+	} while (atomic_read(&wait_sync) > 0);
+	/*
+	 * Issuing a synchronizing instruction must be done on each CPU before
+	 * reenabling interrupts after modifying an instruction. Required by
+	 * Intel's errata.
+	 */
+	sync_core();
+	flush_icache_range(loop_data.imv->imv,
+		loop_data.imv->imv + loop_data.imv->size);
+	local_irq_restore(flags);
+}
+
+/**
+ * apply_imv_update - update one immediate value
+ * @imv: pointer of type const struct __imv to update
+ *
+ * Update one immediate value. Must be called with imv_mutex held.
+ * It makes sure all CPUs are not executing the modified code by having them
+ * busy looping with interrupts disabled.
+ * It does _not_ protect against NMI and MCE (could be a problem with Intel's
+ * errata if we use immediate values in their code path).
+ */
+static int apply_imv_update(const struct __imv *imv)
+{
+	unsigned long flags;
+	long online_cpus;
+
+	/*
+	 * If the variable and the instruction have the same value, there is
+	 * nothing to do.
+	 */
+	switch (imv->size) {
+	case 1:	if (*(uint8_t *)imv->imv
+				== *(uint8_t *)imv->var)
+			return 0;
+		break;
+	case 2:	if (*(uint16_t *)imv->imv
+				== *(uint16_t *)imv->var)
+			return 0;
+		break;
+	case 4:	if (*(uint32_t *)imv->imv
+				== *(uint32_t *)imv->var)
+			return 0;
+		break;
+	case 8:	if (*(uint64_t *)imv->imv
+				== *(uint64_t *)imv->var)
+			return 0;
+		break;
+	default:return -EINVAL;
+	}
+
+	if (imv_early_boot_complete) {
+		kernel_text_lock();
+		lock_cpu_hotplug();
+		online_cpus = num_online_cpus();
+		atomic_set(&wait_sync, 2 * online_cpus);
+		loop_data.value = online_cpus;
+		loop_data.imv = imv;
+		smp_call_function(ipi_busy_loop, NULL, 1, 0);
+		local_irq_save(flags);
+		atomic_dec(&wait_sync);
+		do {
+			/* Make sure the wait_sync gets re-read */
+			smp_mb();
+		} while (atomic_read(&wait_sync) > online_cpus);
+		text_poke((void *)imv->imv, (void *)imv->var,
+				imv->size);
+		/*
+		 * Make sure the modified instruction is seen by all CPUs before
+		 * we continue (visible to other CPUs and local interrupts).
+		 */
+		wmb();
+		atomic_dec(&wait_sync);
+		flush_icache_range(imv->imv,
+				imv->imv + imv->size);
+		local_irq_restore(flags);
+		unlock_cpu_hotplug();
+		kernel_text_unlock();
+	} else
+		text_poke_early((void *)imv->imv, (void *)imv->var,
+				imv->size);
+	return 0;
+}
+
+/**
+ * imv_update_range - Update immediate values in a range
+ * @begin: pointer to the beginning of the range
+ * @end: pointer to the end of the range
+ *
+ * Updates a range of immediates.
+ */
+void imv_update_range(const struct __imv *begin,
+		const struct __imv *end)
+{
+	const struct __imv *iter;
+	int ret;
+	for (iter = begin; iter < end; iter++) {
+		mutex_lock(&imv_mutex);
+		ret = apply_imv_update(iter);
+		if (imv_early_boot_complete && ret)
+			printk(KERN_WARNING
+				"Invalid immediate value. "
+				"Variable at %p, "
+				"instruction at %p, size %hu\n",
+				(void *)iter->imv,
+				(void *)iter->var, iter->size);
+		mutex_unlock(&imv_mutex);
+	}
+}
+EXPORT_SYMBOL_GPL(imv_update_range);
+
+/**
+ * imv_update - update all immediate values in the kernel
+ *
+ * Iterate on the kernel core and modules to update the immediate values.
+ */
+void core_imv_update(void)
+{
+	/* Core kernel imvs */
+	imv_update_range(__start___imv, __stop___imv);
+}
+EXPORT_SYMBOL_GPL(core_imv_update);
+
+void __init imv_init_complete(void)
+{
+	imv_early_boot_complete = 1;
+}
Index: linux-2.6-lttng.mm/init/main.c
===================================================================
--- linux-2.6-lttng.mm.orig/init/main.c	2008-01-24 14:10:55.000000000 -0500
+++ linux-2.6-lttng.mm/init/main.c	2008-01-24 14:29:24.000000000 -0500
@@ -58,6 +58,7 @@
 #include <linux/kthread.h>
 #include <linux/sched.h>
 #include <linux/signal.h>
+#include <linux/immediate.h>
 
 #include <asm/io.h>
 #include <asm/bugs.h>
@@ -101,6 +102,11 @@ static inline void mark_rodata_ro(void) 
 #ifdef CONFIG_TC
 extern void tc_init(void);
 #endif
+#ifdef CONFIG_IMMEDIATE
+extern void imv_init_complete(void);
+#else
+static inline void imv_init_complete(void) { }
+#endif
 
 enum system_states system_state;
 EXPORT_SYMBOL(system_state);
@@ -518,6 +524,7 @@ asmlinkage void __init start_kernel(void
 	unwind_init();
 	lockdep_init();
 	cgroup_init_early();
+	core_imv_update();
 
 	local_irq_disable();
 	early_boot_irqs_off();
@@ -640,6 +647,7 @@ asmlinkage void __init start_kernel(void
 	cpuset_init();
 	taskstats_init_early();
 	delayacct_init();
+	imv_init_complete();
 
 	check_bugs();
 
Index: linux-2.6-lttng.mm/kernel/Makefile
===================================================================
--- linux-2.6-lttng.mm.orig/kernel/Makefile	2008-01-24 14:10:55.000000000 -0500
+++ linux-2.6-lttng.mm/kernel/Makefile	2008-01-24 14:28:47.000000000 -0500
@@ -69,6 +69,7 @@ obj-$(CONFIG_RELAY) += relay.o
 obj-$(CONFIG_SYSCTL) += utsname_sysctl.o
 obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o
 obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o
+obj-$(CONFIG_IMMEDIATE) += immediate.o
 obj-$(CONFIG_MARKERS) += marker.o
 
 ifneq ($(CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER),y)
Index: linux-2.6-lttng.mm/include/asm-generic/vmlinux.lds.h
===================================================================
--- linux-2.6-lttng.mm.orig/include/asm-generic/vmlinux.lds.h	2008-01-24 14:04:03.000000000 -0500
+++ linux-2.6-lttng.mm/include/asm-generic/vmlinux.lds.h	2008-01-24 14:28:47.000000000 -0500
@@ -25,6 +25,9 @@
 		*(.rodata) *(.rodata.*)					\
 		*(__vermagic)		/* Kernel version magic */	\
 		*(__markers_strings)	/* Markers: strings */		\
+		VMLINUX_SYMBOL(__start___imv) = .;			\
+		*(__imv)		/* Immediate values: pointers */ \
+		VMLINUX_SYMBOL(__stop___imv) = .;			\
 	}								\
 									\
 	.rodata1          : AT(ADDR(.rodata1) - LOAD_OFFSET) {		\

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 15/26] Immediate Values - Kconfig menu in EMBEDDED
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (13 preceding siblings ...)
  2008-01-24 20:27 ` [patch 14/26] Immediate Values - Architecture Independent Code Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 16/26] Immediate Values - x86 Optimization Mathieu Desnoyers
                   ` (10 subsequent siblings)
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel
  Cc: Mathieu Desnoyers, Rusty Russell, Adrian Bunk, Andi Kleen,
	Alexey Dobriyan, Christoph Hellwig

[-- Attachment #1: immediate-values-kconfig-embedded.patch --]
[-- Type: text/plain, Size: 2670 bytes --]

Immediate values provide a way to use dynamic code patching to update variables
sitting within the instruction stream. It saves caches lines normally used by
static read mostly variables. Enable it by default, but let users disable it
through the EMBEDDED menu with the "Disable immediate values" submenu entry.

Note: Since I think that I really should let embedded systems developers using
RO memory the option to disable the immediate values, I choose to leave this
menu option there, in the EMBEDDED menu. Also, the "CONFIG_IMMEDIATE" makes
sense because we want to compile out all the immediate code when we decide not
to use optimized immediate values at all (it removes otherwise unused code).

Changelog:
- Change ARCH_SUPPORTS_IMMEDIATE for ARCH_HAS_IMMEDIATE

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
CC: Rusty Russell <rusty@rustcorp.com.au>
CC: Adrian Bunk <bunk@stusta.de>
CC: Andi Kleen <andi@firstfloor.org>
CC: Alexey Dobriyan <adobriyan@gmail.com>
CC: Christoph Hellwig <hch@infradead.org>
---
 init/Kconfig |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Index: linux-2.6-lttng.mm/init/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/init/Kconfig	2008-01-24 14:18:34.000000000 -0500
+++ linux-2.6-lttng.mm/init/Kconfig	2008-01-24 14:29:28.000000000 -0500
@@ -472,6 +472,20 @@ config CC_OPTIMIZE_FOR_SIZE
 config SYSCTL
 	bool
 
+config IMMEDIATE
+	default y if !DISABLE_IMMEDIATE
+	depends on HAVE_IMMEDIATE
+	bool
+	help
+	  Immediate values are used as read-mostly variables that are rarely
+	  updated. They use code patching to modify the values inscribed in the
+	  instruction stream. It provides a way to save precious cache lines
+	  that would otherwise have to be used by these variables. They can be
+	  disabled through the EMBEDDED menu.
+
+config HAVE_IMMEDIATE
+	def_bool n
+
 menuconfig EMBEDDED
 	bool "Configure standard kernel features (for small systems)"
 	help
@@ -716,6 +730,16 @@ config MARKERS
 
 source "arch/Kconfig"
 
+config DISABLE_IMMEDIATE
+	default y if EMBEDDED
+	bool "Disable immediate values" if EMBEDDED
+	depends on HAVE_IMMEDIATE
+	help
+	  Disable code patching based immediate values for embedded systems. It
+	  consumes slightly more memory and requires to modify the instruction
+	  stream each time a variable is updated. Should really be disabled for
+	  embedded systems with read-only text.
+
 endmenu		# General setup
 
 config SLABINFO

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 16/26] Immediate Values - x86 Optimization
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (14 preceding siblings ...)
  2008-01-24 20:27 ` [patch 15/26] Immediate Values - Kconfig menu in EMBEDDED Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 17/26] Add text_poke and sync_core to powerpc Mathieu Desnoyers
                   ` (9 subsequent siblings)
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel
  Cc: Mathieu Desnoyers, Andi Kleen, H. Peter Anvin, Chuck Ebbert,
	Christoph Hellwig, Jeremy Fitzhardinge, Thomas Gleixner,
	Ingo Molnar, Rusty Russell

[-- Attachment #1: immediate-values-x86-optimization.patch --]
[-- Type: text/plain, Size: 5092 bytes --]

x86 optimization of the immediate values which uses a movl with code patching
to set/unset the value used to populate the register used as variable source.

Changelog:
- Use text_poke_early with cr0 WP save/restore to patch the bypass. We are doing
  non atomic writes to a code region only touched by us (nobody can execute it
  since we are protected by the imv_mutex).
- Put imv_set and _imv_set in the architecture independent header.
- Use $0 instead of %2 with (0) operand.
- Add x86_64 support, ready for i386+x86_64 -> x86 merge.
- Use asm-x86/asm.h.

Ok, so the most flexible solution that I see, that should fit for both
x86 and x86_64 would be :
1 byte  :       "=q" : "a", "b", "c", or "d" register for the i386.  For
                       x86-64 it is equivalent to "r" class (for 8-bit
                       instructions that do not use upper halves).
2, 4, 8 bytes : "=r" : A register operand is allowed provided that it is in a
                       general register.

- "Redux" immediate values : no need to put a breakpoint, therefore, no
  need to know where the instruction starts. It's therefore OK to have a
  REX prefix.

- Bugfix : 8 bytes 64 bits immediate value was declared as "4 bytes" in the
  immediate structure.
- Change the immediate.c update code to support variable length opcodes.
- Vastly simplified, using a busy looping IPI with interrupts disabled.
  Does not protect against NMI nor MCE.
- Pack the __imv section. Use smallest types required for size (char).
- Use imv_* instead of immediate_*.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
CC: Andi Kleen <ak@muc.de>
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: Chuck Ebbert <cebbert@redhat.com>
CC: Christoph Hellwig <hch@infradead.org>
CC: Jeremy Fitzhardinge <jeremy@goop.org>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Ingo Molnar <mingo@redhat.com>
CC: Rusty Russell <rusty@rustcorp.com.au>
---
 arch/x86/Kconfig            |    1 
 include/asm-x86/immediate.h |   77 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+)

Index: linux-2.6-lttng.mm/include/asm-x86/immediate.h
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6-lttng.mm/include/asm-x86/immediate.h	2008-01-24 14:30:09.000000000 -0500
@@ -0,0 +1,77 @@
+#ifndef _ASM_X86_IMMEDIATE_H
+#define _ASM_X86_IMMEDIATE_H
+
+/*
+ * Immediate values. x86 architecture optimizations.
+ *
+ * (C) Copyright 2006 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
+#include <asm/asm.h>
+
+/**
+ * imv_read - read immediate variable
+ * @name: immediate value name
+ *
+ * Reads the value of @name.
+ * Optimized version of the immediate.
+ * Do not use in __init and __exit functions. Use _imv_read() instead.
+ * If size is bigger than the architecture long size, fall back on a memory
+ * read.
+ *
+ * Make sure to populate the initial static 64 bits opcode with a value
+ * what will generate an instruction with 8 bytes immediate value (not the REX.W
+ * prefixed one that loads a sign extended 32 bits immediate value in a r64
+ * register).
+ */
+#define imv_read(name)							\
+	({								\
+		__typeof__(name##__imv) value;				\
+		BUILD_BUG_ON(sizeof(value) > 8);			\
+		switch (sizeof(value)) {				\
+		case 1:							\
+			asm(".section __imv,\"a\",@progbits\n\t"	\
+				_ASM_PTR "%c1, (3f)-%c2\n\t"		\
+				".byte %c2\n\t"				\
+				".previous\n\t"				\
+				"mov $0,%0\n\t"				\
+				"3:\n\t"				\
+				: "=q" (value)				\
+				: "i" (&name##__imv),			\
+				  "i" (sizeof(value)));			\
+			break;						\
+		case 2:							\
+		case 4:							\
+			asm(".section __imv,\"a\",@progbits\n\t"	\
+				_ASM_PTR "%c1, (3f)-%c2\n\t"		\
+				".byte %c2\n\t"				\
+				".previous\n\t"				\
+				"mov $0,%0\n\t"				\
+				"3:\n\t"				\
+				: "=r" (value)				\
+				: "i" (&name##__imv),			\
+				  "i" (sizeof(value)));			\
+			break;						\
+		case 8:							\
+			if (sizeof(long) < 8) {				\
+				value = name##__imv;			\
+				break;					\
+			}						\
+			asm(".section __imv,\"a\",@progbits\n\t"	\
+				_ASM_PTR "%c1, (3f)-%c2\n\t"		\
+				".byte %c2\n\t"				\
+				".previous\n\t"				\
+				"mov $0xFEFEFEFE01010101,%0\n\t" 	\
+				"3:\n\t"				\
+				: "=r" (value)				\
+				: "i" (&name##__imv),			\
+				  "i" (sizeof(value)));			\
+			break;						\
+		};							\
+		value;							\
+	})
+
+#endif /* _ASM_X86_IMMEDIATE_H */
Index: linux-2.6-lttng.mm/arch/x86/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/x86/Kconfig	2008-01-24 14:18:34.000000000 -0500
+++ linux-2.6-lttng.mm/arch/x86/Kconfig	2008-01-24 14:30:09.000000000 -0500
@@ -20,6 +20,7 @@ config X86
 	def_bool y
 	select HAVE_OPROFILE
 	select HAVE_KPROBES
+	select HAVE_IMMEDIATE
 
 config GENERIC_LOCKBREAK
 	def_bool n

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 17/26] Add text_poke and sync_core to powerpc
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (15 preceding siblings ...)
  2008-01-24 20:27 ` [patch 16/26] Immediate Values - x86 Optimization Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 18/26] Immediate Values - Powerpc Optimization Mathieu Desnoyers
                   ` (8 subsequent siblings)
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel
  Cc: Mathieu Desnoyers, Rusty Russell, Christoph Hellwig,
	Paul Mackerras

[-- Attachment #1: add-text-poke-to-powerpc.patch --]
[-- Type: text/plain, Size: 1355 bytes --]

- Needed on architectures where we must surround live instruction modification
  with "WP flag disable".
- Turns into a memcpy on powerpc since there is no WP flag activated for
  instruction pages (yet..).
- Add empty sync_core to powerpc so it can be used in architecture independent
  code.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
CC: Rusty Russell <rusty@rustcorp.com.au>
CC: Christoph Hellwig <hch@infradead.org>
CC: Paul Mackerras <paulus@samba.org>
---
 include/asm-powerpc/cacheflush.h |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Index: linux-2.6-lttng/include/asm-powerpc/cacheflush.h
===================================================================
--- linux-2.6-lttng.orig/include/asm-powerpc/cacheflush.h	2007-11-19 12:05:50.000000000 -0500
+++ linux-2.6-lttng/include/asm-powerpc/cacheflush.h	2007-11-19 13:27:36.000000000 -0500
@@ -63,7 +63,9 @@ extern void flush_dcache_phys_range(unsi
 #define copy_from_user_page(vma, page, vaddr, dst, src, len) \
 	memcpy(dst, src, len)
 
-
+#define text_poke	memcpy
+#define text_poke_early	text_poke
+#define sync_core()
 
 #ifdef CONFIG_DEBUG_PAGEALLOC
 /* internal debugging function */

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 18/26] Immediate Values - Powerpc Optimization
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (16 preceding siblings ...)
  2008-01-24 20:27 ` [patch 17/26] Add text_poke and sync_core to powerpc Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 19/26] Immediate Values - Documentation Mathieu Desnoyers
                   ` (7 subsequent siblings)
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel
  Cc: Mathieu Desnoyers, Rusty Russell, Christoph Hellwig,
	Paul Mackerras

[-- Attachment #1: immediate-values-powerpc-optimization.patch --]
[-- Type: text/plain, Size: 3018 bytes --]

PowerPC optimization of the immediate values which uses a li instruction,
patched with an immediate value.

Changelog:
- Put imv_set and _imv_set in the architecture independent header.
- Pack the __imv section. Use smallest types required for size (char).
- Remove architecture specific update code : now handled by architecture
  agnostic code.
- Use imv_* instead of immediate_*.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
CC: Rusty Russell <rusty@rustcorp.com.au>
CC: Christoph Hellwig <hch@infradead.org>
CC: Paul Mackerras <paulus@samba.org>
---
 arch/powerpc/Kconfig            |    1 
 include/asm-powerpc/immediate.h |   55 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+)

Index: linux-2.6-lttng.mm/include/asm-powerpc/immediate.h
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6-lttng.mm/include/asm-powerpc/immediate.h	2008-01-24 14:30:45.000000000 -0500
@@ -0,0 +1,55 @@
+#ifndef _ASM_POWERPC_IMMEDIATE_H
+#define _ASM_POWERPC_IMMEDIATE_H
+
+/*
+ * Immediate values. PowerPC architecture optimizations.
+ *
+ * (C) Copyright 2006 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
+#include <asm/asm-compat.h>
+
+/**
+ * imv_read - read immediate variable
+ * @name: immediate value name
+ *
+ * Reads the value of @name.
+ * Optimized version of the immediate.
+ * Do not use in __init and __exit functions. Use _imv_read() instead.
+ */
+#define imv_read(name)							\
+	({								\
+		__typeof__(name##__imv) value;				\
+		BUILD_BUG_ON(sizeof(value) > 8);			\
+		switch (sizeof(value)) {				\
+		case 1:							\
+			asm(".section __imv,\"a\",@progbits\n\t"	\
+					PPC_LONG "%c1, ((1f)-1)\n\t"	\
+					".byte 1\n\t"			\
+					".previous\n\t"			\
+					"li %0,0\n\t"			\
+					"1:\n\t"			\
+				: "=r" (value)				\
+				: "i" (&name##__imv));			\
+			break;						\
+		case 2:							\
+			asm(".section __imv,\"a\",@progbits\n\t"	\
+					PPC_LONG "%c1, ((1f)-2)\n\t"	\
+					".byte 2\n\t"			\
+					".previous\n\t"			\
+					"li %0,0\n\t"			\
+					"1:\n\t"			\
+				: "=r" (value)				\
+				: "i" (&name##__imv));			\
+			break;						\
+		case 4:							\
+		case 8:	value = name##__imv;				\
+			break;						\
+		};							\
+		value;							\
+	})
+
+#endif /* _ASM_POWERPC_IMMEDIATE_H */
Index: linux-2.6-lttng.mm/arch/powerpc/Kconfig
===================================================================
--- linux-2.6-lttng.mm.orig/arch/powerpc/Kconfig	2008-01-24 14:18:34.000000000 -0500
+++ linux-2.6-lttng.mm/arch/powerpc/Kconfig	2008-01-24 14:30:45.000000000 -0500
@@ -89,6 +89,7 @@ config PPC
 	default y
 	select HAVE_OPROFILE
 	select HAVE_KPROBES
+	select HAVE_IMMEDIATE
 
 config EARLY_PRINTK
 	bool

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 19/26] Immediate Values - Documentation
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (17 preceding siblings ...)
  2008-01-24 20:27 ` [patch 18/26] Immediate Values - Powerpc Optimization Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 20/26] Scheduler Profiling - Use Immediate Values Mathieu Desnoyers
                   ` (6 subsequent siblings)
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel; +Cc: Mathieu Desnoyers, Rusty Russell

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: immediate-values-documentation.patch --]
[-- Type: text/plain, Size: 8867 bytes --]

Changelog:
- Remove imv_set_early (removed from API).
- Use imv_* instead of immediate_*.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
CC: Rusty Russell <rusty@rustcorp.com.au>
---
 Documentation/immediate.txt |  221 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 221 insertions(+)

Index: linux-2.6-lttng/Documentation/immediate.txt
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6-lttng/Documentation/immediate.txt	2007-11-03 20:28:58.000000000 -0400
@@ -0,0 +1,221 @@
+		        Using the Immediate Values
+
+			    Mathieu Desnoyers
+
+
+This document introduces Immediate Values and their use.
+
+
+* Purpose of immediate values
+
+An immediate value is used to compile into the kernel variables that sit within
+the instruction stream. They are meant to be rarely updated but read often.
+Using immediate values for these variables will save cache lines.
+
+This infrastructure is specialized in supporting dynamic patching of the values
+in the instruction stream when multiple CPUs are running without disturbing the
+normal system behavior.
+
+Compiling code meant to be rarely enabled at runtime can be done using
+if (unlikely(imv_read(var))) as condition surrounding the code. The
+smallest data type required for the test (an 8 bits char) is preferred, since
+some architectures, such as powerpc, only allow up to 16 bits immediate values.
+
+
+* Usage
+
+In order to use the "immediate" macros, you should include linux/immediate.h.
+
+#include <linux/immediate.h>
+
+DEFINE_IMV(char, this_immediate);
+EXPORT_IMV_SYMBOL(this_immediate);
+
+
+And use, in the body of a function:
+
+Use imv_set(this_immediate) to set the immediate value.
+
+Use imv_read(this_immediate) to read the immediate value.
+
+The immediate mechanism supports inserting multiple instances of the same
+immediate. Immediate values can be put in inline functions, inlined static
+functions, and unrolled loops.
+
+If you have to read the immediate values from a function declared as __init or
+__exit, you should explicitly use _imv_read(), which will fall back on a
+global variable read. Failing to do so will leave a reference to the __init
+section after it is freed (it would generate a modpost warning).
+
+You can choose to set an initial static value to the immediate by using, for
+instance:
+
+DEFINE_IMV(long, myptr) = 10;
+
+
+* Optimization for a given architecture
+
+One can implement optimized immediate values for a given architecture by
+replacing asm-$ARCH/immediate.h.
+
+
+* Performance improvement
+
+
+  * Memory hit for a data-based branch
+
+Here are the results on a 3GHz Pentium 4:
+
+number of tests: 100
+number of branches per test: 100000
+memory hit cycles per iteration (mean): 636.611
+L1 cache hit cycles per iteration (mean): 89.6413
+instruction stream based test, cycles per iteration (mean): 85.3438
+Just getting the pointer from a modulo on a pseudo-random value, doing
+  nothing with it, cycles per iteration (mean): 77.5044
+
+So:
+Base case:                      77.50 cycles
+instruction stream based test:  +7.8394 cycles
+L1 cache hit based test:        +12.1369 cycles
+Memory load based test:         +559.1066 cycles
+
+So let's say we have a ping flood coming at
+(14014 packets transmitted, 14014 received, 0% packet loss, time 1826ms)
+7674 packets per second. If we put 2 markers for irq entry/exit, it
+brings us to 15348 markers sites executed per second.
+
+(15348 exec/s) * (559 cycles/exec) / (3G cycles/s) = 0.0029
+We therefore have a 0.29% slowdown just on this case.
+
+Compared to this, the instruction stream based test will cause a
+slowdown of:
+
+(15348 exec/s) * (7.84 cycles/exec) / (3G cycles/s) = 0.00004
+For a 0.004% slowdown.
+
+If we plan to use this for memory allocation, spinlock, and all sorts of
+very high event rate tracing, we can assume it will execute 10 to 100
+times more sites per second, which brings us to 0.4% slowdown with the
+instruction stream based test compared to 29% slowdown with the memory
+load based test on a system with high memory pressure.
+
+
+
+  * Markers impact under heavy memory load
+
+Running a kernel with my LTTng instrumentation set, in a test that
+generates memory pressure (from userspace) by trashing L1 and L2 caches
+between calls to getppid() (note: syscall_trace is active and calls
+a marker upon syscall entry and syscall exit; markers are disarmed).
+This test is done in user-space, so there are some delays due to IRQs
+coming and to the scheduler. (UP 2.6.22-rc6-mm1 kernel, task with -20
+nice level)
+
+My first set of results: Linear cache trashing, turned out not to be
+very interesting, because it seems like the linearity of the memset on a
+full array is somehow detected and it does not "really" trash the
+caches.
+
+Now the most interesting result: Random walk L1 and L2 trashing
+surrounding a getppid() call.
+
+- Markers compiled out (but syscall_trace execution forced)
+number of tests: 10000
+No memory pressure
+Reading timestamps takes 108.033 cycles
+getppid: 1681.4 cycles
+With memory pressure
+Reading timestamps takes 102.938 cycles
+getppid: 15691.6 cycles
+
+
+- With the immediate values based markers:
+number of tests: 10000
+No memory pressure
+Reading timestamps takes 108.006 cycles
+getppid: 1681.84 cycles
+With memory pressure
+Reading timestamps takes 100.291 cycles
+getppid: 11793 cycles
+
+
+- With global variables based markers:
+number of tests: 10000
+No memory pressure
+Reading timestamps takes 107.999 cycles
+getppid: 1669.06 cycles
+With memory pressure
+Reading timestamps takes 102.839 cycles
+getppid: 12535 cycles
+
+The result is quite interesting in that the kernel is slower without
+markers than with markers. I explain it by the fact that the data
+accessed is not laid out in the same manner in the cache lines when the
+markers are compiled in or out. It seems that it aligns the function's
+data better to compile-in the markers in this case.
+
+But since the interesting comparison is between the immediate values and
+global variables based markers, and because they share the same memory
+layout, except for the movl being replaced by a movz, we see that the
+global variable based markers (2 markers) adds 742 cycles to each system
+call (syscall entry and exit are traced and memory locations for both
+global variables lie on the same cache line).
+
+
+- Test redone with less iterations, but with error estimates
+
+10 runs of 100 iterations each: Tests done on a 3GHz P4. Here I run getppid with
+syscall trace inactive, comparing the case with memory pressure and without
+memory pressure. (sorry, my system is not setup to execute syscall_trace this
+time, but it will make the point anyway).
+
+No memory pressure
+Reading timestamps:     150.92 cycles,     std dev.    1.01 cycles
+getppid:               1462.09 cycles,     std dev.   18.87 cycles
+
+With memory pressure
+Reading timestamps:     578.22 cycles,     std dev.  269.51 cycles
+getppid:              17113.33 cycles,     std dev. 1655.92 cycles
+
+
+Now for memory read timing: (10 runs, branches per test: 100000)
+Memory read based branch:
+                       644.09 cycles,      std dev.   11.39 cycles
+L1 cache hit based branch:
+                        88.16 cycles,      std dev.    1.35 cycles
+
+
+So, now that we have the raw results, let's calculate:
+
+Memory read:
+644.09±11.39 - 88.16±1.35 = 555.93±11.46 cycles
+
+Getppid without memory pressure:
+1462.09±18.87 - 150.92±1.01 = 1311.17±18.90 cycles
+
+Getppid with memory pressure:
+17113.33±1655.92 - 578.22±269.51 = 16535.11±1677.71 cycles
+
+Therefore, if we add 2 markers not based on immediate values to the getppid
+code, which would add 2 memory reads, we would add
+2 * 555.93±12.74 = 1111.86±25.48 cycles
+
+Therefore,
+
+1111.86±25.48 / 16535.11±1677.71 = 0.0672
+ relative error: sqrt(((25.48/1111.86)^2)+((1677.71/16535.11)^2))
+                     = 0.1040
+ absolute error: 0.1040 * 0.0672 = 0.0070
+
+Therefore: 0.0672±0.0070 * 100% = 6.72±0.70 %
+
+We can therefore affirm that adding 2 markers to getppid, on a system with high
+memory pressure, would have a performance hit of at least 6.0% on the system
+call time, all within the uncertainty limits of these tests. The same applies to
+other kernel code paths. The smaller those code paths are, the highest the
+impact ratio will be.
+
+Therefore, not only is it interesting to use the immediate values to dynamically
+activate dormant code such as the markers, but I think it should also be
+considered as a replacement for many of the "read-mostly" static variables.

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 20/26] Scheduler Profiling - Use Immediate Values
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (18 preceding siblings ...)
  2008-01-24 20:27 ` [patch 19/26] Immediate Values - Documentation Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 21/26] Immediate Values - Move Kprobes x86 restore_interrupt to kdebug.h Mathieu Desnoyers
                   ` (5 subsequent siblings)
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel; +Cc: Mathieu Desnoyers

[-- Attachment #1: profiling-use-immediate-values.patch --]
[-- Type: text/plain, Size: 5770 bytes --]

Use immediate values with lower d-cache hit in optimized version as a
condition for scheduler profiling call.

Changelog :
- Use imv_* instead of immediate_*.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
---
 arch/x86/kvm/x86.c      |    2 +-
 include/linux/profile.h |    5 +++--
 kernel/profile.c        |   22 +++++++++++-----------
 kernel/sched_fair.c     |    6 +-----
 4 files changed, 16 insertions(+), 19 deletions(-)

Index: linux-2.6-lttng.mm/kernel/profile.c
===================================================================
--- linux-2.6-lttng.mm.orig/kernel/profile.c	2008-01-24 14:10:55.000000000 -0500
+++ linux-2.6-lttng.mm/kernel/profile.c	2008-01-24 14:31:44.000000000 -0500
@@ -41,8 +41,8 @@ static int (*timer_hook)(struct pt_regs 
 static atomic_t *prof_buffer;
 static unsigned long prof_len, prof_shift;
 
-int prof_on __read_mostly;
-EXPORT_SYMBOL_GPL(prof_on);
+DEFINE_IMV(char, prof_on) __read_mostly;
+EXPORT_IMV_SYMBOL_GPL(prof_on);
 
 static cpumask_t prof_cpu_mask = CPU_MASK_ALL;
 #ifdef CONFIG_SMP
@@ -60,7 +60,7 @@ static int __init profile_setup(char *st
 
 	if (!strncmp(str, sleepstr, strlen(sleepstr))) {
 #ifdef CONFIG_SCHEDSTATS
-		prof_on = SLEEP_PROFILING;
+		imv_set(prof_on, SLEEP_PROFILING);
 		if (str[strlen(sleepstr)] == ',')
 			str += strlen(sleepstr) + 1;
 		if (get_option(&str, &par))
@@ -73,7 +73,7 @@ static int __init profile_setup(char *st
 			"kernel sleep profiling requires CONFIG_SCHEDSTATS\n");
 #endif /* CONFIG_SCHEDSTATS */
 	} else if (!strncmp(str, schedstr, strlen(schedstr))) {
-		prof_on = SCHED_PROFILING;
+		imv_set(prof_on, SCHED_PROFILING);
 		if (str[strlen(schedstr)] == ',')
 			str += strlen(schedstr) + 1;
 		if (get_option(&str, &par))
@@ -82,7 +82,7 @@ static int __init profile_setup(char *st
 			"kernel schedule profiling enabled (shift: %ld)\n",
 			prof_shift);
 	} else if (!strncmp(str, kvmstr, strlen(kvmstr))) {
-		prof_on = KVM_PROFILING;
+		imv_set(prof_on, KVM_PROFILING);
 		if (str[strlen(kvmstr)] == ',')
 			str += strlen(kvmstr) + 1;
 		if (get_option(&str, &par))
@@ -92,7 +92,7 @@ static int __init profile_setup(char *st
 			prof_shift);
 	} else if (get_option(&str, &par)) {
 		prof_shift = par;
-		prof_on = CPU_PROFILING;
+		imv_set(prof_on, CPU_PROFILING);
 		printk(KERN_INFO "kernel profiling enabled (shift: %ld)\n",
 			prof_shift);
 	}
@@ -103,7 +103,7 @@ __setup("profile=", profile_setup);
 
 void __init profile_init(void)
 {
-	if (!prof_on)
+	if (!_imv_read(prof_on))
 		return;
 
 	/* only text is profiled */
@@ -290,7 +290,7 @@ void profile_hits(int type, void *__pc, 
 	int i, j, cpu;
 	struct profile_hit *hits;
 
-	if (prof_on != type || !prof_buffer)
+	if (!prof_buffer)
 		return;
 	pc = min((pc - (unsigned long)_stext) >> prof_shift, prof_len - 1);
 	i = primary = (pc & (NR_PROFILE_GRP - 1)) << PROFILE_GRPSHIFT;
@@ -400,7 +400,7 @@ void profile_hits(int type, void *__pc, 
 {
 	unsigned long pc;
 
-	if (prof_on != type || !prof_buffer)
+	if (!prof_buffer)
 		return;
 	pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
 	atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
@@ -557,7 +557,7 @@ static int __init create_hash_tables(voi
 	}
 	return 0;
 out_cleanup:
-	prof_on = 0;
+	imv_set(prof_on, 0);
 	smp_mb();
 	on_each_cpu(profile_nop, NULL, 0, 1);
 	for_each_online_cpu(cpu) {
@@ -584,7 +584,7 @@ static int __init create_proc_profile(vo
 {
 	struct proc_dir_entry *entry;
 
-	if (!prof_on)
+	if (!_imv_read(prof_on))
 		return 0;
 	if (create_hash_tables())
 		return -1;
Index: linux-2.6-lttng.mm/include/linux/profile.h
===================================================================
--- linux-2.6-lttng.mm.orig/include/linux/profile.h	2008-01-24 14:04:09.000000000 -0500
+++ linux-2.6-lttng.mm/include/linux/profile.h	2008-01-24 14:30:51.000000000 -0500
@@ -7,10 +7,11 @@
 #include <linux/init.h>
 #include <linux/cpumask.h>
 #include <linux/cache.h>
+#include <linux/immediate.h>
 
 #include <asm/errno.h>
 
-extern int prof_on __read_mostly;
+DECLARE_IMV(char, prof_on) __read_mostly;
 
 #define CPU_PROFILING	1
 #define SCHED_PROFILING	2
@@ -38,7 +39,7 @@ static inline void profile_hit(int type,
 	/*
 	 * Speedup for the common (no profiling enabled) case:
 	 */
-	if (unlikely(prof_on == type))
+	if (unlikely(imv_read(prof_on) == type))
 		profile_hits(type, ip, 1);
 }
 
Index: linux-2.6-lttng.mm/kernel/sched_fair.c
===================================================================
--- linux-2.6-lttng.mm.orig/kernel/sched_fair.c	2008-01-24 14:10:55.000000000 -0500
+++ linux-2.6-lttng.mm/kernel/sched_fair.c	2008-01-24 14:30:51.000000000 -0500
@@ -461,12 +461,8 @@ static void enqueue_sleeper(struct cfs_r
 		 * get a milliseconds-range estimation of the amount of
 		 * time that the task spent sleeping:
 		 */
-		if (unlikely(prof_on == SLEEP_PROFILING)) {
-			struct task_struct *tsk = task_of(se);
-
-			profile_hits(SLEEP_PROFILING, (void *)get_wchan(tsk),
+		profile_hits(SLEEP_PROFILING, (void *)get_wchan(task_of(se)),
 				     delta >> 20);
-		}
 	}
 #endif
 }
Index: linux-2.6-lttng.mm/arch/x86/kvm/x86.c
===================================================================
--- linux-2.6-lttng.mm.orig/arch/x86/kvm/x86.c	2008-01-24 14:33:35.000000000 -0500
+++ linux-2.6-lttng.mm/arch/x86/kvm/x86.c	2008-01-24 14:34:08.000000000 -0500
@@ -2592,7 +2592,7 @@ again:
 	/*
 	 * Profile KVM exit RIPs:
 	 */
-	if (unlikely(prof_on == KVM_PROFILING)) {
+	if (unlikely(imv_read(prof_on) == KVM_PROFILING)) {
 		kvm_x86_ops->cache_regs(vcpu);
 		profile_hit(KVM_PROFILING, (void *)vcpu->arch.rip);
 	}

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 21/26] Immediate Values - Move Kprobes x86 restore_interrupt to kdebug.h
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (19 preceding siblings ...)
  2008-01-24 20:27 ` [patch 20/26] Scheduler Profiling - Use Immediate Values Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 22/26] Add __discard section to x86 Mathieu Desnoyers
                   ` (4 subsequent siblings)
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel
  Cc: Mathieu Desnoyers, Ananth N Mavinakayanahalli, Christoph Hellwig,
	anil.s.keshavamurthy, davem, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin

[-- Attachment #1: immediate-values-move-kprobes-x86-restore-interrupt-to-kdebug-h.patch --]
[-- Type: text/plain, Size: 2539 bytes --]

Since the breakpoint handler is useful both to kprobes and immediate values, it
makes sense to make the required restore_interrupt() available through
asm-i386/kdebug.h.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Acked-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
CC: Christoph Hellwig <hch@infradead.org>
CC: anil.s.keshavamurthy@intel.com
CC: davem@davemloft.net
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Ingo Molnar <mingo@redhat.com>
CC: H. Peter Anvin <hpa@zytor.com>
---
 include/asm-x86/kdebug.h  |   13 +++++++++++++
 include/asm-x86/kprobes.h |    9 ---------
 2 files changed, 13 insertions(+), 9 deletions(-)

Index: linux-2.6-lttng.mm/include/asm-x86/kdebug.h
===================================================================
--- linux-2.6-lttng.mm.orig/include/asm-x86/kdebug.h	2008-01-24 14:40:49.000000000 -0500
+++ linux-2.6-lttng.mm/include/asm-x86/kdebug.h	2008-01-24 14:41:10.000000000 -0500
@@ -3,6 +3,9 @@
 
 #include <linux/notifier.h>
 
+#include <linux/ptrace.h>
+#include <asm/system.h>
+
 struct pt_regs;
 
 /* Grossly misnamed. */
@@ -36,4 +39,14 @@ extern void dump_pagetable(unsigned long
 extern unsigned long oops_begin(void);
 extern void oops_end(unsigned long, struct pt_regs *, int signr);
 
+/*
+ * trap3/1 are intr gates for kprobes.  So, restore the status of IF,
+ * if necessary, before executing the original int3/1 (trap) handler.
+ */
+static inline void restore_interrupts(struct pt_regs *regs)
+{
+	if (regs->flags & X86_EFLAGS_IF)
+		local_irq_enable();
+}
+
 #endif
Index: linux-2.6-lttng.mm/include/asm-x86/kprobes.h
===================================================================
--- linux-2.6-lttng.mm.orig/include/asm-x86/kprobes.h	2008-01-24 14:41:14.000000000 -0500
+++ linux-2.6-lttng.mm/include/asm-x86/kprobes.h	2008-01-24 14:41:21.000000000 -0500
@@ -83,15 +83,6 @@ struct kprobe_ctlblk {
 	struct prev_kprobe prev_kprobe;
 };
 
-/* trap3/1 are intr gates for kprobes.  So, restore the status of IF,
- * if necessary, before executing the original int3/1 (trap) handler.
- */
-static inline void restore_interrupts(struct pt_regs *regs)
-{
-	if (regs->flags & X86_EFLAGS_IF)
-		local_irq_enable();
-}
-
 extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
 extern int kprobe_exceptions_notify(struct notifier_block *self,
 				    unsigned long val, void *data);

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 22/26] Add __discard section to x86
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (20 preceding siblings ...)
  2008-01-24 20:27 ` [patch 21/26] Immediate Values - Move Kprobes x86 restore_interrupt to kdebug.h Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 23/26] Immediate Values - x86 Optimization NMI and MCE support Mathieu Desnoyers
                   ` (3 subsequent siblings)
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel
  Cc: Mathieu Desnoyers, H. Peter Anvin, Andi Kleen, Chuck Ebbert,
	Christoph Hellwig, Jeremy Fitzhardinge, Thomas Gleixner,
	Ingo Molnar

[-- Attachment #1: add-discard-section-to-x86.patch --]
[-- Type: text/plain, Size: 1794 bytes --]

Add a __discard sectionto the linker script. Code produced in this section will
not be put in the vmlinux file. This is useful when we have to calculate the
size of an instruction before actually declaring it (for alignment purposes for
instance). This is used by the immediate values.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Acked-by: H. Peter Anvin <hpa@zytor.com>
CC: Andi Kleen <ak@muc.de>
CC: Chuck Ebbert <cebbert@redhat.com>
CC: Christoph Hellwig <hch@infradead.org>
CC: Jeremy Fitzhardinge <jeremy@goop.org>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Ingo Molnar <mingo@redhat.com>
---
 arch/x86/kernel/vmlinux_32.lds.S |    1 +
 arch/x86/kernel/vmlinux_64.lds.S |    1 +
 2 files changed, 2 insertions(+)

Index: linux-2.6-lttng.mm/arch/x86/kernel/vmlinux_32.lds.S
===================================================================
--- linux-2.6-lttng.mm.orig/arch/x86/kernel/vmlinux_32.lds.S	2008-01-24 14:40:42.000000000 -0500
+++ linux-2.6-lttng.mm/arch/x86/kernel/vmlinux_32.lds.S	2008-01-24 14:41:23.000000000 -0500
@@ -201,6 +201,7 @@ SECTIONS
   /* Sections to be discarded */
   /DISCARD/ : {
 	*(.exitcall.exit)
+	*(__discard)
 	}
 
   STABS_DEBUG
Index: linux-2.6-lttng.mm/arch/x86/kernel/vmlinux_64.lds.S
===================================================================
--- linux-2.6-lttng.mm.orig/arch/x86/kernel/vmlinux_64.lds.S	2008-01-24 14:40:42.000000000 -0500
+++ linux-2.6-lttng.mm/arch/x86/kernel/vmlinux_64.lds.S	2008-01-24 14:41:23.000000000 -0500
@@ -226,6 +226,7 @@ SECTIONS
   /DISCARD/ : {
 	*(.exitcall.exit)
 	*(.eh_frame)
+	*(__discard)
 	}
 
   STABS_DEBUG

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 23/26] Immediate Values - x86 Optimization NMI and MCE support
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (21 preceding siblings ...)
  2008-01-24 20:27 ` [patch 22/26] Add __discard section to x86 Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 24/26] Immediate Values - Powerpc Optimization NMI " Mathieu Desnoyers
                   ` (2 subsequent siblings)
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel
  Cc: Mathieu Desnoyers, Andi Kleen, H. Peter Anvin, Chuck Ebbert,
	Christoph Hellwig, Jeremy Fitzhardinge, Thomas Gleixner,
	Ingo Molnar

[-- Attachment #1: immediate-values-x86-optimization-nmi-mce-support.patch --]
[-- Type: text/plain, Size: 16637 bytes --]

x86 optimization of the immediate values which uses a movl with code patching
to set/unset the value used to populate the register used as variable source.
It uses a breakpoint to bypass the instruction being changed, which lessens the
interrupt latency of the operation and protects against NMIs and MCE.

- More reentrant immediate value : uses a breakpoint. Needs to know the
  instruction's first byte. This is why we keep the "instruction size"
  variable, so we can support the REX prefixed instructions too.

Changelog:
- Use text_poke_early with cr0 WP save/restore to patch the bypass. We are doing
  non atomic writes to a code region only touched by us (nobody can execute it
  since we are protected by the imv_mutex).
- Add x86_64 support, ready for i386+x86_64 -> x86 merge.
- Use asm-x86/asm.h.
- Change the immediate.c update code to support variable length opcodes.
- Use imv_* instead of immediate_*.
- Use kernel_wp_disable/enable instead of save/restore.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
CC: Andi Kleen <ak@muc.de>
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: Chuck Ebbert <cebbert@redhat.com>
CC: Christoph Hellwig <hch@infradead.org>
CC: Jeremy Fitzhardinge <jeremy@goop.org>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Ingo Molnar <mingo@redhat.com>
---
 arch/x86/kernel/Makefile    |    1 
 arch/x86/kernel/immediate.c |  281 ++++++++++++++++++++++++++++++++++++++++++++
 arch/x86/kernel/traps_32.c  |   10 -
 include/asm-x86/immediate.h |   42 +++++-
 4 files changed, 325 insertions(+), 9 deletions(-)

Index: linux-2.6-lttng.mm/include/asm-x86/immediate.h
===================================================================
--- linux-2.6-lttng.mm.orig/include/asm-x86/immediate.h	2008-01-24 14:41:09.000000000 -0500
+++ linux-2.6-lttng.mm/include/asm-x86/immediate.h	2008-01-24 14:41:41.000000000 -0500
@@ -12,6 +12,18 @@
 
 #include <asm/asm.h>
 
+struct __imv {
+	unsigned long var;	/* Pointer to the identifier variable of the
+				 * immediate value
+				 */
+	unsigned long imv;	/*
+				 * Pointer to the memory location of the
+				 * immediate value within the instruction.
+				 */
+	unsigned char size;	/* Type size. */
+	unsigned char insn_size;/* Instruction size. */
+} __attribute__ ((packed));
+
 /**
  * imv_read - read immediate variable
  * @name: immediate value name
@@ -26,6 +38,11 @@
  * what will generate an instruction with 8 bytes immediate value (not the REX.W
  * prefixed one that loads a sign extended 32 bits immediate value in a r64
  * register).
+ *
+ * Create the instruction in a discarded section to calculate its size. This is
+ * how we can align the beginning of the instruction on an address that will
+ * permit atomic modification of the immediate value without knowing the size of
+ * the opcode used by the compiler. The operand size is known in advance.
  */
 #define imv_read(name)							\
 	({								\
@@ -35,8 +52,9 @@
 		case 1:							\
 			asm(".section __imv,\"a\",@progbits\n\t"	\
 				_ASM_PTR "%c1, (3f)-%c2\n\t"		\
-				".byte %c2\n\t"				\
+				".byte %c2, (3f-2f)\n\t"		\
 				".previous\n\t"				\
+				"2:\n\t"				\
 				"mov $0,%0\n\t"				\
 				"3:\n\t"				\
 				: "=q" (value)				\
@@ -45,10 +63,16 @@
 			break;						\
 		case 2:							\
 		case 4:							\
-			asm(".section __imv,\"a\",@progbits\n\t"	\
+			asm(".section __discard,\"\",@progbits\n\t"	\
+				"1:\n\t"				\
+				"mov $0,%0\n\t"				\
+				"2:\n\t"				\
+				".previous\n\t"				\
+				".section __imv,\"a\",@progbits\n\t"	\
 				_ASM_PTR "%c1, (3f)-%c2\n\t"		\
-				".byte %c2\n\t"				\
+				".byte %c2, (2b-1b)\n\t"		\
 				".previous\n\t"				\
+				".org . + ((-.-(2b-1b)) & (%c2-1)), 0x90\n\t" \
 				"mov $0,%0\n\t"				\
 				"3:\n\t"				\
 				: "=r" (value)				\
@@ -60,10 +84,16 @@
 				value = name##__imv;			\
 				break;					\
 			}						\
-			asm(".section __imv,\"a\",@progbits\n\t"	\
+			asm(".section __discard,\"\",@progbits\n\t"	\
+				"1:\n\t"				\
+				"mov $0xFEFEFEFE01010101,%0\n\t" 	\
+				"2:\n\t"				\
+				".previous\n\t"				\
+				".section __imv,\"a\",@progbits\n\t"	\
 				_ASM_PTR "%c1, (3f)-%c2\n\t"		\
-				".byte %c2\n\t"				\
+				".byte %c2, (2b-1b)\n\t"		\
 				".previous\n\t"				\
+				".org . + ((-.-(2b-1b)) & (%c2-1)), 0x90\n\t" \
 				"mov $0xFEFEFEFE01010101,%0\n\t" 	\
 				"3:\n\t"				\
 				: "=r" (value)				\
@@ -74,4 +104,6 @@
 		value;							\
 	})
 
+extern int arch_imv_update(const struct __imv *imv, int early);
+
 #endif /* _ASM_X86_IMMEDIATE_H */
Index: linux-2.6-lttng.mm/arch/x86/kernel/traps_32.c
===================================================================
--- linux-2.6-lttng.mm.orig/arch/x86/kernel/traps_32.c	2008-01-24 14:40:42.000000000 -0500
+++ linux-2.6-lttng.mm/arch/x86/kernel/traps_32.c	2008-01-24 14:43:18.000000000 -0500
@@ -552,7 +552,7 @@ void do_##name(struct pt_regs * regs, lo
 }
 
 DO_VM86_ERROR_INFO( 0, SIGFPE,  "divide error", divide_error, FPE_INTDIV, regs->ip)
-#ifndef CONFIG_KPROBES
+#if !defined(CONFIG_KPROBES) && !defined(CONFIG_IMMEDIATE)
 DO_VM86_ERROR( 3, SIGTRAP, "int3", int3)
 #endif
 DO_VM86_ERROR( 4, SIGSEGV, "overflow", overflow)
@@ -794,7 +794,7 @@ void restart_nmi(void)
 	acpi_nmi_enable();
 }
 
-#ifdef CONFIG_KPROBES
+#if defined(CONFIG_KPROBES) || defined(CONFIG_IMMEDIATE)
 void __kprobes do_int3(struct pt_regs *regs, long error_code)
 {
 	trace_hardirqs_fixup();
@@ -802,8 +802,10 @@ void __kprobes do_int3(struct pt_regs *r
 	if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP)
 			== NOTIFY_STOP)
 		return;
-	/* This is an interrupt gate, because kprobes wants interrupts
-	disabled.  Normal trap handlers don't. */
+	/*
+	 * This is an interrupt gate, because kprobes and immediate values wants
+	 * interrupts disabled.  Normal trap handlers don't.
+	 */
 	restore_interrupts(regs);
 	do_trap(3, SIGTRAP, "int3", 1, regs, error_code, NULL);
 }
Index: linux-2.6-lttng.mm/arch/x86/kernel/immediate.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6-lttng.mm/arch/x86/kernel/immediate.c	2008-01-24 14:41:41.000000000 -0500
@@ -0,0 +1,281 @@
+/*
+ * Immediate Value - x86 architecture specific code.
+ *
+ * Rationale
+ *
+ * Required because of :
+ * - Erratum 49 fix for Intel PIII.
+ * - Still present on newer processors : Intel Core 2 Duo Processor for Intel
+ *   Centrino Duo Processor Technology Specification Update, AH33.
+ *   Unsynchronized Cross-Modifying Code Operations Can Cause Unexpected
+ *   Instruction Execution Results.
+ *
+ * Permits immediate value modification by XMC with correct serialization.
+ *
+ * Reentrant for NMI and trap handler instrumentation. Permits XMC to a
+ * location that has preemption enabled because it involves no temporary or
+ * reused data structure.
+ *
+ * Quoting Richard J Moore, source of the information motivating this
+ * implementation which differs from the one proposed by Intel which is not
+ * suitable for kernel context (does not support NMI and would require disabling
+ * interrupts on every CPU for a long period) :
+ *
+ * "There is another issue to consider when looking into using probes other
+ * then int3:
+ *
+ * Intel erratum 54 - Unsynchronized Cross-modifying code - refers to the
+ * practice of modifying code on one processor where another has prefetched
+ * the unmodified version of the code. Intel states that unpredictable general
+ * protection faults may result if a synchronizing instruction (iret, int,
+ * int3, cpuid, etc ) is not executed on the second processor before it
+ * executes the pre-fetched out-of-date copy of the instruction.
+ *
+ * When we became aware of this I had a long discussion with Intel's
+ * microarchitecture guys. It turns out that the reason for this erratum
+ * (which incidentally Intel does not intend to fix) is because the trace
+ * cache - the stream of micro-ops resulting from instruction interpretation -
+ * cannot be guaranteed to be valid. Reading between the lines I assume this
+ * issue arises because of optimization done in the trace cache, where it is
+ * no longer possible to identify the original instruction boundaries. If the
+ * CPU discoverers that the trace cache has been invalidated because of
+ * unsynchronized cross-modification then instruction execution will be
+ * aborted with a GPF. Further discussion with Intel revealed that replacing
+ * the first opcode byte with an int3 would not be subject to this erratum.
+ *
+ * So, is cmpxchg reliable? One has to guarantee more than mere atomicity."
+ *
+ * Overall design
+ *
+ * The algorithm proposed by Intel applies not so well in kernel context: it
+ * would imply disabling interrupts and looping on every CPUs while modifying
+ * the code and would not support instrumentation of code called from interrupt
+ * sources that cannot be disabled.
+ *
+ * Therefore, we use a different algorithm to respect Intel's erratum (see the
+ * quoted discussion above). We make sure that no CPU sees an out-of-date copy
+ * of a pre-fetched instruction by 1 - using a breakpoint, which skips the
+ * instruction that is going to be modified, 2 - issuing an IPI to every CPU to
+ * execute a sync_core(), to make sure that even when the breakpoint is removed,
+ * no cpu could possibly still have the out-of-date copy of the instruction,
+ * modify the now unused 2nd byte of the instruction, and then put back the
+ * original 1st byte of the instruction.
+ *
+ * It has exactly the same intent as the algorithm proposed by Intel, but
+ * it has less side-effects, scales better and supports NMI, SMI and MCE.
+ *
+ * Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
+ */
+
+#include <linux/preempt.h>
+#include <linux/smp.h>
+#include <linux/notifier.h>
+#include <linux/module.h>
+#include <linux/immediate.h>
+#include <linux/kdebug.h>
+#include <linux/rcupdate.h>
+#include <linux/kprobes.h>
+
+#include <asm/cacheflush.h>
+
+#define BREAKPOINT_INSTRUCTION  0xcc
+#define BREAKPOINT_INS_LEN	1
+#define NR_NOPS			10
+
+static unsigned long target_after_int3;	/* EIP of the target after the int3 */
+static unsigned long bypass_eip;	/* EIP of the bypass. */
+static unsigned long bypass_after_int3;	/* EIP after the end-of-bypass int3 */
+static unsigned long after_imv;	/*
+					 * EIP where to resume after the
+					 * single-stepping.
+					 */
+
+/*
+ * Internal bypass used during value update. The bypass is skipped by the
+ * function in which it is inserted.
+ * No need to be aligned because we exclude readers from the site during
+ * update.
+ * Layout is:
+ * (10x nop) int3
+ * (maximum size is 2 bytes opcode + 8 bytes immediate value for long on x86_64)
+ * The nops are the target replaced by the instruction to single-step.
+ */
+static inline void _imv_bypass(unsigned long *bypassaddr,
+	unsigned long *breaknextaddr)
+{
+		asm volatile("jmp 2f;\n\t"
+				"0:\n\t"
+				".space 10, 0x90;\n\t"
+				"1:\n\t"
+				"int3;\n\t"
+				"2:\n\t"
+				"mov $(0b),%0;\n\t"
+				"mov $((1b)+1),%1;\n\t"
+				: "=r" (*bypassaddr),
+				  "=r" (*breaknextaddr));
+}
+
+static void imv_synchronize_core(void *info)
+{
+	sync_core();	/* use cpuid to stop speculative execution */
+}
+
+/*
+ * The eip value points right after the breakpoint instruction, in the second
+ * byte of the movl.
+ * Disable preemption in the bypass to make sure no thread will be preempted in
+ * it. We can then use synchronize_sched() to make sure every bypass users have
+ * ended.
+ */
+static int imv_notifier(struct notifier_block *nb,
+	unsigned long val, void *data)
+{
+	enum die_val die_val = (enum die_val) val;
+	struct die_args *args = data;
+
+	if (!args->regs || user_mode_vm(args->regs))
+		return NOTIFY_DONE;
+
+	if (die_val == DIE_INT3) {
+		if (instruction_pointer(args->regs) == target_after_int3) {
+			preempt_disable();
+			instruction_pointer(args->regs) = bypass_eip;
+			return NOTIFY_STOP;
+		} else if (instruction_pointer(args->regs)
+				== bypass_after_int3) {
+			instruction_pointer(args->regs) = after_imv;
+			preempt_enable();
+			return NOTIFY_STOP;
+		}
+	}
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block imv_notify = {
+	.notifier_call = imv_notifier,
+	.priority = 0x7fffffff,	/* we need to be notified first */
+};
+
+/**
+ * arch_imv_update - update one immediate value
+ * @imv: pointer of type const struct __imv to update
+ * @early: early boot (1) or normal (0)
+ *
+ * Update one immediate value. Must be called with imv_mutex held.
+ */
+__kprobes int arch_imv_update(const struct __imv *imv, int early)
+{
+	int ret;
+	unsigned char opcode_size = imv->insn_size - imv->size;
+	unsigned long insn = imv->imv - opcode_size;
+	unsigned long len;
+
+#ifdef CONFIG_KPROBES
+	/*
+	 * Fail if a kprobe has been set on this instruction.
+	 * (TODO: we could eventually do better and modify all the (possibly
+	 * nested) kprobes for this site if kprobes had an API for this.
+	 */
+	if (unlikely(!early
+			&& *(unsigned char *)insn == BREAKPOINT_INSTRUCTION)) {
+		printk(KERN_WARNING "Immediate value in conflict with kprobe. "
+				    "Variable at %p, "
+				    "instruction at %p, size %hu\n",
+				    (void *)imv->imv,
+				    (void *)imv->var, imv->size);
+		return -EBUSY;
+	}
+#endif
+
+	/*
+	 * If the variable and the instruction have the same value, there is
+	 * nothing to do.
+	 */
+	switch (imv->size) {
+	case 1:	if (*(uint8_t *)imv->imv
+				== *(uint8_t *)imv->var)
+			return 0;
+		break;
+	case 2:	if (*(uint16_t *)imv->imv
+				== *(uint16_t *)imv->var)
+			return 0;
+		break;
+	case 4:	if (*(uint32_t *)imv->imv
+				== *(uint32_t *)imv->var)
+			return 0;
+		break;
+#ifdef CONFIG_X86_64
+	case 8:	if (*(uint64_t *)imv->imv
+				== *(uint64_t *)imv->var)
+			return 0;
+		break;
+#endif
+	default:return -EINVAL;
+	}
+
+	if (!early) {
+		/* bypass is 10 bytes long for x86_64 long */
+		WARN_ON(imv->insn_size > 10);
+		_imv_bypass(&bypass_eip, &bypass_after_int3);
+
+		after_imv = imv->imv + imv->size;
+
+		/*
+		 * Using the _early variants because nobody is executing the
+		 * bypass code while we patch it. It is protected by the
+		 * imv_mutex. Since we modify the instructions non atomically
+		 * (for nops), we have to use the _early variant.
+		 * We must however deal with the WP flag in cr0 by ourself.
+		 */
+		kernel_wp_disable();
+		text_poke_early((void *)bypass_eip, (void *)insn,
+				imv->insn_size);
+		/*
+		 * Fill the rest with nops.
+		 */
+		len = NR_NOPS - imv->insn_size;
+		add_nops((void *)(bypass_eip + imv->insn_size), len);
+		kernel_wp_enable();
+
+		target_after_int3 = insn + BREAKPOINT_INS_LEN;
+		/* register_die_notifier has memory barriers */
+		register_die_notifier(&imv_notify);
+		/* The breakpoint will single-step the bypass */
+		text_poke((void *)insn,
+			INIT_ARRAY(unsigned char, BREAKPOINT_INSTRUCTION, 1),
+			1);
+		/*
+		 * Make sure the breakpoint is set before we continue (visible
+		 * to other CPUs and interrupts).
+		 */
+		wmb();
+		/*
+		 * Execute serializing instruction on each CPU.
+		 */
+		ret = on_each_cpu(imv_synchronize_core, NULL, 1, 1);
+		BUG_ON(ret != 0);
+
+		text_poke((void *)(insn + opcode_size), (void *)imv->var,
+				imv->size);
+		/*
+		 * Make sure the value can be seen from other CPUs and
+		 * interrupts.
+		 */
+		wmb();
+		text_poke((void *)insn, (unsigned char *)bypass_eip, 1);
+		/*
+		 * Wait for all int3 handlers to end (interrupts are disabled in
+		 * int3). This CPU is clearly not in a int3 handler, because
+		 * int3 handler is not preemptible and there cannot be any more
+		 * int3 handler called for this site, because we placed the
+		 * original instruction back.  synchronize_sched has memory
+		 * barriers.
+		 */
+		synchronize_sched();
+		unregister_die_notifier(&imv_notify);
+		/* unregister_die_notifier has memory barriers */
+	} else
+		text_poke_early((void *)imv->imv, (void *)imv->var,
+			imv->size);
+	return 0;
+}
Index: linux-2.6-lttng.mm/arch/x86/kernel/Makefile
===================================================================
--- linux-2.6-lttng.mm.orig/arch/x86/kernel/Makefile	2008-01-24 14:43:25.000000000 -0500
+++ linux-2.6-lttng.mm/arch/x86/kernel/Makefile	2008-01-24 14:43:43.000000000 -0500
@@ -70,6 +70,7 @@ obj-$(CONFIG_MGEODE_LX)		+= geode_32.o m
 obj-$(CONFIG_VMI)		+= vmi_32.o vmiclock_32.o
 obj-$(CONFIG_PARAVIRT)		+= paravirt.o paravirt_patch_$(BITS).o
 obj-y				+= pcspeaker.o
+obj-$(CONFIG_IMMEDIATE)		+= immediate.o
 
 obj-$(CONFIG_SCx200)		+= scx200_32.o
 

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 24/26] Immediate Values - Powerpc Optimization NMI MCE support
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (22 preceding siblings ...)
  2008-01-24 20:27 ` [patch 23/26] Immediate Values - x86 Optimization NMI and MCE support Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 25/26] Immediate Values Use Arch NMI and MCE Support Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 26/26] Linux Kernel Markers - Use Immediate Values Mathieu Desnoyers
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel
  Cc: Mathieu Desnoyers, Rusty Russell, Christoph Hellwig,
	Paul Mackerras

[-- Attachment #1: immediate-values-powerpc-optimization-nmi-mce-support.patch --]
[-- Type: text/plain, Size: 4859 bytes --]

Use an atomic update for immediate values.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
CC: Rusty Russell <rusty@rustcorp.com.au>
CC: Christoph Hellwig <hch@infradead.org>
CC: Paul Mackerras <paulus@samba.org>
---
 arch/powerpc/kernel/Makefile    |    1 
 arch/powerpc/kernel/immediate.c |   73 ++++++++++++++++++++++++++++++++++++++++
 include/asm-powerpc/immediate.h |   18 +++++++++
 3 files changed, 92 insertions(+)

Index: linux-2.6-lttng/arch/powerpc/kernel/immediate.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6-lttng/arch/powerpc/kernel/immediate.c	2007-12-20 20:52:27.000000000 -0500
@@ -0,0 +1,73 @@
+/*
+ * Powerpc optimized immediate values enabling/disabling.
+ *
+ * Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
+ */
+
+#include <linux/module.h>
+#include <linux/immediate.h>
+#include <linux/string.h>
+#include <linux/kprobes.h>
+#include <asm/cacheflush.h>
+#include <asm/page.h>
+
+#define LI_OPCODE_LEN	2
+
+/**
+ * arch_imv_update - update one immediate value
+ * @imv: pointer of type const struct __imv to update
+ * @early: early boot (1), normal (0)
+ *
+ * Update one immediate value. Must be called with imv_mutex held.
+ */
+int arch_imv_update(const struct __imv *imv, int early)
+{
+#ifdef CONFIG_KPROBES
+	kprobe_opcode_t *insn;
+	/*
+	 * Fail if a kprobe has been set on this instruction.
+	 * (TODO: we could eventually do better and modify all the (possibly
+	 * nested) kprobes for this site if kprobes had an API for this.
+	 */
+	switch (imv->size) {
+	case 1:	/* The uint8_t points to the 3rd byte of the
+		 * instruction */
+		insn = (void *)(imv->imv - 1 - LI_OPCODE_LEN);
+		break;
+	case 2:	insn = (void *)(imv->imv - LI_OPCODE_LEN);
+		break;
+	default:
+	return -EINVAL;
+	}
+
+	if (unlikely(!early && *insn == BREAKPOINT_INSTRUCTION)) {
+		printk(KERN_WARNING "Immediate value in conflict with kprobe. "
+				    "Variable at %p, "
+				    "instruction at %p, size %lu\n",
+				    (void *)imv->imv,
+				    (void *)imv->var, imv->size);
+		return -EBUSY;
+	}
+#endif
+
+	/*
+	 * If the variable and the instruction have the same value, there is
+	 * nothing to do.
+	 */
+	switch (imv->size) {
+	case 1:	if (*(uint8_t *)imv->imv
+				== *(uint8_t *)imv->var)
+			return 0;
+		break;
+	case 2:	if (*(uint16_t *)imv->imv
+				== *(uint16_t *)imv->var)
+			return 0;
+		break;
+	default:return -EINVAL;
+	}
+	memcpy((void *)imv->imv, (void *)imv->var,
+			imv->size);
+	flush_icache_range(imv->imv,
+		imv->imv + imv->size);
+	return 0;
+}
Index: linux-2.6-lttng/include/asm-powerpc/immediate.h
===================================================================
--- linux-2.6-lttng.orig/include/asm-powerpc/immediate.h	2007-12-20 20:52:20.000000000 -0500
+++ linux-2.6-lttng/include/asm-powerpc/immediate.h	2007-12-20 20:52:27.000000000 -0500
@@ -12,6 +12,16 @@
 
 #include <asm/asm-compat.h>
 
+struct __imv {
+	unsigned long var;	/* Identifier variable of the immediate value */
+	unsigned long imv;	/*
+				 * Pointer to the memory location that holds
+				 * the immediate value within the load immediate
+				 * instruction.
+				 */
+	unsigned char size;	/* Type size. */
+} __attribute__ ((packed));
+
 /**
  * imv_read - read immediate variable
  * @name: immediate value name
@@ -19,6 +29,11 @@
  * Reads the value of @name.
  * Optimized version of the immediate.
  * Do not use in __init and __exit functions. Use _imv_read() instead.
+ * Makes sure the 2 bytes update will be atomic by aligning the immediate
+ * value. Use a normal memory read for the 4 bytes immediate because there is no
+ * way to atomically update it without using a seqlock read side, which would
+ * cost more in term of total i-cache and d-cache space than a simple memory
+ * read.
  */
 #define imv_read(name)							\
 	({								\
@@ -40,6 +55,7 @@
 					PPC_LONG "%c1, ((1f)-2)\n\t"	\
 					".byte 2\n\t"			\
 					".previous\n\t"			\
+					".align 2\n\t"			\
 					"li %0,0\n\t"			\
 					"1:\n\t"			\
 				: "=r" (value)				\
@@ -52,4 +68,6 @@
 		value;							\
 	})
 
+extern int arch_imv_update(const struct __imv *imv, int early);
+
 #endif /* _ASM_POWERPC_IMMEDIATE_H */
Index: linux-2.6-lttng/arch/powerpc/kernel/Makefile
===================================================================
--- linux-2.6-lttng.orig/arch/powerpc/kernel/Makefile	2007-12-20 20:52:20.000000000 -0500
+++ linux-2.6-lttng/arch/powerpc/kernel/Makefile	2007-12-20 20:52:27.000000000 -0500
@@ -91,3 +91,4 @@ obj-$(CONFIG_PPC64)		+= $(obj64-y)
 
 extra-$(CONFIG_PPC_FPU)		+= fpu.o
 extra-$(CONFIG_PPC64)		+= entry_64.o
+obj-$(CONFIG_IMMEDIATE)		+= immediate.o

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 25/26] Immediate Values Use Arch NMI and MCE Support
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (23 preceding siblings ...)
  2008-01-24 20:27 ` [patch 24/26] Immediate Values - Powerpc Optimization NMI " Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  2008-01-24 20:27 ` [patch 26/26] Linux Kernel Markers - Use Immediate Values Mathieu Desnoyers
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel; +Cc: Mathieu Desnoyers

[-- Attachment #1: immediate-values-use-arch-nmi-mce-support.patch --]
[-- Type: text/plain, Size: 5107 bytes --]

Remove the architecture agnostic code now replaced by architecture specific,
atomic instruction updates.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
---
 include/linux/immediate.h |   11 ----
 kernel/immediate.c        |  113 +---------------------------------------------
 2 files changed, 4 insertions(+), 120 deletions(-)

Index: linux-2.6-lttng/kernel/immediate.c
===================================================================
--- linux-2.6-lttng.orig/kernel/immediate.c	2007-11-26 12:48:48.000000000 -0500
+++ linux-2.6-lttng/kernel/immediate.c	2007-11-26 13:01:15.000000000 -0500
@@ -19,9 +19,6 @@
 #include <linux/mutex.h>
 #include <linux/immediate.h>
 #include <linux/memory.h>
-#include <linux/cpu.h>
-
-#include <asm/cacheflush.h>
 
 /*
  * Kernel ready to execute the SMP update that may depend on trap and ipi.
@@ -37,111 +34,6 @@ extern const struct __imv __stop___imv[]
  */
 static DEFINE_MUTEX(imv_mutex);
 
-static atomic_t wait_sync;
-
-struct ipi_loop_data {
-	long value;
-	const struct __imv *imv;
-} loop_data;
-
-static void ipi_busy_loop(void *arg)
-{
-	unsigned long flags;
-
-	local_irq_save(flags);
-	atomic_dec(&wait_sync);
-	do {
-		/* Make sure the wait_sync gets re-read */
-		smp_mb();
-	} while (atomic_read(&wait_sync) > loop_data.value);
-	atomic_dec(&wait_sync);
-	do {
-		/* Make sure the wait_sync gets re-read */
-		smp_mb();
-	} while (atomic_read(&wait_sync) > 0);
-	/*
-	 * Issuing a synchronizing instruction must be done on each CPU before
-	 * reenabling interrupts after modifying an instruction. Required by
-	 * Intel's errata.
-	 */
-	sync_core();
-	flush_icache_range(loop_data.imv->imv,
-		loop_data.imv->imv + loop_data.imv->size);
-	local_irq_restore(flags);
-}
-
-/**
- * apply_imv_update - update one immediate value
- * @imv: pointer of type const struct __imv to update
- *
- * Update one immediate value. Must be called with imv_mutex held.
- * It makes sure all CPUs are not executing the modified code by having them
- * busy looping with interrupts disabled.
- * It does _not_ protect against NMI and MCE (could be a problem with Intel's
- * errata if we use immediate values in their code path).
- */
-static int apply_imv_update(const struct __imv *imv)
-{
-	unsigned long flags;
-	long online_cpus;
-
-	/*
-	 * If the variable and the instruction have the same value, there is
-	 * nothing to do.
-	 */
-	switch (imv->size) {
-	case 1:	if (*(uint8_t *)imv->imv
-				== *(uint8_t *)imv->var)
-			return 0;
-		break;
-	case 2:	if (*(uint16_t *)imv->imv
-				== *(uint16_t *)imv->var)
-			return 0;
-		break;
-	case 4:	if (*(uint32_t *)imv->imv
-				== *(uint32_t *)imv->var)
-			return 0;
-		break;
-	case 8:	if (*(uint64_t *)imv->imv
-				== *(uint64_t *)imv->var)
-			return 0;
-		break;
-	default:return -EINVAL;
-	}
-
-	if (imv_early_boot_complete) {
-		kernel_text_lock();
-		lock_cpu_hotplug();
-		online_cpus = num_online_cpus();
-		atomic_set(&wait_sync, 2 * online_cpus);
-		loop_data.value = online_cpus;
-		loop_data.imv = imv;
-		smp_call_function(ipi_busy_loop, NULL, 1, 0);
-		local_irq_save(flags);
-		atomic_dec(&wait_sync);
-		do {
-			/* Make sure the wait_sync gets re-read */
-			smp_mb();
-		} while (atomic_read(&wait_sync) > online_cpus);
-		text_poke((void *)imv->imv, (void *)imv->var,
-				imv->size);
-		/*
-		 * Make sure the modified instruction is seen by all CPUs before
-		 * we continue (visible to other CPUs and local interrupts).
-		 */
-		wmb();
-		atomic_dec(&wait_sync);
-		flush_icache_range(imv->imv,
-				imv->imv + imv->size);
-		local_irq_restore(flags);
-		unlock_cpu_hotplug();
-		kernel_text_unlock();
-	} else
-		text_poke_early((void *)imv->imv, (void *)imv->var,
-				imv->size);
-	return 0;
-}
-
 /**
  * imv_update_range - Update immediate values in a range
  * @begin: pointer to the beginning of the range
@@ -154,9 +46,12 @@ void imv_update_range(const struct __imv
 {
 	const struct __imv *iter;
 	int ret;
+
 	for (iter = begin; iter < end; iter++) {
 		mutex_lock(&imv_mutex);
-		ret = apply_imv_update(iter);
+		kernel_text_lock();
+		ret = arch_imv_update(iter, !imv_early_boot_complete);
+		kernel_text_unlock();
 		if (imv_early_boot_complete && ret)
 			printk(KERN_WARNING
 				"Invalid immediate value. "
Index: linux-2.6-lttng/include/linux/immediate.h
===================================================================
--- linux-2.6-lttng.orig/include/linux/immediate.h	2007-11-26 12:48:48.000000000 -0500
+++ linux-2.6-lttng/include/linux/immediate.h	2007-11-26 12:59:27.000000000 -0500
@@ -12,17 +12,6 @@
 
 #ifdef CONFIG_IMMEDIATE
 
-struct __imv {
-	unsigned long var;	/* Pointer to the identifier variable of the
-				 * immediate value
-				 */
-	unsigned long imv;	/*
-				 * Pointer to the memory location of the
-				 * immediate value within the instruction.
-				 */
-	unsigned char size;	/* Type size. */
-} __attribute__ ((packed));
-
 #include <asm/immediate.h>
 
 /**

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [patch 26/26] Linux Kernel Markers - Use Immediate Values
  2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
                   ` (24 preceding siblings ...)
  2008-01-24 20:27 ` [patch 25/26] Immediate Values Use Arch NMI and MCE Support Mathieu Desnoyers
@ 2008-01-24 20:27 ` Mathieu Desnoyers
  25 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:27 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel; +Cc: Mathieu Desnoyers

[-- Attachment #1: linux-kernel-markers-immediate-values.patch --]
[-- Type: text/plain, Size: 7882 bytes --]

Make markers use immediate values.

Changelog :
- Use imv_* instead of immediate_*.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
---
 Documentation/markers.txt |   17 +++++++++++++----
 include/linux/marker.h    |   42 ++++++++++++++++++++++++++++++++----------
 kernel/marker.c           |    8 ++++++--
 kernel/module.c           |    1 +
 4 files changed, 52 insertions(+), 16 deletions(-)

Index: linux-2.6-lttng.mm/include/linux/marker.h
===================================================================
--- linux-2.6-lttng.mm.orig/include/linux/marker.h	2008-01-24 14:40:50.000000000 -0500
+++ linux-2.6-lttng.mm/include/linux/marker.h	2008-01-24 14:44:30.000000000 -0500
@@ -12,6 +12,7 @@
  * See the file COPYING for more details.
  */
 
+#include <linux/immediate.h>
 #include <linux/types.h>
 
 struct module;
@@ -42,7 +43,7 @@ struct marker {
 	const char *format;	/* Marker format string, describing the
 				 * variable argument list.
 				 */
-	char state;		/* Marker state. */
+	DEFINE_IMV(char, state);/* Immediate value state. */
 	char ptype;		/* probe type : 0 : single, 1 : multi */
 	void (*call)(const struct marker *mdata,	/* Probe wrapper */
 		void *call_private, const char *fmt, ...);
@@ -53,13 +54,14 @@ struct marker {
 #ifdef CONFIG_MARKERS
 
 /*
+ * Generic marker flavor always available.
  * Note : the empty asm volatile with read constraint is used here instead of a
  * "used" attribute to fix a gcc 4.1.x bug.
  * Make sure the alignment of the structure in the __markers section will
  * not add unwanted padding between the beginning of the section and the
  * structure. Force alignment to the same alignment as the section start.
  */
-#define __trace_mark(name, call_private, format, args...)		\
+#define __trace_mark(generic, name, call_private, format, args...)	\
 	do {								\
 		static const char __mstrtab_##name[]			\
 		__attribute__((section("__markers_strings")))		\
@@ -70,17 +72,23 @@ struct marker {
 		0, 0, marker_probe_cb,					\
 		{ __mark_empty_function, NULL}, NULL };			\
 		__mark_check_format(format, ## args);			\
-		if (unlikely(__mark_##name.state)) {			\
-			(*__mark_##name.call)				\
-				(&__mark_##name, call_private,		\
-				format, ## args);			\
+		if (!generic) {						\
+			if (unlikely(imv_read(__mark_##name.state)))	\
+				(*__mark_##name.call)			\
+					(&__mark_##name, call_private,	\
+					format, ## args);		\
+		} else {						\
+			if (unlikely(_imv_read(__mark_##name.state)))	\
+				(*__mark_##name.call)			\
+					(&__mark_##name, call_private,	\
+					format, ## args);		\
 		}							\
 	} while (0)
 
 extern void marker_update_probe_range(struct marker *begin,
 	struct marker *end);
 #else /* !CONFIG_MARKERS */
-#define __trace_mark(name, call_private, format, args...) \
+#define __trace_mark(generic, name, call_private, format, args...) \
 		__mark_check_format(format, ## args)
 static inline void marker_update_probe_range(struct marker *begin,
 	struct marker *end)
@@ -88,15 +96,29 @@ static inline void marker_update_probe_r
 #endif /* CONFIG_MARKERS */
 
 /**
- * trace_mark - Marker
+ * trace_mark - Marker using code patching
  * @name: marker name, not quoted.
  * @format: format string
  * @args...: variable argument list
  *
- * Places a marker.
+ * Places a marker using optimized code patching technique (imv_read())
+ * to be enabled.
  */
 #define trace_mark(name, format, args...) \
-	__trace_mark(name, NULL, format, ## args)
+	__trace_mark(0, name, NULL, format, ## args)
+
+/**
+ * _trace_mark - Marker using variable read
+ * @name: marker name, not quoted.
+ * @format: format string
+ * @args...: variable argument list
+ *
+ * Places a marker using a standard memory read (_imv_read()) to be
+ * enabled. Should be used for markers in __init and __exit functions and in
+ * lockdep code.
+ */
+#define _trace_mark(name, format, args...) \
+	__trace_mark(1, name, NULL, format, ## args)
 
 /**
  * MARK_NOARGS - Format string for a marker with no argument.
Index: linux-2.6-lttng.mm/kernel/marker.c
===================================================================
--- linux-2.6-lttng.mm.orig/kernel/marker.c	2008-01-24 14:40:50.000000000 -0500
+++ linux-2.6-lttng.mm/kernel/marker.c	2008-01-24 14:44:30.000000000 -0500
@@ -23,6 +23,7 @@
 #include <linux/rcupdate.h>
 #include <linux/marker.h>
 #include <linux/err.h>
+#include <linux/immediate.h>
 
 extern struct marker __start___markers[];
 extern struct marker __stop___markers[];
@@ -544,7 +545,7 @@ static int set_marker(struct marker_entr
 	 */
 	smp_wmb();
 	elem->ptype = (*entry)->ptype;
-	elem->state = active;
+	elem->state__imv = active;
 
 	return 0;
 }
@@ -558,7 +559,7 @@ static int set_marker(struct marker_entr
 static void disable_marker(struct marker *elem)
 {
 	/* leave "call" as is. It is known statically. */
-	elem->state = 0;
+	elem->state__imv = 0;
 	elem->single.func = __mark_empty_function;
 	/* Update the function before setting the ptype */
 	smp_wmb();
@@ -625,6 +626,9 @@ static void marker_update_probes(void)
 	marker_update_probe_range(__start___markers, __stop___markers);
 	/* Markers in modules. */
 	module_update_markers();
+	/* Update immediate values */
+	core_imv_update();
+	module_imv_update();
 }
 
 /**
Index: linux-2.6-lttng.mm/Documentation/markers.txt
===================================================================
--- linux-2.6-lttng.mm.orig/Documentation/markers.txt	2008-01-24 14:09:00.000000000 -0500
+++ linux-2.6-lttng.mm/Documentation/markers.txt	2008-01-24 14:44:30.000000000 -0500
@@ -15,10 +15,12 @@ provide at runtime. A marker can be "on"
 (no probe is attached). When a marker is "off" it has no effect, except for
 adding a tiny time penalty (checking a condition for a branch) and space
 penalty (adding a few bytes for the function call at the end of the
-instrumented function and adds a data structure in a separate section).  When a
-marker is "on", the function you provide is called each time the marker is
-executed, in the execution context of the caller. When the function provided
-ends its execution, it returns to the caller (continuing from the marker site).
+instrumented function and adds a data structure in a separate section). The
+immediate values are used to minimize the impact on data cache, encoding the
+condition in the instruction stream. When a marker is "on", the function you
+provide is called each time the marker is executed, in the execution context of
+the caller. When the function provided ends its execution, it returns to the
+caller (continuing from the marker site).
 
 You can put markers at important locations in the code. Markers are
 lightweight hooks that can pass an arbitrary number of parameters,
@@ -69,6 +71,13 @@ a printk warning which identifies the in
 "Format mismatch for probe probe_name (format), marker (format)"
 
 
+* Optimization for a given architecture
+
+To force use of a non-optimized version of the markers, _trace_mark() should be
+used. It takes the same parameters as the normal markers, but it does not use
+the immediate values based on code patching.
+
+
 * Probe / marker example
 
 See the example provided in samples/markers/src
Index: linux-2.6-lttng.mm/kernel/module.c
===================================================================
--- linux-2.6-lttng.mm.orig/kernel/module.c	2008-01-24 14:41:09.000000000 -0500
+++ linux-2.6-lttng.mm/kernel/module.c	2008-01-24 14:44:30.000000000 -0500
@@ -2002,6 +2002,7 @@ static struct module *load_module(void _
 			mod->markers + mod->num_markers);
 #endif
 #ifdef CONFIG_IMMEDIATE
+		/* Immediate values must be updated after markers */
 		imv_update_range(mod->immediate,
 			mod->immediate + mod->num_immediate);
 #endif

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [patch 07/26] Add INIT_ARRAY() to kernel.h
  2008-01-24 20:27 ` [patch 07/26] Add INIT_ARRAY() to kernel.h Mathieu Desnoyers
@ 2008-01-24 20:39   ` Jan Engelhardt
  2008-01-24 20:54     ` [patch 07/26] Add INIT_ARRAY() to kernel.h (updated) Mathieu Desnoyers
  2008-01-24 20:58   ` [patch 07/26] Add INIT_ARRAY() to kernel.h Randy Dunlap
  2008-01-24 23:03   ` H. Peter Anvin
  2 siblings, 1 reply; 48+ messages in thread
From: Jan Engelhardt @ 2008-01-24 20:39 UTC (permalink / raw)
  To: Mathieu Desnoyers; +Cc: akpm, Ingo Molnar, linux-kernel


On Jan 24 2008 15:27, Mathieu Desnoyers wrote:
>such as:
>text_poke(addr, INIT_ARRAY(unsigned char, 0xf0, len), len);
 text_poke(addr, (unsigned char[]){[0 ... len-1] = val});

Well ugliness is debatable, but at least:

>+#define INIT_ARRAY(type, val, len) ((type [len]) { [0 ... (len)-1] = (val) })
  #define INIT_ARRAY(type, val, len) ((type[]){[0 ... (len)-1] = (val)})

You can use type[].

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [patch 07/26] Add INIT_ARRAY() to kernel.h (updated)
  2008-01-24 20:39   ` Jan Engelhardt
@ 2008-01-24 20:54     ` Mathieu Desnoyers
  2008-01-24 21:08       ` Jan Engelhardt
  0 siblings, 1 reply; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 20:54 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: akpm, Ingo Molnar, linux-kernel

Add initialization of an array, which needs brackets that would pollute kernel
code, to kernel.h. It is used to declare arguments passed as function parameters
such as:
text_poke(addr, INIT_ARRAY(unsigned char, 0xf0, len), len);

Changelog :
- [len] -> []
- Remove whitespaces.
- Fixed Jan's suggestion which was not checkpatch.pl-safe.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
CC: Jan Engelhardt <jengelh@computergmbh.de>
---
 include/linux/kernel.h |    2 ++
 1 file changed, 2 insertions(+)

Index: linux-2.6-lttng.mm/include/linux/kernel.h
===================================================================
--- linux-2.6-lttng.mm.orig/include/linux/kernel.h	2008-01-24 15:53:04.000000000 -0500
+++ linux-2.6-lttng.mm/include/linux/kernel.h	2008-01-24 15:53:25.000000000 -0500
@@ -423,4 +423,6 @@ struct sysinfo {
 #define NUMA_BUILD 0
 #endif
 
+#define INIT_ARRAY(type, val, len) ((type[]) {[0 ... (len)-1] = (val)})
+
 #endif

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [patch 07/26] Add INIT_ARRAY() to kernel.h
  2008-01-24 20:27 ` [patch 07/26] Add INIT_ARRAY() to kernel.h Mathieu Desnoyers
  2008-01-24 20:39   ` Jan Engelhardt
@ 2008-01-24 20:58   ` Randy Dunlap
  2008-01-24 21:04     ` Mathieu Desnoyers
  2008-01-24 23:03   ` H. Peter Anvin
  2 siblings, 1 reply; 48+ messages in thread
From: Randy Dunlap @ 2008-01-24 20:58 UTC (permalink / raw)
  To: Mathieu Desnoyers; +Cc: akpm, Ingo Molnar, linux-kernel

On Thu, 24 Jan 2008 15:27:13 -0500 Mathieu Desnoyers wrote:

> Add initialization of an array, which needs brackets that would pollute kernel
> code, to kernel.h. It is used to declare arguments passed as function parameters

Hi Mathieu,

Maybe you have explained this previously, but please give a short
explanation of "brackets that would pollute kernel code".

Thanks.

> such as:
> text_poke(addr, INIT_ARRAY(unsigned char, 0xf0, len), len);
> 
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
> ---
>  include/linux/kernel.h |    2 ++
>  1 file changed, 2 insertions(+)
> 
> Index: linux-2.6-lttng.mm/include/linux/kernel.h
> ===================================================================
> --- linux-2.6-lttng.mm.orig/include/linux/kernel.h	2008-01-24 14:10:54.000000000 -0500
> +++ linux-2.6-lttng.mm/include/linux/kernel.h	2008-01-24 14:23:06.000000000 -0500
> @@ -423,4 +423,6 @@ struct sysinfo {
>  #define NUMA_BUILD 0
>  #endif
>  
> +#define INIT_ARRAY(type, val, len) ((type [len]) { [0 ... (len)-1] = (val) })
> +
>  #endif

---
~Randy

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [patch 03/26] Move Kconfig.instrumentation to arch/Kconfig and init/Kconfig
  2008-01-24 20:27 ` [patch 03/26] Move Kconfig.instrumentation to arch/Kconfig and init/Kconfig Mathieu Desnoyers
@ 2008-01-24 21:00   ` Randy Dunlap
  2008-01-24 21:05     ` Mathieu Desnoyers
  2008-01-24 22:03   ` Mathieu Desnoyers
  2008-01-24 23:05   ` Haavard Skinnemoen
  2 siblings, 1 reply; 48+ messages in thread
From: Randy Dunlap @ 2008-01-24 21:00 UTC (permalink / raw)
  To: Mathieu Desnoyers
  Cc: akpm, Ingo Molnar, linux-kernel, Linus Torvalds, Sam Ravnborg

On Thu, 24 Jan 2008 15:27:09 -0500 Mathieu Desnoyers wrote:

> Move the instrumentation Kconfig to
> 
> arch/Kconfig for architecture dependent options
>   - oprofile
>   - kprobes
> 
> and
> 
> init/Kconfig for architecture independent options
>   - profiling
>   - markers
> 
> Remove the "Instrumentation Support" menu. Everything moves to "General setup".

Was this done based on a suggestion from someone (Linus)?
I prefer an Instrumentation menu, but whatever...


> Delete the kernel/Kconfig.instrumentation file.
> 
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
> CC: Linus Torvalds <torvalds@linux-foundation.org>
> CC: Sam Ravnborg <sam@ravnborg.org>
> ---
>  arch/Kconfig                   |   28 ++++++++++++++++++++
>  arch/alpha/Kconfig             |    2 -
>  arch/arm/Kconfig               |    2 -
>  arch/blackfin/Kconfig          |    2 -
>  arch/cris/Kconfig              |    2 -
>  arch/frv/Kconfig               |    2 -
>  arch/h8300/Kconfig             |    2 -
>  arch/ia64/Kconfig              |    2 -
>  arch/m32r/Kconfig              |    2 -
>  arch/m68k/Kconfig              |    2 -
>  arch/m68knommu/Kconfig         |    2 -
>  arch/mips/Kconfig              |    2 -
>  arch/parisc/Kconfig            |    2 -
>  arch/powerpc/Kconfig           |    2 -
>  arch/ppc/Kconfig               |    2 -
>  arch/s390/Kconfig              |    2 -
>  arch/sh/Kconfig                |    2 -
>  arch/sh64/Kconfig              |    2 -
>  arch/sparc/Kconfig             |    2 -
>  arch/sparc64/Kconfig           |    2 -
>  arch/um/Kconfig                |    2 -
>  arch/v850/Kconfig              |    2 -
>  arch/x86/Kconfig               |    2 -
>  arch/xtensa/Kconfig            |    2 -
>  init/Kconfig                   |   12 ++++++++
>  kernel/Kconfig.instrumentation |   55 -----------------------------------------
>  26 files changed, 40 insertions(+), 101 deletions(-)

---
~Randy

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [patch 07/26] Add INIT_ARRAY() to kernel.h
  2008-01-24 20:58   ` [patch 07/26] Add INIT_ARRAY() to kernel.h Randy Dunlap
@ 2008-01-24 21:04     ` Mathieu Desnoyers
  2008-01-24 22:02       ` Stefan Richter
                         ` (2 more replies)
  0 siblings, 3 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 21:04 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: akpm, Ingo Molnar, linux-kernel

* Randy Dunlap (randy.dunlap@oracle.com) wrote:
> On Thu, 24 Jan 2008 15:27:13 -0500 Mathieu Desnoyers wrote:
> 
> > Add initialization of an array, which needs brackets that would pollute kernel
> > code, to kernel.h. It is used to declare arguments passed as function parameters
> 
> Hi Mathieu,
> 
> Maybe you have explained this previously, but please give a short
> explanation of "brackets that would pollute kernel code".
> 
> Thanks.
> 

Try opening such code in vim, and the syntax highlighting gets all
messed up :-/

The other option is to do the *right thing* and fix vim, of course, but
this change won't be in distros for a while.

Mathieu

> > such as:
> > text_poke(addr, INIT_ARRAY(unsigned char, 0xf0, len), len);
> > 
> > Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
> > ---
> >  include/linux/kernel.h |    2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > Index: linux-2.6-lttng.mm/include/linux/kernel.h
> > ===================================================================
> > --- linux-2.6-lttng.mm.orig/include/linux/kernel.h	2008-01-24 14:10:54.000000000 -0500
> > +++ linux-2.6-lttng.mm/include/linux/kernel.h	2008-01-24 14:23:06.000000000 -0500
> > @@ -423,4 +423,6 @@ struct sysinfo {
> >  #define NUMA_BUILD 0
> >  #endif
> >  
> > +#define INIT_ARRAY(type, val, len) ((type [len]) { [0 ... (len)-1] = (val) })
> > +
> >  #endif
> 
> ---
> ~Randy

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [patch 03/26] Move Kconfig.instrumentation to arch/Kconfig and init/Kconfig
  2008-01-24 21:00   ` Randy Dunlap
@ 2008-01-24 21:05     ` Mathieu Desnoyers
  0 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 21:05 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: akpm, Ingo Molnar, linux-kernel, Linus Torvalds, Sam Ravnborg

* Randy Dunlap (randy.dunlap@oracle.com) wrote:
> On Thu, 24 Jan 2008 15:27:09 -0500 Mathieu Desnoyers wrote:
> 
> > Move the instrumentation Kconfig to
> > 
> > arch/Kconfig for architecture dependent options
> >   - oprofile
> >   - kprobes
> > 
> > and
> > 
> > init/Kconfig for architecture independent options
> >   - profiling
> >   - markers
> > 
> > Remove the "Instrumentation Support" menu. Everything moves to "General setup".
> 
> Was this done based on a suggestion from someone (Linus)?
> I prefer an Instrumentation menu, but whatever...
> 

Yes, it was Linus'suggestion. I prefer the instrumentation menu too, but
in order to be consistent, we would have to create an instrumentation/
directory in the kernel tree.

Mathieu

> 
> > Delete the kernel/Kconfig.instrumentation file.
> > 
> > Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
> > CC: Linus Torvalds <torvalds@linux-foundation.org>
> > CC: Sam Ravnborg <sam@ravnborg.org>
> > ---
> >  arch/Kconfig                   |   28 ++++++++++++++++++++
> >  arch/alpha/Kconfig             |    2 -
> >  arch/arm/Kconfig               |    2 -
> >  arch/blackfin/Kconfig          |    2 -
> >  arch/cris/Kconfig              |    2 -
> >  arch/frv/Kconfig               |    2 -
> >  arch/h8300/Kconfig             |    2 -
> >  arch/ia64/Kconfig              |    2 -
> >  arch/m32r/Kconfig              |    2 -
> >  arch/m68k/Kconfig              |    2 -
> >  arch/m68knommu/Kconfig         |    2 -
> >  arch/mips/Kconfig              |    2 -
> >  arch/parisc/Kconfig            |    2 -
> >  arch/powerpc/Kconfig           |    2 -
> >  arch/ppc/Kconfig               |    2 -
> >  arch/s390/Kconfig              |    2 -
> >  arch/sh/Kconfig                |    2 -
> >  arch/sh64/Kconfig              |    2 -
> >  arch/sparc/Kconfig             |    2 -
> >  arch/sparc64/Kconfig           |    2 -
> >  arch/um/Kconfig                |    2 -
> >  arch/v850/Kconfig              |    2 -
> >  arch/x86/Kconfig               |    2 -
> >  arch/xtensa/Kconfig            |    2 -
> >  init/Kconfig                   |   12 ++++++++
> >  kernel/Kconfig.instrumentation |   55 -----------------------------------------
> >  26 files changed, 40 insertions(+), 101 deletions(-)
> 
> ---
> ~Randy

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [patch 07/26] Add INIT_ARRAY() to kernel.h (updated)
  2008-01-24 20:54     ` [patch 07/26] Add INIT_ARRAY() to kernel.h (updated) Mathieu Desnoyers
@ 2008-01-24 21:08       ` Jan Engelhardt
  2008-01-24 21:18         ` Mathieu Desnoyers
  0 siblings, 1 reply; 48+ messages in thread
From: Jan Engelhardt @ 2008-01-24 21:08 UTC (permalink / raw)
  To: Mathieu Desnoyers; +Cc: akpm, Ingo Molnar, linux-kernel


On Jan 24 2008 15:54, Mathieu Desnoyers wrote:
>
>Add initialization of an array, which needs brackets that would pollute kernel
>code, to kernel.h. It is used to declare arguments passed as function parameters
>such as:
>text_poke(addr, INIT_ARRAY(unsigned char, 0xf0, len), len);
>
>Changelog :
>- [len] -> []
>- Remove whitespaces.
>- Fixed Jan's suggestion which was not checkpatch.pl-safe.

diff -dpru /dev/null <(echo '  #define INIT_ARRAY(type, val, len) ((type[]){[0 ... (len)-1] = (val)}) ') | scripts/checkpatch.pl -
ERROR: Missing Signed-off-by: line(s)
total: 1 errors, 0 warnings, 2 lines checked

Where did checkpatch play unfair again on your side? :)


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [patch 02/26] Fix ARM to play nicely with generic Instrumentation menu
  2008-01-24 20:27 ` [patch 02/26] Fix ARM to play nicely with generic Instrumentation menu Mathieu Desnoyers
@ 2008-01-24 21:13   ` Russell King
  2008-01-24 21:23     ` Mathieu Desnoyers
  0 siblings, 1 reply; 48+ messages in thread
From: Russell King @ 2008-01-24 21:13 UTC (permalink / raw)
  To: Mathieu Desnoyers
  Cc: akpm, Ingo Molnar, linux-kernel, Linus Torvalds, ananth, dhowells,
	jdike, sam, Adrian Bunk, Randy Dunlap, phil.el, oprofile-list

On Thu, Jan 24, 2008 at 03:27:08PM -0500, Mathieu Desnoyers wrote:
> The conflicting commit for 
> move-kconfiginstrumentation-to-arch-kconfig-and-init-kconfig.patch
> is the ARM fix from Linus :
> 
> commit 38ad9aebe70dc72df08851bbd1620d89329129ba

Since we have changes which depend on the location of these options,
please hold off until the ARM tree merges in the next window:

----------------------- arch/arm/Kconfig.instrumentation -----------------------
index 63b8c6d..453ad8e 100644
@@ -43,6 +43,16 @@ config OPROFILE_MPCORE
 config OPROFILE_ARM11_CORE
 	bool
 
+config KPROBES
+	bool "Kprobes"
+	depends on KALLSYMS && MODULES && !UML && !XIP_KERNEL
+	help
+	  Kprobes allows you to trap at almost any kernel address and
+	  execute a callback function.  register_kprobe() establishes
+	  a probepoint and specifies the callback.  Kprobes is useful
+	  for kernel debugging, non-intrusive instrumentation and testing.
+	  If in doubt, say "N".
+
 config MARKERS
 	bool "Activate markers"
 	help


-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [patch 07/26] Add INIT_ARRAY() to kernel.h (updated)
  2008-01-24 21:08       ` Jan Engelhardt
@ 2008-01-24 21:18         ` Mathieu Desnoyers
  0 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 21:18 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: akpm, Ingo Molnar, linux-kernel

* Jan Engelhardt (jengelh@computergmbh.de) wrote:
> 
> On Jan 24 2008 15:54, Mathieu Desnoyers wrote:
> >
> >Add initialization of an array, which needs brackets that would pollute kernel
> >code, to kernel.h. It is used to declare arguments passed as function parameters
> >such as:
> >text_poke(addr, INIT_ARRAY(unsigned char, 0xf0, len), len);
> >
> >Changelog :
> >- [len] -> []
> >- Remove whitespaces.
> >- Fixed Jan's suggestion which was not checkpatch.pl-safe.
> 
> diff -dpru /dev/null <(echo '  #define INIT_ARRAY(type, val, len) ((type[]){[0 ... (len)-1] = (val)}) ') | scripts/checkpatch.pl -
> ERROR: Missing Signed-off-by: line(s)
> total: 1 errors, 0 warnings, 2 lines checked
> 
> Where did checkpatch play unfair again on your side? :)
> 

Hrm, I don't know why checkpatch does not notice the problem when
invoked with your command, but creating a patch with your change results
in :

compudj@dijkstra:~/git/morestable/linux-2.6-lttng.mm$ scripts/checkpatch.pl patches/test.patch 
ERROR: need a space before the open brace '{'
#27: FILE: include/linux/kernel.h:426:
+#define INIT_ARRAY(type, val, len) ((type[]){[0 ... (len)-1] = (val)})

total: 1 errors, 0 warnings, 6 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

but I guess we are deep down in nitpicking land ;)

Cheers,

Mathieu

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [patch 02/26] Fix ARM to play nicely with generic Instrumentation menu
  2008-01-24 21:13   ` Russell King
@ 2008-01-24 21:23     ` Mathieu Desnoyers
  2008-01-24 22:17       ` Russell King
  0 siblings, 1 reply; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 21:23 UTC (permalink / raw)
  To: Russell King
  Cc: akpm, Ingo Molnar, linux-kernel, Linus Torvalds, ananth, dhowells,
	jdike, sam, Adrian Bunk, Randy Dunlap, phil.el, oprofile-list

* Russell King (rmk+lkml@arm.linux.org.uk) wrote:
> On Thu, Jan 24, 2008 at 03:27:08PM -0500, Mathieu Desnoyers wrote:
> > The conflicting commit for 
> > move-kconfiginstrumentation-to-arch-kconfig-and-init-kconfig.patch
> > is the ARM fix from Linus :
> > 
> > commit 38ad9aebe70dc72df08851bbd1620d89329129ba
> 
> Since we have changes which depend on the location of these options,
> please hold off until the ARM tree merges in the next window:
> 

Can you add me to the CC list of this patch please ?

> ----------------------- arch/arm/Kconfig.instrumentation -----------------------
> index 63b8c6d..453ad8e 100644
> @@ -43,6 +43,16 @@ config OPROFILE_MPCORE
>  config OPROFILE_ARM11_CORE
>  	bool
>  
> +config KPROBES
> +	bool "Kprobes"
> +	depends on KALLSYMS && MODULES && !UML && !XIP_KERNEL
> +	help
> +	  Kprobes allows you to trap at almost any kernel address and
> +	  execute a callback function.  register_kprobe() establishes
> +	  a probepoint and specifies the callback.  Kprobes is useful
> +	  for kernel debugging, non-intrusive instrumentation and testing.
> +	  If in doubt, say "N".
> +
>  config MARKERS
>  	bool "Activate markers"
>  	help
> 
> 
> -- 
> Russell King
>  Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
>  maintainer of:

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [patch 07/26] Add INIT_ARRAY() to kernel.h
  2008-01-24 21:04     ` Mathieu Desnoyers
@ 2008-01-24 22:02       ` Stefan Richter
  2008-01-24 22:10         ` [patch 07/26] Add INIT_ARRAY() to kernel.h (update 2) Mathieu Desnoyers
  2008-01-24 23:04       ` [patch 07/26] Add INIT_ARRAY() to kernel.h H. Peter Anvin
  2008-01-25  8:03       ` Jan Engelhardt
  2 siblings, 1 reply; 48+ messages in thread
From: Stefan Richter @ 2008-01-24 22:02 UTC (permalink / raw)
  To: Mathieu Desnoyers; +Cc: Randy Dunlap, akpm, Ingo Molnar, linux-kernel

On 24 Jan, Mathieu Desnoyers wrote:
> * Randy Dunlap (randy.dunlap@oracle.com) wrote:
>> Maybe you have explained this previously, but please give a short
>> explanation of "brackets that would pollute kernel code".
>> 
>> Thanks.
>> 
> 
> Try opening such code in vim, and the syntax highlighting gets all
> messed up :-/
> 
> The other option is to do the *right thing* and fix vim, of course, but
> this change won't be in distros for a while.

Is it about unbalanced brackets?

Anyway, if you add it because other kinds of initializers (which ones?)
aren't displayed nicely in syntax highlighting editors, just say so in
the changelog.  Your log isn't informative at all.
-- 
Stefan Richter
-=====-==--- ---= ==---
http://arcgraph.de/sr/


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [patch 03/26] Move Kconfig.instrumentation to arch/Kconfig and init/Kconfig
  2008-01-24 20:27 ` [patch 03/26] Move Kconfig.instrumentation to arch/Kconfig and init/Kconfig Mathieu Desnoyers
  2008-01-24 21:00   ` Randy Dunlap
@ 2008-01-24 22:03   ` Mathieu Desnoyers
  2008-01-24 23:05   ` Haavard Skinnemoen
  2 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 22:03 UTC (permalink / raw)
  To: akpm, Ingo Molnar, linux-kernel; +Cc: Linus Torvalds, Sam Ravnborg

* Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca) wrote:
> Move the instrumentation Kconfig to
> 
> arch/Kconfig for architecture dependent options
>   - oprofile
>   - kprobes
> 
> and
> 
> init/Kconfig for architecture independent options
>   - profiling
>   - markers
> 
> Remove the "Instrumentation Support" menu. Everything moves to "General setup".
> Delete the kernel/Kconfig.instrumentation file.
> 

Please wait for updated version. Waiting for the next ARM merge adding
kprobes to ARM, which will likely break this.

> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
> CC: Linus Torvalds <torvalds@linux-foundation.org>
> CC: Sam Ravnborg <sam@ravnborg.org>
> ---
>  arch/Kconfig                   |   28 ++++++++++++++++++++
>  arch/alpha/Kconfig             |    2 -
>  arch/arm/Kconfig               |    2 -
>  arch/blackfin/Kconfig          |    2 -
>  arch/cris/Kconfig              |    2 -
>  arch/frv/Kconfig               |    2 -
>  arch/h8300/Kconfig             |    2 -
>  arch/ia64/Kconfig              |    2 -
>  arch/m32r/Kconfig              |    2 -
>  arch/m68k/Kconfig              |    2 -
>  arch/m68knommu/Kconfig         |    2 -
>  arch/mips/Kconfig              |    2 -
>  arch/parisc/Kconfig            |    2 -
>  arch/powerpc/Kconfig           |    2 -
>  arch/ppc/Kconfig               |    2 -
>  arch/s390/Kconfig              |    2 -
>  arch/sh/Kconfig                |    2 -
>  arch/sh64/Kconfig              |    2 -
>  arch/sparc/Kconfig             |    2 -
>  arch/sparc64/Kconfig           |    2 -
>  arch/um/Kconfig                |    2 -
>  arch/v850/Kconfig              |    2 -
>  arch/x86/Kconfig               |    2 -
>  arch/xtensa/Kconfig            |    2 -
>  init/Kconfig                   |   12 ++++++++
>  kernel/Kconfig.instrumentation |   55 -----------------------------------------
>  26 files changed, 40 insertions(+), 101 deletions(-)
> 
> Index: linux-2.6-lttng.mm/arch/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/Kconfig	2008-01-24 14:10:37.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/Kconfig	2008-01-24 14:20:06.000000000 -0500
> @@ -1,3 +1,31 @@
>  #
>  # General architecture dependent options
>  #
> +
> +config OPROFILE
> +	tristate "OProfile system profiling (EXPERIMENTAL)"
> +	depends on PROFILING
> +	depends on HAVE_OPROFILE
> +	help
> +	  OProfile is a profiling system capable of profiling the
> +	  whole system, include the kernel, kernel modules, libraries,
> +	  and applications.
> +
> +	  If unsure, say N.
> +
> +config HAVE_OPROFILE
> +	def_bool n
> +
> +config KPROBES
> +	bool "Kprobes"
> +	depends on KALLSYMS && MODULES
> +	depends on HAVE_KPROBES
> +	help
> +	  Kprobes allows you to trap at almost any kernel address and
> +	  execute a callback function.  register_kprobe() establishes
> +	  a probepoint and specifies the callback.  Kprobes is useful
> +	  for kernel debugging, non-intrusive instrumentation and testing.
> +	  If in doubt, say "N".
> +
> +config HAVE_KPROBES
> +	def_bool n
> Index: linux-2.6-lttng.mm/init/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/init/Kconfig	2008-01-24 14:10:55.000000000 -0500
> +++ linux-2.6-lttng.mm/init/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -702,6 +702,18 @@ config PROC_PAGE_MONITOR
>  	  /proc/kpagecount, and /proc/kpageflags. Disabling these
>            interfaces will reduce the size of the kernel by approximately 4kb.
>  
> +config PROFILING
> +	bool "Profiling support (EXPERIMENTAL)"
> +	help
> +	  Say Y here to enable the extended profiling support mechanisms used
> +	  by profilers such as OProfile.
> +
> +config MARKERS
> +	bool "Activate markers"
> +	help
> +	  Place an empty function call at each marker site. Can be
> +	  dynamically changed for a probe function.
> +
>  source "arch/Kconfig"
>  
>  endmenu		# General setup
> Index: linux-2.6-lttng.mm/arch/alpha/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/alpha/Kconfig	2008-01-24 14:10:37.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/alpha/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -653,8 +653,6 @@ source "drivers/Kconfig"
>  
>  source "fs/Kconfig"
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/alpha/Kconfig.debug"
>  
>  # DUMMY_CONSOLE may be defined in drivers/video/console/Kconfig
> Index: linux-2.6-lttng.mm/arch/arm/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/arm/Kconfig	2008-01-24 14:18:00.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/arm/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -1149,8 +1149,6 @@ endmenu
>  
>  source "fs/Kconfig"
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/arm/Kconfig.debug"
>  
>  source "security/Kconfig"
> Index: linux-2.6-lttng.mm/arch/blackfin/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/blackfin/Kconfig	2008-01-24 14:10:39.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/blackfin/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -1003,8 +1003,6 @@ source "drivers/Kconfig"
>  
>  source "fs/Kconfig"
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/blackfin/Kconfig.debug"
>  
>  source "security/Kconfig"
> Index: linux-2.6-lttng.mm/arch/cris/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/cris/Kconfig	2008-01-24 14:10:39.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/cris/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -214,8 +214,6 @@ source "drivers/pci/Kconfig"
>  
>  source "drivers/usb/Kconfig"
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/cris/Kconfig.debug"
>  
>  source "security/Kconfig"
> Index: linux-2.6-lttng.mm/arch/frv/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/frv/Kconfig	2008-01-24 14:10:39.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/frv/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -384,8 +384,6 @@ source "drivers/Kconfig"
>  
>  source "fs/Kconfig"
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/frv/Kconfig.debug"
>  
>  source "security/Kconfig"
> Index: linux-2.6-lttng.mm/arch/h8300/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/h8300/Kconfig	2008-01-24 14:10:39.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/h8300/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -226,8 +226,6 @@ endmenu
>  
>  source "fs/Kconfig"
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/h8300/Kconfig.debug"
>  
>  source "security/Kconfig"
> Index: linux-2.6-lttng.mm/arch/ia64/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/ia64/Kconfig	2008-01-24 14:10:39.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/ia64/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -602,8 +602,6 @@ config IRQ_PER_CPU
>  
>  source "arch/ia64/hp/sim/Kconfig"
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/ia64/Kconfig.debug"
>  
>  source "security/Kconfig"
> Index: linux-2.6-lttng.mm/arch/m32r/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/m32r/Kconfig	2008-01-24 14:10:39.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/m32r/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -430,8 +430,6 @@ source "drivers/Kconfig"
>  
>  source "fs/Kconfig"
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/m32r/Kconfig.debug"
>  
>  source "security/Kconfig"
> Index: linux-2.6-lttng.mm/arch/m68k/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/m68k/Kconfig	2008-01-24 14:10:39.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/m68k/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -667,8 +667,6 @@ endmenu
>  
>  source "fs/Kconfig"
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/m68k/Kconfig.debug"
>  
>  source "security/Kconfig"
> Index: linux-2.6-lttng.mm/arch/m68knommu/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/m68knommu/Kconfig	2008-01-24 14:10:39.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/m68knommu/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -710,8 +710,6 @@ source "drivers/Kconfig"
>  
>  source "fs/Kconfig"
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/m68knommu/Kconfig.debug"
>  
>  source "security/Kconfig"
> Index: linux-2.6-lttng.mm/arch/mips/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/mips/Kconfig	2008-01-24 14:10:39.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/mips/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -2096,8 +2096,6 @@ source "drivers/Kconfig"
>  
>  source "fs/Kconfig"
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/mips/Kconfig.debug"
>  
>  source "security/Kconfig"
> Index: linux-2.6-lttng.mm/arch/parisc/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/parisc/Kconfig	2008-01-24 14:10:40.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/parisc/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -276,8 +276,6 @@ source "drivers/Kconfig"
>  
>  source "fs/Kconfig"
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/parisc/Kconfig.debug"
>  
>  source "security/Kconfig"
> Index: linux-2.6-lttng.mm/arch/powerpc/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/powerpc/Kconfig	2008-01-24 14:10:40.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/powerpc/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -713,8 +713,6 @@ source "arch/powerpc/sysdev/qe_lib/Kconf
>  
>  source "lib/Kconfig"
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/powerpc/Kconfig.debug"
>  
>  source "security/Kconfig"
> Index: linux-2.6-lttng.mm/arch/ppc/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/ppc/Kconfig	2008-01-24 14:10:41.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/ppc/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -1319,8 +1319,6 @@ endmenu
>  
>  source "lib/Kconfig"
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/ppc/Kconfig.debug"
>  
>  source "security/Kconfig"
> Index: linux-2.6-lttng.mm/arch/s390/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/s390/Kconfig	2008-01-24 14:10:41.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/s390/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -528,8 +528,6 @@ source "drivers/Kconfig"
>  
>  source "fs/Kconfig"
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/s390/Kconfig.debug"
>  
>  source "security/Kconfig"
> Index: linux-2.6-lttng.mm/arch/sh/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/sh/Kconfig	2008-01-24 14:10:41.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/sh/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -899,8 +899,6 @@ source "drivers/Kconfig"
>  
>  source "fs/Kconfig"
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/sh/Kconfig.debug"
>  
>  source "security/Kconfig"
> Index: linux-2.6-lttng.mm/arch/sh64/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/sh64/Kconfig	2008-01-24 14:10:41.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/sh64/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -279,8 +279,6 @@ source "drivers/Kconfig"
>  
>  source "fs/Kconfig"
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/sh64/Kconfig.debug"
>  
>  source "security/Kconfig"
> Index: linux-2.6-lttng.mm/arch/sparc/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/sparc/Kconfig	2008-01-24 14:10:41.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/sparc/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -324,8 +324,6 @@ endmenu
>  
>  source "fs/Kconfig"
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/sparc/Kconfig.debug"
>  
>  source "security/Kconfig"
> Index: linux-2.6-lttng.mm/arch/sparc64/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/sparc64/Kconfig	2008-01-24 14:10:41.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/sparc64/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -470,8 +470,6 @@ source "drivers/sbus/char/Kconfig"
>  
>  source "fs/Kconfig"
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/sparc64/Kconfig.debug"
>  
>  source "security/Kconfig"
> Index: linux-2.6-lttng.mm/arch/um/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/um/Kconfig	2008-01-24 14:10:42.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/um/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -271,6 +271,4 @@ config INPUT
>  	bool
>  	default n
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/um/Kconfig.debug"
> Index: linux-2.6-lttng.mm/arch/v850/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/v850/Kconfig	2008-01-24 14:10:42.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/v850/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -334,8 +334,6 @@ source "sound/Kconfig"
>  
>  source "drivers/usb/Kconfig"
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/v850/Kconfig.debug"
>  
>  source "security/Kconfig"
> Index: linux-2.6-lttng.mm/arch/xtensa/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/xtensa/Kconfig	2008-01-24 14:10:42.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/xtensa/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -246,8 +246,6 @@ config EMBEDDED_RAMDISK_IMAGE
>  	  provide one yourself.
>  endmenu
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/xtensa/Kconfig.debug"
>  
>  source "security/Kconfig"
> Index: linux-2.6-lttng.mm/arch/x86/Kconfig
> ===================================================================
> --- linux-2.6-lttng.mm.orig/arch/x86/Kconfig	2008-01-24 14:10:42.000000000 -0500
> +++ linux-2.6-lttng.mm/arch/x86/Kconfig	2008-01-24 14:18:34.000000000 -0500
> @@ -1609,8 +1609,6 @@ source "drivers/firmware/Kconfig"
>  
>  source "fs/Kconfig"
>  
> -source "kernel/Kconfig.instrumentation"
> -
>  source "arch/x86/Kconfig.debug"
>  
>  source "security/Kconfig"
> Index: linux-2.6-lttng.mm/kernel/Kconfig.instrumentation
> ===================================================================
> --- linux-2.6-lttng.mm.orig/kernel/Kconfig.instrumentation	2008-01-24 14:10:55.000000000 -0500
> +++ /dev/null	1970-01-01 00:00:00.000000000 +0000
> @@ -1,55 +0,0 @@
> -menuconfig INSTRUMENTATION
> -	bool "Instrumentation Support"
> -	default y
> -	---help---
> -	  Say Y here to get to see options related to performance measurement,
> -	  system-wide debugging, and testing. This option alone does not add any
> -	  kernel code.
> -
> -	  If you say N, all options in this submenu will be skipped and
> -	  disabled. If you're trying to debug the kernel itself, go see the
> -	  Kernel Hacking menu.
> -
> -if INSTRUMENTATION
> -
> -config PROFILING
> -	bool "Profiling support (EXPERIMENTAL)"
> -	help
> -	  Say Y here to enable the extended profiling support mechanisms used
> -	  by profilers such as OProfile.
> -
> -config OPROFILE
> -	tristate "OProfile system profiling (EXPERIMENTAL)"
> -	depends on PROFILING
> -	depends on HAVE_OPROFILE
> -	help
> -	  OProfile is a profiling system capable of profiling the
> -	  whole system, include the kernel, kernel modules, libraries,
> -	  and applications.
> -
> -	  If unsure, say N.
> -
> -config HAVE_OPROFILE
> -	def_bool n
> -
> -config KPROBES
> -	bool "Kprobes"
> -	depends on KALLSYMS && MODULES
> -	depends on HAVE_KPROBES
> -	help
> -	  Kprobes allows you to trap at almost any kernel address and
> -	  execute a callback function.  register_kprobe() establishes
> -	  a probepoint and specifies the callback.  Kprobes is useful
> -	  for kernel debugging, non-intrusive instrumentation and testing.
> -	  If in doubt, say "N".
> -
> -config HAVE_KPROBES
> -	def_bool n
> -
> -config MARKERS
> -	bool "Activate markers"
> -	help
> -	  Place an empty function call at each marker site. Can be
> -	  dynamically changed for a probe function.
> -
> -endif # INSTRUMENTATION
> 
> -- 
> Mathieu Desnoyers
> Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
> OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [patch 07/26] Add INIT_ARRAY() to kernel.h (update 2)
  2008-01-24 22:02       ` Stefan Richter
@ 2008-01-24 22:10         ` Mathieu Desnoyers
  2008-01-24 22:50           ` Alexey Dobriyan
  0 siblings, 1 reply; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-24 22:10 UTC (permalink / raw)
  To: Stefan Richter; +Cc: Randy Dunlap, akpm, Ingo Molnar, linux-kernel

Array initializers in the body of a function causes unbalanced brackets which
syntax highlighting editors such as vim have problems with. Fix this by creating
the INIT_ARRAY() macro.

It is used to declare arguments passed as function parameters such as:
text_poke(addr, INIT_ARRAY(unsigned char, 0xf0, len), len);

Changelog :
- [len] -> []
- Remove whitespaces.
- Fixed Jan's suggestion which was not checkpatch.pl-safe.
- More informative patch header.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
CC: Jan Engelhardt <jengelh@computergmbh.de>
CC: Stefan Richter <stefanr@s5r6.in-berlin.de>
---
 include/linux/kernel.h |    2 ++
 1 file changed, 2 insertions(+)

Index: linux-2.6-lttng.mm/include/linux/kernel.h
===================================================================
--- linux-2.6-lttng.mm.orig/include/linux/kernel.h	2008-01-24 15:53:04.000000000 -0500
+++ linux-2.6-lttng.mm/include/linux/kernel.h	2008-01-24 15:53:25.000000000 -0500
@@ -423,4 +423,6 @@ struct sysinfo {
 #define NUMA_BUILD 0
 #endif
 
+#define INIT_ARRAY(type, val, len) ((type[]) {[0 ... (len)-1] = (val)})
+
 #endif

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [patch 02/26] Fix ARM to play nicely with generic Instrumentation menu
  2008-01-24 21:23     ` Mathieu Desnoyers
@ 2008-01-24 22:17       ` Russell King
  0 siblings, 0 replies; 48+ messages in thread
From: Russell King @ 2008-01-24 22:17 UTC (permalink / raw)
  To: Mathieu Desnoyers
  Cc: akpm, Ingo Molnar, linux-kernel, Linus Torvalds, ananth, dhowells,
	jdike, sam, Adrian Bunk, Randy Dunlap, phil.el, oprofile-list

On Thu, Jan 24, 2008 at 04:23:43PM -0500, Mathieu Desnoyers wrote:
> * Russell King (rmk+lkml@arm.linux.org.uk) wrote:
> > On Thu, Jan 24, 2008 at 03:27:08PM -0500, Mathieu Desnoyers wrote:
> > > The conflicting commit for 
> > > move-kconfiginstrumentation-to-arch-kconfig-and-init-kconfig.patch
> > > is the ARM fix from Linus :
> > > 
> > > commit 38ad9aebe70dc72df08851bbd1620d89329129ba
> > 
> > Since we have changes which depend on the location of these options,
> > please hold off until the ARM tree merges in the next window:
> > 
> 
> Can you add me to the CC list of this patch please ?

Not really because it's merged, and any discussion happened a few months
back (though it was updated when Linus fixed your broken changes.)

You can read the patch set at 2007-12-17, via:

http://lists.arm.linux.org.uk/lurker/search/20380101.000000.00000000@ml:linux-arm-kernel,kprobes.en.html

-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [patch 01/26] Linux Kernel Markers Support for Proprierary Modules
  2008-01-24 20:27 ` [patch 01/26] Linux Kernel Markers Support for Proprierary Modules Mathieu Desnoyers
@ 2008-01-24 22:19   ` Jon Masters
  0 siblings, 0 replies; 48+ messages in thread
From: Jon Masters @ 2008-01-24 22:19 UTC (permalink / raw)
  To: Mathieu Desnoyers
  Cc: akpm, Ingo Molnar, linux-kernel, Frank Ch. Eigler, Rusty Russell,
	Christoph Hellwig, Linus Torvalds


On Thu, 2008-01-24 at 15:27 -0500, Mathieu Desnoyers wrote:

> There seems to be good arguments for markers to support proprierary modules. So
> I am throwing this one-liner in and let's see how people react. It only makes
> sure that a module that has been "forced" to be loaded won't have its markers
> used. It is important to leave this check to make sure the kernel does not crash
> by expecting the markers part of the struct module by mistake in the case there
> is an incorrect checksum.

Acked-by: Jon Masters <jcm@jonmasters.org>



^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [patch 07/26] Add INIT_ARRAY() to kernel.h (update 2)
  2008-01-24 22:10         ` [patch 07/26] Add INIT_ARRAY() to kernel.h (update 2) Mathieu Desnoyers
@ 2008-01-24 22:50           ` Alexey Dobriyan
  0 siblings, 0 replies; 48+ messages in thread
From: Alexey Dobriyan @ 2008-01-24 22:50 UTC (permalink / raw)
  To: Mathieu Desnoyers
  Cc: Stefan Richter, Randy Dunlap, akpm, Ingo Molnar, linux-kernel

On Thu, Jan 24, 2008 at 05:10:54PM -0500, Mathieu Desnoyers wrote:
> Array initializers in the body of a function causes unbalanced brackets which
> syntax highlighting editors such as vim have problems with. Fix this by creating
> the INIT_ARRAY() macro.
> 
> It is used to declare arguments passed as function parameters such as:
> text_poke(addr, INIT_ARRAY(unsigned char, 0xf0, len), len);

> +#define INIT_ARRAY(type, val, len) ((type[]) {[0 ... (len)-1] = (val)})

While we are at useless macro territory, let's name it MAKE_ARRAY because
it's exactly what it does.

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [patch 07/26] Add INIT_ARRAY() to kernel.h
  2008-01-24 20:27 ` [patch 07/26] Add INIT_ARRAY() to kernel.h Mathieu Desnoyers
  2008-01-24 20:39   ` Jan Engelhardt
  2008-01-24 20:58   ` [patch 07/26] Add INIT_ARRAY() to kernel.h Randy Dunlap
@ 2008-01-24 23:03   ` H. Peter Anvin
  2 siblings, 0 replies; 48+ messages in thread
From: H. Peter Anvin @ 2008-01-24 23:03 UTC (permalink / raw)
  To: Mathieu Desnoyers; +Cc: akpm, Ingo Molnar, linux-kernel

Mathieu Desnoyers wrote:
> Add initialization of an array, which needs brackets that would pollute kernel
> code, to kernel.h

"brackets which would pollute kernel code"???

	-hpa

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [patch 07/26] Add INIT_ARRAY() to kernel.h
  2008-01-24 21:04     ` Mathieu Desnoyers
  2008-01-24 22:02       ` Stefan Richter
@ 2008-01-24 23:04       ` H. Peter Anvin
  2008-01-25 13:14         ` Mathieu Desnoyers
  2008-01-25  8:03       ` Jan Engelhardt
  2 siblings, 1 reply; 48+ messages in thread
From: H. Peter Anvin @ 2008-01-24 23:04 UTC (permalink / raw)
  To: Mathieu Desnoyers; +Cc: Randy Dunlap, akpm, Ingo Molnar, linux-kernel

Mathieu Desnoyers wrote:
> 
> Try opening such code in vim, and the syntax highlighting gets all
> messed up :-/
> 
> The other option is to do the *right thing* and fix vim, of course, but
> this change won't be in distros for a while.
> 

Let's get this straight...

You're suggesting introducing a pointless, ugly macro into the kernel 
because of a vim bug?

*Plonk!*

	-hpa

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [patch 03/26] Move Kconfig.instrumentation to arch/Kconfig and init/Kconfig
  2008-01-24 20:27 ` [patch 03/26] Move Kconfig.instrumentation to arch/Kconfig and init/Kconfig Mathieu Desnoyers
  2008-01-24 21:00   ` Randy Dunlap
  2008-01-24 22:03   ` Mathieu Desnoyers
@ 2008-01-24 23:05   ` Haavard Skinnemoen
  2 siblings, 0 replies; 48+ messages in thread
From: Haavard Skinnemoen @ 2008-01-24 23:05 UTC (permalink / raw)
  To: Mathieu Desnoyers
  Cc: akpm, Ingo Molnar, linux-kernel, Mathieu Desnoyers,
	Linus Torvalds, Sam Ravnborg

On Thu, 24 Jan 2008 15:27:09 -0500 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> wrote:
> Remove the "Instrumentation Support" menu. Everything moves to "General setup".
> Delete the kernel/Kconfig.instrumentation file.

Hmm. In preparation for oprofile, I currently have the below in my avr32
tree (i.e. -mm). What's the best way to deal with that?

I intend to push this early once the merge window opens. Could you just
remove the instrumentation menu from avr32 as well in your patch? It
should still apply nicely to -mm.

Haavard

commit 5ad893c907a645def629bbdab3a1c114f619bf1c
Author: Haavard Skinnemoen <hskinnemoen@atmel.com>
Date:   Wed Oct 31 15:22:34 2007 +0100

    [AVR32] Include instrumentation menu
    
    Remove KPROBES option from Kconfig.debug and include
    kernel/Kconfig.instrumentation.
    
    Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>

diff --git a/arch/avr32/Kconfig b/arch/avr32/Kconfig
index b77abce..bc08c7f 100644
--- a/arch/avr32/Kconfig
+++ b/arch/avr32/Kconfig
@@ -219,6 +219,8 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
+source "kernel/Kconfig.instrumentation"
+
 source "arch/avr32/Kconfig.debug"
 
 source "security/Kconfig"
diff --git a/arch/avr32/Kconfig.debug b/arch/avr32/Kconfig.debug
index 64ace00..2283933 100644
--- a/arch/avr32/Kconfig.debug
+++ b/arch/avr32/Kconfig.debug
@@ -6,14 +6,4 @@ config TRACE_IRQFLAGS_SUPPORT
 
 source "lib/Kconfig.debug"
 
-config KPROBES
-	bool "Kprobes"
-	depends on DEBUG_KERNEL
-	help
-	  Kprobes allows you to trap at almost any kernel address and
-          execute a callback function.  register_kprobe() establishes
-          a probepoint and specifies the callback.  Kprobes is useful
-          for kernel debugging, non-intrusive instrumentation and testing.
-          If in doubt, say "N".
-
 endmenu

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* Re: [patch 07/26] Add INIT_ARRAY() to kernel.h
  2008-01-24 21:04     ` Mathieu Desnoyers
  2008-01-24 22:02       ` Stefan Richter
  2008-01-24 23:04       ` [patch 07/26] Add INIT_ARRAY() to kernel.h H. Peter Anvin
@ 2008-01-25  8:03       ` Jan Engelhardt
  2 siblings, 0 replies; 48+ messages in thread
From: Jan Engelhardt @ 2008-01-25  8:03 UTC (permalink / raw)
  To: Mathieu Desnoyers; +Cc: Randy Dunlap, akpm, Ingo Molnar, linux-kernel


On Jan 24 2008 16:04, Mathieu Desnoyers wrote:
>* Randy Dunlap (randy.dunlap@oracle.com) wrote:
>
>Try opening such code in vim, and the syntax highlighting gets all
>messed up :-/

Then we'd also have to fix dcache.h:

#define DCACHE_NFSFS_RENAMED  0x0002    /* this dentry has been "silly 
                                         * renamed" and has to be 
                                         * deleted on the last dput() 
                                         */ 

by adding \ at the end of the comments, to unbreak cooledit and mc.
(The problem is not the comment, but the seemingly stray " in the 2nd line)

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [patch 07/26] Add INIT_ARRAY() to kernel.h
  2008-01-24 23:04       ` [patch 07/26] Add INIT_ARRAY() to kernel.h H. Peter Anvin
@ 2008-01-25 13:14         ` Mathieu Desnoyers
  0 siblings, 0 replies; 48+ messages in thread
From: Mathieu Desnoyers @ 2008-01-25 13:14 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Randy Dunlap, akpm, Ingo Molnar, linux-kernel

* H. Peter Anvin (hpa@zytor.com) wrote:
> Mathieu Desnoyers wrote:
>> Try opening such code in vim, and the syntax highlighting gets all
>> messed up :-/
>> The other option is to do the *right thing* and fix vim, of course, but
>> this change won't be in distros for a while.
>
> Let's get this straight...
>
> You're suggesting introducing a pointless, ugly macro into the kernel 
> because of a vim bug?
>
> *Plonk!*
>

heh, yup, I guess we should drop this patch. As you point out, it makes
no sense.

Mathieu

> 	-hpa

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

^ permalink raw reply	[flat|nested] 48+ messages in thread

end of thread, other threads:[~2008-01-25 13:19 UTC | newest]

Thread overview: 48+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-24 20:27 [patch 00/26] Instrumentation Support Enhancement (2.6.24-rc8-mm1) Mathieu Desnoyers
2008-01-24 20:27 ` [patch 01/26] Linux Kernel Markers Support for Proprierary Modules Mathieu Desnoyers
2008-01-24 22:19   ` Jon Masters
2008-01-24 20:27 ` [patch 02/26] Fix ARM to play nicely with generic Instrumentation menu Mathieu Desnoyers
2008-01-24 21:13   ` Russell King
2008-01-24 21:23     ` Mathieu Desnoyers
2008-01-24 22:17       ` Russell King
2008-01-24 20:27 ` [patch 03/26] Move Kconfig.instrumentation to arch/Kconfig and init/Kconfig Mathieu Desnoyers
2008-01-24 21:00   ` Randy Dunlap
2008-01-24 21:05     ` Mathieu Desnoyers
2008-01-24 22:03   ` Mathieu Desnoyers
2008-01-24 23:05   ` Haavard Skinnemoen
2008-01-24 20:27 ` [patch 04/26] Kprobes - use a mutex to protect the instruction pages list Mathieu Desnoyers
2008-01-24 20:27 ` [patch 05/26] Kprobes - do not use kprobes mutex in arch code Mathieu Desnoyers
2008-01-24 20:27 ` [patch 06/26] Kprobes - declare kprobe_mutex static Mathieu Desnoyers
2008-01-24 20:27 ` [patch 07/26] Add INIT_ARRAY() to kernel.h Mathieu Desnoyers
2008-01-24 20:39   ` Jan Engelhardt
2008-01-24 20:54     ` [patch 07/26] Add INIT_ARRAY() to kernel.h (updated) Mathieu Desnoyers
2008-01-24 21:08       ` Jan Engelhardt
2008-01-24 21:18         ` Mathieu Desnoyers
2008-01-24 20:58   ` [patch 07/26] Add INIT_ARRAY() to kernel.h Randy Dunlap
2008-01-24 21:04     ` Mathieu Desnoyers
2008-01-24 22:02       ` Stefan Richter
2008-01-24 22:10         ` [patch 07/26] Add INIT_ARRAY() to kernel.h (update 2) Mathieu Desnoyers
2008-01-24 22:50           ` Alexey Dobriyan
2008-01-24 23:04       ` [patch 07/26] Add INIT_ARRAY() to kernel.h H. Peter Anvin
2008-01-25 13:14         ` Mathieu Desnoyers
2008-01-25  8:03       ` Jan Engelhardt
2008-01-24 23:03   ` H. Peter Anvin
2008-01-24 20:27 ` [patch 08/26] Text Edit Lock - Architecture Independent Code Mathieu Desnoyers
2008-01-24 20:27 ` [patch 09/26] Text Edit Lock - Alternative code for x86 Mathieu Desnoyers
2008-01-24 20:27 ` [patch 10/26] Text Edit Lock - kprobes architecture independent support Mathieu Desnoyers
2008-01-24 20:27 ` [patch 11/26] Text Edit Lock - kprobes x86 Mathieu Desnoyers
2008-01-24 20:27 ` [patch 12/26] Text Edit Lock - x86_32 standardize debug rodata Mathieu Desnoyers
2008-01-24 20:27 ` [patch 13/26] Text Edit Lock - x86_64 " Mathieu Desnoyers
2008-01-24 20:27 ` [patch 14/26] Immediate Values - Architecture Independent Code Mathieu Desnoyers
2008-01-24 20:27 ` [patch 15/26] Immediate Values - Kconfig menu in EMBEDDED Mathieu Desnoyers
2008-01-24 20:27 ` [patch 16/26] Immediate Values - x86 Optimization Mathieu Desnoyers
2008-01-24 20:27 ` [patch 17/26] Add text_poke and sync_core to powerpc Mathieu Desnoyers
2008-01-24 20:27 ` [patch 18/26] Immediate Values - Powerpc Optimization Mathieu Desnoyers
2008-01-24 20:27 ` [patch 19/26] Immediate Values - Documentation Mathieu Desnoyers
2008-01-24 20:27 ` [patch 20/26] Scheduler Profiling - Use Immediate Values Mathieu Desnoyers
2008-01-24 20:27 ` [patch 21/26] Immediate Values - Move Kprobes x86 restore_interrupt to kdebug.h Mathieu Desnoyers
2008-01-24 20:27 ` [patch 22/26] Add __discard section to x86 Mathieu Desnoyers
2008-01-24 20:27 ` [patch 23/26] Immediate Values - x86 Optimization NMI and MCE support Mathieu Desnoyers
2008-01-24 20:27 ` [patch 24/26] Immediate Values - Powerpc Optimization NMI " Mathieu Desnoyers
2008-01-24 20:27 ` [patch 25/26] Immediate Values Use Arch NMI and MCE Support Mathieu Desnoyers
2008-01-24 20:27 ` [patch 26/26] Linux Kernel Markers - Use Immediate Values Mathieu Desnoyers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox