Re: [RFC] [PATCH] To vunmap correct address in text_poke()(kprobes)

2007-07-25 Thread S. P. Prasanna
On Wed, Jul 25, 2007 at 12:21:49PM +0530, Srinivasa Ds wrote:
> 
> When I was testing kprobes on x86_64 and I come across the below error 
> message 
> on latest 2.6.23-rc1 kernel.
> ==
> Trying to vfree() bad address (c20002233199)
>  WARNING: at mm/vmalloc.c:330 __vunmap()
> 
>  Call Trace:
>  [] sys_gettimeofday+0x0/0x62
>   [] text_poke+0x119/0x124
>   [] arch_arm_kprobe+0x1c/0x21
>   [] __register_kprobe+0x28a/0x2ed
>   [] :gettimeofday:kprobe_init+0x39/0x65
>   [] sys_init_module+0x1626/0x1788
>   [] dput+0x3f/0xfa
>   [] audit_syscall_entry+0x141/0x174
>   [] tracesys+0xdc/0xe1
> 
> ==
> 
> This indicates that vunmap() is not receving the page-aligned address in 
> text_poke(). So the below attached patch will address this issue. Please let 
> me know your comments.
> 
> Signed-off-by: Srinivasa DS <[EMAIL PROTECTED]>
> Signed-off-by: Suzuki K P   <[EMAIL PROTECTED]>
> 
> 
> Index: linux-2.6.23-rc1/arch/i386/kernel/alternative.c
> ===
> --- linux-2.6.23-rc1.orig/arch/i386/kernel/alternative.c  2007-07-23 
> 02:11:00.0 +0530
> +++ linux-2.6.23-rc1/arch/i386/kernel/alternative.c   2007-07-25 
> 11:45:53.0 +0530
> @@ -447,5 +447,5 @@ void __kprobes text_poke(void *oaddr, un
>   if (cpu_has_clflush)
>   asm("clflush (%0) " :: "r" (oaddr) : "memory");
>   if (addr != oaddr)
> - vunmap(addr);
> + vunmap(addr-(((unsigned long)oaddr) % PAGE_SIZE));

It is appropriate to use PAGE_MASK rather than doing all this,
as shown below.

vunmap((u8 *)((unsigned long)addr & PAGE_MASK));

Thanks
Prasanna

-- 
Prasanna S.P.
Linux Technology Center
India Software Labs, IBM Bangalore
Email: [EMAIL PROTECTED]
Ph: 91-80-41776329
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC] [PATCH] To vunmap correct address in text_poke()(kprobes)

2007-07-25 Thread S. P. Prasanna
On Wed, Jul 25, 2007 at 12:21:49PM +0530, Srinivasa Ds wrote:
 
 When I was testing kprobes on x86_64 and I come across the below error 
 message 
 on latest 2.6.23-rc1 kernel.
 ==
 Trying to vfree() bad address (c20002233199)
  WARNING: at mm/vmalloc.c:330 __vunmap()
 
  Call Trace:
  [8023d199] sys_gettimeofday+0x0/0x62
   [8047636c] text_poke+0x119/0x124
   [80476b42] arch_arm_kprobe+0x1c/0x21
   [80477cfd] __register_kprobe+0x28a/0x2ed
   [8815a039] :gettimeofday:kprobe_init+0x39/0x65
   [8025b5cf] sys_init_module+0x1626/0x1788
   [802aaf12] dput+0x3f/0xfa
   [8026bf91] audit_syscall_entry+0x141/0x174
   [8020bee5] tracesys+0xdc/0xe1
 
 ==
 
 This indicates that vunmap() is not receving the page-aligned address in 
 text_poke(). So the below attached patch will address this issue. Please let 
 me know your comments.
 
 Signed-off-by: Srinivasa DS [EMAIL PROTECTED]
 Signed-off-by: Suzuki K P   [EMAIL PROTECTED]
 
 
 Index: linux-2.6.23-rc1/arch/i386/kernel/alternative.c
 ===
 --- linux-2.6.23-rc1.orig/arch/i386/kernel/alternative.c  2007-07-23 
 02:11:00.0 +0530
 +++ linux-2.6.23-rc1/arch/i386/kernel/alternative.c   2007-07-25 
 11:45:53.0 +0530
 @@ -447,5 +447,5 @@ void __kprobes text_poke(void *oaddr, un
   if (cpu_has_clflush)
   asm(clflush (%0)  :: r (oaddr) : memory);
   if (addr != oaddr)
 - vunmap(addr);
 + vunmap(addr-(((unsigned long)oaddr) % PAGE_SIZE));

It is appropriate to use PAGE_MASK rather than doing all this,
as shown below.

vunmap((u8 *)((unsigned long)addr  PAGE_MASK));

Thanks
Prasanna

-- 
Prasanna S.P.
Linux Technology Center
India Software Labs, IBM Bangalore
Email: [EMAIL PROTECTED]
Ph: 91-80-41776329
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [patch 3/3] Text Edit Lock - kprobes i386

2007-07-04 Thread S. P. Prasanna
On Tue, Jul 03, 2007 at 12:38:22PM -0400, Mathieu Desnoyers wrote:
> Kprobes can use the text edit lock to insure mutual exclusion when edition the
> code and make sure the pages are writable.

Linus suggested for splitting ro-data and ro-text; And allow ro-text
only if kprobes is not configured.
Please see the discussion thread, URL given below
http://lkml.org/lkml/2007/6/20/436

This patch below allows to configure and mark the kernel text and
kernel data as read-only separately. Also kernel text
is configured read-only if kprobes is not configured.

Thanks
Prasanna

This patch allows to configure and mark the kernel text and
kernel data as read-only separately.

Signed-off-by: Prasanna S P. <[EMAIL PROTECTED]>


 arch/i386/Kconfig.debug |8 
 arch/i386/mm/init.c |   22 --
 2 files changed, 24 insertions(+), 6 deletions(-)

diff -puN arch/i386/Kconfig.debug~mark-kernel-text-data-ro-seperately-i386 
arch/i386/Kconfig.debug
--- 
linux-2.6.22-rc6/arch/i386/Kconfig.debug~mark-kernel-text-data-ro-seperately-i386
   2007-07-04 13:45:24.0 +0530
+++ linux-2.6.22-rc6-prasanna/arch/i386/Kconfig.debug   2007-07-04 
13:52:31.0 +0530
@@ -56,6 +56,14 @@ config DEBUG_RODATA
  portion of the kernel code won't be covered by a 2MB TLB anymore.
  If in doubt, say "N".
 
+config DEBUG_ROTEXT
+   bool "Write protect kernel text"
+   depends on DEBUG_RODATA && !KPROBES
+   help
+ Mark the kernel text as write-protected in the pagetables.
+ Only allow this if kprobes is not configured.
+ If in doubt, say "N".
+
 config 4KSTACKS
bool "Use 4Kb for kernel stacks instead of 8Kb"
depends on DEBUG_KERNEL
diff -puN arch/i386/mm/init.c~mark-kernel-text-data-ro-seperately-i386 
arch/i386/mm/init.c
--- 
linux-2.6.22-rc6/arch/i386/mm/init.c~mark-kernel-text-data-ro-seperately-i386   
2007-07-04 13:45:24.0 +0530
+++ linux-2.6.22-rc6-prasanna/arch/i386/mm/init.c   2007-07-04 
13:51:39.0 +0530
@@ -792,14 +792,11 @@ static int noinline do_test_wp_bit(void)
return flag;
 }
 
-#ifdef CONFIG_DEBUG_RODATA
-
-void mark_rodata_ro(void)
+static inline void mark_rwtext_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)
@@ -809,9 +806,22 @@ void mark_rodata_ro(void)
 size >> PAGE_SHIFT, PAGE_KERNEL_RX);
printk("Write protecting the kernel text: %luk\n", size >> 10);
}
+
+   /*
+* global_flush_tlb() will be called after marking the data as readonly.
+*/
+}
+
+#ifdef CONFIG_DEBUG_RODATA
+
+void mark_rodata_ro(void)
+{
+   unsigned long start = PFN_ALIGN(_etext);
+   unsigned long size = (unsigned long)__end_rodata - start;
+
+#ifdef CONFIG_DEBUG_ROTEXT
+   mark_rwtext_ro();
 #endif
-   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",

_
-- 
Prasanna S.P.
Linux Technology Center
India Software Labs, IBM Bangalore
Email: [EMAIL PROTECTED]
Ph: 91-80-41776329
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [patch 3/3] Text Edit Lock - kprobes i386

2007-07-04 Thread S. P. Prasanna
On Tue, Jul 03, 2007 at 12:38:22PM -0400, Mathieu Desnoyers wrote:
 Kprobes can use the text edit lock to insure mutual exclusion when edition the
 code and make sure the pages are writable.

Linus suggested for splitting ro-data and ro-text; And allow ro-text
only if kprobes is not configured.
Please see the discussion thread, URL given below
http://lkml.org/lkml/2007/6/20/436

This patch below allows to configure and mark the kernel text and
kernel data as read-only separately. Also kernel text
is configured read-only if kprobes is not configured.

Thanks
Prasanna

This patch allows to configure and mark the kernel text and
kernel data as read-only separately.

Signed-off-by: Prasanna S P. [EMAIL PROTECTED]


 arch/i386/Kconfig.debug |8 
 arch/i386/mm/init.c |   22 --
 2 files changed, 24 insertions(+), 6 deletions(-)

diff -puN arch/i386/Kconfig.debug~mark-kernel-text-data-ro-seperately-i386 
arch/i386/Kconfig.debug
--- 
linux-2.6.22-rc6/arch/i386/Kconfig.debug~mark-kernel-text-data-ro-seperately-i386
   2007-07-04 13:45:24.0 +0530
+++ linux-2.6.22-rc6-prasanna/arch/i386/Kconfig.debug   2007-07-04 
13:52:31.0 +0530
@@ -56,6 +56,14 @@ config DEBUG_RODATA
  portion of the kernel code won't be covered by a 2MB TLB anymore.
  If in doubt, say N.
 
+config DEBUG_ROTEXT
+   bool Write protect kernel text
+   depends on DEBUG_RODATA  !KPROBES
+   help
+ Mark the kernel text as write-protected in the pagetables.
+ Only allow this if kprobes is not configured.
+ If in doubt, say N.
+
 config 4KSTACKS
bool Use 4Kb for kernel stacks instead of 8Kb
depends on DEBUG_KERNEL
diff -puN arch/i386/mm/init.c~mark-kernel-text-data-ro-seperately-i386 
arch/i386/mm/init.c
--- 
linux-2.6.22-rc6/arch/i386/mm/init.c~mark-kernel-text-data-ro-seperately-i386   
2007-07-04 13:45:24.0 +0530
+++ linux-2.6.22-rc6-prasanna/arch/i386/mm/init.c   2007-07-04 
13:51:39.0 +0530
@@ -792,14 +792,11 @@ static int noinline do_test_wp_bit(void)
return flag;
 }
 
