[PATCH] save parameter registers and restore them for jprobe handling

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] save parameter registers and restore them for jprobe handling

Zhang, Yanmin
When jprobe is hit, the function parameters of the original function
should be saved before jprobe handler is executed, and restored it after
jprobe handler is executed, because jprobe handler might change the
register values.

Here is a patch against 2.6.14-mm1.

Signed-off-by: Zhang Yanmin <[hidden email]>



jprobe_protect_out_reg_ia64_v2.patch (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] save parameter registers and restore them for jprobe handling

Keith Owens-2
On Thu, 1 Dec 2005 10:28:09 +0800,
"Zhang, Yanmin" <[hidden email]> wrote:
>Content-Transfer-Encoding: base64

Why base64 encoding for the patch?

+/*Invalidate stacked registers outside the current frame*/
+#define invalidate_stacked_regs() { \
+ unsigned long rsc_save = 0; \
+ asm volatile("mov %0=ar.rsc;;\n\t" \
+ "mov ar.rsc=0;;\n\t" \
+ "{\n\tloadrs;;\n\t\n\t\n\t}\n\t" \
+ "mov ar.rsc=%1\n\t" \
+ :"=r" (rsc_save):"r" (rsc_save):"memory"); \
+ }
+

We try to avoid inline asm in the .c files, it makes it harder to
compile the kernel with Intel compilers.

Reply | Threaded
Open this post in threaded view
|

RE: [PATCH] save parameter registers and restore them for jprobe handling

Zhang, Yanmin
In reply to this post by Zhang, Yanmin
>>-----Original Message-----

>>From: [hidden email]
>>[mailto:[hidden email]] On Behalf Of Keith Owens
>>Sent: 2005年12月1日 10:37
>>To: Zhang, Yanmin
>>Cc: [hidden email]; Keshavamurthy, Anil S;
>>[hidden email]
>>Subject: Re: [PATCH] save parameter registers and restore them for jprobe
>>handling
>>
>>On Thu, 1 Dec 2005 10:28:09 +0800,
>>"Zhang, Yanmin" <[hidden email]> wrote:
>>>Content-Transfer-Encoding: base64
>>
>>Why base64 encoding for the patch?
>>
>>+/*Invalidate stacked registers outside the current frame*/
>>+#define invalidate_stacked_regs() { \
>>+ unsigned long rsc_save = 0; \
>>+ asm volatile("mov %0=ar.rsc;;\n\t" \
>>+ "mov ar.rsc=0;;\n\t" \
>>+ "{\n\tloadrs;;\n\t\n\t\n\t}\n\t" \
>>+ "mov ar.rsc=%1\n\t" \
>>+ :"=r" (rsc_save):"r" (rsc_save):"memory"); \
>>+ }
>>+
>>
>>We try to avoid inline asm in the .c files, it makes it harder to
>>compile the kernel with Intel compilers.
How about the new patch? I add a new function in arch/ia64/kernel/entry.S.


jprobe_protect_out_reg_ia64_v3.patch (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

RE: [PATCH] save parameter registers and restore them for jprobe handling

Chen, Kenneth W
Zhang, Yanmin wrote on Wednesday, November 30, 2005 9:19 PM
> >>We try to avoid inline asm in the .c files, it makes it harder to
> >>compile the kernel with Intel compilers.
>
> How about the new patch? I add a new function in arch/ia64/kernel/entry.S.

I think it's more appropriate to place the new assembly function in
arch/ia64/kernel/jprobes.S.

- Ken

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] save parameter registers and restore them for jprobe handling

Keshavamurthy, Anil S
In reply to this post by Zhang, Yanmin
On Wed, Nov 30, 2005 at 09:19:02PM -0800, Zhang, Yanmin wrote:

> How about the new patch? I add a new function in arch/ia64/kernel/entry.S.
>
I agree with Ken, move the assembly function to arch/ia64/kernel/jprobe.S file.
Also, please see my comments.

>  int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
>  {
[...]
>   /* save architectural state */
Wrong comment above, we are not saving architectural state.
I guess the comment should be
"Callee owns the argument space and could overwrite it, eg
tail call optimization. So to be absolutely safe
we save the argument space before transfering the control
to instrumented jprobe function which runs in
the process context"

> @@ -785,8 +821,19 @@ int __kprobes setjmp_pre_handler(struct
>  int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
>  {
[....]
> + unw_init_running(ia64_get_bsp_cfm, &pa);
Just an optimization, avoid calling unw_init_running()
and just save bsp and cfm in the previous call and
reuse it. I think you can save in the kcb
structure.

> + bytes = (char *)ia64_rse_skip_regs(pa.bsp, pa.cfm & 0x3f)
> + - (char *)pa.bsp;
Again Comment please.. like
        /* restoring the original argument space */
> + memcpy( pa.bsp,
> + kcb->jprobes_saved_stacked_regs,
> + bytes );

-Anil Keshavamurthy
Reply | Threaded
Open this post in threaded view
|

RE: [PATCH] save parameter registers and restore them for jprobe handling

Zhang, Yanmin
In reply to this post by Zhang, Yanmin
>>-----Original Message-----
>>From: Keshavamurthy Anil S [mailto:[hidden email]]
>>Sent: 2005年12月2日 4:07
>>To: Zhang, Yanmin
>>Cc: Keith Owens; [hidden email]; Keshavamurthy, Anil S;
>>[hidden email]
>>Subject: Re: [PATCH] save parameter registers and restore them for jprobe
>>handling
Thanks. I updated the patch.
1) Move the assembly function to arch/ia64/kernel/jprobe.S;
2) Add/change comments;
3) Optimize. To do so, I add a new assembly function to flush register stack.


jprobe_protect_out_reg_ia64_v3.patch (5K) Download Attachment