-#ifdef CONFIG_DEBUG_RODATA
-
-void mark_rodata_ro(void)
+static inline void mark_rwtext_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)
@@ -809,9 +806,22 @@ void mark_rodata_ro(void)
 size  PAGE_SHIFT, PAGE_KERNEL_RX);
printk(Write protecting the kernel text: %luk\n, size  10);
}
+
+   /*
+* global_flush_tlb() will be called after marking the data as readonly.
+*/
+}
+
+#ifdef CONFIG_DEBUG_RODATA
+
+void mark_rodata_ro(void)
+{
+   unsigned long start = PFN_ALIGN(_etext);
+   unsigned long size = (unsigned long)__end_rodata - start;
+
+#ifdef CONFIG_DEBUG_ROTEXT
+   mark_rwtext_ro();
 #endif
-   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,

_
-- 
Prasanna S.P.
Linux Technology Center
India Software Labs, IBM Bangalore
Email: [EMAIL PROTECTED]
Ph: 91-80-41776329
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [1/2] 2.6.22-rc5: known regressions with patches

2007-06-21 Thread S. P. Prasanna
On Wed, Jun 20, 2007 at 10:23:21PM -0700, Arjan van de Ven wrote:
> On Wed, 2007-06-20 at 16:50 -0700, Linus Torvalds wrote:
> > 
> > On Wed, 20 Jun 2007, Arjan van de Ven wrote:
> > > 
> > > the real fix would be something like this instead:
> > 
> > If people can test this, and confirm it works, please send a patch that 
> > not only does this ad undoes the Kconfig language.  It looks like the 
> > right thing to do, but I won't touch it without somebody who actually 
> > tested these combinarions sending in a patch.
> 
> Hi,
> 
> I have tested this on x86_64, and without the config language, the
> original oopses, while with the patch below it works fine (as expected).
> I've not been able to test the i386 one (no 32 bit testboxes since 2
> years) but the change is even simpler there, just an ifdef around the
> entire kernel text marking.

I tested this patch on i386 box, it seems to work fine.

Thanks
Prasanna
> 
> 
> 
> Do not mark the kernel text read only if KPROBES is in the kernel;
> kprobes needs to hot-patch the kernel text to insert it's
> instrumentation. In this case, only mark the .rodata segment as read
> only.
> 
> Signed-off-by: Arjan van de Ven <[EMAIL PROTECTED]>
> 
> --- linux-2.6.22-rc5/arch/i386/Kconfig.debug.org  2007-06-20 
> 22:20:30.0 -0700
> +++ linux-2.6.22-rc5/arch/i386/Kconfig.debug  2007-06-20 22:20:55.0 
> -0700
> @@ -49,7 +49,6 @@ config DEBUG_PAGEALLOC
>  config DEBUG_RODATA
>   bool "Write protect kernel read-only data structures"
>   depends on DEBUG_KERNEL
> - depends on !KPROBES # temporary for 2.6.22
>   help
> Mark the kernel read-only data as write-protected in the pagetables,
> in order to catch accidental (and incorrect) writes to such const
> --- linux-2.6.22-rc5/arch/x86_64/Kconfig.debug.org2007-06-20 
> 22:20:28.0 -0700
> +++ linux-2.6.22-rc5/arch/x86_64/Kconfig.debug2007-06-20 
> 22:20:44.0 -0700
> @@ -9,7 +9,6 @@ source "lib/Kconfig.debug"
>  config DEBUG_RODATA
> bool "Write protect kernel read-only data structures"
> depends on DEBUG_KERNEL
> -   depends on !KPROBES # temporary for 2.6.22
> help
>Mark the kernel read-only data as write-protected in the pagetables,
>in order to catch accidental (and incorrect) writes to such const data.
> --- linux-2.6.22-rc5/arch/i386/mm/init.c.org  2007-06-20 22:18:40.0 
> -0700
> +++ linux-2.6.22-rc5/arch/i386/mm/init.c  2007-06-20 22:19:45.0 
> -0700
> @@ -799,6 +799,7 @@ 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)
> @@ -808,7 +809,7 @@ void mark_rodata_ro(void)
>size >> PAGE_SHIFT, PAGE_KERNEL_RX);
>   printk("Write protecting the kernel text: %luk\n", size >> 10);
>   }
> -
> +#endif
>   start += size;
>   size = (unsigned long)__end_rodata - start;
>   change_page_attr(virt_to_page(start),
> --- linux-2.6.22-rc5/arch/x86_64/mm/init.c.org2007-06-20 
> 21:44:15.0 -0700
> +++ linux-2.6.22-rc5/arch/x86_64/mm/init.c2007-06-20 22:17:45.0 
> -0700
> @@ -605,6 +605,11 @@ void mark_rodata_ro(void)
>   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 you want to mail me at work (you don't), use arjan (at) linux.intel.com
> Test the interaction between Linux and your BIOS via 
> http://www.linuxfirmwarekit.org

-- 
Thanks & Regards
Prasanna S.P.
Linux Technology Center
India Software Labs, IBM Bangalore
Email: [EMAIL PROTECTED]
Ph: 91-80-41776329
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [1/2] 2.6.22-rc5: known regressions with patches

2007-06-21 Thread S. P. Prasanna
On Wed, Jun 20, 2007 at 10:23:21PM -0700, Arjan van de Ven wrote:
 On Wed, 2007-06-20 at 16:50 -0700, Linus Torvalds wrote:
  
  On Wed, 20 Jun 2007, Arjan van de Ven wrote:
   
   the real fix would be something like this instead:
  
  If people can test this, and confirm it works, please send a patch that 
  not only does this ad undoes the Kconfig language.  It looks like the 
  right thing to do, but I won't touch it without somebody who actually 
  tested these combinarions sending in a patch.
 
 Hi,
 
 I have tested this on x86_64, and without the config language, the
 original oopses, while with the patch below it works fine (as expected).
 I've not been able to test the i386 one (no 32 bit testboxes since 2
 years) but the change is even simpler there, just an ifdef around the
 entire kernel text marking.

I tested this patch on i386 box, it seems to work fine.

Thanks
Prasanna
 
 
 
 Do not mark the kernel text read only if KPROBES is in the kernel;
 kprobes needs to hot-patch the kernel text to insert it's
 instrumentation. In this case, only mark the .rodata segment as read
 only.
 
 Signed-off-by: Arjan van de Ven [EMAIL PROTECTED]
 
 --- linux-2.6.22-rc5/arch/i386/Kconfig.debug.org  2007-06-20 
 22:20:30.0 -0700
 +++ linux-2.6.22-rc5/arch/i386/Kconfig.debug  2007-06-20 22:20:55.0 
 -0700
 @@ -49,7 +49,6 @@ config DEBUG_PAGEALLOC
  config DEBUG_RODATA
   bool Write protect kernel read-only data structures
   depends on DEBUG_KERNEL
 - depends on !KPROBES # temporary for 2.6.22
   help
 Mark the kernel read-only data as write-protected in the pagetables,
 in order to catch accidental (and incorrect) writes to such const
 --- linux-2.6.22-rc5/arch/x86_64/Kconfig.debug.org2007-06-20 
 22:20:28.0 -0700
 +++ linux-2.6.22-rc5/arch/x86_64/Kconfig.debug2007-06-20 
 22:20:44.0 -0700
 @@ -9,7 +9,6 @@ source lib/Kconfig.debug
  config DEBUG_RODATA
 bool Write protect kernel read-only data structures
 depends on DEBUG_KERNEL
 -   depends on !KPROBES # temporary for 2.6.22
 help
Mark the kernel read-only data as write-protected in the pagetables,
in order to catch accidental (and incorrect) writes to such const data.
 --- linux-2.6.22-rc5/arch/i386/mm/init.c.org  2007-06-20 22:18:40.0 
 -0700
 +++ linux-2.6.22-rc5/arch/i386/mm/init.c  2007-06-20 22:19:45.0 
 -0700
 @@ -799,6 +799,7 @@ 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)
 @@ -808,7 +809,7 @@ void mark_rodata_ro(void)
size  PAGE_SHIFT, PAGE_KERNEL_RX);
   printk(Write protecting the kernel text: %luk\n, size  10);
   }
 -
 +#endif
   start += size;
   size = (unsigned long)__end_rodata - start;
   change_page_attr(virt_to_page(start),
 --- linux-2.6.22-rc5/arch/x86_64/mm/init.c.org2007-06-20 
 21:44:15.0 -0700
 +++ linux-2.6.22-rc5/arch/x86_64/mm/init.c2007-06-20 22:17:45.0 
 -0700
 @@ -605,6 +605,11 @@ void mark_rodata_ro(void)
   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 you want to mail me at work (you don't), use arjan (at) linux.intel.com
 Test the interaction between Linux and your BIOS via 
 http://www.linuxfirmwarekit.org

-- 
Thanks  Regards
Prasanna S.P.
Linux Technology Center
India Software Labs, IBM Bangalore
Email: [EMAIL PROTECTED]
Ph: 91-80-41776329
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [patch 2/2] kprobes x86_64 quick fix mark-ro-data

2007-06-19 Thread S. P. Prasanna
On Tue, Jun 19, 2007 at 06:44:30AM -0700, Arjan van de Ven wrote:
> On Tue, 2007-06-19 at 09:30 -0400, Mathieu Desnoyers wrote:
> > * Arjan van de Ven ([EMAIL PROTECTED]) wrote:
> > > On Tue, 2007-06-19 at 15:38 +0530, S. P. Prasanna wrote:
> > > > This patch is a quick fix for x86_64 to enable kprobes only if 
> > > > DEBUG_RODATA is
> > > > not configured. Since DEBUG_RODATA markes the kernel text pages as 
> > > > read-only.
> > > 
> > > 
> > > it does??
> > > 
> > > I don't seem to be able to find this in the source code. 
> > > 
> 
> > See arch/x86_64/mm/init.c:mark_rodata_ro().
> 
> eh woops
> 
> 
> PATCH] x86: tighten kernel image page access rights
> author
> Jan Beulich <[EMAIL PROTECTED]>
> 
> Wed, 2 May 2007 17:27:10 +
> (19:27 +0200)
> committer
> Andi Kleen <[EMAIL PROTECTED]>
> 
> Wed, 2 May 2007 17:27:10 +
> (19:27 +0200)
> commit
> 6fb14755a676282a4e6caa05a08c92db8e45cfff
> 
> 
> changed it to include text (even though Andi vetoed that before when I
> asked for it on grounds of breaking kprobes)... sounds this really wants
> to be a 2nd config option to seperatedly do code and data.

Something like having a seperate config option and a routine
to mark kernel text as read execute only.
And call mark_rwtext_ro() if CONFIG_DEBUG_ROTEXT is enabled
below in mark_rodata_ro().

/* this code is for i386 architecture*/
static inline void mark_rwtext_ro(void)
{
unsigned long start = PFN_ALIGN(_text);
unsigned long size = PFN_ALIGN(_etext) - start;

#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);
}
/*
 * global_flush_tlb() will be called after marking the data as readonly.
 */
}

#ifdef CONFIG_DEBUG_RODATA

void mark_rodata_ro(void)
{


#ifdef CONFIG_DEBUG_ROTEXT
mark_rwtext_ro();
#endif


}

Thanks
Prasanna
-- 
Prasanna S.P.
Linux Technology Center
India Software Labs, IBM Bangalore
Email: [EMAIL PROTECTED]
Ph: 91-80-41776329
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [patch 2/2] kprobes x86_64 quick fix mark-ro-data

2007-06-19 Thread S. P. Prasanna
This patch is a quick fix for x86_64 to enable kprobes only if DEBUG_RODATA is
not configured. Since DEBUG_RODATA markes the kernel text pages as read-only.

Signed-off-by: Prasanna S P. <[EMAIL PROTECTED]>


 arch/x86_64/Kconfig |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff -puN arch/x86_64/Kconfig~kprobes-quick-fix-mark-ro-data-x86_64 
arch/x86_64/Kconfig
--- linux-2.6.22-rc5/arch/x86_64/Kconfig~kprobes-quick-fix-mark-ro-data-x86_64  
2007-06-19 14:55:56.0 +0530
+++ linux-2.6.22-rc5-prasanna/arch/x86_64/Kconfig   2007-06-19 
14:55:56.0 +0530
@@ -764,6 +764,8 @@ source "drivers/firmware/Kconfig"
 
 source fs/Kconfig
 
+source "arch/x86_64/Kconfig.debug"
+
 menu "Instrumentation Support"
 depends on EXPERIMENTAL
 
@@ -771,7 +773,7 @@ source "arch/x86_64/oprofile/Kconfig"
 
 config KPROBES
bool "Kprobes (EXPERIMENTAL)"
-   depends on KALLSYMS && EXPERIMENTAL && MODULES
+   depends on KALLSYMS && EXPERIMENTAL && MODULES && !DEBUG_RODATA
help
  Kprobes allows you to trap at almost any kernel address and
  execute a callback function.  register_kprobe() establishes
@@ -780,8 +782,6 @@ config KPROBES
  If in doubt, say "N".
 endmenu
 
-source "arch/x86_64/Kconfig.debug"
-
 source "security/Kconfig"
 
 source "crypto/Kconfig"

_
-- 
Prasanna S.P.
Linux Technology Center
India Software Labs, IBM Bangalore
Email: [EMAIL PROTECTED]
Ph: 91-80-41776329
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [patch 1/2] kprobes i386 quick fix mark-ro-data

2007-06-19 Thread S. P. Prasanna
On Mon, Jun 18, 2007 at 09:32:56PM +0200, Andi Kleen wrote:
> On Monday 18 June 2007 20:56:32 Andrew Morton wrote:
> > On Mon, 18 Jun 2007 14:44:57 -0400
> > Chuck Ebbert <[EMAIL PROTECTED]> wrote:
> > 
> > > > I fancy it's done by the kprobe_page_fault handler, but I do not see
> > > > clearly how writing the breakpoint from arch_arm_kprobe() in
> > > > non-writeable memory is done.
> > > 
> > > Looks like it's not merged yet:
> > > 
> > > http://lkml.org/lkml/2007/6/7/2
> > > 
> > > This needs to go in before 2.6.22-final
> > 
> > Andi, I'll include the below two patches in the next batch, OK?
> 
> It won't work reliably unless some of the c_p_a() fixes get in first.
> 
> > 
> > 
> > 
> > +extern int kernel_text_is_ro;
> 
> No externs in .c files
Yes.
> 
> 
> I also don't like kernel_text_is_read_only() much, it would
> be better to just lookup_address() it and check the write flag.

Yes, I will look into this approach.
> 
> But for 2.6.22 as a quick fix it might be better to just
> make KPROBES dependent on !DEBUG_RODATA. That would be a one liner.
> 

Please find the quick fix as per your suggestion below.

Thanks
Prasanna

This patch is a quick fix to enable kprobes only if DEBUG_RODATA is
not configured. Since DEBUG_RODATA markes the kernel text pages as read-only.

Signed-off-by: Prasanna S P. <[EMAIL PROTECTED]>


 arch/i386/Kconfig |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff -puN arch/i386/Kconfig~kprobes-quick-fix-mark-ro-data-i386 
arch/i386/Kconfig
--- linux-2.6.22-rc5/arch/i386/Kconfig~kprobes-quick-fix-mark-ro-data-i386  
2007-06-19 14:55:31.0 +0530
+++ linux-2.6.22-rc5-prasanna/arch/i386/Kconfig 2007-06-19 14:55:31.0 
+0530
@@ -1212,6 +1212,8 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
+source "arch/i386/Kconfig.debug"
+
 menu "Instrumentation Support"
depends on EXPERIMENTAL
 
@@ -1219,7 +1221,7 @@ source "arch/i386/oprofile/Kconfig"
 
 config KPROBES
bool "Kprobes (EXPERIMENTAL)"
-   depends on KALLSYMS && EXPERIMENTAL && MODULES
+   depends on KALLSYMS && EXPERIMENTAL && MODULES && !DEBUG_RODATA
help
  Kprobes allows you to trap at almost any kernel address and
  execute a callback function.  register_kprobe() establishes
@@ -1228,8 +1230,6 @@ config KPROBES
  If in doubt, say "N".
 endmenu
 
-source "arch/i386/Kconfig.debug"
-
 source "security/Kconfig"
 
 source "crypto/Kconfig"

_
-- 
Prasanna S.P.
Linux Technology Center
India Software Labs, IBM Bangalore
Email: [EMAIL PROTECTED]
Ph: 91-80-41776329
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [patch 1/2] kprobes i386 quick fix mark-ro-data

2007-06-19 Thread S. P. Prasanna
On Mon, Jun 18, 2007 at 09:32:56PM +0200, Andi Kleen wrote:
 On Monday 18 June 2007 20:56:32 Andrew Morton wrote:
  On Mon, 18 Jun 2007 14:44:57 -0400
  Chuck Ebbert [EMAIL PROTECTED] wrote:
  
I fancy it's done by the kprobe_page_fault handler, but I do not see
clearly how writing the breakpoint from arch_arm_kprobe() in
non-writeable memory is done.
   
   Looks like it's not merged yet:
   
   http://lkml.org/lkml/2007/6/7/2
   
   This needs to go in before 2.6.22-final
  
  Andi, I'll include the below two patches in the next batch, OK?
 
 It won't work reliably unless some of the c_p_a() fixes get in first.
 
  
  
  
  +extern int kernel_text_is_ro;
 
 No externs in .c files
Yes.
 
 
 I also don't like kernel_text_is_read_only() much, it would
 be better to just lookup_address() it and check the write flag.

Yes, I will look into this approach.
 
 But for 2.6.22 as a quick fix it might be better to just
 make KPROBES dependent on !DEBUG_RODATA. That would be a one liner.
 

Please find the quick fix as per your suggestion below.

Thanks
Prasanna

This patch is a quick fix to enable kprobes only if DEBUG_RODATA is
not configured. Since DEBUG_RODATA markes the kernel text pages as read-only.

Signed-off-by: Prasanna S P. [EMAIL PROTECTED]


 arch/i386/Kconfig |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff -puN arch/i386/Kconfig~kprobes-quick-fix-mark-ro-data-i386 
arch/i386/Kconfig
--- linux-2.6.22-rc5/arch/i386/Kconfig~kprobes-quick-fix-mark-ro-data-i386  
2007-06-19 14:55:31.0 +0530
+++ linux-2.6.22-rc5-prasanna/arch/i386/Kconfig 2007-06-19 14:55:31.0 
+0530
@@ -1212,6 +1212,8 @@ source drivers/Kconfig
 
 source fs/Kconfig
 
+source arch/i386/Kconfig.debug
+
 menu Instrumentation Support
depends on EXPERIMENTAL
 
@@ -1219,7 +1221,7 @@ source arch/i386/oprofile/Kconfig
 
 config KPROBES
bool Kprobes (EXPERIMENTAL)
-   depends on KALLSYMS  EXPERIMENTAL  MODULES
+   depends on KALLSYMS  EXPERIMENTAL  MODULES  !DEBUG_RODATA
help
  Kprobes allows you to trap at almost any kernel address and
  execute a callback function.  register_kprobe() establishes
@@ -1228,8 +1230,6 @@ config KPROBES
  If in doubt, say N.
 endmenu
 
-source arch/i386/Kconfig.debug
-
 source security/Kconfig
 
 source crypto/Kconfig

_
-- 
Prasanna S.P.
Linux Technology Center
India Software Labs, IBM Bangalore
Email: [EMAIL PROTECTED]
Ph: 91-80-41776329
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [patch 2/2] kprobes x86_64 quick fix mark-ro-data

2007-06-19 Thread S. P. Prasanna
This patch is a quick fix for x86_64 to enable kprobes only if DEBUG_RODATA is
not configured. Since DEBUG_RODATA markes the kernel text pages as read-only.

Signed-off-by: Prasanna S P. [EMAIL PROTECTED]


 arch/x86_64/Kconfig |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff -puN arch/x86_64/Kconfig~kprobes-quick-fix-mark-ro-data-x86_64 
arch/x86_64/Kconfig
--- linux-2.6.22-rc5/arch/x86_64/Kconfig~kprobes-quick-fix-mark-ro-data-x86_64  
2007-06-19 14:55:56.0 +0530
+++ linux-2.6.22-rc5-prasanna/arch/x86_64/Kconfig   2007-06-19 
14:55:56.0 +0530
@@ -764,6 +764,8 @@ source drivers/firmware/Kconfig
 
 source fs/Kconfig
 
+source arch/x86_64/Kconfig.debug
+
 menu Instrumentation Support
 depends on EXPERIMENTAL
 
@@ -771,7 +773,7 @@ source arch/x86_64/oprofile/Kconfig
 
 config KPROBES
bool Kprobes (EXPERIMENTAL)
-   depends on KALLSYMS  EXPERIMENTAL  MODULES
+   depends on KALLSYMS  EXPERIMENTAL  MODULES  !DEBUG_RODATA
help
  Kprobes allows you to trap at almost any kernel address and
  execute a callback function.  register_kprobe() establishes
@@ -780,8 +782,6 @@ config KPROBES
  If in doubt, say N.
 endmenu
 
-source arch/x86_64/Kconfig.debug
-
 source security/Kconfig
 
 source crypto/Kconfig

_
-- 
Prasanna S.P.
Linux Technology Center
India Software Labs, IBM Bangalore
Email: [EMAIL PROTECTED]
Ph: 91-80-41776329
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [patch 2/2] kprobes x86_64 quick fix mark-ro-data

2007-06-19 Thread S. P. Prasanna
On Tue, Jun 19, 2007 at 06:44:30AM -0700, Arjan van de Ven wrote:
 On Tue, 2007-06-19 at 09:30 -0400, Mathieu Desnoyers wrote:
  * Arjan van de Ven ([EMAIL PROTECTED]) wrote:
   On Tue, 2007-06-19 at 15:38 +0530, S. P. Prasanna wrote:
This patch is a quick fix for x86_64 to enable kprobes only if 
DEBUG_RODATA is
not configured. Since DEBUG_RODATA markes the kernel text pages as 
read-only.
   
   
   it does??
   
   I don't seem to be able to find this in the source code. 
   
 
  See arch/x86_64/mm/init.c:mark_rodata_ro().
 
 eh woops
 
 
 PATCH] x86: tighten kernel image page access rights
 author
 Jan Beulich [EMAIL PROTECTED]
 
 Wed, 2 May 2007 17:27:10 +
 (19:27 +0200)
 committer
 Andi Kleen [EMAIL PROTECTED]
 
 Wed, 2 May 2007 17:27:10 +
 (19:27 +0200)
 commit
 6fb14755a676282a4e6caa05a08c92db8e45cfff
 
 
 changed it to include text (even though Andi vetoed that before when I
 asked for it on grounds of breaking kprobes)... sounds this really wants
 to be a 2nd config option to seperatedly do code and data.

Something like having a seperate config option and a routine
to mark kernel text as read execute only.
And call mark_rwtext_ro() if CONFIG_DEBUG_ROTEXT is enabled
below in mark_rodata_ro().

/* this code is for i386 architecture*/
static inline void mark_rwtext_ro(void)
{
unsigned long start = PFN_ALIGN(_text);
unsigned long size = PFN_ALIGN(_etext) - start;

#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);
}
/*
 * global_flush_tlb() will be called after marking the data as readonly.
 */
}

#ifdef CONFIG_DEBUG_RODATA

void mark_rodata_ro(void)
{


#ifdef CONFIG_DEBUG_ROTEXT
mark_rwtext_ro();
#endif


}

Thanks
Prasanna
-- 
Prasanna S.P.
Linux Technology Center
India Software Labs, IBM Bangalore
Email: [EMAIL PROTECTED]
Ph: 91-80-41776329
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [2.6 patch] include/linux/kprobes.h: always offer show_registers() prototype

2007-06-18 Thread S. P. Prasanna

On Mon, Jun 18, 2007 at 01:43:04AM +0200, Adrian Bunk wrote:
> Allow gcc to perform show_registers() type checking also with 
> CONFIG_KPROBES=n.
> 
Adrian,

Please implement it as Andrew suggested, when this was patch was posted
eariler. Refer this discussion thread below.

http://lkml.org/lkml/2007/4/27/576

NACK

Thanks
Prasanna

> Signed-off-by: Adrian Bunk <[EMAIL PROTECTED]>
> 
> ---
> 
> This patch has been sent on:
> - 27 Apr 2007
> - 27 Mar 2007
> 
>  include/linux/kprobes.h |4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> --- linux-2.6.21-rc4-mm1/include/linux/kprobes.h.old  2007-03-26 
> 15:28:27.0 +0200
> +++ linux-2.6.21-rc4-mm1/include/linux/kprobes.h  2007-03-26 
> 15:32:23.0 +0200
> @@ -163,7 +163,6 @@
>  extern void arch_arm_kprobe(struct kprobe *p);
>  extern void arch_disarm_kprobe(struct kprobe *p);
>  extern int arch_init_kprobes(void);
> -extern void show_registers(struct pt_regs *regs);
>  extern kprobe_opcode_t *get_insn_slot(void);
>  extern void free_insn_slot(kprobe_opcode_t *slot, int dirty);
>  extern void kprobes_inc_nmissed_count(struct kprobe *p);
> @@ -241,4 +240,7 @@
>  {
>  }
>  #endif   /* CONFIG_KPROBES */
> +
> +void show_registers(struct pt_regs *regs);
> +
>  #endif   /* _LINUX_KPROBES_H */

-- 
Prasanna S.P.
Linux Technology Center
India Software Labs, IBM Bangalore
Email: [EMAIL PROTECTED]
Ph: 91-80-41776329
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [2.6 patch] include/linux/kprobes.h: always offer show_registers() prototype

2007-06-18 Thread S. P. Prasanna

On Mon, Jun 18, 2007 at 01:43:04AM +0200, Adrian Bunk wrote:
 Allow gcc to perform show_registers() type checking also with 
 CONFIG_KPROBES=n.
 
Adrian,

Please implement it as Andrew suggested, when this was patch was posted
eariler. Refer this discussion thread below.

http://lkml.org/lkml/2007/4/27/576

NACK

Thanks
Prasanna

 Signed-off-by: Adrian Bunk [EMAIL PROTECTED]
 
 ---
 
 This patch has been sent on:
 - 27 Apr 2007
 - 27 Mar 2007
 
  include/linux/kprobes.h |4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
 
 --- linux-2.6.21-rc4-mm1/include/linux/kprobes.h.old  2007-03-26 
 15:28:27.0 +0200
 +++ linux-2.6.21-rc4-mm1/include/linux/kprobes.h  2007-03-26 
 15:32:23.0 +0200
 @@ -163,7 +163,6 @@
  extern void arch_arm_kprobe(struct kprobe *p);
  extern void arch_disarm_kprobe(struct kprobe *p);
  extern int arch_init_kprobes(void);
 -extern void show_registers(struct pt_regs *regs);
  extern kprobe_opcode_t *get_insn_slot(void);
  extern void free_insn_slot(kprobe_opcode_t *slot, int dirty);
  extern void kprobes_inc_nmissed_count(struct kprobe *p);
 @@ -241,4 +240,7 @@
  {
  }
  #endif   /* CONFIG_KPROBES */
 +
 +void show_registers(struct pt_regs *regs);
 +
  #endif   /* _LINUX_KPROBES_H */

-- 
Prasanna S.P.
Linux Technology Center
India Software Labs, IBM Bangalore
Email: [EMAIL PROTECTED]
Ph: 91-80-41776329
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Kprobes x86_64 fix for mark ro data

2007-06-06 Thread S. P. Prasanna

This patch fixes the problem of page protection introduced by
CONFIG_DEBUG_RODATA for x86_64 architecture. As per Andi
Kleen's suggestion, the kernel text pages are marked writeable
only for a short duration to insert or remove the breakpoints.

Signed-off-by: Prasanna S P<[EMAIL PROTECTED]>
Ack-ed-by: Jim Keniston <[EMAIL PROTECTED]>


 arch/x86_64/kernel/kprobes.c |   26 ++
 arch/x86_64/mm/init.c|6 +-
 include/asm-x86_64/kprobes.h |   10 ++
 3 files changed, 41 insertions(+), 1 deletion(-)

diff -puN arch/x86_64/kernel/kprobes.c~kprobes-mark-ro-data-fix-x86_64 
arch/x86_64/kernel/kprobes.c
--- 
linux-2.6.22-rc2/arch/x86_64/kernel/kprobes.c~kprobes-mark-ro-data-fix-x86_64   
2007-06-07 09:20:33.0 +0530
+++ linux-2.6.22-rc2-prasanna/arch/x86_64/kernel/kprobes.c  2007-06-07 
09:20:33.0 +0530
@@ -209,16 +209,42 @@ static void __kprobes arch_copy_kprobe(s
 
 void __kprobes arch_arm_kprobe(struct kprobe *p)
 {
+   unsigned long addr = (unsigned long)p->addr;
+   int page_readonly = 0;
+
+   if (kernel_readonly_text(addr)) {
+   change_page_attr_addr(addr, 1, PAGE_KERNEL_EXEC);
+   global_flush_tlb();
+   page_readonly = 1;
+   }
*p->addr = BREAKPOINT_INSTRUCTION;
flush_icache_range((unsigned long) p->addr,
   (unsigned long) p->addr + sizeof(kprobe_opcode_t));
+   if (page_readonly) {
+   change_page_attr_addr(addr, 1, PAGE_KERNEL_RO);
+   global_flush_tlb();
+   }
 }
 
 void __kprobes arch_disarm_kprobe(struct kprobe *p)
 {
+   unsigned long addr = (unsigned long)p->addr;
+   int page_readonly = 0;
+
+   if (kernel_readonly_text(addr)) {
+   change_page_attr_addr(addr, 1, PAGE_KERNEL_EXEC);
+   global_flush_tlb();
+   page_readonly = 1;
+   }
+
*p->addr = p->opcode;
flush_icache_range((unsigned long) p->addr,
   (unsigned long) p->addr + sizeof(kprobe_opcode_t));
+
+   if (page_readonly) {
+   change_page_attr_addr(addr, 1, PAGE_KERNEL_RO);
+   global_flush_tlb();
+   }
 }
 
 void __kprobes arch_remove_kprobe(struct kprobe *p)
diff -puN include/asm-x86_64/kprobes.h~kprobes-mark-ro-data-fix-x86_64 
include/asm-x86_64/kprobes.h
--- 
linux-2.6.22-rc2/include/asm-x86_64/kprobes.h~kprobes-mark-ro-data-fix-x86_64   
2007-06-07 09:20:33.0 +0530
+++ linux-2.6.22-rc2-prasanna/include/asm-x86_64/kprobes.h  2007-06-07 
09:20:33.0 +0530
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define  __ARCH_WANT_KPROBES_INSN_SLOT
 
@@ -88,4 +89,13 @@ extern int kprobe_handler(struct pt_regs
 
 extern int kprobe_exceptions_notify(struct notifier_block *self,
unsigned long val, void *data);
+extern int kernel_text_is_ro;
+static inline int kernel_readonly_text(unsigned long address)
+{
+   if (kernel_text_is_ro && ((address >= (unsigned long)_stext)
+   && (address < (unsigned long) _etext)))
+   return 1;
+
+   return 0;
+}
 #endif /* _ASM_KPROBES_H */
diff -puN arch/x86_64/mm/init.c~kprobes-mark-ro-data-fix-x86_64 
arch/x86_64/mm/init.c
--- linux-2.6.22-rc2/arch/x86_64/mm/init.c~kprobes-mark-ro-data-fix-x86_64  
2007-06-07 09:20:33.0 +0530
+++ linux-2.6.22-rc2-prasanna/arch/x86_64/mm/init.c 2007-06-07 
09:20:33.0 +0530
@@ -48,6 +48,7 @@
 #define Dprintk(x...)
 #endif
 
+int kernel_text_is_ro;
 const struct dma_mapping_ops* dma_ops;
 EXPORT_SYMBOL(dma_ops);
 
@@ -598,10 +599,13 @@ void mark_rodata_ro(void)
 {
unsigned long start = (unsigned long)_stext, end;
 
+   kernel_text_is_ro = 1;
 #ifdef CONFIG_HOTPLUG_CPU
/* It must still be possible to apply SMP alternatives. */
-   if (num_possible_cpus() > 1)
+   if (num_possible_cpus() > 1) {
start = (unsigned long)_etext;
+   kernel_text_is_ro = 0;
+   }
 #endif
end = (unsigned long)__end_rodata;
start = (start + PAGE_SIZE - 1) & PAGE_MASK;

_
-- 
Prasanna S.P.
Linux Technology Center
India Software Labs, IBM Bangalore
Email: [EMAIL PROTECTED]
Ph: 91-80-41776329
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Kprobes i386 fix for mark ro data

2007-06-06 Thread S. P. Prasanna
On Thu, Jun 07, 2007 at 11:12:32AM +1200, Ian McDonald wrote:
> On 6/7/07, Chuck Ebbert <[EMAIL PROTECTED]> wrote:
> >On 06/06/2007 04:47 PM, Ian McDonald wrote:
> >> Hi there,
> >>
> >> We've seen a report of a problem with dccp_probe as shown below. The
> >> user has also verified that it occurs in tcp_probe as well. This is on
> >> Dave Miller's tree but that currently tracks Linus' tree quite
> >> closely. I do note that it is around 2.6.22-rc2 timeframe so there is
> >> a possibility fixes may have gone in since.
> >>
> >
> >It faulted when it tried to write the breakpoint instruction into the
> >running kernel's executable code. Apparently the kernel code is now marked
> >read-only?
> >
> >
> Yes it would appear to be the case as user has CONFIG_DEBUG_RODATA
> set. Patrick - can you turn this off and retest? It's under Kernel
> Hacking, Write protect kernel read only data structures.
> 
> The list of commits that I see around this are at:
> http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git=search=HEAD=commit=DEBUG_RODATA
> 
> I suspect it's probably one of the latter ones giving the timing.
> 
> I guess there are a couple of solutions here - either make kprobes
> conflict with CONFIG_DEBUG_RODATA so you can do one or the other, or
> look into more detail what access kprobes need.
> 
> Ian

Ian,

Please find the fix as suggested by Andi Kleen 
for the above stated problem.

Thanks
Prasanna


This patch fixes the problem of page protection introduced by
CONFIG_DEBUG_RODATA. CONFIG_DEBUG_RODATA marks the text pages as
read-only, hence kprobes is unable to insert breakpoints in the
kernel text. This patch overrides the page protection when adding
or removing a probe for the i386 architecture.

Signed-off-by: Prasanna S P<[EMAIL PROTECTED]>
Ack-ed-by: Jim Keniston <[EMAIL PROTECTED]>



 arch/i386/kernel/kprobes.c |   26 ++
 arch/i386/mm/init.c|2 ++
 include/asm-i386/kprobes.h |   12 
 include/asm-i386/pgtable.h |2 ++
 4 files changed, 42 insertions(+)

diff -puN arch/i386/kernel/kprobes.c~kprobes-mark-ro-data-fix-i386 
arch/i386/kernel/kprobes.c
--- linux-2.6.22-rc2/arch/i386/kernel/kprobes.c~kprobes-mark-ro-data-fix-i386   
2007-06-07 09:19:26.0 +0530
+++ linux-2.6.22-rc2-prasanna/arch/i386/kernel/kprobes.c2007-06-07 
09:19:26.0 +0530
@@ -169,16 +169,42 @@ int __kprobes arch_prepare_kprobe(struct
 
 void __kprobes arch_arm_kprobe(struct kprobe *p)
 {
+   unsigned long addr = (unsigned long) p->addr;
+   int page_readonly = 0;
+
+   if (kernel_readonly_text(addr)) {
+   page_readonly = 1;
+   change_page_attr(virt_to_page(addr), 1, PAGE_KERNEL_RWX);
+   global_flush_tlb();
+   }
+
*p->addr = BREAKPOINT_INSTRUCTION;
flush_icache_range((unsigned long) p->addr,
   (unsigned long) p->addr + sizeof(kprobe_opcode_t));
+
+   if (page_readonly) {
+   change_page_attr(virt_to_page(addr), 1, PAGE_KERNEL_RX);
+   global_flush_tlb();
+   }
 }
 
 void __kprobes arch_disarm_kprobe(struct kprobe *p)
 {
+   unsigned long addr = (unsigned long) p->addr;
+   int page_readonly = 0;
+
+   if (kernel_readonly_text(addr)) {
+   page_readonly = 1;
+   change_page_attr(virt_to_page(addr), 1, PAGE_KERNEL_RWX);
+   global_flush_tlb();
+   }
*p->addr = p->opcode;
flush_icache_range((unsigned long) p->addr,
   (unsigned long) p->addr + sizeof(kprobe_opcode_t));
+   if (page_readonly) {
+   change_page_attr(virt_to_page(addr), 1, PAGE_KERNEL_RX);
+   global_flush_tlb();
+   }
 }
 
 void __kprobes arch_remove_kprobe(struct kprobe *p)
diff -puN include/asm-i386/kprobes.h~kprobes-mark-ro-data-fix-i386 
include/asm-i386/kprobes.h
--- linux-2.6.22-rc2/include/asm-i386/kprobes.h~kprobes-mark-ro-data-fix-i386   
2007-06-07 09:19:26.0 +0530
+++ linux-2.6.22-rc2-prasanna/include/asm-i386/kprobes.h2007-06-07 
09:19:26.0 +0530
@@ -26,6 +26,8 @@
  */
 #include 
 #include 
+#include 
+#include 
 
 #define  __ARCH_WANT_KPROBES_INSN_SLOT
 
@@ -90,4 +92,14 @@ static inline void restore_interrupts(st
 
 extern int kprobe_exceptions_notify(struct notifier_block *self,
unsigned long val, void *data);
+extern int kernel_text_is_ro;
+static inline int kernel_readonly_text(unsigned long address)
+{
+
+   if (kernel_text_is_ro && ((address >= PFN_ALIGN(_text))
+   && (address < PFN_ALIGN(_etext
+   return 1;
+
+   return 0;
+}
 #endif /* _ASM_KPROBES_H */
diff -puN include/asm-i386/pgtable.h~kprobes-mark-ro-data-fix-i386 
include/asm-i386/pgtable.h
--- linux-2.6.22-rc2/include/asm-i386/pgtable.h~kprobes-mark-ro-data-fix-i386   
2007-06-07 09:19:26.0 +0530
+++ 

Re: [PATCH] Kprobes i386 fix for mark ro data

2007-06-06 Thread S. P. Prasanna
On Thu, Jun 07, 2007 at 11:12:32AM +1200, Ian McDonald wrote:
 On 6/7/07, Chuck Ebbert [EMAIL PROTECTED] wrote:
 On 06/06/2007 04:47 PM, Ian McDonald wrote:
  Hi there,
 
  We've seen a report of a problem with dccp_probe as shown below. The
  user has also verified that it occurs in tcp_probe as well. This is on
  Dave Miller's tree but that currently tracks Linus' tree quite
  closely. I do note that it is around 2.6.22-rc2 timeframe so there is
  a possibility fixes may have gone in since.
 
 
 It faulted when it tried to write the breakpoint instruction into the
 running kernel's executable code. Apparently the kernel code is now marked
 read-only?
 
 
 Yes it would appear to be the case as user has CONFIG_DEBUG_RODATA
 set. Patrick - can you turn this off and retest? It's under Kernel
 Hacking, Write protect kernel read only data structures.
 
 The list of commits that I see around this are at:
 http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.gita=searchh=HEADst=commits=DEBUG_RODATA
 
 I suspect it's probably one of the latter ones giving the timing.
 
 I guess there are a couple of solutions here - either make kprobes
 conflict with CONFIG_DEBUG_RODATA so you can do one or the other, or
 look into more detail what access kprobes need.
 
 Ian

Ian,

Please find the fix as suggested by Andi Kleen 
for the above stated problem.

Thanks
Prasanna


This patch fixes the problem of page protection introduced by
CONFIG_DEBUG_RODATA. CONFIG_DEBUG_RODATA marks the text pages as
read-only, hence kprobes is unable to insert breakpoints in the
kernel text. This patch overrides the page protection when adding
or removing a probe for the i386 architecture.

Signed-off-by: Prasanna S P[EMAIL PROTECTED]
Ack-ed-by: Jim Keniston [EMAIL PROTECTED]



 arch/i386/kernel/kprobes.c |   26 ++
 arch/i386/mm/init.c|2 ++
 include/asm-i386/kprobes.h |   12 
 include/asm-i386/pgtable.h |2 ++
 4 files changed, 42 insertions(+)

diff -puN arch/i386/kernel/kprobes.c~kprobes-mark-ro-data-fix-i386 
arch/i386/kernel/kprobes.c
--- linux-2.6.22-rc2/arch/i386/kernel/kprobes.c~kprobes-mark-ro-data-fix-i386   
2007-06-07 09:19:26.0 +0530
+++ linux-2.6.22-rc2-prasanna/arch/i386/kernel/kprobes.c2007-06-07 
09:19:26.0 +0530
@@ -169,16 +169,42 @@ int __kprobes arch_prepare_kprobe(struct
 
 void __kprobes arch_arm_kprobe(struct kprobe *p)
 {
+   unsigned long addr = (unsigned long) p-addr;
+   int page_readonly = 0;
+
+   if (kernel_readonly_text(addr)) {
+   page_readonly = 1;
+   change_page_attr(virt_to_page(addr), 1, PAGE_KERNEL_RWX);
+   global_flush_tlb();
+   }
+
*p-addr = BREAKPOINT_INSTRUCTION;
flush_icache_range((unsigned long) p-addr,
   (unsigned long) p-addr + sizeof(kprobe_opcode_t));
+
+   if (page_readonly) {
+   change_page_attr(virt_to_page(addr), 1, PAGE_KERNEL_RX);
+   global_flush_tlb();
+   }
 }
 
 void __kprobes arch_disarm_kprobe(struct kprobe *p)
 {
+   unsigned long addr = (unsigned long) p-addr;
+   int page_readonly = 0;
+
+   if (kernel_readonly_text(addr)) {
+   page_readonly = 1;
+   change_page_attr(virt_to_page(addr), 1, PAGE_KERNEL_RWX);
+   global_flush_tlb();
+   }
*p-addr = p-opcode;
flush_icache_range((unsigned long) p-addr,
   (unsigned long) p-addr + sizeof(kprobe_opcode_t));
+   if (page_readonly) {
+   change_page_attr(virt_to_page(addr), 1, PAGE_KERNEL_RX);
+   global_flush_tlb();
+   }
 }
 
 void __kprobes arch_remove_kprobe(struct kprobe *p)
diff -puN include/asm-i386/kprobes.h~kprobes-mark-ro-data-fix-i386 
include/asm-i386/kprobes.h
--- linux-2.6.22-rc2/include/asm-i386/kprobes.h~kprobes-mark-ro-data-fix-i386   
2007-06-07 09:19:26.0 +0530
+++ linux-2.6.22-rc2-prasanna/include/asm-i386/kprobes.h2007-06-07 
09:19:26.0 +0530
@@ -26,6 +26,8 @@
  */
 #include linux/types.h
 #include linux/ptrace.h
+#include linux/pfn.h
+#include asm-generic/sections.h
 
 #define  __ARCH_WANT_KPROBES_INSN_SLOT
 
@@ -90,4 +92,14 @@ static inline void restore_interrupts(st
 
 extern int kprobe_exceptions_notify(struct notifier_block *self,
unsigned long val, void *data);
+extern int kernel_text_is_ro;
+static inline int kernel_readonly_text(unsigned long address)
+{
+
+   if (kernel_text_is_ro  ((address = PFN_ALIGN(_text))
+(address  PFN_ALIGN(_etext
+   return 1;
+
+   return 0;
+}
 #endif /* _ASM_KPROBES_H */
diff -puN include/asm-i386/pgtable.h~kprobes-mark-ro-data-fix-i386 
include/asm-i386/pgtable.h
--- linux-2.6.22-rc2/include/asm-i386/pgtable.h~kprobes-mark-ro-data-fix-i386   
2007-06-07 09:19:26.0 +0530
+++ 

Re: [PATCH] Kprobes x86_64 fix for mark ro data

2007-06-06 Thread S. P. Prasanna

This patch fixes the problem of page protection introduced by
CONFIG_DEBUG_RODATA for x86_64 architecture. As per Andi
Kleen's suggestion, the kernel text pages are marked writeable
only for a short duration to insert or remove the breakpoints.

Signed-off-by: Prasanna S P[EMAIL PROTECTED]
Ack-ed-by: Jim Keniston [EMAIL PROTECTED]


 arch/x86_64/kernel/kprobes.c |   26 ++
 arch/x86_64/mm/init.c|6 +-
 include/asm-x86_64/kprobes.h |   10 ++
 3 files changed, 41 insertions(+), 1 deletion(-)

diff -puN arch/x86_64/kernel/kprobes.c~kprobes-mark-ro-data-fix-x86_64 
arch/x86_64/kernel/kprobes.c
--- 
linux-2.6.22-rc2/arch/x86_64/kernel/kprobes.c~kprobes-mark-ro-data-fix-x86_64   
2007-06-07 09:20:33.0 +0530
+++ linux-2.6.22-rc2-prasanna/arch/x86_64/kernel/kprobes.c  2007-06-07 
09:20:33.0 +0530
@@ -209,16 +209,42 @@ static void __kprobes arch_copy_kprobe(s
 
 void __kprobes arch_arm_kprobe(struct kprobe *p)
 {
+   unsigned long addr = (unsigned long)p-addr;
+   int page_readonly = 0;
+
+   if (kernel_readonly_text(addr)) {
+   change_page_attr_addr(addr, 1, PAGE_KERNEL_EXEC);
+   global_flush_tlb();
+   page_readonly = 1;
+   }
*p-addr = BREAKPOINT_INSTRUCTION;
flush_icache_range((unsigned long) p-addr,
   (unsigned long) p-addr + sizeof(kprobe_opcode_t));
+   if (page_readonly) {
+   change_page_attr_addr(addr, 1, PAGE_KERNEL_RO);
+   global_flush_tlb();
+   }
 }
 
 void __kprobes arch_disarm_kprobe(struct kprobe *p)
 {
+   unsigned long addr = (unsigned long)p-addr;
+   int page_readonly = 0;
+
+   if (kernel_readonly_text(addr)) {
+   change_page_attr_addr(addr, 1, PAGE_KERNEL_EXEC);
+   global_flush_tlb();
+   page_readonly = 1;
+   }
+
*p-addr = p-opcode;
flush_icache_range((unsigned long) p-addr,
   (unsigned long) p-addr + sizeof(kprobe_opcode_t));
+
+   if (page_readonly) {
+   change_page_attr_addr(addr, 1, PAGE_KERNEL_RO);
+   global_flush_tlb();
+   }
 }
 
 void __kprobes arch_remove_kprobe(struct kprobe *p)
diff -puN include/asm-x86_64/kprobes.h~kprobes-mark-ro-data-fix-x86_64 
include/asm-x86_64/kprobes.h
--- 
linux-2.6.22-rc2/include/asm-x86_64/kprobes.h~kprobes-mark-ro-data-fix-x86_64   
2007-06-07 09:20:33.0 +0530
+++ linux-2.6.22-rc2-prasanna/include/asm-x86_64/kprobes.h  2007-06-07 
09:20:33.0 +0530
@@ -26,6 +26,7 @@
 #include linux/types.h
 #include linux/ptrace.h
 #include linux/percpu.h
+#include asm-generic/sections.h
 
 #define  __ARCH_WANT_KPROBES_INSN_SLOT
 
@@ -88,4 +89,13 @@ extern int kprobe_handler(struct pt_regs
 
 extern int kprobe_exceptions_notify(struct notifier_block *self,
unsigned long val, void *data);
+extern int kernel_text_is_ro;
+static inline int kernel_readonly_text(unsigned long address)
+{
+   if (kernel_text_is_ro  ((address = (unsigned long)_stext)
+(address  (unsigned long) _etext)))
+   return 1;
+
+   return 0;
+}
 #endif /* _ASM_KPROBES_H */
diff -puN arch/x86_64/mm/init.c~kprobes-mark-ro-data-fix-x86_64 
arch/x86_64/mm/init.c
--- linux-2.6.22-rc2/arch/x86_64/mm/init.c~kprobes-mark-ro-data-fix-x86_64  
2007-06-07 09:20:33.0 +0530
+++ linux-2.6.22-rc2-prasanna/arch/x86_64/mm/init.c 2007-06-07 
09:20:33.0 +0530
@@ -48,6 +48,7 @@
 #define Dprintk(x...)
 #endif
 
+int kernel_text_is_ro;
 const struct dma_mapping_ops* dma_ops;
 EXPORT_SYMBOL(dma_ops);
 
@@ -598,10 +599,13 @@ void mark_rodata_ro(void)
 {
unsigned long start = (unsigned long)_stext, end;
 
+   kernel_text_is_ro = 1;
 #ifdef CONFIG_HOTPLUG_CPU
/* It must still be possible to apply SMP alternatives. */
-   if (num_possible_cpus()  1)
+   if (num_possible_cpus()  1) {
start = (unsigned long)_etext;
+   kernel_text_is_ro = 0;
+   }
 #endif
end = (unsigned long)__end_rodata;
start = (start + PAGE_SIZE - 1)  PAGE_MASK;

_
-- 
Prasanna S.P.
Linux Technology Center
India Software Labs, IBM Bangalore
Email: [EMAIL PROTECTED]
Ph: 91-80-41776329
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Kwatch: kernel watchpoints using CPU debug registers

2007-02-22 Thread S. P. Prasanna
On Wed, Feb 21, 2007 at 03:35:13PM -0500, Alan Stern wrote:
> Going back to something you mentioned earlier...
> 
[...]
> On Fri, 9 Feb 2007, Roland McGrath wrote:
> There are two things I am uncertain about: vm86 mode and kprobes.  I don't
> know anything about how either of them works.  Judging from the current
> code, nothing much should be needed -- debug traps in vm86 mode are
> handled by calling handle_vm86_trap(), and kprobes puts itself at the
> start of the notify_die() chain so it can handle single-step traps.  
> Eventually it will be necessary to check with someone who really 
> understands the issues.

Yes, Kprobes needs to get notified first to handle single-step traps. So kwatch
getting notified secound should be fine.

Thanks
Prasanna
-- 
Prasanna S.P.
Linux Technology Center
India Software Labs, IBM Bangalore
Email: [EMAIL PROTECTED]
Ph: 91-80-41776329
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Kwatch: kernel watchpoints using CPU debug registers

2007-02-22 Thread S. P. Prasanna
On Wed, Feb 21, 2007 at 03:35:13PM -0500, Alan Stern wrote:
 Going back to something you mentioned earlier...
 
[...]
 On Fri, 9 Feb 2007, Roland McGrath wrote:
 There are two things I am uncertain about: vm86 mode and kprobes.  I don't
 know anything about how either of them works.  Judging from the current
 code, nothing much should be needed -- debug traps in vm86 mode are
 handled by calling handle_vm86_trap(), and kprobes puts itself at the
 start of the notify_die() chain so it can handle single-step traps.  
 Eventually it will be necessary to check with someone who really 
 understands the issues.

Yes, Kprobes needs to get notified first to handle single-step traps. So kwatch
getting notified secound should be fine.

Thanks
Prasanna
-- 
Prasanna S.P.
Linux Technology Center
India Software Labs, IBM Bangalore
Email: [EMAIL PROTECTED]
Ph: 91-80-41776329
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 0/4 update] kprobes and traps

2007-01-17 Thread S. P. Prasanna
On Tue, Jan 16, 2007 at 04:27:40PM -0500, Mathieu Desnoyers wrote:
> Hi,
> 
> I have looked at kprobes code and have some questions for you. I would really
> like to use it to patch dynamically my marker immediate value by doing code
> patching. Using an int3 seems like the right way to handle this wrt pIII 
> erratum
> 49.
> 
> Everything is ok, except for a limitation important to the LTTng project :
> kprobes cannot probe trap handlers. Looking at the code, I see that the 
> kprobes
> trap notifier expects interrupts to be disabled when it is run. Looking a 
> little
> deeper in the code, I notice that you use per-cpu data structures to keep the
> probe control information that is needed for single stepping, which clearly
> requires you to disable interrupts so no interrupt handler with a kprobe in it
> fires on top of the kprobe handler. It also forbids trap handler and NMI
> handler instrumentation, as traps can be triggered by the kprobes handler and
> NMIs can come at any point during execution.

>From i386 point of view, your understanding is correct.

> 
> Would it be possible to put these data structures on the stack or on a
> separate stack accessible through thread_info instead ?
> 

Yes, probably you can put them on per thread kernel stack.
But you need to find enough stack space to save the probe control
information. Also enough stack space should be allocated to handle
re-entrant kprobe handlers.
How will you handle the case where in nested interrupts happen while you
are in a the kprobe handler and those interrupt handlers have probes.
How many levels of nesting will you allow?

Regards
Prasanna

> 
> 
> * Mathieu Desnoyers ([EMAIL PROTECTED]) wrote:
> > Hi Richard,
> >
> > * Mathieu Desnoyers ([EMAIL PROTECTED]) wrote:
> > > > You've got the same optimizations for x86 by modifying an instruction's
> > > > immediate operand and thus avoiding a d-cache hit. The only real caveat 
> > > > is
> > > > the need to avoid the unsynchronised cross modification erratum. Which
> > > > means that all processors will need to issue a serializing operation 
> > > > before
> > > > executing a Marker whose state is changed. How is that handled?
> > > >
> > >
> > > Good catch. I thought that modifying only 1 byte would spare us from this
> > > errata, but looking at it in detail tells me than it's not the case.
> > >
> > > I see three different ways to address the problem :
> > [...]
> > > 3 - First write an int3 instead of the instruction's first byte. The 
> > > handler
> > > would do the following :
> > > int3_handler :
> > >   single-step the original instruction.
> > >   iret
> > >
> > > Secondly, we call an IPI that does a smp_processor_id() on each CPU 
> > > and
> > > wait for them to complete. It will make sure we execute a 
> > > synchronizing
> > > instruction on every CPU even if we do not execute the trap handler.
> > >
> > > Then, we write the new 2 bytes instruction atomically instead of the 
> > > int3
> > > and immediate value.
> > >
> > >
> >
> > Here is the implementation of my proposal using a slightly enhanced 
> > kprobes. I
> > add the ability to single step a different instruction than the original 
> > one,
> > and then put the new instruction instead of the original one when removing 
> > the
> > kprobe. It is an improvement on the djprobes design : AFAIK, djprobes 
> > required
> > the int3 to be executed by _every_ CPU before the instruction could be
> > replaced. It was problematic with rarely used code paths (error handling) 
> > and
> > with thread CPU affinity. Comments are welcome.
> >
> > I noticed that it restrains LTTng by removing the ability to probe
> > do_general_protection, do_nmi, do_trap, do_debug and do_page_fault.
> > hardirq on/off in lockdep.c must also be tweaked to allow
> > local_irq_enable/disable usage within the debug trap handler.
> >
> > It would be nice to push the study of the kprobes debug trap handler so it 
> > can
> > become possible to use it to put breakpoints in trap handlers. For now, 
> > kprobes
> > refuses to insert breakpoints in __kprobes marked functions. However, as we
> > instrument specific spots of the functions (not necessarily the function 
> > entry),
> > it is sometimes correct to use kprobes on a marker within the function even 
> > if
> > it is not correct to use it in the prologue. Insight from the SystemTAP team
> > would be welcome on this kprobe limitation.
> >
> > Mathieu
> >
> > Signed-off-by: Mathieu Desnoyers <[EMAIL PROTECTED]>
> >
> > --- a/arch/i386/kernel/kprobes.c
> > +++ b/arch/i386/kernel/kprobes.c
> > @@ -31,6 +31,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -753,6 +754,73 @@ int __kprobes longjmp_break_handler(struct kprobe *p, 
> > struct pt_regs *regs)
> > return 0;
> >  }
> >
> > +static struct kprobe xmc_kp;
> > 

Re: [PATCH 0/4 update] kprobes and traps

2007-01-17 Thread S. P. Prasanna
On Tue, Jan 16, 2007 at 04:27:40PM -0500, Mathieu Desnoyers wrote:
 Hi,
 
 I have looked at kprobes code and have some questions for you. I would really
 like to use it to patch dynamically my marker immediate value by doing code
 patching. Using an int3 seems like the right way to handle this wrt pIII 
 erratum
 49.
 
 Everything is ok, except for a limitation important to the LTTng project :
 kprobes cannot probe trap handlers. Looking at the code, I see that the 
 kprobes
 trap notifier expects interrupts to be disabled when it is run. Looking a 
 little
 deeper in the code, I notice that you use per-cpu data structures to keep the
 probe control information that is needed for single stepping, which clearly
 requires you to disable interrupts so no interrupt handler with a kprobe in it
 fires on top of the kprobe handler. It also forbids trap handler and NMI
 handler instrumentation, as traps can be triggered by the kprobes handler and
 NMIs can come at any point during execution.

From i386 point of view, your understanding is correct.

 
 Would it be possible to put these data structures on the stack or on a
 separate stack accessible through thread_info instead ?
 

Yes, probably you can put them on per thread kernel stack.
But you need to find enough stack space to save the probe control
information. Also enough stack space should be allocated to handle
re-entrant kprobe handlers.
How will you handle the case where in nested interrupts happen while you
are in a the kprobe handler and those interrupt handlers have probes.
How many levels of nesting will you allow?

Regards
Prasanna

 
 
 * Mathieu Desnoyers ([EMAIL PROTECTED]) wrote:
  Hi Richard,
 
  * Mathieu Desnoyers ([EMAIL PROTECTED]) wrote:
You've got the same optimizations for x86 by modifying an instruction's
immediate operand and thus avoiding a d-cache hit. The only real caveat 
is
the need to avoid the unsynchronised cross modification erratum. Which
means that all processors will need to issue a serializing operation 
before
executing a Marker whose state is changed. How is that handled?
   
  
   Good catch. I thought that modifying only 1 byte would spare us from this
   errata, but looking at it in detail tells me than it's not the case.
  
   I see three different ways to address the problem :
  [...]
   3 - First write an int3 instead of the instruction's first byte. The 
   handler
   would do the following :
   int3_handler :
 single-step the original instruction.
 iret
  
   Secondly, we call an IPI that does a smp_processor_id() on each CPU 
   and
   wait for them to complete. It will make sure we execute a 
   synchronizing
   instruction on every CPU even if we do not execute the trap handler.
  
   Then, we write the new 2 bytes instruction atomically instead of the 
   int3
   and immediate value.
  
  
 
  Here is the implementation of my proposal using a slightly enhanced 
  kprobes. I
  add the ability to single step a different instruction than the original 
  one,
  and then put the new instruction instead of the original one when removing 
  the
  kprobe. It is an improvement on the djprobes design : AFAIK, djprobes 
  required
  the int3 to be executed by _every_ CPU before the instruction could be
  replaced. It was problematic with rarely used code paths (error handling) 
  and
  with thread CPU affinity. Comments are welcome.
 
  I noticed that it restrains LTTng by removing the ability to probe
  do_general_protection, do_nmi, do_trap, do_debug and do_page_fault.
  hardirq on/off in lockdep.c must also be tweaked to allow
  local_irq_enable/disable usage within the debug trap handler.
 
  It would be nice to push the study of the kprobes debug trap handler so it 
  can
  become possible to use it to put breakpoints in trap handlers. For now, 
  kprobes
  refuses to insert breakpoints in __kprobes marked functions. However, as we
  instrument specific spots of the functions (not necessarily the function 
  entry),
  it is sometimes correct to use kprobes on a marker within the function even 
  if
  it is not correct to use it in the prologue. Insight from the SystemTAP team
  would be welcome on this kprobe limitation.
 
  Mathieu
 
  Signed-off-by: Mathieu Desnoyers [EMAIL PROTECTED]
 
  --- a/arch/i386/kernel/kprobes.c
  +++ b/arch/i386/kernel/kprobes.c
  @@ -31,6 +31,7 @@
   #include linux/kprobes.h
   #include linux/ptrace.h
   #include linux/preempt.h
  +#include linux/kallsyms.h
   #include asm/cacheflush.h
   #include asm/kdebug.h
   #include asm/desc.h
  @@ -753,6 +754,73 @@ int __kprobes longjmp_break_handler(struct kprobe *p, 
  struct pt_regs *regs)
  return 0;
   }
 
  +static struct kprobe xmc_kp;
  +DEFINE_MUTEX(kprobe_xmc_mutex);
  +
  +static int xmc_handler_pre(struct kprobe *p, struct pt_regs *regs)
  +{
  +   return 0;
  +}
  +
  +static 

Re: Kwatch patch available for 2.6.20?

2007-01-07 Thread S. P. Prasanna
On Sun, Jan 07, 2007 at 01:00:08PM -0500, Alan Stern wrote:
> Has the kwatch patch (hardware watchpooint debugging for x86) been updated
> to the current kernel?  Is it available anywhere?

Hi Alan,

On Sun, Jan 07, 2007 at 01:00:08PM -0500, Alan Stern wrote:
> Has the kwatch patch (hardware watchpooint debugging for x86) been
updated
> to the current kernel?  Is it available anywhere?

Currently kwatch patches are for 2.6.13 kernel.
Please find the watchpoint probe patches in URL below.

http://lkml.org/lkml/2005/8/30/57
http://lkml.org/lkml/2005/8/30/48

These patches were posted on lkml sometime back.
Please let me know if you need any help.


Thanks
Prasanna


> 
> Thank you,
> 
> Alan Stern

-- 
Prasanna S.P.
Linux Technology Center
India Software Labs, IBM Bangalore
Email: [EMAIL PROTECTED]
Ph: 91-80-41776329
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: Kwatch patch available for 2.6.20?

2007-01-07 Thread S. P. Prasanna
On Sun, Jan 07, 2007 at 01:00:08PM -0500, Alan Stern wrote:
 Has the kwatch patch (hardware watchpooint debugging for x86) been updated
 to the current kernel?  Is it available anywhere?

Hi Alan,

On Sun, Jan 07, 2007 at 01:00:08PM -0500, Alan Stern wrote:
 Has the kwatch patch (hardware watchpooint debugging for x86) been
updated
 to the current kernel?  Is it available anywhere?

Currently kwatch patches are for 2.6.13 kernel.
Please find the watchpoint probe patches in URL below.

http://lkml.org/lkml/2005/8/30/57
http://lkml.org/lkml/2005/8/30/48

These patches were posted on lkml sometime back.
Please let me know if you need any help.


Thanks
Prasanna


 
 Thank you,
 
 Alan Stern

-- 
Prasanna S.P.
Linux Technology Center
India Software Labs, IBM Bangalore
Email: [EMAIL PROTECTED]
Ph: 91-80-41776329
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/